/* citySponge — plan-sheet styling over a live map */
:root {
  --paper: #fbfcfd;
  --paper-2: #eef2f5;
  --ink: #12263a;
  --ink-2: #4a5d70;
  --ink-3: #7d8d9c;
  --rule: #cdd6de;
  --water: #1f6fb2;
  --water-soft: #d9e8f5;
  --sewer: #7b2cbf;
  --surface: #0a8f80;
  --cso: #b4232f;
  --ms4: #2f8f46;
  --warn: #c76a12;
  --shadow: 0 1px 2px rgba(18, 38, 58, .12), 0 6px 20px rgba(18, 38, 58, .10);
  --radius: 8px;
  --panel-w: 330px;
  --block-w: 370px;
  font-family: "Public Sans", system-ui, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #142130;
    --paper-2: #1c2c3d;
    --ink: #e4edf5;
    --ink-2: #a6b7c7;
    --ink-3: #74889b;
    --rule: #2c3f53;
    --water: #5fb0f0;
    --water-soft: #1d3a55;
    --sewer: #c58cff;
    --surface: #3fd3bf;
    --cso: #ff6b72;
    --ms4: #6fd389;
    --warn: #f0a24a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  --paper: #142130; --paper-2: #1c2c3d; --ink: #e4edf5; --ink-2: #a6b7c7; --ink-3: #74889b;
  --rule: #2c3f53; --water: #5fb0f0; --water-soft: #1d3a55; --sewer: #c58cff; --surface: #3fd3bf;
  --cso: #ff6b72; --ms4: #6fd389; --warn: #f0a24a;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper-2); }
body { font-variant-numeric: tabular-nums; line-height: 1.4; }
#map { position: fixed; inset: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--water); outline-offset: 2px; }

/* ---------- loader ---------- */
#loader {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: color-mix(in srgb, var(--paper-2) 82%, transparent);
  backdrop-filter: blur(3px); transition: opacity .4s;
}
#loader.done { opacity: 0; pointer-events: none; }
.loader-card { width: min(360px, calc(100vw - 32px)); background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 22px 22px 16px; box-shadow: var(--shadow); }
.loader-title { font-size: 26px; font-weight: 750; letter-spacing: -.02em; }
.loader-sub { margin: 2px 0 16px; color: var(--ink-2); }
.bar { height: 6px; background: var(--paper-2); border-radius: 3px; overflow: hidden; }
#loader-bar { height: 100%; width: 0; background: var(--water); transition: width .2s; }
#loader-msg { margin: 10px 0 0; font-size: 12.5px; color: var(--ink-2); min-height: 1.4em; }
#loader.error #loader-bar { background: var(--cso); }

/* ---------- sheets ---------- */
.sheet {
  position: fixed; z-index: 10; background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
#controls { top: 12px; left: 12px; width: var(--panel-w); max-height: calc(100vh - 24px - 74px); overflow-y: auto; padding: 14px 16px 12px; }
#controls .handle { display: none; }
.brand { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.025em; }
.link-btn, .text-btn { background: none; border: 0; padding: 0; color: var(--water); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; font-size: 13px; }

section { border-top: 1px solid var(--rule); padding: 12px 0; }
.brand + #controls-body > section:first-child { border-top: 0; }
h2 { font-size: 13px; font-weight: 650; margin: 0 0 6px; }

/* the storm sentence is the page's one loud thing */
.storm-headline { margin: 6px 0 12px; font-size: 25px; line-height: 1.12; font-weight: 300; letter-spacing: -.02em; }
.storm-rp { margin: -8px 0 12px; font-size: 12.5px; color: var(--ink-2); }
.storm-headline b { font-weight: 750; color: var(--water); }

.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.presets button {
  border: 1px solid var(--rule); background: var(--paper); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; cursor: pointer;
}
.presets button:hover { border-color: var(--water); }
.presets button[aria-pressed="true"] { background: var(--water); border-color: var(--water); color: var(--paper); }

.slider { display: block; margin: 8px 0 4px; }
.slider-top { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); }
.slider output { color: var(--ink); font-weight: 600; }
input[type=range] { width: 100%; accent-color: var(--water); margin: 4px 0 0; }

.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
select { border: 1px solid var(--rule); background: var(--paper); border-radius: 6px; padding: 4px 6px; max-width: 60%; }

.legend { margin-top: 10px; font-size: 12.5px; }
.legend .row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.legend .sw { width: 22px; height: 5px; border-radius: 3px; flex: none; }
.legend .ramp { height: 8px; border-radius: 4px; margin: 4px 0 2px; }
.legend .ticks { display: flex; justify-content: space-between; color: var(--ink-2); font-size: 11.5px; }
.legend .note { color: var(--ink-3); font-size: 11.5px; margin: 4px 0 0; }
.legend .trace-key { display: flex; gap: 14px; margin-top: 8px; color: var(--ink-2); font-size: 11.5px; }
.legend .trace-key i { display: inline-block; width: 20px; height: 0; vertical-align: middle; margin-right: 5px; }

.check { display: flex; align-items: center; gap: 7px; font-size: 13px; padding: 3px 0; cursor: pointer; }
.check input { accent-color: var(--water); margin: 0; }
.check input:disabled + * , .check:has(input:disabled) { color: var(--ink-3); cursor: default; }
.hint { color: var(--ink-3); font-size: 11.5px; }

.advanced { border-top: 1px solid var(--rule); padding: 10px 0 4px; }
.advanced summary { cursor: pointer; font-size: 13px; font-weight: 600; }
.adv { margin: 10px 0; }
.adv .slider-top span:first-child { color: var(--ink); }
.adv p { margin: 1px 0 0; font-size: 11.5px; color: var(--ink-3); }
.adv-group { font-size: 12px; font-weight: 650; color: var(--ink-2); margin: 14px 0 0; }
.runinfo { margin: 6px 0 0; font-size: 11.5px; color: var(--ink-3); }

/* ---------- summary strip ---------- */
#summary {
  position: fixed; z-index: 9; left: calc(12px + var(--panel-w) + 12px); right: 12px; bottom: 12px;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0;
}
.stat { padding: 8px 12px; border-left: 1px solid var(--rule); display: flex; flex-direction: column; min-width: 0; }
.stat:first-child { border-left: 0; }
.stat .k { font-size: 11.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.stat .u { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat.cso .v { color: var(--cso); }
.stat.flood .v { color: var(--warn); }

body.has-block #summary { right: calc(12px + var(--block-w) + 12px); }

/* ---------- block panel ---------- */
#block { top: 12px; right: 12px; width: var(--block-w); max-height: calc(100vh - 24px); overflow-y: auto; padding: 14px 16px 16px; }
.close { position: absolute; top: 6px; right: 8px; border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--ink-2); padding: 4px 8px; }
.blk-name { font-size: 20px; font-weight: 750; letter-spacing: -.015em; margin: 0 28px 2px 0; }
.blk-meta { color: var(--ink-2); font-size: 12.5px; margin: 0 0 10px; }
.status-chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; font-size: 13px; padding: 3px 10px 3px 8px; border-radius: 999px; background: var(--paper-2); }
.status-chip i { width: 10px; height: 10px; border-radius: 50%; }
.status-desc { margin: 6px 0 0; color: var(--ink-2); font-size: 12.5px; }
#block h3 { font-size: 13px; font-weight: 700; margin: 16px 0 6px; padding-top: 12px; border-top: 1px solid var(--rule); }
table.budget { width: 100%; border-collapse: collapse; font-size: 13px; }
table.budget td { padding: 3px 0; vertical-align: top; }
table.budget td:last-child { text-align: right; white-space: nowrap; font-weight: 600; }
table.budget tr.sub td:first-child { padding-left: 12px; color: var(--ink-2); }
table.budget td small { display: block; font-weight: 400; color: var(--ink-3); font-size: 11.5px; }
.meter { height: 8px; background: var(--paper-2); border-radius: 4px; overflow: hidden; margin: 4px 0 2px; position: relative; }
.meter > div { height: 100%; border-radius: 4px; }
.meter .cap { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); }
.split { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin: 6px 0 4px; background: var(--paper-2); }
.split > div { height: 100%; }
.path-key { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; font-size: 13px; }
.path-key i { flex: none; width: 22px; height: 0; margin-top: 9px; }
.path-key p { margin: 0; }
.path-key small { color: var(--ink-2); display: block; }
.outfall-card { background: var(--paper-2); border-radius: 6px; padding: 10px 12px; margin-top: 8px; font-size: 13px; }
.outfall-card .kind { font-weight: 700; }
.outfall-card .kind.cso { color: var(--cso); }
.outfall-card .kind.ms4 { color: var(--ms4); }
.outfall-card p { margin: 3px 0; }
.blk-actions { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 10px; font-size: 13px; }
.muted { color: var(--ink-3); }
.c311 { margin-top: 10px; font-size: 13px; padding: 8px 10px; border-left: 3px solid var(--warn); background: var(--paper-2); border-radius: 0 6px 6px 0; }

.tap-hint {
  position: fixed; z-index: 8; left: 50%; top: 14px; transform: translateX(-50%); margin: 0;
  background: var(--ink); color: var(--paper); padding: 6px 14px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow);
  transition: opacity .4s; pointer-events: none;
}
.tap-hint.gone { opacity: 0; }

/* outfall marker for traced path */
.outfall-marker { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--sewer); background: var(--paper); box-shadow: 0 0 0 3px color-mix(in srgb, var(--sewer) 30%, transparent); display: grid; place-items: center; }
.outfall-marker::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--sewer); }

/* ---------- about ---------- */
dialog#about {
  max-width: 620px; width: calc(100vw - 32px); max-height: calc(100vh - 48px); border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--paper); color: var(--ink); padding: 20px 24px; box-shadow: var(--shadow); line-height: 1.55;
}
dialog#about::backdrop { background: rgba(10, 20, 30, .45); }
dialog#about h2 { font-size: 22px; font-weight: 750; margin: 0 0 8px; }
dialog#about h3 { font-size: 14px; margin: 18px 0 4px; }
dialog#about p, dialog#about li { font-size: 14px; color: var(--ink-2); max-width: 68ch; }
dialog#about li { margin: 4px 0; }
dialog#about strong { color: var(--ink); }

/* maplibre popup theming */
.maplibregl-popup-content { background: var(--paper); color: var(--ink); border-radius: 6px; padding: 8px 12px; font-size: 12.5px; box-shadow: var(--shadow); }
.maplibregl-popup-tip { border-top-color: var(--paper) !important; border-bottom-color: var(--paper) !important; }
.maplibregl-ctrl-attrib { font-size: 10px; }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  :root { --panel-w: 100vw; }
  #summary {
    left: 8px; right: 8px; top: 8px; bottom: auto; display: flex; overflow-x: auto; scrollbar-width: none;
  }
  .stat { flex: none; min-width: 120px; padding: 6px 10px; }
  .stat .v { font-size: 16px; }
  body.has-block #summary { right: 8px; }
  .tap-hint { top: auto; bottom: 46vh; }
  #controls {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 52vh; border-radius: 14px 14px 0 0;
    padding: 0 16px calc(12px + env(safe-area-inset-bottom)); transition: max-height .25s;
  }
  #controls .handle { display: flex; justify-content: center; width: 100%; background: none; border: 0; padding: 8px 0 6px; cursor: pointer; position: sticky; top: 0; background: var(--paper); z-index: 1; }
  #controls .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--rule); }
  #controls.collapsed { max-height: 120px; overflow: hidden; }
  #controls.collapsed #controls-body > :not(.storm) { display: none; }
  .storm-headline { font-size: 20px; margin: 2px 0 8px; }
  #block {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 62vh; border-radius: 14px 14px 0 0; z-index: 12;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- historical storms ---------- */
.hist { margin: 4px 0 12px; }
.hist-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.hist-head h2 { margin: 0; }
.hist-tools { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.chips { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; flex: none; }
.chips button, .seg-ctl button { border: 0; background: var(--paper); padding: 3px 9px; font-size: 12.5px; cursor: pointer; }
.chips button + button, .seg-ctl button + button { border-left: 1px solid var(--rule); }
.chips button[aria-pressed="true"], .seg-ctl button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
#hist-q { flex: 1; min-width: 0; border: 1px solid var(--rule); border-radius: 6px; padding: 3px 8px; font-size: 12.5px; background: var(--paper); }
.hist-list { list-style: none; margin: 0; padding: 0; max-height: 190px; overflow-y: auto; border: 1px solid var(--rule); border-radius: 6px; }
.hist-list li + li { border-top: 1px solid var(--rule); }
.hist-empty { padding: 10px; font-size: 12.5px; }
.hist-row {
  display: grid; grid-template-columns: 1fr auto; column-gap: 8px; width: 100%; text-align: left;
  border: 0; background: var(--paper); padding: 5px 9px 5px 11px; cursor: pointer; position: relative;
}
.hist-row:hover { background: var(--paper-2); }
.hist-row[aria-pressed="true"] { background: var(--water-soft); }
.hist-row.named::before { content: ""; position: absolute; left: 0; top: 4px; bottom: 4px; width: 3px; border-radius: 0 2px 2px 0; background: var(--water); }
.hr-name { font-size: 13px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-row.event .hr-name { font-weight: 450; color: var(--ink-2); }
.hr-total { font-size: 13px; font-weight: 650; text-align: right; }
.hr-total small { font-weight: 400; color: var(--ink-3); font-size: 11px; }
.hr-date, .hr-peak { font-size: 11.5px; color: var(--ink-3); }
.hr-peak { text-align: right; }
.hist-detail { margin-top: 10px; padding: 10px 12px; background: var(--paper-2); border-radius: 6px; font-size: 12.5px; }
.hist-detail p { margin: 0 0 6px; }
.hd-name { font-size: 15px; font-weight: 750; margin-bottom: 2px !important; }
.hd-dates { color: var(--ink-2); }
.hd-totals { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--ink-2); }
.hd-totals .max { color: var(--ink); font-weight: 650; }
.seg-ctl { display: flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; margin: 8px 0 6px; }
.seg-ctl button { flex: 1; padding: 4px 4px; }
.hd-map { color: var(--ink); }
.hd-fix { border-left: 3px solid var(--warn); padding-left: 8px; color: var(--ink-2); }
.hyeto { margin: 8px 0 4px; }
.hyeto figcaption { color: var(--ink-2); margin-bottom: 4px; }
#hyeto-svg { position: relative; }
#hyeto-svg svg { display: block; width: 100%; height: 70px; cursor: crosshair; }
#hyeto-svg rect { fill: var(--ink-3); }
#hyeto-svg rect.pk { fill: var(--water); }
#hyeto-svg line.base { stroke: var(--rule); stroke-width: 1; vector-effect: non-scaling-stroke; }
#hyeto-svg line.head { stroke: var(--cso); stroke-width: 2; vector-effect: non-scaling-stroke; }
.hyeto-max { position: absolute; top: 0; right: 0; font-size: 11px; color: var(--water); pointer-events: none; }
.hyeto-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); margin-top: 2px; }
.play { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.play-btn { flex: none; border: 1px solid var(--water); background: var(--water); color: var(--paper); border-radius: 999px; padding: 3px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.play input[type=range] { flex: 1; margin: 0; }
.play-status { margin: 4px 0 2px !important; font-weight: 600; min-height: 1.4em; }
.hd-caveat { color: var(--ink-3); font-size: 11.5px; }
.hd-note summary { cursor: pointer; color: var(--ink-2); font-size: 12px; }
.hd-note p { color: var(--ink-3); font-size: 11.5px; margin-top: 4px !important; }
@media (max-width: 760px) { #controls.collapsed .storm .hist { display: none; } }
.hist-src { margin: 6px 0 2px; }
.hist-src button { font-size: 12px; padding: 4px 6px; }
.hist-count { margin: 4px 0 0; }
#hist-sort { font-size: 12.5px; padding: 2px 4px; max-width: none; flex: none; }
.hr-rank { display: inline-block; min-width: 1.6em; color: var(--ink-3); font-weight: 500; font-size: 11.5px; }
.hist-tools { flex-wrap: wrap; }
