/* ==========================================================================
   ADQS Exam v2 — Student SPA Exam Stylesheet
   Auth cards, question cards, thumb bar, review modal & image lightbox.
   ========================================================================== */

.progress-wrap {
  position: fixed; inset: 0 0 auto 0; height: 4px;
  background: var(--border); z-index: 60;
}
.progress-bar {
  height: 100%; width: 0; background: var(--accent);
  transition: width .35s cubic-bezier(.4, 0, .2, 1);
}

.exam-header {
  position: sticky; top: 0; z-index: 55;
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.exam-header__left { display: flex; flex-direction: column; min-width: 0; }
.exam-header__title {
  font-size: 14px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw;
}
.exam-header__counter { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.exam-header__right { display: flex; align-items: center; gap: 8px; }

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700; font-size: 15px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  min-width: 74px; text-align: center;
}
.timer.is-critical { color: var(--danger); border-color: var(--danger); background: var(--danger-weak); }

.metric-flag {
  font-size: 12px; font-weight: 700; color: var(--warn);
  background: var(--warn-weak); border: 1px solid var(--warn);
  padding: 4px 8px; border-radius: 999px;
}

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0;
  background: var(--surface); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

/* Phase 8.5 — high-contrast text button for the exam top bar. The old `.icon-btn`
   glyph-only controls rendered `--text-muted` on `--surface`; on the light theme
   that is roughly a 1.02 ratio against the page, so the icons "disappeared".
   These carry a real `--surface-btn` fill, a visible `--border-color` stroke and
   `--text-main` ink (>7:1 in every theme). */
.top-nav-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--surface-btn);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  font-family: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s;
}
.top-nav-btn:hover { background: var(--surface-btn-hover); border-color: var(--border-focus); }
.top-nav-btn:disabled { opacity: .55; cursor: not-allowed; }
.top-nav-btn[aria-pressed="true"] {
  background: var(--primary-light); color: var(--primary-hover); border-color: var(--primary);
}
.btn-label { white-space: nowrap; }
/* Below ~560px the labels crowd the timer; the glyph still carries the meaning.
   `.theme-label` is the global header's variant of the same label. */
@media (max-width: 560px) { .top-nav-btn .btn-label, .top-nav-btn .theme-label { display: none; } }

/* Phase 8.5 — exam control cluster in the header. */
.exam-top-bar__controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.timer-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 15px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--surface-btn); border: 1px solid var(--border-color); color: var(--text-main);
  min-width: 74px; justify-content: center;
}
.timer-badge.is-critical { color: var(--danger); border-color: var(--danger); background: var(--danger-weak); }

/* Phase 8.6 — global shell header. Lives OUTSIDE `#examHeader` so the theme
   control exists on the login/roster screen too, where the exam header is
   hidden. Anchored to the top-right of the shell, above the login card but
   BELOW the exam header's own control cluster (z-index 40 < 55), so during an
   exam it simply drops behind the sticky header instead of doubling the
   controls. */
.app-global-header {
  display: flex;
  justify-content: flex-end;
  padding: 8px 16px;
  position: absolute;
  top: 0;
  right: 0;
  z-index: 40;
}

/* ---------- login ---------- */
/* Phase 8.6 — extra top padding reserves the strip occupied by the global
   header's theme button, which floats over the top of the shell on this
   screen. Without it the button overlaps the login card on narrow phones. */
.login { display: flex; justify-content: center; padding-top: 56px; }
.login__card {
  width: 100%; max-width: 460px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 32px 26px;
}
.login__brand {
  width: 52px; height: 52px; margin: 0 auto 18px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: var(--radius); font-weight: 800; font-size: 14px; letter-spacing: .04em;
}
.login__title { margin: 0 0 6px; text-align: center; font-size: 22px; font-weight: 800; }
.login__subtitle { margin: 0 0 24px; text-align: center; color: var(--text-muted); font-size: 13.5px; line-height: 1.6; }
.login__form { display: grid; gap: 14px; }
.login__note { margin: 4px 0 0; text-align: center; color: var(--text-faint); font-size: 12px; line-height: 1.5; }

/* ---------- mode tabs (official vs practice) ---------- */
.mode-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  padding: 5px; margin-bottom: 22px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.mode-tab {
  padding: 11px 10px; border: none; border-radius: 6px;
  background: transparent; color: var(--text-muted);
  font-family: inherit; font-size: 13.5px; font-weight: 700;
  cursor: pointer; transition: background .15s, color .15s;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.is-active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.mode-panel { animation: fadeIn .22s ease-out; }


/* ---------- practice options (Phase 5.9) ---------- */
/* A whole-row <label> keeps the box and text clickable as one target and, being
   a flex row, stays aligned on both desktop and narrow mobile viewports. */
.practice-option {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 13px; margin: 2px 0;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px; line-height: 1.4; color: var(--text);
  cursor: pointer; user-select: none;
  transition: border-color .15s, background .15s;
}
.practice-option:hover { border-color: var(--border-strong); }
.practice-option:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
/* Flex-none so the box never stretches or gets squeezed by the label text. */
.practice-option input[type="checkbox"] {
  flex: none; width: 18px; height: 18px; margin: 0;
  accent-color: var(--accent); cursor: pointer;
}
.practice-option span { min-width: 0; }

/* ---------- practice review ---------- */
.review-list { display: grid; gap: 14px; }
.review-card {
  padding: 18px; text-align: left;
  background: var(--surface); border: 1px solid var(--border);
  border-left-width: 4px; border-radius: var(--radius); box-shadow: var(--shadow);
}
.review-card.is-correct { border-left-color: var(--ok); }
.review-card.is-wrong   { border-left-color: var(--danger); }
.review-card.is-neutral { border-left-color: var(--warn); }
.review-card__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.review-card__verdict { font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 999px; }
.review-card__verdict.is-correct { background: var(--ok-weak); color: var(--ok); }
.review-card__verdict.is-wrong   { background: var(--danger-weak); color: var(--danger); }
.review-card__verdict.is-neutral { background: var(--warn-weak); color: var(--warn); }
.review-card__text { margin: 0 0 12px; font-size: 15.5px; font-weight: 600; line-height: 1.55; }
.review-answer { display: grid; gap: 4px; padding: 9px 0; border-top: 1px solid var(--border); font-size: 13.5px; }
.review-answer__label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }
.review-answer__value { font-weight: 700; }
.review-answer__value.is-correct { color: var(--ok); }
.review-answer__value.is-wrong   { color: var(--danger); }
.review-explanation {
  margin: 10px 0 0; padding: 11px 13px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text-muted);
  font-size: 13px; line-height: 1.65;
}
.practice-badge {
  display: inline-block; margin: 0 auto 14px; padding: 5px 12px; border-radius: 999px;
  background: var(--accent-weak); color: var(--accent-text);
  font-size: 11.5px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase;
}

.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; color: var(--text-muted); }
.field input, .field textarea {
  width: 100%; padding: 12px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 15px; font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.field input::placeholder, .field textarea::placeholder { color: var(--text-faint); }

/* ---------- roster picker (Phase 6.3) ---------- */
/* <select> is not covered by the .field input rule above, so it needs its own
   block to stay visually consistent with the text inputs. */
.field select.form-control {
  width: 100%; padding: 12px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 15px; font-family: inherit; transition: border-color .15s, box-shadow .15s;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
                    linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: calc(100% - 20px) calc(50% - 2px), calc(100% - 14px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 38px;
}
.field select.form-control:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.field select.form-control:disabled { opacity: .55; cursor: not-allowed; }

.hint-text { display: block; margin-top: 2px; color: var(--text-faint); font-size: 12px; line-height: 1.5; }

.roster-status {
  margin: 0; padding: 10px 12px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; line-height: 1.5;
  background: var(--surface-2); color: var(--text-muted);
  border: 1px solid var(--border-strong);
}
.roster-status.is-error { background: var(--danger-weak); color: var(--danger); border-color: var(--danger); }

/* ---------- Phase 8.8: exam-code row + exam identity banner ---------- */

/* The code input and its "Kiểm tra đề" button share one row. `flex` on the
   wrapper rather than a grid so the button keeps its intrinsic width and the
   input absorbs the remainder at every breakpoint. Wraps on narrow screens
   instead of crushing the input below a usable width. */
.input-with-button { display: flex; gap: 8px; align-items: stretch; }
.input-with-button > input { flex: 1 1 auto; min-width: 0; }
.input-with-button > .btn { flex: 0 0 auto; padding-left: 14px; padding-right: 14px; }
@media (max-width: 420px) {
  .input-with-button { flex-wrap: wrap; }
  .input-with-button > .btn { width: 100%; }
}

/* Exam identity, revealed once get_exam_roster() succeeds. `role="status"` in
   the markup means the title is announced when it appears, which is the point:
   the student confirms the paper before picking a name. */
.exam-meta-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 8px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border-strong);
}
.exam-meta-banner__title {
  font-size: 14px; font-weight: 700; color: var(--text);
  /* A long exam title must not push the duration out of the card. */
  min-width: 0; overflow-wrap: anywhere;
}
.exam-meta-banner__status {
  flex: 0 0 auto; font-size: 13px; font-weight: 600; color: var(--text-muted);
  white-space: nowrap;
}

/* Phase 8.10 — the practice variant of the banner carries a VERDICT, not just
   an identity: the same component reports "Cho phép tự luyện" or the server's
   refusal. Colour is the fastest signal, so the whole banner is tinted and the
   status text inherits the semantic colour. Text may be long here (an RPC
   message), so it is allowed to wrap instead of being clamped to one line. */
.exam-meta-banner.is-success { background: var(--ok-weak); border-color: var(--ok); }
.exam-meta-banner.is-success .exam-meta-banner__status { color: var(--ok); }
.exam-meta-banner.is-error { background: var(--danger-weak); border-color: var(--danger); }
.exam-meta-banner.is-error .exam-meta-banner__title { color: var(--danger); }
.exam-meta-banner.is-error .exam-meta-banner__status {
  color: var(--danger); white-space: normal; text-align: right;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 20px; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 15px; font-weight: 700;
  border: 1px solid transparent; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s, opacity .15s;
}
.btn:active:not(:disabled) { transform: scale(.985); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn--ghost { background: var(--surface); color: var(--text-muted); border-color: var(--border-strong); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

/* ---------- alerts ---------- */
.alert {
  margin: 0; padding: 12px 14px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 600; line-height: 1.55; border: 1px solid transparent;
}
.alert--error   { background: var(--danger-weak); color: var(--danger); border-color: var(--danger); }
.alert--info    { background: var(--accent-weak); color: var(--accent-text); border-color: var(--accent); }
.alert--warning { background: var(--warn-weak);   color: var(--warn);   border-color: var(--warn); }
.alert--success { background: var(--ok-weak);     color: var(--ok);     border-color: var(--ok); }

/* ---------- quiz ---------- */
.quiz { max-width: 900px; margin: 0 auto; }
.question-host { padding: 24px 0 12px; }

.q-head { margin-bottom: 18px; }
.q-head__row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.q-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
}
.q-badge--mcq   { background: var(--accent-weak); color: var(--accent-text); }
.q-badge--tf    { background: var(--ok-weak);     color: var(--ok); }
.q-badge--short { background: var(--warn-weak);   color: var(--warn); }
.q-badge--essay { background: var(--surface-2);   color: var(--text-muted); border: 1px solid var(--border); }
.q-badge__index { color: var(--text-faint); font-weight: 700; }

.q-head__tools { margin-left: auto; display: flex; gap: 8px; }

.flag-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; font-size: 12.5px; font-weight: 700;
  background: var(--surface); color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
}
.flag-btn:hover { background: var(--surface-2); color: var(--text); }
.flag-btn.is-on { background: var(--warn-weak); color: var(--warn); border-color: var(--warn); }

.q-text {
  margin: 0; line-height: 1.65; white-space: pre-wrap;
  /* Phase 8.5/8.6 — scaled by the font-size control (--reading-scale). This is
     the ONLY place the question body's size is set: the former 1024px media
     query override has been removed, since it silently defeated the scale. */
  font-size: calc(19px * var(--reading-scale)); font-weight: 700;
}
.q-hint { margin: 10px 0 0; font-size: 12.5px; color: var(--text-faint); }

/* options */
.options { display: grid; gap: 10px; margin-top: 20px; }
.option {
  display: flex; align-items: flex-start; gap: 14px; width: 100%;
  padding: 15px 16px; text-align: left;
  background: var(--surface); color: var(--text);
  border: 2px solid var(--border); border-radius: var(--radius);
  font-family: inherit; font-weight: 600; line-height: 1.55;
  /* Phase 8.6 — the answer options scale with the reading control too, so a
     student who enlarged the question does not have to squint at the choices. */
  font-size: calc(15.5px * var(--reading-scale));
  cursor: pointer; transition: border-color .15s, background .15s;
}
.option:hover:not(:disabled) { border-color: var(--accent); }
.option:disabled { cursor: default; }
.option__key {
  flex: 0 0 auto; width: 30px; height: 30px;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--text-muted);
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 800;
}
.option__label { flex: 1 1 auto; min-width: 0; }
/* Sprint L (audit3 V3) — option/statement markup may contain a diagram. It must
   never widen the card past the viewport, and it stays inside the radio row. */
.option__label img, .tf-item__text img {
  max-width: 100%; max-height: 10rem; display: block;
  margin-top: 0.25rem; border-radius: 0.375rem;
}
.option[aria-checked="true"] { border-color: var(--accent); background: var(--accent-weak); }
.option[aria-checked="true"] .option__key { background: var(--accent); color: #fff; }
/* Phase 8.5 — the auto-advance confirmation beat. The instant highlight is a
   distinct `is-flash` ring, so a student sees the tap register before the 280ms
   jump; the class is removed as soon as the next question paints. */
.option.is-flash { animation: optionFlash .28s ease-out; }
@keyframes optionFlash {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.02); box-shadow: 0 0 0 3px var(--primary-light); }
  100% { transform: scale(1); }
}

/* true/false */
.tf-list { display: grid; gap: 10px; margin-top: 20px; }
.tf-item {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius);
}
.tf-item__label { flex: 0 0 auto; width: 28px; height: 28px; display: grid; place-items: center;
  background: var(--surface-2); border-radius: var(--radius-sm); font-weight: 800; font-size: 13px; color: var(--text-muted); }
.tf-item__text {
  flex: 1 1 220px; min-width: 0; font-weight: 600; line-height: 1.55;
  /* Phase 8.6 — sub-statements scale with the reading control. */
  font-size: calc(15px * var(--reading-scale));
}
.tf-item__choice { display: flex; gap: 8px; }
.tf-choice {
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13.5px; font-weight: 800;
  background: var(--surface); color: var(--text-muted);
  border: 2px solid var(--border-strong); cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.tf-choice:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-text); }
.tf-choice[aria-pressed="true"][data-value="Đ"] { background: var(--ok); border-color: var(--ok); color: #fff; }
.tf-choice[aria-pressed="true"][data-value="S"] { background: var(--danger); border-color: var(--danger); color: #fff; }
.tf-item.is-locked { opacity: .92; }

/* text answers */
.text-answer { margin-top: 20px; }
.text-answer textarea { min-height: 96px; resize: vertical; line-height: 1.65; }
.text-answer--essay textarea { min-height: 200px; }
.text-answer__note { margin: 8px 0 0; font-size: 12.5px; color: var(--warn); font-weight: 600; }

/* Phase 8.5 — sticky bottom navigation ("thumb zone"). Always reachable at the
   foot of the quiz screen so prev/next/finish never require scrolling back up on
   a phone. Full-bleed rather than inset, so the buttons sit in the screen's
   corners where the thumbs actually are. */
.exam-bottom-bar {
  position: sticky; bottom: 0; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; margin: 18px -16px 0;
  background: var(--surface-card);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.05);
  flex-wrap: wrap;
}
.btn-nav-prev, .btn-nav-next, .btn-primary-finish {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 16px; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px; font-weight: 700;
  cursor: pointer; transition: background .15s, border-color .15s, filter .15s;
}
.btn-nav-prev { min-width: 110px; background: var(--surface-btn); color: var(--text-main); border: 1px solid var(--border-color); }
.btn-nav-prev:hover:not(:disabled) { background: var(--surface-btn-hover); border-color: var(--border-focus); }
.btn-nav-prev:disabled { opacity: .5; cursor: not-allowed; }
.btn-nav-next { min-width: 110px; background: var(--primary); color: #fff; border: 1px solid var(--primary); }
.btn-nav-next:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary-finish {
  margin-left: auto; background: var(--success); color: #fff; border: 1px solid var(--success);
}
.btn-primary-finish:hover:not(:disabled) { filter: brightness(1.08); }
/* On the last question the "next" slot is hidden and the finish button takes the
   freed space, so the primary action is always the widest target. */
.exam-bottom-bar.is-last .btn-nav-next { display: none; }
.exam-bottom-bar.is-last .btn-primary-finish { flex: 1 1 auto; }
.auto-advance-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  cursor: pointer; user-select: none; white-space: nowrap;
}
.auto-advance-label input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
@media (max-width: 640px) {
  .exam-bottom-bar { gap: 8px; padding: 10px 12px; }
  .btn-nav-prev, .btn-nav-next { min-width: 0; padding: 10px 12px; }
  .auto-advance-label { order: 10; font-size: 12px; }
  #btn-flag-question { min-width: 48px; min-height: 48px; justify-content: center; }
  #btn-flag-question .btn-label { display: none; }
}

/* Phase 8.5 — question palette drawer (bottom sheet). */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(2, 6, 23, .5); z-index: 998; }
.palette-drawer {
  position: fixed; inset: auto 0 0 0; z-index: 999;
  max-height: 75vh; overflow-y: auto;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  background: var(--surface-card);
  border-top: 2px solid var(--border-focus);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 25px -5px rgb(0 0 0 / 0.2);
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4, 0, .2, 1);
}
.palette-drawer.is-open { transform: translateY(0); }
.palette-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.palette-header h3 { margin: 0; font-size: 15px; font-weight: 800; color: var(--text-main); }
.btn-close-drawer {
  width: 48px; height: 48px; display: grid; place-items: center; padding: 0;
  background: var(--surface-btn); color: var(--text-main);
  border: 1px solid var(--border-color); border-radius: var(--radius-sm);
  font-size: 16px; cursor: pointer;
}
.btn-close-drawer:hover { background: var(--surface-btn-hover); }
.palette-legend {
  display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px;
  font-size: 11.5px; font-weight: 600; color: var(--text-muted);
}
.palette-shortcuts {
  margin: 10px 0 0; font-size: 11.5px; font-weight: 600; color: var(--text-muted);
  line-height: 1.5;
}
/* Keyboard hints mean nothing on a touch-only phone. */
@media (hover: none), (pointer: coarse) { .palette-shortcuts { display: none; } }
.palette-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; border: 1px solid var(--border-color); }
.legend-dot.is-answered { background: var(--success); border-color: var(--success); }
.legend-dot.is-unanswered { background: var(--surface-btn); }
.legend-dot.is-current { outline: 2px solid var(--primary); outline-offset: 1px; background: var(--surface-btn); }
.legend-dot.is-flagged { background: var(--warning); border-color: var(--warning); }
.palette-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 8px; margin-top: 16px;
}
.palette-cell {
  position: relative; aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 0; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px; font-weight: 700;
  background: var(--surface-btn); color: var(--text-muted);
  border: 1px solid var(--border-color); cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.palette-cell:hover { border-color: var(--border-focus); }
.palette-cell.is-answered { background: var(--success); color: #fff; border-color: var(--success); }
.palette-cell.is-current { border: 2px solid var(--primary); outline: 2px solid var(--primary-light); }
.palette-cell.is-flagged::after {
  content: "🚩"; position: absolute; top: -8px; right: -6px; font-size: 12px; line-height: 1;
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: 20px;
  background: rgba(2, 6, 23, .78);
  backdrop-filter: blur(4px);
}
.overlay__card {
  width: 100%; max-width: 430px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 28px 24px; text-align: center;
}
.overlay__icon {
  width: 52px; height: 52px; margin: 0 auto 16px;
  display: grid; place-items: center;
  border-radius: 50%; font-size: 24px; font-weight: 800;
}
.overlay__icon--warn   { background: var(--warn-weak);   color: var(--warn); }
.overlay__icon--danger { background: var(--danger-weak); color: var(--danger); }
.overlay__title { margin: 0 0 10px; font-size: 19px; font-weight: 800; line-height: 1.45; }
.overlay__body  { margin: 0 0 20px; font-size: 14px; color: var(--text-muted); line-height: 1.65; }
.overlay__actions { display: flex; gap: 10px; flex-wrap: wrap; }
.overlay__actions .btn { flex: 1 1 150px; }
.overlay--busy { background: rgba(2, 6, 23, .62); }
.overlay--busy .overlay__body { margin: 0; color: #f8fafc; font-weight: 600; }

/* Phase 8.6 — smart submit confirmation modal.
   Sized as a bottom-sheet-friendly card and theme-aware through the canonical
   tokens, so it is legible in light, dark and sepia alike. */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
.submit-modal-card {
  background: var(--surface-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 440px;
  box-shadow: var(--shadow-md);
}
.submit-modal-card h3 { margin: 0 0 8px; font-size: 19px; font-weight: 800; line-height: 1.4; }
.submit-modal-card p { margin: 0; font-size: 14px; color: var(--text-muted); line-height: 1.6; }
.modal-actions .btn-nav-prev,
.modal-actions .btn-primary-finish { margin-left: 0; }
.unanswered-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
  margin: 12px 0;
  padding: 8px;
  background: var(--surface-btn);
  border-radius: 8px;
}
.unanswered-tag {
  background: var(--warning-light);
  color: var(--warning);
  font-weight: 600;
  font-size: 13px;
  padding: 2px 8px;
  border-radius: 6px;
}

.spinner {
  width: 40px; height: 40px; margin: 0 auto 16px;
  border: 4px solid rgba(248, 250, 252, .25);
  border-top-color: #f8fafc; border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 95; max-width: min(560px, 92vw);
  padding: 12px 18px;
  background: var(--text); color: var(--bg);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  font-size: 13.5px; font-weight: 600; line-height: 1.5;
  animation: fadeIn .2s ease-out;
}

/* ---------- result ---------- */
.result { max-width: 720px; margin: 0 auto; text-align: center; padding-top: 20px; }
.result__ring-wrap { position: relative; width: 190px; height: 190px; margin: 0 auto 22px; }
.result__ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.result__ring-track { fill: none; stroke: var(--border); stroke-width: 13; }
.result__ring-value {
  fill: none; stroke: var(--accent); stroke-width: 13; stroke-linecap: round;
  stroke-dasharray: 540; stroke-dashoffset: 540;
  transition: stroke-dashoffset 1s cubic-bezier(.4, 0, .2, 1);
}
.result__ring-label { position: absolute; inset: 0; display: grid; place-content: center; gap: 2px; }
.result__percent { font-size: 42px; font-weight: 800; line-height: 1; }
.result__percent-caption { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); }

.result__heading { margin: 0 0 8px; font-size: 23px; font-weight: 800; }
.result__score { margin: 0 0 6px; font-size: 16px; font-weight: 700; color: var(--accent-text); }
.result__sub { margin: 0 0 6px; color: var(--text-muted); font-size: 14px; }
.result__pending { margin: 0 0 6px; color: var(--warn); font-size: 13.5px; font-weight: 700; }
.result__elapsed { margin: 0 0 18px; color: var(--text-faint); font-size: 13px; }
.result__ring-value.is-ok     { stroke: var(--ok); }
.result__ring-value.is-warn   { stroke: var(--warn); }
.result__ring-value.is-danger { stroke: var(--danger); }

/* ---------- achievement banner ---------- */
.achievement {
  display: grid; gap: 12px; justify-items: center;
  margin: 4px 0 20px; padding: 20px 18px;
  background: linear-gradient(135deg, var(--ok-weak), var(--accent-weak));
  border: 1px solid var(--ok); border-radius: var(--radius);
  animation: fadeIn .35s ease-out;
}
.achievement__icon { font-size: 34px; line-height: 1; }
.achievement__text { margin: 0; font-size: 15.5px; font-weight: 800; color: var(--ok); }

/* ---------- certificate modal ---------- */
.cert-overlay { z-index: 98; }
.cert-dialog {
  width: 100%; max-width: 1040px; max-height: 94vh;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 16px;
}
.cert-dialog__bar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
}
.cert-dialog__title { margin: 0; font-size: 17px; font-weight: 800; }
.cert-dialog__actions { display: flex; gap: 10px; flex-wrap: wrap; }
.cert-dialog__actions .btn { padding: 10px 16px; font-size: 14px; }

/* A4 landscape: 297 x 210 mm. */
.cert-sheet {
  position: relative;
  width: 100%; aspect-ratio: 297 / 210;
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 3%;
  padding: 5%;
  background: #fffdf7; color: #1a1a2e;
  border: 2px solid #c9a227; border-radius: var(--radius-sm);
  overflow: hidden;
}
.cert-sheet__frame { min-width: 0; text-align: center; }
.cert-sheet__org {
  margin: 0 0 2%; font-size: clamp(10px, 1.4vw, 15px); font-weight: 800;
  letter-spacing: .28em; color: #8a6d16; text-transform: uppercase;
}
.cert-sheet__title {
  margin: 0 0 3%; font-size: clamp(20px, 3.4vw, 40px); font-weight: 800;
  letter-spacing: .06em; color: #1a1a2e;
}
.cert-sheet__lead { margin: 0 0 1%; font-size: clamp(9px, 1.2vw, 14px); color: #6b7280; }
.cert-sheet__name {
  margin: 0 0 2%; font-size: clamp(20px, 3.6vw, 42px); font-weight: 800; color: #b45309;
  border-bottom: 2px solid #c9a227; display: inline-block; padding: 0 4% 1%;
}
.cert-sheet__exam { margin: 0 0 4%; font-size: clamp(11px, 1.7vw, 20px); font-weight: 700; color: #1a1a2e; }

.cert-sheet__meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 3%;
  margin-top: 3%; border-top: 1px solid #e5d9a8; padding-top: 3%;
}
.cert-sheet__meta-item { display: grid; gap: 2px; }
.cert-sheet__meta-label {
  font-size: clamp(7px, .95vw, 11px); font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: #9ca3af;
}
.cert-sheet__meta-value { font-size: clamp(10px, 1.3vw, 16px); font-weight: 700; color: #1a1a2e; }

.cert-sheet__qr { display: grid; gap: 6px; justify-items: center; }
.cert-qr { padding: 8px; background: #fff; border: 1px solid #e5d9a8; border-radius: 6px; line-height: 0; }
.cert-qr img, .cert-qr canvas { display: block; width: clamp(72px, 13vw, 150px); height: auto; }
.cert-sheet__qr-caption {
  margin: 0; font-size: clamp(7px, .95vw, 11px); font-weight: 700;
  color: #6b7280; text-align: center;
}

/* ---------- print: isolate the certificate on one A4 landscape page ---------- */
@media print {
  @page { size: A4 landscape; margin: 0; }

  html, body { background: #fff !important; }

  /* Hide every direct body child except the certificate overlay. */
  body > *:not(#certOverlay) { display: none !important; }

  .no-print { display: none !important; }

  #certOverlay {
    position: static !important; inset: auto !important;
    display: block !important; padding: 0 !important;
    background: none !important; backdrop-filter: none !important;
  }
  .cert-dialog {
    display: block !important; max-width: none !important; max-height: none !important;
    width: auto !important; padding: 0 !important; gap: 0 !important;
    background: none !important; border: none !important; box-shadow: none !important;
  }
  .cert-sheet {
    width: 297mm !important; height: 210mm !important;
    aspect-ratio: auto !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}

/* ---------- responsive ---------- */
@media (min-width: 1024px) {
  .app { padding: 28px 24px 56px; }
  .question-host { padding-top: 32px; }
  /* Phase 8.6 — the desktop override that hard-coded `.q-text { font-size: 21px }`
     is GONE. It silently beat `--reading-scale`, which is exactly why the font
     button appeared dead on wide screens: the base size grew but the media
     query pinned the rendered size. The scaled rule below is the only source. */
  .exam-header__title { max-width: 60vw; }
}

@media (max-width: 560px) {
  .exam-header { padding: 0 12px; gap: 8px; }
  .exam-header__title { max-width: 34vw; font-size: 13px; }
  .metric-flag { display: none; }
  .tf-item__choice { width: 100%; }
  .tf-choice { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}


/* Question image styling (Phase 11.3) */
.question-img {
  max-width: 100%;
  max-height: 420px;
  height: auto;
  border-radius: 8px;
  cursor: zoom-in;
  margin: 12px 0;
  display: block;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.question-img:hover {
  transform: scale(1.01);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
}

/* Inline math from Word equations (Phase 23.0) */
.math-inline {
  display: inline;
  white-space: nowrap;
  font-family: 'Cambria Math', 'STIX Two Math', 'Times New Roman', serif;
}

.math-inline sup,
.math-inline sub {
  font-size: 0.72em;
  line-height: 0;
}

.math-block {
  display: block;
  margin: 8px 0;
  text-align: center;
  font-family: 'Cambria Math', 'STIX Two Math', 'Times New Roman', serif;
}

.math-overline {
  border-top: 1px solid currentColor;
  padding-top: 1px;
}

/* Image Lightbox Modal */
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}

.lightbox-close-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
  z-index: 2;
}

.lightbox-close-btn:hover {
  background: rgba(255, 255, 255, 0.32);
  transform: scale(1.08);
}

.lightbox-content {
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  touch-action: pan-x pan-y pinch-zoom;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 86vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

/* =====================================================================
   Phase 19.0 — Responsive Question Tables
   ===================================================================== */
.question-table-wrapper {
  width: 100%;
  overflow-x: auto;
  margin: 12px 0;
  border-radius: 8px;
  border: 1px solid var(--border-color, #cbd5e1);
  background: var(--surface-card, #ffffff);
  -webkit-overflow-scrolling: touch;
}
.question-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95em;
  line-height: 1.5;
  text-align: left;
}
.question-table th,
.question-table td {
  padding: 8px 12px;
  border: 1px solid var(--border-color, #cbd5e1);
  vertical-align: top;
}
.question-table th {
  background: rgba(37, 99, 235, 0.08);
  font-weight: 700;
}
.question-table tr:nth-child(even) td {
  background: rgba(148, 163, 184, 0.05);
}


/* ---------------------------------------------------------------------------
   Phase 22.2 — submission receipt (result screen)
   --------------------------------------------------------------------------- */
.receipt-card {
  margin: 18px 0;
  padding: 16px 18px;
  border: 1px dashed var(--border, #cbd5e1);
  border-radius: 14px;
  background: var(--surface-2, #f8fafc);
  text-align: left;
}
.receipt-card__title { margin: 0 0 10px; font-size: 15px; font-weight: 800; }
.receipt-card__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px 16px;
  margin: 0;
}
.receipt-card__grid dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted, #64748b);
}
.receipt-card__grid dd { margin: 2px 0 0; font-size: 14px; font-weight: 700; word-break: break-word; }
.receipt-card__wide { grid-column: 1 / -1; }
.receipt-card__wide dd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .12em; }
.receipt-card__hint { margin: 10px 0 0; font-size: 12px; color: var(--text-muted, #64748b); line-height: 1.5; }
