/* =============================================
   GRAND PRIX GAMBINO — Styles (mobile-first)
   Base rules = phone. Bigger screens get @media (min-width…) overrides.
   Look borrowed from GG: Anton display, Oswald UI, red glow + gold.
   ============================================= */

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

:root {
  --font-ui: 'Oswald', 'Arial Narrow', Impact, sans-serif;
  --font-display: 'Anton', Impact, 'Arial Black', sans-serif;
  --red: #dc2828;
  --gold: #ffce3a;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

html, body {
  width: 100%; height: 100%;
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: var(--font-ui);
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#gameCanvas { position: fixed; inset: 0; display: block; touch-action: none; }

#ui { position: fixed; inset: 0; pointer-events: none; }
.hidden { display: none !important; }
button { font-family: var(--font-ui); -webkit-tap-highlight-color: transparent; }

/* ── HUD ─────────────────────────────────── */
#hud {
  position: absolute; inset: 0; pointer-events: none;
}
#hudLeft {
  position: absolute;
  top: calc(8px + var(--sat)); left: calc(12px + var(--sal));
  text-shadow: 0 2px 0 #000, 0 0 12px rgba(0,0,0,0.8);
}
#hudPos {
  font-family: var(--font-display);
  font-size: 54px; line-height: 0.95; letter-spacing: -1px;
  color: #fff;
}
#hudPos.p1 { color: var(--gold); }
#hudPos.pop { animation: posPop 0.35s ease-out; }
#posSuf { font-size: 24px; margin-left: 2px; vertical-align: top; position: relative; top: 4px; }
@keyframes posPop { 0% { transform: scale(1.45); } 100% { transform: scale(1); } }
#hudLap {
  font-size: 16px; font-weight: 600; letter-spacing: 2px; color: #ddd; margin-top: 2px;
}
#hudLap b { color: #fff; font-size: 20px; }
#hudLap.final b { color: var(--gold); }
#hudTime {
  position: absolute;
  top: calc(12px + var(--sat)); left: 50%; transform: translateX(-50%);
  font-size: 16px; font-weight: 600; letter-spacing: 1px; color: #fff;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 #000, 0 0 10px rgba(0,0,0,0.8);
}
.icon-btn {
  position: absolute;
  top: calc(8px + var(--sat)); right: calc(10px + var(--sar));
  width: 46px; height: 46px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35);
  background: rgba(0,0,0,0.45);
  color: #fff; font-size: 14px; font-weight: 700;
  pointer-events: all; touch-action: manipulation;
}

/* ── Big centre callouts (countdown, FINAL LAP, WRONG WAY, place gains) ── */
#callout {
  position: absolute; left: 0; right: 0; top: 34%;
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(56px, 18vw, 140px);
  line-height: 1;
  color: #fff;
  text-shadow: 0 0 24px rgba(220,40,40,0.9), 4px 4px 0 rgba(120,0,0,0.85);
  opacity: 0;
  pointer-events: none;
}
#callout.show { animation: calloutPop 0.9s ease-out forwards; }
#callout.hold { opacity: 1; animation: calloutPulse 0.6s ease-in-out infinite alternate; }
#callout.small { font-size: clamp(34px, 10vw, 72px); }
#callout.gold { color: var(--gold); text-shadow: 0 0 24px rgba(255,180,40,0.8), 4px 4px 0 rgba(90,59,0,0.9); }
#callout.warn { color: #ff4b4b; }
@keyframes calloutPop {
  0%   { opacity: 0; transform: scale(2.2); }
  18%  { opacity: 1; transform: scale(0.95); }
  28%  { transform: scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1.05); }
}
@keyframes calloutPulse { from { transform: scale(1); } to { transform: scale(1.06); } }

/* ── Touch controls ──────────────────────── */
#mobileControls { position: absolute; inset: 0; pointer-events: none; }
#joystickZone {
  position: absolute;
  left: 0; bottom: 0;
  width: 55%;
  top: calc(90px + var(--sat));      /* below the HUD so the pause button stays tappable */
  pointer-events: all;
  touch-action: none;
}
#joystickBase {
  position: absolute;
  width: 130px; height: 130px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
  border: 2px solid rgba(255,255,255,0.18);
  left: calc(24px + var(--sal));
  bottom: calc(40px + var(--sab));
  opacity: 0.5;
  pointer-events: none;
}
#joystickKnob {
  position: absolute;
  width: 46px; height: 46px;
  border-radius: 50%;
  background: rgba(255,255,255,0.28);
  border: 2px solid rgba(255,255,255,0.65);
  opacity: 0.4;
  pointer-events: none;
  left: calc(66px + var(--sal));
  bottom: calc(82px + var(--sab));
}
#actionBtns {
  position: absolute;
  right: calc(16px + var(--sar));
  bottom: calc(22px + var(--sab));
  width: 180px; height: 110px;
  pointer-events: none;
}
.abtn {
  position: absolute;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.28);
  background: rgba(0,0,0,0.55);
  color: #fff; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  pointer-events: all; touch-action: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.abtn-nitro {
  width: 88px; height: 88px; right: 0; bottom: 0;
  font-size: 30px;
  border-color: rgba(255,123,0,0.9);
  background: rgba(255,123,0,0.22);
  box-shadow: 0 0 18px rgba(255,123,0,0.4);
  flex-direction: column;
}
.abtn-nitro.down { background: rgba(255,123,0,0.55); transform: scale(0.92); }
.abtn-nitro.empty { opacity: 0.45; filter: grayscale(0.7); }
#nitroMeter {
  position: absolute; bottom: 10px; left: 18%;
  width: 64%; height: 8px;
  background: rgba(0,0,0,0.6);
  border-radius: 4px; overflow: hidden;
  box-shadow: 0 0 6px rgba(255,123,0,0.55);
}
#nitroFill { height: 100%; width: 100%; background: linear-gradient(90deg, #ff7b00, #ffd23f); }
.abtn-fire {
  width: 72px; height: 72px; right: 100px; bottom: 8px;
  font-size: 14px; letter-spacing: 1px;
  border-color: rgba(220,40,40,0.85);
  background: rgba(220,40,40,0.22);
}

#kbHint {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(14px + var(--sab));
  font-size: 12px; letter-spacing: 2px; color: rgba(255,255,255,0.6);
  text-shadow: 0 1px 0 #000;
  white-space: nowrap;
}

/* ── Screens (title / pause / results) ───── */
.screen {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: all;
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
  overflow-y: auto;
}
#title { background: radial-gradient(ellipse at center, rgba(0,0,0,0.35) 0%, rgba(0,0,0,0.78) 70%); }
#pause, #results { background: rgba(0,0,0,0.62); }

.title-content { text-align: center; max-width: 560px; width: 100%; animation: fadeUp 0.7s ease-out both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: none; } }
.eyebrow {
  color: var(--red); font-size: 11px; letter-spacing: 8px; margin-bottom: 12px; opacity: 0.85;
  animation: flicker 4s infinite;
}
@keyframes flicker { 0%, 94%, 96%, 98%, 100% { opacity: 0.85; } 95%, 97%, 99% { opacity: 0.25; } }
.game-title {
  font-family: var(--font-display);
  font-size: clamp(50px, 15vw, 104px);
  font-weight: 400; line-height: 0.9; letter-spacing: -1px;
  color: #fff;
  text-shadow: 0 0 20px rgba(220,40,40,0.9), 0 0 60px rgba(220,40,40,0.5), 4px 4px 0 rgba(120,0,0,0.8);
}
.game-title .t-top { font-size: 0.62em; letter-spacing: 2px; }
.game-title .t-gold {
  color: var(--gold);
  -webkit-text-stroke: 2px #111; paint-order: stroke fill;
  text-shadow: 0 2px 0 #5a3b00, 4px 4px 0 rgba(0,0,0,0.55), 0 0 26px rgba(255,180,40,0.55);
}
.title-line {
  width: 90px; height: 2px; margin: 16px auto;
  background: linear-gradient(to right, transparent, var(--red), transparent);
}
.tagline { color: #bbb; font-size: 15px; letter-spacing: 1px; margin-bottom: 16px; }
.roster { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; align-items: center; margin-bottom: 22px; }
.chip {
  border: 2px solid var(--c); color: var(--c);
  padding: 4px 10px; font-weight: 700; letter-spacing: 2px; font-size: 13px;
  background: rgba(0,0,0,0.5);
  display: flex; flex-direction: column; line-height: 1.1;
}
.chip small { font-size: 9px; letter-spacing: 2px; color: #999; font-weight: 500; }
.vs { font-family: var(--font-display); color: var(--red); font-size: 18px; padding: 0 4px; }

.big-btn {
  display: block; margin: 0 auto 12px;
  min-width: 240px; min-height: 60px; padding: 14px 40px;
  background: var(--red); color: #fff; border: none;
  font-size: 18px; font-weight: 700; letter-spacing: 4px;
  clip-path: polygon(10px 0%, 100% 0%, calc(100% - 10px) 100%, 0% 100%);
  box-shadow: 0 0 30px rgba(220,40,40,0.4);
  animation: btnPulse 2s ease-in-out infinite;
  cursor: pointer; touch-action: manipulation;
}
.big-btn:active { transform: scale(0.96); }
@keyframes btnPulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.18); } }
.wide-btn {
  display: block; margin: 0 auto 10px;
  min-width: 240px; min-height: 48px; padding: 10px 30px;
  background: rgba(255,255,255,0.08); color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  font-size: 15px; font-weight: 600; letter-spacing: 3px;
  cursor: pointer; touch-action: manipulation;
}
.wide-btn:active { background: rgba(255,255,255,0.18); }
.settings-row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.pill-btn {
  min-height: 44px; padding: 8px 14px;
  background: rgba(0,0,0,0.5); color: #ddd;
  border: 1px solid rgba(255,255,255,0.22); border-radius: 22px;
  font-size: 13px; font-weight: 600; letter-spacing: 1px;
  cursor: pointer; touch-action: manipulation;
}
.title-hint { margin-top: 14px; color: #777; font-size: 12px; letter-spacing: 1px; min-height: 16px; }

.panel {
  width: 100%; max-width: 420px;
  background: rgba(10,10,12,0.88);
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  padding: 22px 18px 16px;
  text-align: center;
  animation: popIn 0.22s ease-out both;
}
@keyframes popIn { from { opacity: 0; transform: translateY(10px) scale(0.97); } to { opacity: 1; transform: none; } }
.panel-title { font-family: var(--font-display); font-size: 44px; letter-spacing: 2px; margin-bottom: 16px; }

.res-place {
  font-family: var(--font-display); font-size: 84px; line-height: 0.95;
  text-shadow: 0 0 24px rgba(220,40,40,0.8), 4px 4px 0 rgba(120,0,0,0.85);
}
.res-place.p1 { color: var(--gold); text-shadow: 0 0 26px rgba(255,180,40,0.7), 4px 4px 0 rgba(90,59,0,0.9); }
.res-line { color: #ccc; font-size: 15px; margin: 6px 0 14px; min-height: 20px; font-style: italic; }
.res-list { list-style: none; margin: 0 auto 14px; max-width: 320px; text-align: left; }
.res-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; margin-bottom: 4px;
  background: rgba(255,255,255,0.05);
  border-left: 4px solid var(--c);
  font-size: 16px; font-weight: 600; letter-spacing: 1px;
}
.res-list li.me { background: rgba(255,206,58,0.12); }
.res-list .n { width: 22px; color: #999; }
.res-list .who { flex: 1; color: var(--c); }
.res-list .t { color: #ddd; font-variant-numeric: tabular-nums; }
.res-stats { display: flex; justify-content: center; gap: 18px; margin-bottom: 16px; }
.res-stats div { display: flex; flex-direction: column; }
.res-stats small { color: #888; font-size: 10px; letter-spacing: 2px; }
.res-stats b { font-size: 18px; font-variant-numeric: tabular-nums; }

#debug {
  position: absolute; left: calc(8px + var(--sal)); bottom: calc(8px + var(--sab));
  font: 11px/1.35 ui-monospace, Menlo, monospace; color: #7f7;
  background: rgba(0,0,0,0.6); padding: 4px 6px; white-space: pre;
}

/* ── Bigger screens ──────────────────────── */
@media (min-width: 768px) and (min-height: 600px) {
  #hudPos { font-size: 72px; }
  #posSuf { font-size: 30px; }
  #hudLap { font-size: 20px; }
  #hudTime { font-size: 20px; }
  .abtn-nitro { width: 100px; height: 100px; }
}

/* Short landscape phones: tighten the title so it fits */
@media (max-height: 500px) {
  .game-title { font-size: clamp(40px, 11vh, 70px); }
  .title-line { margin: 8px auto; }
  .tagline { margin-bottom: 8px; font-size: 13px; }
  .roster { margin-bottom: 10px; }
  .big-btn { min-height: 50px; padding: 10px 36px; margin-bottom: 8px; }
  .res-place { font-size: 56px; }
  .panel { padding: 12px 14px 10px; }
  .res-list li { padding: 3px 8px; font-size: 14px; }
  #hudPos { font-size: 44px; }
  #callout { top: 26%; }
}
