/* A paper to work on, with a quiet fixed answer card. */
body.exam-open { overflow: hidden; }
.exam-mode {
  --exam-orange: var(--dg-orange, #f97316);
  --exam-paper: var(--color-surface, #fff);
  --exam-ink: var(--color-foreground, #191919);
  --exam-muted: var(--color-foreground-muted, #65655d);
  --exam-line: var(--color-border, #dcdcd3);
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  background: var(--color-canvas, #fafaf7);
  color: var(--exam-ink);
  font: calc(15px * var(--ui-font-scale, 1))/1.6 var(--font-family-ui, sans-serif);
  overflow: hidden;
}
.exam-mode[hidden] { display: none; }
.exam-mode *, .exam-image-zoom * { box-sizing: border-box; }
.exam-mode h1, .exam-mode h2, .exam-mode h3, .exam-mode p, .exam-mode figure, .exam-mode dl { margin: 0; }
.exam-mode h1 { font: 600 clamp(1.6rem, 2.5vw, 2.15rem)/1.5 var(--font-family-serif, serif); overflow-wrap: anywhere; }
.exam-mode h2 { font-size: 1.15em; line-height: 1.6; }
.exam-mode h3 { font-size: 1em; }
.exam-mode [hidden] { display: none !important; }
.exam-mode button, .exam-mode input, .exam-mode textarea, .exam-mode select { font: inherit; }
.exam-mode button, .exam-mode summary, .exam-mode select { cursor: pointer; }
.exam-mode :focus-visible, .exam-image-zoom :focus-visible { outline: 3px solid var(--exam-orange, #f97316); outline-offset: 3px; }
.exam-topbar { display: flex; align-items: center; gap: 20px; padding: 10px 28px; min-height: 65px; border-bottom: 1px solid var(--exam-line); background: var(--exam-paper); flex: 0 0 auto; }
.exam-topbar > strong { font-family: var(--font-family-serif, serif); font-size: 1.2em; }
.exam-topbar > [data-exam-sync] { color: var(--exam-muted); font-size: .85em; margin-left: auto; }
.exam-topbar > [data-exam-sync][data-state="unsynced"] { color: var(--color-warning, #85561b); }
.exam-content { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; scroll-behavior: auto; }
.exam-button { border: 1px solid var(--exam-line, var(--color-border, #dcdcd3)); border-radius: var(--radius-control, 5px); padding: .48em .9em; min-height: 42px; background: var(--exam-paper, var(--color-surface, #fff)); color: inherit; text-align: center; line-height: 1.5; font-weight: 500; }
.exam-button:hover { background: var(--state-hover-bg, #efefe7); }
.exam-button[aria-pressed="true"] { border-color: var(--exam-orange); background: var(--color-brand-soft, #fdf0e0); color: var(--color-brand-text, #c2410c); }
.exam-button:disabled { cursor: default; opacity: .5; }
.exam-primary { background: var(--exam-orange); border-color: var(--exam-orange); color: #191919; font-weight: 650; }
.exam-primary:hover { background: #ea690f; }
.exam-muted, .exam-source { color: var(--exam-muted); font-size: .87em; }
.exam-intro { max-width: 1100px; margin: 0 auto; padding: 48px 36px 70px; }
.exam-intro > h1 { margin: 12px 0; }
.exam-intro > p { max-width: 62em; color: var(--exam-muted); }
.exam-filter { display: grid; gap: 7px; max-width: 420px; margin-top: 26px; font-size: .88em; color: var(--exam-muted); }
.exam-filter input { border: 1px solid var(--exam-line); border-radius: var(--radius-control, 5px); background: var(--exam-paper); color: var(--exam-ink); padding: .55em .7em; }
.exam-paper-list { margin-top: 30px; border-top: 2px solid var(--exam-ink); }
.exam-paper-row { display: flex; align-items: center; gap: 24px; padding: 24px 0; border-bottom: 1px solid var(--exam-line); }
.exam-paper-row > div { flex: 1; min-width: 0; }
.exam-paper-row h2, .exam-paper-row h3 { font-family: var(--font-family-serif, serif); font-size: 1.25em; }
.exam-paper-row p { margin-top: 5px; color: var(--exam-muted); font-size: .9em; }
.exam-paper-row > button { flex: 0 0 auto; }
.exam-mode .exam-history-title { margin-top: 45px; }
.exam-preflight-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--exam-line); }
.exam-preflight-layout > section { min-width: 0; }
.exam-preflight-layout h2 { margin-bottom: 18px; }
.exam-duration { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.exam-mode input[type="number"], .exam-mode select, .exam-mode textarea { border: 1px solid var(--exam-line); border-radius: var(--radius-control, 5px); background: var(--exam-paper); color: var(--exam-ink); padding: .55em .7em; min-width: 0; }
.exam-mode input[type="number"] { width: 105px; }
.exam-mode input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--exam-orange); vertical-align: middle; }
.exam-mode .exam-duration + p { margin-top: 10px; }
.exam-score-details { margin-top: 24px; }
.exam-score-details > summary { padding: 10px 0; }
.exam-score-details summary strong { margin-left: 8px; font-variant-numeric: tabular-nums; }
.exam-score-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.exam-score-grid > label { display: grid; gap: 4px; border-bottom: 1px solid var(--exam-line); padding-bottom: 12px; }
.exam-score-grid small { color: var(--exam-muted); font-size: .8em; }
.exam-profile { display: grid; gap: 12px; }
.exam-profile label { display: grid; gap: 7px; min-width: 0; }
.exam-profile select { width: 100%; text-overflow: ellipsis; }
.exam-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.exam-preflight-foot { display: flex; gap: 24px; align-items: center; justify-content: space-between; padding-top: 28px; margin-top: 35px; border-top: 1px solid var(--exam-line); }
.exam-preflight-foot p { flex: 1; color: var(--exam-muted); font-size: .9em; }
.exam-preflight-foot > button { flex: 0 0 auto; }
.exam-workspace { --exam-rail-width: 250px; max-width: 1400px; padding: 32px calc(var(--exam-rail-width) + 64px) 70px 36px; margin: 0 auto; position: relative; min-height: 100%; }
.exam-reading { min-width: 0; }
.exam-paper-heading { text-align: center; padding: 12px 18px 30px; border-bottom: 2px solid var(--exam-ink); }
.exam-paper-heading > p { color: var(--exam-muted); margin-bottom: 10px; font-size: .88em; }
.exam-paper-heading > div { margin-top: 12px; font-size: .9em; color: var(--exam-muted); }
.exam-view-bar { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 0; }
.exam-sheet { background: var(--exam-paper); padding: 0 30px; border: 1px solid var(--exam-line); border-radius: 2px; min-width: 0; }
.exam-question { padding: 32px 0 36px; border-bottom: 1px solid var(--exam-line); scroll-margin-top: 20px; min-width: 0; }
.exam-question:last-child { border-bottom: 0; }
.exam-question > header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.exam-question > header h2 { font-family: var(--font-family-serif, serif); display: flex; gap: 10px; align-items: baseline; }
.exam-number { font: 500 1.65em/1.1 var(--font-family-serif, serif); }
.exam-question > header small { font-family: var(--font-family-ui, sans-serif); font-size: .75em; font-weight: 400; color: var(--exam-muted); }
.exam-flag { font-size: .8em !important; min-height: 36px; }
.exam-stem, .exam-choice > div, .exam-text-preview, .exam-result-body, .exam-result-options { font-family: var(--font-family-serif, serif); line-height: 1.9; overflow-wrap: anywhere; min-width: 0; }
.exam-mode .exam-stem p + p, .exam-mode .exam-result-body p + p { margin-top: .75em; }
.exam-mode img { max-width: 100%; height: auto; }
.exam-stem img, .exam-result-body img, .exam-text-preview img { display: inline-block; cursor: zoom-in; max-height: 800px; object-fit: contain; }
.exam-mode .katex-display { overflow-x: auto; overflow-y: hidden; max-width: 100%; padding: 3px 0; }
.exam-mode pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.exam-mode table { display: block; overflow-x: auto; max-width: 100%; }
.exam-source { margin-top: 14px !important; }
.exam-choices { display: grid; gap: 10px; margin-top: 24px; }
.exam-choice { display: flex; gap: 14px; align-items: baseline; text-align: left; padding: 13px 16px; border: 1px solid var(--exam-line); border-radius: var(--radius-control, 5px); background: var(--exam-paper); color: var(--exam-ink); width: 100%; min-width: 0; cursor: pointer; }
.exam-choice > span { flex: 0 0 auto; font-weight: 650; font-variant-numeric: tabular-nums; }
.exam-choice > div { min-width: 0; }
.exam-choice:hover { background: var(--state-hover-bg); }
.exam-choice.is-selected { border-color: var(--exam-orange); box-shadow: inset 3px 0 var(--exam-orange); background: var(--color-brand-soft, #fdf0e0); }
.exam-choice:disabled { cursor: default; }
.exam-text-label { display: grid; gap: 9px; margin-top: 26px; font-size: .9em; color: var(--exam-muted); }
.exam-mode textarea { display: block; resize: vertical; width: 100%; line-height: 1.8; }
.exam-mode textarea:disabled { opacity: .8; }
.exam-preview { margin-top: 12px; font-size: .9em; }
.exam-preview summary { color: var(--exam-muted); padding: 4px 0; }
.exam-text-preview { margin-top: 12px; padding: 18px; border-left: 2px solid var(--exam-line); }
.exam-photos { margin-top: 24px; }
.exam-photos h3 { font-family: var(--font-family-ui, sans-serif); font-size: .9em; font-weight: 500; }
.exam-photos h3 small { font-weight: 400; color: var(--exam-muted); margin-left: 10px; }
.exam-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(170px, 100%), 1fr)); gap: 16px; margin: 12px 0; }
.exam-photo-grid figure { border: 1px solid var(--exam-line); border-radius: var(--radius-control); padding: 8px; min-width: 0; }
.exam-photo-grid img { width: 100%; height: 150px; object-fit: contain; background: #fff; cursor: zoom-in; }
.exam-photo-grid figcaption { color: var(--exam-muted); font-size: .75em; margin: 8px 0; overflow-wrap: anywhere; }
.exam-photo-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.exam-photo-grid .exam-button { font-size: .72em !important; padding: .4em .55em; min-height: 35px; }
.exam-upload { display: inline-flex; position: relative; overflow: hidden; align-items: center; justify-content: center; padding: .5em 1em; min-height: 42px; border: 1px dashed var(--exam-line); border-radius: var(--radius-control); font-size: .85em; cursor: pointer; }
.exam-upload:focus-within { outline: 3px solid var(--exam-orange); outline-offset: 3px; }
.exam-upload input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }
.exam-upload.is-disabled { opacity: .5; cursor: default; }
.exam-photos > p { margin-top: 9px; }
.exam-single-nav { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin-top: 22px; font-size: .9em; }
.exam-rail { position: fixed; right: max(36px, calc((100vw - 1400px) / 2 + 36px)); top: 96px; width: var(--exam-rail-width); max-height: calc(100dvh - 120px); overflow-y: auto; padding: 0 0 20px; }
.exam-time { display: grid; gap: 6px; border-top: 3px solid var(--exam-orange); padding: 20px 0; }
.exam-time > span { color: var(--exam-muted); font-size: .85em; }
.exam-time > strong { font-size: 2.1em; font-weight: 550; line-height: 1.25; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.exam-time > strong.is-urgent { color: var(--color-danger, #ac3936); }
.exam-card-panel { padding: 20px 0; border-top: 1px solid var(--exam-line); }
.exam-card-panel h2 { font-size: 1em; }
.exam-card-legend { display: flex; flex-wrap: wrap; gap: 12px; color: var(--exam-muted); font-size: .73em; margin: 14px 0; }
.exam-card-legend > span::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 5px; border: 1px solid var(--exam-line); }
.exam-card-legend > .is-done::before { background: var(--color-brand-soft, #fdf0e0); border-color: var(--exam-orange); }
.exam-card-legend > .is-flagged::before { background: var(--color-warning-soft, #f9efd9); border-color: var(--color-warning, #85561b); border-radius: 50%; }
.exam-card-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }
.exam-card { position: relative; aspect-ratio: 1; min-height: 38px; padding: 3px; border: 1px solid var(--exam-line); border-radius: 3px; background: var(--exam-paper); color: var(--exam-ink); font-variant-numeric: tabular-nums; }
.exam-card.is-done { background: var(--color-brand-soft, #fdf0e0); border-color: var(--exam-orange); }
.exam-card.is-flagged { border-style: dashed; border-color: var(--color-warning, #85561b); }
.exam-card.is-current { outline: 2px solid var(--exam-ink); outline-offset: 1px; }
.exam-card > span { position: absolute; right: 3px; top: -3px; color: var(--color-warning, #85561b); font-weight: bold; }
.exam-card-panel > p { margin-top: 16px; }
.exam-card-toggle { display: none; }
.exam-submit { width: 100%; margin-top: 10px; }
.exam-save-note { color: var(--exam-muted); font-size: .75em; margin-top: 12px !important; }
.exam-notice { padding: 14px 16px; margin: 16px 0 !important; border-left: 3px solid var(--color-warning, #85561b); background: var(--color-warning-soft, #f9efd9); color: var(--color-warning, #85561b); font-size: .9em; }
.exam-conflict { margin: 20px 0; border: 1px solid var(--color-danger, #ac3936); padding: 20px; background: var(--exam-paper); }
.exam-conflict p, .exam-conflict details, .exam-conflict > button { margin-top: 12px; }
.exam-conflict details section { margin: 16px 0; }
.exam-results { max-width: 1060px; margin: 0 auto; padding: 32px 32px 80px; }
.exam-paper-heading .exam-result-score { display: flex; align-items: baseline; justify-content: center; gap: 10px; }
.exam-result-score > strong { font-size: 2.6rem; color: var(--exam-ink); line-height: 1.4; font-variant-numeric: tabular-nums; }
.exam-result-metrics { display: flex; flex-wrap: wrap; justify-content: space-around; gap: 20px; padding: 24px 0; border-bottom: 1px solid var(--exam-line); }
.exam-result-metrics dt { font-size: .8em; color: var(--exam-muted); }
.exam-result-metrics dd { font-size: 1.3em; margin: 5px 0 0; font-variant-numeric: tabular-nums; }
.exam-grading { padding: 26px 0 30px; }
.exam-grading > p { margin: 8px 0 16px; }
.exam-grading .exam-profile { max-width: 620px; }
.exam-grading > .exam-actions { margin-top: 18px; }
.exam-result-body { margin-top: 26px; }
.exam-result-body > section { margin-top: 24px; }
.exam-result-body > section > h3 { font-family: var(--font-family-ui, sans-serif); font-size: .9em; margin-bottom: 10px; }
.exam-result-options { margin-top: 16px; display: grid; gap: 8px; }
.exam-result-options > div { display: flex; gap: 12px; }
.exam-points { font-weight: 500; margin-left: 12px; color: var(--color-brand-text); }
.exam-mark { font-size: .8em; white-space: nowrap; }
.exam-manual { margin-top: 25px; border-top: 1px dashed var(--exam-line); padding-top: 16px; font-size: .9em; }
.exam-manual summary { color: var(--exam-muted); }
.exam-manual form { margin-top: 16px; display: grid; gap: 12px; }
.exam-manual label { display: grid; gap: 7px; }
.exam-manual button { justify-self: start; }
.exam-results > .exam-button { margin-top: 25px; }
.exam-image-zoom { background: var(--color-surface, #fff); color: var(--color-foreground, #191919); border: 1px solid var(--color-border, #dcdcd3); border-radius: 8px; width: min(1200px, 96vw); max-height: 94dvh; padding: 16px; z-index: 1300; }
.exam-image-zoom::backdrop { background: #191919b3; }
.exam-image-zoom button { display: block; margin: 0 0 14px auto; font: inherit; }
.exam-image-zoom img { display: block; max-width: 100%; height: auto; margin: 0 auto; }
@media (max-width: 1000px) {
  .exam-workspace { --exam-rail-width: 200px; padding-left: 22px; padding-right: calc(var(--exam-rail-width) + 44px); }
  .exam-rail { right: 22px; }
  .exam-sheet { padding: 0 23px; }
}
@media (max-width: 740px) {
  .exam-topbar { padding: 9px 14px; gap: 10px; min-height: 62px; }
  .exam-topbar > strong { font-size: 1em; }
  .exam-topbar > [data-exam-sync] { max-width: 44%; font-size: .72em; line-height: 1.4; }
  .exam-topbar > button { padding: .45em .6em; font-size: .8em; white-space: nowrap; }
  .exam-intro { padding: 24px 18px 50px; }
  .exam-paper-row { gap: 14px; align-items: flex-start; flex-wrap: wrap; }
  .exam-paper-row > div { flex-basis: 100%; }
  .exam-paper-row > button { margin-left: auto; }
  .exam-preflight-layout { grid-template-columns: 1fr; gap: 28px; }
  .exam-preflight-foot { flex-direction: column; align-items: stretch; gap: 18px; }
  .exam-workspace { padding: 135px 14px 50px; }
  .exam-paper-heading { padding: 12px 8px 24px; }
  .exam-sheet { padding: 0 18px; }
  .exam-question { padding: 26px 0; scroll-margin-top: 128px; }
  .exam-question > header { gap: 8px; }
  .exam-question > header h2 { font-size: 1em; gap: 8px; }
  .exam-flag { padding: .35em .55em; }
  .exam-choice { padding: 12px; gap: 10px; }
  .exam-rail { position: fixed; top: 62px; left: 0; right: 0; width: auto; max-height: calc(100dvh - 80px); z-index: 2; overflow-y: auto; display: grid; grid-template-columns: 1fr auto auto; gap: 8px 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--exam-line); background: var(--exam-paper); box-shadow: var(--shadow-panel); }
  .exam-time { padding: 0; border-top: none; gap: 0; }
  .exam-time > span { font-size: .7em; }
  .exam-time > strong { font-size: 1.45em; }
  .exam-time > span:last-child { font-size: .68em; }
  .exam-card-toggle { display: block; font-size: .82em; }
  .exam-submit { width: auto; margin: 0; font-size: .82em; }
  .exam-card-panel { grid-row: 2; grid-column: 1 / -1; max-height: 45dvh; overflow-y: auto; padding: 15px 2px 10px; }
  .exam-card-panel[data-expanded="false"] { display: none; }
  .exam-card-panel h2 { display: none; }
  .exam-card-grid { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .exam-card { aspect-ratio: auto; min-height: 40px; }
  .exam-card-panel > p { margin-top: 10px; }
  .exam-save-note { display: none; }
  .exam-results { padding: 22px 14px 50px; }
  .exam-result-metrics { justify-content: flex-start; gap: 18px 25px; }
  .exam-result-metrics > div { min-width: 65px; }
  .exam-result-metrics dd { font-size: 1.15em; }
}
@media (max-width: 380px) {
  .exam-topbar { padding: 8px 10px; }
  .exam-topbar > strong { font-size: .9em; }
  .exam-topbar > [data-exam-sync] { font-size: .65em; }
  .exam-workspace { padding-left: 9px; padding-right: 9px; }
  .exam-sheet { padding: 0 14px; }
  .exam-rail { padding-left: 12px; padding-right: 12px; gap: 8px; }
  .exam-card-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .exam-score-grid { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { .exam-mode *, .exam-mode *::before, .exam-mode *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
