:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  /* canopy along lines: one hue (green), light -> dark = more trees */
  --g0: #d4ead0; --g1: #a6d29b; --g2: #6fb562; --g3: #3d9131; --g4: #1d6c16; --g5: #0c4a08;
  /* flood water: one hue (blue) */
  --b0: #e3eefc; --b1: #b7d3f6; --b2: #86b6ef; --b3: #3987e5; --b4: #1c5cab; --b5: #0d366b;
  /* tree fall-in reach along lines: one hue (purple) */
  --p0: #ece4f5; --p1: #d0bde8; --p2: #ad8fd6; --p3: #8a62c0; --p4: #6640a0; --p5: #3f2170;
  --nodata: #ecebe6;
  /* risk ramp (multi-hazard tab): one hue, orange-red, light -> dark */
  --r0: #fbe3d6; --r1: #f6bf9f; --r2: #ef9467; --r3: #dd6436; --r4: #b8441c; --r5: #84290b;
  /* facility status (status palette; always paired with a label) */
  --st-flooded: #d03b3b; --st-near: #ec835a; --st-edge: #7d96b4; --st-dry: #a9a8a2; --st-unobs: #c9c8c1;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10); --accent: #3987e5;
    --g0: #22351f; --g1: #2f5527; --g2: #3f7a31; --g3: #57a044; --g4: #7fc568; --g5: #b6e49f;
    --b0: #142338; --b1: #183b66; --b2: #1f5799; --b3: #3987e5; --b4: #6da7ec; --b5: #b7d3f6;
    --p0: #2a1f38; --p1: #3f2c5c; --p2: #5a3d88; --p3: #7d5bb5; --p4: #a786d6; --p5: #d2bdf0;
    --nodata: #2a2a28;
    --r0: #3a2418; --r1: #6a321a; --r2: #9a421e; --r3: #cc5a2a; --r4: #ec8452; --r5: #f8b993;
    --st-dry: #6f6e69; --st-unobs: #4a4a46;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10); --accent: #3987e5;
  --g0: #22351f; --g1: #2f5527; --g2: #3f7a31; --g3: #57a044; --g4: #7fc568; --g5: #b6e49f;
  --b0: #142338; --b1: #183b66; --b2: #1f5799; --b3: #3987e5; --b4: #6da7ec; --b5: #b7d3f6;
  --p0: #2a1f38; --p1: #3f2c5c; --p2: #5a3d88; --p3: #7d5bb5; --p4: #a786d6; --p5: #d2bdf0;
  --nodata: #2a2a28;
  --r0: #3a2418; --r1: #6a321a; --r2: #9a421e; --r3: #cc5a2a; --r4: #ec8452; --r5: #f8b993;
  --st-dry: #6f6e69; --st-unobs: #4a4a46;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex; flex-direction: column;
}
a { color: var(--accent); }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin: 0 0 8px; }
h3 { font-size: 14px; margin: 18px 0 6px; }
.sub { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.mt { margin-top: 20px; }
.mt8 { margin-top: 8px !important; }
.hidden { display: none !important; }

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--ring); background: var(--surface);
}
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button, .seg button {
  font: inherit; border: 1px solid var(--ring); background: transparent; color: var(--ink-2);
  padding: 5px 12px; border-radius: 6px; cursor: pointer;
}
.tabs button[aria-selected="true"], .seg button.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }

#app {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 270px 1fr 340px; grid-template-rows: 1fr;
}
.controls, .detail { overflow-y: auto; padding: 16px; background: var(--surface); }
.controls { border-right: 1px solid var(--ring); }
.detail { border-left: 1px solid var(--ring); }
.controls section { margin-bottom: 22px; }
.view { position: relative; min-height: 0; }
#view-table, #view-method { grid-column: 2 / 4; overflow: auto; padding: 16px; }
#map { position: absolute; inset: 0; background: var(--page); }

.seg { display: flex; gap: 4px; }
.seg button { flex: 1; padding: 5px 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.evinfo { font-size: 12.5px; color: var(--ink-2); margin-top: 8px; }
.evinfo b { color: var(--ink); }
.evinfo .passes { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.evinfo .passes span { border: 1px solid var(--ring); border-radius: 4px; padding: 1px 6px; font-variant-numeric: tabular-nums; font-size: 12px; }

.chk { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 4px 0; cursor: pointer; }
.chk .n { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.chk .src { margin-left: auto; color: var(--muted); font-size: 11px; }
.sub-opts { margin-left: 22px; }
.glyph {
  width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 10px; font-weight: 700; color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--ink-2); flex: none;
}

.legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 500; max-width: calc(100% - 24px);
  background: var(--surface); border: 1px solid var(--ring); border-radius: 8px; padding: 8px 10px;
  font-size: 12px; color: var(--ink-2); box-shadow: 0 1px 4px rgba(0,0,0,.08);
  display: flex; gap: 18px; flex-wrap: wrap;
}
.legend .blk { min-width: 150px; }
.legend .t { color: var(--ink); font-weight: 600; margin-bottom: 2px; }
.legend .bar { display: flex; gap: 2px; margin: 4px 0 2px; }
.legend .bar i { width: 24px; height: 10px; display: block; }
.legend .bar i:first-child { border-radius: 4px 0 0 4px; }
.legend .bar i:last-child { border-radius: 0 4px 4px 0; }
.legend .ends { display: flex; justify-content: space-between; color: var(--muted); }
.legend .row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }

.sw { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--axis); }
.sw.sq { border-radius: 2px; }
.st-flooded { background: var(--st-flooded); }
.st-near { background: var(--st-near); }
.st-water_edge { background: var(--st-edge); }
.st-dry { background: var(--st-dry); }
.st-unobserved { background: transparent; box-shadow: 0 0 0 1.5px var(--st-unobs); }
.st-masked { background: transparent; box-shadow: 0 0 0 1.5px var(--st-unobs); }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.kpi { border: 1px solid var(--ring); border-radius: 8px; padding: 8px 10px; }
.kpi b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--ink-2); }

.cty { border: 1px solid var(--ring); border-radius: 8px; padding: 10px 12px; }
.cty h3 { margin: 0 0 2px; font-size: 16px; display: flex; justify-content: space-between; align-items: baseline; }
.cty h3 button { font: inherit; font-size: 12px; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.cty .score { color: var(--ink-2); font-size: 13px; margin-bottom: 8px; }
.facts { font-size: 12.5px; color: var(--ink-2); margin: 8px 0; }
.facts div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--grid); padding: 3px 0; }
.facts b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.facts .h { border: 0; color: var(--ink); font-weight: 600; padding-top: 8px; }
.empty { color: var(--muted); font-size: 13px; }

.rank { padding-left: 22px; margin: 0; font-size: 13px; }
.rank li { padding: 3px 0; cursor: pointer; }
.rank li:hover { color: var(--accent); }
.rank .s { float: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.wet { list-style: none; padding: 0; margin: 6px 0 0; font-size: 12.5px; }
.wet li { padding: 4px 0; border-bottom: 1px solid var(--grid); cursor: pointer; display: flex; gap: 6px; align-items: baseline; }
.wet li:hover .nm { color: var(--accent); }
.wet .nm { flex: 1; }
.wet .m { color: var(--muted); white-space: nowrap; }

.tablewrap { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; background: var(--surface); }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; background: var(--surface); color: var(--ink-2); font-weight: 600; cursor: pointer; }
th:first-child, td:first-child { text-align: left; }
td:first-child { color: var(--accent); cursor: pointer; }
tr:hover td { background: var(--page); }

.prose { max-width: 860px; }
.prose li { margin: 4px 0; }
.prose ul ul { margin-top: 4px; }
code { font-size: 12px; background: var(--grid); padding: 0 4px; border-radius: 3px; }

.foot { padding: 6px 16px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--ring); background: var(--surface); }

.leaflet-container { font: inherit; }
.leaflet-pane.leaflet-flood-pane img { image-rendering: pixelated; }
.leaflet-tooltip.tt {
  background: var(--surface); color: var(--ink); border: 1px solid var(--ring); border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15); padding: 6px 8px; font-size: 12.5px; max-width: 280px; white-space: normal;
}
.leaflet-tooltip.tt::before { display: none; }
.tt b { display: block; }
.tt .m { color: var(--ink-2); }
.leaflet-control-attribution { font-size: 10px; }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto auto auto; overflow-y: auto; }
  .controls, .detail { border: 0; }
  #view-table, #view-method { grid-column: 1; }
  html, body { height: auto; }
  .legend { position: static; margin: 8px; }
  #view-map { display: flex; flex-direction: column; }
  #map { position: relative; flex: 1; min-height: 65vh; }
}

/* ---------- multi-hazard risk tab ---------- */
#view-risk { grid-column: 1 / 4; display: grid; grid-template-columns: 270px 1fr 340px; min-height: 0; }
#view-risk.hidden { display: none !important; }
.rcenter { position: relative; min-height: 0; }
.rmapwrap { position: absolute; inset: 0; }
#rmap { position: absolute; inset: 0; background: var(--page); }
.rtablewrap { position: absolute; inset: 0; overflow: auto; padding: 16px; }
.rtablewrap td.lnk { color: var(--accent); cursor: pointer; }
.rtablewrap td:first-child { color: var(--muted); cursor: default; }
.rnote { font-size: 12.5px; color: var(--ink-2); }
.rnote p { margin: 6px 0; }
.rnote ul { padding-left: 18px; margin: 6px 0; }
.w { margin-bottom: 10px; }
.w label { display: flex; justify-content: space-between; font-size: 13px; }
.w output { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.w input { width: 100%; accent-color: var(--accent); }
.link { font: inherit; font-size: 12px; background: none; border: 0; color: var(--accent); padding: 0; cursor: pointer; }
.hbar { display: grid; grid-template-columns: 100px 1fr 30px; align-items: center; gap: 8px; font-size: 12.5px; margin: 4px 0; }
.hbar .track { height: 8px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.hbar .fill { display: block; height: 100%; background: var(--r3); border-radius: 0 4px 4px 0; }
.hbar .v { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.spark { margin: 10px 0 4px; }
.spark .t { font-size: 12px; color: var(--ink-2); display: flex; justify-content: space-between; }
.spark svg { width: 100%; height: 40px; display: block; overflow: visible; }
.spark .ln { fill: none; stroke: var(--accent); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark .bl { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.spark .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.spark .hit { fill: transparent; }
.spark .hit:hover { fill: var(--accent); }
@media (max-width: 900px) {
  #view-risk { grid-column: 1; grid-template-columns: 1fr; }
  .rcenter { min-height: 65vh; }
  .rtablewrap { position: static; }
}
