/* vision.nonarkara.org — design system
 *
 * Palette design core (github.com/Nonarkara/palette), applied to a classroom.
 *
 * COLOUR — Sanzo Wada, Plate 303, as converted in Palette's credited dataset
 * (digital values, not printed ink). Four hues, and no fifth hue is admitted.
 *
 *   Naples Yellow    #fbe6a0  the room: reading ground, ~62% of any view
 *   Deep Slate Olive #253122  ink, and the ground of every instrument
 *   Neutral Gray     #b6bfc1  structure: what the machine ignores or is unsure of
 *   Peach Red        #f15a30  rare signal: ONLY what the machine sees
 * Black/white instrument values are Palette's own.
 *
 * TONE LADDER. Sanzo Wada's archive is a grid of hues crossed with tones. Each
 * hue here also gets a `deep` and a `pale` step, built on one shared ladder —
 * 76% hue + 24% black, and 78% hue + 22% white — so a pale Olive and a pale
 * Naples Yellow are visibly the same move rather than two accidental colours.
 * Tone changes emphasis; it never changes meaning.
 *
 * The ladder buys one real freedom. Base Peach Red on Naples is 2.7:1 and has
 * always been banned as text on paper. signal-deep clears 13.0:1, so emphasis
 * set in signal on the paper ground is now legal — same hue, same job, one step
 * down. Every pairing above is measured, and the forbidden ones are proved
 * illegible rather than assumed: `npm run palette`.
 *
 * GEOMETRY — zero radius, no shadows, no gradients, no visible borders.
 * Grouping comes from solid fields, alignment, scale and space.
 *
 * TYPE — eight steps, not three. Display · title · subtitle · lede · body ·
 * read · micro · fine, each with one job. Type feels playful because the sizes
 * vary and the pairings are mixed, not because the sizes are arbitrary.
 *
 * Three families, and the combinations between them are named so the mixing
 * stays a system: Archivo Narrow for display Latin, IBM Plex Sans / IBM Plex
 * Sans Thai for reading, JetBrains Mono for every number, label and confidence.
 * Thai never receives Latin tracking or uppercase.
 *
 * PAIRINGS — `.stem` label-over-heading, `.measure` ghost numeral, `.mix` a
 * word stepped down to body size. All three stay inside four hues.
 *
 * MOTION — confirms a state change, ends inside 280ms, gone under
 * prefers-reduced-motion.
 */

@font-face { font-family: "Archivo Narrow"; font-weight: 600; font-display: swap; src: url("/fonts/archivo-narrow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Archivo Narrow"; font-weight: 700; font-display: swap; src: url("/fonts/archivo-narrow-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-display: swap; src: url("/fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-style: italic; font-display: swap; src: url("/fonts/ibm-plex-sans-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-display: swap; src: url("/fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans Thai"; font-weight: 400; font-display: swap; src: url("/fonts/ibm-plex-sans-thai-thai-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans Thai"; font-weight: 600; font-display: swap; src: url("/fonts/ibm-plex-sans-thai-thai-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans Thai"; font-weight: 700; font-display: swap; src: url("/fonts/ibm-plex-sans-thai-thai-700-normal.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-display: swap; src: url("/fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "JetBrains Mono"; font-weight: 600; font-display: swap; src: url("/fonts/jetbrains-mono-latin-600-normal.woff2") format("woff2"); }

:root {
  color-scheme: light;
  /* Plate 303 — the four hues. Nothing outside this block may add a hue. */
  --naples: #fbe6a0;
  --olive: #253122;
  --gray: #b6bfc1;
  --signal: #f15a30;
  /* Palette instrument values */
  --black: #101010;
  --white: #f7f5ef;

  /* Tone ladder — one shared move, applied to each of the four hues.
   * deep = 76% hue + 24% black · pale = 78% hue + 22% white.
   * Measured by scripts/palette-measure.mjs; do not hand-edit past it. */
  --naples-deep: #3c3726;
  --naples-pale: #fefaea;
  --olive-deep: #090c08;
  --olive-pale: #cfd2ce;
  --gray-deep: #2c2e2e;
  --gray-pale: #eff1f1;
  --signal-deep: #3a160c;   /* 13.0:1 on Naples — the only signal allowed as text on paper */
  --signal-pale: #fcdbd1;

  /* Instrument steps between black and the plate — hardware, never content. */
  --black-1: #161616;
  --black-2: #1f1f1f;
  --black-3: #303030;

  /* Roles */
  --ground: var(--naples);
  --text: var(--olive);
  --field: var(--olive);
  --field-text: var(--naples);
  --quiet: var(--gray);
  --quiet-text: var(--olive);

  /* Type scale — eight steps, one job each. */
  --display:  clamp(2.75rem, 6.2vw + 0.5rem, 7.5rem);
  --title:    clamp(1.9rem, 3.2vw + 0.7rem, 3.5rem);
  --subtitle: clamp(1.45rem, 1.7vw + 0.8rem, 2.125rem);
  --lede:     clamp(1.25rem, 0.7vw + 1.05rem, 1.5rem);
  --body:     clamp(1.125rem, 0.5vw + 0.95rem, 1.375rem);
  --read:     1rem;
  --micro:    0.875rem;
  --fine:     0.78125rem;

  --sans: "IBM Plex Sans", "IBM Plex Sans Thai", "Noto Sans Thai", system-ui, sans-serif;
  --thai: "IBM Plex Sans Thai", "IBM Plex Sans", "Noto Sans Thai", system-ui, sans-serif;
  --narrow: "Archivo Narrow", "IBM Plex Sans Thai", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;

  --gutter: clamp(16px, 3.2vw, 52px);
  --gap: clamp(16px, 1.8vw, 28px);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --target: 44px;
  --rail-height: 56px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground: var(--olive);
    --text: var(--naples);
    --field: var(--black);
    --field-text: var(--naples);
    --btn: var(--black-2);
    --btn-text: var(--white);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ground: var(--olive);
  --text: var(--naples);
  --field: var(--black);
  --field-text: var(--naples);
  --btn: var(--black-2);
  --btn-text: var(--white);
}

*, *::before, *::after { box-sizing: border-box; border-radius: 0 !important; }

html { scroll-padding-top: calc(var(--rail-height) + 16px); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--ground);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--body);
  line-height: 1.6;
  font-kerning: normal;
}
[lang="th"] { font-family: var(--thai); line-height: 1.75; }

/* Language: both languages are in the markup; one is shown. */
html[data-lang="th"] .en,
html[data-lang="en"] .th { display: none !important; }

img, canvas, video, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-underline-offset: 0.22em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }
p { margin: 0 0 1.1em; }
p, li, dd, h1, h2, h3, a, figcaption { overflow-wrap: break-word; }
:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; }

.skip {
  position: absolute; top: 0; left: 0; z-index: 50;
  padding: 12px 16px; background: var(--black); color: var(--white);
  transform: translateY(-120%);
}
.skip:focus { transform: none; }

[hidden] { display: none !important; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Type roles ──────────────────────────────────────────────────────── */

/* h1 is the page. h2 is a section of it. They were the same size for a year,
   which is why the pages read as one long shout. */
h1, .display {
  font-family: var(--narrow);
  font-size: var(--display);
  font-weight: 700;
  line-height: 0.94;
  letter-spacing: -0.02em;
  margin: 0;
}
h2 {
  font-family: var(--narrow);
  font-size: var(--title);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.015em;
  margin: 0;
}
h1 [lang="th"], h2 [lang="th"], .display [lang="th"],
h1[lang="th"], h2[lang="th"] {
  font-family: var(--thai);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.12;
  font-size: 0.82em;
}
h3 { font-size: var(--subtitle); font-weight: 600; line-height: 1.2; margin: 1.6em 0 0.5em; letter-spacing: -0.01em; }
h4 { font-size: var(--body); font-weight: 600; line-height: 1.3; margin: 1.4em 0 0.4em; }
.micro, .label, .fine {
  font-family: var(--mono);
  line-height: 1.4;
  letter-spacing: 0.04em;
}
.micro { font-size: var(--micro); }
.fine { font-size: var(--fine); letter-spacing: 0.08em; }
.label { text-transform: uppercase; }
.label [lang="th"], .label[lang="th"] { text-transform: none; letter-spacing: 0; font-family: var(--thai); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.lede { font-size: var(--lede); font-weight: 600; max-width: 34ch; }
.prose { max-width: 62ch; }
.prose ul, .prose ol { padding-left: 1.2em; }
.prose li { margin-bottom: 0.5em; }
strong { font-weight: 600; }
em { font-style: italic; }

/* ── Pairings ────────────────────────────────────────────────────────── */
/* Three named combinations of the three families. The mixing is the fun part;
 * naming it is what stops the fun part from becoming noise. */

/* STEM — a mono label sitting on a rule, directly over a display heading.
   The label is machine language, the heading is human language, and the rule
   is what keeps them on one grid. */
.stem { display: grid; gap: 10px; align-content: start; }
.stem .stem-label {
  display: flex; align-items: baseline; gap: 10px;
  font-family: var(--mono); font-size: var(--fine); letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--gray);
}
.stem .stem-label::after { content: ""; flex: 1 1 auto; height: 1px; background: currentColor; opacity: 0.55; }
.stem .stem-label [lang="th"], .stem-label[lang="th"] { text-transform: none; letter-spacing: 0; font-family: var(--thai); }

/* MEASURE — a ghost numeral in the "structure" grey, sitting behind a heading.
   Gray is what the machine is unsure of, so it carries the count a reader is
   not meant to read first. Never on a dark ground, where it would vanish. */
.measure { position: relative; isolation: isolate; }
.measure .measure-n {
  position: absolute; z-index: -1; top: -0.34em; left: -0.06em;
  font-family: var(--narrow); font-weight: 700; font-size: 4.2em; line-height: 0.8;
  color: var(--gray); opacity: 0.42; pointer-events: none; user-select: none;
  font-variant-numeric: lining-nums;
}
.field-ink .measure .measure-n, .field-black .measure .measure-n,
.field-signal .measure .measure-n { color: var(--naples); opacity: 0.16; }
@media (max-width: 760px) { .measure .measure-n { font-size: 3em; opacity: 0.3; } }

/* MIX — one word stepped down to body size and set in signal-deep, so a single
   phrase carries two sizes and two tones inside one heading. Reserved for text
   that is genuinely about what a machine sees, which is the only job signal has.
   Never inside a .field-* — signal-deep is paper-ground ink. */
.mix { color: var(--signal-deep); font-family: var(--sans); font-size: 0.42em; font-weight: 600; letter-spacing: 0; white-space: nowrap; }
.mix [lang="th"], .mix[lang="th"] { font-family: var(--thai); }

/* ── Instrument rail (header) ────────────────────────────────────────── */

.rail {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: stretch; gap: 0;
  background: var(--black); color: var(--white);
  min-height: 56px;
}
.rail a { text-decoration: none; }
.mark {
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px 0 var(--gutter);
  min-height: 56px; flex: 0 0 auto;
  font-family: var(--narrow); font-weight: 700; font-size: 1.375rem; letter-spacing: 0.02em;
}
.mark svg { width: 28px; height: 28px; flex: none; }
.rooms {
  display: flex; align-items: stretch; flex: 1 1 auto; min-width: 0;
  overflow-x: auto; scrollbar-width: none;
}
.rooms::-webkit-scrollbar { display: none; }
.rooms a {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; min-height: 56px; white-space: nowrap;
  font-size: var(--micro); color: var(--gray);
  transition: color 160ms var(--ease), background-color 160ms var(--ease);
}
.rooms a .num { color: var(--gray); opacity: 0.7; }
.rooms a:hover { color: var(--white); }
.rooms a[aria-current="page"] { background: var(--signal); color: var(--black); }
.rooms a[aria-current="page"] .num { color: var(--black); opacity: 1; }
.rail-tools { display: flex; align-items: stretch; flex: 0 0 auto; }
.lang-toggle {
  display: flex; align-items: center; gap: 6px;
  min-width: var(--target); min-height: 56px; padding: 0 var(--gutter) 0 16px;
  background: transparent; border: 0; cursor: pointer;
  font-family: var(--mono); font-size: var(--micro); color: var(--white);
}
.lang-toggle span[aria-hidden] { color: var(--gray); }
.lang-toggle b { font-weight: 600; color: var(--signal); }

@media (max-width: 820px) {
  .rail { flex-wrap: wrap; }
  .mark { flex: 1 1 auto; }
  .rooms { order: 3; flex: 1 0 100%; background: var(--olive); }
  .rooms a { min-height: var(--target); }
}

/* ── Fields ──────────────────────────────────────────────────────────── */

.field-ink { background: var(--field); color: var(--field-text); }
.field-quiet { background: var(--quiet); color: var(--quiet-text); }
.field-signal { background: var(--signal); color: var(--black); }
.field-black { background: var(--black); color: var(--white); }

/* Opening: golden split, content-first. */
.opening {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  min-height: calc(100svh - var(--rail-height));
}
.opening-text {
  display: flex; flex-direction: column; justify-content: space-between; gap: var(--gap);
  padding: clamp(28px, 3.5vw, 56px) var(--gutter);
}
.opening-text .lede { margin: 0; }
.opening-stage { display: flex; flex-direction: column; min-width: 0; }
@media (max-width: 900px) {
  .opening { grid-template-columns: 1fr; min-height: 0; }
}

.page-head {
  display: grid; gap: var(--gap);
  grid-template-columns: minmax(0, 1.618fr) minmax(0, 1fr);
  padding: clamp(24px, 3vw, 48px) var(--gutter) clamp(20px, 2.5vw, 36px);
  align-items: end;
}
.page-head .lede { margin: 0; }
@media (max-width: 900px) { .page-head { grid-template-columns: 1fr; } }

.eyebrow { display: block; margin-bottom: 12px; }

/* ── Chapters ────────────────────────────────────────────────────────── */

.chapter {
  display: grid;
  grid-template-columns: minmax(140px, 0.6fr) minmax(0, 2fr);
  gap: var(--gap);
  padding: clamp(28px, 3.5vw, 56px) var(--gutter);
}
.chapter > header { display: flex; flex-direction: column; gap: 12px; }
.chapter-no { font-family: var(--mono); font-size: var(--micro); }
.chapter h2 { margin-bottom: 0.4em; }
.chapter-body { min-width: 0; display: grid; gap: var(--gap); }
.chapter-body.split { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); align-items: start; }
@media (max-width: 1100px) { .chapter-body.split { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .chapter { grid-template-columns: 1fr; } }

/* Contents list — numbered rows, no cards. */
.index { list-style: none; margin: 0; padding: 0; }
.index li { margin: 0; }
.index a {
  display: grid; grid-template-columns: 4.5rem minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 16px 24px; align-items: baseline;
  padding: 20px var(--gutter);
  text-decoration: none;
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}
.index a:hover, .index a:focus-visible { background: var(--field); color: var(--field-text); outline-offset: -3px; }
.index .num { font-size: var(--micro); }
.index .title { font-family: var(--narrow); font-weight: 700; font-size: clamp(1.5rem, 2.2vw + 0.6rem, 2.5rem); line-height: 1; }
.index .title [lang="th"], .index .title[lang="th"] { font-family: var(--thai); font-size: 0.85em; line-height: 1.25; }
.index .desc { max-width: 46ch; }
@media (max-width: 760px) {
  .index a { grid-template-columns: 3rem minmax(0, 1fr); }
  .index .desc { grid-column: 2; }
}

/* Numbers strip */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0; }
.figure { padding: 24px var(--gutter) 28px; }
.figure .n { display: block; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: clamp(2rem, 3vw + 1rem, 3.5rem); font-weight: 600; line-height: 1; margin-bottom: 8px; }

/* ── Instruments (live canvases + controls) ─────────────────────────── */

.bench { background: var(--black); color: var(--white); display: flex; flex-direction: column; min-width: 0; }
.bench-view { position: relative; background: var(--black); aspect-ratio: 16 / 9; overflow: hidden; }
.bench-view canvas, .bench-view video, .bench-view img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.bench-view video.feed, .bench-view img.feed { visibility: hidden; }
.bench-state {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center; font-family: var(--mono); font-size: var(--micro); color: var(--gray);
}
.bench-state[hidden] { display: none; }
.bench-caption { padding: 12px 16px; font-size: var(--micro); color: var(--gray); min-height: var(--target); display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; justify-content: space-between; }
.bench-caption a { color: var(--white); }
.bench-caption .who { color: var(--white); }
.controls { display: flex; flex-wrap: wrap; gap: 2px; background: var(--black); }
.controls.pad { padding: 0 0 2px; }
.readout { padding: 12px 16px; font-family: var(--mono); font-size: var(--micro); color: var(--white); font-variant-numeric: tabular-nums; min-height: var(--target); white-space: pre-wrap; }

/* Buttons: solid fields, mono, 44px. No borders. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--target); min-width: var(--target); padding: 0 16px;
  border: 0; cursor: pointer; text-decoration: none;
  font-family: var(--mono); font-size: var(--micro); letter-spacing: 0.03em;
  background: var(--btn, var(--olive)); color: var(--btn-text, var(--naples));
  transition: background-color 160ms var(--ease), color 160ms var(--ease);
}
.btn [lang="th"], .btn[lang="th"] { font-family: var(--thai); letter-spacing: 0; }
.btn:hover { background: var(--black); color: var(--white); }
.btn[aria-pressed="true"], .btn.is-on { background: var(--signal); color: var(--black); }
.btn:disabled { cursor: not-allowed; opacity: 0.5; }
.bench .btn, .field-ink .btn, .field-black .btn { background: var(--black-2); color: var(--white); }
.bench .btn:hover, .field-ink .btn:hover, .field-black .btn:hover { background: var(--gray); color: var(--black); }
.bench .btn[aria-pressed="true"], .field-ink .btn[aria-pressed="true"], .field-black .btn[aria-pressed="true"],
.bench .btn.is-on, .field-ink .btn.is-on { background: var(--signal); color: var(--black); }
.btn.primary { background: var(--signal); color: var(--black); font-weight: 600; }
.btn.primary:hover { background: var(--black); color: var(--white); }
.btn.big { min-height: 56px; padding: 0 24px; font-size: var(--body); }

/* Sliders: a square thumb on a 4px track. */
.slider { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: center; padding: 8px 16px 12px; background: var(--black); color: var(--white); }
.slider label { font-size: var(--micro); }
.slider output { font-family: var(--mono); font-size: var(--micro); font-variant-numeric: tabular-nums; color: var(--signal); }
.slider input { grid-column: 1 / -1; }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: var(--target); background: transparent; cursor: pointer; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: var(--gray); }
input[type="range"]::-moz-range-track { height: 4px; background: var(--gray); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; margin-top: -10px; background: var(--signal); border: 0; }
input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; background: var(--signal); border: 0; }

.field-input {
  min-height: var(--target); padding: 0 12px; border: 0; width: 100%;
  background: var(--white); color: var(--black);
}
select.field-input { cursor: pointer; }

/* ── Figures, diagrams, tables ──────────────────────────────────────── */

/* `--read` is the dense step: captions, tables and notices sit one notch below
   body text rather than competing with it. */
figure { margin: 0; }
figcaption { font-size: var(--read); padding-top: 12px; max-width: 70ch; }
.diagram { width: 100%; height: auto; }
.diagram text { font-family: var(--mono); font-size: 13px; fill: currentColor; }
.diagram .thai { font-family: var(--thai); }
.diagram .big { font-family: var(--narrow); font-size: 22px; font-weight: 700; }
.diagram .fill-ink { fill: var(--olive); }
.diagram .fill-naples { fill: var(--naples); }
.diagram .fill-gray { fill: var(--gray); }
.diagram .fill-signal { fill: var(--signal); }
.diagram .fill-black { fill: var(--black); }
.diagram .on-dark { fill: var(--naples); }
.diagram .on-signal { fill: var(--black); }
.diagram .stroke { stroke: currentColor; fill: none; stroke-width: 2; }
.diagram .stroke-signal { stroke: var(--signal); fill: none; stroke-width: 3; }
.diagram .stroke-gray { stroke: var(--gray); fill: none; stroke-width: 2; }
.diagram a { cursor: pointer; transition: opacity 160ms var(--ease); }
.diagram a:hover { opacity: 0.65; }
.diagram .mark { fill: var(--ground); stroke: currentColor; stroke-width: 2; }
.diagram .mark-signal { fill: var(--signal); stroke: var(--signal); stroke-width: 3; }

/* Wide diagrams: they scroll inside themselves on narrow screens instead of
   shrinking into illegibility. */
.pipe-scroll { overflow-x: auto; scrollbar-width: thin; }
.pipe-scroll svg { min-width: 780px; }
.flow-fig { margin: 0; }
.pipe-figure { padding: 0 var(--gutter) clamp(32px, 4vw, 56px); }

.table { width: 100%; border-collapse: collapse; font-size: var(--read); }
.table th, .table td { text-align: left; padding: 10px 12px; vertical-align: top; }
.table th { font-family: var(--mono); font-weight: 600; background: var(--field); color: var(--field-text); }
.table tbody tr:nth-child(odd) { background: color-mix(in srgb, var(--gray) 35%, transparent); }
.table td.num, .table th.num { text-align: right; }
.table-wrap { overflow-x: auto; }

/* Steps (everyday-life pipelines) */
.steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; margin: 16px 0 0; padding: 0; list-style: none; counter-reset: step; }
.steps li { background: var(--quiet); color: var(--quiet-text); padding: 12px 14px 16px; font-size: var(--micro); counter-increment: step; margin: 0; }
.steps li::before { content: counter(step, decimal-leading-zero); display: block; font-family: var(--mono); margin-bottom: 6px; }
.steps li:last-child { background: var(--signal); color: var(--black); }
@media (max-width: 700px) { .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Notices */
.note { padding: 16px 20px; background: var(--quiet); color: var(--quiet-text); font-size: var(--read); max-width: 70ch; }
.note strong { font-weight: 600; }
.warn-line { font-family: var(--mono); font-size: var(--micro); }

/* Bars (confidence, class scores) */
.bars { display: grid; gap: 2px; }
.bar { display: grid; grid-template-columns: minmax(6rem, 0.6fr) minmax(0, 1fr) 4.5rem; gap: 12px; align-items: center; min-height: 36px; padding: 0 12px; background: var(--black-2); color: var(--white); font-size: var(--micro); }
.bar-track { height: 12px; background: var(--black-3); }
.bar-fill { height: 100%; background: var(--gray); width: 0; transition: width 200ms var(--ease); }
.bar.top .bar-fill { background: var(--signal); }
.bar .num { text-align: right; }

/* Thumbnail grids (train, census, wall) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 2px; }
.tile { position: relative; background: var(--black); color: var(--white); min-width: 0; }
.tile-view { position: relative; aspect-ratio: 16 / 9; background: var(--black-1); overflow: hidden; }
.tile-view canvas, .tile-view img, .tile-view video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile-meta { padding: 8px 10px 10px; font-size: var(--micro); line-height: 1.35; min-height: 52px; }
.tile-meta .who { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-tag { position: absolute; top: 0; left: 0; padding: 4px 8px; font-family: var(--mono); font-size: 0.75rem; background: var(--black); color: var(--white); }
.tile-tag.hit { background: var(--signal); color: var(--black); }
.tile-actions { display: flex; gap: 2px; }
.tile-actions .btn { flex: 1 1 0; min-width: 0; padding: 0 8px; }
.tile.is-picked { outline: 4px solid var(--signal); outline-offset: -4px; }

/* Footer */
.foot { background: var(--black); color: var(--white); padding: clamp(40px, 6vw, 80px) var(--gutter) 40px; display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1.618fr) minmax(0, 1fr); font-size: var(--micro); }
.foot p { max-width: 70ch; }
.foot a { color: var(--white); }
.foot nav { display: flex; flex-direction: column; gap: 4px; }
.foot nav a { min-height: 32px; display: flex; align-items: center; }
/* The footer shows the whole system: four hues, each on its three-step tone
   ladder. The swatches are the argument — every colour on this site is one of
   these twelve, or an instrument black/white. */
.chord { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; width: 100%; max-width: 420px; margin-bottom: 10px; }
.chord-row { display: flex; gap: 2px; }
.chord i { display: block; height: 22px; flex: 1 1 0; }
.c-naples-d { background: var(--naples-deep); } .c-naples { background: var(--naples); } .c-naples-p { background: var(--naples-pale); }
.c-olive-d { background: var(--olive-deep); } .c-olive { background: var(--olive); } .c-olive-p { background: var(--olive-pale); }
.c-gray-d { background: var(--gray-deep); } .c-gray { background: var(--gray); } .c-gray-p { background: var(--gray-pale); }
.c-signal-d { background: var(--signal-deep); } .c-signal { background: var(--signal); } .c-signal-p { background: var(--signal-pale); }
.chord-note { color: var(--gray); margin: 0 0 16px; max-width: 42ch; }
@media (max-width: 760px) { .foot { grid-template-columns: 1fr; } }

/* Toast: the only element permitted a shadow — transient feedback. */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60; transform: translateX(-50%);
  max-width: min(92vw, 560px); padding: 14px 18px;
  background: var(--black); color: var(--white); font-size: var(--micro);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  animation: toast-in 180ms var(--ease) both;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Confirm box: the page's own yes/no, because the browser's confirm() speaks
   whichever language the browser happens to be set to. */
.confirm-scrim {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center;
  padding: 24px; background: color-mix(in srgb, var(--black) 72%, transparent);
}
.confirm-box {
  display: grid; gap: 18px; width: min(92vw, 460px); padding: 24px;
  background: var(--black); color: var(--white);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
.confirm-box p { margin: 0; font-size: var(--body); }
.confirm-box .controls { background: transparent; }
.confirm-box .controls .btn { flex: 1 1 auto; }

.reveal { animation: reveal 240ms var(--ease) both; }
@keyframes reveal { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

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

@media print {
  .rail, .controls, .bench, .lang-toggle, .skip, .foot nav { display: none !important; }
  body, .field-ink, .field-quiet, .field-black { background: white !important; color: black !important; }
}

/* ── Home ────────────────────────────────────────────────────────────── */

.cta { display: flex; flex-wrap: wrap; gap: 2px; margin-top: var(--gap); }
.opening-stage .stage-view { flex: 1 1 auto; aspect-ratio: auto; min-height: 280px; }
.lens-steps .btn { flex: 1 1 0; min-width: 0; padding: 0 8px; }
.lens-steps .btn .num { opacity: 0.6; }
.lens-say { color: var(--naples); font-family: var(--sans); font-size: var(--micro); line-height: 1.55; min-height: 6.5em; }
html[data-lang="th"] .lens-say { font-family: var(--thai); }
.specimen-line { border-top: 0; align-items: flex-end; }
.specimen-line .btn { flex: none; }
@media (max-width: 900px) { .opening-stage .stage-view { aspect-ratio: 16 / 10; min-height: 0; } }

.promise-list { list-style: none; margin: 0; padding: 0 var(--gutter) clamp(48px, 7vw, 112px); display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--gap); }
.promise-list li { display: flex; flex-direction: column; gap: 8px; max-width: 36ch; }
.promise-list .num { font-size: var(--micro); color: var(--text); }
.promise-list strong { font-size: var(--body); }

/* Specimen bar (shared source controls) */
.specimen-bar { position: sticky; top: var(--rail-height); z-index: 10; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 24px; padding: 8px var(--gutter); }
.specimen-who { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; min-width: 0; }
.specimen-who strong { font-weight: 600; }
.specimen-who .micro { color: var(--gray); }
.specimen-who a { color: var(--white); }
@media (max-width: 820px) { :root { --rail-height: 100px; }
  .specimen-bar { position: static; }
}
.specimen-line .controls { background: transparent; }
.mine-note { margin: 12px 0 0; max-width: 46ch; }
.opening-stage:fullscreen { width: 100vw; height: 100vh; }
.opening-stage:fullscreen .stage-view { flex: 1 1 auto; }
@media (max-width: 560px) {
  .lens-steps .btn { padding: 0 4px; letter-spacing: 0; }
  .lens-steps .btn .num { display: none; }

}

/* On a phone the bar must not eat a quarter of the screen: camera name on one
   line, its owner and kind on at most two. The full credit shows on wider screens. */
@media (max-width: 600px) {
  .specimen-bar { gap: 6px; }
  .specimen-who { flex-direction: column; align-items: stretch; gap: 0; width: 100%; }
  .specimen-who .label { display: none; }
  .specimen-who strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .specimen-who .micro { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
}
.story-teaser h2 { font-size: clamp(2rem, 3vw + 1rem, 4rem); }
.story-teaser .lede { max-width: 46ch; }
.story-teaser .cta { margin-top: 24px; }
.teaser-shot { margin-top: var(--gap); max-width: 720px; }
.teaser-shot img { width: 100%; height: auto; filter: grayscale(1) contrast(1.05); }

/* The picture gets the larger half of the opening; copy stays at reading scale. */
.opening h1 { font-size: clamp(3.5rem, 6vw, 6rem); }
.opening-text .lede { font-weight: 400; font-size: clamp(1.125rem, 1.4vw, 1.25rem); max-width: 36ch; }
.opening-text .cta { margin-top: 24px; }
.opening-text .btn.big { font-size: 1.125rem; padding: 0 18px; }
.opening-stage .lens-say { min-height: 0; margin: 0; padding-block: 12px; }
.opening-stage .stage-view { min-height: 240px; }
@media (max-width: 900px) {
  .opening-stage .stage-view { min-height: 0; aspect-ratio: 16 / 10; }
  .opening-text { gap: 28px; }
}

/* Enlarge the working instrument, keeping every control reachable. */
.instrument-tools { display: flex; justify-content: flex-end; flex: none; background: var(--black); }
.instrument :focus-visible { outline-offset: -3px; }
label.btn:focus-within { outline: 3px solid currentColor; outline-offset: -3px; }
.instrument-open { overflow: hidden; }
.instrument:is(:fullscreen, .is-expanded) {
  width: 100%; height: 100dvh; max-height: none; margin: 0;
  background: var(--black); color: var(--white); overflow: auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.instrument.is-expanded { position: fixed; inset: 0; z-index: 100; }
.bench:is(:fullscreen, .is-expanded) > :not(.bench-view, .map-view) { flex-shrink: 0; }
.bench:is(:fullscreen, .is-expanded) > :is(.bench-view, .map-view) {
  flex: 1 0 200px; height: auto; min-height: 200px; max-height: none; aspect-ratio: auto;
}
.room-grid:is(:fullscreen, .is-expanded) { gap: 24px; padding: 16px; align-items: start; }
.room-grid:is(:fullscreen, .is-expanded) .room-classes { padding: 0 0 24px; }
@media (min-width: 1001px) {
  .room-grid:is(:fullscreen, .is-expanded) { grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.8fr); }
}
@media (max-height: 520px) and (orientation: landscape) {
  .bench:is(:fullscreen, .is-expanded) > :is(.bench-view, .map-view) { flex-basis: 55dvh; }
}

.instrument-credit { display: none; }
.instrument:is(:fullscreen, .is-expanded) .instrument-credit { display: flex; }

/* Long agency names cannot widen a phone's specimen bar. */
.specimen-who > * { min-width: 0; max-width: 100%; }
@media (max-width: 600px) { .specimen-who { flex-wrap: nowrap; } }

.instrument:is(:fullscreen, .is-expanded) .instrument-tools { position: sticky; top: 0; z-index: 2; min-height: 44px; }
.room-grid:is(:fullscreen, .is-expanded) [data-fullscreen] { position: fixed; top: max(16px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); z-index: 3; }
