/* Local Orbitron Web Fonts for 100% Offline Self-Contained Operation */
@font-face {
  font-family: "Orbitron";
  font-style: normal;
  font-weight: 400;
  src: url("assets/fonts/orbitron-400.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "Orbitron";
  font-style: normal;
  font-weight: 700;
  src: url("assets/fonts/orbitron-700.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "Orbitron";
  font-style: normal;
  font-weight: 900;
  src: url("assets/fonts/orbitron-900.ttf") format("truetype");
  font-display: swap;
}

:root {
  --neon-pink: #ff0055;
  --neon-cyan: #00e5ff;
  --neon-purple: #9900ff;
  --neon-yellow: #ffd166;
  --neon-green: #00e676;
  --bg-dark: #07071a;
  --panel-bg: rgba(10, 10, 26, 0.85);
  --panel-border: rgba(0, 229, 255, 0.4);
}

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

body {
  overflow: hidden;
  background-color: var(--bg-dark);
  color: #fff;
  font-family: "Orbitron", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

#game-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ==========================================================================
   HUD
   ========================================================================== */
#hud {
  position: absolute;
  top: 15px;
  left: 15px;
  right: 15px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  pointer-events: auto;
}

.hud-stats-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.stat {
  font-size: 15px;
  font-weight: 700;
  color: var(--neon-cyan);
  text-shadow: 0 0 10px var(--neon-cyan);
  background: var(--panel-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 8px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat small {
  font-size: 10px;
  opacity: 0.8;
}

#combo-stat {
  color: var(--neon-pink);
  text-shadow: 0 0 10px var(--neon-pink);
  border-color: rgba(255, 0, 85, 0.5);
  opacity: 0.6;
}

#combo-stat.hot {
  opacity: 1;
  animation: combo-pulse 0.4s ease-out;
}

@keyframes combo-pulse {
  0% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

#time-stat.low {
  color: #ff3333;
  text-shadow: 0 0 12px #ff3333;
  border-color: #ff3333;
  animation: blinker 0.6s linear infinite;
}

#hull-stat {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #00e676;
  text-shadow: 0 0 10px #00e676;
  border-color: rgba(0, 230, 118, 0.4);
}

.hull-bar-track {
  width: 60px;
  height: 8px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

#hull-bar-fill {
  height: 100%;
  width: 100%;
  background: #00e676;
  transition: width 0.3s ease, background 0.3s ease;
}

#hull-stat.hull-warning {
  color: #ffd166;
  text-shadow: 0 0 10px #ffd166;
  border-color: rgba(255, 209, 102, 0.6);
}

#hull-stat.hull-danger {
  color: #ff3344;
  text-shadow: 0 0 14px #ff3344;
  border-color: #ff3344;
  animation: blinker 0.5s linear infinite;
}

.go-reason-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 2px;
  padding: 6px 16px;
  border-radius: 20px;
  margin-bottom: 15px;
}

.badge-danger {
  background: rgba(255, 51, 68, 0.2);
  color: #ff3344;
  border: 1px solid #ff3344;
  box-shadow: 0 0 15px rgba(255, 51, 68, 0.5);
}

.badge-warning {
  background: rgba(255, 209, 102, 0.2);
  color: #ffd166;
  border: 1px solid #ffd166;
  box-shadow: 0 0 15px rgba(255, 209, 102, 0.4);
}

.mode-badge-inline {
  display: inline-block;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.5px;
  padding: 2px 10px;
  border-radius: 12px;
  background: rgba(0, 229, 255, 0.12);
  color: var(--neon-cyan);
  border: 1px solid rgba(0, 229, 255, 0.5);
  margin-right: 6px;
  text-transform: uppercase;
  vertical-align: middle;
}

.hud-actions-group {
  display: flex;
  gap: 8px;
}

.hud-icon-btn {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--neon-cyan);
  padding: 8px 12px;
  font-size: 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(8px);
}

.hud-icon-btn:hover {
  background: rgba(0, 229, 255, 0.25);
  box-shadow: 0 0 12px var(--neon-cyan);
  transform: translateY(-2px);
}

/* ==========================================================================
   TOAST
   ========================================================================== */
#toast {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 30px;
  font-weight: 900;
  color: var(--neon-yellow);
  text-shadow: 0 0 20px var(--neon-yellow), 0 0 40px #ff5e8a;
  opacity: 0;
  white-space: nowrap;
  pointer-events: none;
  letter-spacing: 2px;
}

#toast.pop {
  animation: toast-pop 1.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes toast-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.7); }
  15% { opacity: 1; transform: translateX(-50%) scale(1.15); }
  75% { opacity: 1; transform: translateX(-50%) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-20px) scale(0.95); }
}

/* ==========================================================================
   OVERLAYS & MODALS
   ========================================================================== */
.overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  background: rgba(7, 7, 26, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 35px 45px;
  border: 2px solid var(--neon-pink);
  box-shadow: 0 0 35px rgba(255, 0, 85, 0.4), inset 0 0 20px rgba(255, 0, 85, 0.15);
  border-radius: 12px;
  max-width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
  pointer-events: auto;
  z-index: 100;
}

.brand-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--neon-cyan);
  background: rgba(0, 229, 255, 0.12);
  border: 1px solid var(--neon-cyan);
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
}

h1 {
  font-size: 42px;
  margin: 0 0 6px 0;
  color: var(--neon-pink);
  text-shadow: 0 0 20px var(--neon-pink);
  letter-spacing: 4px;
}

h2 {
  font-size: 32px;
  color: var(--neon-cyan);
  text-shadow: 0 0 15px var(--neon-cyan);
  margin-bottom: 20px;
  letter-spacing: 2px;
}

.danger-title {
  color: #ff3344;
  text-shadow: 0 0 20px #ff3344;
}

.subtitle {
  font-size: 16px;
  color: #b0c0d8;
  letter-spacing: 4px;
  margin-bottom: 20px;
}

p {
  font-size: 16px;
  color: #cfd8e8;
  line-height: 1.5;
}

.control-hint {
  font-size: 13px;
  color: #7d8ea6;
  margin-top: 20px;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
  display: inline-block;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.2s ease;
  user-select: none;
}

.btn-primary {
  background: linear-gradient(135deg, #ff0055, #c73cff);
  color: #fff;
  box-shadow: 0 0 20px rgba(255, 0, 85, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 0 30px rgba(255, 0, 85, 0.8);
}

.btn-secondary {
  background: rgba(0, 229, 255, 0.1);
  color: var(--neon-cyan);
  border: 1px solid var(--neon-cyan);
}

.btn-secondary:hover {
  background: rgba(0, 229, 255, 0.25);
  box-shadow: 0 0 15px var(--neon-cyan);
  transform: translateY(-2px);
}

.btn-accent {
  background: linear-gradient(135deg, #00e5ff, #00e676);
  color: #050510;
  border: none;
}

.btn-rewarded {
  background: linear-gradient(135deg, #ffd166, #ff5e8a);
  color: #07071a;
  border: none;
  box-shadow: 0 0 20px rgba(255, 209, 102, 0.5);
  margin-top: 10px;
}

.btn-danger {
  background: rgba(255, 50, 80, 0.15);
  color: #ff5566;
  border: 1px solid #ff5566;
}

.btn-danger-small {
  background: rgba(255, 50, 80, 0.2);
  color: #ff6677;
  border: 1px solid #ff6677;
  padding: 8px 16px;
  font-size: 12px;
}

.pulse-btn {
  animation: pulse-glow 1.8s infinite;
}

@keyframes pulse-glow {
  0% { box-shadow: 0 0 15px rgba(255, 0, 85, 0.4); }
  50% { box-shadow: 0 0 30px rgba(255, 0, 85, 0.9); }
  100% { box-shadow: 0 0 15px rgba(255, 0, 85, 0.4); }
}

.menu-actions {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-top: 20px;
}

.menu-btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.pause-actions, .gameover-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

/* ==========================================================================
   MODE SELECTOR
   ========================================================================== */
.mode-selector-container {
  margin: 15px 0;
  background: rgba(0, 0, 0, 0.4);
  padding: 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.mode-tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.mode-tab {
  background: rgba(255, 255, 255, 0.05);
  color: #8899aa;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mode-tab.active-mode {
  background: rgba(0, 229, 255, 0.2);
  color: var(--neon-cyan);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.4);
}

.mode-desc {
  font-size: 13px;
  color: #00e5ff;
  margin-top: 10px;
  min-height: 20px;
}

/* ==========================================================================
   GAME OVER SCREEN STATS
   ========================================================================== */
.gameover-stats {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin: 20px 0;
  flex-wrap: wrap;
}

.go-stat-box {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 12px 20px;
  border-radius: 8px;
  min-width: 130px;
}

.go-stat-box label {
  font-size: 11px;
  letter-spacing: 2px;
  color: #7d8ea6;
  display: block;
  margin-bottom: 4px;
}

.stat-big {
  font-size: 24px;
  font-weight: 900;
  color: #fff;
}

.stat-big.highlight {
  color: var(--neon-yellow);
  text-shadow: 0 0 12px var(--neon-yellow);
}

.save-score-panel {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 20px;
}

.save-score-panel input {
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid var(--neon-cyan);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  padding: 10px 16px;
  border-radius: 6px;
  outline: none;
  text-align: center;
  letter-spacing: 2px;
  width: 220px;
}

.save-score-panel input:focus {
  box-shadow: 0 0 15px var(--neon-cyan);
}

/* ==========================================================================
   GARAGE / SKINS MODAL
   ========================================================================== */
.modal {
  width: 680px;
  max-width: 95vw;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.modal-header h2 {
  margin: 0;
  font-size: 24px;
}

.close-modal-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
}

.close-modal-btn:hover {
  color: var(--neon-pink);
}

.skins-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 15px;
}

.skin-card {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  transition: all 0.2s ease;
}

.skin-card.active-skin {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.4);
  background: rgba(0, 229, 255, 0.08);
}

.skin-swatch {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  margin-bottom: 5px;
}

.skin-info h3 {
  font-size: 16px;
  color: #fff;
}

.skin-info p {
  font-size: 12px;
  color: #8899aa;
}

/* ==========================================================================
   SETTINGS MODAL
   ========================================================================== */
.setting-group {
  margin-bottom: 20px;
  text-align: left;
}

.setting-group h3 {
  font-size: 14px;
  letter-spacing: 2px;
  color: var(--neon-cyan);
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(0, 229, 255, 0.2);
  padding-bottom: 4px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 14px;
}

.setting-row input[type="range"] {
  width: 180px;
  accent-color: var(--neon-pink);
}

.setting-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--neon-pink);
}

.btn-group-toggle {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-toggle {
  background: rgba(255, 255, 255, 0.05);
  color: #8899aa;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 8px 12px;
  font-size: 12px;
}

.btn-toggle.active-choice {
  background: rgba(255, 0, 85, 0.25);
  color: #fff;
  border-color: var(--neon-pink);
  box-shadow: 0 0 12px rgba(255, 0, 85, 0.4);
}

/* ==========================================================================
   LEADERBOARD MODAL
   ========================================================================== */
.table-responsive {
  max-height: 320px;
  overflow-y: auto;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  text-align: left;
}

.leaderboard-table th {
  background: rgba(0, 0, 0, 0.6);
  padding: 10px;
  color: var(--neon-cyan);
  border-bottom: 2px solid var(--neon-cyan);
  font-size: 12px;
  letter-spacing: 1px;
}

.leaderboard-table td {
  padding: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-num {
  font-weight: 700;
  color: var(--neon-yellow);
}

.mode-tag {
  font-size: 11px;
  background: rgba(255, 255, 255, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

.rank-gold td:first-child { color: #ffd700; font-weight: 900; }
.rank-silver td:first-child { color: #c0c0c0; font-weight: 900; }
.rank-bronze td:first-child { color: #cd7f32; font-weight: 900; }

.leaderboard-actions {
  margin-top: 15px;
  text-align: right;
}

/* ==========================================================================
   TUTORIAL MODAL
   ========================================================================== */
.tutorial-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 15px;
  text-align: left;
}

.tut-card {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 14px;
}

.tut-card h3 {
  font-size: 14px;
  color: var(--neon-cyan);
  margin-bottom: 8px;
}

.tut-card p {
  font-size: 13px;
  margin-bottom: 6px;
}

/* ==========================================================================
   TOUCH CONTROLS
   ========================================================================== */
#touch-controls {
  display: none;
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  justify-content: space-between;
  padding: 0 4vw 5vw;
  pointer-events: none;
}

@media (pointer: coarse) {
  #touch-controls {
    display: flex;
  }
}

.tcluster {
  display: flex;
  gap: 4vw;
}

.tbtn {
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  min-width: 17vw;
  padding: 4.5vw 3vw;
  text-align: center;
  font-size: 5vw;
  color: var(--neon-cyan);
  text-shadow: 0 0 10px var(--neon-cyan);
  background: rgba(0, 20, 30, 0.55);
  border: 1px solid rgba(0, 229, 255, 0.6);
  border-radius: 12px;
  backdrop-filter: blur(6px);
}

.tbtn.held {
  background: rgba(0, 229, 255, 0.35);
  transform: scale(0.96);
}

/* ==========================================================================
   MONETIZATION & AD CONTAINERS
   ========================================================================== */
#ad-banner-container {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  background: rgba(5, 5, 16, 0.95);
  border-top: 1px solid var(--neon-cyan);
  padding: 8px;
  text-align: center;
  pointer-events: auto;
  z-index: 50;
}

.ad-banner-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.ad-banner-tag {
  font-size: 10px;
  background: var(--neon-pink);
  color: #fff;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 700;
  letter-spacing: 1px;
}

.ad-banner-content {
  font-size: 13px;
  color: var(--neon-cyan);
  letter-spacing: 1px;
}

.ad-modal {
  width: 480px;
  max-width: 90vw;
  border-color: var(--neon-cyan);
  box-shadow: 0 0 35px rgba(0, 229, 255, 0.4);
}

.ad-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}

.ad-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--neon-yellow);
}

.ad-countdown, .rewarded-countdown {
  font-size: 13px;
  color: #8899aa;
}

.ad-sample-body {
  background: rgba(0, 0, 0, 0.6);
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 25px 15px;
  margin-bottom: 20px;
}

.ad-sample-body h3 {
  font-size: 16px;
  color: var(--neon-cyan);
  margin-bottom: 8px;
}

.ad-demo-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 30px;
  border-radius: 6px;
  margin-top: 15px;
  font-size: 12px;
  color: #7d8ea6;
}

.rewarded-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.disabled {
  opacity: 0.5;
  pointer-events: none;
  cursor: not-allowed;
}

/* ==========================================================================
   UTILITY & ANIMATIONS
   ========================================================================== */
.hidden {
  display: none !important;
}

.blink {
  animation: blinker 1s linear infinite;
}

@keyframes blinker {
  50% { opacity: 0; }
}

/* ==========================================================================
   TOUCH CONTROLS (Mobile Gamepad — 4 Buttons: Left, Right, Brake, Gas)
   Desktop: 100% Hidden. Mobile: Shown only on mobile screens during gameplay.
   ========================================================================== */
#touch-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: none !important; /* Never visible on desktop screens */
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 16px 18px;
  pointer-events: none;
  z-index: 200;
  gap: 12px;
}

.tcluster {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  pointer-events: auto;
}

.tbtn {
  background: rgba(0, 229, 255, 0.08);
  border: 2px solid rgba(0, 229, 255, 0.45);
  border-radius: 16px;
  color: var(--neon-cyan);
  font-family: var(--font-main);
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.08s, border-color 0.08s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 0 15px rgba(0, 229, 255, 0.15);
}

.tbtn-steer {
  width: 64px;
  height: 64px;
  font-size: 22px;
}

.tbtn-brake {
  width: 64px;
  height: 64px;
  font-size: 11px;
  letter-spacing: 1px;
  background: rgba(255, 51, 68, 0.1);
  border-color: rgba(255, 51, 68, 0.5);
  color: #ff3344;
  box-shadow: 0 0 15px rgba(255, 51, 68, 0.2);
}

.tbtn-gas {
  width: 72px;
  height: 72px;
  font-size: 13px;
  letter-spacing: 1.5px;
  background: rgba(0, 255, 136, 0.12);
  border-color: rgba(0, 255, 136, 0.6);
  color: #00e676;
  box-shadow: 0 0 20px rgba(0, 255, 136, 0.25);
}

.tbtn.held,
.tbtn:active {
  transform: scale(0.92);
}

.tbtn-steer.held,
.tbtn-steer:active {
  background: rgba(0, 229, 255, 0.3);
  border-color: var(--neon-cyan);
  box-shadow: 0 0 25px rgba(0, 229, 255, 0.6);
}

.tbtn-gas.held,
.tbtn-gas:active {
  background: rgba(0, 255, 136, 0.35);
  border-color: #00e676;
  box-shadow: 0 0 30px rgba(0, 255, 136, 0.6);
}

.tbtn-brake.held,
.tbtn-brake:active {
  background: rgba(255, 51, 68, 0.35);
  border-color: #ff3344;
  box-shadow: 0 0 30px rgba(255, 51, 68, 0.6);
}

/* Hide HUD on mobile during title/gameover overlays */
#hud.hud-hidden {
  display: none !important;
}

/* ======================================
   MOBILE RESPONSIVE — screens ≤ 768px
   Only changes below affect mobile.
   Desktop layout is 100% untouched.
   ====================================== */
@media (max-width: 768px) {
  /* Touch Gamepad on mobile screens during gameplay */
  #touch-controls.visible {
    display: flex !important;
  }

  /* ---- HUD compact ---- */
  #hud {
    top: 6px;
    left: 6px;
    right: 6px;
    gap: 4px;
  }

  .hud-stats-group {
    gap: 4px;
    flex-wrap: wrap;
  }

  .stat {
    font-size: 10px;
    padding: 4px 7px;
    gap: 3px;
    border-radius: 5px;
  }

  .stat small { font-size: 7px; }

  .hull-bar-track { width: 36px; height: 5px; }

  .hud-actions-group { gap: 4px; }

  .hud-icon-btn {
    width: 28px;
    height: 28px;
    font-size: 13px;
    border-radius: 5px;
  }

  /* ---- Overlays: scrollable, not congested ---- */
  .overlay {
    padding: 20px 14px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-body {
    max-height: 65vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px;
  }

  /* ---- Start Screen: clean, spacious vertical flow ---- */
  #start-screen {
    width: 90vw;
    max-width: 350px;
    max-height: 88vh;
    padding: 20px 16px 22px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 16px;
    box-shadow: 0 0 40px rgba(255, 0, 85, 0.35);
  }

  .brand-badge {
    font-size: 8px !important;
    padding: 2px 8px !important;
    margin-bottom: 0px;
    letter-spacing: 2px;
  }

  #start-screen .glitch-text {
    font-size: 24px !important;
    letter-spacing: 3px;
    line-height: 1.1;
    margin: 2px 0 0 0;
  }

  #start-screen .subtitle {
    font-size: 9px;
    letter-spacing: 2.5px;
    margin-bottom: 4px;
    color: #9cb3d0;
  }

  .mode-selector-container {
    width: 100%;
    margin-bottom: 4px;
  }

  .mode-tabs {
    display: flex;
    gap: 4px;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    padding: 3px;
    border-radius: 8px;
    border: 1px solid rgba(0, 229, 255, 0.2);
  }

  .mode-tab {
    font-size: 8px;
    padding: 7px 4px;
    letter-spacing: 0.3px;
    flex: 1;
    text-align: center;
    min-width: 0;
    border-radius: 6px;
  }

  #mode-description {
    font-size: 10px;
    line-height: 1.35;
    margin-top: 6px;
    padding: 0 2px;
    color: #b8cde8;
  }

  .mode-badge-inline {
    font-size: 8px;
    padding: 1px 6px;
  }

  .menu-actions {
    width: 100%;
    gap: 7px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    margin-top: 2px;
  }

  #btn-start-race {
    font-size: 15px;
    padding: 13px 18px;
    width: 100%;
    border-radius: 10px;
    letter-spacing: 1.5px;
  }

  .menu-btn-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    width: 100%;
  }

  .menu-btn-row .btn {
    font-size: 10px;
    padding: 8px 4px;
    letter-spacing: 0.3px;
    border-radius: 6px;
  }

  .control-hint { display: none; }

  /* ---- Game Over: clean stack ---- */
  .danger-title { font-size: 22px; }

  .go-reason-badge {
    font-size: 10px;
    padding: 4px 12px;
  }

  .gameover-stats {
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
  }

  .go-stat-box {
    min-width: 85px;
    padding: 8px 10px;
  }

  .stat-big { font-size: 20px; }

  .gameover-actions { gap: 6px; }
  .gameover-actions .btn { font-size: 11px; padding: 10px 12px; }

  .save-score-panel {
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
  }

  .save-score-panel input {
    width: 100%;
    font-size: 12px;
    text-align: center;
  }

  /* ---- Pause ---- */
  .pause-actions { gap: 6px; }
  .pause-actions .btn { font-size: 12px; padding: 10px 14px; width: 100%; }

  /* ---- Tutorial ---- */
  .tutorial-grid { grid-template-columns: 1fr; gap: 8px; }
  .tut-card { padding: 10px; font-size: 12px; }

  /* ---- Garage ---- */
  .skins-grid { grid-template-columns: 1fr; gap: 8px; }
  .skin-card { flex-direction: row; gap: 10px; padding: 10px; }
  .skin-swatch { width: 44px; height: 44px; flex-shrink: 0; }

  /* ---- Settings ---- */
  .setting-row label { font-size: 11px; }
  .btn-group-toggle { flex-wrap: wrap; gap: 5px; }
  .btn-group-toggle .btn { flex: 1 1 40%; font-size: 9px; padding: 7px 5px; }

  /* ---- Leaderboard ---- */
  .leaderboard-table { font-size: 10px; }
  .leaderboard-table th, .leaderboard-table td { padding: 5px 6px; }

  /* ---- Toast above touch buttons ---- */
  #toast { font-size: 12px; padding: 7px 16px; bottom: 130px; }

  /* ---- Game Over bottom pad ---- */
  #game-over { padding-bottom: 20px; }
}

/* Very small phones (≤ 390px) */
@media (max-width: 390px) {
  .tbtn-big { width: 85px; height: 75px; font-size: 13px; }

  #start-screen .glitch-text { font-size: 22px !important; }
  .stat { font-size: 9px; padding: 3px 5px; }
  .go-stat-box { min-width: 75px; }
  .stat-big { font-size: 17px; }
  .mode-tab { font-size: 7px; padding: 5px 6px; }
}

/* Landscape phones */
@media (max-height: 450px) and (orientation: landscape) {
  #touch-controls { padding: 0 14px 8px; }
  .tbtn-big { width: 80px; height: 66px; font-size: 12px; border-radius: 14px; }

  .overlay {
    padding: 8px 10px;
    max-height: 96vh;
    overflow-y: auto;
  }

  #start-screen .glitch-text { font-size: 20px !important; margin-bottom: 2px; }
  #start-screen .subtitle { display: none; }
  .mode-tabs { gap: 3px; }
  .menu-actions { gap: 4px; }

  #hud { top: 3px; left: 3px; right: 3px; }
  .stat { font-size: 9px; padding: 3px 5px; }
  #toast { bottom: 80px; }
}

