/* =========================================================
   Bingo Game — Global Styles
   Theme: Deep space purple × electric violet × neon green
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Syne:wght@400;600;700;800&family=DM+Sans:wght@400;500&display=swap');

/* --- CSS Variables --- */
:root {
  --purple-950: #0d0a1a;
  --purple-900: #130e28;
  --purple-800: #1e1540;
  --purple-700: #2d2060;
  --purple-600: #4c3899;
  --purple-500: #6d28d9;
  --purple-400: #8b5cf6;
  --purple-300: #a78bfa;
  --purple-200: #c4b5fd;
  --purple-100: #ede9fe;

  --neon:   #a3e635;
  --neon-d: #65a30d;
  --gold:   #fbbf24;
  --rose:   #fb7185;
  --cyan:   #22d3ee;

  --bg:       var(--purple-950);
  --surface:  var(--purple-900);
  --surface2: var(--purple-800);
  --border:   rgba(139,92,246,0.18);
  --border2:  rgba(139,92,246,0.35);

  --text:      #f1effe;
  --text-muted: #9d8fcc;
  --text-dim:  #5c4f8a;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --shadow: 0 0 0 1px var(--border), 0 4px 24px rgba(0,0,0,0.4);
  --shadow-purple: 0 0 0 1px var(--border2), 0 8px 32px rgba(109,40,217,0.25);
  --glow: 0 0 20px rgba(163,230,53,0.3);

  --transition: 0.2s 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: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3,h4,h5,h6 {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

a { color: var(--purple-300); text-decoration: none; }
a:hover { color: var(--neon); }

img, svg { display: block; }

/* --- Layout Helpers --- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.container-sm {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.text-center { text-align: center; }
.w-full { width: 100%; }
.mt-auto { margin-top: auto; }

/* --- Card Component --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  position: relative;
  overflow: hidden;
}

.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--purple-500), transparent);
  opacity: 0.6;
}

.card-sm { padding: 1.25rem; }

/* --- Form Elements --- */
.form-group { margin-bottom: 1.25rem; }

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-control {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9375rem;
  transition: var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--purple-400);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.18);
}

.form-control::placeholder { color: var(--text-dim); }

select.form-control {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%239d8fcc' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.5rem;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--purple-500);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--purple-400);
  color: white;
  box-shadow: var(--shadow-purple);
}

.btn-neon {
  background: var(--neon);
  color: #0a1a00;
}
.btn-neon:hover:not(:disabled) {
  background: #bef264;
  box-shadow: var(--glow);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
  border-color: var(--border2);
  color: var(--text);
  background: var(--surface2);
}

.btn-danger {
  background: rgba(251,113,133,0.15);
  color: var(--rose);
  border: 1px solid rgba(251,113,133,0.25);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(251,113,133,0.25);
}

.btn-sm { padding: 0.5rem 1rem; font-size: 0.8125rem; }
.btn-lg { padding: 1rem 2rem; font-size: 1rem; }
.btn-full { width: 100%; }

.btn-icon {
  padding: 0.625rem;
  border-radius: var(--radius-sm);
}

/* --- Badge / Pill --- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-purple { background: rgba(109,40,217,0.25); color: var(--purple-300); }
.badge-neon   { background: rgba(163,230,53,0.15); color: var(--neon); }
.badge-gold   { background: rgba(251,191,36,0.15); color: var(--gold); }
.badge-rose   { background: rgba(251,113,133,0.15); color: var(--rose); }
.badge-cyan   { background: rgba(34,211,238,0.15); color: var(--cyan); }

/* --- Alert --- */
.alert {
  padding: 0.875rem 1.125rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.alert-danger {
  background: rgba(251,113,133,0.1);
  border: 1px solid rgba(251,113,133,0.25);
  color: var(--rose);
}

.alert-success {
  background: rgba(163,230,53,0.1);
  border: 1px solid rgba(163,230,53,0.2);
  color: var(--neon);
}

.alert-info {
  background: rgba(139,92,246,0.1);
  border: 1px solid var(--border);
  color: var(--purple-300);
}

/* --- Navbar --- */
.navbar {
  background: rgba(13,10,26,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.25rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  letter-spacing: -0.03em;
}

.navbar-brand .logo-mark {
  width: 32px;
  height: 32px;
  background: var(--purple-500);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

/* --- Avatar --- */
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.avatar-sm { width: 32px; height: 32px; font-size: 0.875rem; }
.avatar-lg { width: 52px; height: 52px; font-size: 1.375rem; }

/* --- Online indicator --- */
.online-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--neon);
  box-shadow: 0 0 6px var(--neon);
  flex-shrink: 0;
}

/* --- Divider --- */
.divider {
  height: 1px;
  background: var(--border);
  margin: 1.25rem 0;
}

/* --- Loading spinner --- */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--purple-400);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Toast notification --- */
.toast-container {
  position: fixed;
  top: 5rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 0.875rem 1.125rem;
  font-size: 0.9rem;
  min-width: 260px;
  max-width: 360px;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease;
  pointer-events: all;
}

.toast.hide { animation: toastOut 0.3s ease forwards; }
.toast-success { border-color: rgba(163,230,53,0.35); }
.toast-error   { border-color: rgba(251,113,133,0.35); }

@keyframes toastIn  { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: none; } }
@keyframes toastOut { to   { opacity:0; transform: translateX(20px); } }

/* --- Notification bell badge --- */
.notif-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--rose);
  color: white;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
}

/* --- PWA Install Banner --- */
.install-banner {
  background: linear-gradient(135deg, var(--purple-800), var(--purple-700));
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: none;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.install-banner.visible { display: flex; }

/* --- Bingo Grid (play) --- */
.bingo-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  max-width: 340px;
  margin: 0 auto;
}

.bingo-cell {
  aspect-ratio: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Syne', sans-serif;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  user-select: none;
}

.bingo-cell:hover:not(.marked):not(.disabled) {
  border-color: var(--purple-400);
  background: var(--purple-800);
  transform: scale(1.05);
}

.bingo-cell.marked {
  background: var(--purple-700);
  border-color: var(--purple-500);
  color: var(--purple-200);
}

.bingo-cell.marked::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(139,92,246,0.4) 0%, transparent 70%);
  animation: markPulse 0.4s ease;
}

.bingo-cell.bingo-line {
  background: linear-gradient(135deg, var(--neon-d), var(--neon));
  border-color: var(--neon);
  color: #0a1a00;
  box-shadow: var(--glow);
}

.bingo-cell.disabled { cursor: default; }

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

/* Setup grid (fill-in mode) */
.setup-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
  max-width: 340px;
  margin: 0 auto;
}

.setup-cell {
  aspect-ratio: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Syne', sans-serif;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.setup-cell.filled {
  background: var(--purple-800);
  border-color: var(--purple-500);
  color: var(--purple-200);
}

.setup-cell:hover:not(.filled) {
  border-color: var(--purple-400);
  transform: scale(1.05);
}

/* --- Turn indicator --- */
.turn-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.875rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9375rem;
}

.turn-bar.your-turn {
  border-color: var(--neon);
  background: rgba(163,230,53,0.06);
}

.pulse-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--neon);
  animation: pulseDot 1.2s ease-in-out infinite;
}

@keyframes pulseDot {
  0%,100% { box-shadow: 0 0 0 0 rgba(163,230,53,0.5); }
  50%      { box-shadow: 0 0 0 6px rgba(163,230,53,0); }
}

/* --- Chat --- */
.chat-box {
  height: 220px;
  overflow-y: auto;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  scroll-behavior: smooth;
}

.chat-box::-webkit-scrollbar { width: 4px; }
.chat-box::-webkit-scrollbar-track { background: transparent; }
.chat-box::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.chat-msg {
  font-size: 0.875rem;
  line-height: 1.4;
}

.chat-msg .who {
  font-weight: 600;
  color: var(--purple-300);
  margin-right: 0.375rem;
}

.chat-msg.system .who { color: var(--text-muted); font-style: italic; }

/* --- Leaderboard --- */
.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.leaderboard-row:hover { background: var(--surface2); }

.rank-num {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.125rem;
  width: 2rem;
  text-align: center;
  color: var(--text-dim);
}

.rank-num.gold   { color: var(--gold); }
.rank-num.silver { color: #94a3b8; }
.rank-num.bronze { color: #b45309; }

/* --- Player list in room --- */
.player-slot {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.player-slot.ready { border-color: rgba(163,230,53,0.35); }
.player-slot.waiting { border-color: var(--border); }
.player-slot.empty {
  border-style: dashed;
  opacity: 0.4;
}

/* --- Win overlay --- */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,10,26,0.92);
  backdrop-filter: blur(12px);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1.5rem;
  animation: fadeIn 0.4s ease;
}

.win-title {
  font-family: 'Syne', sans-serif;
  font-size: clamp(2.5rem, 8vw, 5rem);
  font-weight: 800;
  color: var(--neon);
  text-shadow: 0 0 40px rgba(163,230,53,0.5);
  animation: winPop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

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

/* --- Room code display --- */
.room-code {
  font-family: 'Syne', sans-serif;
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: 0.25em;
  color: var(--purple-300);
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 1rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  user-select: all;
}

.room-code:hover { border-color: var(--purple-400); }

/* --- Page transitions --- */
.page-enter {
  animation: pageIn 0.3s ease;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .card { padding: 1.25rem; }
  .bingo-grid { gap: 0.375rem; max-width: 300px; }
  .bingo-cell { font-size: 1rem; }
  .hide-sm { display: none; }
}

/* --- Confetti canvas (JS-controlled) --- */
#confetti-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 998;
}
