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

:root {
  --bg: #0d0d1a;
  --card: #15152a;
  --border: #2a2a4a;
  --accent: #7c3aed;
  --accent2: #10b981;
  --text: #e2e8f0;
  --muted: #64748b;
  --radius: 14px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; overflow: hidden; }

.screen { display: none; position: fixed; inset: 0; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem; overflow-y: auto; }
.screen.active { display: flex; }

/* ── Lobby ── */
.logo { font-size: 2.6rem; font-weight: 900; letter-spacing: -1px; text-align: center; }
.logo span { color: var(--accent2); }
.tagline { color: var(--muted); margin: .3rem 0 2rem; text-align: center; font-size: .95rem; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; width: 100%; max-width: 380px; }

.btn-login-link {
  background: none; border: none; color: var(--muted); font-size: .8rem;
  cursor: pointer; font-family: inherit; margin-top: 1.25rem;
  text-decoration: underline; text-underline-offset: 3px;
}
.btn-login-link:hover { color: var(--text); }

input[type=text], input[type=password] {
  width: 100%; padding: .75rem 1rem;
  background: #0d0d1a; border: 1.5px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 1rem;
  font-family: inherit; margin-bottom: .75rem;
}
input:focus { outline: none; border-color: var(--accent); }
input::placeholder { color: var(--muted); }

.btn { display: block; width: 100%; padding: .8rem; border: none; border-radius: 8px; font-size: 1rem; font-weight: 700; cursor: pointer; transition: opacity .15s, transform .1s; font-family: inherit; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: transparent; border: 1.5px solid var(--border); color: var(--text); margin-top: .5rem; }
.btn-green { background: var(--accent2); color: #0d0d1a; }
.btn-green:disabled { opacity: .4; cursor: not-allowed; }
.btn-ready { background: #1e293b; border: 2px solid var(--muted); color: var(--text); }
.btn-ready.is-ready { background: #0d2f25; border-color: var(--accent2); color: var(--accent2); }
.btn:hover { opacity: .88; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.divider { text-align: center; color: var(--muted); font-size: .85rem; margin: .8rem 0; }

.error-box { background: #450a0a; border: 1px solid #7f1d1d; color: #fca5a5; border-radius: 8px; padding: .65rem 1rem; font-size: .88rem; margin-bottom: .75rem; display: none; }
.error-box.show { display: block; }

/* ── Question Builder ── */
#screen-questions { justify-content: flex-start; padding-top: 1.25rem; padding-bottom: 1.5rem; }

.qb-wrap { width: 100%; max-width: 460px; }

.qb-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1rem; }
.qb-title { font-size: 1.4rem; font-weight: 900; }
.qb-sub { color: var(--muted); font-size: .82rem; margin-top: .15rem; }

.btn-logout { background: none; border: 1px solid var(--border); border-radius: 6px; color: var(--muted); font-size: .78rem; cursor: pointer; padding: .3rem .65rem; font-family: inherit; white-space: nowrap; }
.btn-logout:hover { color: var(--text); border-color: var(--muted); }

.qb-toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .75rem; }
.btn-outline { padding: .42rem .85rem; border: 1.5px solid var(--border); border-radius: 7px; background: transparent; color: var(--text); font-size: .82rem; font-weight: 600; cursor: pointer; font-family: inherit; transition: opacity .15s, border-color .15s; }
.btn-outline:hover { opacity: .85; border-color: var(--muted); }
.btn-outline-green { border-color: var(--accent2); color: var(--accent2); }

.qb-empty { text-align: center; color: var(--muted); font-size: .85rem; padding: 1.25rem 1rem; background: var(--card); border: 1px dashed var(--border); border-radius: 10px; margin-bottom: .75rem; }

.qb-q-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: .7rem .9rem; margin-bottom: .5rem; }
.qb-q-top { display: flex; align-items: flex-start; gap: .6rem; }
.qb-q-num { font-size: .68rem; font-weight: 700; color: var(--muted); background: var(--border); border-radius: 4px; padding: .15rem .4rem; flex-shrink: 0; margin-top: .18rem; }
.qb-q-text { flex: 1; font-size: .88rem; font-weight: 600; line-height: 1.4; }
.qb-q-delete { background: none; border: none; color: var(--muted); font-size: 1.25rem; cursor: pointer; padding: 0 .2rem; line-height: 1; flex-shrink: 0; }
.qb-q-delete:hover { color: #ef4444; }
.qb-q-answer { font-size: .77rem; color: var(--muted); margin-top: .4rem; }
.qb-ans-tag { font-weight: 700; padding: .1rem .4rem; border-radius: 4px; font-size: .77rem; }
.qb-tag-red    { background: rgba(226,27,60,.22);  color: #f87171; }
.qb-tag-blue   { background: rgba(19,104,206,.22); color: #60a5fa; }
.qb-tag-yellow { background: rgba(216,158,0,.22);  color: #fbbf24; }
.qb-tag-green  { background: rgba(38,137,12,.22);  color: #4ade80; }

.qb-form-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.1rem; margin-bottom: .75rem; }
.qb-form-title { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: .75rem; }

#qb-q-text { margin-bottom: .5rem; }

.qb-opts { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .75rem; }
.qb-opt-row { display: flex; align-items: center; gap: .5rem; padding: .35rem .6rem; border-radius: 7px; }
.qb-opt-row[data-color=red]    { background: rgba(226,27,60,.12); }
.qb-opt-row[data-color=blue]   { background: rgba(19,104,206,.12); }
.qb-opt-row[data-color=yellow] { background: rgba(216,158,0,.12); }
.qb-opt-row[data-color=green]  { background: rgba(38,137,12,.12); }
.qb-shape { font-size: .95rem; width: 20px; text-align: center; flex-shrink: 0; }
.qb-opt-row input {
  flex: 1; background: transparent; border: none;
  border-bottom: 1px solid var(--border); border-radius: 0;
  padding: .25rem .15rem; margin: 0; color: var(--text);
  font-size: .88rem; font-family: inherit;
}
.qb-opt-row input:focus { outline: none; border-bottom-color: var(--accent); }
.qb-opt-row input::placeholder { color: var(--muted); }

.qb-correct-label { font-size: .78rem; color: var(--muted); margin-bottom: .4rem; }
.qb-ans-btns { display: flex; gap: .4rem; flex-wrap: wrap; }
.qb-ans-btn {
  padding: .38rem .65rem; border: 2px solid transparent;
  border-radius: 7px; font-size: .8rem; font-weight: 700;
  cursor: pointer; font-family: inherit; transition: all .15s;
}
.qb-ans-btn.qb-ans-red    { background: rgba(226,27,60,.2); color: #f87171; }
.qb-ans-btn.qb-ans-blue   { background: rgba(19,104,206,.2); color: #60a5fa; }
.qb-ans-btn.qb-ans-yellow { background: rgba(216,158,0,.2); color: #fbbf24; }
.qb-ans-btn.qb-ans-green  { background: rgba(38,137,12,.2); color: #4ade80; }
.qb-ans-btn.selected { border-color: currentColor; }
.qb-ans-btn:hover { opacity: .85; }

.qb-actions { display: flex; flex-direction: column; gap: .5rem; }

/* ── Waiting Room ── */
.waiting-wrap { width: 100%; max-width: 420px; }
.room-code-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem 1.5rem; text-align: center; margin-bottom: 1rem; }
.room-code-label { font-size: .75rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.room-code { font-size: 2.8rem; font-weight: 900; letter-spacing: 8px; color: var(--accent2); line-height: 1; margin: .2rem 0; }
.room-code-hint { font-size: .78rem; color: var(--muted); }

.section-label { font-size: .75rem; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin-bottom: .6rem; }
.player-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.player-chip { display: flex; align-items: center; gap: .6rem; padding: .55rem .8rem; background: var(--card); border: 1px solid var(--border); border-radius: 8px; font-size: .9rem; }
.player-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.player-chip .crown { margin-left: auto; font-size: .8rem; }

/* ── Countdown ── */
#screen-countdown { gap: .5rem; }
.countdown-num { font-size: 8rem; font-weight: 900; color: var(--accent2); animation: pop .4s ease; line-height: 1; }
.countdown-sub { color: var(--muted); font-size: 1rem; }
@keyframes pop { from { transform: scale(1.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ── Question Screen ── */
#screen-question { padding: 0; justify-content: flex-start; align-items: stretch; }

.q-header {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem; background: var(--card);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.q-num-label { font-size: .8rem; font-weight: 700; color: var(--muted); white-space: nowrap; }
.q-timer-wrap { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.q-timer-bar { height: 100%; width: 100%; background: var(--accent2); border-radius: 4px; }
.q-time-num { font-size: 1.1rem; font-weight: 900; width: 28px; text-align: right; font-variant-numeric: tabular-nums; transition: color .3s; }

.q-body { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1.25rem 1.5rem; min-height: 80px; }
.q-text { font-size: 1.25rem; font-weight: 700; text-align: center; line-height: 1.4; }

.q-answered-bar {
  text-align: center; font-size: .85rem; color: var(--muted);
  padding: .4rem 1rem; flex-shrink: 0; min-height: 30px;
  transition: color .2s;
}
.q-answered-bar.reveal-correct { color: #4ade80; font-weight: 700; }
.q-answered-bar.reveal-wrong   { color: #f87171; font-weight: 700; }

.q-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  flex-shrink: 0; min-height: 220px;
}
.q-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: .35rem; padding: .75rem .5rem;
  border: none; cursor: pointer; font-family: inherit;
  font-weight: 700; font-size: .85rem; color: #fff;
  transition: filter .2s, box-shadow .2s, opacity .2s;
  text-align: center; line-height: 1.3;
}
.q-btn:active { filter: brightness(.85); }
.q-shape { font-size: 1.4rem; line-height: 1; }
.q-answer-text { max-width: 130px; }

.q-red    { background: #e21b3c; }
.q-blue   { background: #1368ce; }
.q-yellow { background: #d89e00; }
.q-green  { background: #26890c; }

.q-btn.q-selected   { box-shadow: inset 0 0 0 4px rgba(255,255,255,.8); }
.q-btn.q-dimmed     { opacity: .45; }
.q-btn.q-correct    { box-shadow: inset 0 0 0 4px #fff; filter: brightness(1.15); }
.q-btn.q-wrong      { filter: brightness(.45) saturate(.3); }
.q-btn.q-dim-reveal { filter: brightness(.35); }
.q-btn:disabled     { cursor: default; }

/* ── Scores ── */
#screen-scores { padding: 1rem; }
.scores-wrap { width: 100%; max-width: 420px; }
.scores-title { font-size: 1.6rem; font-weight: 900; text-align: center; color: var(--accent2); }
.scores-sub { text-align: center; color: var(--muted); font-size: .85rem; margin: .3rem 0 1rem; }
.scores-list { display: flex; flex-direction: column; gap: .5rem; }

.score-row { display: flex; align-items: center; gap: .75rem; padding: .7rem 1rem; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
.score-row.me { border-color: var(--accent2); background: #0d2f25; }
.score-rank { font-size: 1.1rem; font-weight: 900; width: 28px; text-align: center; }
.score-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.score-name { flex: 1; font-weight: 600; font-size: .95rem; }
.score-pts { font-size: .9rem; font-weight: 700; color: var(--accent2); font-variant-numeric: tabular-nums; }

/* ── Results ── */
.results-wrap { width: 100%; max-width: 400px; }
.results-title { font-size: 1.8rem; font-weight: 900; text-align: center; margin-bottom: 1.2rem; }
.results-list { display: flex; flex-direction: column; gap: .55rem; margin-bottom: .5rem; }

.result-row { display: flex; align-items: center; gap: .8rem; padding: .75rem 1rem; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
.result-row.first { border-color: #fbbf24; background: #1a1408; }
.result-row.me { border-color: var(--accent2); }
.result-rank { font-size: 1.2rem; font-weight: 900; width: 28px; text-align: center; }
.result-dot { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.result-name { flex: 1; font-weight: 600; }
.result-score { font-size: .9rem; font-weight: 700; color: var(--accent2); font-variant-numeric: tabular-nums; }
