:root {
  font-family: Arial, Helvetica, sans-serif;
  color-scheme: light;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --page: #ffffff;
  --control: #ffffff;
  --surface: #f3f5f6;
  --ink: #183452;
  --body: #202a34;
  --muted: #68737e;
  --rule: #cbd2d8;
  --line: var(--rule);
  --soft: #f3f5f6;
  --accent: #164b69;
  --accent-soft: #e8f0f4;
  --accent-contrast: #ffffff;
  --accent-hover: #103e58;
  --correct: #1f613d;
  --incorrect: #8b2e29;
  --flag: #8c571d;
  --focus: #ad5b00;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #26292c;
  --control: #2f3336;
  --surface: #383c40;
  --ink: #d2d7db;
  --body: #d0d3d6;
  --muted: #a4abb1;
  --rule: #6b7278;
  --line: var(--rule);
  --soft: #383c40;
  --accent: #efbb78;
  --accent-soft: #3a342a;
  --accent-contrast: #26292c;
  --accent-hover: #f3c98a;
  --correct: #8ed6a8;
  --incorrect: #f0a19b;
  --flag: #efbb78;
  --focus: #efbb78;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #26292c;
    --control: #2f3336;
    --surface: #383c40;
    --ink: #d2d7db;
    --body: #d0d3d6;
    --muted: #a4abb1;
    --rule: #6b7278;
  --line: var(--rule);
    --soft: #383c40;
    --accent: #efbb78;
    --accent-soft: #3a342a;
    --accent-contrast: #26292c;
    --accent-hover: #f3c98a;
    --correct: #8ed6a8;
    --incorrect: #f0a19b;
    --flag: #efbb78;
    --focus: #efbb78;
  }
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--page); color: var(--body); }
button, input, textarea { font: inherit; }
button { color: inherit; }
.topbar {
  height: 62px; padding: 0 clamp(20px, 4vw, 64px); border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; justify-content: space-between; background: var(--page);
}
.wordmark { display: inline-flex; align-items: center; gap: 7px; color: var(--ink); text-decoration: none; font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.wordmark .back-icon { display: none; width: 22px; height: 22px; flex: none; }
.header-tools { display: flex; align-items: center; gap: 22px; margin-left: auto; }
.header-actions { display: flex; align-items: center; gap: 22px; color: var(--muted); font-size: 14px; }
.header-actions:empty { display: none; }
.header-actions button { border: 0; padding: 8px 0; color: var(--accent); background: transparent; cursor: pointer; font-size: 14px; font-weight: 700; }
.theme-toggle { border: 0; padding: 8px 0; color: var(--accent); background: transparent; cursor: pointer; font-size: 14px; font-weight: 700; }
.theme-toggle:hover { text-decoration: underline; }
.theme-toggle:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.app { width: min(1120px, calc(100% - 48px)); margin: 0 auto; }
.home { padding: 40px 0 80px; }
.course-intro { max-width: 720px; margin-bottom: 30px; }
.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.course-home-link { margin: 18px 0 0; font-size: 14px; }
.course-home-link a { color: var(--accent); font-weight: 700; text-decoration: none; }
.course-home-link a:hover { text-decoration: underline; }
h1 { margin: 0; font-size: clamp(18px, 4vw, 30px); line-height: 1.12; letter-spacing: -.035em; font-weight: 700; }
.intro { margin: 14px 0 28px; max-width: 640px; font-size: 16px; line-height: 1.55; color: var(--body); }
.paper-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); column-gap: 28px; }
.paper-card { min-width: 0; padding: 18px 0; border-top: 1px solid var(--rule); }
@media (min-width: 761px) {
  .paper-card:nth-child(-n+3) { border-top: 0; }
}
.paper-title { font-size: 17px; font-weight: 700; line-height: 1.35; color: var(--ink); }
.paper-title a { color: inherit; text-decoration: none; }
.paper-title a:hover { text-decoration: underline; }
.hub-heading { margin: 34px 0 4px; padding-bottom: 10px; border-bottom: 2px solid var(--ink); font-size: 15px; text-transform: uppercase; letter-spacing: .06em; }
.hub-section-title { margin: 34px 0 8px; padding-bottom: 8px; border-bottom: 2px solid var(--ink); font-size: 16px; font-weight: 700; color: var(--ink); }
.hub-section-title:first-child { margin-top: 8px; }
.paper-meta { margin-top: 7px; color: var(--muted); font-size: 14px; }
.paper-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 16px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-contrast); font-size: 14px; font-weight: 700; text-decoration: none; cursor: pointer; }
.button:hover { background: var(--accent-hover); }
.button:focus-visible, .text-button:focus-visible, input:focus-visible, textarea:focus-visible, .option:focus-within, .download-menu-item:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.button.secondary { background: var(--control); color: var(--accent); }
.button.secondary:hover { background: var(--accent-soft); }
.home-status { min-height: 20px; margin: 16px 0 0; color: var(--muted); font-size: 13px; }
.home-status:empty { display: none; }

.download { position: relative; }
.download-toggle { display: inline-flex; align-items: center; gap: 9px; }
.download-toggle[aria-expanded="true"] { background: var(--accent-soft); }
.download-caret { width: 11px; height: 8px; flex: none; transition: transform .15s ease; }
.download-toggle[aria-expanded="true"] .download-caret { transform: rotate(180deg); }
.download-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20;
  min-width: 168px; padding: 6px; display: grid; gap: 2px;
  background: var(--control); border: 1px solid var(--rule);
  box-shadow: 0 8px 22px rgba(23, 34, 44, .13);
}
.download-menu[hidden] { display: none; }
.download-menu-item {
  display: block; padding: 9px 12px; white-space: nowrap;
  color: var(--ink); font-size: 14px; font-weight: 700; text-decoration: none;
}
.download-menu-item:hover, .download-menu-item:focus-visible { background: var(--accent-soft); color: var(--accent); }

.exam-shell { padding: 0 0 48px; }
.exam-head { display: flex; justify-content: space-between; align-items: center; padding: 22px 0 18px; border-bottom: 1px solid var(--rule); }
.exam-title { font-size: 17px; font-weight: 700; color: var(--ink); }
.exam-stats { display: flex; gap: 22px; color: var(--muted); font-size: 13px; }
.exam-stats strong { color: var(--ink); font-weight: 700; }
.exam-grid { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: clamp(24px, 5vw, 68px); padding-top: 32px; }
.question-nav { border-right: 1px solid var(--rule); padding-right: 18px; }
.question-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.nav-title { margin: 0; color: var(--muted); font-size: 12px; text-transform: uppercase; font-weight: 700; letter-spacing: .06em; }
.nav-title-static { margin: 0 0 12px; }
.nav-toggle { display: none; }
.nav-toggle-arrow { width: 12px; height: 12px; flex: none; transition: transform .15s ease; }
.question-nav-panel { display: block; }
.number-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.number-button { position: relative; min-width: 0; height: 34px; border: 1px solid transparent; background: var(--control); color: var(--body); font-size: 13px; cursor: pointer; }
.number-button:hover { border-color: var(--rule); }
.number-button.current { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.number-button.answered::after { content: ""; position: absolute; left: 50%; bottom: 3px; width: 4px; height: 4px; background: var(--accent); transform: translateX(-50%); }
.number-button.flagged::before { content: ""; position: absolute; right: 2px; top: 2px; width: 5px; height: 5px; background: var(--flag); }
.nav-legend { display: grid; gap: 7px; margin-top: 18px; color: var(--muted); font-size: 12px; }
.legend-item { display: flex; align-items: center; gap: 8px; }
.legend-mark { width: 9px; height: 9px; border: 1px solid var(--muted); }
.legend-mark.done { border: 0; background: var(--accent); }
.legend-mark.flag { border: 0; background: var(--flag); }
.question-area { max-width: 760px; min-width: 0; }
.question-count { color: var(--muted); font-size: 13px; margin: 8px 0 16px; }
.question-stem { white-space: pre-line; font-size: 18px; line-height: 1.6; }
.question-images { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; margin: 20px 0; }
.question-images img { display: block; max-width: min(100%, 650px); max-height: 500px; object-fit: contain; border: 1px solid var(--rule); }
.question-table-wrap { margin: 20px 0; overflow-x: auto; }
.table-caption { margin: 0 0 8px; color: var(--muted); font-size: 14px; }
.question-table { border-collapse: collapse; width: 100%; min-width: 420px; font-size: 14px; line-height: 1.45; background: var(--control); }
.question-table th, .question-table td { border: 1px solid var(--rule); padding: 8px 10px; text-align: left; vertical-align: top; }
.question-table th { background: var(--surface); color: var(--ink); font-weight: 700; }
.options { display: grid; gap: 0; margin-top: 24px; border-top: 1px solid var(--rule); }
.option { display: grid; grid-template-columns: 24px 24px 1fr; align-items: start; gap: 9px; padding: 15px 12px; border-bottom: 1px solid var(--rule); font-size: 16px; line-height: 1.45; cursor: pointer; }
.option:hover { background: var(--surface); }
.option input { margin: 3px 0 0; accent-color: var(--accent); }
.option-letter { color: var(--muted); font-weight: 700; }
.option-text { min-width: 0; }
.option-image { display: block; width: 100%; max-width: 640px; height: auto; margin: 0 0 8px; border: 1px solid var(--rule); background: #fff; }
.option.selected { background: var(--accent-soft); }
.option.correct { box-shadow: inset 3px 0 var(--correct); }
.option.wrong { box-shadow: inset 3px 0 var(--incorrect); }
.matching-bank { margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--rule); }
.matching-bank h3 { margin: 0 0 8px; font-size: 14px; }
.matching-bank ul { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 0 24px; margin: 0; padding: 0; list-style: none; }
.matching-bank li { padding: 8px 0; border-bottom: 1px solid var(--rule); font-size: 15px; line-height: 1.45; }
.written-response { width: 100%; min-height: 96px; margin-top: 16px; border: 1px solid var(--rule); padding: 12px; resize: vertical; line-height: 1.5; background: var(--control); color: var(--body); }
.written-response::placeholder { color: var(--muted); }
.question-tools { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 28px; }
.left-tools, .right-tools { display: flex; align-items: center; gap: 10px; }
.text-button { padding: 8px 0; border: 0; background: transparent; color: var(--accent); font-size: 14px; font-weight: 700; cursor: pointer; }
.text-button.flagged { color: var(--flag); }
.key-feedback { margin-top: 24px; padding: 16px 18px; border-left: 3px solid var(--accent); background: var(--soft); line-height: 1.55; }
.key-feedback h3 { margin: 0 0 3px; font-size: 14px; line-height: 1.3; }
.key-feedback p { margin: 0; color: var(--body); font-size: 14px; white-space: pre-line; }
.key-feedback p + p { margin-top: 10px; }
.key-feedback .answer-map { margin-bottom: 18px; white-space: pre-line; color: var(--ink) !important; font-weight: 700; }
.key-feedback .model-answer { margin-bottom: 18px; }
.key-feedback.unavailable { border-color: var(--flag); }
.results { padding: 56px 0 80px; }
.results h1 { margin-bottom: 12px; }
.score { margin: 22px 0 34px; padding: 18px 0; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--rule); font-size: 18px; }
.score strong { font-size: 30px; margin-right: 10px; }
.result-table { border-top: 1px solid var(--rule); }
.result-row { display: grid; grid-template-columns: 70px 1fr 140px; gap: 14px; align-items: start; padding: 14px 0; border-bottom: 1px solid var(--rule); font-size: 14px; line-height: 1.45; }
.result-row:last-child { border-bottom: 0; }
.result-status { color: var(--muted); }
.result-status.good { color: var(--correct); font-weight: 700; }
.result-status.bad { color: var(--incorrect); font-weight: 700; }
.result-answer { color: var(--muted); white-space: pre-line; }
.result-actions { display: flex; gap: 12px; margin-top: 24px; }

body.on-home .wordmark { display: inline-flex; }

/* Desktop exam view: keep the top bar, paper heading and question navigation
   fixed; only the question pane scrolls. */
@media (min-width: 761px) {
  body.exam-mode {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  body.exam-mode .topbar { flex: none; }
  body.exam-mode .app {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  body.exam-mode .exam-shell {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
  }
  body.exam-mode .exam-head { flex: none; }
  body.exam-mode .exam-grid {
    flex: 1;
    min-height: 0;
  }
  body.exam-mode .question-nav {
    align-self: start;
    max-height: 100%;
    overflow: hidden;
  }
  body.exam-mode .question-area {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 48px;
    overscroll-behavior: contain;
  }
  /* Reserve the scrollbar outside the 760px content column, and only when
     this question actually needs to scroll. */
  body.exam-mode .question-area.is-scrollable {
    width: calc(100% + var(--scrollbar-width, 0px) + 9px);
    max-width: calc(760px + var(--scrollbar-width, 0px) + 9px);
    padding-right: 9px;
  }
}

@media (max-width: 760px) {
  .app { width: min(100% - 32px, 640px); }
  .topbar { height: 56px; padding: 0 16px; gap: 0; }
  .wordmark { width: 40px; min-width: 40px; height: 40px; margin-left: -8px; gap: 0; justify-content: center; }
  .wordmark .back-icon { display: block; width: 24px; height: 24px; }
  .wordmark .home-label { display: none; }
  .header-tools { gap: 16px; }
  .header-actions { gap: 12px; white-space: nowrap; font-size: 12px; }
  .header-actions button { font-size: 12px; white-space: nowrap; }
  .theme-toggle {
    --theme-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z'/%3E%3C/svg%3E");
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; min-width: 40px; height: 40px; margin-right: -8px; padding: 0;
    font-size: 0; line-height: 0; text-decoration: none;
  }
  .theme-toggle:hover { text-decoration: none; }
  .theme-toggle[aria-pressed="true"] {
    --theme-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath d='M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41'/%3E%3C/svg%3E");
  }
  .theme-toggle::before {
    content: ""; width: 24px; height: 24px; background-color: currentColor;
    -webkit-mask: var(--theme-icon) center / contain no-repeat;
    mask: var(--theme-icon) center / contain no-repeat;
  }
  .home { padding: 24px 0 16px; }
  .paper-card { padding: 16px 0; }
  .paper-card:nth-child(-n+2) { border-top: 0; }
  .course-grid [data-course="foundations"] { order: 1; }
  .course-grid [data-course="sh"] { order: 2; }
  .course-grid [data-course="bgda"] { order: 3; }
  .course-grid [data-course="bgdb"] { order: 4; }
  .course-grid [data-course="hma"] { order: 5; }
  .course-grid [data-course="hmb"] { order: 6; }
  .course-grid [data-course="aea"] { order: 7; }
  .course-grid [data-course="aeb"] { order: 8; }
  .course-grid [data-course="eop"] { order: 9; }
  .course-grid [data-course="foundations"],
  .course-grid [data-course="sh"] { border-top: 0; }
  .course-grid [data-course="bgda"] { border-top: 1px solid var(--rule); }
  .paper-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
  .exam-head { align-items: center; gap: 10px; }
  .exam-title { font-size: 15px; white-space: nowrap; }
  .exam-stats { display: flex; flex-wrap: nowrap; gap: 12px; text-align: right; white-space: nowrap; font-size: 12px; }
  .exam-grid { grid-template-columns: 1fr; gap: 22px; padding-top: 20px; }
  .question-nav { border-right: 0; border-bottom: 1px solid var(--rule); padding: 0 0 14px; }
  .nav-title-static { display: none; }
  .nav-toggle { display: flex; align-items: center; justify-content: flex-start; gap: 8px; width: 100%; margin: 0; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 12px; text-transform: uppercase; font-weight: 700; letter-spacing: .06em; cursor: pointer; }
  .question-nav.nav-open .nav-toggle-arrow { transform: rotate(90deg); }
  .question-nav-panel { display: none; padding-top: 12px; }
  .question-nav.nav-open .question-nav-panel { display: block; }
  .number-grid { grid-template-columns: repeat(9, 1fr); }
  .nav-legend { display: flex; gap: 14px; }
  .question-heading { align-items: center; }
  .question-heading .text-button { white-space: nowrap; }
  .question-stem { font-size: 17px; }
  .question-tools { align-items: flex-end; }
  .left-tools, .right-tools { gap: 7px; }
  .button { padding: 0 11px; }
  .result-row { grid-template-columns: 48px 1fr; }
  .result-status { grid-column: 2; }
}
@media (max-width: 420px) {
  .topbar { height: 56px; padding: 0 16px; }
  .paper-card:nth-child(n+2) { border-top: 1px solid var(--rule); }
  .paper-grid { grid-template-columns: 1fr; }
  .number-grid { grid-template-columns: repeat(7, 1fr); }
  .question-tools { flex-wrap: wrap; }
  .right-tools { margin-left: auto; }
  .button { min-height: 38px; font-size: 13px; }
}

/* Landing page, hub navigation and link cards. */
a { color: inherit; }
a:focus-visible, button:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.breadcrumbs, .content { width: min(100% - 48px, 680px); margin-inline: auto; line-height: 1.5; }
.breadcrumbs { display: flex; align-items: center; gap: 9px; min-height: 48px; transform: translateY(14px); overflow: hidden; white-space: nowrap; color: var(--muted); font-size: 17px; }
.nav-spacer { flex: 1; }
.breadcrumbs .text-button:not(.theme-toggle) { border: 0; padding: 0; background: transparent; color: var(--ink); font: inherit; text-decoration: underline; cursor: pointer; }
.crumb { display: block; min-width: 0; max-width: 345px; overflow: hidden; color: var(--ink); text-overflow: ellipsis; text-decoration: underline; }
.crumb[aria-current="page"] { color: var(--body); font-weight: 600; text-decoration: none; cursor: default; }
.content { padding: 28px 0 64px; }
h2 { margin: 34px 0 12px; color: var(--ink); font-size: 18px; font-weight: 600; }
.resource-divider { max-width: 680px; margin: 12px 0 16px; border: 0; border-top: 1px solid var(--line); }
.link-list { display: grid; gap: 10px; max-width: 680px; margin: 4px 0 0; padding: 0; list-style: none; }
.link-card { display: flex; min-height: 54px; align-items: center; border: 2px solid var(--ink); padding: 12px 16px; background: var(--control); color: var(--ink); font-size: 16px; text-decoration: none; transition: background-color 120ms ease; }
.link-card:hover { background: var(--surface); }
@media (max-width: 600px) {
  .breadcrumbs, .content { width: min(100% - 32px, 960px); }
  .content { padding-top: 24px; }
  .crumb { max-width: 46.5vw; }
  .breadcrumbs { min-height: 56px; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
