/* ============================================================
   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;

  /* Warm stone neutrals. Near-monochrome on purpose: one accent, used only for
     "where you are" and for links, so it always means something. */
  --bg: #FAFAF9;
  --surface: #FFFFFF;
  --sunken: #F5F5F4;
  --border: #E7E5E4;
  --border-strong: #D6D3D1;
  --text: #1C1917;
  --muted: #57534E;
  --faint: #79716B;
  --accent: #C2410C;
  --accent-bg: #FFF7ED;
  --accent-line: #FDBA74;
  /* Primary actions are ink, not accent — a page can have many links but only
     one thing you are meant to press. */
  --ink: #1C1917;
  --ink-fg: #FAFAF9;
  --ok: #15803D;
  --ok-bg: #F0FDF4;
  --bad: #B91C1C;
  --bad-bg: #FEF2F2;
  --warn: #A16207;
  --warn-bg: #FEFCE8;
  --focus: #C2410C;
  --shadow: 0 1px 2px rgba(28, 25, 23, 0.05), 0 8px 28px -12px rgba(28, 25, 23, 0.22);
  --shadow-sm: 0 1px 2px rgba(28, 25, 23, 0.06);
}

/* Code is dark in both themes — it is the one surface that stays constant, and
   it anchors an otherwise very light page. Print flips it back to paper. */
:root {
  --code-bg: #1C1B1A;
  --code-fg: #E7E5E4;
  --code-face: #292524;
  --code-border: #292524;
  --code-gutter: #78716C;

  --t-key: #F0ABFC;
  --t-type: #7DD3FC;
  --t-str: #FCD34D;
  --t-num: #FDBA74;
  --t-com: #8A8279;
  --t-fn: #A5B4FC;
  --t-pre: #C4B5FD;
}

@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: #0C0A09;
  --surface: #171614;
  --sunken: #1F1D1B;
  --border: #292524;
  --border-strong: #44403C;
  --text: #F5F5F4;
  --muted: #A8A29E;
  --faint: #857F79;
  --accent: #FB923C;
  --accent-bg: #241610;
  --accent-line: #9A3412;
  --ink: #F5F5F4;
  --ink-fg: #171614;
  --ok: #4ADE80;
  --ok-bg: #0F1F14;
  --bad: #F87171;
  --bad-bg: #241413;
  --warn: #FACC15;
  --warn-bg: #221D0C;
  --focus: #FB923C;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 28px -12px rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);

  --code-bg: #131211;
  --code-face: #1F1D1B;
  --code-border: #292524;
}

/* ---------- 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; }

/* Inline code stays on the page's own surface — only whole blocks go dark, or
   a paragraph turns into a row of black bricks. */
p code, li code, td code, dd code, .q-text code, summary code,
.lab-brief code, .lab-spec code, .stage-lede code, .goals code, .reveal code {
  background: var(--sunken);
  color: var(--accent);
  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; }

/* Dense, single-line rows. A chapter title that wraps onto three lines turns the
   sidebar into a wall of text, so titles truncate and the full one is the title
   attribute. */
.nav-group { border: 0; margin: 0 0.5rem; }
.nav-group > summary {
  list-style: none; cursor: pointer; border-radius: var(--r-md);
  padding: 0.36rem 0.5rem; display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.83rem; font-weight: 600; color: var(--text);
}
.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.68rem; color: var(--faint);
  background: var(--sunken); border-radius: var(--r-sm);
  padding: 0.08rem 0.32rem; flex: none; letter-spacing: -0.01em;
}
.nav-ch-title {
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-ch-count {
  font-family: var(--mono); font-size: 0.68rem; color: var(--faint); flex: none;
  font-variant-numeric: tabular-nums;
}

.nav-list { list-style: none; margin: 0 0 0.25rem; padding: 0; }
.nav-item {
  display: flex; align-items: center; gap: 0.45rem; width: 100%;
  background: none; border: 0; cursor: pointer; text-align: left;
  border-radius: var(--r-md);
  padding: 0.28rem 0.5rem 0.28rem 1.55rem;
  font-size: 0.83rem; line-height: 1.35; color: var(--muted);
  position: relative;
}
/* The thread down the left tells you these belong to the chapter above. */
.nav-list::before {
  content: ''; position: absolute; left: 1.15rem; width: 1px;
  background: var(--border); top: 0; bottom: 0;
}
.nav-list { position: relative; }
.nav-item:hover { background: var(--sunken); color: var(--text); }
.nav-item[aria-current="true"] {
  background: var(--accent-bg); color: var(--accent); font-weight: 600;
}
.nav-item[aria-current="true"]::before {
  content: ''; position: absolute; left: 1.15rem; top: 0.3rem; bottom: 0.3rem;
  width: 2px; background: var(--accent); border-radius: 2px;
}
.nav-item-label {
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-tier {
  font-family: var(--mono); font-size: 0.62rem; 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: 550; line-height: 1.2;
  padding: 0.5rem 0.85rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--sunken); border-color: var(--faint); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
/* Ink, not accent. Accent means "you are here"; ink means "press this". */
.btn-primary {
  background: var(--ink); color: var(--ink-fg); border-color: var(--ink); font-weight: 580;
}
.btn-primary:hover:not(:disabled) { background: var(--ink); border-color: var(--ink); filter: brightness(1.35); }
[data-theme="dark"] .btn-primary:hover:not(:disabled) { filter: brightness(0.9); }
.btn-sm { font-size: var(--step--2); padding: 0.32rem 0.6rem; }
.btn-icon { padding: 0.42rem; }
.btn-ghost { border-color: transparent; background: none; box-shadow: none; }
.btn-ghost:hover:not(:disabled) { background: var(--sunken); border-color: transparent; }

.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(--code-border); border-radius: var(--r-lg);
  background: var(--code-bg); color: var(--code-fg); overflow: hidden;
  margin: 1.1rem 0; max-width: var(--measure-code);
  box-shadow: var(--shadow-sm);
}
.code-head {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.45rem 0.85rem; border-bottom: 1px solid var(--code-border);
  background: var(--code-face); font-size: var(--step--2);
}
.code-name { font-family: var(--mono); color: #A8A29E; flex: 1; min-width: 0; }
.code-origin {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: #A8A29E; border: 1px solid #44403C; border-radius: var(--r-sm);
  padding: 0.02rem 0.3rem; flex: none;
}
.code-body { overflow-x: auto; }
.code pre { margin: 0; padding: 0.8rem 0; line-height: var(--lh-code); }
.code-line { display: block; padding: 0 0.9rem 0 0; white-space: pre; }
.code-line::before {
  content: attr(data-n);
  display: inline-block; width: 2.7rem; padding-right: 0.95rem;
  text-align: right; color: var(--code-gutter); user-select: none;
  font-variant-numeric: tabular-nums;
}
.code-line.is-hot { background: rgba(251, 146, 60, 0.14); box-shadow: inset 2px 0 0 var(--accent); }
.code-line.is-noted::after {
  content: attr(data-mark); color: #FDBA74; font-weight: 700; padding-left: 0.6rem;
}

.code-out {
  border-top: 1px solid var(--code-border); background: var(--code-face);
  padding: 0.55rem 0.9rem 0.7rem;
}
.code-out-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: #A8A29E; margin-bottom: 0.25rem;
}
.code-out pre { margin: 0; padding: 0; white-space: pre-wrap; color: #E7E5E4; }

.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) ---------- */

/* ============================================================
   Teaching platform additions
   Parts nav · staged lessons · checkpoints · dashboard ·
   challenge mode · AI tutor panel
   ============================================================ */

/* bar-fill: accept both the old is-* and the plain modifier names */
.bar-fill.ok { background: var(--ok); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.bad { background: var(--bad); }

/* ---------- sidebar: parts ---------- */

.nav-part { margin-bottom: 0.9rem; }
.nav-part-h {
  display: flex; align-items: baseline; gap: 0.45rem;
  padding: 0.7rem 0.9rem 0.35rem;
  font-size: var(--step--2);
}
.nav-part-n {
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 680;
  color: var(--accent);
}
.nav-part-t { color: var(--muted); font-weight: 560; }
.nav-part-c {
  margin-left: auto; color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.nav-tier-cp { color: var(--accent); border-color: currentColor; }

/* ---------- crumbs ---------- */

.crumb-b {
  background: none; border: 0; padding: 0; margin: 0;
  font: inherit; color: var(--muted); cursor: pointer;
  border-bottom: 1px solid transparent;
}
.crumb-b:hover { color: var(--accent); border-bottom-color: currentColor; }

/* ---------- lesson stage rail ---------- */

.stage-rail {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  margin: -0.4rem 0 2rem;
  padding-bottom: 1rem; border-bottom: 1px solid var(--border);
}
.stage-pill {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font: inherit; font-size: var(--step--2); font-weight: 560;
  padding: 0.36rem 0.65rem;
  border: 1px solid var(--border); border-radius: 99px;
  background: var(--surface); color: var(--muted); cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.stage-pill:hover { background: var(--sunken); color: var(--text); }
.stage-n {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.05rem; height: 1.05rem; border-radius: 99px;
  background: var(--sunken); color: var(--faint);
  font-size: 0.68rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.stage-pill:hover .stage-n { background: var(--accent); color: var(--surface); }
.stage-ask { border-color: var(--accent); color: var(--accent); }
.stage-ask:hover { background: var(--accent-bg); color: var(--accent); }

/* ---------- lesson stages ---------- */

.stage { margin: 0 0 2.6rem; scroll-margin-top: 4.5rem; }
.stage-h {
  display: flex; align-items: baseline; gap: 0.7rem;
  margin: 0 0 0.9rem; padding-bottom: 0.45rem;
  border-bottom: 1px solid var(--border);
}
.stage-k {
  font-family: var(--sans); font-size: var(--step-1); font-weight: 650;
  letter-spacing: -0.008em;
}
.stage-count { font-size: var(--step--2); color: var(--faint); margin-left: auto; }
.stage-lede {
  max-width: var(--measure); color: var(--muted);
  font-size: var(--step--1); margin: 0 0 1.1rem;
}
.stage-sub {
  font-family: var(--sans); font-size: var(--step-0); font-weight: 620;
  margin: 1.8rem 0 0.7rem; color: var(--text);
}

.stage-goals { background: var(--accent-bg); border-radius: var(--r-lg); padding: 1.2rem 1.3rem; }
.stage-goals .stage-h { border-bottom-color: rgba(0, 0, 0, 0.09); }
.stage-goals .stage-lede { margin-bottom: 0.7rem; }
.goals { list-style: none; margin: 0; padding: 0; max-width: var(--measure); }
.goals li {
  display: flex; gap: 0.6rem; align-items: flex-start;
  padding: 0.3rem 0; font-size: var(--step--1); line-height: var(--lh-snug);
}
.goal-tick { color: var(--accent); flex: none; line-height: 1.4; }

.stage-check { border-left: 3px solid var(--accent); padding-left: 1.1rem; }
.stage-cp { border-left: 3px solid var(--warn); padding-left: 1.1rem; }

/* ---------- ask the tutor row ---------- */

.ask-row {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  margin-top: 1.4rem; padding-top: 0.9rem;
  border-top: 1px dashed var(--border);
}
.btn-ask { border-color: var(--accent); color: var(--accent); }
.btn-ask:hover:not(:disabled) { background: var(--accent-bg); }

/* ---------- checkpoint score ---------- */

.cp-score { margin: 0 0 1.4rem; }
.cp-bar { display: grid; grid-template-columns: auto 1fr; gap: 0.8rem; align-items: center; }
.cp-nums { font-size: var(--step--1); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cp-nums b { font-size: var(--step-1); font-weight: 680; }
.cp-verdict {
  margin-top: 0.9rem; padding: 0.9rem 1rem;
  border-radius: var(--r-md); font-size: var(--step--1); line-height: var(--lh-snug);
}
.cp-pass { background: var(--ok-bg); border: 1px solid var(--ok); color: var(--text); }
.cp-fail { background: var(--warn-bg); border: 1px solid var(--warn); color: var(--text); }
.cp-links { display: flex; flex-wrap: wrap; gap: 0.45rem; align-items: center; margin-top: 0.7rem; }
.cp-links-h { font-size: var(--step--2); color: var(--muted); width: 100%; }

/* ---------- dashboard ---------- */

.dash-h {
  font-family: var(--sans); font-size: var(--step-2); font-weight: 650;
  margin: 2.6rem 0 0.3rem; letter-spacing: -0.01em;
}
.dash-note {
  max-width: var(--measure); color: var(--muted);
  font-size: var(--step--1); margin: 0.4rem 0 1.1rem;
}

.dash-grid {
  display: grid; gap: 1rem; margin: 1.6rem 0 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
}
/* Three real choices, side by side. Anything that is not a choice belongs in
   the strip below, not in a fourth identical box. */
@media (min-width: 1000px) {
  .dash-grid { grid-template-columns: repeat(3, 1fr); }
}

.dash-strip {
  display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--sunken); padding: 0.85rem 1.1rem;
  margin: 0.9rem 0 0.6rem;
  font-size: var(--step--1); color: var(--muted); line-height: var(--lh-snug);
}
.dash-strip > div { flex: 1 1 22rem; min-width: 0; }
.dash-strip-k { color: var(--text); font-weight: 640; }
.dash-grid-sm { grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); }

.dcard {
  display: flex; flex-direction: column; gap: 0.5rem;
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); padding: 1.15rem 1.2rem;
}
.dcard-primary { border-color: var(--accent); background: var(--accent-bg); }
.dcard-sm { padding: 0.95rem 1rem; }
.dcard-k {
  font-size: var(--step--2); text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--faint); font-weight: 640;
}
.dcard-primary .dcard-k { color: var(--accent); }
.dcard-t {
  font-family: var(--sans); font-size: var(--step-1); font-weight: 640;
  line-height: var(--lh-snug); letter-spacing: -0.008em;
}
.dcard-sub {
  font-size: var(--step--1); color: var(--muted); line-height: var(--lh-snug);
  flex: 1 1 auto;
}
.dcard-bar { margin: 0.2rem 0 0.35rem; }
.dcard-barl {
  display: block; margin-top: 0.35rem;
  font-size: var(--step--2); color: var(--faint);
  font-variant-numeric: tabular-nums;
}
.dcard .btn-row { margin-top: 0.3rem; }

.prog-rows {
  border: 1px solid var(--border); border-radius: var(--r-lg);
  overflow: hidden; margin: 0.9rem 0 1rem;
}
.prog-row {
  display: grid; grid-template-columns: minmax(9rem, 1.4fr) 1fr 3.2rem auto;
  gap: 1rem; align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.prog-row:last-child { border-bottom: 0; }
.prog-label { font-size: var(--step--1); min-width: 0; }
.prog-label b { font-weight: 620; }
.prog-label small {
  display: block; color: var(--faint); font-size: var(--step--2); line-height: 1.4;
}
.prog-num {
  font-size: var(--step--1); color: var(--muted);
  font-variant-numeric: tabular-nums; text-align: right;
}
.plan-bar { max-width: 20rem; margin-top: 0.45rem; }

@media (max-width: 640px) {
  .prog-row { grid-template-columns: 1fr auto; row-gap: 0.5rem; }
  .prog-bar { grid-column: 1 / -1; }
}

/* ---------- challenge setup ---------- */

.opt-grid {
  display: grid; gap: 0.7rem; margin: 0.9rem 0 0;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
}
.opt-card {
  display: flex; flex-direction: column; gap: 0.25rem;
  text-align: left; font: inherit; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); padding: 0.8rem 0.9rem;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.opt-card:hover { background: var(--sunken); }
.opt-card[aria-pressed="true"] {
  border-color: var(--accent); background: var(--accent-bg);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.opt-card-t { font-size: var(--step-0); font-weight: 620; }
.opt-card-s { font-size: var(--step--2); color: var(--muted); line-height: 1.4; }

.timer.is-untimed { color: var(--faint); letter-spacing: 0.04em; }

/* ---------- AI tutor panel ---------- */

.tutor { position: fixed; inset: 0; z-index: 80; pointer-events: none; }
.tutor.is-open { pointer-events: auto; }
.tutor-scrim {
  position: absolute; inset: 0; pointer-events: none;
  background: rgba(26, 25, 23, 0.34);
  opacity: 0; transition: opacity var(--dur) var(--ease);
}
.tutor.is-open .tutor-scrim { opacity: 1; pointer-events: auto; }

.tutor-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(460px, 100%);
  display: flex; flex-direction: column;
  background: var(--bg); border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform var(--dur) var(--ease);
}
.tutor.is-open .tutor-panel { transform: none; }
.tutor-panel.is-drop { outline: 2px dashed var(--accent); outline-offset: -8px; }

.tutor-head {
  display: flex; align-items: flex-start; gap: 0.7rem;
  padding: 0.85rem 1rem; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.tutor-title { font-size: var(--step-0); font-weight: 660; }
.tutor-ctx {
  font-size: var(--step--2); color: var(--faint); margin-top: 0.15rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22rem;
}
.tutor-head-acts { margin-left: auto; display: flex; gap: 0.35rem; align-items: center; }

.tutor-log {
  flex: 1 1 auto; overflow-y: auto; padding: 1rem;
  display: flex; flex-direction: column; gap: 0.8rem;
  scroll-behavior: smooth;
}

.tutor-empty { margin: auto 0; text-align: left; }
.tutor-empty-h { font-size: var(--step-1); font-weight: 620; margin: 0 0 0.4rem; }
.tutor-empty-s {
  font-size: var(--step--1); color: var(--muted);
  line-height: var(--lh-snug); margin: 0 0 1.1rem;
}
.tutor-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tutor-chip {
  font: inherit; font-size: var(--step--2); cursor: pointer;
  border: 1px solid var(--border); border-radius: 99px;
  background: var(--surface); color: var(--muted);
  padding: 0.36rem 0.7rem; text-align: left;
}
.tutor-chip:hover { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }

.tmsg { max-width: 100%; }
.tmsg-b {
  border-radius: var(--r-md); padding: 0.6rem 0.8rem;
  font-size: var(--step--1); line-height: var(--lh-snug);
}
.tmsg-b p { margin: 0 0 0.6rem; }
.tmsg-b p:last-child { margin-bottom: 0; }
.tmsg-user { margin-left: 2rem; }
.tmsg-user .tmsg-b {
  background: var(--accent); color: #fff;
  border-bottom-right-radius: 3px;
}
.tmsg-user .tmsg-b code { background: rgba(255, 255, 255, 0.18); color: #fff; border: 0; }
.tmsg-assistant .tmsg-b {
  background: var(--surface); border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}
.tmsg-error .tmsg-b {
  background: var(--warn-bg); border: 1px solid var(--warn); color: var(--text);
}
.tmsg-img {
  display: block; max-width: 190px; max-height: 150px;
  border-radius: var(--r-md); border: 1px solid var(--border);
  margin: 0 0 0.4rem auto;
}
.tutor-code {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 0.6rem 0.7rem; margin: 0.5rem 0;
  font-family: var(--mono); font-size: 0.84em; line-height: var(--lh-code);
  overflow-x: auto; white-space: pre;
}

.tdots { display: inline-flex; gap: 3px; padding: 0.15rem 0; }
.tdots i {
  width: 5px; height: 5px; border-radius: 99px; background: var(--faint);
  animation: tdot 1.1s infinite ease-in-out;
}
.tdots i:nth-child(2) { animation-delay: 0.15s; }
.tdots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes tdot { 0%, 60%, 100% { opacity: 0.28; } 30% { opacity: 1; } }

.tutor-composer {
  border-top: 1px solid var(--border); background: var(--surface);
  padding: 0.7rem 0.8rem 0.6rem;
}
.tutor-composer textarea {
  width: 100%; resize: none; font: inherit; font-size: var(--step--1);
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg); color: var(--text);
  padding: 0.55rem 0.65rem; line-height: var(--lh-snug);
  min-height: 2.9rem; max-height: 160px;
}
.tutor-composer textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

.tutor-attach { margin-bottom: 0.5rem; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 0.5rem;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--bg); padding: 0.3rem 0.4rem 0.3rem 0.3rem;
  max-width: 100%;
}
.attach-chip img {
  width: 38px; height: 38px; object-fit: cover;
  border-radius: var(--r-sm); border: 1px solid var(--border);
}
.attach-name {
  font-size: var(--step--2); color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 13rem;
}
.attach-x {
  font: inherit; font-size: var(--step--2); line-height: 1;
  border: 0; background: none; color: var(--faint);
  cursor: pointer; padding: 0.3rem;
}
.attach-x:hover { color: var(--bad); }

.tutor-tools {
  display: flex; align-items: center; gap: 0.5rem; margin-top: 0.5rem;
}
.tutor-hint {
  font-size: var(--step--2); color: var(--faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tutor-send { margin-left: auto; }
.tutor-foot {
  font-size: var(--step--2); color: var(--faint);
  padding: 0 0.9rem 0.7rem; background: var(--surface);
  line-height: 1.4;
}

/* The drawer only covers the whole viewport on narrow screens, so only lock
   page scroll there — on desktop you should still be able to read the lesson. */

@media (max-width: 560px) {
  body.tutor-open { overflow: hidden; }
  .tutor-panel { width: 100%; border-left: 0; }
  .tutor-ctx { max-width: 14rem; }
}

@media (prefers-reduced-motion: reduce) {
  .tutor-panel, .tutor-scrim { transition: none; }
  .tdots i { animation: none; opacity: 0.55; }
  .tutor-log { scroll-behavior: auto; }
}

@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,
  .tutor, .stage-rail, .ask-row, .cp-score { 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; }

/* ============================================================
   Hands-on layer
   Code editor · labs · playground · reorder / fill-in / find-the-bug
   ============================================================ */

/* ---------- stage rail: a stepper, not a bag of pills ---------- */

.stage-rail {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0;
  margin: -0.2rem 0 2.2rem; padding: 0.3rem 0 0.9rem;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.stage-pill {
  border: 0; background: none; border-radius: var(--r-md);
  padding: 0.3rem 0.55rem; gap: 0.42rem;
  color: var(--faint); font-size: 0.78rem; font-weight: 500;
  box-shadow: none;
}
.stage-pill + .stage-pill::before {
  content: ''; width: 0.7rem; height: 1px; background: var(--border);
  margin-right: 0.2rem; flex: none;
}
.stage-pill:hover { background: var(--sunken); color: var(--text); }
.stage-n {
  width: 1.15rem; height: 1.15rem;
  background: transparent; color: var(--faint);
  border: 1px solid var(--border-strong);
}
.stage-pill:hover .stage-n { background: var(--ink); color: var(--ink-fg); border-color: var(--ink); }
.stage-ask {
  margin-left: 0.4rem; color: var(--accent); font-weight: 560;
  border: 1px dashed var(--accent-line);
}
.stage-ask:hover { background: var(--accent-bg); color: var(--accent); }

/* ---------- code editor ---------- */

.ed {
  display: flex; align-items: stretch;
  background: var(--code-bg); color: var(--code-fg);
  border: 1px solid var(--code-border); border-radius: var(--r-lg);
  overflow: hidden; font-family: var(--mono);
  font-size: 0.86rem; line-height: 1.65;
}
.ed:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.15); }

.ed-gutter {
  flex: none; padding: 0.8rem 0.6rem 0.8rem 0.75rem;
  text-align: right; color: var(--code-gutter); user-select: none;
  background: rgba(255, 255, 255, 0.02);
  border-right: 1px solid var(--code-border);
  font-variant-numeric: tabular-nums; overflow: hidden;
}
.ed-gutter span { display: block; }
.ed-gutter span.is-err { color: #FCA5A5; font-weight: 700; }
.ed-gutter span.is-err::after { content: '  ●'; font-size: 0.6em; vertical-align: middle; }

.ed-scroll { flex: 1; min-width: 0; overflow-x: auto; }
.ed-layers { position: relative; width: max-content; min-width: 100%; }

.ed-hl, .ed-ta {
  margin: 0; padding: 0.8rem 1rem;
  font: inherit; letter-spacing: normal;
  white-space: pre; word-wrap: normal; tab-size: 3;
  border: 0; outline: 0; background: transparent;
}
.ed-hl { display: block; pointer-events: none; min-height: 1.65em; }
.ed-ta {
  position: absolute; inset: 0; width: 100%; height: 100%;
  color: transparent; caret-color: #FDBA74; resize: none; overflow: hidden;
  -webkit-text-fill-color: transparent;
}
.ed-ta::selection { background: rgba(253, 186, 116, 0.28); }
.ed-ta::placeholder { color: var(--code-gutter); -webkit-text-fill-color: var(--code-gutter); }

/* ---------- lab ---------- */

.lab {
  border: 1px solid var(--border); border-radius: var(--r-lg);
  background: var(--surface); margin: 1.4rem 0 2rem;
  overflow: hidden; box-shadow: var(--shadow-sm);
}
.lab.is-done { border-color: var(--ok); }

.lab-head {
  display: flex; align-items: baseline; gap: 0.7rem; flex-wrap: wrap;
  padding: 0.75rem 1.1rem; border-bottom: 1px solid var(--border);
  background: var(--sunken);
}
.lab-kind {
  font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--accent); background: var(--accent-bg);
  border-radius: var(--r-sm); padding: 0.16rem 0.4rem; flex: none;
}
.lab.is-done .lab-kind { color: var(--ok); background: var(--ok-bg); }
.lab.is-done .lab-kind::after { content: ' ✓'; }
.lab-title { font-weight: 620; font-size: var(--step-0); }

.lab-brief { padding: 1rem 1.1rem 0.2rem; font-size: var(--step--1); max-width: var(--measure-code); }
.lab-brief p { margin: 0 0 0.7rem; }
.lab-brief ul, .lab-brief ol { margin: 0 0 0.8rem; padding-left: 1.2rem; }
.lab-brief li { margin-bottom: 0.25rem; }

.lab-spec {
  border: 1px solid var(--border); border-left: 3px solid var(--border-strong);
  border-radius: var(--r-md); background: var(--sunken);
  padding: 0.6rem 0.85rem; margin: 0.9rem 0 0.4rem;
}
.lab-spec-k {
  display: block; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--faint); font-weight: 680; margin-bottom: 0.35rem;
}
.lab-spec ul { list-style: none; margin: 0; padding: 0; }
.lab-spec li {
  display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; align-items: baseline;
  padding: 0.2rem 0; font-size: var(--step--2);
}
.lab-spec-n { font-weight: 620; min-width: 6rem; }
.lab-spec-io { color: var(--muted); }
.lab-spec code { font-size: 0.95em; }

.lab-editor { padding: 0.9rem 1.1rem 0; }
.lab-stdin { padding: 0.8rem 1.1rem 0; }
.lab-stdin label, .play-lab {
  display: block; font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--faint); font-weight: 680; margin-bottom: 0.3rem;
}
.lab-stdin-ta, .play-stdin {
  width: 100%; font-family: var(--mono); font-size: 0.82rem;
  padding: 0.5rem 0.7rem; color: var(--text); background: var(--sunken);
  border: 1px solid var(--border); border-radius: var(--r-md); resize: vertical;
}

.lab-bar {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
  padding: 0.9rem 1.1rem;
}
.btn-run { padding-right: 0.7rem; }
.btn-check { border-color: var(--ok); color: var(--ok); font-weight: 580; }
.btn-check:hover:not(:disabled) { background: var(--ok-bg); border-color: var(--ok); }
.kbd {
  font-family: var(--mono); font-size: 0.68em; opacity: 0.65;
  border: 1px solid currentColor; border-radius: 3px; padding: 0 0.2rem;
}
.lab-status { font-size: var(--step--2); color: var(--muted); margin-left: auto; }
.lab-status.is-right { color: var(--ok); font-weight: 620; }
.lab-status.is-wrong { color: var(--bad); font-weight: 620; }
.lab-note { font-size: var(--step--2); color: var(--faint); }

.lab-out, .play-out { padding: 0 1.1rem 0.8rem; }
.play-out { padding: 0; }

.con-block {
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--sunken); padding: 0.5rem 0.75rem; margin-bottom: 0.5rem;
  font-size: var(--step--2);
}
.con-k {
  font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--faint); font-weight: 700; margin-bottom: 0.25rem;
}
.con-block pre {
  margin: 0; font-family: var(--mono); font-size: 0.82rem; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; color: var(--text);
}
.con-bad { border-color: var(--bad); background: var(--bad-bg); }
.con-bad .con-k { color: var(--bad); }
.con-warn { border-color: var(--warn); background: var(--warn-bg); }
.con-warn .con-k { color: var(--warn); }
.con-run { color: var(--muted); }
.con-empty { color: var(--faint); font-style: italic; }

.lab-tests { margin-top: 0.4rem; }
.lab-test {
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 0.45rem 0.7rem; margin-bottom: 0.4rem; font-size: var(--step--2);
}
.lab-test.is-pass { border-color: var(--ok); background: var(--ok-bg); }
.lab-test.is-fail { border-color: var(--bad); background: var(--bad-bg); }
.lab-test-mark { font-weight: 800; margin-right: 0.45rem; }
.lab-test.is-pass .lab-test-mark { color: var(--ok); }
.lab-test.is-fail .lab-test-mark { color: var(--bad); }
.lab-test-n { font-weight: 600; }
.lab-diff {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-top: 0.5rem;
}
.lab-diff pre {
  margin: 0.1rem 0 0; font-family: var(--mono); font-size: 0.8rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 0.35rem 0.5rem;
  white-space: pre-wrap; word-break: break-word;
}
.lab-hints, .lab-solution { padding: 0 1.1rem; }
.lab-solution:not(:empty) { padding-bottom: 0.9rem; }
.lab-hints:not(:empty) { padding-bottom: 0.3rem; }

/* ---------- playground ---------- */

.play-head { border-bottom: 1px solid var(--border); padding-bottom: 1.2rem; margin-bottom: 1.4rem; }
.play-head .lede { max-width: var(--measure); font-size: var(--step-0); }
.play-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(15rem, 1fr); gap: 1.2rem; align-items: start; }
.play-code .ed { min-height: 22rem; }
.play-code .ed-hl { min-height: 21rem; }
.play-bar { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.8rem; }
.play-side { position: sticky; top: 1.2rem; }
.play-side .play-lab { margin-top: 0.9rem; }
.play-side .play-lab:first-child { margin-top: 0; }
.play-out {
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); padding: 0.5rem; min-height: 9rem;
}
.play-out .con-block:last-child { margin-bottom: 0; }
.play-note { font-size: var(--step--2); color: var(--faint); margin-top: 1.4rem; max-width: var(--measure); }

/* ---------- labs index ---------- */

.page-head { border-bottom: 1px solid var(--border); padding-bottom: 1.3rem; margin-bottom: 1.6rem; }
.page-head .lede { max-width: var(--measure); }
.labs-count {
  display: flex; align-items: center; gap: 0.8rem; margin-top: 1rem;
  font-size: var(--step--2); color: var(--muted); max-width: 26rem;
}
.labs-count .bar-track { flex: 1; }
.labs-ch { font-size: var(--step-0); font-weight: 640; margin: 2rem 0 0.6rem; color: var(--muted); }
.lab-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.lab-row + .lab-row { border-top: 1px solid var(--border); }
.lab-row button {
  display: grid; grid-template-columns: 1.6rem minmax(0, 1fr) minmax(0, 14rem);
  gap: 0.8rem; align-items: baseline; width: 100%; text-align: left;
  background: var(--surface); border: 0; cursor: pointer;
  padding: 0.65rem 1rem; font: inherit; font-size: var(--step--1); color: var(--text);
}
.lab-row button:hover { background: var(--sunken); }
.lab-row-mark { font-weight: 800; color: var(--faint); }
.lab-row.is-pass .lab-row-mark { color: var(--ok); }
.lab-row-t { font-weight: 560; }
.lab-row-s { color: var(--faint); font-size: var(--step--2); text-align: right;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- reorder (Parsons) ---------- */

.parsons { list-style: none; margin: 0.8rem 0 0; padding: 0; max-width: var(--measure-code); counter-reset: par; }
.par {
  display: flex; align-items: center; gap: 0.6rem;
  border: 1px solid var(--code-border); border-radius: var(--r-md);
  background: var(--code-bg); color: var(--code-fg);
  padding: 0.4rem 0.6rem; margin-bottom: 0.35rem; cursor: grab;
}
.par:active { cursor: grabbing; }
.par.is-drag { opacity: 0.4; }
.par.is-moved { outline: 2px solid var(--accent); }
.par-grip { color: var(--code-gutter); flex: none; font-size: 0.8rem; letter-spacing: -0.1em; }
.par code {
  flex: 1; min-width: 0; font-family: var(--mono); font-size: 0.86rem;
  white-space: pre; overflow-x: auto; background: none; border: 0; padding: 0;
}
.par-mv { display: flex; gap: 0.15rem; flex: none; }
.par-mv button {
  width: 1.5rem; height: 1.5rem; line-height: 1; cursor: pointer;
  background: var(--code-face); color: #A8A29E;
  border: 1px solid var(--code-border); border-radius: var(--r-sm);
  font-size: 0.8rem;
}
.par-mv button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.par.is-right { box-shadow: inset 3px 0 0 var(--ok); }
.par.is-wrong { box-shadow: inset 3px 0 0 var(--bad); }

/* ---------- fill in the gaps ---------- */

.code-fill .code-line { padding-top: 0.05rem; padding-bottom: 0.05rem; }
input.blank {
  font-family: var(--mono); font-size: 0.84rem; line-height: 1.2;
  padding: 0.05rem 0.3rem; margin: 0 0.1rem;
  color: #FDE68A; background: rgba(253, 224, 71, 0.09);
  border: 0; border-bottom: 2px dashed #A16207; border-radius: 3px 3px 0 0;
  outline: 0; min-width: 3.5rem;
}
input.blank:focus { background: rgba(253, 224, 71, 0.18); border-bottom-color: #FDE68A; }
input.blank.is-right { color: #86EFAC; border-bottom-color: #22C55E; border-bottom-style: solid; }
input.blank.is-wrong { color: #FCA5A5; border-bottom-color: #EF4444; border-bottom-style: solid; }
.blank-key {
  list-style: none; margin: 0.6rem 0 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 0.3rem 1.1rem;
  font-size: var(--step--2); color: var(--muted); max-width: var(--measure-code);
}
.blank-key b { font-family: var(--mono); color: var(--accent); }

/* ---------- find the broken line ---------- */

.code-pick .code-line.is-pick { cursor: pointer; }
.code-pick .code-line.is-pick:hover { background: rgba(255, 255, 255, 0.06); }
.code-pick .code-line.is-sel { background: rgba(251, 146, 60, 0.18); box-shadow: inset 3px 0 0 var(--accent); }
.code-pick .code-line.is-answer { background: rgba(34, 197, 94, 0.16); box-shadow: inset 3px 0 0 #22C55E; }
.code-pick .code-line.is-missed { background: rgba(239, 68, 68, 0.16); box-shadow: inset 3px 0 0 #EF4444; }
.code-pick .code-line:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

@media (max-width: 900px) {
  .play-grid { grid-template-columns: 1fr; }
  .play-side { position: static; }
  .lab-diff { grid-template-columns: 1fr; }
  .lab-row button { grid-template-columns: 1.4rem 1fr; }
  .lab-row-s { display: none; }
}

@media print {
  /* Code goes back to paper — a black block per snippet is unreadable and
     empties a cartridge. */
  .code, .par, .ed {
    background: #fff !important; color: #000 !important; border-color: #bbb !important;
    box-shadow: none !important;
  }
  .code-head, .code-out { background: #f4f4f4 !important; }
  .code-name, .code-origin, .code-out-label, .code-out pre { color: #333 !important; }
  .tk, .tt, .ts, .tn, .tf, .tp { color: #000 !important; }
  .tc { color: #555 !important; }
  .lab, .play, .lab-list { display: none !important; }
}
