*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep: #0a0e1a;
  --bg-panel: rgba(12, 20, 40, 0.85);
  --accent: #00e5ff;
  --accent-glow: rgba(0, 229, 255, 0.4);
  --gold: #ffd700;
  --danger: #ff3366;
  --success: #00ff88;
  --purple: #a855f7;
  --text: #e8f0ff;
  --text-dim: #7a8baa;
  --border: rgba(0, 229, 255, 0.2);
  --font-display: 'Orbitron', sans-serif;
  --font-body: 'Rajdhani', sans-serif;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font-body);
}

/* Starfield */
#stars {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1px 1px at 10% 20%, #fff8, transparent),
    radial-gradient(1px 1px at 30% 60%, #fff6, transparent),
    radial-gradient(1.5px 1.5px at 50% 10%, #fff9, transparent),
    radial-gradient(1px 1px at 70% 40%, #fff5, transparent),
    radial-gradient(1px 1px at 90% 80%, #fff7, transparent),
    radial-gradient(1.5px 1.5px at 15% 85%, #fff6, transparent),
    radial-gradient(1px 1px at 85% 15%, #fff8, transparent),
    radial-gradient(ellipse at 50% 100%, #0d2847 0%, transparent 60%),
    linear-gradient(180deg, #0a0e1a 0%, #0f1a30 50%, #0a1628 100%);
  z-index: 0;
  animation: starTwinkle 8s ease-in-out infinite alternate;
}

@keyframes starTwinkle {
  0% { opacity: 0.85; }
  100% { opacity: 1; }
}

#zone-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(circle at 50% 50%, transparent 40%, rgba(255, 51, 102, 0.08) 100%);
  transition: background 1s ease;
}

/* Screens */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow-y: auto;
}

.screen.active { display: flex; }

.accent { color: var(--accent); }

/* Title Screen */
.title-content {
  text-align: center;
  z-index: 2;
  animation: fadeUp 0.8s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.logo-ring {
  width: 120px;
  height: 120px;
  margin: 0 auto 1.5rem;
  border-radius: 50%;
  border: 3px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 40px var(--accent-glow), inset 0 0 30px rgba(0, 229, 255, 0.1);
  animation: ringPulse 3s ease-in-out infinite;
}

@keyframes ringPulse {
  0%, 100% { box-shadow: 0 0 40px var(--accent-glow); }
  50% { box-shadow: 0 0 60px var(--accent-glow), 0 0 80px rgba(0, 229, 255, 0.2); }
}

.logo-globe { font-size: 3.5rem; animation: spin 20s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.game-title {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  font-weight: 900;
  letter-spacing: 0.15em;
  text-shadow: 0 0 30px var(--accent-glow);
}

.tagline {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--gold);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  margin: 0.5rem 0;
}

.subtitle { color: var(--text-dim); font-size: 1.15rem; margin-bottom: 1.5rem; }

.title-stats {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 2rem;
}

.stat-pill {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 0.5rem 1.2rem;
  border-radius: 2rem;
  font-size: 0.95rem;
  color: var(--text-dim);
}

.stat-pill span { color: var(--accent); font-weight: 700; }

/* Buttons */
.btn-primary, .btn-secondary, .btn-back, .btn-icon {
  font-family: var(--font-display);
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #0088cc);
  color: #0a0e1a;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 1rem 3rem;
  border-radius: 4px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 30px var(--accent-glow); }
.btn-primary.pulse { animation: btnPulse 2s ease-in-out infinite; }

@keyframes btnPulse {
  0%, 100% { box-shadow: 0 4px 20px var(--accent-glow); }
  50% { box-shadow: 0 4px 40px var(--accent-glow), 0 0 60px rgba(0, 229, 255, 0.3); }
}

.btn-secondary {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 0.7rem 2rem;
  border-radius: 4px;
  font-size: 0.9rem;
  letter-spacing: 0.1em;
  margin-top: 0.8rem;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-back {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 0.4rem 1rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.btn-back:hover { color: var(--accent); border-color: var(--accent); }

.btn-icon {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.3rem;
  z-index: 100;
}

.btn-icon.muted { opacity: 0.5; }

/* Floating players on title */
.floating-players {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.float-player {
  position: absolute;
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 0.3rem 0.7rem;
  border-radius: 1rem;
  animation: floatDrift 12s linear infinite;
  opacity: 0.6;
}

@keyframes floatDrift {
  0% { transform: translateY(100vh) translateX(0); opacity: 0; }
  10% { opacity: 0.6; }
  90% { opacity: 0.6; }
  100% { transform: translateY(-10vh) translateX(30px); opacity: 0; }
}

/* Level Select */
.screen-header {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.screen-header h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  letter-spacing: 0.1em;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.2rem;
  max-width: 900px;
  width: 100%;
}

.level-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.level-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--level-color, var(--accent));
}

.level-card:hover {
  transform: translateY(-4px);
  border-color: var(--level-color, var(--accent));
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.level-card.locked { opacity: 0.4; pointer-events: none; }

.level-icon { font-size: 2.5rem; margin-bottom: 0.8rem; }

.level-name {
  font-family: var(--font-display);
  font-size: 1rem;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
}

.level-desc { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 0.8rem; }

.level-meta {
  display: flex;
  gap: 0.8rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.level-difficulty {
  padding: 0.15rem 0.6rem;
  border-radius: 1rem;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}

.diff-easy { background: rgba(0, 255, 136, 0.15); color: var(--success); }
.diff-medium { background: rgba(255, 215, 0, 0.15); color: var(--gold); }
.diff-hard { background: rgba(255, 136, 51, 0.15); color: #ff8833; }
.diff-expert { background: rgba(255, 51, 102, 0.15); color: var(--danger); }
.diff-legendary { background: rgba(168, 85, 247, 0.15); color: var(--purple); }

/* Lobby */
.lobby-content {
  text-align: center;
  max-width: 500px;
  animation: fadeUp 0.5s ease;
}

.lobby-content h2 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin-bottom: 2rem;
}

.player-count-display { margin-bottom: 1.5rem; }

.big-number {
  font-family: var(--font-display);
  font-size: 5rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 40px var(--accent-glow);
  display: block;
  line-height: 1;
}

.player-count-display .label {
  color: var(--text-dim);
  font-size: 1rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.lobby-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.lobby-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  border-radius: 3px;
  transition: width 0.3s ease;
}

.lobby-status { color: var(--text-dim); margin-bottom: 1.5rem; }

.rival-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  max-height: 120px;
  overflow: hidden;
}

.rival-tag {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 0.2rem 0.6rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  animation: rivalPop 0.3s ease;
}

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

/* Game HUD */
#screen-game {
  justify-content: flex-start;
  padding: 0.8rem;
  gap: 0.6rem;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 1100px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 1.2rem;
  backdrop-filter: blur(10px);
}

.hud-left, .hud-right {
  display: flex;
  gap: 1.2rem;
}

.hud-stat { text-align: center; }

.hud-label {
  display: block;
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.15em;
  font-family: var(--font-display);
}

.hud-value {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
}

.zone-value { color: var(--danger); }
.rank-value { color: var(--gold); }

.timer-ring {
  position: relative;
  width: 56px;
  height: 56px;
}

.timer-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }

.timer-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 6;
}

.timer-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 283;
  stroke-dashoffset: 0;
  transition: stroke 0.3s ease;
}

.timer-progress.warning { stroke: var(--gold); }
.timer-progress.danger { stroke: var(--danger); }

.timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
}

/* Game Map / Zone Canvas */
.game-map {
  position: relative;
  width: 100%;
  max-width: 1100px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

#zone-canvas {
  width: 100%;
  height: auto;
  display: block;
  background: #0d1f3c;
}

.elimination-feed {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-width: 220px;
}

.elim-msg {
  background: rgba(255, 51, 102, 0.85);
  color: #fff;
  padding: 0.3rem 0.7rem;
  border-radius: 4px;
  font-size: 0.75rem;
  animation: elimSlide 0.4s ease, elimFade 3s ease 2s forwards;
}

@keyframes elimSlide {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes elimFade {
  to { opacity: 0; transform: translateX(50px); }
}

/* Question Panel */
.question-panel {
  width: 100%;
  max-width: 1100px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.2rem 1.5rem;
  backdrop-filter: blur(10px);
}

.question-meta {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 0.6rem;
}

.question-category {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.question-difficulty {
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 1rem;
  font-weight: 600;
}

.question-text {
  font-size: clamp(1.1rem, 3vw, 1.5rem);
  font-weight: 600;
  margin-bottom: 1rem;
  line-height: 1.4;
}

.answers-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

.answer-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.9rem 1rem;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.answer-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(0, 229, 255, 0.08);
  transform: translateX(4px);
}

.answer-btn:disabled { cursor: default; }

.answer-btn.correct {
  border-color: var(--success);
  background: rgba(0, 255, 136, 0.15);
  animation: correctFlash 0.5s ease;
}

.answer-btn.wrong {
  border-color: var(--danger);
  background: rgba(255, 51, 102, 0.15);
  animation: wrongShake 0.4s ease;
}

@keyframes correctFlash {
  0% { box-shadow: 0 0 0 rgba(0, 255, 136, 0); }
  50% { box-shadow: 0 0 20px rgba(0, 255, 136, 0.5); }
  100% { box-shadow: 0 0 0 rgba(0, 255, 136, 0); }
}

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

/* Results */
.results-content {
  text-align: center;
  max-width: 600px;
  animation: fadeUp 0.6s ease;
}

.results-badge { font-size: 4rem; margin-bottom: 1rem; }

.results-content h2 {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  letter-spacing: 0.1em;
  margin-bottom: 0.5rem;
}

#results-subtitle { color: var(--text-dim); margin-bottom: 2rem; }

.results-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.result-stat {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 0.5rem;
}

.result-value {
  display: block;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.result-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.leaderboard {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  text-align: left;
}

.lb-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 0.9rem;
}

.lb-row.you { background: rgba(0, 229, 255, 0.1); color: var(--accent); font-weight: 600; }
.lb-row.winner { color: var(--gold); }

.lb-rank { font-family: var(--font-display); font-weight: 700; min-width: 2rem; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  max-width: 500px;
  width: 90%;
  position: relative;
  animation: fadeUp 0.3s ease;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
}

.modal-content h2 {
  font-family: var(--font-display);
  margin-bottom: 1.5rem;
  letter-spacing: 0.1em;
}

.how-step {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: flex-start;
}

.step-num {
  font-family: var(--font-display);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.9rem;
  min-width: 2rem;
}

.how-step p { color: var(--text-dim); line-height: 1.5; }
.how-step strong { color: var(--text); }

/* Responsive */
@media (max-width: 700px) {
  .hud { flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
  .hud-left, .hud-right { gap: 0.8rem; }
  .answers-grid { grid-template-columns: 1fr; }
  .results-stats { grid-template-columns: repeat(2, 1fr); }
}