/* ============================================================
   BRIDGE BUILDERS RACE — Stylesheet
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --primary: #FF6B35;
  --primary-dark: #E85A20;
  --secondary: #4ECDC4;
  --accent: #FFD700;
  --bg-dark: #1a1a2e;
  --bg-mid: #16213e;
  --text-light: #f8f9fa;
  --text-dim: #adb5bd;
  --shadow: 0 4px 20px rgba(0,0,0,0.5);
  --radius: 12px;
  --radius-lg: 20px;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: #000;
  color: var(--text-light);
  touch-action: none;
  user-select: none;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* ============================================================
   SCREENS
   ============================================================ */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

.overlay-screen {
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  cursor: pointer;
  border: none;
  outline: none;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.05em;
  transition: transform 0.1s, filter 0.1s, box-shadow 0.1s;
  border-radius: var(--radius);
}

.btn:active {
  transform: scale(0.95);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: clamp(14px, 2vw, 18px);
  padding: 14px 36px;
  box-shadow: 0 6px 0 #a33000, var(--shadow);
  text-transform: uppercase;
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
  box-shadow: 0 8px 0 #a33000, var(--shadow);
}

.btn-secondary {
  background: linear-gradient(135deg, #2d3561, #1a2040);
  color: var(--text-light);
  font-size: clamp(13px, 1.8vw, 16px);
  padding: 12px 28px;
  border: 2px solid rgba(255,255,255,0.15);
  box-shadow: var(--shadow);
  text-transform: uppercase;
}

.btn-secondary:hover {
  background: linear-gradient(135deg, #3d4571, #2a3050);
  border-color: rgba(255,255,255,0.3);
}

.btn-back {
  background: rgba(255,255,255,0.1);
  color: var(--text-light);
  font-size: 14px;
  padding: 10px 20px;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: var(--radius);
}

.btn-back:hover {
  background: rgba(255,255,255,0.2);
}

.btn-icon {
  background: rgba(255,255,255,0.1);
  color: var(--text-light);
  font-size: 22px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: rgba(255,255,255,0.2);
}

.btn-icon-sm {
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-size: 18px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   START SCREEN
   ============================================================ */

#screen-start {
  background: linear-gradient(135deg, #0d4f3c, #1a6b52, #0d4f3c);
}

#bg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.start-overlay {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
  padding: 20px;
}

.logo-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: clamp(60px, 12vw, 100px);
  filter: drop-shadow(0 4px 20px rgba(0,0,0,0.5));
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.logo-text {
  font-size: clamp(36px, 7vw, 72px);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  color: #fff;
  text-shadow: 4px 4px 0 #a33000, 0 0 30px rgba(255,100,0,0.6);
  letter-spacing: 0.1em;
}

.logo-sub {
  color: var(--accent);
  text-shadow: 3px 3px 0 #8B6914, 0 0 20px rgba(255,215,0,0.5);
}

.logo-race {
  color: var(--secondary);
  text-shadow: 3px 3px 0 #1a8a84, 0 0 20px rgba(78,205,196,0.5);
  font-size: 1.2em;
}

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

.start-footer {
  color: rgba(255,255,255,0.6);
  font-size: 13px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* ============================================================
   LEVEL SELECT
   ============================================================ */

#screen-levels {
  background: linear-gradient(135deg, var(--bg-dark), var(--bg-mid));
  overflow-y: auto;
  justify-content: flex-start;
}

.levels-header {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  gap: 12px;
}

.levels-header h2 {
  font-size: clamp(18px, 3vw, 26px);
  letter-spacing: 0.15em;
  color: var(--accent);
  text-shadow: 0 0 20px rgba(255,215,0,0.4);
}

.coins-display {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(255,215,0,0.1);
  border: 2px solid rgba(255,215,0,0.3);
  border-radius: 20px;
  padding: 6px 14px;
}

.levels-grid {
  width: 100%;
  max-width: 900px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  padding: 0 24px 40px;
}

.level-card {
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 3px solid transparent;
}

.level-card:hover:not(.locked) {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}

.level-card.locked {
  cursor: default;
  opacity: 0.5;
  filter: saturate(0.3);
}

.level-card-bg {
  width: 100%;
  aspect-ratio: 4/3;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 50px;
}

.level-card-info {
  padding: 10px 12px;
  background: rgba(0,0,0,0.6);
}

.level-card-num {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.level-card-name {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

.level-card-stars {
  font-size: 16px;
  margin-top: 4px;
}

.level-lock-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 36px;
  z-index: 2;
}

/* ============================================================
   CHARACTER SELECT
   ============================================================ */

#screen-chars {
  background: linear-gradient(135deg, var(--bg-dark), var(--bg-mid));
}

.chars-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
  padding: 20px;
  max-width: 700px;
}

.char-card {
  width: 120px;
  background: rgba(255,255,255,0.05);
  border: 3px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-lg);
  padding: 16px 12px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
}

.char-card:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.3);
  transform: translateY(-3px);
}

.char-card.selected {
  border-color: var(--accent);
  background: rgba(255,215,0,0.1);
  box-shadow: 0 0 20px rgba(255,215,0,0.3);
}

.char-preview {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  margin: 0 auto 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  position: relative;
}

.char-name {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

/* ============================================================
   GAME SCREEN
   ============================================================ */

#screen-game {
  background: #000;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
  pointer-events: none;
  z-index: 10;
}

#hud-position {
  background: rgba(0,0,0,0.6);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 10px;
  padding: 6px 12px;
  display: flex;
  align-items: baseline;
  gap: 2px;
  pointer-events: none;
}

#pos-rank {
  font-size: 28px;
  font-weight: 900;
  color: var(--accent);
}

#pos-suffix {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

#hud-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

#hud-timer {
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.8);
  font-variant-numeric: tabular-nums;
}

#hud-level-name {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

#hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: all;
}

#plank-display {
  background: rgba(0,0,0,0.6);
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 10px;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

#plank-icon {
  font-size: 18px;
}

#plank-count {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

/* Countdown */
#countdown-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  background: rgba(0,0,0,0.4);
}

#countdown-overlay.hidden {
  display: none;
}

#countdown-text {
  font-size: clamp(80px, 20vw, 160px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 40px rgba(255,107,53,0.8), 4px 4px 0 #a33000;
  animation: countPop 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes countPop {
  0% { transform: scale(2); opacity: 0; }
  50% { transform: scale(0.9); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* Mobile Controls */
#mobile-controls {
  position: absolute;
  bottom: 20px;
  left: 20px;
  z-index: 10;
  display: none;
}

#joystick-zone {
  width: 130px;
  height: 130px;
  position: relative;
}

#joystick-base {
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 3px solid rgba(255,255,255,0.3);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#joystick-thumb {
  width: 55px;
  height: 55px;
  border-radius: 50%;
  background: rgba(255,255,255,0.4);
  border: 3px solid rgba(255,255,255,0.7);
  position: absolute;
  transform: translate(0, 0);
  transition: none;
  pointer-events: none;
}

/* Minimap */
#minimap-canvas {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 120px;
  height: 120px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,0.4);
  background: rgba(0,0,0,0.5);
  z-index: 10;
}

/* ============================================================
   PAUSE SCREEN
   ============================================================ */

.modal {
  background: linear-gradient(135deg, #1e2a4a, #0d1530);
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-lg);
  padding: 36px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  min-width: 280px;
}

.modal h2 {
  font-size: 28px;
  letter-spacing: 0.2em;
  color: var(--accent);
  margin-bottom: 10px;
}

/* ============================================================
   WIN / LOSE SCREENS
   ============================================================ */

#screen-win {
  background: linear-gradient(135deg, #0d4f3c, #1a6b52);
}

#confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.result-overlay {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px;
}

.podium-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 10px;
}

.podium-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.podium-avatar {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  border: 3px solid rgba(255,255,255,0.4);
}

.podium-name {
  font-size: 11px;
  color: rgba(255,255,255,0.8);
}

.podium-block {
  width: 70px;
  border-radius: 8px 8px 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(0,0,0,0.5);
  font-weight: 900;
  font-size: 22px;
}

.podium-1 { height: 100px; background: linear-gradient(135deg, #FFD700, #FFA500); }
.podium-2 { height: 70px; background: linear-gradient(135deg, #C0C0C0, #A0A0A0); }
.podium-3 { height: 50px; background: linear-gradient(135deg, #CD7F32, #A0522D); }

.result-stars {
  font-size: 40px;
  letter-spacing: 4px;
}

.result-coins {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  background: rgba(255,215,0,0.1);
  border: 2px solid rgba(255,215,0,0.3);
  border-radius: 20px;
  padding: 6px 20px;
}

.result-time {
  color: rgba(255,255,255,0.7);
  font-size: 14px;
}

.win-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

#screen-lose {
  background: linear-gradient(135deg, #1a1a3e, #2d1b69);
}

.lose-emoji {
  font-size: 80px;
  animation: wobble 0.5s ease;
}

@keyframes wobble {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-10deg); }
  75% { transform: rotate(10deg); }
}

.lose-title {
  font-size: clamp(28px, 6vw, 48px);
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 20px rgba(255,255,255,0.3);
}

.lose-rank {
  font-size: 18px;
  color: var(--text-dim);
}

.lose-tip {
  font-size: 14px;
  color: var(--secondary);
  max-width: 280px;
  text-align: center;
  line-height: 1.5;
  padding: 10px 16px;
  background: rgba(78,205,196,0.1);
  border: 1px solid rgba(78,205,196,0.3);
  border-radius: var(--radius);
}

/* ============================================================
   MOBILE RESPONSIVE
   ============================================================ */

@media (max-width: 600px) {
  #mobile-controls {
    display: block;
  }

  #minimap-canvas {
    width: 90px;
    height: 90px;
  }

  .levels-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (hover: none) and (pointer: coarse) {
  #mobile-controls {
    display: block;
  }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.05);
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
}

/* ============================================================
   UTILITY
   ============================================================ */

.hidden {
  display: none !important;
}

.flash {
  animation: flash 0.3s ease;
}

@keyframes flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.shake {
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}
