/* Happy Alpaca v4 — a calm, textbook-quality study space.
   Paper, deep teal ink, one saffron accent. Serif for headings, the system sans for reading. */

:root {
  --paper: #faf7f1;
  --surface: #ffffff;
  --sunk: #f2ede3;
  --ink: #1b2a2a;
  --ink-2: #3a4b4a;
  --muted: #5d6c6a;
  --line: #e3dccd;
  --line-2: #d3cab7;
  --teal: #14504d;
  --teal-2: #1d6b66;
  --teal-soft: #e3efec;
  --amber: #e3a33b;
  --amber-ink: #7d5208;
  --amber-soft: #fbf0db;
  --ok: #24704a;
  --ok-soft: #e4f2e9;
  --bad: #ad3a2a;
  --bad-soft: #f8e5e1;
  --focus: #e3a33b;
  --shadow: 0 1px 2px rgba(27, 42, 42, .06), 0 4px 16px rgba(27, 42, 42, .06);
  --radius: 14px;
  --radius-s: 10px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Charter, "Bitstream Charter", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --fs: 17px;
  --nav-w: 248px;
  --top-h: 60px;
  --tab-h: 64px;
  color-scheme: light;
}
:root[data-text="s"] { --fs: 15.5px; }
:root[data-text="l"] { --fs: 19px; }
:root[data-text="xl"] { --fs: 21px; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1717; --surface: #162222; --sunk: #1c2a29; --ink: #e8efec; --ink-2: #cdd9d5; --muted: #9fb2ae;
    --line: #26393a; --line-2: #34494a; --teal: #7cc8bd; --teal-2: #96d6cc; --teal-soft: #1b3533;
    --amber: #f0b552; --amber-ink: #f5c979; --amber-soft: #33291a; --ok: #6fcf98; --ok-soft: #173426;
    --bad: #f0907f; --bad-soft: #3a1f1a; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0f1717; --surface: #162222; --sunk: #1c2a29; --ink: #e8efec; --ink-2: #cdd9d5; --muted: #9fb2ae;
  --line: #26393a; --line-2: #34494a; --teal: #7cc8bd; --teal-2: #96d6cc; --teal-soft: #1b3533;
  --amber: #f0b552; --amber-ink: #f5c979; --amber-soft: #33291a; --ok: #6fcf98; --ok-soft: #173426;
  --bad: #f0907f; --bad-soft: #3a1f1a; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25); color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: var(--fs); -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--top-h) + 12px); }
body {
  margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); line-height: 1.6;
  min-height: 100vh; min-height: 100dvh; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
img { max-width: 100%; height: auto; }
a { color: var(--teal-2); text-underline-offset: .18em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--serif); line-height: 1.2; color: var(--ink); font-weight: 600; letter-spacing: -.005em; }
h1 { font-size: 2rem; margin: .2em 0 .4em; }
h2 { font-size: 1.45rem; margin: 1.6em 0 .5em; }
h3 { font-size: 1.15rem; margin: 1.4em 0 .4em; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 14px; border-radius: 8px; }
.skip:focus { left: 8px; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--top-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--paper) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand img { width: 32px; height: 32px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-name { font-family: var(--serif); font-weight: 700; font-size: 1.08rem; }
.brand-sub { font-size: .72rem; color: var(--muted); letter-spacing: .02em; white-space: nowrap; }
.topbar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 12px; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--sunk); }
.icon-btn svg, .sidenav svg, .tabbar svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.sidenav { display: none; }
.sidenav ul { list-style: none; margin: 0; padding: 0; }
.sidenav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; margin: 2px 0; border-radius: 10px;
  text-decoration: none; color: var(--ink-2); font-weight: 500;
}
.sidenav a:hover { background: var(--sunk); }
.sidenav a[aria-current="page"] { background: var(--teal-soft); color: var(--teal); font-weight: 650; }
.sidenav-foot { margin: 18px 14px; font-size: .85rem; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none;
  color: var(--muted); font-size: .72rem; font-weight: 600; min-height: 44px;
}
.tabbar a[aria-current="page"] { color: var(--teal); }
.tabbar a[aria-current="page"] svg { stroke-width: 2.2; }

main { display: block; padding: 18px max(16px, env(safe-area-inset-left)) calc(var(--tab-h) + 40px + env(safe-area-inset-bottom)); outline: none; }
.page { max-width: 780px; margin: 0 auto; }
.page-wide { max-width: 1040px; margin: 0 auto; }
body.focus-mode .tabbar, body.focus-mode .sidenav { display: none !important; }
body.focus-mode main { padding-bottom: 40px; }

@media (min-width: 960px) {
  .sidenav {
    display: block; position: fixed; top: var(--top-h); left: 0; bottom: 0; width: var(--nav-w); padding: 18px 12px;
    border-right: 1px solid var(--line); overflow-y: auto; background: var(--paper);
  }
  .tabbar { display: none; }
  main { margin-left: var(--nav-w); padding: 28px 40px 60px; }
  body.focus-mode main { margin-left: 0; }
  h1 { font-size: 2.3rem; }
}

.boot { padding: 40px 0; text-align: center; color: var(--muted); }

/* ---------- building blocks ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 14px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.eyebrow { font-size: .78rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 650; margin: 0 0 4px; }
.lede { font-size: 1.1rem; color: var(--ink-2); max-width: 40em; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 10px 18px;
  border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-weight: 600;
  text-decoration: none; cursor: pointer; line-height: 1.2; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--sunk); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--teal); color: #fff; border-color: var(--teal); }
.btn-primary:hover { background: var(--teal-2); border-color: var(--teal-2); }
:root[data-theme="dark"] .btn-primary { color: #0f1717; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #0f1717; } }
.btn-ghost { border-color: transparent; background: transparent; color: var(--teal-2); }
.btn-ghost:hover { background: var(--teal-soft); }
.btn-small { min-height: 38px; padding: 6px 12px; font-size: .9rem; border-radius: 10px; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 650;
  background: var(--sunk); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap;
}
.chip-teal { background: var(--teal-soft); color: var(--teal); border-color: transparent; }
.chip-amber { background: var(--amber-soft); color: var(--amber-ink); border-color: transparent; }
.chip-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label, .field .label { font-weight: 650; font-size: .95rem; }
.field .hint { font-size: .85rem; color: var(--muted); }
input[type="text"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: 10px; background: var(--surface);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--teal-2); }

.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  position: relative; display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; min-height: 44px; border: 1px solid var(--line-2);
  border-radius: 999px; cursor: pointer; background: var(--surface); font-weight: 550; font-size: .93rem; user-select: none;
}
.check input { position: absolute; opacity: 0; pointer-events: none; }
.check:has(input:checked) { background: var(--teal-soft); border-color: var(--teal-2); color: var(--teal); }
.check:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.check:has(input:checked)::before { content: "✓"; font-weight: 800; }

.segmented { display: inline-flex; border: 1px solid var(--line-2); border-radius: 12px; padding: 3px; background: var(--sunk); flex-wrap: wrap; }
.segmented label { position: relative; padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: .92rem; min-height: 40px; display: flex; align-items: center; }
.segmented input { position: absolute; opacity: 0; }
.segmented label:has(input:checked) { background: var(--surface); box-shadow: var(--shadow); color: var(--teal); }
.segmented label:has(input:focus-visible) { outline: 3px solid var(--focus); }

.meter { height: 10px; background: var(--sunk); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.meter > span { display: block; height: 100%; background: var(--teal-2); border-radius: 999px; transition: width .4s ease; }
.meter.amber > span { background: var(--amber); }

.stat { display: grid; gap: 2px; }
.stat b { font-family: var(--serif); font-size: 1.9rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: .85rem; color: var(--muted); }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty img { width: 150px; margin: 0 auto 10px; display: block; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 18px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: .92rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 960px) { .toast { bottom: 24px; } }

/* ---------- home ---------- */
.hero { display: grid; gap: 10px; align-items: center; margin-bottom: 8px; }
.hero img { width: 100%; max-width: 420px; justify-self: center; border-radius: var(--radius); }
.hero h1 { margin-top: 0; }
@media (min-width: 760px) { .hero { grid-template-columns: 1.15fr 1fr; gap: 28px; } }
.countdown { font-family: var(--serif); font-size: 2.6rem; font-weight: 700; line-height: 1; color: var(--teal); font-variant-numeric: tabular-nums; }
.task { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; }
.task input[type="checkbox"] { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--teal-2); flex: none; }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-title { font-weight: 600; }
.quick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .quick { grid-template-columns: repeat(4, 1fr); } }
.quick a {
  display: grid; gap: 4px; padding: 14px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; color: var(--ink); box-shadow: var(--shadow); min-height: 96px;
}
.quick a:hover { border-color: var(--teal-2); }
.quick a b { font-size: 1rem; }
.quick a span { font-size: .82rem; color: var(--muted); line-height: 1.35; }
.quick svg { width: 24px; height: 24px; fill: none; stroke: var(--teal-2); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- prose (guides) ---------- */
.prose { font-size: 1rem; }
.prose h2 { padding-top: .2em; border-top: 1px solid var(--line); padding-top: 1em; }
.prose h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.prose ul, .prose ol { padding-left: 1.3em; margin: 0 0 1em; }
.prose li { margin: .3em 0; }
.prose li::marker { color: var(--teal-2); }
.prose code { font-family: var(--mono); font-size: .9em; background: var(--sunk); padding: .05em .35em; border-radius: 5px; }
.prose strong { color: var(--ink); }
.table-wrap { overflow-x: auto; margin: 0 0 1.2em; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { background: var(--sunk); font-weight: 700; white-space: nowrap; }
tbody tr:last-child > * { border-bottom: 0; }
tbody th { font-weight: 650; }
.callout { margin: 0 0 1.1em; padding: 12px 14px 12px 16px; border-radius: var(--radius-s); background: var(--teal-soft); border-left: 4px solid var(--teal-2); }
.callout-tip { background: var(--amber-soft); border-left-color: var(--amber); }
.callout-warn { background: var(--bad-soft); border-left-color: var(--bad); }
.guide-layout { display: grid; gap: 24px; }
.toc { font-size: .9rem; }
.toc ol { list-style: none; padding: 0; margin: 0; }
.toc a { display: block; padding: 5px 10px; border-radius: 8px; text-decoration: none; color: var(--ink-2); border-left: 2px solid var(--line); }
.toc a:hover { background: var(--sunk); }
.toc a.on { border-left-color: var(--teal-2); color: var(--teal); font-weight: 650; }
.toc details summary { cursor: pointer; font-weight: 650; padding: 10px 0; }
@media (min-width: 1200px) {
  .guide-layout { grid-template-columns: minmax(0, 1fr) 230px; }
  .toc { position: sticky; top: calc(var(--top-h) + 20px); align-self: start; max-height: calc(100vh - 120px); overflow: auto; }
  .toc details > summary { display: none; }
}
.guide-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 1.6em 0 0; padding-top: 1em; border-top: 1px solid var(--line); }

.topic-list { display: grid; gap: 12px; }
@media (min-width: 640px) { .topic-list { grid-template-columns: 1fr 1fr; } }
.topic {
  display: grid; gap: 6px; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
}
.topic:hover { border-color: var(--teal-2); }
.topic h3 { margin: 0; font-size: 1.1rem; }
.topic p { margin: 0; font-size: .88rem; color: var(--muted); line-height: 1.45; }
.topic .meter { margin-top: 6px; height: 6px; }

/* ---------- question ---------- */
.q-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.q-progress { flex: 1 1 160px; }
.q-progress .meter { height: 6px; margin-top: 4px; }
.timer { font-family: var(--mono); font-weight: 700; font-size: 1rem; padding: 4px 10px; border-radius: 8px; background: var(--sunk); font-variant-numeric: tabular-nums; }
.timer.low { background: var(--bad-soft); color: var(--bad); }
.q-stem { font-size: 1.06rem; line-height: 1.65; margin: 6px 0 18px; white-space: pre-line; }
.q-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.options { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.opt {
  width: 100%; display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: start; text-align: left; padding: 12px 14px;
  border: 1.5px solid var(--line-2); border-radius: 12px; background: var(--surface); cursor: pointer; line-height: 1.5; min-height: 52px;
}
.opt:hover:not([disabled]) { border-color: var(--teal-2); background: var(--teal-soft); }
.opt .letter {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 750; font-size: .9rem;
  background: var(--sunk); color: var(--ink-2); border: 1px solid var(--line-2);
}
.opt[aria-pressed="true"] { border-color: var(--teal); background: var(--teal-soft); }
.opt[aria-pressed="true"] .letter { background: var(--teal); color: #fff; border-color: var(--teal); }
.opt.is-right { border-color: var(--ok); background: var(--ok-soft); }
.opt.is-right .letter { background: var(--ok); color: #fff; border-color: var(--ok); }
.opt.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.is-wrong .letter { background: var(--bad); color: #fff; border-color: var(--bad); }
.opt.is-struck .opt-text { text-decoration: line-through; color: var(--muted); }
.opt[disabled] { cursor: default; }
.opt .mark { font-weight: 800; font-size: .85rem; }
.opt .why { grid-column: 2 / -1; font-size: .9rem; color: var(--ink-2); margin-top: 4px; }
.q-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: space-between; margin-top: 18px; }
.q-actions .grow { flex: 1; }
.explain { margin-top: 18px; padding: 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--sunk); }
.explain h3 { margin-top: 0; }
.explain .verdict { font-weight: 750; font-size: 1.05rem; margin-bottom: 6px; }
.explain .verdict.ok { color: var(--ok); }
.explain .verdict.bad { color: var(--bad); }
.key-point { margin: 12px 0 0; padding: 10px 12px; background: var(--amber-soft); border-radius: 10px; }
.ref { font-size: .85rem; color: var(--muted); margin-top: 10px; }
.strike-hint { font-size: .8rem; color: var(--muted); margin-top: 8px; }

.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; }
.palette button {
  height: 40px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); font-weight: 650; font-size: .85rem; cursor: pointer; position: relative;
}
.palette button.answered { background: var(--teal-soft); border-color: var(--teal-2); color: var(--teal); }
.palette button.current { outline: 2.5px solid var(--ink); outline-offset: 1px; }
.palette button.flagged::after { content: ""; position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.palette button.right { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.palette button.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }

/* ---------- results ---------- */
.score-ring { width: 140px; height: 140px; }
.score-ring circle { fill: none; stroke-width: 12; }
.score-ring .bg { stroke: var(--sunk); }
.score-ring .fg { stroke: var(--teal-2); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .8s ease; }
.score-ring text { font-family: var(--serif); font-weight: 700; fill: var(--ink); }
.bars { display: grid; gap: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 38%) 1fr 54px; gap: 10px; align-items: center; font-size: .92rem; }
.bar-row .meter { height: 12px; }
.bar-row b { text-align: right; font-variant-numeric: tabular-nums; }
.review-item { padding: 12px 0; border-top: 1px solid var(--line); }
.review-item summary { cursor: pointer; display: flex; gap: 10px; align-items: baseline; list-style: none; }
.review-item summary::-webkit-details-marker { display: none; }
.review-item summary .rq { flex: 1; }

/* ---------- flashcards ---------- */
.flash { perspective: 1200px; margin: 0 auto; max-width: 520px; }
.flash-inner {
  position: relative; min-height: 300px; transform-style: preserve-3d; transition: transform .45s cubic-bezier(.3,.7,.3,1); cursor: pointer;
}
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.flash-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 18px; border: 1px solid var(--line);
  background: var(--surface); box-shadow: var(--shadow); padding: 22px; display: flex; flex-direction: column; overflow: auto;
}
.flash-front { align-items: center; justify-content: center; text-align: center; }
.flash-front .drug { font-family: var(--serif); font-size: 2rem; font-weight: 700; color: var(--teal); }
.flash-back { transform: rotateY(180deg); gap: 8px; }
.flash-back dl { margin: 0; display: grid; gap: 8px; }
.flash-back dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.flash-back dd { margin: 0 0 4px; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; max-width: 520px; margin-inline: auto; }
.rate .btn { flex-direction: column; gap: 0; min-height: 56px; font-size: .9rem; padding: 6px; }
.rate .btn small { font-weight: 500; color: var(--muted); font-size: .72rem; }

/* ---------- tutor ---------- */
.chat { display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 92%; padding: 11px 14px; border-radius: 16px; line-height: 1.55; }
.msg p:last-child, .msg ul:last-child, .msg ol:last-child { margin-bottom: 0; }
.msg ul, .msg ol { padding-left: 1.2em; margin: 0 0 .7em; }
.msg-user { align-self: flex-end; background: var(--teal); color: #fff; border-bottom-right-radius: 6px; white-space: pre-wrap; }
:root[data-theme="dark"] .msg-user { color: #0f1717; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .msg-user { color: #0f1717; } }
.msg-ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg-ai.notice { background: var(--amber-soft); border-color: transparent; }
.msg-who { display: flex; align-items: center; gap: 8px; font-size: .78rem; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.msg-who img { width: 26px; height: 26px; border-radius: 50%; background: var(--teal-soft); object-fit: cover; }
.composer { display: flex; gap: 8px; align-items: flex-end; margin-top: 14px; position: sticky; bottom: calc(var(--tab-h) + 8px + env(safe-area-inset-bottom)); background: var(--paper); padding: 8px 0; }
@media (min-width: 960px) { .composer { bottom: 0; } }
.composer textarea { min-height: 48px; max-height: 180px; }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.suggest { display: flex; gap: 8px; flex-wrap: wrap; }
.suggest button { border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 7px 13px; cursor: pointer; font-size: .88rem; min-height: 40px; text-align: left; }
.suggest button:hover { border-color: var(--teal-2); }

/* ---------- drawer & dialog ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3);
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 40px);
}
dialog::backdrop { background: rgba(15, 23, 23, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 6px 20px; }
.dialog-head h2 { margin: 0; font-size: 1.2rem; }
.dialog-body { padding: 6px 20px 20px; overflow-y: auto; max-height: calc(100dvh - 140px); }
dialog.drawer { margin: auto 0 0 auto; height: 100dvh; max-height: 100dvh; border-radius: 18px 0 0 18px; width: min(460px, 100vw); display: none; flex-direction: column; }
dialog.drawer[open] { display: flex; }
dialog.drawer .dialog-body { flex: 1; max-height: none; display: flex; flex-direction: column; }
dialog.drawer .chat { flex: 1; overflow-y: auto; padding-bottom: 8px; }
dialog.drawer .composer { position: static; padding-bottom: env(safe-area-inset-bottom); }
@media (max-width: 640px) { dialog.drawer { width: 100vw; border-radius: 0; } }

.search-results { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 4px; }
.search-results a { display: block; padding: 10px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); }
.search-results a:hover, .search-results a:focus-visible { background: var(--sunk); }
.search-results small { display: block; color: var(--muted); }
mark { background: var(--amber-soft); color: inherit; padding: 0 2px; border-radius: 3px; }

.more-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.more-list a { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--radius-s); background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-weight: 600; }
.more-list svg { width: 22px; height: 22px; fill: none; stroke: var(--teal-2); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.more-list span small { display: block; font-weight: 400; color: var(--muted); font-size: .85rem; }

.plan-week { border-top: 1px solid var(--line); padding: 14px 0; }
.plan-week:first-child { border-top: 0; }
.plan-week h3 { margin: 0 0 6px; font-size: 1.05rem; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.plan-week.current { background: var(--teal-soft); margin: 0 -18px; padding: 14px 18px; }

.calc-q { font-size: 1.08rem; line-height: 1.65; }
.calc-answer { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.calc-answer input { max-width: 200px; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.calc-steps { margin-top: 14px; }
.calc-steps ol { padding-left: 1.2em; }
.calc-steps li { margin: 4px 0; font-variant-numeric: tabular-nums; }

.disclaimer { font-size: .82rem; color: var(--muted); border-top: 1px solid var(--line); margin-top: 40px; padding-top: 14px; }
.facts-src { font-size: .82rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
@media print {
  .topbar, .sidenav, .tabbar, .guide-actions, .toc, .q-actions, .composer { display: none !important; }
  main { margin: 0; padding: 0; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; }
}

/* small utilities used by views */
.mt { margin-top: 14px; }
h2.h3 { font-size: 1.15rem; margin: 0 0 .5em; }
.nowrap { white-space: nowrap; }
.feat-icon { flex: none; fill: none; stroke: var(--teal-2); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.drug-small { font-family: var(--serif); font-size: 1.1rem; margin: 0 0 6px; color: var(--teal); }
.row > img { flex: none; }
[tabindex="-1"]:focus:not(:focus-visible), h1[tabindex="-1"]:focus, main:focus { outline: none; }

/* question layout refinements */
.q-top { display: grid; grid-template-columns: auto 1fr auto; align-items: center; }
.q-top .q-progress { grid-column: 1 / -1; grid-row: 2; }
.q-top .timer { grid-column: 3; justify-self: end; }
@media (min-width: 640px) { .q-top { grid-template-columns: auto 1fr auto; } .q-top .q-progress { grid-column: 2; grid-row: 1; } }
.opt { grid-template-columns: 34px 1fr; }
.opt .mark { grid-column: 2; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.opt.is-right .mark { color: var(--ok); }
.opt.is-wrong .mark { color: var(--bad); }
@media (hover: none) { .strike-hint { display: none; } }
.guide-layout { grid-template-columns: minmax(0, 1fr); }
.guide-layout > * { min-width: 0; }
.toc { order: -1; }
@media (min-width: 1200px) { .guide-layout { grid-template-columns: minmax(0, 1fr) 230px; } .toc { order: 0; } }
.toc details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s); padding: 0 12px; }
.toc details[open] { padding-bottom: 10px; }
@media (min-width: 1200px) { .toc details { background: none; border: 0; padding: 0; } }
.prose { overflow-wrap: break-word; }
.stat .countdown { font-family: var(--serif); font-size: 2.6rem; font-weight: 700; color: var(--teal); line-height: 1; }
.rate [data-flip] { grid-column: 1 / -1; }

/* ---------- v4.1: lessons, embeds, cases, reference ---------- */
.grid > .card + .card { margin-top: 0; }
.lesson-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.lesson-list a { display: grid; grid-template-columns: 34px 1fr auto; gap: 12px; align-items: center; padding: 12px; border-radius: var(--radius-s); text-decoration: none; color: var(--ink); border: 1px solid var(--line); background: var(--surface); }
.lesson-list a:hover { border-color: var(--teal-2); }
.lesson-list small { display: block; color: var(--muted); font-size: .84rem; line-height: 1.4; margin-top: 2px; }
.lesson-n { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--sunk); font-weight: 750; font-size: .9rem; color: var(--ink-2); }
.lesson-list li.done .lesson-n { background: var(--ok); color: #fff; }
.reading-bar { position: sticky; top: var(--top-h); z-index: 5; height: 3px; background: transparent; margin: 0 -16px 8px; }
.reading-bar span { display: block; height: 100%; width: 0; background: var(--amber); transition: width .1s linear; }
.lesson-nav { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 18px; font-size: .92rem; }
.embed { margin: 1.2em 0; }
.check-q, .drill { border: 1.5px solid var(--teal-2); border-radius: var(--radius); background: var(--surface); padding: 14px 16px; box-shadow: var(--shadow); }
.check-q .eyebrow, .drill .eyebrow { color: var(--teal); }
.check-stem { font-weight: 600; }
.drill .calc-answer { margin-top: 8px; }
.drill-out { margin-top: 10px; }
.drill-out ol { padding-left: 1.2em; font-variant-numeric: tabular-nums; font-size: .95rem; }
details.reveal { margin: 1.1em 0; border: 1px dashed var(--line-2); border-radius: var(--radius-s); background: var(--amber-soft); }
details.reveal summary { cursor: pointer; padding: 12px 14px; font-weight: 600; list-style: none; }
details.reveal summary::-webkit-details-marker { display: none; }
details.reveal summary::after { content: " Tap to reveal ›"; color: var(--amber-ink); font-weight: 700; font-size: .85rem; }
details.reveal[open] summary::after { content: ""; }
.reveal-label { display: inline-block; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--amber-ink); margin-right: 6px; }
.reveal-body { padding: 0 14px 12px; }
.case-steps { list-style: none; padding: 0; margin: 0 0 14px; display: flex; gap: 4px; overflow-x: auto; }
.case-steps li { flex: 1 0 auto; padding: 6px 10px; border-radius: 999px; font-size: .76rem; font-weight: 650; background: var(--sunk); color: var(--muted); white-space: nowrap; }
.case-steps li.done { background: var(--teal-soft); color: var(--teal); }
.case-steps li.now { background: var(--teal); color: #fff; }
.case-chart { border-left: 4px solid var(--teal-2); }
.case-reveal { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.case-reveal.new { animation: flashin .8s ease; }
@keyframes flashin { from { background: var(--amber-soft); } to { background: transparent; } }
.step-card.live { outline: 2px solid var(--teal-2); outline-offset: -1px; }
.seg-link { padding: 8px 14px; border-radius: 9px; font-weight: 600; font-size: .92rem; text-decoration: none; color: var(--ink-2); }
.seg-link[aria-current="page"] { background: var(--surface); box-shadow: var(--shadow); color: var(--teal); }
.deck-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 10px; }
.deck-tabs .chip { text-decoration: none; padding: 6px 12px; font-size: .85rem; min-height: 34px; }
.ix-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: .92rem; }
.concept { font-family: var(--serif); font-size: 1.35rem; font-weight: 650; color: var(--teal); line-height: 1.35; }
.concept-back { font-size: 1.05rem; }
.qid { margin-left: auto; font-family: var(--mono); font-size: .72rem; }
.lab-group h2 { margin-top: 1.2em; }

/* flashcards grow with their content (large text) instead of clipping */
.flash-inner { display: grid; min-height: 280px; }
.flash-face { position: relative; inset: auto; grid-area: 1 / 1; }

/* wide tables on phones: the first column stays put, and a hint says the table scrolls */
.table-wrap { position: relative; }
.table-wrap tbody th[scope="row"], .table-wrap thead th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
.table-wrap thead th:first-child { background: var(--sunk); }
.table-wrap.scrolls::after { content: "Swipe the table →"; position: sticky; left: 0; display: block; padding: 4px 10px; font-size: .75rem; color: var(--muted); background: var(--sunk); }
@media (max-width: 640px) { th, td { min-width: 130px; } tbody th[scope="row"] { min-width: 110px; max-width: 42vw; } }

/* bigger tap targets */
.task input[type="checkbox"] { width: 26px; height: 26px; }
.task a.small { display: inline-block; padding: 4px 8px; margin-left: 2px; }

/* questions on phones: header and the main action stay in reach */
@media (max-width: 959px) {
  body.focus-mode .q-top { position: sticky; top: var(--top-h); z-index: 6; background: var(--paper); padding: 8px 0; margin: -8px 0 6px; }
  body.focus-mode .q-actions { position: sticky; bottom: 0; background: color-mix(in srgb, var(--surface) 94%, transparent); padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); margin: 12px -18px -18px; padding-left: 18px; padding-right: 18px; border-top: 1px solid var(--line); z-index: 4; }
}
.search-results .snip { margin-top: 2px; font-size: .8rem; line-height: 1.4; }
.case-steps { flex-wrap: wrap; overflow: visible; }
.case-steps li { flex: 0 1 auto; }
.prose .options { padding-left: 0; }
.prose .options li { margin: 0; }
.prose .options li::marker { content: none; }
dl.terms { margin: 0; display: grid; gap: 4px; }
dl.terms > div { padding: 10px 12px; border-radius: var(--radius-s); background: var(--surface); border: 1px solid var(--line); }
dl.terms dt { font-size: .95rem; }
dl.terms dd { margin: 2px 0 0; font-size: .88rem; color: var(--ink-2); }
nav.segmented { overflow-x: auto; max-width: 100%; flex-wrap: nowrap; }
.seg-link { white-space: nowrap; }
h1, h2, h3, .q-stem, .opt-text, .calc-q { overflow-wrap: anywhere; }
@supports (hyphens: auto) { h1, h2, h3 { hyphens: auto; } }
.step-card .case-reveal { border-top: 0; margin: 0 0 8px; padding: 10px 12px; background: var(--teal-soft); border-radius: var(--radius-s); }
.smart > div:first-child { min-width: 0; flex: 1 1 220px; }
.step-card .case-reveal { border-top: 0; margin: 0 0 8px; padding: 10px 12px; background: var(--teal-soft); border-radius: var(--radius-s); }
.smart > div:first-child { min-width: 0; flex: 1 1 220px; }
/* extra-large text: keep tables and sticky bars usable */
:root[data-text="xl"] .table-wrap table, :root[data-text="l"] .table-wrap table { font-size: .85rem; }
:root[data-text="xl"] th, :root[data-text="xl"] td { min-width: 150px; }
@media (max-width: 959px) {
  body.focus-mode .q-actions { background: var(--surface); }
  :root[data-text="xl"] body.focus-mode .q-actions .btn, :root[data-text="l"] body.focus-mode .q-actions .btn { min-height: 40px; padding: 6px 12px; font-size: .85rem; }
}

/* The exam switch stays alongside the brand on small screens. */
.exam-switch { font-size: .75rem; line-height: 1.3; margin: 0 10px; max-width: 7em; }
.topbar-actions { flex: none; }
.exam-audience { max-width: 65ch; }
@media (max-width: 420px) {
  .brand { gap: 6px; }
  .brand-sub { white-space: normal; font-size: .65rem; }
  .brand-name { font-size: .95rem; }
  .exam-switch { margin: 0 6px; }
}

/* ---------- error reports ---------- */
.report-btn { color: var(--muted); font-weight: 500; }
.report-btn svg { width: 16px; height: 16px; }
.report-btn:disabled { opacity: 1; cursor: default; background: transparent; }
.explain .row:last-child { margin-top: 10px; }
.report-line { font-size: .85rem; color: var(--muted); margin-top: 10px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.report-line.center { justify-content: center; }
.report-dialog fieldset { border: 0; margin: 0 0 14px; padding: 0; min-width: 0; }
.report-dialog legend { padding: 0; margin-bottom: 8px; }
.choice-list { display: grid; gap: 4px; }
.choice-list label { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; font-weight: 450; cursor: pointer; }
.choice-list label:hover { background: var(--sunk); }
.choice-list input { margin-top: 3px; flex: none; accent-color: var(--teal-2); }
.report-dialog textarea { width: 100%; margin-top: 6px; }
.rep-status { min-height: 1.3em; font-size: .9rem; color: var(--bad); margin: 6px 0; }
.report-icon { width: 30px; height: 30px; min-height: 0; vertical-align: middle; color: var(--muted); margin: -4px 2px -4px -6px; }
.report-icon svg { width: 16px; height: 16px; }
.report-dialog select { width: 100%; margin-top: 6px; }
