:root {
  --bg: #ffffff;
  --panel: #fafaf8;
  --panel-2: #f1f2f0;
  --ink: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --accent-2: #7c3aed;
  --good: #15803d;
  --bad: #dc2626;
  --gold: #b45309;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.7 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

#app { display: grid; grid-template-columns: 300px 1fr; height: 100vh; }

/* ---- timeline rail ---- */
#rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 22px 18px;
}
.rail-head h1 { margin: 0; font-size: 21px; letter-spacing: -0.2px; }
.rail-head .sub { margin: 2px 0 14px; color: var(--muted); font-size: 13px; }
.hublink { display: inline-block; margin-bottom: 12px; color: var(--muted); font-size: 12px; text-decoration: none; }
.hublink:hover { color: var(--accent); }
/* cross-link to the SVD deep-dive — reads as a quiet call-to-action card */
.deepdive {
  display: block; margin: 22px auto; padding: 14px 18px;
  border: 1px solid var(--line); border-left: 3px solid var(--accent-2);
  border-radius: 8px; color: var(--ink); text-decoration: none; font-size: 15px;
  background: var(--bg);
}
.deepdive:hover { border-color: var(--accent-2); }
.deepdive b { color: var(--accent-2); }
#overall-progress { height: 5px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
#overall-bar { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
#overall-label { font-size: 12px; color: var(--muted); }

#timeline { margin-top: 20px; position: relative; }
#timeline::before {
  content: ""; position: absolute; left: 13px; top: 6px; bottom: 6px;
  width: 2px; background: var(--line);
}
.tl-item {
  position: relative; padding: 8px 8px 8px 36px; cursor: pointer;
  border-radius: 8px; margin-bottom: 2px;
}
.tl-item:hover { background: var(--panel-2); }
.tl-item.active { background: var(--panel-2); }
.tl-dot {
  position: absolute; left: 7px; top: 12px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--bg); border: 2px solid var(--line);
}
.tl-item.active .tl-dot { border-color: var(--accent); }
.tl-item.done .tl-dot { background: var(--good); border-color: var(--good); }
.tl-year { font-family: var(--mono); font-size: 12px; color: var(--accent); }
.tl-title { font-size: 13.5px; }
.tl-item.done .tl-title { color: var(--muted); }

/* ---- stage ---- */
#stage { display: flex; flex-direction: column; overflow: hidden; }

#lesson { overflow-y: auto; padding: 48px 6vw; flex: 1; }
/* hold every block to one reading-measure column (~70ch), flush-left. NOT
   margin:auto centering — p/h3/h2 carry their own `margin: x 0` which beats the
   `#lesson > *` selector on specificity, so auto here would center only the
   callouts/tables and leave paragraphs left-aligned (the columns drift apart). */
#lesson > * { max-width: 720px; margin-left: 0; margin-right: 0; }
#lesson.fade { animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

.era { font-family: var(--mono); color: var(--accent); letter-spacing: 2px; font-size: 13px; }
h2.lt { font-size: 32px; margin: 8px 0 5px; line-height: 1.14; letter-spacing: -.4px; }
.people { color: var(--muted); font-style: italic; margin-bottom: 18px; }

/* ---- closing summary: the resolution, after the story ---- */
.summary {
  display: flex; flex-direction: column; gap: 6px;
  margin: 36px 0 0; padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 8px;
}
.summary-tag {
  font-family: var(--mono); font-size: 11px; letter-spacing: 1px; font-weight: 700;
  color: var(--accent); text-transform: uppercase;
}
.summary-body { font-size: 16px; color: var(--ink); }

#lesson h3 { font-size: 20px; margin: 30px 0 6px; }
#lesson p { margin: 12px 0; }
.lead { font-size: 18px; color: #374151; }

/* flat margin-notes, not stacked cards — a quiet left rule carries the color, and
   the label is a small run-in lead (not a shouty stacked badge on every block) */
.callout {
  border-left: 2px solid var(--line); padding: 1px 0 1px 18px; margin: 16px 0;
  background: none; border-radius: 0;
  /* long unbroken tokens (urls, code) must wrap, not push the box past 720px */
  overflow-wrap: break-word;
}
.callout .tag {
  font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: .2px;
}
.callout .tag::after { content: " — "; color: var(--muted); font-weight: 400; }
.callout.desk { border-color: var(--gold); } .callout.desk .tag { color: var(--gold); }
.callout.leap { border-color: var(--accent-2); } .callout.leap .tag { color: var(--accent-2); }
.callout.aside { border-color: var(--muted); } .callout.aside .tag { color: var(--muted); }
.callout.legacy { border-color: var(--good); } .callout.legacy .tag { color: var(--good); }

/* further-reading link(s) at the end of a chapter */
.further { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 14px;
  margin: 18px 0 0; padding-top: 12px; border-top: 1px solid var(--line); }
.further-tag { font-family: var(--mono); font-size: 10px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--muted); }
.src-link { font-size: 13px; color: var(--muted); text-decoration: none; border-bottom: 1px dotted var(--line); }
.src-link:hover { color: var(--accent); border-color: var(--accent); }

code { font-family: var(--mono); background: var(--panel-2); padding: 1px 6px; border-radius: 4px; font-size: 14px; }
.eq { font-family: var(--mono); background: var(--panel); border: 1px solid var(--line); padding: 12px 16px; border-radius: 8px; display: block; margin: 16px 0; color: var(--ink); overflow-x: auto; font-size: 14px; }
em { color: var(--ink); font-style: italic; }
strong { color: var(--ink); font-weight: 600; }

/* ---- quiz ---- */
/* a hard, labelled break so the quiz reads as a distinct section, not just one
   more box bleeding into the lesson body */
.quiz-sep { display: flex; align-items: center; gap: 16px; margin: 54px 0 0; }
.quiz-sep::before, .quiz-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.quiz-sep span { font-family: var(--mono); font-size: 12px; letter-spacing: 2.5px; text-transform: uppercase; color: var(--accent); white-space: nowrap; }
.quiz {
  background: var(--panel); border: 1px solid var(--line); border-top: 2px solid var(--accent);
  border-radius: 8px; padding: 22px 24px; margin: 18px 0 8px;
}
.quiz .q { margin: 20px 0 10px; font-weight: 600; }
.quiz .q:first-child { margin-top: 2px; }
.opt {
  display: block; width: 100%; text-align: left; padding: 11px 14px; margin: 7px 0;
  background: var(--bg); border: 1px solid var(--line); color: var(--ink);
  border-radius: 8px; cursor: pointer; font-size: 15px; transition: .15s;
  font-family: inherit;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.correct { border-color: var(--good); background: rgba(21,128,61,.07); }
.opt.wrong { border-color: var(--bad); background: rgba(220,38,38,.06); }
.opt:disabled { cursor: default; }
.explain { margin-top: 10px; font-size: 14px; color: var(--muted); display: none; }
.explain.show { display: block; }
.explain b { color: var(--ink); }

/* ---- interactive widgets ---- */
.widget { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin: 28px 0; }
.widget svg { display: block; margin: 0 auto; }
.widget label { font-size: 13px; color: var(--muted); display: inline-block; width: 120px; }
.widget input[type=range] { vertical-align: middle; accent-color: var(--accent); }
.readout { font-family: var(--mono); font-size: 15px; margin-top: 10px; }
.readout b { color: var(--accent); }
/* generic "selected" pill state shared by every widget's toggle buttons/chips */
.widget .opt.on, .opt.mask.on { border-color: var(--accent); background: rgba(37,99,235,.08); color: var(--ink); }
.widget .wsel {
  font-family: var(--mono); font-size: 14px; background: var(--bg);
  color: var(--accent); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; cursor: pointer;
}
.widget .wtext {
  width: 100%; font-family: var(--mono); font-size: 15px; background: var(--bg);
  color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px;
}
.widget .wtext:focus, .widget .wsel:focus { outline: none; border-color: var(--accent); }

/* ---- nav footer ---- */
#nav { display: flex; align-items: center; justify-content: space-between; padding: 14px 8vw; border-top: 1px solid var(--line); background: var(--panel); }
#nav button { background: var(--bg); color: var(--ink); border: 1px solid var(--line); padding: 9px 18px; border-radius: 8px; cursor: pointer; font-size: 14px; font-family: inherit; }
#nav button:hover:not(:disabled) { border-color: var(--accent); }
#nav button:disabled { opacity: .35; cursor: default; }
#crumb { color: var(--muted); font-size: 13px; font-family: var(--mono); }

/* ---- mobile: the 300px grid rail breaks on phones, so stack and let the
   page scroll instead of trapping scroll inside #lesson ---- */
@media (max-width: 760px) {
  html, body { height: auto; }
  #app { display: block; height: auto; }
  #rail { border-right: none; border-bottom: 1px solid var(--line); overflow-y: visible; padding: 16px 14px; }
  /* collapse the long vertical timeline into a capped, scrollable strip so it
     doesn't push the lesson far below the fold */
  #timeline { max-height: 38vh; overflow-y: auto; }
  #stage { display: block; overflow: visible; }
  #lesson { overflow-y: visible; padding: 28px 18px; }
  h2.lt { font-size: 25px; }
  .lead { font-size: 16px; }
  #lesson { padding-bottom: 8px; }
  #nav { padding: 12px 18px; position: sticky; bottom: 0; }
  .widget label { width: auto; display: block; margin-bottom: 2px; }
  .widget svg { max-width: 100%; height: auto; }
}
