/* ===== FONTS (local, no CDN) ===== */
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Vazirmatn';
  src: url('fonts/Vazirmatn-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Vazirmatn', 'Arial', sans-serif;
  background: #020810;
  color: #e0f0ff;
  overflow: hidden;
  text-align: center;
  height: 100vh;
  width: 100vw;
}

/* ===== ANIMATED BACKGROUND ===== */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 120% 60% at 50% 0%, rgba(0,60,120,0.35) 0%, transparent 70%),
    radial-gradient(ellipse 80% 50% at 20% 80%, rgba(0,180,255,0.08) 0%, transparent 60%),
    radial-gradient(ellipse 80% 50% at 80% 90%, rgba(0,255,200,0.06) 0%, transparent 60%);
  z-index: -2;
  pointer-events: none;
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.6), transparent),
    radial-gradient(1px 1px at 30% 60%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.5px 1.5px at 50% 10%, rgba(200,230,255,0.7), transparent),
    radial-gradient(1px 1px at 70% 40%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 90% 80%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1.5px 1.5px at 15% 85%, rgba(200,240,255,0.5), transparent),
    radial-gradient(1px 1px at 60% 75%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 85% 15%, rgba(200,230,255,0.6), transparent);
  animation: starsTwinkle 4s ease-in-out infinite alternate;
  z-index: -1;
  pointer-events: none;
}

@keyframes starsTwinkle {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

/* ===== TYPOGRAPHY ===== */
h1 {
  font-size: 3em;
  margin-bottom: 8px;
  background: linear-gradient(135deg, #00e5ff 0%, #00b0ff 40%, #a0f0ff 70%, #00e5ff 100%);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer 3s ease-in-out infinite;
  filter: drop-shadow(0 0 20px rgba(0,200,255,0.5));
  letter-spacing: -1px;
}

h2 {
  font-size: 2.2em;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #00e5ff, #80d8ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 12px rgba(0,200,255,0.4));
}

.subtitle {
  font-size: 0.95em;
  color: rgba(160,210,255,0.6);
  margin-bottom: 28px;
  letter-spacing: 3px;
  text-transform: uppercase;
}

@keyframes shimmer {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* ===== GLASS PANELS ===== */
#start-screen, #game-over-screen, #leaderboard-screen {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  background: linear-gradient(145deg, rgba(10,30,60,0.85) 0%, rgba(5,15,35,0.92) 100%);
  backdrop-filter: blur(24px) saturate(1.5);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  padding: 48px 44px;
  border-radius: 24px;
  border: 1px solid rgba(0,200,255,0.15);
  box-shadow:
    0 0 40px rgba(0,150,255,0.12),
    0 0 80px rgba(0,100,200,0.06),
    inset 0 1px 0 rgba(255,255,255,0.06),
    inset 0 -1px 0 rgba(0,0,0,0.3);
  animation: panelIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
  min-width: 340px;
  z-index: 10;
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9) translateY(30px);
    filter: blur(8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) translateY(0);
    filter: blur(0);
  }
}

/* ===== INPUT ===== */
input {
  padding: 14px 20px;
  font-size: 1.1em;
  font-family: 'Vazirmatn', sans-serif;
  margin: 16px 0;
  border: 1px solid rgba(0,200,255,0.2);
  border-radius: 14px;
  background: rgba(0,30,60,0.6);
  color: #e0f0ff;
  width: 100%;
  max-width: 300px;
  outline: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
}

input::placeholder {
  color: rgba(140,190,225,0.5);
}

input:focus {
  border-color: rgba(0,200,255,0.5);
  box-shadow: 0 0 20px rgba(0,180,255,0.15), inset 0 0 12px rgba(0,150,255,0.05);
  background: rgba(0,35,70,0.7);
}

/* ===== BUTTONS ===== */
button {
  position: relative;
  padding: 14px 32px;
  font-size: 1.1em;
  font-family: 'Vazirmatn', sans-serif;
  font-weight: 700;
  background: linear-gradient(135deg, rgba(0,200,255,0.2) 0%, rgba(0,150,255,0.1) 100%);
  color: #a0e8ff;
  border: 1px solid rgba(0,200,255,0.3);
  border-radius: 14px;
  cursor: pointer;
  margin: 8px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  letter-spacing: 0.5px;
}

button::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 0%, rgba(0,200,255,0.08) 50%, transparent 100%);
  transform: translateX(-100%);
  transition: transform 0.5s ease;
}

button:hover {
  background: linear-gradient(135deg, rgba(0,220,255,0.3) 0%, rgba(0,180,255,0.2) 100%);
  border-color: rgba(0,220,255,0.5);
  box-shadow: 0 0 30px rgba(0,180,255,0.2), 0 8px 24px rgba(0,0,0,0.3);
  transform: translateY(-2px);
  color: #ffffff;
}

button:hover::before {
  transform: translateX(100%);
}

button:active {
  transform: translateY(0);
  box-shadow: 0 0 15px rgba(0,180,255,0.15);
}

#start-btn {
  background: linear-gradient(135deg, rgba(0,220,255,0.35) 0%, rgba(0,100,200,0.25) 100%);
  border-color: rgba(0,220,255,0.45);
  color: #fff;
  padding: 16px 48px;
  font-size: 1.25em;
  display: block;
  width: 100%;
  max-width: 300px;
  margin: 20px auto 0;
}

/* ===== GAME SCREEN ===== */
#game-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #020810;
}

#game-canvas {
  border-radius: 8px;
  border: 1px solid rgba(0,180,255,0.12);
  box-shadow:
    0 0 60px rgba(0,120,200,0.1),
    0 0 120px rgba(0,80,160,0.06);
}

/* ===== HUD ===== */
#hud {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 24px;
  align-items: center;
  background: linear-gradient(135deg, rgba(5,20,40,0.82) 0%, rgba(8,25,50,0.78) 100%);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 10px 28px;
  border-radius: 16px;
  border: 1px solid rgba(0,180,255,0.12);
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  font-size: 1em;
  z-index: 5;
  min-width: 260px;
  justify-content: center;
}

#score {
  color: #a0e8ff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

#fuel-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

#fuel-label {
  color: #a0e8ff;
  font-weight: 700;
  font-size: 0.9em;
}

#fuel-bar-outer {
  width: 100px;
  height: 10px;
  background: rgba(0,40,80,0.6);
  border-radius: 5px;
  border: 1px solid rgba(0,180,255,0.15);
  overflow: hidden;
}

#fuel-bar-inner {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #00e676, #00c853);
  border-radius: 4px;
  transition: width 0.3s ease, background 0.3s ease;
  box-shadow: 0 0 8px rgba(0,230,118,0.4);
}

#fuel-bar-inner.warning {
  background: linear-gradient(90deg, #ff9100, #ff6d00);
  box-shadow: 0 0 8px rgba(255,145,0,0.5);
}

#fuel-bar-inner.critical {
  background: linear-gradient(90deg, #ff1744, #d50000);
  box-shadow: 0 0 8px rgba(255,23,68,0.6);
  animation: fuelPulse 0.5s ease-in-out infinite alternate;
}

@keyframes fuelPulse {
  from { opacity: 1; }
  to { opacity: 0.6; }
}

/* ===== LEADERBOARD ===== */
#leaderboard-list {
  text-align: right;
  margin: 20px auto;
  max-width: 90vw;
  width: 720px;
  padding: 0;
  list-style: none;
  counter-reset: rank;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

#leaderboard-list li {
  counter-increment: rank;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, rgba(0,40,80,0.4) 0%, rgba(0,20,50,0.3) 100%);
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid rgba(0,180,255,0.08);
  transition: all 0.25s ease;
  animation: listItemIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: calc(var(--i, 0) * 0.03s);
  font-size: 0.9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#leaderboard-list li:hover {
  background: linear-gradient(135deg, rgba(0,60,110,0.5) 0%, rgba(0,30,70,0.4) 100%);
  border-color: rgba(0,180,255,0.2);
  transform: translateY(-2px);
}

#leaderboard-list li::before {
  content: counter(rank);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 0.8em;
  font-weight: 700;
  background: rgba(0,100,180,0.2);
  color: #60c0e8;
  border: 1px solid rgba(0,180,255,0.15);
  flex-shrink: 0;
}

#leaderboard-list li:nth-child(1)::before {
  background: linear-gradient(135deg, rgba(255,215,0,0.3), rgba(255,180,0,0.15));
  color: #ffd700;
  border-color: rgba(255,215,0,0.3);
  box-shadow: 0 0 12px rgba(255,215,0,0.15);
}

#leaderboard-list li:nth-child(2)::before {
  background: linear-gradient(135deg, rgba(192,192,192,0.25), rgba(160,160,160,0.12));
  color: #c0c0d0;
  border-color: rgba(192,192,192,0.25);
}

#leaderboard-list li:nth-child(3)::before {
  background: linear-gradient(135deg, rgba(205,127,50,0.3), rgba(180,100,30,0.15));
  color: #cd7f32;
  border-color: rgba(205,127,50,0.25);
}

#leaderboard-list .leaderboard-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#leaderboard-list .leaderboard-score {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 0.85em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: rgba(0,100,180,0.25);
  color: #70c8f0;
  border: 1px solid rgba(0,180,255,0.2);
  flex-shrink: 0;
}

#leaderboard-list li:nth-child(1) .leaderboard-score {
  background: linear-gradient(135deg, rgba(255,215,0,0.25), rgba(255,180,0,0.12));
  color: #ffd700;
  border-color: rgba(255,215,0,0.35);
  box-shadow: 0 0 10px rgba(255,215,0,0.12);
}

#leaderboard-list li:nth-child(2) .leaderboard-score {
  background: linear-gradient(135deg, rgba(192,192,192,0.2), rgba(160,160,160,0.1));
  color: #c0c0d0;
  border-color: rgba(192,192,192,0.3);
}

#leaderboard-list li:nth-child(3) .leaderboard-score {
  background: linear-gradient(135deg, rgba(205,127,50,0.25), rgba(180,100,30,0.12));
  color: #d4a574;
  border-color: rgba(205,127,50,0.3);
}

@keyframes listItemIn {
  from {
    opacity: 0;
    transform: translateY(12px) translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0) translateX(0);
  }
}

/* ===== GAME OVER ===== */
#final-score {
  font-size: 1.8em;
  font-weight: 700;
  margin: 12px 0 24px;
  background: linear-gradient(135deg, #ffd54f, #ffab00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 10px rgba(255,180,0,0.3));
}

/* ===== RESPONSIVE ===== */
@media (max-width: 760px) {
  #leaderboard-list {
    grid-template-columns: repeat(2, 1fr);
    width: 100%;
  }
}

@media (max-width: 500px) {
  #start-screen, #game-over-screen, #leaderboard-screen {
    padding: 32px 24px;
    min-width: 280px;
    width: 90vw;
  }
  h1 { font-size: 2.2em; }
  h2 { font-size: 1.7em; }
  #hud { padding: 8px 16px; gap: 14px; min-width: 220px; }
  #leaderboard-list {
    grid-template-columns: 1fr;
    max-width: 320px;
  }
}