/* =========================================================
   CAR RACING — Premium UI Stylesheet
   Glassmorphism HUD/menus layered over a Phaser <canvas>.
   ========================================================= */

:root {
  --purple: #7C5CFC;
  --red: #FF6B5C;
  --teal: #4ECDC4;
  --gold: #f5c451;
  --bg: #0a0b18;
  --bg2: #0D0E1F;
  --text: #F5F3FF;
  --text-dim: #A8A5C4;
  --glass-bg: rgba(255, 255, 255, 0.07);
  --glass-border: rgba(255, 255, 255, 0.14);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }

html, body {
  margin: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Segoe UI', 'Chakra Petch', sans-serif;
  touch-action: none;
  overscroll-behavior: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#game-container {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

#game-container canvas {
  max-width: 100%;
  max-height: 100%;
}

/* ---------- Glass primitive ---------- */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid var(--glass-border);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.4);
}

/* ---------- Full-screen menu panels ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  color: var(--text);
  background: radial-gradient(circle at 50% 20%, #1a1c3a 0%, var(--bg) 70%);
  transition: opacity 0.25s ease;
}
.screen.hidden { display: none; }

.logo {
  font-size: clamp(28px, 8vw, 44px);
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--text);
  text-shadow: 0 0 24px rgba(124, 92, 252, 0.6);
}
.logo span { color: var(--red); }

.subtitle { color: var(--text-dim); font-size: 14px; letter-spacing: 3px; text-transform: uppercase; margin-top: -8px; }

.best-badge {
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--gold);
}

.instructions {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.8;
}
.instructions strong { color: var(--teal); }

.footer-row { margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 999px;
  padding: 14px 34px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  min-width: 220px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}
.btn:active { transform: scale(0.94); }
.btn-primary {
  background: linear-gradient(135deg, var(--purple), #9b7bff);
  color: #fff;
  box-shadow: 0 6px 22px rgba(124, 92, 252, 0.5);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--glass-border);
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease;
  flex-shrink: 0;
}
.icon-btn:active { transform: scale(0.88); }

/* ---------- Loading screen ---------- */
.loading-bar {
  width: min(280px, 70vw);
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  border: 1px solid var(--glass-border);
}
.loading-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--purple), var(--teal));
  transition: width 0.15s ease;
}
.loading-text { font-size: 12px; color: var(--text-dim); letter-spacing: 1px; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
}
#hud.hidden { display: none; }

.hud-top {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.stat-pill {
  border-radius: 14px;
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
  min-width: 58px;
}
.stat-label { font-size: 9px; letter-spacing: 1px; color: var(--text-dim); font-weight: 600; }
.stat-value { font-size: 15px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }

.hud-top .icon-btn { margin-left: auto; }
.hud-top .icon-btn + .icon-btn { margin-left: 4px; }

.speed-meter {
  position: absolute;
  bottom: max(96px, env(safe-area-inset-bottom) + 96px);
  left: 50%;
  transform: translateX(-50%);
  width: min(220px, 60vw);
  border-radius: 12px;
  padding: 8px 14px;
  pointer-events: none;
}
.speed-label { font-size: 9px; letter-spacing: 2px; color: var(--text-dim); text-align: center; margin-bottom: 4px; }
.speed-track {
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.speed-fill {
  height: 100%;
  width: 20%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--red));
  transition: width 0.15s linear;
}

#touchControls {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  pointer-events: none;
}
.ctrl-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--text);
  pointer-events: auto;
  transition: transform 0.1s ease, background 0.1s ease;
}
.ctrl-btn:active { transform: scale(0.9); background: rgba(124, 92, 252, 0.3); }

/* ---------- Pause / Game Over panels ---------- */
.panel {
  border-radius: 22px;
  padding: 28px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: min(300px, 84vw);
}
.panel h2 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: 1px;
  color: var(--red);
}
.new-best {
  color: var(--gold);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1px;
  animation: pulseGlow 1s ease-in-out infinite;
}
@keyframes pulseGlow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 24px;
  width: 100%;
  margin: 6px 0 10px;
}
.stats-grid > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stats-grid .stat-label { font-size: 10px; }
.stats-grid span:last-child { font-size: 18px; font-weight: 800; color: var(--text); }

/* ---------- Orientation notice ---------- */
#rotate-notice {
  position: absolute;
  inset: 0;
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text-dim);
  text-align: center;
  padding: 24px;
  font-size: 14px;
}

/* Only nag for rotation on short/very wide phones in landscape */
@media (max-height: 420px) and (orientation: landscape) {
  #rotate-notice { display: flex; }
}

/* ---------- Small screens ---------- */
@media (max-width: 380px) {
  .btn { min-width: 180px; padding: 12px 24px; font-size: 14px; }
  .stat-pill { padding: 5px 9px; min-width: 48px; }
  .stat-value { font-size: 13px; }
  .ctrl-btn { width: 52px; height: 52px; font-size: 20px; }
}

/* ---------- Below-game SEO content ---------- */
.info-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 20px 40px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.7;
}
.info-page h1 { font-size: 22px; color: var(--text); margin: 0 0 10px; font-family: var(--font-display, inherit); }
.info-page h2 { font-size: 16px; color: var(--text); margin: 20px 0 6px; }
