/* ======================================
   SAT FORGE — TEST PAGE
======================================= */

:root {
    --test-header-height: 80px;
    --test-footer-height: 76px;
    --calculator-split-width: min(50vw, 760px);
    --test-blue: #2563eb;
    --test-blue-dark: #1d4ed8;
    --test-green: #22c55e;
    --test-amber: #f59e0b;
    --test-orange: #f97316;
    --test-red: #dc2626;
    --test-border: var(--border-color, #d1d5db);
    --test-card: var(--card-background, #ffffff);
    --test-text: var(--text-color, #111827);
    --test-muted: var(--muted-text, #6b7280);
}

/* ======================================
   SHARED
======================================= */

.hidden {
    display: none !important;
}

button {
    font: inherit;
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ======================================
   TEST HEADER
======================================= */

.test-header {
    min-height: var(--test-header-height);
    padding: 14px 30px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;

    color: var(--test-text);
    background: var(--test-card);
    border-bottom: 1px solid var(--test-border);
}

.test-header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.test-header .logo img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    flex: 0 0 auto;
}

.test-header .logo span {
    font-size: 1.1rem;
    font-weight: 800;
    white-space: nowrap;
}

.module-info {
    min-width: 0;
    text-align: center;
    font-weight: 600;
}

#module-title {
    overflow-wrap: anywhere;
}

.timer {
    flex: 0 0 auto;
    font-size: 1.25rem;
    font-weight: 800;
    white-space: nowrap;
}

/* ======================================
   HEADER BUTTONS
======================================= */

#calculator-btn,
#reference-btn,
#theme-toggle,
#save-exit-btn,
#reset-btn {
    min-height: 44px;
    padding: 10px 14px;

    border: 1px solid var(--test-border);
    border-radius: 10px;

    font-size: 0.95rem;
    font-weight: 700;

    cursor: pointer;

    color: var(--test-text);
    background: var(--test-card);

    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

#theme-toggle {
    width: 50px;
    padding: 10px;
    font-size: 1.1rem;
}

#calculator-btn:hover,
#reference-btn:hover,
#theme-toggle:hover,
#save-exit-btn:hover,
#reset-btn:hover {
    transform: translateY(-1px);
    border-color: var(--test-blue);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.15);
}

#save-exit-btn {
    color: var(--test-blue-dark);
    border-color: #93c5fd;
    background: #eff6ff;
}

#save-exit-btn:hover {
    background: #dbeafe;
}

#reset-btn {
    color: #b91c1c;
    border-color: #fca5a5;
    background: #fef2f2;
}

#reset-btn:hover {
    color: #ffffff;
    border-color: var(--test-red);
    background: var(--test-red);
}

#calculator-btn:focus-visible,
#reference-btn:focus-visible,
#theme-toggle:focus-visible,
#save-exit-btn:focus-visible,
#reset-btn:focus-visible,
.test-footer button:focus-visible,
.choice:focus-visible,
.navigator button:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.35);
    outline-offset: 3px;
}

/* ======================================
   MAIN TEST LAYOUT
======================================= */

#test-content {
    width: 100%;
}

.test-layout {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-height: calc(100vh - var(--test-header-height) - var(--test-footer-height));
    height: calc(100vh - var(--test-header-height) - var(--test-footer-height));
}

.passage-panel,
.question-panel,
.navigator-panel {
    min-width: 0;
    padding: 36px;

    display: flex;
    flex-direction: column;

    overflow-y: auto;

    color: var(--test-text);
    background: var(--test-card);
}

.passage-panel,
.question-panel {
    border-right: 1px solid var(--test-border);
}

.passage-panel h2,
.question-panel h2,
.navigator-panel h3 {
    margin-top: 0;
}

#passage {
    font-size: 1.04rem;
    line-height: 1.75;
    overflow-wrap: anywhere;
}

#passage u {
    text-decoration-color: var(--test-blue);
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

#question-text {
    margin-top: 22px;
    font-size: 1.04rem;
    line-height: 1.65;
}

/* ======================================
   ANSWER CHOICES
======================================= */

.choices {
    margin-top: 34px;

    display: flex;
    flex-direction: column;
    gap: 18px;
}

.choice {
    width: 100%;
    min-height: 78px;
    padding: 22px 24px;

    text-align: left;
    font-size: 1rem;
    line-height: 1.5;

    border: 1px solid var(--test-border);
    border-radius: 12px;

    color: #111827;
    background: #ffffff;

    cursor: pointer;

    transition:
        transform 0.2s ease,
        border-color 0.2s ease,
        background-color 0.2s ease,
        color 0.2s ease;
}

.choice:hover {
    transform: translateY(-2px);
    border-color: var(--test-blue);
}

.choice.selected {
    color: #ffffff;
    background: var(--test-blue);
    border-color: var(--test-blue);
}

/* ======================================
   QUESTION NAVIGATOR
======================================= */

.question-navigator-dialog {
    position: fixed;
    inset: 0;
    width: min(760px, calc(100% - 32px));
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    margin: auto;
    padding: 26px;
    overflow: auto;
    overscroll-behavior: contain;
    color: var(--test-text);
    background: var(--glass-surface-strong, var(--test-card));
    border: 1px solid var(--test-border);
    border-radius: 22px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
}

.question-navigator-dialog:not([open]) { display: none; }

.question-navigator-dialog::backdrop {
    background: rgba(8, 15, 30, 0.55);
}

.question-navigator-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.question-navigator-heading p,
.question-navigator-summary {
    color: var(--test-muted);
    font-size: 0.88rem;
}

.question-navigator-heading h2 {
    margin: 4px 0 0;
    font-size: clamp(1.1rem, 3vw, 1.4rem);
    line-height: 1.4;
}

#question-navigator-close {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    color: var(--test-text);
    background: var(--glass-tint, transparent);
    border: 1px solid var(--test-border);
    border-radius: 12px;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}

.question-navigator-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 20px;
    margin: 20px 0;
    padding: 0;
    list-style: none;
    font-size: 0.84rem;
}

.question-navigator-legend li {
    display: flex;
    align-items: center;
    gap: 8px;
}

.navigator-key {
    width: 20px;
    height: 20px;
    border: 2px dashed var(--test-border);
    border-radius: 5px;
}

.navigator-key-current { background: var(--test-blue); border: 2px solid var(--test-blue); }
.navigator-key-answered { background: rgba(34, 197, 94, 0.13); border: 2px solid #16a34a; }
.navigator-key-review { border: 0; color: #b45309; line-height: 20px; text-align: center; }

.question-navigator-dialog .navigator {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 12px;
    margin: 0 0 18px;
}

.question-navigator-dialog .navigator button {
    position: relative;
    width: 100%;
    height: auto;
    min-height: 48px;
    aspect-ratio: 1;
    padding: 10px;
    border: 2px dashed var(--test-border);
    border-radius: 12px;
    font-weight: 700;
    color: var(--test-text);
    background: var(--glass-tint, transparent);
    cursor: pointer;
}

.question-navigator-dialog .navigator button:hover { border-color: var(--test-blue); }

.question-navigator-dialog .navigator button.answered {
    border-style: solid;
    border-color: #16a34a;
    background: rgba(34, 197, 94, 0.13);
}

.question-navigator-dialog .navigator button.review { border-color: #b45309; }

.question-navigator-dialog .navigator button.active {
    color: #ffffff;
    background: var(--test-blue);
    border-color: var(--test-blue);
    border-style: solid;
}

.navigator-review-flag {
    position: absolute;
    top: 1px;
    right: 5px;
    color: #b45309;
    font-size: 0.85rem;
}

.navigator-review-flag[hidden] { display: none; }
.navigator button.active .navigator-review-flag { color: #ffffff; }
html[data-theme="dark"] .navigator-review-flag,
html[data-theme="dark"] .navigator-key-review { color: #fbbf24; }
html[data-theme="dark"] .navigator button.review { border-color: #fbbf24; }
html[data-theme="dark"] .navigator button.active { border-color: var(--test-blue); }

#question-navigator-return {
    width: 100%;
    min-height: 46px;
    margin-top: 14px;
    padding: 10px 16px;
    border: 1px solid var(--test-border);
    border-radius: 12px;
    color: var(--test-text);
    background: var(--glass-tint, transparent);
    font-weight: 700;
    cursor: pointer;
}

.question-navigator-dialog button:focus-visible {
    outline: 3px solid var(--test-blue);
    outline-offset: 3px;
}

@media (max-width: 600px) {
    .question-navigator-dialog { padding: 18px; border-radius: 18px; }
    .question-navigator-dialog .navigator { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
    .question-navigator-legend { gap: 8px 14px; }
}

/* ======================================
   TEST FOOTER
======================================= */

.test-footer {
    min-height: var(--test-footer-height);
    padding: 14px 30px;

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;

    color: var(--test-text);
    background: var(--test-card);
    border-top: 1px solid var(--test-border);
}

.test-footer button {
    min-height: 48px;
    padding: 13px 22px;

    border: none;
    border-radius: 12px;

    font-weight: 700;

    color: #ffffff;
    background: var(--test-blue);

    cursor: pointer;
}

.test-footer button:hover:not(:disabled) {
    background: var(--test-blue-dark);
}

#question-navigator-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--test-text);
    background: var(--glass-tint, transparent);
    border: 1px solid var(--test-border);
    white-space: nowrap;
}

#question-navigator-btn:hover { border-color: var(--test-blue); }
#question-navigator-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
}
#question-navigator-btn[aria-expanded="true"] svg { transform: rotate(180deg); }

#review-btn.active {
    font-weight: 800;
    background: var(--test-blue-dark);
}

/* ======================================
   BREAK SCREEN
======================================= */

.break-screen {
    width: 100%;
    min-height: calc(100vh - var(--test-header-height));

    display: grid;
    place-items: center;

    padding: 24px;
}

.break-card {
    width: min(520px, 100%);
    padding: 32px;

    text-align: center;

    border: 1px solid var(--test-border);
    border-radius: 16px;

    color: var(--test-text);
    background: var(--test-card);

    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
}

.break-card h1 {
    margin-top: 0;
}

.break-card button {
    min-height: 46px;
    margin-top: 20px;
    padding: 12px 20px;

    border: none;
    border-radius: 10px;

    font-weight: 700;

    color: #ffffff;
    background: var(--test-blue);

    cursor: pointer;
}

/* ======================================
   MODULE INSTRUCTIONS
======================================= */

.instructions-screen {
    width: 100%;
    min-height: calc(100vh - var(--test-header-height));

    display: grid;
    place-items: center;

    padding: 24px;
}

.instructions-card {
    width: min(620px, 100%);
    padding: 36px;

    border: 1px solid var(--test-border);
    border-radius: 16px;

    color: var(--test-text);
    background: var(--test-card);

    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.12);
}

.instructions-label {
    margin-bottom: 8px;

    font-size: 0.85rem;
    font-weight: 800;

    letter-spacing: 0.08em;
    text-transform: uppercase;

    color: var(--test-blue);
}

.instructions-card h1 {
    margin-top: 0;
}

.instructions-details {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;

    margin: 24px 0;
}

.instructions-details div {
    padding: 16px;

    text-align: center;

    border: 1px solid var(--test-border);
    border-radius: 10px;
}

.instructions-details span,
.instructions-details strong {
    display: block;
}

.instructions-details span {
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: var(--test-muted);
}

.instructions-card li {
    margin-bottom: 10px;
}

#start-module-btn {
    width: 100%;
    min-height: 48px;

    margin-top: 20px;
    padding: 14px 20px;

    border: none;
    border-radius: 10px;

    font-size: 1rem;
    font-weight: 800;

    color: #ffffff;
    background: var(--test-blue);

    cursor: pointer;
}

#start-module-btn:hover {
    background: var(--test-blue-dark);
}

/* ======================================
   DESMOS MODAL
======================================= */

.calculator-modal,
.reference-modal {
    position: fixed;
    inset: 0;

    display: grid;
    place-items: center;

    padding: 20px;

    background: rgba(0, 0, 0, 0.65);
}

.calculator-modal {
    z-index: 1000;
}

.reference-modal {
    z-index: 1100;
}

.calculator-window {
    width: min(1000px, 96vw);
    height: min(720px, 90vh);

    display: flex;
    flex-direction: column;

    overflow: hidden;

    border-radius: 14px;
    background: #ffffff;

    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.calculator-header,
.reference-header {
    display: flex;
    align-items: center;
    justify-content: space-between;

    padding: 12px 16px;

    border-bottom: 1px solid #d1d5db;

    color: #111827;
    background: #ffffff;
}

.calculator-header h2,
.reference-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

#calculator-close-btn,
#reference-close-btn {
    width: 42px;
    height: 42px;

    border: none;
    border-radius: 50%;

    font-size: 1.8rem;
    line-height: 1;

    color: #111827;
    background: transparent;

    cursor: pointer;
}

#calculator-close-btn:hover,
#reference-close-btn:hover {
    background: #f3f4f6;
}

#desmos-calculator {
    width: 100%;
    flex: 1;
    min-height: 0;
}

body.calculator-open,
body.reference-open {
    overflow: hidden;
}

/* ======================================
   REFERENCE SHEET
======================================= */

.reference-window {
    width: min(940px, 96vw);
    max-height: 92vh;

    display: flex;
    flex-direction: column;

    overflow: hidden;

    border-radius: 14px;
    background: #ffffff;

    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.reference-content {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 20px;

    color: #111827;
    background: #ffffff;
}

.reference-image-wrap {
    width: 100%;
    min-height: 0;

    display: flex;
    align-items: center;
    justify-content: center;
}

.reference-sheet-image {
    display: block;

    width: min(100%, 900px);
    height: auto;
    max-height: calc(92vh - 92px);

    margin: 0 auto;

    object-fit: contain;
}

/* Prevent old text-formula reference blocks from appearing if stale HTML is cached. */
.reference-section {
    display: none !important;
}

/* ======================================
   DARK MODE
======================================= */

html[data-theme="dark"] .test-header,
html[data-theme="dark"] .test-footer,
html[data-theme="dark"] .passage-panel,
html[data-theme="dark"] .question-panel,
html[data-theme="dark"] .navigator-panel,
html[data-theme="dark"] .instructions-card,
html[data-theme="dark"] .break-card {
    color: #f8fafc;
    border-color: #475569;
    background: #1e293b;
}

html[data-theme="dark"] #calculator-btn,
html[data-theme="dark"] #reference-btn,
html[data-theme="dark"] #theme-toggle,
html[data-theme="dark"] #save-exit-btn {
    color: #f8fafc;
    border-color: #475569;
    background: #334155;
}

html[data-theme="dark"] #calculator-btn:hover,
html[data-theme="dark"] #reference-btn:hover,
html[data-theme="dark"] #theme-toggle:hover,
html[data-theme="dark"] #save-exit-btn:hover {
    background: #475569;
}

html[data-theme="dark"] #reset-btn {
    color: #fecaca;
    border-color: #991b1b;
    background: #450a0a;
}

html[data-theme="dark"] #reset-btn:hover {
    color: #ffffff;
    background: #b91c1c;
}

html[data-theme="dark"] #module-progress {
    color: #cbd5e1;
}

/* ======================================
   TABLET
======================================= */

@media (max-width: 980px) and (min-width: 701px) {
    .test-header {
        flex-wrap: wrap;
        height: auto;
    }

    .module-info {
        order: 10;
        width: 100%;
        padding-top: 8px;
        border-top: 1px solid var(--test-border);
    }

    .test-layout {
        grid-template-columns: minmax(0, 42%) minmax(0, 58%);
        height: auto;
        min-height: 0;
    }

    .test-footer {
        flex-wrap: wrap;
        height: auto;
    }
}

/* ======================================
   MOBILE
======================================= */

@media (max-width: 700px) {
    body {
        overflow-x: hidden;
    }

    .test-header {
        height: auto;
        min-height: 0;

        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        grid-template-areas:
            "logo timer theme"
            "module module module"
            "tools tools tools"
            "save save save"
            "reset reset reset";
        gap: 10px;

        padding: 12px 16px;
    }

    .test-header .logo {
        grid-area: logo;
    }

    .timer {
        grid-area: timer;
        align-self: center;
        font-size: 1rem;
    }

    #theme-toggle {
        grid-area: theme;
        width: 48px;
        min-width: 48px;
    }

    .module-info {
        grid-area: module;

        width: 100%;
        padding: 10px 0 0;

        text-align: center;

        border-top: 1px solid var(--test-border);
    }

    #calculator-btn,
    #reference-btn {
        min-width: 0;
    }

    #calculator-btn {
        grid-area: tools;
        justify-self: start;
        width: calc(50% - 5px);
    }

    #reference-btn {
        grid-area: tools;
        justify-self: end;
        width: calc(50% - 5px);
    }

    #save-exit-btn {
        grid-area: save;
        width: 100%;
    }

    #reset-btn {
        grid-area: reset;
        width: 100%;
    }

    #test-content {
        width: 100%;
        padding-bottom: 150px;
    }

    .test-layout {
        display: block;
        width: 100%;
        height: auto;
        min-height: 0;
    }

    .passage-panel,
    .question-panel,
    .navigator-panel {
        position: static;

        width: 100%;
        min-width: 0;
        height: auto;
        max-height: none;

        padding: 22px 20px;

        overflow: visible;

        border-right: none;
        border-bottom: 1px solid var(--test-border);
    }

    .passage-panel h2,
    .question-panel h2,
    .navigator-panel h3 {
        margin-top: 0;
    }

    #passage {
        line-height: 1.6;
        overflow-wrap: anywhere;
    }

    .choices {
        display: grid;
        grid-template-columns: 1fr;
        gap: 12px;
        margin-top: 24px;
    }

    .choice {
        min-height: 64px;
        padding: 16px 18px;

        white-space: normal;
        overflow-wrap: anywhere;
    }

    .test-footer {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 100;

        height: auto;
        min-height: 0;

        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;

        padding: 10px 12px;

        background: var(--test-card);
        border-top: 1px solid var(--test-border);
    }

    .test-footer button {
        width: 100%;
        min-height: 48px;
        padding: 10px 8px;

        font-size: 0.88rem;
        line-height: 1.15;

        white-space: normal;
    }

    .instructions-screen,
    .break-screen {
        min-height: calc(100vh - 180px);
        padding: 16px;
    }

    .instructions-card,
    .break-card {
        padding: 24px;
    }

    .instructions-details {
        grid-template-columns: 1fr;
    }

    .calculator-modal,
    .reference-modal {
        padding: 0;
    }

    .calculator-window,
    .reference-window {
        width: 100vw;
        height: 100vh;
        max-height: none;
        border-radius: 0;
    }

    .reference-content {
        padding: 12px;
    }

    .reference-sheet-image {
        width: 100%;
        max-height: calc(100vh - 78px);
    }
}

/* ======================================
   VERY SMALL PHONES
======================================= */

@media (max-width: 420px) {
    .test-header {
        padding: 10px 12px;
    }

    .test-header .logo span {
        font-size: 0.95rem;
    }

    .timer {
        font-size: 0.95rem;
    }

    .passage-panel,
    .question-panel,
    .navigator-panel {
        padding: 20px 16px;
    }

    .test-footer {
        padding: 8px;
        gap: 6px;
    }

    .test-footer button {
        font-size: 0.82rem;
        padding: 8px 6px;
    }
}

/* ======================================
   STUDENT-PRODUCED RESPONSE
====================================== */

.student-response-container {
    margin-top: 20px;
    padding: 20px;

    border: 1px solid var(--border-color);
    border-radius: 12px;

    background: var(--card-background);
}

.student-response-container label {
    display: block;
    margin-bottom: 10px;

    color: var(--text-color);
    font-weight: 700;
}

.student-response-input {
    width: 100%;
    min-height: 52px;
    padding: 12px 14px;

    color: var(--text-color);
    background: var(--page-background);

    border: 2px solid var(--border-color);
    border-radius: 10px;

    font: inherit;
    font-size: 1.1rem;
}

.student-response-input:focus {
    border-color: #2563eb;
    outline: 3px solid rgba(37, 99, 235, 0.18);
}

.student-response-help {
    margin: 10px 0 0;

    color: var(--muted-text);
    font-size: 0.86rem;
}

@media (max-width: 600px) {
    .student-response-container {
        padding: 16px;
    }
}


/* ======================================
   QUESTION DIAGRAMS
====================================== */

.question-image-container {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    margin: 20px 0;
    padding: 16px;

    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.passage-panel .question-image-container {
    margin: 0 0 20px;
}

.question-image-container:not(.hidden) + #question-text {
    margin-top: 0;
}

.question-image-container.hidden {
    display: none;
}

.question-image-container img {
    display: block;

    width: auto;
    max-width: 100%;
    max-height: 420px;

    object-fit: contain;
}

html[data-theme="dark"] .question-image-container {
    background: #ffffff;
}

@media (max-width: 600px) {
    .question-image-container {
        margin: 16px 0;
        padding: 10px;
    }

    .question-image-container img {
        max-height: 300px;
    }
}

/* Hide the general website footer during the test */
body .site-footer {
    display: none;
}

@media (max-width: 600px) {
    #test-content {
        padding-bottom: 150px;
    }
}


#passage {
    white-space: pre-line;
}


/* ======================================
   TEXT HIGHLIGHTING
====================================== */

#highlight-btn,
#clear-highlights-btn {
    min-height: 44px;
    padding: 10px 14px;

    color: var(--text-color);
    background: var(--card-background);

    border: 1px solid var(--border-color);
    border-radius: 10px;

    font-weight: 700;
    cursor: pointer;
}

#highlight-btn:hover,
#clear-highlights-btn:hover {
    border-color: #2563eb;
    background: rgba(37, 99, 235, 0.08);
}

.text-highlight {
    padding: 1px 2px;

    color: inherit;
    background: #fde047;

    border-radius: 3px;
    cursor: pointer;
}

html[data-theme="dark"] .text-highlight {
    color: #111827;
    background: #facc15;
}

@media (max-width: 600px) {

    #highlight-btn,
    #clear-highlights-btn {
        padding: 8px 10px;
        font-size: 0.82rem;
    }
}

/* ======================================
   QUESTION TYPOGRAPHY AND READABILITY
====================================== */

.question-panel,
.navigator-panel,
.test-footer,
.test-header {
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Arial,
        Helvetica,
        sans-serif;
}

.passage-panel {
    font-family:
        Georgia,
        "Times New Roman",
        serif;
}

#passage {
    width: 100%;
    max-width: 68ch;

    color: #1f2937;

    font-size: 1.08rem;
    font-weight: 400;
    line-height: 1.75;
    letter-spacing: 0.005em;

    white-space: pre-line;
    overflow-wrap: break-word;
    word-break: normal;
}

#question-text {
    width: 100%;
    max-width: 920px;
    margin: 22px 0 0;

    color: #111827;

    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Arial,
        Helvetica,
        sans-serif;

    font-size: 1.12rem;
    font-weight: 450;
    line-height: 1.65;
    letter-spacing: 0;

    white-space: pre-line;
    overflow-wrap: break-word;
    word-break: normal;
}

.question-panel h2 {
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Arial,
        Helvetica,
        sans-serif;

    font-size: 1.55rem;
    font-weight: 750;
    line-height: 1.2;
}

#module-progress {
    line-height: 1.45;
}

.choice {
    min-height: 78px;
    padding: 22px 24px;

    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Arial,
        Helvetica,
        sans-serif;

    font-size: 1rem;
    font-weight: 400;
    line-height: 1.55;

    white-space: normal;
    overflow-wrap: break-word;
    word-break: normal;
}

.student-response-input {
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Arial,
        Helvetica,
        sans-serif;
}

.question-underline {
    text-decoration: underline;
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
}


/* ======================================
   MATH MODULE LAYOUT
====================================== */

.passage-panel.hidden-for-math {
    display: none;
}

.test-layout.math-layout {
    grid-template-columns: minmax(0, 1fr);
}

.test-layout.math-layout .question-panel {
    width: 100%;
    max-width: none;
    padding-inline: clamp(30px, 4vw, 64px);
}

.test-layout.math-layout #question-text {
    max-width: 1000px;
}

.test-layout.math-layout .question-image-container {
    width: min(100%, 820px);
    margin-inline: auto;
}

.test-layout.math-layout .question-image-container img {
    max-height: 520px;
}

/* Official College Board paper forms are rendered as faithful question crops.
   They need full natural height so long passages, tables, and graph-choice grids stay readable. */
.test-layout.official-image-layout .question-panel {
    padding-inline: clamp(22px, 4vw, 60px);
}

.test-layout.official-image-layout #question-text {
    max-width: 860px;
    margin-inline: auto;
    color: var(--muted-text, #64748b);
    font-size: 0.9rem;
}

.test-layout.official-image-layout .question-image-container {
    width: min(100%, 900px);
    margin: 14px auto 22px;
    padding: clamp(8px, 1.6vw, 14px);
}

.test-layout.official-image-layout .question-image-container img {
    width: 100%;
    height: auto;
    max-height: none;
    object-fit: contain;
}

.test-layout.official-image-layout .choices {
    width: min(100%, 760px);
    margin-inline: auto;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.test-layout.official-image-layout .choice {
    min-height: 54px;
    justify-content: center;
    padding: 10px;
}

.test-layout.official-image-layout .choice-label {
    margin: 0;
}

@media (max-width: 600px) {
    .test-layout.official-image-layout .question-image-container img {
        max-height: none;
    }

    .test-layout.official-image-layout .choices {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}


/* ======================================
   TYPOGRAPHY — DARK MODE
====================================== */

html[data-theme="dark"] #passage,
html[data-theme="dark"] #question-text {
    color: #f3f4f6;
}

html[data-theme="dark"] .choice {
    color: #f8fafc;
    background: #334155;
    border-color: #475569;
}

html[data-theme="dark"] .choice:hover {
    border-color: #60a5fa;
}

html[data-theme="dark"] .choice.selected {
    color: #ffffff;
    background: var(--test-blue);
    border-color: var(--test-blue);
}


/* ======================================
   TYPOGRAPHY — TABLET
====================================== */

@media (max-width: 980px) {
    #passage,
    #question-text {
        max-width: none;
    }

    #question-text {
        font-size: 1.08rem;
        line-height: 1.62;
    }

    .test-layout.math-layout {
        grid-template-columns: minmax(0, 1fr);
    }

}


/* ======================================
   TYPOGRAPHY — MOBILE
====================================== */

@media (max-width: 700px) {
    #passage {
        font-size: 1.02rem;
        line-height: 1.68;
    }

    #question-text {
        margin-top: 8px;

        font-size: 1.05rem;
        font-weight: 450;
        line-height: 1.6;
    }

    .question-panel h2 {
        font-size: 1.38rem;
    }

    .choice {
        min-height: 60px;
        padding: 16px 18px;

        font-size: 0.98rem;
        line-height: 1.5;
    }

    .test-layout.math-layout .question-panel {
        padding: 22px 20px;
    }
}

@media (max-width: 420px) {
    #question-text {
        font-size: 1rem;
    }

    .choice {
        padding: 15px 16px;
        font-size: 0.95rem;
    }
}


.test-loader {
    position: fixed;
    inset: 0;
    z-index: 9999;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;

    background: #ffffff;
    color: #111827;
    font-size: 17px;
    font-weight: 600;
}

.loader-spinner {
    width: 42px;
    height: 42px;

    border: 4px solid #dbe4f0;
    border-top-color: #2563eb;
    border-radius: 50%;

    animation: loader-spin 0.8s linear infinite;
}

@keyframes loader-spin {
    to {
        transform: rotate(360deg);
    }
}

.test-loader.hidden {
    display: none;
}


#test-loader {
    position: fixed;
    inset: 0;
    z-index: 999999;

    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;

    background: white;
    color: #111827;

    font-family: Arial, sans-serif;
    font-size: 18px;
    font-weight: 600;
}

#test-loader.loader-hidden {
    display: none;
}

.test-loader-spinner {
    width: 44px;
    height: 44px;

    border: 4px solid #dbe3ef;
    border-top-color: #2563eb;
    border-radius: 50%;

    animation: test-loader-spin 0.8s linear infinite;
}

@keyframes test-loader-spin {
    to {
        transform: rotate(360deg);
    }
}
.choice {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
}

.choice-label {
    font-weight: 700;
    flex-shrink: 0;
}

.choice-image {
    display: block;
    width: 100%;
    max-width: 420px;
    height: auto;
    margin: 0 auto;
    object-fit: contain;
    pointer-events: none;
}

.choice-text,
.choice-image-caption {
    line-height: 1.5;
}

@media (max-width: 600px) {
    .choice-image {
        max-width: 100%;
    }
}
/* Keep every control reachable, with a wide question picker on small screens. */
@media (max-width: 700px) {
    #test-content {
        padding-bottom: calc(124px + env(safe-area-inset-bottom, 0px));
    }

    .test-footer {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        grid-template-areas:
            "review review finish finish"
            "previous navigator navigator next";
        gap: 6px;
        padding: 8px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }

    #prev-btn { grid-area: previous; }
    #review-btn { grid-area: review; }
    #question-navigator-btn { grid-area: navigator; gap: 5px; }
    #finish-btn { grid-area: finish; }
    #next-btn { grid-area: next; }

    .test-footer button {
        min-height: 46px;
        padding: 7px 4px;
        font-size: 0.76rem;
    }
}

@media (max-width: 420px) {
    .test-footer button {
        font-size: 0.7rem;
    }
}

/* ======================================
   TEST TOOLS V2 — ANNOTATE + CALCULATOR
====================================== */

.test-header-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
}

#annotate-btn,
.test-tool-button {
    min-height: 44px;
    padding: 9px 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--test-border);
    border-radius: 11px;
    color: var(--test-text);
    background: var(--test-card);
    font-size: 0.9rem;
    font-weight: 750;
    cursor: pointer;
    transition: transform 150ms ease, border-color 150ms ease,
        color 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}

.test-tool-button svg,
.calculator-title-group svg {
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#annotate-btn:hover,
.test-tool-button:hover,
#annotate-btn.is-active,
.test-tool-button.is-active {
    transform: translateY(-1px);
    color: var(--test-blue-dark);
    border-color: #93c5fd;
    background: #eff6ff;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.13);
}

#annotate-btn:focus-visible,
.test-tool-button:focus-visible,
.annotation-toolbar button:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.3);
    outline-offset: 2px;
}

.annotation-toolbar {
    position: fixed;
    z-index: 1500;
    min-height: 54px;
    padding: 7px 8px 7px 12px;
    display: flex;
    align-items: center;
    gap: 9px;
    border: 1px solid rgba(148, 163, 184, 0.55);
    border-radius: 16px;
    color: #172033;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.2), 0 3px 10px rgba(15, 23, 42, 0.1);
    backdrop-filter: blur(16px) saturate(1.2);
    opacity: 0;
    transform: translateY(5px) scale(0.98);
    transition: opacity 130ms ease, transform 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.annotation-toolbar.is-open {
    opacity: 1;
    transform: none;
}

.annotation-hint {
    min-width: 106px;
    font-size: 0.78rem;
    font-weight: 750;
    color: #64748b;
    white-space: nowrap;
}

.annotation-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.annotation-swatch,
.annotation-underline-tool {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(15, 23, 42, 0.14);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.annotation-swatch:hover,
.annotation-underline-tool:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 5px 12px rgba(15, 23, 42, 0.14);
}

.annotation-swatch.annotation-red {
    background: #fb7185;
}

.annotation-swatch.annotation-yellow {
    background: #facc15;
}

.annotation-swatch.annotation-blue {
    background: #60a5fa;
}

.annotation-underline-tool {
    border-radius: 10px;
    color: #172033;
    background: #f8fafc;
    font-weight: 800;
}

.annotation-underline-tool span {
    line-height: 1;
    text-decoration: underline 2px;
    text-underline-offset: 3px;
}

.annotation-divider {
    width: 1px;
    height: 30px;
    background: #dbe2ea;
}

.annotation-clear {
    min-height: 34px;
    padding: 6px 10px;
    border: 0;
    border-radius: 9px;
    color: #64748b;
    background: transparent;
    font-size: 0.76rem;
    font-weight: 750;
    cursor: pointer;
}

.annotation-clear:hover {
    color: #b91c1c;
    background: #fff1f2;
}

.text-annotation,
.text-highlight {
    padding: 0.04em 0.08em;
    color: inherit;
    border-radius: 0.18em;
    cursor: pointer;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.annotation-highlight.annotation-red {
    background: rgba(251, 113, 133, 0.48);
}

.annotation-highlight.annotation-yellow,
.text-highlight {
    background: rgba(250, 204, 21, 0.52);
}

.annotation-highlight.annotation-blue {
    background: rgba(96, 165, 250, 0.48);
}

.annotation-underline {
    padding-inline: 0;
    text-decoration-line: underline;
    text-decoration-color: #2563eb;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
}

.calculator-modal {
    position: fixed;
    inset:
        var(--test-header-current-height, var(--test-header-height))
        auto
        var(--test-footer-current-height, var(--test-footer-height))
        0;
    z-index: 1000;
    width: var(--calculator-split-width);
    display: block;
    padding: 0;
    background: transparent;
}

.calculator-window {
    position: relative;
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-right: 1px solid #cbd5e1;
    border-radius: 0;
    box-shadow: 14px 0 36px rgba(15, 23, 42, 0.14);
    animation: calculator-panel-enter 220ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.calculator-modal.is-closing .calculator-window {
    animation: calculator-panel-exit 180ms cubic-bezier(0.4, 0, 1, 1) both;
}

.calculator-header {
    min-height: 64px;
    padding: 10px 14px 10px 18px;
    background: #f8fafc;
}

.calculator-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.calculator-title-group h2,
.calculator-title-group p {
    margin: 0;
}

.calculator-title-group p {
    margin-top: 2px;
    color: #64748b;
    font-size: 0.72rem;
}

#calculator-close-btn {
    display: grid;
    place-items: center;
    color: #475569;
}

.calculator-loading {
    position: absolute;
    inset: 64px 0 0;
    z-index: 3;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 12px;
    padding: 24px;
    color: #475569;
    background: #ffffff;
    font-size: 0.92rem;
    font-weight: 700;
    text-align: center;
}

.calculator-loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #dbeafe;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: calculator-loading-spin 700ms linear infinite;
}

@keyframes calculator-loading-spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes calculator-panel-enter {
    from {
        opacity: 0;
        transform: translateX(-24px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@keyframes calculator-panel-exit {
    from {
        opacity: 1;
        transform: none;
    }
    to {
        opacity: 0;
        transform: translateX(-22px);
    }
}

/* On a desktop the calculator is a true split workspace. The test content is
   resized into the remaining space, so answers can never sit underneath the
   calculator. The question picker stays available in the footer. */
@media (min-width: 1181px) {
    #test-content {
        margin-left: 0;
        transition:
            width 240ms cubic-bezier(0.22, 1, 0.36, 1),
            margin-left 240ms cubic-bezier(0.22, 1, 0.36, 1);
    }

    body.calculator-open #test-content {
        width: calc(100% - var(--calculator-split-width));
        margin-left: var(--calculator-split-width);
    }

    body.calculator-open .test-layout.math-layout {
        grid-template-columns: minmax(0, 1fr);
    }

    body.calculator-open .test-layout.math-layout .question-panel {
        padding-inline: clamp(30px, 4vw, 66px);
        border-right: 0;
    }

}

html[data-theme="dark"] #annotate-btn,
html[data-theme="dark"] .test-tool-button {
    color: #e2e8f0;
    background: #1e293b;
    border-color: #475569;
}

html[data-theme="dark"] #annotate-btn:hover,
html[data-theme="dark"] .test-tool-button:hover,
html[data-theme="dark"] #annotate-btn.is-active,
html[data-theme="dark"] .test-tool-button.is-active {
    color: #bfdbfe;
    background: #172554;
    border-color: #3b82f6;
}

html[data-theme="dark"] .annotation-toolbar {
    color: #f8fafc;
    background: rgba(15, 23, 42, 0.97);
    border-color: #475569;
}

html[data-theme="dark"] .annotation-hint,
html[data-theme="dark"] .annotation-clear {
    color: #cbd5e1;
}

html[data-theme="dark"] .annotation-divider {
    background: #475569;
}

html[data-theme="dark"] .annotation-underline-tool {
    color: #f8fafc;
    background: #334155;
    border-color: #64748b;
}

html[data-theme="dark"] .annotation-highlight.annotation-red {
    color: #fff;
    background: rgba(244, 63, 94, 0.48);
}

html[data-theme="dark"] .annotation-highlight.annotation-yellow,
html[data-theme="dark"] .text-highlight {
    color: #fff;
    background: rgba(234, 179, 8, 0.5);
}

html[data-theme="dark"] .annotation-highlight.annotation-blue {
    color: #fff;
    background: rgba(59, 130, 246, 0.52);
}

@media (max-width: 1180px) and (min-width: 701px) {
    .test-header {
        flex-wrap: wrap;
    }

    .test-header-tools {
        width: 100%;
        order: 20;
        justify-content: center;
        padding-top: 9px;
        border-top: 1px solid var(--test-border);
    }

    .calculator-modal {
        inset: 0;
        width: 100vw;
        height: 100dvh;
    }

    .calculator-window {
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }
}

@media (max-width: 700px) {
    .test-header {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "logo timer"
            "module module"
            "header-tools header-tools";
    }

    .test-header-tools {
        grid-area: header-tools;
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        padding: 2px 1px 5px;
        scrollbar-width: none;
    }

    .test-header-tools::-webkit-scrollbar {
        display: none;
    }

    .test-header-tools > button {
        flex: 0 0 auto;
        width: auto !important;
        min-width: 44px !important;
    }

    .test-tool-button span {
        display: none;
    }

    .annotation-toolbar {
        max-width: calc(100vw - 20px);
        min-height: 50px;
        padding-left: 8px;
        gap: 6px;
    }

    .annotation-hint {
        display: none;
    }

    .annotation-swatch,
    .annotation-underline-tool {
        width: 32px;
        height: 32px;
    }

    .calculator-modal {
        inset: 0;
        width: 100vw;
        height: 100dvh;
    }

    .calculator-window {
        width: 100%;
        height: 100%;
        border: 0;
        border-radius: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .calculator-window,
    .annotation-toolbar,
    .calculator-loading-spinner {
        animation: none;
        transition: none;
    }

    #test-content {
        transition: none !important;
    }
}
