*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: #111;
  font-family: system-ui, -apple-system, sans-serif;
}

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

/* ── Panels ──────────────────────────────────────────────────────────────── */

.panel {
  position: absolute;
  background: rgba(12, 12, 22, 0.93);
  color: #d8d8e8;
  border: 1px solid #2a2a40;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  z-index: 10;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#layer-panel {
  top: 10px;
  left: 10px;
  min-width: 195px;
  max-width: 250px;
}

#status-panel {
  bottom: 36px;
  right: 10px;
  min-width: 215px;
  max-width: 270px;
}

.panel-btn {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: #d8d8e8;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  text-align: left;
  padding: 9px 12px;
  border-radius: 8px;
}
.panel-btn:hover { background: rgba(255, 255, 255, 0.07); }

.hidden { display: none !important; }

/* ── Layer panel body ────────────────────────────────────────────────────── */

#panel-body {
  padding: 2px 8px 10px;
  max-height: 72vh;
  overflow-y: auto;
}

.group {
  margin-bottom: 6px;
}

.group + .group {
  border-top: 1px solid #22223a;
  padding-top: 6px;
}

.group-header {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  color: #8888aa;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 4px 2px 3px;
  cursor: pointer;
  user-select: none;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 3px 2px;
  cursor: pointer;
  border-radius: 4px;
}
.layer-row:hover { background: rgba(255, 255, 255, 0.05); }
.layer-row.indented { padding-left: 16px; }

input[type="checkbox"] {
  accent-color: #5599ff;
  cursor: pointer;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 4px currentColor;
}

.zoom-badge {
  display: inline-block;
  font-size: 10px;
  color: #667;
  background: #1e1e30;
  border: 1px solid #333;
  border-radius: 3px;
  padding: 0 3px;
  vertical-align: middle;
  margin-left: 2px;
}

/* ── Feed status panel ───────────────────────────────────────────────────── */

#status-body {
  padding: 4px 0 8px;
}

.feed-row {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  gap: 5px;
  padding: 3px 12px;
  font-size: 12px;
}

.feed-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feed-time {
  color: #667;
  font-size: 11px;
  white-space: nowrap;
}

/* ── Zoom hint ───────────────────────────────────────────────────────────── */

.hint {
  position: absolute;
  bottom: 36px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(12, 12, 22, 0.92);
  color: #ffd060;
  border: 1px solid #554400;
  border-radius: 6px;
  padding: 6px 16px;
  font-size: 13px;
  z-index: 10;
  pointer-events: none;
  white-space: nowrap;
}

/* ── MapLibre popup overrides ────────────────────────────────────────────── */

.maplibregl-popup-content {
  background: rgba(12, 12, 22, 0.96) !important;
  color: #d8d8e8 !important;
  border: 1px solid #2a2a40 !important;
  border-radius: 6px !important;
  padding: 10px 12px !important;
  max-width: 290px;
  max-height: 320px;
  overflow-y: auto;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6) !important;
}

.maplibregl-popup-close-button {
  color: #667 !important;
  font-size: 16px !important;
  padding: 4px 8px !important;
}
.maplibregl-popup-close-button:hover { color: #d8d8e8 !important; }

.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #2a2a40 !important; }
.maplibregl-popup-anchor-top    .maplibregl-popup-tip { border-bottom-color: #2a2a40 !important; }
.maplibregl-popup-anchor-left   .maplibregl-popup-tip { border-right-color: #2a2a40 !important; }
.maplibregl-popup-anchor-right  .maplibregl-popup-tip { border-left-color: #2a2a40 !important; }

.popup-table {
  border-collapse: collapse;
  width: 100%;
}

.popup-table td {
  padding: 2px 4px;
  vertical-align: top;
  word-break: break-word;
}

.popup-table .pk {
  font-weight: 600;
  color: #6688aa;
  white-space: nowrap;
  padding-right: 10px;
}

/* ── MSI matrix sign gantry markers (RWS rijstrooksignalering style) ────── */

.msi-gantry {
  display: flex;
  gap: 3px;
  background: #0d0d0d;
  padding: 4px;
  border-radius: 4px;
  border: 2px solid #3a3a3a;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
  transform-origin: center center;  /* zoom-scaling pivots on the marker point */
}
.msi-gantry:hover { border-color: #777; }

.msi-lane {
  width: 40px;
  height: 40px;
  background: #0d0d0d;
  border: 1px solid #1c1c1c;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  position: relative;
  overflow: hidden;
}

/* Speed limit: lit digits on the black sign (no fill). Red ring only when
   mandatory (red_ring=true). */
.msi-speed-disc {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  border: 3px solid transparent;  /* reserve space; ring shown via .ringed */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  color: #fff;
  line-height: 1;
  font-family: Arial, sans-serif;
}
.msi-speed-disc.ringed { border-color: #cc0000; }

/* Lane open: green downward arrow */
.msi-lane.lane-open  { color: #00cc00; font-size: 26px; line-height: 1; }

/* Lane closed: solid red X */
.msi-lane.lane-closed { color: #ff1111; font-size: 26px; font-weight: 900; line-height: 1; }

/* Merge / lane-closing: white diagonal arrow toward the open lane */
.msi-lane.lane-merge { color: #fff; font-size: 26px; font-weight: 900; line-height: 1; }

/* Flashing lamps: 4 amber corner dots. Top pair → off → bottom pair → off.
   The lit symbol underneath stays steady; only the lamps cycle. */
.msi-lamp {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffd24d;
  box-shadow: 0 0 4px #ffb300;
  opacity: 0;
  pointer-events: none;
}
.msi-lamp.tl { top: 2px; left: 2px; }
.msi-lamp.tr { top: 2px; right: 2px; }
.msi-lamp.bl { bottom: 2px; left: 2px; }
.msi-lamp.br { bottom: 2px; right: 2px; }
.msi-lamp.top    { animation: msi-lamp-top 1.2s linear infinite; }
.msi-lamp.bottom { animation: msi-lamp-bottom 1.2s linear infinite; }

@keyframes msi-lamp-top {
  0%, 24.9%  { opacity: 1; }
  25%, 100%  { opacity: 0; }
}
@keyframes msi-lamp-bottom {
  0%, 49.9%  { opacity: 0; }
  50%, 74.9% { opacity: 1; }
  75%, 100%  { opacity: 0; }
}

/* End of restriction: light-grey ring with a diagonal slash (no fill) */
.msi-end-disc {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid #cfcfcf;
  position: relative;
  overflow: hidden;
}
.msi-end-disc::after {
  content: '';
  position: absolute;
  left: 50%;
  top: -10%;
  width: 3px;
  height: 120%;
  background: #cfcfcf;
  transform: translateX(-50%) rotate(-45deg);  /* lower-left → upper-right slash */
}

/* Blank / sign off: nearly invisible dark square */
.msi-lane.blank { background: #080808; border-color: #111; }

/* ── Traffic speed site markers ─────────────────────────────────────────── */

.speed-site {
  display: flex;
  gap: 2px;
  background: rgba(0,0,0,0.7);
  padding: 2px;
  border-radius: 3px;
  border: 1px solid #555;
  cursor: pointer;
  transform-origin: center center;
}
.speed-site:hover { border-color: #aaa; }

.speed-lane {
  width: 24px;
  height: 24px;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: bold;
  user-select: none;
}

/* ── Scrollbar (dark theme) ──────────────────────────────────────────────── */

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2a40; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a58; }

/* ── Floating Map Controls ────────────────────────────────────────────────── */

#map-controls {
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px;
}

.control-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: #8888aa;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 6px;
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.control-btn:active {
  transform: scale(0.9);
}

/* GPS Button States */
#gps-btn.state-off {
  color: #8888aa;
}

#gps-btn.state-follow {
  color: #3897ff;
  filter: drop-shadow(0 0 6px rgba(56, 151, 255, 0.6));
}

#gps-btn.state-navigation {
  color: #34c759;
  filter: drop-shadow(0 0 6px rgba(52, 199, 89, 0.6));
}

/* Compass needle rotation */
#compass-needle {
  transform: rotate(var(--bearing, 0deg));
  transform-origin: center center;
  transition: transform 0.15s cubic-bezier(0.25, 0.8, 0.25, 1);
}

/* Re-center Pill Button */
#recenter-btn {
  position: absolute !important;
  top: 15px !important;
  bottom: auto !important;
  height: auto !important;
  pointer-events: auto !important;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  background: rgba(12, 12, 22, 0.95);
  color: #3897ff;
  border: 1px solid #2a2a40;
  border-radius: 20px;
  padding: 8px 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#recenter-btn:hover {
  background: rgba(56, 151, 255, 0.12);
  border-color: #3897ff;
  box-shadow: 0 4px 20px rgba(56, 151, 255, 0.25);
  transform: translateX(-50%) translateY(-1px);
}

#recenter-btn:active {
  transform: translateX(-50%) scale(0.96);
}

/* ── Pulse GPS User Marker ────────────────────────────────────────────────── */

.user-marker-container {
  position: relative;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-dot {
  width: 14px;
  height: 14px;
  background: #3897ff;
  border: 2px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

.user-pulse {
  position: absolute;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(56, 151, 255, 0.2);
  border: 1px solid rgba(56, 151, 255, 0.4);
  animation: gps-pulse 2.2s infinite cubic-bezier(0.1, 0.8, 0.3, 1);
  z-index: 1;
  pointer-events: none;
}

@keyframes gps-pulse {
  0% {
    transform: scale(0.5);
    opacity: 0.9;
  }
  100% {
    transform: scale(2.0);
    opacity: 0;
  }
}

/* Directional heading cone */
.user-heading-cone {
  position: absolute;
  width: 90px;
  height: 90px;
  background: conic-gradient(from 330deg, transparent 0deg, rgba(56, 151, 255, 0.35) 30deg, transparent 60deg);
  transform: rotate(var(--heading, 0deg));
  transform-origin: center center;
  border-radius: 50%;
  z-index: 0;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.user-heading-cone.visible {
  opacity: 1;
}

/* ── Drive HUD page (/drive) ─────────────────────────────────────────────────── */

body.drive {
  color: #e6e6f0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

#drive-status {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: #0a0a12;
  border-bottom: 1px solid #23233a;
}

#drive-gps-btn {
  font: 700 13px/1 system-ui, sans-serif;
  color: #fff;
  border: none;
  border-radius: 20px;
  padding: 10px 16px;
  cursor: pointer;
}
#drive-gps-btn.state-off { background: #444; }
#drive-gps-btn.state-on  { background: #1e8e3e; }

#drive-speed-readout { display: flex; align-items: baseline; gap: 4px; }
#drive-kmh { font-size: 30px; font-weight: 800; }
#drive-speed-readout small { color: #8888a0; font-size: 12px; }

#drive-road { flex: 1; text-align: right; color: #aab; font-size: 14px; }

#drive-flags .flag { opacity: 0.25; font-size: 18px; }
#drive-flags .flag.active { opacity: 1; color: #ffd24d; }

#drive-banner {
  background: #b35900;
  color: #fff;
  padding: 8px 14px;
  font-size: 13px;
  text-align: center;
}

#drive-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
}

.hud-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #777790;
  margin-bottom: 8px;
}

.hud-empty { color: #66667e; font-size: 14px; padding: 6px 0; }
.hud-meta  { color: #8888a0; font-size: 13px; margin-top: 8px; }

/* Per-lane measured-speed strip */
.speed-strip { display: flex; gap: 8px; }
.speed-tile {
  flex: 1;
  min-width: 56px;
  height: 72px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.speed-tile b { font-size: 32px; font-weight: 800; }

/* Cards */
.hud-card {
  background: #15151f;
  border: 1px solid #26263c;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 10px;
}
.hud-card.passed { opacity: 0.5; }

.hud-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.hud-road { font-size: 15px; font-weight: 700; color: #dfe; }
.hud-dist { font-size: 16px; font-weight: 800; color: #ffd24d; }

.hud-gantry-wrap { display: flex; justify-content: center; }
#hud-passed .hud-gantry-wrap { transform: scale(0.8); transform-origin: left center; }

.hud-drip-img {
  max-width: 100%;
  display: block;
  border-radius: 6px;
  image-rendering: pixelated;
  background: #000;
}

#hud-passed { margin-top: 4px; }
