:root {
  --bg: #f4f5f6;
  --panel-bg: #ffffff;
  --text: #1a1d23;
  --text-muted: #5b6270;
  --border: #dde1e6;
  --accent: #2f5fdb;
  --accent-text: #ffffff;
  --correct: #147a42;
  --correct-bg: #e3f5ea;
  --incorrect: #b3261e;
  --incorrect-bg: #fbeaea;
  --chip-bg: #eef1f6;
  --shadow: 0 1px 3px rgba(0,0,0,.08);

  /* exam-shell specific */
  --exam-header-bg: #1c2a3a;
  --exam-header-text: #eef2f7;
  --exam-header-muted: #9fb0c3;
  --flagged: #b8860b;
  --flagged-bg: #fff4d9;
  --timer-warn: #b8860b;
  --timer-danger: #b3261e;
  --nav-unattempted: #d8dde3;
  --nav-answered: #2f9e5c;
  --nav-current: #2f5fdb;
  --nav-flagged: #d9a441;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel-bg: #1d2026;
    --text: #e7e9ee;
    --text-muted: #9aa1ad;
    --border: #2b2f38;
    --accent: #6d93ff;
    --accent-text: #0b1020;
    --correct: #4ad181;
    --correct-bg: #123322;
    --incorrect: #ff7a7a;
    --incorrect-bg: #3a1a1a;
    --chip-bg: #262a33;
    --shadow: 0 1px 3px rgba(0,0,0,.4);

    --exam-header-bg: #0e1620;
    --exam-header-text: #eef2f7;
    --exam-header-muted: #7c8ba0;
    --flagged: #e2b53c;
    --flagged-bg: #3a2f10;
    --timer-warn: #e2b53c;
    --timer-danger: #ff6b6b;
    --nav-unattempted: #333844;
    --nav-answered: #2f9e5c;
    --nav-current: #6d93ff;
    --nav-flagged: #e2b53c;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- exam-shell top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 22px;
  background: var(--exam-header-bg);
  color: var(--exam-header-text);
}
#topbar-left { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
#exam-title { font-size: 15px; font-weight: 700; letter-spacing: .01em; }
#exam-subtitle { font-size: 11.5px; color: var(--exam-header-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#topbar-center { display: flex; align-items: center; justify-content: center; flex: 1; }
#timer-wrap { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); border-radius: 8px; padding: 5px 8px 5px 12px; }
#timer-toggle { background: transparent; border: none; color: var(--exam-header-muted); font-size: 11px; cursor: pointer; padding: 3px 6px; border-radius: 5px; }
#timer-toggle:hover { background: rgba(255,255,255,.08); color: var(--exam-header-text); }
#timer-display { font-family: "SF Mono", Consolas, "Courier New", monospace; font-size: 16px; font-weight: 700; letter-spacing: .04em; color: var(--exam-header-text); min-width: 78px; text-align: center; }
#timer-wrap.warn #timer-display { color: var(--timer-warn); }
#timer-wrap.danger #timer-display { color: var(--timer-danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

#topbar-right { display: flex; align-items: center; gap: 14px; }
#btn-navigator {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16); color: var(--exam-header-text);
  padding: 7px 12px; border-radius: 7px; cursor: pointer; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
#btn-navigator:hover { background: rgba(255,255,255,.15); }
#topbar-stats { font-size: 11.5px; color: var(--exam-header-muted); white-space: nowrap; }

#mode-tabs {
  display: flex; gap: 8px; padding: 10px 24px; background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
}
.mode-tab {
  padding: 8px 18px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text-muted); font-size: 13.5px; font-weight: 600; cursor: pointer;
}
.mode-tab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.exam-source-group { margin-bottom: 4px; }
.exam-source-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); margin: 12px 0 4px; }
.exam-source-group:first-child .exam-source-label { margin-top: 0; }
#exam-list { list-style: none; margin: 0; padding: 0; }
#exam-list li {
  padding: 8px; border-radius: 6px; cursor: pointer; font-size: 13.5px;
  display: flex; justify-content: space-between; gap: 6px;
}
#exam-list li:hover { background: var(--chip-bg); }
#exam-list li.active { background: var(--accent); color: var(--accent-text); }
#exam-list li.active .count-badge { color: var(--accent-text); opacity: .85; }

.itemset-note { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; font-weight: 600; }
.case-siblings { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.case-siblings-title { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.case-sibling-btn { display: flex; gap: 8px; align-items: baseline; text-align: left; background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: 13px; color: var(--text); }
.case-sibling-btn.current { border-color: var(--accent); font-weight: 600; cursor: default; }
.case-sibling-btn.answered .case-sibling-num { color: var(--correct); font-weight: 700; }
.case-sibling-num { flex: none; color: var(--text-muted); font-weight: 600; }
.case-sibling-body { flex: 1; min-width: 0; }
.case-sibling-stem { display: block; margin-bottom: 4px; }
.case-sibling-choices { display: block; font-size: 12px; color: var(--text-muted); }
.case-sibling-choice { display: block; }
.case-question + .case-question { margin-top: 28px; padding-top: 22px; border-top: 2px solid var(--border); }
.case-question .itemset-note { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }









#layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1300px;
  margin: 0 auto;
}

#btn-menu { display: none; }
#sidebar-scrim { display: none; }

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 0 0 10px; }

#topic-list, #source-list, #stage-list { list-style: none; margin: 0; padding: 0; }
#topic-list li, #source-list li, #stage-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13.5px;
}
#topic-list li:hover, #source-list li:hover, #stage-list li:hover { background: var(--chip-bg); }
#topic-list li.active, #source-list li.active, #stage-list li.active { background: var(--accent); color: var(--accent-text); }
.count-badge { font-size: 11px; color: var(--text-muted); }
#topic-list li.active .count-badge, #source-list li.active .count-badge, #stage-list li.active .count-badge { color: var(--accent-text); opacity: .85; }

.opt { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-bottom: 8px; cursor: pointer; }
.opt-label { display: block; font-size: 12px; color: var(--text-muted); margin: 10px 0 4px; }
#opt-vignette { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 13px; }
#search-box { width: 100%; padding: 7px 9px; margin: 8px 0; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 13px; }
#btn-apply, #btn-reset-stats, #btn-export, .file-label {
  width: 100%; padding: 9px; border-radius: 8px; border: none; cursor: pointer;
  font-size: 13.5px; font-weight: 600; margin-top: 4px;
}
#btn-apply { background: var(--accent); color: var(--accent-text); }
.secondary { background: transparent; color: var(--text); border: 1px solid var(--border); font-weight: 500; margin-top: 8px; }
#btn-reset-stats.danger { color: var(--incorrect); }

/* file input styled as a button */
.file-label { display: block; text-align: center; background: transparent; border: 1px solid var(--border); color: var(--text); font-weight: 500; margin-top: 8px; }
.file-label:hover { border-color: var(--accent); }
#import-file { display: none; }

#progress-bar-wrap { height: 6px; background: var(--chip-bg); border-radius: 3px; overflow: hidden; margin-bottom: 10px; }
#progress-bar { height: 100%; width: 0%; background: var(--accent); transition: width .2s; }

#quiz-toolbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
#quiz-meta { font-size: 12.5px; color: var(--text-muted); display: flex; gap: 10px; flex-wrap: wrap; }
.tag { background: var(--chip-bg); padding: 2px 8px; border-radius: 999px; }
.tag-id { border: 0; font: inherit; font-family: ui-monospace, Consolas, monospace; font-weight: 600; color: var(--accent); cursor: pointer; }
.tag-verified { background: var(--correct-bg); color: var(--correct); font-weight: 600; }
.tag-unreviewed { background: var(--flagged-bg); color: var(--flagged); }

#btn-flag {
  flex-shrink: 0; background: var(--panel-bg); border: 1px solid var(--border); color: var(--text-muted);
  padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
#btn-flag:hover { border-color: var(--flagged); color: var(--flagged); }
#btn-flag.flagged { background: var(--flagged-bg); border-color: var(--flagged); color: var(--flagged); }
#quiz-actions { display: flex; gap: 8px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
#btn-submit, #btn-results {
  flex-shrink: 0; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-size: 12.5px;
  font-weight: 600; white-space: nowrap; border: 1px solid var(--accent);
}
#btn-submit { background: var(--accent); color: var(--accent-text); }
#btn-results { background: var(--panel-bg); color: var(--accent); }

#quiz-card {
  background: var(--panel-bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 22px; box-shadow: var(--shadow); min-height: 300px;
}
#empty-state { color: var(--text-muted); text-align: center; padding: 60px 20px; }

/* item sets stack: vignette full width on top, question full width below */
.exam-layout { display: grid; grid-template-columns: 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .exam-layout { grid-template-columns: 1fr; } }
.vignette-pane { max-height: none; overflow: visible; padding-right: 0; min-width: 0; }
.question-pane { max-height: none; overflow: visible; padding-left: 0; min-width: 0; }

.vignette {
  background: var(--chip-bg); border-radius: 8px; padding: 14px 16px;
  font-size: 14px; line-height: 1.55; white-space: pre-wrap;
}
.exam-layout .vignette { margin-bottom: 0; height: 100%; }
.vignette p { margin: 0 0 10px; }
.vignette p:last-child { margin-bottom: 0; }
/* shared narrative paragraph styling: used in the vignette pane, the
   question stem and the answer explanation alike */
p.exhibit-cap { font-weight: 700; }
p.choice-verdict.is-correct { color: var(--correct); }
p.choice-verdict.is-incorrect { color: var(--incorrect); }
p.los-note, .vignette-src { color: var(--text-muted); font-size: 12px; }
/* reconstructed exhibit tables: plain-text pipe rows rendered as tables */
.rich-table { overflow-x: auto; margin: 0 0 10px; }
.rich-table table { border-collapse: collapse; width: 100%; font-size: 13.5px; line-height: 1.45; }
.rich-table th, .rich-table td { border: 1px solid var(--border); padding: 6px 9px; text-align: left; vertical-align: top; }
.rich-table thead th { background: var(--chip-bg); font-weight: 700; }
.rich-table th:not(:first-child), .rich-table td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.vignette .rich-table:last-child, .explanation .rich-table:last-child { margin-bottom: 0; }

/* Flattened exhibits re-laid as one row per line. Deliberately NOT a grid:
   the label sits left, its numbers sit right exactly as they appear in the
   source, because which column each number belongs to is not recoverable. */
.rich-rows-head {
  margin: 0 0 2px; font-size: 12.5px; color: var(--text-muted); line-height: 1.4;
}
.rich-rows { margin: 0 0 10px; border-top: 1px solid var(--border); }
.rich-rows .rr {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 5px 2px; border-bottom: 1px solid var(--border);
  font-size: 13.5px; line-height: 1.45;
}
.rich-rows .rr-l { flex: 1 1 auto; min-width: 0; }
.rich-rows .rr-sep {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: pre;
}
.rich-rows .rr { position: relative; }
.rich-rows .rr-v {
  flex: 0 0 auto; text-align: right; white-space: pre-wrap;
  font-variant-numeric: tabular-nums;
}
.vignette .rich-rows:last-child, .explanation .rich-rows:last-child { margin-bottom: 0; }

@media (max-width: 900px) {
  /* On a phone a long label and a long number run cannot share a line. */
  .rich-rows .rr { flex-direction: column; gap: 2px; padding: 7px 2px; font-size: 14.5px; }
  .rich-rows .rr-v { text-align: left; font-weight: 600; }
}
.stem { font-size: 16px; line-height: 1.5; margin-bottom: 16px; font-weight: 500; white-space: pre-wrap; }
.stem p { margin: 0 0 8px; }
.stem p:last-child { margin-bottom: 0; }

.choices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.choice-row { display: flex; align-items: stretch; gap: 6px; }
.choice-btn {
  flex: 1; text-align: left; padding: 11px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14.5px; cursor: pointer; line-height: 1.4;
  display: flex; gap: 10px;
}
.choice-btn.struck { text-decoration: line-through; opacity: .5; }
.choice-btn:hover { border-color: var(--accent); }
.choice-letter { font-weight: 700; color: var(--accent); flex-shrink: 0; }
.choice-btn.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.choice-btn.correct { background: var(--correct-bg); border-color: var(--correct); }
.choice-btn.correct .choice-letter { color: var(--correct); }
.choice-btn.incorrect { background: var(--incorrect-bg); border-color: var(--incorrect); }
.choice-btn.incorrect .choice-letter { color: var(--incorrect); }
.choice-btn:disabled { cursor: default; }
.strike-btn {
  flex-shrink: 0; width: 30px; border-radius: 9px; border: 1px solid var(--border); background: var(--panel-bg);
  color: var(--text-muted); cursor: pointer; font-size: 12px; text-decoration: line-through;
}
.strike-btn:hover { border-color: var(--text-muted); }
.strike-btn.active { background: var(--chip-bg); color: var(--text); }

.explanation {
  border-top: 1px dashed var(--border); padding-top: 14px; margin-top: 6px;
  font-size: 14px; line-height: 1.6; white-space: pre-wrap;
}
.explanation .verdict { font-weight: 700; margin-bottom: 6px; }
.explanation .verdict.correct { color: var(--correct); }
.explanation .verdict.incorrect { color: var(--incorrect); }
.explanation .verdict.ungraded { color: var(--text-muted); }
.explanation p { margin: 0 0 8px; }
.explanation p:last-child { margin-bottom: 0; }
.previous-answer { font-size: 12.5px; color: var(--text-muted); margin-bottom: 10px; }
.previous-answer .prev-correct { color: var(--correct); }
.previous-answer .prev-incorrect { color: var(--incorrect); }
.link-btn { background: none; border: none; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-decoration: underline; }
.no-answer-note { font-size: 12.5px; color: var(--text-muted); margin-bottom: 8px; font-style: italic; }

#quiz-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
#quiz-nav button {
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel-bg);
  color: var(--text); cursor: pointer; font-size: 13.5px;
}
#quiz-nav button:disabled { opacity: .4; cursor: default; }
#quiz-position { font-size: 13px; color: var(--text-muted); }

/* ---------- question navigator modal ---------- */
#nav-modal-overlay {
  position: fixed; inset: 0; background: rgba(10,14,20,.55); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
#nav-modal {
  background: var(--panel-bg); border-radius: 12px; padding: 18px 20px; width: min(640px, 92vw);
  max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 8px 30px rgba(0,0,0,.3);
}
#nav-modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
#nav-modal-header h3 { margin: 0; font-size: 15px; }
#nav-modal-close { background: none; border: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-muted); }
#nav-modal-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); margin-bottom: 14px; }
#nav-modal-legend span { display: flex; align-items: center; gap: 5px; }
.swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.swatch.current { background: var(--nav-current); }
.swatch.answered { background: var(--nav-answered); }
.swatch.unattempted { background: var(--nav-unattempted); }
.swatch.flagged { background: var(--nav-flagged); }
.swatch.res-correct { background: var(--correct); }
.swatch.res-incorrect { background: var(--incorrect); }
.nav-btn.res-correct { background: var(--correct); color: var(--panel-bg); }
.nav-btn.res-incorrect { background: var(--incorrect); color: var(--panel-bg); }

/* ---------- generic dialog ---------- */
#dialog-overlay {
  position: fixed; inset: 0; background: rgba(10,14,20,.55); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#dialog {
  background: var(--panel-bg); color: var(--text); border-radius: 12px; padding: 20px 22px;
  width: min(460px, 100%); box-shadow: 0 8px 30px rgba(0,0,0,.3);
}
#dialog-title { margin: 0 0 10px; font-size: 16px; }
#dialog-body { font-size: 14px; line-height: 1.5; }
#dialog-body p { margin: 0 0 8px; }
#dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 16px; }
#dialog-actions button, .results-actions button {
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); margin: 0;
}
#dialog-actions button.secondary, .results-actions button.secondary {
  background: transparent; color: var(--text); border-color: var(--border); font-weight: 500;
}

/* ---------- mock exam results ---------- */
.results h2 { margin: 0 0 4px; font-size: 18px; }
.results h3 { margin: 22px 0 8px; font-size: 14px; }
.results-note { margin: 0 0 4px; font-size: 13px; color: var(--text-muted); }
.results-score { margin: 16px 0 4px; padding: 16px; border-radius: 10px; background: var(--chip-bg); text-align: center; }
.results-big { font-size: 40px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.results-big span { font-size: 22px; font-weight: 600; color: var(--text-muted); }
.results-pct { font-size: 16px; font-weight: 700; margin-top: 2px; }
.results-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }
.results-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.results-table th, .results-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.results-table th { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.results-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.results-table .case-row { cursor: pointer; }
.results-table .case-row:hover td { background: var(--chip-bg); }
.case-topic { font-size: 11.5px; color: var(--text-muted); margin-left: 4px; }
.results-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.results-legend span { display: flex; align-items: center; gap: 5px; }
.results-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 7px; }
.result-q {
  height: 38px; border-radius: 7px; border: none; cursor: pointer; font-size: 12.5px; font-weight: 700;
  background: var(--nav-unattempted); color: var(--text);
}
.result-q.correct { background: var(--correct); color: var(--panel-bg); }
.result-q.incorrect { background: var(--incorrect); color: var(--panel-bg); }
.result-q.ungraded { background: var(--nav-answered); color: #fff; }
.results-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 20px; }

#nav-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 7px; overflow-y: auto;
}
.nav-btn {
  position: relative; height: 38px; border-radius: 7px; border: 2px solid transparent; cursor: pointer;
  font-size: 12.5px; font-weight: 700; background: var(--nav-unattempted); color: var(--text);
}
.nav-btn.answered { background: var(--nav-answered); color: #fff; }
.nav-btn.current { border-color: var(--nav-current); }
.nav-btn.flagged::after {
  content: ""; position: absolute; top: -4px; right: -4px; width: 10px; height: 10px;
  background: var(--nav-flagged); border-radius: 50%; border: 2px solid var(--panel-bg);
}

.opt-hint { font-size: 12px; color: var(--text-muted); margin: 6px 0 2px; }

#stage-list li { margin-bottom: 2px; }
#stage-list li small { font-size: 11px; opacity: .75; }

.loading-note { font-size: 14px; }
.loading-note::after {
  content: ""; display: inline-block; width: 1.2em; text-align: left;
  animation: ellipsis 1.2s steps(4, end) infinite;
}
@keyframes ellipsis { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* ---------- sync status chip ---------- */
#sync-status {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  border: 1px solid rgba(255,255,255,.16); color: var(--exam-header-muted);
}
#sync-status.sync-synced { color: #8ee0ad; border-color: rgba(142,224,173,.35); }
#sync-status.sync-offline { color: #e2b53c; border-color: rgba(226,181,60,.35); }
#sync-status.sync-local { color: var(--exam-header-muted); }

/* ==========================================================================
   Phone and tablet
   The sidebar becomes a slide-in drawer so the question gets the full width,
   and the two scrolling panes of an item set collapse into one page scroll —
   nested scroll areas are unusable on a touch screen.
   ========================================================================== */
@media (max-width: 900px) {
  #layout {
    grid-template-columns: 1fr;
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  #btn-menu {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; margin-right: 4px; flex-shrink: 0;
    background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16);
    color: var(--exam-header-text); border-radius: 8px; font-size: 17px; cursor: pointer;
  }

  #topbar { padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); gap: 8px; }
  #topbar-left { flex-direction: row; align-items: center; gap: 8px; flex: 1; }
  #exam-title { font-size: 14px; }
  #exam-subtitle { display: none; }
  #topbar-center { flex: 0 0 auto; }
  #topbar-stats { display: none; }
  #btn-navigator { padding: 7px 10px; font-size: 12px; }
  #timer-display { font-size: 15px; min-width: 68px; }

  #mode-tabs { padding: 8px 12px; }
  .mode-tab { flex: 1; text-align: center; padding: 10px 12px; }

  /* drawer */
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: min(320px, 86vw);
    z-index: 60; background: var(--bg); overflow-y: auto;
    padding: 12px; padding-top: calc(12px + env(safe-area-inset-top));
    transform: translateX(-100%); transition: transform .22s ease-out;
    box-shadow: 2px 0 18px rgba(0,0,0,.28);
    -webkit-overflow-scrolling: touch;
  }
  body.sidebar-open #sidebar { transform: translateX(0); }

  #sidebar-scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(10,14,20,.5); opacity: 0; pointer-events: none; transition: opacity .22s;
  }
  body.sidebar-open #sidebar-scrim { opacity: 1; pointer-events: auto; }
  body.sidebar-open { overflow: hidden; }

  /* one page scroll, not three */
  .exam-layout { grid-template-columns: 1fr; gap: 14px; }
  .vignette-pane, .question-pane { max-height: none; overflow: visible; padding: 0; }
  .vignette { font-size: 15px; line-height: 1.6; }

  #quiz-card { padding: 16px; border-radius: 10px; min-height: 0; }
  .stem { font-size: 16.5px; }

  /* thumb-sized targets */
  .choice-btn { padding: 14px; font-size: 15.5px; }
  .strike-btn { width: 42px; font-size: 13px; }
  #topic-list li, #source-list li, #stage-list li, #exam-list li { padding: 11px 10px; font-size: 14.5px; }
  #quiz-nav { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; margin-top: 10px; }
  #quiz-nav button { padding: 13px 18px; font-size: 14.5px; flex: 1; max-width: 45%; }
  #btn-apply, #btn-reset-stats, #btn-export, .file-label { padding: 13px; }

  /* iOS zooms the page when a font under 16px gets focus */
  #search-box, #opt-vignette { font-size: 16px; padding: 10px; }
  .opt { padding: 4px 0; font-size: 14px; }
  .opt input[type="checkbox"] { width: 18px; height: 18px; }
}

@media (max-width: 380px) {
  #exam-title { font-size: 13px; }
  #sync-status { display: none; }
  #nav-grid { grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); }
}

/* ==========================================================================
   Exam mode
   Sitting or reviewing a mock, laid out after the CFA Institute test screen:
   no sidebar, the clock in the header, the vignette and the question side by
   side with their own scrollbars, radio-style choices, and a fixed bar of
   Previous / End Exam / Next along the bottom.
   ========================================================================== */
body.exam-mode #mode-tabs,
body.exam-mode #sidebar,
body.exam-mode #sidebar-scrim,
body.exam-mode #btn-menu,
body.exam-mode #topbar-stats,
body.exam-mode #quiz-meta,
body.exam-mode #progress-bar-wrap { display: none !important; }
/* The related-questions list stays visible below the current question,
   in a sitting and in review. */
body.exam-mode .case-siblings { margin-top: 14px; }

body.exam-mode #layout { grid-template-columns: 1fr; max-width: 1600px; padding: 12px 16px 84px; }
body.exam-mode #quiz-toolbar { justify-content: flex-end; margin-bottom: 8px; }
body.exam-mode #quiz-card { padding: 0; border-radius: 8px; min-height: 0; overflow: hidden; }
body.exam-mode #quiz-card > .question-pane,
body.exam-mode #quiz-card > .itemset-note,
body.exam-mode #quiz-card > .stem,
body.exam-mode #quiz-card > .choices,
body.exam-mode #quiz-card > .explanation-slot { padding-left: 24px; padding-right: 24px; }
body.exam-mode #quiz-card > :not(.exam-layout):first-child { padding-top: 20px; }
body.exam-mode #quiz-card > :not(.exam-layout):last-child { padding-bottom: 20px; }

/* header */
#btn-pause, #btn-exit-exam {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.16); color: var(--exam-header-text);
  padding: 5px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; white-space: nowrap;
}
#btn-pause:hover, #btn-exit-exam:hover { background: rgba(255,255,255,.16); }
#timer-wrap.paused #timer-display { color: var(--exam-header-muted); }

/* side-by-side item set, each pane scrolling on its own. Practice cases with a
   vignette (body.practice-split) share this look with the exam screen. */
@media (min-width: 901px) {
  body.exam-mode .exam-layout,
  body.practice-split .exam-layout {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0;
    height: calc(100vh - 200px); min-height: 420px;
  }
  body.exam-mode .vignette-pane,
  body.exam-mode .question-pane,
  body.practice-split .question-pane { height: 100%; overflow-y: auto; }
  body.exam-mode .vignette-pane,
  body.practice-split .vignette-pane { border-right: 1px solid var(--border); }
  body.exam-mode .question-pane,
  body.practice-split .question-pane { padding: 20px 24px; }
  body.exam-mode .exam-layout .vignette,
  body.practice-split .exam-layout .vignette { border-radius: 0; min-height: 100%; padding: 20px 24px; }
}
@media (max-width: 900px) {
  body.exam-mode .question-pane,
  body.practice-split .question-pane { padding: 16px; }
  body.exam-mode .exam-layout .vignette,
  body.practice-split .exam-layout .vignette { border-radius: 0; }
}

/* radio-style choices */
body.exam-mode .choices,
body.practice-split .choices { gap: 6px; }
body.exam-mode .choice-btn,
body.practice-split .choice-btn {
  background: var(--panel-bg); border-radius: 6px; align-items: flex-start; gap: 12px; padding: 12px 14px;
}
body.exam-mode .choice-btn::before,
body.practice-split .choice-btn::before {
  content: ""; flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--text-muted); background: var(--panel-bg);
}
body.exam-mode .choice-btn.selected,
body.practice-split .choice-btn.selected { box-shadow: none; background: var(--chip-bg); }
body.exam-mode .choice-btn.selected::before,
body.practice-split .choice-btn.selected::before {
  border-color: var(--accent); background: radial-gradient(circle, var(--accent) 0 4px, var(--panel-bg) 5px);
}
body.exam-mode .choice-btn.correct,
body.practice-split .choice-btn.correct { background: var(--correct-bg); }
body.exam-mode .choice-btn.incorrect,
body.practice-split .choice-btn.incorrect { background: var(--incorrect-bg); }
body.exam-mode .choice-btn.correct::before,
body.practice-split .choice-btn.correct::before { border-color: var(--correct); }
body.exam-mode .choice-btn.incorrect::before,
body.practice-split .choice-btn.incorrect::before { border-color: var(--incorrect); }
body.exam-mode .choice-letter,
body.practice-split .choice-letter { color: var(--text); }
body.exam-mode .choice-letter::after,
body.practice-split .choice-letter::after { content: "."; }

/* practice keeps its header and sidebar, so the panes have less height */
@media (min-width: 901px) {
  body.practice-split:not(.exam-mode) .exam-layout { height: calc(100vh - 250px); }
}
body.practice-split:not(.exam-mode) #quiz-card { padding: 0; border-radius: 8px; min-height: 0; overflow: hidden; }

/* fixed bottom bar */
body.exam-mode #quiz-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; margin: 0;
  padding: 10px 16px; padding-bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--exam-header-bg); color: var(--exam-header-text);
}
body.exam-mode #quiz-nav button {
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2); color: var(--exam-header-text);
  font-weight: 600; max-width: none; flex: none;
}
body.exam-mode #quiz-nav button:hover:not(:disabled) { background: rgba(255,255,255,.18); }
body.exam-mode #quiz-position { color: var(--exam-header-muted); }
#quiz-nav-mid { display: flex; align-items: center; gap: 12px; }
#quiz-nav #btn-submit { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
body.exam-mode #quiz-nav #btn-submit { background: #c9372c; border-color: #c9372c; color: #fff; }

/* pause screen */
#pause-overlay {
  position: fixed; inset: 0; z-index: 45; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: var(--bg);
}
#pause-box {
  background: var(--panel-bg); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 28px 32px; width: min(420px, 100%); text-align: center;
}
.pause-icon { font-size: 28px; color: var(--accent); letter-spacing: -2px; }
#pause-box h2 { margin: 6px 0 10px; font-size: 20px; }
#pause-box p { margin: 0 0 8px; font-size: 14.5px; }
#pause-time { font-family: "SF Mono", Consolas, "Courier New", monospace; font-size: 16px; }
.pause-hint { color: var(--text-muted); font-size: 13px !important; }
.pause-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.pause-actions button {
  padding: 11px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600; margin: 0;
}
#btn-resume { background: var(--accent); color: var(--accent-text); border: 1px solid var(--accent); }

/* navigator list */
#nav-modal-legend { gap: 6px; }
.nav-filter {
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border); background: var(--panel-bg);
  color: var(--text-muted); font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.nav-filter.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
#nav-grid { display: block; overflow-y: auto; }
.nav-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.nav-table th {
  position: sticky; top: 0; background: var(--panel-bg); text-align: left; font-size: 12px;
  color: var(--text-muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--border);
}
.nav-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); }
.nav-row { cursor: pointer; }
.nav-row:hover td, .nav-row:focus td { background: var(--chip-bg); outline: none; }
.nav-row.current td { background: var(--chip-bg); font-weight: 700; }
.nav-row.current td:first-child { box-shadow: inset 3px 0 0 var(--nav-current); }
.nav-table .flag-col { text-align: center; width: 64px; }
.nav-flag { color: var(--nav-flagged); font-size: 15px; }
.nav-status { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--chip-bg); color: var(--text-muted); }
.nav-status.st-answered { background: var(--correct-bg); color: var(--correct); }
.nav-status.st-correct { background: var(--correct-bg); color: var(--correct); }
.nav-status.st-incorrect { background: var(--incorrect-bg); color: var(--incorrect); }
.nav-empty { color: var(--text-muted); font-size: 13px; text-align: center; padding: 20px 0; }
#nav-modal-keys { margin-top: 12px; font-size: 11.5px; color: var(--text-muted); }
kbd {
  font-family: inherit; font-size: 11px; padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--chip-bg);
}

@media (max-width: 900px) {
  body.exam-mode #layout { padding: 10px 10px 84px; }
  body.exam-mode #quiz-nav button { padding: 11px 14px; }
  #btn-pause { padding: 5px 8px; }
  #nav-modal-keys { display: none; }
}
@media (max-width: 520px) {
  body.exam-mode #quiz-position { display: none; }
  #btn-exit-exam { padding: 5px 8px; }
}

/* formulas shown as images cropped from the source PDF (rebuild_formulas.py):
   black ink on a transparent background, inverted to light ink in dark mode */
.eq { margin: 8px 0 12px; overflow-x: auto; }
.eq img { display: block; max-width: 100%; height: auto; }
@media (prefers-color-scheme: dark) {
  .eq img { filter: invert(1); }
}

/* exhibits printed as pictures in the source (insert_source_figures.py):
   kept on white, as printed, in both themes */
.fig { margin: 10px 0 14px; overflow-x: auto; }
.fig img { display: block; max-width: 100%; height: auto; background: #fff; border-radius: 4px; }

/* a formula as an answer choice */
.eq-inline { display: inline-block; vertical-align: middle; max-width: 100%; height: auto; }
@media (prefers-color-scheme: dark) {
  .eq-inline { filter: invert(1); }
}

/* my progress / wide dialog */
#dialog.wide { width: min(720px, 100%); max-height: 85vh; overflow-y: auto; }
#dialog h4 { margin: 16px 0 6px; font-size: 13.5px; }
.progress-table .bar { display: inline-block; width: 90px; height: 7px; background: var(--chip-bg); border-radius: 4px; overflow: hidden; vertical-align: middle; }
.progress-table .bar i { display: block; height: 100%; background: var(--accent); }
#btn-progress { width: 100%; padding: 9px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
/* Single-column item sets: the vignette sits on top and every question
   follows below it, scrolling with the page instead of in its own pane. */
body.exam-mode .exam-layout,
body.practice-split .exam-layout,
.exam-layout { grid-template-columns: minmax(0, 1fr); gap: 20px; height: auto; min-height: 0; }
body.exam-mode .vignette-pane,
body.exam-mode .question-pane,
body.practice-split .vignette-pane,
body.practice-split .question-pane,
.vignette-pane,
.question-pane { height: auto; max-height: none; overflow: visible; border-right: 0; }
body.exam-mode .exam-layout .vignette,
body.practice-split .exam-layout .vignette,
.exam-layout .vignette { height: auto; min-height: 0; }
