:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #081222;
  color: #effbff;
  --cyan: #53e7f7;
  --pink: #ff56b6;
  --yellow: #ffe46b;
  --panel: rgba(5, 13, 27, 0.72);
  --line: rgba(145, 220, 240, 0.28);
}

* {
  box-sizing: border-box;
}

html,
body,
.game-shell {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(circle at 50% 25%, rgba(42, 99, 130, 0.32), transparent 48%),
    #081222;
}

.game-shell {
  position: relative;
  isolation: isolate;
}

#flown-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  background: #081222;
}

.hud {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.hud-top {
  top: max(18px, env(safe-area-inset-top));
  left: max(22px, env(safe-area-inset-left));
  right: max(22px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.identity {
  filter: drop-shadow(0 4px 18px rgba(0, 0, 0, 0.7));
}

.eyebrow {
  display: block;
  margin-bottom: 1px;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.24em;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 62px);
  font-style: italic;
  font-weight: 950;
  letter-spacing: -0.075em;
  line-height: 0.9;
  text-shadow: 3px 3px 0 var(--pink);
}

.actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

button {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: var(--panel);
  color: #effbff;
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.04em;
  backdrop-filter: blur(12px);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

button:hover,
button:focus-visible,
button[data-pressed="true"] {
  border-color: var(--cyan);
  background: rgba(24, 78, 94, 0.82);
  outline: none;
}

kbd {
  color: var(--yellow);
  font: inherit;
  font-size: 0.85em;
}

.telemetry {
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 44px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  background: var(--panel);
  color: rgba(235, 250, 255, 0.82);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  white-space: nowrap;
  opacity: 0.68;
  backdrop-filter: blur(12px);
}

.race-panel {
  top: max(104px, calc(env(safe-area-inset-top) + 84px));
  left: max(22px, env(safe-area-inset-left));
  width: 230px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  background: linear-gradient(145deg, rgba(5, 13, 27, 0.86), rgba(8, 31, 49, 0.68));
  backdrop-filter: blur(12px);
}

.track-line,
.lap-line,
.energy-line,
.speed-line {
  display: flex;
  align-items: baseline;
}

.track-line {
  justify-content: space-between;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.13em;
}

#surface {
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 2px 4px;
  color: rgba(235, 250, 255, 0.64);
  font-size: 8px;
}

#surface[data-surface="ROUGH"] {
  color: #ef9c60;
}

#surface[data-surface="RECHARGE"] {
  color: #55f5d5;
}

.lap-line {
  gap: 7px;
  margin-top: 6px;
}

.hud-label {
  color: rgba(235, 250, 255, 0.66);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

#lap {
  color: white;
  font-size: 36px;
  font-style: italic;
  line-height: 1;
}

#sector {
  margin-left: auto;
  color: var(--yellow);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.timing {
  display: grid;
  gap: 3px;
  margin: 8px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.timing div {
  display: flex;
  justify-content: space-between;
}

.timing dt {
  color: rgba(235, 250, 255, 0.48);
  font-size: 9px;
  letter-spacing: 0.1em;
}

.timing dd {
  margin: 0;
  color: rgba(245, 253, 255, 0.88);
  font-size: 11px;
}

.speed-panel {
  top: max(104px, calc(env(safe-area-inset-top) + 84px));
  right: max(22px, env(safe-area-inset-right));
  width: min(250px, calc(100% - 44px));
  text-align: right;
  filter: drop-shadow(0 3px 12px rgba(0, 0, 0, 0.8));
}

.speed-line {
  justify-content: flex-end;
  gap: 7px;
}

#speed {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: clamp(36px, 6vw, 68px);
  font-style: italic;
  line-height: 0.9;
  text-shadow: 2px 2px 0 var(--pink);
}

.speed-line span {
  color: var(--cyan);
  font-size: 10px;
  font-weight: 900;
}

.energy-line {
  justify-content: flex-end;
  gap: 7px;
  margin-top: 9px;
  color: rgba(235, 250, 255, 0.7);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.energy-track {
  width: 110px;
  height: 7px;
  overflow: hidden;
  border: 1px solid rgba(83, 231, 247, 0.42);
  transform: skewX(-16deg);
  background: rgba(0, 0, 0, 0.42);
}

#energy-fill {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--pink), var(--cyan));
  box-shadow: 0 0 8px var(--cyan);
  transition: width 100ms linear;
}

.live-dot {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #aeb8c5;
  box-shadow: 0 0 10px currentColor;
}

#status[data-state="running"] + .live-dot,
.telemetry:has(#status[data-state="running"]) .live-dot {
  color: var(--cyan);
  background: var(--cyan);
}

.telemetry:has(#status[data-state="error"]) .live-dot {
  color: #ff6e81;
  background: #ff6e81;
}

.help {
  right: max(22px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  gap: 18px;
  color: rgba(235, 250, 255, 0.68);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 8px #000;
}

.touch-controls {
  position: absolute;
  z-index: 3;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  left: max(16px, env(safe-area-inset-left));
  display: none;
  justify-content: space-between;
  pointer-events: none;
}

.touch-cluster {
  display: flex;
  align-items: end;
  gap: 8px;
  pointer-events: auto;
}

.touch-controls button {
  width: 58px;
  height: 58px;
  padding: 0;
  border-radius: 18px;
  background: rgba(5, 13, 27, 0.58);
  touch-action: none;
  transition: transform 70ms ease, background 70ms ease, box-shadow 70ms ease;
  -webkit-tap-highlight-color: transparent;
}

.touch-controls .boost {
  border-color: rgba(255, 86, 182, 0.62);
}

.touch-controls .throttle {
  width: 68px;
  height: 76px;
  border-color: rgba(83, 231, 247, 0.62);
}

.touch-controls button[data-pressed="true"] {
  transform: translateY(3px) scale(0.96);
  box-shadow: 0 0 22px rgba(83, 231, 247, 0.42);
}

.touch-controls .throttle[data-pressed="true"] {
  border-color: #baf9ff;
  background: rgba(38, 199, 216, 0.92);
  color: #03131a;
  box-shadow:
    0 0 0 4px rgba(83, 231, 247, 0.22),
    0 0 34px rgba(83, 231, 247, 0.72);
}

#unsupported {
  position: absolute;
  z-index: 5;
  top: 50%;
  left: 50%;
  display: flex;
  width: min(440px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  flex-direction: column;
  gap: 8px;
  border: 1px solid rgba(255, 110, 129, 0.7);
  border-radius: 12px;
  padding: 22px;
  background: rgba(12, 18, 32, 0.94);
  box-shadow: 0 18px 80px rgba(0, 0, 0, 0.55);
}

#unsupported[hidden] {
  display: none;
}

@media (pointer: coarse), (max-width: 700px) {
  .touch-controls {
    display: flex;
  }

  .help {
    display: none;
  }

  .actions button kbd {
    display: none;
  }

  .telemetry {
    display: none;
  }

  .race-panel {
    top: max(80px, calc(env(safe-area-inset-top) + 62px));
    width: 165px;
    padding: 8px 9px;
  }

  .track-line {
    font-size: 8px;
  }

  #lap {
    font-size: 27px;
  }

  .timing {
    margin-top: 4px;
  }

  .speed-panel {
    top: max(82px, calc(env(safe-area-inset-top) + 64px));
    width: 145px;
  }

  #speed {
    font-size: 38px;
  }

  .energy-track {
    width: 62px;
  }
}
