/* ───────────────────────────── Tokens ───────────────────────────── */
:root {
  --paper: #f2eee6;
  --paper-2: #ebe6dc;
  --ink: #17161a;
  --ink-2: #3a383f;
  --muted: #6f6a62;
  --line: #d3cdc0;
  --line-2: #bdb6a7;
  --grid: rgba(23, 22, 26, 0.055);
  --accent: #3f47a0;
  --accent-tint: rgba(63, 71, 160, 0.10);
  --rust: #b3432a;
  --rust-tint: rgba(179, 67, 42, 0.12);

  --display: "Roboto Condensed", "Arial Narrow", system-ui, sans-serif;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", "JetBrains Mono", "SFMono-Regular", Consolas, monospace;

  --gutter: clamp(16px, 4vw, 56px);
  --max: 1280px;
}

* { box-sizing: border-box; }
.grown-body > *, .features-body > *, .hero-head > *, .hero-foot > *, .features-right { min-width: 0; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-inline: var(--gutter);
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.92em; }
p code { padding: 0 0.15em; }
::selection { background: var(--accent); color: var(--paper); }

h1, h2 {
  font-family: var(--display);
  font-weight: 300;
  letter-spacing: -0.01em;
  line-height: 0.98;
  margin: 0;
}

/* ───────────────────────────── Header ───────────────────────────── */
.top {
  max-width: var(--max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 700; font-size: 20px; letter-spacing: 0.02em; text-transform: uppercase; }
.mark { width: 22px; height: 22px; fill: var(--ink); }
.nav { display: flex; flex-wrap: wrap; gap: 4px 20px; font-size: 14px; color: var(--ink-2); }
.nav a { padding: 4px 0; border-bottom: 1px solid transparent; }
.nav a:hover { border-bottom-color: var(--accent); }
.nav .ext::after { content: " ↗"; color: var(--muted); font-size: 12px; }

/* ───────────────────────────── Sections ───────────────────────────── */
section { max-width: var(--max); margin: 0 auto; padding-block: clamp(64px, 10vw, 140px); border-bottom: 1px solid var(--line); }
.section-head { display: grid; grid-template-columns: 1fr; gap: 10px; margin-bottom: clamp(32px, 5vw, 64px); max-width: 860px; }
.num { font-family: var(--mono); font-size: 13px; color: var(--muted); margin: 0; letter-spacing: 0.08em; }
.section-head h2 { font-size: clamp(44px, 7vw, 88px); }
.sub { margin: 8px 0 0; color: var(--ink-2); font-size: clamp(16px, 1.4vw, 19px); max-width: 720px; }

/* ───────────────────────────── Hero ───────────────────────────── */
.hero { padding-top: clamp(32px, 5vw, 64px); }
.hero-head { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr); gap: 24px clamp(24px, 5vw, 80px); align-items: end; }
.hero-head .kicker { grid-column: 1 / -1; }
.kicker { display: flex; flex-wrap: wrap; gap: 8px 0; margin: 0 0 24px; font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.kicker span + span::before { content: "·"; margin: 0 12px; color: var(--line-2); }
.hero h1 { font-size: clamp(44px, 6.4vw, 92px); }
.lede { margin: 0; font-size: clamp(15px, 1.2vw, 17px); color: var(--ink-2); max-width: 560px; }
.lede code { white-space: nowrap; }

/* ───────────────────────────── Stage (source + tree) ───────────────────────────── */
.stage {
  --fs: 24px;   /* source font size */
  --rh: 24px;   /* tree row height */
  --cw: 14.4px; /* measured char width, set by JS */
  position: relative;
  margin-top: 40px;
  border: 1px solid var(--line-2);
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 100% 24px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 24px 100%;
  background-color: var(--paper);
}
.stage::before, .stage::after { content: ""; position: absolute; width: 10px; height: 10px; border: 1px solid var(--ink); }
.stage::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; }
.stage::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; }
.stage-scroll { overflow-x: auto; overflow-y: hidden; padding: 32px 28px 8px; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.line { position: relative; font-family: var(--mono); font-size: var(--fs); line-height: 1.3; height: calc(var(--fs) * 1.3); width: max-content; min-width: 100%; }
.mirror, .src {
  margin: 0; padding: 0; border: 0; background: transparent;
  font: inherit; letter-spacing: 0; white-space: pre; color: var(--ink);
}
.mirror { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.src {
  position: relative; z-index: 2; display: block; width: 100%; min-width: 100%;
  color: transparent; caret-color: var(--ink); outline: none; border-radius: 0;
}
.src::selection { background: var(--accent-tint); color: transparent; }
.mirror .t-punct { color: var(--muted); }
.mirror .t-lit { color: var(--accent); }
.mirror .t-var { font-style: italic; }
.mirror .t-kw { color: var(--muted); font-style: italic; }
.mirror .t-err { text-decoration: underline wavy var(--rust); text-decoration-skip-ink: none; text-underline-offset: 4px; }
.mirror .t-eoi { display: inline-block; width: 1ch; margin-left: -1ch; border-bottom: 2px solid var(--rust); height: 0.9em; vertical-align: -0.2em; }
.mirror .fresh { animation: fresh 1.4s ease-out both; }
@keyframes fresh { from { color: var(--accent); } to { color: inherit; } }
.hl { position: absolute; top: 0; height: 100%; z-index: 0; background: var(--accent-tint); border-bottom: 2px solid var(--accent); left: calc(var(--s) * var(--cw)); width: calc(var(--l) * var(--cw)); }

.tree { position: relative; width: max-content; min-width: 100%; height: 0; transition: height 0.35s ease; margin-top: 6px; }
.tree.dim { opacity: 0.35; }
.tree.ghost { opacity: 0.5; }
.tree.ghost .br i { border-style: dashed; }
.br {
  position: absolute; height: var(--rh);
  left: calc(var(--s) * var(--cw)); width: calc(var(--l) * var(--cw)); top: calc(var(--r) * var(--rh));
  transition: left 0.35s ease, width 0.35s ease, top 0.35s ease, opacity 0.25s ease;
  color: var(--ink);
  cursor: default;
}
.br i { position: absolute; left: 0; right: 0; top: 2px; height: 5px; border: 1px solid currentColor; border-top: 0; }
.br b {
  position: absolute; left: 0; right: 0; top: 8px; text-align: center;
  font: 500 10px/1.4 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; font-weight: 500;
  overflow: hidden; white-space: nowrap; text-overflow: clip;
}
.br.leaf { color: var(--muted); }
.br.leaf b { font-weight: 400; }
.br.enter { opacity: 0; }
.br.tight b { visibility: hidden; }
.br.tight:hover b { visibility: visible; overflow: visible; }
.br:hover, .br.on { color: var(--accent); }
.br:hover b, .br.on b { font-weight: 700; }

.status { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 8px 28px 12px; border-top: 1px solid var(--line); font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
.msg { margin: 0; color: var(--muted); min-height: 1.6em; line-height: 1.6; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg:empty::before { content: "\00a0"; visibility: hidden; }
.msg.err { color: var(--rust); }
.msg .cls { color: var(--ink); }
.meta { margin: 0; display: flex; gap: 18px; color: var(--muted); white-space: nowrap; line-height: 1.6; }

.stage-hero { --fs: clamp(20px, 2.6vw, 34px); --rh: 26px; margin-top: 32px; }
.stage-hero .stage-scroll { padding-top: 44px; min-height: 260px; }

.hero-foot { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-top: 28px; align-items: start; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font-family: var(--mono); font-size: 13px; padding: 6px 10px; border: 1px solid var(--line-2); background: transparent; color: var(--ink-2); cursor: pointer; }
.chip:hover { border-color: var(--ink); color: var(--ink); }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.printed { border-left: 1px solid var(--line); padding-left: 24px; }
.label { margin: 0 0 8px; font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.printed pre { margin: 0; font-family: var(--mono); font-size: 14px; line-height: 1.5; white-space: pre; overflow-x: auto; min-height: 3em; }

/* ───────────────────────────── § 01 Grown ───────────────────────────── */
.grown-body { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr); gap: clamp(24px, 4vw, 64px); align-items: start; }
.grown-stage-wrap { position: sticky; top: 24px; }
.stage-grown { --fs: clamp(15px, 1.5vw, 20px); --rh: 22px; margin-top: 0; }
.stage-grown .stage-scroll { min-height: 300px; }
.steps { list-style: none; margin: 0; padding: 0; }
.step { min-height: 62vh; display: flex; flex-direction: column; justify-content: center; padding: 24px 0 24px 24px; border-left: 1px solid var(--line); transition: border-color 0.3s; }
.step:first-child { min-height: 50vh; }
.step:last-child { min-height: 50vh; }
.step h3 { margin: 0 0 10px; font-family: var(--display); font-weight: 400; font-size: 28px; letter-spacing: 0; color: var(--muted); transition: color 0.3s; }
.step p { margin: 0; color: var(--muted); transition: color 0.3s; }
.step a { display: inline-block; margin-top: 12px; font-family: var(--mono); font-size: 13px; color: var(--muted); }
.step.on { border-left-color: var(--ink); }
.step.on h3, .step.on p { color: var(--ink); }
.step.on a { color: var(--accent); }

/* ───────────────────────────── § 02 Vocabulary ───────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.card { background: var(--paper); padding: 20px 20px 12px; display: flex; flex-direction: column; gap: 10px; position: relative; min-width: 0; }
.card.wide { grid-column: span 2; }
.card h3 { margin: 0; font: 400 13px/1.4 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); display: flex; justify-content: space-between; }
.card h3 a { color: var(--muted); font-size: 12px; }
.card h3 a:hover { color: var(--accent); }
.card .stage { --fs: 15px; --rh: 18px; margin: 0; border: 0; background: none; }
.card .stage::before, .card .stage::after { display: none; }
.card .stage-scroll { padding: 6px 0 0; }
.card .status { display: none; }

/* ───────────────────────────── § 03 Features ───────────────────────────── */
.features-body { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: clamp(24px, 4vw, 56px); align-items: start; }
.switches { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; }
.switch .name { font-family: var(--mono); font-size: 14px; }
.switch .ex { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-left: auto; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .knob { flex: none; width: 36px; height: 18px; border: 1px solid var(--ink); position: relative; }
.switch .knob::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 12px; background: var(--ink); transition: left 0.15s ease; }
.switch input:not(:checked) + .knob { border-color: var(--line-2); }
.switch input:not(:checked) + .knob::after { left: 18px; background: var(--line-2); }
.switch input:not(:checked) ~ .name { color: var(--muted); text-decoration: line-through; }
.switch input:focus-visible + .knob { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-all { display: flex; gap: 16px; padding: 12px 0; font-family: var(--mono); font-size: 12px; }
.switch-all button { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.stage-features { --fs: clamp(14px, 1.5vw, 19px); --rh: 22px; margin-top: 0; }
.stage-features .stage-scroll { min-height: 250px; }
.php { margin: 16px 0 0; padding: 18px 22px; border: 1px solid var(--line); font-family: var(--mono); font-size: 13.5px; line-height: 1.55; white-space: pre; overflow-x: auto; color: var(--ink-2); }
.php .k, .usage .k { color: var(--accent); }
.php .s, .usage .s { color: var(--ink); }
.php .c, .usage .c { color: var(--muted); }
.php .off { color: var(--rust); }
.usage .v { color: var(--ink); }

/* ───────────────────────────── § 04 Coverage ───────────────────────────── */
.rulers { display: flex; flex-direction: column; gap: 0; border-top: 1px solid var(--line); max-width: 1000px; }
.ruler { display: grid; grid-template-columns: 220px 1fr 80px; align-items: center; gap: 20px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.who { font-family: var(--display); font-size: 22px; font-weight: 400; display: flex; flex-direction: column; line-height: 1.1; }
.who small { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 4px; letter-spacing: 0.04em; }
.bar {
  position: relative; height: 22px;
  background: repeating-linear-gradient(90deg, var(--line-2) 0 1px, transparent 1px calc(100% / 83));
  border-left: 1px solid var(--ink); border-right: 1px solid var(--line-2);
}
.bar i { position: absolute; top: 4px; bottom: 4px; left: 0; width: 0; background: var(--ink-2); transition: width 1.1s cubic-bezier(0.2, 0.8, 0.2, 1); }
.ruler:first-child .bar i { background: var(--accent); }
.ruler.in .bar i { width: calc(var(--v) / 83 * 100%); }
.val { font-family: var(--mono); font-size: 22px; text-align: right; font-weight: 500; }
.val small { font-size: 12px; color: var(--muted); }
.foot-note { max-width: 720px; color: var(--ink-2); margin-top: 28px; }
.foot-note a { color: var(--accent); }

/* ───────────────────────────── § 05 Packages ───────────────────────────── */
.pipeline { margin: 0 0 40px; max-width: 1000px; overflow-x: auto; }
.pipeline svg { width: 100%; min-width: 640px; height: auto; display: block; color: var(--ink); font-family: var(--mono); font-size: 14px; }
.pipeline rect { fill: var(--paper); stroke: var(--ink); stroke-width: 1.25; }
.pipeline .inputs rect { stroke: var(--line-2); stroke-dasharray: 3 3; }
.pipeline .inputs text { fill: var(--muted); }
.pipeline text { text-anchor: middle; fill: var(--ink); dominant-baseline: middle; }
.pipeline .core { fill: var(--ink); }
.pipeline .core + text, .pipeline .core + text + .tiny { fill: var(--paper); }
.pipeline .tiny { font-size: 10px; }
.pipeline figcaption { margin-top: 10px; font-size: 14px; color: var(--muted); }

.pkg-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.pkg { background: var(--paper); padding: 22px 20px; display: flex; flex-direction: column; gap: 8px; }
.pkg:hover { background: var(--paper-2); color: inherit; }
.pkg h3 { margin: 0; font: 500 15px/1.3 var(--mono); }
.pkg p { margin: 0; font-size: 14px; color: var(--ink-2); flex: 1; }
.pkg code { font-size: 12px; color: var(--muted); }
.pkg:hover h3 { color: var(--accent); }

.usage { margin-top: 40px; max-width: 1000px; }
.usage pre { margin: 0; padding: 22px 26px; border: 1px solid var(--line); font-family: var(--mono); font-size: 14px; line-height: 1.6; overflow-x: auto; color: var(--ink-2); }

/* ───────────────────────────── Footer ───────────────────────────── */
.foot { max-width: var(--max); margin: 0 auto; padding: 48px 0 40px; font-size: 14px; color: var(--ink-2); }
.foot-grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 32px; }
.foot ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.foot a:hover { color: var(--accent); }
.brand-foot { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-family: var(--display); font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; color: var(--ink); }
.foot p { margin: 0; }
.colophon { margin-top: 40px !important; padding-top: 20px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }

/* ───────────────────────────── Tooltip ───────────────────────────── */
.tip {
  position: fixed; z-index: 50; pointer-events: none;
  background: var(--ink); color: var(--paper); font-family: var(--mono); font-size: 12px; line-height: 1.4;
  padding: 6px 9px; max-width: 360px; white-space: nowrap;
}
.tip small { display: block; color: rgba(242, 238, 230, 0.6); }

/* ───────────────────────────── Responsive ───────────────────────────── */
@media (max-width: 960px) {
  .grown-body { grid-template-columns: 1fr; }
  .grown-stage-wrap { top: 0; z-index: 5; background: var(--paper); padding-block: 8px; }
  .stage-grown .stage-scroll { min-height: 200px; }
  .step { min-height: 48vh; }
  .features-body { grid-template-columns: 1fr; }
  .switches { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
  .hero-foot { grid-template-columns: 1fr; }
  .hero-head { grid-template-columns: 1fr; }
  .printed { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 16px; }
  .foot-grid { grid-template-columns: 1fr; }
  .ruler { grid-template-columns: 1fr; gap: 8px; }
  .val { text-align: left; }
}
@media (max-width: 560px) {
  .top { flex-direction: column; align-items: flex-start; }
  .stage-scroll { padding: 24px 16px 8px; }
  .status { padding: 8px 16px 10px; flex-direction: column; gap: 4px; }
  .switches { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  .card.wide { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .br, .tree, .bar i, .switch .knob::after { transition: none; }
  .mirror .fresh { animation: none; }
  html { scroll-behavior: auto; }
}
