/*
 * style.css
 * Responsive, projector-optimized styling for Unicorn Energy Challenge.
 * High-contrast, large type, and clamp()-based sizing so the UI scales from
 * phones to big projector screens. No frameworks.
 */

:root {
  --bg: #2a1a5e;
  --accent: #a06bff;
  --accent-2: #ff5964;
  --gold: #ffb400;
  --text: #ffffff;
  --panel: rgba(20, 12, 46, 0.82);
  --radius: 16px;
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  touch-action: manipulation;
}

/* Full-viewport canvas */
#game-canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
}

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: clamp(12px, 2.5vw, 32px);
  pointer-events: none;
  z-index: 5;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.hud__timer {
  font-size: clamp(1.8rem, 5vw, 3.6rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s ease;
}

/* Last few seconds: red and pulsing so a projector crowd feels the urgency. */
.hud__timer--urgent {
  color: var(--accent-2);
  animation: timer-pulse 0.6s ease-in-out infinite;
}

@keyframes timer-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

.hud__scores { text-align: right; }

.hud__score {
  font-size: clamp(1.8rem, 5vw, 3.6rem);
  font-weight: 800;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.hud__best {
  font-size: clamp(0.8rem, 2vw, 1.2rem);
  opacity: 0.85;
}

/* ---------- Energy meter ---------- */
.energy {
  position: fixed;
  left: 50%;
  bottom: clamp(16px, 3vh, 40px);
  transform: translateX(-50%);
  width: min(80vw, 900px);
  z-index: 5;
  text-align: center;
}

.energy__track {
  height: clamp(18px, 3vh, 34px);
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.energy__fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #6bd67d, #fff275, #ffb400, #ff5964);
  transition: width 60ms linear;
}

.energy__label {
  display: inline-block;
  margin-top: 6px;
  font-size: clamp(0.7rem, 1.6vw, 1rem);
  letter-spacing: 0.25em;
  opacity: 0.8;
}

/* ---------- Controls ---------- */
.controls {
  position: fixed;
  top: clamp(12px, 2.5vw, 32px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: clamp(8px, 1.5vw, 16px);
  z-index: 6;
}

.btn {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 999px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(6px);
  transition: transform 0.12s ease, background 0.2s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.26); }
.btn:active { transform: scale(0.94); }
.btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.btn--icon {
  width: clamp(44px, 6vw, 64px);
  height: clamp(44px, 6vw, 64px);
  font-size: clamp(1.1rem, 2.5vw, 1.8rem);
  display: grid;
  place-items: center;
}

.btn--primary {
  padding: clamp(12px, 2vw, 20px) clamp(24px, 4vw, 44px);
  font-size: clamp(1rem, 2.4vw, 1.6rem);
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 30px rgba(160, 107, 255, 0.5);
}

.btn--ghost {
  display: inline-block;
  margin-top: clamp(10px, 1.6vw, 16px);
  padding: clamp(9px, 1.4vw, 14px) clamp(18px, 3vw, 30px);
  font-size: clamp(0.85rem, 1.9vw, 1.15rem);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.28);
}

/* ---------- Screens & panels ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 10;
  background: rgba(10, 6, 26, 0.45);
  backdrop-filter: blur(4px);
  padding: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius);
  padding: clamp(24px, 4vw, 56px);
  text-align: center;
  max-width: min(92vw, 620px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  /* Entrance tween when a screen/panel appears. */
  animation: panel-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.3) both;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(16px) scale(0.94); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.title {
  margin: 0 0 0.4em;
  font-size: clamp(1.6rem, 5vw, 3.2rem);
  line-height: 1.1;
}

.subtitle {
  margin: 0 0 1.4em;
  font-size: clamp(1rem, 2.6vw, 1.5rem);
  opacity: 0.9;
}

.hint {
  margin-top: 1em;
  font-size: clamp(0.75rem, 1.8vw, 1rem);
  opacity: 0.6;
}

/* ---------- Round-length picker ---------- */
.round-picker {
  margin: 0 0 1.6em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.round-picker__label {
  font-size: clamp(0.85rem, 2vw, 1.1rem);
  letter-spacing: 0.05em;
  opacity: 0.85;
}
.round-picker__presets {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
.chip {
  font-family: inherit;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border-radius: 999px;
  padding: clamp(6px, 1.2vw, 10px) clamp(12px, 2vw, 18px);
  font-size: clamp(0.8rem, 1.8vw, 1.05rem);
  font-weight: 600;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.chip:hover { background: rgba(255, 255, 255, 0.2); }
.chip--active {
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  border-color: transparent;
}
.round-picker__custom {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: clamp(0.8rem, 1.8vw, 1.05rem);
  opacity: 0.9;
}
.round-picker__custom input {
  width: 5.5em;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  color: var(--text);
  font: inherit;
  text-align: center;
}

/* ---------- Leaderboard ---------- */
.leaderboard {
  list-style: none;
  padding: 0;
  margin: 0 0 1.4em;
  max-height: 34vh;
  overflow-y: auto;
  text-align: left;
}
.leaderboard li {
  display: flex;
  justify-content: space-between;
  padding: clamp(6px, 1.2vw, 10px) clamp(10px, 2vw, 16px);
  font-size: clamp(0.9rem, 2vw, 1.3rem);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-variant-numeric: tabular-nums;
}
/* Highlight the row belonging to the run that just finished. */
.leaderboard__mine {
  background: rgba(255, 180, 0, 0.16);
  border-radius: 8px;
  font-weight: 800;
  color: var(--gold);
}

/* ---------- Game-over: highlighted score, badge, fireworks ---------- */
/* Lighter, un-blurred veil so the canvas fireworks read through the screen. */
#gameover-screen {
  background: rgba(10, 6, 26, 0.3);
  backdrop-filter: none;
}

.final { margin: 0 0 1.2em; }

.final__label {
  display: block;
  font-size: clamp(0.75rem, 1.9vw, 1.05rem);
  letter-spacing: 0.35em;
  opacity: 0.7;
  margin-bottom: 0.05em;
}

.final__score {
  font-size: clamp(3rem, 12vw, 6rem);
  font-weight: 900;
  line-height: 1;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 18px rgba(255, 180, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.5);
  animation: score-glow 2.2s ease-in-out infinite;
}

@keyframes score-glow {
  0%, 100% { text-shadow: 0 0 16px rgba(255, 180, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.5); }
  50% { text-shadow: 0 0 32px rgba(255, 180, 0, 0.95), 0 2px 6px rgba(0, 0, 0, 0.5); }
}

/* Re-triggered on each game over: a pop reveal, then the steady glow. */
.final__score--pop {
  animation: score-pop 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.4),
             score-glow 2.2s 0.7s ease-in-out infinite;
}

@keyframes score-pop {
  0% { transform: scale(0.4); opacity: 0; }
  60% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); }
}

.badge-best {
  display: inline-block;
  margin: 0 0 0.7em;
  padding: 6px 18px;
  border-radius: 999px;
  font-weight: 800;
  font-size: clamp(0.85rem, 2vw, 1.2rem);
  color: #2a1a5e;
  background: linear-gradient(90deg, #fff275, var(--gold));
  box-shadow: 0 6px 22px rgba(255, 180, 0, 0.5);
  animation: badge-bounce 0.8s ease both;
}

@keyframes badge-bounce {
  0% { transform: translateY(-14px) scale(0.6); opacity: 0; }
  60% { transform: translateY(3px) scale(1.08); opacity: 1; }
  100% { transform: translateY(0) scale(1); }
}

/* ---------- Settings ---------- */
.panel--settings {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  width: min(92vw, 460px);
  /* Own animation that preserves the centering transform. */
  animation: settings-in 0.3s ease both;
}

@keyframes settings-in {
  from { opacity: 0; transform: translate(-50%, -46%) scale(0.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  margin-bottom: 1.2em;
  font-size: clamp(0.9rem, 2vw, 1.2rem);
}
.field input[type='range'] { width: 100%; accent-color: var(--accent); }
.field--check { flex-direction: row; align-items: center; gap: 12px; }
.field--check input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---------- Spinner ---------- */
.spinner {
  width: 48px;
  height: 48px;
  margin: 12px auto 0;
  border: 5px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Error banner ---------- */
.error-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: var(--accent-2);
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: clamp(0.85rem, 2vw, 1.1rem);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  max-width: 90vw;
  text-align: center;
}

[hidden] { display: none !important; }

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  .btn { transition: none; }
  .panel, .panel--settings { animation: none; }
  .hud__timer--urgent { animation: none; }
  .final__score, .final__score--pop, .badge-best { animation: none; }
}
