/* ── Google Fonts ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;600;700&display=swap');

/* ── CSS Variables ───────────────────────────────────────────────────────── */
:root {
  --bg: #0a0e1a;
  --surface: #111827;
  --surface2: #1a2235;
  --border: #1e2d48;
  --accent: #00d4ff;
  --accent2: #7b61ff;
  --accent3: #ff6b6b;
  --success: #00e5a0;
  --danger: #ff4c6a;
  --text: #e8eaf6;
  --text-muted: #6b7a99;
  --glow: rgba(0, 212, 255, 0.15);
  --glow-strong: rgba(0, 212, 255, 0.35);
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Outfit', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* ── Animated background grid ────────────────────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 212, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 212, 255, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ── Floating orbs ───────────────────────────────────────────────────────── */
.orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.15;
  pointer-events: none;
  z-index: 0;
  animation: float 12s ease-in-out infinite;
}

.orb-1 {
  width: 500px;
  height: 500px;
  background: var(--accent2);
  top: -150px;
  right: -150px;
  animation-delay: 0s;
}

.orb-2 {
  width: 400px;
  height: 400px;
  background: var(--accent);
  bottom: -100px;
  left: -100px;
  animation-delay: -4s;
}

.orb-3 {
  width: 300px;
  height: 300px;
  background: var(--accent3);
  top: 50%;
  left: 40%;
  animation-delay: -8s;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  50% {
    transform: translateY(-40px) scale(1.05);
  }
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
.container {
  position: relative;
  z-index: 1;
  max-width: 680px;
  margin: 0 auto;
  padding: 40px 24px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
}

/* ── Logo / Header ───────────────────────────────────────────────────────── */
.logo {
  text-align: center;
  animation: slideDown 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.logo-icon {
  font-size: 56px;
  display: block;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 20px rgba(0, 212, 255, 0.6));
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {

  0%,
  100% {
    filter: drop-shadow(0 0 20px rgba(0, 212, 255, 0.6));
  }

  50% {
    filter: drop-shadow(0 0 40px rgba(0, 212, 255, 0.9));
  }
}

.logo h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo p {
  color: var(--text-muted);
  font-size: 1rem;
  margin-top: 6px;
}

/* ── Card ────────────────────────────────────────────────────────────────── */
.card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(10px);
  animation: slideUp 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent2), var(--accent3));
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Form Elements ───────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.input-wrapper {
  position: relative;
}

.input-wrapper .input-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  pointer-events: none;
}

input[type="text"] {
  width: 100%;
  padding: 16px 20px 16px 48px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'Outfit', sans-serif;
  font-size: 1.05rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input[type="text"]::placeholder {
  color: var(--text-muted);
}

input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--glow);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 32px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0);
  transition: background var(--transition);
}

.btn:hover::after {
  background: rgba(255, 255, 255, 0.07);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent2) 100%);
  color: #fff;
  box-shadow: 0 4px 24px rgba(0, 212, 255, 0.25);
}

.btn-primary:hover {
  box-shadow: 0 6px 36px rgba(0, 212, 255, 0.45);
  transform: translateY(-1px);
}

.btn-success {
  background: linear-gradient(135deg, var(--success) 0%, #00b37e 100%);
  color: #001a12;
  box-shadow: 0 4px 20px rgba(0, 229, 160, 0.25);
}

.btn-success:hover {
  box-shadow: 0 6px 32px rgba(0, 229, 160, 0.45);
  transform: translateY(-1px);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger) 0%, #cc1a3a 100%);
  color: #fff;
  box-shadow: 0 4px 20px rgba(255, 76, 106, 0.25);
}

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
}

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Score Badge ─────────────────────────────────────────────────────────── */
.score-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  margin-bottom: 24px;
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.score-item .label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}

.score-item .value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.6rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.score-item .value.bump {
  animation: bump 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bump {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.4);
  }

  100% {
    transform: scale(1);
  }
}

.divider {
  width: 1px;
  height: 40px;
  background: var(--border);
}

/* ── Question Box ────────────────────────────────────────────────────────── */
.question-box {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 28px 24px;
  text-align: center;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
  transition: all 0.4s ease;
}

.question-box::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.question-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.question-text {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.5;
}

.question-text code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(0, 212, 255, 0.08);
  padding: 2px 10px;
  border-radius: 6px;
  border: 1px solid rgba(0, 212, 255, 0.2);
}

.hint-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 10px;
  font-style: italic;
}

/* ── Answer Input Area ───────────────────────────────────────────────────── */
.answer-area {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.answer-area input {
  flex: 1;
  text-align: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.2rem;
  font-weight: 600;
  padding-left: 20px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ── Feedback Toast ──────────────────────────────────────────────────────── */
.feedback {
  text-align: center;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.3s ease;
  pointer-events: none;
}

.feedback.show {
  opacity: 1;
  transform: translateY(0);
}

.feedback.correct {
  background: rgba(0, 229, 160, 0.12);
  border: 1px solid rgba(0, 229, 160, 0.3);
  color: var(--success);
}

.feedback.wrong {
  background: rgba(255, 76, 106, 0.12);
  border: 1px solid rgba(255, 76, 106, 0.3);
  color: var(--danger);
}

/* ── Game Over Overlay ───────────────────────────────────────────────────── */
.game-over {
  text-align: center;
  animation: slideUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.game-over .big-icon {
  font-size: 64px;
  margin-bottom: 12px;
}

.game-over h2 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
}

.game-over .final-score {
  font-family: 'JetBrains Mono', monospace;
  font-size: 4rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent3), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 16px 0;
  line-height: 1;
}

.game-over .best-label {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.game-over .best-label span {
  color: var(--accent);
  font-weight: 700;
}

.game-over .btn-group {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Leaderboard ─────────────────────────────────────────────────────────── */
.leaderboard-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Scrollable leaderboard list — shows ~6 rows, then scroll */
#leaderboardList {
  max-height: calc(6 * 58px);
  /* ~58px per row (padding + gap) */
  overflow-y: auto;
  padding-right: 4px;
  /* room for scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#leaderboardList::-webkit-scrollbar {
  width: 5px;
}

#leaderboardList::-webkit-scrollbar-track {
  background: transparent;
}

#leaderboardList::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}

#leaderboardList::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  transition: all var(--transition);
  animation: slideUp 0.4s ease both;
}

.lb-row:hover {
  border-color: var(--accent);
  background: rgba(0, 212, 255, 0.04);
}

.lb-rank {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 0.85rem;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.lb-rank.gold {
  color: #ffd700;
}

.lb-rank.silver {
  color: #c0c0c0;
}

.lb-rank.bronze {
  color: #cd7f32;
}

.lb-rank.other {
  color: var(--text-muted);
}

.lb-name {
  flex: 1;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lb-score {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
}

/* ── Username display (in game) ──────────────────────────────────────────── */
.player-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.player-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fff;
  flex-shrink: 0;
}

/* ── Error message ───────────────────────────────────────────────────────── */
.error-msg {
  background: rgba(255, 76, 106, 0.1);
  border: 1px solid rgba(255, 76, 106, 0.3);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  margin-bottom: 16px;
  display: none;
}

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Streak badge ─────────────────────────────────────────────────────────── */
.streak {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: linear-gradient(135deg, rgba(255, 107, 0, 0.15), rgba(255, 107, 0, 0.05));
  border: 1px solid rgba(255, 107, 0, 0.25);
  color: #ff9f43;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.3s ease;
}

.streak.active {
  opacity: 1;
  transform: scale(1);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .card {
    padding: 28px 20px;
  }

  .answer-area {
    flex-direction: column;
  }

  .game-over .btn-group {
    flex-direction: column;
  }

  .game-over .final-score {
    font-size: 3rem;
  }
}