/* Vroom Boom Buggies — candy-neon arcade theme.
   Palette mirrors CONFIG.COLORS in src/config.js. */

:root {
  --bg: #1b1035;
  --road: #3d2b63;
  --edge: #ff6fd8;
  --grass: #3fd97f;
  --pink: #ff5ccf;
  --blue: #2fd4ff;
  --orange: #ff9f1c;
  --green: #4fdc4f;
  --purple: #7a5cff;
  --teal: #00e5c0;
  --red: #ff4f4f;
  --yellow: #ffe63d;
  --font-fun: 'Comic Sans MS', 'Chalkboard SE', 'Baloo', 'Comic Neue', cursive, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh; /* mobile URL bars: prefer dynamic viewport height */
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font-fun);
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}

/* Hidden probe that exposes env(safe-area-inset-*) to JS (see main.js). */
#safe-area-probe {
  position: fixed;
  left: -9999px;
  top: -9999px;
  visibility: hidden;
  pointer-events: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- Screens ------------------------------------------------------------- */

#screens { position: fixed; inset: 0; pointer-events: none; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start; /* centering handled by ::before/::after below */
  gap: 18px;
  padding: 24px;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  pointer-events: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100vw;
}
.screen.active { display: flex; }

/* Center content when it fits, scroll from the top when it doesn't. */
.screen::before,
.screen::after {
  content: '';
  display: block;
  margin: auto;
}
.screen > * { flex-shrink: 0; }

.overlay-screen {
  background: rgba(27, 16, 53, 0.82);
  z-index: 30;
}

.game-title {
  font-size: clamp(44px, 9vw, 96px);
  line-height: 1.02;
  text-align: center;
  letter-spacing: 2px;
  background: linear-gradient(90deg, var(--pink), var(--yellow), var(--teal), var(--blue), var(--pink));
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: title-slide 6s linear infinite;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.45)) drop-shadow(0 0 22px rgba(255, 111, 216, 0.55));
}

@keyframes title-slide {
  0% { background-position: 0% 50%; }
  100% { background-position: 300% 50%; }
}

.tagline {
  font-size: clamp(16px, 2.4vw, 24px);
  color: var(--yellow);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

.screen-title {
  font-size: clamp(30px, 5vw, 52px);
  color: var(--edge);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.55), 0 0 18px rgba(255, 111, 216, 0.6);
}

/* --- Buttons -------------------------------------------------------------- */

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.big-btn {
  font-family: var(--font-fun);
  font-size: clamp(18px, 2.6vw, 26px);
  font-weight: bold;
  color: #fff;
  border: 4px solid rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  padding: 12px 38px;
  min-width: min(300px, 82vw);
  min-height: 48px; /* comfortable tap target */
  cursor: pointer;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.4), 0 0 16px rgba(255, 255, 255, 0.15);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.12s ease;
}
.big-btn:hover { transform: scale(1.05) rotate(-1deg); filter: brightness(1.12); }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4); }
.big-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-pink { background: linear-gradient(180deg, #ff7ade, var(--pink)); }
.btn-blue { background: linear-gradient(180deg, #63e3ff, #12a8dd); }
.btn-orange { background: linear-gradient(180deg, #ffbe55, var(--orange)); }
.btn-green { background: linear-gradient(180deg, #7bf07b, #2cb32c); }
.btn-purple { background: linear-gradient(180deg, #9d84ff, var(--purple)); }
.btn-teal { background: linear-gradient(180deg, #4cf3d8, #00b392); }
.btn-back { background: linear-gradient(180deg, #8d8da8, #55556e); min-width: 200px; }
.btn-small { min-width: 140px; padding: 8px 20px; font-size: 18px; }

.coin-pill {
  font-size: 24px;
  font-weight: bold;
  background: rgba(0, 0, 0, 0.45);
  border: 3px solid var(--yellow);
  border-radius: 999px;
  padding: 6px 22px;
  color: var(--yellow);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

/* --- Track select cards ---------------------------------------------------- */

.card-row {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
  justify-content: center;
}

.track-card {
  font-family: var(--font-fun);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 240px;
  max-width: 86vw;
  padding: 26px 18px;
  border-radius: 26px;
  border: 4px solid var(--edge);
  background: linear-gradient(180deg, rgba(61, 43, 99, 0.95), rgba(27, 16, 53, 0.95));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 0 22px rgba(255, 111, 216, 0.35);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.track-card:hover { transform: scale(1.06) rotate(1deg); box-shadow: 0 0 34px rgba(255, 111, 216, 0.7); }
.track-emoji { font-size: 54px; }
.track-name { font-size: 24px; font-weight: bold; }
.track-sub { font-size: 15px; color: var(--teal); }

/* --- Settings ---------------------------------------------------------------- */

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: rgba(61, 43, 99, 0.85);
  border: 4px solid var(--teal);
  border-radius: 26px;
  padding: 28px 34px;
  box-shadow: 0 0 22px rgba(0, 229, 192, 0.3);
  max-width: 94vw;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 26px;
  font-size: 22px;
  font-weight: bold;
  flex-wrap: wrap;
}

input[type="range"] {
  width: 200px;
  accent-color: var(--pink);
  height: 28px;
  cursor: pointer;
}

/* --- Pre-race controls card -------------------------------------------------- */

.controls-card {
  background: rgba(0, 0, 0, 0.5);
  border: 4px dashed var(--yellow);
  border-radius: 22px;
  padding: 20px 30px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: clamp(16px, 2.2vw, 22px);
  text-align: center;
}

kbd {
  display: inline-block;
  background: #fff;
  color: #222;
  border-radius: 8px;
  padding: 2px 10px;
  margin: 0 2px;
  font-family: var(--font-fun);
  font-weight: bold;
  box-shadow: 0 3px 0 #999;
}

/* --- Garage / stats shared panel bits ----------------------------------------- */

.screen-wide { justify-content: flex-start; padding-top: 4vh; }

.panel {
  background: rgba(27, 16, 53, 0.92);
  border: 4px solid var(--edge);
  border-radius: 26px;
  padding: 18px 22px;
  box-shadow: 0 0 24px rgba(255, 111, 216, 0.35);
  max-width: 94vw;
}

.controls-card {
  max-width: 94vw;
}

.garage-layout {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  max-width: 1200px;
}

.garage-left, .garage-right {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.part-category-title {
  font-size: 22px;
  color: var(--yellow);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

.part-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.part-card {
  font-family: var(--font-fun);
  width: 168px;
  min-height: 150px;
  border-radius: 18px;
  border: 3px solid rgba(255, 255, 255, 0.5);
  background: linear-gradient(180deg, rgba(61, 43, 99, 0.95), rgba(20, 12, 42, 0.95));
  color: #fff;
  padding: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  text-align: center;
  transition: transform 0.08s ease, border-color 0.08s ease, box-shadow 0.08s ease;
}
.part-card:hover { transform: translateY(-3px); }
.part-card.selected {
  border-color: var(--yellow);
  box-shadow: 0 0 16px rgba(255, 230, 61, 0.65);
}
.part-card.locked { opacity: 0.75; }
.part-name { font-size: 16px; font-weight: bold; color: var(--teal); }
.part-blurb { font-size: 12px; line-height: 1.25; color: #d8ccf5; flex: 1; }
.part-cost { font-size: 14px; font-weight: bold; color: var(--yellow); }
.part-owned { font-size: 13px; font-weight: bold; color: var(--green); }

.stat-bars { display: flex; flex-direction: column; gap: 8px; width: 260px; max-width: 78vw; }
.stat-bar-row { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: bold; }
.stat-bar-label { width: 92px; text-align: right; }
.stat-bar-track {
  flex: 1;
  height: 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid rgba(255, 255, 255, 0.4);
  overflow: hidden;
}
.stat-bar-fill { height: 100%; border-radius: 999px; transition: width 0.2s ease; }

.paint-row, .decal-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.paint-swatch {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.55);
  cursor: pointer;
  transition: transform 0.08s ease;
}
.paint-swatch:hover { transform: scale(1.15); }
.paint-swatch.selected { border-color: #fff; box-shadow: 0 0 12px #fff; transform: scale(1.15); }

.decal-chip {
  font-family: var(--font-fun);
  font-size: 22px;
  background: rgba(61, 43, 99, 0.9);
  border: 3px solid rgba(255, 255, 255, 0.45);
  border-radius: 14px;
  padding: 4px 10px;
  cursor: pointer;
  color: #fff;
}
.decal-chip.selected { border-color: var(--yellow); box-shadow: 0 0 12px rgba(255, 230, 61, 0.7); }

.preview-canvas {
  border-radius: 20px;
  border: 4px solid var(--teal);
  background: linear-gradient(180deg, #241546, #160d31);
  box-shadow: 0 0 18px rgba(0, 229, 192, 0.35);
  max-width: min(260px, 72vw);
  height: auto;
}

/* --- Stats ------------------------------------------------------------------- */

.stats-grid {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 1100px;
}

.stat-card {
  min-width: 150px;
  padding: 14px 18px;
  text-align: center;
}
.stat-card .stat-value { font-size: 30px; font-weight: bold; color: var(--yellow); }
.stat-card .stat-label { font-size: 14px; color: var(--teal); }

.chart-canvas {
  border-radius: 16px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.35);
  max-width: 88vw;
  height: auto; /* keep aspect when the canvas shrinks to fit */
}

.achievement-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 6px;
}
.achievement {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 15px;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
}
.achievement.unlocked { background: rgba(79, 220, 79, 0.18); border: 1px solid var(--green); }
.achievement.locked { opacity: 0.55; }
.achievement .ach-icon { font-size: 22px; }

/* --- Results ------------------------------------------------------------------ */

.results-headline {
  font-size: clamp(34px, 6vw, 64px);
  font-weight: bold;
  color: var(--yellow);
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.5), 0 0 26px rgba(255, 230, 61, 0.55);
  text-align: center;
}

.results-table {
  border-collapse: collapse;
  font-size: clamp(15px, 2vw, 20px);
  min-width: 320px;
  display: block; /* lets narrow phones scroll the table horizontally */
  overflow-x: auto;
  max-width: 92vw;
}
.results-table td, .results-table th {
  padding: 6px 16px;
  text-align: left;
}
.results-table tr.player-row td {
  background: rgba(255, 230, 61, 0.22);
  border-top: 2px solid var(--yellow);
  border-bottom: 2px solid var(--yellow);
  font-weight: bold;
}
.paint-dot {
  display: inline-block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  margin-right: 8px;
  vertical-align: middle;
}

.coach-tip {
  font-size: clamp(15px, 2vw, 20px);
  color: var(--teal);
  background: rgba(0, 229, 192, 0.12);
  border: 3px dashed var(--teal);
  border-radius: 18px;
  padding: 12px 22px;
  max-width: 640px;
  text-align: center;
}

.coins-earned {
  font-size: clamp(20px, 3vw, 30px);
  font-weight: bold;
  color: var(--yellow);
}

/* --- Touch controls ---------------------------------------------------------- */

#game { touch-action: none; }
button { touch-action: manipulation; }

#touch-controls {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  pointer-events: none;
}
#touch-controls.active { display: block; }

.touch-cluster {
  position: absolute;
  display: flex;
  gap: 14px;
  align-items: flex-end;
}
/* Lifted above the speedometer/minimap and any home-indicator bar. */
.touch-steer {
  left: calc(14px + env(safe-area-inset-left));
  bottom: calc(max(96px, 16vh) + env(safe-area-inset-bottom));
}
.touch-pedals {
  right: calc(108px + env(safe-area-inset-right));
  bottom: calc(max(96px, 16vh) + env(safe-area-inset-bottom));
}
.touch-gas {
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(max(96px, 16vh) + env(safe-area-inset-bottom));
  flex-direction: column;
  align-items: center;
}

.touch-btn {
  pointer-events: auto;
  touch-action: none;
  font-family: var(--font-fun);
  font-weight: bold;
  color: #fff;
  border: 3px solid rgba(255, 255, 255, 0.65);
  background: rgba(61, 43, 99, 0.55);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
}
.touch-btn.pressed {
  background: rgba(255, 111, 216, 0.75);
  border-color: var(--yellow);
  transform: scale(0.93);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.touch-wide {
  min-width: 88px;
  min-height: 88px;
  border-radius: 24px;
  font-size: 38px;
}
.touch-round {
  min-width: 76px;
  min-height: 76px;
  border-radius: 50%;
  font-size: 32px;
}
.touch-tall {
  min-width: 80px;
  min-height: 92px;
  border-radius: 22px;
  font-size: 36px;
}
.touch-tall#touch-gas { background: rgba(44, 179, 44, 0.55); }
.touch-tall#touch-brake { background: rgba(255, 79, 79, 0.5); }

#touch-pause {
  position: absolute;
  top: calc(82px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  min-width: 56px;
  min-height: 56px;
  font-size: 24px;
}

/* One-shot "rotate your phone" nudge (added/removed by main.js). */
.rotate-hint {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 45;
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  background: rgba(61, 43, 99, 0.92);
  border: 3px solid var(--yellow);
  border-radius: 999px;
  padding: 10px 22px;
  pointer-events: none;
  white-space: nowrap;
  animation: hint-in 0.3s ease, hint-out 0.5s ease 2.8s forwards;
}
@keyframes hint-in {
  from { transform: translateX(-50%) translateY(-30px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}
@keyframes hint-out {
  to { transform: translateX(-50%) translateY(-30px); opacity: 0; }
}

@media (max-width: 720px) {
  .touch-wide { min-width: 74px; min-height: 74px; font-size: 32px; }
  .touch-round { min-width: 64px; min-height: 64px; font-size: 27px; }
  .touch-tall { min-width: 68px; min-height: 78px; font-size: 30px; }
  .touch-pedals { right: calc(94px + env(safe-area-inset-right)); }
}

/* --- Mute button / footer / toasts --------------------------------------------- */

#mute-btn {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  z-index: 50;
  font-size: 26px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.7);
  background: rgba(27, 16, 53, 0.85);
  cursor: pointer;
  box-shadow: 0 0 14px rgba(255, 111, 216, 0.4);
  transition: transform 0.1s ease;
}
#mute-btn:hover { transform: scale(1.12); }

#footer {
  position: fixed;
  bottom: calc(8px + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  text-align: center;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.45);
  pointer-events: none;
  z-index: 5;
}

#toast-holder {
  position: fixed;
  top: calc(84px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 60;
  pointer-events: none;
  max-width: 80vw;
}

.toast {
  font-size: 18px;
  font-weight: bold;
  background: linear-gradient(180deg, rgba(61, 43, 99, 0.97), rgba(27, 16, 53, 0.97));
  border: 3px solid var(--yellow);
  border-radius: 18px;
  padding: 10px 18px;
  color: #fff;
  box-shadow: 0 0 18px rgba(255, 230, 61, 0.45);
  animation: toast-in 0.25s ease, toast-out 0.4s ease 3.6s forwards;
}

@keyframes toast-in {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
  to { transform: translateX(120%); opacity: 0; }
}

/* --- Responsive ---------------------------------------------------------------- */

@media (max-width: 720px) {
  .big-btn { min-width: 240px; padding: 10px 24px; }
  .part-card { width: 140px; min-height: 140px; }
  .screen {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    gap: 12px;
  }
  .garage-layout { gap: 12px; }
  .panel { padding: 14px 16px; }
}

@media (max-width: 520px) {
  /* Two part cards per row on a narrow phone. */
  .part-card { width: calc(46vw - 18px); min-height: 0; padding: 8px; }
  .part-name { font-size: 14px; }
  .part-blurb { font-size: 11px; }
  .menu-buttons { width: 100%; align-items: center; }
  .setting-row { font-size: 18px; gap: 12px; }
  .stats-grid { gap: 10px; }
  .stat-card { min-width: 120px; padding: 10px 12px; }
  .stat-card .stat-value { font-size: 22px; }
  input[type="range"] { width: 150px; }
}

/* Landscape phones: very short viewport — keep things compact. */
@media (max-height: 480px) {
  .game-title { font-size: clamp(30px, 6vw, 54px); }
  .screen {
    gap: 10px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .big-btn { padding: 8px 26px; min-height: 44px; font-size: 18px; }
  .controls-card { padding: 12px 18px; gap: 8px; }
  .preview-canvas { max-width: min(200px, 40vw); }
}
