:root {
  color-scheme: dark;
  --ink: #f7ead2;
  --muted: #cbbba0;
  --panel: rgba(16, 10, 28, 0.72);
  --line: rgba(240, 194, 122, 0.35);
  --gas: #2a9d8f;
  --brake: #c45c2a;
  --restart: #5b4d8a;
  --bg: #120c22;
  font-family: "Segoe UI", ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.hud {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 12px 8px;
  padding-top: max(10px, env(safe-area-inset-top));
  z-index: 2;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  min-width: 0;
  backdrop-filter: blur(8px);
}

.stat-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 2px;
}

.stat [data-testid] {
  display: block;
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-fuel .fuel-track {
  display: block;
  height: 6px;
  margin-top: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.fuel-fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #c45c2a, #f0c27a 55%, #7dffd2);
}

#app[data-status="out-of-fuel"] [data-testid="fuel-display"],
#app[data-status="crashed"] [data-testid="game-status"] {
  color: #ffb089;
}

#app[data-status="driving"] [data-testid="game-status"] {
  color: #7dffd2;
}

#app[data-fuel="low"] [data-testid="fuel-display"] {
  color: #ffb089;
}

#app[data-fuel="low"] .fuel-fill {
  background: linear-gradient(90deg, #a61b1b, #f0c27a);
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.scene-hook {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.overlay {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  background: rgba(12, 8, 22, 0.72);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 22px;
  min-width: min(78vw, 320px);
}

.overlay-title {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: 0.04em;
}

.overlay-hint {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.controls {
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
  z-index: 2;
}

.hint {
  margin: 0 0 8px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.control-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: stretch;
}

.ctl {
  appearance: none;
  border: 0;
  border-radius: 16px;
  min-height: 64px;
  color: var(--ink);
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  transition: transform 0.08s ease, filter 0.08s ease, box-shadow 0.08s ease;
}

.ctl:focus-visible {
  outline: 3px solid #f0c27a;
  outline-offset: 3px;
}

.ctl:hover {
  filter: brightness(1.08);
}

.ctl.is-pressed,
.ctl:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  filter: brightness(0.96);
}

.ctl-gas {
  background: linear-gradient(#3ec8b4, var(--gas));
}

.ctl-brake {
  background: linear-gradient(#e07a45, var(--brake));
}

.ctl-restart {
  background: linear-gradient(#7a6cb0, var(--restart));
  min-width: 108px;
  padding: 0 16px;
}

@media (max-width: 720px) {
  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stat [data-testid] {
    font-size: 16px;
  }

  .hint {
    font-size: 11px;
  }
}

@media (max-width: 420px) {
  .hud {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 8px;
  }

  .ctl {
    min-height: 56px;
    font-size: 15px;
  }

  .ctl-restart {
    min-width: 84px;
  }
}
