:root {
  --bg: #07090d;
  --panel: rgba(12, 15, 22, 0.72);
  --border: rgba(255, 255, 255, 0.08);
  --text: #e8edf5;
  --muted: #8b95a7;
  --live: #3ddc84;
  --warning: #ffbd69;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#map { position: fixed; inset: 0; }

.panel {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  z-index: 2;
}

.title {
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  padding: 14px 18px;
  max-width: calc(100vw - 32px);
}
.title h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.title p {
  margin: 2px 0 8px;
  color: var(--muted);
  font-size: 13px;
}
.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.dot.live {
  background: var(--live);
  box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.6);
  animation: pulse 2s infinite;
}
.dot.error { background: #ff6b6b; }
.dot.replay { background: #b28cff; }
.dot.warning { background: var(--warning); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0.55); }
  70% { box-shadow: 0 0 0 8px rgba(61, 220, 132, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); }
}

.controls {
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  padding: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.bottom-dock { display: contents; }
.controls button {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 7px 12px;
  cursor: pointer;
}
.controls button:hover { background: rgba(255, 255, 255, 0.12); }
.controls button[aria-pressed="true"] {
  background: rgba(61, 220, 132, 0.18);
  border-color: rgba(61, 220, 132, 0.5);
}
.clock {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 0 8px;
  letter-spacing: 0.02em;
}

.legend {
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 16px;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: calc(100vw - 32px);
}
.search {
  top: 116px;
  left: 16px;
  width: min(300px, calc(100vw - 32px));
  padding: 10px;
}
.search label {
  display: block;
  margin: 0 2px 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.search input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 10px;
  outline: none;
  background: rgba(255,255,255,.06);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}
.search input:focus { border-color: rgba(61,220,132,.7); }
.search input::placeholder { color: #7d8798; }
.search-results {
  margin-top: 7px;
  max-height: min(300px, 40vh);
  overflow: auto;
}
.search-result {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 8px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.search-result:hover, .search-result:focus-visible { background: rgba(255,255,255,.1); }
.search-result small { flex: none; color: var(--muted); }
.search-empty { margin: 10px 6px 4px; color: var(--muted); font-size: 12px; }

.vehicle-card {
  right: 16px;
  bottom: 78px;
  width: min(310px, calc(100vw - 32px));
  padding: 16px;
}
.vehicle-mode {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.vehicle-card h2 { margin: 0 28px 5px 0; font-size: 20px; letter-spacing: -.02em; }
.vehicle-label { margin: 0 0 11px; color: var(--muted); font-size: 12px; }
.card-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
}
.card-close:hover { color: var(--text); }
.vehicle-facts { margin: 10px 0 13px; font-size: 12px; }
.vehicle-facts div { display: flex; justify-content: space-between; gap: 12px; margin-top: 7px; }
.vehicle-facts dt { color: var(--muted); }
.vehicle-facts dd { margin: 0; text-align: right; }
.vehicle-note { margin: -2px 0 11px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.card-actions { display: flex; gap: 7px; }
.card-actions button {
  flex: 1;
  padding: 8px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 9px;
  background: rgba(255,255,255,.07);
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.card-actions button:hover { background: rgba(255,255,255,.14); }
.card-actions button:disabled { opacity: .45; cursor: default; }
.card-actions button[aria-pressed="true"] { border-color: rgba(61,220,132,.5); background: rgba(61,220,132,.18); }
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px 6px 8px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.chip .swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 10px currentColor;
}
.chip .count { color: var(--muted); }
.chip[aria-pressed="false"] { opacity: 0.4; }

/* A chip plus its route-line switch, joined into one pill. */
.chip-group { display: flex; }
.chip-group .chip {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}
.route-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  font: inherit;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-left: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 0 999px 999px 0;
  cursor: pointer;
  padding: 0 4px 0 2px;
}
.route-toggle:hover { background: rgba(255, 255, 255, 0.12); }
.route-toggle[aria-pressed="false"] { opacity: 0.3; }
.route-toggle[aria-pressed="false"] path { stroke-dasharray: 2 3; }

.message {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: min(440px, calc(100vw - 32px));
  padding: 20px 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 3;
  font-size: 14px;
  line-height: 1.5;
}
.message code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 6px;
}

.credit {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 2;
  font-size: 11px;
  color: var(--muted);
}
.credit a { color: var(--muted); }

/* deck.gl tooltip */
.deck-tooltip {
  font-family: var(--font) !important;
  font-size: 12px !important;
  background: rgba(12, 15, 22, 0.92) !important;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px !important;
}

/* MapLibre attribution: keep it, but quiet. */
.maplibregl-ctrl-attrib {
  background: transparent !important;
  font-size: 10px;
}
.maplibregl-ctrl-attrib a { color: #59627a !important; }
.maplibregl-ctrl-bottom-right { bottom: 28px; }

/* Regional colour key, opened from the "i" on the regional legend item. */
.key-toggle {
  width: 26px;
  margin-left: 4px;
  font: 600 12px/1 Georgia, serif;
  font-style: italic;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
}
.key-toggle:hover, .key-toggle[aria-expanded="true"] { background: rgba(255, 255, 255, 0.14); }
.color-key {
  left: 16px;
  bottom: 78px;
  width: min(330px, calc(100vw - 32px));
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  padding: 14px 16px;
  font-size: 13px;
  z-index: 3;
}
.color-key h2 { margin: 0 28px 4px 0; font-size: 15px; }
.color-key p { margin: 0 0 10px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.color-key ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.color-key li { display: flex; align-items: center; gap: 10px; }
.color-key li > span:last-child { display: flex; flex-direction: column; }
.color-key small { color: var(--muted); font-size: 11px; }
.key-swatch { position: relative; flex: none; width: 34px; height: 14px; display: flex; align-items: center; justify-content: center; }
.key-line { position: absolute; left: 0; right: 0; height: 3px; border-radius: 2px; opacity: 0.75; }
.key-dot { position: relative; width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }

/* Replay: a transport bar above the legend. */
.replay {
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  padding: 12px 14px;
  font-size: 13px;
}
.replay-head, .replay-row, .replay-foot { display: flex; align-items: center; gap: 10px; }
.replay-head { justify-content: space-between; margin-bottom: 8px; }
.replay-head strong { margin-right: 8px; }
.replay-head span { color: var(--muted); font-size: 12px; }
.replay-row { margin-bottom: 8px; }
.replay-row input { flex: 1; accent-color: #b28cff; }
.replay-foot { justify-content: space-between; flex-wrap: wrap; }
.replay-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.replay-speeds { display: flex; gap: 4px; }
.replay button {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 5px 10px;
  cursor: pointer;
}
.replay button:hover { background: rgba(255, 255, 255, 0.12); }
.replay button[aria-pressed="true"] { background: rgba(178, 140, 255, 0.22); border-color: rgba(178, 140, 255, 0.6); }
#replay-play { min-width: 64px; }
.replaying .vehicle-card { bottom: 210px; }
.replaying .clock { color: #cbb6ff; }

@media (max-width: 640px) {
  .title { padding: 10px 14px; width: calc(100vw - 32px); }
  .title h1 { font-size: 18px; }
  .title p { margin-bottom: 5px; }
  .bottom-dock {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    z-index: 3;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .controls, .legend { position: static; max-width: none; width: 100%; }
  .controls { justify-content: center; }
  .controls button { flex: 1; padding: 8px 5px; }
  .legend { flex-wrap: nowrap; overflow-x: auto; padding: 7px; scrollbar-width: thin; }
  .chip-group { flex: none; }
  .search { top: 106px; width: calc(100vw - 32px); }
  .search label { display: none; }
  .vehicle-card {
    left: 12px;
    right: 12px;
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + 112px);
    width: auto;
    max-height: min(42vh, 310px);
    overflow: auto;
  }
  .clock { display: none; }
  .color-key { left: 12px; right: 12px; width: auto; bottom: calc(max(12px, env(safe-area-inset-bottom)) + 112px); }
  .replay {
    left: 12px;
    right: 12px;
    width: auto;
    transform: none;
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + 112px);
  }
  .replaying .vehicle-card { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 250px); }
  .credit { display: none; }
  .maplibregl-ctrl-bottom-right { bottom: calc(max(12px, env(safe-area-inset-bottom)) + 122px); }
}

/* Video capture: the map and vehicles only. */
body.video header, body.video .bottom-dock, body.video .panel, body.video .replay,
body.video .credit, body.video .maplibregl-ctrl, body.video #message { display: none !important; }
