/* ===== RESET & BASE ===== */
:root {
  --clr-bg: #0a0a1a;
  --clr-primary: #00e5ff;
  --clr-accent: #9c27b0;
  --clr-fast: #ff9800;
  --clr-slow: #ffeb3b;
  --clr-text: #ffffff;
  --clr-danger: #ff1744;
  --clr-success: #4caf50;
  --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);
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--clr-text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* ===== CANVAS ===== */
canvas {
  position: fixed;
  inset: 0;
  display: block;
  background: var(--clr-bg);
}

/* ===== LANGUAGE TOGGLE ===== */
.lang-btn {
  position: fixed;
  top: calc(10px + var(--safe-top));
  right: calc(10px + var(--safe-right));
  z-index: 20;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: rgba(10, 10, 26, 0.7);
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  touch-action: manipulation;
  min-height: 36px;
  min-width: 64px;
}

.lang-btn:hover, .lang-btn:focus-visible {
  border-color: var(--clr-primary);
  color: var(--clr-primary);
  background: rgba(0, 229, 255, 0.1);
}

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

/* ===== OVERLAY ===== */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 6, 20, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-inner {
  text-align: center;
  max-width: 420px;
  width: 100%;
  padding: 24px 16px;
  animation: fadeSlideIn 0.4s ease-out;
  margin: auto;
}

/* ===== TITLE ===== */
.title {
  margin: 0 0 8px;
  font-size: clamp(36px, 10vw, 56px);
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--clr-primary);
  text-shadow: 0 0 30px rgba(0, 229, 255, 0.5), 0 0 60px rgba(0, 229, 255, 0.2);
}

.subtitle {
  margin: 0 0 20px;
  font-size: clamp(14px, 3.5vw, 16px);
  opacity: 0.7;
  font-weight: 400;
}

/* ===== LEGEND ===== */
.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  margin: 16px 0;
  font-size: clamp(11px, 2.8vw, 13px);
  opacity: 0.85;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot-blue   { background: var(--clr-primary); box-shadow: 0 0 6px var(--clr-primary); }
.dot-orange { background: var(--clr-fast);    box-shadow: 0 0 6px var(--clr-fast); }
.dot-yellow { background: var(--clr-slow);    box-shadow: 0 0 6px var(--clr-slow); }
.dot-purple { background: var(--clr-accent);  box-shadow: 0 0 6px var(--clr-accent); }

/* ===== TIPS ===== */
.tip {
  margin: 12px 0 4px;
  font-size: clamp(11px, 2.8vw, 13px);
  opacity: 0.55;
}

.controls-hint {
  margin: 16px 0 0;
  font-size: clamp(10px, 2.5vw, 12px);
  opacity: 0.4;
  letter-spacing: 0.05em;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-block;
  margin-top: 20px;
  padding: 14px 48px;
  font-size: clamp(15px, 4vw, 18px);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 2px solid var(--clr-primary);
  border-radius: 6px;
  background: transparent;
  color: var(--clr-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
  touch-action: manipulation;
  min-height: 48px;
}

.btn:hover, .btn:focus-visible {
  background: var(--clr-primary);
  color: var(--clr-bg);
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.4);
}

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

/* ===== COUNTDOWN ===== */
.countdown-num {
  font-size: clamp(80px, 25vw, 140px);
  font-weight: 900;
  color: var(--clr-primary);
  text-shadow: 0 0 40px rgba(0, 229, 255, 0.6);
  animation: countPulse 0.6s ease-out;
  line-height: 1;
}

.countdown-go {
  font-size: clamp(60px, 20vw, 100px);
  font-weight: 900;
  color: var(--clr-success);
  text-shadow: 0 0 40px rgba(76, 175, 80, 0.6);
  animation: countPulse 0.4s ease-out;
  line-height: 1;
}

/* ===== LIFE OVER ===== */
.life-lost-title {
  font-size: clamp(32px, 9vw, 48px);
  font-weight: 900;
  color: var(--clr-danger);
  margin: 0 0 8px;
  text-shadow: 0 0 20px rgba(255, 23, 68, 0.5);
}

.lives-remaining {
  font-size: clamp(15px, 4vw, 18px);
  opacity: 0.7;
  margin: 0 0 16px;
}

/* ===== GAME OVER ===== */
.game-over-title {
  font-size: clamp(34px, 9vw, 52px);
  font-weight: 900;
  margin: 0 0 4px;
  color: var(--clr-danger);
  text-shadow: 0 0 30px rgba(255, 23, 68, 0.5);
}

.new-highscore {
  font-size: clamp(16px, 4.5vw, 20px);
  font-weight: 700;
  color: var(--clr-slow);
  margin: 8px 0;
  animation: highscorePulse 1.2s ease-in-out infinite;
  text-shadow: 0 0 15px rgba(255, 235, 59, 0.5);
}

.final-score {
  margin: 16px 0 4px;
}

.final-score .label {
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  opacity: 0.5;
}

.final-score .value {
  display: block;
  font-size: clamp(36px, 12vw, 56px);
  font-weight: 900;
  color: var(--clr-primary);
  text-shadow: 0 0 20px rgba(0, 229, 255, 0.4);
  line-height: 1.1;
}

.final-time {
  font-size: 14px;
  opacity: 0.5;
  margin-bottom: 20px;
}

/* ===== LEADERBOARD ===== */
.leaderboard {
  margin: 0 auto;
  max-width: 320px;
}

.leaderboard h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  opacity: 0.5;
  margin: 0 0 10px;
  font-weight: 600;
}

.lb-entry {
  display: flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 4px;
  font-size: 14px;
  gap: 10px;
  transition: background 0.2s;
}

.lb-entry.current {
  background: rgba(0, 229, 255, 0.12);
  border: 1px solid rgba(0, 229, 255, 0.25);
}

.lb-entry:not(.current) {
  border: 1px solid transparent;
}

.lb-rank {
  width: 28px;
  text-align: center;
  font-weight: 700;
  flex-shrink: 0;
}

.lb-score {
  flex: 1;
  text-align: left;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.lb-time {
  font-size: 12px;
  opacity: 0.45;
  font-variant-numeric: tabular-nums;
}

.lb-you {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--clr-primary);
  letter-spacing: 0.1em;
}

.lb-empty {
  font-size: 13px;
  opacity: 0.3;
  padding: 8px 0;
}

/* ===== PAUSED ===== */
.paused-title {
  font-size: clamp(36px, 10vw, 52px);
  font-weight: 900;
  margin: 0 0 12px;
  opacity: 0.8;
}

/* ===== ANIMATIONS ===== */
@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes countPulse {
  from {
    transform: scale(1.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes highscorePulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}

/* ===== RESPONSIVE — small phones ===== */
@media (max-width: 380px) {
  .overlay-inner { padding: 16px 10px; }
  .btn { padding: 12px 32px; }
  .legend { gap: 6px 12px; }
}

/* ===== RESPONSIVE — landscape phones ===== */
@media (max-height: 420px) and (orientation: landscape) {
  .overlay-inner { padding: 8px 16px; }
  .title { font-size: 28px; margin-bottom: 4px; }
  .subtitle { margin-bottom: 8px; font-size: 13px; }
  .legend { margin: 6px 0; gap: 4px 12px; font-size: 11px; }
  .tip { margin: 4px 0; font-size: 11px; }
  .btn { margin-top: 8px; padding: 8px 32px; font-size: 14px; min-height: 36px; }
  .controls-hint { margin-top: 6px; }
  .game-over-title, .life-lost-title, .paused-title { font-size: 28px; }
  .final-score .value { font-size: 32px; }
  .final-score { margin: 8px 0 2px; }
  .final-time { margin-bottom: 8px; }
  .leaderboard h2 { margin-bottom: 4px; }
  .lb-entry { padding: 4px 10px; }
  .countdown-num { font-size: 72px; }
  .countdown-go { font-size: 56px; }
}
