/* ==========================================================================
   Traffic Dodge — Stylesheet
   Responsive Low-Poly Arcade Racer for Mobile & Tablet
   ========================================================================== */

:root {
  --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --color-primary: #ef4444;
  --color-primary-dark: #dc2626;
  --color-accent: #3b82f6;
  --color-gold: #f59e0b;
  --color-success: #10b981;
  --color-bg-dark: #0f172a;
  --color-text-light: #ffffff;
  --color-text-muted: #94a3b8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: #6b21a8;
  font-family: var(--font-main);
  color: #1e293b;
  touch-action: none;
}

#game-app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* --- Sky & Background Decor --- */
#sky-decor {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.sky-gradient {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #6b21a8 0%, #8b5cf6 30%, #c026d3 50%, #db2777 68%, #f472b6 82%, #fef08a 100%);
}

.cloud {
  position: absolute;
  aspect-ratio: 2.4 / 1;
  background: url('assets/cloud.png') center / contain no-repeat;
  filter: drop-shadow(0 12px 14px rgba(107, 33, 168, 0.25));
  animation: cloudFloat 18s ease-in-out infinite alternate;
  pointer-events: none;
}

.cloud-a {
  top: 7%;
  left: -8%;
  width: clamp(190px, 45vw, 290px);
  opacity: 0.95;
}

.cloud-b {
  top: 14%;
  right: -10%;
  width: clamp(210px, 48vw, 320px);
  opacity: 0.92;
  animation-delay: -5s;
}

.cloud-c {
  top: 5%;
  left: 36%;
  width: clamp(140px, 32vw, 210px);
  opacity: 0.85;
  animation-delay: -11s;
}

.cloud-d {
  top: 18%;
  left: 10%;
  width: clamp(170px, 38vw, 250px);
  opacity: 0.88;
  animation-delay: -15s;
}

@keyframes cloudFloat {
  from {
    transform: translateX(-14px);
  }
  to {
    transform: translateX(18px);
  }
}

.mountains-layer {
  position: absolute;
  bottom: 46%;
  left: 0;
  right: 0;
  transform: none;
  width: 100%;
  min-width: 0;
  max-width: none;
  height: 36%;
  background: url('assets/mountains.png?v=4') center bottom / 100% 100% no-repeat;
  pointer-events: none;
  filter: drop-shadow(0 8px 24px rgba(107, 33, 168, 0.4));
}

/* --- 3D WebGL Canvas --- */
#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

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

/* --- HUD Top --- */
#hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: calc(var(--safe-top) + 12px) 16px 8px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 540px;
  margin: 0 auto;
}

.hud-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 16px;
  padding: 8px 16px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.6);
}

.hud-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pill-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: #ffffff;
  background: linear-gradient(135deg, #ef4444, #f97316);
  padding: 2px 8px;
  border-radius: 20px;
  width: fit-content;
}

.level-subtitle {
  font-size: 13px;
  font-weight: 700;
  color: #334155;
  white-space: nowrap;
}

.hud-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.speed-pill {
  font-size: 14px;
  font-weight: 900;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
  box-shadow: inset 0 1px 2px rgba(239, 68, 68, 0.1);
}

.speed-pill small {
  font-size: 10px;
  font-weight: 800;
  color: #dc2626;
  margin-left: 2px;
}

.hud-right {

  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.score-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.8px;
  color: #64748b;
}

.score-value {
  font-size: 22px;
  font-weight: 900;
  color: #0f172a;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* --- Progress Bar --- */
.progress-wrap {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 4px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #10b981);
  border-radius: 4px;
  transition: width 0.15s ease-out;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 700;
  color: #475569;
}

/* --- Near Miss Toasts --- */
#toast-container {
  position: absolute;
  top: 35%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 15;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.toast-item {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #ffffff;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.5px;
  padding: 6px 14px;
  border-radius: 20px;
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
  animation: toastPop 0.8s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
}

@keyframes toastPop {
  0% { transform: scale(0.6) translateY(20px); opacity: 0; }
  25% { transform: scale(1.1) translateY(0); opacity: 1; }
  75% { transform: scale(1) translateY(-10px); opacity: 1; }
  100% { transform: scale(0.9) translateY(-30px); opacity: 0; }
}

/* --- Bottom Controls --- */
#controls-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 16px calc(var(--safe-right) + 20px) calc(var(--safe-bottom) + 24px) calc(var(--safe-left) + 20px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  max-width: 520px;
  margin: 0 auto;
}

.steer-btn {
  pointer-events: auto;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 3px solid rgba(255, 255, 255, 0.8);
  color: #1e293b;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), inset 0 2px 4px rgba(255, 255, 255, 0.4);
  transition: transform 0.08s ease, background-color 0.08s ease, border-color 0.08s ease;
  touch-action: manipulation;
}

.steer-btn:active, .steer-btn.active {
  transform: scale(0.90);
  background: rgba(239, 68, 68, 0.85);
  color: #ffffff;
  border-color: #ffffff;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

/* --- Modals --- */
.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.25s ease-out;
}

.modal-backdrop[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  max-width: 360px;
  background: #ffffff;
  border-radius: 24px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.8);
  animation: scaleUp 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

@keyframes scaleUp {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-sparkle {
  font-size: 40px;
  margin-bottom: 8px;
}

.modal-eyebrow {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #3b82f6;
  margin-bottom: 4px;
}

.modal-eyebrow.fail-eyebrow {
  color: #ef4444;
}

.modal-title {
  font-size: 22px;
  font-weight: 900;
  color: #0f172a;
  margin-bottom: 14px;
}

.stars-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  font-size: 34px;
  margin-bottom: 16px;
  color: #e2e8f0;
}

.star-slot.active {
  color: #f59e0b;
  text-shadow: 0 2px 10px rgba(245, 158, 11, 0.4);
  animation: starPop 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.3) both;
}

.star-slot.star-1.active { animation-delay: 0.1s; }
.star-slot.star-2.active { animation-delay: 0.25s; }
.star-slot.star-3.active { animation-delay: 0.4s; }

@keyframes starPop {
  0% { transform: scale(0.3) rotate(-20deg); opacity: 0; }
  70% { transform: scale(1.25) rotate(10deg); }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.campaign-stars {
  font-size: 28px;
  font-weight: 900;
  color: #f59e0b;
  margin-bottom: 10px;
}

.campaign-copy {
  font-size: 14px;
  color: #64748b;
  line-height: 1.4;
  margin-bottom: 18px;
}

.stats-box {
  background: #f8fafc;
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
}

.stat-label {
  color: #64748b;
  font-weight: 600;
}

.stat-val {
  color: #0f172a;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  width: 100%;
  padding: 14px 20px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.4px;
  border: none;
  cursor: pointer;
  outline: none;
  transition: transform 0.1s ease, filter 0.1s ease;
  touch-action: manipulation;
}

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

.btn-primary {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
}

.btn-primary.fail-btn {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
}

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-tertiary {
  background: transparent;
  color: #64748b;
  font-size: 13px;
  padding: 8px;
}

/* --- Tablet Adjustments --- */
@media (min-width: 600px) {
  .steer-btn {
    width: 90px;
    height: 90px;
  }
  
  .hud-bar {
    padding: 10px 20px;
  }

  .score-value {
    font-size: 26px;
  }
}
