:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --success: #10b981;
  --success-soft: #ecfdf5;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --warning: #f59e0b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 14px rgba(15, 23, 42, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

.hidden { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 14px 22px; font-size: 16px; border-radius: 12px; }
.btn-block { width: 100%; }

/* Inputs */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.input, .textarea, .select {
  width: 100%;
  padding: 10px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.14);
}
.textarea { min-height: 92px; resize: vertical; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: #047857; }
.badge-danger { background: var(--danger-soft); color: #b91c1c; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  z-index: 9999;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ================= ADMIN LAYOUT ================= */
.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4f46e5, #06b6d4);
}
.admin-shell {
  max-width: 1260px;
  margin: 0 auto;
  padding: 24px;
}
.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.admin-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .admin-grid { grid-template-columns: 1fr; }
}
.pres-item {
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  background: var(--surface);
}
.pres-item:hover { border-color: #c7d2fe; }
.pres-item.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.pres-item-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.pres-item-meta { font-size: 12px; color: var(--text-muted); display: flex; justify-content: space-between; }

.slide-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.slide-list-item.active { border-color: var(--primary); background: var(--primary-soft); }
.slide-num {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.editor-split {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
  margin-top: 16px;
}
@media (max-width: 980px) {
  .editor-split { grid-template-columns: 1fr; }
}
.option-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.login-box {
  max-width: 400px;
  margin: 12vh auto;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th, .table td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
}
.table th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

/* ================= PRESENTER VIEW (DARK PROJECTOR) ================= */
body.presenter-body {
  background: radial-gradient(circle at top right, #1e1b4b 0%, #0f172a 55%, #020617 100%);
  color: #f8fafc;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}
.presenter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  gap: 16px;
}
.join-pill {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 16px;
}
.join-pill strong {
  font-size: 22px;
  letter-spacing: 0.12em;
  color: #38bdf8;
}
.presenter-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 15px;
  color: #cbd5e1;
}
.stat-chip {
  background: rgba(255, 255, 255, 0.08);
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
}
.presenter-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 28px 48px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}
.stage-title {
  font-size: clamp(28px, 4vw, 52px);
  font-weight: 800;
  line-height: 1.15;
  margin: 0 0 12px 0;
  letter-spacing: -0.02em;
}
.stage-subtitle {
  font-size: clamp(16px, 1.8vw, 24px);
  color: #94a3b8;
  margin: 0 0 32px 0;
}

/* Content Slide on Projector */
.content-slide-layout {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 48px;
  align-items: center;
}
@media (max-width: 900px) {
  .content-slide-layout { grid-template-columns: 1fr; text-align: center; }
}
.qr-card-large {
  background: #ffffff;
  color: #0f172a;
  padding: 24px;
  border-radius: 24px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  justify-self: center;
}
.qr-card-large img {
  width: 260px;
  height: 260px;
  display: block;
}
.qr-code-text {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: #4f46e5;
}

/* MCQ Bar Chart */
.mcq-bars {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
}
.mcq-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mcq-row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 20px;
  font-weight: 600;
}
.mcq-row-count {
  font-size: 18px;
  color: #94a3b8;
  font-variant-numeric: tabular-nums;
}
.mcq-track {
  height: 36px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  overflow: hidden;
}
.mcq-fill {
  height: 100%;
  border-radius: 12px;
  transition: width 0.45s cubic-bezier(0.22, 1, 0.36, 1);
  min-width: 6px;
}

/* Word Cloud */
.wordcloud-stage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px 24px;
  padding: 24px;
  min-height: 280px;
}
.wc-word {
  font-weight: 800;
  line-height: 1.1;
  transition: all 0.35s ease;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 10px;
  user-select: none;
}
.wc-word:hover {
  background: rgba(239, 68, 68, 0.2);
  text-decoration: line-through;
}

/* Open Ended Cards */
.open-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  max-height: 54vh;
  overflow-y: auto;
  padding: 4px;
}
.open-card {
  position: relative;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px;
  padding: 20px;
  font-size: 20px;
  line-height: 1.4;
  color: #f8fafc;
  animation: fadeSlideUp 0.25s ease;
}
.open-card-hide {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(15, 23, 42, 0.75);
  color: #fca5a5;
  border: 1px solid rgba(252, 165, 165, 0.35);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.open-card:hover .open-card-hide { opacity: 1; }

.results-curtain {
  background: rgba(255, 255, 255, 0.06);
  border: 1.5px dashed rgba(255, 255, 255, 0.22);
  border-radius: 20px;
  padding: 48px;
  text-align: center;
  color: #cbd5e1;
  font-size: 22px;
}

.presenter-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  background: rgba(2, 6, 23, 0.65);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  gap: 12px;
  flex-wrap: wrap;
}
.presenter-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.p-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.16);
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}
.p-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.2); }
.p-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.p-btn.active { background: #4f46e5; border-color: #6366f1; }

/* QR Modal Overlay */
.qr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}

/* ================= AUDIENCE MOBILE VIEW ================= */
body.audience-body {
  background: #f1f5f9;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.audience-shell {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 36px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.audience-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.conn-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--success);
  display: inline-block;
}
.conn-dot.offline { background: var(--warning); }
.audience-question {
  font-size: 23px;
  font-weight: 800;
  line-height: 1.25;
  margin: 0 0 8px 0;
}
.audience-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  margin: 0 0 20px 0;
}
.choice-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 16px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}
.choice-card.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}
.choice-indicator {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #cbd5e1;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.choice-card.multi .choice-indicator { border-radius: 6px; }
.choice-card.selected .choice-indicator {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}
.voted-banner {
  text-align: center;
  padding: 36px 20px;
}
.voted-check {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--success-soft);
  color: var(--success);
  font-size: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}
.code-input {
  text-align: center;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0.25em;
  padding: 16px;
}

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