/* ==========================================================================
   AlNajdi — Quiz & question type styles
   ========================================================================== */

/* — Quiz layout — */
.quiz-wrap {
    max-width: 820px;
    margin: 0 auto;
    padding: var(--s-4) var(--s-5) var(--s-7);
    min-height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.quiz-wrap.exam-quiz-wrap { max-width: 1120px; }

/* Shared-link invitation: public metadata first, authentication on intent. */
.question-set-preview-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at 50% 20%, color-mix(in oklab, var(--brand-300) 13%, transparent), transparent 34%),
        var(--bg);
}
.question-set-preview-main {
    min-height: calc(100vh - 65px);
    display: grid;
    place-items: center;
    padding: clamp(28px, 7vw, 84px) 20px;
}
.question-set-preview-card {
    width: min(100%, 620px);
    position: relative;
    overflow: hidden;
    padding: clamp(28px, 6vw, 52px);
    border: 1px solid var(--border);
    border-radius: 30px;
    background: var(--bg-elev);
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.question-set-preview-card::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 5px;
    background: linear-gradient(90deg, var(--brand-300), var(--brand-600), var(--brand-300));
}
.question-set-preview-mark {
    width: 68px;
    height: 68px;
    display: grid;
    place-items: center;
    margin: 0 auto 20px;
    border: 1px solid var(--border-strong);
    border-radius: 22px;
    background: var(--bg-elev-2);
    color: var(--text);
    transform: rotate(-3deg);
}
[dir="rtl"] .question-set-preview-mark { transform: rotate(3deg); }
.question-set-preview-kicker {
    margin: 0 0 9px;
    color: var(--text-mute);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .12em;
}
.question-set-preview-card h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(30px, 6vw, 46px);
    font-weight: 800;
    line-height: 1.18;
    letter-spacing: -.035em;
    overflow-wrap: anywhere;
}
[dir="rtl"] .question-set-preview-card h1 { letter-spacing: 0; }
.question-set-preview-subject {
    margin: 10px 0 0;
    color: var(--text-mute);
    font-size: 15px;
    font-weight: 600;
}
.question-set-preview-details {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin: 30px 0 22px;
}
.question-set-preview-detail {
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--bg-elev-2);
    text-align: start;
}
.question-set-preview-detail dt {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 8px;
    color: var(--text-mute);
    font-size: 12px;
    font-weight: 700;
}
.question-set-preview-detail dd {
    margin: 0;
    color: var(--text);
    font-size: 18px;
    font-weight: 800;
    line-height: 1.35;
    overflow-wrap: anywhere;
}
.question-set-preview-start {
    width: 100%;
    min-height: 52px;
    font-size: 16px;
}
.question-set-preview-note {
    margin: 12px 0 0;
    color: var(--text-mute);
    font-size: 13px;
}

@media (max-width: 580px) {
    .question-set-preview-nav .brand-name {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .question-set-preview-main {
        min-height: calc(100svh - 59px);
        padding: 22px 14px 34px;
    }
    .question-set-preview-card { padding: 28px 18px 24px; border-radius: 24px; }
    .question-set-preview-mark { width: 58px; height: 58px; margin-bottom: 16px; border-radius: 19px; }
    .question-set-preview-card h1 { font-size: clamp(27px, 9vw, 36px); }
    .question-set-preview-details { grid-template-columns: 1fr; margin-top: 24px; }
    .question-set-preview-detail { padding: 14px 16px; }
}

.exam-question-layout.has-context {
    display: grid;
    grid-template-columns: minmax(300px, .92fr) minmax(0, 1.08fr);
    gap: 24px;
    align-items: start;
}
.exam-question-pane { min-width: 0; }
.exam-context-pane {
    position: sticky;
    top: 82px;
    align-self: start;
    max-height: calc(100vh - 104px);
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding-inline-end: 4px;
}
.exam-context-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: 22px;
    box-shadow: var(--shadow);
    text-align: start;
    unicode-bidi: isolate;
}
.exam-context-card + .exam-context-card { margin-top: 14px; }
.exam-context-kicker {
    margin: 0 0 14px;
    color: var(--text-mute);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.exam-context-content {
    color: var(--text);
    font-size: 17px;
    line-height: 1.72;
    max-width: 72ch;
}
.exam-context-content p { margin: 0 0 1em; }
.exam-context-content p:last-child { margin-bottom: 0; }
.exam-context-content table { width: 100%; border-collapse: collapse; }
.exam-context-content th,
.exam-context-content td { padding: 8px 10px; border: 1px solid var(--border); text-align: center; }
.exam-reading-nav {
    display: none;
    gap: 8px;
}
.exam-reading-start {
    padding: 22px;
    border: 1px solid var(--brand-400);
    border-radius: var(--r-xl);
    background: var(--bg-elev);
    box-shadow: var(--shadow);
    text-align: center;
}
.exam-reading-start p { margin: 0 0 18px; color: var(--text-soft); line-height: 1.6; }
.exam-section-identity {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 14px;
    padding: 8px 11px;
    border-inline-start: 3px solid var(--brand-500);
    background: var(--brand-50);
    color: var(--brand-700);
    font-size: 13px;
    font-weight: 800;
}
.exam-section-range { font-family: var(--font-mono); white-space: nowrap; }
.exam-section-nav {
    display: flex;
    gap: 8px;
    max-width: 100%;
    padding: 2px 1px 4px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-snap-type: inline proximity;
    scrollbar-width: thin;
}
.exam-section-tab {
    flex: 0 0 auto;
    min-width: 138px;
    max-width: 230px;
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 11px;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    background: var(--bg-elev);
    color: var(--text-soft);
    font: inherit;
    cursor: pointer;
    scroll-snap-align: start;
    transition: border-color .15s ease, background-color .15s ease, color .15s ease;
}
.exam-section-tab:hover { border-color: var(--brand-300); color: var(--text); }
.exam-section-tab:focus-visible { outline: 3px solid var(--brand-300); outline-offset: 2px; }
.exam-section-tab.active {
    border-color: var(--brand-500);
    background: var(--brand-50);
    color: var(--brand-700);
}
.exam-section-tab-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 800;
}
.exam-section-tab-meta {
    flex: 0 0 auto;
    padding: 2px 7px;
    border-radius: var(--r-full);
    background: var(--bg-elev-2);
    color: var(--text-mute);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 800;
}
.exam-section-tab.active .exam-section-tab-meta {
    background: var(--brand-100);
    color: var(--brand-700);
}

/* Head: progress bar row + stats bar */
.quiz-head { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.quiz-progress-row { display: flex; align-items: center; gap: 12px; }
.progress-bar {
    flex: 1;
    height: 10px;
    border-radius: var(--r-full);
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--brand-400), var(--brand-600));
    border-radius: var(--r-full);
    transition: width .4s cubic-bezier(.2,.8,.3,1);
}
.quiz-counter {
    font-weight: 700;
    font-size: 13px;
    color: var(--text-mute);
    white-space: nowrap;
    min-width: 48px;
    text-align: end;
}
.exam-timer {
    min-width: 64px;
    padding: 5px 9px;
    border: 1px solid var(--border);
    border-radius: var(--r-full);
    background: var(--bg-elev);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 800;
    text-align: center;
    white-space: nowrap;
}
.exam-timer.urgent { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }

/* Stats bar — correct / wrong / remaining pills */
.stats-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--r-full);
    font-weight: 700;
    font-size: 13px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    color: var(--text-soft);
}
.stat-pill.correct { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.stat-pill.wrong   { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.stat-pill.remaining { background: var(--bg-elev-2); }
.stat-pct {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-mute);
    margin-inline-start: 4px;
}
[data-theme="dark"] .stat-pill.correct { background: rgba(5, 150, 105, .18); }
[data-theme="dark"] .stat-pill.wrong   { background: rgba(220, 38, 38, .18); }

/* Result bar (previous Q result) */
.quiz-result-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0;
    border-radius: var(--r-lg);
    font-weight: 700;
    font-size: 14px;
    max-height: 0;
    overflow: hidden;
    transition: max-height .2s, padding .2s, opacity .2s;
    opacity: 0;
}
.quiz-result-bar.show {
    max-height: 56px;
    padding: 10px 16px;
    opacity: 1;
    margin-bottom: 18px; /* gap between the verdict bar and the question card */
}
.quiz-result-bar.ok   { background: var(--ok-bg); color: var(--ok); }
.quiz-result-bar.bad  { background: var(--bad-bg); color: var(--bad); }
.quiz-result-bar.warn { background: var(--warn-bg); color: var(--warn); }
[data-theme="dark"] .quiz-result-bar.ok   { background: rgba(5, 150, 105, .18); }
[data-theme="dark"] .quiz-result-bar.bad  { background: rgba(220, 38, 38, .18); }
[data-theme="dark"] .quiz-result-bar.warn { background: rgba(217, 119, 6, .18); }
.result-bar-verdict { display: flex; align-items: center; gap: 8px; }
.result-bar-score   { font-size: 13px; opacity: .75; }

/* — Question card — */
.q-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: var(--s-6);
    box-shadow: var(--shadow);
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}
/* On-card repeat (re-read) control — a real top row, aligned to the inline
   end. Flow layout instead of absolute positioning, so no question text can
   ever run underneath it. */
.q-card-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 6px;
}
.q-repeat-btn {
    width: 38px; height: 38px;
    display: inline-grid; place-items: center;
    border: 1px solid var(--border);
    background: var(--bg-elev-2);
    color: var(--text-soft);
    border-radius: var(--r-full);
    cursor: pointer;
    transition: color .15s ease, border-color .15s ease, background .15s ease;
}
.q-repeat-btn:hover { color: var(--brand-600, var(--brand-500)); border-color: var(--brand-500); background: var(--brand-50); }
.q-repeat-btn:active { transform: scale(.94); }
.q-card[dir],
.q-block[dir] {
    text-align: start;
    unicode-bidi: isolate;
}
.q-prompt,
.q-host,
.opt {
    text-align: start;
}

/* — Actions row (back / check·continue / forward) — */
.quiz-actions {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 4px 0;
    margin-top: 24px; /* gap between the question card and the action row */
}
.quiz-actions-center {
    display: flex;
    justify-content: center;
    gap: 10px;
}
.quiz-nav-arr {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    min-width: 80px;
}
.quiz-nav-arr:disabled { opacity: .35; cursor: not-allowed; }
[dir="rtl"] .quiz-nav-arr svg { transform: scaleX(-1); }

.q-prompt {
    font-size: 20px;
    font-weight: 600;
    line-height: 1.5;
    margin-bottom: var(--s-5);
    color: var(--text);
}
.q-prompt p { margin: 0 0 var(--s-3); }
.q-prompt p:last-child { margin-bottom: 0; }
.q-prompt img, .q-prompt video {
    border-radius: var(--r);
    margin: var(--s-3) 0;
    max-height: 360px;
    border: 1px solid var(--border);
}
.q-prompt,
.opt > span:not(.opt-marker),
.exam-context-content {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
}
.katex-display {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-block: 2px;
}
.q-tag {
    display: inline-flex; gap: 6px; font-size: 12.5px; font-weight: 700;
    background: var(--brand-50); color: var(--brand-700);
    padding: 4px 10px; border-radius: 999px;
    margin-bottom: var(--s-3);
    text-transform: uppercase; letter-spacing: .04em;
}

/* — MCQ & multi-select options — */
.opt {
    display: flex; align-items: center; gap: 14px;
    padding: 14px 18px;
    border: 2px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease, transform .08s ease;
    font-weight: 600;
    margin-bottom: 10px;
    background: var(--bg-elev);
    user-select: none;
}
.opt > span:not(.opt-marker) {
    flex: 1;
    min-width: 0;
}
.opt:hover { border-color: var(--brand-300); }
.opt.selected { border-color: var(--brand-500); background: var(--brand-50); color: var(--brand-700); }
.opt.correct { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt-marker {
    width: 28px; height: 28px; border-radius: 50%;
    border: 2px solid var(--border-strong);
    display: grid; place-items: center;
    font-size: 13px; font-weight: 800;
    color: var(--text-mute);
    flex-shrink: 0;
}
.opt.selected .opt-marker {
    border-color: var(--brand-500);
    background: var(--brand-500);
    color: var(--on-brand);
}
.opt.correct .opt-marker {
    border-color: var(--ok);
    background: var(--ok);
    color: white;
}
.opt.wrong .opt-marker {
    border-color: var(--bad);
    background: var(--bad);
    color: white;
}
.opt input[type="checkbox"] { display: none; }
.opt-radio-input {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}
.opt-radio-input:focus-visible + .opt-marker {
    outline: 3px solid var(--brand-300);
    outline-offset: 3px;
}
.opt:has(.opt-radio-input:disabled) { cursor: default; }

/* — Inputs that appear inline inside question prompts — */
.q-prompt input[type="number"],
.q-prompt input[type="text"] {
    border: 0;
    border-bottom: 2px dashed var(--border-strong);
    background: transparent;
    color: var(--text);
    font: inherit;
    font-weight: 700;
    padding: 2px 6px;
    min-width: 70px; max-width: 160px;
    text-align: center;
    transition: border-color .15s ease;
}
.q-prompt input:focus {
    outline: none;
    border-bottom-color: var(--brand-500);
}

/* — True / False — */
.tf-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
}
.tf-btn {
    padding: 24px;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    text-align: center;
    font-size: 18px;
    font-weight: 800;
    border-radius: 16px;
    border: 2px solid var(--border);
    background: var(--bg-elev);
    color: var(--text);
    cursor: pointer;
    transition: all .15s ease;
}
.tf-btn:hover { border-color: var(--brand-400); }
.tf-btn.selected { border-color: var(--brand-500); background: var(--brand-50); color: var(--brand-700); }

/* — Matching — */
.match-board {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 80px minmax(0, 1fr);
    gap: 0;
}
.match-col { display: flex; flex-direction: column; gap: 12px; }
.match-item {
    width: 100%;
    min-width: 0;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg-elev);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    line-height: 1.4;
    text-align: start;
    overflow-wrap: anywhere;
    position: relative;
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease, color .15s ease;
}
.match-item:hover { border-color: var(--brand-400); }
.match-item.active { border-color: var(--brand-500); background: var(--brand-50); }
.match-item:focus-visible { outline: 3px solid var(--brand-300); outline-offset: 3px; }
.match-dot {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 14px; height: 14px;
    border-radius: 50%;
    background: var(--bg-elev);
    border: 2.5px solid var(--border-strong);
}
.match-col.left .match-dot  { inset-inline-end: -8px; }
.match-col.right .match-dot { inset-inline-start: -8px; }
.match-item.linked .match-dot { background: currentColor; border-color: currentColor; }
.match-review-mark {
    display: none;
    position: absolute;
    inset-block-start: -10px;
    inset-inline-start: -10px;
    width: 22px;
    height: 22px;
    place-items: center;
    border: 2px solid var(--bg-elev);
    border-radius: 50%;
    color: white;
    font-size: 14px;
    font-weight: 900;
    line-height: 1;
}
.match-board.reviewed .match-item { cursor: default; }
.match-board.reviewed .match-item:hover { border-color: var(--border); }
.match-board.reviewed .match-item.is-correct {
    border-color: var(--ok);
    background: var(--ok-bg);
    color: var(--ok);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--ok) 20%, transparent);
}
.match-board.reviewed .match-item.is-wrong {
    border-color: var(--bad);
    background: var(--bad-bg);
    color: var(--bad);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--bad) 20%, transparent);
}
.match-board.reviewed .match-item.is-correct .match-review-mark,
.match-board.reviewed .match-item.is-wrong .match-review-mark { display: grid; }
.match-item.is-correct .match-review-mark { background: var(--ok); }
.match-item.is-wrong .match-review-mark { background: var(--bad); }
.match-svg {
    position: absolute; inset: 0;
    pointer-events: none;
}
.match-wire.is-correct { stroke: var(--ok); }
.match-wire.is-wrong { stroke: var(--bad); }

@media (max-width: 640px) {
    .match-board { grid-template-columns: minmax(0, 1fr) 52px minmax(0, 1fr); }
    .match-item { padding: 13px 12px; }
}

/* — Drag and drop — */
.dnd-grid { display: grid; gap: var(--s-4); grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) { .dnd-grid { grid-template-columns: 1fr; } }
.dnd-bin {
    border: 2.5px dashed var(--border-strong);
    border-radius: var(--r-lg);
    padding: var(--s-4);
    min-height: 120px;
    background: var(--bg-elev-2);
    transition: border-color .15s ease, background .15s ease;
}
.dnd-bin.over { border-color: var(--brand-500); background: var(--brand-50); }
.dnd-bin .bin-label { font-size: 13px; font-weight: 700; color: var(--text-soft); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .04em; }
.dnd-tile {
    display: inline-block;
    padding: 10px 14px;
    margin: 4px;
    border-radius: 10px;
    background: var(--bg-elev);
    border: 2px solid var(--border);
    cursor: grab;
    font-weight: 600;
    user-select: none;
    /* Pointer drag must beat page scrolling on touch, otherwise the browser
       claims the gesture and the tile only moves after a long-press. */
    touch-action: none;
    -webkit-touch-callout: none;
}
.dnd-tile:active { cursor: grabbing; }
.dnd-tile.dragging { opacity: .45; }
.dnd-tile.selected { outline: 3px solid var(--brand-200, #93c5fd); outline-offset: 2px; }
.dnd-tile:focus-visible,
.dnd-bin:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }
.dnd-drag-ghost {
    position: fixed; z-index: 3200; pointer-events: none;
    transform: translate(-50%, -50%);
    background: var(--bg-elev); color: var(--text);
    border: 2px solid var(--brand-500); border-radius: 10px;
    padding: 10px 14px; font-weight: 600;
    box-shadow: var(--shadow-pop); opacity: .94;
}
.dnd-hint { margin: 16px 0 0; font-size: 13px; color: var(--text-mute); }

/* — Diagram labeling — */
.diagram-wrap {
    position: relative;
    width: 100%;
    border-radius: var(--r-lg);
    overflow: hidden;
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
}
.diagram-wrap img { width: 100%; display: block; }
.diagram-pin {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--brand-500);
    color: var(--on-brand);
    display: grid; place-items: center;
    font-weight: 800; font-size: 14px;
    border: 3px solid var(--bg-elev);
    box-shadow: 0 4px 14px rgba(0,0,0,.25);
    cursor: pointer;
    transition: transform .15s ease;
}
.diagram-pin:hover { transform: translate(-50%, -50%) scale(1.1); }
.diagram-pin.labeled { background: var(--brand-700); }
.diagram-labels { margin-top: var(--s-4); display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.diagram-row {
    display: flex; align-items: center; gap: 10px;
}
.diagram-row .pin-num {
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--brand-500); color: var(--on-brand);
    display: grid; place-items: center; font-weight: 800; font-size: 12.5px;
    flex-shrink: 0;
}

/* — Graph plotting — */
.graph-canvas {
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: var(--r);
    cursor: crosshair;
    touch-action: none;
    width: 100%; max-width: 100%;
    display: block;
}
.graph-tools { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }

/* — Code editor — */
.code-block {
    background: #0e1612;
    color: #d6e6db;
    border-radius: var(--r);
    padding: var(--s-4);
    font-family: var(--font-mono);
    font-size: 13.5px;
    line-height: 1.55;
    overflow: auto;
    border: 1px solid #1e2925;
}
.code-block textarea {
    display: block;
    width: 100%;
    min-height: 220px;
    background: transparent;
    color: inherit;
    border: 0;
    font: inherit;
    resize: none;
    overflow-y: hidden;
    outline: none;
}
.code-output {
    margin-top: 12px;
    padding: 12px;
    border-radius: var(--r);
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    font-family: var(--font-mono);
    font-size: 13px;
    white-space: pre-wrap;
    max-height: 260px;
    overflow: auto;
}

/* — Math / Special keyboards — */
.symbol-keyboard {
    margin-top: 10px;
    display: flex; flex-wrap: wrap; gap: 6px;
    padding: 10px;
    border-radius: var(--r);
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
}
.sym-btn {
    min-width: 38px; height: 36px; padding: 0 10px;
    border-radius: 8px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    transition: background-color .12s ease;
}
.sym-btn:hover { background: var(--brand-50); color: var(--brand-700); }

/* — Feedback panel — */
.feedback {
    margin-top: var(--s-4);
    padding: var(--s-4) var(--s-5);
    border-radius: var(--r-lg);
    border-inline-start: 6px solid;
    display: none;
    animation: pop .25s cubic-bezier(.2,1,.4,1);
}
.feedback.show { display: block; }
.feedback.ok  { border-color: var(--ok);  background: var(--ok-bg);  color: #115f33; }
.feedback.bad { border-color: var(--bad); background: var(--bad-bg); color: #8b1a1a; }
.feedback.warn { border-color: var(--warn); background: var(--warn-bg); color: #6e4a01; }
:root[data-theme="dark"] .feedback.ok { color: #b6e6c4; }
:root[data-theme="dark"] .feedback.bad { color: #ffc1c1; }
:root[data-theme="dark"] .feedback.warn { color: #f5d27a; }
.feedback h4 { margin: 0 0 6px; font-size: 17px; font-family: var(--font-display); }
.feedback p { margin: 0; }

/* — All-questions scroll layout — */
.all-view {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-block: clamp(24px, 14vh, 128px) clamp(96px, 38vh, 340px);
}
.q-block {
    background: color-mix(in oklab, var(--bg-elev) 78%, var(--bg-elev-2));
    border: 1.5px solid var(--border);
    border-radius: var(--r-xl);
    padding: var(--s-5) var(--s-6);
    box-shadow: var(--shadow-xs);
    opacity: .72;
    filter: grayscale(.18) saturate(.78);
    transform: scale(.975);
    transform-origin: center;
    transition: border-color .18s, background .18s, box-shadow .18s, opacity .18s, filter .18s, transform .18s;
    animation: question-batch-enter .22s ease-out;
}
@keyframes question-batch-enter {
    from { opacity: 0; transform: translateY(8px) scale(.975); }
    to { opacity: .72; transform: translateY(0) scale(.975); }
}
.q-block-ok  { border-color: var(--ok); }
.q-block-bad { border-color: var(--bad); }
.q-block-active,
.q-block-active.q-block-ok,
.q-block-active.q-block-bad {
    background: var(--bg-elev);
    border-color: #fff;
    box-shadow: 0 0 0 1px var(--border-strong), var(--shadow-lg);
    opacity: 1;
    filter: none;
    transform: scale(1.015);
}
.q-block-hd {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; margin-bottom: 12px;
}
.q-block-num   { font-size: 12px; color: var(--text-mute); font-weight: 600; }
.q-block-badge { display: inline-flex; align-items: center; line-height: 1; }
.q-block-badge.ok { color: var(--ok); }
.q-block-badge.bad { color: var(--bad); }

@media (prefers-reduced-motion: reduce) {
    .q-block,
    .q-block-active { animation: none; transition: none; }
}

/* — Inline feedback — */
.q-feedback { border-top: 1px solid var(--border); margin-top: 20px; padding-top: 14px; }
.fb-verdict { margin: 0 0 6px; font-size: 16px; font-weight: 700; }
.fb-verdict.ok   { color: var(--ok); }
.fb-verdict.bad  { color: var(--bad); }
.fb-verdict.warn { color: var(--warn); }
.fb-explanation  { color: var(--text-soft); font-size: 14px; margin: 0; line-height: 1.5; }

/* — Auto-advance pending bar — */
.auto-pending { position: relative; overflow: hidden; }
.auto-pending::after {
    content: "";
    position: absolute; bottom: 0; left: 0;
    width: 100%; height: 3px;
    background: rgba(255,255,255,.5);
    animation: auto-progress 1.6s linear forwards;
}
@keyframes auto-progress { from { transform: translateX(-100%); } to { transform: translateX(0); } }

/* — Result screen — */
.result-wrap { text-align: center; padding: var(--s-5) var(--s-4); }
.result-ring {
    width: 140px; height: 140px; border-radius: 50%;
    display: grid; place-items: center; margin: 0 auto 24px;
}
.result-ring-inner {
    width: 106px; height: 106px; border-radius: 50%;
    background: var(--bg-elev);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.result-pct { font-size: 30px; font-weight: 800; color: var(--text); line-height: 1; }
.result-pct-label { font-size: 13px; color: var(--text-mute); }
.result-title { margin: 0 0 20px; font-size: 22px; font-weight: 800; }
.result-stats-row {
    display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px;
}
.result-stat-box {
    background: var(--bg-elev-2); border: 1px solid var(--border);
    border-radius: var(--r-lg); padding: 14px 22px; min-width: 90px;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.result-stat-box.ok  { background: var(--ok-bg); border-color: transparent; }
.result-stat-box.bad { background: var(--bad-bg); border-color: transparent; }
[data-theme="dark"] .result-stat-box.ok  { background: rgba(5, 150, 105, .2); }
[data-theme="dark"] .result-stat-box.bad { background: rgba(220, 38, 38, .2); }
.rs-num   { font-size: 28px; font-weight: 800; color: var(--text); }
.rs-label { font-size: 12px; color: var(--text-mute); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.result-stat-box.ok  .rs-num { color: var(--ok); }
.result-stat-box.bad .rs-num { color: var(--bad); }

/* — Fill-in-the-blank — */
.fill-wrap { line-height: 2.4; font-size: 17px; }
.fill-wrap .fill-blank {
    display: inline-block; width: 9ch; min-width: 80px; max-width: 180px;
    padding: 4px 10px; margin: 0 4px; border-radius: 8px;
    font: inherit; vertical-align: baseline; text-align: center;
}

/* — Fill the blanks from a word bank (cloze) — */
.fb-wrap { font-size: 17px; }
.fb-sentence { line-height: 2.3; }
.fb-text { white-space: pre-wrap; }
.fb-blank {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 44px; min-height: 26px; padding: 2px 9px; margin: 0 3px;
    line-height: 1.25;
    border: 2px solid var(--brand-500); border-radius: 7px;
    vertical-align: middle; cursor: pointer; user-select: none;
    touch-action: none;
    transition: background .12s, border-color .12s, box-shadow .12s;
}
.fb-blank.filled { background: var(--brand-500); color: var(--on-brand); border-color: var(--brand-500); font-weight: 700; }
.fb-blank.fb-target { box-shadow: 0 0 0 3px var(--brand-50); border-style: dashed; }
.fb-blank.fb-ok  { background: var(--ok-bg);  border-color: var(--ok);  color: var(--ok); }
.fb-blank.fb-bad { background: var(--bad-bg); border-color: var(--bad); color: var(--bad); }
.fb-bank { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.fb-chip {
    background: var(--brand-500); color: var(--on-brand);
    border: 0; border-radius: 8px; padding: 8px 15px;
    font: inherit; font-weight: 700; line-height: 1.2; cursor: pointer;
    touch-action: none;
    box-shadow: 0 2px 8px rgba(37,99,235,.25); transition: transform .1s, box-shadow .12s, outline-color .12s, opacity .12s;
}
.fb-chip:hover:not(:disabled) { transform: translateY(-1px); }
.fb-chip:active { cursor: grabbing; }
.fb-chip.fb-chip-sel { outline: 3px solid var(--brand-200, #93c5fd); outline-offset: 2px; }
.fb-chip.fb-chip-drag { opacity: .45; }
.fb-chip:disabled { opacity: .6; cursor: default; box-shadow: none; }
.fb-drag-ghost {
    position: fixed; z-index: 3200; pointer-events: none;
    transform: translate(-50%, -50%);
    background: var(--brand-500); color: var(--on-brand);
    border-radius: 8px; padding: 8px 15px; font-weight: 700;
    box-shadow: var(--shadow-pop); opacity: .94;
}
.fb-hint { margin: 16px 0 0; font-size: 13px; color: var(--text-mute); }

/* A question view failed to render — keep the rest of the quiz alive. */
.q-render-error {
    display: grid; gap: 10px; justify-items: start;
    padding: 16px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--r-md);
    color: var(--text-soft);
}

/* — Drag & drop — */
.dnd-pool { margin-bottom: 18px; border-style: dashed; }

/* — Diagram label popup — */
.pin-menu {
    background: var(--bg-elev); border: 1px solid var(--border);
    border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.18); padding: 6px;
}
.pin-menu-item {
    display: block; width: 100%; text-align: start; padding: 10px 14px;
    background: transparent; border: 0; border-radius: 10px;
    font: inherit; color: inherit; cursor: pointer;
}
.pin-menu-item:hover:not(.disabled) { background: var(--bg-elev-2); }
.pin-menu-item.disabled { opacity: .45; cursor: not-allowed; }

@media (max-width: 580px) {
    .quiz-wrap { padding: var(--s-3); gap: 8px; }
    .all-view { gap: 28px; padding-inline: 8px; }
    .q-card, .q-block { padding: var(--s-4); border-radius: var(--r-lg); }
    .q-block {
        opacity: .5;
        filter: grayscale(.55) saturate(.55) brightness(.76);
        transform: scale(.92);
    }
    .q-block-active,
    .q-block-active.q-block-ok,
    .q-block-active.q-block-bad {
        border-width: 2px;
        opacity: 1;
        filter: none;
        transform: scale(1.01);
    }
    .q-prompt { font-size: 17px; }
    .quiz-actions { grid-template-columns: auto 1fr auto; gap: 6px; }
    .quiz-nav-arr { min-width: 52px; padding: 10px 8px; font-size: 12px; }
    .result-stats-row { gap: 8px; }
    .result-stat-box { padding: 12px 16px; min-width: 76px; }
    .rs-num { font-size: 22px; }
}

@media (max-width: 820px) {
    .exam-question-layout.has-context { display: block; }
    .exam-context-pane {
        position: static;
        max-height: none;
        overflow: visible;
        padding-inline-end: 0;
        margin-bottom: 10px;
        scroll-margin-top: 78px;
    }
    .exam-reading-nav {
        position: sticky;
        top: 66px;
        z-index: 12;
        display: flex;
        gap: 8px;
        margin-bottom: 10px;
        padding: 8px;
        background: color-mix(in srgb, var(--bg) 92%, transparent);
        backdrop-filter: blur(12px);
        border: 1px solid var(--border);
        border-radius: var(--r-lg);
    }
    .exam-reading-nav button {
        flex: 1;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 7px;
        border: 0;
        border-radius: var(--r);
        background: var(--bg-elev-2);
        color: var(--text);
        font: inherit;
        font-size: 13px;
        font-weight: 800;
        cursor: pointer;
    }
    .exam-reading-nav button.active { background: var(--brand-50); color: var(--brand-700); }
    .exam-reading-nav button:focus-visible { outline: 3px solid var(--brand-300); outline-offset: 1px; }
    .exam-question-pane > .q-card { scroll-margin-top: 138px; }
}

/* ─── Read-aloud toggle ───────────────────────────────────────────
   The toggle lives in the quiz top nav. We layer two visual states
   on top of the base .icon-btn:
     .active           — toggle is ON (idle)
     .voice-speaking   — currently reading a question (blue pulse)
   The pulse is a CSS ring animation rather than a JS-driven indicator
   so it never desyncs from the actual player state. */
.voice-toggle.active {
    background: var(--brand-50);
    color: var(--brand-700);
    border-color: var(--brand-300);
}
.voice-toggle.voice-speaking {
    position: relative;
    background: var(--brand-100, #cfe8ff);
    color: var(--brand-700, #1d4ed8);
    border-color: var(--brand-500, #2563eb);
}
.voice-toggle.voice-speaking::after {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: var(--r-full);
    border: 2px solid currentColor;
    animation: voice-pulse 1.1s ease-out infinite;
    pointer-events: none;
}
@keyframes voice-pulse {
    0%   { transform: scale(1);   opacity: .9; }
    70%  { transform: scale(1.4); opacity: 0; }
    100% { transform: scale(1.4); opacity: 0; }
}
