:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-glass: rgba(26, 26, 25, 0.93);
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --hair: rgba(255, 255, 255, 0.1);
  --track: #2c2c2a;

  /* Category identity: dark-surface steps, in a fixed order that keeps neighbours distinguishable. */
  --cat-flood: #3987e5;
  --cat-road: #d95926;
  --cat-rail: #199e70;
  --cat-power: #c98500;
  --cat-air: #d55181;
  --cat-bus: #008300;
  --cat-weather: #9085e9;

  /* Feed health: reserved status colours, always shown with a word beside them. */
  --ok: #0ca30c;
  --warn: #fab219;
  --bad: #d03b3b;

  --topbar-h: 96px;
  --sheet-h: 82dvh;
  --sheet-peek: 148px;
  --panel-w: 372px;
  --gap: 12px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

h1, h2, p, ol, ul { margin: 0; padding: 0; }
ol, ul { list-style: none; }
button { font: inherit; color: inherit; }
a { color: var(--ink-2); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

#map { position: fixed; inset: 0; background: var(--page); }

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(var(--gap), env(safe-area-inset-right)) 10px max(var(--gap), env(safe-area-inset-left));
  background: var(--surface-glass);
  border-bottom: 1px solid var(--hair);
  backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.brand-text { min-width: 0; }
.brand h1 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }

/* Unusual / All: which question the whole map is answering. */
.mode { display: inline-flex; flex: none; padding: 2px; border: 1px solid var(--hair); border-radius: 999px; background: var(--surface); }
.mode button {
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--ink-2);
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mode button[aria-pressed="true"] { background: var(--ink-2); color: var(--page); font-weight: 600; }
.mode button:disabled { color: var(--muted); cursor: not-allowed; }
.status { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status[data-state="error"] { color: var(--warn); }

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
  /* Bleed to the screen edge so a half-visible chip signals that the row scrolls. */
  margin: -2px calc(-1 * var(--gap));
  padding: 2px var(--gap);
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  min-height: 36px;
  padding: 0 11px 0 9px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13.5px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.chip .count { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="false"] { color: var(--muted); background: transparent; }
.chip[aria-pressed="false"] .dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); }
.chip[aria-pressed="false"] .count { color: var(--muted); }
.chip[data-empty="true"] { border-style: dashed; }
@media (hover: hover) { .chip:hover { border-color: rgba(255, 255, 255, 0.28); } }

/* "Planned works" is a modifier on every category, so it reads as a checkbox rather than a coloured series. */
.chip-planned { margin-left: 6px; }
.chip-planned .check {
  display: grid;
  place-items: center;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  box-shadow: inset 0 0 0 1.5px var(--muted);
  font-size: 11px;
  line-height: 1;
}
.chip-planned[aria-pressed="true"] .check { background: var(--ink-2); box-shadow: none; color: var(--page); }
.chip-planned[aria-pressed="true"] .check::before { content: "✓"; font-weight: 700; }

/* ------------------------------------------------------------------ panel (bottom sheet on phones) */

.panel {
  position: fixed;
  z-index: 4;
  inset: auto 0 0 0;
  height: var(--sheet-h);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid var(--hair);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.45);
  transform: translateY(calc(var(--sheet-h) - var(--sheet-peek)));
  transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
}
.panel[data-sheet="half"] { transform: translateY(calc(var(--sheet-h) - 52dvh)); }
.panel[data-sheet="full"] { transform: translateY(0); }
.panel.dragging { transition: none; }

.handle {
  flex: none;
  display: grid;
  place-items: center;
  width: 100%;
  height: 28px;
  padding: 0;
  border: 0;
  background: none;
  cursor: grab;
  touch-action: none;
}
.handle span { width: 40px; height: 4px; border-radius: 2px; background: var(--muted); opacity: 0.7; }

.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #4a4a47 transparent;
  padding: 0 max(16px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.panel[data-sheet="peek"] .panel-scroll { overflow: hidden; }
/* The sheet is taller than what is on screen in the half state; pad so the last rows can scroll into view. */
.panel[data-sheet="half"] .panel-scroll { padding-bottom: calc(var(--sheet-h) - 52dvh + 20px); }

.panel h2 { font-size: 15px; font-weight: 650; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.note {
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid var(--hair);
  border-left: 3px solid var(--warn);
  border-radius: 6px;
  color: var(--ink-2);
  font-size: 12.5px;
}

/* ------------------------------------------------------------------ worst-hit list */

.hotspots { margin: 10px -8px 0; }
.hotspot {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 2px 8px;
  width: 100%;
  padding: 9px 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
  cursor: pointer;
}
@media (hover: hover) { .hotspot:hover { background: rgba(255, 255, 255, 0.05); } }
.hotspot .rank { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; padding-top: 1px; }
.hotspot .name { font-weight: 600; }
.hotspot .bar, .hotspot .what { grid-column: 2; }
.hotspot .what { color: var(--ink-2); font-size: 12.5px; }

.bar { display: flex; gap: 2px; height: 8px; margin: 4px 0 3px; background: var(--track); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--c); min-width: 3px; }

.empty { color: var(--ink-2); padding: 14px 8px; font-size: 14px; }

/* ------------------------------------------------------------------ feeds */

.sources { margin-top: 18px; border-top: 1px solid var(--hair); padding-top: 4px; }
.sources summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}
.sources summary::-webkit-details-marker { display: none; }
.sources summary::after { content: "▾"; color: var(--muted); margin-left: 4px; }
.sources[open] summary::after { content: "▴"; }
.sources-summary { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 12.5px; }
.sources li { padding: 8px 0; border-top: 1px solid var(--hair); font-size: 13px; }
.sources li:first-child { border-top: 0; }
.source-head { display: flex; align-items: baseline; gap: 8px; }
.source-head .label { flex: 1; min-width: 0; font-weight: 550; }
.source-head .state { flex: none; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.state::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; background: var(--muted); }
.state[data-state="ok"]::before { background: var(--ok); }
.state[data-state="stale"]::before { background: var(--warn); }
.state[data-state="error"]::before { background: var(--bad); }
.state[data-state="off"]::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); }
.source-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.sources .hint { padding: 10px 0 2px; }

/* ------------------------------------------------------------------ area detail */

.back {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  margin: 0 0 4px -6px;
  padding: 0 8px 0 6px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--ink-2);
  cursor: pointer;
}
@media (hover: hover) { .back:hover { background: rgba(255, 255, 255, 0.06); color: var(--ink); } }

.events { margin-top: 10px; }
.event { padding: 10px 0; border-top: 1px solid var(--hair); }
.event .kind { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 12px; }
.event .kind .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; }
.event .kind .tag { margin-left: auto; padding: 0 6px; border: 1px solid var(--hair); border-radius: 999px; color: var(--muted); }
.event .kind .tag + .tag { margin-left: 0; }
.event .versus { color: var(--ink-2); font-size: 12.5px; margin-top: 3px; }
.event .title { font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.event .detail { color: var(--ink-2); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.event .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }

/* ------------------------------------------------------------------ map furniture */

.legend {
  position: fixed;
  z-index: 2;
  left: max(var(--gap), env(safe-area-inset-left));
  bottom: calc(var(--sheet-peek) + 10px);
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  border: 1px solid var(--hair);
  border-radius: 8px;
  background: var(--surface-glass);
  color: var(--ink-2);
  font-size: 11.5px;
  pointer-events: none;
}
.legend .ramp {
  width: 84px;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, #3a1410, #8f2a19 28%, #d95926 55%, #fab219 80%, #fff4c8);
}

.maplibregl-ctrl-top-right { top: calc(var(--topbar-h) + 2px); }
.maplibregl-ctrl-bottom-right { bottom: calc(var(--sheet-peek) + 2px); }
.maplibregl-ctrl-group { background: var(--surface); border: 1px solid var(--hair); box-shadow: none; }
.maplibregl-ctrl-group button + button { border-top-color: var(--hair); }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1) brightness(0.85); }
.maplibregl-ctrl-attrib { background: var(--surface-glass) !important; color: var(--muted); font-size: 10.5px; }
.maplibregl-ctrl-attrib a { color: var(--ink-2); }
.maplibregl-ctrl-attrib-button { filter: invert(1) brightness(0.8); }
/* Pinch-zoom covers this on touch screens, and the buttons would crowd a phone-width map. */
@media (pointer: coarse) { .maplibregl-ctrl-zoom-in, .maplibregl-ctrl-zoom-out { display: none !important; } }

/* ------------------------------------------------------------------ wide screens: side panel */

@media (min-width: 900px) {
  .topbar { flex-direction: row; align-items: center; gap: 20px; padding-top: 10px; }
  .brand { flex: none; width: calc(var(--panel-w) + 96px); }
  .chips { flex: 1; flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }

  .panel,
  .panel[data-sheet="half"],
  .panel[data-sheet="full"] {
    inset: calc(var(--topbar-h) + var(--gap)) auto var(--gap) var(--gap);
    width: var(--panel-w);
    height: auto;
    transform: none;
    transition: none;
    border: 1px solid var(--hair);
    border-radius: 14px;
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  }
  .handle { display: none; }
  .panel .panel-scroll,
  .panel[data-sheet="peek"] .panel-scroll,
  .panel[data-sheet="half"] .panel-scroll { overflow-y: auto; padding: 16px 16px 18px; }

  .legend { left: calc(var(--panel-w) + 2 * var(--gap)); bottom: var(--gap); }
  .maplibregl-ctrl-bottom-right { bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .panel { transition: none; }
}
