@font-face {
  font-family: 'ArcadeClassic';
  src: url('../fonts/ARCADECLASSIC.TTF?v=1') format('truetype');
  font-display: swap;
}
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #0a0a0f;
  color: #fff;
  font-family: 'Arial Black', Arial, sans-serif;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

.screen { display: none; width: 100vw; height: 100vh; }
.screen.active { display: flex; }

/* ── TITLE SCREEN ─────────────────────────────────────────── */
#title-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-image: url('../images/RTTTGameBanner.png');
  background-size: cover;
  background-position: center;
  transition: background-image 0.3s;
}
#title-screen.bg-difficulty {
  background-image: url('../images/selectdifficultlybanner.png');
}
#title-screen.bg-car {
  background-image: url('../images/carselectbanner.png');
}

#title-content {
  text-align: center;
  position: relative;
  z-index: 1;
}

/* Dark overlay so text stays readable over the banner */
#title-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 0;
}

#game-title {
  font-size: 72px;
  letter-spacing: 8px;
  color: #fff;
  text-shadow: 0 0 40px #ff4400, 0 0 80px #ff220066;
  margin-bottom: 8px;
  animation: pulse-glow 2s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { text-shadow: 0 0 40px #ff4400, 0 0 80px #ff220066; }
  50%       { text-shadow: 0 0 60px #ff6600, 0 0 120px #ff4400aa; }
}
#game-subtitle {
  font-size: 18px;
  letter-spacing: 4px;
  color: #ff8844;
  margin-bottom: 60px;
  text-transform: uppercase;
}
.sub-heading {
  font-size: 26px;
  letter-spacing: 4px;
  color: #ff8844;
  margin-bottom: 24px;
}
#title-menu { display: flex; flex-direction: column; gap: 16px; align-items: center; }

.menu-btn {
  background: transparent;
  border: 2px solid #ff4400;
  color: #fff;
  font-family: 'Arial Black', Arial, sans-serif;
  font-size: 20px;
  letter-spacing: 3px;
  padding: 14px 48px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.2s;
  min-width: 280px;
  -webkit-tap-highlight-color: transparent;
}
.menu-btn:hover, .menu-btn:active { background: #ff4400; box-shadow: 0 0 20px #ff4400; }

/* Difficulty */
#difficulty-screen, #car-select-screen, #track-select-screen { margin-top: 32px; }
#difficulty-list { display: flex; gap: 16px; justify-content: center; margin-bottom: 24px; flex-wrap: wrap; }

.diff-btn {
  background: transparent;
  border: 2px solid #ff4400aa;
  color: #fff;
  font-family: 'Arial Black', Arial, sans-serif;
  font-size: 18px;
  letter-spacing: 3px;
  padding: 12px 36px;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.diff-btn:hover, .diff-btn:active, .diff-btn.selected {
  background: #ff4400; border-color: #ff4400; box-shadow: 0 0 16px #ff4400;
}

/* Car select */
#car-list {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.car-card {
  background: rgba(255,255,255,0.05);
  border: 2px solid #ff4400aa;
  padding: 20px 16px;
  cursor: pointer;
  width: 170px;
  transition: all 0.2s;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.car-card:hover, .car-card:active, .car-card.selected {
  border-color: #ff4400;
  background: rgba(255,68,0,0.15);
  box-shadow: 0 0 20px #ff440066;
}
.car-preview {
  width: 32px;
  height: 50px;
  margin: 0 auto 12px;
  border-radius: 4px;
  position: relative;
}
.car-preview::after {
  content: '';
  position: absolute;
  top: 4px; left: 4px; right: 4px;
  height: 10px;
  background: rgba(180,220,255,0.5);
  border-radius: 2px;
}
.car-card-name {
  font-size: 13px;
  letter-spacing: 2px;
  color: #fff;
  margin-bottom: 4px;
}
.car-card-desc {
  font-size: 10px;
  color: #aaa;
  margin-bottom: 12px;
  letter-spacing: 1px;
}
.car-stat { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; font-size: 10px; }
.car-stat-label { color: #888; width: 42px; text-align: right; letter-spacing: 1px; }
.car-stat-track { flex: 1; height: 5px; background: #222; border-radius: 3px; }
.car-stat-fill { height: 100%; border-radius: 3px; background: #ff4400; }

/* Track select */
#track-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.track-item { display: flex; align-items: center; gap: 16px; }
.track-btn {
  background: transparent;
  border: 1px solid #ff4400aa;
  color: #fff;
  font-family: Arial, sans-serif;
  font-size: 16px;
  letter-spacing: 2px;
  padding: 12px 32px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  flex: 1;
  -webkit-tap-highlight-color: transparent;
}
.track-btn:hover, .track-btn:active { background: #ff440033; border-color: #ff4400; }
.best-time { font-size: 13px; color: #ffcc00; letter-spacing: 1px; white-space: nowrap; min-width: 110px; }

/* ── GAME SCREEN ──────────────────────────────────────────── */
#game-screen { flex-direction: column; position: relative; }

#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 20px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.75), transparent);
  pointer-events: none;
}
#hud-left, #hud-right { display: flex; flex-direction: column; gap: 4px; }
#hud-left { margin-left: 116px; } /* clear the mute + controls buttons */
#hud-right { align-items: flex-end; }

#lap-display   { font-size: 18px; color: #ff8844; letter-spacing: 2px; }
#pos-display   { font-size: 24px; color: #ffcc00; font-weight: bold; letter-spacing: 2px; }
#timer-display { font-size: 22px; color: #ff8844; font-family: monospace; letter-spacing: 1px; }
#speed-display { font-size: 14px; color: #fff; letter-spacing: 1px; }
#track-name-display { font-size: 13px; letter-spacing: 3px; color: #aaa; text-align: center; }
#diff-display  { font-size: 12px; letter-spacing: 2px; color: #ff8844; text-align: center; margin-top: 2px; }

#ghost-delta {
  font-size: 16px;
  font-family: monospace;
  letter-spacing: 1px;
  font-weight: bold;
}
#ghost-delta.ahead { color: #44ff88; }
#ghost-delta.behind { color: #ff4444; }

/* Nitro */
#nitro-display { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.nitro-label { font-size: 11px; letter-spacing: 2px; color: #44ccff; }
#nitro-charges { display: flex; gap: 4px; }
.nitro-charge {
  display: block; width: 18px; height: 10px; border-radius: 3px;
  background: #44ccff; box-shadow: 0 0 6px #44ccff; transition: all 0.3s;
}
.nitro-charge.empty  { background: #1a3a44; box-shadow: none; }
.nitro-charge.active { background: #fff; box-shadow: 0 0 12px #44ccff, 0 0 20px #44ccff; }

/* Shield */
#shield-display { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.shield-label { font-size: 11px; letter-spacing: 2px; color: #66ffcc; }
#shield-icon { font-size: 16px; color: #66ffcc; text-shadow: 0 0 10px #66ffcc; }

#game-canvas { width: 100vw; height: 100vh; display: block; }

/* Touch controls */
#touch-controls {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 15;
  display: flex; justify-content: space-between;
  padding: 0 16px 20px; pointer-events: none;
}
#touch-left, #touch-right { display: flex; gap: 10px; align-items: flex-end; pointer-events: all; }
.touch-btn {
  background: rgba(255,255,255,0.12);
  border: 2px solid rgba(255,255,255,0.3);
  color: #fff; font-family: 'Arial Black', Arial, sans-serif;
  font-size: 22px; width: 72px; height: 72px; border-radius: 12px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background 0.1s; touch-action: none;
}
.touch-btn:active, .touch-btn.pressed { background: rgba(255,68,0,0.5); border-color: #ff4400; }
.touch-nitro {
  font-size: 13px; letter-spacing: 1px; color: #44ccff;
  border-color: rgba(68,204,255,0.4); background: rgba(68,204,255,0.1);
}
.touch-nitro:active, .touch-nitro.pressed {
  background: rgba(68,204,255,0.45); border-color: #44ccff; box-shadow: 0 0 16px #44ccff;
}
.touch-accel { background: rgba(255,68,0,0.2); border-color: rgba(255,68,0,0.5); }

/* Countdown / pause */
#countdown-overlay, #pause-overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: rgba(0,0,0,0.5); z-index: 20; gap: 20px;
}
#countdown-text {
  font-size: 120px; color: #ffcc00; text-shadow: 0 0 40px #ffcc00;
  animation: pop 0.4s ease-out;
}
@keyframes pop {
  from { transform: scale(1.6); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
#pause-overlay h2 { font-size: 48px; letter-spacing: 6px; color: #fff; }

/* ── RESULTS ──────────────────────────────────────────────── */
#results-screen {
  flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #1a0a2e 0%, #0a0a0f 70%);
}
#results-content { text-align: center; }
#results-title {
  font-size: 52px; letter-spacing: 6px; color: #ffcc00;
  text-shadow: 0 0 30px #ffcc00; margin-bottom: 40px;
}
#results-stats { margin-bottom: 40px; display: flex; flex-direction: column; gap: 12px; }
.stat-row {
  display: flex; justify-content: space-between; gap: 60px;
  font-size: 20px; border-bottom: 1px solid #333; padding-bottom: 8px;
}
.stat-row span:first-child { color: #aaa; letter-spacing: 2px; }
.stat-row span:last-child  { color: #fff; font-weight: bold; }
.new-record { color: #ffcc00 !important; }
#results-content .menu-btn { margin-top: 12px; }

/* ── GRAND PRIX SCREEN ────────────────────────────────────── */
#gp-screen {
  flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #1a0a2e 0%, #0a0a0f 70%);
}
#gp-content { text-align: center; }
#gp-title {
  font-size: 44px; letter-spacing: 6px; color: #ffcc00;
  text-shadow: 0 0 30px #ffcc00; margin-bottom: 6px;
}
#gp-subtitle { font-size: 16px; letter-spacing: 3px; color: #ff8844; margin-bottom: 28px; text-transform: uppercase; }
#gp-table {
  border-collapse: collapse; margin: 0 auto 32px; min-width: 520px;
}
#gp-table th {
  font-size: 12px; letter-spacing: 2px; color: #888; text-transform: uppercase;
  padding: 8px 18px; border-bottom: 2px solid #444; text-align: left;
}
#gp-table td {
  font-size: 18px; padding: 10px 18px; border-bottom: 1px solid #2a2a2a;
  color: #fff; text-align: left;
}
#gp-table td:first-child, #gp-table th:first-child { text-align: center; width: 40px; }
#gp-table td:last-child { font-weight: bold; color: #ffcc00; text-align: right; }
#gp-table th:last-child { text-align: right; }
#gp-table tr.is-player td { color: #ff8844; background: rgba(255,68,0,0.08); }
#gp-table tr.is-player td:last-child { color: #ffcc00; }
.gp-points-gain { color: #44ff88; font-size: 14px; }
#gp-content .menu-btn { margin: 6px; }

/* ── Mute button ──────────────────────────────────────────── */
#mute-btn {
  position: fixed;
  top: 12px; left: 12px;
  z-index: 50;
  width: 44px; height: 44px;
  border: 2px solid #ff4400;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 20px;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
#mute-btn:hover { background: rgba(255,68,0,0.4); }
#mute-btn.muted { opacity: 0.55; border-color: #666; }

/* ── Win/Lose result image ────────────────────────────────── */
.result-img {
  display: block;
  margin: 0 auto 18px;
  max-width: 460px;
  width: 60vw;
  border: 3px solid #ff4400;
  border-radius: 8px;
  box-shadow: 0 0 30px rgba(0,0,0,0.6);
  image-rendering: pixelated;
}

/* ── Full-screen result backgrounds ───────────────────────── */
.result-img { display: none; } /* no longer inline — used as full-screen bg */
#results-screen, #gp-screen {
  background-size: cover;
  background-position: center;
}
#results-screen::before, #gp-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 0;
}
#results-content, #gp-content {
  position: relative;
  z-index: 1;
  background: rgba(0, 0, 0, 0.35);
  padding: 28px 44px;
  border-radius: 14px;
  backdrop-filter: blur(2px);
}
#results-title, #gp-title { text-shadow: 0 0 18px #000, 0 2px 6px #000; }
.stat-row span, #gp-table td, #gp-table th, #gp-subtitle { text-shadow: 0 1px 4px #000; }

/* ── Red Coral Universe promo widget ──────────────────────── */
#rcu-widget {
  position: fixed;
  right: 18px; bottom: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 132px;
  padding: 10px;
  background: rgba(0,0,0,0.55);
  border: 2px solid #e6004c;
  border-radius: 10px;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}
#rcu-widget:hover {
  transform: translateY(-3px);
  box-shadow: 0 0 22px rgba(230,0,76,0.6);
}
#rcu-poster {
  width: 100%;
  border-radius: 4px;
  display: block;
}
#rcu-text {
  font-family: 'Arial Black', Arial, sans-serif;
  font-size: 10px;
  letter-spacing: 1.5px;
  color: #fff;
  text-align: center;
  line-height: 1.3;
}
#rcu-logo {
  width: 118px;
  display: block;
}

/* ── Controls button ──────────────────────────────────────── */
#controls-btn {
  position: fixed;
  top: 12px; left: 64px;
  z-index: 50;
  width: 44px; height: 44px;
  border: 2px solid #ff4400;
  background: rgba(0,0,0,0.55);
  color: #fff; font-size: 20px;
  border-radius: 8px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
#controls-btn:hover { background: rgba(255,68,0,0.4); }

/* ── Generic full-screen overlays (quit / controls) ───────── */
.overlay {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.7);
}
.overlay-panel {
  background: rgba(15,8,24,0.95);
  border: 2px solid #ff4400;
  border-radius: 14px;
  padding: 34px 48px;
  text-align: center;
  box-shadow: 0 0 40px rgba(255,68,0,0.4);
}
.overlay-panel h2 {
  font-size: 34px; letter-spacing: 5px; color: #ffcc00;
  text-shadow: 0 0 20px #ff8800; margin-bottom: 24px;
}
.overlay-btns { display: flex; gap: 18px; justify-content: center; }
.overlay-btns .menu-btn { min-width: 150px; }

#controls-table { margin: 0 auto 26px; border-collapse: collapse; }
#controls-table td {
  padding: 9px 22px; font-size: 17px; text-align: left;
  border-bottom: 1px solid #333;
}
#controls-table td:first-child {
  color: #ff8844; font-family: 'Arial Black', Arial, sans-serif;
  letter-spacing: 1px; white-space: nowrap; text-align: right;
}
#controls-table td:last-child { color: #fff; letter-spacing: 1px; }

/* ── Universal ArcadeClassic font ─────────────────────────── */
body, button, input, h1, h2, h3, p, span, div, td, th, table, a, label {
  font-family: 'ArcadeClassic', 'Arial Black', Arial, sans-serif !important;
}
/* keep the monospace timers tidy but still arcade */
#timer-display, #ghost-delta { font-family: 'ArcadeClassic', monospace !important; }

/* ── In-race "Press C for controls" hint (right side) ─────── */
#controls-hint {
  position: absolute;
  right: 16px; top: 50%; transform: translateY(-50%);
  z-index: 12;
  width: 120px;
  padding: 10px 8px;
  text-align: center;
  color: #ffcc00;
  font-size: 18px;
  letter-spacing: 2px;
  line-height: 1.5;
  background: rgba(0,0,0,0.45);
  border: 2px solid #ff4400;
  border-radius: 8px;
  text-shadow: 0 1px 4px #000;
  pointer-events: none;
}

/* Mobile brake + drift buttons */
.touch-brake { background: rgba(255,68,0,0.15); border-color: rgba(255,68,0,0.4); }
.touch-drift {
  font-size: 12px; letter-spacing: 1px; color: #ffcc00;
  background: rgba(255,204,0,0.12); border-color: rgba(255,204,0,0.45);
}
.touch-drift:active, .touch-drift.pressed { background: rgba(255,204,0,0.45); border-color: #ffcc00; }

/* In-race gap + last-lap readouts */
#gap-ahead  { font-size: 13px; color: #ff8888; letter-spacing: 1px; }
#gap-behind { font-size: 13px; color: #88ccff; letter-spacing: 1px; }
#lastlap-display { font-size: 13px; color: #aaa; letter-spacing: 1px; }

/* Locked car card */
.car-card.locked { opacity: 0.6; cursor: not-allowed; border-color: #555; }
.car-card.locked:hover { transform: none; box-shadow: none; background: rgba(255,255,255,0.05); border-color: #555; }
.car-lock-note { font-size: 11px; letter-spacing: 1px; color: #ffcc00; margin-top: 14px; }

/* ── Loading screen ───────────────────────────────────────── */
#loading-screen {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  background: #0a0a0f url('../images/loading_screen.png') center/cover no-repeat;
  transition: opacity 0.5s;
}
#loading-screen.hidden { opacity: 0; pointer-events: none; }
#loading-content {
  width: 100%; text-align: center;
  padding: 40px 20px 64px;
  background: linear-gradient(to top, rgba(0,0,0,0.85), transparent);
}
#loading-title {
  font-size: 44px; letter-spacing: 6px; color: #fff;
  text-shadow: 0 0 30px #ff4400; margin-bottom: 22px;
}
#loading-bar-track {
  width: min(520px, 80vw); height: 20px; margin: 0 auto 12px;
  background: rgba(0,0,0,0.6); border: 2px solid #ff4400; border-radius: 10px; overflow: hidden;
}
#loading-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(to right, #ff8800, #ff4400);
  box-shadow: 0 0 14px #ff6600; transition: width 0.15s;
}
#loading-pct { font-size: 16px; letter-spacing: 3px; color: #ff8844; }
