/* kuangrad write-up. Same paper, ink and Georgia as the π0.7 notebook; yellow marks "this part, right now". */
:root {
  color-scheme: light;
  --paper: #fbfbfa;
  --ink: #1a1a1a;
  --secondary: #5a5a5a;
  --muted: #8b8b84;
  --accent: #1f3a8a;
  --grad: #c2410c;
  --rule: #d8d8d4;
  --card: #ffffff;
  --card-head: #f6f5f1;
  --yellow: #e0b100;
  --yellow-fill: #f5c51824;
  --cache: #0f766e;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, 'Liberation Mono', monospace;
  --footer-h: 24px;
  font-family: Georgia, 'Times New Roman', serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
.nobr { white-space: nowrap; }
body { margin: 0; background: var(--paper); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }
a { color: var(--accent); }

.workspace {
  height: calc(100vh - var(--footer-h));
  height: calc(100dvh - var(--footer-h));
  display: grid;
  grid-template-columns: minmax(0, var(--split, 1.12fr)) minmax(0, 1fr);
  overflow: clip;
}

/* ---- left: graph + card stack ---------------------------------------------------------------------------------- */
.visual { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.visual-head { height: 56px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 clamp(20px, 3vw, 40px); font-size: 14px; }
.visual-head .wordmark { font-family: var(--mono); font-size: 13px; letter-spacing: .02em; }
.visual-head .wordmark span { color: var(--muted); }
.visual-head .wordmark code { font: inherit; background: #efeee9; padding: .15em .4em; border-radius: 3px; }
#step-counter { font: 12px/1 var(--mono); color: var(--muted); }
.visual { outline: 0; }
.visual:focus-visible { box-shadow: inset 0 0 0 1px #1f3a8a30; }
/* shown on the animated passages; once the panel has focus, the arrow keys step through the pass */
.step-hint { margin-left: auto; font: 12px/1 Arial, sans-serif; color: var(--muted); white-space: nowrap; opacity: 0; transition: opacity .3s; }
.visual.is-animated .step-hint { opacity: 1; }
.visual:focus-within .step-hint-click { display: none; }
@media (hover: none) { .step-hint { display: none; } }
.step-hint kbd { display: inline-block; min-width: 18px; padding: 2px 4px; border: 1px solid var(--rule); border-radius: 3px; background: #fff; font: 11px/1 var(--mono); color: var(--secondary); text-align: center; }
.graph-wrap { position: relative; flex-shrink: 0; width: min(100% - 40px, 48vh * 720 / 346); width: min(100% - 40px, 48dvh * 720 / 346); margin: 16px auto 0; aspect-ratio: 720 / 346; container-type: inline-size;
  transition: width .6s cubic-bezier(.65, 0, .35, 1), margin-top .6s cubic-bezier(.65, 0, .35, 1), opacity .3s, visibility .3s; }
/* while the card is a drawing rather than a listing, the graph shrinks and the card takes the room */
.visual.has-widget .graph-wrap { width: min(100% - 40px, 26vh * 720 / 346); width: min(100% - 40px, 26dvh * 720 / 346); }
.graph-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.graph-caption { flex-shrink: 0; height: 54px; margin: 0 clamp(16px, 2.5vw, 36px); display: flex; align-items: center; justify-content: center; flex-wrap: wrap; font: 12.5px/1.5 Arial, sans-serif; color: var(--secondary); text-align: center; }
.graph-caption .katex { font-size: 1.22em; }
.graph-caption code { font: 11.5px var(--mono); background: #efeee9; padding: .1em .35em; border-radius: 3px; color: var(--ink); }
.graph-caption .sep { color: var(--muted); margin: 0 6px; }
.stack { position: relative; flex: 1; min-height: 0; margin: 2px clamp(16px, 2.5vw, 36px) clamp(16px, 2.2vw, 28px); }

/* graph: SVG shapes, with every label an HTML overlay typeset by KaTeX and sized in the graph's own units */
.graph-labels { position: absolute; inset: 0; pointer-events: none; }
.gl { position: absolute; transform: translate(-50%, -50%); font-size: calc(var(--fs) * 100cqw / 720); line-height: 1; white-space: nowrap; color: var(--ink); transition: color .25s, opacity .3s; }
.gl .katex { font-size: 1em; }
.node-label.on-dark { color: #fff; }
.node-label.pending { color: #bdbcb5; }
.matrix-dims { color: var(--secondary); }
.edges line { stroke: var(--ink); stroke-opacity: .2; stroke-width: .9; transition: stroke .3s, stroke-opacity .3s, stroke-width .3s, opacity .3s; }
.link-relu line { stroke-opacity: .42; }
.link-all line { stroke-opacity: .14; }
.flow-fwd { stroke: var(--accent); stroke-width: 1.9; stroke-linecap: round; }
.flow-bwd { stroke: var(--grad); stroke-width: 2; stroke-linecap: round; }
.particle { fill: var(--cache); }
.node { stroke: var(--ink); stroke-width: 1.1; transition: stroke .3s, stroke-width .3s, opacity .3s; }
.node.pending { stroke: #c9c8c2; stroke-dasharray: 2.5 2.5; }
.ellipsis { fill: var(--muted); transition: opacity .3s; }
.ring { fill: none; stroke: var(--grad); }
.badge { fill: var(--cache); stroke: #fff; stroke-width: 1.1; }
.badge.is-read { fill: #14b8a6; }
.matrix { transition: opacity .3s; }
.matrix-bg { fill: #fff; }
.bracket { fill: none; stroke: var(--ink); stroke-width: 1.2; transition: stroke .3s, stroke-width .3s; }
.cell { stroke: var(--accent); stroke-width: 1.6; transition: opacity .3s; }
.cell-cache { fill: var(--cache); }
.cell-grad { fill: none; stroke: var(--grad); stroke-width: 1.5; }
.size-label { font: 10.5px Arial, sans-serif; text-anchor: middle; fill: var(--secondary); }
.op-label { font: 9.5px var(--mono); text-anchor: middle; fill: var(--muted); }
.depth-badge { opacity: 0; transition: opacity .25s; }
.depth-badge circle { fill: var(--paper); stroke: var(--grad); stroke-width: 1.2; }
.depth-label { font: bold 10px Arial, sans-serif; text-anchor: middle; fill: var(--grad); }
[data-mode=backward] .depth-badge, [data-mode=depth] .depth-badge { opacity: 1; transition-delay: var(--delay); }
[data-mode=forward] .edges line, [data-mode=backward] .edges line { stroke-opacity: .1; }
[data-mode=edge] :is(.edges line, .node, .cell, .bracket, .ellipsis) { opacity: .22; }
[data-mode=edge] .gl:not(.chosen, .col-label) { opacity: .3; }
[data-mode=edge] :is(.edges line.chosen, .node.chosen, .cell.chosen) { opacity: 1; }
[data-mode=edge] .edges line.chosen { stroke: var(--accent); stroke-opacity: 1; stroke-width: 2; }
[data-mode=edge] .node.chosen { stroke: var(--accent); stroke-width: 2.2; }
[data-mode=edge] .cell.chosen { stroke: var(--yellow); stroke-opacity: 1; stroke-width: 2.2; }
[data-mode=relu] .node.dead { stroke: var(--muted); stroke-dasharray: 3 2.5; }
[data-mode=relu] .link-relu line.to-dead { stroke-dasharray: 2 3; stroke-opacity: .3; }
[data-mode=softmax] .link-all line { stroke: var(--accent); stroke-opacity: .45; }
[data-mode=loss] .link-loss line { stroke-dasharray: 2 3; stroke-opacity: .3; }
[data-mode=loss] .link-loss line.py { stroke: var(--accent); stroke-opacity: 1; stroke-width: 2; stroke-dasharray: none; }
[data-mode=loss] .node.py { stroke: var(--accent); stroke-width: 2.4; }
[data-mode=layer] .link-w1 line { stroke: var(--accent); stroke-opacity: .55; }
:is([data-mode=layer] .matrix-w1, [data-mode=params] .matrix, [data-mode=update] .matrix) .bracket { stroke: var(--accent); stroke-width: 2; }
:is([data-mode=params], [data-mode=update]) :is(.nodes, .edges, .node-label, .col-label) { opacity: .35; }
[data-mode=update] .matrix { animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 50% { opacity: .5; } }
[data-mode=hot] :is(.link-w1, .link-w2) line { stroke: var(--grad); stroke-opacity: .5; }
[data-mode=hot] .node.hot { stroke: var(--grad); stroke-width: 2.2; }
/* caption keys */
.sw { display: inline-block; flex-shrink: 0; width: 9px; height: 9px; margin: 0 5px 0 3px; border-radius: 50%; }
.sw-pos { background: rgb(31 58 138 / .82); }
.sw-neg { background: rgb(138 59 107 / .82); }
.sw-zero { background: #fff; border: 1.2px solid var(--ink); }
.sw-dead { background: #fff; border: 1.2px dashed var(--muted); }
.sw-cache { background: var(--cache); border-radius: 2px; margin-right: 7px; }
.sw-grad { width: 11px; height: 11px; border: 2px solid var(--grad); margin-right: 7px; }
.sw-hot { width: 16px; height: 0; border-radius: 0; border-top: 2px solid var(--grad); }
.key-depth { display: inline-block; width: 16px; height: 16px; margin: 0 6px 0 4px; border: 1.2px solid var(--grad); border-radius: 50%; color: var(--grad); font: bold 9px/14px Arial, sans-serif; text-align: center; }

/* the yellow box */
.hl { position: absolute; border: 2px solid var(--yellow); background: var(--yellow-fill); border-radius: 7px; box-shadow: 0 0 0 4px #f5c51812; opacity: 0; pointer-events: none;
  transition: left .65s cubic-bezier(.65, 0, .35, 1), top .65s cubic-bezier(.65, 0, .35, 1), width .65s cubic-bezier(.65, 0, .35, 1), height .65s cubic-bezier(.65, 0, .35, 1), opacity .3s; }
.hl.is-on { opacity: 1; }
.hl-tag { position: absolute; left: -2px; bottom: calc(100% + 2px); padding: 3px 7px 3px; background: var(--yellow); color: var(--ink); font: 11px/1.2 var(--mono); border-radius: 4px; white-space: nowrap; }
.hl.tag-right .hl-tag { left: auto; right: -2px; }

/* cards */
.card { position: absolute; left: 0; right: 0; top: 48px; bottom: 0; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--rule); border-radius: 7px; overflow: hidden;
  box-shadow: 0 1px 2px #322d250d, 0 6px 20px #322d2517; transform-origin: 50% 0;
  transform: translateX(calc(-100% - 90px)) rotate(-5deg); transition: transform .42s cubic-bezier(.55, 0, .85, .25), background-color .4s; z-index: 60; }
.card.is-focus { transform: none; transition: transform .75s cubic-bezier(.17, 1.28, .38, 1), background-color .4s; z-index: 50; }
.card.is-behind { transform: translateY(calc(var(--depth) * -11px)) scale(calc(1 - var(--depth) * .04)); transition: transform .5s cubic-bezier(.3, .7, .3, 1), background-color .4s, opacity .4s; z-index: calc(50 - var(--depth)); background: #f1f0eb; }
.card.is-behind .card-body { opacity: 0; transition: opacity .3s; }
.card.is-behind .card-head { background: #eceae4; align-items: flex-start; padding-top: 3px; }
.card.is-buried { opacity: 0; }
body:not(.is-ready) :is(.card, .graph-wrap) { transition: none; }
.card-head { flex-shrink: 0; height: 34px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 14px; background: var(--card-head); border-bottom: 1px solid var(--rule); font: 12px/1 var(--mono); transition: background-color .4s; }
.card-title { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { color: var(--muted); font: 11px/1 Arial, sans-serif; white-space: nowrap; }
.card-body { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; container-type: size; }
.card-meta .katex { font-size: 1.1em; }
/* "there is more below": shown on the front card while it can still scroll */
.card-more { position: absolute; right: 14px; bottom: 14px; z-index: 2; height: 30px; display: flex; align-items: center; gap: 3px; padding: 0 8px 0 12px; border-radius: 15px; background: var(--ink); color: #fff; font: 12px/1 Arial, sans-serif; box-shadow: 0 2px 10px #1a1a1a38; opacity: 0; pointer-events: none; transition: opacity .25s; }
.card-more svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.card.is-focus.has-more .card-more { opacity: 1; pointer-events: auto; animation: hint 1.8s ease-in-out infinite; }
.card-more:hover { background: var(--accent); }
@keyframes hint { 50% { transform: translateY(3px); } }

/* code */
.code { margin: 0; padding: 12px 0 18px; font: 12.5px/1.62 var(--mono); tab-size: 4; color: var(--ink); }
.code code { display: block; }
.ln { display: grid; grid-template-columns: 3.6em minmax(0, 1fr); padding-right: 16px; }
.code.plain .ln { grid-template-columns: minmax(0, 1fr); padding-left: 18px; }
.gutter { text-align: right; padding-right: 1.2em; color: #b5b4ad; user-select: none; }
.src { white-space: pre-wrap; overflow-wrap: anywhere; }
.ln.focus { background: #f5c5182b; box-shadow: inset 3px 0 0 var(--yellow); }
.ln.focus .gutter { color: #9c7c00; }
.ln.gap .gutter { color: var(--muted); }
.tk-kw { color: var(--accent); }
.tk-def { font-weight: 700; }
.tk-str { color: #3d6b35; }
.tk-num { color: #9a4d0b; }
.tk-com { color: var(--muted); font-style: italic; }
.tk-bi { color: #2f6f7a; }
.tk-self { color: #7a5c99; }
.tk-type { color: #8a3b6b; }

/* digits */
.digits { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto; gap: 16px 24px; padding: 18px; align-items: start; }
.digit-big { margin: 0; }
.digit-big svg { display: block; width: clamp(130px, 100cqh - 116px, min(320px, 46cqw)); aspect-ratio: 1; border: 1px solid var(--rule); background: #fff; }
.digit-big .grid-lines { stroke: #ecebe6; stroke-width: .04; }
.digit-big .ink, .digit-picks path, .digit-strip .ink { fill: var(--ink); }
.digit-big figcaption { margin-top: 8px; font: 12px Arial, sans-serif; color: var(--secondary); }
.digit-picks { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; max-width: 470px; }
.digit-picks button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px; border: 1px solid var(--rule); border-radius: 4px; background: #fff; }
.digit-picks button[aria-pressed=true] { border-color: var(--yellow); box-shadow: 0 0 0 2px var(--yellow-fill); }
.digit-picks svg { width: 100%; aspect-ratio: 1; display: block; }
.digit-picks span { font: 11px Arial, sans-serif; color: var(--secondary); }
.digit-strip { grid-column: 1 / -1; }
.digit-strip svg { display: block; width: 100%; height: 16px; border: 1px solid var(--rule); background: #fff; }
.digit-strip .row-ticks { stroke: var(--yellow); stroke-width: .9; vector-effect: non-scaling-stroke; }
.digit-strip p { display: flex; justify-content: space-between; margin: 6px 0 0; font: 11px Arial, sans-serif; color: var(--secondary); }

/* one edge */
.edge-card { padding: 16px 18px; }
.edge-figure { position: relative; width: min(100%, 520px, max(260px, (100cqh - 172px) * 460 / 200)); aspect-ratio: 460 / 200; margin: 0 auto; container-type: inline-size; }
.edge-figure svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.edge-card line { stroke: var(--ink); stroke-width: 1.2; }
.edge-card marker path, .bfs-card marker path { fill: var(--ink); }
.edge-node circle { fill: #fff; stroke: var(--ink); stroke-width: 1.3; }
.edge-node.is-child circle { stroke: var(--accent); stroke-width: 2; }
.ef { position: absolute; transform: translate(-50%, -50%); white-space: nowrap; line-height: 1; }
.ef .katex { font-size: 1em; }
.ef-name { font-size: max(13px, 3.7cqw); }
.ef-value { font: max(10.5px, 2.5cqw) var(--mono); color: var(--secondary); }
.ef-grad { font-size: max(11.5px, 2.8cqw); color: var(--accent); background: #ffffffe8; padding: 2px 4px; border-radius: 3px; }
.edge-lists { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px 18px; margin-top: 10px; }
.edge-lists h4 { margin: 0 0 6px; font: 12px var(--mono); font-weight: 400; }
.edge-lists h4 span { color: var(--muted); font: 11px Arial, sans-serif; margin-left: 4px; }
.edge-lists ol { list-style: none; margin: 0; padding: 0; font: 12px/1.7 var(--mono); color: var(--secondary); }
.edge-lists ol.inline { display: flex; flex-wrap: wrap; gap: 0 8px; }
.edge-lists li.is-hit { color: var(--ink); background: var(--yellow-fill); box-shadow: inset 2px 0 0 var(--yellow); padding-left: 6px; }
.edge-lists ol.inline li.is-hit { padding: 0 4px; box-shadow: none; }
.edge-lists li.more { color: var(--muted); font-style: italic; }

/* jacobian */
.jacobian { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 18px; padding: 16px 18px; align-items: start; }
.jacobian svg { display: block; width: 100%; max-height: 330px; }
.jacobian .axis { font: 10px Arial, sans-serif; fill: var(--secondary); text-anchor: middle; }
.jacobian .axis-title { font: 10px Arial, sans-serif; fill: var(--muted); }
.jacobian .p-bar { fill: #b9b8b1; }
.jacobian .p-bar.is-label { fill: var(--accent); }
.jacobian .j-cell { stroke: transparent; stroke-width: 2; }
.jacobian .j-cell.is-hover { stroke: var(--yellow); }
.jacobian-side { font: 12px/1.5 Arial, sans-serif; color: var(--secondary); padding-top: 54px; }
.j-readout { margin: 0 0 14px; color: var(--ink); min-height: 40px; display: flex; align-items: center; }
.j-legend { display: flex; align-items: center; gap: 6px; }
.j-legend i { flex: 1; height: 10px; border-radius: 2px; background: linear-gradient(90deg, rgb(180, 35, 24), rgb(240, 239, 236), rgb(31, 58, 138)); }
.j-note { margin: 10px 0 14px; }
.j-examples { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; color: var(--ink); font-size: 15px; }
.jacobian-side .katex { font-size: 1.15em; }
.j-readout { font-size: 16px; }

/* bfs */
.bfs-card { padding: 14px 18px; }
.bfs-card svg { display: block; width: 100%; max-height: min(300px, max(100cqh - 28px, 120px)); }
.bfs-card line { stroke: var(--ink); stroke-width: 1.1; }
.bfs-node circle { fill: #fff; stroke: var(--ink); stroke-width: 1.2; }
.bfs-node text { font: italic 13px Georgia, serif; text-anchor: middle; fill: var(--ink); }
.bfs-node .bfs-depth { font: bold 11px Arial, sans-serif; font-style: normal; fill: var(--grad); }
.bfs-node.is-late circle { stroke: var(--grad); stroke-width: 2; fill: #fdf1ea; }
.bfs-title { font: 11px Arial, sans-serif; fill: var(--secondary); }

/* cost */
.cost-card { padding: 16px 20px 14px; font: 12px Arial, sans-serif; color: var(--secondary); }
.cost-card h4 { margin: 0 0 12px; font: 12px var(--mono); font-weight: 400; color: var(--ink); }
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 11em minmax(0, 1fr) 4.5em; align-items: center; gap: 10px; }
.bar-track { height: 12px; }
.bar { display: block; height: 100%; width: var(--w); min-width: 3px; background: #a9a8a1; border-radius: 0 4px 4px 0; }
.bar-row.is-hot .bar { background: var(--grad); }
.bar-row.is-hot .bar-label, .bar-row.is-hot .bar-value { color: var(--ink); }
.bar-value { font: 12px var(--mono); color: var(--ink); text-align: right; }
.facts { margin: 16px 0 0; border-top: 1px solid var(--rule); }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid #ecebe6; }
.facts dt { color: var(--secondary); }
.facts dd { margin: 0; font: 12px var(--mono); color: var(--ink); }
.cost-note { margin: 10px 0 0; color: var(--muted); }

/* ---- right: the article ---------------------------------------------------------------------------------------- */
.notes { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; border-left: 1px solid var(--rule); background: var(--paper); }
/* split.js: the draggable line between the panels, a few pixels either side of the border */
.splitter { position: absolute; z-index: 60; top: 0; bottom: 0; left: -6px; width: 11px; cursor: col-resize; touch-action: none; outline: 0; }
.splitter::after { content: ''; position: absolute; top: 0; bottom: 0; left: 4px; width: 3px; background: var(--accent); opacity: 0; transition: opacity .15s; }
.splitter:hover::after, .splitter:focus-visible::after, .is-splitting .splitter::after { opacity: .55; }
.is-splitting { cursor: col-resize; user-select: none; }
.is-splitting iframe, .is-splitting canvas { pointer-events: none; }
.reading-nav { height: 56px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 clamp(24px, 4vw, 64px); font-size: 14px; }
#contents-toggle { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
#contents-toggle svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.3; transition: transform .15s; }
#contents-toggle[aria-expanded=true] svg { transform: rotate(180deg); }
#chapter-label { color: var(--secondary); text-align: right; }
.page-tabs { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--rule); border-radius: 5px; flex-shrink: 0; }
.page-tabs a { padding: 5px 11px; border-radius: 3px; color: var(--secondary); text-decoration: none; font-size: 14px; line-height: 1.2; }
.page-tabs a:hover { color: var(--ink); background: #1a1a1a06; }
.page-tabs a[aria-current=page] { background: var(--accent); color: #fff; }
.reading-nav #contents-toggle { margin-right: auto; }
#contents-menu { position: absolute; z-index: 8; top: 50px; left: 24px; right: 24px; max-height: calc(100% - 82px); overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; background: var(--paper); padding: 16px 20px 22px; border: 1px solid var(--rule); border-radius: 5px; box-shadow: 0 12px 30px #1a1a1a10; }
.toc-chapter { margin: 14px 8px 4px; font: 11px Arial, sans-serif; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.toc-chapter:first-child { margin-top: 0; }
.toc-link { display: flex; align-items: baseline; gap: 10px; width: 100%; text-align: left; padding: 6px 8px; border-radius: 3px; font-size: 14px; line-height: 1.4; }
.toc-link.level-3 { padding-left: 30px; color: var(--secondary); font-size: 13px; }
.toc-number { min-width: 16px; color: var(--muted); font: 10px/1.5 Arial, sans-serif; }
.toc-link code { font: .9em var(--mono); }
.toc-link:hover { background: #1a1a1a06; color: var(--ink); }
.toc-link[aria-current] { background: #1f3a8a0a; color: var(--accent); }
.reader { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; outline: 0; }
.reader:focus-visible { box-shadow: inset 0 0 0 1px #1f3a8a30; }
#article { max-width: 680px; margin: 0 auto; padding: 8px clamp(24px, 4vw, 64px) 72vh; }
.reading-block { padding: 40px 0 20px; }
.reading-block.level-2 { padding-top: 64px; }
.reading-block:first-child { padding-top: 24px; }
.title-block { margin-bottom: 30px; }
.chapter-kicker { margin: 0 0 10px; font: 11px Arial, sans-serif; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.title-block h1 code { font: inherit; background: #efeee9; padding: 0 .14em; border-radius: 6px; }
.title-block h1 { margin: 0; font: 400 clamp(44px, 4.4vw, 64px)/1.02 var(--mono); letter-spacing: -.04em; }
.subtitle code { font: .8em var(--mono); background: #efeee9; padding: .1em .35em; border-radius: 3px; }
.subtitle { margin: 14px 0 0; font-size: clamp(20px, 1.7vw, 24px); line-height: 1.35; color: var(--secondary); }
.byline { margin: 18px 0 0; font: 13px Arial, sans-serif; color: var(--secondary); }
.reading-block h2, .reading-block h3 { font-weight: 400; line-height: 1.18; letter-spacing: -.02em; text-wrap: balance; margin: 0 0 26px; transition: color .25s; }
.reading-block h2 { font-size: clamp(28px, 2.6vw, 40px); }
.reading-block h3 { font-size: clamp(23px, 1.9vw, 29px); }
.reading-block.is-current > h2, .reading-block.is-current > h3 { color: var(--accent); }
.reading-block p, .reading-block li { font-size: 18px; line-height: 1.75; overflow-wrap: break-word; }
.reading-block p { margin: 0 0 24px; }
.reading-block ul { margin: 0 0 24px; padding-left: 1.3em; }
.reading-block li { margin: 0 0 8px; }
.reading-block p:last-child { margin-bottom: 0; }
.reading-block .katex, .dialog-body .katex { font-size: 1.12em; }
.reading-block .math, .dialog-body .math { margin: 26px 0; overflow-x: auto; overflow-y: hidden; }
.katex-display { margin: 0; }
.reading-block li .katex-display { margin: 14px 0 10px; }
.reading-block .note { padding: 14px 18px; border-left: 3px solid var(--yellow); background: #f5c51814; font-size: 17px; line-height: 1.65; }
/* follows the graph's animation */
.stages { width: 100%; border-collapse: collapse; margin: 4px 0 28px; font: 14.5px/1.4 Arial, sans-serif; }
.stages th { text-align: left; font-weight: 400; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0 10px 8px; border-bottom: 1px solid var(--rule); }
.stages th code { text-transform: none; letter-spacing: 0; }
.stages td { padding: 5px 10px; border-bottom: 1px solid #ecebe6; color: var(--ink); transition: background-color .3s, color .3s; }
.stages .stage-n { width: 2em; color: var(--muted); font-size: 11px; }
.stages .katex { font-size: 1.08em; }
.stages.is-playing td { color: var(--muted); }
.stages.is-playing tr.is-done td { color: var(--secondary); }
.stages tr.is-live td { background: var(--yellow-fill); color: var(--ink); }
.stages tr.is-live td:first-child { box-shadow: inset 3px 0 0 var(--yellow); }
.details-btn { display: inline-flex; align-items: center; gap: 9px; padding: 8px 15px; border: 1px solid var(--rule); border-radius: 999px; background: #fff; font: 14px Arial, sans-serif; color: var(--accent); transition: border-color .2s, box-shadow .2s; }
.details-btn:hover { border-color: var(--accent); box-shadow: 0 2px 10px #1f3a8a14; }
.details-btn svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.details-dialog { width: min(780px, calc(100vw - 32px)); max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px); padding: 0; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink); box-shadow: 0 24px 64px #1a1a1a38; }
.details-dialog[open] { display: flex; flex-direction: column; }
.details-dialog::backdrop { background: #1a1a1a45; }
.details-dialog header { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px 14px 24px; border-bottom: 1px solid var(--rule); }
.details-dialog h2 { margin: 0; font-weight: 400; font-size: 24px; letter-spacing: -.01em; }
.dialog-close { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; }
.dialog-close:hover { background: #1a1a1a0d; }
.dialog-close svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.dialog-body { min-height: 0; overflow: auto; padding: 6px 24px 22px; }
.dialog-body p { font-size: 16.5px; line-height: 1.65; margin: 14px 0; }
.dialog-body .jacobian { padding: 8px 0 0; }
.reading-block code, .article-end code { font: .82em var(--mono); background: #efeee9; padding: .12em .38em; border-radius: 3px; }
.reading-block sub, .reading-block sup { font-size: .72em; line-height: 0; }
.article-end { margin-top: 64px; padding-top: 22px; border-top: 1px solid var(--rule); font-size: 15px; line-height: 1.6; color: var(--secondary); }

.site-footer { height: var(--footer-h); display: flex; align-items: center; justify-content: center; gap: 4px; font: 11px/1 Arial, sans-serif; color: var(--secondary); background: var(--paper); border-top: 1px solid var(--rule); }
.site-footer a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--rule); }
.site-footer a:hover { color: var(--accent); border-bottom-color: var(--accent); }
.skip-link { position: absolute; left: 15px; top: -100px; z-index: 10; background: var(--paper); padding: 12px; color: var(--accent); }
.skip-link:focus { top: 12px; }
.no-script { position: fixed; inset: 0; z-index: 20; background: var(--paper); padding: 30px; }

/* ---- phones: graph and cards on top, article below --------------------------------------------------------------- */
@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(0, 50%) minmax(0, 1fr); }
  .notes { border-left: 0; border-top: 1px solid var(--rule); }
  .splitter { display: none; }
  .visual-head { height: 34px; padding: 0 16px; }
  .graph-wrap { width: min(100% - 32px, 24vh * 720 / 346); width: min(100% - 32px, 24dvh * 720 / 346); margin-top: 12px; }
  .graph-caption { display: none; }
  .visual.has-widget .graph-wrap { width: 0; margin-top: 0; opacity: 0; visibility: hidden; }
  .stack { margin: 4px 16px 12px; }
  .card { top: 30px; }
  .card.is-behind { transform: translateY(calc(var(--depth) * -7px)) scale(calc(1 - var(--depth) * .03)); }
  .card-more { height: 26px; padding: 0 6px 0 10px; font-size: 11px; right: 10px; bottom: 10px; }
  .step-hint { display: none; }
  .notation { right: 10px; bottom: 10px; max-height: calc(100% - 70px); font-size: 11.5px; }
  .card.is-behind .card-head > * { visibility: hidden; }
  .card-head { height: 28px; }
  .code { font-size: 11px; padding: 8px 0 12px; }
  .hl-tag { font-size: 10px; padding: 2px 5px; }
  .reading-nav { height: 48px; padding: 0 24px; font-size: 13px; }
  .page-tabs a { padding: 4px 8px; font-size: 13px; }
  #article { padding: 0 26px 55vh; }
  .reading-block { padding: 28px 0 16px; }
  .reading-block.level-2 { padding-top: 44px; }
  .reading-block h2 { font-size: 28px; }
  .reading-block h3 { font-size: 23px; }
  .reading-block p, .reading-block li { font-size: 16px; line-height: 1.65; }
  .reading-block p { margin-bottom: 20px; }
  .title-block h1 { font-size: 40px; }
  #contents-menu { top: 42px; left: 12px; right: 12px; max-height: calc(100% - 54px); padding: 14px; }
  .digits { padding: 12px; gap: 10px 14px; }
  .jacobian { grid-template-columns: 1fr; }
  .jacobian-side { padding-top: 0; }
  .bar-row { grid-template-columns: 8.5em minmax(0, 1fr) 4em; }
}

@container (max-width: 460px) {
  .node-label, .matrix-dims { display: none; }
}

/* ---- preface, term notes, notation key ---------------------------------------------------------------------------- */
.reading-block .preface { margin: 0 0 30px; font-style: italic; color: var(--secondary); }
.reading-block .preface p { margin: 0 0 10px; }
.reading-block .preface ul { margin: 0 0 12px; }
.reading-block .preface li { margin: 0 0 4px; }
.term { position: relative; border-bottom: 1px dotted var(--muted); cursor: help; outline: 0; }
.term:focus-visible { border-bottom-color: var(--accent); }
.term-note { position: absolute; z-index: 6; left: 0; bottom: calc(100% + 10px); width: min(360px, 78vw); padding: 12px 14px; background: #fff; border: 1px solid var(--rule); border-radius: 6px; box-shadow: 0 10px 28px #1a1a1a1f;
  font: 14px/1.55 Georgia, serif; color: var(--ink); opacity: 0; visibility: hidden; transform: translateY(4px); transition: opacity .18s, transform .18s, visibility .18s; }
.term-note .katex { font-size: 1.05em; }
.term-note code { font-size: .85em; }
.term:is(:hover, :focus, :focus-within) .term-note { opacity: 1; visibility: visible; transform: none; }
.notation { position: absolute; z-index: 7; right: 16px; bottom: 14px; width: 330px; max-height: calc(100% - 100px); display: flex; flex-direction: column; background: #ffffffed; backdrop-filter: blur(6px); border: 1px solid var(--rule); border-radius: 8px; box-shadow: 0 8px 26px #1a1a1a1a;
  font: 12px/1.4 Arial, sans-serif; color: var(--secondary); }
.notation header { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 8px 7px 12px; border-bottom: 1px solid #ecebe6; }
.notation header span { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.notation-toggle { padding: 3px 9px; border: 1px solid var(--rule); border-radius: 999px; font: 11.5px Arial, sans-serif; color: var(--accent); }
.notation-toggle:hover { border-color: var(--accent); }
.notation dl { margin: 0; padding: 6px 12px 10px 6px; overflow: auto; scrollbar-width: thin; display: grid; gap: 5px; }
.notation dl div { display: grid; grid-template-columns: 54px minmax(0, 1fr); gap: 10px; align-items: center; }
.notation dt { color: var(--ink); text-align: right; }
.notation dd { margin: 0; }
.notation .katex { font-size: 1.08em; }
.notation code { font: .95em var(--mono); background: #efeee9; padding: .05em .3em; border-radius: 3px; }
.notation .word { display: none; color: var(--ink); }
.notation.is-compact { width: auto; }
.notation.is-compact dl { gap: 3px; }
.notation.is-compact dl div { grid-template-columns: 50px auto; gap: 8px; }
.notation.is-compact .word { display: inline; }
.notation.is-compact .full { display: none; }

/* ---- graph chips: the cached derivative going forward, gradients landing going back ------------------------------- */
.chip { position: absolute; left: 0; top: 0; z-index: 3; opacity: 0; pointer-events: none; white-space: nowrap; line-height: 1; padding: .4em .6em; border-radius: .5em; font-size: calc(12.5 * 100cqw / 720); color: #fff; box-shadow: 0 2px 10px #1a1a1a40; }
.chip .katex { font-size: 1em; }
.chip-loc { background: var(--cache); }
.chip-grad { background: var(--grad); padding: .34em .55em; border-radius: 999px; font-size: calc(11 * 100cqw / 720); box-shadow: 0 0 0 3px #c2410c2e, 0 2px 10px #c2410c55; }
.chip-rest { font: 600 calc(10.5 * 100cqw / 720)/1 Arial, sans-serif; }
.chip-sum { background: #fff; color: var(--grad); border: 1.5px solid var(--grad); }
.chip-sum.is-final { background: var(--grad); color: #fff; }
.burst { fill: none; stroke: var(--grad); stroke-width: 2.2; }
:is([data-mode=forward], [data-mode=backward]) .node.featured { stroke: #a37b00; stroke-width: 2.4; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
