/* ==========================================================================
   AI explained: stylesheet
   A guided path: a hero, chapters beside a growing map, the whole kitchen at the end;
   every term and every guide is a page of its own.
   Look: warm paper, slate ink, a clay accent and hand-drawn shapes (rough.js).
   Every colour is a token; dark mode redefines the tokens only.
   ========================================================================== */

/* ---------- Fonts (self-hosted, SIL Open Font License) ------------------- */
@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("../fonts/source-serif-4-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
  src: url("../fonts/source-serif-4-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Source Serif 4";
  font-style: italic;
  font-weight: 200 900;
  font-display: swap;
  src: url("../fonts/source-serif-4-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 100 1000;
  font-display: swap;
  src: url("../fonts/dm-sans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "DM Sans";
  font-style: normal;
  font-weight: 100 1000;
  font-display: swap;
  src: url("../fonts/dm-sans-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "DM Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/dm-mono-400-latin.woff2") format("woff2");
}
@font-face {
  font-family: "DM Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/dm-mono-500-latin.woff2") format("woff2");
}

/* ---------- Tokens -------------------------------------------------------- */
/* Light values sit on :root, dark values on [data-theme="dark"]. The script in
   the <head> of index.html always sets data-theme (the saved choice, else the
   system setting), so every value is written once per theme. DESIGN.md lists
   what each token is for. */
:root {
  color-scheme: light;

  /* Surfaces and ink */
  --paper: #faf9f5;
  --paper-2: #f0eee6;
  --paper-3: #e8e5da;
  --surface: #ffffff;
  --ink: #141413;
  --ink-2: #3d3d3a;
  --ink-3: #6b6a65;
  --ink-hover: #2f2e2b;
  --rule: #e3e1d8;
  --rule-strong: #cfccc0;
  --focus: #2c6fbb;
  --shadow: 0 2px 6px rgba(20, 20, 19, 0.06), 0 18px 48px rgba(20, 20, 19, 0.14);

  /* Accent. --clay is for fills and graphics; accent text always uses --clay-ink. */
  --clay: #d97757;
  --clay-ink: #9e4a2d;
  --clay-soft: #f6e0d4;
  --clay-mid: #e9a385;

  /* Sketch layer (rough.js) */
  --sk-ink: #141413;
  --sk-paper: #fffdf8;

  /* Status: own values, so recolouring a zone never recolours a status. */
  --ok: #4d6b2f;   --ok-soft: #e5e9d3;
  --bad: #983e5c;  --bad-soft: #f4dee5;
  --part: #855628; --part-soft: #f2e6cd;
  --warn: var(--clay-ink); --warn-soft: var(--clay-soft);

  /* Zones: label ink (--z), tint (--t), mid (--m). Source-type badges borrow these hues too. */
  --z-start: #5f5d57;   --t-start: #ebe7dc;   --m-start: #cdc5b2;
  --z-model: #5b5486;   --t-model: #e4e1f0;   --m-model: #b9b3d8;
  --z-harness: #9e4a2d; --t-harness: #f7e3d8; --m-harness: #e9a385;
  --z-control: #983e5c; --t-control: #f4dee5; --m-control: #dfa6b9;
  --z-know: #56652c;    --t-know: #e5e9d3;    --m-know: #b8c38a;
  --z-tools: #855628;   --t-tools: #f2e6cd;   --m-tools: #dbb586;
  --z-orch: #2f6190;    --t-orch: #dce8f3;    --m-orch: #9cc0df;
  --z-ops: #386857;     --t-ops: #dceae3;     --m-ops: #a3c8b8;
  /* How much of the zone mid a text highlight uses; the rest is paper. */
  --hl-mix: 100%;

  /* Type */
  --serif: "Source Serif 4", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "DM Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --fs-2xs: 11px;    /* mono badges, kbd */
  --fs-xs: 12px;     /* eyebrows, captions */
  --fs-sm: 13.5px;   /* meta, chips, notes */
  --fs-md: 15px;     /* UI text, lists, tables */
  --fs-base: 16px;   /* body and reading text */
  --fs-lg: 17.5px;   /* ledes, small headings */
  --fs-xl: 19.5px;   /* zone and card titles */
  --fs-2xl: 22px;    /* section headings */
  --fs-3xl: 26px;    /* large headings, numerals */
  --fs-4xl: 30px;    /* page titles */
  --fs-5xl: 38px;    /* display numerals, guide title */
  --track-caps: 0.09em;
  --track-mono: 0.05em;

  /* Shape */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-pill: 999px;
  --dot: 9px;
  --dot-ring: 1.6px;

  /* Motion */
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  --dur-fast: 0.15s;    /* hover and colour changes */
  --dur-base: 0.25s;    /* small moves and fades */
  --dur-slow: 0.35s;    /* panels sliding in */
  --dur-reveal: 0.6s;   /* first-paint fades */
  --dur-draw: 0.9s;     /* sketch strokes, connector flow */
  --dur-boil: 0.42s;    /* one line-boil cycle */

  /* Layers */
  --z-bar: 30;
  --z-rail: 35;
  --z-menu: 45;
  --z-skip: 100;

  /* Layout */
  --bar-h: 58px;
  --gutter: clamp(16px, 2.4vw, 36px);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1f1e1d;
  --paper-2: #262624;
  --paper-3: #30302d;
  --surface: #2a2927;
  --ink: #f2f0e8;
  --ink-2: #d4d1c7;
  --ink-3: #a7a49a;
  --ink-hover: #ffffff;
  --rule: #383733;
  --rule-strong: #4c4a45;
  --focus: #7fb0ea;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.3), 0 18px 48px rgba(0, 0, 0, 0.45);
  --clay: #e0896a;
  --clay-ink: #ef9f7d;
  --clay-soft: #45302a;
  --clay-mid: #a9654a;
  --sk-ink: #e9e6dc;
  --sk-paper: #34332f;
  --ok: #b4c98a;   --ok-soft: #323624;
  --bad: #f0abc1;  --bad-soft: #432b34;
  --part: #ecc69c; --part-soft: #403527;
  --z-start: #d3cfc4;   --t-start: #33312d;   --m-start: #6f6a5e;
  --z-model: #c8c2ee;   --t-model: #312e44;   --m-model: #6f6898;
  --z-harness: #f2a787; --t-harness: #432e27; --m-harness: #a9654a;
  --z-control: #f0abc1; --t-control: #432b34; --m-control: #a65c76;
  --z-know: #cdd7a0;    --t-know: #323624;    --m-know: #7b884e;
  --z-tools: #ecc69c;   --t-tools: #403527;   --m-tools: #a17a50;
  --z-orch: #a9cbec;    --t-orch: #273645;    --m-orch: #5a84ab;
  --z-ops: #a9d6c4;     --t-ops: #283a33;     --m-ops: #5d8d7b;
  /* Light ink on a full mid falls to 3.3:1; three quarters mid keeps it above 4.5:1. */
  --hl-mix: 75%;
}

/* Zone helpers: any element with data-zone gets its colours. --zh is the text highlight. */
[data-zone="start"]   { --zc: var(--z-start);   --zt: var(--t-start);   --zm: var(--m-start); }
[data-zone="model"]   { --zc: var(--z-model);   --zt: var(--t-model);   --zm: var(--m-model); }
[data-zone="harness"] { --zc: var(--z-harness); --zt: var(--t-harness); --zm: var(--m-harness); }
[data-zone="control"] { --zc: var(--z-control); --zt: var(--t-control); --zm: var(--m-control); }
[data-zone="know"]    { --zc: var(--z-know);    --zt: var(--t-know);    --zm: var(--m-know); }
[data-zone="tools"]   { --zc: var(--z-tools);   --zt: var(--t-tools);   --zm: var(--m-tools); }
[data-zone="orch"]    { --zc: var(--z-orch);    --zt: var(--t-orch);    --zm: var(--m-orch); }
[data-zone="ops"]     { --zc: var(--z-ops);     --zt: var(--t-ops);     --zm: var(--m-ops); }
[data-zone]           { --zh: color-mix(in srgb, var(--zm) var(--hl-mix), var(--paper)); }

/* ---------- Base ----------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + 16px); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--fs-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; text-wrap: balance; letter-spacing: -0.005em; }
p { margin: 0; }
a { color: var(--clay-ink); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
button { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: 0.88em; background: var(--paper-2); border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 0.05em 0.35em; overflow-wrap: anywhere; }
strong, b { font-weight: 650; }
svg { display: block; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: var(--z-skip);
  background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: var(--r-md); text-decoration: none;
}
.skip-link:focus { top: calc(env(safe-area-inset-top, 0px) + 10px); }

/* ---------- Shared pieces --------------------------------------------------- */
/* Buttons. Variants are suffixes (-ink, -ghost, -sm, -outline). Every button
   has hover, active, focus-visible and disabled states. */
.btn {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 42px; padding: 10px 18px;
  border: 1px solid var(--rule-strong); border-radius: var(--r-pill);
  background: var(--surface); color: var(--ink);
  font: 500 var(--fs-md)/1.2 var(--sans); letter-spacing: 0.005em;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), transform var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--paper-2); border-color: var(--ink-3); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-ink { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn-ink:hover { background: var(--ink-hover); border-color: var(--ink-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover, .btn-ghost[aria-expanded="true"] { background: var(--paper-2); border-color: transparent; color: var(--ink); }
.btn-sm { min-height: 34px; padding: 6px 14px; font-size: var(--fs-sm); }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none; padding: 0;
  border: 1px solid transparent; border-radius: var(--r-pill); background: transparent; color: var(--ink-2); cursor: pointer;
  transition: background-color var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast), transform var(--dur-fast) var(--ease);
}
.icon-btn:hover { background: var(--paper-2); color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn-outline { border-color: var(--rule-strong); background: var(--surface); color: var(--ink); }
.icon-btn-outline svg, .icon-btn-ink svg { width: 18px; height: 18px; }
.icon-btn-ink { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.icon-btn-ink:hover { border-color: var(--ink-hover); background: var(--ink-hover); color: var(--paper); }
.btn:active, .icon-btn:active { transform: translateY(1px); }
/* No pointer events, so a disabled button never shows a hover state. */
.btn:disabled, .icon-btn:disabled { opacity: 0.35; pointer-events: none; }
.link-btn {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--clay-ink); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
  font: inherit; text-align: left;
}
.link-btn:hover { text-decoration-thickness: 2px; }

/* Eyebrow: the small uppercase label above or inside a block. */
.eyebrow, thead th, .proto .grp th {
  font: 600 var(--fs-xs)/1.2 var(--sans); letter-spacing: var(--track-caps); text-transform: uppercase; color: var(--ink-3);
}

/* Badge: a small mono label. -clay marks steps and counts. */
.badge {
  display: inline-block; padding: 4px 8px; border-radius: var(--r-sm);
  font: 500 var(--fs-2xs)/1 var(--mono); letter-spacing: var(--track-mono);
  background: var(--paper-2); color: var(--ink-2);
}
.badge-clay { background: var(--clay-soft); color: var(--clay-ink); }

/* Card: a bordered panel on the surface colour. Padding belongs to each use. */
.card { border: 1px solid var(--rule); border-radius: var(--r-lg); background: var(--surface); }

/* Zone dot: marks which zone a block belongs to. Needs a data-zone ancestor. */
.zdot {
  flex: none; width: var(--dot); height: var(--dot); border-radius: 50%;
  background: var(--zm); box-shadow: inset 0 0 0 var(--dot-ring) var(--zc);
}

/* ---------- Top bar ------------------------------------------------------- */
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: var(--z-bar);
  height: var(--bar-h);
  display: flex; align-items: center; gap: 16px;
  padding-inline: var(--gutter);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.2) blur(10px);
  backdrop-filter: saturate(1.2) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; color: var(--ink); text-decoration: none; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-line { fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.brand-node-fill { fill: var(--surface); stroke: none; }
.brand-core { fill: var(--clay); stroke: none; }
.brand-core-edge { fill: none; stroke: var(--clay); stroke-width: 1.2; stroke-linecap: round; stroke-linejoin: round; }
.brand-title { font: 600 var(--fs-xl)/1.1 var(--serif); letter-spacing: -0.01em; white-space: nowrap; margin: 0; }
.brand-title em { font-style: italic; font-weight: 500; }
.brand-sub {
  font: 400 var(--fs-sm)/1.2 var(--sans); color: var(--ink-3); white-space: nowrap;
  padding-left: 14px; border-left: 1px solid var(--rule-strong);
}
.bar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.bar-actions .btn { min-height: 40px; padding: 0 14px; gap: 8px; }
/* The theme button shows the choice, not the colours in use: System (a screen), Light (a sun) or Dark (a moon); theme.js sets data-theme-pref. */
.theme-icon-light, .theme-icon-dark { display: none; }
:root[data-theme-pref="light"] .theme-icon-light, :root[data-theme-pref="dark"] .theme-icon-dark { display: block; }
:root[data-theme-pref="light"] .theme-icon-system, :root[data-theme-pref="dark"] .theme-icon-system { display: none; }

/* Search in the bar */
.search { position: relative; }
.search-field {
  display: flex; align-items: center; gap: 8px; height: 40px; width: 250px; padding: 0 12px;
  border: 1px solid var(--rule-strong); border-radius: var(--r-pill); background: var(--surface);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.search-field:focus-within { border-color: var(--ink-3); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.search-field svg { width: 17px; height: 17px; color: var(--ink-3); flex: none; }
.search-field input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink); outline: none;
  font: 400 var(--fs-md)/1 var(--sans);
}
.search-field input::placeholder { color: var(--ink-3); }
.search-field kbd {
  font: 500 var(--fs-2xs)/1 var(--mono); color: var(--ink-3); border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm); padding: 3px 6px; background: var(--paper);
}
.search-open { display: none; }
.search-results {
  position: absolute; right: 0; top: calc(100% + 8px); width: min(380px, calc(100vw - 32px));
  margin: 0; padding: 6px; list-style: none;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); box-shadow: var(--shadow);
  max-height: min(420px, 70vh); overflow: auto;
}
.search-results li { margin: 0; }
.search-results a {
  display: grid; grid-template-columns: 10px 1fr; column-gap: 10px; align-items: baseline;
  width: 100%; padding: 10px 10px; border-radius: var(--r-md); background: transparent; text-align: left; color: inherit; text-decoration: none;
}
.search-results a:hover, .search-results a:focus-visible, .search-field:focus-within ~ .search-results a.is-first { background: var(--paper-2); }
.search-results a:focus-visible { outline-offset: -2px; }
.search-field:focus-within kbd { display: none; }
.search-results .zdot { align-self: center; }
.search-results b { font: 600 var(--fs-md)/1.25 var(--sans); }
.search-results span { grid-column: 2; font-size: var(--fs-sm); line-height: 1.35; color: var(--ink-3); }
.search-results .sr-empty { padding: 12px; color: var(--ink-3); font-size: var(--fs-sm); }

/* Zones */
.zone {
  position: relative; isolation: isolate;
  padding: 14px 18px 14px;
  border-radius: var(--r-lg);
  background: var(--zt); /* replaced by the sketch once it is drawn */
}
.zone.is-sketched { background: transparent; }
.zone > .sk-bg { position: absolute; inset: -3px; z-index: -1; width: calc(100% + 6px); height: calc(100% + 6px); overflow: visible; pointer-events: none; }
.zone-head { display: grid; gap: 1px; padding-right: 52px; margin-bottom: 8px; }
.zone-h { margin: 0; font-size: inherit; line-height: 1.2; }
.zone-title {
  justify-self: start; margin: 0; padding: 0; border: 0; background: none; cursor: pointer; text-align: left;
  font: 600 var(--fs-xl)/1.2 var(--serif); color: var(--ink); letter-spacing: -0.01em;
}
.zone-title:hover { text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 4px; text-decoration-color: var(--zc); }
.zone-nick { font: italic 400 var(--fs-md)/1.3 var(--serif); color: var(--zc); }
.zone-doodle { position: absolute; top: 9px; right: 10px; width: 48px; height: 48px; overflow: visible; pointer-events: none; }
.zone-side .zone-head { padding-right: 0; }
/* Side zones wear their doodle like a sticker on the corner. */
.zone-side .zone-doodle { top: -15px; right: -14px; width: 42px; height: 42px; transform: rotate(-5deg); }
.zone-side[data-area="tools"] .zone-doodle, .zone-side[data-area="orch"] .zone-doodle { transform: rotate(5deg); }

.blk-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }
.blk {
  position: relative; display: flex; align-items: center; gap: 10px;
  width: 100%; margin: 0; padding: 3px 6px 3px 2px;
  border: 0; border-radius: var(--r-md); background: none; cursor: pointer; text-align: left; text-decoration: none;
  font: 500 var(--fs-md)/1.3 var(--sans); color: var(--ink);
  transition: opacity var(--dur-base), transform var(--dur-base) var(--ease);
}
.blk-dot { transition: transform var(--dur-base) var(--ease); }
.blk-t { position: relative; z-index: 0; }
.blk-t::before {
  /* Highlighter stroke, swept in on hover. */
  content: ""; position: absolute; z-index: -1; left: -4px; right: -5px; top: 52%; bottom: -1px;
  background: color-mix(in srgb, var(--zh) 75%, transparent);
  border-radius: 3px 9px 4px 10px / 6px 4px 8px 5px;
  transform: scaleX(0) rotate(-1deg); transform-origin: 0 50%;
  transition: transform var(--dur-base) var(--ease), top var(--dur-base) var(--ease);
}
.blk:hover .blk-t::before, .blk:focus-visible .blk-t::before { transform: scaleX(1) rotate(-1deg); }
.blk:hover .blk-dot { transform: scale(1.25); }
.blk.is-selected .blk-t::before, .blk.is-on .blk-t::before { transform: scaleX(1) rotate(-1deg); top: 8%; background: var(--zh); }
.blk.is-on .blk-dot { background: var(--zc); }
.blk.is-match .blk-t::before { transform: scaleX(1) rotate(-1deg); }

/* Inline zones (start and ops): head on the left, blocks in a row. */
.zone-row { display: flex; align-items: center; gap: 6px 22px; flex-wrap: wrap; padding: 12px 18px; }
.zone-row .zone-head { margin: 0; padding-right: 0; }
.zone-row .zone-doodle { position: static; width: 42px; height: 42px; order: -1; margin-right: -8px; }
.zone-row .blk-list { display: flex; flex-wrap: wrap; gap: 2px 14px; }
.zone-row .blk { width: auto; }
.map > [data-area="start"] { justify-self: center; width: min(100%, 640px); }
.map > [data-area="ops"] { justify-self: center; width: min(100%, 780px); }

/* The agent loop drawing (a link to the agent loop term) */
.loop {
  position: relative; display: block; margin: 8px auto 6px; padding: 0; width: 100%; max-width: 490px;
  border: 0; border-radius: var(--r-md); background: none; cursor: pointer; color: inherit; text-align: center; text-decoration: none;
}
.loop:hover .lp-center { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }
.loop-cap { display: block; margin-top: 2px; font: 400 var(--fs-xs)/1.3 var(--sans); color: var(--ink-3); letter-spacing: 0.01em; }
.loop .lp-exit-label.is-here { fill: var(--clay-ink); font-weight: 600; }
.loop svg { width: 100%; height: auto; overflow: visible; }
.loop .lp-name { font: 600 13.5px/1 var(--sans); fill: var(--ink); }
.loop .lp-sub { font: italic 400 12.5px/1 var(--serif); fill: var(--ink-3); }
.loop .lp-center { font: italic 500 17px/1 var(--serif); fill: var(--ink); }
.loop .lp-center-sub { font: 400 12px/1 var(--sans); fill: var(--ink-3); letter-spacing: 0.02em; }
.loop .lp-st .lp-node { transition: transform var(--dur-base) var(--ease); transform-box: fill-box; transform-origin: center; }
.loop .lp-st.is-here .lp-node { transform: scale(1.35); }
.loop .lp-st .lp-name { transition: fill var(--dur-base); }
.loop .lp-st.is-here .lp-name { fill: var(--clay-ink); }
.loop .lp-token { fill: var(--clay); stroke: var(--sk-ink); stroke-width: 1.5; }
.loop .lp-glow { fill: var(--clay); opacity: 0.22; }
.loop .lp-exit-label { font: italic 400 12.5px/1 var(--serif); fill: var(--ink-3); }

/* Connectors: hand-drawn arrows between the zones and the harness. */
.conn {
  --conn-axis: h;
  position: relative; display: block; width: 100%; margin: 0; padding: 0;
  border: 0; background: none; cursor: pointer; color: var(--ink-2); text-align: center;
  transition: opacity var(--dur-base);
}
.conn > .sk-conn { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.conn-text { position: absolute; inset: 0; }
.conn-label { font: 600 var(--fs-sm)/1.2 var(--sans); color: var(--ink); letter-spacing: 0.01em; }
.conn-sub { font: italic 400 var(--fs-sm)/1.25 var(--serif); color: var(--ink-3); }
.conn-glyph, .conn-to { display: none; }
.conn-h { align-self: center; height: 112px; }
.conn-h .conn-label { position: absolute; left: 0; right: 0; bottom: calc(50% + 9px); }
.conn-h .conn-sub { position: absolute; left: 50%; top: calc(50% + 10px); width: 104px; transform: translateX(-50%); }
.conn-v { --conn-axis: v; height: 100%; }
.conn-v .conn-label { position: absolute; left: calc(50% + 16px); top: 50%; transform: translateY(-50%); white-space: nowrap; text-align: left; }
.conn:hover .conn-label { text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 3px; text-decoration-color: var(--clay); }
.conn:focus-visible { outline-offset: -2px; }
.conn-flow { fill: none; stroke: var(--clay); stroke-width: 3.2; stroke-linecap: round; stroke-dasharray: 0.1 9; opacity: 0; }
.conn.is-on .conn-flow { opacity: 1; animation: conn-flow var(--dur-draw) linear infinite; }
.conn.is-on .conn-flow-rev { animation-direction: reverse; }
.conn.is-on .conn-label { color: var(--clay-ink); }
@keyframes conn-flow { to { stroke-dashoffset: -9.1; } }

/* ---------- Sketch layer (rough.js output) -------------------------------- */
.sk-line { fill: none; stroke: var(--sk-ink); stroke-linecap: round; stroke-linejoin: round; }
.sk-edge { stroke: var(--zc); }
.sk-fill { stroke: none; }
.sk-hatch { fill: none; }
.zone > .sk-bg .sk-line { opacity: 0.8; }
.boil .v1, .boil .v2 { visibility: hidden; }
.zone:hover > .sk-bg.boil .v0 { animation: boil0 var(--dur-boil) steps(1) infinite; }
.zone:hover > .sk-bg.boil .v1 { animation: boil1 var(--dur-boil) steps(1) infinite; }
.zone:hover > .sk-bg.boil .v2 { animation: boil2 var(--dur-boil) steps(1) infinite; }
@keyframes boil0 { 0% { visibility: visible; } 33.3% { visibility: hidden; } }
@keyframes boil1 { 0% { visibility: hidden; } 33.3% { visibility: visible; } 66.6% { visibility: hidden; } }
@keyframes boil2 { 0% { visibility: hidden; } 66.6% { visibility: visible; } }

/* First paint: outlines draw themselves, fills and labels fade in. */
.is-drawing .sk-draw { stroke-dasharray: 1; stroke-dashoffset: 1; animation: sk-draw var(--dur-draw) var(--ease) forwards; animation-delay: var(--d, 0s); }
.is-drawing .sk-fade { opacity: 0; animation: sk-fade var(--dur-reveal) var(--ease) forwards; animation-delay: var(--d, 0s); }
.is-drawing .zone .zone-head, .is-drawing .zone .blk-list, .is-drawing .zone .groups, .is-drawing .conn-label, .is-drawing .conn-sub, .is-drawing .conn-text,
.is-drawing .cta, .is-drawing .map-caption, .is-drawing .map-stamp, .is-drawing .loop {
  opacity: 0; animation: sk-rise var(--dur-reveal) var(--ease) forwards; animation-delay: calc(var(--d, 0s) + 0.25s);
}
@keyframes sk-draw { to { stroke-dashoffset: 0; } }
@keyframes sk-fade { to { opacity: 1; } }
@keyframes sk-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Term and guide pages, menu ------------------------------------------ */
.def { font: 400 var(--fs-lg)/1.55 var(--serif); color: var(--ink-2); }
.def-label { display: block; margin-bottom: 8px; }
.enter { margin-top: 22px; }
.enter-steps { display: flex; flex-wrap: wrap; gap: 6px; }
.step-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 8px;
  border: 1px solid var(--rule-strong); border-radius: var(--r-pill); background: var(--surface); cursor: pointer;
  font: 500 var(--fs-sm)/1.2 var(--sans); color: var(--ink);
}
.step-chip .badge { border-radius: var(--r-pill); padding: 4px 6px; }
.step-chip:hover { border-color: var(--ink-3); background: var(--paper-2); }
.deep { margin-top: 30px; padding-top: 4px; }
.deep-title { display: flex; align-items: center; gap: 12px; }
.deep-title::after { content: ""; flex: 1; height: 1px; background: var(--rule-strong); }
.bd-section { margin-top: 22px; }
.bd-section h2 { font: 600 var(--fs-lg)/1.3 var(--serif); margin-bottom: 8px; }
.prose p { font: 400 var(--fs-base)/1.6 var(--serif); color: var(--ink-2); }
.prose p + p { margin-top: 10px; }
.prose-s { font: 400 var(--fs-base)/1.55 var(--serif); color: var(--ink-2); }
.bd-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.bd-list li { position: relative; padding-left: 22px; font: 400 var(--fs-base)/1.5 var(--serif); color: var(--ink-2); }
.bd-list li::before { content: ""; position: absolute; left: 3px; top: 0.6em; width: var(--dot); height: var(--dot); border-radius: 50%; background: var(--zm); box-shadow: inset 0 0 0 var(--dot-ring) var(--zc); }
.bd-list-warn li::before { border-radius: 2px; transform: rotate(45deg); background: var(--warn-soft); box-shadow: inset 0 0 0 var(--dot-ring) var(--warn); }
.bd-list-sota li::before { background: var(--ok-soft); box-shadow: inset 0 0 0 var(--dot-ring) var(--ok); }
.bd-facts { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.bd-facts li { padding: 10px 12px; border-radius: var(--r-md); background: var(--paper-2); font: 400 var(--fs-md)/1.5 var(--sans); color: var(--ink-2); }
.bd-facts a { font-size: var(--fs-sm); white-space: nowrap; }
.bd-examples { display: flex; flex-wrap: wrap; gap: 6px; }
.bd-examples span { padding: 4px 10px; border-radius: var(--r-pill); background: var(--paper-2); border: 1px solid var(--rule); font: 400 var(--fs-sm)/1.35 var(--sans); color: var(--ink-2); }
.links { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.links li { display: grid; grid-template-columns: 78px 1fr; column-gap: 12px; row-gap: 2px; padding: 8px 0; border-top: 1px solid var(--rule); }
.links li:first-child { border-top: 0; }
.links .link-type { grid-row: span 2; align-self: start; justify-self: start; margin-top: 2px; text-transform: uppercase; border: 1px solid var(--rule); }
/* Source types borrow the zone hues as a categorical palette. */
.links .link-type-video { background: var(--t-control); color: var(--z-control); border-color: transparent; }
.links .link-type-paper { background: var(--t-model); color: var(--z-model); border-color: transparent; }
.links .link-type-docs, .links .link-type-spec, .links .link-type-standard { background: var(--t-orch); color: var(--z-orch); border-color: transparent; }
.links .link-type-course, .links .link-type-book { background: var(--t-know); color: var(--z-know); border-color: transparent; }
.links .link-type-guide, .links .link-type-blog, .links .link-type-definition { background: var(--t-tools); color: var(--z-tools); border-color: transparent; }
.links .link-type-law { background: var(--t-ops); color: var(--z-ops); border-color: transparent; }
.links a { font: 500 var(--fs-md)/1.35 var(--sans); }
.links .link-meta { font: 400 var(--fs-sm)/1.4 var(--sans); color: var(--ink-3); }

/* Chips: small block buttons used in panels. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px 4px 8px;
  border: 1px solid color-mix(in srgb, var(--zc) 30%, var(--rule)); border-radius: var(--r-pill);
  background: var(--zt); color: var(--ink); cursor: pointer; text-decoration: none;
  font: 500 var(--fs-sm)/1.3 var(--sans); text-align: left;
  transition: background-color var(--dur-fast), border-color var(--dur-fast);
}
.chip::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--zc); }
.chip:hover { border-color: var(--zc); background: color-mix(in srgb, var(--zm) 45%, var(--zt)); }

/* Guides menu */
.menu {
  position: fixed; z-index: var(--z-menu); top: calc(var(--bar-h) + env(safe-area-inset-top, 0px) - 4px); right: var(--gutter);
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - var(--bar-h) - 24px); overflow: auto;
  padding: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-xl); box-shadow: var(--shadow);
  animation: drop-in var(--dur-base) var(--ease);
}
@keyframes drop-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.menu-group { display: grid; align-content: start; gap: 2px; }
.menu-group h2 { padding: 10px 10px 6px; }
.menu-item {
  display: grid; gap: 1px; width: 100%; padding: 10px 10px; border: 0; border-radius: var(--r-md); background: none; cursor: pointer; text-align: left; text-decoration: none;
}
.menu-item[aria-current="page"] { background: var(--clay-soft); }
.menu-item:hover, .menu-item:focus-visible { background: var(--paper-2); }
.menu-item b { font: 600 var(--fs-md)/1.3 var(--sans); color: var(--ink); }
.menu-item span { font: italic 400 var(--fs-sm)/1.35 var(--serif); color: var(--ink-3); }

.subhead { font: 600 var(--fs-2xl)/1.25 var(--serif); margin: 40px 0 14px; }
.subhead:first-child { margin-top: 0; }
.sub-lede { font: 400 var(--fs-base)/1.55 var(--serif); color: var(--ink-2); max-width: 70ch; margin: -6px 0 16px; }

/* Five ideas */
.ideas { list-style: none; margin: 0; padding: 0; display: grid; gap: 18px; max-width: 860px; counter-reset: idea; }
.ideas li { position: relative; display: grid; grid-template-columns: 54px 1fr; column-gap: 18px; padding: 18px 0; border-top: 1px solid var(--rule); }
.ideas li:first-child { border-top: 0; }
.ideas .idea-num { grid-row: span 3; font: 500 var(--fs-5xl)/1 var(--serif); color: var(--clay-ink); }
.ideas h3 { font: 600 var(--fs-2xl)/1.3 var(--serif); }
.ideas p { margin-top: 6px; font: 400 var(--fs-lg)/1.55 var(--serif); color: var(--ink-2); max-width: 62ch; }
.ideas .chips { margin-top: 10px; }

/* Context window bars */
.ctx-wrap { display: grid; gap: 34px; max-width: 1000px; }
.ctx-row-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; margin-bottom: 10px; }
.ctx-row-head h3 { font: 600 var(--fs-xl)/1.3 var(--serif); }
.ctx-row-head .meta { font: 400 var(--fs-sm)/1.3 var(--mono); color: var(--ink-3); }
.ctx-bar-scroll { overflow-x: auto; padding-bottom: 4px; }
.ctx-bar { position: relative; display: flex; min-width: 640px; height: 58px; border-radius: var(--r-md); overflow: hidden; isolation: isolate; }
.ctx-bar > .sk-bg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; overflow: visible; }
.ctx-seg {
  position: relative; display: flex; align-items: center; justify-content: center; padding: 0 6px;
  background: var(--zt); color: var(--ink); font: 500 var(--fs-xs)/1.2 var(--sans); text-align: center; overflow: hidden;
  border-right: 1.5px solid var(--paper);
}
.ctx-seg-strong { background: var(--zh); }
.ctx-seg-danger { background: repeating-linear-gradient(135deg, var(--zh) 0 6px, var(--zt) 6px 12px); }
.ctx-seg-free { background: repeating-linear-gradient(135deg, var(--paper-2) 0 4px, var(--paper) 4px 8px); color: var(--ink-3); }
.ctx-cache { min-width: 640px; height: 36px; position: relative; }
.ctx-cache span { position: absolute; left: 0; bottom: 4px; height: 14px; border: 1.5px solid var(--clay-ink); border-bottom: 0; border-radius: var(--r-sm) var(--r-sm) 0 0; }
.ctx-cache em { position: absolute; left: 6px; bottom: 15px; white-space: nowrap; font: italic 400 var(--fs-sm)/1 var(--serif); color: var(--clay-ink); }
.ctx-break { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; font: 400 var(--fs-sm)/1.4 var(--sans); color: var(--ink-2); }
.ctx-break span { display: inline-flex; align-items: center; gap: 6px; }
.ctx-break i { width: 10px; height: 10px; border-radius: var(--r-xs); background: var(--zm); }
.ctx-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; font: italic 400 var(--fs-md)/1.4 var(--serif); color: var(--ink-3); }
.ctx-mini { display: inline-flex; width: 120px; height: 16px; border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--rule-strong); }
.ctx-mini .ctx-seg { border-right: 0; padding: 0; }
.ctx-row .cap { margin-top: 10px; font: 400 var(--fs-base)/1.55 var(--serif); color: var(--ink-2); max-width: 75ch; }
.ctx-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; font: 400 var(--fs-sm)/1.4 var(--sans); color: var(--ink-2); }
.ctx-legend span { display: inline-flex; align-items: center; gap: 8px; }
.ctx-legend i { width: 14px; height: 14px; border-radius: var(--r-xs); background: var(--zm); }
.ctx-legend .free-i { background: repeating-linear-gradient(135deg, var(--paper-2) 0 3px, var(--surface) 3px 6px); border: 1px solid var(--rule-strong); }

/* Tables */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font: 400 var(--fs-md)/1.45 var(--sans); }
th, td { text-align: left; vertical-align: top; padding: 12px 14px; border-top: 1px solid var(--rule); }
thead th { border-top: 0; background: var(--paper-2); position: sticky; top: 0; }
tbody th { font-weight: 600; }
.cmp { min-width: 980px; }
.cmp td { color: var(--ink-2); }
.cmp td:last-child { min-width: 170px; }
/* Tag: a status label that may wrap. */
.tag { display: inline-block; padding: 3px 10px; border-radius: var(--r-md); font: 600 var(--fs-xs)/1.35 var(--sans); max-width: 180px; }
.tag-yes { background: var(--ok-soft); color: var(--ok); }
.tag-no { background: var(--bad-soft); color: var(--bad); }
.tag-part { background: var(--part-soft); color: var(--part); }
.proto { min-width: 980px; }
.proto td { color: var(--ink-2); }
.proto .grp th { background: var(--paper-2); padding-block: 10px; }
.proto-name { display: block; font: 600 var(--fs-base)/1.3 var(--serif); }
.proto-link { font-size: var(--fs-sm); }
.proto-chip { margin-top: 8px; }

/* Patterns */
.patterns { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); gap: 16px; }
.pattern { margin: 0; padding: 18px 20px 20px; display: grid; align-content: start; gap: 10px; }
.pattern-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.pattern-head h2 { font: 600 var(--fs-2xl)/1.25 var(--serif); }
.pattern-head .kind { font: 500 var(--fs-xs)/1 var(--mono); letter-spacing: var(--track-mono); text-transform: uppercase; color: var(--ink-3); }
.pattern svg { width: 100%; height: auto; margin: 4px 0; overflow: visible; }
.pattern p { font: 400 var(--fs-md)/1.5 var(--serif); color: var(--ink-2); }
.pattern p strong { font-family: var(--sans); font-size: var(--fs-md); color: var(--ink); }
.pd-text { font: 500 11.5px/1 var(--sans); fill: var(--ink); }
.pd-elabel { font: italic 400 11px/1 var(--serif); fill: var(--ink-3); }
.pattern-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; font: 500 var(--fs-xs)/1.2 var(--sans); color: var(--ink-3); }
.pattern-meta > span { display: inline-flex; align-items: center; gap: 8px; }
.meter { display: inline-flex; gap: 3px; }
.meter i { width: 9px; height: 9px; border-radius: 50%; border: 1.4px solid var(--ink-3); }
.meter i.is-on { background: var(--clay); border-color: var(--clay); }

/* Build */
.build-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 32px; align-items: start; }
.ladder, .recipe { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.rung { position: relative; padding: 14px 16px 14px 70px; }
.rung .lvl { position: absolute; left: 14px; top: 14px; display: grid; justify-items: center; width: 42px; font: 500 var(--fs-2xs)/1 var(--mono); letter-spacing: var(--track-mono); text-transform: uppercase; color: var(--ink-3); }
.rung .lvl b { font: 500 var(--fs-3xl)/1.1 var(--serif); color: var(--clay-ink); }
.rung h2, .rung h3 { font: 600 var(--fs-lg)/1.3 var(--serif); }
.rung p { margin-top: 4px; font: 400 var(--fs-md)/1.5 var(--sans); color: var(--ink-2); }
.rung .climb { color: var(--ink-3); }
.recipe { counter-reset: rec; }
.recipe li { counter-increment: rec; position: relative; padding: 2px 0 14px 46px; border-bottom: 1px solid var(--rule); }
.recipe li::before { content: counter(rec, decimal-leading-zero); position: absolute; left: 0; top: 3px; font: 500 var(--fs-sm)/1.3 var(--mono); color: var(--clay-ink); }
.recipe h3 { font: 600 var(--fs-lg)/1.3 var(--serif); }
.recipe p { margin-top: 4px; font: 400 var(--fs-md)/1.5 var(--serif); color: var(--ink-2); }
.recipe .chips { margin-top: 8px; }
.flows { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 480px), 1fr)); gap: 14px; }
.flow { padding: 18px 20px; display: grid; gap: 10px; align-content: start; }
.flow h3 { font: 600 var(--fs-xl)/1.3 var(--serif); }
.flow > p { font: 400 var(--fs-md)/1.5 var(--serif); color: var(--ink-2); }
.flow-route { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px 4px; }
.flow-stop { display: grid; gap: 3px; justify-items: start; }
.flow-stop-note { font: italic 400 var(--fs-xs)/1.2 var(--serif); color: var(--ink-3); padding-left: 10px; }
.flow-route .sep { color: var(--ink-3); padding-top: 4px; }
.pairs { display: grid; gap: 10px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; }
.pair > div { position: relative; padding: 14px 16px 14px 42px; font: 400 var(--fs-md)/1.5 var(--serif); color: var(--ink-2); }
.pair > div::before { position: absolute; left: 15px; top: 12px; font: 650 var(--fs-md)/1.5 var(--sans); }
.pair-bad { background: color-mix(in srgb, var(--bad-soft) 55%, var(--surface)); }
.pair-bad::before { content: "✕"; color: var(--bad); }
.pair-good::before { content: "✓"; color: var(--ok); }
.checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 8px 18px; }
.checklist label { display: grid; grid-template-columns: 22px 1fr; gap: 12px; align-items: start; padding: 10px 12px; border-radius: var(--r-md); cursor: pointer; font: 400 var(--fs-md)/1.5 var(--serif); color: var(--ink-2); }
.checklist label:hover { background: var(--paper-2); }
.checklist input { width: 19px; height: 19px; margin: 2px 0 0; accent-color: var(--clay); }
.checklist input:checked + span { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--clay); }
.checklist-meta { display: flex; gap: 16px; align-items: center; margin-top: 12px; font: 400 var(--fs-sm)/1.4 var(--sans); color: var(--ink-3); }

/* Glossary */
.gloss-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-bottom: 18px; }
.gloss-tools .search-field { width: min(360px, 100%); }
.gloss { columns: 2 380px; column-gap: 40px; }
.gloss-letter { font: 600 var(--fs-3xl)/1 var(--serif); color: var(--clay-ink); margin: 18px 0 6px; break-after: avoid; }
.gloss dl { margin: 0; }
.gloss-entry { break-inside: avoid; padding: 8px 0 10px; border-top: 1px solid var(--rule); }
.gloss dt { font: 600 var(--fs-base)/1.35 var(--sans); }
.gloss dd { margin: 3px 0 0; font: 400 var(--fs-md)/1.5 var(--serif); color: var(--ink-2); }
.gloss dd .link-btn { margin-left: 6px; font: 500 var(--fs-sm)/1 var(--sans); }
.gloss-empty { color: var(--ink-3); }

/* Learn */
.learn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 460px), 1fr)); gap: 18px 28px; }
.learn-col h2 { font: 600 var(--fs-2xl)/1.3 var(--serif); }
.learn-col > p { margin: 4px 0 8px; font: italic 400 var(--fs-md)/1.45 var(--serif); color: var(--ink-3); }
.learn-col-wide { grid-column: 1 / -1; }
.learn-col-wide .links { grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); column-gap: 28px; }
.learn-col-wide .links li:nth-child(2) { border-top: 0; }

/* About */
.about { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 36px; max-width: 1000px; }
.about h2 { font: 600 var(--fs-xl)/1.3 var(--serif); margin: 0 0 8px; }
.about p, .about li { font: 400 var(--fs-base)/1.6 var(--serif); color: var(--ink-2); }
.about p + p, .about p + h2, .about ul + h2 { margin-top: 14px; }
.about ul { margin: 0; padding-left: 20px; }

/* ---------- Motion preferences ---------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important; scroll-behavior: auto !important; }
  .zone:hover > .sk-bg.boil .v0 { animation: none !important; visibility: visible; }
  .zone:hover > .sk-bg.boil .v1, .zone:hover > .sk-bg.boil .v2 { animation: none !important; visibility: hidden; }
  .conn.is-on .conn-flow { animation: none !important; stroke-dasharray: none; opacity: 0.8; }
}

/* ---------- Forced colours (Windows high contrast) -------------------------- */
@media (forced-colors: active) {
  .rail-item[aria-current] .rail-dot { forced-color-adjust: none; background: Highlight; color: HighlightText; }
  .rail-dot { border: 1px solid CanvasText; }
  .zone { border: 1px solid CanvasText; }
  .blk.is-on .blk-t, .blk.is-selected .blk-t { outline: 2px solid Highlight; }
}

/* ==========================================================================
   The deep dives: the chapters, the map, the glossary and the guides. Uses the tokens and shared pieces from DESIGN.md
   (.btn, .eyebrow, .badge, .card, .zdot, .chip); new prefixes: kmap (the kitchen
   map), ch (a chapter), hub (the whole kitchen), deeper (level 3 of an entry).
   ========================================================================== */

.stage { padding-inline: var(--gutter); }
.noscript { max-width: 640px; margin: 48px auto; font: 400 var(--fs-lg)/1.6 var(--serif); }
.btn-note { font-weight: 400; opacity: 0.8; }

/* Hero */
.hero {
  max-width: 1180px; margin: 0 auto; min-height: calc(100svh - var(--bar-h));
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: clamp(24px, 5vw, 72px); align-items: center;
  padding-block: 32px;
}
.hero .eyebrow { color: var(--clay-ink); }
.hero-title { margin-top: 14px; font: 600 clamp(var(--fs-5xl), 5.4vw, calc(var(--fs-5xl) * 1.7))/1.05 var(--serif); letter-spacing: -0.025em; }
.hero-line { margin-top: 18px; max-width: 36ch; font: 400 clamp(var(--fs-xl), 1.9vw, var(--fs-2xl))/1.5 var(--serif); color: var(--ink-2); }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.hero-actions .btn { min-height: 48px; padding-inline: 22px; font-size: var(--fs-base); }
.hero .pic { max-width: 520px; width: 100%; justify-self: center; }

/* Pictures */
.pic { margin: 0; aspect-ratio: 240 / 160; }
.pic svg { width: 100%; height: 100%; overflow: visible; }
.pic .sk-label { font: italic 500 10.5px/1 var(--serif); fill: var(--ink-2); }

/* Story: chapters on the left, the growing map on the right */
.story {
  max-width: 1440px; margin: 0 auto;
  display: grid; grid-template-columns: minmax(34rem, 1fr) minmax(0, 1.05fr); gap: clamp(28px, 4vw, 64px); align-items: start;
}
.chapters { min-width: 0; }
.chapter { max-width: 640px; padding-block: clamp(48px, 9vh, 96px); border-top: 1px solid var(--rule); }
.chapter:first-child { border-top: 0; }
.chapter:focus { outline: none; }
.chapter > .eyebrow { color: var(--zc); }
.ch-title { margin-top: 10px; font: 600 clamp(var(--fs-4xl), 3.4vw, calc(var(--fs-5xl) * 1.1))/1.1 var(--serif); letter-spacing: -0.02em; }
.ch-problem { margin-top: 16px; padding-left: 16px; border-left: 3px solid var(--zm); font: italic 400 var(--fs-xl)/1.5 var(--serif); color: var(--ink-2); }
.ch-section { margin-top: 28px; }
.ch-section > .eyebrow { display: block; margin-bottom: 8px; }
.ch-real p:not(.eyebrow) { font: 400 var(--fs-lg)/1.65 var(--serif); color: var(--ink-2); }
.ch-real p + p { margin-top: 12px; }
.ch-example { padding: 16px 18px; border-radius: var(--r-lg); background: var(--paper-2); border: 1px dashed var(--rule-strong); }
.ch-example p:not(.eyebrow) { font: 400 var(--fs-lg)/1.55 var(--serif); color: var(--ink); }
.ch-terms .chip { padding: 6px 13px 6px 10px; font-size: var(--fs-md); }
.fig { margin-top: 28px; }
.fig-loop .loop { max-width: 520px; margin: 0; }
.fig-cap { margin-top: 4px; font: italic 400 var(--fs-sm)/1.4 var(--serif); color: var(--ink-3); }
.ctx-wrap { gap: 24px; }
.ctx-title { margin-bottom: 8px; font: 600 var(--fs-lg)/1.3 var(--serif); }
.ctx-bar { min-width: 0; height: 46px; }
.ctx-seg { white-space: nowrap; text-overflow: ellipsis; }
.ctx-row .cap { font-size: var(--fs-md); }

/* The map beside the chapters (wide screens) and the small sketches inside them (narrow screens) */
.story-map { position: sticky; top: calc(var(--bar-h) + 16px); padding-block: 24px; }
.story-map-inner { transform-origin: top center; }
.mini-map { display: none; }

/* The kitchen map */
.kmap { position: relative; display: grid; gap: 14px; }
.kmap-tall {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-areas: "you you" "chef tools" "kitchen kitchen" "recipes helpers" "ops ops";
}
.kmap-hub {
  max-width: 1400px; margin: 0 auto; row-gap: 18px; column-gap: 0;
  grid-template-columns: minmax(200px, 1fr) 96px minmax(0, 2.1fr) 96px minmax(200px, 1fr);
  grid-template-areas:
    ".       .  you     .  ."
    "chef    cA kitchen cB tools"
    "recipes cC kitchen cD helpers"
    ".       .  ops     .  .";
}
.kmap > [data-area="you"] { grid-area: you; justify-self: center; }
.kmap > [data-area="chef"] { grid-area: chef; }
.kmap > [data-area="tools"] { grid-area: tools; }
.kmap > [data-area="kitchen"] { grid-area: kitchen; }
.kmap > [data-area="recipes"] { grid-area: recipes; }
.kmap > [data-area="helpers"] { grid-area: helpers; }
.kmap > [data-area="ops"] { grid-area: ops; justify-self: center; width: min(100%, 720px); }
.kmap > [data-area="cA"] { grid-area: cA; }
.kmap > [data-area="cB"] { grid-area: cB; }
.kmap > [data-area="cC"] { grid-area: cC; }
.kmap > [data-area="cD"] { grid-area: cD; }
.kmap-hub > [data-area="recipes"], .kmap-hub > [data-area="helpers"], .kmap-hub > [data-area="cC"], .kmap-hub > [data-area="cD"] { align-self: start; }
.kmap .conn { cursor: default; }
.zone-n {
  display: inline-grid; place-items: center; min-width: 1.6em; height: 1.6em; margin-right: 6px; padding: 0 0.3em;
  border-radius: var(--r-pill); background: var(--zh); color: var(--ink); font: 600 0.62em/1 var(--sans); vertical-align: 0.2em;
}
.zone-you { display: flex; align-items: center; gap: 10px; padding: 8px 18px; }
.you-text { font: italic 400 var(--fs-base)/1.3 var(--serif); color: var(--ink-2); }
.you-text b { font: 600 var(--fs-base)/1.3 var(--sans); color: var(--ink); }
.blk-row { display: flex; flex-wrap: wrap; gap: 2px 14px; }
.blk-row .blk { width: auto; }

/* The kitchen: counter, loop and locks inside one frame; the frame appears with chapter 4 */
.zone-kitchen { display: flex; flex-direction: column; gap: 12px; padding: 16px 20px 18px; }
.zone-kitchen:not(.is-framed) { padding: 0; background: transparent; }
.zone-kitchen:not(.is-framed) > .sk-bg { display: none; }
.kitchen-head { display: grid; gap: 4px; padding-right: 56px; }
.kitchen-head .zone-head { margin-bottom: 2px; }
.kitchen-head .zone-title { font-size: var(--fs-2xl); }
.counter { position: relative; isolation: isolate; padding: 12px 16px; border-radius: var(--r-md); background: var(--sk-paper); }
.counter.is-sketched { background: transparent; }
.counter > .sk-bg { position: absolute; inset: -3px; z-index: -1; width: calc(100% + 6px); height: calc(100% + 6px); overflow: visible; pointer-events: none; }
.counter .zone-head { padding-right: 0; }
.zone-locks { padding: 10px 14px; }
.zone-locks .zone-title { font-size: var(--fs-lg); }
.kmap .loop { max-width: 480px; margin: 0 auto; }

/* Reading progress: the current chapter's pieces stand out, earlier ones step back */
.kmap [data-ch] { transition: opacity var(--dur-base); }
.kmap [data-ch].is-past { opacity: 0.7; }
.kmap [data-ch].is-current .blk-t::before { transform: scaleX(1) rotate(-1deg); }
.kmap [data-ch].is-current .zone-title { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; text-decoration-color: var(--zc); }
.kmap.is-search .blk:not(.is-match) { opacity: 0.3; }
.kmap.is-search .blk.is-match .blk-t::before { transform: scaleX(1) rotate(-1deg); }

/* Pieces that appear: the outline draws itself, the content rises */
.is-drawing > .zone-head, .is-drawing > .blk-list, .is-drawing > .zone-doodle, .is-drawing > .kitchen-head, .is-drawing > .you-text {
  opacity: 0; animation: sk-rise var(--dur-reveal) var(--ease) forwards; animation-delay: 0.3s;
}

/* Mini maps: small, quiet, not interactive */
.kmap-mini { gap: 8px; }
.kmap-mini .zone { padding: 8px 10px; }
.kmap-mini .zone-head { padding-right: 0; margin-bottom: 4px; }
.kmap-mini .zone-title { font-size: var(--fs-md); }
.kmap-mini .zone-nick { font-size: var(--fs-xs); }
.kmap-mini .blk { gap: 6px; padding: 1px 2px; font-size: var(--fs-xs); }
.kmap-mini .blk-dot { width: 7px; height: 7px; }
.kmap-mini .zone-kitchen { gap: 8px; padding: 10px 12px; }
.kmap-mini .zone-kitchen:not(.is-framed) { padding: 0; }
.kmap-mini .kitchen-head { padding-right: 0; }
.kmap-mini .kitchen-head .zone-title { font-size: var(--fs-base); }
.kmap-mini .counter { padding: 8px 10px; }
.kmap-mini .zone-you { padding: 4px 12px; }
.kmap-mini .you-text, .kmap-mini .you-text b { font-size: var(--fs-sm); }

/* Hub, recap and stamp */
.hub { padding-block: clamp(56px, 10vh, 120px) 40px; border-top: 1px solid var(--rule); }
.hub:focus { outline: none; }
.hub-head { max-width: 1400px; margin: 0 auto 28px; }
.hub-head .eyebrow { color: var(--clay-ink); }
.hub-title { margin-top: 10px; font: 600 clamp(var(--fs-4xl), 3.6vw, calc(var(--fs-5xl) * 1.2))/1.1 var(--serif); letter-spacing: -0.02em; }
.hub-lede { margin-top: 10px; font: italic 400 var(--fs-lg)/1.5 var(--serif); color: var(--ink-3); }
.recap { max-width: 900px; margin: clamp(56px, 9vh, 96px) auto 0; }
.recap-title { margin-bottom: 18px; font: 600 clamp(var(--fs-3xl), 3vw, var(--fs-5xl))/1.15 var(--serif); }
.stamp { max-width: 900px; margin: 48px auto 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font: 400 var(--fs-sm)/1.5 var(--sans); color: var(--ink-3); }
.stamp .badge { transform: rotate(-2deg); text-transform: uppercase; }

/* Drawer additions: the example, "go deeper", sources */
.bd-example { padding: 12px 14px; border-radius: var(--r-md); background: var(--paper-2); border: 1px dashed var(--rule-strong); font: 400 var(--fs-base)/1.55 var(--serif); color: var(--ink); }
.deeper { margin-top: 30px; border-top: 1px solid var(--rule-strong); }
.deeper > summary { display: flex; align-items: baseline; gap: 10px; padding: 14px 0 4px; cursor: pointer; list-style: none; font: 600 var(--fs-md)/1.3 var(--sans); color: var(--ink); }
.deeper > summary::-webkit-details-marker { display: none; }
.deeper > summary::before {
  content: "+"; display: inline-grid; place-items: center; width: 22px; height: 22px; flex: none;
  border: 1.5px solid var(--ink-3); border-radius: 50%; font: 600 var(--fs-sm)/1 var(--sans); color: var(--ink-2);
}
.deeper[open] > summary::before { content: "−"; }
.deeper-hint { font: italic 400 var(--fs-sm)/1.3 var(--serif); color: var(--ink-3); }
.more-sources { margin-top: 8px; }
.more-sources > summary { padding: 6px 0; cursor: pointer; font: 500 var(--fs-sm)/1.4 var(--sans); color: var(--clay-ink); }
.v1-ref { margin-top: 22px; font: 400 var(--fs-sm)/1.5 var(--sans); color: var(--ink-3); }
.sr-kind { font: italic 400 var(--fs-sm)/1 var(--serif); color: var(--ink-3); }
.menu { grid-template-columns: 1fr; width: min(380px, calc(100vw - 32px)); }

/* ---------- Term and guide pages ---------------------------------------------- */
.page { max-width: 760px; margin: 0 auto; padding-block: clamp(24px, 5vh, 56px) clamp(48px, 9vh, 96px); }
.page-guide { max-width: 1120px; }
.page-head { margin-bottom: 26px; padding-bottom: 20px; border-bottom: 1px solid var(--rule); }
.crumb {
  display: inline-flex; align-items: center; gap: 8px; margin-bottom: 18px; padding: 4px 0;
  font: 500 var(--fs-sm)/1.3 var(--sans); color: var(--ink-2); text-decoration: none;
}
.crumb:hover { color: var(--ink); text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 4px; }
.page-entry .crumb { color: var(--zc); }
.page-eyebrow { color: var(--clay-ink); }
.page-entry .page-eyebrow { color: var(--zc); }
.page-title { margin-top: 10px; font: 600 clamp(var(--fs-3xl), 3.6vw, var(--fs-5xl))/1.12 var(--serif); letter-spacing: -0.02em; max-width: 26ch; }
.page-lede { margin-top: 12px; max-width: 70ch; font: 400 var(--fs-lg)/1.55 var(--serif); color: var(--ink-2); }
.page-body { padding-top: 6px; }
.page-note { margin-top: 18px; max-width: 75ch; font: 400 var(--fs-md)/1.55 var(--sans); color: var(--ink-3); }
.pager { display: flex; justify-content: space-between; gap: 14px; margin-top: 44px; padding-top: 20px; border-top: 1px solid var(--rule); }
.pager-link {
  display: grid; gap: 4px; max-width: 48%; padding: 10px 12px; margin: -10px -12px; border-radius: var(--r-md);
  color: var(--ink); text-decoration: none;
}
.pager-link:hover { background: var(--paper-2); }
.pager-link b { font: 600 var(--fs-base)/1.3 var(--serif); }
.pager-next { margin-left: auto; text-align: right; }

/* ---------- Where you are: dots beside the text (number inside), a line on narrow screens ------- */
.rail { position: fixed; z-index: var(--z-rail); left: var(--rail-x, 56px); top: 50%; transform: translate(-100%, -50%); display: none; }
.rail-list { list-style: none; margin: 0; padding: 0; position: relative; display: grid; gap: 8px; }
.rail-list::before, .rail-list::after {
  content: ""; position: absolute; right: 9px; top: 12px; bottom: 12px; width: 2px; margin-right: -1px; border-radius: 1px;
}
.rail-list::before { background: var(--ink-3); opacity: 0.45; }
.rail-list::after { background: var(--clay); transform: scaleY(var(--rail-p, 0)); transform-origin: top; transition: transform var(--dur-base) linear; }
.rail-item {
  position: relative; display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-height: 24px; padding: 1px 0;
  color: var(--ink-2); text-decoration: none; font: 500 var(--fs-sm)/1.2 var(--sans);
}
.rail-dot {
  flex: none; width: 18px; height: 18px; border-radius: 50%; position: relative; z-index: 1;
  display: grid; place-items: center; font: 700 10px/1 var(--sans); color: var(--ink-2);
  background: var(--paper); box-shadow: inset 0 0 0 2px var(--ink-3);
  transition: transform var(--dur-base) var(--ease), background-color var(--dur-base), box-shadow var(--dur-base);
}
.rail-dot:empty { width: 12px; height: 12px; margin: 3px; }
.rail-item.is-past .rail-dot { background: var(--clay-mid); box-shadow: inset 0 0 0 2px var(--clay); color: var(--ink); }
.rail-item[aria-current] .rail-dot { background: var(--zc, var(--clay)); box-shadow: inset 0 0 0 2px var(--zc, var(--clay)); transform: scale(1.25); color: var(--paper); }
.rail-label {
  position: absolute; left: calc(100% + 8px); top: 50%; padding: 5px 10px; border: 1px solid var(--rule); border-radius: var(--r-md);
  background: var(--surface); box-shadow: var(--shadow); white-space: nowrap; color: var(--ink);
  opacity: 0; pointer-events: none; transform: translate(-4px, -50%); transition: opacity var(--dur-fast), transform var(--dur-fast) var(--ease);
}
.rail-item:hover .rail-label, .rail-item:focus-visible .rail-label { opacity: 1; transform: translate(0, -50%); }
.rail-item:hover .rail-dot, .rail-item:focus-visible .rail-dot { transform: scale(1.25); }
.progress {
  position: fixed; z-index: var(--z-rail); left: 0; right: 0; top: calc(var(--bar-h) + env(safe-area-inset-top, 0px)); height: 3px;
  background: transparent; pointer-events: none;
}
.progress i { display: block; height: 100%; background: var(--clay); transform: scaleX(0); transform-origin: left; }
@media (min-width: 1280px) and (min-height: 480px) {
  .rail { display: block; }
  .progress { display: none; }
}
/* With the map beside the text the dots need a strip of their own at the left of the chapters. */
@media (min-width: 1280px) and (min-height: 660px) {
  .story { padding-left: 56px; }
}

/* ---------- Responsive ------------------------------------------------------ */
@media (max-width: 1240px) {
  .brand-sub { display: none; }
}
@media (max-width: 1079px) {
  .kmap-hub {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 14px;
    grid-template-areas: "you you" "chef tools" "kitchen kitchen" "recipes helpers" "ops ops";
  }
  .kmap-hub > .conn { display: none; }
}
/* Narrow or short screens: one column with a small map in each chapter; the sticky map would not fit. */
@media (max-width: 1023px), (max-height: 659px) {
  .story { grid-template-columns: minmax(0, 1fr); }
  .story-map { display: none; }
  .mini-map { display: block; margin-top: 20px; }
  .chapter { max-width: 680px; margin-inline: auto; }
}
@media (max-width: 760px) {
  :root { --bar-h: 54px; }
  .bar { gap: 8px; }
  .brand-title { font-size: var(--fs-lg); }
  .brand-mark { width: 26px; height: 26px; }
  .bar-actions .btn-label { display: none; }
  .bar-actions .btn { padding: 0 10px; }
  .search-field { display: none; }
  .search-open { display: inline-grid; }
  .search.is-open .search-field {
    display: flex; position: fixed; left: 12px; right: 12px; top: calc(var(--bar-h) + env(safe-area-inset-top, 0px) + 8px); width: auto; z-index: calc(var(--z-bar) + 1); box-shadow: var(--shadow);
  }
  .search.is-open .search-results { position: fixed; left: 12px; right: 12px; top: calc(var(--bar-h) + env(safe-area-inset-top, 0px) + 58px); width: auto; }
  .zone { padding: 12px 14px; }
  .links li { grid-template-columns: 1fr; }
  .links .link-type { grid-row: auto; margin-bottom: 4px; }
  .menu { left: 12px; right: 12px; width: auto; }
  .build-grid, .about { grid-template-columns: 1fr; }
  .ideas li { grid-template-columns: 40px 1fr; column-gap: 12px; }
  .ideas .idea-num { font-size: var(--fs-4xl); }
  .hero { grid-template-columns: 1fr; min-height: 0; padding-block: 24px 40px; }
  .hero .pic { max-width: 360px; order: -1; }
  .ch-problem { font-size: var(--fs-lg); }
  .ctx-seg { font-size: 0; }
  .ch-real p:not(.eyebrow) { font-size: var(--fs-base); }
  .kmap-hub { grid-template-columns: minmax(0, 1fr); grid-template-areas: "you" "chef" "kitchen" "tools" "recipes" "helpers" "ops"; }
}
@media (max-width: 480px) {
  .brand-tail { display: none; }
  /* The switch needs the room: the mark alone stands for the brand (the link keeps its label). */
  .brand-title { display: none; }
}

/* ---------- The technical hero (the formula) and the way from a kitchen page to the technical one ----------------- */
.formula { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 14px 12px; max-width: 520px; width: 100%; justify-self: center; }
.formula-part { display: inline-flex; padding: 14px 20px; font: 600 var(--fs-2xl)/1.2 var(--serif); color: var(--zc); text-decoration: none; }
.formula-agent { color: var(--ink); }
.formula-op { font: 400 var(--fs-3xl)/1 var(--serif); color: var(--ink-3); }
a.formula-part:hover { color: var(--ink); }


.deeper-open { padding-top: 6px; }
.deeper-title { margin: 22px 0 0; font: 600 var(--fs-xl)/1.3 var(--serif); }

/* The slim bar that keeps the chapter in view once its title has scrolled out (stickhead.js shows it; it is drawn by story.js and hidden from screen readers, which have the real heading). Its box has a height and no
   room in the flow (the negative margin), so it is pushed out when the chapter ends. */
.ch-stick { position: sticky; top: calc(var(--bar-h) + env(safe-area-inset-top, 0px)); z-index: calc(var(--z-bar) - 5); height: 44px; margin-bottom: -44px; pointer-events: none; opacity: 0; visibility: hidden; transition: opacity var(--dur-fast), visibility 0s linear var(--dur-fast); }
.ch-stick.is-on { opacity: 1; visibility: visible; transition: opacity var(--dur-fast); }
.ch-stick-in { display: flex; align-items: baseline; gap: 12px; height: 100%; margin-inline: -14px; padding: 0 14px; align-content: center; align-items: center; overflow: hidden; white-space: nowrap; background: var(--paper); border-bottom: 1px solid var(--rule); }
.ch-stick-n { flex: none; font: 500 var(--fs-2xs)/1 var(--mono); letter-spacing: var(--track-mono); text-transform: uppercase; color: var(--ink-3); }
.ch-stick-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; font: 600 var(--fs-2xl)/1.2 var(--serif); letter-spacing: -0.01em; color: var(--ink); }
@media (prefers-reduced-motion: reduce) { .ch-stick, .ch-stick.is-on { transition: none; } }
.chapter { scroll-margin-top: calc(-1 * var(--stick-h, 0px)); }
.ch-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.ch-icon { flex: none; width: 64px; height: 64px; overflow: visible; margin-top: 4px; }
.def-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.def-icon { flex: none; width: 64px; height: 64px; overflow: visible; }
.formula-icon { width: 30px; height: 30px; margin-right: 8px; overflow: visible; flex: none; }
.formula-part { align-items: center; }
.formula-pair { display: inline-flex; align-items: center; gap: 12px; white-space: nowrap; }
@media (max-width: 760px) {
  .ch-icon, .def-icon { width: 48px; height: 48px; }
  .formula-icon { display: none; }
}

/* ---------- Print: the text and the whole kitchen ---------------------------- */
@media print {
  .bar, .menu, .rail, .progress, .crumb, .pager, .skip-link, .story-map, .mini-map, .hero-actions { display: none !important; }
  /* A dark theme still prints on white paper: put the light colours back. */
  :root[data-theme="dark"] {
    color-scheme: light;
    --paper: #faf9f5;
    --paper-2: #f0eee6;
    --paper-3: #e8e5da;
    --surface: #ffffff;
    --ink: #141413;
    --ink-2: #3d3d3a;
    --ink-3: #6b6a65;
    --ink-hover: #2f2e2b;
    --rule: #e3e1d8;
    --rule-strong: #cfccc0;
    --focus: #2c6fbb;
    --shadow: 0 2px 6px rgba(20, 20, 19, 0.06), 0 18px 48px rgba(20, 20, 19, 0.14);
    --clay: #d97757;
    --clay-ink: #9e4a2d;
    --clay-soft: #f6e0d4;
    --clay-mid: #e9a385;
    --sk-ink: #141413;
    --sk-paper: #fffdf8;
    --ok: #4d6b2f; --ok-soft: #e5e9d3;
    --bad: #983e5c; --bad-soft: #f4dee5;
    --part: #855628; --part-soft: #f2e6cd;
    --z-start: #5f5d57; --t-start: #ebe7dc; --m-start: #cdc5b2;
    --z-model: #5b5486; --t-model: #e4e1f0; --m-model: #b9b3d8;
    --z-harness: #9e4a2d; --t-harness: #f7e3d8; --m-harness: #e9a385;
    --z-control: #983e5c; --t-control: #f4dee5; --m-control: #dfa6b9;
    --z-know: #56652c; --t-know: #e5e9d3; --m-know: #b8c38a;
    --z-tools: #855628; --t-tools: #f2e6cd; --m-tools: #dbb586;
    --z-orch: #2f6190; --t-orch: #dce8f3; --m-orch: #9cc0df;
    --z-ops: #386857; --t-ops: #dceae3; --m-ops: #a3c8b8;
    --hl-mix: 100%;
  }
  body { background: var(--paper); }
  .story { display: block; }
  .chapter, .zone { break-inside: avoid; }
}

/* ==========================================================================
   Touch and reading details.
   ========================================================================== */
/* A field under 16px makes iOS zoom the page on focus. */
@media (max-width: 760px) {
  .search-field input { font-size: 16px; }
}
/* Links in a list of sources and pager links are easy to hit. */
.links li { padding-block: 10px; }
/* A wide table (the comparison) says it scrolls: a soft edge on the right while there is more. */
.table-scroll { background: linear-gradient(to right, var(--surface) 30%, transparent) 0 0 / 28px 100% no-repeat local, linear-gradient(to left, var(--surface) 30%, transparent) 100% 0 / 28px 100% no-repeat local, radial-gradient(farthest-side at 0 50%, var(--rule-strong), transparent) 0 0 / 10px 100% no-repeat scroll, radial-gradient(farthest-side at 100% 50%, var(--rule-strong), transparent) 100% 0 / 10px 100% no-repeat scroll; }

/* ---------- Touch on the deep dive: the pieces of the map, the chips and the footer links get a hit area of 40px ---------- */
@media (pointer: coarse) {
  .hub .kmap .blk { min-height: 40px; }
  .hub .kmap .zone-title { min-height: 40px; display: inline-flex; align-items: center; }
  .chip { min-height: 40px; }
  .stamp a { display: inline-block; padding-block: 12px; margin-block: -12px; }
}
/* The small map of a chapter is a picture (it cannot be tapped), but its words still have to be readable. */
@media (max-width: 760px) {
  .kmap-mini .blk { font-size: var(--fs-sm); }
  /* The shield of the guardrails sits in the corner: the row of words leaves it room. */
  .zone-locks .blk-row { padding-right: 52px; }
  /* "You" stays one row (icon left, words right) on the narrowest screens. */
  .zone-you { flex-wrap: nowrap; padding-inline: 12px; }
  .zone-you .zone-doodle { flex: none; width: 34px; height: 34px; }
}
