/* ============================================================
   Live Learning Quest — style.css
   Mobile-first, vanilla CSS, no external dependencies
   Color scheme: blue/purple primary, green correct, red wrong, gold winner
   ============================================================ */

/* ---- Reset & Base ---- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary: #4a2fbd;
  --color-primary-light: #7b5ef0;
  --color-secondary: #8b3fcf;
  --color-bg: #0f0c29;
  --color-bg-card: #1a1545;
  --color-bg-card2: #231a60;
  --color-text: #f0eeff;
  --color-text-muted: #a89ccc;
  --color-correct: #22c55e;
  --color-wrong: #ef4444;
  --color-gold: #fbbf24;
  --color-silver: #9ca3af;
  --color-bronze: #b45309;
  --color-host: #f59e0b;
  --radius: 12px;
  --radius-lg: 20px;
  --shadow: 0 4px 24px rgba(74, 47, 189, 0.3);
  --transition: 0.2s ease;
  --font-body: 'Segoe UI', system-ui, sans-serif;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ---- Typography ---- */
h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.5px; }
h2 { font-size: 1.5rem; font-weight: 700; }
h3 { font-size: 1.2rem; font-weight: 600; }
p  { font-size: 1rem; }

/* ---- Layout Utilities ---- */
.container {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
}

.card {
  background: var(--color-bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.gap-24 { gap: 24px; }
.text-center { text-align: center; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-body);
  cursor: pointer;
  transition: transform var(--transition), opacity var(--transition), box-shadow var(--transition);
  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: linear-gradient(135deg, var(--color-primary-light), var(--color-primary));
  color: #fff;
  box-shadow: 0 4px 16px rgba(74, 47, 189, 0.45);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 24px rgba(74, 47, 189, 0.6);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--color-bg-card2);
  color: var(--color-text);
  border: 2px solid var(--color-primary-light);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--color-primary-light);
}

.btn-lg {
  min-height: 56px;
  font-size: 1.15rem;
  padding: 14px 36px;
  border-radius: var(--radius-lg);
}

.btn-full { width: 100%; }

/* ---- Forms ---- */
.form-group { display: flex; flex-direction: column; gap: 8px; }

label {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"] {
  height: 52px;
  padding: 0 16px;
  background: var(--color-bg-card2);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 1.1rem;
  font-family: var(--font-body);
  transition: border-color var(--transition);
  outline: none;
}

input[type="text"]:focus {
  border-color: var(--color-primary-light);
}

input[type="text"].error {
  border-color: var(--color-wrong);
}

.form-error {
  font-size: 0.9rem;
  color: var(--color-wrong);
  min-height: 1.2em;
}

/* ---- Page Header ---- */
.page-header {
  text-align: center;
  padding: 32px 16px 16px;
}

.page-header .logo {
  font-size: 2.4rem;
  font-weight: 900;
  background: linear-gradient(135deg, #a78bfa, #60a5fa, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.page-header .tagline {
  color: var(--color-text-muted);
  font-size: 1rem;
  margin-top: 4px;
}

/* ---- Leaderboard (index.html) ---- */
.leaderboard-section { padding: 24px 0 48px; }

.leaderboard-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 400px;
}

.leaderboard-table th {
  background: var(--color-bg-card2);
  color: var(--color-text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 12px 14px;
  text-align: left;
}

.leaderboard-table td {
  padding: 12px 14px;
  font-size: 0.95rem;
  border-top: 1px solid rgba(255,255,255,0.05);
}

.leaderboard-table tr:hover td { background: rgba(255,255,255,0.03); }

.rank-cell { width: 48px; text-align: center; font-weight: 700; }
.rank-1 .rank-cell { color: var(--color-gold); font-size: 1.1rem; }
.rank-2 .rank-cell { color: var(--color-silver); }
.rank-3 .rank-cell { color: var(--color-bronze); }

.name-cell { font-weight: 600; font-size: 1rem; }
.score-cell { font-weight: 700; color: var(--color-primary-light); }

/* ---- Join Section (index.html) ---- */
.join-section {
  padding: 16px 0 32px;
}

/* ---- Game page base ---- */
#game-app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- View system ---- */
.view {
  display: none;
  flex: 1;
  flex-direction: column;
}
.view.active { display: flex; }

/* ---- Lobby View ---- */
#view-lobby {
  padding: 16px;
  gap: 20px;
}

.lobby-header {
  text-align: center;
  padding: 16px 0 8px;
}

.lobby-header h2 { font-size: 1.8rem; }
.lobby-header .sub { color: var(--color-text-muted); font-size: 0.95rem; margin-top: 4px; }

.lobby-players {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lobby-player-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--color-bg-card2);
  border-radius: var(--radius);
  padding: 12px 16px;
  transition: background var(--transition);
}

.player-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
  flex-shrink: 0;
  color: #fff;
}

.player-name-text { font-weight: 600; font-size: 1rem; flex: 1; }

.host-badge {
  background: var(--color-host);
  color: #000;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0.05em;
}

.you-badge {
  background: var(--color-primary-light);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
}

.lobby-waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--color-text-muted);
  font-size: 0.95rem;
  padding: 8px 0;
}

.dots-anim span {
  display: inline-block;
  animation: bounce-dot 1.2s infinite;
  font-size: 1.4rem;
}
.dots-anim span:nth-child(2) { animation-delay: 0.2s; }
.dots-anim span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-8px); opacity: 1; }
}

.player-count-display {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* ---- Countdown View ---- */
#view-countdown {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #2d1b69 0%, var(--color-bg) 70%);
}

.countdown-inner {
  text-align: center;
}

.countdown-number {
  font-size: 9rem;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(135deg, #a78bfa, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: pop-in 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.countdown-go {
  font-size: 5rem;
  font-weight: 900;
  color: var(--color-correct);
  animation: pop-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.countdown-label {
  font-size: 1.2rem;
  color: var(--color-text-muted);
  margin-top: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

@keyframes pop-in {
  0%   { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}

/* ---- Playing View ---- */
#view-playing {
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.playing-top {
  background: var(--color-bg-card);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-shrink: 0;
}

.q-progress {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.timer-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.timer-bar-bg {
  flex: 1;
  height: 10px;
  background: rgba(255,255,255,0.1);
  border-radius: 999px;
  overflow: hidden;
}

.timer-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--color-correct), #86efac);
  transition: width 1s linear, background 0.5s;
}

.timer-bar-fill.urgent { background: linear-gradient(90deg, var(--color-wrong), #fca5a5); }

.timer-text {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
  min-width: 28px;
  text-align: right;
}

.timer-text.urgent { color: var(--color-wrong); }

.score-display {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-gold);
  white-space: nowrap;
}

.playing-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.question-meta {
  display: flex;
  gap: 8px;
  align-items: center;
}

.category-badge {
  background: var(--color-primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: 0.05em;
}

.difficulty-badge {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
}

.difficulty-badge.easy   { background: #14532d; color: #86efac; }
.difficulty-badge.medium { background: #713f12; color: #fde68a; }
.difficulty-badge.hard   { background: #7f1d1d; color: #fca5a5; }

.question-text {
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.4;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.option-btn {
  min-height: 64px;
  padding: 14px 12px;
  background: var(--color-bg-card2);
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  text-align: left;
  transition: border-color var(--transition), background var(--transition), transform 0.1s;
  word-break: break-word;
  display: flex;
  align-items: center;
  gap: 8px;
}

.option-btn:hover:not(:disabled) {
  border-color: var(--color-primary-light);
  background: rgba(123, 94, 240, 0.15);
  transform: scale(1.02);
}

.option-btn:active:not(:disabled) { transform: scale(0.98); }

.option-btn.selected {
  border-color: var(--color-primary-light);
  background: rgba(123, 94, 240, 0.25);
}

.option-btn.correct {
  border-color: var(--color-correct);
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
}

.option-btn.wrong {
  border-color: var(--color-wrong);
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.option-btn:disabled { cursor: not-allowed; }

.option-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ---- Round Scores Overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 41, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.overlay.hidden { display: none; }

.overlay-card {
  background: var(--color-bg-card);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.overlay-title {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
}

.answer-feedback {
  text-align: center;
  margin-bottom: 16px;
  padding: 16px;
  border-radius: var(--radius);
}

.answer-feedback.correct { background: rgba(34, 197, 94, 0.15); border: 1px solid var(--color-correct); }
.answer-feedback.wrong   { background: rgba(239, 68, 68, 0.15); border: 1px solid var(--color-wrong); }

.answer-feedback .feedback-icon { font-size: 2.5rem; }
.answer-feedback .feedback-text { font-size: 1.1rem; font-weight: 700; margin-top: 4px; }
.answer-feedback .points-text { font-size: 0.9rem; color: var(--color-text-muted); margin-top: 4px; }

.scores-list { display: flex; flex-direction: column; gap: 8px; }

.score-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--color-bg-card2);
  border-radius: var(--radius);
}

.score-row.me { border: 1px solid var(--color-primary-light); }
.score-row.rank-1 { border: 1px solid var(--color-gold); }

.score-rank {
  font-weight: 800;
  font-size: 1rem;
  width: 28px;
  text-align: center;
}
.score-row.rank-1 .score-rank { color: var(--color-gold); }

.score-player-name { flex: 1; font-weight: 600; font-size: 0.95rem; }
.score-round-pts {
  font-size: 0.85rem;
  color: var(--color-correct);
  font-weight: 600;
  min-width: 60px;
  text-align: right;
}
.score-total {
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-primary-light);
  min-width: 60px;
  text-align: right;
}

.next-question-bar {
  margin-top: 16px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* ---- Results View ---- */
#view-results {
  padding: 16px;
  gap: 20px;
  overflow-y: auto;
}

.results-header { text-align: center; padding: 16px 0 8px; }
.results-header h2 { font-size: 2rem; }

.winner-banner {
  background: linear-gradient(135deg, #78350f, #92400e);
  border: 2px solid var(--color-gold);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.winner-crown { font-size: 2.5rem; }
.winner-name  { font-size: 1.5rem; font-weight: 800; color: var(--color-gold); margin-top: 4px; }
.winner-score { font-size: 1rem; color: #fde68a; margin-top: 4px; }

/* Confetti */
.confetti-container {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 100vh;
  pointer-events: none;
  overflow: hidden;
  z-index: 200;
}

.confetti-piece {
  position: absolute;
  top: -10px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  0%   { transform: translateY(0) rotate(0deg); opacity: 1; }
  100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

.results-list { display: flex; flex-direction: column; gap: 10px; }

.result-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--color-bg-card2);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.result-row.rank-1 { background: rgba(251, 191, 36, 0.1); border: 1px solid var(--color-gold); }
.result-row.rank-2 { border: 1px solid rgba(156, 163, 175, 0.4); }
.result-row.rank-3 { border: 1px solid rgba(180, 83, 9, 0.4); }
.result-row.me     { border-color: var(--color-primary-light); }

.result-rank {
  font-weight: 800;
  font-size: 1.2rem;
  width: 32px;
  text-align: center;
}

.result-row.rank-1 .result-rank { color: var(--color-gold); }
.result-row.rank-2 .result-rank { color: var(--color-silver); }
.result-row.rank-3 .result-rank { color: var(--color-bronze); }

.result-info { flex: 1; }
.result-name  { font-weight: 700; font-size: 1rem; }
.result-stats { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 2px; }

.result-score { font-size: 1.2rem; font-weight: 800; color: var(--color-primary-light); }

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 32px;
}

/* ---- Connection Lost Overlay ---- */
#overlay-connection {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 41, 0.97);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 500;
  text-align: center;
  padding: 24px;
}

#overlay-connection.hidden { display: none; }

#overlay-connection .conn-icon { font-size: 3rem; }
#overlay-connection h3 { font-size: 1.4rem; }
#overlay-connection p  { color: var(--color-text-muted); }

/* ---- Toast / Error notification ---- */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--color-bg-card);
  border: 1px solid var(--color-wrong);
  color: var(--color-text);
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in 0.3s ease, toast-out 0.4s ease 2.6s forwards;
  max-width: 320px;
  text-align: center;
  pointer-events: auto;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* ---- Loading spinner ---- */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--color-primary-light);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---- Responsive: tablet/desktop ---- */
@media (min-width: 640px) {
  .page-header .logo { font-size: 3rem; }
  h1 { font-size: 2.4rem; }
  .question-text { font-size: 1.4rem; }
  .options-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .option-btn { min-height: 72px; font-size: 1.05rem; }
  .playing-body { padding: 24px; }
  #view-lobby, #view-results { padding: 24px; max-width: 600px; margin: 0 auto; width: 100%; }
}

@media (min-width: 1024px) {
  #view-playing {
    flex-direction: row;
    align-items: stretch;
  }
  .playing-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .playing-sidebar {
    width: 220px;
    background: var(--color-bg-card);
    border-left: 1px solid rgba(255,255,255,0.07);
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
  }
  .playing-sidebar h4 {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--color-text-muted);
    margin-bottom: 4px;
  }
  .playing-top { grid-column: 1 / -1; }
}

/* ---- Avatar palette ---- */
.av-0  { background: #7c3aed; }
.av-1  { background: #db2777; }
.av-2  { background: #0891b2; }
.av-3  { background: #059669; }
.av-4  { background: #d97706; }
.av-5  { background: #dc2626; }
.av-6  { background: #7c3aed; }
.av-7  { background: #4338ca; }

/* ---- Utility animations ---- */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fade-in 0.3s ease forwards; }

/* ---- Streak indicator ---- */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--color-secondary);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
