:root {
  color-scheme: dark;
  --bg: #08111d;
  --panel: rgba(5, 13, 25, 0.76);
  --panel-strong: rgba(4, 11, 21, 0.88);
  --panel-border: rgba(125, 211, 252, 0.18);
  --text: #e5eefc;
  --muted: #8ca3bd;
  --accent: #38bdf8;
  --accent-soft: #4ade80;
  --warm: #f97316;
  --warning: #fde047;
  --danger: #f87171;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", system-ui, sans-serif;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.85);
  outline-offset: 2px;
}

.playground,
.sim-viewport {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 45% 35%, rgba(56, 189, 248, 0.08), transparent 30%),
    #08111d;
}

.sim-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.loading-screen {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  color: #dbeafe;
  background:
    radial-gradient(circle at 50% 42%, rgba(56, 189, 248, 0.14), transparent 25%),
    #08111d;
  transition: opacity 280ms ease, visibility 280ms ease;
}

.loading-screen.ready {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-screen.error {
  color: #fecaca;
}

.loading-screen small {
  max-width: 460px;
  color: var(--muted);
}

.loading-progress {
  width: min(280px, 72vw);
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(125, 211, 252, 0.12);
}

.loading-progress i {
  display: block;
  width: 8%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #38bdf8, #4ade80);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.72);
  transition: width 180ms ease;
}

.loading-screen.error small {
  color: #fca5a5;
}

.loader {
  width: 30px;
  height: 30px;
  border: 2px solid rgba(125, 211, 252, 0.18);
  border-top-color: #7dd3fc;
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.feature-switch {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 40;
  display: flex;
  max-width: calc(100vw - 28px);
  gap: 7px;
  padding: 6px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scrollbar-width: none;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 999px;
  background: rgba(5, 13, 25, 0.74);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
}

.feature-switch::-webkit-scrollbar {
  display: none;
}

.feature-btn {
  flex: 0 0 auto;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: #9fb3c8;
  background: rgba(15, 23, 42, 0.74);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease;
}

.feature-btn:hover {
  color: #e0f2fe;
  border-color: rgba(148, 163, 184, 0.26);
}

.feature-btn.active {
  color: #e0f2fe;
  border-color: rgba(56, 189, 248, 0.42);
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.20), rgba(34, 197, 94, 0.12));
}

.hud {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 20;
  display: flex;
  width: min(330px, calc(100vw - 36px));
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.status-pill,
.vehicle-mode-switch,
.metric-card,
.telemetry-card,
.help-pill,
.minimap-panel {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border-radius: 999px;
  color: #e0f2fe;
  font-size: 11px;
  letter-spacing: 0.06em;
}

.status-pill #assetMode {
  color: #bae6fd;
  font-weight: 600;
}

.vehicle-mode-switch {
  display: grid;
  width: 100%;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 5px;
  padding: 5px 6px 5px 12px;
  border-radius: 13px;
  color: #64748b;
  pointer-events: auto;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.09em;
}

.vehicle-mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 82px;
  justify-content: center;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: #7890a8;
  background: rgba(15, 23, 42, 0.68);
  cursor: pointer;
  font: 700 9px "IBM Plex Mono", ui-monospace, monospace;
  letter-spacing: 0.055em;
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}

.vehicle-mode-btn i {
  width: 6px;
  height: 6px;
  border: 1px solid currentColor;
  border-radius: 50%;
  opacity: 0.7;
}

.vehicle-mode-btn:hover {
  color: #dbeafe;
  border-color: rgba(125, 211, 252, 0.28);
}

.vehicle-mode-btn.active,
.vehicle-mode-btn[aria-pressed="true"] {
  color: #e0f2fe;
  border-color: rgba(56, 189, 248, 0.46);
  background: linear-gradient(135deg, rgba(14, 116, 144, 0.34), rgba(30, 64, 175, 0.18));
}

.vehicle-mode-btn.active i,
.vehicle-mode-btn[aria-pressed="true"] i {
  border-color: #67e8f9;
  background: #22d3ee;
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.78);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-soft);
  box-shadow: 0 0 12px rgba(74, 222, 128, 0.8);
}

.hud.paused .status-dot {
  background: var(--warning);
  box-shadow: 0 0 12px rgba(253, 224, 71, 0.75);
}

.metric-card {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
  padding: 10px 12px;
  border-radius: 13px;
}

.metric {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
  color: #7890a8;
  font-size: 9px;
  text-transform: uppercase;
}

.metric strong {
  overflow: hidden;
  color: #dbeafe;
  font-size: 10px;
  font-weight: 500;
  text-overflow: ellipsis;
  text-transform: none;
  white-space: nowrap;
}

.trailer-metric {
  transition: opacity 140ms ease;
}

.hud[data-vehicle-mode="solo"] .trailer-metric {
  opacity: 0.42;
}

.hud[data-vehicle-mode="trailer"] .trailer-metric strong {
  color: #a7f3d0;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.pill-btn,
.camera-switch {
  border: 1px solid rgba(125, 211, 252, 0.28);
  border-radius: 999px;
  background: rgba(15, 31, 48, 0.82);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(14px);
}

.pill-btn {
  min-width: 84px;
  padding: 7px 13px;
  cursor: pointer;
  font: 600 10px "IBM Plex Mono", ui-monospace, monospace;
  letter-spacing: 0.05em;
}

.pill-btn.active {
  color: #fff7ed;
  border-color: rgba(249, 115, 22, 0.62);
  background: rgba(124, 45, 18, 0.62);
}

.camera-switch {
  display: flex;
  padding: 3px;
}

.camera-btn {
  padding: 4px 9px;
  border: 0;
  border-radius: 999px;
  color: #7890a8;
  background: transparent;
  cursor: pointer;
  font: 600 9px "IBM Plex Mono", ui-monospace, monospace;
}

.camera-btn.active {
  color: #e0f2fe;
  background: rgba(14, 116, 144, 0.34);
}

.telemetry-card {
  width: 100%;
  padding: 9px 10px 8px;
  border-radius: 13px;
}

.telemetry-head {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #64748b;
  font-size: 7px;
  letter-spacing: 0.07em;
}

.telemetry-head > :first-child {
  margin-right: auto;
  color: #9fb3c8;
  font-weight: 700;
}

.legend-line {
  display: inline-block;
  width: 13px;
  height: 2px;
  margin-right: 4px;
  vertical-align: middle;
  border-radius: 99px;
}

.legend-line.speed {
  background: var(--accent);
}

.legend-line.slip {
  background: var(--warning);
}

#telemetryCanvas {
  position: static;
  display: block;
  width: 100%;
  height: 63px;
  margin-top: 6px;
}

.engine-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid rgba(148, 163, 184, 0.10);
  color: #64748b;
  font-size: 7px;
  letter-spacing: 0.04em;
}

.engine-row strong {
  color: #bae6fd;
  font-weight: 600;
}

.engine-row em {
  color: #fb923c;
  font-style: normal;
}

.calibration-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  padding-top: 5px;
  color: #64748b;
  font-size: 7px;
  letter-spacing: 0.04em;
}

.calibration-row strong {
  color: #bbf7d0;
  font-weight: 600;
}

.calibration-row em {
  color: #94a3b8;
  font-style: normal;
}

.airborne .status-dot {
  background: #7dd3fc;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.92);
}

.help-pill {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 20;
  display: flex;
  max-width: calc(100vw - 294px);
  gap: 12px;
  padding: 8px 12px;
  border-radius: 999px;
  color: #a8bdd2;
  font: 500 9px "IBM Plex Mono", ui-monospace, monospace;
  pointer-events: none;
}

kbd {
  padding: 1px 4px;
  border: 1px solid rgba(148, 163, 184, 0.32);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: #e0f2fe;
  background: rgba(30, 41, 59, 0.9);
  font: inherit;
}

.minimap-panel {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  width: 238px;
  padding: 9px;
  border-radius: 16px;
  color: #dbeafe;
  background: var(--panel-strong);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.36);
  font: 500 9px "IBM Plex Mono", ui-monospace, monospace;
  user-select: none;
}

.minimap-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 1px 7px;
  letter-spacing: 0.08em;
}

.minimap-head small {
  color: #4ade80;
  font-size: 7px;
}

.friction-toggle,
.trajectory-toggle,
.map-tool {
  border: 1px solid rgba(148, 163, 184, 0.20);
  border-radius: 7px;
  color: #9fb3c8;
  background: rgba(15, 23, 42, 0.78);
  cursor: pointer;
  font: 600 8px "IBM Plex Mono", ui-monospace, monospace;
  letter-spacing: 0.04em;
}

.map-switches {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.friction-toggle,
.trajectory-toggle {
  padding: 5px 7px;
}

.trajectory-toggle.active {
  color: #cffafe;
  border-color: rgba(34, 211, 238, 0.56);
  background: rgba(8, 145, 178, 0.30);
}

.friction-toggle.active {
  color: #bbf7d0;
  border-color: rgba(74, 222, 128, 0.52);
  background: rgba(20, 83, 45, 0.42);
}

.minimap {
  position: static;
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  border-radius: 9px;
  cursor: crosshair;
  touch-action: none;
}

.planner-key {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 7px;
  padding: 6px 2px 0;
  color: #7890a8;
  font-size: 6.5px;
  letter-spacing: 0.035em;
}

.planner-key span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.planner-swatch {
  display: inline-block;
  width: 17px;
  height: 0;
  border-top: 2px solid;
}

.planner-swatch.plan {
  border-color: #22d3ee;
}

.planner-swatch.samples {
  border-color: #93c5fd;
  border-top-style: dotted;
  opacity: 0.82;
}

.planner-swatch.best {
  border-color: #f97316;
  border-top-style: dashed;
  opacity: 0.82;
}

.surface-key {
  display: flex;
  justify-content: space-between;
  gap: 5px;
  padding: 6px 2px 0;
  color: #7890a8;
  font-size: 6.5px;
}

.surface-key span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.surface {
  width: 9px;
  height: 4px;
  border-radius: 1px;
}

.surface.asphalt { background: #526171; }
.surface.wet { background: #0ea5e9; }
.surface.dust { background: #f59e0b; }
.surface.ice { background: #c4b5fd; }
.surface.gravel { background: #d6a86e; }

.map-tools {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding-top: 7px;
}

.map-tool {
  min-width: 0;
  padding: 5px 2px;
}

.map-tool:hover,
.map-tool.active {
  color: #e0f2fe;
  border-color: rgba(56, 189, 248, 0.5);
  background: rgba(14, 116, 144, 0.28);
}

.dynamics-readout {
  display: grid;
  grid-template-columns: 1fr 1fr 0.85fr;
  gap: 4px;
  margin-top: 7px;
  color: #64748b;
  font-size: 7px;
}

.dynamics-readout span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.dynamics-readout strong {
  color: #cbd5e1;
  font-size: 8px;
  font-weight: 600;
}

.adapter-note {
  margin: 7px 0 0;
  color: #60758c;
  font-size: 7px;
  line-height: 1.35;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  max-width: min(480px, calc(100vw - 32px));
  padding: 8px 13px;
  border: 1px solid rgba(56, 189, 248, 0.30);
  border-radius: 999px;
  color: #dbeafe;
  background: rgba(5, 13, 25, 0.88);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.34);
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  font: 500 9px "IBM Plex Mono", ui-monospace, monospace;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 760px) {
  .feature-switch {
    top: 8px;
    right: 8px;
    max-width: calc(100vw - 16px);
  }

  .feature-btn {
    padding: 6px 10px;
    font-size: 0.72rem;
  }

  .hud {
    top: 62px;
    left: 10px;
    width: min(290px, calc(100vw - 20px));
  }

  .metric-card {
    width: min(250px, 100%);
  }

  .vehicle-mode-switch {
    width: min(290px, 100%);
  }

  .telemetry-card {
    display: none;
  }

  .help-pill {
    display: none;
  }

  .minimap-panel {
    right: 8px;
    bottom: 8px;
    width: min(190px, calc(100vw - 16px));
    padding: 7px;
  }

  .dynamics-readout,
  .adapter-note {
    display: none;
  }
}

@media (max-width: 480px) {
  .metric-card {
    grid-template-columns: 1fr 1fr;
    width: 220px;
  }

  .surface-key {
    display: none;
  }

  .vehicle-mode-switch {
    grid-template-columns: 1fr auto auto;
    padding-left: 9px;
  }

  .vehicle-mode-btn {
    min-width: 70px;
    padding-inline: 7px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
