/* ============================================================
   C++ Cram — study engine
   Light default, dark toggle. System fonts only. No network.
   ============================================================ */

:root {
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --step--2: 0.75rem;
  --step--1: 0.875rem;
  --step-0: clamp(1.0625rem, 1.02rem + 0.22vw, 1.1875rem);
  --step-1: clamp(1.1875rem, 1.13rem + 0.28vw, 1.375rem);
  --step-2: clamp(1.375rem, 1.28rem + 0.44vw, 1.625rem);
  --step-3: clamp(1.625rem, 1.44rem + 0.9vw, 2.125rem);
  --step-4: clamp(2rem, 1.7rem + 1.4vw, 2.75rem);

  --lh-body: 1.7;
  --lh-code: 1.6;
  --lh-snug: 1.35;
  --lh-tight: 1.2;

  --measure: 66ch;
  --measure-code: 88ch;
  --measure-note: 52ch;

  --r-sm: 4px;
  --r-md: 7px;
  --r-lg: 11px;

  --dur: 160ms;
  --ease: cubic-bezier(0.2, 0, 0.2, 1);

  --sidebar-w: 296px;

  color-scheme: light;
  --bg: #FBFAF7;
  --surface: #FFFFFF;
  --sunken: #F2F0EA;
  --border: #DDD9CF;
  --border-strong: #C4BFB2;
  --text: #1A1917;
  --muted: #57524A;
  --faint: #756F63;
  --accent: #1B4D8F;
  --accent-bg: #EAF0F8;
  --ok: #1F6B3F;
  --ok-bg: #E8F3EC;
  --bad: #A3241F;
  --bad-bg: #FBEAE9;
  --warn: #7A5200;
  --warn-bg: #FBF2DE;
  --code-bg: #F6F4EF;
  --focus: #1B4D8F;
  --shadow: 0 6px 24px -8px rgba(26, 25, 23, 0.28);

  --t-key: #8A2A6B;
  --t-type: #1B4D8F;
  --t-str: #8A3A12;
  --t-num: #7A3E00;
  --t-com: #6B6459;
  --t-fn: #3A3F8F;
  --t-pre: #6E4B8A;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
}

:root[data-theme="dark"], html[data-theme="dark"] { color-scheme: dark; }

/* Dark palette, applied by explicit attribute (the toggle always stamps it) */
[data-theme="dark"] {
  --bg: #14161A;
  --surface: #1B1E23;
  --sunken: #23272E;
  --border: #333941;
  --border-strong: #4A515B;
  --text: #E8E6E1;
  --muted: #A9A59C;
  --faint: #8B857A;
  --accent: #8FB6E8;
  --accent-bg: #1C2733;
  --ok: #6FCF97;
  --ok-bg: #16271D;
  --bad: #F0857D;
  --bad-bg: #2C1A1A;
  --warn: #E0B15C;
  --warn-bg: #2A2314;
  --code-bg: #191C21;
  --focus: #8FB6E8;
  --shadow: 0 6px 24px -8px rgba(0, 0, 0, 0.6);

  --t-key: #E39CD0;
  --t-type: #9FC5F0;
  --t-str: #E0A87A;
  --t-num: #E8B98A;
  --t-com: #8B857A;
  --t-fn: #A9AEF5;
  --t-pre: #C6A9E4;
}

/* ---------- base ---------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--step-0);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { line-height: var(--lh-tight); font-weight: 650; margin: 0; letter-spacing: -0.011em; }
h1 { font-size: var(--step-4); }
h2 { font-size: var(--step-2); }
h3 { font-size: var(--step-1); }
h4 { font-size: var(--step-0); }
p { margin: 0 0 0.9em; }
ul, ol { margin: 0 0 1em; padding-left: 1.35em; }
li { margin-bottom: 0.35em; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }

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

button { font: inherit; color: inherit; }

code, kbd, samp, pre { font-family: var(--mono); font-size: 0.895em; }

p code, li code, td code, dd code, .q-text code, summary code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 0.08em 0.34em;
  white-space: nowrap;
}

hr { border: 0; border-top: 1px solid var(--border); margin: 2rem 0; }

.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;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 200;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  padding: 0.6rem 1rem; transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: 8px; }

/* ---------- layout ---------- */

.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  grid-column: 1;
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
}

.main { grid-column: 2; min-width: 0; }

/* Mobile nav backdrop. Must stay out of grid flow, or it claims a cell
   and pushes .main down by a whole row. */
.scrim { display: none; }

.wrap { max-width: calc(var(--measure) + 6rem); margin: 0 auto; padding: 2.4rem 3rem 6rem; }
.wrap-wide { max-width: 78rem; margin: 0 auto; padding: 2.4rem 3rem 6rem; }

/* ---------- sidebar ---------- */

.side-head {
  padding: 1rem 1.1rem 0.85rem;
  border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 0.7rem;
}

.brand {
  display: flex; align-items: baseline; gap: 0.5rem;
  font-weight: 680; font-size: var(--step--1); letter-spacing: 0.01em;
  background: none; border: 0; padding: 0; cursor: pointer; text-align: left;
}
.brand span { color: var(--faint); font-weight: 500; }

.side-actions { display: flex; gap: 0.4rem; }

.search-field { position: relative; }
.search-field input {
  width: 100%; font: inherit; font-size: var(--step--1);
  padding: 0.44rem 2.6rem 0.44rem 0.6rem;
  background: var(--sunken); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-md);
}
.search-field input::placeholder { color: var(--faint); }
.kbd-badge {
  position: absolute; right: 0.4rem; top: 50%; transform: translateY(-50%);
  font-family: var(--mono); font-size: 0.7rem; color: var(--faint);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 0.05rem 0.3rem; pointer-events: none; background: var(--surface);
}

.nav { overflow-y: auto; flex: 1; padding: 0.5rem 0 2rem; }

.nav-group { border-bottom: 1px solid var(--border); }
.nav-group > summary {
  list-style: none; cursor: pointer;
  padding: 0.6rem 1.1rem; display: flex; align-items: center; gap: 0.55rem;
  font-size: var(--step--1); font-weight: 620;
}
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary:hover { background: var(--sunken); }
.nav-chev { color: var(--faint); flex: none; transition: transform var(--dur) var(--ease); }
.nav-group[open] .nav-chev { transform: rotate(90deg); }
.nav-ch-num {
  font-family: var(--mono); font-size: 0.72rem; color: var(--faint);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 0.02rem 0.3rem; flex: none;
}
.nav-ch-title { flex: 1; min-width: 0; }
.nav-ch-count { font-family: var(--mono); font-size: 0.72rem; color: var(--faint); flex: none; }

.nav-list { list-style: none; margin: 0; padding: 0 0 0.4rem; }
.nav-item {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  background: none; border: 0; cursor: pointer; text-align: left;
  padding: 0.34rem 1.1rem 0.34rem 1.9rem;
  font-size: var(--step--1); line-height: var(--lh-snug); color: var(--muted);
  border-left: 2px solid transparent;
}
.nav-item:hover { background: var(--sunken); color: var(--text); }
.nav-item[aria-current="true"] {
  background: var(--accent-bg); color: var(--text);
  border-left-color: var(--accent); font-weight: 600;
}
.nav-item-label { flex: 1; min-width: 0; }
.nav-tier {
  font-family: var(--mono); font-size: 0.66rem; letter-spacing: 0.03em;
  color: var(--faint); flex: none; text-transform: uppercase;
}

/* progress dot — shape differs per state, never colour alone */
.dot { flex: none; width: 13px; height: 13px; }
.dot circle, .dot path, .dot rect { vector-effect: non-scaling-stroke; }
.dot-none { color: var(--border-strong); }
.dot-shaky { color: var(--warn); }
.dot-learned { color: var(--ok); }

.side-foot {
  border-top: 1px solid var(--border);
  padding: 0.6rem 1.1rem;
  display: flex; gap: 0.4rem; align-items: center;
  font-size: var(--step--2); color: var(--faint);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  font-size: var(--step--1); font-weight: 560; line-height: 1.2;
  padding: 0.52rem 0.85rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  cursor: pointer; transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--sunken); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
[data-theme="dark"] .btn-primary { color: #10141A; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn-sm { font-size: var(--step--2); padding: 0.34rem 0.6rem; }
.btn-icon { padding: 0.42rem; }
.btn-ghost { border-color: transparent; background: none; }
.btn-ghost:hover:not(:disabled) { background: var(--sunken); }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; }

/* ---------- topbar (mobile) ---------- */

.topbar { display: none; }

/* ---------- home ---------- */

.hero { border-bottom: 1px solid var(--border); padding-bottom: 2rem; margin-bottom: 2rem; }
.kicker {
  font-size: var(--step--2); text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--faint); font-weight: 640; margin-bottom: 0.7rem;
}
.standfirst {
  font-family: var(--serif); font-size: var(--step-1); line-height: 1.55;
  color: var(--muted); max-width: var(--measure); margin: 1rem 0 1.4rem;
}

.stat-row {
  display: flex; flex-wrap: wrap; gap: 0 2.2rem;
  border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1.4rem;
}
.stat { display: flex; flex-direction: column; }
.stat-n { font-size: var(--step-2); font-weight: 660; font-variant-numeric: tabular-nums; }
.stat-l { font-size: var(--step--2); color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em; }

.plan { border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; margin: 1.6rem 0 2rem; }
.plan-row {
  display: grid; grid-template-columns: 5.5rem 1fr auto; gap: 1rem;
  align-items: center; padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.plan-row:last-child { border-bottom: 0; }
.plan-row.is-break { background: var(--sunken); }
.plan-time { font-family: var(--mono); font-size: var(--step--2); color: var(--faint); font-variant-numeric: tabular-nums; }
.plan-what { font-size: var(--step--1); }
.plan-what b { font-weight: 620; }
.plan-what small { display: block; color: var(--faint); font-size: var(--step--2); line-height: 1.4; }

.bar-track { height: 6px; background: var(--sunken); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); }
.bar-fill.is-ok { background: var(--ok); }
.bar-fill.is-warn { background: var(--warn); }
.bar-fill.is-bad { background: var(--bad); }

/* ---------- lesson ---------- */

.lesson-head { border-bottom: 1px solid var(--border); padding-bottom: 1.5rem; margin-bottom: 1.8rem; }
.crumb { font-size: var(--step--2); color: var(--faint); margin-bottom: 0.6rem; }
.crumb b { color: var(--muted); font-weight: 560; }

.meta-row {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
  margin-top: 1rem; font-size: var(--step--2);
}
.chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  border: 1px solid var(--border); border-radius: 99px;
  padding: 0.17rem 0.6rem; color: var(--muted); background: var(--surface);
  font-size: var(--step--2); white-space: nowrap;
}
.chip-must { border-color: var(--accent); color: var(--accent); font-weight: 620; }
.chip-should { color: var(--muted); }
.chip-nice { color: var(--faint); }
.chip-src { font-family: var(--mono); }

.prose { max-width: var(--measure); }
.prose p { font-family: var(--serif); font-size: 1.03em; }
.prose > h2 {
  font-size: var(--step-1); margin: 2.4rem 0 0.9rem;
  padding-top: 1.4rem; border-top: 1px solid var(--border);
}
.prose > h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.prose > h3 { font-size: var(--step-0); font-weight: 660; margin: 1.7rem 0 0.6rem; }

.lede { font-family: var(--serif); font-size: var(--step-1); line-height: 1.55; color: var(--muted); }

/* ---------- code ---------- */

.code {
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--code-bg); overflow: hidden;
  margin: 1.1rem 0; max-width: var(--measure-code);
}
.code-head {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.4rem 0.7rem; border-bottom: 1px solid var(--border);
  background: var(--surface); font-size: var(--step--2);
}
.code-name { font-family: var(--mono); color: var(--muted); flex: 1; min-width: 0; }
.code-origin {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--faint); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 0.02rem 0.3rem; flex: none;
}
.code-body { overflow-x: auto; }
.code pre { margin: 0; padding: 0.75rem 0; line-height: var(--lh-code); }
.code-line { display: block; padding: 0 0.85rem 0 0; white-space: pre; }
.code-line::before {
  content: attr(data-n);
  display: inline-block; width: 2.6rem; padding-right: 0.9rem;
  text-align: right; color: var(--faint); user-select: none;
  font-variant-numeric: tabular-nums;
}
.code-line.is-hot { background: var(--accent-bg); }
.code-line.is-noted::after {
  content: attr(data-mark); color: var(--accent); font-weight: 700; padding-left: 0.6rem;
}

.code-out {
  border-top: 1px dashed var(--border-strong); background: var(--surface);
  padding: 0.55rem 0.85rem 0.7rem;
}
.code-out-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--faint); margin-bottom: 0.25rem;
}
.code-out pre { margin: 0; padding: 0; white-space: pre-wrap; color: var(--text); }

.annos { list-style: none; margin: 0.6rem 0 1.4rem; padding: 0; max-width: var(--measure); }
.annos li {
  display: grid; grid-template-columns: 1.9rem 1fr; gap: 0.5rem;
  font-size: var(--step--1); color: var(--muted); margin-bottom: 0.4rem;
  line-height: var(--lh-snug);
}
.anno-mark { font-family: var(--mono); color: var(--accent); font-weight: 700; }

/* syntax tokens */
.tk { color: var(--t-key); font-weight: 600; }
.tt { color: var(--t-type); }
.ts { color: var(--t-str); }
.tn { color: var(--t-num); }
.tc { color: var(--t-com); font-style: italic; }
.tf { color: var(--t-fn); }
.tp { color: var(--t-pre); }

/* ---------- callouts ---------- */

.note {
  border: 1px solid var(--border); border-left: 3px solid var(--border-strong);
  border-radius: var(--r-md); background: var(--surface);
  padding: 0.8rem 1rem; margin: 1.3rem 0; max-width: var(--measure);
  font-size: var(--step--1);
}
.note-title {
  font-weight: 640; font-size: var(--step--2); text-transform: uppercase;
  letter-spacing: 0.06em; margin-bottom: 0.4rem; color: var(--muted);
}
.note p:last-child, .note ul:last-child { margin-bottom: 0; }
.note-warn { border-left-color: var(--warn); background: var(--warn-bg); }
.note-warn .note-title { color: var(--warn); }
.note-exam { border-left-color: var(--accent); background: var(--accent-bg); }
.note-exam .note-title { color: var(--accent); }
.note-flag { border-left-color: var(--bad); background: var(--bad-bg); }
.note-flag .note-title { color: var(--bad); }

.gotchas { list-style: none; margin: 0; padding: 0; }
.gotchas li { display: grid; grid-template-columns: 1.2rem 1fr; gap: 0.4rem; margin-bottom: 0.55rem; }
.gotchas li:last-child { margin-bottom: 0; }
.gotcha-x { color: var(--warn); font-weight: 700; }

.terms { margin: 0; }
.terms div { display: grid; grid-template-columns: minmax(7rem, 12rem) 1fr; gap: 0.4rem 1rem; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.terms div:last-child { border-bottom: 0; }
.terms dt { font-weight: 620; }
.terms dd { margin: 0; color: var(--muted); }

details.deeper {
  border: 1px solid var(--border); border-radius: var(--r-md);
  margin: 1.5rem 0; max-width: var(--measure); background: var(--surface);
}
details.deeper > summary {
  cursor: pointer; padding: 0.65rem 0.9rem; font-size: var(--step--1);
  font-weight: 600; list-style: none; display: flex; align-items: center; gap: 0.5rem;
}
details.deeper > summary::-webkit-details-marker { display: none; }
details.deeper > summary::before { content: "+"; font-family: var(--mono); color: var(--faint); }
details.deeper[open] > summary::before { content: "-"; }
details.deeper > div { padding: 0 0.9rem 0.9rem; }

/* ---------- trace ---------- */

.trace { border: 1px solid var(--border); border-radius: var(--r-md); margin: 1.4rem 0; max-width: var(--measure-code); background: var(--surface); }
.trace-head { padding: 0.6rem 0.9rem; border-bottom: 1px solid var(--border); font-size: var(--step--1); font-weight: 620; }
.trace-body { padding: 0.9rem; }
.trace-gate { text-align: left; }
.trace-gate label { display: block; font-size: var(--step--1); margin-bottom: 0.5rem; }
.trace-gate input {
  font-family: var(--mono); font-size: var(--step--1); width: 100%;
  padding: 0.5rem 0.6rem; background: var(--code-bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md); margin-bottom: 0.6rem;
}
.trace-steps { display: grid; grid-template-columns: 1fr; gap: 0.9rem; }
@media (min-width: 900px) { .trace-steps { grid-template-columns: 1fr minmax(13rem, 18rem); } }
.watch { border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; align-self: start; }
.watch-h { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--border); background: var(--sunken); }
.watch table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: var(--step--2); }
.watch td { padding: 0.24rem 0.6rem; border-bottom: 1px solid var(--border); }
.watch tr:last-child td { border-bottom: 0; }
.watch td:first-child { color: var(--muted); }
.watch td:last-child { text-align: right; font-weight: 600; }
.watch-out { padding: 0.4rem 0.6rem; border-top: 1px solid var(--border); background: var(--code-bg); }
.watch-out pre { margin: 0; font-size: var(--step--2); white-space: pre-wrap; min-height: 1.4em; }
.trace-note { font-size: var(--step--1); color: var(--muted); margin-top: 0.6rem; max-width: var(--measure-note); }
.trace-ctl { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.8rem; }
.trace-pos { font-family: var(--mono); font-size: var(--step--2); color: var(--faint); font-variant-numeric: tabular-nums; }

/* ---------- questions ---------- */

.q {
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); margin: 1.1rem 0; overflow: hidden;
  max-width: var(--measure-code);
}
.q-head {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.5rem 0.9rem; border-bottom: 1px solid var(--border);
  font-size: var(--step--2); color: var(--faint);
}
.q-kind { font-weight: 640; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.q-src { font-family: var(--mono); margin-left: auto; }
.q-body { padding: 0.9rem; }
.q-text { font-size: var(--step-0); margin-bottom: 0.8rem; max-width: var(--measure); }
.q-text p:last-child { margin-bottom: 0; }

.opts { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.45rem; }
.opt {
  display: grid; grid-template-columns: 1.6rem 1fr; gap: 0.5rem; align-items: start;
  width: 100%; text-align: left; cursor: pointer;
  padding: 0.6rem 0.75rem; font-size: var(--step--1); line-height: var(--lh-snug);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-md);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.opt:hover:not(:disabled) { background: var(--sunken); border-color: var(--border-strong); }
.opt-key {
  font-family: var(--mono); font-size: var(--step--2); font-weight: 700;
  color: var(--faint); border: 1px solid var(--border); border-radius: var(--r-sm);
  width: 1.5rem; height: 1.5rem; display: grid; place-items: center;
}
.opt[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-bg); }
.opt[aria-pressed="true"] .opt-key { border-color: var(--accent); color: var(--accent); }
.opt.is-right { border: 2px solid var(--ok); background: var(--ok-bg); }
.opt.is-right .opt-key { border-color: var(--ok); color: var(--ok); }
.opt.is-wrong { border: 2px dashed var(--bad); background: var(--bad-bg); }
.opt.is-wrong .opt-key { border-color: var(--bad); color: var(--bad); }
.opt.is-dim { opacity: 0.4; }
.opt-mark { font-weight: 700; margin-left: auto; padding-left: 0.5rem; }
.opt.is-right .opt-mark { color: var(--ok); }
.opt.is-wrong .opt-mark { color: var(--bad); }

.answer-field {
  font-family: var(--mono); font-size: var(--step--1); width: 100%;
  padding: 0.55rem 0.65rem; background: var(--code-bg); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  resize: vertical; line-height: var(--lh-code);
}
textarea.answer-field { min-height: 6.5rem; }

.q-foot {
  display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center;
  padding: 0.7rem 0.9rem; border-top: 1px solid var(--border); background: var(--sunken);
}
.q-status { font-size: var(--step--2); font-weight: 620; }
.q-status.is-right { color: var(--ok); }
.q-status.is-wrong { color: var(--bad); }
.q-spacer { margin-left: auto; }

.reveal { border-top: 1px solid var(--border); padding: 0.9rem; background: var(--surface); }
.reveal-h {
  font-size: var(--step--2); text-transform: uppercase; letter-spacing: 0.06em;
  font-weight: 640; color: var(--muted); margin-bottom: 0.45rem;
}
.reveal p { font-size: var(--step--1); max-width: var(--measure); }
.reveal p:last-child { margin-bottom: 0; }
.checklist { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.checklist li { display: grid; grid-template-columns: 1.3rem 1fr; gap: 0.4rem; font-size: var(--step--1); margin-bottom: 0.35rem; }
.checklist .tick { color: var(--ok); font-weight: 700; }

.hint-tray {
  border-left: 3px solid var(--warn); background: var(--warn-bg);
  border-radius: var(--r-sm); padding: 0.6rem 0.8rem; margin-top: 0.8rem;
  font-size: var(--step--1); max-width: var(--measure);
}
.hint-tray .reveal-h { color: var(--warn); }

/* ---------- flashcards ---------- */

.card-stage { max-width: 46rem; margin: 0 auto; }
.flash {
  border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  background: var(--surface); min-height: 15rem;
  display: grid; place-items: center; padding: 2.4rem 1.6rem; text-align: center;
  cursor: pointer; position: relative;
}
.flash-side { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--faint); position: absolute; top: 0.7rem; left: 0.9rem; }
.flash-src { font-family: var(--mono); font-size: var(--step--2); color: var(--faint); position: absolute; top: 0.7rem; right: 0.9rem; }
.flash-text { font-size: var(--step-1); line-height: 1.45; max-width: 34rem; }
.flash-hintline { position: absolute; bottom: 0.8rem; left: 0; right: 0; font-size: var(--step--2); color: var(--faint); }
.deck-bar { display: flex; align-items: center; gap: 0.9rem; margin-bottom: 1rem; font-size: var(--step--1); }
.deck-count { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--muted); }
.deck-known { color: var(--ok); font-weight: 620; }

/* ---------- test ---------- */

.test-chrome {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0.6rem 1rem; display: flex; align-items: center; gap: 1rem;
}
.timer { font-family: var(--mono); font-size: var(--step-1); font-weight: 650; font-variant-numeric: tabular-nums; }
.timer.is-low { color: var(--bad); }
.test-pos { font-size: var(--step--1); color: var(--muted); font-variant-numeric: tabular-nums; }
.test-progress { flex: 1; max-width: 22rem; }

.grid-nav { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 1rem 0; }
.gnav {
  width: 2.1rem; height: 2.1rem; display: grid; place-items: center;
  font-family: var(--mono); font-size: var(--step--2); cursor: pointer;
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--r-sm);
}
.gnav.is-done { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.gnav.is-flag { border-color: var(--warn); border-style: dashed; color: var(--warn); }
.gnav[aria-current="true"] { outline: 2px solid var(--focus); outline-offset: 1px; }

.score-big { font-size: clamp(3rem, 2rem + 5vw, 5rem); font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.score-sub { color: var(--muted); font-size: var(--step-1); }

.break-row { display: grid; grid-template-columns: 1fr; gap: 0.35rem; padding: 0.8rem 0; border-bottom: 1px solid var(--border); }
.break-top { display: flex; align-items: baseline; gap: 0.7rem; }
.break-name { font-weight: 620; font-size: var(--step--1); flex: 1; }
.break-pct { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: var(--step--1); }
.break-acts { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.3rem; }

/* ---------- search results ---------- */

.results { list-style: none; margin: 0; padding: 0; max-width: var(--measure-code); }
.res {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: none; border: 0; border-bottom: 1px solid var(--border);
  padding: 0.75rem 0.4rem;
}
.res:hover { background: var(--sunken); }
.res-title { font-weight: 620; font-size: var(--step--1); }
.res-path { font-size: var(--step--2); color: var(--faint); margin-top: 0.1rem; }
.res-snip { font-size: var(--step--2); color: var(--muted); margin-top: 0.25rem; line-height: 1.45; }
.res mark { background: var(--warn-bg); color: var(--text); border-radius: 2px; padding: 0 2px; }

.empty { color: var(--muted); padding: 2rem 0; max-width: var(--measure); }

/* ---------- palette ---------- */

.palette-back {
  position: fixed; inset: 0; background: rgba(16, 16, 16, 0.34);
  display: grid; place-items: start center; padding-top: 12vh; z-index: 100;
}
.palette {
  width: min(38rem, calc(100vw - 2rem)); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  box-shadow: var(--shadow); overflow: hidden;
}
.palette input {
  width: 100%; font: inherit; font-size: var(--step-0); padding: 0.85rem 1rem;
  background: none; color: var(--text); border: 0; border-bottom: 1px solid var(--border);
}
.palette-list { list-style: none; margin: 0; padding: 0.3rem; max-height: 22rem; overflow-y: auto; }
.palette-item {
  display: flex; align-items: center; gap: 0.6rem; width: 100%; text-align: left;
  padding: 0.5rem 0.7rem; background: none; border: 0; border-radius: var(--r-md);
  cursor: pointer; font-size: var(--step--1);
}
.palette-item:hover, .palette-item.is-sel { background: var(--accent-bg); }
.palette-item .p-sub { color: var(--faint); font-size: var(--step--2); margin-left: auto; font-family: var(--mono); }
.palette-foot {
  border-top: 1px solid var(--border); padding: 0.45rem 0.8rem; background: var(--sunken);
  font-size: var(--step--2); color: var(--faint); display: flex; gap: 1rem; flex-wrap: wrap;
}
.palette-foot kbd {
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  padding: 0.02rem 0.28rem; background: var(--surface); font-size: 0.72rem;
}

/* ---------- cheat sheet ---------- */

.cheat-group { margin-bottom: 1.6rem; break-inside: avoid; }
.cheat-h {
  font-size: var(--step--1); font-weight: 660; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted);
  border-bottom: 1px solid var(--border-strong); padding-bottom: 0.25rem; margin-bottom: 0.4rem;
}
.cheat-row {
  display: grid; grid-template-columns: minmax(9rem, 15rem) 1fr;
  gap: 0.3rem 1rem; padding: 0.28rem 0; border-bottom: 1px solid var(--border);
  font-size: var(--step--1); line-height: var(--lh-snug); break-inside: avoid;
}
.cheat-k { font-weight: 600; }
.cheat-v { color: var(--muted); }
.cheat-cols { columns: 1; }
@media (min-width: 1100px) { .cheat-cols { columns: 2; column-gap: 2.6rem; } }

/* ---------- prev/next ---------- */

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; margin-top: 3rem; border-top: 1px solid var(--border); padding-top: 1.4rem; }
.pager-btn {
  display: block; text-align: left; cursor: pointer; padding: 0.8rem 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
}
.pager-btn:hover { background: var(--sunken); border-color: var(--border-strong); }
.pager-btn.is-next { text-align: right; }
.pager-l { font-size: var(--step--2); color: var(--faint); }
.pager-t { font-size: var(--step--1); font-weight: 620; margin-top: 0.15rem; }
.pager-btn:disabled { opacity: 0.35; cursor: default; }

/* ---------- status setter ---------- */

.status-set { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.status-set .btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); font-weight: 640; }

/* ---------- responsive ---------- */

@media (max-width: 950px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(88vw, var(--sidebar-w));
    z-index: 90; transform: translateX(-101%);
    transition: transform var(--dur) var(--ease); box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(16,16,16,0.34); z-index: 80; }
  .main { grid-column: 1; }
  .topbar {
    display: flex; align-items: center; gap: 0.6rem;
    position: sticky; top: 0; z-index: 40;
    padding: 0.5rem 0.8rem; background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .topbar-title { font-size: var(--step--1); font-weight: 620; flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .wrap, .wrap-wide { padding: 1.4rem 1.1rem 5rem; }
  .pager { grid-template-columns: 1fr; }
  .terms div { grid-template-columns: 1fr; gap: 0.1rem; }
  .plan-row { grid-template-columns: 4.6rem 1fr; }
  .plan-row > :last-child { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ---------- print (cheat sheet) ---------- */

@media print {
  @page { size: A4 portrait; margin: 12mm 11mm; }
  :root { --step-0: 9.6pt; --step--1: 8.7pt; --step--2: 7.6pt; --lh-body: 1.4; --lh-snug: 1.28; }
  html, body { background: #fff !important; color: #000 !important; }
  .sidebar, .topbar, .pager, .no-print, .btn, .scrim, .palette-back { display: none !important; }
  .app { display: block; }
  .wrap, .wrap-wide { max-width: none; padding: 0; margin: 0; }
  .cheat-cols { columns: 2; column-gap: 8mm; }
  .cheat-group { break-inside: avoid; margin-bottom: 4mm; }
  .cheat-h { border-bottom: 0.6pt solid #000; color: #000; margin-bottom: 1mm; padding-bottom: 0.6mm; }
  .cheat-row { border-bottom: 0.3pt solid #bbb; padding: 0.7mm 0; grid-template-columns: 34mm 1fr; }
  .cheat-v { color: #222; }
  code, pre { font-size: 8.2pt; }
  p code, li code, td code { background: #f2f2f2 !important; border: 0.3pt solid #ccc; }
  h1 { font-size: 15pt; margin-bottom: 1mm; }
  a { color: #000; text-decoration: none; }
  .print-head { display: block !important; border-bottom: 1pt solid #000; padding-bottom: 2mm; margin-bottom: 4mm; }
}

.print-head { display: none; }
