/* Where the rain goes: a field-guide study of runoff in the Cagayan de Oro river basin.
   One page, two faces (Spectral for reading, Barlow for controls), flat colour, no outlines. */

:root {
  --ground: #1c3830;
  --ground-2: #2a4a41;
  --paper: #e8ece2;
  --paper-2: #d8dfd0;
  --ink: #15211c;
  --muted: #3f4f47;
  --on-ground: #e8ece2;
  --on-ground-muted: #b9c9bd;
  --water: #255f87;
  --water-light: #9ccbe6;
  --water-pale: #bcd2dc;
  --silt: #8a4e24;
  --silt-light: #e0a870;

  --c-forest: #3a6b45;
  --c-grass: #8fa85a;
  --c-crops: #c09a45;
  --c-town: #7b7f83;

  --serif: 'Spectral', Georgia, 'Times New Roman', serif;
  --sans: 'Barlow', 'Helvetica Neue', Arial, sans-serif;

  --step-small: 0.9rem;
  --step-body: 1.125rem;
  --step-lead: 1.4rem;
  --step-head: clamp(2.25rem, 4.4vw, 3.75rem);
  --step-title: clamp(3.5rem, 9vw, 8.5rem);

  --m: clamp(16px, 4vw, 56px);
  --gap-section: clamp(72px, 10vw, 160px);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: var(--step-body);
  line-height: 1.55;
  overflow-x: hidden;
}
img, svg { display: block; max-width: 100%; }
p { margin: 0 0 1em; }
h1, h2 { font-family: var(--serif); font-weight: 300; margin: 0; letter-spacing: -0.02em; line-height: 1.02; }
h2 { font-size: var(--step-head); }
a { color: inherit; text-underline-offset: 0.18em; }
strong { font-weight: 500; }
small { font-size: 0.5em; font-family: var(--sans); font-weight: 500; letter-spacing: 0; }

:focus-visible { outline: 3px solid var(--water); outline-offset: 3px; }
.cover :focus-visible, .method :focus-visible, .back :focus-visible { outline-color: var(--water-light); }

.skip {
  position: absolute; left: var(--m); top: -80px; z-index: 20;
  background: var(--paper); color: var(--ink); padding: 12px 18px; font-family: var(--sans); font-weight: 600;
}
.skip:focus { top: 12px; }

.button {
  display: inline-block;
  font-family: var(--sans); font-weight: 600; font-size: 1.05rem;
  background: var(--water-light); color: var(--ground);
  padding: 14px 28px; min-height: 48px;
  text-decoration: none;
  transition: transform 0.15s ease, background-color 0.15s ease;
}
.button:hover { background: #b6d9ee; transform: translateY(-2px); }
.button:active { transform: translateY(0); }

/* ---------- Cover ---------- */
.cover {
  background: var(--ground);
  color: var(--on-ground);
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
}
.cover-left { display: flex; flex-direction: column; min-width: 0; }
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 18px var(--m);
  font-family: var(--sans); font-size: 1rem; font-weight: 500;
}
.bar nav { display: flex; gap: clamp(14px, 2.4vw, 32px); flex-wrap: wrap; justify-content: flex-end; }
.bar a { text-decoration: none; padding: 12px 0; }
.bar a:hover { text-decoration: underline; }
.wordmark { font-weight: 600; }

.cover-text {
  flex: 1;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  padding: clamp(32px, 5vw, 72px) var(--m) clamp(40px, 6vw, 80px);
}
.cover h1 { font-size: var(--step-title); max-width: 10ch; margin-bottom: 0.3em; }
.statement { font-size: var(--step-lead); line-height: 1.35; max-width: 30ch; color: var(--on-ground); }
.tag {
  background: var(--ground-2); color: var(--on-ground);
  font-family: var(--sans); font-size: 1rem; line-height: 1.45;
  padding: 14px 18px; max-width: 46ch; margin: 28px 0 32px;
}
.cover-photo { margin: 0; position: relative; overflow: hidden; min-height: 320px; }
.cover-photo img {
  width: 100%; height: 100%; object-fit: cover; object-position: 60% 40%;
  animation: drift 40s ease-in-out infinite alternate;
}
.cover-photo figcaption {
  position: absolute; left: 0; bottom: 0;
  background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: var(--step-small); padding: 10px 16px;
}
@keyframes drift { from { transform: scale(1.02); } to { transform: scale(1.1) translate(-1.5%, 1%); } }

/* ---------- Study ---------- */
.study { padding: var(--gap-section) var(--m); }
.study-head { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 48px; align-items: end; margin-bottom: clamp(32px, 5vw, 64px); }
.study-head p { margin: 0; max-width: 34ch; }
.nojs { background: var(--paper-2); padding: 16px 20px; }

.study-grid { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: clamp(24px, 4vw, 56px); align-items: start; }
.left { position: sticky; top: 16px; }
.plate-wrap { background: var(--paper-2); padding: 12px; }
.plate { margin: 0; }
#plate { width: 100%; height: auto; aspect-ratio: 800 / 480; }
#plate .sky { fill: #d3dfe2; }
#plate .far-range { fill: #b4c6cb; }
#plate .cloud ellipse { fill: var(--cloud, #a3b4ba); }
#plate .earth { fill: #54463a; }
#plate .sea { fill: #4f85a3; }
#plate .plume { fill: var(--silt); }
.plate-note { font-size: var(--step-body); line-height: 1.4; margin: 14px 4px 10px; min-height: 2.8em; }
.plate-note strong { font-weight: 500; }
.split { display: flex; height: 14px; margin: 0 4px 4px; background: var(--water-pale); }
.split span { display: block; height: 100%; transition: width 0.25s ease; }
#split-kept { background: var(--water); }
#split-run { background: var(--silt); }

.figures { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; margin-top: 24px; }
.fig { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fig-num { order: 1; }
.fig-label { order: 2; font-family: var(--sans); font-weight: 600; font-size: 1rem; }
.fig-sub { order: 3; }
.fig-num { font-size: var(--step-head); font-weight: 300; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.fig-num.silt { color: var(--silt); }
.fig-num.water { color: var(--water); }
.fig-sub { font-family: var(--sans); font-size: var(--step-small); color: var(--muted); line-height: 1.35; }

.controls { background: var(--paper-2); padding: clamp(20px, 3vw, 32px); display: grid; gap: 32px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { font-family: var(--serif); font-weight: 500; font-size: var(--step-lead); padding: 0; margin-bottom: 10px; }
.slider-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-family: var(--sans); font-weight: 500; }
.slider-row output { font-weight: 600; font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; height: 36px; margin: 2px 0 6px; accent-color: var(--water); cursor: pointer; }
.hint { font-family: var(--sans); font-size: var(--step-small); color: var(--muted); line-height: 1.4; margin: 6px 0 12px; }

.presets { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.presets button, .seg label span {
  font: inherit; font-family: var(--sans); font-weight: 500; font-size: 1rem;
  background: var(--paper); color: var(--ink);
  border: 0; border-radius: 0; cursor: pointer;
  padding: 10px 14px; min-height: 44px;
  display: inline-flex; flex-direction: column; justify-content: center; text-align: left; line-height: 1.15;
  transition: transform 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}
.presets button span { font-weight: 400; font-size: var(--step-small); color: var(--muted); }
.presets button:hover, .seg label:hover span { transform: translateY(-2px); }
.presets button:active, .seg label:active span { transform: translateY(0); }
.presets button.on { background: var(--ink); color: var(--paper); }
.presets button.on span { color: var(--on-ground-muted); }

.seg { display: flex; gap: 8px; }
.seg label { flex: 1; display: block; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg label span { display: flex; align-items: center; justify-content: center; text-align: center; width: 100%; }
.seg input:checked + span { background: var(--ink); color: var(--paper); }
.seg input:focus-visible + span { outline: 3px solid var(--water); outline-offset: 3px; }

.cover-row { margin-bottom: 8px; }
.cover-row .slider-row { align-items: center; }
.cover-row .name { display: flex; align-items: center; gap: 10px; }
.swatch { width: 16px; height: 16px; flex: none; }
.cover-row .cn { color: var(--muted); font-weight: 400; font-size: var(--step-small); }

/* ---------- Same rain, different ground ---------- */
.ground { background: var(--paper-2); padding: var(--gap-section) var(--m); }
.ground-head { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 48px; align-items: end; margin-bottom: clamp(28px, 4vw, 56px); }
.ground-head p { margin: 0; max-width: 34ch; }
.bars { display: grid; gap: 14px; }
.bar-row { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(0, 4fr); gap: 20px; align-items: center; }
.bar-label { font-family: var(--sans); font-weight: 500; line-height: 1.2; }
.bar-label small { display: block; font-size: var(--step-small); color: var(--muted); font-weight: 400; margin-top: 2px; }
.bar-track { background: var(--water-pale); height: 44px; position: relative; }
.bar-fill { background: var(--silt); height: 100%; width: 0; transition: width 0.35s ease; }
.bar-row.mine .bar-fill { background: var(--ink); }
.bar-row.mine .bar-label { font-weight: 600; }

/* ---------- Method slip ---------- */
.method {
  background: var(--ground); color: var(--on-ground);
  padding: var(--gap-section) var(--m);
  display: grid; grid-template-columns: minmax(0, 6fr) minmax(0, 5fr); gap: clamp(32px, 6vw, 96px); align-items: start;
}
.method h2 { margin-bottom: 0.5em; }
.method-text > p { max-width: 44ch; }
.steps { padding-left: 1.2em; margin: 28px 0 0; max-width: 50ch; }
.steps li { margin-bottom: 18px; padding-left: 8px; }
.steps li::marker { font-family: var(--sans); font-weight: 600; color: var(--water-light); }
.steps strong { color: var(--on-ground); }

.slip { position: sticky; top: 24px; background: var(--paper); color: var(--ink); max-width: 480px; justify-self: end; width: 100%; padding: 32px 28px 24px; font-family: var(--sans); font-size: 1.05rem; }
.slip-title { font-family: var(--serif); font-weight: 500; font-size: var(--step-lead); margin-bottom: 14px; }
.slip-rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 18px; }
.slip-rows li { display: flex; align-items: flex-end; gap: 8px; }
.r-name { line-height: 1.2; font-weight: 600; }
.r-name em { display: block; font-style: normal; font-weight: 400; font-size: var(--step-small); color: var(--muted); margin-top: 2px; }
.r-dots { flex: 1; min-width: 12px; border-bottom: 4px dotted var(--muted); transform: translateY(-6px); }
.r-val { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.slip-total { background: var(--ink); color: var(--paper); display: flex; justify-content: space-between; gap: 12px; align-items: center; font-weight: 600; margin: 28px -28px 0; padding: 14px 28px; min-height: 48px; }
.slip-total span:last-child { font-variant-numeric: tabular-nums; }
.slip .edge { position: absolute; left: 0; right: 0; bottom: -17px; width: 100%; height: 18px; fill: var(--paper); }

/* ---------- Walk ---------- */
.walk { padding: var(--gap-section) var(--m); }
.walk-lead { font-size: var(--step-lead); line-height: 1.35; max-width: 34ch; margin: 24px 0 clamp(28px, 4vw, 56px); }
.walk-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: clamp(16px, 2.4vw, 32px); }
.plate-photo { margin: 0; display: flex; flex-direction: column; background: var(--paper-2); }
.plate-photo img { width: 100%; object-fit: cover; flex: 1; min-height: 0; }
.plate-photo figcaption { padding: 16px 18px 20px; font-size: 1rem; line-height: 1.45; }
.p-ridge { grid-column: 1 / 8; grid-row: 1; }
.p-ridge img { aspect-ratio: 3 / 2; }
.p-bay { grid-column: 8 / 13; grid-row: 1 / 3; }
.p-bay img { aspect-ratio: 1 / 1; }
.p-crops { grid-column: 1 / 5; grid-row: 2; }
.p-crops img { aspect-ratio: 16 / 10; }
.p-city { grid-column: 5 / 8; grid-row: 2; }
.p-city img { aspect-ratio: 4 / 3; }

/* ---------- Limits ---------- */
.limits { background: var(--paper-2); padding: var(--gap-section) var(--m); }
.limits-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: clamp(32px, 6vw, 96px); margin-top: clamp(24px, 4vw, 48px); align-items: start; }
.limits-lead { font-size: var(--step-lead); line-height: 1.35; max-width: 26ch; position: sticky; top: 24px; }
.limits-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 16px; }
.limits-list li { background: var(--paper); padding: 18px 22px; max-width: 64ch; }
.limits-care { grid-column: 2; background: var(--ground); color: var(--on-ground); padding: 18px 22px; margin: 0; max-width: 64ch; font-family: var(--sans); font-weight: 500; }

/* ---------- Back of the card ---------- */
.back { background: var(--ground); color: var(--on-ground); padding: clamp(56px, 8vw, 112px) var(--m) clamp(24px, 4vw, 48px); }
.scallop { width: 100%; height: 28px; fill: var(--paper); margin-bottom: -1px; }
.back-card { background: var(--paper); color: var(--ink); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: clamp(24px, 5vw, 80px); padding: clamp(28px, 4vw, 56px); font-size: 1rem; }
.back-card .back-sign { font-family: var(--serif); font-weight: 500; font-size: var(--step-lead); margin: 0 0 10px; }
.back-right .back-sign:not(:first-child) { margin-top: 24px; }
.back-left p { max-width: 46ch; }
.sources-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; line-height: 1.4; }
.sources-list.credits { font-family: var(--sans); font-size: var(--step-small); }
.imprint { grid-column: 1 / -1; margin: 8px 0 0; text-align: center; font-family: var(--sans); font-size: var(--step-small); color: var(--muted); }

/* ---------- Plate animation ---------- */
.rain-line { stroke: #3f7fa9; stroke-linecap: round; animation: fall 0.9s linear infinite; }
@keyframes fall { to { stroke-dashoffset: -44; } }
.flow-line { fill: none; stroke: var(--silt); stroke-linecap: round; animation: slide 1.4s linear infinite; }
@keyframes slide { to { stroke-dashoffset: -26; } }
.soak-drop { stroke: #8ec1e0; stroke-linecap: round; animation: sink 2.4s linear infinite; }
@keyframes sink { from { transform: translateY(0); opacity: 0.9; } to { transform: translateY(16px); opacity: 0; } }

/* ---------- Entrances ---------- */
.js .reveal { opacity: 0; transform: translateY(22px); transition: opacity 0.6s ease, transform 0.6s ease; transition-delay: var(--d, 0ms); }
.js .reveal.in { opacity: 1; transform: none; }

/* ---------- Tablet and phone ---------- */
@media (max-width: 960px) {
  .cover { grid-template-columns: 1fr; min-height: 0; }
  .cover-photo { min-height: 46svh; }
  .study-grid { grid-template-columns: 1fr; }
  .left { display: contents; position: static; }
  .plate-wrap { position: sticky; top: 0; z-index: 6; margin: 0 calc(var(--m) * -1); padding: 8px var(--m) 4px; background: var(--paper-2); }
  .plate-note { font-size: 1rem; min-height: 2.8em; margin: 8px 0 8px; }
  .plate-wrap { order: 1; }
  .controls { order: 2; }
  .figures { order: 3; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
  .schematic { order: 4; }
  .fig { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
  .fig-label { flex-basis: 100%; }
  .method { grid-template-columns: 1fr; }
  .slip { position: relative; justify-self: stretch; max-width: none; margin-bottom: 20px; }
  .walk-grid { grid-template-columns: 1fr; }
  .p-ridge, .p-bay, .p-crops, .p-city { grid-column: 1; grid-row: auto; }
  .p-bay img { aspect-ratio: 4 / 3; }
  .limits-grid { grid-template-columns: 1fr; }
  .limits-lead { position: static; }
  .limits-care { grid-column: 1; }
  .back-card { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .figures { grid-template-columns: 1fr; gap: 56px; }
  .study-head, .ground-head { grid-template-columns: 1fr; gap: 16px; }
}
@media (max-width: 560px) {
  .bar { flex-direction: column; align-items: flex-start; gap: 4px; }
  .bar nav { justify-content: flex-start; }
  .bar-row { grid-template-columns: 1fr; gap: 6px; }
  .bar-track { height: 32px; }
  .plate-wrap { padding-top: 6px; }
  #plate { aspect-ratio: 800 / 420; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .js .reveal { opacity: 1; transform: none; }
}
