@import url('https://fonts.googleapis.com/css2?family=Spectral:ital,wght@0,400;0,500;0,600;0,700;1,400&family=Archivo:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* light-first, same background family as the Thailand piece */
  --bg: #F1F4EC;
  --surface: #FFFFFF;
  --surface-2: #E7ECE0;
  --ink: #1E1811;
  --ink-2: #4A3F2E;
  --muted: #6B7A63;
  --border: #D7DECD;
  --accent: #0A9484;
  --accent-strong: #075E54;
  --shift: #E08928;
  --agri: #C1442A;
  --other: #1D5FA0;
  --src: #D2691E;
  --sink: #0A9484;
  --map-lo: #E4EDEA;
  --map-hi: #075E54;
  --tooltip-accent: #5FE0C8;
  --font-display: 'Spectral', Georgia, 'Times New Roman', serif;
  --font-body: 'Archivo', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15100B;
    --surface: #1E1811;
    --surface-2: #281F15;
    --ink: #F1EAD9;
    --ink-2: #C7B79E;
    --muted: #8C7A62;
    --border: #332920;
    --accent: #22A18E;
    --accent-strong: #5FE0C8;
    --shift: #BC8A35;
    --agri: #B23A26;
    --other: #3B7FC4;
    --src: #CB7635;
    --sink: #22A18E;
    --map-lo: #1B2B28;
    --map-hi: #5FE0C8;
    --tooltip-accent: #075E54;
  }
}

:root[data-theme="dark"] {
  --bg: #15100B;
  --surface: #1E1811;
  --surface-2: #281F15;
  --ink: #F1EAD9;
  --ink-2: #C7B79E;
  --muted: #8C7A62;
  --border: #332920;
  --accent: #22A18E;
  --accent-strong: #5FE0C8;
  --shift: #BC8A35;
  --agri: #B23A26;
  --other: #3B7FC4;
  --src: #CB7635;
  --sink: #22A18E;
  --map-lo: #1B2B28;
  --map-hi: #5FE0C8;
  --tooltip-accent: #075E54;
}

* { box-sizing: border-box; }
html { scroll-behavior: auto; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: var(--bg); }

.frame-rail {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  pointer-events: none;
}
.frame-rail__label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  color: var(--muted);
  white-space: nowrap;
}
@media (max-width: 720px) { .frame-rail { display: none; } }

main { margin-left: 34px; }
@media (max-width: 720px) { main { margin-left: 0; } }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 32px; }
@media (max-width: 720px) { .wrap { padding: 0 20px; } }

/* ---------- Hero ---------- */
.hero {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  background: var(--bg);
}
.hero canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.5; }
.hero__inner { position: relative; z-index: 2; padding: 120px 32px 90px; max-width: 900px; }
.kicker {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-strong);
  margin: 0 0 22px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.kicker::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: inline-block; }
h1.title {
  font-family: var(--font-display);
  font-weight: 600;
  font-style: italic;
  font-size: clamp(2.6rem, 6.2vw, 5.4rem);
  line-height: 1.0;
  letter-spacing: -0.005em;
  margin: 0 0 28px;
  text-wrap: balance;
  color: var(--ink);
}
h1.title em { font-style: normal; font-weight: 700; color: var(--accent-strong); }
.hero__dek { font-size: clamp(1.05rem, 1.6vw, 1.25rem); line-height: 1.65; color: var(--ink-2); max-width: 46em; margin: 0 0 44px; }
.hero__stat { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.hero__stat-num {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}
.hero__stat-label { font-size: 0.95rem; color: var(--muted); max-width: 22em; line-height: 1.45; }
.scroll-cue { position: absolute; bottom: 34px; left: 32px; z-index: 2; font-family: var(--font-mono); font-size: 11px; color: var(--muted); letter-spacing: 0.1em; display: flex; align-items: center; gap: 8px; }
.scroll-cue__bar { width: 1px; height: 26px; background: linear-gradient(var(--accent), transparent); animation: scrollpulse 1.8s ease-in-out infinite; }
@keyframes scrollpulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

/* ---------- Prose ---------- */
section.intro { padding: 96px 0 40px; }
.lede {
  font-family: var(--font-display);
  font-weight: 400;
  font-style: italic;
  font-size: clamp(1.3rem, 2.4vw, 1.7rem);
  line-height: 1.55;
  color: var(--ink);
  max-width: 34em;
  text-wrap: balance;
}
.prose { font-size: 1.05rem; line-height: 1.75; color: var(--ink-2); max-width: 40em; }
.prose + .prose { margin-top: 1.1em; }
.source-note { margin-top: 28px; font-family: var(--font-mono); font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 18px; }

.chapter {
  padding: 84px 0;
  border-top: 1px solid var(--border);
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.7s ease, transform 0.7s ease;
}
.chapter.is-visible { opacity: 1; transform: translateY(0); }
.chapter.map-chapter { transform: none; padding: 84px 0 0; }
.chapter.map-chapter.is-visible { transform: none; }

.chapter__head { display: grid; grid-template-columns: 90px 1fr; gap: 24px; margin-bottom: 36px; align-items: start; }
.chapter__num { font-family: var(--font-mono); font-size: 13px; color: var(--muted); padding-top: 10px; }
h2.chapter__title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.9rem, 3.4vw, 2.7rem);
  line-height: 1.1;
  margin: 0;
  text-wrap: balance;
  color: var(--ink);
}
.chapter__body { display: grid; grid-template-columns: 90px 1fr; gap: 24px; }
.chapter__body > * { min-width: 0; }
.chapter__text { max-width: 38em; }
.chapter__text p { font-size: 1.02rem; line-height: 1.75; color: var(--ink-2); margin: 0 0 1.1em; }
.chapter__text strong { color: var(--ink); font-weight: 600; }
.chapter__chart { margin-top: 40px; grid-column: 2; }
@media (max-width: 720px) {
  .chapter__head, .chapter__body { grid-template-columns: 1fr; gap: 10px; }
  .chapter__chart { grid-column: 1; }
}

.annotation { font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); margin-top: 14px; line-height: 1.5; }

/* ---------- Charts ---------- */
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 28px 26px 22px; }
svg text { font-family: var(--font-mono); fill: var(--muted); }
.axis-line { stroke: var(--border); stroke-width: 1; }
.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 7px 10px;
  border-radius: 3px;
  line-height: 1.5;
  transform: translate(-50%, -110%);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
  z-index: 200;
}
.tooltip.show { opacity: 1; visibility: visible; }
.tooltip b { font-weight: 600; color: var(--tooltip-accent); }

.legend { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 18px; font-size: 12.5px; color: var(--ink-2); }
.legend__item { display: flex; align-items: center; gap: 7px; }
.legend__swatch { width: 10px; height: 10px; border-radius: 2px; flex: none; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); margin-top: 24px; }
.stat-tile { background: var(--surface); padding: 20px 18px; }
.stat-tile__label { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.stat-tile__val { font-family: var(--font-mono); font-size: 1.5rem; font-variant-numeric: tabular-nums; color: var(--ink); }
.stat-tile__val.src { color: var(--src); }
.stat-tile__val.sink { color: var(--sink); }

/* ---------- Scrollama map ---------- */
.scrolly-map { display: flex; align-items: flex-start; gap: 5vw; padding: 0 32px; }
@media (max-width: 720px) { .scrolly-map { padding: 0 20px; } }
.scrolly-map__text { flex: 1 1 40%; min-width: 0; }
.scrolly-map__graphic { flex: 1 1 58%; min-width: 0; position: sticky; top: 0; height: 100vh; display: flex; align-items: center; }
.map-card { width: 100%; height: 76vh; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 20px; position: relative; overflow: hidden; }
#mapSvg { width: 100%; height: 100%; display: block; }
.state {
  fill: var(--map-lo);
  stroke: var(--bg);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
  transition: fill 0.6s ease, opacity 0.5s ease, stroke-width 0.3s ease;
}
.state.is-dimmed { opacity: 0.32; }
.state.is-focus { stroke: var(--ink); stroke-width: 1.4; }
.state-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  fill: var(--ink);
  paint-order: stroke;
  stroke: var(--surface);
  stroke-width: 3px;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}
.state-label.is-visible { opacity: 1; }
.map-legend { position: absolute; right: 22px; bottom: 20px; display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 10.5px; color: var(--muted); background: var(--surface); padding: 4px 6px; }
.map-legend__ramp { width: 90px; height: 8px; border-radius: 2px; background: linear-gradient(to right, var(--map-lo), var(--map-hi)); }
.map-caption { position: absolute; left: 22px; top: 18px; font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

.map-step { min-height: 82vh; display: flex; flex-direction: column; justify-content: center; padding: 60px 0; opacity: 0.3; transition: opacity 0.4s ease; }
.map-step:first-child { padding-top: 0; }
.map-step:last-child { padding-bottom: 100px; }
.map-step.is-active { opacity: 1; }
.map-step__eyebrow { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent-strong); margin: 0 0 12px; }
.map-step__title { font-family: var(--font-display); font-weight: 600; font-size: clamp(1.4rem, 2.4vw, 1.9rem); line-height: 1.18; margin: 0 0 16px; text-wrap: balance; color: var(--ink); }
.map-step p { font-size: 1.02rem; line-height: 1.75; color: var(--ink-2); margin: 0 0 1em; }
.map-step p strong { color: var(--ink); font-weight: 600; }
.map-step__list { list-style: none; margin: 14px 0 0; padding: 0; font-family: var(--font-mono); font-size: 12.5px; }
.map-step__list li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-top: 1px solid var(--border); color: var(--ink-2); }
.map-step__list li b { color: var(--ink); font-weight: 500; }

@media (max-width: 860px) {
  .scrolly-map { flex-direction: column; }
  .scrolly-map__graphic { flex: none; position: static; height: 60vh; margin-bottom: 24px; }
  .map-card { height: 100%; }
  .map-step { min-height: 0; padding: 24px 0; opacity: 1; }
}

/* ---------- Close ---------- */
.close { padding: 100px 0 60px; border-top: 1px solid var(--border); }
.close__take {
  font-family: var(--font-display);
  font-weight: 500;
  font-style: italic;
  font-size: clamp(1.5rem, 2.8vw, 2rem);
  line-height: 1.42;
  max-width: 30em;
  text-wrap: balance;
  color: var(--ink);
  margin: 0 0 40px;
}
.close__take em { color: var(--accent); font-style: normal; font-weight: 700; }

footer.colophon { border-top: 1px solid var(--border); padding: 34px 0 60px; font-family: var(--font-mono); font-size: 11.5px; line-height: 1.9; color: var(--muted); }
footer.colophon a { color: var(--accent-strong); }

@media (prefers-reduced-motion: reduce) {
  .chapter { transition: none; opacity: 1; transform: none; }
  .scroll-cue__bar { animation: none; }
  html { scroll-behavior: auto; }
}
