/* heyadhi explainer kit: the post components and diagram primitives TIL posts are built from.
   Links after tokens.css and components.css. kit.js wires the steppers, tabs and reading bar;
   without it every figure shows its final state with all its captions listed below. */

body{font-size:17.5px;line-height:1.62}

/* ---- hero: a two-tone headline, the lede, the key terms ---- */
/* The hero is a wide grid: the heading and intro on the left, a visual slot on the right
   (the post's key figure, a small stage, or a .media image). Anything else in it — the back
   link, .terms — spans both columns. Below 900px the columns stack: text first, then the visual. */
.hero{max-width:1240px;padding-block:clamp(24px,5vw,48px) 30px;display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.05fr);gap:8px clamp(28px,4vw,56px);align-items:center}
.hero>*{grid-column:1/-1}
.hero>.hero-text{grid-column:1}
.hero>.hero-visual{grid-column:2;min-width:0}
.hero-visual>.stage,.hero-visual>.media{margin:0}
.hero h1{font-size:clamp(38px,4.8vw,68px);line-height:1.04;text-wrap:wrap;margin-top:18px}
.hero-visual .hint{margin:14px 0 0;max-width:none}
.hero .sub{font-size:var(--fs-lg);margin-top:24px;max-width:52ch}
@media (max-width:900px){
  .hero{grid-template-columns:minmax(0,1fr)}
  .hero>.hero-text,.hero>.hero-visual{grid-column:1}
  .hero-visual{margin-top:18px}
}
.hint{font-size:var(--fs-sm)}
.terms{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:18px 14px;margin:34px 0 10px}
.term{border-top:3px solid var(--ink);padding-top:12px;min-width:0}
.term .pic{min-height:46px;display:flex;align-items:center;gap:4px;margin-bottom:10px;position:relative}
.term h3{font-size:var(--fs-lg);margin-bottom:4px}
.term p{font-size:var(--fs-sm);color:var(--muted);margin:0}

/* ---- chapters ---- */
.ch{padding-block:clamp(48px,8vw,84px) 36px;border-top:1px solid var(--line)}
.ch-head{display:grid;grid-template-columns:64px minmax(0,1fr);gap:6px 18px;align-items:baseline;margin-bottom:18px}
.ch-num{font:800 44px/1 var(--display);-webkit-text-stroke:1.5px var(--ink);color:transparent}
.ch h2{font-size:clamp(28px,4.2vw,44px);max-width:22ch}
.ch-body{margin-left:82px}
.ch-body h3{font-size:var(--fs-xl);margin:6px 0 12px}
.gist{font:600 var(--fs-xl)/1.4 var(--display);letter-spacing:-.005em;max-width:44ch;margin-bottom:18px;padding:14px 18px;background:var(--surface);border-radius:var(--r3);border:1px solid var(--line);border-left:6px solid var(--ink)}
.facts{list-style:none;padding:0;margin:0 0 1em;max-width:66ch}
.facts li{position:relative;padding-left:26px;margin-bottom:.6em}
.facts li::before{content:"";position:absolute;left:4px;top:.62em;width:9px;height:9px;border-radius:3px;background:var(--ink);transform:rotate(45deg)}
.aside{font-size:var(--fs-sm);color:var(--muted);max-width:70ch}
.stage .aside{margin:12px 0 0}
.part{margin:70px 0 0;padding-block:48px 10px;border-top:6px solid var(--ink)}
.part h2{font-size:clamp(34px,5vw,56px);font-weight:800;letter-spacing:-.025em;max-width:18ch}
.part p{font-size:var(--fs-lg);margin-top:16px}
.back{display:inline-flex;align-items:center;gap:.4em;font-weight:700;text-decoration:none;padding-top:20px}
.back:hover{text-decoration:underline}
.sources{border-top:1px solid var(--line);margin-top:48px;padding-block:28px 12px;font-size:var(--fs-sm);color:var(--muted)}
.sources h2{font-size:var(--fs-lg);color:var(--ink);margin-bottom:8px}
.sources ul{padding-left:18px}
.recap{list-style:none;padding:0;margin:0;display:grid;gap:12px;max-width:74ch}
.recap li{position:relative;padding:14px 16px 14px 58px;background:var(--surface);border:1px solid var(--line);border-radius:var(--r3)}
.recap li::before{content:"";position:absolute;left:18px;top:15px;width:24px;height:24px;border-radius:50%;background:var(--ok)}
.recap li::after{content:"";position:absolute;left:27px;top:19px;width:6px;height:11px;border:solid var(--on-ok);border-width:0 3px 3px 0;transform:rotate(45deg)}

/* ---- the stage: the frame of a figure ---- */
/* A stage is a size container, so a figure can lay itself out by the room it has (@container). */
.stage{container-type:inline-size;background:var(--surface);border:1px solid var(--line);border-radius:var(--r4);padding:clamp(16px,3vw,26px);box-shadow:var(--shadow);margin:28px 0 8px;min-width:0}
.stage:focus-visible{outline-offset:4px}
.stage-top{display:flex;flex-wrap:wrap;gap:10px 16px;align-items:center;justify-content:space-between;margin-bottom:6px}
.stage-top .what{font-weight:700}
.narrate{min-height:3.3em;margin:16px 0 0;font-size:var(--fs-md);font-weight:600;max-width:70ch;padding-left:14px;border-left:4px solid var(--focus)}
/* Every caption, in order: what a reader without scripts sees under the final state. */
.captions{margin:16px 0 0;padding:0 0 0 14px;border-left:4px solid var(--focus);list-style:none;counter-reset:cap;max-width:74ch;font-size:var(--fs-sm)}
.captions li{counter-increment:cap;position:relative;padding-left:2.2em;margin:0 0 .45em}
.captions li::before{content:counter(cap);position:absolute;left:0;top:.1em;min-width:1.6em;text-align:center;font:600 var(--fs-2xs)/1.6 var(--mono);background:var(--soft);border-radius:var(--r1)}
.stage.is-live .captions{display:none}
.transport{display:flex;flex-wrap:wrap;align-items:center;gap:6px;margin-top:14px}
.transport .play{min-width:6.5em}
.transport .count{font-size:var(--fs-xs);color:var(--muted);margin-left:6px}
.stage.is-instant *,.stage.is-instant *::before,.stage.is-instant *::after{transition:none!important;animation:none!important}

.legend{display:flex;flex-wrap:wrap;gap:6px 18px;font-size:var(--fs-xs);color:var(--muted);margin-top:14px}
.legend>span{display:inline-flex;align-items:center;gap:7px}
.sw{display:inline-block;width:24px;height:12px;border-radius:3px;background:var(--sw,var(--muted));flex:none}
.sw.c1{--sw:var(--c1)}.sw.c2{--sw:var(--c2)}.sw.c3{--sw:var(--c3)}.sw.c4{--sw:var(--c4)}
.sw.is-ok{--sw:var(--ok)}.sw.is-new{--sw:var(--new)}
.sw.is-bad{background:repeating-linear-gradient(135deg,var(--bad) 0 4px,transparent 4px 7px);box-shadow:inset 0 0 0 1.5px var(--bad)}
.sw.is-focus{background:transparent;box-shadow:inset 0 0 0 3px var(--focus),0 0 0 1.5px var(--ink)}

/* ---- diagram primitives ---- */
/* A track of cells. It wraps onto more rows on narrow screens; the row gap leaves room for markers. */
.track{display:flex;flex-wrap:wrap;gap:44px 6px;padding:32px 2px 12px;min-width:0}
.track.is-row{flex-wrap:nowrap}
.cell{--fill:var(--soft);--on:var(--ink);position:relative;flex:var(--grow,1) 1 var(--w,7rem);min-width:0;max-width:calc(var(--w,7rem) * 2.4);min-height:74px;border-radius:var(--r2);padding:8px 10px 16px;display:flex;flex-direction:column;justify-content:space-between;gap:4px;
  background:var(--fill);color:var(--on);transition:transform .5s cubic-bezier(.2,.8,.2,1),opacity .5s,box-shadow .3s,background-color .4s}
.track.is-row .cell{flex-basis:0;max-width:none}
.cell.wide{--grow:1.6}
.cell.mini{min-height:30px;padding:0;flex-basis:0;border-radius:var(--r1)}
.cell .kind{font-size:var(--fs-2xs);font-weight:600;line-height:1.2}
.cell .txt{font-size:var(--fs-xs);font-weight:700;line-height:1.25;overflow-wrap:anywhere}
.cell.c1{--fill:var(--c1);--on:var(--on-c1)}.cell.c2{--fill:var(--c2);--on:var(--on-c2)}
.cell.c3{--fill:var(--c3);--on:var(--on-c3)}.cell.c4{--fill:var(--c4);--on:var(--on-c4)}
/* States keep the category fill and add a band along the bottom plus a badge, so colour is never the only signal.
   A figure names its badges with --say-ok, --say-bad and --say-new (strings), e.g. style='--say-ok:"cached"'. */
.cell::before{content:"";position:absolute;left:0;right:0;bottom:0;height:8px;border-radius:0 0 var(--r2) var(--r2);background:var(--band,transparent);transition:background-color .4s}
/* The badge straddles the bottom edge, in the row gap, so it never covers the cell's own text. */
.cell::after{position:absolute;right:6px;bottom:-10px;z-index:1;box-shadow:0 0 0 2px var(--surface);font:700 var(--fs-2xs)/1.3 var(--body);padding:1px 7px;border-radius:var(--pill);background:var(--band);color:var(--on-band);white-space:nowrap}
.cell.is-ok{--band:var(--ok);--on-band:var(--on-ok)}.cell.is-ok::after{content:"✓ " var(--say-ok,"")}
.cell.is-new{--band:var(--new);--on-band:var(--on-new)}.cell.is-new::after{content:"+ " var(--say-new,"")}
.cell.is-bad{--band:var(--bad);--on-band:var(--on-bad)}.cell.is-bad::after{content:"✕ " var(--say-bad,"")}
.cell.is-bad::before{background:repeating-linear-gradient(135deg,var(--bad) 0 5px,var(--on-bad) 5px 8px)}
.cell.mini::after{display:none}
.cell.is-focus{box-shadow:0 0 0 3px var(--focus),0 0 0 5px var(--ink),0 0 18px 4px color-mix(in srgb,var(--focus) 70%,transparent);z-index:1}
.cell.is-ghost{background:transparent;color:var(--muted);outline:2px dashed var(--line);outline-offset:-2px}
/* Utility states the steps toggle. */
.is-pre{opacity:0;transform:translateY(-12px) scale(.96)}
.is-gone{display:none!important}
.is-lit{--lit:1}
/* A marker: a flag on a cell's right edge, with its label above it. */
.marker{position:absolute;right:-4px;top:-30px;bottom:-4px;width:2px;background:var(--ink);z-index:2;pointer-events:none;font-style:normal;transition:opacity .4s}
.cell.mini .marker{top:-12px}
.marker span{position:absolute;top:0;right:0;white-space:nowrap;font:700 var(--fs-2xs)/1.3 var(--body);background:var(--ink);color:var(--on-ink);padding:2px 7px;border-radius:6px 6px 0 6px}
/* A ring: a countdown. Its --left (0–100) is the static amount left; .is-run drains it over --ttl. */
.ring{width:36px;height:36px;transform:rotate(-90deg);flex:none}
.ring circle{fill:none;stroke-width:4}
.ring .bg{stroke:var(--soft)}
.ring .fg{stroke:var(--ok);stroke-dasharray:100;stroke-dashoffset:calc(100 - var(--left,100));stroke-linecap:round;transition:stroke-dashoffset .6s}
.ring.is-run .fg{animation:ring-drain var(--ttl,30s) linear forwards}
@keyframes ring-drain{from{stroke-dashoffset:0}to{stroke-dashoffset:100}}
/* Arcs: SVG dependency curves over a row of cells. Paths carry class="arc"; .is-bad or .is-lit colours one. */
.arcs svg{display:block;width:100%;height:110px;overflow:visible}
.arcs .arc{fill:none;stroke:var(--line);stroke-width:2;vector-effect:non-scaling-stroke;transition:stroke .5s,stroke-width .5s}
.arcs .arc.is-lit{stroke:var(--ink);stroke-width:3}
.arcs .arc.is-bad{stroke:var(--bad);stroke-width:3;stroke-dasharray:7 4}
.arcs .track{padding-top:0}

/* ---- media: an image figure, and a clip (a short video on the kit's controls) ---- */
/* Give every <img>/<video> its width and height attributes, so the space is reserved before it loads. */
.media{margin:28px 0 8px}
.media img{display:block;max-width:100%;height:auto;border-radius:var(--r3);border:1px solid var(--line);background:var(--soft)}
.media figcaption,.clip figcaption{font-size:var(--fs-sm);color:var(--muted);margin-top:10px;max-width:70ch}
.clip video{display:block;width:100%;height:auto;border-radius:var(--r2);border:1px solid var(--line);background:var(--soft)}

/* ---- more post components ---- */
.anatomy{display:grid;grid-template-columns:minmax(0,1.25fr) minmax(0,1fr);gap:22px;align-items:start;margin-top:18px}
.pin{display:inline-grid;place-items:center;width:20px;height:20px;border-radius:50%;background:var(--focus);color:var(--on-focus);font:700 11px var(--body);margin-right:6px;vertical-align:1px}
.pins{list-style:none;padding:0;margin:0;display:flex;flex-direction:column;gap:12px}
.pins li{font-size:var(--fs-sm);padding:12px 14px;border-radius:var(--r3);background:var(--surface);border:1px solid var(--line)}
.bars{display:flex;flex-direction:column;gap:14px;margin-top:6px}
.bar-row{display:grid;grid-template-columns:minmax(6rem,170px) minmax(0,1fr) auto;gap:14px;align-items:center}
.bar-row .nm{font-weight:700;font-size:var(--fs-sm)}
.bar-track{height:30px;border-radius:8px;background:var(--soft);overflow:hidden}
.bar{height:100%;width:var(--v,0%);border-radius:8px;background:var(--fill,var(--ink));transition:width 1.6s cubic-bezier(.2,.8,.2,1)}
.bar.is-ok{--fill:var(--ok)}.bar.is-new{--fill:var(--new)}.bar.is-bad{--fill:var(--bad)}
.stack-bar{display:flex;min-height:44px;border-radius:var(--r2);overflow:hidden;flex-wrap:wrap}
.stack-bar>*{flex:var(--v,1) 1 0;min-width:max-content;display:flex;align-items:center;justify-content:center;padding:4px 10px;font:600 var(--fs-xs) var(--mono);background:var(--fill,var(--soft));color:var(--on,var(--ink))}
.stack-bar .is-ok{--fill:var(--ok);--on:var(--on-ok)}.stack-bar .is-new{--fill:var(--new);--on:var(--on-new)}.stack-bar .is-bad{--fill:var(--bad);--on:var(--on-bad)}

/* ---- the reading bar: sticky at the top, in its own row, so it never sits over what is being read ---- */
html:has(.dock){scroll-padding-top:calc(var(--dock-h,52px) + 12px)}
.dock{position:sticky;top:0;z-index:50;background:color-mix(in srgb,var(--paper) 88%,transparent);-webkit-backdrop-filter:blur(12px);backdrop-filter:blur(12px);border-bottom:1px solid var(--line)}
.dock-in{max-width:1060px;margin:0 auto;padding:7px clamp(16px,4vw,32px);display:flex;align-items:center;gap:6px;flex-wrap:wrap}
.dock .here{flex:1 1 8rem;min-width:0;font:700 var(--fs-sm)/1.2 var(--display);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding:0 6px}
.dock .sep{width:1px;height:22px;background:var(--line);flex:none}
.toc{inset:auto;position:fixed;top:calc(var(--dock-h,52px) + 6px);left:50%;translate:-50% 0;margin:0;width:min(440px,calc(100vw - 24px));max-height:70vh;overflow:auto;padding:8px;background:var(--surface);color:var(--ink);border:1px solid var(--line);border-radius:var(--r4);box-shadow:var(--shadow)}
.toc a{display:flex;gap:10px;padding:8px 10px;border-radius:var(--r2);text-decoration:none;font-size:var(--fs-sm);line-height:1.35}
.toc a:hover,.toc a:focus-visible{background:var(--soft)}
.toc a[aria-current]{background:var(--soft);font-weight:700}
.toc .n{font-family:var(--mono);color:var(--muted);width:26px;flex:none}

@media (max-width:800px){
  .ch-body{margin-left:0}
  .ch-head{grid-template-columns:44px minmax(0,1fr)}
  .ch-num{font-size:32px}
  .terms{grid-template-columns:repeat(2,minmax(0,1fr))}
  .gist{font-size:var(--fs-lg)}
  .anatomy{grid-template-columns:minmax(0,1fr)}
  .bar-row{grid-template-columns:minmax(0,1fr) auto}
  .bar-row .bar-track{grid-column:1/-1;grid-row:2}
}
@media (max-width:560px){
  .dock .lbl{display:none}
  .dock .here,.dock .sep{display:none}
  .dock-in{justify-content:center;gap:4px;padding-inline:8px}
  .dock .btn{padding:.42em .65em}
  .dock .seg button{padding:.38em .55em}
  .stage{--w:5.5rem}
  .track.is-row .cell{padding-inline:6px}
  .track.is-row .cell .txt{font-size:var(--fs-2xs)}
}
