:root {
  --bg: #0e1116; --panel: #161b22; --line: #2a313c; --text: #e6edf3; --muted: #8b949e;
  --accent: #58a6ff; --ion: #3fb950; --agent: #f0883e; --ion-brand: #00e27b;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 24px; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.7 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }

/* Header */
.hero {
  border-bottom: 1px solid var(--line);
  background:
    radial-gradient(1100px 420px at 15% -20%, rgba(240, 136, 62, .20), transparent 60%),
    radial-gradient(900px 420px at 95% -10%, rgba(63, 185, 80, .16), transparent 60%);
}
.hero-inner { max-width: 1120px; margin: 0 auto; padding: 80px 24px 52px; }
.kicker { margin: 0 0 14px; color: var(--ion-brand); font-size: 13px; letter-spacing: .14em; text-transform: uppercase; }
.hero h1 { max-width: 920px; margin: 0 0 20px; color: var(--ion-brand); font-size: clamp(32px, 4.6vw, 52px); line-height: 1.1; letter-spacing: -.02em; }
.standfirst { max-width: 760px; margin: 0 0 28px; color: var(--muted); font-size: 19px; }
.hero-stats {
  display: flex; flex-wrap: wrap; gap: 12px; margin: 0 0 28px; padding: 0; list-style: none;
}
.hero-stats li {
  flex: 1 1 180px; max-width: 280px; margin: 0; padding: 16px 18px;
  border: 1px solid rgba(0, 226, 123, .45); border-radius: 14px;
  background: rgba(0, 226, 123, .08);
  box-shadow: 0 0 32px rgba(0, 226, 123, .12);
}
.hero-stats .stat {
  display: block; color: var(--ion-brand); font-size: clamp(36px, 4vw, 48px);
  font-weight: 750; letter-spacing: -.03em; line-height: 1;
}
.hero-stats .stat-label { display: block; margin-top: 8px; color: var(--text); font-size: 14px; line-height: 1.35; }
.hero-links { display: flex; flex-wrap: wrap; gap: 14px; }
.cta {
  display: flex; flex-direction: column; gap: 4px; flex: 1 1 300px; max-width: 420px; padding: 16px 20px;
  border: 1px solid var(--line); border-radius: 14px; background: rgba(22, 27, 34, .8);
  color: var(--text); text-decoration: none; transition: transform .15s, border-color .15s, box-shadow .15s;
}
.cta.primary { border-color: rgba(0, 226, 123, .55); background: rgba(0, 226, 123, .08); }
.cta:hover { transform: translateY(-2px); border-color: var(--ion-brand); box-shadow: 0 8px 28px rgba(0, 226, 123, .18); }
.cta-title { font-size: 16px; font-weight: 600; }
.cta-sub { color: var(--muted); font-size: 14px; }
.downloads { display: flex; flex-wrap: wrap; gap: 14px; margin: 8px 0 32px; }
.cta .arrow { display: inline-block; color: var(--ion-brand); transition: transform .15s; }
.cta:hover .arrow { transform: translateX(4px); }

/* Layout */
.layout {
  display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 56px;
  max-width: 1120px; margin: 0 auto; padding: 48px 24px 96px;
}
.toc nav { position: sticky; top: 24px; max-height: calc(100vh - 48px); overflow: auto; font-size: 14px; line-height: 1.4; }
.toc-title { margin: 0 0 10px; color: var(--muted); font-size: 12px; letter-spacing: .1em; text-transform: uppercase; }
.toc ol { margin: 0; padding: 0; list-style: none; }
.toc a { display: block; padding: 6px 12px; border-left: 2px solid var(--line); color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--text); }
.toc a.active { border-left-color: var(--agent); color: var(--text); }
.toc code { font-size: .9em; }

/* Article */
.prose { min-width: 0; max-width: 780px; }
.prose h2 { margin: 72px 0 18px; padding-top: 36px; border-top: 1px solid var(--line); font-size: 30px; line-height: 1.25; letter-spacing: -.01em; }
.prose h2:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.prose h3 { margin: 44px 0 12px; font-size: 21px; line-height: 1.3; }
.prose h2, .prose h3 { position: relative; }
.anchor { position: absolute; left: -1.1em; color: var(--muted); text-decoration: none; opacity: 0; }
.prose h2:hover .anchor, .prose h3:hover .anchor { opacity: 1; }
.prose p, .prose ul, .prose ol { margin: 0 0 18px; }
.prose ul, .prose ol { padding-left: 1.4em; }
.prose li { margin: 6px 0; }
.prose li > ul, .prose li > ol { margin: 6px 0 0; }
.prose strong { color: #fff; }
/* Sections already have a rule above each heading. */
.prose hr { display: none; }

.prose code { padding: .12em .38em; border-radius: 5px; background: #1f2630; font: .86em/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.prose pre { margin: 0 0 24px; padding: 16px 18px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); font-size: 14px; line-height: 1.55; }
.prose pre code { padding: 0; background: none; font-size: inherit; }

.table-wrap { margin: 0 0 26px; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.prose table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 1.5; font-variant-numeric: tabular-nums; }
.prose th, .prose td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.prose th { background: var(--panel); color: var(--muted); font-size: 13px; font-weight: 600; }
.prose tr:last-child td { border-bottom: 0; }
.prose tbody tr:hover td { background: rgba(255, 255, 255, .02); }
.prose th.col-ion { background: rgba(63, 185, 80, .24); color: #7ee787; }
.prose td.col-ion { background: rgba(63, 185, 80, .10); }
.prose th.col-agent { background: rgba(240, 136, 62, .24); color: #ffb37a; }
.prose td.col-agent { background: rgba(240, 136, 62, .11); }
.prose tbody tr:hover td.col-ion { background: rgba(63, 185, 80, .18); }
.prose tbody tr:hover td.col-agent { background: rgba(240, 136, 62, .18); }

.prose blockquote { margin: 0 0 24px; padding: 14px 20px; border-left: 3px solid var(--agent); border-radius: 0 10px 10px 0; background: var(--panel); }
.prose blockquote p:last-child { margin-bottom: 0; }

.calc { margin: 8px 0 36px; scroll-margin-top: 24px; }
.prose .calc h2 {
  margin: 0 0 12px; padding: 0; border: 0; font-size: 16px; line-height: 1.3;
  letter-spacing: 0; color: var(--muted); font-weight: 500;
}
.calc .panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; margin-bottom: 20px;
}
.calc .slider-panel { border-color: rgba(0, 226, 123, .35); }
/* Pin the control to the top of the viewport so it stays reachable while the
   charts and tables below update as the slider moves. */
.calc .slider-panel {
  position: sticky; top: 16px; z-index: 5;
  background: rgba(22, 27, 34, .96);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
.calc .count { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.calc .count .n { font-size: 48px; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -1px; color: var(--text); }
.calc .count .label { color: var(--muted); font-size: 18px; }
/* Only the control (count + slider + ticks) is pinned, so keep it compact and
   tight. The summary cards live in a separate panel below and scroll away. */
.calc .slider-panel { padding: 14px 20px; }
.calc .slider-panel .count .n { font-size: 34px; }
.calc .slider-panel .count .label { font-size: 15px; }
.calc input[type=range] { width: 100%; margin: 12px 0 4px; accent-color: var(--ion-brand); height: 30px; cursor: pointer; }
/* Summary panel sits flush under the pinned control, reading as one unit. */
.calc .slider-summary { margin-top: -8px; }
.calc-scale .ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.calc-length .ticks { position: relative; height: 24px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.calc .ticks button {
  background: none; border: 0; color: inherit; font: inherit; font-size: 13px; cursor: pointer; padding: 3px 6px; border-radius: 6px;
}
.calc-length .ticks button { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.calc .ticks button:hover { color: var(--text); background: rgba(255, 255, 255, .06); }
.calc .ticks button.measured { color: var(--ion-brand); font-weight: 700; }
.calc .headline { display: grid; grid-template-columns: 1fr 1fr auto; gap: 16px; align-items: stretch; }
.calc .big { border-radius: 10px; padding: 14px 16px; border: 1px solid var(--line); background: rgba(255, 255, 255, .02); }
.calc .big .who { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.calc .big .val { font-size: 36px; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin: 2px 0; }
.calc .big .sub { color: var(--muted); font-size: 13px; }
.calc .big.ion { border-color: rgba(63, 185, 80, .4); background: rgba(63, 185, 80, .08); }
.calc .big.ion .who { color: var(--ion); }
.calc .big.ion .val { color: #7ee787; }
.calc .big.agent { border-color: rgba(240, 136, 62, .3); background: rgba(240, 136, 62, .06); }
.calc .big.agent .who { color: var(--agent); }
.calc .ratio { display: flex; flex-direction: column; justify-content: center; text-align: center; padding: 0 12px; }
.calc .ratio .val { font-size: 32px; font-weight: 750; color: var(--ion-brand); }
.calc .ratio .sub { color: var(--muted); font-size: 13px; }
.calc svg text { fill: var(--muted); font-size: 11px; }
.prose .calc table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 15px; }
.prose .calc th, .prose .calc td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.prose .calc th { color: var(--muted); font-weight: 500; font-size: 13px; background: transparent; }
.prose .calc td.num { white-space: nowrap; }
.calc-scale td.num { width: 18%; }
.calc-length td.num { width: 20%; }
.prose .calc td.ion { color: var(--ion); }
.prose .calc td.agent { color: var(--agent); }
.prose .calc td.sub { padding-left: 24px; color: var(--muted); }
.calc .bars { width: 34%; }
.calc .bar { height: 8px; border-radius: 4px; margin: 4px 0; min-width: 2px; transition: width .08s linear; }
.calc .bar.ion { background: var(--ion); }
.calc .bar.agent { background: var(--agent); }
.calc .note { color: var(--muted); font-size: 13px; margin-top: 12px; }
.calc .note ul { margin: 6px 0 0; padding-left: 18px; }
.calc .options { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 18px; }
.calc .option .title { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.calc .seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.calc .seg button {
  background: none; border: 0; border-right: 1px solid var(--line); color: var(--muted);
  font: inherit; font-size: 13px; padding: 6px 10px; cursor: pointer;
}
.calc .seg button:last-child { border-right: 0; }
.calc .seg button.on { background: #21262d; color: var(--text); }
.calc .verdict { font-size: 15px; }
.calc .verdict strong { color: var(--text); }
@media (max-width: 640px) {
  .calc .headline, .calc .options { grid-template-columns: 1fr; }
  .calc .bars { display: none; }
  /* On narrow screens let the control scroll normally rather than pin. */
  .calc .slider-panel { position: static; }
  .calc .slider-summary { margin-top: 0; }
}

.player { margin: 8px 0 32px; }
.player-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.player-tabs button {
  padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
  color: var(--muted); font: inherit; font-size: 14px; cursor: pointer;
}
.player-tabs button:hover { border-color: var(--muted); color: var(--text); }
.player-tabs button[aria-selected="true"] { border-color: var(--ion-brand); background: rgba(0, 226, 123, .1); color: var(--text); }
.player-frame { aspect-ratio: 16 / 9; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: #000; }
.player-frame iframe { display: block; width: 100%; height: 100%; border: 0; }
.player figcaption { margin-top: 10px; color: var(--muted); font-size: 14px; text-align: center; }

.diagram { margin: 8px 0 32px; }
.diagram img { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 14px; }
.diagram a:hover img { border-color: var(--muted); }
.diagram figcaption { margin-top: 10px; color: var(--muted); font-size: 14px; text-align: center; }

footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
footer .inner { max-width: 1120px; margin: 0 auto; padding: 28px 24px; }

@media (min-width: 1240px) {
  .diagram, .player, .calc { margin-right: -120px; }
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; gap: 0; }
  .toc { display: none; }
  .hero-inner { padding-top: 56px; }
}
