:root {
  color-scheme: light;
  --bg: #FFF7F2;
  --surface: #FFFCFA;
  --raised: #F0E2E0;
  --line: #CFBBBF;
  --line-soft: #E7D9DB;
  --text: #283A53;
  --muted: #60576B;
  --dim: #6D597A;
  --accent: #355070;
  --earth: #6D597A;
  --positive: #E56B6F;
  --negative: #355070;
  --positive-ink: #A23B45;
  --negative-ink: #355070;
  --positive-soft: #F8DDE0;
  --negative-soft: #E4EAF1;
  --selected: #F2CBB6;
  --change: #EAAC8B;
  --change-ink: #355070;
  --change-soft: #F7D9C9;
  --neutral: #B56576;
  --neutral-dark: #6D597A;
  --header: #355070;
  --sidebar: #6D597A;
  --teal: var(--accent);
  --violet: var(--negative-ink);
  --orange: var(--earth);
  --gold: var(--change);
  --radius: 3px;
  font: 16px/1.5 Arial, Helvetica, sans-serif;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 20px; }
body { margin: 0; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1,h2,h3,h4,p { margin: 0; }
h1,h2,h3 { font-family: Georgia, 'Times New Roman', serif; font-weight: 400; }
h1 { color: var(--earth); font-size: clamp(32px,3vw,48px); line-height: 1.12; letter-spacing: -1.6px; max-width: 880px; }
h2 { font-size: 28px; letter-spacing: -.5px; }
h3 { font-size: 26px; line-height: 1.2; }
h4 { font-size: 16px; font-weight: 600; }
p { color: var(--muted); }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--teal); }
button,input,select { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { opacity: .45; cursor: not-allowed; }
button:hover:not(:disabled) { border-color: var(--text); }
button:focus-visible,a:focus-visible,input:focus-visible,select:focus-visible,summary:focus-visible,canvas:focus-visible { outline: 2px solid var(--violet); outline-offset: 4px; }
[hidden] { display: none !important; }
.site-header { height: 82px; padding: 0 34px; border-top: 4px solid var(--teal); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 48px; }
.brand { font: 600 25px/1 Georgia,serif; display: inline-flex; align-items: center; gap: 10px; letter-spacing: -.9px; white-space: nowrap; }
.brand img { width: 31px; height: 31px; }
.brand-comma,.brand-dot { color: var(--teal); }
.site-header nav { display: flex; align-items: center; gap: 25px; font-size: 14px; }
.site-header nav a { padding: 27px 0; }
.site-header nav a.active { color: var(--teal); box-shadow: 0 1px var(--teal); }
.header-note { margin-left: auto; color: var(--dim); font: italic 14px Georgia,serif; }
.book-layout { display: grid; grid-template-columns: 224px minmax(0,1fr); max-width: 1780px; margin: auto; }
.book-sidebar { border-right: 1px solid var(--line); padding: 34px 18px; position: sticky; top: 0; height: fit-content; max-height: 100vh; overflow-y: auto; }
.sidebar-label,.toc-group,.eyebrow,.context-label { font: 12px/1.5 'Courier New',monospace; letter-spacing: 1.2px; }
.sidebar-label { color: var(--dim); margin: 0 10px 20px; }
.overview-link,.notes-link { display: flex; justify-content: space-between; padding: 10px; font-size: 14px; }
.overview-link.active,.notes-link.active { color: var(--teal); background: var(--positive-soft); }
.notes-link { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 16px; }
.toc-group { color: var(--dim); font-size: 10px; margin: 26px 10px 9px; letter-spacing: .75px; }
.stage-nav { display: block; }
.stage-button { display: flex; gap: 12px; align-items: center; padding: 8px 10px; font-size: 14px; border-left: 2px solid transparent; }
.stage-button>span { font: 11px 'Courier New',monospace; color: var(--dim); }
.stage-button.selected { background: var(--positive-soft); color: var(--teal); border-left-color: var(--teal); }
.stage-button.selected>span { color: var(--teal); }
.sidebar-foot { margin: 30px 10px 0; font: italic 13px/1.65 Georgia,serif; color: var(--dim); }
main { padding: 34px clamp(20px,3vw,46px) 48px; min-width: 0; }
.intro { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 0 0 28px; border-bottom: 1px solid var(--line); }
.eyebrow { color: var(--teal); margin-bottom: 15px; font-size: 11px; }
.intro-copy { margin-top: 17px; font-size: 16px; line-height: 1.65; max-width: 790px; }
.button { background: var(--surface); border: 1px solid var(--line); border-radius: 2px; padding: 10px 14px; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 12px; }
.button.primary { background: var(--teal); color: #fff; border-color: var(--teal); }
.intro .button { flex-shrink: 0; }
.model-bar { display: flex; justify-content: space-between; gap: 18px; align-items: center; padding: 18px 0; }
.model-name,.model-switch { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; font-size: 13px; }
.tag { padding: 2px 5px; border: 1px solid var(--line); font: 11px 'Courier New',monospace; }
.model-name>.subtle { font-size: 12px; }
.model-switch>.subtle { font-size: 12px; }
.subtle { color: var(--muted); }
.small { font-size: 14px; }
.mono { font: 12px/1.5 'Courier New',monospace; }
.accuracy { color: var(--muted); font-size: 12px; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: 2px; padding: 2px; gap: 2px; background: var(--bg); }
.segmented button { padding: 5px 11px; border: 0; background: transparent; font-size: 13px; }
.segmented button.selected { background: var(--text); color: #fff; }
.lab-grid { display: grid; grid-template-columns: minmax(220px,1fr) minmax(355px,2fr) minmax(220px,1fr); gap: 16px; }
.panel { padding: 19px; border: 1px solid var(--line); background: var(--surface); min-width: 0; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-heading h2 { font-family: Arial,sans-serif; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; letter-spacing: -.3px; }
.section-number { color: var(--teal); font: 12px 'Courier New',monospace; }
.input-tabs { margin: 20px 0 16px; }
.input-tabs button { flex: 1; padding: 5px 7px; }
.input-canvas-wrap { width: 100%; max-width: 250px; aspect-ratio: 1; margin: 0 auto 16px; position: relative; background: #101010; border: 1px solid #161616; }
.input-canvas-wrap canvas { width: 100%; height: 100%; display: block; image-rendering: pixelated; }
#draw-canvas { touch-action: none; cursor: crosshair; image-rendering: auto; }
.canvas-corner { position: absolute; bottom: 6px; left: 8px; font: 11px 'Courier New',monospace; color: #aaa; pointer-events: none; }
.digit-picker { display: grid; grid-template-columns: repeat(10,1fr); gap: 2px; }
.digit-picker button { padding: 4px 0; background: none; border: 1px solid transparent; font: 14px 'Courier New',monospace; }
.digit-picker button.selected { color: var(--teal); border-color: var(--teal); background: var(--positive-soft); }
.input-actions { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px; margin-top: 14px; font-size: 12px; }
.text-button { border: 0; background: none; color: var(--teal); font-size: 13px; padding: 3px 0; cursor: pointer; }
.input-footer { border-top: 1px solid var(--line-soft); margin-top: 17px; padding-top: 13px; color: var(--dim); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.tiny-icon { font-size: 19px; }
.upload { margin-top: 14px; font-size: 12px; color: var(--muted); }
.upload label { display: block; margin: 12px 0; line-height: 1.6; }
.upload input { max-width: 100%; font-size: 12px; }
summary { cursor: pointer; }
.network-panel { display: flex; flex-direction: column; }
.network-hint { margin-top: 20px; font-size: 14px; line-height: 1.65; }
.pill { font: 10px 'Courier New',monospace; color: var(--dim); }
.live-dot { display: none; }
.network-flow { display: flex; flex: 1; justify-content: space-around; align-items: center; gap: 5px; min-height: 255px; overflow-x: auto; }
.network-block { flex: 1; min-width: 83px; padding: 10px 0; border: 1px solid transparent; background: none; display: flex; align-items: center; flex-direction: column; }
.network-block:hover { background: var(--bg); }
.tensor-stack { position: relative; height: 125px; width: 96px; margin-bottom: 14px; }
.tensor-stack canvas { width: 64px; height: 64px; position: absolute; border: 1px solid var(--positive); image-rendering: pixelated; transform: skewY(-8deg); background: var(--bg); }
.tensor-stack canvas:nth-child(1) { left: 8px; top: 16px; }
.tensor-stack canvas:nth-child(2) { left: 17px; top: 29px; }
.tensor-stack canvas:nth-child(3) { left: 26px; top: 42px; }
.tensor-stack.smaller canvas { width: 52px; height: 52px; }
.net-name { font-size: 13px; font-weight: 600; }
.net-shape { font: 12px 'Courier New',monospace; color: var(--teal); margin-top: 8px; }
.classification .net-shape { color: var(--violet); }
.net-op { font-size: 10px; color: var(--dim); margin-top: 10px; }
.net-arrow { font-size: 18px; color: var(--dim); margin-top: -45px; }
.node-svg { width: 94px; height: 125px; margin-bottom: 14px; }
.network-legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--dim); font-size: 11px; padding: 14px 0; }
.legend-dot { width: 6px; height: 6px; display: inline-block; margin-right: 4px; }
.teal { background: var(--teal); }
.violet { background: var(--violet); }
.signal-note { display: flex; gap: 12px; border-top: 1px solid var(--line-soft); padding-top: 16px; }
.pulse-glyph { display: none; }
.signal-note strong { display: block; color: var(--text); font: 18px/1.3 Georgia,serif; margin-bottom: 8px; }
.signal-note p { font-size: 12px; line-height: 1.6; }
.prediction-hero { display: flex; gap: 18px; align-items: center; padding: 20px 0; }
.prediction-hero>span { font: 68px/1 Georgia,serif; color: var(--teal); }
.prediction-hero>div { display: flex; flex-direction: column; }
.prediction-hero strong { font: 25px Georgia,serif; }
.prediction-hero .small { font-size: 12px; }
.probabilities { display: grid; gap: 8px; }
.probability { display: grid; grid-template-columns: 12px 1fr 45px; align-items: center; gap: 8px; padding: 0; min-height: 20px; width: 100%; border: 0; background: none; text-align: left; font: 12px 'Courier New',monospace; }
.prob-track { height: 7px; background: var(--raised); }
.prob-fill { height: 100%; background: var(--neutral); min-width: 1px; transition: width .25s; }
.probability.winner .prob-fill { background: var(--teal); }
.prob-value { text-align: right; color: var(--dim); font-size: 11px; }
.prediction-note,.prediction-foot { font-size: 12px; margin-top: 16px; line-height: 1.6; }
.prediction-foot { border-top: 1px solid var(--line); padding-top: 12px; color: var(--dim); }
.image-context { display: flex; align-items: center; gap: 17px; border-block: 1px solid var(--line); padding: 12px 0; margin: 0 0 24px; font-size: 14px; }
#context-image { width: 42px; height: 42px; image-rendering: pixelated; }
.context-label { display: block; font-size: 10px; color: var(--dim); margin-bottom: 3px; }
.image-context label { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.context-result { margin-left: 14px; border-left: 1px solid var(--line); padding-left: 22px; }
#context-prediction { font: 18px Georgia,serif; }
.lesson { border: 1px solid var(--line); background: var(--surface); }
.lesson-top { display: block; }
.lesson-copy { padding: 24px 28px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 0 30px; align-items: start; }
.lesson-copy .eyebrow,.lesson-copy h3 { display: none; }
.lesson-copy>p { font-size: 16px; line-height: 1.8; max-width: 840px; }
.code-label { display: block; white-space: pre-wrap; font: 13px/1.8 'Courier New',monospace; background: var(--bg); border-left: 2px solid var(--line); padding: 10px 15px; max-width: 280px; overflow-wrap: anywhere; }
.shape-line { grid-column: 1/-1; margin-top: 13px; font: 12px 'Courier New',monospace; color: var(--muted); }
.shape-line strong { font-weight: 400; color: var(--teal); }
.lesson-work { padding: 28px; min-width: 0; }
.work-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 24px; }
.work-toolbar h4 { font: 20px Georgia,serif; }
.controls { display: flex; align-items: center; gap: 15px; flex-wrap: wrap; }
.controls label { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
select,input[type=number] { border: 1px solid var(--line); border-radius: 2px; background: var(--surface); color: var(--text); font-size: 14px; padding: 6px 8px; }
input[type=number] { width: 70px; }
input[type=range] { accent-color: var(--teal); width: 140px; }
.map-and-math { display: grid; grid-template-columns: 190px minmax(0,1fr); gap: 32px; align-items: start; }
.map-label { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.heatmap-large { width: 100%; aspect-ratio: 1; image-rendering: pixelated; border: 1px solid var(--line); cursor: crosshair; touch-action: none; }
.map-caption { font-size: 13px; line-height: 1.65; margin-top: 10px; color: var(--dim); }
.map-coordinates { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; color: var(--muted); font-size: 12px; }
.map-coordinates label { display: flex; align-items: center; gap: 4px; }
.map-coordinates input { width: 56px; padding: 5px; }
.math-expression { padding: 15px 18px; background: var(--bg); border: 1px solid var(--line-soft); font: 17px/1.8 'Courier New',monospace; overflow-x: auto; white-space: nowrap; margin-bottom: 20px; color: var(--text); }
.math-expression em { font-style: normal; color: var(--teal); }
.matrix-equation { display: flex; align-items: center; justify-content: center; gap: 14px; }
.matrix-block { flex: 1; min-width: 0; }
.matrix-title { text-align: center; font: 11px/1.5 'Courier New',monospace; letter-spacing: .5px; color: var(--muted); margin-bottom: 12px; }
.matrix { display: grid; gap: 4px; border-left: 1px solid var(--text); border-right: 1px solid var(--text); padding: 4px 6px; }
.matrix-cell { min-height: 36px; aspect-ratio: 1; background: var(--positive-soft); color: var(--positive-ink); display: flex; justify-content: center; align-items: center; font: clamp(11px,1vw,16px) 'Courier New',monospace; border: 1px solid transparent; position: relative; }
.matrix-cell.negative { background: var(--negative-soft); color: var(--negative-ink); }
.matrix-cell.zero { background: var(--raised); color: var(--dim); }
.matrix-cell.padded:after { content: ''; position: absolute; inset: 2px; border: 1px dashed var(--dim); pointer-events: none; }
.matrix-cell.max-cell { border: 2px solid var(--text); }
.math-op { font: 24px Georgia,serif; padding-top: 25px; color: var(--dim); }
.sum-line { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 24px; font: 14px/1.8 'Courier New',monospace; color: var(--muted); }
.sum-value { padding: 8px 14px; border-bottom: 2px solid var(--teal); color: var(--teal); font-size: 19px; font-weight: 400; }
.math-note { font-size: 14px; line-height: 1.8; margin-top: 18px; }
.channel-sums { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 20px; }
.channel-sums button { border: 1px solid var(--line); background: var(--bg); font: 12px 'Courier New',monospace; padding: 8px; }
.channel-sums button.selected { border-color: var(--teal); color: var(--teal); }
.feature-strip { display: flex; gap: 20px; align-items: center; padding: 22px 28px; border-top: 1px solid var(--line); }
.strip-label { font-size: 12px; color: var(--dim); min-width: 120px; }
.strip-label strong { display: block; font-weight: 400; color: var(--text); font-size: 14px; margin-bottom: 4px; }
.feature-maps { display: flex; gap: 9px; overflow-x: auto; padding: 4px 0; }
.feature-map { display: flex; flex-direction: column; align-items: center; gap: 5px; border: 1px solid transparent; background: none; padding: 4px; font: 11px 'Courier New',monospace; color: var(--dim); }
.feature-map canvas { width: 46px; height: 46px; image-rendering: pixelated; }
.feature-map.selected { border-color: var(--teal); color: var(--teal); }
.deep-dive { padding: 20px 28px; border-top: 1px solid var(--line); }
.deep-dive summary { font-size: 14px; color: var(--text); }
.deep-dive p { font-size: 16px; line-height: 1.9; max-width: 940px; margin-top: 16px; }
.deep-dive a,.guide a,.model-details a { color: var(--teal); text-decoration: underline; text-underline-offset: 3px; }
.deep-dive code,.guide code { font-size: .84em; color: var(--violet); background: var(--negative-soft); padding: 2px 4px; }
.two-map { display: grid; grid-template-columns: 1fr 42px 1fr; align-items: center; gap: 22px; max-width: 650px; margin: auto; }
.transform-arrow { font-size: 30px; color: var(--teal); text-align: center; }
.value-callout { background: var(--bg); border: 1px solid var(--line); padding: 18px; text-align: center; font: 17px/1.9 'Courier New',monospace; margin-top: 24px; overflow-wrap: anywhere; }
.value-callout strong { font-weight: 400; color: var(--teal); }
.pixel-swatch { width: 68px; height: 68px; border: 1px solid var(--line); margin-bottom: 18px; }
.pool-window-equation { display: grid; grid-template-columns: 1fr 30px 1fr; gap: 16px; align-items: center; max-width: 380px; margin: auto; }
.pool-window-equation canvas { max-width: 180px; cursor: default; }
.pool-window-equation .math-op { text-align: center; }
.flat-vector { display: grid; grid-template-columns: repeat(49,1fr); gap: 3px; padding: 12px; border: 1px solid var(--line); }
.flat-vector button { aspect-ratio: 1; min-width: 0; padding: 0; border: 0; }
.flat-vector button.selected { outline: 2px solid var(--text); }
.flatten-origin { display: flex; align-items: center; gap: 20px; margin-top: 24px; font-size: 14px; }
.flatten-origin canvas { width: 90px; height: 90px; image-rendering: pixelated; border: 1px solid var(--line); }
.dense-grid { display: grid; grid-template-columns: repeat(16,1fr); gap: 6px; margin: 18px 0; }
.dense-grid button { aspect-ratio: 1; border: 1px solid var(--line); min-width: 0; padding: 0; border-radius: 50%; color: var(--text); font: 12px 'Courier New',monospace; }
.dense-grid button.selected { outline: 2px solid var(--teal); outline-offset: 2px; }
.table-scroll { overflow: auto; max-height: 250px; margin-top: 16px; border: 1px solid var(--line); }
.contribution-table { width: 100%; border-collapse: collapse; font: 13px 'Courier New',monospace; }
.contribution-table th { position: sticky; top: 0; font-weight: 400; background: var(--raised); text-align: left; }
.contribution-table td,.contribution-table th { border-bottom: 1px solid var(--line-soft); padding: 10px 13px; }
.contribution-table td:last-child { color: var(--teal); }
.contribution-table tfoot { background: var(--raised); }
.highlight-row { background: var(--positive-soft); }
.softmax-table { max-height: none; }
.chart-bars { display: flex; height: 190px; align-items: center; gap: 12px; margin: 24px 0 32px; border-bottom: 1px solid var(--line); }
.logit-column { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; font: 12px 'Courier New',monospace; }
.logit-bar { width: 65%; background: var(--negative); min-height: 2px; }
.logit-column.winner .logit-bar { background: var(--teal); }
.bar-value { font-size: 11px; margin-bottom: 7px; }
.bar-label { position: absolute; bottom: -24px; }
.learning-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 36px; }
.learning-stat { background: var(--bg); border: 1px solid var(--line); padding: 22px; }
.learning-stat p { font-size: 14px; }
.stat-value { font: 38px/1.5 Georgia,serif; color: var(--teal); }
.learning-grid .matrix { max-width: 250px; margin: auto; }
.training-chart { width: 100%; height: 105px; margin-top: 14px; }
.learning-chain { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin: 28px 0; }
.learning-chain span { font: 14px 'Courier New',monospace; padding: 10px; border: 1px solid var(--line); color: var(--violet); }
.training-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.gradient-detail { margin-top: 25px; border-top: 1px solid var(--line); padding-top: 20px; font-size: 15px; }
.gradient-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 24px; }
.gradient-grid canvas { width: 160px; height: 160px; image-rendering: pixelated; display: block; margin: auto; }
.gradient-grid .map-caption { max-width: 280px; margin: 12px auto; }
.page-turner { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--line); }
.page-turner a { font: 21px Georgia,serif; max-width: 40%; }
.page-turner a:last-child { text-align: right; margin-left: auto; }
.page-turner a>span { display: block; font: 10px 'Courier New',monospace; letter-spacing: 1px; color: var(--dim); margin-bottom: 7px; }
.guide { display: grid; grid-template-columns: 240px 1fr; gap: 40px; padding-top: 34px; }
.guide-heading h2 { margin-bottom: 14px; }
.guide-heading p:last-child { font-size: 15px; line-height: 1.8; }
.guide-content details { border-bottom: 1px solid var(--line); padding: 19px 0; }
.guide-content details:first-child { padding-top: 0; }
.guide-content summary { font-size: 17px; }
.guide-content p { margin-top: 17px; font-size: 16px; line-height: 1.9; }
.model-details { border-top: 1px solid var(--line); margin-top: 48px; padding-top: 30px; display: grid; grid-template-columns: 1fr 1fr; gap: 40px; }
.model-details h2 { margin-bottom: 14px; }
.model-details p { font-size: 15px; line-height: 1.9; }
.model-details dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.model-details dt { font-size: 12px; color: var(--dim); }
.model-details dd { margin: 7px 0 0; font: 14px 'Courier New',monospace; }
footer { border-top: 1px solid var(--line); margin: 0 34px; padding: 25px 0; display: flex; gap: 25px; justify-content: space-between; align-items: center; }
footer .brand { font-size: 20px; }
footer p,footer>a:last-child { font-size: 12px; color: var(--dim); }
.loading,.error { padding: 28px; border: 1px solid var(--line); margin: 24px 0; color: var(--muted); }
.error { border-color: var(--teal); color: var(--teal); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--teal); animation: spin 1s linear infinite; border-radius: 50%; margin-right: 10px; }
.skip-link { position: absolute; left: 10px; top: -60px; z-index: 100; background: var(--text); color: #fff; padding: 10px; }
.skip-link:focus { top: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
body:not([data-page=overview]) #overview-page,body[data-page=overview] #lesson-page,body[data-page=guide] #lesson-page,body:not([data-page=guide]) #guide,body:not([data-page=guide]) #about-model { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media(max-width:1350px) {
  .header-note { display: none; }
  .site-header { justify-content: space-between; }
  .book-layout { grid-template-columns: 205px minmax(0,1fr); }
  .book-sidebar { padding-inline: 12px; }
  .lab-grid { grid-template-columns: 230px minmax(0,1fr); }
  .prediction-panel { grid-column: 1/-1; display: grid; grid-template-columns: 220px 1fr; column-gap: 30px; }
  .prediction-hero { grid-column: 1; grid-row: 2/4; }
  .probabilities { grid-column: 2; grid-row: 1/4; grid-template-columns: 1fr 1fr; column-gap: 30px; }
  .prediction-foot { grid-column: 1/-1; }
  .intro { display: block; }
  .intro .button { margin-top: 20px; }
  .model-name>.subtle { display: none; }
  .matrix-cell { font-size: 12px; }
  .guide { grid-template-columns: 1fr; gap: 24px; }
}
@media(max-width:1000px) {
  .book-layout { grid-template-columns: 180px minmax(0,1fr); }
  .stage-button { font-size: 12px; padding: 8px 6px; gap: 8px; }
  .overview-link,.notes-link { font-size: 12px; }
  .toc-group { font-size: 9px; margin-left: 6px; }
  .model-bar { flex-wrap: wrap; }
  .model-switch { flex-wrap: wrap; }
  .lab-grid { grid-template-columns: 195px minmax(0,1fr); gap: 12px; }
  .panel { padding: 15px; }
  .network-flow { justify-content: flex-start; }
  .network-panel .pill { display: none; }
  .lesson-copy { display: block; padding: 22px; }
  .lesson-copy .code-label { display: none; }
  .lesson-work { padding: 24px 20px; }
  .map-and-math { grid-template-columns: 145px minmax(0,1fr); gap: 24px; }
  .matrix-equation { gap: 7px; }
  .matrix-cell { font-size: 11px; }
  .math-expression { font-size: 14px; }
  .image-context { flex-wrap: wrap; gap: 12px; }
  .image-context>.text-button { display: none; }
  .context-result { margin-left: 0; padding-left: 12px; }
  .model-details { grid-template-columns: 1fr; }
}
@media(max-width:760px) {
  .site-header { padding: 0 18px; height: 72px; gap: 12px; }
  .brand { font-size: 21px; gap: 7px; }
  .brand img { width: 25px; height: 25px; }
  .site-header nav { gap: 15px; font-size: 12px; }
  .site-header nav>a:first-child,.site-header nav>a:last-child { display: none; }
  .book-layout { display: flex; flex-direction: column; }
  .book-sidebar { position: static; order: 0; padding: 0 14px; width: 100%; max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-label,.overview-link,.notes-link,.sidebar-foot,.toc-group { display: none; }
  .stage-nav { display: flex; overflow-x: auto; padding: 9px 0; gap: 5px; }
  .stage-button { flex-shrink: 0; border-left: 0; border-bottom: 2px solid transparent; padding: 7px 9px; font-size: 12px; }
  .stage-button.selected { border-bottom-color: var(--teal); }
  main { padding: 27px 16px 36px; }
  h1 { color: var(--earth); font-size: 34px; letter-spacing: -1px; }
  .intro-copy { font-size: 15px; margin-top: 14px; }
  .intro { padding-bottom: 23px; }
  .model-name { display: none; }
  .model-switch { width: 100%; justify-content: space-between; gap: 6px; }
  .model-switch>.subtle { display: none; }
  .lab-grid { grid-template-columns: 1fr; }
  .input-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
  .input-panel .panel-heading,.input-panel .input-tabs { grid-column: 1/-1; }
  .input-tabs { margin: 0; }
  .input-canvas-wrap { margin: 0; grid-column: 1; grid-row: 3/6; max-width: 230px; }
  #sample-controls,#draw-controls { grid-column: 2; grid-row: 3/5; align-self: center; }
  .digit-picker { grid-template-columns: repeat(5,1fr); gap: 6px; }
  .digit-picker button { padding: 6px 0; font-size: 16px; }
  .input-footer,.upload { grid-column: 1/-1; margin: 0; }
  .input-actions { flex-direction: column; align-items: flex-start; }
  .network-panel { grid-column: 1; }
  .network-flow { justify-content: space-around; min-height: 245px; }
  .prediction-panel { grid-template-columns: 110px 1fr; column-gap: 18px; }
  .prediction-panel .panel-heading { grid-column: 1/-1; margin-bottom: 15px; }
  .prediction-hero { flex-direction: column; align-items: flex-start; gap: 10px; grid-row: 2; padding: 10px 0; }
  .probabilities { grid-column: 2; grid-row: 2; grid-template-columns: 1fr; gap: 4px; }
  .prediction-note { grid-column: 1/-1; }
  .image-context { font-size: 12px; gap: 10px; }
  .image-context label { gap: 5px; }
  .image-context .context-result { border: 0; padding: 0; margin-left: auto; }
  .image-context>div:nth-child(2) { max-width: 100px; }
  #context-image { width: 36px; height: 36px; }
  .context-label { font-size: 9px; }
  #context-prediction { font-size: 16px; }
  .lesson-copy { padding: 18px; }
  .lesson-copy>p { font-size: 15px; }
  .shape-line { font-size: 11px; }
  .lesson-work { padding: 22px 16px; }
  .map-and-math { grid-template-columns: 1fr; gap: 24px; }
  .map-column { display: grid; grid-template-columns: 145px 1fr; gap: 0 18px; }
  .map-column .map-label { grid-column: 1/-1; }
  .map-column canvas { grid-column: 1; grid-row: 2/5; }
  .map-column .map-caption,.map-column .map-coordinates { grid-column: 2; }
  .map-column .map-coordinates { margin-top: 7px; gap: 6px; }
  .matrix-title { font-size: 10px; }
  .matrix-cell { font-size: 12px; }
  .matrix-equation { gap: 7px; }
  .matrix { gap: 3px; padding: 3px; }
  .feature-strip { display: block; padding: 18px 16px; }
  .strip-label { margin-bottom: 9px; display: flex; gap: 10px; align-items: baseline; }
  .feature-maps { gap: 6px; }
  .deep-dive { padding: 18px; }
  .deep-dive p { font-size: 15px; }
  .deep-dive summary { font-size: 13px; }
  .two-map { gap: 12px; grid-template-columns: 1fr 25px 1fr; }
  .value-callout { font-size: 14px; padding: 15px 10px; }
  .flat-vector { grid-template-columns: repeat(28,1fr); gap: 2px; padding: 7px; }
  .dense-grid { grid-template-columns: repeat(8,1fr); gap: 5px; }
  .learning-grid,.gradient-grid { grid-template-columns: 1fr; gap: 25px; }
  .learning-grid .matrix { max-width: 210px; }
  .learning-chain { justify-content: flex-start; }
  .learning-chain span { font-size: 12px; }
  .page-turner a { font-size: 18px; }
  .page-turner>.mono { display: none; }
  .guide-heading h2 { font-size: 27px; }
  .model-details dl { gap: 18px; }
  .model-details dd { font-size: 12px; }
  .contribution-table { font-size: 11px; }
  .contribution-table td,.contribution-table th { padding: 9px 7px; }
  footer { margin: 0 18px; display: block; }
  footer p { margin: 10px 0; }
}
@media(prefers-reduced-motion:reduce) {
  html { scroll-behavior: auto; }
  *,*:before,*:after { animation: none !important; transition: none !important; }
}
/* Worked mathematics: figures have one consistent coordinate/term selection. */
.convolution-flow { display: grid; grid-template-columns: minmax(0,1fr) 34px minmax(0,.85fr) 34px minmax(0,1fr); align-items: center; gap: 15px; max-width: 960px; margin: auto; }
.convolution-flow figure { margin: 0; min-width: 0; }
.convolution-flow figcaption { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; font-size: 14px; margin-bottom: 16px; }
.convolution-flow figcaption b { color: var(--teal); font: italic 22px Georgia,serif; }
.convolution-flow figcaption>span { margin-left: auto; font: 12px 'Courier New',monospace; color: var(--dim); }
.convolution-flow figure>p { font-size: 13px; line-height: 1.7; margin-top: 13px; }
.convolution-flow canvas { display: block; }
.flow-arrow { font: 30px Georgia,serif; text-align: center; color: var(--dim); }
.kernel-figure .matrix-cell { font-size: 14px; }
.kernel-figure .matrix-title { display: none; }
.work-position { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; padding: 21px 0; border-bottom: 1px solid var(--line); color: var(--dim); font-size: 13px; }
.work-position .map-coordinates { margin: 0; }
.worked-heading { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 15px; margin: 30px 0 22px; }
.worked-heading>div:first-child { display: flex; align-items: center; gap: 13px; }
.worked-heading h4 { font: 22px Georgia,serif; }
.worked-heading p { font-size: 13px; max-width: 390px; }
.annotation-number { font: 13px 'Courier New',monospace; color: var(--teal); border: 1px solid var(--teal); width: 28px; height: 28px; display: grid; place-items: center; flex-shrink: 0; }
.worked-equation { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.worked-matrix { flex: 1; min-width: 0; }
.worked-matrix .matrix-cell { flex-direction: column; gap: 5px; min-height: 60px; font-size: clamp(12px,1.15vw,18px); padding: 8px 3px; cursor: pointer; }
.worked-matrix .matrix-cell small { font: 9px 'Courier New',monospace; opacity: .65; }
.matrix-cell.term-selected { border: 2px solid var(--text); color: var(--text); background: var(--selected); }
.term-equation { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 17px; margin: 23px 0; min-height: 77px; border-block: 1px solid var(--line); font: 23px/1.5 'Courier New',monospace; padding: 16px 20px; }
.term-reference { font: 11px/1.5 'Courier New',monospace; color: var(--dim); margin-right: auto; }
.term-equation small { width: 100%; color: var(--dim); font: 13px Arial,sans-serif; text-align: center; }
.term-equation strong { color: var(--teal); font-weight: 400; }
.weight-ink { color: var(--violet); }
.input-ink { color: var(--text); }
.product-strip { display: grid; grid-template-columns: repeat(9,minmax(0,1fr)); gap: 7px; overflow-x: auto; padding: 4px 0; }
.product-term { padding: 11px 5px; background: var(--bg); border: 1px solid var(--line); color: var(--dim); }
.product-term small { display: block; font: 9px 'Courier New',monospace; margin-bottom: 7px; }
.product-term>span { font: 13px 'Courier New',monospace; }
.product-term.revealed { color: var(--text); background: var(--positive-soft); }
.product-term.term-selected { outline: 2px solid var(--text); outline-offset: -2px; }
.arithmetic-progress { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; font: 13px 'Courier New',monospace; margin: 22px 0 6px; }
.arithmetic-progress label { font: 13px Arial,sans-serif; color: var(--muted); }
.arithmetic-progress strong { margin-left: auto; font-size: 17px; color: var(--teal); font-weight: 400; }
.trace-plot { overflow-x: auto; padding-top: 7px; }
.accumulation-chart { display: block; width: 100%; min-width: 560px; max-height: 210px; }
.accumulation-chart text { font: 11px 'Courier New',monospace; fill: var(--muted); }
.channel-ledger { display: grid; grid-template-columns: repeat(8,1fr); gap: 7px; }
.channel-ledger button { background: var(--bg); border: 1px solid var(--line); padding: 11px 4px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.channel-ledger button.selected { border-color: var(--teal); background: var(--positive-soft); }
.channel-ledger small { font: 9px 'Courier New',monospace; color: var(--dim); }
.channel-ledger strong { font: 13px 'Courier New',monospace; }
.channel-ledger span { font-size: 10px; color: var(--dim); }
.bias-equation { display: flex; flex-wrap: wrap; justify-content: space-around; align-items: center; gap: 20px; padding: 25px 20px; margin-top: 25px; border: 1px solid var(--line); background: var(--bg); }
.bias-equation>span { font: 27px Georgia,serif; color: var(--dim); }
.bias-equation>div { text-align: center; }
.bias-equation strong { display: block; font: 25px/1.5 'Courier New',monospace; }
.final-answer { border-bottom: 2px solid var(--teal); color: var(--teal); padding-bottom: 5px; }
.bias-equation .context-label { font-size: 9px; letter-spacing: .6px; }
.connection-control { color: var(--muted); font-size: 13px; }
.connection-control input { margin-left: 8px; width: 80px; }
.fan-scroll { overflow-x: auto; border: 1px solid var(--line-soft); padding: 10px; }
.fan-in-svg { display: block; width: 100%; min-width: 730px; }
.fan-in-svg text { font: 12px 'Courier New',monospace; fill: var(--text); }
.fan-in-svg>text { font-size: 10px; fill: var(--dim); }
.fan-in-svg .sigma-symbol { font: 26px Georgia,serif; }
.fan-in-svg .fan-result { font-size: 17px; fill: var(--teal); }
.connection-line { cursor: pointer; }
.connection-line:focus-visible { outline: 2px solid var(--text); }
.contribution-bars { max-width: 700px; margin: auto; }
.contribution-key { display: flex; justify-content: space-between; padding-left: 100px; padding-right: 92px; font-size: 11px; color: var(--dim); margin-bottom: 15px; }
.contribution-bar-row { display: grid; grid-template-columns: 90px 1fr 86px; gap: 12px; align-items: center; margin: 9px 0; font: 12px 'Courier New',monospace; }
.contribution-bar-row>strong { text-align: right; font-weight: 400; }
.signed-track { height: 17px; position: relative; background: var(--raised); }
.signed-track:after { content: ''; position: absolute; width: 1px; top: -4px; bottom: -4px; left: 50%; background: var(--neutral); }
.signed-track i { display: block; position: absolute; height: 11px; top: 3px; }
.all-neurons,.all-connections { margin-top: 25px; padding-top: 18px; border-top: 1px solid var(--line); font-size: 14px; }
.neuron-worked + .all-neurons { margin-top: 20px; }
.softmax-pipeline { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 20px; overflow-x: auto; padding: 6px 0; }
.softmax-column { min-width: 135px; }
.softmax-column h4 { font: 18px Georgia,serif; }
.softmax-column>.mono { height: 42px; margin-top: 9px; color: var(--muted); font-size: 11px; }
.softmax-cell { display: flex; align-items: center; position: relative; gap: 10px; justify-content: space-between; background: var(--bg); border: 1px solid var(--line-soft); width: 100%; padding: 10px; margin-bottom: 7px; font: 13px 'Courier New',monospace; overflow: hidden; }
.softmax-cell small { font: 10px 'Courier New',monospace; color: var(--dim); }
.softmax-cell.selected { border-color: var(--teal); background: var(--positive-soft); }
.softmax-cell i { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--teal); }
.column-foot { font-size: 12px; line-height: 1.7; margin-top: 14px; }
.softmax-fraction { display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap; font: 27px Georgia,serif; padding: 20px 0; }
.softmax-fraction math { font-size: 24px; }
.softmax-fraction>strong { color: var(--teal); font-weight: 400; }
.probability-whole { width: 100%; height: 34px; display: flex; margin-top: 20px; background: var(--raised); }
.probability-whole span { display: grid; place-items: center; color: #fff; font: 15px 'Courier New',monospace; overflow: hidden; }
.relu-function { display: grid; grid-template-columns: 1fr 1fr; gap: 35px; margin-top: 30px; align-items: center; border-top: 1px solid var(--line); padding-top: 25px; }
.relu-function h4 { font: 24px Georgia,serif; margin-bottom: 15px; }
.relu-function p { font-size: 14px; line-height: 1.8; margin-top: 13px; }
.relu-function svg { display: block; width: 100%; max-width: 430px; }
.relu-function text { font: 12px 'Courier New',monospace; fill: var(--muted); }
.pool-routing { display: flex; gap: 28px; align-items: center; border-top: 1px solid var(--line); padding-top: 28px; margin-top: 30px; }
.pool-routing>div:first-child { flex: 1; }
.pool-routing h4 { font: 22px Georgia,serif; }
.pool-routing p { font-size: 14px; line-height: 1.8; margin-top: 13px; }
.pool-switch { display: grid; grid-template-columns: repeat(2,1fr); gap: 5px; width: 240px; }
.pool-switch>div { padding: 12px; background: var(--bg); border: 1px solid var(--line); text-align: center; }
.pool-switch span { display: block; font: 16px 'Courier New',monospace; }
.pool-switch small { display: block; font-size: 11px; color: var(--dim); margin-top: 7px; }
.pool-switch .winner { border: 2px solid var(--teal); background: var(--positive-soft); }
.routing-arrow { font: 28px Georgia,serif; color: var(--teal); }
.chain-derivatives { display: flex; gap: 15px; align-items: center; margin-top: 23px; }
.chain-derivatives>div { flex: 1; min-width: 0; padding: 19px 13px; background: var(--bg); border: 1px solid var(--line); text-align: center; }
.chain-derivatives small { display: block; font: 10px 'Courier New',monospace; color: var(--dim); margin-bottom: 13px; }
.chain-derivatives span { display: block; font: 21px Georgia,serif; margin-bottom: 14px; }
.chain-derivatives strong { font: 13px/1.8 'Courier New',monospace; overflow-wrap: anywhere; }
.chain-derivatives>b { font: 25px Georgia,serif; color: var(--dim); }
.chain-derivatives .gradient-answer { background: var(--positive-soft); border-color: var(--teal); }
.weight-update-line { display: flex; gap: 13px; justify-content: space-between; align-items: center; flex-wrap: wrap; margin-top: 20px; border-block: 1px solid var(--line); padding: 18px 0; font-size: 12px; color: var(--dim); }
.weight-update-line strong { display: block; font: 16px/1.9 'Courier New',monospace; color: var(--text); }
@media(max-width:1000px) {
  .convolution-flow { gap: 10px; grid-template-columns: minmax(0,1fr) 25px minmax(0,.85fr) 25px minmax(0,1fr); }
  .convolution-flow figcaption { font-size: 12px; }
  .convolution-flow figcaption>span { display: none; }
  .kernel-figure .matrix-cell { font-size: 11px; min-height: 30px; }
  .kernel-figure .matrix-cell small { display: none; }
  .term-equation { font-size: 18px; gap: 13px; }
  .product-strip { grid-template-columns: repeat(9,73px); }
  .channel-ledger { grid-template-columns: repeat(4,1fr); }
  .bias-equation strong { font-size: 22px; }
  .pool-routing { gap: 18px; }
  .pool-switch { width: 200px; }
  .routing-arrow { display: none; }
  .chain-derivatives { flex-wrap: wrap; gap: 10px; }
  .chain-derivatives strong { font-size: 11px; }
}
@media(max-width:760px) {
  .convolution-flow { grid-template-columns: 1fr 18px 1fr; gap: 8px; }
  .kernel-figure { display: none; }
  .convolution-flow>.flow-arrow:nth-child(4) { display: none; }
  .convolution-flow figure>p { font-size: 12px; }
  .convolution-flow figure>p { min-height: 40px; }
  .worked-heading { margin: 27px 0 18px; }
  .worked-heading h4 { font-size: 21px; }
  .worked-heading p { font-size: 13px; }
  .worked-equation { overflow-x: auto; gap: 10px; padding: 4px 0 12px; }
  .worked-equation .worked-matrix { min-width: 145px; }
  .worked-matrix .matrix-cell { font-size: 13px; min-height: 48px; }
  .term-equation { padding: 14px 6px; gap: 10px; font-size: 17px; }
  .term-reference { width: 100%; text-align: center; margin: 0; }
  .arithmetic-progress { gap: 10px; font-size: 12px; }
  .arithmetic-progress input { width: 90px; }
  .arithmetic-progress strong { font-size: 15px; }
  .bias-equation { gap: 11px; padding: 17px 9px; }
  .bias-equation strong { font-size: 18px; }
  .bias-equation .context-label { max-width: 95px; font-size: 8px; }
  .bias-equation>span { font-size: 19px; }
  .contribution-bar-row { grid-template-columns: 75px 1fr 70px; gap: 8px; font-size: 11px; }
  .contribution-key { padding: 0; font-size: 10px; }
  .softmax-pipeline { grid-template-columns: repeat(4,145px); gap: 12px; }
  .softmax-fraction { gap: 12px; font-size: 23px; }
  .softmax-fraction math { font-size: 21px; }
  .relu-function { grid-template-columns: 1fr; gap: 8px; }
  .relu-function svg { max-width: 400px; margin: auto; }
  .pool-routing { flex-wrap: wrap; justify-content: center; }
  .pool-routing>div:first-child { flex-basis: 100%; }
  .pool-switch { width: 240px; }
  .chain-derivatives { flex-direction: column; }
  .chain-derivatives>div { width: 100%; }
  .chain-derivatives strong { font-size: 15px; }
  .weight-update-line { justify-content: center; gap: 11px; }
  .weight-update-line strong { font-size: 14px; }
}

.site-header nav { margin-left:auto; }
/* Use the reference navy and muted purple across every lesson page. */
.site-header { background:var(--header); border-top-color:var(--positive); border-bottom-color:var(--header); }
.site-header .brand,.site-header .brand:hover { color:var(--surface); }
.site-header .brand-comma,.site-header .brand-dot { color:var(--change); }
.site-header nav a { color:var(--bg); }
.site-header nav a:hover,.site-header nav a.active { color:var(--change-soft); }
.site-header nav a.active { box-shadow:0 1px var(--change); }
.book-sidebar { background:var(--sidebar); color:var(--surface); }
.book-sidebar .sidebar-label,.book-sidebar .toc-group,.book-sidebar .sidebar-foot,.book-sidebar .stage-button>span { color:var(--bg); }
.book-sidebar .overview-link,.book-sidebar .notes-link,.book-sidebar .stage-button { color:var(--surface); }
.book-sidebar .stage-button.selected,.book-sidebar .overview-link.active,.book-sidebar .notes-link.active { background:var(--change-soft); color:var(--header); border-color:var(--change); }
.book-sidebar .stage-button.selected>span { color:var(--header); }
.book-sidebar .notes-link { border-top-color:var(--neutral); }
.book-sidebar a:hover { background:var(--change-soft); color:var(--header); }
.book-sidebar .stage-button:hover>span { color:var(--header); }
