* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  background: #14102b;
  font-family: -apple-system, "Segoe UI", system-ui, sans-serif;
  user-select: none; -webkit-user-select: none;
}

#game, #game canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; text-align: center;
  background: rgba(10, 8, 30, 0.82);
  backdrop-filter: blur(4px);
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}

.overlay h1 {
  font-size: clamp(52px, 12vw, 110px);
  font-weight: 900; letter-spacing: 2px;
  color: #ffd42a;
  text-shadow: 0 4px 0 #c2320a, 0 8px 24px rgba(0,0,0,.6);
  transform: rotate(-2deg);
}

.busted-title {
  color: #ff3b3b !important;
  text-shadow: 0 4px 0 #1e2b8f, 0 8px 24px rgba(0,0,0,.6) !important;
  animation: busted-flash .5s steps(2) infinite;
}
@keyframes busted-flash {
  0% { color: #ff3b3b; } 50% { color: #4d7bff; }
}

.tag { color: #cfc9ff; font-size: 17px; line-height: 1.5; font-weight: 600; }
.keys { color: #8f88c2; font-size: 14px; font-weight: 600; }

.busted-score { font-size: 44px; font-weight: 900; color: #fff; }
.busted-best { font-size: 18px; font-weight: 700; color: #ffd42a; }

.big-btn {
  font-size: 26px; font-weight: 900; letter-spacing: 1px;
  padding: 18px 44px; border: none; border-radius: 18px;
  background: linear-gradient(#ff5a3c, #d92b0f);
  color: #fff; cursor: pointer;
  box-shadow: 0 6px 0 #8f1a05, 0 12px 24px rgba(0,0,0,.5);
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #8f1a05; }

/* car picker */
#cars { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; max-width: 520px; }
.car-card {
  border: 3px solid rgba(255,255,255,.2); border-radius: 14px;
  background: rgba(255,255,255,.07); color: #fff; cursor: pointer;
  padding: 10px 14px; text-align: center; min-width: 108px;
  font-family: inherit;
}
.car-card b { display: block; font-size: 17px; font-weight: 900; letter-spacing: 1px; }
.car-card i { display: block; font-style: normal; font-size: 11px; color: #cfc9ff; margin-top: 2px; }
.car-card s { display: block; text-decoration: none; font-size: 12px; margin-top: 4px; }
.car-card.sel { border-color: #ffd42a; background: rgba(255,212,42,.16); transform: scale(1.06); box-shadow: 0 0 18px rgba(255,212,42,.4); }

/* colour swatches */
#swatches { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; max-width: 420px; }
.swatch {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.25); cursor: pointer;
  transition: transform .1s;
}
.swatch.sel { border-color: #ffd42a; transform: scale(1.25); box-shadow: 0 0 16px rgba(255,212,42,.7); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }

#score-box {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); left: 14px;
  color: #fff; text-shadow: 0 2px 6px rgba(0,0,0,.8);
}
#score { font-size: 34px; font-weight: 900; }
#best { font-size: 13px; font-weight: 700; color: #ffd42a; }
#hearts { font-size: 17px; margin-top: 3px; letter-spacing: 1px; }

#heat-box {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  width: min(46vw, 260px); text-align: center;
}
.heat-label { font-size: 13px; font-weight: 900; color: #fff; text-shadow: 0 2px 4px #000; }
#heat-bar {
  margin-top: 4px; height: 14px; border-radius: 8px;
  background: rgba(0,0,0,.5); border: 2px solid rgba(255,255,255,.3); overflow: hidden;
}
#heat-fill {
  height: 100%; width: 50%; border-radius: 6px;
  background: linear-gradient(90deg, #ff3b3b, #4d7bff);
  transition: width .15s linear;
}

#wheels-box {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 14px;
  font-size: 22px; letter-spacing: 2px; text-shadow: 0 2px 6px rgba(0,0,0,.8);
}
.wheel-dot.gone { opacity: .18; filter: grayscale(1); }

#boost-box {
  position: absolute; bottom: calc(118px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); width: min(50vw, 300px);
}
#boost-bar {
  height: 12px; border-radius: 8px;
  background: rgba(0,0,0,.5); border: 2px solid rgba(255,255,255,.3); overflow: hidden;
}
#boost-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff9d00, #ffd42a); border-radius: 6px; }

/* big touch buttons */
.ctl-btn {
  position: absolute; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 92px; height: 92px; border-radius: 50%;
  border: none; pointer-events: auto; cursor: pointer;
  font-size: 34px; font-weight: 900; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-shadow: 0 2px 4px rgba(0,0,0,.6);
}
.ctl-btn span { font-size: 13px; letter-spacing: 1px; }
#btn-boost {
  right: 18px;
  background: radial-gradient(circle at 35% 30%, #ff7a52, #d92b0f 70%);
  box-shadow: 0 5px 0 #8f1a05, 0 10px 20px rgba(0,0,0,.5);
}
#btn-pop {
  left: 18px;
  background: radial-gradient(circle at 35% 30%, #6a6a7a, #23232e 70%);
  box-shadow: 0 5px 0 #0c0c12, 0 10px 20px rgba(0,0,0,.5);
}
.ctl-btn:active, .ctl-btn.pressed { transform: translateY(4px); }

#btn-drift {
  right: 22px; bottom: calc(122px + env(safe-area-inset-bottom));
  width: 72px; height: 72px; font-size: 26px;
  background: radial-gradient(circle at 35% 30%, #6a8ae8, #22348f 70%);
  box-shadow: 0 5px 0 #101a4a, 0 10px 20px rgba(0,0,0,.5);
}
#btn-drift span { font-size: 11px; }

/* cop proximity screen flash */
#hud::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  opacity: var(--danger, 0);
  background:
    linear-gradient(90deg, rgba(255,40,40,.35), transparent 30%, transparent 70%, rgba(60,90,255,.35));
  animation: danger-strobe .4s steps(2) infinite;
}
@keyframes danger-strobe { 0% { filter: hue-rotate(0deg); } 50% { filter: hue-rotate(180deg); } }
