/* ================= base ================= */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: #10123A;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Cairo', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #10123A;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }
button, .carcard, .chip { user-select: none; -webkit-user-select: none; }

.game-root {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: #10123A;
}

/* ================= HUD ================= */
.hud {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 7px 8px 6px;
  background: #10123A;
  z-index: 5;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}

.hud-row-2 { gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 7px;
  border: 2.5px solid #FFF3E4;
  border-radius: 11px;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  color: #FFF3E4;
  white-space: nowrap;
  box-shadow: 2.5px 2.5px 0 rgba(0, 0, 0, 0.35);
  flex: 0 0 auto;
}

.chip b { font-size: 13px; letter-spacing: 0.2px; }
.chip .c-label { font-size: 10px; opacity: 0.85; font-weight: 700; }
.chip .c-unit { font-size: 10px; opacity: 0.85; font-weight: 700; }

.chip-hearts { background: #2B4BF2; padding: 4px 6px; gap: 2px; }
.chip-hearts .hh {
  width: 13px; height: 13px; fill: #FFF3E4;
  transition: opacity .2s ease, transform .2s ease;
}
.chip-hearts .hh.lost { opacity: 0.22; transform: scale(0.82); }

.chip-dist { background: #FF2D95; }
.chip-speed { background: #2B4BF2; }
.chip-combo {
  background: #FF7A3C;
  color: #10123A;
  border-color: #FFF3E4;
  min-width: 42px;
  justify-content: center;
  transition: transform .12s ease;
}
.chip-combo.bump { transform: scale(1.18); }

.pause-btn {
  margin-inline-start: auto;
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 11px;
  border: 2.5px solid #FFF3E4;
  background: #1B1E4E;
  color: #FFF3E4;
  box-shadow: 2.5px 2.5px 0 rgba(0, 0, 0, 0.35);
  cursor: pointer;
  padding: 0;
}
.pause-btn svg { width: 16px; height: 16px; fill: currentColor; }
.pause-btn:active { transform: translate(1px, 1px); }
.pause-btn[hidden] { display: none; }

.nitro-track {
  flex: 1 1 auto;
  min-width: 40px;
  height: 13px;
  background: #1B1E4E;
  border: 2.5px solid #FFF3E4;
  border-radius: 99px;
  overflow: hidden;
  box-shadow: 2.5px 2.5px 0 rgba(0, 0, 0, 0.35);
}
.nitro-fill {
  height: 100%;
  width: 0%;
  background: #22E0D6;
  border-radius: 99px;
  transition: width .1s linear, background .2s;
}
.nitro-track.full .nitro-fill { background: #FFF3E4; }

.nitro-word {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 900;
  color: #22E0D6;
  letter-spacing: 0.5px;
}

/* ================= stage ================= */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #10123A;
  touch-action: none;
}

#game {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* ================= controls ================= */
.controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px 10px;
  background: #10123A;
  border-top: 3px solid #1B1E4E;
}

.ctl-group { display: flex; align-items: center; gap: 9px; }

.pad-btn {
  width: 68px; height: 62px;
  border-radius: 20px;
  border: 3px solid #FFF3E4;
  background: #2B4BF2;
  color: #FFF3E4;
  display: grid; place-items: center;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.4);
  cursor: pointer;
  padding: 0;
  transition: transform .07s ease, background .12s ease;
}
.pad-btn svg { width: 26px; height: 26px; }
.pad-btn:active, .pad-btn.pressed {
  transform: translate(2px, 2px);
  background: #FF2D95;
  box-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
}

.nitro-btn {
  height: 62px;
  min-width: 96px;
  padding: 0 16px;
  border-radius: 20px;
  border: 3px solid #FFF3E4;
  background: #3B2E63;
  color: #9B93C4;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  font-weight: 900; font-size: 14px;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform .07s ease, background .15s ease, color .15s ease;
}
.nitro-btn svg { width: 20px; height: 20px; fill: currentColor; }
.nitro-btn.ready {
  background: #22E0D6;
  color: #10123A;
  animation: nitroPulse 1.15s ease-in-out infinite;
}
.nitro-btn:active { transform: translate(2px, 2px); }
.nitro-btn.ready:active { background: #FFF3E4; }

@keyframes nitroPulse {
  0%, 100% { box-shadow: 4px 4px 0 rgba(0,0,0,.4), 0 0 0 0 rgba(34,224,214,.65); }
  50% { box-shadow: 4px 4px 0 rgba(0,0,0,.4), 0 0 0 10px rgba(34,224,214,0); }
}

/* ================= overlays ================= */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: rgba(16, 18, 58, 0.78);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.overlay.hidden { display: none !important; }

.over-overlay { padding-top: clamp(56px, 15vh, 112px); }

.panel {
  width: 100%;
  max-width: 380px;
  margin: auto 0;
  background: #FFF3E4;
  border: 4px solid #10123A;
  border-radius: 24px;
  box-shadow: 7px 7px 0 rgba(16, 18, 58, 0.55);
  padding: 16px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  text-align: center;
  color: #10123A;
}

.panel-sm { max-width: 320px; }

/* logo */
.logo { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.logo-sun {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(180deg, #FF2D95 0%, #FF7A3C 100%);
  border: 3px solid #10123A;
  margin-bottom: 2px;
}
.logo h1 {
  font-family: 'Baloo Bhaijaan 2', 'Cairo', sans-serif;
  font-size: 30px;
  font-weight: 800;
  margin: 0;
  line-height: 1.1;
  color: #FF2D95;
  letter-spacing: 0;
}
.logo p { margin: 0; font-size: 12px; font-weight: 700; color: #4A4770; }

.panel h2 {
  font-family: 'Baloo Bhaijaan 2', 'Cairo', sans-serif;
  font-size: 23px;
  margin: 0;
  font-weight: 800;
  color: #10123A;
}
.panel .sub { margin: -4px 0 4px; font-size: 12.5px; color: #4A4770; font-weight: 600; }

/* car picker */
.cars {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.carcard {
  flex: 1 1 0;
  min-width: 0;
  background: #EBE2D2;
  border: 3px solid #10123A;
  border-radius: 16px;
  padding: 6px 2px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  color: #10123A;
  font-weight: 900;
  font-size: 11.5px;
  transition: background .15s ease, transform .12s ease, box-shadow .15s ease;
  box-shadow: 3px 3px 0 rgba(16,18,58,.28);
}
.carcard canvas { display: block; }
.carcard.selected {
  background: #FF2D95;
  color: #FFF3E4;
  transform: translateY(-2px);
  box-shadow: 3px 5px 0 rgba(16,18,58,.35);
}
.carcard:active { transform: translateY(1px); }

/* buttons */
.btn-primary {
  width: 100%;
  min-height: 50px;
  border-radius: 16px;
  border: 3px solid #10123A;
  background: #FF7A3C;
  color: #10123A;
  font-weight: 900;
  font-size: 17px;
  cursor: pointer;
  box-shadow: 4px 4px 0 #10123A;
  transition: transform .08s ease, box-shadow .08s ease, background .15s ease;
  padding: 10px 14px;
}
.btn-primary:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 #10123A;
}
.btn-primary:focus-visible, .btn-ghost:focus-visible,
.pad-btn:focus-visible, .nitro-btn:focus-visible, .carcard:focus-visible,
.pause-btn:focus-visible, .lb-join:focus-visible {
  outline: 3px solid #22E0D6;
  outline-offset: 2px;
}

.btn-ghost {
  width: 100%;
  min-height: 44px;
  border-radius: 14px;
  border: 3px solid #10123A;
  background: transparent;
  color: #10123A;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  padding: 8px 12px;
  transition: background .15s ease;
}
.btn-ghost:active { background: rgba(16,18,58,.08); }

.best-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
  font-size: 12.5px;
  font-weight: 700;
  color: #4A4770;
}
.best-row b { font-size: 19px; color: #FF2D95; font-weight: 900; }

.hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.6;
  color: #6A6790;
  font-weight: 600;
}

/* game over */
.bigscore {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  background: #10123A;
  border-radius: 18px;
  padding: 8px 14px;
  margin: -2px 0 0;
}
.bigscore b {
  font-family: 'Baloo Bhaijaan 2', 'Cairo', sans-serif;
  font-size: 40px;
  line-height: 1;
  color: #FFF3E4;
  font-weight: 800;
}
.bigscore span { font-size: 15px; font-weight: 900; color: #22E0D6; }

.stats {
  display: flex;
  gap: 7px;
}
.stats > div {
  flex: 1 1 0;
  min-width: 0;
  background: #EBE2D2;
  border: 2.5px solid #10123A;
  border-radius: 13px;
  padding: 6px 3px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.stats span { font-size: 10px; font-weight: 700; color: #5C5880; }
.stats b { font-size: 16px; font-weight: 900; color: #10123A; }

/* leaderboard */
.lb {
  border-top: 2.5px dashed #C9BFAE;
  padding-top: 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lb-title { font-size: 12px; font-weight: 900; color: #4A4770; }
.lb-list { display: flex; flex-direction: column; gap: 4px; }
.lb-row {
  display: flex;
  align-items: center;
  gap: 7px;
  background: #EBE2D2;
  border-radius: 10px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}
.lb-row .r { color: #FF2D95; min-width: 18px; font-weight: 900; }
.lb-row .h { flex: 1 1 auto; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .s { color: #10123A; font-variant-numeric: tabular-nums; }
.lb-row.you { background: #FFD34E; }
.lb-empty { font-size: 11.5px; color: #7A7699; font-weight: 600; padding: 4px 0; }
.lb-note { margin: -4px 0 0; font-size: 10px; color: #8C88AA; font-weight: 600; }
.lb-join {
  border: 2.5px solid #10123A;
  background: #22E0D6;
  color: #10123A;
  border-radius: 11px;
  font-weight: 900;
  font-size: 12px;
  padding: 8px;
  cursor: pointer;
}

/* ================= responsive ================= */
@media (max-height: 700px) {
  .logo h1 { font-size: 25px; }
  .panel { gap: 9px; padding: 13px 13px 15px; }
  .bigscore b { font-size: 33px; }
}

@media (max-height: 560px) {
  .logo-sun { display: none; }
  .logo h1 { font-size: 21px; }
  .logo p { font-size: 11px; }
  .carcard canvas { height: 52px !important; }
  .panel { border-radius: 18px; padding: 11px 11px 13px; gap: 7px; }
  .bigscore b { font-size: 27px; }
  .hint { display: none; }
  .pad-btn { height: 54px; width: 60px; border-radius: 16px; }
  .nitro-btn { height: 54px; min-width: 84px; border-radius: 16px; }
  .controls { padding: 5px 10px 7px; }
  .hud { padding: 5px 6px 4px; gap: 4px; }
  .chip { font-size: 10px; padding: 2px 6px; border-width: 2px; }
  .chip b { font-size: 12px; }
}

@media (max-height: 380px) {
  .carcard span { display: none; }
  .carcard canvas { height: 44px !important; }
  .logo-sun { display: none; }
}

@media (max-width: 350px) {
  .chip .c-label { display: none; }
  .pad-btn { width: 62px; }
  .nitro-btn { min-width: 88px; padding: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .nitro-btn.ready { animation: none; }
  * { transition-duration: .01ms !important; }
}