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

:root {
  --bg:        #0d0d0d;
  --surface:   #1a1a2e;
  --surface2:  #16213e;
  --accent:    #0f3460;
  --blue:      #0095d9;
  --green:     #57f287;
  --red:       #ed4245;
  --gold:      #f1c40f;
  --text:      #e0e0e0;
  --muted:     #888;
  --radius:    12px;
  font-size: clamp(16px, 0.85vw, 30px);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.screen { display: none; width: 100%; max-width: clamp(900px, 45vw, 1600px); padding: clamp(32px, 1.67vw, 60px) clamp(16px, 0.83vw, 30px); }
.screen.active { display: flex; flex-direction: column; gap: clamp(24px, 1.25vw, 44px); }

/* ── Header ── */
.app-header {
  width: 100%;
  max-width: clamp(900px, 45vw, 1600px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(16px, 0.83vw, 30px);
  border-bottom: 1px solid #222;
}
.app-header h1 { font-size: 1.25rem; color: var(--text); letter-spacing: 2px; text-transform: uppercase; }

/* ── User menu dropdown ── */
.user-menu { position: relative; }

.user-menu-btn {
  background: none;
  border: 1px solid #333;
  border-radius: 20px;
  color: var(--text);
  font-size: 0.85rem;
  padding: clamp(6px, 0.31vw, 11px) clamp(14px, 0.73vw, 26px);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.user-menu-btn:hover,
.user-menu-btn.open { border-color: var(--blue); color: var(--text); }

.user-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--surface);
  border: 1px solid #333;
  border-radius: var(--radius);
  min-width: clamp(180px, 9.4vw, 320px);
  overflow: hidden;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.user-dropdown.open { display: block; }

.dropdown-item {
  display: block;
  width: 100%;
  padding: clamp(11px, 0.57vw, 20px) clamp(16px, 0.83vw, 30px);
  background: none;
  border: none;
  border-radius: 0;
  color: var(--text);
  font-size: 0.9rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.1s;
}
.dropdown-item:hover { background: var(--accent); }
.dropdown-item.hidden { display: none; }

/* ── Help modal ── */
.help-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.help-modal.open { display: flex; }

.help-box {
  background: var(--surface);
  border: 1px solid #333;
  border-radius: var(--radius);
  width: 90%;
  max-width: clamp(460px, 24vw, 820px);
  overflow: hidden;
}
.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(16px, 0.83vw, 30px) clamp(20px, 1.04vw, 36px);
  border-bottom: 1px solid #222;
}
.help-header h3 { font-size: 1rem; }
.help-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.help-close:hover { color: var(--text); }
.help-body { padding: clamp(20px, 1.04vw, 36px); display: flex; flex-direction: column; gap: clamp(12px, 0.63vw, 22px); }
.help-body p { font-size: 0.9rem; line-height: 1.6; color: var(--text); }
.help-note { color: var(--muted); font-size: 0.82rem; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: clamp(24px, 1.25vw, 44px);
  border: 1px solid #222;
}

/* ── Buttons ── */
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: clamp(12px, 0.63vw, 22px) clamp(24px, 1.25vw, 44px);
  font-size: 1rem;
  font-weight: 600;
  transition: opacity 0.15s;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
button:not(:disabled):hover { opacity: 0.85; }

.btn-primary  { background: var(--blue);  color: #fff; }
.btn-success  { background: var(--green); color: #000; }
.btn-danger   { background: var(--red);   color: #fff; }
.btn-ghost    { background: #333;         color: var(--text); }
.btn-large    { padding: clamp(16px, 0.83vw, 28px) clamp(40px, 2.08vw, 72px); font-size: 1.2rem; border-radius: 10px; }

/* ── Form ── */
label { font-size: 0.85rem; color: var(--muted); display: block; margin-bottom: 6px; }
select, input[type="number"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid #333;
  border-radius: 8px;
  padding: clamp(10px, 0.52vw, 18px) clamp(14px, 0.73vw, 26px);
  color: var(--text);
  font-size: 1rem;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-row   { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(16px, 0.83vw, 30px); }

/* ── Setup screen ── */
#screen-setup h2 { font-size: 1.5rem; }
#screen-setup p  { color: var(--muted); font-size: 0.95rem; }

/* ── Lobby screen ── */
.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(24px, 1.25vw, 44px);
}
.join-code {
  font-size: 5rem;
  font-weight: 900;
  letter-spacing: 12px;
  color: var(--blue);
  text-align: center;
  line-height: 1;
}
.join-url  { font-size: 0.85rem; color: var(--muted); text-align: center; word-break: break-all; }
.qr-wrap   { display: flex; justify-content: center; }
.qr-wrap img { width: clamp(160px, 8.33vw, 280px); height: clamp(160px, 8.33vw, 280px); border-radius: 8px; background: #fff; padding: 8px; }

.player-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: clamp(12px, 0.63vw, 22px);
}
.player-list-header h3 { font-size: 1rem; }
.player-count { font-size: 0.85rem; color: var(--muted); }
.player-list  { display: flex; flex-wrap: wrap; gap: 8px; min-height: 80px; }
.player-chip  {
  background: var(--accent);
  border-radius: 20px;
  padding: clamp(6px, 0.31vw, 11px) clamp(16px, 0.83vw, 30px);
  font-size: 0.9rem;
}
.lobby-warn   { color: var(--gold); font-size: 0.85rem; margin-top: 12px; display: none; }
.lobby-actions { display: flex; gap: clamp(12px, 0.63vw, 22px); justify-content: flex-end; }

/* ── Question screen ── */
.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  color: var(--muted);
}
.timer-bar-wrap { background: #222; border-radius: 4px; height: clamp(6px, 0.31vw, 10px); overflow: hidden; }
.timer-bar      { height: 100%; background: var(--blue); transition: width 0.5s linear; border-radius: 4px; }
.question-text  { font-size: 1.6rem; font-weight: 700; line-height: 1.4; }
.options-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(12px, 0.63vw, 22px); }
.option-card    {
  background: var(--surface2);
  border: 2px solid #333;
  border-radius: var(--radius);
  padding: clamp(20px, 1.04vw, 36px);
  display: flex;
  align-items: center;
  gap: clamp(12px, 0.63vw, 22px);
  font-size: 1rem;
}
.option-letter  {
  width: clamp(36px, 1.875vw, 64px); height: clamp(36px, 1.875vw, 64px);
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}
.progress-wrap  { display: flex; align-items: center; gap: clamp(12px, 0.63vw, 22px); color: var(--muted); font-size: 0.9rem; }
.progress-bar-wrap { flex: 1; background: #222; border-radius: 4px; height: clamp(8px, 0.42vw, 14px); overflow: hidden; }
.progress-bar   { height: 100%; background: var(--green); transition: width 0.3s ease; border-radius: 4px; }

/* ── Reveal screen ── */
.option-card.correct { border-color: var(--green); background: rgba(87,242,135,0.1); }
.option-card.wrong   { border-color: var(--red);   opacity: 0.4; }
.winner-banner {
  text-align: center;
  padding: clamp(20px, 1.04vw, 36px);
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--gold);
}
.winner-banner .winner-name  { font-size: 1.6rem; font-weight: 700; color: var(--gold); }
.winner-banner .winner-label { font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.no-winner { text-align: center; color: var(--muted); font-size: 1rem; padding: clamp(16px, 0.83vw, 30px); }
.reveal-actions { display: flex; gap: clamp(12px, 0.63vw, 22px); justify-content: flex-end; }

/* ── Leaderboard screen ── */
.leaderboard-list { display: flex; flex-direction: column; gap: clamp(8px, 0.42vw, 14px); }
.leaderboard-row  {
  display: flex;
  align-items: center;
  gap: clamp(16px, 0.83vw, 30px);
  background: var(--surface2);
  border-radius: 8px;
  padding: clamp(12px, 0.63vw, 22px) clamp(16px, 0.83vw, 30px);
}
.lb-rank   { width: clamp(28px, 1.46vw, 50px); font-weight: 700; color: var(--muted); text-align: center; flex-shrink: 0; }
.lb-rank.gold   { color: var(--gold); }
.lb-rank.silver { color: #aaa; }
.lb-rank.bronze { color: #cd7f32; }
.lb-name   { flex: 1; font-weight: 600; }
.lb-score  { font-size: 1.1rem; font-weight: 700; color: var(--blue); }

/* ── Final screen ── */
.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(8px, 0.42vw, 14px);
  padding: clamp(24px, 1.25vw, 44px) 0;
}
.podium-place {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 0.42vw, 14px);
}
.podium-name   { font-size: 0.9rem; font-weight: 700; text-align: center; max-width: clamp(100px, 5.2vw, 180px); word-break: break-word; }
.podium-score  { font-size: 0.8rem; color: var(--muted); }
.podium-block  {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 900;
  border-radius: 8px 8px 0 0;
  width: clamp(80px, 4.17vw, 140px);
}
.podium-place.first  .podium-block { background: var(--gold);    color: #000; height: clamp(100px, 5.2vw, 180px); }
.podium-place.second .podium-block { background: #aaa;           color: #000; height: clamp(70px, 3.65vw, 126px); }
.podium-place.third  .podium-block { background: #cd7f32;        color: #000; height: clamp(50px, 2.6vw, 90px); }
.final-actions { display: flex; gap: clamp(12px, 0.63vw, 22px); justify-content: center; }

/* ── Connection banner ── */
.conn-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--red);
  color: #fff;
  text-align: center;
  padding: clamp(10px, 0.52vw, 18px);
  font-size: 0.9rem;
  display: none;
  z-index: 100;
}
.conn-banner.visible { display: block; }

/* ── Option letter colors ── */
.option-letter[data-letter="A"] { background: #e74c3c; }
.option-letter[data-letter="B"] { background: #3498db; }
.option-letter[data-letter="C"] { background: #2ecc71; }
.option-letter[data-letter="D"] { background: #f39c12; }

/* ── Empty state ── */
.empty-state { color: var(--muted); text-align: center; }

/* ── Initial hidden elements ── */
#setup-fields { display: none; }
#rejoin-card  { display: none; }

/* ── Setup form layout ── */
#bank-info      { margin-top: 12px; color: var(--muted); font-size: 0.85rem; }
#setup-error    { margin-top: 12px; color: var(--red); font-size: 0.9rem; display: none; }
.setup-submit   { margin-top: 20px; display: flex; justify-content: flex-end; }
.rejoin-actions { margin-top: 12px; display: flex; gap: 12px; }

/* ── Lobby layout ── */
.lobby-code-col   { display: flex; flex-direction: column; gap: 16px; align-items: center; justify-content: center; }
.lobby-code-label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 2px; }

/* ── Timer bar top margin ── */
.timer-bar-wrap-mt { margin-top: 10px; }

/* ── Leaderboard / between-round layout ── */
.lb-section-header { margin-bottom: 16px; }
.lb-next-actions   { display: flex; justify-content: flex-end; }

/* ── Final screen layout ── */
.card-center      { text-align: center; }
.game-over-title  { font-size: 2rem; margin-bottom: 4px; }
.final-subtitle   { color: var(--muted); }
.rankings-header  { margin-bottom: 12px; }
.alltime-header   { display: flex; justify-content: space-between; align-items: center; }

/* ── Loading spinner ── */
.spinner {
  width: clamp(32px, 1.67vw, 56px); height: clamp(32px, 1.67vw, 56px);
  border: 3px solid #333;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
