:root {
  --bg: #0b1220;
  --panel: rgba(15, 23, 42, 0.97);
  --panel-solid: #111c2e;
  --line: rgba(148, 163, 184, 0.22);
  --text: #e8eef8;
  --muted: #93a4bd;
  --accent: #38bdf8;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --police: #60a5fa;
  --camera: #c084fc;
  --jam: #fb923c;
  --accident: #f87171;
  --hazard: #facc15;
  --closure: #f43f5e;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Author display rules (e.g. `#panel { display:flex }`) beat the UA rule for
   [hidden], so make the attribute authoritative. */
[hidden] { display: none !important; }

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

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

/* ---------- top bar ---------- */
#topbar {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 5;
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);

  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 650;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.pill {
  flex: 1;
  min-width: 0;
  /* Allow wrapping to two lines instead of truncating with an ellipsis. */
  white-space: normal;
  line-height: 1.18;
  max-height: 44px;
  overflow: hidden;
  background: var(--panel);

  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.pill.live { color: var(--ok); border-color: rgba(52, 211, 153, 0.45); }
.pill.sim { color: var(--warn); border-color: rgba(251, 191, 36, 0.45); }
.pill.err { color: var(--bad); border-color: rgba(248, 113, 113, 0.45); }

.icon-btn, .mini-btn {
  background: var(--panel);

  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 50%;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 16px;
  cursor: pointer;
}
.mini-btn { width: 28px; height: 28px; font-size: 12px; }

/* ---------- search ---------- */
#searchWrap {
  position: absolute;
  top: calc(var(--safe-top) + 62px);
  left: 12px;
  right: 12px;
  z-index: 6;
}
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
}
.search-box input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  font-size: 15px;
}
.search-box input::placeholder { color: var(--muted); }
.search-ico { color: var(--muted); font-size: 17px; }

#searchResults {
  list-style: none;
  margin: 6px 0 0;
  padding: 4px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  max-height: 46vh;
  overflow: auto;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
}
#searchResults li {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}
#searchResults li:hover,
#searchResults li.active { background: rgba(56, 189, 248, 0.14); }
#searchResults li small { display: block; color: var(--muted); font-size: 12px; }

/* ---------- panel ---------- */
#panel {
  position: absolute;
  left: 12px; right: 12px;
  bottom: calc(var(--safe-bottom) + 186px);
  z-index: 5;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--panel);

  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
}
#panelMain { flex: 1; min-width: 0; }
#panelTitle { font-weight: 700; font-size: 16px; }
#panelSub { color: var(--muted); font-size: 13px; margin-top: 2px; }
#panelMeta { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }

.tag {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.tag.ok { color: var(--ok); border-color: rgba(52,211,153,0.4); }
.tag.warn { color: var(--warn); border-color: rgba(251,191,36,0.4); }
.tag.bad { color: var(--bad); border-color: rgba(248,113,113,0.4); }

.fab.cruise {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
  font-size: 18px;
  padding: 0 13px;
}
.fab.cruise.active {
  background: var(--ok);
  border-color: var(--ok);
  color: #04231a;
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.25);
}

/* ---------- police scanner ---------- */
#scannerPanel {
  position: absolute;
  left: 8px; right: 8px;
  bottom: calc(var(--safe-bottom) + 186px);
  height: 62vh;
  z-index: 9;
  display: flex;
  flex-direction: column;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.6);
}
#scannerFrame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #fff;
}
.scanner-foot {
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}
.scanner-foot a { color: var(--accent); }
.fab.radio {
  background: #0f766e;
  border-color: #0f766e;
  color: #fff;
  font-size: 18px;
  padding: 0 13px;
}

/* ---------- trip sheet ---------- */
#tripPanel {
  position: absolute;
  left: 8px; right: 8px;
  bottom: calc(var(--safe-bottom) + 186px);
  z-index: 8;
  max-height: 62vh;
  display: flex;
  flex-direction: column;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.trip-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 8px;
  font-weight: 700;
  font-size: 15px;
}
.trip-tabs { display: flex; gap: 6px; padding: 0 10px 10px; }
.trip-tab {
  flex: 1;
  padding: 8px 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 650;
  cursor: pointer;
}
.trip-tab.active { background: rgba(56,189,248,.16); color: var(--accent); border-color: rgba(56,189,248,.5); }
#tripList {
  list-style: none; margin: 0; padding: 0 8px 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#tripList li {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 8px;
  border-bottom: 1px solid rgba(148,163,184,.12);
  font-size: 13.5px;
  line-height: 1.35;
}
#tripList li:last-child { border-bottom: 0; }
#tripList li.current { background: rgba(56,189,248,.12); border-radius: 10px; }
#tripList .dist {
  min-width: 58px;
  text-align: right;
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#tripList .txt { flex: 1; min-width: 0; }
#tripList .sub { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
#tripList .empty { color: var(--muted); padding: 18px 10px; justify-content: center; }

/* ---------- nav banner ---------- */
#navBanner {
  position: absolute;
  top: calc(var(--safe-top) + 62px);
  left: 12px; right: 12px;
  z-index: 6;
  background: linear-gradient(135deg, rgba(56,189,248,0.22), rgba(15,23,42,0.95));
  border: 1px solid rgba(56,189,248,0.4);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 12px 34px rgba(0,0,0,0.5);
}

/* speed limit roundel: white disc, red ring, black number (AU style) */
#speedLimit {
  flex: 0 0 auto;
  min-width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  color: #111;
  border: 4px solid #dc2626;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 17px;
  line-height: 1;
  letter-spacing: -0.5px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.45);
}
#navManeuver { font-weight: 650; font-size: 15px; }
#navDistance { color: var(--accent); font-weight: 700; white-space: nowrap; }

/* ---------- report markers ---------- */
.threat-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0;
  margin: 0;
  background: none;
  border: 0;
  cursor: pointer;

  transition: transform 0.12s ease;
}
.threat-marker:hover { transform: translateY(-2px) scale(1.08); }
.threat-marker svg { display: block; }
.threat-marker .cap {
  font: 800 9px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  letter-spacing: 0.5px;
  color: #e8eef8;
  background: rgba(6, 12, 24, 0.8);
  border: 1px solid rgba(148, 163, 184, 0.25);
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
}
.threat-marker.cat-police svg { width: 36px; height: 36px; }
.threat-marker.cat-police .cap {
  color: #bfdbfe;
  border-color: rgba(96, 165, 250, 0.55);
  background: rgba(12, 30, 62, 0.88);
}
.threat-marker.cat-camera .cap { color: #e9d5ff; border-color: rgba(192, 132, 252, 0.45); }
.threat-marker.cat-aircraft .cap {
  color: #bae6fd;
  border-color: rgba(14, 165, 233, 0.6);
  background: rgba(8, 25, 45, 0.9);
}
.threat-marker.simulated { opacity: 0.94; }

/* ---------- camera alert ---------- */
#cameraBanner {
  position: absolute;
  top: calc(var(--safe-top) + 122px);
  left: 12px;
  right: 12px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 15px;
  border-radius: 12px;
  font-weight: 650;
  font-size: 14px;
  background: rgba(251, 191, 36, 0.16);
  border: 1px solid rgba(251, 191, 36, 0.5);
  color: #fde68a;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}
#cameraBanner.near {
  background: rgba(248, 113, 113, 0.2);
  border-color: rgba(248, 113, 113, 0.65);
  color: #fecaca;
}
#cameraBanner.police {
  background: rgba(96, 165, 250, 0.2);
  border-color: rgba(96, 165, 250, 0.7);
  color: #dbeafe;
}
#cameraBanner.police strong { color: #fff; }
.cam-ico { font-size: 15px; }

.hint {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.35;
}

/* ---------- fabs ---------- */
#fabs {
  position: absolute;
  right: 12px;
  bottom: calc(var(--safe-bottom) + 16px);
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
#fabRow {
  display: flex;
  gap: 10px;
  align-items: center;
}
.fab {
  background: var(--panel-solid);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  min-width: 48px; height: 48px;
  padding: 0 16px;
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
  box-shadow: 0 10px 26px rgba(0,0,0,0.5);
}
.fab.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #05202e;
}
.fab.police {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  font-size: 19px;
  padding: 0 14px;
}
.fab.primary.stop { background: var(--bad); border-color: var(--bad); color: #2b0b0b; }

/* ---------- dialog ---------- */
dialog#settings {
  border: 1px solid var(--line);
  background: var(--panel-solid);
  color: var(--text);
  border-radius: 18px;
  padding: 0;
  width: min(440px, calc(100vw - 24px));
  max-height: 86vh;
}
dialog#settings::backdrop { background: rgba(2, 6, 18, 0.8); }
#settingsForm { padding: 18px; overflow: auto; max-height: 86vh; }
#settingsForm h2 { margin: 0 0 14px; font-size: 17px; }
#settingsForm fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px 12px;
  margin: 12px 0;
}
#settingsForm legend { padding: 0 6px; color: var(--muted); font-size: 12px; }
.row { display: flex; justify-content: space-between; align-items: center; font-size: 14px; }
.row output { color: var(--accent); font-weight: 650; }
input[type="range"] { width: 100%; margin: 8px 0 4px; accent-color: var(--accent); }
.chk { display: flex; align-items: center; gap: 9px; padding: 6px 0; font-size: 14px; }
.chk input { accent-color: var(--accent); width: 17px; height: 17px; }
.note { font-size: 12.5px; color: var(--muted); background: rgba(148,163,184,0.08); padding: 10px; border-radius: 10px; margin-top: 6px; }
.note.bad { color: var(--bad); background: rgba(248,113,113,0.1); }
.note.warn { color: var(--warn); background: rgba(251,191,36,0.1); }
.actions { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-weight: 650;
  font-size: 14px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #05202e; }

/* ---------- toast ---------- */
#toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 240px);
  transform: translateX(-50%);
  background: rgba(2, 6, 18, 0.95);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  z-index: 20;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}

/* ---------- map pins ---------- */
.pin {
  width: 26px; height: 26px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
  display: grid; place-items: center;
}
.pin span { transform: rotate(45deg); font-size: 12px; }
.me-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 0 0 8px rgba(56,189,248,0.22), 0 2px 8px rgba(0,0,0,0.6);
}

.maplibregl-popup-content {
  background: var(--panel-solid) !important;
  color: var(--text) !important;
  border: 1px solid var(--line);
  border-radius: 12px !important;
  font-size: 13px;
  padding: 10px 12px !important;
}
.maplibregl-popup-tip { border-top-color: var(--panel-solid) !important; border-bottom-color: var(--panel-solid) !important; }
.maplibregl-ctrl-attrib { font-size: 10px; }



/* Keep MapLibre's attribution clear of the button stack */
.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-bottom-right {
  bottom: calc(var(--safe-bottom) + 78px);
}
.maplibregl-ctrl-attrib {
  font-size: 10.5px;
}
