*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --sidebar-w: 220px;
  --sidebar-bg: #0f2542;
  --sidebar-text: #a8c0d6;
  --sidebar-active: #1d4ed8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --correct: #16a34a;
  --incorrect: #dc2626;
  --bg: #f3f6fb;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 8px;
}

/* ── Color Themes ─────────────────────────────────────────────── */
html[data-theme="teal"] {
  --sidebar-bg: #134e4a;
  --sidebar-active: #0d9488;
  --accent: #0d9488;
  --accent-hover: #0f766e;
}
html[data-theme="purple"] {
  --sidebar-bg: #2e1065;
  --sidebar-active: #7c3aed;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
}
html[data-theme="rose"] {
  --sidebar-bg: #4c0519;
  --sidebar-active: #e11d48;
  --accent: #e11d48;
  --accent-hover: #be123c;
}
html[data-theme="amber"] {
  --sidebar-bg: #431407;
  --sidebar-active: #d97706;
  --accent: #d97706;
  --accent-hover: #b45309;
}

/* ── Dark Mode ────────────────────────────────────────────────── */
html[data-mode="dark"] {
  --bg: #0f172a;
  --card: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
}
html[data-mode="dark"] .quiz-overlay    { background: #0f172a; }
html[data-mode="dark"] .results-overlay { background: #0f172a; }
html[data-mode="dark"] .quiz-choice     { background: var(--card); border-color: var(--border); }
html[data-mode="dark"] .quiz-choice:hover:not(.disabled) { background: #263048; border-color: #60a5fa; }
html[data-mode="dark"] .quiz-choice.selected { background: #1e3a5f; border-color: var(--accent); }
html[data-mode="dark"] .quiz-explanation { background: var(--card); border-color: var(--border); }
html[data-mode="dark"] .quiz-explanation-body { color: #cbd5e1; }
html[data-mode="dark"] .quiz-list-panel { background: var(--card); border-color: var(--border); }
html[data-mode="dark"] .quiz-list-panel-header { border-color: var(--border); }
html[data-mode="dark"] .quiz-list-item  { border-color: var(--border); }
html[data-mode="dark"] .quiz-list-item:hover { background: #263048; }
html[data-mode="dark"] .quiz-list-item.current { background: #1e3a5f; }
html[data-mode="dark"] .results-score-card  { background: var(--card); border-color: var(--border); }
html[data-mode="dark"] .results-qitem       { background: var(--card); border-color: var(--border); }
html[data-mode="dark"] .results-qitem-body  { border-color: var(--border); }
html[data-mode="dark"] .results-choice.neutral-ans { background: #263048; border-color: var(--border); }
html[data-mode="dark"] .results-expl        { color: #cbd5e1; border-color: var(--border); }
html[data-mode="dark"] .check-item          { border-color: var(--border); }
html[data-mode="dark"] .check-item:hover    { background: #263048; }
html[data-mode="dark"] .check-item.checked  { background: #1e3a5f; border-color: #60a5fa; }
html[data-mode="dark"] .mode-tab            { border-color: var(--border); color: var(--text-muted); }
html[data-mode="dark"] .mode-tab.active     { background: #1e3a5f; color: #60a5fa; border-color: #60a5fa; }
html[data-mode="dark"] .test-history-item   { background: var(--card); border-color: var(--border); }
html[data-mode="dark"] .card                { background: var(--card); border-color: var(--border); }
html[data-mode="dark"] .stat-card           { background: var(--card); border-color: var(--border); }
html[data-mode="dark"] .page-header         { background: var(--card); border-color: var(--border); }
html[data-mode="dark"] .num-input           { background: var(--card); border-color: var(--border); color: var(--text); }
html[data-mode="dark"] .btn-outline         { background: var(--card); border-color: var(--border); color: var(--text); }
html[data-mode="dark"] .btn-outline:hover   { background: #263048; }
html[data-mode="dark"] .expl-choice-item    { background: #263048; border-color: var(--border); color: var(--text); }

html, body { height: 100%; font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  transition: transform .25s ease;
  z-index: 300;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 299;
}
.sidebar-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  position: relative;
}
.logo-icon-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-uworld-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.logo-uworld-name {
  color: #fff;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.2px;
}
.logo-uworld-name span { font-weight: 400; }
.logo-uworld-sub {
  color: rgba(255,255,255,.45);
  font-size: 7.5px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  margin-top: 1px;
}
.logo-text { color: #fff; font-weight: 700; font-size: 14px; margin-top: 8px; letter-spacing: .3px; }

/* ── Theme Switcher Panel ─────────────────────────────────────── */
.sidebar-theme-panel {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.theme-panel-label {
  font-size: 10px;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: rgba(255,255,255,.4);
  margin-bottom: 8px;
}
.theme-swatches {
  display: flex;
  gap: 7px;
  margin-bottom: 10px;
}
.theme-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: transform .15s, border-color .15s;
  padding: 0;
  flex-shrink: 0;
}
.theme-swatch:hover { transform: scale(1.18); }
.theme-swatch.active { border-color: rgba(255,255,255,.9); transform: scale(1.12); }
.dark-mode-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  background: rgba(255,255,255,.08);
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  color: rgba(255,255,255,.75);
  font-size: 12px;
  cursor: pointer;
  transition: background .15s;
  font-family: inherit;
}
.dark-mode-toggle:hover { background: rgba(255,255,255,.14); color: #fff; }
.dark-mode-toggle svg { width: 14px; height: 14px; flex-shrink: 0; }
.sidebar-close-btn {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--sidebar-text);
  padding: 4px;
}
.sidebar-close-btn svg { width: 18px; height: 18px; }
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  cursor: pointer;
  transition: background .15s, color .15s;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; }
.nav-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
}
.nav-group-header:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-chevron { width: 14px; height: 14px; margin-left: auto; transition: transform .2s; }
.nav-chevron.open { transform: rotate(-90deg); }
.nav-sub { overflow: hidden; }
.nav-sub-item { padding-left: 40px; font-size: 13px; }
/* ── Sidebar search ──────────────────────────────────────── */
.sidebar-search {
  padding: 10px 14px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-search input {
  flex: 1;
  padding: 7px 10px;
  border-radius: 5px;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  min-width: 0;
  width: 100%;
}
.sidebar-search input::placeholder { color: rgba(255,255,255,.4); }
.sidebar-search input:focus { outline: none; border-color: rgba(255,255,255,.4); background: rgba(255,255,255,.12); }
.sidebar-search button {
  padding: 7px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  white-space: nowrap;
  transition: background .15s;
}
.sidebar-search button:hover { background: var(--accent-hover); }

/* ── Reset button ────────────────────────────────────────── */
.nav-reset-btn {
  margin-top: 4px;
  color: #f87171 !important;
}
.nav-reset-btn:hover {
  background: rgba(239,68,68,.12) !important;
  color: #fca5a5 !important;
}
.nav-reset-btn svg { stroke: currentColor; }

/* ── Page loading placeholder ────────────────────────────── */
.page-loading {
  padding: 40px 20px;
  color: #64748b;
  font-size: 14px;
}

.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,.08); text-align: center; }
.expiry-label { color: var(--sidebar-text); font-size: 11px; }
.expiry-value { color: #60a5fa; font-size: 13px; font-weight: 600; margin-top: 2px; }

/* ── Mobile top bar ──────────────────────────────────────── */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 52px;
  background: var(--sidebar-bg);
  color: #fff;
  flex-shrink: 0;
}
.mobile-topbar-title { font-size: 14px; font-weight: 700; }
.mobile-menu-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
}
.mobile-menu-btn svg { width: 22px; height: 22px; }

/* ── Main ────────────────────────────────────────────────── */
.main-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; min-width: 0; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 20px; font-weight: 600; }
.page-body { padding: 20px 24px; flex: 1; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-lg { padding: 12px 28px; font-size: 15px; }

/* ── Cards ───────────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.card-header { padding: 18px 22px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 15px; }
.card-body { padding: 22px; }

/* ── Stats grid ──────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  gap: 20px;
  align-items: center;
}
.stat-donut { position: relative; flex-shrink: 0; }
.stat-donut svg { transform: rotate(-90deg); }
.stat-donut-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.stat-donut-sublabel { font-size: 10px; color: var(--text-muted); font-weight: 400; }
.stat-table { flex: 1; min-width: 0; }
.stat-table-title { font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.stat-row:last-child { border-bottom: none; }
.stat-val { font-weight: 600; color: var(--text); }

/* ── Create Test ─────────────────────────────────────────── */
.create-section { margin-bottom: 22px; }
.create-section-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.toggle-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.toggle-label { font-size: 14px; font-weight: 500; }
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 24px; cursor: pointer; transition: .2s; }
.toggle-slider::before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }
.mode-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.mode-tab {
  padding: 6px 18px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: 13px;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: all .15s;
}
.mode-tab.active { border-color: var(--accent); background: #eff6ff; color: var(--accent); font-weight: 600; }

/* ── Checkbox grid ───────────────────────────────────────── */
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
.check-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s;
  font-size: 13px;
}
.check-item:hover { background: #f8fafc; }
.check-item input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.check-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.check-badge { background: #dbeafe; color: var(--accent); font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 20px; flex-shrink: 0; }
.check-item.checked { background: #eff6ff; border-color: #93c5fd; }
.section-divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.num-questions-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.num-input { width: 80px; padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 6px; font-size: 15px; text-align: center; }
.num-input:focus { outline: none; border-color: var(--accent); }
.num-hint { font-size: 13px; color: var(--text-muted); }

/* ── Quiz overlay ────────────────────────────────────────── */
.quiz-overlay { position: fixed; inset: 0; background: #f5f7fb; z-index: 400; display: flex; flex-direction: column; }
.quiz-overlay.hidden { display: none; }
.quiz-top-bar {
  background: #1e3a5f;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 52px;
  flex-shrink: 0;
  gap: 8px;
}
.quiz-top-left { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.quiz-top-nav { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.quiz-top-right { display: flex; align-items: center; gap: 6px; flex: 1; justify-content: flex-end; }
.quiz-menu-btn, .quiz-nav-btn, .quiz-tool-btn, .quiz-mark-btn {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background .15s;
  white-space: nowrap;
}
.quiz-menu-btn:hover, .quiz-nav-btn:hover, .quiz-tool-btn:hover, .quiz-mark-btn:hover { background: rgba(255,255,255,.12); }
.quiz-menu-btn svg, .quiz-nav-btn svg, .quiz-tool-btn svg, .quiz-mark-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.quiz-item-info { display: flex; flex-direction: column; min-width: 0; }
.quiz-item-num { font-size: 12px; font-weight: 600; white-space: nowrap; }
.quiz-qid { font-size: 10px; color: #93c5fd; white-space: nowrap; }
.quiz-mark-btn.marked svg { fill: #fbbf24; stroke: #fbbf24; }
.quiz-mark-btn.marked { color: #fbbf24; }

.quiz-body { flex: 1; overflow-y: auto; padding: 24px 32px; max-width: 860px; margin: 0 auto; width: 100%; }
.quiz-question-text {
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--text);
  margin-bottom: 24px;
}

.usmle-p {
  margin-bottom: 1em;
}
.quiz-question-text img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 12px 0;
  display: block;
}
/* Tables inside question statements */
.quiz-question-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13.5px;
  overflow-x: auto;
  display: block;
  background: var(--card);
}
.quiz-question-text th,
.quiz-question-text td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.quiz-question-text th,
.quiz-question-text tr:first-child td {
  background: #f0f4f8;
  font-weight: 600;
  color: #1e293b;
}
html[data-mode="dark"] .quiz-question-text th,
html[data-mode="dark"] .quiz-question-text tr:first-child td { background: #263048; color: var(--text); }
/* Images inside answer choices */
.quiz-choice-text img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 4px 0;
  display: block;
}
/* HTML content in results */
.results-question-html img { max-width: 100%; height: auto; border-radius: 4px; margin: 4px 0; display: block; }
.results-question-html table { width: 100%; border-collapse: collapse; font-size: 12.5px; overflow-x: auto; display: block; margin: 8px 0; }
.results-question-html th,
.results-question-html td { border: 1px solid var(--border); padding: 6px 8px; }
.results-question-html th { background: #f8fafc; font-weight: 600; }
.results-choice-html img { max-width: 100%; height: auto; border-radius: 4px; margin: 2px 0; display: block; }
.quiz-choices { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; }
.quiz-choice {
  display: flex;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1.5px solid #d1d5db;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all .15s;
  background: #fff;
  gap: 10px;
}
.quiz-choice:hover:not(.disabled) { border-color: #93c5fd; background: #eff6ff; }
.quiz-choice.selected { border-color: var(--accent); background: #eff6ff; }
.quiz-choice.correct { border-color: var(--correct); background: #f0fdf4; }
.quiz-choice.incorrect-selected { border-color: var(--incorrect); background: #fff1f2; }
.quiz-choice.disabled { cursor: default; pointer-events: none; }
.quiz-choice-radio {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #9ca3af;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  margin-top: 2px;
}
.quiz-choice.selected .quiz-choice-radio { border-color: var(--accent); background: var(--accent); }
.quiz-choice.correct .quiz-choice-radio { border-color: var(--correct); background: var(--correct); }
.quiz-choice.incorrect-selected .quiz-choice-radio { border-color: var(--incorrect); background: var(--incorrect); }
.quiz-choice-radio::after { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #fff; display: none; }
.quiz-choice.selected .quiz-choice-radio::after,
.quiz-choice.correct .quiz-choice-radio::after,
.quiz-choice.incorrect-selected .quiz-choice-radio::after { display: block; }
.quiz-choice-letter { font-weight: 600; color: var(--text-muted); min-width: 18px; flex-shrink: 0; }
.quiz-choice-text { flex: 1; line-height: 1.55; }
.quiz-choice-pct { font-size: 12px; color: var(--text-muted); min-width: 38px; text-align: right; flex-shrink: 0; }
.quiz-choice-icon { width: 18px; height: 18px; flex-shrink: 0; }
.quiz-choice-icon.check { color: var(--correct); }
.quiz-choice-icon.cross { color: var(--incorrect); }

.quiz-submit-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 28px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.quiz-submit-btn:hover { background: var(--accent-hover); }
.quiz-submit-btn:disabled { background: #94a3b8; cursor: not-allowed; }

.quiz-result-banner {
  padding: 11px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
}
.quiz-result-banner.correct-banner { background: #f0fdf4; border-left: 4px solid var(--correct); color: var(--correct); }
.quiz-result-banner.incorrect-banner { background: #fff1f2; border-left: 4px solid var(--incorrect); color: var(--incorrect); }

/* ── Explanation ─────────────────────────────────────────── */
.quiz-explanation {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  margin-top: 18px;
}
.quiz-explanation-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 14px;
  color: var(--text);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.quiz-explanation-body {
  font-size: 14px;
  line-height: 1.8;
  color: #374151;
  overflow-wrap: break-word;
  word-break: break-word;
}
.quiz-explanation-body p { margin-bottom: 10px; }
.quiz-explanation-body p:last-child { margin-bottom: 0; }
.quiz-explanation-body img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 12px 0;
  display: block;
}
.quiz-explanation-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
  overflow-x: auto;
  display: block;
}
.quiz-explanation-body th,
.quiz-explanation-body td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.quiz-explanation-body th { background: #f8fafc; font-weight: 600; }
.quiz-explanation-body ul,
.quiz-explanation-body ol { padding-left: 20px; margin: 8px 0; }
.quiz-explanation-body li { margin-bottom: 4px; }

/* Style paragraphs that reference choices */
.quiz-explanation-body p:has(> strong:first-child),
.results-expl p:has(> strong:first-child) {
  /* handled below via JS class */
}

/* Clickable embed links */
.quiz-explanation-body a {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}
.quiz-explanation-body a:hover { color: var(--accent-hover); }

/* Embed popup divs */
.quiz-explanation-body [id^="embed-"] {
  border: 2px solid var(--accent) !important;
  border-radius: 8px !important;
  padding: 14px !important;
  margin: 10px 0 !important;
  background: #f8fafc !important;
  font-size: 13.5px;
  line-height: 1.7;
}
.quiz-explanation-body [id^="embed-"] img {
  max-width: 100%;
  height: auto;
}

/* Choices within explanation */
.expl-choices { margin: 12px 0; }
.expl-choice-item {
  display: block;
  padding: 6px 10px;
  margin-bottom: 4px;
  border-radius: 5px;
  font-size: 13.5px;
  line-height: 1.5;
  background: #f8fafc;
  border: 1px solid var(--border);
}
.expl-choice-item.expl-correct { background: #f0fdf4; border-color: #86efac; }
.expl-choice-item.expl-wrong { background: #fff1f2; border-color: #fca5a5; }

.quiz-explanation-loading {
  color: var(--text-muted);
  font-size: 14px;
  padding: 10px 0;
}

.quiz-stats-row { display: flex; flex-wrap: wrap; gap: 16px; padding: 8px 0; margin-top: 8px; }
.quiz-stat-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.quiz-stat-item svg { width: 14px; height: 14px; }
.quiz-stat-val { font-weight: 600; color: var(--text); }

.quiz-bottom-bar {
  background: #1e3a5f;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 40px;
  flex-shrink: 0;
}
.quiz-timer { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.quiz-timer svg { width: 14px; height: 14px; }
.quiz-bottom-actions { display: flex; align-items: center; gap: 12px; }
.quiz-progress-info { font-size: 12px; color: #93c5fd; }

/* ── Results Page ────────────────────────────────────────── */
.results-overlay { position: fixed; inset: 0; background: #f5f7fb; z-index: 400; overflow-y: auto; }
.results-overlay.hidden { display: none; }
.results-header {
  background: #1e3a5f;
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.results-title { font-size: 17px; font-weight: 700; }
.results-body { max-width: 900px; margin: 0 auto; padding: 24px 16px; }
.results-score-card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 24px;
}
.results-donut { position: relative; flex-shrink: 0; }
.results-donut svg { transform: rotate(-90deg); }
.results-donut-label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 800;
}
.results-donut-sub { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.results-stats { flex: 1; min-width: 200px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.results-stat { text-align: center; padding: 14px; background: var(--bg); border-radius: 8px; }
.results-stat-val { font-size: 24px; font-weight: 800; }
.results-stat-val.correct { color: var(--correct); }
.results-stat-val.incorrect { color: var(--incorrect); }
.results-stat-val.neutral { color: var(--accent); }
.results-stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.results-qlist-title { font-size: 15px; font-weight: 700; margin-bottom: 14px; }
.results-qitem { background: #fff; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; overflow: hidden; }
.results-qitem-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
}
.results-qitem-num { font-weight: 700; font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.results-qitem-text { flex: 1; font-size: 13px; line-height: 1.4; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results-qitem-badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.badge-correct { background: #dcfce7; color: #16a34a; }
.badge-incorrect { background: #fee2e2; color: #dc2626; }
.badge-skipped { background: #f1f5f9; color: #64748b; }
.results-qitem-body { padding: 0 16px 14px; border-top: 1px solid var(--border); display: none; }
.results-qitem-body.open { display: block; }
.results-choice-list { margin: 10px 0; display: flex; flex-direction: column; gap: 4px; }
.results-choice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  flex-wrap: wrap;
}
.results-choice strong { flex-shrink: 0; }
.results-choice.correct-ans { background: #f0fdf4; border: 1px solid #86efac; }
.results-choice.wrong-ans { background: #fff1f2; border: 1px solid #fca5a5; }
.results-choice.neutral-ans { background: #f8fafc; border: 1px solid #e2e8f0; }
.results-expl {
  font-size: 13px;
  line-height: 1.75;
  color: #374151;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  overflow-wrap: break-word;
  word-break: break-word;
}
.results-expl img { max-width: 100%; height: auto; margin: 8px 0; display: block; border-radius: 4px; }
.results-expl table { width: 100%; border-collapse: collapse; font-size: 12px; overflow-x: auto; display: block; }
.results-expl th, .results-expl td { border: 1px solid var(--border); padding: 6px 8px; }
.results-expl th { background: #f8fafc; font-weight: 600; }
.results-expl a { color: var(--accent); text-decoration: underline; cursor: pointer; }

/* ── Performance ─────────────────────────────────────────── */
.perf-section { margin-bottom: 24px; }
.perf-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.perf-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; flex-wrap: wrap; }
.perf-bar-label { min-width: 160px; max-width: 200px; color: var(--text-muted); font-size: 12px; }
.perf-bar-wrap { flex: 1; min-width: 80px; background: #e2e8f0; border-radius: 4px; height: 10px; overflow: hidden; }
.perf-bar { height: 100%; background: var(--accent); border-radius: 4px; transition: width .6s; }
.perf-bar-count { min-width: 80px; text-align: right; color: var(--text-muted); font-size: 12px; }

/* ── Previous Tests ──────────────────────────────────────── */
.test-history-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.test-history-info { flex: 1; min-width: 0; }
.test-history-name { font-weight: 600; font-size: 14px; }
.test-history-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.test-history-score { text-align: center; }
.test-history-score-val { font-size: 18px; font-weight: 800; }
.test-history-score-label { font-size: 11px; color: var(--text-muted); }
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state svg { width: 44px; height: 44px; margin: 0 auto 14px; display: block; color: #cbd5e1; }
.empty-state-text { font-size: 14px; }

/* ── Quiz list panel ─────────────────────────────────────── */
.quiz-list-panel {
  position: fixed;
  top: 52px;
  left: 0;
  bottom: 40px;
  width: 260px;
  background: #fff;
  border-right: 1px solid var(--border);
  z-index: 101;
  transform: translateX(-100%);
  transition: transform .2s;
  overflow-y: auto;
}
.quiz-list-panel.open { transform: translateX(0); }
.quiz-list-panel-header { padding: 12px 14px; font-weight: 700; font-size: 13px; border-bottom: 1px solid var(--border); }
.quiz-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.quiz-list-item:hover { background: var(--bg); }
.quiz-list-item.current { background: #eff6ff; font-weight: 600; }
.qli-num { font-weight: 700; color: var(--text-muted); min-width: 22px; font-size: 12px; }
.qli-dot { width: 9px; height: 9px; border-radius: 50%; background: #d1d5db; flex-shrink: 0; }
.qli-dot.answered-correct { background: var(--correct); }
.qli-dot.answered-incorrect { background: var(--incorrect); }
.qli-dot.marked { background: #f59e0b; }
.qli-dot.current { background: var(--accent); }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Table styles from explanations ─────────────────────── */
.table-default-style {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 10px 0;
}
.table-default-style th,
.table-default-style td {
  border: 1px solid #d1d5db;
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.table-default-style th,
.table-default-style tr:first-child td { background: #f8fafc; font-weight: 600; }

/* ── Responsive / Mobile ─────────────────────────────────── */
@media (max-width: 768px) {
  /* Show mobile topbar */
  .mobile-topbar { display: flex; }

  /* Sidebar becomes slide-in drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    transform: translateX(-100%);
    z-index: 300;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.visible { display: block; }
  .sidebar-close-btn { display: flex; align-items: center; justify-content: center; }

  /* #app layout: stack vertically, sidebar is fixed so not in flow */
  #app { flex-direction: column; height: 100vh; overflow: hidden; }

  /* Main content fills remaining height below mobile topbar */
  .main-content { flex: 1; overflow: hidden; height: 0; flex-direction: column; }

  /* Page padding */
  .page-header { padding: 12px 14px; }
  .page-body { padding: 14px; }

  /* Stats grid → single column */
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 14px 16px; gap: 14px; }
  .stat-donut-label { font-size: 12px; }

  /* Test count row → single column */
  .test-count-grid { grid-template-columns: 1fr !important; }

  /* Checkbox grid → single column */
  .check-grid { grid-template-columns: 1fr; }

  /* Quiz body */
  .quiz-body { padding: 14px; }
  .quiz-question-text { font-size: 14px; margin-bottom: 16px; }
  .quiz-choice { font-size: 13px; padding: 10px 12px; }

  /* Quiz top bar: hide labels on tiny screens */
  .quiz-btn-label { display: none; }
  .quiz-item-num { font-size: 11px; }

  /* Results */
  .results-header { padding: 12px 14px; }
  .results-body { padding: 14px; }
  .results-score-card { padding: 16px; gap: 16px; flex-direction: column; align-items: flex-start; }
  .results-stats { grid-template-columns: 1fr 1fr; width: 100%; }
  .results-qitem-header { flex-wrap: wrap; }
  .results-qitem-text { white-space: normal; }

  /* Explanation */
  .quiz-explanation { padding: 14px; }
  .quiz-explanation-body table { font-size: 12px; }
  .quiz-explanation-body [id^="embed-"] { padding: 10px !important; }

  /* Performance bars */
  .perf-bar-label { min-width: 100px; max-width: 130px; }
  .perf-bar-count { min-width: 60px; }

  /* Num questions row */
  .num-questions-row { flex-wrap: wrap; gap: 8px; }

  /* Test history */
  .test-history-item { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
  .results-stats { grid-template-columns: 1fr 1fr; }
  .results-stat-val { font-size: 20px; }
  .quiz-top-bar { padding: 0 8px; gap: 4px; }
  .quiz-menu-btn, .quiz-nav-btn, .quiz-tool-btn, .quiz-mark-btn { padding: 5px 6px; }
  .quiz-explanation-body { font-size: 13px; }
  .page-title { font-size: 17px; }
}

/* --- New Feature Styles --- */
.strike { text-decoration: line-through; opacity: 0.6; }

.quiz-bottom-tool-btn {
  border: 1px solid rgba(255,255,255,0.3);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 13px;
  background: transparent;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s;
}
.quiz-bottom-tool-btn:hover { background: rgba(255,255,255,0.1); }
.quiz-bottom-tool-btn svg { width: 14px; height: 14px; }

/* Modals */
.draggable-modal {
  position: absolute;
  top: 100px; left: 100px;
  width: 260px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  z-index: 1000;
  display: flex;
  flex-direction: column;
}
.draggable-modal.hidden, .center-modal.hidden { display: none; }
.modal-header {
  padding: 10px 14px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 14px;
  border-top-left-radius: 7px;
  border-top-right-radius: 7px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: move;
}
.modal-close-btn {
  background: none; border: none; color: white; font-size: 18px; cursor: pointer; padding: 0; line-height: 1; opacity: 0.8;
}
.modal-close-btn:hover { opacity: 1; }
.modal-body { padding: 14px; }

.center-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}
.center-modal .modal-content {
  background: var(--card);
  width: 90%;
  max-width: 500px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}
.center-modal .modal-header { cursor: default; }
.center-modal textarea {
  width: 100%;
  min-height: 150px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  font-family: inherit;
}
.center-modal .modal-footer {
  padding: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

/* Calculator Grid */
.calc-display {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
  font-size: 18px;
  text-align: right;
  margin-bottom: 10px;
}
.calc-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.calc-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 0;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.1s;
}
.calc-btn:hover { background: var(--border); }
.calc-btn.op { background: #dbeafe; color: #1e3a8a; border-color: #bfdbfe; }
html[data-mode="dark"] .calc-btn.op { background: #1e3a8a; color: #dbeafe; border-color: #1e40af; }
.calc-btn.equals { background: #fef08a; color: #854d0e; border-color: #fde047; }
html[data-mode="dark"] .calc-btn.equals { background: #854d0e; color: #fef08a; border-color: #713f12; }
.calc-btn.clear { background: #fecdd3; color: #9f1239; border-color: #fda4af; }
html[data-mode="dark"] .calc-btn.clear { background: #9f1239; color: #fecdd3; border-color: #be123c; }

/* Flashcards */
.flashcard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}
.flashcard {
  perspective: 1000px;
  cursor: pointer;
  height: 250px;
}
.flashcard-inner {
  position: relative;
  width: 100%; height: 100%;
  text-align: center;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }
.flashcard-front, .flashcard-back {
  position: absolute;
  width: 100%; height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.flashcard-back {
  transform: rotateY(180deg);
  background: #f0fdf4;
}
html[data-mode="dark"] .flashcard-back { background: #064e3b; }
.flashcard-content {
  overflow-y: auto;
  width: 100%;
  font-size: 14px;
}

/* ── Button Press Effects ─────────────────────────────────────────────── */
.btn:active,
.quiz-nav-btn:active,
.quiz-bottom-tool-btn:active,
.calc-btn:active,
.quiz-submit-btn:active,
.mode-tab:active {
  transform: scale(0.96);
  opacity: 0.9;
  transition: transform 0.05s ease;
}

/* --- Mobile Scrolling Fixes --- */
#page-container {
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
}

.page-body {
  padding-bottom: 80px !important;
}

@media (max-width: 768px) {
  .page-body {
    padding-bottom: 120px !important;
  }
}

