/* === DASH FRENZY — Main Styles === */
@import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Nunito:wght@400;600;800;900&display=swap');

:root {
  --c-bg:       #1a0a2e;
  --c-primary:  #ff4d8d;
  --c-secondary:#00e5ff;
  --c-accent:   #ffe234;
  --c-green:    #4dff91;
  --c-purple:   #b44dff;
  --c-orange:   #ff8c00;
  --c-white:    #ffffff;
  --c-dark:     #0d0020;
  --font-head:  'Fredoka One', cursive;
  --font-body:  'Nunito', sans-serif;
  --radius:     18px;
  --shadow:     0 8px 32px rgba(0,0,0,0.5);
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--c-bg);
  font-family: var(--font-body);
  color: var(--c-white);
  user-select: none;
  -webkit-user-select: none;
}

/* CANVAS */
#gameCanvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: block;
  image-rendering: pixelated;
}

/* UI LAYER */
#ui-layer {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 10;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: all;
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}
.screen.active {
  opacity: 1;
  transform: scale(1);
  pointer-events: all;
}
.screen.hidden {
  display: none;
}

/* ===== MENU ===== */
.menu-bg-shapes {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.shape {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.22;
  animation: floatShape 8s ease-in-out infinite;
}
.s1 { width: 400px; height: 400px; background: var(--c-primary); top: -100px; left: -100px; animation-delay: 0s; }
.s2 { width: 300px; height: 300px; background: var(--c-secondary); bottom: -80px; right: -80px; animation-delay: 2s; }
.s3 { width: 250px; height: 250px; background: var(--c-accent); top: 40%; left: 60%; animation-delay: 4s; }
.s4 { width: 200px; height: 200px; background: var(--c-purple); bottom: 20%; left: 10%; animation-delay: 6s; }

@keyframes floatShape {
  0%, 100% { transform: translate(0,0) scale(1); }
  50% { transform: translate(20px, -30px) scale(1.08); }
}

.menu-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  text-align: center;
  padding: 20px;
}

.logo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.logo-eyebrow {
  font-size: 14px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
  font-weight: 600;
}
.logo {
  font-family: var(--font-head);
  font-size: clamp(56px, 11vw, 110px);
  line-height: 0.9;
  color: var(--c-white);
  text-shadow:
    0 0 40px rgba(255,77,141,0.7),
    0 4px 0 rgba(0,0,0,0.4),
    0 6px 0 rgba(0,0,0,0.2);
  animation: logoPulse 2.5s ease-in-out infinite;
}
.logo span {
  color: var(--c-accent);
  text-shadow:
    0 0 40px rgba(255,226,52,0.8),
    0 4px 0 rgba(180,120,0,0.6);
}
@keyframes logoPulse {
  0%, 100% { filter: drop-shadow(0 0 20px rgba(255,77,141,0.5)); }
  50% { filter: drop-shadow(0 0 40px rgba(255,77,141,0.9)); }
}
.logo-tagline {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}

.powerup-legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}
.pu-badge {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  border: 2px solid rgba(255,255,255,0.2);
}
.pu-badge.speed  { background: rgba(255,220,0,0.15); border-color: #ffe234; color: #ffe234; }
.pu-badge.freeze { background: rgba(0,229,255,0.15); border-color: #00e5ff; color: #00e5ff; }
.pu-badge.star   { background: rgba(255,180,0,0.15);  border-color: #ffb800; color: #ffb800; }
.pu-badge.saw    { background: rgba(255,77,77,0.15);   border-color: #ff4d4d; color: #ff4d4d; }

/* ===== BUTTONS ===== */
.btn {
  display: block;
  width: 100%;
  padding: 16px 32px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-head);
  font-size: 20px;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.15s ease;
  outline: none;
  position: relative;
  overflow: hidden;
}
.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background 0.15s;
}
.btn:hover::after { background: rgba(255,255,255,0.1); }
.btn:active { transform: scale(0.97) translateY(2px); }

.btn-primary {
  background: linear-gradient(135deg, #ff4d8d, #ff8c00);
  color: white;
  box-shadow: 0 6px 0 rgba(180,30,0,0.4), var(--shadow);
}
.btn-primary:hover { box-shadow: 0 8px 0 rgba(180,30,0,0.4), 0 0 30px rgba(255,77,141,0.5); }
.btn-primary:active { box-shadow: 0 2px 0 rgba(180,30,0,0.4); }

.btn-secondary {
  background: rgba(255,255,255,0.1);
  color: white;
  border: 2px solid rgba(255,255,255,0.25);
  box-shadow: 0 4px 0 rgba(0,0,0,0.3);
}
.btn-secondary:hover { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.45); }

/* ===== PANEL ===== */
.panel {
  background: rgba(10,0,30,0.92);
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 24px;
  padding: 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: center;
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  max-width: 400px;
  width: 90%;
}
.panel h2 {
  font-family: var(--font-head);
  font-size: 32px;
  color: var(--c-accent);
  text-shadow: 0 0 20px rgba(255,226,52,0.5);
}

/* ===== CONTROLS ===== */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}
.ctrl-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px;
  background: rgba(255,255,255,0.06);
  border-radius: 12px;
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  font-weight: 600;
}
.key {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  padding: 4px 10px;
  font-family: var(--font-head);
  font-size: 14px;
  color: var(--c-accent);
}
.touch-hint {
  font-size: 12px;
  color: rgba(255,255,255,0.35);
  font-weight: 600;
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
#hud.hidden { display: none; }
#hud.active { pointer-events: none; }

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 18px;
  gap: 12px;
}

.race-positions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(6px);
  border-radius: 14px;
  padding: 10px 14px;
  border: 1px solid rgba(255,255,255,0.1);
  min-width: 120px;
}
.pos-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}
.pos-num {
  font-family: var(--font-head);
  font-size: 16px;
  width: 22px;
  text-align: center;
}
.pos-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  flex-shrink: 0;
}
.pos-you {
  font-size: 10px;
  color: var(--c-accent);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.hud-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  max-width: 360px;
}
.race-progress-bar {
  width: 100%;
  height: 10px;
  background: rgba(255,255,255,0.12);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.15);
  position: relative;
}
.progress-track {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
}
.lap-label {
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  font-weight: 800;
}

.hud-right {
  min-width: 120px;
  display: flex;
  justify-content: flex-end;
}
.powerup-slot {
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(6px);
  border-radius: 14px;
  padding: 10px 14px;
  border: 2px solid rgba(255,255,255,0.12);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-align: center;
  transition: all 0.2s;
}
.powerup-slot.has-pu {
  border-color: var(--c-accent);
  box-shadow: 0 0 14px rgba(255,226,52,0.3);
}
.pu-empty { color: rgba(255,255,255,0.3); }
.pu-icon { font-size: 22px; }
.pu-name { font-size: 10px; color: var(--c-accent); }

/* TOUCH CONTROLS */
.touch-controls {
  display: none;
  position: absolute;
  bottom: 20px;
  left: 0; right: 0;
  justify-content: center;
  align-items: center;
  gap: 12px;
  pointer-events: all;
  padding: 0 20px;
}
@media (hover: none) and (pointer: coarse) {
  .touch-controls { display: flex; }
}
.touch-btn {
  width: 68px; height: 68px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  color: white;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-head);
  transition: all 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.touch-btn:active { background: rgba(255,255,255,0.2); transform: scale(0.93); }
.tc-action { width: 80px; height: 80px; background: rgba(255,77,141,0.4); border-color: var(--c-primary); }
.tc-use { background: rgba(255,226,52,0.3); border-color: var(--c-accent); font-size: 14px; letter-spacing: 1px; width: 64px; height: 64px; }

/* COUNTDOWN */
#countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#countdown.hidden { display: none; }
.count-num {
  font-family: var(--font-head);
  font-size: 200px;
  color: var(--c-white);
  text-shadow: 0 0 60px rgba(255,77,141,0.9), 0 8px 0 rgba(0,0,0,0.4);
  animation: countPop 0.5s ease-out;
}
@keyframes countPop {
  0% { transform: scale(2); opacity: 0; }
  60% { transform: scale(0.9); }
  100% { transform: scale(1); opacity: 1; }
}

/* FINISH SCREEN */
.finish-panel {
  background: rgba(10,0,30,0.95);
  border: 2px solid rgba(255,255,255,0.12);
  border-radius: 28px;
  padding: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  backdrop-filter: blur(20px);
  box-shadow: 0 0 80px rgba(255,77,141,0.3), var(--shadow);
  max-width: 460px;
  width: 90%;
}
.finish-title {
  font-family: var(--font-head);
  font-size: clamp(36px, 8vw, 60px);
  text-align: center;
  text-shadow: 0 0 30px currentColor;
}
.finish-title.win { color: var(--c-accent); }
.finish-title.lose { color: var(--c-secondary); }
.finish-subtitle {
  font-size: 18px;
  font-weight: 800;
  color: rgba(255,255,255,0.6);
  letter-spacing: 2px;
  text-transform: uppercase;
}
.results-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: rgba(255,255,255,0.06);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
}
.result-pos {
  font-family: var(--font-head);
  font-size: 22px;
  width: 32px;
  text-align: center;
}
.result-pos.p1 { color: var(--c-accent); }
.result-pos.p2 { color: #c0c0c0; }
.result-pos.p3 { color: #cd7f32; }
.result-name {
  font-weight: 800;
  font-size: 15px;
  flex: 1;
}
.result-time {
  font-family: var(--font-head);
  font-size: 14px;
  color: rgba(255,255,255,0.45);
}
.finish-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/* Progress dots on bar */
.prog-runner {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid white;
  transition: left 0.3s ease;
  box-shadow: 0 0 8px currentColor;
}

/* ===== MISC UTILITY ===== */
.hidden { display: none !important; }
