:root {
  --bg: #0d1024;
  --ink: #fdf6ec;
  --accent: #ff5d3b;
  --accent2: #ffcf4d;
  --good: #3ddc97;
  --panel: rgba(16, 20, 44, 0.86);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(120% 90% at 50% -10%, #1a1f47 0%, #0d1024 60%, #07091a 100%);
}

#game {
  display: block;
  background: #11162e;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04);
  border-radius: 14px;
  touch-action: none;
}

.back-link {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  z-index: 50;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 15px;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: transform 0.15s ease, background 0.15s ease;
}
.back-link:hover { transform: translateX(-2px); background: rgba(0, 0, 0, 0.5); }

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  align-items: flex-start;
  padding: 14px 18px;
  pointer-events: none;
  z-index: 20;
  font-family: 'Baloo 2', system-ui, sans-serif;
}
.hud-block { display: flex; flex-direction: column; align-items: center; line-height: 1; }
.hud-label {
  font-size: 11px;
  letter-spacing: 0.14em;
  font-weight: 700;
  opacity: 0.65;
  margin-bottom: 4px;
}
.hud-value { font-size: 26px; font-weight: 800; text-shadow: 0 2px 8px rgba(0,0,0,0.5); }
.hud-value small { font-size: 12px; font-weight: 700; opacity: 0.7; margin-left: 2px; }
.hud-speed .hud-value { color: var(--accent2); }

.nitro-wrap {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: 160px;
  text-align: center;
}
.nitro-label {
  font-size: 10px;
  letter-spacing: 0.18em;
  font-weight: 700;
  color: var(--good);
  margin-bottom: 3px;
}
.nitro-bar {
  height: 7px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
}
.nitro-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--good), #7af7c9);
  border-radius: 999px;
  box-shadow: 0 0 12px var(--good);
  transform-origin: left;
}

/* ---------- Overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}
[hidden] { display: none !important; }
.overlay {
  z-index: 40;
  background: radial-gradient(100% 100% at 50% 30%, rgba(13,16,36,0.55), rgba(7,9,26,0.9));
  backdrop-filter: blur(3px);
  animation: fade 0.3s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.panel {
  text-align: center;
  padding: 34px 38px 30px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  max-width: 360px;
  width: calc(100% - 48px);
}
.logo { font-size: 52px; margin-bottom: 4px; filter: drop-shadow(0 6px 14px rgba(255,93,59,0.4)); }
.title {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 46px;
  line-height: 0.95;
  letter-spacing: 0.01em;
  background: linear-gradient(180deg, #fff, var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 12px;
}
.title span { display: block; color: var(--accent); -webkit-text-fill-color: var(--accent); }
.howto { font-size: 15px; opacity: 0.85; margin-bottom: 22px; line-height: 1.4; }

.btn {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 21px;
  letter-spacing: 0.04em;
  color: #1a0a05;
  background: linear-gradient(180deg, var(--accent2), var(--accent));
  border: none;
  border-radius: 14px;
  padding: 15px 44px;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(255, 93, 59, 0.4);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(255, 93, 59, 0.5); }
.btn:active { transform: translateY(1px) scale(0.98); }

.best-line { margin-top: 18px; font-size: 14px; opacity: 0.8; }
.best-line strong { color: var(--accent2); font-weight: 700; }
.controls { margin-top: 8px; font-size: 12px; opacity: 0.5; }

.crash-emoji { font-size: 56px; margin-bottom: 6px; }
.over-title {
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: 36px;
  color: var(--accent);
  margin-bottom: 18px;
}
.result-grid {
  display: flex;
  gap: 28px;
  justify-content: center;
  margin-bottom: 6px;
}
.result-grid > div { display: flex; flex-direction: column; }
.r-label { font-size: 11px; letter-spacing: 0.14em; opacity: 0.6; font-weight: 600; }
.r-value {
  font-family: 'Baloo 2', sans-serif;
  font-size: 34px;
  font-weight: 800;
}
.new-best {
  color: var(--good);
  font-weight: 700;
  font-size: 16px;
  margin: 10px 0 4px;
  animation: pop 0.4s ease;
}
@keyframes pop { 0% { transform: scale(0.5); opacity: 0; } 60% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }

#over .btn { margin-top: 18px; }
.quit-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 0;
  margin-top: 14px;
  color: var(--ink);
  opacity: 0.55;
  text-decoration: none;
  font-size: 13px;
}
.quit-link:hover { opacity: 0.85; }

@media (max-width: 420px) {
  .title { font-size: 38px; }
  .panel { padding: 28px 24px; }
}

/* arcade-ui fullscreen button: the HUD is centred so top-right is clear — no offset needed */

/* ---------- Touch steer buttons ---------- */
.steer-btn {
  display: none; /* hidden by default; shown on touch devices below */
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 999;
  min-width: 72px;
  min-height: 72px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.1s ease, transform 0.08s ease;
}
.steer-btn:active { background: rgba(255, 93, 59, 0.5); transform: scale(0.92); }
.steer-left  { left:  max(18px, env(safe-area-inset-left)); }
.steer-right { right: max(18px, env(safe-area-inset-right)); }

@media (hover: none) and (pointer: coarse) {
  .steer-btn { display: inline-flex; align-items: center; justify-content: center; }
}
