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

:root {
  /* Surfaces */
  --bg:        #f4f6f9;
  --surface:   #ffffff;
  --surface-2: #f0f3f7;
  --border:    #e2e8f0;

  /* Text */
  --text:      #111827;
  --muted:     #6b7280;

  /* Accent */
  --accent:       #6366f1;
  --accent-light: #eef2ff;
  --accent-dark:  #4f46e5;

  /* Status */
  --success:        #059669;
  --success-light:  #d1fae5;
  --success-border: #6ee7b7;
  --danger:         #dc2626;
  --danger-light:   #fee2e2;
  --danger-border:  #fca5a5;
  --warning:        #d97706;
  --warning-light:  #fef3c7;

  /* Option palette: color + light tint */
  --c0: #6366f1; --l0: #eef2ff;   /* indigo  */
  --c1: #0ea5e9; --l1: #e0f2fe;   /* sky     */
  --c2: #f59e0b; --l2: #fef3c7;   /* amber   */
  --c3: #10b981; --l3: #d1fae5;   /* emerald */
  --c4: #f43f5e; --l4: #ffe4e6;   /* rose    */
  --c5: #8b5cf6; --l5: #f5f3ff;   /* violet  */

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.1);

  --radius:    14px;
  --radius-sm: 10px;
}

/* Per-option CSS custom property injection */
.opt-0 { --opt-c: var(--c0); --opt-l: var(--l0); }
.opt-1 { --opt-c: var(--c1); --opt-l: var(--l1); }
.opt-2 { --opt-c: var(--c2); --opt-l: var(--l2); }
.opt-3 { --opt-c: var(--c3); --opt-l: var(--l3); }
.opt-4 { --opt-c: var(--c4); --opt-l: var(--l4); }
.opt-5 { --opt-c: var(--c5); --opt-l: var(--l5); }

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

/* ── Utility ──────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.muted  { color: var(--muted); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
}
.btn:hover:not(:disabled)  { opacity: 0.88; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary { background: var(--accent);   color: #fff; }
.btn-success { background: var(--success);  color: #fff; }
.btn-danger  { background: var(--danger);   color: #fff; }
.btn-warning { background: var(--warning);  color: #fff; }
.btn-neutral { background: var(--surface-2); color: var(--text); border: 1.5px solid var(--border); }
.btn-full    { width: 100%; }

/* ── Inputs ───────────────────────────────────────────────────────────────── */
input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 11px 15px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}
input::placeholder { color: var(--muted); }
select option { background: var(--surface); }
textarea {
  resize: vertical;
  min-height: 110px;
  font-family: 'Cascadia Code', 'Courier New', monospace;
  font-size: 0.82rem;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
  margin-top: 4px;
}

/* ── Timer bar (fixed top strip) ─────────────────────────────────────────── */
.timer-bar-container {
  width: 100%;
  height: 5px;
  background: var(--border);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
}

.timer-bar {
  height: 100%;
  background: var(--accent);
  transition: width 1s linear, background-color 0.4s;
}
.timer-bar.warn   { background: var(--warning); }
.timer-bar.danger { background: var(--danger); }

/* ── Join page ────────────────────────────────────────────────────────────── */
.join-page {
  align-items: center;
  justify-content: center;
}

.join-container {
  background: var(--surface);
  border-radius: 20px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  margin: auto;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.join-container h1 {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 6px;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.join-container > p {
  color: var(--muted);
  margin-bottom: 28px;
  font-size: 0.95rem;
}

.join-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-link { margin-top: 24px; }
.admin-link a {
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: none;
}
.admin-link a:hover { color: var(--accent); }

/* ── Admin layout ─────────────────────────────────────────────────────────── */
.admin-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100vh;
  background: var(--bg);
}

.admin-sidebar {
  background: var(--surface);
  padding: 24px 20px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--shadow-sm);
}

.admin-sidebar h2 {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.01em;
}

.admin-main {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

.panel h3 {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 14px;
}

.room-code-display {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-align: center;
  padding: 14px;
  background: var(--accent-light);
  border-radius: var(--radius-sm);
  border: 1.5px solid rgba(99,102,241,0.2);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.stat-row:last-child { border: none; }
.stat-value { font-size: 1.2rem; font-weight: 800; color: var(--accent); }

.control-buttons { display: flex; flex-direction: column; gap: 8px; }

.player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}

.player-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  border: 1px solid var(--border);
}
.player-score { font-weight: 700; color: var(--accent); }

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.lb-rank         { font-size: 1.1rem; font-weight: 900; width: 28px; text-align: center; color: var(--muted); }
.lb-rank.gold    { color: #d97706; }
.lb-rank.silver  { color: #9ca3af; }
.lb-rank.bronze  { color: #b45309; }
.lb-name         { flex: 1; font-weight: 600; }
.lb-score        { font-weight: 800; color: var(--accent); }

.upload-section { display: flex; flex-direction: column; gap: 8px; }

/* ── Player page ──────────────────────────────────────────────────────────── */
.player-page {
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  padding-top: 28px;
}

.status-screen {
  width: 100%;
  max-width: 560px;
  margin: auto;
  text-align: center;
}

.status-screen h2 {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 10px;
}

.waiting-dots::after {
  content: '';
  animation: dots 1.5s infinite;
}
@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
}

.player-name-badge {
  display: inline-block;
  background: var(--accent-light);
  color: var(--accent);
  border: 1.5px solid rgba(99,102,241,0.25);
  border-radius: 999px;
  padding: 5px 16px;
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 14px;
}

/* ── Question screen ──────────────────────────────────────────────────────── */
.question-screen {
  width: 100%;
  max-width: 640px;
  margin: auto;
  padding-top: 16px;
}

.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 10px;
}

.meta-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.q-progress-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

/* Score eye */
.eye-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 5px 7px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  transition: all 0.15s;
  line-height: 0;
}
.eye-btn:hover, .eye-btn.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}
.eye-btn svg { width: 16px; height: 16px; }

.score-reveal {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
}
.score-reveal .score-good  { color: var(--success); }
.score-reveal .score-pts   { color: var(--accent); }

.timer-number {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--accent);
  min-width: 2ch;
  text-align: right;
  transition: color 0.4s;
  font-variant-numeric: tabular-nums;
}
.timer-number.warn   { color: var(--warning); }
.timer-number.danger { color: var(--danger); animation: pulse 0.6s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

.question-text {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.5;
  margin-bottom: 20px;
  background: var(--surface);
  padding: 18px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  color: var(--text);
}

.multi-hint {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--warning);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.multi-hint::before { content: '☑'; font-size: 1rem; }

/* ── Option buttons (single column) ──────────────────────────────────────── */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  width: 100%;
  padding: 14px 18px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--opt-c, #e2e8f0);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.975rem;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
  line-height: 1.4;
}

.option-btn:hover:not(:disabled) {
  background: var(--opt-l, var(--surface-2));
  border-color: var(--opt-c, var(--accent));
  transform: translateX(4px);
  box-shadow: var(--shadow-md);
}

.option-btn:active:not(:disabled) { transform: translateX(2px); }
.option-btn:disabled { cursor: default; }

.option-btn.selected {
  background: var(--opt-l, var(--accent-light));
  border-color: var(--opt-c, var(--accent));
  box-shadow: 0 0 0 1px var(--opt-c, var(--accent)), var(--shadow-sm);
}

.option-btn.dimmed {
  opacity: 0.3;
  transform: none !important;
}

.option-btn.correct-answer {
  background: var(--success-light);
  border-color: var(--success-border);
  border-left-color: var(--success);
  box-shadow: 0 0 0 1px var(--success-border);
}

.option-btn.wrong-answer {
  background: var(--danger-light);
  border-color: var(--danger-border);
  border-left-color: var(--danger);
  opacity: 0.65;
}

.opt-letter {
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 7px;
  background: var(--opt-c, var(--muted));
  color: #fff;
  font-weight: 800;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.option-text { flex: 1; }

.option-check {
  font-size: 1rem;
  color: var(--success);
  flex-shrink: 0;
}

.option-vote {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
  flex-shrink: 0;
  white-space: nowrap;
}

.submit-row {
  margin-top: 14px;
  text-align: center;
}

/* ── Result feedback chip ─────────────────────────────────────────────────── */
.result-feedback {
  margin-top: 18px;
  padding: 16px 20px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}
.result-feedback .icon { font-size: 1.8rem; line-height: 1; }
.result-feedback h3    { font-size: 1.05rem; font-weight: 700; }
.result-feedback p     { font-size: 0.85rem; color: inherit; opacity: 0.8; margin-top: 2px; }

.result-feedback.correct {
  background: var(--success-light);
  border: 1.5px solid var(--success-border);
  color: var(--success);
}
.result-feedback.wrong {
  background: var(--danger-light);
  border: 1.5px solid var(--danger-border);
  color: var(--danger);
}

/* ── Leaderboard (shared) ─────────────────────────────────────────────────── */
.lb-list {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 auto;
}

/* ── Host (projector) page ────────────────────────────────────────────────── */
.host-page { padding: 0; }

.host-screen {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Lobby */
.host-lobby {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 48px;
  background: var(--bg);
}

.room-label {
  font-size: 1.1rem;
  color: var(--muted);
}

.room-code-big {
  font-size: 7rem;
  font-weight: 900;
  letter-spacing: 0.25em;
  line-height: 1;
  color: var(--accent);
}

.player-count {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--muted);
}

.host-player-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 860px;
}

.host-player-chip {
  background: var(--surface);
  border: 1.5px solid var(--border);
  padding: 7px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 1rem;
  box-shadow: var(--shadow-sm);
  animation: popIn 0.3s ease;
}
@keyframes popIn {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* Host question view */
.host-question-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 28px 48px 36px;
  background: var(--bg);
}

.host-question-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.host-q-progress {
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
}

.host-answered-badge {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.host-timer-big {
  font-size: 3.5rem;
  font-weight: 900;
  color: var(--accent);
  transition: color 0.4s;
  min-width: 2ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.host-timer-big.warn   { color: var(--warning); }
.host-timer-big.danger { color: var(--danger); animation: pulse 0.5s infinite; }

/* Inline timer bar (host) */
.host-timer-track {
  height: 6px;
  background: var(--border);
  border-radius: 6px;
  margin-bottom: 22px;
  overflow: hidden;
}
.host-timer-track .timer-bar { border-radius: 6px; }

.host-question-text {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1.35;
  margin-bottom: 28px;
  color: var(--text);
  background: var(--surface);
  padding: 20px 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

/* Host options — single column, larger */
.host-options-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.host-option {
  padding: 16px 22px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-left: 5px solid var(--opt-c, var(--accent));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  line-height: 1.35;
}

.host-option .opt-letter {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 8px;
  font-size: 1rem;
}

/* Host results view */
.host-results-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 28px 48px 36px;
  background: var(--bg);
}

.host-results-question {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 22px;
  padding: 14px 18px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.results-bars {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.result-bar-row {
  display: grid;
  grid-template-columns: 40px 1fr 54px;
  align-items: center;
  gap: 12px;
}

.result-bar-letter {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 900;
  color: #fff;
  flex-shrink: 0;
  /* background set via JS inline style */
}

/* Label + bar stacked vertically */
.result-bar-body {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.result-bar-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}

.result-bar-label .correct-tick {
  color: var(--success);
  margin-left: 5px;
  font-weight: 800;
}

.result-bar-track {
  background: var(--border);
  border-radius: 6px;
  height: 10px;
  overflow: hidden;
}

/* Fill is a plain colored bar — NO text inside */
.result-bar-fill {
  height: 100%;
  border-radius: 6px;
  width: 0%;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  /* background set via JS inline style */
}

.result-bar-count {
  font-size: 1.3rem;
  font-weight: 900;
  color: var(--text);
  text-align: right;
}

/* Correct answer highlight */
.result-bar-row.correct .result-bar-letter {
  box-shadow: 0 0 0 3px var(--success-border);
}
.result-bar-row.correct .result-bar-label {
  color: var(--success);
}
.result-bar-row.correct .result-bar-track {
  background: var(--success-light);
  outline: 1.5px solid var(--success-border);
}
.result-bar-row.correct .result-bar-fill {
  background: var(--success) !important;
}

/* Host overrides — larger for projector */
.host-results-view .result-bar-label { font-size: 1.05rem; }
.host-results-view .result-bar-track  { height: 14px; border-radius: 8px; }
.host-results-view .result-bar-fill   { border-radius: 8px; }
.host-results-view .result-bar-count  { font-size: 1.5rem; }
.host-results-view .result-bar-letter { width: 44px; height: 44px; font-size: 1.1rem; }

/* Host finished / leaderboard */
.host-leaderboard {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 16px;
  background: var(--bg);
}

.host-leaderboard h2 {
  font-size: 2.5rem;
  font-weight: 900;
  margin-bottom: 12px;
  color: var(--text);
}

.host-leaderboard .lb-list { max-width: 640px; }
.host-leaderboard .leaderboard-item { font-size: 1.2rem; padding: 14px 18px; }
.host-leaderboard .lb-score { font-size: 1.2rem; }
