/* ==========================================================================
   CS611 Study Site
   Theme: a defect tracker. Sections carry a status, progress reads as coverage.
   Mobile first. Everything scales up from 360px.
   ========================================================================== */

/* ---------- tokens ---------- */
:root {
  --bg: #f2f5f7;
  --surface: #ffffff;
  --surface-2: #e9eef2;
  --surface-3: #dfe6ec;
  --ink: #0e141b;
  --ink-2: #33404f;
  --muted: #677484;
  --line: #d8e0e7;
  --line-2: #c3ced8;

  --accent: #0d7a6a;
  --accent-ink: #075246;
  --accent-soft: #dff1ed;

  --pending: #8b97a6;
  --progress: #c07400;
  --progress-soft: #fdf1de;
  --closed: #197a51;
  --closed-soft: #ddf2e8;
  --flag: #bf3a44;
  --flag-soft: #fce9ea;

  --shadow-sm: 0 1px 2px rgba(14, 20, 27, .06), 0 1px 3px rgba(14, 20, 27, .04);
  --shadow-md: 0 4px 14px rgba(14, 20, 27, .1);
  --shadow-lg: 0 12px 40px rgba(14, 20, 27, .18);

  --display: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --body: "Source Serif 4", Charter, Georgia, "Times New Roman", serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;

  --topbar-h: 54px;
  --fs: 17px;
  --maxw: 44rem;
}

html[data-theme="dark"] {
  --bg: #0b0f15;
  --surface: #131a22;
  --surface-2: #1b232d;
  --surface-3: #232d39;
  --ink: #e7ecf2;
  --ink-2: #bcc6d2;
  --muted: #808d9d;
  --line: #232d39;
  --line-2: #33404f;

  --accent: #45c9b1;
  --accent-ink: #8fe3d3;
  --accent-soft: #10312c;

  --pending: #6d7a8a;
  --progress: #e0a145;
  --progress-soft: #2c2314;
  --closed: #4cc78d;
  --closed-soft: #102c20;
  --flag: #e8757f;
  --flag-soft: #2e181b;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .5);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .6);
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--topbar-h) + 16px);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: var(--fs);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

body.locked { overflow: hidden; }

button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

a { color: var(--accent); text-underline-offset: 3px; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ==========================================================================
   Top bar
   ========================================================================== */
.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 60;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px 0 4px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  color: var(--ink-2);
  flex: none;
  transition: background .15s ease, color .15s ease;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 21px; height: 21px; stroke-width: 1.9; }

.brand {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding-left: 2px;
}
.brand-code {
  font-family: var(--mono);
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--accent);
}
.brand-name {
  font-family: var(--display);
  font-size: .78rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: .01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- coverage bar: the signature element ---------- */
.coverage {
  position: fixed;
  top: var(--topbar-h);
  left: 0; right: 0;
  z-index: 59;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 7px 12px 8px;
}
.coverage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 5px;
}
.coverage-row .pct { margin-left: auto; color: var(--accent); font-weight: 700; letter-spacing: .02em; }
.coverage-track {
  height: 5px;
  border-radius: 99px;
  background: var(--surface-3);
  overflow: hidden;
  display: flex;
}
.coverage-fill {
  height: 100%;
  background: var(--closed);
  transition: width .45s cubic-bezier(.22, 1, .36, 1);
}
.coverage-fill.is-progress { background: var(--progress); opacity: .75; }

/* ==========================================================================
   Layout
   ========================================================================== */
.page {
  padding-top: calc(var(--topbar-h) + 44px);
  padding-bottom: 88px;
}
.wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 14px;
}

/* ---------- hero ---------- */
.hero { padding: 26px 0 8px; }
.hero-kicker {
  font-family: var(--mono);
  font-size: .64rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 14px;
  display: flex; align-items: center; gap: 8px;
}
.hero-kicker::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--line-2), transparent);
}
.hero h1 {
  font-family: var(--display);
  font-size: clamp(1.85rem, 8.5vw, 2.6rem);
  line-height: 1.08;
  letter-spacing: -.028em;
  font-weight: 600;
  margin: 0 0 12px;
  text-wrap: balance;
}
.hero h1 em {
  font-style: normal;
  color: var(--accent);
}
.hero-sub {
  color: var(--ink-2);
  margin: 0 0 20px;
  font-size: 1.02rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 22px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 11px 10px;
}
.stat b {
  display: block;
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -.02em;
  line-height: 1.1;
}
.stat span {
  font-family: var(--mono);
  font-size: .58rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 11px 15px;
  border-radius: var(--r-md);
  font-family: var(--display);
  font-size: .85rem;
  font-weight: 500;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
  transition: transform .12s ease;
}
.btn:active { transform: scale(.97); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
html[data-theme="dark"] .btn-primary { color: #06201c; }

/* ==========================================================================
   Parts
   ========================================================================== */
.part { margin-top: 40px; scroll-margin-top: calc(var(--topbar-h) + 52px); }

.part-head {
  padding: 0 0 14px;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 18px;
}
.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
}
.eyebrow-num { color: var(--accent); font-weight: 700; }
.eyebrow-dot { width: 3px; height: 3px; border-radius: 99px; background: var(--line-2); }
.part-title {
  font-family: var(--display);
  font-size: clamp(1.4rem, 6vw, 1.75rem);
  font-weight: 600;
  letter-spacing: -.024em;
  line-height: 1.12;
  margin: 0;
  text-wrap: balance;
}
.part-time {
  font-family: var(--mono);
  font-size: .64rem;
  color: var(--muted);
  margin: 7px 0 0;
  letter-spacing: .04em;
}

.part-intro { margin-bottom: 20px; }

/* ---------- module band ---------- */
.module-band {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 9px;
  margin: 30px 0 14px;
  padding: 11px 13px;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--r-md) var(--r-md) 0;
}
.module-label {
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .11em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
}
.module-name {
  font-family: var(--display);
  font-size: .95rem;
  font-weight: 500;
  letter-spacing: -.01em;
  flex: 1 1 100%;
}
.module-range {
  font-family: var(--mono);
  font-size: .6rem;
  color: var(--muted);
  letter-spacing: .05em;
}

/* ==========================================================================
   Topic cards
   ========================================================================== */
.topic {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  margin-bottom: 10px;
  overflow: hidden;
  scroll-margin-top: calc(var(--topbar-h) + 52px);
  transition: border-color .2s ease;
}
.topic[data-status="progress"] { border-left: 3px solid var(--progress); }
.topic[data-status="closed"] { border-left: 3px solid var(--closed); }
.topic[data-status="closed"] .topic-title { color: var(--muted); }

.topic-head { margin: 0; font-size: inherit; font-weight: inherit; }
.topic-toggle {
  width: 100%;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 14px 13px;
  text-align: left;
}
.topic-id {
  font-family: var(--mono);
  font-size: .68rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 6px;
  border-radius: var(--r-sm);
  flex: none;
  margin-top: 2px;
  letter-spacing: -.01em;
}
.topic-title {
  flex: 1;
  font-family: var(--display);
  font-size: .98rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -.012em;
}
.flag {
  flex: none;
  align-self: flex-start;
  margin-top: 3px;
  font-family: var(--mono);
  font-size: .54rem;
  letter-spacing: .07em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--flag);
  background: var(--flag-soft);
  padding: 3px 5px;
  border-radius: var(--r-sm);
  white-space: nowrap;
}
.chev {
  flex: none;
  width: 16px; height: 16px;
  margin-top: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .22s ease;
}
.topic-toggle[aria-expanded="false"] .chev { transform: rotate(-45deg) translate(-2px, 2px); }

.topic-body { padding: 0 13px 13px; }
.topic-body[hidden] { display: none; }

.topic-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border-radius: 99px;
  border: 1px solid var(--line-2);
  font-family: var(--mono);
  font-size: .66rem;
  letter-spacing: .07em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
  transition: all .18s ease;
}
.status-chip .dot {
  width: 7px; height: 7px;
  border-radius: 99px;
  background: currentColor;
  flex: none;
}
.status-chip[data-state="progress"] {
  color: var(--progress);
  border-color: color-mix(in srgb, var(--progress) 40%, transparent);
  background: var(--progress-soft);
}
.status-chip[data-state="closed"] {
  color: var(--closed);
  border-color: color-mix(in srgb, var(--closed) 40%, transparent);
  background: var(--closed-soft);
}
.status-chip:active { transform: scale(.95); }
.chip-hint {
  font-family: var(--mono);
  font-size: .58rem;
  color: var(--muted);
  letter-spacing: .05em;
}

/* ==========================================================================
   Content typography
   ========================================================================== */
.content > *:first-child { margin-top: 0; }
.content > *:last-child { margin-bottom: 0; }

.content p { margin: 0 0 .95em; }
.content h3, .content h4 {
  font-family: var(--display);
  font-weight: 600;
  letter-spacing: -.014em;
  line-height: 1.25;
  margin: 1.5em 0 .5em;
}
.content h3 { font-size: 1.02rem; }
.content h4 {
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--accent);
  font-family: var(--mono);
  font-weight: 700;
}

.content strong { font-weight: 700; color: var(--ink); }
.content em { font-style: italic; color: var(--ink-2); }

.content ul, .content ol { margin: 0 0 1em; padding-left: 1.35em; }
.content li { margin-bottom: .5em; }
.content li::marker { color: var(--accent); font-family: var(--mono); font-size: .85em; }
.content ul { list-style: none; padding-left: 1.1em; }
.content ul > li { position: relative; }
.content ul > li::before {
  content: "";
  position: absolute;
  left: -.95em; top: .62em;
  width: 5px; height: 5px;
  border-radius: 99px;
  background: var(--line-2);
}

/* inline "why this matters" tag, e.g. an item flagged as a real exam question */
.tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: .58rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--flag);
  background: var(--flag-soft);
  padding: 2px 6px;
  border-radius: var(--r-sm);
  margin-left: 4px;
  vertical-align: 1px;
  white-space: nowrap;
}

/* longer exam callouts read better as a note than a badge */
.note {
  display: inline;
  font-family: var(--display);
  font-size: .78em;
  font-weight: 600;
  color: var(--flag);
  margin-left: 4px;
}
.note::before { content: "\2190  "; }

/* ---------- formula callout ---------- */
.content blockquote {
  margin: 1.1em 0;
  padding: 15px 16px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
  border-radius: var(--r-md);
  position: relative;
}
.content blockquote::before {
  content: "Formula";
  position: absolute;
  top: -8px; left: 13px;
  font-family: var(--mono);
  font-size: .55rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  padding: 2px 7px;
  border-radius: 99px;
}
html[data-theme="dark"] .content blockquote::before { color: #06201c; }
.content blockquote > *:first-child { margin-top: 0; }
.content blockquote > *:last-child { margin-bottom: 0; }
.content blockquote h3 {
  font-family: var(--mono);
  font-size: .95rem;
  color: var(--accent-ink);
  margin: 4px 0;
  letter-spacing: -.01em;
}

/* ---------- code ---------- */
.content code {
  font-family: var(--mono);
  font-size: .8em;
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
}
.content pre {
  margin: 1.1em 0;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-size: .78rem;
  line-height: 1.6;
}
.content pre code {
  background: none; border: 0; padding: 0; font-size: inherit;
  white-space: pre;
}

/* ---------- tables ---------- */
.table-wrap {
  margin: 1.1em 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  position: relative;
}
.table-wrap.is-scrollable::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 28px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--surface));
  border-radius: 0 var(--r-md) var(--r-md) 0;
}
.table-wrap.at-end::after { opacity: 0; }
.content table {
  border-collapse: collapse;
  width: 100%;
  min-width: 460px;
  font-size: .82rem;
  font-family: var(--display);
}
.content thead th {
  background: var(--surface-2);
  font-weight: 600;
  text-align: left;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-family: var(--mono);
  color: var(--ink-2);
  white-space: nowrap;
}
.content th, .content td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  line-height: 1.45;
}
.content tbody tr:last-child td { border-bottom: 0; }
.content tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.scroll-note {
  font-family: var(--mono);
  font-size: .56rem;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  margin: -.7em 0 1.1em;
  display: flex; align-items: center; gap: 5px;
}

.content hr { border: 0; border-top: 1px solid var(--line); margin: 1.6em 0; }

/* ==========================================================================
   Quiz items (Part 06)
   ========================================================================== */
.content li.q {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 11px 12px;
  margin-bottom: 8px;
  list-style: none;
}
.content ol:has(li.q) { padding-left: 0; counter-reset: qn; }
.content li.q { counter-increment: qn; }
.content li.q .q-text::before {
  content: "Q" counter(qn);
  display: inline-block;
  font-family: var(--mono);
  font-size: .6rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 6px;
  border-radius: var(--r-sm);
  margin-right: 7px;
  vertical-align: 1px;
}
.q-text { display: block; }
.reveal {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
  padding: 6px 12px;
  border: 1px dashed var(--line-2);
  border-radius: 99px;
  font-family: var(--mono);
  font-size: .63rem;
  letter-spacing: .07em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
}
.reveal::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 99px;
  background: var(--pending);
}
.reveal:active { transform: scale(.96); }
.reveal[aria-expanded="true"] { display: none; }
.ans {
  display: block;
  margin-top: 9px;
  padding: 9px 11px;
  background: var(--closed-soft);
  border-left: 3px solid var(--closed);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: .95em;
  animation: reveal .22s ease;
}
.ans strong { color: var(--closed); }
@keyframes reveal { from { opacity: 0; transform: translateY(-3px); } }

/* ==========================================================================
   Drawer navigation
   ========================================================================== */
.scrim {
  position: fixed; inset: 0;
  z-index: 70;
  background: rgba(8, 12, 17, .5);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .24s ease, visibility .24s;
}
.scrim.open { opacity: 1; visibility: visible; }

.drawer {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 80;
  width: min(85vw, 340px);
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  transform: translateX(-102%);
  transition: transform .28s cubic-bezier(.22, 1, .36, 1);
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: none; }
@media (prefers-reduced-motion: reduce) {
  .drawer, .scrim, .coverage-fill, .chev { transition: none; }
  html { scroll-behavior: auto; }
}

.drawer-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px 12px 16px;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.drawer-head h2 {
  flex: 1;
  margin: 0;
  font-family: var(--display);
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: -.01em;
}
.drawer-nav {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px 28px;
  overscroll-behavior: contain;
}

.nav-part { margin-bottom: 3px; }
.nav-part-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 9px;
  border-radius: var(--r-md);
  text-align: left;
}
.nav-part-btn:active { background: var(--surface-2); }
.nav-num {
  font-family: var(--mono);
  font-size: .62rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 5px;
  border-radius: var(--r-sm);
  flex: none;
}
.nav-name {
  flex: 1;
  font-family: var(--display);
  font-size: .85rem;
  font-weight: 500;
  line-height: 1.25;
}
.nav-count {
  font-family: var(--mono);
  font-size: .58rem;
  color: var(--muted);
  flex: none;
}
.nav-caret {
  width: 12px; height: 12px; flex: none;
  border-right: 1.8px solid var(--muted);
  border-bottom: 1.8px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform .2s ease;
}
.nav-part.open .nav-caret { transform: rotate(45deg); }

.nav-topics { display: none; padding: 2px 0 8px 12px; margin-left: 12px; border-left: 1px solid var(--line); }
.nav-part.open .nav-topics { display: block; }
.nav-topic {
  display: flex;
  gap: 8px;
  padding: 8px 8px;
  border-radius: var(--r-sm);
  font-size: .8rem;
  font-family: var(--display);
  color: var(--ink-2);
  text-decoration: none;
  line-height: 1.3;
}
.nav-topic:active { background: var(--surface-2); }
.nav-topic .b { font-family: var(--mono); font-size: .68rem; color: var(--muted); flex: none; }
.nav-topic .s {
  width: 6px; height: 6px; border-radius: 99px; flex: none;
  margin-top: 6px; background: var(--surface-3);
}
.nav-topic[data-status="progress"] .s { background: var(--progress); }
.nav-topic[data-status="closed"] .s { background: var(--closed); }
.nav-band {
  font-family: var(--mono);
  font-size: .56rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 8px 4px;
  font-weight: 700;
}

/* ==========================================================================
   Search
   ========================================================================== */
.search {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: var(--bg);
  display: none;
  flex-direction: column;
}
.search.open { display: flex; }
.search-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: none;
}
.search-field {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 0 10px;
}
.search-field svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
#searchInput {
  flex: 1;
  border: 0; background: none; outline: none;
  padding: 11px 0;
  font-family: var(--display);
  font-size: 16px; /* keeps iOS from zooming */
  color: var(--ink);
  min-width: 0;
}
.search-results {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px 40px;
  overscroll-behavior: contain;
}
.search-meta {
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 2px;
}
.result {
  display: block;
  padding: 12px 13px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  text-decoration: none;
  color: inherit;
}
.result:active { border-color: var(--accent); }
.result-top {
  display: flex; align-items: center; gap: 7px; margin-bottom: 5px;
  font-family: var(--mono); font-size: .58rem;
  letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}
.result-top .p { color: var(--accent); font-weight: 700; }
.result-title {
  font-family: var(--display); font-size: .92rem; font-weight: 500;
  line-height: 1.3; margin-bottom: 4px;
}
.result-snip { font-size: .82rem; color: var(--ink-2); line-height: 1.5; }
.result mark, .content mark {
  background: color-mix(in srgb, var(--progress) 32%, transparent);
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty p { margin: 0 0 6px; }
.empty .big { font-family: var(--display); font-size: 1rem; color: var(--ink); }

/* ==========================================================================
   Floating controls
   ========================================================================== */
.fab-stack {
  position: fixed;
  right: 12px;
  bottom: 16px;
  z-index: 55;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
}
.fab {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 99px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  color: var(--ink-2);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px) scale(.9);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}
.fab.show { opacity: 1; transform: none; pointer-events: auto; }
.fab:active { transform: scale(.92); }
.fab svg { width: 20px; height: 20px; }

/* sheet of study tools */
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 85;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-lg);
  transform: translateY(102%);
  transition: transform .28s cubic-bezier(.22, 1, .36, 1);
  padding: 8px 14px calc(18px + env(safe-area-inset-bottom));
  max-height: 82vh;
  overflow-y: auto;
}
.sheet.open { transform: none; }
.sheet-grab {
  width: 36px; height: 4px; border-radius: 99px;
  background: var(--line-2); margin: 6px auto 14px;
}
.sheet h2 {
  font-family: var(--mono); font-size: .62rem; letter-spacing: .12em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 10px; font-weight: 700;
}
.tool-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
}
.tool-row:last-of-type { border-bottom: 0; }
.tool-label { flex: 1; font-family: var(--display); font-size: .88rem; }
.tool-label small { display: block; font-size: .72rem; color: var(--muted); font-weight: 400; margin-top: 1px; }

.switch {
  width: 46px; height: 27px; border-radius: 99px;
  background: var(--surface-3); position: relative; flex: none;
  transition: background .2s ease;
}
.switch::after {
  content: ""; position: absolute;
  top: 3px; left: 3px;
  width: 21px; height: 21px; border-radius: 99px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform .2s cubic-bezier(.22, 1, .36, 1);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(19px); }

.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: var(--r-md); flex: none; }
.seg button {
  padding: 7px 12px; border-radius: var(--r-sm);
  font-family: var(--mono); font-size: .68rem; font-weight: 700;
  color: var(--muted);
}
.seg button[data-fs="s"] { font-size: .6rem; }
.seg button[data-fs="m"] { font-size: .72rem; }
.seg button[data-fs="l"] { font-size: .88rem; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.danger {
  width: 100%; margin-top: 14px; padding: 12px;
  border: 1px solid color-mix(in srgb, var(--flag) 40%, transparent);
  background: var(--flag-soft); color: var(--flag);
  border-radius: var(--r-md);
  font-family: var(--display); font-size: .85rem; font-weight: 500;
}

/* toast */
.toast {
  position: fixed;
  left: 50%; bottom: 78px;
  transform: translate(-50%, 12px);
  z-index: 95;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 99px;
  font-family: var(--mono);
  font-size: .68rem;
  letter-spacing: .04em;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  white-space: nowrap;
  max-width: 92vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* footer */
.foot {
  margin-top: 52px;
  padding: 24px 0 12px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: .62rem;
  letter-spacing: .05em;
  color: var(--muted);
  text-align: center;
  line-height: 1.9;
}

/* Answers hide via the hidden attribute, so a single reveal still works in quiz mode. */
.ans[hidden] { display: none; }

/* font size steps */
html[data-fs="s"] { --fs: 15.5px; }
html[data-fs="m"] { --fs: 17px; }
html[data-fs="l"] { --fs: 19px; }

/* ==========================================================================
   Larger screens
   ========================================================================== */
@media (min-width: 700px) {
  :root { --topbar-h: 60px; }
  .wrap { padding: 0 24px; }
  .stats { gap: 12px; }
  .topic-toggle { padding: 16px; }
  .topic-body { padding: 0 16px 16px; }
  .content table { min-width: 0; }
  .fab-stack { right: 20px; bottom: 22px; }
  .search-results { padding: 8px 24px 40px; }
  .sheet {
    left: 50%; right: auto; bottom: 0;
    transform: translate(-50%, 102%);
    width: min(520px, 94vw);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }
  .sheet.open { transform: translate(-50%, 0); }
}

@media (min-width: 1080px) {
  .drawer {
    transform: none;
    box-shadow: none;
    width: 300px;
  }
  .scrim { display: none; }
  .page, .topbar, .coverage { padding-left: 300px; }
  .topbar .icon-btn.menu { display: none; }
  .drawer-head .icon-btn { display: none; }
  .fab.top { right: 20px; }
}

@media print {
  .topbar, .coverage, .drawer, .scrim, .fab-stack, .sheet, .search, .topic-foot { display: none !important; }
  .page { padding: 0; }
  .topic-body { display: block !important; }
  body { background: #fff; }
}
