:root {
  --bg: #0a1118;
  --map: #101923;
  --panel: #131e29;
  --panel-strong: #172433;
  --panel-soft: #1b2a38;
  --text: #e8eef6;
  --muted: #8fa2b8;
  --line: rgba(151, 176, 199, 0.14);
  --road: #313d51;
  --road-edge: #44536b;
  --accent: #7bc6ff;
  --accent-strong: #aee4ff;
  --finish: #ffd359;
  --car: #ff5c7c;
  --brake: #ff8f7f;
  --good: #7af6a1;
  --bad: #ff9d9d;
  --shadow: 0 22px 48px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(79, 103, 128, 0.16), transparent 34%),
    linear-gradient(180deg, #081018 0%, #0b121a 100%);
  color: var(--text);
  font-family: "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  overscroll-behavior: none;
}

button,
input,
canvas {
  font: inherit;
}

#app {
  position: relative;
  width: min(100vw, 560px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  background: var(--bg);
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.mapPane {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--map);
  border-bottom: 1px solid var(--line);
}

canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.mapTopBar {
  position: absolute;
  inset: max(12px, env(safe-area-inset-top)) 12px auto 12px;
  z-index: 12;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 12px;
  pointer-events: none;
}

.mapActions {
  pointer-events: auto;
}

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

.mapActions button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  width: 46px;
  height: 46px;
  padding: 0;
  background: rgba(13, 20, 28, 0.8);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(12px);
  touch-action: manipulation;
}

.mapActions button:active {
  transform: translateY(1px);
}

.attrib {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 11;
  max-width: calc(100% - 24px);
  padding: 9px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(9, 13, 18, 0.84);
  color: var(--muted);
  font-size: 11px;
  backdrop-filter: blur(10px);
}

.attrib a {
  color: var(--accent-strong);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 15;
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(9, 13, 18, 0.92);
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  font-size: 13px;
  font-weight: 800;
}

.toast.show {
  opacity: 1;
}

.dashboard {
  display: grid;
  grid-template-columns: 1fr 1.15fr 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 9px;
  background:
    linear-gradient(180deg, rgba(21, 31, 44, 0.98) 0%, rgba(18, 28, 40, 0.98) 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid var(--line);
}

.telemetryCard {
  min-width: 0;
  display: grid;
  justify-items: center;
  align-items: center;
  gap: 4px;
}

.telemetryCardCenter {
  gap: 3px;
  text-align: center;
}

.telemetryLabel {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.cityName {
  max-width: 100%;
  font-size: clamp(14px, 3vw, 17px);
  font-weight: 800;
  line-height: 1.2;
  text-wrap: balance;
}

.timeReadout {
  font-size: clamp(22px, 5vw, 30px);
  font-weight: 300;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.timeCaption {
  color: var(--muted);
  font-size: 11px;
}

.speedometer {
  --needle-rot: -88deg;
  --gauge-center-y: 64%;
  --tick-radius: clamp(30px, 7vw, 40px);
  position: relative;
  width: min(25vw, 124px);
  aspect-ratio: 1.3 / 1;
}

.speedArc {
  position: absolute;
  left: 50%;
  top: 10%;
  width: 86%;
  aspect-ratio: 2 / 1;
  transform: translateX(-50%);
  border-radius: 999px 999px 0 0;
  background:
    radial-gradient(circle at 50% 112%, rgba(49, 61, 81, 0.28), rgba(49, 61, 81, 0.08) 42%, rgba(16, 25, 35, 0.04) 68%, transparent 100%),
    linear-gradient(180deg, rgba(26, 39, 54, 0.92) 0%, rgba(17, 27, 37, 0.98) 100%);
  box-shadow:
    inset 0 -18px 26px rgba(0, 0, 0, 0.26),
    inset 0 10px 18px rgba(255, 255, 255, 0.02);
}

.speedTicks {
  position: absolute;
  inset: 0;
}

.tick {
  position: absolute;
  left: 50%;
  top: var(--gauge-center-y);
  width: 4px;
  height: 12px;
  border-radius: 999px;
  background: var(--accent-strong);
  transform-origin: 50% 50%;
  box-shadow: 0 0 14px rgba(123, 198, 255, 0.22);
}

.tick1 { transform: translate(-50%, -50%) rotate(-62deg) translateY(calc(-1 * var(--tick-radius))); }
.tick2 { transform: translate(-50%, -50%) rotate(-34deg) translateY(calc(-1 * var(--tick-radius))); }
.tick3 { transform: translate(-50%, -50%) rotate(0deg) translateY(calc(-1 * var(--tick-radius))); }
.tick4 { transform: translate(-50%, -50%) rotate(34deg) translateY(calc(-1 * var(--tick-radius))); }
.tick5 { transform: translate(-50%, -50%) rotate(62deg) translateY(calc(-1 * var(--tick-radius))); }

.speedNeedle {
  position: absolute;
  left: 50%;
  top: var(--gauge-center-y);
  width: 5px;
  height: 40%;
  border-radius: 999px;
  transform: translate(-50%, -100%) rotate(var(--needle-rot));
  transform-origin: 50% 100%;
  background: linear-gradient(180deg, #f7fdff 0%, var(--accent) 66%, rgba(123, 198, 255, 0.55) 100%);
  box-shadow:
    0 0 18px rgba(123, 198, 255, 0.35),
    0 0 8px rgba(123, 198, 255, 0.22);
}

.speedHub {
  position: absolute;
  left: 50%;
  top: var(--gauge-center-y);
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow:
    0 0 0 5px rgba(17, 27, 37, 0.94),
    0 0 18px rgba(123, 198, 255, 0.28);
}

.compassDial {
  position: relative;
  width: min(19vw, 82px);
  aspect-ratio: 1;
}

.compassRing {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    radial-gradient(circle at center, rgba(255, 255, 255, 0.06), transparent 62%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  box-shadow: inset 0 0 22px rgba(0, 0, 0, 0.28);
}

.compassArrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 52px;
  transform-origin: 50% 50%;
  clip-path: polygon(50% 0%, 90% 36%, 64% 36%, 64% 100%, 36% 100%, 36% 36%, 10% 36%);
  background: linear-gradient(180deg, #fff0a8 0%, var(--finish) 100%);
  box-shadow:
    0 0 22px rgba(255, 211, 89, 0.26),
    inset 0 -10px 14px rgba(0, 0, 0, 0.16);
}

.compassDistance {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  z-index: 2;
  min-width: 40px;
  padding: 4px 6px;
  border-radius: 999px;
  background: rgba(9, 13, 18, 0.76);
  color: var(--text);
  font-size: clamp(13px, 3.2vw, 16px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-align: center;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.controlsDock {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, rgba(17, 25, 35, 0.98) 0%, rgba(12, 19, 28, 0.98) 100%);
}

.controlCluster {
  display: flex;
  justify-content: center;
  gap: 12px;
  min-width: 0;
}

.controlCluster.gears {
  display: grid;
  gap: 8px;
}

.controlBtn {
  appearance: none;
  width: min(18vw, 92px);
  aspect-ratio: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2px solid rgba(152, 178, 202, 0.22);
  background:
    radial-gradient(circle at 32% 24%, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0) 36%),
    linear-gradient(180deg, var(--panel-soft) 0%, var(--panel) 100%);
  color: var(--text);
  font-size: clamp(18px, 4vw, 22px);
  font-weight: 800;
  letter-spacing: 0.14em;
  box-shadow:
    inset 0 -10px 24px rgba(0, 0, 0, 0.22),
    0 12px 26px rgba(0, 0, 0, 0.2);
  touch-action: manipulation;
  user-select: none;
}

.controlCluster.gears .controlBtn {
  width: min(13vw, 64px);
}

.controlText {
  font-size: clamp(22px, 5vw, 28px);
  font-weight: 900;
  letter-spacing: 0.08em;
}

.controlIcon {
  width: clamp(30px, 7vw, 38px);
  height: clamp(30px, 7vw, 38px);
  display: block;
  fill: currentColor;
}

.controlCluster.gears .controlIcon {
  width: clamp(22px, 5vw, 28px);
  height: clamp(22px, 5vw, 28px);
}

.controlIconReset {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.controlBtn.is-active,
.controlBtn.is-selected {
  transform: scale(0.97);
}

.controlBtnGas {
  border-color: rgba(122, 246, 161, 0.34);
  background:
    radial-gradient(circle at 36% 24%, rgba(189, 255, 211, 0.16), rgba(0, 0, 0, 0) 42%),
    linear-gradient(180deg, rgba(30, 72, 49, 0.98) 0%, rgba(16, 44, 29, 0.98) 100%);
  color: #edfff3;
}

.controlBtnGas.is-active {
  border-color: rgba(122, 246, 161, 0.58);
  background:
    radial-gradient(circle at 36% 24%, rgba(204, 255, 221, 0.3), rgba(0, 0, 0, 0) 42%),
    linear-gradient(180deg, rgba(41, 100, 69, 0.98) 0%, rgba(20, 59, 39, 0.98) 100%);
  box-shadow:
    inset 0 -12px 22px rgba(0, 0, 0, 0.18),
    0 0 0 1px rgba(122, 246, 161, 0.18),
    0 0 28px rgba(122, 246, 161, 0.2);
}

.controlBtnBrake {
  border-color: rgba(255, 130, 130, 0.34);
  background:
    radial-gradient(circle at 36% 24%, rgba(255, 196, 196, 0.14), rgba(0, 0, 0, 0) 42%),
    linear-gradient(180deg, rgba(100, 35, 38, 0.98) 0%, rgba(57, 18, 21, 0.98) 100%);
  color: #fff1f1;
}

.controlBtnBrake.is-active {
  border-color: rgba(255, 130, 130, 0.58);
  background:
    radial-gradient(circle at 36% 24%, rgba(255, 214, 214, 0.24), rgba(0, 0, 0, 0) 42%),
    linear-gradient(180deg, rgba(132, 43, 49, 0.98) 0%, rgba(73, 24, 29, 0.98) 100%);
  box-shadow:
    inset 0 -12px 22px rgba(0, 0, 0, 0.18),
    0 0 0 1px rgba(255, 130, 130, 0.18),
    0 0 24px rgba(255, 130, 130, 0.18);
}

.controlBtnSteer.is-active {
  border-color: rgba(174, 228, 255, 0.42);
  background:
    radial-gradient(circle at 36% 24%, rgba(174, 228, 255, 0.18), rgba(0, 0, 0, 0) 40%),
    linear-gradient(180deg, rgba(35, 49, 66, 0.98) 0%, rgba(21, 31, 44, 0.98) 100%);
}

.controlBtnGear.is-selected {
  border-color: rgba(255, 211, 89, 0.44);
  background:
    radial-gradient(circle at 36% 24%, rgba(255, 240, 168, 0.22), rgba(0, 0, 0, 0) 42%),
    linear-gradient(180deg, rgba(61, 60, 39, 0.98) 0%, rgba(34, 34, 24, 0.98) 100%);
  color: #fff1c4;
}

.finishOverlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(7, 11, 16, 0.48);
  backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.finishOverlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.finishCard {
  width: min(100%, 320px);
  padding: 20px 18px 18px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    radial-gradient(circle at top, rgba(255, 211, 89, 0.16), transparent 36%),
    linear-gradient(180deg, rgba(19, 30, 41, 0.98) 0%, rgba(13, 20, 28, 0.98) 100%);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.34);
  text-align: center;
}

.finishEyebrow {
  color: var(--finish);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.finishTitle {
  margin-top: 8px;
  font-size: clamp(28px, 7vw, 36px);
  font-weight: 800;
  line-height: 1.05;
  text-wrap: balance;
}

.finishStats {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.finishStat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.finishStatLabel {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.finishStatValue {
  font-size: 19px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.finishButton {
  appearance: none;
  width: 100%;
  margin-top: 16px;
  padding: 13px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 211, 89, 0.3);
  background:
    radial-gradient(circle at top, rgba(255, 240, 168, 0.2), transparent 50%),
    linear-gradient(180deg, rgba(72, 63, 30, 0.96) 0%, rgba(43, 35, 17, 0.98) 100%);
  color: #fff4ce;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow:
    inset 0 -10px 18px rgba(0, 0, 0, 0.22),
    0 12px 24px rgba(0, 0, 0, 0.22);
}

.finishButton:active {
  transform: scale(0.98);
}

.srOnly {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 430px) {
  .mapTopBar {
    inset: max(10px, env(safe-area-inset-top)) 10px auto 10px;
  }

  .mapActions button {
    width: 42px;
    height: 42px;
  }

  .dashboard {
    gap: 7px;
    padding: 9px 10px 8px;
  }

  .controlsDock {
    gap: 8px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }

  .controlCluster {
    gap: 9px;
  }

  .controlCluster.gears .controlBtn {
    width: min(12vw, 56px);
  }

  .finishCard {
    padding: 18px 16px 16px;
  }
}
