/* =========================================================================
   Model Engineering — course design system
   One rule to remember: colour means something. It never decorates.
     data / activations .... cyan      weights / parameters ... amber
     gradients ............. magenta   loss ................... red
     output / correct ...... green     frozen / discarded ..... grey
   ========================================================================= */

/* ---------- 1. Tokens ---------------------------------------------------- */

:root {
  /* ground */
  --bg:            #0a0c11;
  --bg-soft:       #0f131b;
  --surface:       #141924;
  --surface-2:     #1b2130;
  --surface-3:     #232b3d;
  --line:          #262f42;
  --line-soft:     #1c2434;

  /* type */
  --text:          #e8ecf4;
  --text-soft:     #aab3c5;
  --text-dim:      #78839a;

  /* semantic diagram palette */
  --c-data:        #4cd7e8;
  --c-data-dim:    #4cd7e833;
  --c-param:       #f5b544;
  --c-param-dim:   #f5b54433;
  --c-grad:        #ff6fae;
  --c-grad-dim:    #ff6fae33;
  --c-loss:        #ff6b57;
  --c-loss-dim:    #ff6b5733;
  --c-ok:          #5ddb95;
  --c-ok-dim:      #5ddb9533;
  --c-frozen:      #6c778f;
  --c-frozen-dim:  #6c778f33;

  --accent:        var(--c-data);
  --accent-ink:    #05242a;

  /* geometry */
  --r-sm: 6px;
  --r:    10px;
  --r-lg: 16px;
  --r-xl: 22px;

  --measure: 68ch;
  --rail: 264px;
  --rail-r: 220px;
  --topbar: 56px;

  --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-2: 0 8px 30px rgb(0 0 0 / .45);

  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter,
          system-ui, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo,
          Consolas, monospace;

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg:            #fbfaf7;
  --bg-soft:       #f4f3ef;
  --surface:       #ffffff;
  --surface-2:     #f4f4f1;
  --surface-3:     #e9e9e4;
  --line:          #ddddd6;
  --line-soft:     #eaeae4;

  --text:          #16191f;
  --text-soft:     #4a5160;
  --text-dim:      #6d7686;

  --c-data:        #0d8ea3;
  --c-data-dim:    #0d8ea31f;
  --c-param:       #b57407;
  --c-param-dim:   #b574071f;
  --c-grad:        #cc3b78;
  --c-grad-dim:    #cc3b781f;
  --c-loss:        #d43f28;
  --c-loss-dim:    #d43f281f;
  --c-ok:          #10864f;
  --c-ok-dim:      #10864f1f;
  --c-frozen:      #7d8698;
  --c-frozen-dim:  #7d86981f;

  --accent-ink:    #ffffff;
  --shadow-1: 0 1px 2px rgb(20 25 35 / .07);
  --shadow-2: 0 10px 34px rgb(20 25 35 / .10);

  color-scheme: light;
}

/* ---------- 2. Reset ----------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img, svg, video { max-width: 100%; }
a { color: var(--accent); text-decoration-color: color-mix(in oklab, var(--accent) 40%, transparent); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--c-data); outline-offset: 2px; border-radius: 3px; }

/* ---------- 3. Top bar --------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 60;
  height: var(--topbar);
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px;
  background: color-mix(in oklab, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand__mark {
  width: 26px; height: 26px; flex: none;
  border-radius: 7px;
  background: linear-gradient(140deg, var(--c-data), var(--c-param) 55%, var(--c-grad));
  position: relative;
}
.brand__mark::after {
  content: ""; position: absolute; inset: 6px 6px auto auto;
  width: 7px; height: 7px; border-radius: 2px;
  background: var(--bg);
}
.brand__name { font-weight: 620; letter-spacing: -.015em; font-size: 15px; }
.brand__name span { color: var(--text-dim); font-weight: 450; }

.topbar__spacer { flex: 1; }

.tb-btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 32px; padding: 0 11px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer;
  font-size: 13px; color: var(--text-soft);
  transition: background .15s, color .15s, border-color .15s;
}
.tb-btn:hover { background: var(--surface-3); color: var(--text); }
.tb-btn svg { width: 15px; height: 15px; }

.tb-progress { display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--text-dim); }
.tb-progress__track { width: 92px; height: 5px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.tb-progress__fill { height: 100%; width: 0%; border-radius: 99px; background: linear-gradient(90deg, var(--c-data), var(--c-ok)); transition: width .5s cubic-bezier(.2,.8,.2,1); }

.menu-toggle { display: none; }

/* ---------- 4. Shell layout ---------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  align-items: start;
  max-width: 1560px; margin: 0 auto;
}
.shell--wide { grid-template-columns: var(--rail) minmax(0, 1fr) var(--rail-r); }

/* ---------- 5. Sidebar --------------------------------------------------- */

.rail {
  position: sticky; top: var(--topbar);
  height: calc(100vh - var(--topbar));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 22px 12px 60px 18px;
  border-right: 1px solid var(--line-soft);
  scrollbar-width: thin;
}
.rail__part { margin-top: 22px; }
.rail__part:first-child { margin-top: 4px; }
.rail__part-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .11em;
  color: var(--text-dim); font-weight: 620;
  padding: 0 10px 7px;
}
.rail__link {
  display: grid; grid-template-columns: 22px 1fr; align-items: baseline; gap: 8px;
  padding: 6px 10px; border-radius: 8px;
  text-decoration: none; color: var(--text-soft);
  font-size: 14px; line-height: 1.4;
  transition: background .13s, color .13s;
}
.rail__link:hover { background: var(--surface-2); color: var(--text); }
.rail__link[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 560; }
.rail__link[aria-current="page"] .rail__num { color: var(--c-data); }
.rail__num { font: 600 11.5px/1.5 var(--mono); color: var(--text-dim); letter-spacing: -.02em; }
.rail__link.is-done .rail__num::after { content: "✓"; margin-left: 2px; color: var(--c-ok); }
.rail__link.is-done .rail__num { color: var(--c-ok); }

.rail__meta { margin-top: 30px; padding: 0 10px; border-top: 1px solid var(--line-soft); padding-top: 16px; }
.rail__meta a { display: block; font-size: 13.5px; color: var(--text-soft); text-decoration: none; padding: 5px 0; }
.rail__meta a:hover { color: var(--text); }

/* ---------- 6. Main column ----------------------------------------------- */

.main { min-width: 0; padding: 0 40px 120px; }
.prose { max-width: var(--measure); margin: 0 auto; }

.prose > * { margin-inline: auto; }
.prose p, .prose ul, .prose ol, .prose h2, .prose h3, .prose h4,
.prose blockquote, .prose .callout, .prose .terms, .prose .check,
.prose .code, .prose .steps, .prose .resources, .prose .project,
.prose .compare, .prose table { max-width: var(--measure); }

/* full-bleed figures inside the prose column */
.prose .scene, .prose .figure, .prose .bleed {
  max-width: min(1020px, 100%);
  width: 100%;
}

/* ---------- 7. Typography ------------------------------------------------ */

h1, h2, h3, h4 { line-height: 1.18; letter-spacing: -.021em; font-weight: 640; margin: 0; }
h1 { font-size: clamp(30px, 4.2vw, 44px); letter-spacing: -.03em; }
h2 { font-size: clamp(22px, 2.6vw, 27px); margin-top: 2.6em; margin-bottom: .55em; padding-top: .3em; }
h3 { font-size: 19px; margin-top: 2em; margin-bottom: .4em; }
h4 { font-size: 16px; margin-top: 1.6em; margin-bottom: .3em; color: var(--text-soft); }

h2 .h-num {
  font: 620 12px/1 var(--mono); color: var(--c-data);
  display: block; margin-bottom: .7em; letter-spacing: .06em;
}

p { margin: 0 0 1.05em; }
.prose ul, .prose ol { margin: 0 0 1.15em; padding-left: 1.35em; }
.prose li { margin-bottom: .42em; }
.prose li::marker { color: var(--text-dim); }

strong { font-weight: 640; color: var(--text); }
em { font-style: italic; }

.lead { font-size: 20px; line-height: 1.55; color: var(--text-soft); margin-bottom: 1.6em; }
.lead strong { color: var(--text); }

.eyebrow {
  font: 620 11px/1 var(--mono); letter-spacing: .13em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 14px; display: block;
}

hr { border: 0; border-top: 1px solid var(--line-soft); margin: 3em auto; max-width: var(--measure); }

/* inline code */
code {
  font-family: var(--mono); font-size: .875em;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  padding: .1em .35em; border-radius: var(--r-sm);
  color: var(--text);
  word-break: break-word;
}
.prose a code { color: inherit; }

kbd {
  font-family: var(--mono); font-size: .8em;
  background: var(--surface-3); border: 1px solid var(--line);
  border-bottom-width: 2px;
  padding: .12em .4em; border-radius: 5px;
}

/* ---------- 8. Lesson header --------------------------------------------- */

.lesson-head { padding: 46px 0 8px; }
.lesson-head__num {
  font: 700 clamp(46px, 8vw, 76px)/1 var(--mono);
  letter-spacing: -.05em;
  background: linear-gradient(140deg, var(--c-data), var(--c-param));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  display: block; margin-bottom: -6px;
}
.lesson-head__meta {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--text-soft);
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 4px 10px; border-radius: 99px;
}
.chip b { font-weight: 600; color: var(--text); }

/* outcomes box under the header */
.outcomes {
  margin: 30px auto 0; padding: 20px 22px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.outcomes h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-dim); margin: 0 0 12px; padding: 0;
}
.outcomes ul { margin: 0; padding-left: 1.2em; }
.outcomes li { margin-bottom: .35em; font-size: 15.5px; color: var(--text-soft); }
.outcomes li strong { color: var(--text); }

/* ---------- 9. Scenes (animated diagrams) -------------------------------- */

.scene {
  margin: 2.4em auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.scene__head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--bg-soft);
}
.scene__title { font-size: 13.5px; font-weight: 600; letter-spacing: -.01em; }
.scene__badge {
  font: 600 10px/1 var(--mono); letter-spacing: .09em; text-transform: uppercase;
  color: var(--c-data); background: var(--c-data-dim);
  padding: 4px 7px; border-radius: 5px; flex: none;
}
.scene__stage {
  position: relative;
  padding: 22px 18px;
  display: flex; align-items: center; justify-content: center;
  min-height: 180px;
  background:
    radial-gradient(120% 90% at 50% 0%, color-mix(in oklab, var(--surface-2) 70%, transparent), transparent 70%);
}
.scene__stage svg { width: 100%; height: auto; display: block; overflow: visible; }
.scene__stage > svg { max-width: 900px; }

/* scene footer: caption + controls */
.scene__foot {
  border-top: 1px solid var(--line-soft);
  padding: 12px 18px 14px;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--bg-soft);
}
.scene__caption {
  flex: 1 1 320px; min-width: 0;
  font-size: 14.5px; line-height: 1.5; color: var(--text-soft);
  min-height: 2.9em;
}
.scene__caption b, .scene__caption strong { color: var(--text); font-weight: 600; }
.scene__caption .kw { font-family: var(--mono); font-size: .9em; }

.scene__controls { display: flex; align-items: center; gap: 6px; flex: none; }
.sbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 30px; min-width: 30px; padding: 0 9px;
  border-radius: 8px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text-soft); font-size: 12.5px;
  transition: background .13s, color .13s;
}
.sbtn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.sbtn:disabled { opacity: .38; cursor: default; }
.sbtn--primary { background: var(--c-data); border-color: var(--c-data); color: var(--accent-ink); font-weight: 600; }
.sbtn--primary:hover:not(:disabled) { background: color-mix(in oklab, var(--c-data) 85%, white); color: var(--accent-ink); }
.sbtn svg { width: 13px; height: 13px; }

.scene__dots { display: flex; gap: 5px; align-items: center; }
.scene__dot {
  width: 6px; height: 6px; border-radius: 99px; padding: 0; border: 0;
  background: var(--surface-3); cursor: pointer; transition: background .2s, width .2s;
}
.scene__dot.is-active { background: var(--c-data); width: 16px; }
.scene__dot.is-past { background: color-mix(in oklab, var(--c-data) 45%, var(--surface-3)); }

.scene__step-n { font: 600 11.5px/1 var(--mono); color: var(--text-dim); min-width: 34px; text-align: center; }

/* SVG diagram conventions */
.dg-label { font: 600 12px var(--sans); fill: var(--text-soft); }
.dg-label--sm { font-size: 10.5px; }
.dg-mono { font: 600 12px var(--mono); fill: var(--text-soft); }
.dg-title { font: 650 13px var(--sans); fill: var(--text); }
.dg-box { fill: var(--surface-2); stroke: var(--line); stroke-width: 1.5; }
.dg-line { stroke: var(--line); stroke-width: 1.5; fill: none; }
.dg-arrow { stroke: var(--text-dim); stroke-width: 1.5; fill: none; }

.dg-data   { fill: var(--c-data); }   .dg-data-s   { stroke: var(--c-data); }
.dg-param  { fill: var(--c-param); }  .dg-param-s  { stroke: var(--c-param); }
.dg-grad   { fill: var(--c-grad); }   .dg-grad-s   { stroke: var(--c-grad); }
.dg-loss   { fill: var(--c-loss); }   .dg-loss-s   { stroke: var(--c-loss); }
.dg-ok     { fill: var(--c-ok); }     .dg-ok-s     { stroke: var(--c-ok); }
.dg-frozen { fill: var(--c-frozen); } .dg-frozen-s { stroke: var(--c-frozen); }

/* colour legend */
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 1.4em auto; }
.legend__item { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-soft); }
.legend__swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }

/* ---------- 10. Callouts -------------------------------------------------- */

.callout {
  margin: 1.7em auto; padding: 15px 18px 15px 17px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  border-left: 3px solid var(--text-dim);
  background: var(--surface);
  font-size: 15.5px; line-height: 1.6;
}
.callout > :last-child { margin-bottom: 0; }
.callout__label {
  display: block; font: 620 10.5px/1 var(--mono);
  letter-spacing: .11em; text-transform: uppercase;
  margin-bottom: 8px; color: var(--text-dim);
}
.callout--key      { border-left-color: var(--c-param); background: color-mix(in oklab, var(--c-param-dim) 55%, var(--surface)); }
.callout--key .callout__label { color: var(--c-param); }
.callout--pitfall  { border-left-color: var(--c-loss); background: color-mix(in oklab, var(--c-loss-dim) 50%, var(--surface)); }
.callout--pitfall .callout__label { color: var(--c-loss); }
.callout--note     { border-left-color: var(--c-data); }
.callout--note .callout__label { color: var(--c-data); }
.callout--math     { border-left-color: var(--c-grad); background: var(--surface); }
.callout--math .callout__label { color: var(--c-grad); }
.callout--try      { border-left-color: var(--c-ok); background: color-mix(in oklab, var(--c-ok-dim) 45%, var(--surface)); }
.callout--try .callout__label { color: var(--c-ok); }

/* maths, written plainly */
.eq {
  font-family: var(--mono); font-size: 15px;
  background: var(--bg-soft); border: 1px solid var(--line-soft);
  border-radius: var(--r); padding: 13px 16px; margin: 1em 0;
  overflow-x: auto; white-space: pre; line-height: 1.7;
}
.eq b { color: var(--c-param); font-weight: 600; }
.eq i { color: var(--c-data); font-style: normal; }
.eq u { color: var(--c-grad); text-decoration: none; }

/* ---------- 11. Code ------------------------------------------------------ */

.code {
  margin: 1.7em auto;
  border: 1px solid var(--line); border-radius: var(--r);
  background: var(--bg-soft); overflow: hidden;
}
.code__head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px 8px 14px;
  border-bottom: 1px solid var(--line-soft);
  font: 500 12px/1 var(--mono); color: var(--text-dim);
}
.code__head .lang {
  margin-left: auto; font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-dim);
}
.copy-btn {
  border: 1px solid var(--line); background: var(--surface-2);
  border-radius: 6px; padding: 3px 8px; cursor: pointer;
  font: 500 11px/1.5 var(--sans); color: var(--text-soft);
}
.copy-btn:hover { background: var(--surface-3); color: var(--text); }
.copy-btn.is-done { color: var(--c-ok); border-color: color-mix(in oklab, var(--c-ok) 40%, var(--line)); }

.code pre {
  margin: 0; padding: 14px 16px; overflow-x: auto;
  font-family: var(--mono); font-size: 13.2px; line-height: 1.62;
  tab-size: 4;
}
.code pre code { background: none; border: 0; padding: 0; font-size: inherit; }

/* tiny syntax palette, applied by course.js */
.tok-kw  { color: var(--c-grad); }
.tok-str { color: var(--c-ok); }
.tok-num { color: var(--c-param); }
.tok-com { color: var(--text-dim); font-style: italic; }
.tok-fn  { color: var(--c-data); }
.tok-dec { color: var(--c-param); }

/* ---------- 12. Terms / glossary ----------------------------------------- */

.terms {
  margin: 2em auto; padding: 4px 0 0;
  border-top: 1px solid var(--line-soft);
}
.terms__label {
  font: 620 10.5px/1 var(--mono); letter-spacing: .11em; text-transform: uppercase;
  color: var(--text-dim); margin: 16px 0 12px; display: block;
}
.terms dl { margin: 0; display: grid; gap: 11px; }
.terms dt {
  font-weight: 620; font-size: 14.5px;
  display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap;
}
.terms dt .en { font: 500 12.5px/1.4 var(--mono); color: var(--text-dim); }
.terms dd { margin: 2px 0 0; font-size: 14.5px; color: var(--text-soft); line-height: 1.55; }

/* inline glossary term */
.term {
  border-bottom: 1px dashed color-mix(in oklab, var(--c-data) 55%, transparent);
  cursor: help; position: relative;
}
.tip {
  position: fixed; z-index: 100; max-width: 300px;
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 10px 13px; font-size: 13.5px; line-height: 1.5;
  box-shadow: var(--shadow-2);
  pointer-events: none; opacity: 0;
}
.tip b { display: block; margin-bottom: 3px; font-size: 13px; color: var(--c-data); }

/* ---------- 13. Self-check ------------------------------------------------ */

.check {
  margin: 1.8em auto; border: 1px solid var(--line);
  border-radius: var(--r); background: var(--surface); overflow: hidden;
}
.check__q {
  padding: 14px 18px; font-size: 15.5px; font-weight: 560;
  display: flex; gap: 11px; align-items: flex-start;
}
.check__q::before {
  content: "?"; flex: none;
  width: 21px; height: 21px; border-radius: 6px; margin-top: 1px;
  background: var(--c-param-dim); color: var(--c-param);
  font: 700 12px/21px var(--mono); text-align: center;
}
.check__opts { display: grid; gap: 7px; padding: 0 18px 14px 50px; }
.check__opt {
  text-align: left; padding: 9px 13px; border-radius: 8px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 14.5px; color: var(--text-soft); transition: .14s;
}
.check__opt:hover { border-color: var(--text-dim); color: var(--text); }
.check__opt.is-right { border-color: var(--c-ok); background: var(--c-ok-dim); color: var(--text); }
.check__opt.is-wrong { border-color: var(--c-loss); background: var(--c-loss-dim); color: var(--text); }
.check__why {
  display: none; padding: 0 18px 16px 50px;
  font-size: 14.5px; color: var(--text-soft); line-height: 1.55;
}
.check__why.is-open { display: block; }

/* ---------- 14. Project / steps / resources ------------------------------- */

.project {
  margin: 2.4em auto; padding: 22px 24px;
  border-radius: var(--r-lg);
  border: 1px solid color-mix(in oklab, var(--c-ok) 30%, var(--line));
  background: linear-gradient(160deg, color-mix(in oklab, var(--c-ok-dim) 60%, var(--surface)), var(--surface));
}
.project__label {
  font: 620 10.5px/1 var(--mono); letter-spacing: .11em; text-transform: uppercase;
  color: var(--c-ok); margin-bottom: 9px; display: block;
}
.project h3 { margin: 0 0 10px; font-size: 20px; }
.project__grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin: 16px 0 4px; }
.project__stat {
  background: color-mix(in oklab, var(--bg) 45%, transparent);
  border: 1px solid var(--line-soft); border-radius: var(--r); padding: 10px 12px;
}
.project__stat dt { font: 600 10px/1 var(--mono); letter-spacing: .09em; text-transform: uppercase; color: var(--text-dim); margin-bottom: 5px; }
.project__stat dd { margin: 0; font-size: 14px; font-weight: 560; }

.steps { counter-reset: s; margin: 1.6em auto; padding: 0; list-style: none; }
.steps > li {
  counter-increment: s; position: relative;
  padding-left: 38px; margin-bottom: 1.1em;
}
.steps > li::before {
  content: counter(s); position: absolute; left: 0; top: 1px;
  width: 25px; height: 25px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  font: 620 12px/24px var(--mono); text-align: center; color: var(--c-data);
}

.resources { margin: 1.6em auto; display: grid; gap: 9px; }
.res {
  display: flex; gap: 13px; align-items: flex-start;
  padding: 12px 15px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; color: inherit; transition: border-color .15s, transform .15s;
}
.res:hover { border-color: var(--c-data); transform: translateY(-1px); }
.res__kind {
  font: 620 9.5px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase;
  padding: 5px 7px; border-radius: 5px; flex: none; margin-top: 2px;
  background: var(--surface-3); color: var(--text-dim);
}
.res__kind[data-kind="paper"] { background: var(--c-grad-dim); color: var(--c-grad); }
.res__kind[data-kind="docs"]  { background: var(--c-data-dim); color: var(--c-data); }
.res__kind[data-kind="code"]  { background: var(--c-param-dim); color: var(--c-param); }
.res__kind[data-kind="course"]{ background: var(--c-ok-dim); color: var(--c-ok); }
.res__kind[data-kind="video"] { background: var(--c-loss-dim); color: var(--c-loss); }
.res__body { min-width: 0; }
.res__title { font-size: 14.5px; font-weight: 560; margin-bottom: 1px; }
.res__why { font-size: 13px; color: var(--text-dim); line-height: 1.45; }

/* ---------- 15. Tables / compare ----------------------------------------- */

.table-wrap { overflow-x: auto; margin: 1.7em auto; max-width: min(1020px, 100%); }
table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th {
  font: 620 10.5px/1.4 var(--mono); letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-dim); border-bottom-color: var(--line); white-space: nowrap;
}
tbody tr:hover { background: var(--surface); }
td code, th code { font-size: .84em; white-space: nowrap; word-break: normal; }
.num { font-family: var(--mono); font-size: .92em; white-space: nowrap; }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 1.8em auto; }
.compare__col { padding: 16px 18px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); }
.compare__col h4 { margin: 0 0 9px; font-size: 15px; color: var(--text); }
.compare__col ul { margin: 0; padding-left: 1.1em; font-size: 14.5px; color: var(--text-soft); }
.compare__col--a { border-top: 2px solid var(--c-data); }
.compare__col--b { border-top: 2px solid var(--c-param); }

/* ---------- 16. Right rail (on this page) -------------------------------- */

/* The grid uses align-items:start, which would size this column to its own
   content. A sticky child can only travel inside its parent, so the column
   must stretch to the height of the article or the list scrolls away. */
.toc-rail { align-self: stretch; }

.toc {
  position: sticky; top: calc(var(--topbar) + 22px);
  max-height: calc(100vh - var(--topbar) - 44px); overflow-y: auto;
  padding: 4px 20px 40px 4px; font-size: 13.5px;
}
.toc__label {
  font: 620 10.5px/1 var(--mono); letter-spacing: .11em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 12px; display: block;
}
.toc a {
  display: block; padding: 4px 0 4px 12px;
  border-left: 2px solid var(--line-soft);
  color: var(--text-dim); text-decoration: none; line-height: 1.4;
  transition: color .15s, border-color .15s;
}
.toc a:hover { color: var(--text); }
.toc a.is-active { color: var(--text); border-left-color: var(--c-data); }
.toc a.lvl-3 { padding-left: 24px; font-size: 12.8px; }

/* ---------- 17. Lesson footer nav ---------------------------------------- */

.lesson-foot {
  max-width: var(--measure); margin: 60px auto 0;
  border-top: 1px solid var(--line-soft); padding-top: 28px;
}
.done-btn {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  width: 100%; padding: 13px; margin-bottom: 22px;
  border-radius: var(--r); cursor: pointer;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 15px; font-weight: 560; color: var(--text-soft);
  transition: .15s;
}
.done-btn:hover { border-color: var(--c-ok); color: var(--text); }
.done-btn.is-done { background: var(--c-ok-dim); border-color: var(--c-ok); color: var(--text); }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pager a {
  display: block; padding: 15px 17px; border-radius: var(--r);
  border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; color: inherit; transition: border-color .15s;
}
.pager a:hover { border-color: var(--c-data); }
.pager__dir { font: 620 10px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--text-dim); }
.pager__title { font-size: 15px; font-weight: 560; margin-top: 6px; }
.pager a:last-child { text-align: right; }
.pager__empty { visibility: hidden; }

/* ---------- 18. Home page ------------------------------------------------ */

.hero { padding: 70px 0 40px; max-width: 880px; margin-inline: auto; }
.hero h1 { font-size: clamp(38px, 6.4vw, 68px); letter-spacing: -.038em; margin-bottom: 20px; }
.hero h1 .grad {
  background: linear-gradient(110deg, var(--c-data), var(--c-param) 50%, var(--c-grad));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero__sub { font-size: clamp(17px, 2.2vw, 21px); color: var(--text-soft); max-width: 62ch; line-height: 1.55; }
.hero__cta { display: flex; flex-wrap: wrap; gap: 11px; margin-top: 32px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 19px; border-radius: 10px; cursor: pointer;
  text-decoration: none; font-size: 15px; font-weight: 560;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  transition: .15s;
}
.btn:hover { border-color: var(--text-dim); }
.btn--primary { background: var(--c-data); border-color: var(--c-data); color: var(--accent-ink); }
.btn--primary:hover { background: color-mix(in oklab, var(--c-data) 86%, white); border-color: transparent; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; margin: 46px auto; background: var(--line-soft); border: 1px solid var(--line-soft); border-radius: var(--r-lg); overflow: hidden; max-width: 1020px; }
.fact { background: var(--bg); padding: 20px 22px; }
.fact__n { font: 700 27px/1 var(--mono); letter-spacing: -.03em; color: var(--text); }
.fact__l { font-size: 13px; color: var(--text-dim); margin-top: 6px; }

.part-head { max-width: 1020px; margin: 60px auto 18px; display: flex; align-items: baseline; gap: 14px; }
.part-head__n { font: 700 12px/1 var(--mono); letter-spacing: .1em; color: var(--c-data); }
.part-head h2 { margin: 0; font-size: 23px; padding: 0; }
.part-head p { margin: 0 0 0 auto; font-size: 14px; color: var(--text-dim); text-align: right; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(266px, 1fr)); gap: 13px; max-width: 1020px; margin-inline: auto; }
.card {
  display: flex; flex-direction: column;
  padding: 19px 20px 17px; border-radius: var(--r-lg);
  border: 1px solid var(--line); background: var(--surface);
  text-decoration: none; color: inherit;
  transition: border-color .18s, transform .18s, box-shadow .18s;
  position: relative; overflow: hidden;
}
.card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 2px;
  background: linear-gradient(90deg, var(--c-data), var(--c-param));
  transform: scaleX(0); transform-origin: left; transition: transform .3s ease;
}
.card:hover { border-color: var(--text-dim); transform: translateY(-2px); box-shadow: var(--shadow-2); }
.card:hover::before { transform: scaleX(1); }
.card__n { font: 700 12px/1 var(--mono); color: var(--text-dim); letter-spacing: .04em; }
.card__t { font-size: 17px; font-weight: 600; margin: 11px 0 7px; letter-spacing: -.015em; line-height: 1.25; }
.card__d { font-size: 14px; color: var(--text-dim); line-height: 1.5; flex: 1; }
.card__f { margin-top: 15px; padding-top: 12px; border-top: 1px solid var(--line-soft); font-size: 12.5px; color: var(--text-dim); display: flex; gap: 10px; align-items: center; }
.card.is-done .card__n { color: var(--c-ok); }
.card.is-done .card__n::after { content: " ✓"; }

/* ---------- 18b. Narrated walkthrough ------------------------------------ */

/* the invitation on the lesson page */
.watch {
  display: flex; align-items: center; gap: 16px;
  margin: 26px auto 0; padding: 16px 20px;
  max-width: var(--measure);
  border-radius: var(--r-lg); cursor: pointer;
  border: 1px solid color-mix(in oklab, var(--c-data) 34%, var(--line));
  background: linear-gradient(120deg, color-mix(in oklab, var(--c-data-dim) 65%, var(--surface)), var(--surface));
  transition: border-color .18s, transform .18s;
}
.watch:hover { border-color: var(--c-data); transform: translateY(-1px); }
.watch__go {
  flex: none; width: 46px; height: 46px; border-radius: 50%;
  border: 0; cursor: pointer;
  background: var(--c-data); color: var(--accent-ink);
  display: grid; place-items: center;
}
.watch__go svg { width: 17px; height: 17px; margin-left: 2px; }
.watch__body { flex: 1; min-width: 0; }
.watch__label {
  font: 620 10.5px/1 var(--mono); letter-spacing: .11em; text-transform: uppercase;
  color: var(--c-data); display: block; margin-bottom: 5px;
}
.watch__desc { margin: 0; font-size: 14.5px; color: var(--text-soft); line-height: 1.45; }
.watch__desc em { color: var(--text-dim); font-size: 13.5px; }
.watch__meta { flex: none; font: 500 12.5px/1 var(--mono); color: var(--text-dim); }

/* the cinema */
.film {
  position: fixed; inset: 0; z-index: 200;
  display: none; grid-template-rows: auto 1fr auto auto;
  background: color-mix(in oklab, var(--bg) 96%, black);
}
.film.is-open { display: grid; }
body.film-open { overflow: hidden; }

.film__bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--line-soft);
}
.film__badge {
  font: 620 10px/1 var(--mono); letter-spacing: .1em; text-transform: uppercase;
  color: var(--c-data); background: var(--c-data-dim); padding: 5px 8px; border-radius: 5px;
}
.film__title { font-size: 14.5px; font-weight: 600; }
.film__spacer { flex: 1; }
.film__x {
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text-soft);
  display: grid; place-items: center;
}
.film__x:hover { background: var(--surface-3); color: var(--text); }
.film__x svg { width: 15px; height: 15px; }

.film__stage {
  display: grid; place-items: center;
  padding: 20px 26px; min-height: 0; overflow: hidden;
}
/* a figure while it is on the cinema stage */
.scene.is-filming {
  margin: 0; width: 100%; max-width: 1080px;
  border: 0; background: none; box-shadow: none;
}
.scene.is-filming .scene__head,
.scene.is-filming .scene__foot,
.scene.is-filming .rm-notice { display: none; }
.scene.is-filming .scene__stage { background: none; padding: 0; }
.scene.is-filming .scene__stage > svg { max-width: min(1080px, 100%); }

.film__cap {
  padding: 4px 30px 16px;
  max-width: 940px; margin: 0 auto; width: 100%;
  font-size: clamp(17px, 2.1vw, 23px); line-height: 1.5;
  text-align: center;
  min-height: 3.1em;
}
/* One word per span so the highlight can track the voice. Unspoken words
   stay legible but recede; the word being said is the bright one. */
.cap-w {
  color: var(--text-dim);
  transition: color .12s linear;
}
.cap-w.is-said { color: var(--text-soft); }
.cap-w.is-now { color: var(--text); }
.cap-w--em { font-weight: 640; }
.cap-w--em.is-said { color: color-mix(in oklab, var(--c-data) 70%, var(--text-soft)); }
.cap-w--em.is-now { color: var(--c-data); }
.cap-w--kw { font-family: var(--mono); font-size: .9em; }

/* title and end cards */
.film__card {
  text-align: center; max-width: 760px; padding: 20px;
}
.film__card-kicker {
  display: block; font: 620 11px/1 var(--mono); letter-spacing: .13em;
  text-transform: uppercase; color: var(--c-data); margin-bottom: 18px;
}
.film__card-num {
  display: block; font: 700 clamp(56px, 11vw, 108px)/1 var(--mono);
  letter-spacing: -.05em; margin-bottom: 6px;
  background: linear-gradient(140deg, var(--c-data), var(--c-param));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.film__card-title {
  margin: 0 0 14px; font-size: clamp(26px, 4.4vw, 44px);
  letter-spacing: -.028em; line-height: 1.12;
}
.film__card-sub { margin: 0; font-size: 16px; color: var(--text-soft); }
.film__card-sub b { color: var(--text); }
.film__card-next {
  margin: 22px 0 0; padding-top: 16px; font-size: 15px; color: var(--text-dim);
  border-top: 1px solid var(--line-soft);
}

.film__ui {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px 16px; border-top: 1px solid var(--line-soft);
  background: var(--bg-soft);
}
.film__btn {
  width: 36px; height: 36px; border-radius: 9px; cursor: pointer; flex: none;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text-soft);
  display: grid; place-items: center;
}
.film__btn:hover { background: var(--surface-3); color: var(--text); }
.film__btn svg { width: 15px; height: 15px; }
.film__btn--main { background: var(--c-data); border-color: var(--c-data); color: var(--accent-ink); width: 44px; height: 44px; }
.film__btn--main:hover { background: color-mix(in oklab, var(--c-data) 86%, white); color: var(--accent-ink); }
.film__btn--cc { opacity: .45; }
.film__btn--cc.is-on { opacity: 1; color: var(--c-data); border-color: color-mix(in oklab, var(--c-data) 40%, var(--line)); }
.film__time { font: 500 12.5px/1 var(--mono); color: var(--text-dim); flex: none; min-width: 40px; }
/* The visible groove is thin, but the clickable area must not be: a 6px-high
   target is very hard to hit. The padding grows the hit area to 22px while
   background-clip keeps the groove looking slim. */
.film__track {
  flex: 1; height: 6px; box-sizing: content-box;
  padding: 8px 0; margin: -8px 0;
  border-radius: 99px; background: var(--surface-3);
  background-clip: content-box;
  cursor: pointer; position: relative;
}
.film__track:hover { background-color: color-mix(in oklab, var(--c-data) 25%, var(--surface-3)); }
.film__fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--c-data), var(--c-ok)); border-radius: 99px; }

/* the transcript on the page */
.transcript {
  max-width: var(--measure); margin: 2.4em auto;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
}
.transcript > summary {
  cursor: pointer; padding: 14px 18px; font-size: 15px; font-weight: 560;
  list-style: none;
}
.transcript > summary::-webkit-details-marker { display: none; }
.transcript > summary::before { content: "▸ "; color: var(--text-dim); }
.transcript[open] > summary::before { content: "▾ "; }
.transcript__list { margin: 0; padding: 0 10px 12px; list-style: none; }
.transcript__list button {
  display: flex; gap: 14px; width: 100%; text-align: left;
  background: none; border: 0; cursor: pointer;
  padding: 7px 10px; border-radius: 7px; color: var(--text-soft);
  font-size: 14.5px; line-height: 1.5;
}
.transcript__list button:hover { background: var(--surface-2); color: var(--text); }
.transcript__t { font: 500 12px/1.6 var(--mono); color: var(--c-data); flex: none; }
.transcript__x b, .transcript__x strong { color: var(--text); }

@media (max-width: 700px) {
  .watch { flex-wrap: wrap; }
  .watch__meta { width: 100%; }
  .film__cap { font-size: 15.5px; padding-inline: 16px; min-height: 5.4em; }
  .film__ui { flex-wrap: wrap; }
  .film__track { order: 5; flex-basis: 100%; }
}

/* ---------- 19. Utility --------------------------------------------------- */

.center { text-align: center; }
.muted { color: var(--text-dim); }
.small { font-size: 13.5px; }
.mt-0 { margin-top: 0; }
.nowrap { white-space: nowrap; }
.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;
}

/* ---------- 20. Responsive ------------------------------------------------ */

@media (max-width: 1260px) {
  .shell--wide { grid-template-columns: var(--rail) minmax(0, 1fr); }
  .toc-rail { display: none; }
}

@media (max-width: 900px) {
  body { font-size: 16.5px; }
  .shell, .shell--wide { grid-template-columns: minmax(0, 1fr); }
  .menu-toggle { display: inline-flex; }
  .rail {
    position: fixed; top: var(--topbar); left: 0; bottom: 0; width: min(310px, 84vw);
    background: var(--bg); z-index: 55; height: auto;
    transform: translateX(-102%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
    box-shadow: var(--shadow-2);
  }
  .rail.is-open { transform: none; }
  .scrim {
    position: fixed; inset: var(--topbar) 0 0 0; z-index: 54;
    background: rgb(0 0 0 / .5); opacity: 0; pointer-events: none; transition: opacity .28s;
  }
  .scrim.is-open { opacity: 1; pointer-events: auto; }
  .main { padding: 0 20px 90px; }
  .compare { grid-template-columns: 1fr; }
  .tb-progress__track { display: none; }
  .scene__foot { gap: 10px; }
  .scene__caption { flex-basis: 100%; min-height: 0; }
  .part-head p { display: none; }
}

@media (max-width: 560px) {
  .pager { grid-template-columns: 1fr; }
  .pager a:last-child { text-align: left; }
  .scene__stage { padding: 16px 10px; }
  .hero { padding: 44px 0 28px; }
}

/* ---------- 21. Motion preferences ---------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

.rm-notice {
  display: none;
  font-size: 12.5px; color: var(--text-dim);
  padding: 8px 18px; border-top: 1px dashed var(--line);
  background: var(--bg-soft);
}
html[data-reduced-motion="true"] .rm-notice { display: block; }

/* print */
@media print {
  .topbar, .rail, .toc-rail, .scene__controls, .lesson-foot, .scrim { display: none !important; }
  .shell, .shell--wide { grid-template-columns: 1fr; }
  body { background: #fff; color: #000; font-size: 11pt; }
}
