  body { min-height: 100vh; }
  .qm-wrap { padding: 32px 44px 80px; max-width: 920px; margin: 0 auto; width: 100%; }

  /* Phase containers */
  .phase { display: none; }
  @keyframes phase-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
  .phase.active { display: block; animation: phase-in 260ms var(--ease) both; }

  /* ===== Phase 1: mode picker ===== */

  .qm-title {
    font-size: 38px; line-height: 1.05; letter-spacing: -0.028em;
    font-weight: 600; margin: 0 0 36px;
    color: var(--ink);
  }

  .mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .mode-tile {
    background: var(--bg-2); border: 1px solid var(--rule-soft);
    border-radius: var(--r-md); padding: 20px 22px;
    cursor: pointer;
    display: flex; flex-direction: column; gap: 8px;
    min-height: 150px;
    transition: background 200ms var(--ease), border-color 200ms var(--ease);
  }
  .mode-tile:hover { background: var(--bg-3); border-color: color-mix(in srgb, var(--accent) 25%, var(--rule)); }
  .mode-tile .mn { font-size: 10px; color: var(--ink-muted); letter-spacing: 0.14em; font-weight: 600; text-transform: uppercase; }
  .mode-tile .mt { font-size: 19px; line-height: 1.2; letter-spacing: -0.015em; font-weight: 600; margin-top: 4px; }
  .mode-tile .md { font-size: 12.5px; color: var(--ink-muted); max-width: 38ch; line-height: 1.5; }
  .mode-tile .arrow { margin-top: auto; font-size: 12.5px; font-weight: 500; color: var(--ink); }

  /* ===== Phase 2: setup ===== */
  .setup-title {
    font-size: 36px; line-height: 1.04; letter-spacing: -0.025em;
    font-weight: 600; margin: 0 0 22px;
  }
  

  /* Flat baseline row, not boxed tiles — a grid of bordered cards reads as
     template dashboard filler for four numbers. */
  .stat-grid { display: flex; flex-wrap: wrap; gap: 8px 32px; margin-bottom: 26px; }
  .stat-tile { display: flex; align-items: baseline; gap: 10px; }
  
  

  .setup-card {
    background: var(--bg-2); border: 1px solid var(--rule-soft);
    border-radius: var(--r-md); padding: 18px 22px;
  }
  .setup-row { display: flex; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--rule-soft); }
  .setup-row:first-child { padding-top: 0; }
  .setup-row:last-child { border-bottom: 0; padding-bottom: 0; }
  .setup-row .lbl { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; color: var(--ink-muted); min-width: 100px; }
  .setup-row .val { flex: 1; display: flex; }

  .seg {
    display: inline-flex; gap: 0;
    background: transparent;
    border: 1px solid var(--rule-soft);
    border-radius: var(--r-pill);
    padding: 3px;
    background: var(--bg);
    flex: 1;
    justify-content: space-between;
  }
  .seg button {
    flex: 1;
    padding: 8px 16px;
    border-radius: var(--r-pill);
    font-size: 12px; font-weight: 500;
    color: var(--ink-muted);
    transition: background 160ms var(--ease), color 160ms var(--ease);
    white-space: nowrap;
  }
  .seg button.on { background: var(--ink); color: var(--bg); }

  .selection-row {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--rule-soft);
  }
  
  
  
  .selection-row .sel-lbl {
    font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
    font-weight: 600; color: var(--ink-muted);
  }
  .selection-row .sel-val { font-size: 13px; color: var(--ink); margin-top: 4px; }

  /* Multi-select chip rows (modules / types / difficulty) */
  .ms-row { display: flex; flex-wrap: wrap; gap: 6px; }
  .ms-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px;
    background: var(--bg); border: 1px solid var(--rule-soft);
    border-radius: var(--r-pill);
    font-size: 12px; font-weight: 500;
    color: var(--ink-soft);
    cursor: pointer;
    transition: background var(--dur-base) var(--ease-fluid), border-color var(--dur-base) var(--ease-fluid), color var(--dur-base) var(--ease-fluid);
    font-family: var(--sans);
  }
  .ms-chip:hover { background: var(--bg-3); }
  .ms-chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
  .ms-chip .check { display: none; }
  .ms-chip.on .check { display: inline; font-size: 10px; opacity: 0.85; }

  /* Dotpoint multi-select grid (expands per selected module) */
  .dp-section { margin-top: 14px; }
  .dp-section:first-child { margin-top: 0; }
  .dp-section .dpmod-lbl { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; font-size: 11px; }
  .dp-section .dpmod-lbl .nm { font-weight: 600; color: var(--ink); letter-spacing: 0.02em; }
  .dp-section .dpmod-lbl .ct { color: var(--ink-muted); }
  .dp-section .dpmod-lbl .actions { display: flex; gap: 8px; font-size: 10.5px; }
  .dp-section .dpmod-lbl .actions span { color: var(--ink-muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--ink-faint); }
  .dp-section .dpmod-lbl .actions span:hover { color: var(--ink); }
  .dp-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 6px;
    background: var(--bg);
    border: 1px solid var(--rule-soft);
    border-radius: var(--r-sm);
    padding: 8px;
  }
  .dp-card {
    display: flex; align-items: center; gap: 8px;
    padding: 9px 12px;
    background: var(--bg-2); border: 1px solid var(--rule-soft);
    border-radius: var(--r-sm);
    font-size: 11.5px; line-height: 1.35;
    color: var(--ink-soft);
    cursor: pointer;
    transition: background var(--dur-base) var(--ease-fluid), border-color var(--dur-base) var(--ease-fluid), color var(--dur-base) var(--ease-fluid);
    user-select: none;
  }
  .dp-card:hover { background: var(--bg-3); }
  .dp-card.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
  .dp-card .ix { font-size: 9.5px; font-weight: 600; color: var(--ink-faint); letter-spacing: 0.04em; }
  .dp-card.on .ix { color: var(--bg); opacity: 0.6; }
  .dp-card .dp-name { flex: 1; }
  .dp-empty { padding: 22px; text-align: center; font-size: 12px; color: var(--ink-muted); background: var(--bg); border: 1px dashed var(--rule-soft); border-radius: var(--r-sm); }
  .gen-btn {
    background: var(--ink); color: var(--bg);
    border: 0;
    padding: 11px 22px;
    border-radius: var(--r-pill);
    font-size: 13px; font-weight: 500;
    cursor: pointer;
    transition: filter 160ms var(--ease), transform 180ms var(--ease);
  }
  .gen-btn:hover { background: var(--ink-soft); }
  .gen-btn:active { transform: translateY(1px); }

  /* ===== Phase 3: question ===== */
  .q-back-link { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--ink-faint); margin-bottom: 16px; transition: color 160ms var(--ease); }
  .q-back-link:hover { color: var(--ink); }

  .q-card {
    background: var(--bg-2); border: 1px solid var(--rule-soft);
    border-radius: var(--r-md); padding: 22px 26px;
    margin-bottom: 14px;
  }
  /* Plain metadata line, not chip pills: "Mod 5 · Hard · Short Answer". */
  .q-tags { display: flex; align-items: center; flex-wrap: wrap; margin-bottom: 14px; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 600; color: var(--ink-muted); }
  .q-tag { background: none; border: none; padding: 0; color: inherit; font: inherit; }
  .q-tag + .q-tag::before { content: "·"; margin: 0 9px; color: var(--ink-faint); font-weight: 400; }
  .q-stem { font-size: 14px; line-height: 1.6; color: var(--ink); margin: 0; }
  .q-stem .hl { background: color-mix(in srgb, var(--accent) 16%, transparent); padding: 0 3px; border-radius: 3px; }
  /* The body uses text-rendering:optimizeLegibility, which switches on the font
     ligatures that paint "(c)"→©, "(r)"→®, "(tm)"→™. Disable them wherever question /
     answer / model text is shown so part labels like "(c)" render as three glyphs. */
  .q-stem, .dfs-q-stem, .model-text, .sa-text, #res-student-answer,
  .res-mcq-stem, .res-mcq-opt, .crit-table td, .qpart-line, .qpart-intro {
    font-feature-settings: "liga" 0, "clig" 0, "dlig" 0, "hlig" 0, "calt" 0;
    font-variant-ligatures: none;
  }
  /* Graph Lab "Question testing", before/after editor's note (not student-facing) */
  .q-editor-note { background: color-mix(in srgb, var(--accent) 7%, var(--bg)); border: 1px solid var(--rule-soft); border-radius: var(--r-sm, 8px); padding: 12px 14px; margin-bottom: 16px; font-size: 12.5px; line-height: 1.55; color: var(--ink-soft); }
  .q-editor-note .en-label { display: inline-block; font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; font-weight: 600; color: var(--accent); margin-bottom: 6px; }
  .q-editor-note .en-tags { display: flex; gap: 6px; flex-wrap: wrap; margin: 2px 0 8px; }
  .q-editor-note .en-tag { font-size: 10px; padding: 2px 8px; border-radius: var(--r-pill); background: var(--bg-2); border: 1px solid var(--rule-soft); color: var(--ink-soft); font-weight: 500; }
  .q-editor-note .en-row { margin: 4px 0; }
  .q-editor-note .en-row b { color: var(--ink); font-weight: 600; }
  .q-editor-note .en-before { color: var(--ink-muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--ink-muted) 55%, transparent); }
  .q-stem .marks { font-size: 12px; color: var(--ink-muted); font-weight: 500; margin-left: 6px; }

  .answer-card {
    background: var(--bg-2); border: 1px solid var(--rule-soft);
    border-radius: var(--r-md); padding: 18px 22px;
    margin-bottom: 14px;
  }
  .answer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
  .ans-tabs { display: inline-flex; gap: 4px; background: var(--bg); border-radius: var(--r-pill); padding: 3px; border: 1px solid var(--rule-soft); }
  .ans-tabs button { padding: 7px 16px; border-radius: var(--r-pill); font-size: 12px; font-weight: 500; color: var(--ink-muted); }
  .ans-tabs button.on { background: var(--ink); color: var(--bg); }
  .ans-toolbar { display: inline-flex; gap: 2px; }
  .ans-toolbar button {
    width: 28px; height: 28px;
    border-radius: 6px;
    font-size: 12px;
    color: var(--ink-muted);
    font-weight: 500;
    transition: background 140ms var(--ease), color 140ms var(--ease);
  }
  .ans-toolbar button:hover { background: var(--panel); color: var(--ink); }
  .ans-toolbar button.on { background: color-mix(in srgb, var(--accent) 16%, var(--bg-2)); color: var(--accent); }
  .ans-toolbar .div { width: 1px; background: var(--rule-soft); margin: 0 4px; height: 18px; align-self: center; }
  .ans-toolbar button.smart-btn { width: auto; padding: 0 10px; font-size: 11.5px; letter-spacing: 0.01em; }

  .ans-area {
    width: 100%; min-height: 180px;
    border: 1px solid var(--rule-soft);
    background: var(--bg);
    border-radius: var(--r-sm);
    padding: 14px 16px;
    font-family: var(--sans);
    font-size: 15px; line-height: 1.6;
    color: var(--ink);
    outline: none;
    resize: vertical;
  }
  .ans-area:focus { border-color: color-mix(in srgb, var(--accent) 55%, var(--rule)); }
  .ans-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }
  .ans-foot .ch { font-size: 11px; color: var(--ink-muted); }

  /* ===== Multi-part question navigator ===== */
  /* Answer foot button group, single-part questions show only the submit button. */
  .ans-foot-btns { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
  .gen-btn.ghost { background: transparent; color: var(--ink-soft); box-shadow: none; border: 1px solid var(--rule); }
  .gen-btn.ghost:disabled { opacity: 0.38; cursor: default; pointer-events: none; }

  /* The A·b·c·d toggle rail between the question and answer panels. */
  body.qm-has-parts #q-part-rail { display: flex; }
  body.qm-has-parts.qm-layout-side #q-part-rail { flex-direction: column; align-self: center; padding: 0 2px; }   /* gutter strip */
  body.qm-has-parts:not(.qm-layout-side) #q-part-rail { flex-direction: row; padding: 2px 0 12px; }                /* stacked strip */

  /* Stem lines: prose stacks naturally; a chemical equation gets its own
     centred line, the way the exam paper sets one out. */
  /* .stem-line / .stem-eq / .stem-gap and the one table style live in
     ionik-q-format.css, shared with every page that shows a question. */

  /* Clickable part lines inside the stem. */
  .qpart-intro { display: block; margin-bottom: 9px; }
  .qpart-line { display: block; padding: 3px 7px; margin: 1px -7px; border-radius:var(--r-sm); cursor: pointer; transition: background 160ms var(--ease-sharp); }
  .qpart-line:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
  .qpart-line.on { background: color-mix(in srgb, var(--accent) 13%, transparent); }
  .qpart-tag { font-weight: 600; color: var(--ink); margin-right: 5px; }
  .qpart-line.on .qpart-tag { color: var(--accent); }
  .qpart-mode { display: inline-block; margin-left: 6px; font-size: 10px; font-weight: 600; color: var(--accent); background: color-mix(in srgb, var(--accent) 13%, transparent); border-radius: 999px; padding: 1px 7px; vertical-align: middle; letter-spacing: .02em; }
  /* When parts choose their own input (draw vs write), hide the manual answer tabs. */
  body.qm-part-modes .ans-tabs { display: none; }

  /* Question action bar, two pill groups (left: controls, right: tools) */
  .q-actionbar { display: flex; align-items: center; justify-content: space-between; width: 100%; margin-top: 14px; }
  .q-actionbar .ab-group { display: inline-flex; gap: 4px; align-items: center; background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-pill); padding: 5px; }
  .q-actionbar .ab { width: 32px; height: 32px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-muted); cursor: pointer; transition: background 140ms var(--ease), color 140ms var(--ease); }
  .q-actionbar .ab:hover { background: var(--panel); color: var(--ink); }
  .q-actionbar .ab.on { background: color-mix(in srgb,var(--accent) 14%,var(--bg-2)); color: var(--accent); }
  .q-actionbar .ab.next { background: var(--ink); color: var(--bg); width: auto; padding: 0 14px; gap: 6px; font-size: 12px; font-weight: 500; border-radius: var(--r-pill); }
  .q-actionbar .ab.next:hover { background: var(--ink-soft); }
  .q-actionbar .div { width: 1px; height: 18px; background: var(--rule-soft); margin: 0 3px; align-self: center; }
  /* Long questions: pin the action bar to the bottom of the viewport so its tools
     (layout toggle, star/heart, skip) are always reachable without scrolling
     to the very end. Exam mode keeps its own fixed footer. */
  body:not(.exam-mode) .q-actionbar {
    position: sticky; bottom: 0; z-index: 30; margin-top: 10px;
    padding: 10px 0 6px; background: linear-gradient(to top, var(--bg) 58%, transparent);
  }

  @keyframes sc-in { from { opacity:0; transform:translateY(12px) scale(0.97); } to { opacity:1; transform:none; } }
  
  /* Toggle switch */
  .fm-toggle { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
  .fm-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
  .fm-toggle .slider { position: absolute; inset: 0; background: var(--rule); border-radius: 999px; cursor: pointer; transition: background 200ms var(--ease); }
  .fm-toggle .slider::before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 999px; transition: transform 200ms var(--ease); }
  .fm-toggle input:checked + .slider { background: var(--ink); }
  .fm-toggle input:checked + .slider::before { transform: translateX(18px); }

  /* Periodic table grid */
  .pt-wrap { overflow-x: auto; padding-bottom: 4px; }
  .pt-grid { display: grid; grid-template-columns: repeat(18, 1fr); gap: 2px; min-width: 480px; }
  .pt-cell { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2px 1px; border-radius: 3px; border: 1px solid var(--rule-soft); min-height: 36px; cursor: default; position: relative; transition: border-color 120ms, z-index 0ms; }
  .pt-cell:hover { border-color: var(--accent); z-index: 2; box-shadow:var(--shadow-sm); }
  .pt-z   { font-size: 5.5px; color: var(--ink-muted); align-self: flex-start; margin-left: 2px; line-height: 1; }
  .pt-sym { font-size: 11px; font-weight: 700; color: var(--ink); line-height: 1.3; }
  .pt-m   { font-size: 5px; color: var(--ink-muted); line-height: 1; margin-top: 1px; max-width: 100%; overflow: hidden; text-overflow: clip; }
  .pt-placeholder { font-size: 7px; font-weight: 600; color: var(--ink-muted); justify-content: center; align-items: center; }
  .pt-gap { grid-column: 1 / -1; height: 4px; }
  .pt-cell:not(.pt-placeholder) { background: var(--bg-2); }
  .pt-placeholder { font-size: 6.5px; }
  .pt-row-lbl { font-size: 8px; color: var(--ink-muted); display: flex; align-items: center; letter-spacing: 0.02em; }

  /* ===== Floating Calculator ===== */
  .calc-float { position: fixed; top: 80px; right: 24px; z-index: 8500; display: none; flex-direction: column; background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-lg); box-shadow:var(--shadow-lg); width: calc(var(--calc-scale, 1) * 280px); user-select: none; }
  .calc-float.open { display: flex; }
  .calc-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--rule-soft); cursor: grab; border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .calc-head:active { cursor: grabbing; }
  .calc-head .ch-title { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
  .calc-head .ch-ctrl { display: flex; gap: 4px; }
  .calc-head .ch-btn { width: 22px; height: 22px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: var(--ink-muted); cursor: pointer; transition: background 120ms; }
  .calc-head .ch-btn:hover { background: var(--panel); color: var(--ink); }
  .calc-disp { padding: 10px 14px 6px; text-align: right; }
  .calc-expr { font-size: calc(var(--calc-scale, 1) * 10px); color: var(--ink-muted); min-height: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .calc-val { font-size: calc(var(--calc-scale, 1) * 22px); font-weight: 500; letter-spacing: -0.02em; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .calc-grid { display: grid; padding: 6px 8px 10px; gap: 4px; }
  .calc-row { display: grid; gap: 4px; }
  .calc-btn { height: calc(var(--calc-scale, 1) * 34px); border-radius: var(--r-sm); display: flex; align-items: center; justify-content: center; font-size: calc(var(--calc-scale, 1) * 12px); font-weight: 500; color: var(--ink-soft); background: var(--bg); border: 1px solid var(--rule-soft); cursor: pointer; transition: background 100ms, transform 80ms; }
  .calc-btn:hover { background: var(--bg-3); color: var(--ink); }
  .calc-btn:active { transform: scale(0.93); }
  .calc-btn.op { background: var(--bg-2); color: var(--ink); }
  .calc-btn.eq { background: var(--accent); color: #fff; border-color: var(--accent); }
  .calc-btn.eq:hover { filter: brightness(1.1); }
  .calc-btn.fn { font-size: calc(var(--calc-scale, 1) * 10.5px); color: var(--ink-muted); }
  .calc-btn.clr { color: var(--r-red); }

  /* ===== Data Sheet Panel ===== */
  .ds-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 92vw); background: var(--bg-2); border-left: 1px solid var(--rule-soft); z-index: 8000; display: flex; flex-direction: column; transform: translateX(100%); transition: transform 320ms cubic-bezier(0.22,1.5,0.36,1); box-shadow:var(--shadow-lg); }
  .ds-panel.open { transform: translateX(0); }
  .ds-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--rule-soft); flex-shrink: 0; }
  .ds-head h3 { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
  .ds-close { width: 28px; height: 28px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-muted); cursor: pointer; transition: background 140ms; }
  .ds-close:hover { background: var(--panel); color: var(--ink); }
  .ds-tabs { display: flex; gap: 0; padding: 8px 12px; border-bottom: 1px solid var(--rule-soft); flex-shrink: 0; overflow-x: auto; scrollbar-width: none; }
  .ds-tabs::-webkit-scrollbar { display: none; }
  .ds-tab { padding: 6px 12px; border-radius: var(--r-pill); font-size: 11.5px; font-weight: 500; color: var(--ink-muted); cursor: pointer; white-space: nowrap; transition: background 140ms, color 140ms; }
  .ds-tab.on { background: var(--ink); color: var(--bg); }
  .ds-tab:hover:not(.on) { background: var(--bg-3); color: var(--ink); }
  .ds-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
  /* Data sheet content styles */
  .ds-section { margin-bottom: 22px; }
  .ds-section h4 { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 600; color: var(--ink-muted); margin: 0 0 10px; }
  .ds-formula { display: flex; align-items: baseline; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--rule-soft); font-size: 13px; }
  .ds-formula .sym { font-weight: 600; color: var(--ink); font-family: ui-monospace, monospace; min-width: 180px; }
  .ds-formula .desc { color: var(--ink-muted); font-size: 12px; }
  .ds-const { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--rule-soft); font-size: 12.5px; }
  .ds-const .ck { color: var(--ink-muted); }
  .ds-const .cv { font-weight: 500; color: var(--ink); font-family: ui-monospace, monospace; font-size: 12px; }
  .ds-fgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .ds-f { display: flex; align-items: center; min-height: 52px; padding: 10px 14px; background: var(--bg); border: 1px solid var(--rule-soft);
    border-radius: var(--r-sm); font-family: Georgia, 'Times New Roman', serif; font-size: 15px; color: var(--ink); white-space: nowrap; }
  .ds-frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; margin: 0 3px; line-height: 1.15; font-size: 0.9em; }
  .ds-frac > span:first-child { border-bottom: 1px solid currentColor; padding: 0 3px 1px; }
  .ds-frac > span:last-child { padding: 1px 3px 0; }
  .ds-kv { background: var(--bg); border: 1px solid var(--rule-soft); border-radius: var(--r-sm); }
  .ds-kv-row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 9px 14px; font-size: 12.5px; }
  .ds-kv-row + .ds-kv-row { border-top: 1px solid var(--rule-soft); }
  .ds-kv-row .k { color: var(--ink-muted); }
  .ds-kv-row .v { color: var(--ink); font-weight: 500; white-space: nowrap; font-variant-numeric: tabular-nums; }
  .ds-ksp { column-count: 2; column-gap: 8px; }
  .ds-ksp-card { break-inside: avoid; margin-bottom: 8px; padding: 9px 12px; background: var(--bg); border: 1px solid var(--rule-soft); border-radius: var(--r-sm); }
  .ds-ksp-ion { font-size: 12.5px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
  .ds-ksp-row { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; font-size: 12px; color: var(--ink-muted); }
  .ds-ksp-row .v { color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .ds-pot { background: var(--bg); border: 1px solid var(--rule-soft); border-radius: var(--r-sm); padding: 4px 0; }
  .ds-pot-row { display: grid; grid-template-columns: minmax(0, 1.25fr) 22px minmax(0, 1fr) 62px; align-items: baseline; padding: 3.5px 14px; font-size: 12.5px; color: var(--ink); }
  .ds-pot-row:hover { background: var(--bg-3); }
  .ds-pot-row .eq { text-align: center; color: var(--ink-muted); }
  .ds-pot-row .v { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .ds-note { font-size: 11px; font-style: italic; color: var(--ink-muted); margin: -4px 0 8px; }
  .ds-ring { vertical-align: middle; color: var(--ink); }
  @media (max-width: 520px) { .ds-fgrid { grid-template-columns: 1fr; } .ds-ksp { column-count: 1; } }
  .ds-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
  .ds-table th { background: var(--bg); padding: 6px 8px; text-align: left; font-size: 11px; letter-spacing: 0; text-transform: none; font-weight: 600; color: var(--ink-muted); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 1; }
  .ds-table td { padding: 5px 8px; border-bottom: 1px solid var(--rule-soft); color: var(--ink); }
  .ds-table tr:hover td { background: var(--bg-3); }
  

  /* ===== Phase 4: result ===== */
  .res-score {
    font-size: 64px; line-height: 1; letter-spacing: -0.035em;
    font-weight: 500; margin: 0 0 6px;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
  }
  .res-band { font-size: 14px; color: var(--ink-muted); margin: 0 0 22px; }
  
  
  
  .crit {
    background: var(--bg-2); border: 1px solid var(--rule-soft);
    border-radius: var(--r-md); padding: 16px 18px;
    margin-bottom: 10px;
  }
  .crit .ch { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
  
  
  
  
  
  

  
  
  
  
  
  

  .modal-back { display: none; }
  .modal-back.visible { display: flex; }

  /* ===== Draw canvas ===== */
  .draw-wrap { display: none; flex-direction: column; gap: 10px; }
  .draw-wrap.active { display: flex; }
  .draw-pen-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  .draw-pen-row input[type=color] { width: 28px; height: 28px; padding: 2px; border: 1px solid var(--rule-soft); border-radius: 6px; cursor: pointer; background: var(--bg); }
  .draw-pen-row input[type=range] { flex: 1; max-width: 90px; accent-color: var(--ink); }
  .draw-pen-label { font-size: 11px; color: var(--ink-muted); }
  .draw-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
  .dc-btn { height: 27px; padding: 0 11px; border-radius: var(--r-pill); font-size: 11.5px; font-weight: 500; color: var(--ink-muted); background: var(--bg); border: 1px solid var(--rule-soft); cursor: pointer; transition: background 140ms, color 140ms; font-family: var(--sans); }
  .dc-btn:hover { background: var(--bg-3); color: var(--ink); }
  .dc-btn:disabled { opacity: 0.4; cursor: not-allowed; }
  .dfs-tool:disabled { opacity: 0.4; cursor: not-allowed; }
  .dc-btn.danger { color: var(--r-red); }
  .dc-btn.danger:hover { background: color-mix(in srgb, var(--r-red) 10%, var(--bg)); }
  .draw-page-counter { font-size: 12px; color: var(--ink-muted); font-weight: 500; margin-left: auto; }
  .draw-canvas-wrap { overflow-y: scroll; max-height: min(78vh, 980px); border: 1px solid var(--rule-soft); border-radius: var(--r-sm); background: #fff; }
  /* A per-part draw BOX (diagrams / structural formulae): a single fixed blank box, no page navigation. */
  body.qm-draw-box .draw-controls { display: none; }
  /* Multi draw-box part: labelled boxes side by side (reactant + product) */
  .draw-multi { display: none; gap: 14px; flex-wrap: wrap; }
  body.qm-draw-multi .draw-multi { display: flex; }
  body.qm-draw-multi #draw-canvas-wrap { display: none; }
  /* Multi-box parts have a per-box Enlarge; hide the single-canvas one (it targets the
     now-hidden #draw-canvas). Its page controls are hidden already via .draw-controls. */
  body.qm-draw-multi .draw-pen-row .dc-fs { display: none; }
  .draw-multi .mbox-card { flex: 1 1 240px; min-width: 220px; display: flex; flex-direction: column; gap: 6px; }
  .draw-multi .mbox-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .draw-multi .mbox-label { font-size: 11px; font-weight: 600; letter-spacing: 0.04em; color: var(--ink-muted); }
  .draw-multi .mbox-enlarge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; font-size: 10.5px; font-weight: 500;
    color: var(--ink-muted); background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-sm); cursor: pointer; }
  .draw-multi .mbox-enlarge:hover { background: var(--bg-3); color: var(--ink); }
  .draw-multi .mbox-canvas { width: 100%; background: #fff; border: 1px solid var(--rule-soft); border-radius: var(--r-sm); touch-action: none; display: block; }
  /* While a single multi-box canvas is enlarged in the fullscreen stage, the page
     navigation (prev/next/new page) is meaningless — hide it, keep pen/clear tools.
     Same for a blank draw BOX (one box, no pages) — only lined-page mode has pages. */
  body.qm-draw-fs-mbox .dfs-nav-group,
  body.qm-draw-box .dfs-nav-group { display: none; }
  /* Holistic draw-box + text answer (q30): show BOTH the blank draw box and the typed
     justification together, no Text/Draw/Upload tabs, draw box on top. */
  body.qm-drawtext .answer-card { display: flex; flex-direction: column; }
  body.qm-drawtext .ans-tabs { display: none; }
  body.qm-drawtext #draw-wrap { display: flex !important; order: -1; margin-bottom: 12px; }
  body.qm-drawtext #upload-wrap { display: none !important; }
  body.qm-drawtext .ans-area { display: block !important; min-height: 120px; }
  body.qm-drawtext #draw-hint, body.qm-drawtext #upload-hint { display: none; }
  body.qm-drawtext #draw-wrap::before { content: "Draw the structure"; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; color: var(--ink-muted); }
  body.qm-drawtext .ans-area::placeholder { color: var(--ink-faint); }
  body.qm-draw-box .draw-canvas-wrap { overflow: visible; max-height: none; }
  body.qm-draw-box #draw-hint { display: none; }
  .draw-canvas-wrap canvas { display: block; width: 100%; cursor: crosshair; touch-action: none; }
  .dc-btn.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
  .dc-btn.dc-fs { display: inline-flex; align-items: center; gap: 5px; margin-left: 8px; }

  /* ===== Drawing fullscreen ===== */
  body.qm-draw-fs { overflow: hidden; }
  .draw-fs {
    position: fixed; inset: 0; z-index: 5000;
    background: var(--bg); flex-direction: column;
    display: none;
  }
  .draw-fs.open { display: flex; }
  .draw-fs-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 18px; border-bottom: 1px solid var(--rule-soft); background: var(--bg-2);
  }
  .dfs-btn {
    display: inline-flex; align-items: center; gap: 7px;
    font-size: 12.5px; font-weight: 500; font-family: var(--sans);
    padding: 8px 14px; border-radius: var(--r-pill);
    border: 1px solid var(--rule-soft); background: var(--bg); color: var(--ink-soft);
    cursor: pointer; transition: background 140ms var(--ease), color 140ms var(--ease);
  }
  .dfs-btn:hover { background: var(--bg-3); color: var(--ink); }
  .dfs-btn.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
  .dfs-btn.dfs-exit { margin-left: auto; }
  .dfs-page { font-size: 12px; color: var(--ink-muted); font-weight: 500; }
  .draw-fs-question {
    max-height: 0; overflow: hidden; background: var(--bg-2);
    border-bottom: 1px solid transparent;
    transition: max-height var(--m-base, 420ms) var(--ease, ease), padding var(--m-base, 420ms) var(--ease, ease);
  }
  .draw-fs-question.open { max-height: 38vh; overflow-y: auto; padding: 16px 22px; border-bottom-color: var(--rule-soft); }
  .dfs-q-stem { font-size: 14px; line-height: 1.6; color: var(--ink); white-space: pre-wrap; }
  .draw-fs-stage { flex: 1; min-height: 0; display: flex; gap: 16px; padding: 18px; overflow: hidden; }
  .draw-fs-canvas-wrap {
    flex: 1; min-width: 0; height: 100%; overflow: auto;
    display: flex; justify-content: center; align-items: flex-start;
    background: var(--bg-3); border-radius: var(--r-md); padding: 16px;
  }
  .draw-fs-page { width: min(calc((100vh - 130px) * 0.7071), 100%); flex-shrink: 0; }
  .draw-fs-page canvas {
    display: block; width: 100%; background: #fff; cursor: crosshair; touch-action: none;
    border-radius: 2px; box-shadow:var(--shadow-md);
  }
  .draw-fs-tools {
    width: 60px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; gap: 9px;
    padding: 14px 7px; background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-md);
  }
  .dfs-tool {
    width: 44px; height: 44px; border-radius: var(--r-sm);
    border: 1px solid var(--rule-soft); background: var(--bg); color: var(--ink-soft);
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
    transition: background 140ms var(--ease), color 140ms var(--ease);
  }
  .dfs-tool:hover { background: var(--bg-3); color: var(--ink); }
  .dfs-tool.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
  .dfs-tool.dfs-clear:hover { color: var(--r-red); }
  .dfs-tool input[type=color] { width: 30px; height: 30px; border: none; background: none; cursor: pointer; padding: 0; }
  .dfs-size { width: 44px; }
  .dfs-divider { width: 70%; height: 1px; background: var(--rule-soft); margin: 3px 0; }
  @media (max-width: 640px) {
    .draw-fs-tools { width: 52px; }
    .dfs-tool { width: 38px; height: 38px; }
    .draw-fs-page { width: 100%; }
  }

  /* ===== Upload tab ===== */
  .upload-wrap { display: none; flex-direction: column; gap: 10px; }
  .upload-wrap.active { display: flex; }

  /* ===== Marked-in-background toast ===== */
  .mark-toast { position: fixed; right: 22px; bottom: 22px; z-index: 300; background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-md); box-shadow:var(--shadow-md); padding: 14px 16px; max-width: 320px; cursor: pointer; }
  .mark-toast .mt-stem { font-size: 12px; font-style: italic; color: var(--ink-muted); margin: 0 0 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .mark-toast .mt-score { font-size: 14px; font-weight: 600; color: var(--ink); }
  /* The marked result a toast opens: same slide-up panel as History */
  .qm-rv-back { position: fixed; inset: 0; z-index: 320; background: color-mix(in srgb, var(--ink) 32%, transparent);
    opacity: 0; pointer-events: none; transition: opacity 260ms var(--ease); }
  .qm-rv-back.open { opacity: 1; pointer-events: auto; }
  .qm-rv-panel { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg);
    transform: translateY(100%); transition: transform 360ms cubic-bezier(0.22, 1.5, 0.36, 1); }
  .qm-rv-back.open .qm-rv-panel { transform: none; }
  .qm-rv-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 28px;
    border-bottom: 1px solid var(--rule-soft); flex-shrink: 0; }
  .qm-rv-title { font-size: 15px; font-weight: 600; color: var(--ink); }
  .qm-rv-close { width: 30px; height: 30px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--rule-soft);
    color: var(--ink-muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; transition: background 140ms; }
  .qm-rv-close:hover { background: var(--bg-3); color: var(--ink); }
  .qm-rv-body { flex: 1; overflow-y: auto; padding: 24px 28px 40px; }
  @media (prefers-reduced-motion: reduce) { .qm-rv-back, .qm-rv-panel { transition: none; } }
  /* One drop zone for every upload (single questions and the mock exam's Upload tab) */
  .upload-zone, .ias-drop-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 150px; width: 100%;
    border: 1.5px dashed var(--rule); border-radius: var(--r-md); padding: 24px 20px; background: var(--bg-2); color: var(--ink-soft);
    font: inherit; text-align: center; cursor: pointer; transition: border-color 160ms, background 160ms; }
  .upload-zone:hover, .ias-drop-empty:hover, .upload-zone.is-over, .ias-zone.is-over .ias-drop-empty { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--bg-2)); }
  .upload-zone:focus-visible, .ias-drop-empty:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .upload-zone input[type=file] { display: none; }
  .uz-plus, .ias-drop-plus { width: 44px; height: 44px; border-radius: 999px; display: grid; place-items: center; background: var(--bg-3); color: var(--ink);
    border: 1px solid var(--rule-soft); transition: transform 160ms, background 160ms, color 160ms; }
  .upload-zone:hover .uz-plus, .ias-drop-empty:hover .ias-drop-plus { transform: scale(1.06); background: var(--ink); color: var(--bg); }
  .upload-zone .uz-icon { line-height: 0; }
  .upload-zone .uz-lbl, .ias-drop-t { font-size: 13.5px; color: var(--ink-soft); font-weight: 400; }
  .upload-zone .uz-lbl u, .ias-drop-t u { color: var(--ink); text-underline-offset: 3px; }
  .upload-zone .uz-sub, .ias-drop-sub { font-size: 11.5px; color: var(--ink-muted); }
  .upload-error { font-size: 12px; color: var(--r-red); padding: 7px 11px; background: color-mix(in srgb, var(--r-red) 8%, var(--bg)); border-radius: var(--r-sm); border: 1px solid color-mix(in srgb, var(--r-red) 25%, var(--rule)); display: none; }
  .upload-error.visible { display: block; }
  .upload-preview { display: none; flex-direction: column; gap: 8px; }
  .upload-preview.visible { display: flex; }
  .upload-preview img { max-width: 100%; border-radius: var(--r-sm); border: 1px solid var(--rule-soft); }
  .upload-preview .up-clear { font-size: 12px; color: var(--ink-muted); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
  .upload-preview .up-clear:hover { color: var(--r-red); }
  .ans-hint { font-size: 11.5px; color: var(--ink-muted); display: none; }
  .ans-hint.visible { display: block; }

  /* ===== Action bar left cluster ===== */
  .q-actionbar .ab-left-side { display: inline-flex; gap: 8px; align-items: center; }

  /* ===== Focus pill inside action bar (left side, next to left pill) ===== */
  .ab.exit-focus { color: var(--r-red); }
  .ab.exit-focus:hover { background: color-mix(in srgb, var(--r-red) 12%, var(--panel)); color: var(--r-red); }

  /* HSC review — question palette / navigator (top-right; dock sits below it). */
  .qnav { position: fixed; right: 16px; top: 74px; width: 152px; max-height: calc(100vh - 250px); display: none; flex-direction: column; background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-md); box-shadow:var(--shadow-md); z-index: 440; overflow: hidden; }
  .qnav.show { display: flex; }
  .qnav-head { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; border-bottom: 1px solid var(--rule-soft); }
  .qnav-title { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; font-weight: 600; color: var(--ink-muted); }
  .qnav-count { font-size: 11px; font-weight: 600; color: var(--ink-soft); }
  .qnav-list { overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 2px; }
  .qnav-item { display: flex; align-items: center; gap: 8px; padding: 6px 9px; border: none; background: transparent; border-radius:var(--r-sm); cursor: pointer; font-family: inherit; font-size: 12.5px; color: var(--ink); text-align: left; width: 100%; }
  .qnav-item:hover { background: color-mix(in srgb, var(--ink) 6%, var(--bg-2)); }
  .qnav-item.cur { background: color-mix(in srgb, var(--ink) 11%, var(--bg-2)); font-weight: 600; }
  .qnav-dot { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; background: var(--ink-faint, #b3a68c); }
  .qnav-item.note .qnav-dot { background: var(--r-amber); }
  .qnav-item.approved .qnav-dot { background: var(--r-green); }
  .qnav-item.approved .qnav-lbl { color: var(--ink-muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--ink-muted) 50%, transparent); }
  .qnav-lbl { flex: 1; }

  /* Per-question review dock — the on-page feedback box for HSC review mode. */
  .qrev-dock { position: fixed; right: 18px; bottom: 18px; width: 330px; max-width: calc(100vw - 36px); background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-md); box-shadow:var(--shadow-md); z-index: 450; display: none; }
  .qrev-dock.show { display: block; }
  .qrev-dock.collapsed .qrev-body { display: none; }
  .qrev-head { display: flex; align-items: center; gap: 8px; padding: 11px 13px; cursor: pointer; }
  .qrev-title { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; font-weight: 600; color: var(--ink-muted); }
  .qrev-code { font-size: 11px; font-weight: 600; color: var(--ink); flex: 1; text-align: right; }
  .qrev-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--ink-faint, #b3a68c); flex-shrink: 0; }
  .qrev-dot.saved { background: var(--r-green); }
  .qrev-dot.dirty { background: var(--r-amber); }
  .qrev-chev { color: var(--ink-muted); flex-shrink: 0; transition: transform .2s ease; }
  .qrev-dock.collapsed .qrev-chev { transform: rotate(-90deg); }
  .qrev-body { padding: 0 13px 13px; }
  .qrev-history { max-height: 168px; overflow-y: auto; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
  .qrev-rev { background: var(--bg); border: 1px solid var(--rule-soft); border-radius:var(--r-sm); padding: 8px 10px; }
  .qrev-rev-head { font-size: 10px; font-weight: 600; color: var(--ink-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 3px; }
  .qrev-rev.needs .qrev-rev-head { color: var(--r-red); }
  .qrev-rev-body { font-size: 12.5px; color: var(--ink); white-space: pre-wrap; line-height: 1.45; }
  .qrev-body textarea { width: 100%; box-sizing: border-box; min-height: 92px; resize: vertical; border: 1px solid var(--rule-soft); border-radius:var(--r-sm); padding: 9px 11px; font-family: inherit; font-size: 13px; line-height: 1.5; color: var(--ink); background: var(--bg); }
  .qrev-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
  .qrev-save { padding: 6px 15px; border-radius:var(--r-sm); border: none; background: var(--ink); color: var(--bg); font-family: inherit; font-size: 12px; font-weight: 500; cursor: pointer; }
  .qrev-save:disabled { opacity: .6; cursor: default; }
  .qrev-status { font-size: 11.5px; color: var(--ink-muted); flex-basis: 100%; }
  .qrev-approve { padding: 6px 12px; border-radius:var(--r-sm); border: 1px solid var(--r-green); background: color-mix(in srgb, var(--r-green) 12%, var(--bg)); color: #2f7d58; font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
  .qrev-approve:disabled { opacity: .6; cursor: default; }
  .qrev-dot.approved { background: var(--r-green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--r-green) 25%, transparent); }
  .qrev-needs { padding: 6px 12px; border-radius:var(--r-sm); border: 1px solid var(--r-red); background: color-mix(in srgb, var(--r-red) 12%, var(--bg)); color: var(--r-red); font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
  .qrev-needs:disabled { opacity: .6; cursor: default; }
  .qrev-dot.needs { background: var(--r-red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--r-red) 25%, transparent); }
  .qnav-item.needs .qnav-dot { background: var(--r-red); }

  /* Expand-a-diagram: a corner button on every stimulus figure opens it larger. */
  .fig-expandable { position: relative; }
  .fig-expand-btn { position: absolute; top: 6px; right: 6px; z-index: 6; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius:var(--r-sm); border: 1px solid var(--rule-soft); background: color-mix(in srgb, var(--bg) 86%, transparent); color: var(--ink-muted); cursor: pointer; opacity: 0; transition: opacity 160ms ease, color 160ms ease, transform 160ms var(--spring-soft, ease); }
  .fig-expandable:hover .fig-expand-btn, .fig-expand-btn:focus-visible { opacity: 1; }
  .fig-expand-btn:hover { color: var(--ink); transform: scale(1.08); }
  .fig-modal { position: fixed; inset: 0; z-index: 900; display: none; align-items: center; justify-content: center; background: color-mix(in srgb, var(--ink) 52%, transparent); padding: 4vh 4vw; }
  .fig-modal.show { display: flex; }
  .fig-modal-inner { position: relative; background: var(--bg); border: 1px solid var(--rule-soft); border-radius: var(--r-md); box-shadow:var(--shadow-lg); padding: 26px 24px 22px; max-width: 96vw; max-height: 92vh; overflow: auto; }
  .fig-modal-body { width: min(1050px, 86vw); }
  .fig-modal-body svg { width: 100%; height: auto; max-width: none; display: block; }
  .fig-modal-body table { width: 100%; }
  .fig-modal-close { position: absolute; top: 10px; right: 10px; width: 32px; height: 32px; border-radius:var(--r-sm); border: 1px solid var(--rule-soft); background: var(--bg-2); color: var(--ink-muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
  .fig-modal-close:hover { color: var(--ink); }

  sub.chstate { font-style: normal; }
  sub.chsub { font-style: italic; }

  /* Action bar icon spring animations */
  .q-actionbar .ab.anim-star { animation: ri-star 400ms cubic-bezier(0.34,1.56,0.64,1) both; }
  .q-actionbar .ab.anim-heart { animation: ri-heart 380ms cubic-bezier(0.34,1.56,0.64,1) both; }
  .q-actionbar .ab#ab-star.on { color: var(--r-amber); }
  .q-actionbar .ab#ab-star.on svg path { fill: var(--r-amber); stroke: var(--r-amber); }
  .q-actionbar .ab#ab-heart.on { color: var(--r-red); }
  .q-actionbar .ab#ab-heart.on svg path { fill: var(--r-red); stroke: var(--r-red); }

  /* ===== Mock exam ===== */
  body.exam-mode .top,
  body.exam-mode aside.rail,
  body.fluid-rail-mounted.exam-mode .fluid-rail { display: none !important; }
  body.exam-mode .shell { padding-left: 0 !important; }
  body.exam-mode .qm-wrap { max-width: 100%; padding: 0; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
  body.exam-mode #phase-mock-exam { display: flex !important; flex-direction: column; flex: 1; overflow: hidden; min-height: 0; }

  .exam-topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; border-bottom: 1px solid var(--rule-soft); background: var(--bg-2); flex-shrink: 0; gap: 16px; }
  .exam-timer { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); letter-spacing: 0.04em; }
  .exam-timer.untimed { font-size: 13px; color: var(--ink-muted); font-weight: 400; }
  .exam-finish-btn { padding: 6px 13px; border-radius: var(--r-pill); font-size: 12px; font-weight: 500; background: color-mix(in srgb, var(--r-red) 12%, var(--bg-2)); color: var(--r-red); border: 1px solid color-mix(in srgb, var(--r-red) 30%, var(--rule)); cursor: pointer; transition: background 140ms; font-family: var(--sans); }
  .exam-finish-btn:hover { background: color-mix(in srgb, var(--r-red) 20%, var(--bg-2)); }

  .exam-layout { display: flex; flex: 1; overflow: hidden; min-height: 0; }
  .exam-sidebar { width: 190px; flex-shrink: 0; border-right: 1px solid var(--rule-soft); background: var(--bg-2); display: flex; flex-direction: column; overflow: hidden; }
  
  .q-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; padding: 10px; overflow-y: auto; flex: 1; align-content: start; }
  .q-sq { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: var(--r-sm); font-size: 11px; font-weight: 700; cursor: pointer; position: relative; border: 2px solid transparent; transition: all 120ms; background: var(--ink); color: var(--bg); user-select: none; }
  .q-sq:hover { opacity: 0.75; }
  .q-sq.visited { background: var(--bg-3); color: var(--ink); border-color: var(--rule-soft); }
  .q-sq.current { border-color: var(--accent) !important; }
  .q-sq-flag { position: absolute; top: 1px; right: 2px; width: 8px; height: 8px; color: #fff; }
  .exam-sidebar-legend { padding: 8px 10px; border-top: 1px solid var(--rule-soft); display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
  .exam-leg-item { display: flex; align-items: center; gap: 6px; font-size: 10px; color: var(--ink-muted); }
  .exam-leg-sq { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

  .exam-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
  .exam-scroll { flex: 1; overflow-y: auto; padding: 28px 32px 38px; }
  .exam-scroll > .exam-main-area {
    max-width: 1080px; width: 100%; margin-left: auto; margin-right: auto;
  }
  body.qm-layout-side .exam-scroll > .exam-main-area { max-width: 1480px; }
  #phase-mock-exam .exam-main-area > .q-card { padding:30px 34px; }
  /* Multiple choice has no answer card, so it always stacks, as in practice. */
  body.qm-layout-side #exam-main-area.is-mcq { flex-direction: column; }
  body.qm-layout-side #exam-main-area.is-mcq > .q-card { min-height: 0; }
  body.qm-layout-side #exam-main-area > #exam-part-rail.show { flex-direction: column; align-self: center; padding: 0 2px; }
  .exam-actionbar .ab-left-side { min-width: 0; }
  .mx-saved-note { align-self: center; font-size: 12px; color: var(--ink-muted); }
  #phase-mock-exam .q-stem, #phase-question .q-stem { font-size:18px; line-height:1.65; font-weight:400; }
  #phase-mock-exam .q-tags, #phase-question .q-tags { font-size:12px; margin-bottom:18px; }
  #exam-answer-card { padding:24px 28px; }
  #exam-ans-area { min-height:clamp(320px,42vh,560px); font-size:16px; }
  #eq-diagram-area.graph-host { display:block; padding:6px 0 0; background:transparent; border:0; color:inherit; }
  #eq-diagram-area.graph-host svg { display:block; width:100%; height:auto; }
  #eq-diagram-area.table-host { display:block; min-height:0; padding:0; background:transparent; border:0; color:inherit; }
  #eq-diagram-area:not(.graph-host):not(.table-host):not(.spectro-host):has(.exam-question-image),
  #eq-diagram-area:not(.graph-host):not(.table-host):not(.spectro-host):has(.exam-question-pdf) {
    display:block; min-height:0; padding:0; background:transparent; border:0;
  }
  .exam-question-image { display:block; max-width:100%; max-height:420px; margin:auto; border-radius:var(--r-sm); }
  .exam-question-pdf { display:block; width:100%; height:480px; border-radius:var(--r-sm); }
  #exam-part-rail.show { display:flex; align-items:center; gap:8px; padding:2px 0 12px; }
  #exam-ans-toolbar { display:inline-flex; }
  #exam-answer-card .ans-foot { display:flex; justify-content:space-between; align-items:center; gap:12px; }
  #exam-answer-card .ans-foot-btns { display:flex; align-items:center; flex-wrap:wrap; justify-content:flex-end; }
  #exam-answer-card .ans-hint { font-size:11px; color:var(--ink-muted); }
  @media(max-width:760px) {
    .exam-scroll { padding:16px 14px 28px; }
    #phase-mock-exam .exam-main-area > .q-card { padding:20px 20px; }
    #phase-mock-exam .q-stem { font-size:16px; }
    #exam-answer-card { padding:18px 20px; }
    #exam-ans-area { min-height:300px; }
    #exam-ans-toolbar { max-width:100%; overflow-x:auto; }
    #exam-answer-card .ans-foot { flex-wrap:wrap; }
  }
  .exam-actionbar { flex-shrink:0; width:100%; padding:10px 20px 12px; margin:0; background:linear-gradient(to top,var(--bg) 65%,transparent); gap:12px; }
  .exam-actionbar .ab-group { flex-shrink:0; }
  .exam-actionbar .ab[hidden] { display:none; }
  .exam-actionbar #exam-ab-flag.on { color:#fff; background:var(--r-red); }
  .exam-actionbar #exam-ab-flag.on svg path { fill:currentColor; }
  .exam-actionbar #exam-ab-star.on { color:var(--r-amber); }
  .exam-actionbar #exam-ab-star.on svg path { fill:var(--r-amber); stroke:var(--r-amber); }
  .exam-actionbar #exam-ab-heart.on { color:var(--r-red); }
  .exam-actionbar #exam-ab-heart.on svg path { fill:var(--r-red); stroke:var(--r-red); }
  .exam-actionbar .exam-phone-tool { color:var(--r-blue); }
  .exam-actionbar .ab.anim-star { animation:ri-star 400ms cubic-bezier(0.34,1.56,0.64,1) both; }
  .exam-actionbar .ab.anim-heart { animation:ri-heart 380ms cubic-bezier(0.34,1.56,0.64,1) both; }

  /* Mock setup */
  .mock-marks-row { display: flex; gap: 6px; flex-wrap: wrap; }
  .mock-marks-chip { padding: 8px 18px; border-radius: var(--r-pill); font-size: 13px; font-weight: 500; border: 1px solid var(--rule-soft); background: var(--bg); color: var(--ink-muted); cursor: pointer; transition: all 140ms; font-family: var(--sans); }
  .mock-marks-chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
  .mock-time-row { display: flex; gap: 6px; }
  .mock-time-chip { flex: 1; padding: 10px 12px; border-radius: var(--r-md); border: 1px solid var(--rule-soft); background: var(--bg); cursor: pointer; text-align: center; transition: all 140ms; font-family: var(--sans); }
  .mock-time-chip.on { border-color: var(--ink); background: var(--ink); }
  .mock-time-chip.on .mtc-lbl, .mock-time-chip.on .mtc-sub { color: var(--bg); }
  .mock-time-chip .mtc-lbl { font-size: 13px; font-weight: 500; color: var(--ink); }
  .mock-time-chip .mtc-sub { font-size: 11px; color: var(--ink-muted); margin-top: 2px; }

  /* Finish exam modal */
  .finish-modal-back { position: fixed; inset: 0; z-index: 9000; display: none; align-items: center; justify-content: center; background: rgba(42,36,28,0.3);  }
  .finish-modal-back.open { display: flex; }
  .finish-modal { background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-lg); padding: 28px 32px; width: min(760px, calc(100vw - 32px)); max-height:min(85vh,850px); display:flex; flex-direction:column; box-shadow:var(--shadow-lg); animation: sc-in 280ms cubic-bezier(0.34,1.56,0.64,1) both; }
  .finish-modal h3 { font-size: 17px; font-weight: 600; margin: 0 0 10px; }
  .finish-modal p { font-size: 13.5px; color: var(--ink-muted); line-height: 1.55; margin: 0 0 18px; }
  .finish-review-filters { display:flex; flex-wrap:wrap; gap:6px; margin-bottom:16px; }
  .finish-filter { display:inline-flex; align-items:center; gap:6px; padding:6px 12px; border-radius:var(--r-pill); border:1px solid var(--rule-soft); background:transparent; color:var(--ink-muted); font:inherit; font-size:12px; font-weight:500; cursor:pointer; transition:background 140ms, color 140ms, border-color 140ms; }
  .finish-filter:hover { color:var(--ink); border-color:var(--rule); }
  .finish-filter.on { background:var(--ink); color:var(--bg); border-color:var(--ink); }
  .finish-filter.is-flag svg { color:var(--r-red); }
  .finish-filter.is-flag.on svg { color:var(--bg); }
  .finish-review-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(104px,1fr)); gap:9px; min-height:0; overflow-y:auto; padding:3px 3px 6px 1px; margin-bottom:22px; }
  .finish-review-none { grid-column:1/-1; margin:8px 0; font-size:13px; color:var(--ink-muted); }
  .finish-review-q { position:relative; min-height:84px; display:flex; flex-direction:column; align-items:flex-start; justify-content:space-between; gap:6px; padding:11px 12px; border:1px solid color-mix(in srgb,var(--r-green) 45%,var(--rule-soft)); border-radius:var(--r-sm); background:color-mix(in srgb,var(--r-green) 14%,var(--bg-2)); color:var(--ink); text-align:left; font:inherit; cursor:pointer; transition:transform 140ms, border-color 140ms; }
  .finish-review-q:hover { transform:translateY(-2px); border-color:var(--accent); }
  .finish-review-q:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }
  .finish-review-q strong { font-size:18px; font-weight:600; }
  .finish-review-q span { font-size:11px; line-height:1.25; color:var(--ink-soft); }
  .finish-review-q.partial { background:color-mix(in srgb,var(--r-amber) 16%,var(--bg-2)); border-color:color-mix(in srgb,var(--r-amber) 50%,var(--rule-soft)); }
  .finish-review-q.unanswered { background:var(--bg-3); border:1px dashed var(--rule); }
  .finish-review-q.unanswered span { color:var(--ink-muted); }
  .finish-review-q.flagged { border:2px solid var(--r-red); padding:10px 11px; }
  .finish-flag { position:absolute; top:8px; right:8px; width:22px; height:22px; border-radius:999px; display:inline-flex; align-items:center; justify-content:center; background:var(--r-red); color:#fff; font-style:normal; }
  .finish-modal .fm-acts { display: flex; gap: 10px; justify-content: flex-end; }
  @media(max-width:620px) {
    .finish-modal { padding:22px 18px; max-height:90vh; }
    .finish-review-grid { grid-template-columns:repeat(auto-fill,minmax(86px,1fr)); }
    .finish-modal .fm-acts { flex-wrap:wrap; }
  }

  /* Mock results */
  /* Mock results: modules that expand into dot points */
  .mx-actions { margin: 4px 0 26px; }
  .mx { margin-bottom: 26px; }
  .mx-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
  .mx-h h4 { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
  .mx-h span { font-size: 12px; color: var(--ink-faint); }
  .mx-wait { font-size: 13px; color: var(--ink-muted); margin: 0; padding: 16px 0; }
  .mx-mod { border-bottom: 1px solid var(--rule-soft); }
  .mx-mod:first-child { border-top: 1px solid var(--rule-soft); }
  .mx-mod-row { width: 100%; display: grid; grid-template-columns: 14px minmax(0, 1fr) minmax(80px, 200px) 64px 44px; gap: 14px; align-items: center;
    padding: 14px 4px; background: none; border: 0; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
  .mx-mod-row:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
  .mx-mod-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
  .mx-caret { width: 7px; height: 7px; border-right: 1.5px solid var(--ink-muted); border-bottom: 1.5px solid var(--ink-muted); transform: rotate(-45deg); transition: transform 160ms var(--ease); justify-self: center; }
  .mx-mod.open .mx-caret { transform: rotate(45deg); }
  .mx-name { display: flex; gap: 10px; align-items: baseline; min-width: 0; font-size: 14px; }
  .mx-name b { font-weight: 600; white-space: nowrap; }
  .mx-name span { color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .mx-bar { height: 6px; border-radius: 999px; background: var(--bg-3); overflow: hidden; }
  .mx-bar i { display: block; height: 100%; border-radius: inherit; }
  .mx-bar i.hi, .mx-dot.hi { background: var(--r-green); }
  .mx-bar i.mid, .mx-dot.mid { background: var(--r-amber); }
  .mx-bar i.lo, .mx-dot.lo { background: var(--r-red); }
  .mx-mark { font-size: 14px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
  .mx-pct { font-size: 12px; color: var(--ink-muted); text-align: right; font-variant-numeric: tabular-nums; }
  .mx-dps { padding: 0 4px 12px 32px; }
  .mx-dp { display: grid; grid-template-columns: 8px 34px minmax(0, 1fr) auto 56px 112px; gap: 12px; align-items: center; padding: 8px 0; font-size: 13px; }
  .mx-dp + .mx-dp { border-top: 1px dashed var(--rule-soft); }
  .mx-dot { width: 8px; height: 8px; border-radius: 999px; }
  .mx-dp-code { font-weight: 600; font-variant-numeric: tabular-nums; }
  .mx-dp-name { color: var(--ink-soft); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mx-dp-qs { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
  .mx-q { padding: 2px 7px; border-radius: var(--r-pill); border: 1px solid var(--rule-soft); background: transparent; color: var(--ink-muted); font: inherit; font-size: 11px; cursor: pointer; }
  .mx-q:hover { color: var(--ink); border-color: var(--rule); }
  .mx-dp-mark { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
  .mx-practise { justify-self: end; white-space: nowrap; }
  .mx-focus { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 18px; border: 1px solid var(--rule-soft); border-radius: var(--r-md); background: var(--bg-2); }
  .mx-focus > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; font-size: 13.5px; }
  .mx-focus-k { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
  .mx.compact .mx-mod-row { grid-template-columns: 12px minmax(0, 1fr) 70px 52px; gap: 10px; padding: 12px 2px; }
  .mx.compact .mx-pct { display: none; }
  .mx.compact .mx-dps { padding-left: 14px; }
  .mx.compact .mx-dp { grid-template-columns: 8px 30px minmax(0, 1fr) 48px; }
  .mx.compact .mx-dp-qs, .mx.compact .mx-practise, .mx.compact .mx-practise-gap { display: none; }
  .an-score { display: flex; flex-direction: column; gap: 4px; padding: 4px 0 14px; }
  .an-score b { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; }
  .an-score span { font-size: 12.5px; color: var(--ink-muted); }
  @media (max-width: 900px) {
    .mx-mod-row { grid-template-columns: 14px minmax(0, 1fr) 90px 56px; }
    .mx-pct { display: none; }
    .mx-dp { grid-template-columns: 8px 32px minmax(0, 1fr) 52px; }
    .mx-dp-qs { display: none; }
    .mx-practise, .mx-practise-gap { grid-column: 3 / -1; justify-self: start; }
  }
  button.mr-q-tile { font: inherit; color: inherit; cursor: pointer; transition: border-color 140ms, transform 140ms; }
  button.mr-q-tile:hover { border-color: var(--accent); transform: translateY(-1px); }
  .mr-q-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; margin-top: 14px; }
  .mr-q-tile { background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-sm); padding: 10px 8px; text-align: center; }
  .mr-q-tile .mrqt-n { font-size: 10px; color: var(--ink-muted); font-weight: 600; letter-spacing: 0.08em; margin-bottom: 4px; }
  .mr-q-tile .mrqt-m { font-size: 16px; font-weight: 500; color: var(--ink); }
  .mr-q-tile.full .mrqt-m { color: var(--r-green); }
  .mr-q-tile.none .mrqt-m { color: var(--r-red); }
  .mr-q-tile.partial .mrqt-m { color: var(--r-amber); }

  /* ===== Side-by-side layout ===== */
  .q-main-area { display: flex; flex-direction: column; }
  body.qm-layout-side .q-main-area { flex-direction: row; gap: 14px; align-items: stretch; }
  body.qm-layout-side .q-card { flex: 1; min-width: 0; margin-bottom: 0; min-height: 520px; overflow-y: auto; }
  body.qm-layout-side .answer-card { flex: 1; min-width: 0; margin-bottom: 0; min-height: 520px; display: flex; flex-direction: column; }
  body.qm-layout-side .answer-card .ans-area { flex: 1; min-height: 320px; resize: none; }
  body.qm-layout-side .answer-card .draw-canvas-wrap,
  body.qm-layout-side .answer-card #canvas-draw { min-height: 480px; flex: 1; }

  /* Layout orientation picker panel */
  .ab-left-side { position: relative; }
  .layout-picker-panel {
    position: absolute; bottom: calc(100% + 8px); left: 0;
    background: var(--bg-2); border: 1px solid var(--rule-soft);
    border-radius: var(--r-md); padding: 6px;
    display: none; flex-direction: column; gap: 3px;
    min-width: 150px; box-shadow:var(--shadow-md);
    z-index: 200; animation: sc-in 180ms var(--spring-bouncy,cubic-bezier(0.34,1.56,0.64,1)) both;
  }
  .layout-picker-panel.open { display: flex; }
  .lp-item { padding: 8px 11px; border-radius: var(--r-sm); cursor: pointer; font-size: 12px; font-weight: 500; color: var(--ink-muted); display: flex; align-items: center; gap: 8px; transition: background 140ms; }
  .lp-item:hover { background: var(--bg-3); color: var(--ink); }
  .lp-item.on { background: color-mix(in srgb,var(--accent) 10%,var(--bg-2)); color: var(--accent); }
  .lp-dot { width: 7px; height: 7px; border-radius: 999px; background: currentColor; flex-shrink: 0; }

  /* ===== MCQ options + diagrams in question card ===== */
  .q-diagram { background: #fff; border: 1px dashed var(--rule); border-radius: var(--r-sm); display: flex; align-items: center; justify-content: center; min-height: 110px; color: var(--ink-faint); font-size: 11px; margin: 12px 0; letter-spacing: 0.04em; }
  /* ===== Spectroscopy spectra grid (renders into q-diagram-area / eq-diagram-area) ===== */
  .q-diagram.spectro-host { display: block; min-height: 0; background: transparent; border: none; padding: 0; margin: 14px 0; letter-spacing: normal; }
  /* Always a fixed 2×2 grid (four spectra), never let it reflow to 3+1. The columns
     stay equal via minmax(0,1fr); width for the 2 columns is guaranteed by widening the
     side-by-side question card (below). Only collapse to 1-up on a phone. */
  .spectro-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  @media (max-width: 560px) { .spectro-grid { grid-template-columns: 1fr; } }
  .spectro-card { background: #fff; border: 1px solid var(--rule-soft); border-radius: var(--r-sm); overflow: hidden; }
  .spectro-cap { font-size: 10.5px; font-weight: 600; color: var(--ink-muted); letter-spacing: 0.04em; padding: 6px 10px; border-bottom: 1px solid var(--rule-soft); }
  .spectro-canvas { display: block; width: 100%; height: 184px; background: #fff; }
  .q-mcq-opts { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
  .q-mcq-opt { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border: 1px solid var(--rule-soft); border-radius: var(--r-sm); background: var(--bg); cursor: pointer; font-size: 13.5px; transition: background 140ms, border-color 140ms; user-select: none; }
  .q-mcq-opt:hover { background: var(--bg-3); }
  .q-mcq-opt.selected { border-color: var(--accent); background: color-mix(in srgb,var(--accent) 8%,var(--bg)); }
  .q-mcq-opt .opt-letter { width: 22px; height: 22px; border-radius: 999px; border: 1.5px solid var(--rule); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: var(--ink-muted); flex-shrink: 0; transition: all 140ms; }
  .q-mcq-opt.selected .opt-letter { border-color: var(--accent); background: var(--accent); color: #fff; }
  .q-mcq-opt-diagram { width: 80px; height: 56px; border-radius: 4px; background: #fff; border: 1px dashed var(--rule); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 9px; color: var(--ink-faint); letter-spacing: 0.04em; }
  /* Diagram-option MCQ, the four panels ARE the answers, shown as a 2×2 grid (Kahoot-style) */
  .q-mcq-opts.opts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .q-mcq-opts.opts-grid .q-mcq-opt { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px; }
  .q-mcq-opts.opts-grid .q-mcq-opt .opt-letter { align-self: flex-start; }
  .q-mcq-opts.opts-grid .opt-fig { background: transparent; border-radius: 6px; padding: 6px; min-height: 100px; display: flex; align-items: center; justify-content: center; }
  .q-mcq-opts.opts-grid .opt-fig svg { width: 100%; height: auto; display: block; }
  @media (max-width: 640px) { .q-mcq-opts.opts-grid { grid-template-columns: 1fr; } }

  /* ===== Floating Periodic Table ===== */
  .pt-float {
    position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
    z-index: 8600; display: none; flex-direction: column;
    background: var(--bg-2); border: 1px solid var(--rule-soft);
    border-radius: var(--r-lg); box-shadow:var(--shadow-lg);
    width: min(660px, 94vw); user-select: none;
    animation: sc-in 280ms var(--spring-bouncy,cubic-bezier(0.34,1.56,0.64,1)) both;
  }
  .pt-float.open { display: flex; }
  .pt-float-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--rule-soft); cursor: grab; flex-shrink: 0; border-radius: var(--r-lg) var(--r-lg) 0 0; }
  .pt-float-head:active { cursor: grabbing; }
  .pt-float-title { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted); }
  .pt-float-ctrl { display: flex; gap: 6px; align-items: center; }
  .pt-float-ctrl .pfc-btn { width: 22px; height: 22px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: var(--ink-muted); cursor: pointer; transition: background 120ms; }
  .pt-float-ctrl .pfc-btn:hover { background: var(--panel); color: var(--ink); }
  .pt-hover-lbl { font-size: 10px; color: var(--ink-muted); margin-right: 4px; }
  .pt-float-body { padding: 10px 12px 12px; overflow-x: auto; }
  /* hover-expand tooltip */
  .pt-hover-tip {
    position: fixed; z-index: 9500; pointer-events: none;
    background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-md);
    padding: 10px 14px; box-shadow:var(--shadow-md);
    min-width: 140px; display: none;
  }
  .pt-hover-tip.visible { display: block; }
  .ptt-sym { font-size: 26px; font-weight: 700; color: var(--ink); line-height: 1; }
  .ptt-name { font-size: 12px; color: var(--ink-muted); margin-top: 3px; }
  .ptt-rows { margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }
  .ptt-r { display: flex; justify-content: space-between; gap: 16px; font-size: 11px; }
  .ptt-k { color: var(--ink-muted); }
  .ptt-v { color: var(--ink); font-weight: 500; font-family: ui-monospace,monospace; }
  /* hover-mode cells */
  .pt-float .pt-cell { cursor: default; }
  body.pt-hover-mode .pt-float .pt-cell { cursor: pointer; }

  /* ===== Mock setup improvements ===== */
  .marks-custom-wrap { display: none; align-items: center; gap: 10px; padding-top: 10px; }
  .marks-custom-wrap.visible { display: flex; }
  .marks-spinner { display: inline-flex; align-items: center; border: 1px solid var(--rule-soft); border-radius: var(--r-pill); overflow: hidden; background: var(--bg); }
  .ms-spin-btn { width: 32px; height: 34px; display: flex; align-items: center; justify-content: center; font-size: 18px; cursor: pointer; color: var(--ink-muted); transition: background 120ms; border: none; font-family: var(--sans); background: transparent; }
  .ms-spin-btn:hover { background: var(--bg-3); color: var(--ink); }
  .ms-spin-val { min-width: 52px; text-align: center; font-size: 14px; font-weight: 500; color: var(--ink); font-variant-numeric: tabular-nums; padding: 0 4px; }

  /* ===== Mock setup: paper weighting (split sliders) =====
     Opens under the dotpoint grid once two or more are picked, and under the
     question types when both are on. Rows animate open with the soft spring. */
  .mock-split { display: grid; grid-template-rows: 0fr; opacity: 0; transform: translateY(-6px);
    transition: grid-template-rows var(--m-base) var(--spring-soft), opacity var(--m-quick) var(--ease-sharp), transform var(--m-base) var(--spring-soft), margin-top var(--m-base) var(--spring-soft); }
  .mock-split.open { grid-template-rows: 1fr; opacity: 1; transform: none; margin-top: 14px; }
  .mock-split > .mock-split-in { overflow: hidden; min-height: 0; }
  .mock-split.open > .mock-split-in { overflow: visible; }
  .mock-split-box { background: var(--bg); border: 1px solid var(--rule-soft); border-radius: var(--r-sm); padding: 14px 16px 10px; }
  .mock-split-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
  .msp-t { font-size: 12px; font-weight: 600; color: var(--ink); letter-spacing: 0.01em; }
  .msp-sub { font-size: 11.5px; color: var(--ink-muted); margin-top: 2px; line-height: 1.45; }
  .msp-reset { flex: none; font-size: 11px; font-weight: 500; color: var(--ink-muted); padding: 5px 11px; border-radius: var(--r-pill); border: 1px solid var(--rule-soft); background: var(--bg-2);
    opacity: 0; pointer-events: none; transform: scale(0.9);
    transition: opacity var(--m-quick) var(--ease-sharp), transform var(--m-quick) var(--spring-bouncy), color var(--m-quick) var(--ease-sharp); }
  .msp-reset:not(.show) { display: none; }
  .msp-reset.show { opacity: 1; pointer-events: auto; transform: scale(1); animation: ionik-bubble-in var(--m-bubble) var(--spring-bouncy) backwards; }
  /* Phones: stack each mock setup label above its controls so the
     weighting bars get the full card width. */
  @media (max-width: 600px) {
    #phase-mock-setup .setup-row { flex-direction: column; align-items: stretch; gap: 10px; }
    #phase-mock-setup .setup-row .lbl { min-width: 0; }
    .mock-split-box { padding: 12px 12px 8px; }
  }
  .msp-reset:hover { color: var(--ink); transform: translateY(-2px); }
  .msp-reset:active { transform: translateY(1px) scale(0.97); }
  /* Picked dotpoints carry their section colour once the bar is showing. */
  /* Text stays in the selected-card colour (--bg on an --ink card), so a
     picked dot point reads clearly in both themes. */
  #mock-dp-stack.dp-keyed .dp-card.on { color: var(--bg); box-shadow: inset 4px 0 0 var(--dp-c, transparent); }
  #mock-dp-stack.dp-keyed .dp-card.on .ix { color: var(--bg); opacity: 0.7; }
  #mock-dp-stack.dp-keyed .dp-card.on .ix::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--dp-c); margin-right: 5px; transform: translateY(-1px);
    animation: ionik-bubble-in var(--m-bubble) var(--spring-bouncy) both; }
  .paper-split-bar { display: flex; height: 6px; border-radius: var(--r-pill); overflow: hidden; margin: 12px 0 4px; background: var(--bg-3); }
  .paper-split-bar span { height: 100%; background: var(--c); box-shadow: inset -1px 0 0 var(--bg-2); transform-origin: left center; animation: ionik-fade-rise var(--m-base) var(--ease-decel) both; }
  .paper-split-note { font-size: 11.5px; color: var(--ink-muted); margin-bottom: 2px; }

  /* ===== Unfinished mock exam: carry on where you left off ===== */
  .mock-resume { display: flex; align-items: center; justify-content: space-between; gap: 14px 24px; flex-wrap: wrap;
    margin-bottom: 14px; border-color: color-mix(in srgb, var(--accent) 32%, var(--rule-soft)); }
  .mock-resume .mrs-lbl { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; color: var(--accent); }
  .mock-resume .mrs-where { font-size: 17px; line-height: 1.25; font-weight: 600; letter-spacing: -0.01em; color: var(--ink); margin-top: 5px; }
  .mock-resume .mrs-detail { font-size: 12.5px; color: var(--ink-muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
  .mock-resume .mrs-actions { display: flex; align-items: center; gap: 18px; margin-left: auto; }
  .mock-resume .mrs-discard.armed { color: var(--r-red); }

  /* ===== Mock setup: generated-paper actions ===== */
  .paper-card { display: none; margin-top: 12px; padding: 16px 22px; }
  .paper-card.visible { display: block; }
  .paper-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
  .paper-meta { font-size: 13px; color: var(--ink); font-weight: 400; }
  .paper-regen { font-size: 11px; color: var(--ink-muted); background: none; border: 0; cursor: pointer;
    font-family: var(--sans); padding: 0; transition: color 140ms; }
  .paper-regen:hover { color: var(--ink); }
  .paper-split { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 5px;
    font-size: 11.5px; color: var(--ink-muted); }
  .paper-split span + span { padding-left: 14px; border-left: 1px solid var(--rule-soft); }
  .paper-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
  .paper-actions .btn { font-size: 12px; padding: 8px 15px; }
  .paper-lock { display: none; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 11px;
    font-size: 11.5px; color: var(--ink); }
  .paper-lock.visible { display: flex; }
  .paper-lock .btn { font-size: 11px; padding: 6px 12px; }
  .paper-note { font-size: 11px; color: var(--ink-muted); margin-top: 10px; line-height: 1.5; }
  .paper-note strong { font-weight: 600; color: var(--ink); }
  .paper-title-input {
    flex: 1; padding: 8px 12px; font-family: var(--sans); font-size: 13px; color: var(--ink);
    background: var(--bg); border: 1px solid var(--rule-soft); border-radius: var(--r-sm, 8px);
    outline: none; transition: border-color 140ms;
  }
  .paper-title-input:focus { border-color: var(--accent); }

  /* ===== Mock exam: collapsible sidebar ===== */
  .exam-sidebar-toggle { display: flex; align-items: center; justify-content: space-between; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--rule-soft); flex-shrink: 0; user-select: none; gap: 6px; }
  .exam-sidebar-toggle .est-lbl { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; color: var(--ink-muted); }
  .exam-sidebar-toggle .est-chev { color: var(--ink-muted); transition: transform 200ms var(--ease); flex-shrink: 0; }
  .exam-sidebar.collapsed .est-chev { transform: rotate(-90deg); }
  .exam-sidebar.collapsed .q-grid,
  .exam-sidebar.collapsed .exam-sidebar-legend { display: none; }
  .exam-sidebar { transition: width 200ms var(--ease); }
  .exam-sidebar.collapsed { width: 44px; }
  .exam-sidebar.collapsed .est-lbl { display: none; }
  @media(max-width:760px) {
    .exam-layout { position:relative; }
    .exam-sidebar:not(.collapsed) { position:absolute; left:0; top:0; bottom:0; z-index:5; box-shadow:8px 0 20px rgba(0,0,0,.12); }
    .exam-actionbar { padding:8px; gap:6px; }
    .exam-actionbar .ab-left-side { flex:1; }
    .exam-actionbar .exam-action-primary { flex:1; min-width:0; overflow-x:auto; scrollbar-width:none; }
    .exam-actionbar .exam-action-primary::-webkit-scrollbar { display:none; }
  }

  /* ===== Grid square states ===== */
  /* Override default dark, softer neutral-brown for "not visited" */
  .q-sq { background: color-mix(in srgb, var(--ink) 20%, var(--bg-3)); color: var(--ink-soft); }
  .q-sq.visited { background: var(--bg-3); color: var(--ink-muted); border-color: var(--rule-soft); }
  .q-sq.attempted { background: color-mix(in srgb, #5a7a8a 28%, var(--bg-3)); color: var(--ink); border-color: color-mix(in srgb, #5a7a8a 35%, var(--rule)); }
  .q-sq.current { border-color: var(--accent) !important; }
  
  .q-sq.flagged { background:var(--r-red); color:#fff; border-color:var(--r-red); }
  .q-sq.flagged.current { border-color:var(--ink) !important; }
  /* Remove pseudo-element flag in favor of child span */

  /* ===== Flag button red state ===== */

  /* ===== Timer toggle indicator ===== */
  .exam-timer-wrap { display: flex; align-items: center; gap: 6px; cursor: pointer; }
  .exam-timer-mode-lbl { font-size: 10px; color: var(--ink-faint); letter-spacing: 0.05em; }

  /* ===== Time's up modal ===== */
  .timesup-back { position: fixed; inset: 0; z-index: 9200; display: none; align-items: center; justify-content: center; background: rgba(42,36,28,0.55);  }
  .timesup-back.open { display: flex; }
  .timesup-modal { background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-lg); padding: 32px; width: min(360px, 92vw); box-shadow:var(--shadow-lg); animation: sc-in 300ms cubic-bezier(0.34,1.56,0.64,1) both; }
  .timesup-modal .tu-timer { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 600; color: var(--ink-muted); margin-bottom: 12px; }
  .timesup-modal h3 { font-size: 20px; font-weight: 600; margin: 0 0 8px; letter-spacing: -0.01em; }
  .timesup-modal p { font-size: 13px; color: var(--ink-muted); margin: 0 0 20px; line-height: 1.55; }
  .tu-extra-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 7px; margin-bottom: 10px; }
  .tu-extra-btn { padding: 10px 6px; border-radius: var(--r-md); border: 1px solid var(--rule-soft); background: var(--bg); cursor: pointer; font-size: 12px; font-weight: 500; color: var(--ink-muted); transition: background 140ms, color 140ms; font-family: var(--sans); text-align: center; }
  .tu-extra-btn:hover { background: var(--bg-3); color: var(--ink); }
  .tu-submit-btn { width: 100%; padding: 12px; border-radius: var(--r-pill); background: var(--ink); color: var(--bg); font-size: 13px; font-weight: 500; cursor: pointer; border: none; font-family: var(--sans); transition: filter 140ms; }
  .tu-submit-btn:hover { filter: brightness(1.08); }

  /* ===== Validation error banners ===== */
  .gen-error { font-size: 12px; color: var(--r-red); padding: 7px 11px; background: color-mix(in srgb, var(--r-red) 8%, var(--bg)); border-radius: var(--r-sm); border: 1px solid color-mix(in srgb, var(--r-red) 25%, var(--rule)); display: none; margin-top: 10px; }
  .gen-error.visible { display: block; }

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

  /* ===== Mock Exam Breakdown Phase ===== */
  #phase-mock-breakdown.active { display: flex !important; flex-direction: column; min-height: calc(100vh - 60px); }
  .bd-topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-bottom: 1px solid var(--rule-soft); flex-shrink: 0; background: var(--bg-2); }
  .bd-topbar-left { display: flex; align-items: center; gap: 12px; }
  
  
  
  .bd-score-chip { font-size: 12px; color: var(--ink-muted); background: var(--bg-3); padding: 3px 10px; border-radius: var(--r-pill); }
  .bd-analytics-btn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-muted); cursor: pointer; padding: 5px 12px; border-radius: var(--r-pill); border: 1px solid var(--rule-soft); background: transparent; transition: background 180ms; }
  .bd-analytics-btn:hover { background: var(--bg-3); }
  .bd-body { display: flex; flex: 1; min-height: 0; align-items: stretch; }
  /* Reuse exam-sidebar classes, just add bd-sidebar wrapper */
  .bd-sidebar { width: 190px; flex-shrink: 0; border-right: 1px solid var(--rule-soft); background: var(--bg-2); display: flex; flex-direction: column; overflow: hidden; transition: width 200ms var(--ease); }
  .bd-sidebar.collapsed { width: 44px; }
  .bd-sidebar.collapsed .q-grid,
  .bd-sidebar.collapsed .exam-sidebar-legend,
  .bd-sidebar.collapsed .est-lbl { display: none; }
  .bd-sidebar.collapsed .est-chev { transform: rotate(-90deg); }
  .bd-main { flex: 1; overflow-y: auto; padding: 22px 28px; min-width: 0; }
  /* Q grid squares for breakdown, color-coded by result */
  .bd-q-sq { width: 28px; height: 28px; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 600; cursor: pointer; border: 1.5px solid transparent; transition: border-color 160ms, transform 120ms; }
  .bd-q-sq:hover { transform: scale(1.08); }
  .bd-q-sq.full { background: color-mix(in srgb, var(--r-green) 30%, var(--bg-3)); color: var(--r-green); }
  .bd-q-sq.partial { background: color-mix(in srgb, var(--r-amber) 24%, var(--bg-3)); color: var(--r-amber); }
  .bd-q-sq.zero { background: color-mix(in srgb, var(--r-red) 24%, var(--bg-3)); color: var(--r-red); }
  .bd-q-sq.active-q { border-color: var(--ink) !important; }

  /* Analytics slide-in panel */
  .analytics-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 88vw); background: var(--bg-2); border-left: 1px solid var(--rule-soft); z-index: 8100; display: flex; flex-direction: column; transform: translateX(100%); transition: transform 320ms cubic-bezier(0.22,1.5,0.36,1); box-shadow:var(--shadow-lg); }
  .analytics-panel.open { transform: translateX(0); }
  .an-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--rule-soft); flex-shrink: 0; }
  .an-panel-head h3 { font-size: 13px; font-weight: 600; color: var(--ink); margin: 0; }
  .an-close-btn { width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--rule-soft); background: transparent; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--ink-muted); transition: background 180ms; }
  .an-close-btn:hover { background: var(--bg-3); }
  .an-panel-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
  .an-stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  
  
  
  
  .an-section-lbl { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; color: var(--ink-muted); margin: 0; }
  .an-bar-list { display: flex; flex-direction: column; gap: 8px; }
  
  
  
  

  /* ===== MCQ mode: hide answer card in question phase only (not exam mode) ===== */
  body.qm-mcq #phase-question .answer-card { display: none !important; }
  body.qm-mcq #phase-question .q-main-area { flex-direction: column !important; }
  body.qm-mcq #phase-question .q-card { min-height: 0 !important; overflow: visible !important; }
  /* MCQ submit bar, shown below question card for MCQ type */
  .mcq-submit-bar { display: none; padding: 12px 0 0; }
  body.qm-mcq #phase-question .mcq-submit-bar { display: flex; align-items: center; justify-content: flex-end; }

  /* ===== Graph questions ===== */
  /* draw-only + match formats reuse the bare-card layout (no text answer panel) */
  body.qm-graph-bare #phase-question .answer-card { display: none !important; }
  body.qm-graph-bare #phase-question .q-main-area { flex-direction: column !important; }
  body.qm-graph-bare #phase-question .q-card { min-height: 0 !important; overflow: visible !important; }
  body.qm-graph-bare #phase-question .mcq-submit-bar { display: flex; align-items: center; justify-content: flex-end; }
  /* the graph SVG host fills the diagram slot cleanly (no placeholder border/padding) */
  #q-diagram-area.graph-host { padding: 6px 0 0; background: transparent; border: none; color: inherit; }
  #q-diagram-area.graph-host svg { width: 100%; height: auto; display: block; }
  /* draw questions: the diagram lives in its own beige box (a separate division),
     stacked under the question card; the graph fills the full width so it's large. */
  .q-graph-box { background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-md);
    padding: 14px 16px; margin-bottom: 14px; }
  body.qm-drawq #phase-question .q-main-area { flex-direction: column !important; align-items: stretch; }
  /* the diagram box keeps its base .q-diagram flex-centering, which would shrink-wrap
     the drawing layout, force block so .gdraw-root fills the full width. */
  body.qm-drawq #phase-question #q-diagram-area.graph-host { display: block; padding: 0; }
  /* keep the tool column compact so the drawing area gets the width */
  body.qm-drawq #phase-question .q-graph-box .gdraw-tools-v { width: 116px; }
  
  
  /* match grid */
  .graph-match-area { display: none; flex-direction: column; gap: 8px; margin-top: 14px; }
  body.qm-graph-match #phase-question .graph-match-area { display: flex; }
  .gm-row { display: flex; align-items: center; gap: 10px; }
  .gm-left { flex: 1; font-size: 13px; color: var(--ink); line-height: 1.35; }
  .gm-right select { flex: 1; max-width: 52%; }
  /* result page: graph host + draw-only panel suppression */
  #res-q-graph-host.graph-host { padding: 6px 0 0; background: transparent; border: none; }
  #res-q-graph-host.graph-host svg { width: 100%; height: auto; display: block; }

  /* ===== Side-by-side ratio: question narrower, answer wider ===== */
  body.qm-layout-side .q-card { flex: 2 !important; }
  body.qm-layout-side .answer-card { flex: 3 !important; }

  /* Draw questions in side-by-side: keep the stem PINNED on the left half while the
     answer panels (draw box + text working) stack and scroll on the right half —
     instead of the default stacked column for draw questions. */
  body.qm-drawq.qm-layout-side #phase-question .q-main-area {
    display: grid !important; grid-template-columns: 2fr 3fr; gap: 16px; align-items: start;
  }
  body.qm-drawq.qm-layout-side #phase-question .q-card {
    grid-column: 1; grid-row: 1 / span 50; position: sticky; top: 8px; align-self: start;
    max-height: calc(100vh - 92px); overflow-y: auto; min-height: 0; margin-bottom: 0;
  }
  body.qm-drawq.qm-layout-side #phase-question #q-graph-box,
  body.qm-drawq.qm-layout-side #phase-question .part-rail,
  body.qm-drawq.qm-layout-side #phase-question .q-graph-panel,
  body.qm-drawq.qm-layout-side #phase-question .answer-card {
    grid-column: 2; margin-bottom: 0;
  }
  @media (max-width: 780px) {
    body.qm-drawq.qm-layout-side #phase-question .q-main-area { display: block !important; }
    body.qm-drawq.qm-layout-side #phase-question .q-card { position: static; max-height: none; }
  }

  /* ===== Graphical MCQ: question + options on the LEFT, graph on the RIGHT ===== */
  .q-graph-panel {
    background: var(--bg-2); border: 1px solid var(--rule-soft);
    border-radius: var(--r-md); padding: 22px 26px; margin-bottom: 14px;
  }
  .q-graph-panel .graph-host { padding: 0; background: transparent; border: none; color: inherit; width: 100%; }
  .q-graph-panel .graph-host svg { width: 100%; height: auto; display: block; }
  /* Two-panel row: only for graphical multiple-choice questions */
  body.qm-graph-mcq #phase-question .answer-card { display: none !important; }
  body.qm-graph-mcq #phase-question .q-main-area { flex-direction: row !important; flex-wrap: wrap; gap: 14px; align-items: stretch; }
  body.qm-graph-mcq #phase-question .q-card { flex: 1 1 0 !important; min-width: 0; min-height: 0 !important; overflow: visible !important; margin-bottom: 0; }
  body.qm-graph-mcq #phase-question .q-graph-panel { display: flex !important; flex-direction: column; justify-content: center; flex: 1 1 0; min-width: 0; margin-bottom: 0; }
  body.qm-graph-mcq #phase-question .mcq-submit-bar { display: flex; align-items: center; justify-content: flex-end; flex-basis: 100%; }
  /* Stack the two panels on narrow screens */
  @media (max-width: 820px) {
    body.qm-graph-mcq #phase-question .q-main-area { flex-direction: column !important; }
  }

  /* Structure diagrams (molecules / reaction schemes): always full width, molecule
     on top and the answer below, never side-by-side or the cramped two-panel. */
  body.qm-graph-structure #phase-question .q-main-area { flex-direction: column !important; align-items: stretch; }
  body.qm-graph-structure #phase-question .q-card,
  body.qm-graph-structure #phase-question .answer-card { flex: none !important; width: 100% !important; max-width: none !important; min-width: 0; }
  body.qm-graph-structure #phase-question .q-diagram.graph-host { min-height: 280px; }
  body.qm-graph-structure #phase-question .q-diagram.graph-host svg { max-height: 460px; }

  /* Tabular questions: full width like structure (the table is wide), table on top,
     answer below. The figure is a real <table>, not an SVG. */
  body.qm-graph-table #phase-question .q-main-area { flex-direction: column !important; align-items: stretch; }
  body.qm-graph-table #phase-question .q-card,
  body.qm-graph-table #phase-question .answer-card { flex: none !important; width: 100% !important; max-width: none !important; min-width: 0; }
  /* Table MCQ — stacked: stem → table → options; wide: stem+options left, table right */
  body.qm-table-mcq #phase-question .q-main-area { flex-direction: column !important; align-items: stretch; }
  body.qm-table-mcq #phase-question .q-card,
  body.qm-table-mcq #phase-question .answer-card { flex: none !important; width: 100% !important; max-width: none !important; min-width: 0; }
  body.qm-table-mcq #phase-question #q-stem-area { display: grid; gap: 14px; grid-template-columns: 1fr; grid-template-areas: "stem" "table" "options"; }
  body.qm-table-mcq #phase-question #q-stem-area > #q-stem-text { grid-area: stem; margin: 0; }
  body.qm-table-mcq #phase-question #q-stem-area > #q-diagram-area { grid-area: table; display: block; }
  body.qm-table-mcq #phase-question #q-stem-area > #q-mcq-opts-area { grid-area: options; }
  @media (min-width: 900px) {
    body.qm-table-mcq #phase-question #q-stem-area { grid-template-columns: 1fr 1fr; grid-template-areas: "stem table" "options table"; align-items: start; column-gap: 22px; }
  }
  .q-diagram.table-host { display: block; min-height: 0; background: transparent; border: none; padding: 0; margin: 14px 0; letter-spacing: normal; }

  /* Stimulus-grid MCQ (e.g. q07 — four structures + statement options). Stacked:
     stem → figure → options (figure ON TOP of the options). Side-by-side (layout
     toggle): stem+options on the left, the figure on the right. Toggle-driven, so
     "stacked" always keeps the compounds above the options. */
  body.qm-stim-mcq #phase-question .q-main-area { flex-direction: column !important; align-items: stretch; }
  body.qm-stim-mcq #phase-question .q-card { flex: none !important; width: 100% !important; max-width: none !important; min-width: 0; }
  body.qm-stim-mcq #phase-question #q-stem-area { display: grid; gap: 14px; grid-template-columns: 1fr; grid-template-areas: "stem" "figure" "options"; }
  body.qm-stim-mcq #phase-question #q-stem-area > #q-stem-text { grid-area: stem; margin: 0; }
  body.qm-stim-mcq #phase-question #q-stem-area > #q-diagram-area { grid-area: figure; display: block; }
  body.qm-stim-mcq #phase-question #q-stem-area > #q-mcq-opts-area { grid-area: options; }
  body.qm-stim-mcq.qm-layout-side #phase-question #q-stem-area {
    grid-template-columns: 1fr 1fr; grid-template-areas: "stem figure" "options figure"; align-items: start; column-gap: 22px;
  }

  /* ----- the real exam-style table ----- */
  .ionik-qtable-wrap { width: 100%; overflow-x: auto; }
  .ionik-qtable {
    border-collapse: collapse;
    width: 100%;
    font-family: var(--sans, 'Manrope', system-ui, sans-serif);
    font-size: 14px;
    color: var(--ink);
    background: var(--bg-2, transparent);
    border: 1px solid var(--rule, rgba(42,36,28,0.18));
    border-radius: var(--r-sm, 8px);
    overflow: hidden;
  }
  .ionik-qtable .qt-caption {
    caption-side: top;
    text-align: left;
    font-weight: 600;
    font-size: 14px;
    color: var(--ink);
    padding: 0 2px 10px;
    line-height: 1.4;
  }
  .ionik-qtable th.qt-cell,
  .ionik-qtable td.qt-cell {
    border: 1px solid var(--rule, rgba(42,36,28,0.18));
    padding: 10px 12px;
    text-align: left;
    vertical-align: top;
    line-height: 1.5;
  }
  .ionik-qtable thead th.qt-cell,
  .ionik-qtable th.qt-head {
    background: var(--bg-3, rgba(42,36,28,0.05));
    font-weight: 600;
    color: var(--ink);
  }
  .ionik-qtable tbody tr:nth-child(even) td.qt-cell { background: rgba(42,36,28,0.022); }
  .ionik-qtable .qt-muted { color: var(--ink-muted); font-weight: 400; }
  /* fill-in cell: a clear empty box telling the student a value/word is missing */
  .ionik-qtable td.qt-blank { text-align: center; vertical-align: middle; }
  .ionik-qtable .qt-box {
    display: inline-block;
    min-width: 64px;
    min-height: 22px;
    padding: 2px 8px;
    border: 1.5px dashed var(--rule, rgba(42,36,28,0.35));
    border-radius: var(--r-xs, 5px);
    background: transparent;
  }
  .ionik-qtable .qt-box-hint { border-style: solid; color: var(--ink-muted); font-size: 12px; }
  .qt-note { margin-top: 8px; font-size: 12px; color: var(--ink-muted); line-height: 1.5; }

  /* ===== Star/heart standardization, no circle bg, just colour the icon ===== */
  /* Action bar star/heart: fill icon, no background circle */
  .q-actionbar .ab#ab-star.on,
  .q-actionbar .ab#ab-heart.on { background: transparent !important; }
  .q-actionbar .ab#ab-star.on svg path { fill: var(--r-amber); stroke: var(--r-amber); }
  .q-actionbar .ab#ab-heart.on svg path { fill: var(--r-red); stroke: var(--r-red); }
  /* Result page icons: same fill behaviour */
  .res-icon-btn.star-on svg path { fill: var(--r-amber); stroke: var(--r-amber); }
  .res-icon-btn.heart-on svg path { fill: var(--r-red); stroke: var(--r-red); }
  .res-icon-btn { background: transparent !important; }
  /* Breakdown per-Q icon buttons */
  .bd-q-icon-btn { width: 24px; height: 24px; background: transparent; border: none; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; color: var(--ink-muted); transition: color 160ms; }
  .bd-q-icon-btn:hover { color: var(--ink); }
  .bd-q-icon-btn.star-on svg path { fill: var(--r-amber); stroke: var(--r-amber); }
  .bd-q-icon-btn.heart-on svg path { fill: var(--r-red); stroke: var(--r-red); }

  /* ===== Mock breakdown: page-native feel (no box) ===== */
  #phase-mock-breakdown.active { display: flex !important; flex-direction: column; padding: 0; }
  .bd-topbar { background: transparent !important; border-bottom: none !important; padding: 0 0 18px 0 !important; }
  .bd-body { gap: 0; }
  .bd-sidebar { background: transparent !important; border-right: 1px solid var(--rule-soft); }
  .bd-main { padding: 0 0 80px 24px; }
  /* Remove double border from panels inside bd-main */
  .bd-main .res-model-panel,
  .bd-main .res-criteria-panel { margin-top: 16px; }
  /* Make bd-main panels blend with page */
  .bd-main .res-two-col .res-col { background: transparent; border: none; padding: 0; }
  .bd-main .res-two-col { padding: 0; border: none; background: transparent; gap: 20px; }
  /* BD score / header: same as result page */
  #bd-res-header { padding: 0; border-bottom: 1px solid var(--rule-soft); padding-bottom: 16px; margin-bottom: 20px; }

  /* ===== Coming soon overlay for disabled subject items ===== */
  .item.coming-soon { opacity: 0.4; pointer-events: none; position: relative; }
  .item.coming-soon::after { content: 'Coming soon'; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 9px; letter-spacing: 0.06em; color: var(--ink-muted); background: var(--bg-3); padding: 1px 6px; border-radius: var(--r-pill); }

  /* ===== Side-by-side: fit the whole question (incl. a 2×2 spectra grid) AND the answer
     on one screen so the student never scrolls back and forth. ===== */
  /* Widen the page and pull it toward the edges, only on the question screen.
     Falls back gracefully where :has() is unsupported. */
  body.qm-layout-side:has(#phase-question.active) .qm-wrap {
    max-width: 1500px; padding-left: 28px; padding-right: 28px;
  }
  /* Spectroscopy: the four-spectra grid needs the bigger half, so the question leads. */
  body.qm-spectro.qm-layout-side .q-card { flex: 3 !important; }
  body.qm-spectro.qm-layout-side .answer-card { flex: 2 !important; }
  body.qm-layout-side .spectro-grid { gap: 8px; }
  body.qm-layout-side .spectro-canvas { height: 172px; }

  /* ===== Bug report panel ===== */
  .bug-overlay { position: fixed; inset: 0; background: rgba(42,36,28,0.28); z-index: 300; opacity: 0; pointer-events: none; transition: opacity 200ms var(--ease); }
  .bug-overlay.visible { opacity: 1; pointer-events: auto; }
  .bug-panel {
    position: fixed; top: 50%; left: 50%;
    transform: translate(-50%, -52%) scale(0.94);
    width: 360px; background: var(--bg); border: 1px solid var(--rule-soft);
    border-radius: var(--r-lg); z-index: 301; padding: 0;
    box-shadow:var(--shadow-lg);
    opacity: 0; pointer-events: none;
    transition: transform 260ms var(--spring-bouncy), opacity 200ms var(--ease);
    display: flex; flex-direction: column; overflow: hidden;
  }
  .bug-panel.open { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%) scale(1); }
  .bug-ph { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--rule-soft); }
  .bug-ph .bph-title { font-size: 13px; font-weight: 600; color: var(--ink); }
  .bug-ph .bph-close { width: 26px; height: 26px; border-radius: 999px; border: 1px solid var(--rule-soft); background: var(--bg-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--ink-muted); transition: background 140ms; }
  .bug-ph .bph-close:hover { background: var(--bg-3); }
  .bug-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
  .bug-qref { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-md); }
  .bug-qref-lbl { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 600; color: var(--ink-muted); }
  .bug-qref-stem { font-size: 12px; line-height: 1.45; color: var(--ink-soft); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
  .bug-field { display: flex; flex-direction: column; gap: 6px; }
  .bug-field label { font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; font-weight: 600; color: var(--ink-muted); }
  .bug-field select { padding: 9px 12px; background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-md); font-size: 13px; font-family: var(--sans); color: var(--ink); cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6 9l6 6 6-6' stroke='%237e7361' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 14px; }
  .bug-field select:focus { outline: none; border-color: color-mix(in srgb, var(--accent) 50%, var(--rule-soft)); }
  .bug-field textarea { padding: 9px 12px; background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-md); font-size: 13px; font-family: var(--sans); color: var(--ink); resize: vertical; min-height: 90px; line-height: 1.5; }
  .bug-field textarea::placeholder { color: var(--ink-faint); }
  .bug-field textarea:focus { outline: none; border-color: color-mix(in srgb, var(--accent) 50%, var(--rule-soft)); }
  .bug-submit-row { padding: 0 20px 20px; }
  .bug-submit { width: 100%; padding: 10px; background: var(--ink); color: var(--bg); border: 0; border-radius: var(--r-pill); font-size: 13px; font-weight: 500; font-family: var(--sans); cursor: pointer; transition: filter 140ms; }
  .bug-submit:hover { filter: brightness(1.12); }
  .bug-success { padding: 40px 24px; display: none; flex-direction: column; align-items: center; gap: 10px; text-align: center; }
  .bug-success.show { display: flex; }
  .bug-check-ring { width: 54px; height: 54px; border-radius: 999px; border: 2px solid var(--r-green); display: flex; align-items: center; justify-content: center; color: var(--r-green); margin-bottom: 4px; }
  .bug-thanks { font-size: 16px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em; }
  .bug-thanks-sub { font-size: 13px; color: var(--ink-muted); }
  .bug-close-btn { margin-top: 10px; padding: 8px 22px; background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-pill); font-size: 12px; font-weight: 500; font-family: var(--sans); color: var(--ink-soft); cursor: pointer; transition: background 140ms; }
  .bug-close-btn:hover { background: var(--bg-3); }

/* Last mock still marking: a quiet wait card, no pop-up */
.mock-wait .mrs-lbl { display: inline-flex; align-items: center; gap: 7px; }
.mock-wait .mw-track { margin-top: 10px; width: min(260px, 100%); height: 4px; border-radius: 999px; overflow: hidden; background: var(--bg-3); }
.mock-wait .mw-track i { display: block; height: 100%; width: 6%; border-radius: inherit; background: var(--accent); transition: width 320ms var(--ease); }
@media (prefers-reduced-motion: reduce) { .mock-wait .mw-track i { transition: none; } }
.gen-btn:disabled { opacity: 0.5; cursor: not-allowed; }
/* Busy state: the Ionik loader sits before the label */
.gen-btn > .ik-loader { margin: -2px 8px 0 0; }
.mark-toast .mt-sub { margin-top: 3px; font-size: 11.5px; color: var(--accent); font-weight: 500; }

/* Calculator takes the keyboard while it was the last thing touched */
.calc-head .ch-kbd { margin-left: 8px; margin-right: auto; padding: 2px 7px; border-radius: 999px; font-size: 9.5px; font-weight: 600; letter-spacing: 0.04em; color: var(--ink-faint); border: 1px solid var(--rule-soft); opacity: 0; transition: opacity 160ms var(--ease); cursor: help; }
.calc-float.kbd-on .ch-kbd { opacity: 1; color: var(--ink-muted); }
.calc-float.kbd-on { border-color: color-mix(in srgb, var(--ink) 28%, var(--rule-soft)); }
.calc-btn.kbd-press { background: var(--bg-3); color: var(--ink); transform: scale(0.93); }
.calc-btn.eq.kbd-press { filter: brightness(1.15); background: var(--accent); color: #fff; }

/* Periodic table and data sheet: − / + scale, data sheet can float */
.pt-float { width: min(calc(660px * var(--pt-scale, 1)), 96vw); }
.pt-float-body { zoom: var(--pt-scale, 1); }
.ds-body, .ds-tabs { zoom: var(--ds-scale, 1); }
.ds-panel { width: min(calc(560px * var(--ds-scale, 1)), 92vw); }
.ds-ctrl { display: flex; align-items: center; gap: 4px; }
.ds-cb { width: 26px; height: 26px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; color: var(--ink-muted); cursor: pointer; user-select: none; transition: background 140ms; }
.ds-cb:hover { background: var(--panel); color: var(--ink); }
.ds-panel.no-anim { transition: none; }
.ds-panel.floating {
  top: 80px; right: 24px; bottom: auto; left: auto;
  width: min(calc(460px * var(--ds-scale, 1)), 94vw); height: min(72vh, 680px);
  min-width: 280px; min-height: 240px; max-width: 96vw; max-height: 92vh;
  border: 1px solid var(--rule-soft); border-radius: var(--r-lg);
  overflow: hidden; resize: both;
  transform: none; display: none;
}
.ds-panel.floating.open { display: flex; }
.ds-panel.floating .ds-head { cursor: grab; user-select: none; touch-action: none; }
.ds-panel.floating .ds-head:active { cursor: grabbing; }

/* Download the paper as a PDF, top right of the exam, results and review */
.pdf-dl-btn { display: inline-flex; align-items: center; gap: 6px; font: 500 12px var(--sans); color: var(--ink-muted); cursor: pointer; padding: 5px 12px; border-radius: var(--r-pill); border: 1px solid var(--rule-soft); background: transparent; white-space: nowrap; transition: background 180ms, color 180ms; }
.pdf-dl-btn:hover { background: var(--bg-3); color: var(--ink); }
@media (max-width: 560px) { .exam-topbar .pdf-dl-btn { padding: 5px 9px; font-size: 0; gap: 0; } .exam-topbar .pdf-dl-btn svg { width: 14px; height: 14px; } }

/* The mock paper's title: beside the timer while sitting it, above the score after */
.exam-topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.exam-title-lbl { font-size: 12.5px; font-weight: 500; color: var(--ink-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 38vw; padding-left: 14px; border-left: 1px solid var(--rule-soft); }
.exam-title-lbl[hidden], .mr-title[hidden] { display: none; }
.mr-title { margin: 0 0 6px; font-size: 13px; font-weight: 600; letter-spacing: 0.02em; color: var(--ink-muted); }
@media (max-width: 560px) { .exam-title-lbl { display: none; } }

/* Admin preview (opened from the Admin knowledge grid): question only, no app chrome */
body.qm-preview .fluid-rail,
body.qm-preview [data-ionik-topbar],
body.qm-preview .top { display: none !important; }
body.qm-preview .shell { padding-left: 0 !important; }
.qm-preview-bar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0 0 16px; padding: 10px 14px;
  background: var(--bg-2); border: 1px solid var(--rule-soft); border-radius: var(--r-md);
}
.qm-preview-bar .qpb-text { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.qm-preview-bar .qpb-title { font-size: 13px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qm-preview-bar .qpb-pos { font-size: 12px; color: var(--ink-muted); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.qm-preview-bar .qpb-gpt, .qm-preview-bar .qpb-new { font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; flex-shrink: 0; }
.qm-preview-bar .qpb-gpt { color: #2a5d8a; background: color-mix(in srgb, #4a90d9 24%, transparent); }
.qm-preview-bar .qpb-new { color: #8a6a12; background: color-mix(in srgb, #e8c33f 32%, transparent); }
.qm-preview-bar .qpb-gpt[hidden], .qm-preview-bar .qpb-new[hidden] { display: none; }
:root[data-theme="dark"] .qm-preview-bar .qpb-gpt { color: #9cc7f2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .qm-preview-bar .qpb-gpt { color: #9cc7f2; } }
:root[data-theme="dark"] .qm-preview-bar .qpb-new { color: #f0d272; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .qm-preview-bar .qpb-new { color: #f0d272; } }
.qm-preview-bar .btn:disabled { opacity: .45; pointer-events: none; }

/* Mock exam batch marking: the results-page notice, and the build buttons
   while the last paper is still being marked (clickable; the click explains). */
.mr-batch-note { display: flex; align-items: flex-start; gap: 12px; margin: 0 0 14px; padding: 14px 16px; border-radius: var(--r-md); background: color-mix(in srgb, var(--accent) 8%, var(--bg)); border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent); color: var(--ink-soft); font-size: 13px; line-height: 1.5; }
.mr-batch-note b { display: block; color: var(--ink); font-weight: 600; margin-bottom: 2px; }
.mr-batch-note p { margin: 0; }
.mr-batch-note .ik-loader { margin-top: 3px; }
#mock-gen-btn.is-waiting, #mock-start-online.is-waiting { opacity: .55; }

/* Unreadable photo: the question screen's upload box sits under the faded
   photo in Your Answer, and Resubmit is a small pill beside Next question. */
#res-student-answer .sa-unreadable { opacity: .45; filter: grayscale(.4); }
#res-student-answer .upload-wrap.res-reupload { margin-top: 12px; }
.res-actions-row .res-resubmit { border-radius: var(--r-pill); }
