/* Layout: header band, stage strip in route order, map + signal feed, sources table. */
:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --ink: #14202b;
  --muted: #5a6875;
  --line: #d9dfe4;
  --accent: #0f5c8c;
  --water: #dfe7ec;
  --land: #f9fafa;
  --border: #b8c3cc;
  --lv0: #2f8a5b;
  --lv1: #c79100;
  --lv2: #d9622b;
  --lv3: #c0223b;
  --lvu: #8a96a1;
  --tint0: #e3f2ea; --tint1: #fbf1d4; --tint2: #fbe3d7; --tint3: #f8dce1; --tintu: #e8ecef;
  --font-head: "IBM Plex Sans Condensed", "Arial Narrow", system-ui, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e151b; --surface: #16212a; --ink: #e3e9ee; --muted: #93a2ae; --line: #2a3a46; --accent: #5fb0e0; --water: #0b1218; --land: #1d2a34; --border: #3d4f5c;
    --lv0: #4cb27e; --lv1: #e3b23c; --lv2: #f08354; --lv3: #f0566e; --lvu: #6f7d88;
    --tint0: #16352a; --tint1: #3a3115; --tint2: #3e2619; --tint3: #421d26; --tintu: #22303a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e151b; --surface: #16212a; --ink: #e3e9ee; --muted: #93a2ae; --line: #2a3a46; --accent: #5fb0e0; --water: #0b1218; --land: #1d2a34; --border: #3d4f5c;
  --lv0: #4cb27e; --lv1: #e3b23c; --lv2: #f08354; --lv3: #f0566e; --lvu: #6f7d88;
  --tint0: #16352a; --tint1: #3a3115; --tint2: #3e2619; --tint3: #421d26; --tintu: #22303a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font-body); }
h1, h2, h3 { font-family: var(--font-head); text-wrap: balance; margin: 0; }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: env(safe-area-inset-top, 0px); z-index: 1000; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 1001; background: var(--surface); }
.top-inner, .wrap { max-width: 1440px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top-inner { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding-block: 12px; }
.brand { flex: 1 1 320px; min-width: 0; }
.brand h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: .01em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }
.overall { display: flex; flex-direction: column; padding: 6px 14px; border-radius: 6px; background: var(--tintu); border-left: 4px solid var(--lvu); }
.overall-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.overall-value { font-family: var(--font-head); font-size: 1.2rem; font-weight: 700; }
.clock { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn[disabled] { opacity: .5; cursor: progress; }

[data-level="0"] { --lv: var(--lv0); --tint: var(--tint0); }
[data-level="1"] { --lv: var(--lv1); --tint: var(--tint1); }
[data-level="2"] { --lv: var(--lv2); --tint: var(--tint2); }
[data-level="3"] { --lv: var(--lv3); --tint: var(--tint3); }
[data-level="-1"] { --lv: var(--lvu); --tint: var(--tintu); }
.overall[data-level] { background: var(--tint); border-left-color: var(--lv); }

.wrap { padding-block: 16px 40px; display: grid; gap: 16px; }

.stages { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; counter-reset: stage; }
.stage { background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--lv); border-radius: 6px; padding: 10px 12px; display: grid; gap: 4px; align-content: start; cursor: pointer; text-align: left; color: inherit; }
.stage:hover { border-color: var(--lv); }
.stage[aria-pressed="true"] { outline: 2px solid var(--lv); outline-offset: -1px; }
.stage-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.stage-num { font-family: var(--font-mono); font-size: .72rem; color: var(--muted); }
.stage h3 { font-size: 1rem; font-weight: 600; }
.pill { display: inline-block; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: 1px 8px; border-radius: 999px; background: var(--tint); color: var(--ink); border: 1px solid var(--lv); white-space: nowrap; }
.stage-meta { color: var(--muted); font-size: .8rem; }
.stage-top-sig { font-size: .82rem; min-height: 2.4em; overflow-wrap: anywhere; }

.grid { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.map-card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; position: relative; }
#map { height: 620px; background: var(--water); }
.leaflet-container { background: var(--water); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; padding: 8px 12px; border-top: 1px solid var(--line); font-size: .8rem; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--lv); margin-right: 6px; vertical-align: -1px; }

.feed { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; display: flex; flex-direction: column; max-height: 660px; min-width: 0; }
.feed-head { padding: 12px 12px 8px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.feed h2 { font-size: 1.1rem; }
.count { font-family: var(--font-mono); font-size: .8rem; color: var(--muted); font-weight: 400; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px; padding: 2px 10px; font-size: .78rem; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.signals { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.sig { padding: 10px 12px; border-bottom: 1px solid var(--line); border-left: 4px solid var(--lv); display: grid; gap: 3px; cursor: pointer; }
.sig:hover { background: var(--tint); }
.sig-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .75rem; color: var(--muted); }
.layer-tag { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .04em; }
.sig-title { font-weight: 600; overflow-wrap: anywhere; }
.sig-detail { color: var(--muted); font-size: .82rem; overflow-wrap: anywhere; }
.sig a { color: var(--accent); font-size: .8rem; }
.empty { padding: 24px 12px; color: var(--muted); }

.sources { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 14px; display: grid; gap: 10px; }
.sources h2 { font-size: 1.1rem; }
.note, .attrib { margin: 0; color: var(--muted); font-size: .82rem; max-width: 80ch; }
.attrib { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 2px 0; max-width: none; }
.attrib li:not(:last-child)::after { content: "·"; margin: 0 8px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .84rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
td a { color: var(--accent); }
.st { font-weight: 600; }
.st[data-s="ok"] { color: var(--lv0); }
.st[data-s="error"] { color: var(--lv3); }
.st[data-s="loading"] { color: var(--muted); }

/* Leaflet theming */
.leaflet-container { font: 13px/1.4 var(--font-body); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--accent); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--ink); }
.leaflet-popup-content { margin: 10px 12px; max-width: 300px; }
.pop h3 { font-size: .95rem; margin-bottom: 4px; }
.pop ul { margin: 6px 0 0; padding-left: 16px; }
.pop li { margin-bottom: 3px; }
.pop .muted { color: var(--muted); font-size: .8rem; }
.leaflet-control-layers { background: var(--surface); color: var(--ink); }
.leaflet-bar a { background: var(--surface); color: var(--ink); border-color: var(--line); }

@media (max-width: 1100px) {
  .stages { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .feed { max-height: 520px; }
  #map { height: 480px; }
}
@media (max-width: 520px) {
  #map { height: 380px; }
  .clock { width: 100%; justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
