/* ============================================================
   A-Math Lobby — Dark, polished, mobile-first
   ============================================================ */

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

body {
  font-family: 'Outfit', sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Screens */
.screen { display: none; min-height: 100vh; min-height: 100dvh; }
.screen.active { display: flex; }

/* ============================================================
   LOGIN
   ============================================================ */
#screen-login {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
}

.login-card {
  width: 90%;
  max-width: 380px;
  text-align: center;
  padding: 32px 24px;
}

.logo { margin-bottom: 40px; }
.logo-icon { font-size: 48px; display: block; margin-bottom: 8px; }
.logo h1 {
  font-size: 36px;
  font-weight: 800;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -1px;
}
.tagline { color: #94a3b8; font-size: 14px; margin-top: 4px; }

.login-buttons { display: flex; flex-direction: column; gap: 12px; }

.btn-login {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 14px 20px;
  border: none; border-radius: 12px;
  font-size: 15px; font-weight: 600; font-family: 'Outfit', sans-serif;
  cursor: pointer; transition: transform 0.1s, box-shadow 0.2s;
}
.btn-login:active { transform: scale(0.97); }

.btn-google {
  background: #fff; color: #1f2937;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.btn-google:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.3); }

.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 8px 0; color: #475569; font-size: 13px;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: #334155;
}

.email-form { display: flex; flex-direction: column; gap: 10px; }
.email-form input {
  padding: 12px 16px;
  border: 1px solid #334155; border-radius: 10px;
  background: #1e293b; color: #e2e8f0;
  font-size: 15px; font-family: 'Outfit', sans-serif;
  outline: none; transition: border-color 0.2s;
}
.email-form input:focus { border-color: #fbbf24; }

.email-buttons { display: flex; gap: 8px; }
.btn-email {
  flex: 1; background: #fbbf24; color: #1f2937;
}
.btn-register {
  flex: 1; background: #334155; color: #e2e8f0;
}

.btn-guest {
  margin-top: 24px;
  background: none; border: none; color: #64748b;
  font-size: 14px; font-family: 'Outfit', sans-serif;
  cursor: pointer; text-decoration: underline;
}
.btn-guest:hover { color: #94a3b8; }

.error-msg {
  margin-top: 12px; padding: 8px 12px;
  background: #450a0a; color: #fca5a5;
  border-radius: 8px; font-size: 13px;
  display: none;
}
.error-msg.show { display: block; }

/* ============================================================
   PROFILE SETUP
   ============================================================ */
#screen-profile-setup {
  align-items: center;
  justify-content: center;
  background: #0f172a;
}

.setup-card, .modal-card {
  width: 90%; max-width: 380px;
  background: #1e293b;
  border-radius: 16px;
  padding: 28px 24px;
}
.setup-card h2, .modal-card h2 {
  font-size: 22px; font-weight: 700; margin-bottom: 20px; text-align: center;
}

.avatar-section { text-align: center; margin-bottom: 20px; }
.avatar-preview {
  width: 96px; height: 96px; margin: 0 auto 12px;
  border-radius: 50%; overflow: hidden;
  background: #334155;
  display: flex; align-items: center; justify-content: center;
  border: 3px solid #fbbf24;
}
.avatar-preview img {
  width: 100%; height: 100%; object-fit: cover;
  display: none;
}
.avatar-preview img[src]:not([src=""]) { display: block; }
.avatar-preview img[src]:not([src=""]) + .avatar-placeholder { display: none; }
.avatar-placeholder { font-size: 36px; color: #64748b; }

.btn-upload {
  display: inline-block;
  padding: 8px 16px;
  background: #334155; border-radius: 8px;
  color: #e2e8f0; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: 'Outfit', sans-serif;
}
.btn-upload:hover { background: #475569; }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 13px; color: #94a3b8;
  margin-bottom: 6px; font-weight: 600;
}
.form-group input {
  width: 100%; padding: 12px 16px;
  border: 1px solid #334155; border-radius: 10px;
  background: #0f172a; color: #e2e8f0;
  font-size: 15px; font-family: 'Outfit', sans-serif;
  outline: none;
}
.form-group input:focus { border-color: #fbbf24; }

.btn-primary {
  width: 100%; padding: 14px;
  background: #fbbf24; color: #1f2937;
  border: none; border-radius: 12px;
  font-size: 16px; font-weight: 700;
  cursor: pointer; font-family: 'Outfit', sans-serif;
}
.btn-primary:hover { background: #f59e0b; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  width: 100%; padding: 14px;
  background: #334155; color: #e2e8f0;
  border: none; border-radius: 12px;
  font-size: 16px; font-weight: 600;
  cursor: pointer; font-family: 'Outfit', sans-serif;
}

/* ============================================================
   LOBBY
   ============================================================ */
#screen-lobby {
  flex-direction: column;
  padding: 0 16px 24px;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.lobby-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 0; border-bottom: 1px solid #1e293b;
  margin-bottom: 20px;
}
.user-info {
  display: flex; align-items: center; gap: 12px;
  cursor: pointer;
}
.lobby-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  object-fit: cover; border: 2px solid #fbbf24;
  background: #334155;
}
.lobby-name { font-size: 16px; font-weight: 700; }
.lobby-school { font-size: 12px; color: #64748b; }

.btn-icon-header {
  background: none; border: none; font-size: 24px;
  cursor: pointer; padding: 8px; border-radius: 8px;
}
.btn-icon-header:hover { background: #1e293b; }

/* Stats */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px; margin-bottom: 24px;
}
.stat-card {
  background: #1e293b; border-radius: 12px;
  padding: 14px 8px; text-align: center;
}
.stat-value { font-size: 22px; font-weight: 800; color: #fbbf24; }
.stat-label { font-size: 11px; color: #64748b; margin-top: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-win .stat-value { color: #34d399; }
.stat-loss .stat-value { color: #f87171; }
.stat-high .stat-value { color: #a78bfa; }

/* Play Buttons */
.play-section { display: flex; flex-direction: column; gap: 10px; margin-bottom: 28px; }
.btn-play {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 20px;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #1f2937;
  border: none; border-radius: 14px;
  font-size: 17px; font-weight: 700;
  cursor: pointer; font-family: 'Outfit', sans-serif;
}
.btn-play:active { transform: scale(0.97); }
.btn-play .play-icon { font-size: 28px; }
.btn-play-2p {
  background: linear-gradient(135deg, #3b82f6, #2563eb); color: #fff;
}
.btn-play-2p:disabled { opacity: 0.6; cursor: not-allowed; }

/* Leaderboard */
.leaderboard-section {
  background: #1e293b; border-radius: 16px;
  overflow: hidden;
}
.lb-tabs {
  display: flex; border-bottom: 1px solid #334155;
}
.lb-tab {
  flex: 1; padding: 12px;
  background: none; border: none;
  color: #64748b; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: 'Outfit', sans-serif;
  transition: color 0.2s, border-color 0.2s;
  border-bottom: 2px solid transparent;
}
.lb-tab.active { color: #fbbf24; border-bottom-color: #fbbf24; }

.lb-list { padding: 8px 0; max-height: 300px; overflow-y: auto; }
.lb-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
}
.lb-row:nth-child(even) { background: rgba(255,255,255,0.02); }
.lb-rank {
  width: 28px; font-size: 14px; font-weight: 700; color: #64748b; text-align: center;
}
.lb-rank-1 { color: #fbbf24; font-size: 18px; }
.lb-rank-2 { color: #94a3b8; font-size: 16px; }
.lb-rank-3 { color: #cd7f32; font-size: 16px; }
.lb-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; background: #334155;
}
.lb-info { flex: 1; }
.lb-player-name { font-size: 14px; font-weight: 600; }
.lb-player-school { font-size: 11px; color: #64748b; }
.lb-score { font-size: 16px; font-weight: 800; color: #fbbf24; }
.lb-loading { text-align: center; padding: 20px; color: #64748b; font-size: 14px; }
.lb-empty { text-align: center; padding: 20px; color: #475569; font-size: 13px; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-buttons { display: flex; gap: 8px; margin-top: 16px; }
.modal-buttons .btn-primary, .modal-buttons .btn-secondary { flex: 1; }

/* Responsive */
@media (max-width: 360px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   LIGHT MODE  (toggled by the 🎨 header icon → body.lobby-light)
   Overrides the dark defaults with a clean light palette.
   ============================================================ */
body.lobby-light { background: #f1f5f9; color: #1f2937; }
body.lobby-light #screen-login { background: linear-gradient(135deg,#e0e7ff 0%,#f1f5f9 50%,#e0e7ff 100%); }
body.lobby-light .login-card,
body.lobby-light .lobby-header,
body.lobby-light .stat-card,
body.lobby-light .leaderboard-section,
body.lobby-light .badges-section,
body.lobby-light #active-rooms-section,
body.lobby-light .my-games-section,
body.lobby-light .lb-list,
body.lobby-light .card,
body.lobby-light .panel { background: #ffffff; color: #1f2937; border-color: #e2e8f0; }
body.lobby-light .lobby-name,
body.lobby-light .stat-value,
body.lobby-light h1, body.lobby-light h2, body.lobby-light h3 { color: #1f2937; }
body.lobby-light .lobby-school,
body.lobby-light .stat-label,
body.lobby-light .muted,
body.lobby-light .lb-loading { color: #64748b; }
body.lobby-light .btn-icon-header { background: #e2e8f0; color: #1f2937; }
body.lobby-light .btn-guest { color: #2563eb; }
/* keep the bright gradient play buttons & their white text unchanged */

/* Small ghost buttons (View all / Refresh): theme-aware so they stay legible
   in light mode instead of faint grey-on-white. */
.lb-ghost-btn { border: 1px solid #475569; color: #94a3b8; }
body.lobby-light .lb-ghost-btn { border-color: #cbd5e1; color: #475569; }

/* ═══════════════════════════════════════════════════════
   3D EFFECTS — GPU-only (transform + perspective)
   ═══════════════════════════════════════════════════════ */

/* Stat cards — lift on hover */
.stat-card {
  transform-style: preserve-3d;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.stat-card:hover {
  box-shadow: 0 10px 24px rgba(0,0,0,0.4);
}

/* Play buttons — lift + tilt on hover */
.btn-play {
  transform-style: preserve-3d;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 3px 12px rgba(0,0,0,0.3);
}
.btn-play:hover {
  transform: translateY(-3px) scale(1.01);
  box-shadow: 0 10px 24px rgba(0,0,0,0.35);
}
.btn-play:active {
  transform: scale(0.97) !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* Leaderboard rows — slide forward on hover */
.lb-row {
  transition: transform 0.15s ease, background 0.15s;
}
.lb-row:hover {
  transform: translateX(4px);
  background: rgba(255,255,255,0.05) !important;
}

/* User info card — subtle lift */
.user-info {
  transition: transform 0.2s ease;
}
.user-info:hover {
  transform: translateY(-2px);
}

/* Floating background tiles */
.lobby-bg-tile {
  position: fixed;
  width: 36px; height: 36px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 15px;
  pointer-events: none; z-index: 0;
  opacity: 0;
  animation: lobbyTileFloat var(--tile-dur) var(--tile-delay) infinite ease-in;
  will-change: transform, opacity;
}
.lobby-bg-tile.t-num { background:#d4a017; color:#1a1200; border:1.5px solid #f5c842; }
.lobby-bg-tile.t-op  { background:#1e3a8a; color:#bfdbfe; border:1.5px solid #3b82f6; }
.lobby-bg-tile.t-eq  { background:#166534; color:#bbf7d0; border:1.5px solid #22c55e; }

@keyframes lobbyTileFloat {
  0%   { opacity:0; transform:translateY(0) rotateY(0deg); }
  8%   { opacity:0.25; }
  85%  { opacity:0.1; }
  100% { opacity:0; transform:translateY(-105vh) rotateY(360deg); }
}

/* Pause animations when page is hidden (battery saving) */
.lobby-anim-paused .lobby-bg-tile { animation-play-state: paused; }
