
/* Layout: a chapter list (sidebar on wide screens, collapsible on phones) and one long column of
   chapters. Each chapter is a diagram you step through, then study aids underneath. */
:root {
  --bg: #f4f6f8; --panel: #ffffff; --fg: #141c24; --muted: #5b6875; --rule: #d7dee5; --soft: #eef2f6;
  --accent: #1f5fbf; --accent-soft: #dde8fa; --store: #f3ecdc; --warn: #b45309; --good: #15803d;
  --font-display: "Archivo", "Segoe UI", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #0f141a; --panel: #161d25; --fg: #e3e9ef; --muted: #98a6b3; --rule: #2a3440; --soft: #1b232d; --accent: #6ea8ff; --accent-soft: #1d2e47; --store: #2b2618; --warn: #f0a24c; --good: #4ade80; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #0f141a; --panel: #161d25; --fg: #e3e9ef; --muted: #98a6b3; --rule: #2a3440; --soft: #1b232d; --accent: #6ea8ff; --accent-soft: #1d2e47; --store: #2b2618; --warn: #f0a24c; --good: #4ade80; color-scheme: dark; }
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font-body); font-size: 16px; line-height: 1.55; }
a { color: var(--accent); }
.shell { max-width: 1180px; margin: 0 auto; padding-inline: 16px; padding-block: 32px 64px; display: grid; gap: 28px; }
@media (min-width: 1000px) { .shell { grid-template-columns: 240px minmax(0, 1fr); } }
.kicker { font-family: var(--font-mono); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
h1 { font-family: var(--font-display); font-weight: 800; font-size: clamp(32px, 6vw, 52px); margin: 6px 0 10px; line-height: 1.02; }
.lede { color: var(--muted); max-width: 68ch; margin: 0 0 8px; }
nav.toc { position: relative; }
@media (min-width: 1000px) { nav.toc { position: sticky; top: 16px; align-self: start; max-height: calc(100vh - 32px); overflow: auto; } }
nav.toc details { background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px; }
nav.toc summary { cursor: pointer; font-weight: 600; }
nav.toc ol { margin: 8px 0 0; padding-left: 22px; display: grid; gap: 4px; font-size: 14.5px; }
nav.toc a { color: var(--fg); text-decoration: none; }
nav.toc a:hover, nav.toc a:focus-visible, nav.toc a[aria-current="true"] { color: var(--accent); text-decoration: underline; }
.chapter { padding-top: 26px; border-top: 1px solid var(--rule); margin-top: 26px; scroll-margin-top: 12px; }
.chapter h2 { font-family: var(--font-display); font-weight: 800; font-size: clamp(24px, 3.6vw, 32px); margin: 0 0 4px; }
.chapter h2 .n { color: var(--accent); margin-right: 8px; }
.chapter .q { color: var(--muted); margin: 0 0 14px; font-size: 17px; }
figure.diagram { margin: 0; background: var(--panel); border: 1px solid var(--rule); border-radius: 12px; overflow: hidden; }
figure.diagram:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.frame { overflow-x: auto; padding: 12px; }
.frame svg { display: block; width: 100%; min-width: 560px; height: auto; color: var(--fg); font-family: var(--font-body); }
.controls { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--rule); background: var(--soft); flex-wrap: wrap; }
.controls button { font: inherit; font-size: 14px; font-weight: 600; padding: 6px 14px; border-radius: 8px; border: 1px solid var(--rule); background: var(--panel); color: var(--fg); cursor: pointer; }
.controls button:hover:not(:disabled), .controls button:focus-visible { border-color: var(--accent); outline: none; }
.controls button:disabled { opacity: .45; cursor: default; }
.controls .count { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); }
.controls .hint { margin-left: auto; font-size: 12.5px; color: var(--muted); }
figcaption { padding: 12px 14px 14px; font-size: 16px; min-height: 4.2em; }
.aids { display: grid; gap: 14px; margin-top: 14px; }
@media (min-width: 760px) { .aids { grid-template-columns: 1fr 1fr; } }
.aid { background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; padding: 14px 16px; }
.aid h3 { font-family: var(--font-mono); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
.aid.say { grid-column: 1 / -1; border-left: 3px solid var(--accent); }
.aid.say p { margin: 0; font-size: 16.5px; }
.aid ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 15px; }
.aid details { border-top: 1px solid var(--rule); padding: 8px 0; font-size: 15px; }
.aid details:first-of-type { border-top: 0; padding-top: 0; }
.aid summary { cursor: pointer; font-weight: 600; }
.aid details p { margin: 6px 0 0; color: var(--fg); }
.aid.more { font-size: 14.5px; }
.aid.more p { margin: 0 0 6px; }
.steps-text summary { cursor: pointer; color: var(--muted); font-size: 14px; padding: 0 14px 12px; }
.steps-text ol { margin: 0; padding: 0 14px 14px 36px; font-size: 14.5px; display: grid; gap: 4px; }
code { font-family: var(--font-mono); font-size: .92em; background: var(--soft); padding: 1px 4px; border-radius: 4px; }
footer { margin-top: 40px; color: var(--muted); font-size: 14px; border-top: 1px solid var(--rule); padding-top: 14px; }

/* Diagram elements */
.d-node rect { fill: var(--panel); stroke: currentColor; stroke-width: 1.4; }
.d-node.store rect { fill: var(--store); }
.d-node.actor rect { fill: var(--soft); }
.d-node.pod rect { stroke-dasharray: none; rx: 14; }
.d-node.q rect { fill: var(--soft); stroke-dasharray: 5 3; }
.d-node.note rect { fill: none; stroke: none; }
.d-node text.lbl { font-size: 13px; font-weight: 600; fill: currentColor; text-anchor: middle; }
.d-node text.sub { font-family: var(--font-mono); font-size: 10.5px; fill: var(--muted); text-anchor: middle; }
.d-group rect { fill: none; stroke: var(--muted); stroke-dasharray: 6 4; stroke-width: 1.2; }
.d-group text { font-family: var(--font-mono); font-size: 11px; fill: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.d-edge path { fill: none; stroke: currentColor; stroke-width: 1.4; }
.d-edge.dashed path { stroke-dasharray: 5 4; }
.d-edge text { font-family: var(--font-mono); font-size: 10.5px; fill: currentColor; text-anchor: middle; paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round; }
.d-el { transition: opacity .25s; }
svg.stepping .d-el.dim { opacity: .18; }
svg.stepping .d-node.on rect { stroke: var(--accent); stroke-width: 2.4; fill: var(--accent-soft); }
svg.stepping .d-edge.on path { stroke: var(--accent); stroke-width: 2.2; }
svg.stepping .d-edge.on text { fill: var(--accent); }
svg.stepping .d-edge.flow path { stroke-dasharray: 7 5; animation: march .8s linear infinite; }
@keyframes march { to { stroke-dashoffset: -12; } }
@media (prefers-reduced-motion: reduce) { svg.stepping .d-edge.flow path { animation: none; } .d-el { transition: none; } }

/* Header link back to the lab */
.kicker a { color: inherit; text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.kicker a:hover, .kicker a:focus-visible { border-bottom-color: var(--accent); outline: none; }
/* Side-by-side code */
.codes { display: grid; gap: 10px; margin-top: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .codes { grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); } }
.codes pre { tab-size: 4; -moz-tab-size: 4; }
.code-col { background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.code-head { font-family: var(--font-mono); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--rule); background: var(--soft); }
.code-col pre { margin: 0; padding: 12px; overflow-x: auto; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.5; flex: 1; }
.code-col pre code { background: none; padding: 0; font-size: inherit; }
.code-note { color: var(--muted); font-size: 14.5px; margin: 8px 0 0; }

/* "What breaks at scale" aid */
.aid.scale { grid-column: 1 / -1; border-left: 3px solid var(--warn); }
.aid.scale h3 { color: var(--warn); }
