/* ============================================================
   AI Racer — Stylesheet
   Bright, saturated, playful. Rounded fonts, gradients, glow.
   ============================================================ */

* { box-sizing: border-box; }

:root {
  --blue:        #2dd4ff;
  --green:       #2dff95;
  --pink:        #ff3ea5;
  --yellow:      #ffd23d;
  --orange:      #ff8a2a;
  --purple:      #a855ff;
  --red:         #ff3b3b;
  --cyan:        #5cf6ff;
  --bg-dark:     #1a0b3a;
  --ink:         #1f1147;
  --paper:       #fff8f0;

  --font-fun:    'Fredoka', 'Nunito', system-ui, sans-serif;
  --font-num:    'Nunito', 'Fredoka', system-ui, sans-serif;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-fun);
  color: var(--ink);
  background: radial-gradient(circle at 30% 20%, #ff4ea2 0%, #6a2bff 35%, #1a0b3a 80%);
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.screen {
  width: 100%;
  max-width: 1100px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hidden { display: none !important; }

/* ============================================================
   Background ORBS (animated blurs behind everything)
   ============================================================ */
.bg-orbs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.55;
  animation: float 14s ease-in-out infinite;
}
.orb1 { width: 320px; height: 320px; background: var(--pink); top: -40px; left: -60px; }
.orb2 { width: 380px; height: 380px; background: var(--blue); top: 30%; right: -100px; animation-delay: -3s; }
.orb3 { width: 280px; height: 280px; background: var(--yellow); bottom: -80px; left: 25%; animation-delay: -6s; }
.orb4 { width: 240px; height: 240px; background: var(--green); top: 50%; left: 40%; animation-delay: -9s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%      { transform: translate(40px, -30px) scale(1.1); }
  66%      { transform: translate(-30px, 40px) scale(0.95); }
}

/* ============================================================
   MENU — title & cards
   ============================================================ */
.title {
  font-family: var(--font-fun);
  font-weight: 700;
  font-size: clamp(48px, 9vw, 110px);
  margin: 10px 0 0;
  letter-spacing: 4px;
  line-height: 1;
  text-align: center;
  color: white;
  text-shadow:
    0 0 18px rgba(255, 62, 165, 0.8),
    0 0 36px rgba(45, 212, 255, 0.6),
    0 6px 0 rgba(0, 0, 0, 0.25);
  animation: titlePulse 2.4s ease-in-out infinite;
}
.title-ai     { color: var(--yellow); }
.title-racer  { color: white; }
.rocket {
  display: inline-block;
  animation: rocketJiggle 1.6s ease-in-out infinite;
}
@keyframes titlePulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 12px rgba(255, 62, 165, 0.4)); }
  50%      { transform: scale(1.03); filter: drop-shadow(0 0 32px rgba(45, 212, 255, 0.7)); }
}
@keyframes rocketJiggle {
  0%, 100% { transform: rotate(-8deg) translateY(0); }
  50%      { transform: rotate(10deg) translateY(-6px); }
}
.subtitle {
  font-size: clamp(16px, 2.2vw, 22px);
  color: #fff;
  opacity: 0.9;
  margin: 8px 0 36px;
  text-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

.env-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 22px;
  width: 100%;
  max-width: 900px;
  margin-bottom: 36px;
}

.env-card {
  border: none;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 22px;
  padding: 18px 18px 14px;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25), 0 0 0 4px rgba(255,255,255,0.15);
  transform: translateY(0);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  font-family: var(--font-fun);
  text-align: center;
}
.env-card:hover {
  transform: translateY(-6px) rotate(-1deg);
  box-shadow: 0 22px 40px rgba(0, 0, 0, 0.35), 0 0 0 4px rgba(255,255,255,0.3);
}
.env-card:active { transform: translateY(-2px) scale(0.98); }

.env-thumb {
  height: 130px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 64px;
  margin-bottom: 12px;
  overflow: hidden;
  position: relative;
}
.thumb-circuit {
  background:
    repeating-linear-gradient(90deg, #fff 0 18px, transparent 18px 36px) center 70%/100% 8px no-repeat,
    linear-gradient(180deg, #87e2ff 0%, #b8ffb0 60%, #4fc46e 100%);
}
.thumb-desert {
  background:
    radial-gradient(circle at 70% 25%, #ffd86b 0 60px, transparent 61px),
    linear-gradient(180deg, #ff8c3a 0%, #ffb877 55%, #e8b061 100%);
}
.thumb-ice {
  background:
    linear-gradient(180deg, #6a4dff 0%, #2dd4ff 50%, #e6f5ff 100%);
}
.thumb-emoji {
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.3));
}

.env-name {
  font-weight: 700;
  font-size: 20px;
  margin-bottom: 6px;
  color: var(--ink);
}
.env-tag {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: white;
  letter-spacing: 0.5px;
}
.tag-easy   { background: var(--green); color: #003a1a; }
.tag-medium { background: var(--orange); }
.tag-hard   { background: var(--purple); }

.menu-actions {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.hi-score {
  color: white;
  font-size: 18px;
  font-weight: 700;
  background: rgba(0,0,0,0.25);
  padding: 10px 18px;
  border-radius: 999px;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  font-family: var(--font-fun);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  box-shadow: 0 6px 0 rgba(0,0,0,0.18), 0 10px 18px rgba(0,0,0,0.25);
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,0.18); }

.btn-primary {
  background: linear-gradient(180deg, var(--pink), #c4248a);
  color: white;
}
.btn-secondary {
  background: linear-gradient(180deg, var(--blue), #1aa0c8);
  color: white;
}

/* ============================================================
   Overlays / cards
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 5, 50, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  animation: fadeIn 0.25s ease both;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  background: var(--paper);
  border-radius: 28px;
  padding: 32px 36px;
  max-width: 560px;
  width: 100%;
  box-shadow: 0 30px 80px rgba(0,0,0,0.45), 0 0 0 6px rgba(255,255,255,0.2);
  text-align: center;
  animation: popIn 0.4s cubic-bezier(.34,1.56,.64,1) both;
}
.overlay-card.small { max-width: 380px; }

@keyframes popIn {
  0%  { transform: scale(0.6); opacity: 0; }
  100%{ transform: scale(1);   opacity: 1; }
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-size: 36px;
  color: var(--ink);
}
.overlay-card .muted { color: #6a5e8a; margin-top: -4px; }

.how-list {
  text-align: left;
  font-size: 15px;
  line-height: 1.7;
  padding-left: 22px;
  color: #2b1d4d;
}
.how-list li { margin: 4px 0; }
.howto-tiers {
  background: #ffeefb;
  border-radius: 14px;
  padding: 12px 16px;
  margin: 12px 0 20px;
  font-size: 14px;
}
.tier-line {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
}
.tier-line .stars { min-width: 70px; }

.result-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 2px dashed #e6dcfa;
  font-size: 17px;
}
.result-row:last-child { border-bottom: none; }
.result-row b { color: var(--pink); font-size: 20px; }

.learn-box {
  background: linear-gradient(180deg, #fff4e0, #ffe7ee);
  border-radius: 18px;
  padding: 14px 18px;
  margin-top: 18px;
  text-align: left;
}
.learn-box h3 { margin: 0 0 6px; color: var(--ink); font-size: 18px; }
.learn-box ul {
  margin: 0;
  padding-left: 22px;
  font-size: 14px;
  color: #3a2a6a;
  max-height: 160px;
  overflow-y: auto;
}
.learn-box li { margin: 4px 0; }
.learn-box .empty { color: #8a7eb0; font-style: italic; list-style: none; padding-left: 0; }

.overlay-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

.celebrate-burst {
  font-size: 64px;
  animation: burst 0.6s cubic-bezier(.34,1.56,.64,1) both;
}
.celebrate-burst.sad { animation: shake 0.6s ease both; }
@keyframes burst {
  0%   { transform: scale(0) rotate(-20deg); }
  60%  { transform: scale(1.2) rotate(10deg); }
  100% { transform: scale(1)   rotate(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-10px) rotate(-6deg); }
  40%      { transform: translateX(10px)  rotate(6deg); }
  60%      { transform: translateX(-6px)  rotate(-3deg); }
  80%      { transform: translateX(6px)   rotate(3deg); }
}

/* ============================================================
   GAME SCREEN
   ============================================================ */
.stage-wrap {
  position: relative;
  width: 100%;
  max-width: 1000px;
  aspect-ratio: 4 / 3;
  border-radius: 24px;
  overflow: hidden;
  box-shadow: 0 25px 60px rgba(0,0,0,0.5), 0 0 0 6px rgba(255,255,255,0.15);
  background: #000;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-family: var(--font-fun);
}

.hud-row {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
}
.top-row    { top: 0; }
.bottom-row { bottom: 0; flex-direction: row; gap: 10px; }

.hud-left, .hud-right, .hud-center {
  display: flex;
  gap: 8px;
  align-items: center;
}
.hud-center {
  flex-direction: column;
  gap: 6px;
}

.hud-pill {
  background: rgba(20, 8, 50, 0.65);
  color: white;
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 800;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35), inset 0 0 0 2px rgba(255,255,255,0.12);
  backdrop-filter: blur(6px);
}
.hud-label {
  font-size: 11px;
  letter-spacing: 1px;
  opacity: 0.75;
}
#combo {
  background: linear-gradient(120deg, #ff3ea5, #ff8a2a);
  animation: comboPulse 0.9s ease-in-out infinite;
}
@keyframes comboPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}
#score-val { font-size: 18px; color: var(--yellow); }
#lives-icons { font-size: 16px; letter-spacing: 1px; }

.env-pill {
  background: rgba(255,255,255,0.85);
  color: var(--ink);
  letter-spacing: 1.5px;
}

#progress-track {
  position: relative;
  width: 220px;
  height: 10px;
  background: rgba(255,255,255,0.18);
  border-radius: 999px;
  overflow: visible;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.18);
}
#progress-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--orange));
  border-radius: 999px;
  transition: width 0.15s linear;
}
#progress-marker {
  position: absolute;
  top: -10px;
  left: 0%;
  transform: translateX(-50%);
  font-size: 18px;
  transition: left 0.15s linear;
}
#progress-flag {
  position: absolute;
  right: -16px;
  top: -10px;
  font-size: 18px;
}

.meter-pill {
  min-width: 160px;
}
.meter-bar {
  width: 100px;
  height: 8px;
  background: rgba(255,255,255,0.18);
  border-radius: 999px;
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--yellow), var(--orange));
  transition: width 0.15s ease;
}
#boost-fill   { background: linear-gradient(90deg, var(--green), var(--cyan)); }
#special-fill { background: linear-gradient(90deg, var(--yellow), var(--red)); }

/* Countdown / banners */
#countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 180px;
  font-family: var(--font-fun);
  font-weight: 700;
  color: white;
  text-shadow:
    0 0 30px rgba(255, 62, 165, 0.9),
    0 0 60px rgba(45, 212, 255, 0.8),
    0 10px 0 rgba(0, 0, 0, 0.25);
  pointer-events: none;
}
#countdown.show {
  animation: cdPop 1s ease both;
}
@keyframes cdPop {
  0%   { transform: scale(0.3); opacity: 0; }
  20%  { transform: scale(1.2); opacity: 1; }
  80%  { transform: scale(1);   opacity: 1; }
  100% { transform: scale(2);   opacity: 0; }
}

#event-banner {
  position: absolute;
  top: 38%;
  left: 50%;
  transform: translate(-50%, 0);
  font-weight: 800;
  font-size: 42px;
  color: white;
  text-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 0 24px rgba(255,255,255,0.6);
  pointer-events: none;
  letter-spacing: 2px;
}
#event-banner.show {
  animation: bannerIn 1.5s ease both;
}
@keyframes bannerIn {
  0%   { transform: translate(-50%, 30px) scale(0.5); opacity: 0; }
  20%  { transform: translate(-50%, 0)    scale(1.2); opacity: 1; }
  80%  { transform: translate(-50%, 0)    scale(1);   opacity: 1; }
  100% { transform: translate(-50%, -40px)scale(0.9); opacity: 0; }
}

#pause-hint {
  position: absolute;
  bottom: 6px;
  right: 12px;
  color: rgba(255,255,255,0.55);
  font-size: 11px;
  letter-spacing: 1px;
  pointer-events: none;
}

/* ============================================================
   QUESTION CARD
   ============================================================ */
#question-card {
  position: absolute;
  left: 50%;
  top: 0;
  transform: translate(-50%, -110%);
  width: min(94%, 700px);
  background: var(--paper);
  border-radius: 22px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.55), 0 0 0 6px rgba(255,255,255,0.25);
  padding: 18px 22px 16px;
  pointer-events: auto;
  z-index: 30;
  transition: transform 0.45s cubic-bezier(.34,1.56,.64,1);
}
#question-card.show {
  transform: translate(-50%, 16px);
}

.qc-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}
.qc-bot {
  font-size: 32px;
  animation: rocketJiggle 1.4s ease-in-out infinite;
}
.qc-title {
  font-family: var(--font-fun);
  font-weight: 700;
  font-size: 24px;
  letter-spacing: 1.5px;
  background: linear-gradient(90deg, var(--pink), var(--purple), var(--blue));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.qc-stars {
  font-size: 18px;
  letter-spacing: 1px;
}
.qc-question {
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  margin: 6px 0 14px;
  color: var(--ink);
  min-height: 44px;
  line-height: 1.3;
}
.qc-answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.qc-ans {
  border: none;
  background: white;
  border-radius: 14px;
  padding: 12px 14px;
  font-family: var(--font-fun);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 5px 0 rgba(0,0,0,0.18), 0 10px 18px rgba(0,0,0,0.15);
  color: var(--ink);
  transition: transform 0.1s ease, filter 0.1s ease;
}
.qc-ans .ans-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: white;
  font-weight: 800;
  flex-shrink: 0;
}
.ans-a .ans-key { background: var(--blue); }
.ans-b .ans-key { background: var(--green); color: #013014; }
.ans-c .ans-key { background: var(--orange); }
.ans-d .ans-key { background: var(--purple); }
.qc-ans:hover    { transform: translateY(-2px); filter: brightness(1.05); }
.qc-ans:active   { transform: translateY(2px); }
.qc-ans:disabled { cursor: default; opacity: 0.65; }
.qc-ans.correct  { background: linear-gradient(180deg, #b8ffd6, #4cffa0); }
.qc-ans.wrong    { background: linear-gradient(180deg, #ffd1d1, #ff7a7a); }
.qc-ans.reveal   { outline: 3px dashed var(--green); outline-offset: -6px; }

.qc-timer-bar {
  height: 10px;
  background: #eee5fa;
  border-radius: 999px;
  margin-top: 14px;
  overflow: hidden;
}
.qc-timer-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--orange), var(--red));
  transition: width 0.1s linear;
}
.qc-feedback {
  text-align: center;
  margin-top: 10px;
  font-weight: 700;
  font-size: 16px;
  color: var(--ink);
}
.qc-feedback.good { color: #1e9a55; }
.qc-feedback.bad  { color: #c4264f; }

/* Screen shake on canvas */
.shake { animation: canvasShake 0.4s ease both; }
@keyframes canvasShake {
  0%, 100% { transform: translate(0, 0); }
  20%      { transform: translate(-8px, 4px); }
  40%      { transform: translate(8px, -4px); }
  60%      { transform: translate(-4px, 8px); }
  80%      { transform: translate(4px, -8px); }
}

/* Responsive */
@media (max-width: 600px) {
  .qc-answers { grid-template-columns: 1fr; }
  .hud-row { padding: 8px 10px; gap: 6px; }
  .hud-pill { padding: 4px 10px; font-size: 12px; }
  #progress-track { width: 140px; }
}
