/* Layout: a single reading column that descends through abstraction levels; a depth rail on the left tracks how technical the reader is. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #0e1726;
  --muted: #566275;
  --line: #dde3eb;
  --accent: #2f5bd8;
  --accent-soft: #e3eafc;
  --warm: #d9680f;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s0: #aab3c0;
  --grid: #e6ebf1;
  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Geist", "Segoe UI", system-ui, sans-serif;
  --f-mono: "Geist Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b111c; --surface: #121a28; --ink: #e7ecf4; --muted: #9aa6b8; --line: #243044;
    --accent: #7d9bff; --accent-soft: #1b2a4d; --warm: #f29a45;
    --s1: #3987e5; --s2: #d95926; --s0: #4a5568; --grid: #1c2636; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b111c; --surface: #121a28; --ink: #e7ecf4; --muted: #9aa6b8; --line: #243044;
  --accent: #7d9bff; --accent-soft: #1b2a4d; --warm: #f29a45;
  --s1: #3987e5; --s2: #d95926; --s0: #4a5568; --grid: #1c2636; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 var(--f-body);
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); }
code, .mono { font-family: var(--f-mono); font-size: .86em; }
code { background: var(--accent-soft); padding: .05em .35em; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }

main {
  max-width: 1080px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
@media (min-width: 1240px) { main { padding-left: 200px; max-width: 1280px; } }

/* depth rail */
.rail { display: none; }
@media (min-width: 1240px) {
  .rail {
    display: block; position: fixed; left: max(24px, env(safe-area-inset-left, 0px)); top: 50%;
    transform: translateY(-50%); z-index: 5; font: 500 12px/1.2 var(--f-mono);
  }
  .rail-cap { color: var(--muted); text-transform: uppercase; letter-spacing: .12em; margin: 0 0 14px; }
  .rail ol { list-style: none; margin: 0; padding: 0; position: relative; display: grid; gap: 18px; }
  .rail ol::before { content: ""; position: absolute; left: 4px; top: 6px; bottom: 6px; width: 1px; background: var(--line); }
  .rail a { display: flex; align-items: center; gap: 12px; color: var(--muted); text-decoration: none; }
  .rail i { width: 9px; height: 9px; border-radius: 50%; background: var(--bg); border: 1px solid var(--muted); position: relative; transition: transform .25s, background .25s; }
  .rail li.on a { color: var(--ink); }
  .rail li.on i { background: var(--accent); border-color: var(--accent); transform: scale(1.35); }
  .rail li.past i { background: var(--muted); }
}

/* sections */
.sec { padding-block: 72px; border-top: 1px solid var(--line); }
.sec-head { max-width: 680px; margin-bottom: 36px; }
.sec-head p:last-child { color: var(--muted); margin: 0; }
.lvl { font: 500 12px/1 var(--f-mono); letter-spacing: .12em; text-transform: uppercase; color: var(--accent); margin: 0 0 12px; }
h1, h2, h3 { font-family: var(--f-display); text-wrap: balance; margin: 0; }
h2 { font-size: clamp(28px, 4vw, 40px); line-height: 1.1; font-weight: 600; letter-spacing: -.02em; margin-bottom: 12px; }
h3 { font-size: 19px; line-height: 1.25; font-weight: 600; }
.sub { margin: 56px 0 20px; font-size: 22px; }

/* hero */
.hero { border-top: 0; padding-block: 88px 64px; }
.eyebrow { font: 500 13px/1 var(--f-mono); color: var(--muted); letter-spacing: .06em; margin: 0 0 28px; }
.hero h1 {
  font-size: clamp(42px, 8vw, 92px); line-height: .98; font-weight: 800; letter-spacing: -.035em;
  font-variation-settings: "opsz" 96; max-width: 12ch;
}
.lede { font-size: clamp(18px, 2.1vw, 21px); max-width: 60ch; color: var(--muted); margin: 28px 0 40px; }

.stream { margin: 0 0 44px; max-width: 720px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.stream-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); font: 12px/1.4 var(--f-mono); color: var(--muted); }
.stream-meter { margin-left: auto; font-variant-numeric: tabular-nums; }
.stream-meter b { color: var(--ink); font-weight: 500; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
.stream-text { margin: 0; padding: 18px 16px 20px; font: 17px/1.6 var(--f-mono); min-height: 7.2em; }
.stream-text .tk { animation: tk .35s ease-out; border-radius: 3px; }
@keyframes tk { from { background: var(--accent-soft); } }
.stream-text .caret { display: inline-block; width: .55em; height: 1.05em; background: var(--accent); vertical-align: -0.15em; margin-left: 2px; animation: pulse 1s steps(1) infinite; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; margin: 0; max-width: 820px; border-top: 1px solid var(--line); }
.stats div { padding: 18px 16px 0 0; }
.stats dt { font: 12px/1.3 var(--f-mono); color: var(--muted); order: 2; }
.stats dd { margin: 0 0 4px; font: 600 clamp(32px, 4.5vw, 46px)/1 var(--f-display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stats div { display: flex; flex-direction: column-reverse; justify-content: flex-end; }
.stats small { font-size: .5em; color: var(--muted); margin-left: 2px; }
@media (max-width: 620px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 8px; } }
.scrollhint { margin: 40px 0 0; font-size: 14px; color: var(--muted); }

.chip {
  font: 500 14px/1 var(--f-body); color: var(--muted); background: transparent; border: 1px solid transparent;
  padding: 9px 14px; border-radius: 7px; cursor: pointer; white-space: nowrap;
}
.chip:hover { color: var(--ink); background: var(--bg); }

/* gallery */
.gallery { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.gallery figure { margin: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.gallery img { border-radius: 8px; width: 100%; }
.gallery figcaption { font-size: 14px; color: var(--muted); }
.gallery figcaption b { color: var(--ink); font-weight: 600; }
.g-wide, .g-pair, .g-crop { grid-column: span 2; }
.g-crop img { aspect-ratio: 16 / 10; object-fit: cover; object-position: top left; border: 1px solid var(--line); }
.g-full { grid-column: 1 / -1; }
.g-full img { border: 1px solid var(--line); }
.g-pair .pair { flex: 1; }
@media (max-width: 820px) { .gallery { grid-template-columns: minmax(0, 1fr); } .g-wide, .g-pair, .g-crop, .g-full { grid-column: auto; } }
.pair { display: grid; grid-template-columns: minmax(0, .62fr) auto minmax(0, 1fr); align-items: center; gap: 10px; background: #000; border-radius: 8px; padding: 10px; }
.pair img { border-radius: 4px; }
.pair-arrow { color: #fff; font: 600 22px var(--f-display); }
.pixel { image-rendering: pixelated; }

/* cards */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.chip { border-color: var(--line); background: var(--surface); }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 560px) { .cards { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; display: flex; flex-direction: column; transition: transform .2s, border-color .2s; }
.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card canvas { width: 100%; height: 110px; display: block; background: var(--bg); border-bottom: 1px solid var(--line); }
.card-body { padding: 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.card h3 { font-size: 18px; }
.card p { margin: 0; font-size: 15px; color: var(--muted); }
.card .fact { font: 12px/1.4 var(--f-mono); color: var(--ink); margin-top: auto; padding-top: 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tags span { font: 11px/1 var(--f-mono); padding: 4px 6px; border-radius: 4px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.card[hidden] { display: none; }
.card-link { font: 500 13px var(--f-mono); text-decoration: none; }
.card-link:hover { text-decoration: underline; }
.card .fact { margin-top: auto; }
.lab { margin-top: 32px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; }
.lab > p { margin: 6px 0 16px; font-size: 14px; color: var(--muted); max-width: 70ch; }
.lab-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 900px) { .lab-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .lab-grid { grid-template-columns: minmax(0, 1fr); } }
.lab-item { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: var(--bg); display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.lab-item b { font: 600 15px var(--f-display); }
.lab-item span { font: 12px/1.45 var(--f-mono); color: var(--muted); }

/* flows */
.flow-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 24px; margin-bottom: 16px; }
.flow-card > p { max-width: 70ch; margin: 8px 0 20px; font-size: 15px; }
.flow { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 24px 22px; }
.flow li {
  position: relative; flex: 1 1 0; min-width: 88px; padding: 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); display: flex; flex-direction: column; gap: 4px;
}
.flow li b { font: 600 15px/1.2 var(--f-display); }
.flow li span { font: 12px/1.4 var(--f-mono); color: var(--muted); }
.flow li:not(:last-child)::after {
  content: ""; position: absolute; right: -18px; top: 50%; width: 14px; height: 2px;
  background: linear-gradient(90deg, var(--line), var(--accent));
}
.flow li.hot { border-color: var(--accent); background: var(--accent-soft); }
.flow li { animation: none; }
.flow.flowing li::before {
  content: ""; position: absolute; inset: -1px; border-radius: 8px; border: 1px solid var(--accent); opacity: 0;
  animation: lit 3.6s calc(var(--i) * .45s) infinite;
}
@keyframes lit { 0%, 30%, 100% { opacity: 0; } 8%, 18% { opacity: 1; } }
@media (max-width: 620px) {
  .flow { flex-direction: column; gap: 18px; }
  .flow li:not(:last-child)::after { right: auto; left: 22px; top: auto; bottom: -15px; width: 2px; height: 12px; }
}

/* forks */
.diffchart, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; margin-bottom: 16px; min-width: 0; }
.charttitle { font-size: 16px; margin-bottom: 4px; }
.chartsub { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.forks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
@media (max-width: 760px) { .forks { grid-template-columns: minmax(0, 1fr); } }
.fork { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; min-width: 0; }
.fork header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.fork header .mono { color: var(--muted); font-size: 12px; }
.fork ul { margin: 0; padding-left: 18px; display: grid; gap: 8px; font-size: 14.5px; }
.fork li::marker { color: var(--accent); }
.explain { margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; }
.explain figcaption { font-size: 14px; color: var(--muted); max-width: 75ch; margin-top: 12px; }
.moe { margin-top: 12px; }
.moe svg, .chart svg, #diffbars svg { display: block; width: 100%; overflow: visible; }

/* diff bars */
.drow { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 12px; align-items: center; padding: 6px 0; font-size: 14px; }
.drow b { font-family: var(--f-display); font-weight: 600; }
.dtrack { display: flex; align-items: center; gap: 2px; min-width: 0; }
.dadd, .ddel { height: 14px; border-radius: 0 4px 4px 0; transform-origin: left; }
.dadd { background: var(--s1); }
.ddel { background: var(--s2); border-radius: 0 4px 4px 0; }
.dnum { font: 12px var(--f-mono); color: var(--muted); margin-left: 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
@media (max-width: 520px) { .drow { grid-template-columns: minmax(0, 1fr); gap: 4px; } }

/* bench */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid2 .panel { margin-bottom: 0; }
.grid2 + .panel { margin-top: 16px; }
@media (max-width: 820px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.chart { height: 250px; position: relative; }
.chart.short { height: 210px; }
.dumb { display: grid; gap: 2px; }
.drow2 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 2fr) 92px; gap: 14px; align-items: center; padding: 8px 0; border-top: 1px solid var(--grid); font-size: 14px; }
.drow2:first-child { border-top: 0; }
.drow2 .what b { display: block; font-weight: 600; }
.drow2 .what span { color: var(--muted); font-size: 12px; font-family: var(--f-mono); }
.dbar { position: relative; height: 14px; }
.dbar .was { position: absolute; inset: 0; border-radius: 0 4px 4px 0; background: var(--grid); }
.dbar .now { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--s1); transition: width 1s cubic-bezier(.2,.7,.2,1); }
.drow2 .gain { font: 600 18px/1 var(--f-display); text-align: right; font-variant-numeric: tabular-nums; }
.drow2 .gain small { display: block; font: 11px var(--f-mono); color: var(--muted); margin-top: 3px; }
@media (max-width: 620px) {
  .drow2 { grid-template-columns: minmax(0, 1fr) 80px; }
  .drow2 .dbar { grid-column: 1 / -1; order: 3; }
}

.statusbar { display: flex; gap: 2px; height: 28px; margin: 12px 0; }
.statusbar div { border-radius: 4px; display: flex; align-items: center; padding-left: 8px; font: 500 12px var(--f-mono); color: #fff; overflow: hidden; white-space: nowrap; min-width: 0; }

/* tooltip */
.tip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--ink); color: var(--bg);
  padding: 8px 10px; border-radius: 6px; font: 12px/1.45 var(--f-body); max-width: 240px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
}
.tip b { font: 600 15px/1.2 var(--f-display); display: block; }

/* svg text */
svg text { font-family: var(--f-mono); font-size: 11px; fill: var(--muted); }
svg .lbl { fill: var(--ink); font-family: var(--f-body); font-size: 12px; }
svg .hit { fill: transparent; cursor: pointer; }

.foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 20px; padding-block: 56px 72px; border-top: 1px solid var(--line); }
.foot-big { font: 700 28px/1.1 var(--f-display); margin: 0 0 6px; }
.foot p { margin: 0; }
.btn { font: 500 15px var(--f-mono); padding: 12px 18px; border: 1px solid var(--ink); border-radius: 8px; color: var(--ink); text-decoration: none; }
.btn:hover { background: var(--ink); color: var(--bg); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}
.forks .fork:last-child:nth-child(odd) { grid-column: 1 / -1; }
.foot-links { display: flex; flex-wrap: wrap; gap: 10px; }
.eyebrow a { color: var(--muted); text-underline-offset: 3px; }
.eyebrow a:hover { color: var(--accent); }

/* card detail layer */
.card { position: relative; cursor: pointer; }
.more-hint { font: 11px var(--f-mono); color: var(--accent); }
.card-more {
  position: absolute; inset: 0; z-index: 2; background: var(--surface); padding: 14px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  opacity: 0; visibility: hidden; transform: translateY(6px); transition: opacity .2s, transform .2s, visibility 0s .2s;
}
.card:hover .card-more, .card:focus-within .card-more, .card.open .card-more {
  opacity: 1; visibility: visible; transform: none; transition: opacity .2s, transform .2s;
}
.card-more img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; object-position: top left; border-radius: 6px; border: 1px solid var(--line); flex: none; }
.card-more h4 { margin: 2px 0 0; font: 600 12px var(--f-mono); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.card-more ul { margin: 0; padding-left: 16px; display: grid; gap: 6px; font-size: 13px; line-height: 1.45; }
.card-more li::marker { color: var(--accent); }
@media (hover: none) { .card:hover:not(.open) .card-more { opacity: 0; visibility: hidden; } }
.card { overflow: visible; }
.card canvas { border-radius: var(--r) var(--r) 0 0; }
.card:hover, .card:focus-within, .card.open { z-index: 6; }
.card-more {
  inset: auto; top: -6px; left: -6px; right: -6px; min-height: calc(100% + 12px); overflow: visible;
  border: 1px solid var(--accent); border-radius: var(--r); box-shadow: 0 18px 48px rgba(0, 0, 0, .35);
}

.hero h1 { max-width: 14ch; }
.hero h1 em { font-style: normal; color: var(--accent); }
.streams { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 0 0 44px; max-width: 980px; }
.streams .stream { margin: 0; max-width: none; min-width: 0; }
.stream-head b { color: var(--ink); font-weight: 500; }
.streams .stream-text { font-size: 15px; min-height: 8.4em; }
@media (max-width: 720px) { .streams { grid-template-columns: minmax(0, 1fr); } }

/* chat assistant */
.chat-fab {
  position: fixed; z-index: 20; display: inline-flex; align-items: center; gap: 10px;
  right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px));
  font: 500 14px/1 var(--f-body); color: var(--surface); background: var(--ink);
  border: 0; border-radius: 999px; padding: 13px 18px; cursor: pointer;
  box-shadow: 0 8px 24px rgb(0 0 0 / .18); transition: transform .2s;
}
.chat-fab:hover { transform: translateY(-2px); }
.chat-fab[aria-expanded="true"] { display: none; }
.chat {
  position: fixed; z-index: 21; display: flex; flex-direction: column;
  right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px));
  width: min(400px, calc(100vw - 32px)); height: min(600px, calc(100dvh - 32px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 18px 48px rgb(0 0 0 / .22); overflow: hidden;
}
.chat[hidden] { display: none; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.chat-head b { display: block; font: 600 16px/1.2 var(--f-display); }
.chat-head .mono { font-size: 11px; color: var(--muted); }
.chat-x { border: 0; background: none; color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.chat-x:hover { background: var(--bg); color: var(--ink); }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
.msg { margin: 0; max-width: 88%; padding: 10px 13px; border-radius: 12px; font-size: 14.5px; line-height: 1.55; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot p { margin: 0 0 .5em; } .msg.bot p:last-child { margin: 0; }
.msg.bot ul { margin: .2em 0 .5em; padding-left: 1.2em; }
.msg.err { color: var(--warm); }
.msg.wait::after { content: "…"; animation: pulse 1.2s infinite; }
.msg-meta { align-self: flex-start; margin-top: -6px; font: 11px/1.4 var(--f-mono); color: var(--muted); max-width: 88%; }
.chat-sugg { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-sugg button {
  font: 13px/1.3 var(--f-body); text-align: left; color: var(--accent); background: var(--accent-soft);
  border: 1px solid transparent; border-radius: 999px; padding: 7px 12px; cursor: pointer;
}
.chat-sugg button:hover { border-color: var(--accent); }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-form input {
  flex: 1; min-width: 0; font: 15px/1.4 var(--f-body); color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.chat-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.chat-form button { border: 0; border-radius: 10px; width: 44px; font-size: 18px; color: #fff; background: var(--accent); cursor: pointer; }
.chat-form button:disabled { opacity: .5; cursor: default; }
@media (max-width: 520px) {
  .chat { right: 0; bottom: 0; width: 100vw; height: 88dvh; border-radius: 14px 14px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
}
