:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-faint: #64748b;

  /* Sierra Leone emerald + sapphire academic palette */
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: #ccfbf1;
  --primary-text: #0f5132;
  --accent: #1d4ed8;
  --accent-soft: #dbeafe;

  --success: #15803d;
  --success-bg: #dcfce7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --warn: #b45309;
  --warn-bg: #fef3c7;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.07);
  --radius: 14px;
  --radius-sm: 9px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-subtle: #1e293b;
  --border: #1f2937;
  --border-strong: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;

  --primary: #14b8a6;
  --primary-hover: #2dd4bf;
  --primary-soft: rgba(20, 184, 166, 0.16);
  --primary-text: #5eead4;
  --accent: #60a5fa;
  --accent-soft: rgba(96, 165, 250, 0.16);

  --success: #4ade80;
  --success-bg: rgba(34, 197, 94, 0.15);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.16);
  --warn: #fbbf24;
  --warn-bg: rgba(251, 191, 36, 0.16);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.45);
}

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

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 800;
  font-size: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.brand-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.nav-tabs {
  display: flex;
  gap: 0.35rem;
  background: var(--surface-subtle);
  padding: 4px;
  border-radius: 11px;
  border: 1px solid var(--border);
}

.nav-tab {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.86rem;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: background 0.15s, color 0.15s;
}

.nav-tab:hover { color: var(--text); }
.nav-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.pill-count {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-text);
}

.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.38rem 0.75rem;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: "JetBrains Mono", monospace;
}

.score-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
}

.user-pill {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0.32rem 0.65rem;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Admin Panel */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.admin-form {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.85rem;
}

.admin-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.admin-form input {
  padding: 0.5rem 0.72rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 0.86rem;
}

.new-codes-box {
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  background: var(--success-bg);
  color: var(--success);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.82rem;
  white-space: pre-line;
}

.admin-table-wrap {
  overflow-x: auto;
  margin-top: 0.75rem;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 700;
}
.status-active { background: var(--success-bg); color: var(--success); }
.status-suspended { background: var(--danger-bg); color: var(--danger); }
.status-used { background: var(--surface-subtle); color: var(--text-muted); }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--surface-subtle); border-color: var(--border-strong); }

.mobile-only { display: none; }

/* Layout Shell */
.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}

/* Sidebar */
.sidebar {
  position: sticky;
  top: 63px;
  height: calc(100vh - 63px);
  overflow-y: auto;
  padding: 1rem;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.sidebar select {
  font-size: 0.78rem;
  padding: 4px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  cursor: pointer;
}

.topic-all-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-weight: 700;
  font-size: 0.86rem;
  cursor: pointer;
  margin-bottom: 0.75rem;
}

.topic-all-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.topic-all-btn.active .badge {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.module-group {
  margin-bottom: 0.75rem;
}

.module-title {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  padding: 0.35rem 0.45rem;
}

.topic-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  text-align: left;
  padding: 0.45rem 0.6rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.83rem;
  cursor: pointer;
  transition: background 0.12s;
}

.topic-btn:hover { background: var(--surface-subtle); }
.topic-btn.active {
  background: var(--primary-soft);
  color: var(--primary-text);
  font-weight: 600;
}

.topic-btn .tid {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: var(--text-faint);
  flex-shrink: 0;
}
.topic-btn.active .tid { color: var(--primary-text); }

.topic-btn .tlabel {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Main Content */
.main-content {
  padding: 1.5rem clamp(1rem, 3vw, 2.25rem) 3rem;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
}

.hero-strip {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.15rem;
}

.hero-strip h2 {
  margin: 0 0 0.25rem;
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.025em;
}

.hero-strip p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

/* Switch */
.mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  cursor: pointer;
  user-select: none;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
}

.mode-switch input { display: none; }
.switch-track {
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  transition: background 0.18s;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s;
}
.mode-switch input:checked + .switch-track { background: var(--primary); }
.mode-switch input:checked + .switch-track::after { transform: translateX(14px); }

/* Filter Bar */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}

.search-wrap {
  flex: 1 1 240px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.48rem 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.search-wrap input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.88rem;
  outline: none;
}

.segmented {
  display: inline-flex;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 3px;
  border-radius: var(--radius-sm);
}

.seg-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.filter-bar select {
  padding: 0.48rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 500;
}

/* Buttons */
.primary-btn, .secondary-btn, .ghost-btn {
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.84rem;
  padding: 0.5rem 0.95rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}
.primary-btn:hover { background: var(--primary-hover); }

.secondary-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 25%, transparent);
}
.secondary-btn:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }

.ghost-btn {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.ghost-btn:hover { background: var(--surface-subtle); color: var(--text); }

/* Pagination & Results Meta */
.results-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.bottom-meta { margin-top: 1.25rem; }

.pagination {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.page-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.page-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Question Cards */
.question-feed {
  display: grid;
  gap: 1rem;
}

.card, .q-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.q-card {
  transition: border-color 0.15s, box-shadow 0.15s;
}
.q-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}

.q-badges {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tag-year { background: var(--surface-subtle); color: var(--text); font-family: "JetBrains Mono", monospace; }
.tag-mcq { background: var(--accent-soft); color: var(--accent); }
.tag-essay { background: var(--warn-bg); color: var(--warn); }
.tag-topic { background: var(--primary-soft); color: var(--primary-text); }
.tag-img { background: #ede9fe; color: #6d28d9; }
[data-theme="dark"] .tag-img { background: rgba(139, 92, 246, 0.2); color: #c4b5fd; }

.q-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.scan-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 0.77rem;
  font-weight: 600;
  cursor: pointer;
}
.scan-btn:hover { border-color: var(--primary); color: var(--primary); }

.star-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 1rem;
}
.star-btn.starred {
  color: #f59e0b;
  border-color: #f59e0b;
  background: var(--warn-bg);
}

.q-context {
  background: var(--surface-subtle);
  border-left: 3px solid var(--accent);
  padding: 0.65rem 0.9rem;
  border-radius: 0 8px 8px 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
  white-space: pre-line;
}

.q-text {
  font-size: 1.02rem;
  font-weight: 500;
  margin: 0 0 1rem;
  white-space: pre-line;
  overflow-x: auto;
}

.q-body-with-diagram {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 280px);
  gap: 1rem;
  align-items: start;
  margin-bottom: 0.9rem;
}

.q-body-with-diagram .q-text {
  margin-bottom: 0;
}

.q-diagram-box {
  margin: 0;
  padding: 0.5rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
  cursor: zoom-in;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.q-diagram-box:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.q-diagram-box img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 6px;
}

.q-diagram-caption {
  margin-top: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: #64748b;
  font-weight: 600;
}

.diag-toggle-btn {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  font-size: 0.69rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  cursor: pointer;
}
.diag-toggle-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* MCQ Options */
.options-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem;
  margin-bottom: 0.95rem;
}

.opt-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.94rem;
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s;
}

.opt-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--surface-subtle);
}

.opt-letter {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--surface-subtle);
  font-weight: 700;
  font-size: 0.8rem;
  font-family: "JetBrains Mono", monospace;
  flex-shrink: 0;
}

.opt-btn.correct {
  border-color: var(--success);
  background: var(--success-bg);
}
.opt-btn.correct .opt-letter {
  background: var(--success);
  color: #fff;
}

.opt-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
}
.opt-btn.wrong .opt-letter {
  background: var(--danger);
  color: #fff;
}

.opt-btn.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.opt-btn.selected .opt-letter {
  background: var(--accent);
  color: #fff;
}

/* Solution Box */
.q-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.solution-box {
  margin-top: 0.9rem;
  padding: 0.95rem 1.05rem;
  border-radius: 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  font-size: 0.93rem;
}

.solution-answer {
  font-weight: 700;
  color: var(--primary-text);
  margin-bottom: 0.45rem;
}

.solution-steps strong,
.sheet-sol strong,
.q-text strong {
  font-weight: 700;
  color: var(--text);
}

.solution-steps code,
.sheet-sol code,
.q-text code {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.86em;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.solution-steps {
  white-space: pre-line;
  overflow-x: auto;
}

/* Quiz View */
.quiz-setup {
  max-width: 720px;
  margin: 0.5rem auto;
}
.quiz-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.9rem;
  margin: 1.25rem 0 1.4rem;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.84rem;
  font-weight: 600;
}
.field select {
  padding: 0.55rem 0.75rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 0.88rem;
}

.quiz-header { margin-bottom: 1rem; }
.quiz-progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
  font-weight: 600;
}
.timer-badge {
  background: var(--surface-subtle);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}
.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-subtle);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  width: 0%;
  transition: width 0.25s ease;
}

.quiz-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

/* Analytics */
.analytics-filter-card {
  margin-bottom: 1.15rem;
  padding: 0.95rem 1.1rem;
  display: grid;
  gap: 0.75rem;
}

.analytics-filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.preset-group, .year-chips {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.year-chips-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.72rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s, color 0.14s;
}

.chip-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}

.chip-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.analytics-type-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
}

.analytics-type-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.chart-header h3 { margin: 0 0 0.2rem; }
.chart-header p { margin: 0; }

.chart-legend {
  display: inline-flex;
  align-items: center;
  gap: 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -1px;
}
.legend-dot.mcq { background: var(--accent); }
.legend-dot.essay { background: var(--primary); }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
}
.kpi-val {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--primary);
}
.kpi-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Topic Progression Line Chart */
.trend-card {
  margin-bottom: 1.25rem;
}

.trend-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.trend-controls select {
  padding: 0.42rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
  max-width: 220px;
}

.trend-type-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 0.32rem 0.68rem;
  border-radius: 6px;
  cursor: pointer;
}

.trend-type-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.trend-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.85rem 0 0.75rem;
}

.trend-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 4px 8px 4px 10px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.14s, opacity 0.14s;
}

.trend-pill:hover, .trend-pill.highlighted {
  border-color: var(--pill-color);
  transform: translateY(-1px);
}

.trend-pill.dimmed {
  opacity: 0.4;
}

.trend-pill-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--pill-color);
  flex-shrink: 0;
}

.trend-pill-remove {
  border: 0;
  background: transparent;
  color: var(--text-faint);
  font-size: 0.85rem;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}
.trend-pill-remove:hover { color: var(--danger); }

.trend-svg-wrap {
  position: relative;
  width: 100%;
  overflow-x: auto;
}

.trend-svg {
  width: 100%;
  min-width: 580px;
  height: auto;
  display: block;
}

.trend-grid-line {
  stroke: var(--border);
  stroke-dasharray: 3 4;
}

.trend-axis-label {
  fill: var(--text-muted);
  font-size: 11px;
  font-family: "JetBrains Mono", monospace;
}

.trend-line {
  fill: none;
  stroke-width: 2.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.18s, stroke-width 0.18s;
}

.trend-line.highlighted {
  stroke-width: 4.5;
  opacity: 1;
}

.trend-line.dimmed {
  opacity: 0.16;
}

.trend-dot {
  cursor: pointer;
  stroke: var(--surface);
  stroke-width: 2;
  transition: r 0.14s, opacity 0.18s;
}

.trend-dot.dimmed {
  opacity: 0.18;
}

.trend-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 10;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  font-size: 0.79rem;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

.analytics-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 1rem;
}

.bar-chart {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.85rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 195px 1fr 48px;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 7px;
}
.bar-row:hover { background: var(--surface-subtle); }

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.bar-track {
  height: 14px;
  background: var(--surface-subtle);
  border-radius: 999px;
  overflow: hidden;
  display: flex;
}

.bar-mcq { background: var(--accent); height: 100%; }
.bar-essay { background: var(--primary); height: 100%; }
.bar-total { text-align: right; font-family: "JetBrains Mono", monospace; font-weight: 700; }

/* Native Modal Dialog — compliant with modern-web-guidance (dialog, light-dismiss-a-dialog, prevent-page-scroll-under-modal-dialog) */
dialog.scan-dialog {
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  width: min(960px, 94vw);
  max-height: 92vh;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35);
}

/* Scope display strictly to [open] so closed state is never overridden */
dialog.scan-dialog[open] {
  display: flex;
  flex-direction: column;
}

/* Mandatory scroll containment on modal and backdrop */
dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.68);
  backdrop-filter: blur(4px);
  overflow: hidden;
  overscroll-behavior: contain;
}

.scan-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.9rem 1.15rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.scan-dialog-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.scan-dialog-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.scan-dialog-body {
  overflow: auto;
  padding: 1rem;
  background: var(--surface-subtle);
  text-align: center;
  flex: 1;
}

.scan-dialog-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  transition: width 0.2s ease;
}

.scan-dialog-body.zoomed img {
  max-width: none;
  width: 150%;
}

dialog.pw-dialog {
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  width: min(440px, 94vw);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35);
}

dialog.pw-dialog[open] {
  display: flex;
  flex-direction: column;
}

.pw-dialog-body {
  padding: 1.15rem;
  display: grid;
  gap: 0.85rem;
}

.pw-dialog-body input {
  width: 100%;
  padding: 0.58rem 0.78rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 0.9rem;
}

.pw-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 0.25rem;
}

.pw-status {
  padding: 0.6rem 0.8rem;
  border-radius: 9px;
  font-size: 0.84rem;
  font-weight: 600;
}
.pw-status.error {
  background: var(--danger-bg);
  color: var(--danger);
}
.pw-status.success {
  background: var(--success-bg);
  color: var(--success);
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
}

/* Export PDF Builder & Print Worksheet */
.export-builder {
  margin-bottom: 1.25rem;
}

.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.85rem;
  margin-bottom: 0.9rem;
}

.export-grid input,
.export-title-row input {
  padding: 0.52rem 0.72rem;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
  font-size: 0.88rem;
}

.export-title-row {
  display: flex;
  align-items: flex-end;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.export-meta-pill {
  padding: 0.55rem 0.95rem;
  border-radius: 9px;
  background: var(--primary-soft);
  color: var(--primary-text);
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
}

.print-sheet {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.25rem;
  box-shadow: var(--shadow-md);
}

.sheet-header {
  border-bottom: 2px solid #0f766e;
  padding-bottom: 0.85rem;
  margin-bottom: 1.35rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

.sheet-header h1 {
  margin: 0 0 0.2rem;
  font-size: 1.35rem;
  font-weight: 800;
  color: #0f172a;
}

.sheet-header p {
  margin: 0;
  font-size: 0.85rem;
  color: #475569;
}

.sheet-q {
  padding: 0.9rem 0;
  border-bottom: 1px solid #e2e8f0;
  break-inside: avoid;
  page-break-inside: avoid;
}

.sheet-q:last-child {
  border-bottom: 0;
}

.sheet-q-meta {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-bottom: 0.45rem;
  font-size: 0.76rem;
  font-weight: 700;
  color: #0f766e;
}

.sheet-q-meta .sheet-pill {
  background: #f1f5f9;
  color: #334155;
  padding: 2px 7px;
  border-radius: 999px;
  font-family: "JetBrains Mono", monospace;
}

.sheet-q-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.85rem;
  align-items: start;
}

.sheet-q-body.has-diag {
  grid-template-columns: minmax(0, 1fr) 230px;
}

.sheet-q-context {
  background: #f8fafc;
  border-left: 3px solid #1d4ed8;
  padding: 0.45rem 0.7rem;
  margin-bottom: 0.5rem;
  font-size: 0.86rem;
  color: #334155;
  white-space: pre-line;
}

.sheet-q-text {
  font-size: 0.96rem;
  line-height: 1.55;
  white-space: pre-line;
}

.sheet-q-diag {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.35rem;
  background: #ffffff;
  text-align: center;
}

.sheet-q-diag img {
  display: block;
  width: 100%;
  max-height: 185px;
  object-fit: contain;
}

.sheet-opts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem 1.25rem;
  margin-top: 0.55rem;
  font-size: 0.9rem;
}

.sheet-sol {
  margin-top: 0.65rem;
  padding: 0.6rem 0.8rem;
  background: #f8fafc;
  border-left: 3px solid #0f766e;
  border-radius: 0 6px 6px 0;
  font-size: 0.86rem;
  white-space: pre-line;
}

.sheet-sol-ans {
  font-weight: 700;
  color: #0f5132;
  margin-bottom: 0.25rem;
}

.sheet-answer-key {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 2px solid #0f766e;
  break-before: page;
  page-break-before: always;
}

.sheet-answer-key h2 {
  margin: 0 0 0.85rem;
  font-size: 1.15rem;
  color: #0f172a;
}

.answer-key-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.4rem 0.85rem;
  font-size: 0.84rem;
}

.answer-key-item {
  padding: 0.28rem 0.45rem;
  background: #f8fafc;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 14mm 14mm 16mm 14mm;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    background: #ffffff !important;
    color: #0f172a !important;
  }

  .topbar,
  .sidebar,
  .no-print,
  dialog,
  #view-bank,
  #view-quiz,
  #view-analytics,
  #view-starred,
  #view-admin {
    display: none !important;
  }

  .app-shell {
    display: block !important;
  }

  .main-content {
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
  }

  #view-export {
    display: block !important;
  }

  .print-sheet {
    border: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
  }
}

/* Responsive */
@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .mobile-only { display: inline-grid; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 63px;
    width: 300px;
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .analytics-grid { grid-template-columns: 1fr; }
  .nav-tabs { overflow-x: auto; max-width: 100%; }
}

@media (max-width: 640px) {
  .options-grid { grid-template-columns: 1fr; }
  .q-body-with-diagram { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .bar-row { grid-template-columns: 135px 1fr 40px; }
}

/* ---------- High-Level Course Module Overview (M01–M08) ---------- */
.module-overview-card {
  margin-bottom: 1.25rem;
}

.mod-sort-btn {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  padding: 0.34rem 0.72rem;
  border-radius: 6px;
  cursor: pointer;
}

.mod-sort-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.overview-insights {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.insight-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.48rem 0.82rem;
  border-radius: 999px;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  background: var(--surface-subtle);
  color: var(--text);
}

.insight-pill.gold {
  border-color: rgba(217, 119, 6, 0.35);
  background: rgba(217, 119, 6, 0.10);
}
.insight-pill.gold strong { color: #d97706; }

.insight-pill.emerald {
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.10);
}
.insight-pill.emerald strong { color: #059669; }

.insight-pill.sapphire {
  border-color: rgba(37, 99, 235, 0.35);
  background: rgba(37, 99, 235, 0.10);
}
.insight-pill.sapphire strong { color: #2563eb; }

.module-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
  gap: 0.85rem;
}

.module-overview-item {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
  transition: border-color 0.15s, transform 0.12s;
}

.module-overview-item:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.mod-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.mod-code-badge {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.18rem 0.52rem;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
}

.mod-pct-badge {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--accent);
}

.mod-item-name {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.28;
}

.mod-item-range {
  font-size: 0.74rem;
}

.mod-item-nums {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 0.15rem;
}

.mod-item-total {
  font-size: 1.08rem;
  color: var(--text);
}

.mod-item-bar {
  height: 8px;
  margin: 0.15rem 0 0.35rem;
}

.mod-top-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: auto;
}

.mod-topic-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 0.22rem 0.48rem;
  font-size: 0.73rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.32rem;
  max-width: 100%;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}

.mod-topic-pill:hover {
  border-color: var(--primary);
  background: var(--accent-soft);
}

.mod-topic-pill strong {
  color: var(--primary);
}
