/* Blithe Runoff Simulator — styles.
   Design tokens are the site owner's (hishamnuhu.com): light values on :root, dark values under
   prefers-color-scheme (unless data-theme="light") and under data-theme="dark".
   The --scene-* and --viz-* additions drive the 3D view and the chart and are read by js/theme.js. */

:root {
  --paper:#F3F6F7; --sheet:#FFFFFF; --sheet-2:#F8FAFB; --ink:#0C2230; --ink-2:#33495A; --ink-3:#526676;
  --rule:#D3DDE2; --rule-2:#9FB1BC; --accent:#00768A; --accent-2:#B4570F; --accent-ink:#00768A; --accent-wash:#DDF2F5; --on-accent:#FFFFFF;
  --link:#1E5A84; --act:#B5382B; --inv:#C38812; --ok:#2A7247; --mon:#C6D1D8; --mon-ink:#526676; --mon-wash:#EAEFF2;
  --ground:#D4DCD6; --ground-line:#7E8E84;
  --viz-cat-1:#285B9C; --viz-cat-2:#C8651B; --viz-cat-3:#1E8C6E; --viz-cat-4:#7B5CC4; --viz-cat-5:#A27A00; --viz-cat-6:#C2457E;
  --water-1:#E7F1F5; --water-2:#CBE1EB; --water-3:#A2C8DB; --water-4:#72A8C6; --water-5:#4683AA; --water-6:#275F88; --water-7:#123F5E;
  --viz-seq-1:#DEF5F8; --viz-seq-2:#ABDFE8; --viz-seq-3:#73C3DA; --viz-seq-4:#339CC4; --viz-seq-5:#0B78AC; --viz-seq-6:#12588A; --viz-seq-7:#103962;
  --flood-1:#A6F6FF; --flood-2:#5FE0F5; --flood-3:#23B5E6; --flood-4:#1584CF; --flood-5:#0F57A8; --flood-6:#0B3A7A;
  --night-0:#050D14; --night-1:#081521; --night-2:#0D1F2E; --night-3:#13293B;
  --radius:6px;
  --f-sans:"Archivo","Helvetica Neue","Arial Nova",Arial,system-ui,sans-serif;
  --f-serif:"Newsreader","Iowan Old Style","Charter","Bitstream Charter","Sitka Text",Cambria,Georgia,serif;
  --shadow-1:0 1px 2px rgba(5,13,20,.08),0 8px 24px -12px rgba(5,13,20,.28);
  --shadow-2:0 2px 4px rgba(5,13,20,.1),0 24px 48px -20px rgba(5,13,20,.45);

  /* chart */
  --viz-rain:#A2C8DB; --viz-net:#275F88; --viz-gauge:#0C2230; --viz-obs:#B4570F; --viz-ref:#526676;
  /* 3D scene */
  --stage-a:#FFFFFF; --stage-b:#EDF2F4; --stage-c:#DCE5E9; --stage-grid:rgba(12,34,48,.05);
  --scene-tint-low:#CBD8D0; --scene-tint-high:#F6F3E9;
  --scene-hyp-1:#8FB08C; --scene-hyp-2:#B9CC9B; --scene-hyp-3:#E2DBAE; --scene-hyp-4:#D9BD93; --scene-hyp-5:#C7A68A;
  --scene-outside:#E3E9EB; --scene-outside-amt:.66;
  --scene-fog:#EAF0F2; --scene-fog-amt:.4;
  --scene-contour:#6A5740; --scene-contour-alpha:.6;
  --scene-grid:#0C2230; --scene-grid-alpha:.2;
  --scene-shade-lo:.38; --scene-shade-hi:1.16; --scene-shade-gamma:1;
  --scene-sat-gain:1.08; --scene-wash:.34; --scene-tau-mix:.86;
  --scene-skirt-top:#C4CFCC; --scene-skirt-bottom:#A5B3B2; --scene-skirt-line:#6F8079;
  --scene-shadow:#0C2230; --scene-shadow-alpha:.2;
  --scene-water-deep:#A2C8DB; --scene-water-bright:#3C7CA6;
  --scene-channel:#2F6E9A; --scene-channel-hi:#0B3A7A;
  --scene-boundary:#0C2230; --scene-lake-line:#275F88;
  --scene-drop:#1584CF; --scene-drop-stream:#0B3A7A; --scene-drop-soak:#9A6A2C; --scene-streak:#33495A;
  --scene-additive:0; --scene-ws-boost:.12;
  --scene-town:#BDB2A2; --scene-town-edge:#7C6C58; --scene-town-amt:.85; --scene-town-sat-amt:.22; --scene-town-edge-amt:.7;
  --scene-wood:#A6C8A4; --scene-wood-amt:.85; --scene-open-water:#A9CDE0; --scene-ctx-line:#5F8FAE; --scene-road:#7A6A5A; --scene-wash-sat:.3; --scene-outside-sat:.3;
  --halo:rgba(255,255,255,.9); --map-water-ink:#1E5A84; --map-contour-ink:#6A5740;
  --panel:rgba(255,255,255,.9); --panel-2:rgba(248,250,251,.92);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:#09161E; --sheet:#0F202B; --sheet-2:#0C1B24; --ink:#E2ECF0; --ink-2:#AFC2CC; --ink-3:#8BA2AF;
    --rule:#1F3443; --rule-2:#3B5466; --accent:#6FB0F4; --accent-2:#6FD3A0; --accent-ink:#A3CBF8; --accent-wash:#13294A; --on-accent:#06121F;
    --link:#8CC3E0; --act:#CC4A3A; --inv:#E4AE48; --ok:#6CC08E; --mon:#2B3F4C; --mon-ink:#8BA2AF; --mon-wash:#172832;
    --ground:#22332D; --ground-line:#56695E;
    --viz-cat-1:#4177C7; --viz-cat-2:#D27330; --viz-cat-3:#22A07D; --viz-cat-4:#8E73E0; --viz-cat-5:#B98C00; --viz-cat-6:#D25E92;
    --water-1:#0F2733; --water-2:#133647; --water-3:#1A4C63; --water-4:#266887; --water-5:#3E87AE; --water-6:#73AED0; --water-7:#B4D8EA;
    --viz-seq-1:#21374E; --viz-seq-2:#295273; --viz-seq-3:#2E7199; --viz-seq-4:#2B91B7; --viz-seq-5:#32B2D1; --viz-seq-6:#56D3E7; --viz-seq-7:#92F0F9;
    --shadow-1:0 1px 2px rgba(0,0,0,.4),0 10px 28px -14px rgba(0,0,0,.75);
    --shadow-2:0 2px 6px rgba(0,0,0,.45),0 28px 56px -22px rgba(0,0,0,.9);
    --viz-rain:#266887; --viz-net:#73AED0; --viz-gauge:#E2ECF0; --viz-obs:#6FD3A0; --viz-ref:#8BA2AF;
    --stage-a:#0F2231; --stage-b:#081521; --stage-c:#050D14; --stage-grid:rgba(160,200,230,.055);
    --scene-tint-low:#14283A; --scene-tint-high:#647D8E;
    --scene-hyp-1:#35543F; --scene-hyp-2:#566E49; --scene-hyp-3:#7F8358; --scene-hyp-4:#8E7C5C; --scene-hyp-5:#9D8C7A;
    --scene-outside:#0B1924; --scene-outside-amt:.72;
    --scene-fog:#07131C; --scene-fog-amt:.55;
    --scene-contour:#C5D6DF; --scene-contour-alpha:.42;
    --scene-grid:#A0C8E6; --scene-grid-alpha:.2;
    --scene-shade-lo:.22; --scene-shade-hi:1.5; --scene-shade-gamma:1.1;
    --scene-sat-gain:.82; --scene-wash:.36; --scene-tau-mix:.86;
    --scene-skirt-top:#182C3D; --scene-skirt-bottom:#091620; --scene-skirt-line:#46627A;
    --scene-shadow:#000000; --scene-shadow-alpha:.55;
    --scene-water-deep:#17425A; --scene-water-bright:#7FBBDD;
    --scene-channel:#5E9CC2; --scene-channel-hi:#9BE6F7;
    --scene-boundary:#E2ECF0; --scene-lake-line:#73AED0;
    --scene-drop:#5FE0F5; --scene-drop-stream:#C9F8FF; --scene-drop-soak:#C79A55; --scene-streak:#B5CAD6;
    --scene-additive:1; --scene-ws-boost:.28;
  --scene-town:#6E675C; --scene-town-edge:#B4A68F; --scene-town-amt:.75; --scene-town-sat-amt:.25; --scene-town-edge-amt:.6;
  --scene-wood:#1F4A3E; --scene-wood-amt:.8; --scene-open-water:#1D5069; --scene-ctx-line:#4F7F9E; --scene-road:#9A8E7C; --scene-wash-sat:.3; --scene-outside-sat:.5;
    --halo:rgba(5,13,20,.85); --map-water-ink:#9CCBE6; --map-contour-ink:#B5CAD6;
    --panel:rgba(13,29,40,.86); --panel-2:rgba(10,24,33,.9);
  }
}
:root[data-theme="dark"] {
  --paper:#09161E; --sheet:#0F202B; --sheet-2:#0C1B24; --ink:#E2ECF0; --ink-2:#AFC2CC; --ink-3:#8BA2AF;
  --rule:#1F3443; --rule-2:#3B5466; --accent:#6FB0F4; --accent-2:#6FD3A0; --accent-ink:#A3CBF8; --accent-wash:#13294A; --on-accent:#06121F;
  --link:#8CC3E0; --act:#CC4A3A; --inv:#E4AE48; --ok:#6CC08E; --mon:#2B3F4C; --mon-ink:#8BA2AF; --mon-wash:#172832;
  --ground:#22332D; --ground-line:#56695E;
  --viz-cat-1:#4177C7; --viz-cat-2:#D27330; --viz-cat-3:#22A07D; --viz-cat-4:#8E73E0; --viz-cat-5:#B98C00; --viz-cat-6:#D25E92;
  --water-1:#0F2733; --water-2:#133647; --water-3:#1A4C63; --water-4:#266887; --water-5:#3E87AE; --water-6:#73AED0; --water-7:#B4D8EA;
  --viz-seq-1:#21374E; --viz-seq-2:#295273; --viz-seq-3:#2E7199; --viz-seq-4:#2B91B7; --viz-seq-5:#32B2D1; --viz-seq-6:#56D3E7; --viz-seq-7:#92F0F9;
  --shadow-1:0 1px 2px rgba(0,0,0,.4),0 10px 28px -14px rgba(0,0,0,.75);
  --shadow-2:0 2px 6px rgba(0,0,0,.45),0 28px 56px -22px rgba(0,0,0,.9);
  --viz-rain:#266887; --viz-net:#73AED0; --viz-gauge:#E2ECF0; --viz-obs:#6FD3A0; --viz-ref:#8BA2AF;
  --stage-a:#0F2231; --stage-b:#081521; --stage-c:#050D14; --stage-grid:rgba(160,200,230,.055);
  --scene-tint-low:#14283A; --scene-tint-high:#647D8E;
  --scene-hyp-1:#35543F; --scene-hyp-2:#566E49; --scene-hyp-3:#7F8358; --scene-hyp-4:#8E7C5C; --scene-hyp-5:#9D8C7A;
  --scene-outside:#0B1924; --scene-outside-amt:.72;
  --scene-fog:#07131C; --scene-fog-amt:.55;
  --scene-contour:#C5D6DF; --scene-contour-alpha:.42;
  --scene-grid:#A0C8E6; --scene-grid-alpha:.2;
  --scene-shade-lo:.22; --scene-shade-hi:1.5; --scene-shade-gamma:1.1;
  --scene-sat-gain:.82; --scene-wash:.36; --scene-tau-mix:.86;
  --scene-skirt-top:#182C3D; --scene-skirt-bottom:#091620; --scene-skirt-line:#46627A;
  --scene-shadow:#000000; --scene-shadow-alpha:.55;
  --scene-water-deep:#17425A; --scene-water-bright:#7FBBDD;
  --scene-channel:#5E9CC2; --scene-channel-hi:#9BE6F7;
  --scene-boundary:#E2ECF0; --scene-lake-line:#73AED0;
  --scene-drop:#5FE0F5; --scene-drop-stream:#C9F8FF; --scene-drop-soak:#C79A55; --scene-streak:#B5CAD6;
  --scene-additive:1; --scene-ws-boost:.28;
  --scene-town:#6E675C; --scene-town-edge:#B4A68F; --scene-town-amt:.75; --scene-town-sat-amt:.25; --scene-town-edge-amt:.6;
  --scene-wood:#1F4A3E; --scene-wood-amt:.8; --scene-open-water:#1D5069; --scene-ctx-line:#4F7F9E; --scene-road:#9A8E7C; --scene-wash-sat:.3; --scene-outside-sat:.5;
  --halo:rgba(5,13,20,.85); --map-water-ink:#9CCBE6; --map-contour-ink:#B5CAD6;
  --panel:rgba(13,29,40,.86); --panel-2:rgba(10,24,33,.9);
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font: 500 13px/1.35 var(--f-sans); font-stretch: 96%;
  -webkit-font-smoothing: antialiased; overflow: hidden;
  font-variant-numeric: tabular-nums;
}
#app { position: relative; height: 100%; overflow: hidden; --gap: 12px; --left-w: 304px; --right-w: 428px; }
h1, h2, p, ul, dl, dd { margin: 0; padding: 0; }
ul { list-style: none; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ stage */
#stage {
  position: absolute; inset: 0;
  background:
    linear-gradient(var(--stage-grid) 1px, transparent 1px) 0 0 / 100% 88px,
    linear-gradient(90deg, var(--stage-grid) 1px, transparent 1px) 0 0 / 88px 100%,
    radial-gradient(120% 90% at 55% 38%, var(--stage-a) 0%, var(--stage-b) 52%, var(--stage-c) 100%);
}
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline-offset: -3px; cursor: grab; }
#gl:active { cursor: grabbing; }
#labels { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }

.lbl {
  position: absolute; left: 0; top: 0; white-space: nowrap; visibility: hidden; pointer-events: none;
  will-change: transform; color: var(--ink-2); font-size: 11px; line-height: 1.15;
  text-shadow: 0 0 2px var(--halo), 0 0 4px var(--halo), 0 1px 6px var(--halo);
}
.lbl.place { display: flex; align-items: center; gap: 5px; font-stretch: 92%; letter-spacing: .01em; }
.lbl.place.l { flex-direction: row-reverse; }
.lbl.place .sym { flex: none; box-sizing: border-box; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--ink-2); background: var(--halo); box-shadow: 0 0 0 1.5px var(--halo); }
.lbl.place.village { font-size: 11.5px; font-weight: 550; color: var(--ink-2); }
.lbl.place.town { color: var(--ink); font-weight: 750; font-size: 14px; font-stretch: 100%; letter-spacing: .03em; gap: 6px; }
.lbl.place.town .sym { border-radius: 1px; border: 0; background: var(--ink); }
.lbl.place.out { color: var(--ink-3); }
.lbl.place.village.out .sym { border-color: var(--ink-3); }
.lbl.place.town.out { color: var(--ink); }
.lbl.place.hamlet { font-size: 10px; font-weight: 500; color: var(--ink-3); font-style: italic; }
.lbl.place.hamlet .sym { width: 4px; height: 4px; border: 0; background: var(--ink-3); }
.lbl.river.ctx { font-size: 12.5px; opacity: .75; }
.lbl.river.minor { font-size: 12px; }
.lbl.river { font: italic 400 14px/1.1 var(--f-serif); color: var(--map-water-ink); letter-spacing: .02em; }
.lbl.water { font-size: 13px; }
.lbl.grat { font-size: 10px; color: var(--ink-3); font-stretch: 86%; letter-spacing: .03em; padding: 5px 7px; }
.lbl.contour { font-size: 9.5px; color: var(--map-contour-ink); font-stretch: 86%; }
.lbl.mk {
  display: flex; align-items: center; gap: 7px; padding: 0; border: 0; background: none; pointer-events: auto;
  color: var(--ink); text-align: left; transition: opacity .2s;
}
.lbl.mk .ring {
  --c: var(--ink); flex: none; width: 13px; height: 13px; margin-left: -6.5px; border-radius: 50%;
  border: 2px solid var(--c); background: radial-gradient(circle, var(--c) 0 2.2px, transparent 2.6px);
  box-shadow: 0 0 0 calc(2.5px * var(--pulse, 1)) color-mix(in srgb, var(--c) 28%, transparent), 0 0 calc(9px * var(--pulse, 1)) color-mix(in srgb, var(--c) 75%, transparent);
  transition: box-shadow .25s linear;
}
.lbl.mk .t { display: flex; flex-direction: column; }
.lbl.mk b { font-weight: 650; font-size: 11.5px; font-stretch: 96%; }
.lbl.mk small { font-size: 10px; color: var(--ink-2); font-stretch: 88%; }
.lbl.mk-gauge b { font-size: 12.5px; }
.lbl.mk.dimmed { opacity: .35; }
.lbl.mk.flip { flex-direction: row-reverse; text-align: right; }
.lbl.mk.flip .ring { margin-left: 0; margin-right: -6.5px; }
.lbl.mk.flip .t { align-items: flex-end; }
.lbl.mk.compact .t { display: none; }
.lbl.mk.up .t { position: absolute; bottom: calc(100% + 2px); left: -4px; }
.lbl.mk.up.flip .t { left: auto; right: -4px; }
.lbl.mk:hover b { text-decoration: underline; text-underline-offset: 2px; }

/* ------------------------------------------------------------------ panels */
.card {
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: var(--shadow-1); -webkit-backdrop-filter: blur(10px) saturate(1.1); backdrop-filter: blur(10px) saturate(1.1);
  pointer-events: auto;
}
.scroll { overflow: auto; scrollbar-width: thin; scrollbar-color: var(--rule-2) transparent; overscroll-behavior: contain; }
h2 { font-size: 11px; font-weight: 650; font-stretch: 108%; letter-spacing: .05em; color: var(--ink-3); }

#left { position: absolute; top: var(--gap); left: var(--gap); bottom: var(--gap); width: var(--left-w); display: flex; flex-direction: column; gap: 8px; pointer-events: none; z-index: 3; }
#hdr { padding: 12px 14px 10px; border-left: 2px solid var(--accent); flex: none; }
.hdr-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
#title { font-size: 17px; line-height: 1.15; font-weight: 750; font-stretch: 112%; letter-spacing: -.005em; }
.chip { flex: none; font-size: 10px; font-stretch: 90%; padding: 1px 6px; border: 1px solid var(--inv); color: var(--inv); border-radius: 99px; white-space: nowrap; }
.sub { margin-top: 3px; color: var(--ink-2); font: 400 14px/1.3 var(--f-serif); }
#factsBox { margin-top: 8px; border-top: 1px solid var(--rule); padding-top: 7px; }
#factsBox > summary, .explain > summary, #about > summary { cursor: pointer; list-style: none; }
#factsBox > summary::-webkit-details-marker, .explain > summary::-webkit-details-marker, #about > summary::-webkit-details-marker { display: none; }
#factsBox > summary { font-size: 11px; color: var(--ink-3); display: flex; align-items: center; gap: 8px; }
#factsBox > summary .chip { margin-left: auto; }
#factsBox > summary::after { margin-left: 0; }
#factsBox > summary::after, .explain > summary::after, #about > summary::after { content: "+"; color: var(--ink-3); font-weight: 400; margin-left: 8px; }
#factsBox[open] > summary::after, .explain[open] > summary::after, #about[open] > summary::after { content: "–"; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin-top: 6px; font-size: 12px; font-stretch: 90%; }
.facts dt { color: var(--ink-3); }
.facts dd { text-align: right; font-weight: 600; }
.attrib { margin-top: 7px; font-size: 10px; line-height: 1.35; color: var(--ink-3); font-stretch: 88%; }

#controls { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
#ctlTabs { flex: none; display: flex; border-bottom: 1px solid var(--rule); }
#ctlTabs button { flex: 1 1 0; padding: 9px 4px 8px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; font-size: 12px; font-weight: 650; font-stretch: 100%; color: var(--ink-3); }
#ctlTabs button:hover { color: var(--ink); }
#ctlTabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
#ctlBody { flex: 1 1 auto; min-height: 0; padding: 0 14px; -webkit-mask-image: linear-gradient(#000 calc(100% - 22px), transparent); mask-image: linear-gradient(#000 calc(100% - 22px), transparent); }
#ctlBody::after { content: ""; display: block; height: 14px; }
@media (min-width: 761px) {
  body[data-ctl="storm"] .pane:not([data-pane="storm"]), body[data-ctl="res"] .pane:not([data-pane="res"]), body[data-ctl="map"] .pane:not([data-pane="map"]) { display: none; }
  #ctlBody .pane { border-top: 0; }
  #ctlBody .pane + .pane[data-pane="map"] { border-top: 1px solid var(--rule); }
}
.pane { padding: 12px 0 13px; border-top: 1px solid var(--rule); }
.pane:first-child { border-top: 0; }
.pane > h2 { margin-bottom: 9px; }
.field { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 8px; margin-bottom: 9px; }
.field > label { font-size: 12px; color: var(--ink-2); }
.field > output { font-weight: 650; font-size: 12px; font-stretch: 90%; }
.field > input[type=range], .field > select, .field > .hint { grid-column: 1 / -1; }
.hint { font: 400 12.5px/1.35 var(--f-serif); color: var(--ink-3); }
select {
  width: 100%; padding: 5px 26px 5px 8px; border: 1px solid var(--rule-2); border-radius: 4px; background-color: var(--panel-2);
  appearance: none; -webkit-appearance: none; font-size: 12px; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 14px) 55%, calc(100% - 9px) 55%; background-size: 5px 5px; background-repeat: no-repeat;
}
select option { background: var(--sheet); color: var(--ink); }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 20px; margin: 0; background: transparent; cursor: pointer; --p: 50%; }
input[type=range]::-webkit-slider-runnable-track { height: 2px; background: linear-gradient(90deg, var(--accent) var(--p), var(--rule-2) var(--p)); border-radius: 1px; }
input[type=range]::-moz-range-track { height: 2px; background: linear-gradient(90deg, var(--accent) var(--p), var(--rule-2) var(--p)); border-radius: 1px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; margin-top: -5.5px; border-radius: 50%; background: var(--sheet); border: 2px solid var(--accent); }
input[type=range]::-moz-range-thumb { width: 9px; height: 9px; border-radius: 50%; background: var(--sheet); border: 2px solid var(--accent); }
input[type=range]:disabled { opacity: .45; cursor: default; }
input[type=range]:focus-visible { outline-offset: 0; }

.tg { display: flex; align-items: center; gap: 9px; padding: 3.5px 0; font-size: 12.5px; cursor: pointer; }
.tg input { position: absolute; opacity: 0; width: 0; height: 0; }
.tg .sw { flex: none; position: relative; width: 26px; height: 14px; border-radius: 99px; border: 1px solid var(--rule-2); background: transparent; transition: background .15s, border-color .15s; }
.tg .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); transition: transform .15s, background .15s; }
.tg input:checked + .sw { background: var(--accent); border-color: var(--accent); }
.tg input:checked + .sw::after { transform: translateX(12px); background: var(--on-accent); }
.tg input:focus-visible + .sw { outline: 2px solid var(--accent); outline-offset: 2px; }
.tg input:disabled ~ span { opacity: .5; }
.tg .note { color: var(--ink-3); font-size: 11px; margin-left: auto; font-stretch: 88%; text-align: right; }
.toggles { margin-bottom: 10px; }
.pane > .tg { margin-bottom: 8px; }

.keyfig { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; margin: 8px 0 6px; border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; background: var(--rule); }
.keyfig > div { background: var(--panel-2); padding: 6px 7px 5px; min-width: 0; }
.keyfig .k { display: block; font-size: 10px; color: var(--ink-3); font-stretch: 88%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.keyfig .v { display: block; font-size: 15px; font-weight: 700; font-stretch: 86%; line-height: 1.15; white-space: nowrap; }
.keyfig .v small { font-size: 10px; font-weight: 500; color: var(--ink-3); white-space: normal; }
.keyfig .v:has(small:only-child) { line-height: 1.05; white-space: normal; }
.keyfig .d { display: block; font-size: 10px; font-stretch: 86%; color: var(--accent-ink); min-height: 12px; white-space: nowrap; }
.keyfig .d.none { color: var(--ink-3); }
.tag { display: inline-block; margin-left: 5px; padding: 0 5px; border: 1px solid currentColor; border-radius: 99px; font-size: 9.5px; font-weight: 600; font-stretch: 88%; line-height: 14px; vertical-align: 1px; white-space: nowrap; cursor: help; color: var(--ink-3); }
.tag.sourced { color: var(--ok); }
.tag.derived { color: var(--link); }
.tag.assumed { color: var(--inv); }
.tag.hypothetical { color: var(--act); }
.field > label .tag { margin-left: 6px; }
#resControls { margin-top: 10px; }
#resStart { margin-top: 10px; }
#resControls .field.indent { margin-left: 35px; }
#resControls .gap { margin-top: 12px; }
#resControls p.gap { margin-bottom: 12px; }
.linkbtn { border: 0; background: none; padding: 0; color: var(--accent-ink); font-size: 12px; text-decoration: underline; text-underline-offset: 2px; }
.facts.detail, .facts.sheet { font-size: 11.5px; gap: 3px 10px; }
.facts.detail { grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); }
.facts.detail dd { font-stretch: 86%; }
.facts.sheet { grid-template-columns: 84px minmax(0, 1fr); }
.facts.detail dt.grp { grid-column: 1 / -1; margin-top: 7px; color: var(--ink); font-weight: 650; font-size: 11px; }
.facts.sheet dd { font-weight: 500; text-align: left; }
.facts.sheet dd small { display: block; color: var(--ink-3); font-size: 10px; }
.explain { margin-top: 2px; }
.explain + .explain { margin-top: 9px; }
.explain > summary { font-size: 12px; color: var(--accent-ink); display: flex; justify-content: space-between; }
.explain p { margin-top: 7px; font: 400 13px/1.45 var(--f-serif); color: var(--ink-2); }

.ramp { margin-top: 4px; }
.ramp-bar { height: 8px; border-radius: 2px; background: linear-gradient(90deg, var(--viz-seq-1), var(--viz-seq-2), var(--viz-seq-3), var(--viz-seq-4), var(--viz-seq-5), var(--viz-seq-6), var(--viz-seq-7)); border: 1px solid var(--rule); }
.ramp-ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--ink-3); margin: 2px 0 4px; font-stretch: 88%; }

#transport { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 9px 10px; }
.btn { padding: 6px 10px; border: 1px solid var(--rule-2); border-radius: 4px; background: transparent; font-size: 12px; font-weight: 600; font-stretch: 94%; white-space: nowrap; }
.btn:hover { border-color: var(--ink-3); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); min-width: 58px; }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 86%, var(--ink)); }
.clock { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
#clock { font-weight: 700; font-size: 13px; font-stretch: 88%; }
#phase { font: italic 400 12.5px var(--f-serif); color: var(--ink-3); }

#right { position: absolute; top: var(--gap); right: var(--gap); bottom: var(--gap); width: var(--right-w); display: flex; flex-direction: column; gap: 8px; pointer-events: none; z-index: 3; }
#topbar { display: flex; gap: 6px; align-items: flex-start; justify-content: flex-end; flex: none; }
#topbar .btn { background: var(--panel); pointer-events: auto; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); padding: 8px 10px; }
#about { flex: 1 1 auto; min-width: 0; }
#about > summary { padding: 8px 12px; font-size: 12px; font-weight: 600; display: flex; justify-content: space-between; }
@media (min-width: 761px) {
  #about[open] { position: absolute; top: 0; left: auto; width: min(720px, calc(100vw - 360px)); right: 0; bottom: 0; z-index: 5; display: flex; flex-direction: column; box-shadow: var(--shadow-2); background: var(--sheet); }
  #about[open] > summary { border-bottom: 1px solid var(--rule); flex: none; }
  /* the details content box is not a flex item in every engine, so bound the body explicitly */
  #about[open] .about-body { max-height: calc(100% - 36px); max-height: calc(100dvh - var(--gap) * 2 - 36px); overflow-y: auto; }
}
.about-body { padding: 4px 16px 18px; flex: 1 1 auto; min-height: 0; font: 400 14.5px/1.52 var(--f-serif); color: var(--ink-2); }
.about-body h3 { font: 650 12px/1.3 var(--f-sans); font-stretch: 106%; letter-spacing: .03em; color: var(--ink); margin: 18px 0 6px; }
.about-body p { margin: 0 0 9px; max-width: 62ch; }
.about-body ul, .about-body ol { margin: 0 0 9px; padding-left: 1.15em; max-width: 62ch; }
.about-body ul { list-style: disc; }
.about-body li { margin-bottom: 5px; }
.about-body strong { color: var(--ink); font-weight: 600; }
.about-body .note { border-left: 2px solid var(--inv); padding-left: 10px; color: var(--ink-2); }
.about-body .src { font: 500 11px/1.4 var(--f-sans); color: var(--ink-3); font-stretch: 90%; }
.about-body .aside { font-size: 13px; color: var(--ink-3); }
.about-body .tbl-sub, .about-body .tbl-note { font: 500 11px/1.4 var(--f-sans); color: var(--ink-3); font-stretch: 92%; max-width: none; }
.about-body .tbl-note { margin-top: 6px; }
.tbl-wrap { overflow-x: auto; margin: 4px 0 0; -webkit-overflow-scrolling: touch; }
.tbl { border-collapse: collapse; font: 500 11.5px/1.3 var(--f-sans); font-stretch: 92%; color: var(--ink-2); font-variant-numeric: tabular-nums; min-width: 100%; }
.tbl th, .tbl td { padding: 5px 7px; border-bottom: 1px solid var(--rule); text-align: right; vertical-align: top; white-space: nowrap; }
.tbl thead th { font-weight: 650; color: var(--ink-3); font-size: 10.5px; letter-spacing: .02em; border-bottom: 1px solid var(--rule-2); white-space: normal; vertical-align: bottom; }
.tbl thead th:first-child { text-align: left; }
.tbl tbody th { text-align: left; font-weight: 600; color: var(--ink); white-space: normal; min-width: 12em; }
.tbl .txt { text-align: left; white-space: normal; min-width: 11em; }
.tbl td.em { color: var(--ink); font-weight: 650; }
.tbl small { display: block; font-size: 10px; color: var(--ink-3); font-weight: 500; white-space: normal; }
.tbl td:not(.txt) small { white-space: nowrap; }
.tbl .na { color: var(--ink-3); }
.tbl .vs { color: var(--ink-3); padding: 0 1px; }
.tbl sup { font-size: 9px; color: var(--accent-2); margin-left: 1px; }
.tbl sup.pad { visibility: hidden; }

#wsPanel { margin-top: auto; padding: 10px 6px 6px; flex: none; }
#wsPanel > h2 { padding: 0 8px 6px; }
.ws {
  display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 2px 9px; width: 100%;
  padding: 6px 8px; border: 0; border-top: 1px solid var(--rule); background: transparent; text-align: left; border-radius: 0;
}
.ws:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.ws[aria-pressed="true"] { background: var(--accent-wash); box-shadow: inset 2px 0 0 var(--accent); }
.ws .sw { width: 10px; height: 10px; border-radius: 2px; background: var(--c); grid-row: 1 / span 2; }
.ws .sw.g { border-radius: 50%; background: transparent; border: 2px solid var(--viz-gauge); }
.ws .nm { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws .meta { grid-column: 2; font-size: 11px; color: var(--ink-3); font-stretch: 88%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws .pk { grid-row: 1 / span 2; grid-column: 3; text-align: right; font-weight: 700; font-size: 14px; font-stretch: 88%; line-height: 1.05; }
.ws .pk small { display: block; font-weight: 500; font-size: 10px; color: var(--ink-3); }

#flowPanel { flex: 0 1 430px; min-height: 280px; padding: 10px 12px 9px; display: flex; flex-direction: column; }
.flow-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 1px 10px; margin-bottom: 6px; }
#flowTitle { font-size: 12.5px; letter-spacing: .01em; color: var(--ink); font-stretch: 100%; }
.readout { flex: none; font-size: 11.5px; color: var(--ink-3); font-stretch: 88%; white-space: nowrap; }
.readout b { color: var(--ink); font-weight: 700; }
.chart-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
#chart { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: ew-resize; }
.tip { position: absolute; z-index: 4; min-width: 150px; padding: 6px 8px; background: var(--sheet); border: 1px solid var(--rule-2); border-radius: 4px; box-shadow: var(--shadow-1); pointer-events: none; font-size: 11px; font-stretch: 90%; }
.tip .tt { font-weight: 700; margin-bottom: 3px; }
.tip .tr { display: grid; grid-template-columns: 9px 1fr auto; gap: 6px; align-items: center; color: var(--ink-2); }
.tip .tr i { width: 9px; height: 3px; border-radius: 1px; }
.tip .tr b { color: var(--ink); font-weight: 650; }
.legend { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 6px; font-size: 10.5px; color: var(--ink-2); font-stretch: 88%; max-height: 122px; overflow: hidden; flex: none; }
.refmore { font-size: 11px; margin-top: 4px; }
.legend li { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend i { flex: none; width: 12px; height: 2.5px; border-radius: 1px; background: var(--c); }
.legend i.bar { height: 8px; width: 6px; opacity: .6; }
.legend i.chip { width: 7px; margin-right: -3px; }
.legend i.chip:last-of-type { margin-right: 0; }
.legend i.dot { width: 7px; height: 7px; border-radius: 50%; }
.legend i.dash { background: repeating-linear-gradient(90deg, var(--c) 0 3px, transparent 3px 5px); }
.legend i.split { height: 8px; width: 8px; background: linear-gradient(var(--viz-net) 55%, var(--viz-rain) 55%); }

/* ------------------------------------------------------------------ map furniture */
#furniture { position: absolute; left: calc(var(--left-w) + var(--gap) * 2 + 4px); bottom: 36px; display: flex; align-items: flex-end; gap: 12px; pointer-events: none; z-index: 2; color: var(--ink-2); }
#compass svg { display: block; overflow: visible; }
.credits { position: absolute; z-index: 2; left: calc(var(--left-w) + var(--gap) * 2 + 4px); right: calc(var(--right-w) + var(--gap) * 2); bottom: 6px;
  border: 0; background: none; padding: 0; text-align: left; font: 500 9.5px/1.3 var(--f-sans); font-stretch: 88%; color: var(--ink-3);
  text-shadow: 0 0 3px var(--halo); white-space: normal; overflow: hidden; max-height: 2.6em; }
.credits:hover { color: var(--ink-2); text-decoration: underline; }
.credits .short { display: none; }
body.panels-off .credits { left: 16px; right: 16px; bottom: 80px; }
#compass .n { fill: var(--ink); }
#compass .s { stroke: var(--ink-3); stroke-width: 1; }
#compass .nl { font: 650 7px var(--f-sans); fill: var(--ink-2); }
#needle { transform-origin: 16px 16px; }
#scale { display: flex; flex-direction: column; gap: 3px; font-size: 10px; font-stretch: 88%; }
#scaleBar { display: block; height: 5px; border: 1px solid var(--ink-2); border-top: 0; }
#readout { font-size: 10.5px; font-stretch: 88%; color: var(--ink-3); min-width: 220px; padding-bottom: 1px; text-shadow: 0 0 3px var(--halo); }

/* ------------------------------------------------------------------ states */
#tabs { display: none; }
#loading { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; background: var(--paper); transition: opacity .4s; }
#loading.done { opacity: 0; pointer-events: none; }
.load-box { width: min(300px, 80%); }
.load-title { font-size: 16px; font-weight: 750; font-stretch: 112%; }
#loadMsg { margin-top: 4px; font: 400 14px var(--f-serif); color: var(--ink-2); }
.load-bar { margin-top: 12px; height: 2px; background: var(--rule); overflow: hidden; }
.load-bar i { display: block; height: 100%; width: 35%; background: var(--accent); animation: slide 1.3s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(290%); } }
.notice { position: absolute; z-index: 21; left: 50%; top: 42%; transform: translate(-50%, -50%); width: min(430px, 86%); padding: 16px 18px; background: var(--sheet); border: 1px solid var(--rule-2); border-left: 2px solid var(--act); border-radius: var(--radius); box-shadow: var(--shadow-2); font: 400 15px/1.45 var(--f-serif); color: var(--ink-2); }
.notice b { display: block; font: 700 14px var(--f-sans); color: var(--ink); margin-bottom: 4px; }
.notice .btn { margin-top: 10px; font-family: var(--f-sans); }
#nogl { z-index: 1; }

body.panels-off #hdr, body.panels-off #controls, body.panels-off #wsPanel, body.panels-off #flowPanel, body.panels-off #about { display: none; }
body.panels-off #left { top: auto; }
body.panels-off #furniture { left: 16px; bottom: 104px; }

@media (max-width: 1120px) and (min-width: 761px) {
  #app { --left-w: 280px; --right-w: 360px; }
}

/* ------------------------------------------------------------------ phone: the 3D view stays, panels become a bottom sheet with tabs */
@media (max-width: 760px) {
  #app { --tabs-h: 44px; --sheet-h: min(42%, 340px); --tr-h: 48px; }
  body.sheet-closed #app { --sheet-h: 0px; }
  #left, #right, #topbar { display: contents; }
  .card { border-radius: 0; border-width: 1px 0 0; box-shadow: none; }
  #hdr { position: absolute; top: 0; left: 0; right: 0; z-index: 4; padding: 8px 96px 7px 12px; border-left: 0; border-top: 0; border-bottom: 1px solid var(--rule); }
  #title { font-size: 15px; }
  .sub { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #factsBox { margin-top: 4px; padding-top: 4px; }
  #factsBox[open] { max-height: 260px; overflow: auto; }
  #themeBtn { position: absolute; top: 7px; right: 8px; z-index: 5; padding: 5px 8px; }
  #panelsBtn { display: none; }
  #transport { position: absolute; left: 0; right: 0; bottom: calc(var(--tabs-h) + var(--sheet-h)); height: var(--tr-h); z-index: 4; flex-wrap: nowrap; padding: 6px 10px; }
  #transport .btn { padding: 6px 8px; }
  #viewBtn { order: 3; }
  #controls, #wsPanel, #flowPanel, #about {
    position: absolute; left: 0; right: 0; bottom: var(--tabs-h); height: var(--sheet-h); z-index: 4; display: none; margin: 0;
    background: var(--sheet);
  }
  body[data-tab="storm"] #controls, body[data-tab="map"] #controls, body[data-tab="res"] #controls { display: flex; }
  #ctlTabs { display: none; }
  body[data-tab="storm"] .pane:not([data-pane="storm"]), body[data-tab="map"] .pane:not([data-pane="map"]), body[data-tab="res"] .pane:not([data-pane="res"]) { display: none; }
  #ctlBody .pane:first-child, body[data-tab="res"] .pane[data-pane="res"] { border-top: 0; }
  body[data-tab="ws"] #wsPanel { display: block; overflow: auto; }
  body[data-tab="flow"] #flowPanel { display: flex; }
  body[data-tab="about"] #about { display: flex; flex-direction: column; }
  body.sheet-closed #controls, body.sheet-closed #wsPanel, body.sheet-closed #flowPanel, body.sheet-closed #about { display: none; }
  #about > summary { display: none; }
  #tabs { position: absolute; left: 0; right: 0; bottom: 0; height: var(--tabs-h); z-index: 6; display: flex; background: var(--sheet); border-top: 1px solid var(--rule); padding-bottom: env(safe-area-inset-bottom, 0); }
  #tabs button { flex: 1 1 0; border: 0; background: none; font-size: 11.5px; font-stretch: 92%; font-weight: 600; color: var(--ink-3); border-top: 2px solid transparent; padding: 0 2px; }
  #tabs button[aria-selected="true"] { color: var(--ink); border-top-color: var(--accent); }
  #furniture { left: 10px; bottom: calc(var(--tabs-h) + var(--sheet-h) + var(--tr-h) + 8px); gap: 8px; }
  #compass svg { width: 22px; height: 22px; }
  #readout { display: none; }
  .credits { left: 96px; right: 8px; bottom: calc(var(--tabs-h) + var(--sheet-h) + var(--tr-h) + 8px); font-size: 9px; white-space: nowrap; text-overflow: ellipsis; }
  .credits .long { display: none; } .credits .short { display: inline; }
  .lbl.grat { display: none; }
  .legend { max-height: 32px; overflow-y: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .load-bar i { animation: none; width: 100%; }
}
