:root {
    --bg1: #e8f1f4;
    --bg2: #f7f3ea;
    --ink: #1c2b33;
    --muted: #5b6b74;
    --brand: #0f6e7a;
    --brand-dark: #0a525b;
    --accent: #d97706;
    --card: #ffffff;
    --line: #d5e0e5;
    --ok: #0f7a4a;
    --ok-bg: #e8f7ef;
    --warn: #b45309;
    --warn-bg: #fff7ed;
    --danger: #b42318;
    --danger-bg: #fef3f2;
    --shadow: 0 12px 32px rgba(28, 43, 51, 0.09);
    --radius: 18px;
    --font: "IBM Plex Sans Thai", "Sarabun", sans-serif;
    --display: "Outfit", "IBM Plex Sans Thai", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    color: var(--ink);
    min-height: 100vh;
    background:
        radial-gradient(ellipse 70% 45% at 8% -5%, rgba(15, 110, 122, 0.2), transparent 50%),
        radial-gradient(ellipse 55% 40% at 96% 5%, rgba(217, 119, 6, 0.14), transparent 45%),
        linear-gradient(165deg, var(--bg1) 0%, #eef4f6 45%, var(--bg2) 100%);
}
.student-body .panel,
.student-body .hero,
.student-body .confirm-page,
.student-body .result-page,
.student-body .home-page {
    animation: rise 0.4s ease both;
}

.app-shell { min-height: 100vh; }

.page {
    width: min(960px, calc(100% - 1.5rem));
    margin: 0 auto;
    padding: 1.25rem 0 2.5rem;
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
}
.page.narrow { width: min(560px, calc(100% - 1.5rem)); }
.page.wide { width: min(1100px, calc(100% - 1.5rem)); }

.hero {
    text-align: center;
    padding: 1.5rem 0 1.15rem;
}
.hero .brand {
    display: block;
    font-family: var(--display);
    font-size: clamp(1.65rem, 5vw, 2.35rem);
    font-weight: 700;
    color: var(--brand-dark);
    letter-spacing: -0.03em;
    line-height: 1.15;
    margin: 0 0 0.55rem;
}
.hero h1 {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(1.05rem, 2.8vw, 1.3rem);
    font-weight: 600;
    letter-spacing: -0.015em;
}
.hero p {
    margin: 0.55rem auto 0;
    max-width: 28rem;
    color: var(--muted);
    font-size: 0.98rem;
    line-height: 1.5;
}

.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.35rem 1.25rem;
}

.panel h1, .panel h2 {
    margin: 0 0 1rem;
    font-family: var(--display);
    font-size: 1.2rem;
    letter-spacing: -0.015em;
}

.form-grid {
    display: grid;
    gap: 0.9rem;
}

label {
    display: grid;
    gap: 0.35rem;
    font-weight: 600;
    font-size: 0.95rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea {
    width: 100%;
    border: 1.5px solid var(--line);
    border-radius: 12px;
    padding: 0.85rem 0.95rem;
    font: inherit;
    background: #fbfcfd;
    color: var(--ink);
}
textarea {
    resize: vertical;
    min-height: 4.5rem;
    line-height: 1.5;
}
input:focus,
textarea:focus {
    outline: 2px solid rgba(15, 110, 122, 0.35);
    border-color: var(--brand);
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.7rem;
    margin-top: 1rem;
}

.btn {
    appearance: none;
    border: none;
    border-radius: 12px;
    padding: 0.8rem 1.2rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 46px;
    transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary {
    background: linear-gradient(145deg, #148a96, var(--brand));
    color: #fff;
    box-shadow: 0 6px 16px rgba(15, 110, 122, 0.22);
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #e7eef1; color: var(--ink); }
.btn-accent {
    background: linear-gradient(145deg, #e8921a, var(--accent));
    color: #fff;
    box-shadow: 0 6px 16px rgba(217, 119, 6, 0.22);
}
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border: 1.5px solid var(--line); color: var(--ink); }
.btn:disabled, .btn.is-disabled {
    opacity: 0.45;
    pointer-events: none;
}
.btn.full { width: 100%; }

.alert {
    border-radius: 12px;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    font-weight: 500;
}
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }

.hint { color: var(--muted); font-size: 0.9rem; margin-top: 1rem; }
.message-list { padding-left: 1.1rem; }
.message-list.ok { color: var(--ok); }
.message-list.err { color: var(--danger); }

.subject-list {
    display: grid;
    gap: 0.75rem;
}
.subject-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    padding: 1.05rem 1.15rem;
    border: 1.5px solid var(--line);
    border-radius: 14px;
    text-decoration: none;
    color: inherit;
    background: linear-gradient(135deg, #fff 0%, #f4fafb 100%);
    transition: border-color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}
.subject-card:hover {
    border-color: var(--brand);
    box-shadow: 0 10px 24px rgba(15, 110, 122, 0.12);
    transform: translateY(-2px);
}
.subject-card-body {
    display: grid;
    gap: 0.2rem;
    min-width: 0;
}
.subject-card-name {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}
.subject-card-hint {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 500;
}
.subject-card-meta {
    flex-shrink: 0;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: rgba(15, 110, 122, 0.1);
    color: var(--brand-dark);
    font-weight: 700;
    font-size: 0.88rem;
    white-space: nowrap;
}

.home-panel-head {
    margin-bottom: 1rem;
}
.home-footer-actions {
    margin-top: 1.25rem;
}
.entry-subject-chip {
    display: grid;
    gap: 0.2rem;
    margin-bottom: 1rem;
    padding: 0.9rem 1rem;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(15, 110, 122, 0.1), rgba(217, 119, 6, 0.08));
    border: 1px solid rgba(15, 110, 122, 0.14);
}
.entry-subject-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.entry-subject-chip strong {
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}
.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.9rem;
}
@media (max-width: 480px) {
    .form-row-2 { grid-template-columns: 1fr; }
}

.empty-state-premium {
    text-align: center;
    padding: 1.75rem 1rem;
}
.empty-icon {
    display: block;
    width: 52px;
    height: 52px;
    margin: 0 auto 0.85rem;
    border-radius: 16px;
    background:
        linear-gradient(145deg, rgba(15, 110, 122, 0.12), rgba(217, 119, 6, 0.1)),
        #eef4f6;
    position: relative;
}
.empty-icon::after {
    content: "";
    position: absolute;
    inset: 18px 14px;
    border: 2.5px solid var(--muted);
    border-radius: 4px;
    opacity: 0.55;
}
.empty-state-premium strong {
    display: block;
    font-family: var(--display);
    font-size: 1.05rem;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 600;
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-muted { background: #eef2f4; color: var(--muted); }

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-weight: 500;
}
.checkbox-row input { width: auto; margin: 0; }

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.panel-head h2 { margin: 0; }
.filter-inline label {
    display: grid;
    gap: 0.35rem;
    font-size: 0.9rem;
    color: var(--muted);
}
.filter-inline select {
    min-width: 220px;
    padding: 0.55rem 0.75rem;
    border: 1.5px solid var(--line);
    border-radius: 10px;
    font: inherit;
    background: #fff;
}

.subject-form { margin-top: 0.25rem; }

/* Subjects admin */
.subjects-page .subjects-stats {
    margin-bottom: 1rem;
}
.panel-head-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}
.subject-form-main {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.9rem;
}
.subject-options {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.7rem;
}
.option-tile {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin: 0;
    padding: 0.9rem 1rem;
    border: 1.5px solid var(--line);
    border-radius: 14px;
    background: #f8fbfc;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.option-tile input {
    width: auto;
    margin: 0.2rem 0 0;
    flex-shrink: 0;
}
.option-tile:has(input:checked) {
    border-color: var(--brand);
    background: #eaf6f8;
}
.option-tile-body {
    display: grid;
    gap: 0.2rem;
}
.option-tile-title {
    font-weight: 700;
    font-size: 0.98rem;
}
.option-tile-desc {
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 500;
    line-height: 1.4;
}
.subject-form-actions {
    margin-top: 0.25rem;
}
.subject-list-panel {
    margin-top: 0;
}
.empty-state {
    text-align: center;
    padding: 1.5rem 0.5rem;
}
.empty-state p { margin: 0; }
.empty-state .hint { margin-top: 0.4rem; }

.subject-admin-list {
    display: grid;
    gap: 0.85rem;
}
.subject-admin-card {
    display: grid;
    gap: 1rem;
    padding: 1rem 1.05rem;
    border: 1.5px solid var(--line);
    border-radius: 16px;
    background: linear-gradient(160deg, #fff, #f7fbfc);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.subject-admin-card.is-closed {
    background: #fafbfc;
    opacity: 0.92;
}
.subject-admin-main {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    min-width: 0;
}
.subject-admin-index {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: #e7eef1;
    color: var(--brand-dark);
    font-weight: 700;
    font-size: 0.9rem;
}
.subject-admin-info {
    min-width: 0;
    flex: 1;
}
.subject-admin-name {
    margin: 0;
    font-size: 1.08rem;
    font-weight: 700;
    line-height: 1.35;
    word-break: break-word;
}
.subject-admin-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.85rem;
    margin-top: 0.35rem;
    color: var(--muted);
    font-size: 0.88rem;
}
.meta-warn {
    color: var(--warn);
    font-weight: 600;
}
.subject-admin-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.55rem;
}
.subject-admin-actions {
    display: grid;
    gap: 0.65rem;
}
.subject-admin-primary,
.subject-admin-secondary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.subject-admin-secondary form {
    margin: 0;
}
.btn-compact {
    min-height: 40px;
    padding: 0.45rem 0.9rem;
    font-size: 0.92rem;
}
.topbar-actions {
    margin: 0;
}

@media (min-width: 640px) {
    .subject-form-main {
        grid-template-columns: 1fr 7.5rem;
        align-items: end;
    }
    .subject-options {
        grid-template-columns: 1fr 1fr;
    }
}

@media (min-width: 768px) {
    .subject-admin-card {
        grid-template-columns: 1fr auto;
        align-items: center;
        gap: 1.25rem;
        padding: 1.1rem 1.2rem;
    }
    .subject-admin-actions {
        justify-items: end;
        min-width: 280px;
    }
    .subject-admin-primary,
    .subject-admin-secondary {
        justify-content: flex-end;
    }
    .subject-admin-primary .btn,
    .subject-admin-secondary .btn {
        width: auto;
    }
}

@media (min-width: 900px) {
    .subject-admin-actions {
        min-width: 320px;
    }
}

.question-form { margin-top: 0.25rem; }
.choice-fieldset {
    margin: 0;
    padding: 1rem;
    border: 1.5px solid var(--line);
    border-radius: 14px;
    background: #f8fbfc;
}
.choice-fieldset legend {
    font-weight: 700;
    padding: 0 0.35rem;
}
.choice-edit-row {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.65rem;
    align-items: start;
    margin-bottom: 0.65rem;
}
.choice-edit-row:last-child { margin-bottom: 0; }
.choice-correct-pick {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.55rem;
    font-weight: 600;
    cursor: pointer;
}
.choice-correct-pick input { width: auto; margin: 0; }
.choice-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 999px;
    background: #e7eef1;
    font-size: 0.92rem;
}
.choice-correct-pick:has(input:checked) .choice-letter {
    background: var(--ok-bg);
    color: var(--ok);
}
.q-preview {
    font-weight: 500;
    line-height: 1.45;
}
table tr.is-editing td {
    background: rgba(15, 110, 122, 0.06);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.topbar .meta { color: var(--muted); font-size: 0.92rem; }

.progress-wrap {
    margin: 0.75rem 0 1rem;
}
.progress-bar {
    height: 10px;
    background: #e5ecef;
    border-radius: 999px;
    overflow: hidden;
}
.progress-bar > span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--brand), #1aa0b0);
    border-radius: inherit;
    transition: width 0.25s ease;
}
.progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 0.88rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

.question-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.2rem;
    border-left: 5px solid var(--brand);
    animation: rise 0.28s ease;
}
@keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.q-number {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 0.65rem;
}
.q-number span {
    display: inline-flex;
    align-items: center;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    background: rgba(15, 110, 122, 0.12);
    color: var(--brand-dark);
    font-weight: 700;
    font-size: 0.82rem;
}
.q-text {
    font-family: var(--display);
    font-size: clamp(1.08rem, 2.8vw, 1.28rem);
    font-weight: 600;
    letter-spacing: -0.015em;
    line-height: 1.55;
    margin: 0 0 1.1rem;
}

.choice-list {
    display: grid;
    gap: 0.7rem;
}

.choice-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.75rem;
    align-items: center;
    width: 100%;
    text-align: left;
    border: 1.5px solid var(--line);
    background: #fbfcfd;
    border-radius: 14px;
    padding: 0.95rem 1rem;
    min-height: 52px;
    font: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: border-color 0.15s ease, background 0.15s ease;
}
@media (hover: hover) and (pointer: fine) {
    .choice-card:hover {
        border-color: #9bc4cb;
    }
}
.choice-card:active {
    background: #eef5f7;
}
.choice-card.is-selected {
    border-color: var(--brand);
    background: #eaf6f8;
    box-shadow: inset 0 0 0 1px rgba(15, 110, 122, 0.25);
}
.choice-badge {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-weight: 700;
    background: #e7eef1;
    color: var(--brand-dark);
    flex-shrink: 0;
}
.choice-card.is-selected .choice-badge {
    background: var(--brand);
    color: #fff;
}
.choice-text { line-height: 1.5; }

.nav-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
    margin-top: 1rem;
}
.nav-grid .span-2 { grid-column: 1 / -1; }

.navigator {
    margin-top: 1.1rem;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem;
}
.navigator h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
}
.nav-dots {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 0.5rem;
}
.nav-dot {
    min-height: 44px;
    min-width: 44px;
    border-radius: 10px;
    border: 1.5px solid var(--line);
    background: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.nav-dot.answered {
    background: var(--ok-bg);
    border-color: #9fd4b5;
    color: var(--ok);
}
.nav-dot.current {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}
.nav-dot.unanswered {
    background: #fff;
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin-top: 0.8rem;
    font-size: 0.85rem;
    color: var(--muted);
}
.legend span::before {
    content: "";
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-right: 0.35rem;
    vertical-align: -1px;
    border: 1px solid var(--line);
}
.legend .l-answered::before { background: var(--ok-bg); border-color: #9fd4b5; }
.legend .l-current::before { background: #fff; outline: 2px solid var(--brand); }
.legend .l-empty::before { background: #fff; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(16, 28, 34, 0.55);
    display: none;
    align-items: flex-end;
    justify-content: center;
    padding: 1rem;
    z-index: 50;
}
.modal-backdrop.is-open { display: flex; }
.modal {
    width: min(480px, 100%);
    background: #fff;
    border-radius: 18px 18px 14px 14px;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    animation: rise 0.2s ease;
}
.modal h3 { margin: 0 0 0.5rem; }
.modal p { margin: 0 0 1rem; color: var(--muted); }

body.modal-open { overflow: hidden; }

.subject-modal-backdrop {
    align-items: center;
    z-index: 60;
}
.modal.subject-modal {
    width: min(560px, 100%);
    max-height: min(92vh, 720px);
    overflow-y: auto;
    border-radius: 18px;
    padding: 1.15rem 1.25rem 1.25rem;
}
.modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.modal-head h3 {
    margin: 0;
    font-size: 1.15rem;
    line-height: 1.35;
}
.modal-close {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: 10px;
    background: #eef3f5;
    color: var(--text);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    display: grid;
    place-items: center;
}
.modal-close:hover {
    background: #e2eaed;
}
.subject-modal .subject-form-actions {
    justify-content: flex-end;
    margin-top: 0.5rem;
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
}
table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}
th, td {
    padding: 0.8rem 0.9rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-size: 0.94rem;
}
th {
    background: #f2f7f8;
    font-weight: 700;
    white-space: nowrap;
    font-size: 0.84rem;
    color: var(--muted);
    letter-spacing: 0.02em;
}
tr:last-child td { border-bottom: none; }
tbody tr:hover td {
    background: rgba(15, 110, 122, 0.03);
}
.score-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: rgba(15, 110, 122, 0.1);
    color: var(--brand-dark);
    font-weight: 700;
    font-size: 0.88rem;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.7rem;
    margin-bottom: 1rem;
}
.stat {
    background: #f7fafb;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0.9rem;
}
.stat .label { color: var(--muted); font-size: 0.85rem; }
.stat .value { font-size: 1.4rem; font-weight: 700; margin-top: 0.2rem; }

.score-hero {
    text-align: center;
    padding: 1.5rem 1rem;
}
.score-hero .score {
    font-size: clamp(2.4rem, 8vw, 3.5rem);
    font-weight: 700;
    color: var(--brand-dark);
    line-height: 1;
}
.score-hero .sub { color: var(--muted); margin-top: 0.4rem; }

/* Result page */
.result-page .result-card {
    padding: 1.4rem 1.25rem 1.35rem;
}
.result-score-block {
    text-align: center;
    padding: 1.15rem 1rem 1.25rem;
    margin-bottom: 1rem;
    border-radius: 16px;
    background:
        linear-gradient(160deg, rgba(15, 110, 122, 0.1), rgba(217, 119, 6, 0.07)),
        #f5fafb;
    border: 1px solid rgba(15, 110, 122, 0.12);
}
.result-score-label {
    display: block;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}
.result-score {
    font-family: var(--display);
    font-size: clamp(2.6rem, 9vw, 3.6rem);
    font-weight: 700;
    color: var(--brand-dark);
    letter-spacing: -0.04em;
    line-height: 1;
}
.result-score span {
    font-size: 0.45em;
    font-weight: 600;
    color: var(--muted);
    margin-left: 0.1rem;
}
.result-meter {
    height: 8px;
    max-width: 220px;
    margin: 0.85rem auto 0.55rem;
    border-radius: 999px;
    background: rgba(15, 110, 122, 0.12);
    overflow: hidden;
}
.result-meter > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--brand), #2bb3c0);
}
.result-percent {
    display: block;
    font-family: var(--display);
    font-size: 1.25rem;
    color: var(--brand-dark);
    letter-spacing: -0.02em;
}
.result-facts {
    margin-bottom: 1rem;
}
.result-note {
    margin-bottom: 0.25rem;
}

/* Confirm submit */
.confirm-page {
    animation: rise 0.4s ease;
}
.confirm-hero {
    text-align: center;
    padding: 0.35rem 0 1.15rem;
}
.confirm-eyebrow {
    display: inline-block;
    margin: 0 0 0.55rem;
    padding: 0.28rem 0.75rem;
    border-radius: 999px;
    background: rgba(15, 110, 122, 0.12);
    color: var(--brand-dark);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.confirm-hero h1 {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(1.35rem, 4vw, 1.75rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.25;
}
.confirm-hero p {
    margin: 0.55rem auto 0;
    max-width: 28rem;
    color: var(--muted);
    font-size: 0.98rem;
    line-height: 1.5;
}
.confirm-card {
    padding: 1.35rem 1.25rem 1.3rem;
}
.confirm-subject {
    display: grid;
    gap: 0.25rem;
    padding: 1rem 1.05rem;
    border-radius: 14px;
    background:
        linear-gradient(135deg, rgba(15, 110, 122, 0.1), rgba(217, 119, 6, 0.08)),
        #f4fafb;
    border: 1px solid rgba(15, 110, 122, 0.14);
    margin-bottom: 1rem;
}
.confirm-subject-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
}
.confirm-subject-name {
    font-size: 1.12rem;
    font-weight: 700;
    line-height: 1.35;
    letter-spacing: -0.01em;
}
.confirm-progress {
    margin-bottom: 1rem;
    padding: 0.95rem 1.05rem;
    border-radius: 14px;
    background: var(--ok-bg);
    border: 1px solid #9fd4b5;
}
.confirm-progress-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.55rem;
}
.confirm-progress-top span {
    color: var(--ok);
    font-size: 0.88rem;
    font-weight: 600;
}
.confirm-progress-top strong {
    color: var(--ok);
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}
.confirm-meter {
    height: 8px;
    border-radius: 999px;
    background: rgba(15, 122, 74, 0.15);
    overflow: hidden;
}
.confirm-meter > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #0f7a4a, #2a9b66);
}
.confirm-facts {
    margin: 0 0 1rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.55rem;
}
.confirm-fact {
    display: grid;
    gap: 0.2rem;
    padding: 0.8rem 0.95rem;
    border-radius: 12px;
    background: #f7fafb;
    border: 1px solid var(--line);
}
.confirm-fact dt {
    margin: 0;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
}
.confirm-fact dd {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.35;
    word-break: break-word;
}
.confirm-note {
    margin: 0 0 0.25rem;
    padding: 0.85rem 0.95rem;
    border-radius: 12px;
    background: var(--warn-bg);
    color: var(--warn);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.45;
}
.confirm-actions {
    margin-top: 1.15rem;
}
.confirm-modal {
    text-align: center;
    padding: 1.5rem 1.25rem 1.35rem;
}
.confirm-modal-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 0.85rem;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(145deg, #f59e0b, #d97706);
    color: #fff;
    font-size: 1.45rem;
    font-weight: 700;
    box-shadow: 0 8px 20px rgba(217, 119, 6, 0.28);
}
.confirm-modal h3 {
    font-size: 1.2rem;
}
.confirm-modal .btn-row {
    justify-content: center;
}

@media (min-width: 520px) {
    .confirm-facts {
        grid-template-columns: 1fr 1fr;
    }
    .confirm-card {
        padding: 1.5rem 1.4rem 1.4rem;
    }
}

@media (max-width: 640px) {
    .stats { grid-template-columns: 1fr; }
    .nav-grid { grid-template-columns: 1fr; }
    .page:not(.exam-page) .btn { width: 100%; }
    .topbar { flex-direction: column; align-items: stretch; }
    .btn-row { flex-direction: column; }
    .btn-row .btn { width: 100%; }
    .subjects-page .subjects-stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
    }
    .subjects-page .subjects-stats .stat {
        padding: 0.7rem 0.55rem;
        text-align: center;
    }
    .subjects-page .subjects-stats .value {
        font-size: 1.2rem;
    }
    .subject-admin-primary .btn,
    .subject-admin-secondary .btn {
        width: 100%;
    }
    .subject-admin-secondary {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
    .subject-admin-secondary form:last-child {
        grid-column: 1 / -1;
    }
    .panel-head .btn-compact {
        width: auto;
        align-self: flex-start;
    }
}

/* Exam page layout */
.exam-page {
    width: min(720px, calc(100% - 1rem));
    padding-top: 0.75rem;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
}

.exam-sticky-top {
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 -0.15rem 0.85rem;
    padding: 0.7rem 0.75rem 0.8rem;
    background: rgba(247, 250, 251, 0.92);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 8px 20px rgba(28, 43, 51, 0.06);
    backdrop-filter: blur(10px);
}

.exam-student-name {
    display: block;
    font-family: var(--display);
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.015em;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.exam-student .meta {
    color: var(--muted);
    font-size: 0.82rem;
    margin-top: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.exam-subject-tag {
    display: inline-flex;
    align-items: center;
    margin-right: 0.35rem;
    padding: 0.12rem 0.5rem;
    border-radius: 999px;
    background: rgba(15, 110, 122, 0.12);
    color: var(--brand-dark);
    font-weight: 700;
    font-size: 0.78rem;
}
.exam-progress {
    margin: 0.65rem 0 0;
}

.exam-page .question-card {
    padding: 1rem 1rem 1.1rem;
}
.exam-page .q-text {
    font-size: clamp(1.05rem, 3.6vw, 1.2rem);
    line-height: 1.6;
}
.exam-page .choice-list {
    gap: 0.65rem;
}

.exam-navigator {
    margin-top: 1rem;
    padding: 0;
    overflow: hidden;
}
.navigator-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.95rem 1rem;
    font-weight: 700;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.navigator-summary::-webkit-details-marker { display: none; }
.navigator-summary::after {
    content: "▾";
    position: absolute;
    right: 1rem;
    top: 1rem;
    color: var(--muted);
    font-weight: 700;
}
.exam-navigator {
    position: relative;
}
.exam-navigator[open] .navigator-summary::after {
    content: "▴";
}
.navigator-summary-meta {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--muted);
    padding-right: 1.5rem;
}
.exam-navigator .nav-dots,
.exam-navigator .legend {
    padding: 0 1rem 1rem;
}
.exam-navigator .legend {
    margin-top: 0.2rem;
}

.exam-actions {
    margin: 1rem 0 0;
}
.exam-actions-row {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1.2fr;
    gap: 0.55rem;
}
.exam-actions-secondary {
    margin-top: 0.55rem;
    grid-template-columns: 1fr 1.35fr;
}
.exam-actions .btn {
    width: 100%;
    min-height: 48px;
    border-radius: 14px;
    font-size: 0.95rem;
    touch-action: manipulation;
}
.exam-btn-skip {
    font-weight: 600;
}

@media (min-width: 768px) {
    .exam-page {
        padding-bottom: 2.5rem;
    }
    .exam-sticky-top {
        margin-bottom: 1rem;
    }
    .exam-navigator .navigator-summary {
        pointer-events: none;
    }
    .exam-navigator .navigator-summary::after {
        display: none;
    }
}

@media (max-width: 380px) {
    .exam-page {
        width: calc(100% - 0.75rem);
    }
    .exam-actions .btn {
        font-size: 0.88rem;
        padding: 0.7rem 0.6rem;
    }
    .nav-dots {
        grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
        gap: 0.4rem;
    }
}

/* Exam anti-copy / focus guard */
.exam-protect {
    position: relative;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}
.exam-protect img {
    -webkit-user-drag: none;
    pointer-events: none;
}

.exam-watermark {
    position: fixed;
    inset: 0;
    z-index: 5;
    pointer-events: none;
    overflow: hidden;
    opacity: 0.11;
}
.exam-watermark-inner {
    position: absolute;
    inset: -40%;
    display: flex;
    flex-wrap: wrap;
    gap: 3.5rem 4rem;
    align-content: flex-start;
    transform: rotate(-28deg);
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--ink);
    white-space: nowrap;
}
.exam-watermark-inner span {
    display: inline-block;
}

.exam-protect-toast {
    position: fixed;
    left: 50%;
    bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%) translateY(120%);
    z-index: 80;
    max-width: min(420px, calc(100% - 2rem));
    background: #1c2b33;
    color: #fff;
    padding: 0.85rem 1.1rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.92rem;
    text-align: center;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.22s ease, opacity 0.22s ease;
}
.exam-protect-toast.is-visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.exam-focus-guard {
    position: fixed;
    inset: 0;
    z-index: 70;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(16, 28, 34, 0.72);
    backdrop-filter: blur(6px);
}
.exam-focus-guard.is-open { display: flex; }
.exam-focus-panel {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 18px;
    padding: 1.35rem 1.25rem;
    box-shadow: var(--shadow);
    text-align: center;
    animation: rise 0.22s ease;
}
.exam-focus-panel h3 {
    margin: 0 0 0.5rem;
    font-size: 1.2rem;
}
.exam-focus-panel p {
    margin: 0 0 0.35rem;
    color: var(--muted);
    line-height: 1.5;
}
.exam-focus-panel .leave-note {
    margin: 0 0 1.1rem;
    color: var(--warn);
    font-size: 0.9rem;
    font-weight: 600;
}

#exam-leave-badge {
    font-weight: 700;
    color: var(--warn);
}

td.leave-warn {
    color: var(--warn);
    font-weight: 700;
}

.steps-list {
    margin: 0.35rem 0 0;
    padding-left: 1.25rem;
    display: grid;
    gap: 0.45rem;
    color: var(--ink);
    line-height: 1.5;
}
.steps-list a {
    color: var(--brand);
    font-weight: 600;
}
.import-form input[type="file"] {
    width: 100%;
    border: 1.5px dashed var(--line);
    border-radius: 12px;
    padding: 0.9rem 1rem;
    background: #fbfcfd;
    font: inherit;
}
.import-form fieldset.choice-fieldset {
    margin: 0;
}
