/* ─── Tokens ──────────────────────────────────────────────────────────────── */
:root {
  --bg: #0f0f14;
  --surface: #1a1a24;
  --surface2: #22222e;
  --border: #2a2a3a;
  --text: #f0f0f5;
  --text-muted: #8888aa;
  --accent-p: #f59e0b;   /* presenter amber */
  --accent-s: #6366f1;   /* participant indigo */
  --success: #10b981;
  --error: #ef4444;
  --radius: 12px;
  --radius-sm: 6px;
  --font: 'DM Sans', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ─── Utilities ──────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ─── KaTeX overrides ────────────────────────────────────────────────────── */
.katex { font-size: 1.1em; }
.display-katex .katex { font-size: 1.4em; }

/* ─── Join Screen ────────────────────────────────────────────────────────── */
.join-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.join-screen .logo {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent-s);
  margin-bottom: 0.25rem;
  letter-spacing: -0.03em;
}
.join-screen .subtitle {
  color: var(--text-muted);
  margin-bottom: 3rem;
  font-size: 1.1rem;
}
.join-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}
.join-card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
input[type="text"] {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.25rem;
  font-family: var(--mono);
  letter-spacing: 0.15em;
  text-align: center;
  padding: 0.75rem 1rem;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus { border-color: var(--accent-s); }
input[type="text"].error { border-color: var(--error); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--accent-s);
  color: #fff;
  width: 100%;
}
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); }
.error-msg {
  color: var(--error);
  font-size: 0.875rem;
  margin-top: 0.75rem;
  text-align: center;
  min-height: 1.25rem;
}

/* ─── Question Screen (Participant) ──────────────────────────────────────── */
.question-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
}
.question-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}
.session-badge {
  font-family: var(--mono);
  font-size: 0.875rem;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  color: var(--accent-s);
}
.progress-label {
  font-size: 0.875rem;
  color: var(--text-muted);
}
.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  margin-bottom: 1.5rem;
  flex: 1;
}
.question-text {
  font-size: 1.4rem;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 1.5rem;
}
.question-type-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  background: var(--surface2);
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ─── Answer Options ──────────────────────────────────────────────────────── */
.answer-options { display: flex; flex-direction: column; gap: 0.75rem; }

.option-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 1rem;
}
.option-item:hover { border-color: var(--accent-s); }
.option-item.selected { border-color: var(--accent-s); background: rgba(99,102,241,0.1); }

.option-item input[type="radio"],
.option-item input[type="checkbox"] { accent-color: var(--accent-s); width: 18px; height: 18px; }

.option-item label { cursor: pointer; flex: 1; }

/* Ranking items */
.ranking-list { display: flex; flex-direction: column; gap: 0.5rem; }
.ranking-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: grab;
  font-size: 1rem;
  user-select: none;
}
.ranking-item:active { cursor: grabbing; }
.ranking-item .drag-handle { color: var(--text-muted); font-size: 1.2rem; line-height: 1; }
.ranking-item .rank-number {
  width: 24px;
  height: 24px;
  background: var(--accent-s);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Short answer */
.short-answer-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
  padding: 0.875rem 1rem;
  outline: none;
  resize: vertical;
  min-height: 100px;
  transition: border-color 0.15s;
}
.short-answer-input:focus { border-color: var(--accent-s); }
.char-count {
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Submit row */
.submit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.5rem;
}
.answer-feedback {
  font-size: 0.875rem;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* ─── Waiting / Submitted State ───────────────────────────────────────────── */
.waiting-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
}
.waiting-state .spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-s);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.waiting-state p { font-size: 1.1rem; }
.submitted-confirm {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem;
  text-align: center;
}
.submitted-confirm .check-icon {
  width: 48px;
  height: 48px;
  background: var(--success);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

/* ─── Presenter View ──────────────────────────────────────────────────────── */
.presenter-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.presenter-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.presenter-topbar .session-code {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-p);
  letter-spacing: 0.1em;
}
.presenter-topbar .participant-count {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}
.participant-dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
}
.presenter-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 2rem;
  gap: 2rem;
}
.presenter-question-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
}
.presenter-question-text {
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 1.5rem;
}
.presenter-controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}
.presenter-results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  flex: 1;
}
.results-title {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}
.result-bars { display: flex; flex-direction: column; gap: 1rem; }
.result-bar-item { }
.result-bar-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.35rem;
  font-size: 0.875rem;
}
.result-bar-label { color: var(--text); }
.result-bar-count { color: var(--text-muted); }
.result-bar-track {
  height: 12px;
  background: var(--surface2);
  border-radius: 6px;
  overflow: hidden;
}
.result-bar-fill {
  height: 100%;
  background: var(--accent-p);
  border-radius: 6px;
  transition: width 0.4s ease;
}
.result-bar-fill.short-answer-bar { background: var(--accent-s); }

/* Short answer word list */
.word-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem;
}
.word-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: 0.25rem 0.65rem;
  border-radius: 4px;
  font-size: 0.875rem;
}
.word-chip .count {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-left: 0.25rem;
}

/* Ranking results */
.ranking-results { display: flex; flex-direction: column; gap: 0.75rem; }
.ranking-result-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--surface2);
  border-radius: var(--radius-sm);
}
.ranking-result-item .rank-badge {
  width: 28px;
  height: 28px;
  background: var(--accent-p);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.ranking-result-item .rank-label { flex: 1; font-size: 1rem; }
.ranking-result-item .rank-pct {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Empty state */
.empty-results {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}
.empty-results .empty-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  opacity: 0.4;
}

/* ─── Presenter Question Builder ──────────────────────────────────────────── */
.question-builder {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.question-builder h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.builder-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  align-items: flex-start;
}
.builder-row input[type="text"] {
  flex: 1;
  font-family: var(--font);
  font-size: 1rem;
  letter-spacing: normal;
  text-align: left;
  padding: 0.5rem 0.75rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
}
.builder-row input[type="text"]:focus { border-color: var(--accent-p); }
.question-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1rem; }
.question-list-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 0.9rem;
}
.question-list-item.active { border-color: var(--accent-p); }
.question-list-item .q-num {
  width: 24px;
  height: 24px;
  background: var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.question-list-item.active .q-num { background: var(--accent-p); }
.question-list-item .q-type {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
}
.question-list-item .q-text-preview {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
}
.question-list-item.active .q-text-preview { color: var(--text); }
.remove-q-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem;
  border-radius: 4px;
}
.remove-q-btn:hover { color: var(--error); background: rgba(239,68,68,0.1); }

/* ─── Display/Projector View ──────────────────────────────────────────────── */
.display-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 4rem;
}
.display-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 3rem;
}
.display-code {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent-p);
  letter-spacing: 0.15em;
}
.display-progress {
  font-size: 1.25rem;
  color: var(--text-muted);
}
.display-question {
  font-size: 2.75rem;
  font-weight: 500;
  line-height: 1.3;
  margin-bottom: 3rem;
  max-width: 900px;
}
.display-results {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 900px;
}
.display-bar-item { }
.display-bar-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 1.3rem;
}
.display-bar-label { color: var(--text); }
.display-bar-pct { color: var(--accent-p); font-weight: 600; }
.display-bar-track {
  height: 24px;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
}
.display-bar-fill {
  height: 100%;
  background: var(--accent-p);
  border-radius: 8px;
  transition: width 0.5s ease;
}
.display-short-answers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.display-word-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.display-word-chip .count {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ─── Session Ended ────────────────────────────────────────────────────────── */
.session-ended-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}
.session-ended-screen h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
}
.session-ended-screen p {
  color: var(--text-muted);
  font-size: 1.2rem;
}

/* ─── Presenter Nav ───────────────────────────────────────────────────────── */
.presenter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.25rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: border-color 0.15s;
}
.nav-btn:hover { border-color: var(--accent-p); }
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.nav-btn.primary { background: var(--accent-p); color: #000; border-color: var(--accent-p); }
.nav-btn.danger { border-color: var(--error); color: var(--error); }
.nav-center { font-size: 0.875rem; color: var(--text-muted); }

/* ─── Tabs ────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem;
  margin-bottom: 1.5rem;
}
.tab-btn {
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.tab-btn.active { background: var(--surface2); color: var(--text); }
.tab-btn:hover:not(.active) { color: var(--text); }

/* ─── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }