/* ============================================================
   QuizLive — Design tokens
   Palette : Ink #12163B (bg) · Panel #1B1F4B · Violet #8B5CF6
             Gold #F5B942 · Coral #FF6B6B · Cloud #F5F3FF
   Type    : Space Grotesk (display/scores) · Inter (body)
             JetBrains Mono (timer / numeric readouts)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@500;700&display=swap');

:root {
  --ink: #10132E;
  --ink-2: #171B45;
  --panel: #1C2054;
  --panel-2: #232967;
  --border: rgba(245, 243, 255, 0.10);
  --violet: #8B5CF6;
  --violet-2: #A78BFA;
  --gold: #F5B942;
  --coral: #FF6B6B;
  --mint: #4ADE80;
  --cloud: #F5F3FF;
  --muted: #9CA3D4;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 0%, rgba(139,92,246,0.20), transparent 45%),
    radial-gradient(circle at 85% 100%, rgba(245,185,66,0.12), transparent 40%),
    var(--ink);
  color: var(--cloud);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
}

.brand .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 14px 3px rgba(245,185,66,0.65);
}

.pill {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.pill.live { color: var(--mint); border-color: rgba(74,222,128,0.35); background: rgba(74,222,128,0.08); }
.pill.wait { color: var(--gold); border-color: rgba(245,185,66,0.35); background: rgba(245,185,66,0.08); }
.pill.done { color: var(--violet-2); border-color: rgba(167,139,250,0.35); background: rgba(167,139,250,0.08); }

/* ---------- Layout containers ---------- */
.center-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}

.container {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px;
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2) 160%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 32px;
}

.card-tight { padding: 20px 24px; }

h1, h2, h3 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
h1 { font-size: 34px; }
h2 { font-size: 24px; }
h3 { font-size: 17px; }
p { color: var(--muted); line-height: 1.55; margin: 0 0 16px; }

.muted { color: var(--muted); }

/* ---------- Forms ---------- */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%;
  background: rgba(16, 19, 46, 0.55);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  color: var(--cloud);
  font-family: var(--font-body);
  font-size: 15px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--violet);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.25);
}
textarea { resize: vertical; min-height: 80px; }

.field { margin-bottom: 18px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15px;
  padding: 13px 22px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--violet), #7C3AED);
  color: #fff;
  box-shadow: 0 10px 24px rgba(139,92,246,0.35);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 14px 30px rgba(139,92,246,0.5); }

.btn-gold {
  background: linear-gradient(135deg, var(--gold), #E09A1F);
  color: #241703;
  box-shadow: 0 10px 24px rgba(245,185,66,0.3);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--cloud);
}
.btn-ghost:hover { border-color: var(--violet-2); }

.btn-danger {
  background: rgba(255,107,107,0.12);
  border-color: rgba(255,107,107,0.35);
  color: #FF9B9B;
}

.btn-block { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.tab {
  padding: 12px 18px;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--cloud); border-color: var(--violet); }

/* ---------- Question card (user) ---------- */
.question-card {
  max-width: 720px;
  width: 100%;
  animation: rise .35s ease both;
}

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

.q-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.q-index {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
}

/* Countdown ring — signature element */
.timer-ring {
  position: relative;
  width: 64px;
  height: 64px;
}
.timer-ring svg { transform: rotate(-90deg); width: 100%; height: 100%; }
.timer-ring circle {
  fill: none;
  stroke-width: 6;
}
.timer-ring .track { stroke: rgba(245,243,255,0.10); }
.timer-ring .progress {
  stroke: var(--gold);
  stroke-linecap: round;
  transition: stroke-dashoffset .25s linear, stroke .25s ease;
}
.timer-ring .progress.urgent { stroke: var(--coral); }
.timer-ring .label {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 18px;
}

.q-text {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 26px;
}

.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 640px) {
  .options-grid { grid-template-columns: 1fr; }
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(16,19,46,0.5);
  color: var(--cloud);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s ease, transform .1s ease, background .15s ease;
}
.option-btn:hover:not(:disabled) { border-color: var(--violet-2); transform: translateY(-2px); }
.option-btn:disabled { cursor: default; }

.option-key {
  width: 30px; height: 30px;
  min-width: 30px;
  border-radius: 8px;
  background: var(--panel-2);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 13px;
}

.option-btn.selected { border-color: var(--violet); background: rgba(139,92,246,0.16); }
.option-btn.correct { border-color: var(--mint); background: rgba(74,222,128,0.14); }
.option-btn.incorrect { border-color: var(--coral); background: rgba(255,107,107,0.14); }
.option-btn.dim { opacity: 0.45; }

/* ---------- Leaderboard ---------- */
.leaderboard-list { display: flex; flex-direction: column; gap: 10px; }

.lb-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(16,19,46,0.4);
}
.lb-row.me { border-color: var(--gold); background: rgba(245,185,66,0.10); }
.lb-row.top1 { border-color: var(--gold); background: linear-gradient(90deg, rgba(245,185,66,0.18), transparent); }
.lb-row.top2 { border-color: #C9CEDD; }
.lb-row.top3 { border-color: #C77B4B; }

.lb-rank {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}
.lb-name { font-weight: 600; }
.lb-dept { color: var(--muted); font-size: 13px; }
.lb-score {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--gold);
  font-size: 17px;
}

/* ---------- Waiting / status screens ---------- */
.status-screen {
  text-align: center;
  max-width: 480px;
}
.pulse-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--violet);
  margin: 0 auto 22px;
  box-shadow: 0 0 0 0 rgba(139,92,246,0.6);
  animation: pulse 1.6s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(139,92,246,0.55); }
  70% { box-shadow: 0 0 0 16px rgba(139,92,246,0); }
  100% { box-shadow: 0 0 0 0 rgba(139,92,246,0); }
}

/* ---------- Score toast ---------- */
.score-pop {
  position: fixed;
  top: 24px; left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--panel);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-family: var(--font-mono);
  font-weight: 700;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: all .3s ease;
  z-index: 200;
  pointer-events: none;
}
.score-pop.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Tables (admin) ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.05em; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.badge-current { background: rgba(74,222,128,0.15); color: var(--mint); }
.badge-done { background: rgba(156,163,212,0.15); color: var(--muted); }
.badge-pending { background: rgba(245,185,66,0.15); color: var(--gold); }

.grid-2 { display: grid; grid-template-columns: 1.3fr 0.9fr; gap: 24px; }
@media (max-width: 960px) { .grid-2 { grid-template-columns: 1fr; } }

.stat {
  background: rgba(16,19,46,0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
}
.stat .num { font-family: var(--font-mono); font-size: 28px; font-weight: 700; color: var(--gold); }
.stat .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 4px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 22px; }

.divider { height: 1px; background: var(--border); margin: 24px 0; }

.empty-note {
  text-align: center;
  color: var(--muted);
  padding: 30px 10px;
  font-size: 14px;
}

.error-text { color: var(--coral); font-size: 13px; margin-top: 6px; min-height: 18px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.toolbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.q-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  background: rgba(16,19,46,0.35);
}
.q-list-row.is-current { border-color: var(--mint); }
