/* ===== CSS Variables & Reset ===== */
:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #12122a;
  --bg-card: #1a1a3e;
  --bg-card-hover: #252560;
  --neon-green: #00ff88;
  --neon-blue: #00d4ff;
  --neon-purple: #a855f7;
  --neon-pink: #ff00aa;
  --text-primary: #e0e0ff;
  --text-secondary: #8888bb;
  --danger: #ff4444;
  --success: #00ff88;
  --gold: #ffd700;
  --silver: #c0c0c0;
  --bronze: #cd7f32;
  --glow-green: 0 0 15px rgba(0, 255, 136, 0.4);
  --glow-blue: 0 0 15px rgba(0, 212, 255, 0.4);
  --glow-purple: 0 0 15px rgba(168, 85, 247, 0.4);
}

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

body {
  font-family: 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* Subtle animated background grid */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 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: 50px 50px;
  pointer-events: none;
  z-index: 0;
}

#confetti-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 9999;
}

/* ===== Container ===== */
.container {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* ===== Header ===== */
header {
  text-align: center;
  margin-bottom: 20px;
}

header h1 {
  font-size: 2.2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--neon-green), var(--neon-blue), var(--neon-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 2px;
  text-transform: uppercase;
}

header h1 i {
  -webkit-text-fill-color: var(--neon-green);
  margin-right: 8px;
  filter: drop-shadow(var(--glow-green));
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 4px;
  letter-spacing: 1px;
}

/* ===== Target Area ===== */
#target-area {
  background: var(--bg-secondary);
  border: 1px solid rgba(0, 212, 255, 0.2);
  border-radius: 16px;
  padding: 16px 20px;
  text-align: center;
  margin-bottom: 16px;
  box-shadow: var(--glow-blue);
  transition: all 0.3s ease;
}

.target-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: var(--neon-blue);
  margin-bottom: 8px;
}

#target-concept {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--neon-green);
  text-shadow: var(--glow-green);
  min-height: 48px;
}

#target-icon {
  font-size: 1.8rem;
}

/* ===== Info Bar (Score & Question Count) ===== */
.info-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

.info-badge {
  background: var(--bg-secondary);
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--neon-purple);
  text-shadow: var(--glow-purple);
  letter-spacing: 1px;
}

.info-badge i {
  margin-right: 6px;
  color: var(--gold);
}

/* ===== Controls ===== */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

#timer {
  font-family: 'Courier New', monospace;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--neon-blue);
  text-shadow: var(--glow-blue);
  letter-spacing: 2px;
  background: var(--bg-secondary);
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid rgba(0, 212, 255, 0.15);
  transition: color 0.3s ease, text-shadow 0.3s ease, border-color 0.3s ease;
}

#timer.timer-warning {
  color: var(--danger);
  text-shadow: 0 0 15px rgba(255, 68, 68, 0.6);
  border-color: rgba(255, 68, 68, 0.4);
  animation: timerPulse 1s ease infinite;
}

@keyframes timerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

#skip-btn {
  background: linear-gradient(135deg, #3a1c71, #d76d77);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

#skip-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(215, 109, 119, 0.4);
}

#skip-btn:active {
  transform: translateY(0);
}

/* ===== Bingo Grid ===== */
#bingo-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.tile {
  aspect-ratio: 1;
  background: var(--bg-card);
  border: 2px solid rgba(168, 85, 247, 0.15);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tile::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(135deg, transparent 40%, rgba(168, 85, 247, 0.05));
  pointer-events: none;
}

.tile:hover:not(.matched):not(.disabled) {
  background: var(--bg-card-hover);
  border-color: rgba(168, 85, 247, 0.4);
  transform: translateY(-3px);
  box-shadow: var(--glow-purple);
}

.tile .tile-icon {
  font-size: 1.6rem;
  color: var(--neon-purple);
  transition: all 0.25s ease;
}

.tile .tile-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.2;
  padding: 0 4px;
  transition: all 0.25s ease;
}

/* Matched tile (correct answer) */
.tile.matched {
  background: linear-gradient(135deg, rgba(0, 255, 136, 0.15), rgba(0, 212, 255, 0.1));
  border-color: var(--neon-green);
  box-shadow: var(--glow-green);
  cursor: default;
}

.tile.matched .tile-icon {
  color: var(--neon-green);
}

.tile.matched .tile-label {
  color: var(--neon-green);
}

.tile.matched::after {
  content: '\f00c';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.65rem;
  color: var(--neon-green);
}

/* Burned tile (wrong answer, one-time-use) */
.tile.burned {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.08);
  cursor: default;
  opacity: 0.45;
}

.tile.burned .tile-icon {
  color: var(--text-secondary);
}

.tile.burned .tile-label {
  color: var(--text-secondary);
}

.tile.burned::after {
  content: '\f00d';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 0.65rem;
  color: var(--danger);
}

/* End-of-game result: wrong (red highlight) */
.tile.result-wrong {
  background: rgba(255, 68, 68, 0.2) !important;
  border-color: var(--danger) !important;
  box-shadow: 0 0 15px rgba(255, 68, 68, 0.3);
  opacity: 1 !important;
}

.tile.result-wrong .tile-icon {
  color: var(--danger);
}

.tile.result-wrong .tile-label {
  color: var(--danger);
}

/* End-of-game result: correct (green highlight) */
.tile.result-correct {
  background: linear-gradient(135deg, rgba(0, 255, 136, 0.15), rgba(0, 212, 255, 0.1)) !important;
  border-color: var(--neon-green) !important;
  box-shadow: var(--glow-green);
  opacity: 1 !important;
}

/* Wrong shake */
.tile.wrong {
  animation: shake 0.5s ease;
  border-color: var(--danger) !important;
  background: rgba(255, 68, 68, 0.15) !important;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-8px); }
  30% { transform: translateX(8px); }
  45% { transform: translateX(-6px); }
  60% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
  90% { transform: translateX(3px); }
}

/* Bingo line highlight */
.tile.bingo-line {
  animation: bingoGlow 0.8s ease infinite alternate;
}

@keyframes bingoGlow {
  from {
    box-shadow: 0 0 10px rgba(0, 255, 136, 0.4);
    border-color: var(--neon-green);
  }
  to {
    box-shadow: 0 0 30px rgba(0, 255, 136, 0.8), 0 0 60px rgba(0, 255, 136, 0.3);
    border-color: #fff;
  }
}

/* Disabled tile (game not started / game over) */
.tile.disabled {
  opacity: 0.5;
  cursor: default;
}

/* ===== Action Buttons ===== */
.actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 24px;
}

.actions button {
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.5px;
}

#new-game-btn {
  background: linear-gradient(135deg, var(--neon-green), #00b894);
  color: #0a0a1a;
}

#new-game-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0, 255, 136, 0.4);
}

#leaderboard-btn {
  background: linear-gradient(135deg, var(--neon-purple), #6c5ce7);
  color: #fff;
}

#leaderboard-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(168, 85, 247, 0.4);
}

/* ===== Leaderboard Panel ===== */
#leaderboard-panel {
  background: var(--bg-secondary);
  border: 1px solid rgba(168, 85, 247, 0.25);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--glow-purple);
  animation: fadeIn 0.3s ease;
}

#leaderboard-panel h2 {
  text-align: center;
  color: var(--neon-purple);
  margin-bottom: 16px;
  font-size: 1.3rem;
}

#leaderboard-panel h2 i {
  color: var(--gold);
  margin-right: 8px;
}

#leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 16px;
}

#leaderboard-table th {
  color: var(--neon-blue);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding: 8px 12px;
  border-bottom: 1px solid rgba(0, 212, 255, 0.15);
  text-align: left;
}

#leaderboard-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 0.9rem;
}

#leaderboard-table tbody tr {
  transition: background 0.2s ease;
}

#leaderboard-table tbody tr:hover {
  background: rgba(168, 85, 247, 0.08);
}

/* Rank medals */
.rank-1 { color: var(--gold); font-weight: 700; }
.rank-2 { color: var(--silver); font-weight: 700; }
.rank-3 { color: var(--bronze); font-weight: 700; }

#close-lb-btn {
  display: block;
  margin: 0 auto;
  padding: 10px 28px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

#close-lb-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
}

/* ===== Win Modal ===== */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid rgba(0, 255, 136, 0.3);
  border-radius: 20px;
  padding: 36px 32px;
  text-align: center;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 0 40px rgba(0, 255, 136, 0.2);
  animation: scaleIn 0.4s ease;
}

.modal-content h2 {
  font-size: 2rem;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--neon-green), var(--neon-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-content p {
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-size: 1rem;
}

.win-score {
  font-size: 1.4rem;
  margin-bottom: 8px !important;
}

.win-score span {
  color: var(--neon-green);
  font-weight: 700;
  font-family: 'Courier New', monospace;
}

.win-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 20px !important;
}

#player-name,
#game-code,
#student-id {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 2px solid rgba(168, 85, 247, 0.3);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s ease;
  margin-bottom: 12px;
}

#player-name:focus,
#game-code:focus,
#student-id:focus {
  border-color: var(--neon-purple);
  box-shadow: var(--glow-purple);
}

#player-name::placeholder,
#game-code::placeholder,
#student-id::placeholder {
  color: var(--text-secondary);
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.modal-actions button {
  padding: 12px 28px;
  border: none;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

#submit-score-btn {
  background: linear-gradient(135deg, var(--neon-green), #00b894);
  color: #0a0a1a;
}

#submit-score-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0, 255, 136, 0.4);
}

#skip-submit-btn {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

#skip-submit-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
}

/* ===== Utilities ===== */
.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* ===== Responsive ===== */
@media (max-width: 480px) {
  .container {
    padding: 12px 10px 30px;
  }

  header h1 {
    font-size: 1.6rem;
  }

  #target-concept {
    font-size: 1.2rem;
  }

  #target-icon {
    font-size: 1.4rem;
  }

  #timer {
    font-size: 1.2rem;
    padding: 6px 12px;
  }

  #skip-btn {
    padding: 8px 14px;
    font-size: 0.8rem;
  }

  #bingo-grid {
    gap: 7px;
  }

  .tile .tile-icon {
    font-size: 1.2rem;
  }

  .tile .tile-label {
    font-size: 0.55rem;
  }

  .actions button {
    padding: 10px 18px;
    font-size: 0.85rem;
  }
}

@media (max-width: 360px) {
  #bingo-grid {
    gap: 5px;
  }

  .tile .tile-icon {
    font-size: 1rem;
  }

  .tile .tile-label {
    font-size: 0.5rem;
  }
}
