:root {
  --bg: #090b10;
  --glass: rgba(12, 16, 24, 0.72);
  --glass-strong: rgba(11, 14, 21, 0.92);
  --border: rgba(255, 255, 255, 0.12);
  --text: #f3f6fb;
  --muted: #98a4b8;
  --blue: #2f8cff;
  --blue-glow: rgba(47, 140, 255, 0.45);
  --emerald: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --gold: #eab308;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  user-select: none;
}

.hidden { display: none !important; }

/* FULLSCREEN 3D STAGE */
.scene-stage, .watchdog-map-stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#tw-webgl-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#watchdog-map {
  width: 100%;
  height: 100%;
}

/* LIVE AR / REAR CAMERA */
.live-cam-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 4;
}

.ar-hud-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.ar-top-banner {
  pointer-events: auto;
  position: absolute;
  top: calc(12px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(10, 14, 22, 0.84);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.ar-reticle {
  position: absolute;
  top: 46%;
  left: 50%;
  width: 160px;
  height: 96px;
  transform: translate(-50%, -50%);
  border: 1.5px solid rgba(47, 140, 255, 0.7);
  border-radius: 14px;
  box-shadow: 0 0 24px rgba(47, 140, 255, 0.25);
}

.ar-detection-layer {
  position: absolute;
  inset: 0;
}

.ar-box {
  position: absolute;
  border: 1.5px solid var(--emerald);
  border-radius: 8px;
  background: rgba(34, 197, 94, 0.08);
  padding: 2px 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #bbf7d0;
}

/* SPATIAL 3D FLOATING PINS */
.spatial-pins-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  pointer-events: none;
  overflow: hidden;
}

.spatial-pin {
  position: absolute;
  transform: translate(-50%, -100%);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(11, 15, 24, 0.86);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.spatial-pin:hover, .spatial-pin:active {
  transform: translate(-50%, -106%) scale(1.04);
  border-color: var(--blue);
}

.spatial-pin.gold {
  border-color: rgba(234, 179, 8, 0.65);
}

.spatial-pin.peer {
  border-color: rgba(239, 68, 68, 0.8);
  background: rgba(45, 12, 16, 0.88);
}

.spatial-pin .pin-dist {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: #93c5fd;
}

.spatial-pin.peer .pin-dist {
  color: #fca5a5;
}

/* GLASS SURFACES */
.glass-panel {
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
}

.glass-panel-strong {
  background: var(--glass-strong);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--border);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

/* TOP MINIMAL TESLA-STYLE HUD */
.top-hud {
  position: fixed;
  top: calc(10px + var(--safe-top));
  left: 12px;
  right: 12px;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}

.hud-left-cluster, .hud-right-cluster {
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

.hud-right-cluster {
  align-items: flex-end;
}

.speed-card {
  padding: 9px 13px;
  border-radius: 16px;
  min-width: 112px;
}

.speed-row {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.speed-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
}

.speed-unit {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.hud-status-pill {
  margin-top: 5px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.16);
  color: #86efac;
}

.hud-status-pill.jam {
  background: rgba(239, 68, 68, 0.24);
  color: #fca5a5;
}

.hud-status-pill.info {
  background: rgba(47, 140, 255, 0.2);
  color: #93c5fd;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.turn-card {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border-radius: 14px;
  max-width: 210px;
}

.turn-icon {
  font-size: 20px;
  font-weight: 800;
  color: var(--blue);
  line-height: 1;
}

.turn-dist {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 700;
}

.turn-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

/* SEGMENTED CONTROLS */
.seg-control {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  gap: 2px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.seg-btn.active {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 2px 12px var(--blue-glow);
}

.style-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--text);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.cam-dot, .pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
}

/* TOAST */
.tw-toast {
  position: fixed;
  top: calc(118px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(14, 19, 30, 0.94);
  border: 1px solid rgba(47, 140, 255, 0.5);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
}

/* 21-LANGUAGE GUIDE MODAL */
.guide-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 14px 14px calc(86px + var(--safe-bottom));
  background: rgba(5, 8, 14, 0.45);
  backdrop-filter: blur(4px);
}

.guide-card {
  width: 100%;
  max-width: 440px;
  border-radius: 22px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guide-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.guide-header h3 {
  font-size: 18px;
  font-weight: 800;
  margin-top: 4px;
}

.muted-mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.close-x {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.guide-lang-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.guide-body {
  font-size: 13.5px;
  line-height: 1.5;
  color: #dbe4f3;
}

.street-preview-box {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
}

.street-preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.street-preview-content {
  padding: 10px;
  font-size: 12px;
  color: #cbd5e1;
}

.street-preview-content img {
  width: 100%;
  max-height: 165px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  margin-bottom: 8px;
}

.guide-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* EXPANDABLE BOTTOM SHEET */
.bottom-sheet {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(74px + var(--safe-bottom));
  max-width: 560px;
  margin: 0 auto;
  z-index: 25;
  border-radius: 20px;
  background: var(--glass-strong);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--border);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.55);
  transition: max-height 0.24s ease;
  overflow: hidden;
}

.bottom-sheet.collapsed .sheet-body {
  display: none;
}

.sheet-handle-bar {
  padding: 8px 14px 10px;
  cursor: pointer;
}

.sheet-pill-grip {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  margin: 0 auto 7px;
}

.sheet-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sheet-title {
  font-size: 13px;
  font-weight: 700;
}

.sheet-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fps-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  font-weight: 700;
  color: #86efac;
  background: rgba(34, 197, 94, 0.14);
  padding: 3px 7px;
  border-radius: 999px;
}

.sheet-body {
  max-height: 52vh;
  overflow-y: auto;
  padding: 4px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tab-panel { display: none; flex-direction: column; gap: 12px; }
.tab-panel.active { display: flex; }

.card-block {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 15px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.block-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.block-title {
  font-size: 13.5px;
  font-weight: 700;
}

.block-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

/* CONTROLS & BUTTONS */
.primary-btn, .secondary-btn, .danger-btn, .pill-btn, .chip-btn {
  border: none;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  border-radius: 11px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: transform 0.12s ease, opacity 0.15s ease;
}

.primary-btn {
  background: var(--blue);
  color: #fff;
  padding: 9px 13px;
  font-size: 12.5px;
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 13px;
  font-size: 12.5px;
}

.danger-btn {
  background: rgba(239, 68, 68, 0.9);
  color: #fff;
  padding: 9px 13px;
  font-size: 12.5px;
}

.pill-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 11.5px;
}

.pill-btn.danger {
  background: rgba(239, 68, 68, 0.25);
  border-color: rgba(239, 68, 68, 0.6);
  color: #fecaca;
}

.compact { padding: 7px 11px; font-size: 11.5px; }

.chip-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #d6e0f0;
  padding: 6px 10px;
  font-size: 11.5px;
  border-radius: 999px;
}

.chip-btn.active {
  background: rgba(47, 140, 255, 0.22);
  border-color: var(--blue);
  color: #fff;
}

.text-btn {
  border: none;
  background: none;
  color: var(--blue);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.slider-wrap input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
  margin-bottom: 8px;
}

.search-row {
  display: flex;
  gap: 6px;
}

.dark-input, .dark-select {
  flex: 1;
  background: rgba(8, 11, 18, 0.85);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  outline: none;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.micro-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.micro-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.micro-badge.blue { background: rgba(47, 140, 255, 0.16); color: #93c5fd; border-color: rgba(47, 140, 255, 0.35); }
.micro-badge.emerald { background: rgba(34, 197, 94, 0.16); color: #86efac; border-color: rgba(34, 197, 94, 0.35); }
.micro-badge.red { background: rgba(239, 68, 68, 0.18); color: #fca5a5; border-color: rgba(239, 68, 68, 0.4); }
.micro-badge.gold { background: rgba(234, 179, 8, 0.18); color: #fde047; border-color: rgba(234, 179, 8, 0.4); }

.sub-box {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tiny-note {
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--muted);
}

/* WATCHDOG METRICS */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.metric-tile {
  background: rgba(8, 11, 18, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 11px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.metric-k {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.metric-v {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 700;
}

.wd-results {
  font-size: 12px;
  line-height: 1.5;
  color: #cbd5e1;
}

.wd-pass-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  margin-top: 6px;
  font-size: 11.5px;
}

/* RADAR */
.radar-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#radar-canvas {
  width: 148px;
  height: 148px;
  border-radius: 50%;
  background: #070b12;
  border: 1px solid rgba(47, 140, 255, 0.35);
}

.radar-legend {
  flex: 1;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11.5px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.dot.red { background: var(--red); box-shadow: 0 0 8px var(--red); }
.dot.amber { background: var(--amber); }
.dot.emerald { background: var(--emerald); }

.lag-alert-box {
  margin-top: 4px;
  padding: 7px 9px;
  border-radius: 10px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.38);
  color: #fecaca;
  font-size: 11px;
  line-height: 1.4;
}

/* GARAGE */
.vehicle-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.veh-card {
  background: rgba(9, 13, 22, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 10px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.veh-card span { font-size: 12.5px; font-weight: 700; }
.veh-card small { font-size: 10.5px; color: var(--muted); }
.veh-card.active {
  border-color: var(--blue);
  background: rgba(47, 140, 255, 0.18);
}

.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.swatches {
  display: flex;
  gap: 8px;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
}

.swatch.active {
  border-color: var(--blue);
  transform: scale(1.14);
}

.tier-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tier-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 11.5px;
}

.tier-row span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tier-row small {
  color: var(--muted);
  font-size: 10.5px;
}

/* FLOATING BOTTOM DOCK */
.bottom-dock {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(10px + var(--safe-bottom));
  max-width: 560px;
  margin: 0 auto;
  z-index: 30;
  border-radius: 20px;
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.dock-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 7px 4px;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.dock-btn svg {
  width: 19px;
  height: 19px;
}

.dock-btn.active {
  background: rgba(47, 140, 255, 0.2);
  color: #fff;
}

@media (max-width: 430px) {
  .seg-btn { padding: 5px 8px; font-size: 11px; }
  .speed-val { font-size: 24px; }
  .turn-card { max-width: 168px; }
}
