/* Gearbx: precision as material. Tokens in DESIGN.md. */

:root {
  --paper: oklch(0.972 0.006 250);
  --paper-2: oklch(0.948 0.008 250);
  --paper-3: oklch(0.92 0.01 250);
  --ink: oklch(0.23 0.025 265);
  --ink-2: oklch(0.45 0.02 265);
  --ink-3: oklch(0.62 0.015 260);
  --rule: oklch(0.86 0.01 255);
  --brass: oklch(0.72 0.12 78);
  --verdigris: oklch(0.58 0.09 190);
  --vermilion: oklch(0.56 0.19 30);
  --brass-soft: oklch(0.72 0.12 78 / 0.16);
  --verdigris-soft: oklch(0.58 0.09 190 / 0.14);
  --vermilion-soft: oklch(0.56 0.19 30 / 0.12);

  --serif: "Spectral", "Iowan Old Style", Georgia, serif;
  --sans: "Schibsted Grotesk", ui-sans-serif, system-ui, sans-serif;
  --mono: "Fragment Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --gut: clamp(1.25rem, 4vw, 3rem);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: oklch(0.19 0.015 265);
    --paper-2: oklch(0.225 0.017 265);
    --paper-3: oklch(0.27 0.02 265);
    --ink: oklch(0.93 0.008 250);
    --ink-2: oklch(0.74 0.015 255);
    --ink-3: oklch(0.58 0.015 258);
    --rule: oklch(0.33 0.02 262);
    --brass: oklch(0.8 0.12 80);
    --verdigris: oklch(0.72 0.1 190);
    --vermilion: oklch(0.68 0.17 32);
    --brass-soft: oklch(0.8 0.12 80 / 0.16);
    --verdigris-soft: oklch(0.72 0.1 190 / 0.14);
    --vermilion-soft: oklch(0.68 0.17 32 / 0.14);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.0625rem, 0.98rem + 0.3vw, 1.1875rem);
  line-height: 1.65;
  font-feature-settings: "kern", "liga", "onum";
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
::selection { background: var(--brass-soft); }
a { color: inherit; text-decoration-color: var(--rule); text-underline-offset: 0.2em; text-decoration-thickness: 1px; transition: text-decoration-color 0.3s var(--ease); }
a:hover { text-decoration-color: var(--vermilion); }
img, svg, canvas { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--vermilion); outline-offset: 3px; border-radius: 2px; }

/* ---------- Paper grid ---------- */
.grid {
  display: grid;
  grid-template-columns:
    [full-start] minmax(var(--gut), 1fr)
    [wide-start] minmax(0, 5rem)
    [text-start] minmax(0, 40rem)
    [text-end] minmax(0, 3rem)
    [side-start] minmax(0, 15rem)
    [side-end wide-end] minmax(var(--gut), 1.5fr)
    [full-end];
}
.grid > * { grid-column: text; }
.grid > .wide { grid-column: wide; }
.grid > .full { grid-column: full; }
.side {
  grid-column: side;
  font-family: var(--sans);
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--ink-2);
  align-self: start;
}
@media (max-width: 64rem) {
  .grid {
    grid-template-columns:
      [full-start] var(--gut) [wide-start text-start side-start] minmax(0, 1fr) [text-end side-end wide-end] var(--gut) [full-end];
  }
  .side { margin: -0.5rem 0 1.5rem; padding-left: 0.9rem; border-left: 1px solid var(--rule); }
}

/* ---------- Top bar ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 2rem;
  padding: 1rem var(--gut);
  font-family: var(--sans); font-size: 0.875rem;
  background: color-mix(in oklch, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.2) blur(10px);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.4s var(--ease);
}
.bar.scrolled { border-bottom-color: var(--rule); }
.wordmark { display: inline-flex; align-items: center; gap: 0.55rem; font-family: var(--serif); font-weight: 500; font-size: 1.125rem; letter-spacing: -0.01em; text-decoration: none; }
.wordmark svg { width: 18px; height: 18px; }
.bar nav { display: flex; gap: 1.6rem; margin-left: auto; }
.bar nav a { text-decoration: none; color: var(--ink-2); transition: color 0.25s var(--ease); }
.bar nav a:hover, .bar nav a[aria-current="page"] { color: var(--ink); }
.bar .install-link { color: var(--ink); border-bottom: 1px solid var(--vermilion); padding-bottom: 1px; }
@media (max-width: 40rem) {
  .bar { gap: 1rem; }
  .bar nav { gap: 1rem; }
  .bar nav .opt { display: none; }
}

/* ---------- Type ---------- */
h1, h2, h3 { font-weight: 300; letter-spacing: -0.02em; line-height: 1.08; margin: 0; text-wrap: balance; }
h2 { font-size: clamp(2rem, 1.3rem + 2.6vw, 3.25rem); margin: 0 0 1.75rem; }
h3 { font-size: 1.5rem; font-weight: 400; margin: 2.5rem 0 0.75rem; letter-spacing: -0.01em; }
p { margin: 0 0 1.25rem; text-wrap: pretty; }
.lede { font-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.6rem); line-height: 1.5; color: var(--ink); font-weight: 300; }
.muted { color: var(--ink-2); }
em { font-style: italic; }
strong { font-weight: 500; }
code, kbd { font-family: var(--mono); font-size: 0.86em; }
:not(pre) > code { background: var(--paper-2); padding: 0.1em 0.35em; border-radius: 4px; }

.g-low { color: var(--brass); }
.g-mid { color: var(--verdigris); }
.g-high { color: var(--vermilion); }

/* ---------- Sections ---------- */
section { padding-block: clamp(4rem, 9vw, 8.5rem); }
section + section { padding-top: 0; }
.chapter-num { font-family: var(--mono); font-size: 0.75rem; color: var(--ink-3); margin-bottom: 1.25rem; display: block; }

/* ---------- Hero ---------- */
.hero { padding-top: clamp(2.5rem, 7vw, 6rem); padding-bottom: clamp(3rem, 7vw, 6rem); }
.hero-stage { grid-column: wide; position: relative; }
.hero h1 {
  font-size: clamp(3.25rem, 1.4rem + 7.4vw, 8rem);
  font-weight: 200;
  line-height: 0.98;
  letter-spacing: -0.035em;
  max-width: 14ch;
}
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: pan-y; }
.hero.gl h1 { color: transparent; }
.hero .hint {
  grid-column: wide; margin-top: 1rem;
  font-family: var(--sans); font-size: 0.8125rem; color: var(--ink-3);
  display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap;
}
.legend { display: inline-flex; gap: 1rem; }
.legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.legend i { width: 0.6rem; height: 0.6rem; border-radius: 50%; display: inline-block; }
.legend .l i { background: var(--brass); }
.legend .m i { background: var(--verdigris); }
.legend .h i { background: var(--ink); }
.hero-copy { margin-top: clamp(2.5rem, 5vw, 4rem); }
.hero-actions > .cmd { min-width: 0; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: center; margin-top: 2rem; font-family: var(--sans); font-size: 0.9375rem; }

/* ---------- Command line ---------- */
.cmd {
  display: inline-flex; align-items: center; gap: 0.9rem;
  font-family: var(--mono); font-size: 0.9rem;
  padding: 0.7rem 0.8rem 0.7rem 1rem;
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: 8px;
  max-width: 100%;
}
.cmd .p { color: var(--ink-3); user-select: none; }
.cmd code { background: none; padding: 0; font-size: inherit; white-space: nowrap; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.copy {
  border: 0; background: none; cursor: pointer; color: var(--ink-3);
  font-family: var(--sans); font-size: 0.75rem; padding: 0.25rem 0.4rem; border-radius: 4px;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}
.copy:hover { color: var(--ink); background: var(--paper-3); }
.copy.done { color: var(--verdigris); }
.textlink { text-decoration: none; border-bottom: 1px solid var(--rule); padding-bottom: 2px; transition: border-color 0.3s var(--ease); }
.textlink:hover { border-color: var(--vermilion); }

/* ---------- Figures ---------- */
figure { margin: 2.5rem 0 3rem; }
.fig {
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: clamp(1.25rem, 3vw, 2.25rem);
  position: relative;
}
figcaption { font-family: var(--sans); font-size: 0.875rem; line-height: 1.55; color: var(--ink-2); margin-top: 1rem; max-width: 46rem; }
figcaption b { color: var(--ink); font-weight: 500; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.5rem; font-family: var(--sans); font-size: 0.8125rem; color: var(--ink-2); }
.readout { font-family: var(--mono); font-size: 0.8125rem; color: var(--ink); font-variant-numeric: tabular-nums; }
.readouts { display: flex; flex-wrap: wrap; gap: 0.5rem 2.25rem; margin-top: 1.25rem; font-family: var(--sans); font-size: 0.8125rem; color: var(--ink-2); }
.readouts div { display: grid; gap: 0.15rem; }
.readouts .readout { font-size: 1.05rem; }
.pill-btn {
  border: 1px solid var(--rule); background: var(--paper); cursor: pointer;
  border-radius: 999px; padding: 0.35rem 0.9rem; font-family: var(--sans); font-size: 0.8125rem;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
}
.pill-btn:hover { border-color: var(--ink-3); }
.pill-btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

input[type="range"] { -webkit-appearance: none; appearance: none; background: none; width: min(22rem, 100%); height: 1.5rem; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--rule); border-radius: 2px; }
input[type="range"]::-moz-range-track { height: 2px; background: var(--rule); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--thumb, var(--ink)); margin-top: -7px; border: 3px solid var(--paper); box-shadow: 0 0 0 1px var(--thumb, var(--ink)); transition: transform 0.2s var(--ease); }
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--thumb, var(--ink)); border: 3px solid var(--paper); box-shadow: 0 0 0 1px var(--thumb, var(--ink)); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.2); }

/* Fig 1: token sentence */
.tokens { font-size: clamp(1.25rem, 1rem + 1.1vw, 1.75rem); line-height: 1.9; font-weight: 300; min-height: 4em; }
.tok {
  position: relative; display: inline; cursor: default; border-radius: 3px;
  padding: 0.06em 0.02em; transition: background 0.25s var(--ease), color 0.25s var(--ease), opacity 0.4s var(--ease);
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat; background-size: 100% 2px; background-position: 0 92%;
}
.tok.low { color: var(--ink-2); background-image: radial-gradient(circle, var(--brass) 0.9px, transparent 1.2px); background-size: 4px 4px; background-repeat: repeat-x; background-position: 0 94%; }
.tok.mid { background-image: linear-gradient(var(--verdigris), var(--verdigris)); background-size: 100% 1px; }
.tok.high { background-image: linear-gradient(var(--vermilion), var(--vermilion)); background-size: 100% 2px; font-weight: 400; }
.tok.pending { opacity: 0; }
.tok:hover, .tok.focus { background-color: var(--paper-3); }
.dist {
  margin-top: 1.5rem; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 1.5rem 2.5rem; align-items: start;
  font-family: var(--sans); font-size: 0.8125rem; color: var(--ink-2); min-height: 9.5rem;
}
.dist h4 { margin: 0 0 0.35rem; font-family: var(--serif); font-weight: 300; color: var(--ink); font-size: 2.25rem; line-height: 1.1; min-height: 1.1em; }
.dist-bars { display: grid; gap: 0.35rem; }
.dist-row { display: grid; grid-template-columns: 6.5rem 1fr 3rem; gap: 0.6rem; align-items: center; }
.dist-row .w { font-family: var(--mono); color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dist-row .b { height: 6px; border-radius: 3px; background: var(--rule); overflow: hidden; }
.dist-row .b > span { display: block; height: 100%; border-radius: 3px; background: var(--ink-3); transform-origin: left; transition: transform 0.5s var(--ease); }
.dist-row .n { font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
.spark { width: 100%; height: 64px; }
@media (max-width: 40rem) { .dist { grid-template-columns: 1fr; } }

/* Fig 2 + 3 SVG */
.plot { width: 100%; height: auto; overflow: visible; font-family: var(--mono); font-size: 11px; }
.plot .axis { stroke: var(--rule); stroke-width: 1; }
.plot .lvl { stroke: var(--rule); stroke-width: 1; }
.plot text { fill: var(--ink-3); paint-order: stroke; stroke: var(--paper-2); stroke-width: 4px; stroke-linejoin: round; }
.handle { cursor: ns-resize; }
.handle .grip { fill: var(--paper); stroke-width: 1.5; }
.handle:focus-visible { outline: none; }
.handle:focus-visible .grip { stroke-width: 3; }

/* Gear ribbon */
.ribbon rect { transition: fill 0.35s var(--ease); }

/* Loop diagram */
.loop { display: grid; grid-template-columns: minmax(0, 20rem) minmax(0, 1fr); gap: clamp(2rem, 5vw, 4.5rem); align-items: center; }
.loop svg { width: 100%; height: auto; }
.loop ol { list-style: none; margin: 0; padding: 0; counter-reset: s; display: grid; gap: 1.6rem; }
.loop li { counter-increment: s; display: grid; grid-template-columns: 2.25rem 1fr; gap: 0.25rem 0.5rem; color: var(--ink-2); transition: color 0.5s var(--ease); }
.loop li::before { content: counter(s, decimal-leading-zero); font-family: var(--mono); font-size: 0.75rem; padding-top: 0.45rem; color: var(--ink-3); }
.loop li b { font-weight: 400; color: var(--ink); display: block; font-size: 1.2rem; margin-bottom: 0.15rem; }
.loop li p { margin: 0; font-size: 1rem; grid-column: 2; }
.loop li.on b { color: var(--vermilion); }
@media (max-width: 52rem) { .loop { grid-template-columns: 1fr; } .loop svg { max-width: 18rem; } }

/* Results prose */
.results p { font-size: clamp(1.4rem, 1.1rem + 1.3vw, 2.2rem); line-height: 1.32; font-weight: 300; letter-spacing: -0.012em; margin-bottom: 1.6rem; }
.results .num { font-weight: 400; font-variant-numeric: lining-nums; }

/* Install */
.tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.75rem; justify-items: start; }
.panel[hidden] { display: none; }
.panel p { font-family: var(--sans); font-size: 0.875rem; color: var(--ink-2); margin: 0.5rem 0 0; }

/* Footer */
.foot { padding-block: 4rem 3rem; border-top: 1px solid var(--rule); font-family: var(--sans); font-size: 0.8125rem; color: var(--ink-3); }
.foot .row { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: baseline; }
.foot a { text-decoration: none; color: var(--ink-2); }
.foot a:hover { color: var(--ink); }
.foot .spacer { flex: 1; }

/* Reveal */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity 0.9s var(--ease), transform 0.9s var(--ease); }
.reveal.in { opacity: 1; transform: none; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-family: var(--sans); font-size: 0.875rem; margin: 1.25rem 0 2rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 0.6rem 1rem 0.6rem 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 500; color: var(--ink-2); font-size: 0.8125rem; }
td code { white-space: nowrap; }
td.num, th.num { text-align: right; font-family: var(--mono); font-size: 0.8125rem; }
.table-wrap { overflow-x: auto; }

/* Code blocks */
pre {
  margin: 1.25rem 0 1.75rem; padding: 1.1rem 1.25rem; overflow-x: auto;
  background: var(--paper-2); border: 1px solid var(--rule); border-radius: 10px;
  font-family: var(--mono); font-size: 0.8125rem; line-height: 1.7; position: relative;
}
pre code { background: none; padding: 0; font-size: inherit; }
pre .copy { position: absolute; top: 0.5rem; right: 0.5rem; }
.tk-c { color: var(--ink-3); }
.tk-s { color: var(--verdigris); }
.tk-k { color: var(--vermilion); }
.tk-n { color: oklch(0.55 0.11 70); }
@media (prefers-color-scheme: dark) { .tk-n { color: var(--brass); } }

/* Docs layout */
.docs { display: grid; grid-template-columns: [full-start] minmax(var(--gut), 1fr) [toc-start] 13rem [toc-end] 4rem [text-start] minmax(0, 44rem) [text-end] minmax(var(--gut), 2fr) [full-end]; padding-block: clamp(3rem, 6vw, 5rem); }
.docs .toc { grid-column: toc; position: sticky; top: 5.5rem; align-self: start; font-family: var(--sans); font-size: 0.8125rem; max-height: calc(100vh - 7rem); overflow-y: auto; }
.docs .toc p { margin: 1.4rem 0 0.4rem; color: var(--ink-3); font-size: 0.75rem; }
.docs .toc p:first-child { margin-top: 0; }
.docs .toc a { display: block; padding: 0.28rem 0 0.28rem 0.85rem; text-decoration: none; color: var(--ink-2); border-left: 1px solid var(--rule); transition: color 0.2s var(--ease), border-color 0.2s var(--ease); }
.docs .toc a:hover { color: var(--ink); }
.docs .toc a.active { color: var(--ink); border-left-color: var(--vermilion); }
.docs article { grid-column: text; min-width: 0; }
.docs article h2 { font-size: clamp(1.75rem, 1.4rem + 1.4vw, 2.4rem); margin: 4.5rem 0 1rem; scroll-margin-top: 5.5rem; }
.docs article h1 { font-size: clamp(2.5rem, 1.8rem + 3vw, 4.25rem); font-weight: 200; margin-bottom: 1.25rem; }
.docs article h3 { scroll-margin-top: 5.5rem; }
.note { font-family: var(--sans); font-size: 0.875rem; line-height: 1.6; color: var(--ink-2); padding: 1rem 1.15rem; background: var(--verdigris-soft); border-radius: 10px; margin: 1.25rem 0 1.75rem; }
.note b { color: var(--ink); font-weight: 500; }
@media (max-width: 60rem) {
  .docs { grid-template-columns: [full-start] var(--gut) [toc-start text-start] minmax(0, 1fr) [toc-end text-end] var(--gut) [full-end]; }
  .docs .toc { position: static; max-height: none; margin-bottom: 2.5rem; display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }
  .docs .toc p { display: none; }
  .docs .toc a { border: 0; padding: 0.2rem 0; }
}

/* Benchmarks */
.bars { display: grid; gap: 0.9rem; }
.bars .row { display: grid; grid-template-columns: 7.5rem 1fr 4.5rem; gap: 1rem; align-items: center; font-family: var(--sans); font-size: 0.875rem; }
.bars .track { height: 10px; background: var(--paper-3); border-radius: 5px; overflow: hidden; }
.bars .track span { display: block; height: 100%; border-radius: 5px; transform-origin: left; transform: scaleX(0); transition: transform 1.2s var(--ease); }
.in .bars .track span, .bars.in .track span { transform: scaleX(var(--v)); }
.bars .val { font-family: var(--mono); font-size: 0.8125rem; text-align: right; font-variant-numeric: tabular-nums; }
.stack { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; }
.stack span { height: 100%; transition: flex-grow 1s var(--ease); }
.multiples { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(22rem, 100%), 1fr)); gap: 2rem 2.5rem; }
.multiples h4 { margin: 0 0 0.5rem; font-family: var(--sans); font-weight: 500; font-size: 0.875rem; }

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