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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #090b12;
  color: #f8fafc;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

#gameWrap {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

[hidden] {
  display: none !important;
}

.hud-top {
  position: fixed;
  top: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 10;
}

.hud-card {
  background: rgba(15, 17, 23, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: 18px;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 10px;
  font-weight: 800;
  color: #94a3b8;
  letter-spacing: 0.05em;
}

.stat-val {
  font-size: 22px;
  font-weight: 900;
  line-height: 1.1;
}

.speed-val {
  font-size: 26px;
  transition: color 0.12s ease, text-shadow 0.12s ease;
}
.speed-val.fast { color: #facc15; }
.speed-val.boost { color: #22d3ee; text-shadow: 0 0 12px rgba(34, 211, 238, 0.65); }

.stat-val small {
  font-size: 12px;
  color: #94a3b8;
}

.gold { color: #facc15; }
.green { color: #34d399; }
.cyan { color: #22d3ee; }

.siren-badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.22);
  border: 1px solid #ef4444;
  color: #fca5a5;
  font-size: 12px;
  font-weight: 900;
  animation: pulseSiren 0.45s infinite alternate;
}

@keyframes pulseSiren {
  from { background: rgba(239, 68, 68, 0.25); border-color: #ef4444; }
  to { background: rgba(59, 130, 246, 0.28); border-color: #3b82f6; }
}

.hud-bars {
  min-width: 220px;
}

.bar-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 4px;
}

.bar-track {
  height: 8px;
  border-radius: 999px;
  background: #1e293b;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0%;
  transition: width 0.08s linear;
}

.boost-fill {
  background: linear-gradient(90deg, #06b6d4, #6366f1);
}

.boost-fill.boost-ready {
  box-shadow: 0 0 12px rgba(34, 211, 238, 0.85);
  filter: brightness(1.15);
}

.hp-fill {
  width: 100%;
  background: linear-gradient(90deg, #10b981, #34d399);
}

.hud-bottom {
  position: fixed;
  bottom: 14px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 10;
}

.controls-hint {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.key-pill {
  padding: 6px 11px;
  border-radius: 999px;
  background: rgba(15, 17, 23, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-size: 11.5px;
  font-weight: 700;
}

.key-pill.accent { border-color: #6366f1; color: #a5b4fc; }
.key-pill.cyan-pill { border-color: #06b6d4; color: #67e8f9; }
.key-pill.gold-pill { border-color: #facc15; color: #fde047; }

.auto-gas-btn {
  pointer-events: auto;
  cursor: pointer;
  color: #94a3b8;
  transition: 0.15s ease;
}
.auto-gas-btn.active {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.hud-right-group {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.hud-icon-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pause-btn {
  pointer-events: auto;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(15, 17, 23, 0.88);
  color: #f8fafc;
  font-size: 16px;
  cursor: pointer;
  display: grid;
  place-items: center;
  backdrop-filter: blur(8px);
}
.pause-btn:hover { border-color: #facc15; }

.minimap-canvas {
  width: 112px;
  height: 112px;
  border-radius: 14px;
  background: rgba(15, 17, 23, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(8px);
}

.powerup-box {
  display: flex;
  align-items: center;
  gap: 10px;
  border-color: rgba(250, 204, 21, 0.45);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.powerup-box.ready {
  border-color: #facc15;
  animation: pulsePower 1.1s infinite alternate;
}

@keyframes pulsePower {
  from { box-shadow: 0 0 8px rgba(250, 204, 21, 0.28); }
  to { box-shadow: 0 0 20px rgba(250, 204, 21, 0.72); }
}

.pu-icon { font-size: 22px; }
.pu-label { font-size: 10px; font-weight: 800; color: #facc15; }
.pu-name { font-size: 13px; font-weight: 800; }

.countdown-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 92px;
  font-weight: 900;
  font-style: italic;
  color: #facc15;
  text-shadow: 5px 5px 0 #ef4444, -3px -3px 0 #0f172a;
  pointer-events: none;
  z-index: 25;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 11, 18, 0.82);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 30;
}

.menu-card {
  width: min(560px, 100%);
  max-height: 92dvh;
  overflow-y: auto;
  background: #131724;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}

.brand-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.brand-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.feedback-pill {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.14);
  color: #7dd3fc;
  font-size: 10.5px;
  font-weight: 800;
  cursor: pointer;
}
.feedback-pill:hover { filter: brightness(1.15); }

.feedback-card { width: min(420px, 100%); }

.fb-field {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.fb-field label {
  font-size: 11.5px;
  font-weight: 800;
  color: #cbd5e1;
}
.fb-field input, .fb-field select {
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #1b2133;
  color: #f8fafc;
  font-size: 13px;
}

.dbe-pill {
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.38);
  color: #34d399;
  font-size: 11px;
  font-weight: 800;
}

.best-pill {
  font-size: 12px;
  color: #94a3b8;
}

.best-pill strong { color: #facc15; }

.game-title {
  font-size: 44px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.game-title span { color: #facc15; }

.game-sub {
  margin-top: 6px;
  font-size: 13.5px;
  color: #94a3b8;
}

.section-label {
  margin-top: 18px;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 800;
  color: #94a3b8;
  letter-spacing: 0.06em;
}

.picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.toto-opt {
  background: #1b2133;
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 13px;
  padding: 10px;
  color: #f8fafc;
  text-align: left;
  cursor: pointer;
}

.toto-opt.active {
  border-color: #facc15;
  background: rgba(250, 204, 21, 0.1);
}

.toto-swatch {
  width: 34px;
  height: 18px;
  border-radius: 6px;
  margin-bottom: 7px;
}

.toto-name { font-size: 13px; font-weight: 800; }
.toto-tag { font-size: 10.5px; color: #94a3b8; margin-top: 2px; }

.upgrade-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.toto-mini {
  display: block;
  width: 28px;
  height: 40px;
  margin-bottom: 6px;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.55));
}

.upg-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 6px;
  border-radius: 10px;
  border: 1px solid rgba(250, 204, 21, 0.25);
  background: #1b2133;
  color: #f8fafc;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}
.upg-btn.affordable {
  border-color: rgba(16, 185, 129, 0.72);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.28);
}
.upg-btn.affordable::after {
  content: '+';
  position: absolute;
  top: -6px;
  right: -6px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #10b981;
  color: #0f172a;
  font-size: 12px;
  font-weight: 900;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}
.upg-btn:hover:not(:disabled) { border-color: #facc15; background: rgba(250, 204, 21, 0.12); }
.upg-btn:disabled { opacity: 0.48; cursor: not-allowed; }
.upg-btn strong { color: #facc15; }
.upg-btn small { font-size: 10px; color: #34d399; font-weight: 800; }

.city-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.city-btn {
  flex: 1 1 auto;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #1b2133;
  color: #cbd5e1;
  font-size: 11.5px;
  font-weight: 800;
  cursor: pointer;
}
.city-btn.active {
  border-color: #facc15;
  background: rgba(250, 204, 21, 0.16);
  color: #fde047;
}
.city-btn.locked {
  opacity: 0.55;
  border-style: dashed;
}

.track-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.race-opts-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
  align-items: center;
  justify-content: space-between;
}

.opt-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.opt-lbl {
  font-size: 10px;
  font-weight: 900;
  color: #94a3b8;
}

.mini-pills {
  display: flex;
  gap: 4px;
}

.mini-pill {
  padding: 5px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #1b2133;
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.mini-pill.active {
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.25);
  color: #fff;
}

.track-btn {
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #1b2133;
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.track-btn.active {
  border-color: #6366f1;
  background: rgba(99, 102, 241, 0.22);
  color: #fff;
}

.race-btn {
  width: 100%;
  margin-top: 18px;
  padding: 14px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #facc15, #f97316);
  color: #0f172a;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(249, 115, 22, 0.35);
}

.race-btn:hover { filter: brightness(1.05); }

.end-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.end-stats > div {
  background: #1b2133;
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}

.end-stats span { display: block; font-size: 10px; color: #94a3b8; font-weight: 800; }
.end-stats strong { font-size: 18px; font-weight: 900; color: #facc15; }

.end-actions {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 10px;
  margin-top: 6px;
}

.sec-btn {
  margin-top: 18px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: #1b2133;
  color: #f8fafc;
  font-weight: 800;
  cursor: pointer;
}
.sec-btn:hover { border-color: rgba(255, 255, 255, 0.35); }

.share-btn {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(16, 185, 129, 0.45);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.22), rgba(6, 182, 212, 0.18));
  color: #34d399;
  font-size: 13.5px;
  font-weight: 900;
  cursor: pointer;
  letter-spacing: 0.03em;
}
.share-btn:hover { filter: brightness(1.15); }

.onboard-hint {
  position: fixed;
  top: 26%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 22;
  pointer-events: none;
  text-align: center;
  width: min(92vw, 460px);
}

.onboard-pill {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(15, 17, 23, 0.86);
  border: 2px solid rgba(250, 204, 21, 0.75);
  color: #fde047;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.03em;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  animation: pulsePower 0.9s infinite alternate;
}

.challenge-banner {
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.16), rgba(249, 115, 22, 0.16));
  border: 1px solid rgba(250, 204, 21, 0.55);
  color: #fde047;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.touch-controls {
  position: fixed;
  bottom: 72px;
  left: 14px;
  right: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  z-index: 15;
  pointer-events: none;
  touch-action: none;
  user-select: none;
}

.touch-left, .touch-right {
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: auto;
  touch-action: none;
}

.steer-pad {
  position: relative;
  width: 156px;
  height: 62px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(15, 17, 23, 0.82);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  touch-action: none;
  user-select: none;
}

.steer-arrow {
  font-size: 16px;
  font-weight: 900;
  color: rgba(248, 250, 252, 0.45);
  pointer-events: none;
}

.steer-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(135deg, #facc15, #f97316);
  box-shadow: 0 4px 14px rgba(249, 115, 22, 0.45);
  pointer-events: none;
  transition: transform 0.04s linear;
}

.touch-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(15, 17, 23, 0.82);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  touch-action: none;
  user-select: none;
}

.touch-btn.active {
  transform: scale(0.93);
  filter: brightness(1.25);
}

.brake-btn { border-color: #ef4444; color: #fca5a5; }
.drift-btn { border-color: #6366f1; }
.boost-btn { border-color: #06b6d4; }
.power-btn { border-color: #facc15; }

@media (max-width: 720px) {
  .controls-hint { display: none; }
  .hud-top {
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    gap: 8px;
    flex-wrap: wrap;
  }
  .hud-card { padding: 7px 10px; border-radius: 11px; }
  .hud-stats { gap: 10px; flex: 1 1 100%; justify-content: space-between; }
  .stat-val { font-size: 17px; }
  .hud-bars { min-width: 145px; flex: 1; }
  .minimap-canvas { width: 68px; height: 68px; }
  .hud-bottom { bottom: calc(82px + env(safe-area-inset-bottom)); left: 10px; right: 10px; justify-content: flex-end; }
  .touch-controls {
    bottom: max(14px, env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
  }
  .steer-pad { width: 132px; height: 54px; }
  .touch-btn { width: 46px; height: 46px; font-size: 10.5px; }
  .menu-card { padding: 16px; }
  .game-title { font-size: 34px; }
  .toto-opt { padding: 8px 6px; }
  .toto-name { font-size: 11.5px; }
  .toto-tag { font-size: 9.5px; }
  .track-grid { grid-template-columns: repeat(2, 1fr); }
  .end-stats { grid-template-columns: repeat(2, 1fr); }
}

@media (max-height: 500px) {
  .controls-hint { display: none; }
  .touch-controls { bottom: max(10px, env(safe-area-inset-bottom)); }
  .hud-bottom { bottom: calc(74px + env(safe-area-inset-bottom)); justify-content: flex-end; }
  .menu-card { padding: 14px; }
  .game-title { font-size: 28px; }
}
