/* Gravity Standard. Layout: a flight-rules manual — sticky instrument strip, chapter openers, prose held near 65ch, figures run wide */
:root {
  --bg: #f1f3f0;
  --surface: #fbfcfa;
  --sunk: #e5e9e6;
  --ink: #15213a;
  --muted: #586378;
  --rule: #c7ced3;
  --route: #c4470e;       /* the standard: safety orange */
  --route-soft: #c4470e1f;
  --anchor: #15213a;      /* gravity */
  --lift: #2b7a4b;

  --s-float: #2f6fd0;
  --s-accel: #0c9493;
  --s-capt: #2c8f48;
  --s-drift: #c27400;
  --s-break: #cf3328;
  --s-unst: #7444c9;
  --s-well: #111318;
  --s-well-ring: #111318;

  --f-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Source Serif 4", Georgia, "Times New Roman", serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  --step--1: 0.84rem;
  --step-0: 1.06rem;
  --step-1: 1.3rem;
  --step-2: 1.7rem;
  --step-3: clamp(1.9rem, 1.4rem + 2vw, 2.5rem);
  --step-4: clamp(2.4rem, 1.5rem + 4vw, 4rem);
  --measure: 65ch;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1424; --surface: #131d33; --sunk: #0a101d; --ink: #e4e9f2; --muted: #95a1b9; --rule: #2a3755;
    --route: #ff8a4c; --route-soft: #ff8a4c2b; --anchor: #e4e9f2; --lift: #5fc58a;
    --s-float: #5b95f0; --s-accel: #2ec4c2; --s-capt: #4cbc6c; --s-drift: #f0a43a; --s-break: #f2665b; --s-unst: #a07ef0; --s-well: #000000; --s-well-ring: #8a93a6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1424; --surface: #131d33; --sunk: #0a101d; --ink: #e4e9f2; --muted: #95a1b9; --rule: #2a3755;
  --route: #ff8a4c; --route-soft: #ff8a4c2b; --anchor: #e4e9f2; --lift: #5fc58a;
  --s-float: #5b95f0; --s-accel: #2ec4c2; --s-capt: #4cbc6c; --s-drift: #f0a43a; --s-break: #f2665b; --s-unst: #a07ef0; --s-well: #000000; --s-well-ring: #8a93a6;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--step-0)/1.62 var(--f-body);
  -webkit-font-smoothing: antialiased;
}
img, svg { max-width: 100%; }
[hidden] { display: none !important; }
a { color: inherit; text-decoration-color: var(--route); text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
a:hover { color: var(--route); }
:focus-visible { outline: 2px solid var(--route); outline-offset: 3px; border-radius: 2px; }

.gutter {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.wrap { max-width: 1120px; margin: 0 auto; }

/* ---------- instrument strip ---------- */
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 10; background: var(--surface);
}
.strip {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 9;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.strip .wrap { display: flex; align-items: center; gap: 24px; min-height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; flex: none; }
.brand svg { width: 30px; height: 30px; }
.brand b {
  font: 800 1rem/1 var(--f-display); font-stretch: 118%; letter-spacing: 0.01em; text-transform: uppercase;
}
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; min-width: 0; flex: 1; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  flex: none; text-decoration: none; padding: 8px 10px; border-radius: 4px;
  font: 500 0.78rem/1 var(--f-mono); letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted);
}
.nav a span { color: var(--rule); margin-right: 6px; }
.nav a:hover { color: var(--ink); background: var(--sunk); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--sunk); }
.nav a[aria-current="page"] span { color: var(--route); }

/* ---------- type ---------- */
h1, h2, h3, h4 { font-family: var(--f-display); text-wrap: balance; margin: 0; line-height: 1.04; }
h1 { font-size: var(--step-4); font-weight: 800; font-stretch: 112%; letter-spacing: -0.015em; }
h2 { font-size: var(--step-3); font-weight: 750; font-stretch: 108%; letter-spacing: -0.01em; }
h3 { font-size: var(--step-1); font-weight: 700; font-stretch: 104%; line-height: 1.15; }
h4 { font-size: var(--step-0); font-weight: 700; }
p { margin: 0; }
.eyebrow {
  font: 500 var(--step--1)/1.2 var(--f-mono); text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted);
}
.eyebrow b { color: var(--route); font-weight: 500; }
.lede { font-size: var(--step-1); line-height: 1.5; max-width: 52ch; color: var(--ink); }
.muted { color: var(--muted); }
.mono { font-family: var(--f-mono); font-size: 0.92em; }
.prose { max-width: var(--measure); display: grid; gap: 1em; }
.prose ul, .prose ol { margin: 0; padding-left: 1.3em; display: grid; gap: 0.35em; }
code, .code { font-family: var(--f-mono); font-size: 0.88em; background: var(--sunk); padding: 0.1em 0.35em; border-radius: 3px; }

/* ---------- page rhythm ---------- */
main { display: grid; gap: 0; }
.opener { padding-block: clamp(40px, 7vw, 88px) clamp(28px, 4vw, 48px); }
.opener .wrap { display: grid; gap: 20px; }
.section { padding-block: clamp(36px, 6vw, 72px); border-top: 1px solid var(--rule); }
.section > .wrap { display: grid; gap: 28px; }
.section-head { display: grid; gap: 12px; max-width: var(--measure); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: clamp(24px, 4vw, 56px); align-items: center; }
.split > * { min-width: 0; }
@media (max-width: 820px) { .split { grid-template-columns: minmax(0, 1fr); } }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 28px 32px; }
.cols > * { min-width: 0; }

/* ---------- figures ---------- */
.figure { margin: 0; display: grid; gap: 10px; min-width: 0; }
.figure .plate {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 6px;
  overflow-x: auto; padding: 8px;
}
.figure .plate svg { display: block; width: 100%; height: auto; min-width: 480px; }
.figure .plate.fit svg { min-width: 0; }
.figure figcaption { font: 400 var(--step--1)/1.45 var(--f-mono); color: var(--muted); max-width: 70ch; }

/* svg text + strokes take theme tokens */
.svg-ink { fill: var(--ink); }
.svg-muted { fill: var(--muted); }
.svg-label { font: 500 11px var(--f-mono); letter-spacing: 0.06em; fill: var(--muted); }
.svg-label-ink { font: 500 11px var(--f-mono); letter-spacing: 0.06em; fill: var(--ink); }
.svg-big { font: 800 15px var(--f-display); font-stretch: 112%; fill: var(--ink); }
.svg-grid { stroke: var(--rule); stroke-width: 1; fill: none; }
.svg-route { stroke: var(--route); fill: none; }
.svg-anchor { stroke: var(--anchor); fill: none; }

/* ---------- spec rows (label / body) ---------- */
.specs { display: grid; border-top: 1px solid var(--rule); }
.spec { display: grid; grid-template-columns: minmax(150px, 220px) minmax(0, 1fr); gap: 8px 28px; padding-block: 18px; border-bottom: 1px solid var(--rule); }
.spec > * { min-width: 0; }
.spec dt, .spec .k { display: grid; gap: 4px; align-content: start; }
.spec dd, .spec .v { margin: 0; display: grid; gap: 8px; align-content: start; }
@media (max-width: 640px) { .spec { grid-template-columns: minmax(0, 1fr); } }
.k-name { font: 750 var(--step-1)/1.1 var(--f-display); font-stretch: 108%; }
.k-role { font: 500 var(--step--1)/1.3 var(--f-mono); color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------- formula ---------- */
.formula {
  font: 500 clamp(1rem, 0.9rem + 0.8vw, 1.35rem)/1.4 var(--f-mono);
  border-block: 2px solid var(--ink); padding: 14px 0; max-width: var(--measure);
  display: flex; flex-wrap: wrap; gap: 0.4em 0.6em; align-items: baseline;
}
.formula .eq { color: var(--muted); }
.formula .v-route { color: var(--route); }

/* ---------- state chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
  font: 500 0.8rem/1 var(--f-mono); letter-spacing: 0.03em; padding: 5px 9px 5px 7px;
  border: 1px solid var(--rule); border-radius: 999px; background: var(--surface); color: var(--ink);
}
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--c, var(--muted)); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c, var(--muted)) 25%, transparent); }
.dot.well { box-shadow: 0 0 0 2px var(--s-well-ring); }
.c-float { --c: var(--s-float); } .c-accel { --c: var(--s-accel); } .c-capt { --c: var(--s-capt); }
.c-drift { --c: var(--s-drift); } .c-break { --c: var(--s-break); } .c-unst { --c: var(--s-unst); } .c-well { --c: var(--s-well); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 0.97rem; }
th {
  text-align: left; font: 500 0.74rem/1.2 var(--f-mono); text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--rule); background: var(--sunk);
}
td { padding: 11px 14px; border-bottom: 1px solid var(--rule); vertical-align: top; line-height: 1.45; }
tr:last-child td { border-bottom: 0; }
td.mono, td .mono { font-family: var(--f-mono); font-size: 0.86rem; }
td:first-child { font-weight: 600; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- quotes ---------- */
.pull {
  margin: 0; max-width: 42ch; font: 400 italic var(--step-2)/1.3 var(--f-body);
  text-wrap: balance; padding-left: 20px; border-left: 3px solid var(--route);
}

/* ---------- buttons, links ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 10px; text-decoration: none; cursor: pointer;
  font: 600 0.95rem/1 var(--f-display); font-stretch: 108%; letter-spacing: 0.01em;
  padding: 13px 18px; border-radius: 4px; border: 1.5px solid var(--ink); background: var(--ink); color: var(--bg);
}
.btn:hover { color: var(--bg); background: var(--route); border-color: var(--route); }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { color: var(--route); background: transparent; border-color: var(--route); }
.actions { display: flex; flex-wrap: wrap; gap: 12px; }

/* ---------- chapter list ---------- */
.chapters { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); border-top: 1px solid var(--rule); border-left: 1px solid var(--rule); }
.chapter {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 16px; align-content: start;
  padding: 22px 22px 24px; text-decoration: none; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.chapter .n { font: 500 0.8rem/1.6 var(--f-mono); color: var(--route); grid-row: span 2; }
.chapter h3 { font-size: var(--step-1); }
.chapter p { color: var(--muted); font-size: 0.97rem; }
.chapter:hover { background: var(--surface); color: var(--ink); }
.chapter:hover h3 { color: var(--route); }

/* ---------- interactive panels ---------- */
.instrument {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 6px;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-width: 0;
}
.instrument > * { min-width: 0; padding: 22px; }
.instrument > * + * { border-left: 1px solid var(--rule); }
@media (max-width: 760px) { .instrument { grid-template-columns: minmax(0, 1fr); } .instrument > * + * { border-left: 0; border-top: 1px solid var(--rule); } }
.controls { display: grid; gap: 18px; align-content: start; }
.field { display: grid; gap: 6px; }
.field label, .field .lbl { font: 500 0.74rem/1.2 var(--f-mono); text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); display: flex; justify-content: space-between; gap: 12px; }
.field output, .field .val { color: var(--ink); font-variant-numeric: tabular-nums; }
.field input[type="date"], .field input[type="number"] {
  font: 500 1rem var(--f-mono); color: var(--ink); background: var(--bg); border: 1px solid var(--rule);
  border-radius: 4px; padding: 9px 10px; width: 100%;
}
input[type="range"] { width: 100%; accent-color: var(--route); }
.check { display: flex; gap: 10px; align-items: center; font-size: 0.97rem; }
.check input { accent-color: var(--route); width: 18px; height: 18px; }
.readout { display: grid; gap: 16px; align-content: start; }
.readout .big { font: 800 clamp(2rem, 1.5rem + 2vw, 2.8rem)/1 var(--f-display); font-stretch: 112%; display: flex; align-items: center; gap: 12px; }
.readout .big .dot { width: 18px; height: 18px; }
.gauges { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; }
.gauge { display: grid; gap: 4px; border-top: 1px solid var(--rule); padding-top: 8px; }
.gauge b { font: 600 1.25rem/1.1 var(--f-mono); font-variant-numeric: tabular-nums; }
.gauge span { font: 500 0.7rem/1.2 var(--f-mono); text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.advice { border-left: 3px solid var(--c, var(--rule)); padding: 4px 0 4px 14px; }

/* ---------- code / packets ---------- */
.packet { background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; display: grid; min-width: 0; }
.packet header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--rule); }
.packet pre { margin: 0; padding: 14px; overflow-x: auto; font: 400 0.84rem/1.55 var(--f-mono); }
.copy { font: 500 0.74rem/1 var(--f-mono); text-transform: uppercase; letter-spacing: 0.06em; background: transparent; color: var(--ink); border: 1px solid var(--rule); border-radius: 4px; padding: 7px 10px; cursor: pointer; }
.copy:hover { border-color: var(--route); color: var(--route); }

/* ---------- footer ---------- */
.foot { border-top: 1px solid var(--rule); padding-block: 28px 40px; }
.foot .wrap { display: grid; gap: 28px; }
.pager { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.pager a { display: grid; gap: 4px; text-decoration: none; padding: 16px 18px; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); }
.pager a:hover { border-color: var(--route); color: var(--ink); }
.pager a.next { text-align: right; }
.pager b { font: 700 var(--step-1)/1.1 var(--f-display); font-stretch: 108%; }
.colophon { font: 400 var(--step--1)/1.5 var(--f-mono); color: var(--muted); display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Gravity Standard additions ---------- */
:root { --ok: var(--s-capt); --deny: var(--s-break); --warn: var(--s-drift); --info: var(--s-float); }
.svg-node { fill: var(--surface); stroke: var(--rule); stroke-width: 1.5; }
.svg-node-ink { fill: var(--surface); stroke: var(--ink); stroke-width: 1.5; }
.svg-sunk { fill: var(--sunk); stroke: var(--rule); stroke-width: 1; }
.svg-small { font: 400 10px var(--f-mono); fill: var(--muted); }
.svg-title { font: 700 13px var(--f-display); font-stretch: 108%; fill: var(--ink); }
.rules { counter-reset: rule; display: grid; border-top: 1px solid var(--rule); }
.rules li { list-style: none; display: grid; grid-template-columns: 3.2em minmax(0, 1fr); gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--rule); }
.rules li::before { counter-increment: rule; content: counter(rule, decimal-leading-zero); font: 500 0.9rem/1.6 var(--f-mono); color: var(--route); }
.rules { padding: 0; margin: 0; }
.trio { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 0; border: 1px solid var(--rule); border-radius: 6px; background: var(--surface); }
.trio > * { padding: 22px; display: grid; gap: 8px; align-content: start; min-width: 0; }
.trio > * + * { border-left: 1px solid var(--rule); }
@media (max-width: 760px) { .trio > * + * { border-left: 0; border-top: 1px solid var(--rule); } }
.trio .k-role { color: var(--route); }
