:root {
  color-scheme: light;
  --paper: #f7f8f5;
  --surface: #ffffff;
  --ink: #17232b;
  --muted: #5a6870;
  --rule: #cdd5d4;
  --teal: #087e78;
  --teal-soft: #e3f2ef;
  --coral: #c54f3f;
  --coral-soft: #fae9e5;
  --gold: #a96c00;
  --gold-soft: #fff3d6;
  --blue: #315ea8;
  --blue-soft: #e8eef9;
  --success: #276b45;
  --danger: #a2372b;
  --shadow: 0 8px 24px rgba(23, 35, 43, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.65;
}

a { color: var(--blue); text-underline-offset: 0.18em; }
a:hover { color: var(--coral); }

main, .site-header, .site-footer {
  width: min(100% - 32px, 1040px);
  margin-inline: auto;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 64px;
  border-bottom: 1px solid var(--rule);
}

.brand {
  color: var(--ink);
  font-weight: 760;
  text-decoration: none;
}

.course-link { font-size: 0.9rem; }

.hero {
  padding: 64px 0 44px;
  border-bottom: 1px solid var(--rule);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--coral);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1, h2, h3 { line-height: 1.16; letter-spacing: 0; }
h1 { max-width: 800px; margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 3rem; font-weight: 650; }
h2 { margin: 52px 0 18px; font-size: 1.65rem; }
h3 { margin: 30px 0 10px; font-size: 1.05rem; }
p { max-width: 760px; }
.lede { max-width: 760px; margin: 20px 0 0; color: var(--muted); font-size: 1.15rem; }

.lesson-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 22px;
  color: var(--muted);
  font-size: 0.9rem;
}

.goal {
  margin: 30px 0;
  padding: 18px 20px;
  border-left: 4px solid var(--teal);
  background: var(--teal-soft);
}

.equation {
  overflow-x: auto;
  margin: 24px 0;
  padding: 22px;
  border-block: 1px solid var(--rule);
  background: var(--surface);
  font-family: "Times New Roman", Georgia, serif;
  font-size: 1.3rem;
  text-align: center;
  white-space: nowrap;
}

.equation .label {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.78rem;
}

mjx-container[jax="CHTML"][display="true"] {
  margin: 0.35em 0 !important;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.15em 0;
}

.two-col, .three-col {
  display: grid;
  gap: 24px;
  margin: 26px 0;
}
.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.three-col { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.panel, .quiz, .worked-example {
  padding: 22px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--surface);
}

.panel h3, .quiz h3, .worked-example h3 { margin-top: 0; }
.panel.teal { border-top: 4px solid var(--teal); }
.panel.coral { border-top: 4px solid var(--coral); }
.panel.gold { border-top: 4px solid var(--gold); }

.callout {
  margin: 28px 0;
  padding: 18px 20px;
  border: 1px solid var(--gold);
  border-radius: 6px;
  background: var(--gold-soft);
}

.callout strong { color: #714800; }

.course-toolkit {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 42px;
  margin: 64px 0 24px;
  padding: 32px 0;
  border-block: 1px solid var(--rule);
}

.toolkit-intro h2 {
  margin: 0 0 16px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 650;
}

.toolkit-intro p { margin: 12px 0 0; }

.toolkit-references {
  align-self: start;
  border-left: 1px solid var(--rule);
  padding-left: 32px;
}

.toolkit-references h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.toolkit-references a {
  display: block;
  padding: 15px 0;
  border-bottom: 1px solid var(--rule);
  color: var(--ink);
  text-decoration: none;
}

.toolkit-references a:last-child { border-bottom: 0; }
.toolkit-references a:hover span { color: var(--coral); }

.toolkit-references span {
  display: block;
  color: var(--blue);
  font-weight: 760;
}

.toolkit-references small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.reference-sequence { margin-top: 28px; }

.reference-stepper {
  position: sticky;
  z-index: 20;
  top: 0;
  margin-bottom: 34px;
  border-block: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(12px);
}

.reference-step-tabs {
  display: grid;
  grid-template-columns: repeat(var(--reference-step-count, 5), minmax(0, 1fr));
  border-bottom: 1px solid var(--rule);
}

.reference-step-tabs:has(> :nth-child(4):last-child) { --reference-step-count: 4; }

.reference-step-tabs button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 58px;
  padding: 10px 12px;
  border: 0;
  border-right: 1px solid var(--rule);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.reference-step-tabs button:last-child { border-right: 0; }
.reference-step-tabs button:hover { background: var(--surface); }
.reference-step-tabs button[aria-current="step"] { background: var(--teal-soft); color: var(--ink); }
.reference-step-tabs b { color: var(--coral); font-size: 0.72rem; }
.reference-step-tabs span { overflow: hidden; font-size: 0.78rem; text-overflow: ellipsis; white-space: nowrap; }

.reference-step-controls {
  display: grid;
  grid-template-columns: auto minmax(110px, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
}

.reference-step-controls button {
  min-height: 40px;
  padding: 7px 12px;
  text-align: center;
}

.reference-step-controls output { color: var(--muted); font-size: 0.82rem; text-align: center; }
.reference-step-controls [data-step-all] { color: var(--blue); }
.reference-step-controls [data-step-all][aria-pressed="true"] { background: var(--blue-soft); }

.reference-step {
  min-height: 390px;
  padding-bottom: 18px;
  scroll-margin-top: 160px;
}

.reference-step[hidden] { display: none; }
.reference-step > h2 { margin-top: 8px; }

.reference-step-kicker {
  margin: 0;
  color: var(--coral);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.code-checkpoint {
  margin: 34px 0;
  padding-left: 18px;
  border-left: 4px solid var(--teal);
}
.code-checkpoint > h2 { margin: 0 0 8px; }
.code-checkpoint > p { max-width: 76ch; }
.code-checkpoint details { margin-top: 14px; }
.code-checkpoint summary { color: var(--ink); cursor: pointer; font-weight: 760; }
.code-checkpoint summary::marker { color: var(--teal); }
.code-checkpoint pre,
.source-code {
  overflow-x: auto;
  margin: 14px 0 10px;
  padding: 18px;
  border: 1px solid #314142;
  border-radius: 4px;
  background: #172224;
  color: #edf6f2;
  font: 0.82rem/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  tab-size: 4;
  white-space: pre;
}
.code-checkpoint code,
.source-code code { font: inherit; }
.code-checkpoint .hljs,
.source-code .hljs { padding: 0; background: transparent; }
.code-prompt { margin: 10px 0 0; color: var(--muted); font-size: 0.9rem; }
.code-lineage {
  margin: 18px 0;
  padding: 14px 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.88rem;
}
.code-lineage a { font-weight: 720; }
.table-scroll { max-width: 100%; overflow-x: auto; }
.table-scroll table { min-width: 680px; }

.diagram {
  min-height: 280px;
  margin: 28px 0;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.diagram canvas { display: block; width: 100%; height: 300px; }

.controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 20px;
  align-items: center;
  padding: 18px 20px;
  border-top: 1px solid var(--rule);
}

input[type="range"] { width: 100%; accent-color: var(--teal); }

.readout {
  min-width: 104px;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  text-align: right;
}

.swatch {
  display: inline-block;
  width: 34px;
  height: 12px;
  border: 1px solid rgba(23, 35, 43, 0.22);
  border-radius: 2px;
}
.swatch.blue { background: var(--blue); }
.swatch.coral { background: var(--coral); }

.rope-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  margin: 0;
  padding: 16px 20px;
  border-top: 1px solid var(--rule);
  font-variant-numeric: tabular-nums;
}

.rope-readout span { white-space: nowrap; }

.quiz { margin: 32px 0; border-left: 4px solid var(--blue); }
.choices { display: grid; gap: 10px; margin-top: 16px; }

button, .button {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid #87939a;
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 680;
  text-align: left;
  cursor: pointer;
}

button:hover, .button:hover { border-color: var(--blue); background: var(--blue-soft); }
button.correct { border-color: var(--success); background: #e5f3e9; color: var(--success); }
button.incorrect { border-color: var(--danger); background: var(--coral-soft); color: var(--danger); }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid #e0a422; outline-offset: 2px; }

.feedback { min-height: 1.7em; margin: 12px 0 0; font-weight: 700; }
.feedback.ok { color: var(--success); }
.feedback.no { color: var(--danger); }

.steps { margin: 28px 0; padding: 0; counter-reset: lesson-step; list-style: none; }
.steps li { position: relative; margin: 0; padding: 18px 0 18px 54px; border-top: 1px solid var(--rule); }
.steps li::before {
  position: absolute;
  top: 18px;
  left: 4px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--ink);
  color: white;
  content: counter(lesson-step);
  counter-increment: lesson-step;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 32px;
  text-align: center;
}

table { width: 100%; margin: 24px 0; border-collapse: collapse; background: var(--surface); }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--rule); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; }

.course-table td:first-child { width: 64px; color: var(--coral); font-weight: 800; }
.course-table td:last-child { width: 110px; color: var(--muted); }

.source {
  margin: 42px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.88rem;
}

.exercises {
  margin: 44px 0;
  padding: 4px 22px 22px;
  border-left: 4px solid var(--coral);
  background: var(--coral-soft);
}

.exercises h2 { margin-top: 24px; }
.exercises li { margin: 10px 0; padding-left: 4px; }

details {
  margin-top: 22px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--surface);
}

summary {
  padding: 13px 16px;
  font-weight: 760;
  cursor: pointer;
}

details > ol, details > div, details > p { margin: 0; padding: 4px 36px 20px; }

.completion { display: flex; align-items: center; gap: 10px; margin: 36px 0; font-weight: 700; }
.completion input { width: 20px; height: 20px; accent-color: var(--success); }

.lesson-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 48px 0;
  padding-top: 24px;
  border-top: 1px solid var(--rule);
}
.lesson-nav a { padding: 14px 0; font-weight: 720; text-decoration: none; }
.lesson-nav a:last-child { text-align: right; }

.site-footer { padding: 24px 0 48px; border-top: 1px solid var(--rule); color: var(--muted); font-size: 0.88rem; }
.small { color: var(--muted); font-size: 0.9rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.accent { color: var(--coral); }

.shape-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 22px 0;
}

.shape-chip {
  display: inline-grid;
  min-height: 42px;
  place-items: center;
  padding: 8px 12px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--surface);
  font-weight: 720;
}

.shape-arrow { color: var(--coral); font-weight: 800; }
.masked { background: #ecefed; color: var(--muted); }
progress { width: min(180px, 100%); height: 12px; accent-color: var(--teal); }

.course-figure {
  margin: 32px 0;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.course-figure img {
  display: block;
  width: 100%;
  height: auto;
  background: white;
}

.course-figure figcaption {
  padding: 12px 16px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.84rem;
}

.visual-reference > summary { color: var(--blue); }
.visual-reference .course-figure { margin: 0; border: 0; border-top: 1px solid var(--rule); border-radius: 0; box-shadow: none; }

.token-shift {
  display: grid;
  gap: 12px;
  margin: 24px 0;
}

.token-shift-row {
  display: grid;
  grid-template-columns: 90px repeat(5, minmax(0, 1fr));
  gap: 7px;
  align-items: center;
}

.token-shift-row > strong { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; }
.token-shift-row > span { min-width: 0; padding: 9px 5px; border: 1px solid var(--rule); background: var(--surface); font-size: 0.82rem; text-align: center; }
.token-shift-row.targets > span { border-color: #d4a744; background: var(--gold-soft); }

.sampling-bars { display: grid; gap: 10px; padding: 20px; }
.sampling-row { display: grid; grid-template-columns: 62px minmax(0, 1fr) 64px; gap: 10px; align-items: center; font-size: 0.82rem; }
.sampling-track { height: 16px; border: 1px solid var(--rule); background: #eef1ef; }
.sampling-fill { display: block; width: var(--probability); height: 100%; background: var(--blue); transition: width 160ms ease; }
.sampling-row:first-child .sampling-fill { background: var(--teal); }

.block-pipeline {
  margin: 28px 0;
  padding: 0;
  list-style: none;
}

.block-pipeline li {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px 0;
  border-top: 1px solid var(--rule);
}

.block-pipeline .step-no {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: white;
  font-weight: 800;
}

.nn-viz {
  overflow: hidden;
  min-height: 0;
}

.viz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--rule);
}

.viz-header h3 { margin: 0; }

.viz-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.viz-actions button {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.84rem;
}

.viz-actions button[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: white;
}

.viz-body { padding: 20px; }

.viz-caption {
  max-width: none;
  margin: 0;
  padding: 14px 20px;
  border-top: 1px solid var(--rule);
  background: #f3f5f3;
  color: var(--muted);
  font-size: 0.9rem;
}

.tensor-axis-labels {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
}

.tensor-axis-labels span:last-child { text-align: center; }

.tensor-grid { display: grid; gap: 7px; }

.tensor-row {
  display: grid;
  grid-template-columns: 64px repeat(6, minmax(36px, 1fr));
  gap: 6px;
  width: 100%;
  min-height: 46px;
  padding: 5px;
  border-color: transparent;
  text-align: center;
}

.tensor-row .token-label {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 760;
}

.tensor-cell, .feature-cell {
  display: grid;
  min-width: 0;
  min-height: 34px;
  place-items: center;
  border: 1px solid #aeb9b8;
  border-radius: 3px;
  background: var(--teal-soft);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.tensor-row[aria-pressed="true"] { border-color: var(--teal); background: #eef7f5; }
.tensor-row[aria-pressed="true"] .tensor-cell { border-color: var(--teal); background: #cce9e4; }

.vector-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.vector-plot h4 { margin: 0 0 12px; font-size: 0.88rem; }
.value-bars { display: grid; gap: 10px; }

.value-bar {
  display: grid;
  grid-template-columns: 28px minmax(120px, 1fr) 58px;
  gap: 8px;
  align-items: center;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.bar-track {
  position: relative;
  height: 22px;
  border: 1px solid var(--rule);
  background: #f4f6f4;
}

.bar-track::after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 1px solid #748188;
  content: "";
}

.bar-fill {
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: calc(var(--magnitude) * 50%);
  background: var(--blue);
}

.bar-fill.positive { left: 50%; }
.bar-fill.negative { right: 50%; background: var(--coral); }

.projection-flow { display: grid; gap: 16px; }
.projection-input, .projection-row { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: 12px; align-items: center; }
.projection-label { font-size: 0.82rem; font-weight: 800; }
.feature-strip { display: flex; flex-wrap: wrap; gap: 6px; }
.feature-strip .feature-cell { width: 50px; }

.head-group {
  display: flex;
  gap: 5px;
  padding: 5px;
  border: 2px solid var(--blue);
  border-radius: 4px;
}

.head-group:nth-child(2) { border-color: var(--coral); }
.head-tag { align-self: center; margin: 0 2px; color: var(--muted); font-size: 0.72rem; font-weight: 800; }

.head-visuals { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.head-visual { min-width: 0; }
.head-visual h4 { margin: 0 0 8px; }
.token-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.token-strip button { min-height: 38px; padding: 5px; text-align: center; font-size: 0.78rem; }
.token-strip button[aria-pressed="true"] { border-color: var(--blue); background: var(--blue-soft); }

.attention-mini-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(30px, 1fr));
  gap: 4px;
  margin-top: 10px;
}

.attention-mini-cell {
  display: grid;
  aspect-ratio: 1.35;
  place-items: center;
  border: 1px solid rgba(23, 35, 43, 0.12);
  background: color-mix(in srgb, var(--blue) calc(var(--weight) * 75%), white);
  color: var(--ink);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
}

.attention-mini-cell.inactive { opacity: 0.22; }
.head-visual:nth-child(2) .attention-mini-cell { background: color-mix(in srgb, var(--coral) calc(var(--weight) * 75%), white); }

.residual-flow {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.vector-node { min-width: 0; }
.vector-node strong { display: block; margin-bottom: 8px; font-size: 0.8rem; }
.vector-cells { display: grid; grid-template-columns: repeat(3, minmax(42px, 1fr)); gap: 5px; }
.math-join { color: var(--coral); font-size: 1.6rem; font-weight: 800; }

.swiglu-flow { display: grid; gap: 10px; }
.swiglu-stage { display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 12px; align-items: center; }
.swiglu-stage strong { font-size: 0.8rem; }
.pair-values { display: grid; grid-template-columns: repeat(2, minmax(56px, 1fr)); gap: 6px; }
.pair-values span { padding: 8px; border: 1px solid var(--rule); background: var(--surface); text-align: center; font-variant-numeric: tabular-nums; }
.swiglu-stage.gate .pair-values span { background: var(--gold-soft); }
.swiglu-stage.product .pair-values span { background: var(--teal-soft); }

.block-step-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 5px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--rule);
}

.block-step-strip button { min-height: 42px; padding: 5px; text-align: center; }
.block-step-strip button[aria-current="step"] { border-color: var(--coral); background: var(--coral-soft); color: var(--danger); }

.block-stage-visual {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
  padding: 24px 20px;
}

.stage-tensor, .stage-operation {
  display: grid;
  min-height: 150px;
  place-items: center;
  padding: 16px;
  border: 1px solid var(--rule);
  background: var(--surface);
  text-align: center;
}

.stage-operation { border-color: var(--coral); background: var(--coral-soft); font-weight: 800; }
.stage-tensor strong { display: block; }
.stage-tensor span { display: block; margin-top: 8px; color: var(--muted); font-size: 0.82rem; }

.stepper-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px 20px;
}

.stepper-controls output { color: var(--muted); font-size: 0.9rem; text-align: center; }

.lesson-map {
  overflow: hidden;
  margin: 34px 0 42px;
  border: 1px solid var(--rule);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.lesson-map-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--rule);
}
.lesson-map-header h2 { margin: 0; font-size: 1.15rem; }
.lesson-map-header span { color: var(--muted); font-size: 0.76rem; font-weight: 750; text-transform: uppercase; }
.lesson-map-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(220px, 0.8fr); }
.lesson-map-stages { min-width: 0; }

.lesson-map-stage {
  position: relative;
  display: grid;
  grid-template-columns: 36px minmax(150px, 0.9fr) minmax(210px, 1.25fr);
  gap: 12px;
  align-items: center;
  min-height: 94px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--rule);
}
.lesson-map-stage:last-child { border-bottom: 0; }
.lesson-map-stage::after {
  position: absolute;
  bottom: -12px;
  left: 27px;
  z-index: 2;
  color: var(--muted);
  content: "↓";
  font-weight: 900;
}
.lesson-map-stage:last-child::after { content: none; }

.lesson-map-number {
  display: grid;
  width: 29px;
  height: 29px;
  place-items: center;
  border-radius: 50%;
  background: var(--map-color, var(--blue));
  color: white;
  font-size: 0.75rem;
  font-weight: 850;
}
.lesson-map-copy h3 { margin: 0 0 4px; font-size: 0.9rem; }
.lesson-map-copy p { margin: 0; color: var(--muted); font-size: 0.72rem; line-height: 1.35; }
.lesson-map-formula { margin-top: 4px; font-size: 0.8rem; }

.lesson-map-aside {
  display: grid;
  align-content: center;
  padding: 20px;
  border-left: 1px solid var(--rule);
  border-top: 4px solid var(--coral);
  background: #f7f8f6;
}
.lesson-map-aside strong { font-size: 0.74rem; text-transform: uppercase; }
.lesson-map-aside p { margin: 8px 0 18px; font-size: 0.82rem; line-height: 1.5; }
.lesson-map-chain { display: grid; gap: 5px; }
.lesson-map-chain span { padding: 7px 8px; border: 1px solid var(--rule); background: var(--surface); font-size: 0.7rem; font-weight: 750; text-align: center; }
.lesson-map-chain i { color: var(--coral); font-style: normal; font-weight: 900; text-align: center; }

.map-schematic { min-width: 0; }
.map-features, .map-pairs { display: flex; gap: 4px; align-items: center; }
.map-features span {
  display: block;
  width: 32px;
  height: 24px;
  border: 1px solid #9bacb2;
  background: var(--blue-soft);
}
.map-pairs b { display: flex; gap: 3px; padding: 4px; border: 2px solid var(--pair-color); }
.map-pairs b:nth-child(2) { --pair-color: var(--coral); }
.map-pairs b:nth-child(3) { --pair-color: var(--teal); }
.map-pairs span { width: 28px; height: 22px; background: color-mix(in srgb, var(--pair-color) 20%, white); }

.map-circle {
  position: relative;
  width: 72px;
  height: 72px;
  margin: auto;
  border: 1px solid #aab5b5;
  border-radius: 50%;
}
.map-circle::before, .map-circle::after { position: absolute; top: 50%; left: 50%; content: ""; transform-origin: left; }
.map-circle::before { width: 43%; border-top: 3px solid var(--blue); transform: rotate(-28deg); }
.map-circle::after { width: 5px; height: 5px; border-radius: 50%; background: var(--coral); transform: translate(-50%, -50%); }

.map-plane {
  position: relative;
  width: 90px;
  height: 66px;
  margin: auto;
  border-bottom: 1px solid var(--ink);
  border-left: 1px solid var(--ink);
}
.map-plane span { position: absolute; left: 58%; bottom: 55%; width: 8px; height: 8px; border-radius: 50%; background: var(--coral); }

.map-matrix { display: grid; grid-template-columns: 72px auto 46px; gap: 8px; align-items: center; justify-content: center; }
.map-matrix-grid { display: grid; grid-template-columns: repeat(2, 30px); gap: 3px; padding: 5px; border-inline: 2px solid var(--ink); }
.map-matrix-grid span { display: grid; height: 24px; place-items: center; background: var(--blue-soft); font-size: 0.64rem; }
.map-vector { display: grid; gap: 3px; }
.map-vector span { display: grid; width: 40px; height: 24px; place-items: center; border: 1px solid var(--rule); background: var(--teal-soft); font-size: 0.65rem; }

.map-attention { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.map-node { display: grid; width: 38px; height: 38px; place-items: center; border: 2px solid var(--blue); border-radius: 50%; font-size: 0.72rem; font-weight: 850; }
.map-node.key { border-color: var(--coral); }
.map-link { position: relative; border-top: 2px solid var(--teal); }
.map-link::after { position: absolute; top: -13px; right: 40%; content: "score"; color: var(--muted); font-size: 0.62rem; }

.map-frequency { display: flex; gap: 7px; align-items: end; height: 64px; }
.map-frequency span { width: 18%; height: var(--period); border: 2px solid var(--teal); border-top: 0; background: repeating-linear-gradient(0deg, transparent 0 6px, var(--teal-soft) 6px 10px); }
.map-distance { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: end; }
.map-distance b { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; background: var(--blue); color: white; }
.map-distance b:last-child { background: var(--coral); }
.map-distance span { padding-bottom: 5px; border-bottom: 2px dashed var(--teal); color: var(--muted); font-size: 0.66rem; text-align: center; }

.map-tensor { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; }
.map-tensor span { height: 18px; border: 1px solid #a7b2b2; background: var(--teal-soft); }
.map-tensor span:nth-child(n+7):nth-child(-n+12) { background: var(--blue-soft); }
.map-tensor span:nth-child(n+13) { background: var(--coral-soft); }
.map-branch { display: grid; grid-template-columns: auto repeat(3, 1fr); gap: 6px; align-items: center; }
.map-branch > b { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid var(--rule); }
.map-branch span { padding: 7px 3px; border-top: 3px solid var(--branch-color); background: #f4f6f4; font-size: 0.64rem; font-weight: 800; text-align: center; }
.map-branch span:nth-child(3) { --branch-color: var(--coral); }
.map-branch span:nth-child(4) { --branch-color: var(--teal); }

.map-mask { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.map-mask span {
  display: grid;
  aspect-ratio: 1.45;
  place-items: center;
  background: #c6e8e3;
  color: #075e59;
}
.map-mask span::after { content: "✓"; font-size: 0.78rem; font-weight: 900; }
.map-mask span.off {
  background: repeating-linear-gradient(135deg, #657270 0 7px, #74817f 7px 14px);
  color: #fff;
}
.map-mask span.off::after { content: "×"; }
.map-bars { display: flex; gap: 6px; align-items: end; height: 62px; border-bottom: 1px solid var(--muted); }
.map-bars span { width: 20%; height: var(--bar); background: var(--blue); }
.map-bars span:last-child { background: #d9dfdc; }
.map-heads { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.map-heads div { padding: 5px; border-top: 3px solid var(--head); background: #f4f6f4; }
.map-heads div:nth-child(2) { --head: var(--teal); }
.map-heads div:nth-child(3) { --head: var(--coral); }
.map-heads span { display: block; height: 12px; margin: 2px 0; background: color-mix(in srgb, var(--head) 20%, white); }

.map-sum { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: 5px; align-items: center; }
.map-sum span { padding: 8px 3px; border: 1px solid var(--rule); background: var(--blue-soft); font-size: 0.65rem; font-weight: 800; text-align: center; }
.map-sum span:last-child { background: var(--coral-soft); }
.map-sum b { color: var(--coral); }
.map-gate { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.map-gate span { padding: 8px; border: 1px solid var(--rule); background: var(--gold-soft); font-size: 0.65rem; text-align: center; }
.map-gate strong { grid-column: 1 / -1; padding: 7px; background: var(--teal-soft); font-size: 0.68rem; text-align: center; }
.map-block { display: flex; flex-wrap: wrap; gap: 4px; }
.map-block span { padding: 6px; border-top: 3px solid var(--step-color); background: #f4f6f4; font-size: 0.61rem; font-weight: 750; }
.map-block span:nth-child(2n) { --step-color: var(--teal); }
.map-block span:nth-child(3n) { --step-color: var(--coral); }

@media (max-width: 720px) {
  body { font-size: 16px; }
  main, .site-header, .site-footer { width: min(100% - 24px, 1040px); }
  .site-header { min-height: 56px; }
  .hero { padding: 42px 0 32px; }
  h1 { font-size: 2.25rem; }
  h2 { margin-top: 42px; font-size: 1.45rem; }
  .two-col, .three-col { grid-template-columns: 1fr; }
  .course-toolkit { grid-template-columns: 1fr; gap: 26px; margin-top: 48px; padding: 26px 0; }
  .toolkit-intro h2 { font-size: 1.65rem; }
  .toolkit-references { padding: 24px 0 0; border-top: 1px solid var(--rule); border-left: 0; }
  .reference-stepper { margin-inline: -12px; }
  .reference-step-tabs { display: flex; overflow-x: auto; scrollbar-width: thin; }
  .reference-step-tabs button { flex: 0 0 148px; }
  .reference-step-controls { grid-template-columns: auto minmax(80px, 1fr) auto; padding-inline: 8px; }
  .reference-step-controls [data-step-all] { grid-column: 1 / -1; }
  .reference-step { min-height: 0; scroll-margin-top: 190px; }
  .diagram canvas { height: 260px; }
  .equation { padding: 16px 10px; font-size: 1.05rem; }
  .controls { grid-template-columns: 1fr; }
  .readout { text-align: left; }
  .rope-readout { display: grid; grid-template-columns: 1fr; }
  .block-pipeline li { grid-template-columns: 36px minmax(0, 1fr); }
  .block-pipeline li > :last-child { grid-column: 2; }
  .viz-header { align-items: flex-start; flex-direction: column; }
  .tensor-axis-labels { grid-template-columns: 52px minmax(0, 1fr); }
  .tensor-row { grid-template-columns: 46px repeat(6, minmax(38px, 1fr)); overflow-x: auto; }
  .vector-compare, .head-visuals { grid-template-columns: 1fr; }
  .projection-input, .projection-row { grid-template-columns: 62px minmax(0, 1fr); }
  .residual-flow { grid-template-columns: 1fr; }
  .math-join { text-align: center; }
  .swiglu-stage { grid-template-columns: 96px minmax(0, 1fr); }
  .block-step-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .block-stage-visual { grid-template-columns: 1fr; }
  .stage-operation { min-height: 72px; }
  .lesson-map-grid { grid-template-columns: 1fr; }
  .lesson-map-aside { border-top: 1px solid var(--rule); border-left: 0; }
  .lesson-map-stage { grid-template-columns: 32px minmax(0, 1fr); }
  .map-schematic { grid-column: 2; }
  .token-shift { overflow-x: auto; }
  .token-shift-row { min-width: 560px; grid-template-columns: 80px repeat(5, minmax(76px, 1fr)); }
  th, td { padding: 10px 8px; }
  .course-table td:last-child { width: auto; }
}

@media print {
  body { background: white; color: black; font-size: 11pt; }
  .site-header, .site-footer, .lesson-nav, .completion, .controls, .quiz, .reference-stepper { display: none; }
  main { width: 100%; }
  .hero { padding-top: 0; }
  h1 { font-size: 25pt; }
  h2 { break-after: avoid; }
  .panel, .worked-example, .diagram, table { break-inside: avoid; box-shadow: none; }
  .reference-step[hidden] { display: block !important; }
  a { color: black; text-decoration: none; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 8pt; }
}
