* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0c121e;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #f8fafc;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: #0c121e;
  overflow: hidden;
}

/* --- HUD Header --- */
#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: linear-gradient(180deg, #182236 0%, #0e1524 100%);
  border-bottom: 2px solid #23314d;
  height: 60px;
  z-index: 10;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

#level-badge {
  background: #f59e0b;
  color: #0f172a;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.5px;
}

#speed-badge {
  background: #1e293b;
  border: 1px solid #334155;
  color: #38bdf8;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 900;
  display: flex;
  align-items: baseline;
  gap: 3px;
}

#speed-badge small {
  font-size: 9px;
  color: #94a3b8;
}

.hud-center {
  flex: 1;
  max-width: 220px;
  margin: 0 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#distance-container {
  width: 100%;
  height: 10px;
  background: #090e18;
  border: 1px solid #334155;
  border-radius: 9999px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

#distance-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f59e0b 0%, #10b981 100%);
  border-radius: 9999px;
  transition: width 0.15s ease-out;
}

#distance-label {
  font-size: 10px;
  font-weight: 800;
  color: #94a3b8;
  margin-top: 2px;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

#score-badge {
  background: #1e293b;
  border: 1px solid #334155;
  color: #fbbf24;
  padding: 4px 8px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 3px;
}

.hud-btn {
  background: #1e293b;
  border: 1px solid #334155;
  color: #f8fafc;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.hud-btn:hover {
  background: #334155;
  transform: translateY(-1px);
}

.hud-btn:active {
  transform: translateY(1px);
}

/* Floating Near-Miss Alert */
#near-miss-banner {
  position: absolute;
  top: 75px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  padding: 6px 18px;
  border-radius: 9999px;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 1px;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.8), 0 4px 10px rgba(0, 0, 0, 0.5);
  z-index: 20;
  pointer-events: none;
  animation: bannerPulse 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#near-miss-banner.hidden {
  display: none;
}

@keyframes bannerPulse {
  0% { transform: translateX(-50%) scale(0.4); opacity: 0; }
  60% { transform: translateX(-50%) scale(1.15); opacity: 1; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

/* Nitro Gauge */
#nitro-gauge-wrap {
  position: absolute;
  top: 72px;
  right: 14px;
  width: 140px;
  height: 18px;
  background: #090e18;
  border: 1.5px solid #0284c7;
  border-radius: 9999px;
  overflow: hidden;
  z-index: 15;
  box-shadow: 0 0 10px rgba(2, 132, 199, 0.4);
}

#nitro-fill {
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, #0284c7 0%, #38bdf8 100%);
  transition: width 0.1s ease-out;
}

#nitro-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 1px;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

/* --- Main Stage & Canvas --- */
#stage {
  flex: 1;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* --- Touch Controls for Mobile --- */
#touch-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding: 8px 12px;
  background: #090e18;
  border-top: 1px solid #1e293b;
  z-index: 10;
}

.touch-btn {
  padding: 14px 6px;
  border-radius: 10px;
  border: 1px solid #334155;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.1s ease;
}

.steer-btn {
  background: #1e293b;
  color: #f1f5f9;
}

.steer-btn:active {
  background: #334155;
  transform: scale(0.96);
}

.nitro-btn {
  background: linear-gradient(180deg, #0284c7 0%, #0369a1 100%);
  color: #ffffff;
  border-color: #38bdf8;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.4);
}

.nitro-btn:active {
  transform: scale(0.96);
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.8);
}

/* --- Modals & Overlays --- */
.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 10, 20, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
  transition: opacity 0.25s ease;
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
  border: 2px solid #334155;
  border-radius: 20px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.6);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(30px) scale(0.95); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.danger-card {
  border-color: #ef4444;
}

.modal-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}

.hero-bike {
  width: 55px;
  height: 110px;
  filter: drop-shadow(0 6px 14px rgba(56, 189, 248, 0.5));
}

.hero-car {
  width: 60px;
  height: 115px;
  filter: drop-shadow(0 6px 14px rgba(245, 158, 11, 0.5));
}

.game-title {
  font-size: 26px;
  font-weight: 900;
  color: #f8fafc;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.game-subtitle {
  font-size: 13px;
  color: #94a3b8;
  line-height: 1.4;
  margin-bottom: 16px;
}

.rules-box {
  background: #090e1a;
  border: 1px solid #1e293b;
  border-radius: 12px;
  padding: 12px;
  text-align: left;
  font-size: 12px;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.rule-item b {
  color: #f1f5f9;
}

.action-btn {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.5px;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

.primary-btn {
  background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
  color: #0f172a;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(245, 158, 11, 0.6);
}

.secondary-btn {
  background: #334155;
  color: #f8fafc;
  margin-top: 10px;
}

.secondary-btn:hover {
  background: #475569;
}

/* Stars & Level Complete */
.stars-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}

.star-icon {
  font-size: 38px;
  color: #334155;
}

.star-icon.star-active {
  color: #f59e0b;
  text-shadow: 0 0 16px rgba(245, 158, 11, 0.6);
  animation: starPop 0.4s ease-out;
}

@keyframes starPop {
  0% { transform: scale(0.2); }
  60% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.modal-title {
  font-size: 24px;
  font-weight: 900;
  margin-bottom: 6px;
}

.modal-desc {
  font-size: 13px;
  color: #94a3b8;
  margin-bottom: 16px;
}

.stats-box {
  background: #090e1a;
  border: 1px solid #1e293b;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 20px;
  font-size: 14px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  color: #94a3b8;
}

.stat-row b {
  color: #f8fafc;
}

.danger-icon {
  font-size: 48px;
  margin-bottom: 8px;
}
