:root {
  --sky-top: #3aa0e8;
  --ink: #1c2733;
  --ink-soft: #51606f;
  --panel: rgba(18, 26, 38, 0.82);
  --panel-line: rgba(255, 255, 255, 0.14);
  --accent: #ff6a3d;
  --accent-2: #ffd23f;
  --good: #4f9a3d;
  --bad: #e63946;
  --gas: #ff6a3d;
  --brake: #3f7bd6;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #0e1620;
  color: #fff;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 1100px;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background:
    radial-gradient(1200px 500px at 50% -10%, #1b3a52, transparent),
    linear-gradient(180deg, #0e1620, #0a1018);
}

/* ---------- HUD ---------- */
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

.hud-left,
.hud-right {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.hud-right {
  justify-content: flex-end;
}

.stat {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  min-width: 64px;
}
.stat-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  color: rgba(255, 255, 255, 0.6);
}
.stat-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #fff;
}

.hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.status-badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  background: rgba(79, 154, 61, 0.25);
  color: #cdeec0;
  border: 1px solid rgba(116, 195, 101, 0.5);
  white-space: nowrap;
}
.status-badge[data-state='crashed'] {
  background: rgba(230, 57, 70, 0.25);
  color: #ffd0d4;
  border-color: rgba(230, 57, 70, 0.6);
}
.status-badge[data-state='outoffuel'] {
  background: rgba(255, 159, 28, 0.22);
  color: #ffe2ad;
  border-color: rgba(255, 159, 28, 0.6);
}
.seed {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}
.seed-value {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #cfe8ff;
}

.fuel {
  min-width: 92px;
}
.fuel-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
}
.fuel-track {
  margin-top: 4px;
  height: 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.12);
}
.fuel-bar {
  height: 100%;
  width: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6ed086, #4f9a3d);
  transition: width 0.12s linear;
}
.fuel-bar.low {
  background: linear-gradient(90deg, #ffb347, #e63946);
}

/* ---------- Stage / canvas ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 240px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow);
  background: #7cc4f2;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hint {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  padding: 4px 10px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(0, 0, 0, 0.3);
  border-radius: 999px;
  pointer-events: none;
  white-space: nowrap;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 14, 22, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.overlay.is-visible {
  opacity: 1;
}
.overlay-card {
  text-align: center;
  padding: 18px 26px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  box-shadow: var(--shadow);
}
.overlay-title {
  font-size: 28px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.02em;
}
.overlay-hint {
  margin-top: 6px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
}

/* ---------- Controls ---------- */
.controls {
  display: grid;
  grid-template-columns: 1fr auto auto 1fr;
  gap: 8px;
}
.ctrl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 58px;
  padding: 0 16px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.06s ease, filter 0.1s ease, box-shadow 0.1s ease;
  box-shadow: var(--shadow);
}
.ctrl .ctrl-arrow {
  font-size: 14px;
}
.ctrl-gas {
  background: linear-gradient(180deg, #ff7d52, #e8542a);
}
.ctrl-brake {
  background: linear-gradient(180deg, #4f86db, #2f59b0);
}
.ctrl-restart {
  background: linear-gradient(180deg, #3a4658, #28323f);
}
.ctrl-secondary {
  background: linear-gradient(180deg, #2c3a4c, #1d2733);
  font-size: 14px;
  min-width: 92px;
}
.ctrl:hover {
  filter: brightness(1.06);
}
.ctrl:focus-visible {
  outline: 3px solid #ffd23f;
  outline-offset: 2px;
}
.ctrl.is-pressed {
  transform: translateY(2px) scale(0.985);
  filter: brightness(1.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ---------- A11y helper ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hook-error {
  margin: 24px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(230, 57, 70, 0.15);
  border: 1px solid rgba(230, 57, 70, 0.6);
  color: #ffd0d4;
}

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  .app {
    padding: 6px;
    gap: 6px;
  }
  .hud {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 8px;
  }
  .hud-center {
    grid-column: 1 / -1;
    order: -1;
    flex-direction: row;
    justify-content: space-between;
    gap: 10px;
  }
  .stat-value {
    font-size: 15px;
  }
  .stat {
    min-width: 0;
  }
  .fuel {
    min-width: 0;
    flex: 1;
  }
  .ctrl {
    min-height: 64px;
    padding: 0 10px;
    font-size: 15px;
  }
  .ctrl-secondary {
    display: none;
  }
  .controls {
    grid-template-columns: 1fr auto 1fr;
  }
  .hint {
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .fuel-bar,
  .overlay {
    transition: none;
  }
}
