/* ============================================
   TOKENS
   ============================================ */
:root {
  --surface: oklch(0.955 0.008 165);
  --surface-raised: oklch(0.985 0.004 165);
  --ink: oklch(0.24 0.025 205);
  --line: oklch(0.8 0.012 190);
  --signal-ink: oklch(0.5 0.17 40);

  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --gutter: clamp(16px, 2.6vw, 40px);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

  --z-scene: 0;
  --z-story: 10;
  --z-panel: 20;
  --z-header: 30;
  --rain: oklch(0.66 0.1 240);
}

/* Night: the page turns to a moonlit sky; ink and surfaces swap. */
body.night {
  --surface: oklch(0.2 0.03 262);
  --surface-raised: oklch(0.27 0.035 262);
  --ink: oklch(0.93 0.012 240);
  --line: oklch(0.42 0.03 262);
  --signal-ink: oklch(0.8 0.13 75);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--surface); scroll-behavior: smooth; }
body { min-height: 100%; background: var(--surface); }

body {
  transition: background-color 1.2s var(--ease-out), color 1.2s var(--ease-out);
  overflow-x: hidden;
  color: var(--ink);
  font-family: var(--font-display);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}

:focus-visible {
  outline: 2px solid var(--signal-ink);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ============================================
   MASTHEAD
   ============================================ */
.masthead {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: var(--z-header);
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  padding: var(--gutter);
  pointer-events: none;
}
.masthead > * { pointer-events: auto; }

.name {
  font-size: clamp(2.8rem, 6.6vw, 6rem);
  font-weight: 750;
  font-variation-settings: 'opsz' 96;
  letter-spacing: -0.025em;
  line-height: 0.95;
}

.topnav { display: flex; align-items: center; gap: 0.6rem; }

.contact-btn {
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--surface-raised);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s var(--ease-out);
}
.contact-btn:hover { background: var(--signal-ink); }

.lang-btn {
  font: 600 0.8rem/1 var(--font-display);
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  transition: border-color 0.2s;
}
.lang-btn:hover { border-color: var(--ink); }

.night-btn { display: grid; place-items: center; padding: 0.45rem; }
.night-btn svg { width: 1.05rem; height: 1.05rem; fill: currentColor; }
.night-btn .i-sun path { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.night-btn .i-sun, .night-btn[aria-pressed="true"] .i-moon { display: none; }
.night-btn[aria-pressed="true"] .i-sun { display: block; }

/* ============================================
   SIMULATION
   ============================================ */
.sim { position: relative; }
.sim[hidden] { display: none; }
.sim-btn { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.5rem 0.7rem 0.5rem 0.65rem; line-height: 1; }
.sim-btn svg { flex: none; display: block; }
.sim-ico { width: 1rem; height: 1rem; fill: currentColor; }
.sim-ico .drops { fill: none; stroke: var(--rain); stroke-width: 2; stroke-linecap: round; }
.sim-caret { width: 0.6rem; height: 0.6rem; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; opacity: 0.6; transition: transform 0.2s var(--ease-out); }
.sim-btn[aria-expanded="true"] .sim-caret { transform: rotate(180deg); }
.sim-btn[aria-expanded="true"], .sim-btn.running { border-color: var(--ink); }
.sim-btn.running .drops { animation: drizzle 0.9s linear infinite; }
@keyframes drizzle { from { transform: translateY(-1.5px); opacity: 0.4; } 50% { opacity: 1; } to { transform: translateY(1.5px); opacity: 0.4; } }

.sim-menu {
  position: absolute; top: calc(100% + 0.5rem); right: 0;
  width: 19rem;
  padding: 0.35rem;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 6px 8px oklch(0.2 0.03 220 / 0.1);
  transform-origin: top right;
  animation: menu-in 0.2s var(--ease-out);
}
.sim-menu[hidden] { display: none; }
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
.sim-item {
  display: flex; align-items: center; gap: 0.75rem;
  width: 100%;
  padding: 0.6rem 0.65rem;
  border: 0; border-radius: 10px;
  background: none;
  color: var(--ink);
  font: inherit; text-align: left;
  cursor: pointer;
  transition: background-color 0.15s;
}
.sim-item[hidden] { display: none; }
.sim-item:hover, .sim-item:focus-visible { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.sim-item:focus-visible { outline-offset: -2px; }
.sim-item-ico {
  flex: none; display: grid; place-items: center;
  width: 2.4rem; height: 2.4rem; border-radius: 9px;
  background: color-mix(in srgb, var(--rain) 18%, var(--surface-raised));
  color: oklch(0.45 0.12 240);
}
.sim-item-ico svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sim-item-end .sim-item-ico { background: color-mix(in srgb, var(--signal-ink) 16%, var(--surface-raised)); color: var(--signal-ink); }
.sim-item-end .sim-item-ico svg { fill: currentColor; stroke: none; }
.sim-item-text { display: grid; gap: 0.15rem; min-width: 0; flex: 1; }
.sim-item-text strong { font-size: 0.92rem; font-weight: 650; }
.sim-item-text span { font-size: 0.78rem; line-height: 1.35; color: color-mix(in srgb, var(--ink) 70%, var(--surface-raised)); }
.sim-item-go { flex: none; width: 0.8rem; height: 0.8rem; fill: currentColor; opacity: 0; transform: translateX(-3px); transition: opacity 0.15s, transform 0.2s var(--ease-out); }
.sim-item:hover .sim-item-go, .sim-item:focus-visible .sim-item-go { opacity: 0.7; transform: none; }
body.night .sim-item-ico { color: oklch(0.82 0.09 240); }

.sim-panel {
  position: fixed; left: var(--gutter); bottom: var(--gutter);
  z-index: var(--z-panel);
  width: min(21.5rem, calc(100vw - 2 * var(--gutter)));
  padding: 0.85rem 0.95rem 0.95rem;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 6px 8px oklch(0.2 0.03 220 / 0.1);
  color: var(--ink);
  font-size: 0.85rem;
  animation: panel-in 0.4s var(--ease-out);
}
.sim-panel[hidden] { display: none; }
@keyframes panel-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } }
.sim-head { display: flex; align-items: center; gap: 0.7rem; }
.sim-badge { width: 2.3rem; height: 2.3rem; }
.sim-head-text { display: grid; gap: 0.1rem; }
.sim-panel h2 { font-size: 1.02rem; font-weight: 720; letter-spacing: -0.01em; line-height: 1.1; }
.sim-clock { font-variant-numeric: tabular-nums; font-size: 0.78rem; color: color-mix(in srgb, var(--ink) 70%, var(--surface-raised)); }
.sim-phase { margin: 0.65rem 0 0.75rem; min-height: 2.6em; line-height: 1.3; color: color-mix(in srgb, var(--ink) 80%, var(--surface-raised)); text-wrap: pretty; }
.sim-body { display: grid; grid-template-columns: 4.1rem 1fr; gap: 0.85rem; align-items: stretch; }
.sim-gauge { display: block; width: 100%; height: 9.8rem; }
.sim-stats { display: grid; gap: 0.5rem; align-content: space-between; }
.sim-stats dt { display: flex; align-items: center; gap: 0.35rem; font-size: 0.72rem; color: color-mix(in srgb, var(--ink) 72%, var(--surface-raised)); }
.sim-st-ico { flex: none; width: 0.85rem; height: 0.85rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sim-stats dd { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 0.25rem; font-size: 1.15rem; font-weight: 680; font-variant-numeric: tabular-nums; line-height: 1.2; }
.sim-stats small { font-size: 0.72rem; font-weight: 500; }
.sim-meter { flex-basis: 100%; height: 4px; margin-top: 0.2rem; border-radius: 2px; background: color-mix(in srgb, var(--line) 60%, transparent); overflow: hidden; }
.sim-meter i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--rain); transition: width 0.3s var(--ease-out); }
.sim-trend { margin-left: auto; padding: 0.1rem 0.4rem; border-radius: 999px; font-size: 0.68rem; font-weight: 650; background: color-mix(in srgb, var(--ink) 8%, transparent); }
.sim-trend[data-dir="2"] { background: color-mix(in srgb, #e0782f 22%, var(--surface-raised)); }
.sim-trend[data-dir="2"]::before { content: '▲ '; font-size: 0.6rem; }
.sim-trend[data-dir="0"] { background: color-mix(in srgb, #3f9c78 20%, var(--surface-raised)); }
.sim-trend[data-dir="0"]::before { content: '▼ '; font-size: 0.6rem; }
.sim-spa {
  --spa: #3f9c78;
  display: flex; align-items: center; gap: 0.5rem;
  margin-top: 0.85rem; padding: 0.5rem 0.65rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--spa) 20%, var(--surface-raised));
  font-weight: 650;
}
.sim-spa[data-level="1"] { --spa: #d9a91e; }
.sim-spa[data-level="2"] { --spa: #e0782f; }
.sim-spa[data-level="3"] { --spa: #c8392f; }
.sim-spa[data-level="3"] .sim-dot { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--spa) 25%, transparent); } }
.sim-area { margin-left: auto; font-size: 0.75rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sim-dot { width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--spa); flex: none; }
.sim-chart { display: block; width: 100%; height: 92px; margin-top: 0.8rem; }
.sim-close { width: 100%; margin-top: 0.8rem; }
.sim-close:disabled { opacity: 0.55; cursor: default; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Storm: the sky behind the block turns grey, the stars go. */
body.storm { --surface: oklch(0.86 0.012 230); }
body.storm.night { --surface: oklch(0.16 0.02 250); }
body.storm .viewport::before, body.storm.night .viewport::before { opacity: 0; }

/* ============================================
   MAP
   ============================================ */
.viewport {
  position: fixed; inset: 0 0 auto;
  height: 100vh; height: 100lvh;   /* a phone's address bar sliding away does not resize the map */
  z-index: var(--z-scene);
}

/* A name pinned to a place on the map (the university in the Science chapter). */
.map-label {
  position: absolute; left: 0; top: 0;
  margin-top: -0.45rem; padding: 0.32rem 0.7rem;
  border-radius: 999px;
  background: var(--ink); color: var(--surface-raised);
  font-size: 0.84rem; font-weight: 650; white-space: nowrap;
  pointer-events: none; opacity: 0;
}
.map-legend {
  position: absolute; left: 0; top: 0;
  display: grid; gap: 0.3rem; padding: 0.5rem 0.75rem 0.55rem;
  border: 1px solid var(--line); border-radius: 10px;
  background: color-mix(in srgb, var(--surface-raised) 94%, transparent); color: var(--ink);
  font-size: 0.8rem; font-weight: 600; white-space: nowrap;
  pointer-events: none; opacity: 0;
}
.map-legend b { font-weight: 700; }
.ml-ramp { display: flex; align-items: center; gap: 0.45rem; font-variant-numeric: tabular-nums; }
.ml-ramp i { width: 6.5rem; height: 0.5rem; border-radius: 3px; background: linear-gradient(90deg, #c79a4f, #d9c77a, #86b58a, #3f8fb0, #23578f); }
.map-label::after {
  content: ''; position: absolute; left: 50%; top: 100%; translate: -50% 0;
  border: 5px solid transparent; border-top-color: var(--ink);
}

/* Stars and moon behind the map, shown at night. */
/* The moon hangs high in the sky, on the side the moonlight comes from. */
.viewport::before {
  --moon-x: 38%; --moon-y: 7%;
  content: '';
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 1.2s var(--ease-out);
  background-image:
    radial-gradient(circle at var(--moon-x) var(--moon-y), oklch(0.96 0.03 90) 0 20px, oklch(0.96 0.03 90 / 0.14) 21px, transparent 60px),
    radial-gradient(1.5px 1.5px at 7% 12%, #fff 50%, transparent 52%),
    radial-gradient(1px 1px at 18% 31%, #fff 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 29% 8%, #fff 50%, transparent 52%),
    radial-gradient(1px 1px at 41% 21%, #fff 50%, transparent 52%),
    radial-gradient(1px 1px at 55% 6%, #fff 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 63% 17%, #fff 50%, transparent 52%),
    radial-gradient(1px 1px at 72% 9%, #fff 50%, transparent 52%),
    radial-gradient(1px 1px at 93% 13%, #fff 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 96% 41%, #fff 50%, transparent 52%),
    radial-gradient(1px 1px at 4% 52%, #fff 50%, transparent 52%),
    radial-gradient(1px 1px at 11% 78%, #fff 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 24% 92%, #fff 50%, transparent 52%),
    radial-gradient(1px 1px at 47% 96%, #fff 50%, transparent 52%),
    radial-gradient(1px 1px at 78% 88%, #fff 50%, transparent 52%),
    radial-gradient(1.5px 1.5px at 91% 71%, #fff 50%, transparent 52%),
    radial-gradient(1px 1px at 88% 58%, #fff 50%, transparent 52%),
    radial-gradient(1px 1px at 35% 44%, #fff 50%, transparent 52%);
}
body.night .viewport::before { opacity: 0.85; }

#scene {
  position: relative;
  display: block;
  width: 100%; height: 100%;
  touch-action: pan-y;   /* a vertical swipe scrolls the story, a sideways drag turns the map */
  cursor: grab;
  opacity: 0;
  transition: opacity 1s var(--ease-out);
}
#scene.ready { opacity: 1; }
/* While the map is being built: a thin running bar where it will appear. */
.map-loading {
  position: absolute; left: 50%; top: 52%; translate: -50% -50%;
  width: 7rem; height: 3px; border-radius: 3px; overflow: hidden;
  background: color-mix(in srgb, var(--ink) 12%, transparent);
  transition: opacity 0.4s var(--ease-out);
}
.map-loading::after {
  content: ''; position: absolute; inset: 0; width: 40%; border-radius: inherit;
  background: var(--signal-ink);
  animation: loading 1.1s var(--ease-out) infinite;
}
@keyframes loading { from { translate: -100% 0; } to { translate: 250% 0; } }
.map-ready .map-loading { opacity: 0; visibility: hidden; }
#scene.dragging { cursor: grabbing; }

/* Free roam: the story steps aside; a bar says how to move the map and how to get back. */
body.free .story, body.free .story-rail { display: none; }
body.free #scene { touch-action: none; }
.free-bar {
  position: fixed; left: var(--gutter); bottom: clamp(1.5rem, 5vh, 3rem);
  z-index: var(--z-panel);
  display: none; align-items: center; gap: 0.9rem;
  max-width: calc(100vw - 2 * var(--gutter));
  padding: 0.4rem 0.4rem 0.4rem 1.1rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: color-mix(in srgb, var(--surface-raised) 94%, transparent); color: var(--ink);
}
body.free .free-bar { display: flex; }
.free-hint { font-size: 0.84rem; font-weight: 560; line-height: 1.35; }
.free-exit { flex: none; }
@media (max-width: 560px) {
  .free-bar {
    left: var(--gutter); right: var(--gutter);
    bottom: calc(var(--gutter) + env(safe-area-inset-bottom) + 3.4rem);
    flex-direction: column; align-items: stretch; gap: 0.55rem;
    padding: 0.7rem; border-radius: 14px; text-align: center;
  }
}

.noscript { position: relative; z-index: var(--z-story); padding: 2rem var(--gutter); text-align: center; }

/* ============================================
   STORY
   Sections scroll over the fixed map; each card sits clear of the place
   the camera shows (to its right on wide screens, below it on narrow ones).
   ============================================ */
.story { position: relative; z-index: var(--z-story); pointer-events: none; }
.story[hidden], .story-rail[hidden] { display: none; }   /* one story at a time (the study sits in the forest) */
.story-step {
  min-height: 100svh;
  display: flex; align-items: center; justify-content: flex-end;
  padding: 7rem calc(var(--gutter) + 3rem) 4rem var(--gutter);
}
.story-card {
  pointer-events: auto;
  width: min(26rem, 100%);
  padding: 1.35rem 1.5rem 1.4rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-raised) 94%, transparent);
  box-shadow: 0 2px 8px oklch(0.2 0.02 200 / 0.08);
}
.story-tag { font-size: 0.85rem; font-weight: 600; color: var(--signal-ink); letter-spacing: 0.01em; }
.story-card h2 {
  margin-top: 0.3rem;
  font-size: clamp(2rem, 3.6vw, 2.9rem); font-weight: 780; line-height: 1;
  letter-spacing: -0.025em; font-variation-settings: 'opsz' 96;
  text-wrap: balance;
}
.story-text { margin-top: 0.85rem; font-size: 1rem; font-weight: 500; line-height: 1.55; text-wrap: pretty; }
.story-note {
  margin-top: 1rem; padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  font-size: 0.84rem; font-weight: 500; line-height: 1.45;
  color: color-mix(in srgb, var(--ink) 78%, var(--surface));
}

/* Opening: the motto over the map, no card. */
.story-hero { justify-content: flex-start; align-items: flex-end; padding-bottom: clamp(3rem, 9vh, 6rem); }
.story-hero-text { pointer-events: auto; max-width: 28rem; }
/* The motto stays on screen under the name through the whole story, like the name itself. */
.story-hero-head {
  position: fixed; left: var(--gutter);
  top: calc(var(--gutter) + clamp(2.8rem, 6.6vw, 6rem) * 0.95 + 1.1rem);
  max-width: min(36rem, 100vw - 34rem);
  pointer-events: auto;
}
.story-hero-head .story-tag { font-size: clamp(0.9rem, 1.1vw, 1.05rem); }
.story-motto {
  margin-top: 0.5rem;
  font-size: clamp(2rem, 3.7vw, 3.4rem); font-weight: 760; line-height: 1.02;
  letter-spacing: -0.018em; font-variation-settings: 'opsz' 96;
  text-wrap: balance;
}
.story-cue {
  display: inline-flex; align-items: center; gap: 0.4rem;
  margin-top: 1.3rem; padding: 0.5rem 0.95rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-raised); color: var(--ink);
  font-size: 0.9rem; font-weight: 600; text-decoration: none;
}
/* On wide screens the cue stays on screen under the motto's corner and always goes one on. */
@media (min-width: 761px) {
  #s-0 .story-cue { position: fixed; left: var(--gutter); bottom: clamp(3rem, 9vh, 6rem); margin: 0; z-index: 1; }
}
.story-cue svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; animation: cue 2.4s var(--ease-out) infinite; }
@media (pointer: coarse) { .story-cue svg { rotate: 180deg; } }
@keyframes cue { 0%, 60%, 100% { translate: 0 0; } 30% { translate: 0 3px; } }

/* Contact */
.story-mail {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.2rem 0.8rem;
  margin-top: 1.1rem; padding: 0.8rem 1rem;
  border-radius: 10px;
  background: var(--ink); color: var(--surface-raised);
  font-weight: 600; text-decoration: none;
}
.story-mail b { font-weight: 750; }
.story-mail:hover { background: color-mix(in srgb, var(--ink) 88%, var(--signal-ink)); }
.story-social { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.8rem; list-style: none; }
.story-social a, .story-research {
  display: inline-block; padding: 0.35rem 0.75rem;
  border: 1px solid var(--line); border-radius: 999px;
  color: var(--ink); font-size: 0.84rem; font-weight: 600; text-decoration: none;
}
.story-social a:hover, .story-research:hover { border-color: var(--ink); }
.story-research { margin-top: 0.8rem; }

/* Progress rail on the right edge. */
.story-rail {
  position: fixed; right: calc(var(--gutter) * 0.5); top: 50%; translate: 0 -50%;
  z-index: var(--z-story);
  display: flex; flex-direction: column; gap: 0.1rem;
  padding: 0.3rem 0.15rem;
  border: 1px solid var(--line); border-radius: 999px;
  background: color-mix(in srgb, var(--surface-raised) 90%, transparent);
}
.story-rail a {
  position: relative; display: grid; place-items: center;
  width: 1.6rem; height: 1.6rem;
  border-radius: 50%;
}
.story-rail a::before {
  content: ''; width: 0.45rem; height: 0.45rem; border-radius: 50%;
  background: var(--ink); opacity: 0.3;
  transition: opacity 0.3s var(--ease-out), scale 0.3s var(--ease-out);
}
.story-rail a[aria-current]::before { opacity: 1; scale: 1.5; }
.story-rail a:hover::before { opacity: 0.8; }
.story-rail span {
  position: absolute; right: 100%; margin-right: 0.3rem;
  padding: 0.15rem 0.5rem; border-radius: 6px;
  background: var(--surface-raised); color: var(--ink);
  font-size: 0.78rem; font-weight: 600; white-space: nowrap;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s var(--ease-out);
}
.story-rail a:hover span, .story-rail a:focus-visible span { opacity: 1; }

/* Narrow screens: contact moves to the bottom edge, thumb-reachable. */
@media (max-width: 760px) {
  .story-step { align-items: flex-end; justify-content: center; padding: 5rem var(--gutter) calc(var(--gutter) + 4.6rem + env(safe-area-inset-bottom)); }
  .story-card { width: 100%; max-width: 30rem; padding: 1.05rem 1.1rem 1.1rem; }
  .story-text { font-size: 0.95rem; line-height: 1.5; }
  .story-hero { justify-content: flex-start; }
  .story-rail { right: 0.3rem; top: 36%; padding: 0.2rem 0.05rem; }
  .story-rail a { width: 1.3rem; height: 1.3rem; }
  .story-rail span { display: none; }
}

@media (max-width: 560px) {
  .viewport::before { --moon-x: 72%; --moon-y: 6%; }
  .topnav {
    position: fixed;
    left: var(--gutter); right: var(--gutter);
    bottom: calc(var(--gutter) + env(safe-area-inset-bottom));
    justify-content: center;
  }
  .sim-menu { top: auto; bottom: calc(100% + 0.5rem); right: auto; left: 50%; translate: -50% 0; width: min(19rem, calc(100vw - 2 * var(--gutter))); transform-origin: bottom center; }
  .sim-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .sim-btn { padding: 0.45rem; }
  .sim-panel { top: calc(var(--gutter) + 2.6rem); bottom: auto; padding: 0.7rem 0.8rem 0.8rem; }
  .sim-badge { display: none; }
  .sim-phase { min-height: 0; margin: 0.35rem 0 0.6rem; }
  .sim-body { grid-template-columns: 3.4rem 1fr; }
  .sim-gauge { height: 6.2rem; }
  .sim-stats { grid-template-columns: 1fr 1fr; gap: 0.4rem 0.8rem; align-content: start; }
  .sim-stats dd { font-size: 1rem; }
  .sim-spa { margin-top: 0.6rem; padding: 0.4rem 0.6rem; }
  .sim-chart { height: 56px; margin-top: 0.6rem; }
  .sim-close { margin-top: 0.6rem; padding: 0.5rem; }
}

/* ============================================
   STUDY PAGE (/research/)
   The same map and cards; the cards carry charts. Two sections are taller
   than the screen: their card stays pinned while scrolling steps through
   decades or soil states, then the story moves on.
   ============================================ */
:root { --c-f: oklch(0.68 0.14 78); --c-h: oklch(0.52 0.12 245); --c-s: oklch(0.55 0.16 32); --soil: #4b3323; --iso: #fff7e6; }
body.night { --c-f: oklch(0.82 0.13 82); --c-h: oklch(0.76 0.1 245); --c-s: oklch(0.74 0.13 35); }

.name a { color: inherit; text-decoration: none; pointer-events: auto; }
.name a:hover { color: var(--signal-ink); }

/* The study opens over the forest, which is too busy to read on, so its title sits on a card. */
.rs-hero .story-hero-text {
  max-width: 38rem; padding: 1.5rem 1.7rem 1.6rem;
  border: 1px solid var(--line); border-radius: 14px;
  background: color-mix(in srgb, var(--surface-raised) 94%, transparent);
  box-shadow: 0 2px 8px oklch(0.2 0.02 200 / 0.08);
}
@media (max-width: 760px) {
  .rs-hero .story-hero-text { width: 100%; padding: 1.05rem 1.1rem 1.1rem; }
  .story-hero-head { right: var(--gutter); max-width: none; top: calc(var(--gutter) + clamp(2.8rem, 6.6vw, 6rem) * 0.95 + 0.7rem); }
  .story-motto { font-size: clamp(1.45rem, 6.4vw, 2rem); }
  /* on a phone the motto would cover a fifth of the map in every chapter: it stays with the opening */
  .story-hero-head { transition: opacity 0.4s var(--ease-out), visibility 0.4s; }
  .past-hero .story-hero-head { opacity: 0; visibility: hidden; }
}
.rs-title {
  margin-top: 0.45rem;
  font-size: clamp(2.4rem, 5.4vw, 4.6rem); font-weight: 780; line-height: 0.98;
  letter-spacing: -0.025em; font-variation-settings: 'opsz' 96;
  text-wrap: balance;
}
.rs-lead { margin-top: 0.9rem; max-width: 33rem; font-size: clamp(1.02rem, 1.4vw, 1.2rem); font-weight: 580; line-height: 1.45; text-wrap: pretty; }
.rs-meta { margin-top: 0.6rem; font-size: 0.86rem; font-weight: 620; }

.rs-card { width: min(30rem, 100%); }
.story-step.story-scrub { display: block; min-height: 330svh; padding: 0; }
.story-pin {
  position: sticky; top: 0;
  min-height: 100svh;
  display: flex; align-items: center; justify-content: flex-end;
  padding: 5.5rem calc(var(--gutter) + 3rem) 1.5rem var(--gutter);
}
.story-pin .story-card { max-height: calc(100svh - 7rem); overflow-y: auto; }
@media (min-width: 761px) and (max-height: 980px) { .story-pin .story-note { display: none; } }

/* Read-outs that follow the scroll */
.rs-read {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0.2rem 0.8rem;
  margin-top: 0.9rem; padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}
.rs-read-k { font-size: 0.9rem; font-weight: 680; font-variant-numeric: tabular-nums; }
.rs-read b { font-size: clamp(1.8rem, 3vw, 2.4rem); font-weight: 780; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.rs-read-sub { margin-top: 0.3rem; font-size: 0.8rem; font-weight: 560; line-height: 1.45; color: color-mix(in srgb, var(--ink) 80%, var(--surface)); }

/* Charts */
.rs-chart { position: relative; margin-top: 0.55rem; }
.rs-chart svg { display: block; width: 100%; height: auto; overflow: visible; touch-action: pan-y; }
.rs-chart .grid { stroke: var(--line); stroke-width: 1; }
.rs-chart .ax { font: 600 9.5px var(--font-display); fill: color-mix(in srgb, var(--ink) 74%, var(--surface)); }
.rs-chart .ax-t, .rs-chart .ax-b { font: 650 9.5px var(--font-display); fill: var(--ink); }
.rs-chart .ax-b { font-weight: 760; }
.pt-f, .bar-f, .dot-f, .sp-1 { fill: var(--c-f); background: var(--c-f); }
.pt-h, .bar-h, .dot-h { fill: var(--c-h); background: var(--c-h); }
.pt-s, .bar-s, .dot-s { fill: var(--c-s); background: var(--c-s); }
.rs-scatter .pt { fill-opacity: 0.75; }
.rs-scatter .pt-dg { fill: none; stroke: var(--c-h); stroke-width: 1; }
.pt-ring { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.trend { stroke-width: 2.2; stroke-linecap: round; }
.tr-f { stroke: color-mix(in srgb, var(--c-f) 70%, var(--ink)); }
.tr-h { stroke: color-mix(in srgb, var(--c-h) 80%, var(--ink)); }
.tr-s { stroke: color-mix(in srgb, var(--c-s) 80%, var(--ink)); }
.ln { fill: none; stroke-width: 2; stroke-linejoin: round; }
.ln-f { stroke: var(--c-f); } .ln-h { stroke: var(--c-h); } .ln-s { stroke: var(--c-s); }
.rs-chart [class*="end-"] { fill: var(--ink); font-weight: 750; }
.bar-old { opacity: 0.4; }
.dec .bar { opacity: 0.28; transition: opacity 0.35s var(--ease-out); }
.dec.on .bar { opacity: 1; }
.laden { stroke: var(--ink); stroke-width: 2.2; }
.rs-tip {
  position: absolute; z-index: 1; translate: -50% calc(-100% - 9px);
  padding: 0.3rem 0.55rem; border-radius: 6px;
  background: var(--ink); color: var(--surface-raised);
  font-size: 0.76rem; font-weight: 620; white-space: nowrap;
  pointer-events: none;
}
.rs-cap { margin-top: 0.95rem; font-size: 0.8rem; font-weight: 680; }
.rs-hint { margin-top: 0.45rem; font-size: 0.76rem; font-weight: 530; line-height: 1.4; color: color-mix(in srgb, var(--ink) 76%, var(--surface)); }

/* Legends */
.rs-key { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; margin-top: 0.75rem; list-style: none; font-size: 0.8rem; font-weight: 620; }
.rs-key li { display: flex; align-items: center; gap: 0.35rem; }
.dot { width: 0.62rem; height: 0.62rem; border-radius: 50%; }
.rs-slope { font-size: 0.76rem; font-weight: 560; font-variant-numeric: tabular-nums; color: color-mix(in srgb, var(--ink) 76%, var(--surface)); }
.rs-legend { display: grid; gap: 0.3rem; margin-top: 0.75rem; list-style: none; font-size: 0.8rem; font-weight: 560; }
.rs-legend li { display: flex; align-items: center; gap: 0.55rem; }
.sw { flex: none; position: relative; width: 1.6rem; height: 0.8rem; border-radius: 3px; background: var(--soil); }
.sw-fill { background: linear-gradient(90deg, oklch(0.74 0.15 55), oklch(0.5 0.17 30)); }
.sw-iso::after { content: ''; position: absolute; left: 0.15rem; right: 0.15rem; top: calc(50% - 1px); border-top: 2px solid var(--iso); }
.sw-ruler { background: var(--soil) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 26 13'%3E%3Cpath d='M4 1v11M4 2h4M4 4.5h2.5M4 7h4M4 9.5h2.5M4 12h4' stroke='%23fff7e6' stroke-width='1.2' fill='none'/%3E%3C/svg%3E") center / cover; }

/* Decade and state buttons */
.rs-decs { display: grid; grid-template-columns: repeat(7, 1fr); margin: 0.2rem 1.25% 0 7.5%; }
.rs-decs button, .rs-states button {
  padding: 0.3rem 0;
  border: 1px solid transparent; border-radius: 6px;
  background: none; color: var(--ink);
  font: inherit; font-size: 0.74rem; font-weight: 660; font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.rs-decs button:hover { border-color: var(--line); }
.rs-states { display: flex; gap: 0.35rem; margin-top: 0.7rem; }
.rs-states button { flex: 1; padding: 0.42rem 0.5rem; border-color: var(--line); border-radius: 999px; font-size: 0.8rem; }
.rs-states button:hover { border-color: var(--ink); }
.rs-decs button[aria-pressed="true"], .rs-states button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface-raised); }

/* Composition of the weight gain */
.rs-split { display: flex; gap: 2px; height: 0.9rem; margin-top: 0.45rem; border-radius: 4px; overflow: hidden; }
.rs-split .sp-1 { flex: 87; } .rs-split .sp-2 { flex: 8; } .rs-split .sp-3 { flex: 6; }
.sp-2 { background: color-mix(in srgb, var(--c-f) 45%, var(--ink)); }
.sp-3 { background: color-mix(in srgb, var(--ink) 35%, var(--surface)); }
.rs-split-key { display: grid; gap: 0.2rem; margin-top: 0.45rem; list-style: none; font-size: 0.8rem; font-weight: 560; }
.rs-split-key li { display: flex; align-items: center; gap: 0.45rem; }
.rs-split-key .sp { flex: none; width: 0.7rem; height: 0.7rem; border-radius: 2px; }
.rs-split-key b { margin-left: auto; font-weight: 750; font-variant-numeric: tabular-nums; }

/* Data tables (also what crawlers and screen readers get) */
.rs-table { margin-top: 0.75rem; font-size: 0.8rem; }
.rs-table summary { cursor: pointer; font-weight: 660; }
.rs-table table { width: 100%; margin-top: 0.5rem; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rs-table th, .rs-table td { padding: 0.22rem 0.3rem; border-bottom: 1px solid var(--line); text-align: right; font-weight: 560; }
.rs-table th:first-child { text-align: left; }
.rs-table thead th { font-weight: 700; vertical-align: bottom; }

.rs-recs { display: grid; gap: 0.35rem; margin: 0.85rem 0 0 1.15rem; font-size: 0.92rem; font-weight: 580; line-height: 1.45; }
.rs-recs li::marker { font-weight: 760; color: var(--signal-ink); }

@media (max-width: 760px) {
  .story-pin { align-items: flex-end; justify-content: center; padding: 5rem var(--gutter) calc(var(--gutter) + 4.6rem + env(safe-area-inset-bottom)); }
  /* the scene has to stay visible above a pinned card: keep it to half the screen, with
     the live read-out and controls first and the longer text further down inside it */
  .story-pin .story-card { display: flex; flex-direction: column; max-height: 52svh; overscroll-behavior: contain; }
  .story-pin .story-card > .story-text { order: 2; margin-top: 0.8rem; }
  .story-pin .story-card > .rs-table { order: 3; }
  .rs-card :is(.story-note, .rs-hint) { display: none; }
  .rs-card .story-text { font-size: 0.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .dec .bar { transition: none; }
  .story-cue svg, .map-loading::after { animation: none; }
  #scene, body, .viewport::before { transition: none; }
  .sim-menu, .sim-panel, .sim-btn.running .drops, .sim-spa .sim-dot { animation: none !important; }
  .sim-meter i { transition: none; }
  .sim-caret, .sim-item-go { transition: none; }
}
