:root {
  --bg-dark: #0B0F14;
  --bg-panel: #111826;
  --primary: #FF9A00;
  --primary-dark: #FF3D00;
  --accent: #3b82f6;
  --text: #EAF0F6;
  --text-muted: #9AA7B4;
}

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

html, body {
  font-family: 'Poppins', sans-serif;
  background: var(--bg-dark);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 500px;
  max-height: 900px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: var(--bg-panel);
  overflow: hidden;
}

@media (min-width: 500px) {
  .game-wrapper {
    height: auto;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.08);
    padding: 20px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  }
}

/* --- HUD --- */
.top-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 10px 15px;
  z-index: 10;
}

.circuit-info {
  display: flex;
  flex-direction: column;
}
.circuit-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 1px;
}
.drift-score {
  font-size: 12px;
  font-weight: 800;
  color: var(--primary);
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 0.2s, transform 0.2s;
}
.drift-score.visible { opacity: 1; transform: translateY(0); }

.stats-board {
  display: flex;
  gap: 15px;
}
.stat { text-align: center; }
.stat-label { font-size: 9px; color: #6B7785; font-weight: 700; }
.value {
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 800;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.icon-btn:active { background: rgba(255,255,255,0.1); transform: scale(0.95); }

/* --- BARS --- */
.status-bars {
  width: 100%;
  padding: 0 15px;
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  z-index: 10;
}
.bar-container {
  flex: 1;
  background: #000;
  height: 6px;
  border-radius: 3px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.15);
}
.bar-label {
  position: absolute; left: 4px; top: 0; bottom: 0;
  font-size: 5px; line-height: 6px; font-weight: 900;
  color: rgba(255,255,255,0.8); z-index: 2;
  text-shadow: 0 1px 2px black;
}
.bar-fill { height: 100%; width: 100%; transition: width 0.1s linear; }
#healthFill { background: #ef4444; }
#nitroFill { background: var(--accent); }

/* --- CANVAS --- */
#gameCanvas {
  width: 100%;
  max-width: 100%;
  aspect-ratio: 1/1;
  background: #0B0F14;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  touch-action: none;
}

/* --- BRAND --- */
.brand {
  margin-top: 15px;
  font-weight: 900;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-decoration: none;
  font-size: 18px;
  z-index: 10;
}

/* --- MOBILE CONTROLS (VISUAL) --- */
.mobile-controls-visual {
  position: absolute;
  bottom: 50px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 0 20px;
  pointer-events: none; /* Let clicks pass through to canvas handler */
  opacity: 0.5;
}
.control-zone {
  width: 60px; height: 60px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.1);
  display: flex; align-items: center; justify-content: center;
  font-weight: bold; font-size: 24px;
  color: rgba(255,255,255,0.3);
  transition: all 0.1s;
}
.control-zone.active {
  background: rgba(255,154,0,0.2);
  border-color: var(--primary);
  color: var(--primary);
  transform: scale(0.9);
}
.control-zone.nitro {
  width: 80px; height: 80px;
  border-color: rgba(59,130,246,0.3);
  color: rgba(59,130,246,0.5);
}
.control-zone.nitro.active {
  background: rgba(59,130,246,0.2);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 20px var(--accent);
}
@media (min-width: 800px) { .mobile-controls-visual { display: none; } }

/* --- OVERLAYS --- */
.overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fadeIn 0.3s ease;
}
.overlay.hidden { display: none; }

.panel {
  background: rgba(17,24,38,0.95);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 24px;
  border-radius: 24px;
  width: 100%; max-width: 380px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}

.panel h1 {
  font-size: 28px;
  margin-bottom: 10px;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 800;
}
.panel h1.danger-text { background: linear-gradient(90deg, #ef4444, #991b1b); -webkit-background-clip: text; background-clip: text; }

.instruction-text { color: var(--text-muted); font-size: 13px; margin: 15px 0; line-height: 1.6; }
.stats-text { font-size: 14px; color: #fff; margin-bottom: 20px; font-weight: 600; }

.row { display: flex; gap: 10px; margin-top: 15px; }
.btn {
  flex: 1; border: none; padding: 14px;
  border-radius: 12px; font-weight: 700; font-size: 14px;
  cursor: pointer;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  color: #000;
  transition: transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn.big-btn { font-size: 18px; padding: 16px; box-shadow: 0 10px 20px rgba(255, 61, 0, 0.2); }
.btn.secondary { background: transparent; border: 1px solid rgba(255,255,255,0.15); color: var(--text); }
.btn.danger-btn { border-color: #ef4444; color: #ef4444; }

/* Settings Toggles */
.settings-list { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.toggle {
  display: flex; justify-content: space-between; align-items: center;
  background: rgba(255,255,255,0.03); padding: 12px; border-radius: 10px;
  font-size: 13px; color: var(--text-muted);
}
.switch {
  width: 40px; height: 22px; background: rgba(255,255,255,0.1);
  border-radius: 20px; position: relative; cursor: pointer; transition: background 0.2s;
}
.switch.on { background: var(--accent); }
.knob {
  width: 18px; height: 18px; background: #fff; border-radius: 50%;
  position: absolute; top: 2px; left: 2px; transition: left 0.2s;
}
.switch.on .knob { left: 20px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }