:root {
    --bg: #f4f7f8;
    --panel: #ffffff;
    --ink: #1d2a32;
    --muted: #5f6f78;
    --accent: #0f8b8d;
    --accent-strong: #0a6668;
    --warm: #f4a261;
    --ok-bg: #e8f8ef;
    --ok-ink: #136b3a;
    --err-bg: #fee9e8;
    --err-ink: #8f2f2a;
    --line: #d9e2e5;
    --shadow: 0 12px 24px rgba(16, 31, 44, 0.08);
    --font-scale: 1;
}

body[data-theme="sand"] {
    --bg: #faf6ef;
    --panel: #fffdf7;
    --ink: #342b23;
    --muted: #7a6b5c;
    --accent: #b56a3f;
    --accent-strong: #8d4e2a;
    --line: #eadfce;
}

body[data-theme="forest"] {
    --bg: #eff7f1;
    --panel: #ffffff;
    --ink: #203127;
    --muted: #5c6d62;
    --accent: #2f7d4f;
    --accent-strong: #225b39;
    --line: #d1e1d6;
}

body[data-theme="night"] {
    --bg: #11161b;
    --panel: #1b2229;
    --ink: #e6edf3;
    --muted: #a8b4c0;
    --accent: #2ca3a3;
    --accent-strong: #1f7f7f;
    --line: #2d3742;
    --ok-bg: #193226;
    --ok-ink: #a6e5bb;
    --err-bg: #3a2222;
    --err-ink: #f2b6b6;
    --shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
}

body[data-font="small"] {
    --font-scale: 0.8;
}

body[data-font="medium"] {
    --font-scale: 1;
}

body[data-font="large"] {
    --font-scale: 1.22;
}

body[data-font="xlarge"] {
    --font-scale: 1.36;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Manrope", "Segoe UI", sans-serif;
    background: radial-gradient(circle at 5% 10%, #d8f3e9 0%, transparent 35%),
        radial-gradient(circle at 90% 90%, #fce3cb 0%, transparent 30%),
        var(--bg);
    color: var(--ink);
    font-size: calc(16px * var(--font-scale));
}

body[data-page="student"] {
    -webkit-user-select: none;
    user-select: none;
}

body[data-page="student"] input,
body[data-page="student"] select,
body[data-page="student"] textarea,
body[data-page="student"] button,
body[data-page="student"] a {
    -webkit-user-select: auto;
    user-select: auto;
}

a {
    color: var(--accent-strong);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.container {
    width: min(1100px, 92vw);
    margin: 28px auto 42px;
}

.hero {
    background: linear-gradient(120deg, #0f8b8d 0%, #1d3557 100%);
    color: #fff;
    padding: 24px;
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.hero h1 {
    margin: 0 0 10px;
    font-size: clamp(1.6rem, 3vw, 2.3rem);
}

.hero p {
    margin: 0;
    max-width: 70ch;
    opacity: 0.95;
}

.grid {
    margin-top: 22px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.card h2,
.card h3 {
    margin-top: 0;
}

.kpi {
    font-size: 2rem;
    font-weight: 700;
}

.row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.row>* {
    flex: 1 1 180px;
}

button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 11px;
    padding: calc(10px * var(--font-scale)) calc(14px * var(--font-scale));
    cursor: pointer;
    font-weight: 600;
    background: var(--accent);
    color: #fff;
    text-align: center;
    white-space: nowrap;
}

button:hover,
.btn:hover {
    background: var(--accent-strong);
    text-decoration: none;
}

.btn-secondary {
    background: #2f3e46;
}

.btn-warm {
    background: #d97706;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: calc(10px * var(--font-scale));
    font: inherit;
    color: inherit;
    background: #fff;
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    min-width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
    flex: 0 0 auto;
}

input,
select,
textarea,
button,
.btn {
    font-size: calc(1rem * var(--font-scale));
}

label {
    display: block;
    margin: 10px 0 6px;
    font-weight: 600;
}

small,
.hint {
    color: var(--muted);
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.85rem;
    font-weight: 700;
    background: #e6f2f2;
    color: #0b5d5f;
}

.badge-dark {
    background: #2f3e46;
    color: #f8fbfd;
}

.alert {
    border-radius: 11px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.alert-error {
    background: var(--err-bg);
    color: var(--err-ink);
}

.alert-success {
    background: var(--ok-bg);
    color: var(--ok-ink);
}

.question-block {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
    background: #fcfefe;
}

.question-block h3,
.question-block .hint,
.question-block label {
    -webkit-user-select: none;
    user-select: none;
}

.question-block--expired {
    opacity: 0.72;
    filter: saturate(0.9);
}

.question-timer {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    margin-left: 8px;
    border-radius: 999px;
    background: #edf7f2;
    color: var(--accent-strong);
    font-size: 0.85em;
    font-weight: 700;
}

.timer-expired {
    background: #fde8e8;
    color: var(--err-ink);
    font-weight: 700;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    gap: 8px;
}

.teacher-nav {
    justify-content: flex-start;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
}

.teacher-nav .btn {
    min-width: auto;
}

.teacher-nav>* {
    flex: 0 0 auto;
}

.topbar .btn,
.topbar button {
    min-width: 120px;
}

.stack {
    display: grid;
    gap: 12px;
}

.split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.mono {
    font-family: "JetBrains Mono", "Fira Mono", monospace;
    font-size: 0.9em;
}

.btn-wide {
    width: 100%;
}

.actions {
    justify-content: center;
}

.actions>* {
    flex: 0 0 auto;
}

.student-actions {
    justify-content: flex-start;
}

.student-actions>* {
    flex: 0 0 auto;
    max-width: 360px;
}

.student-option {
    font-weight: 400;
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-start;
    text-align: left;
    margin: 8px 0;
}

.question-bank-list {
    display: grid;
    gap: 8px;
}

.question-bank-item {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fbfdfd;
    padding: 8px 10px;
}

.question-bank-item>summary {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.question-bank-item>summary .badge {
    margin-left: auto;
}

.question-bank-item-body {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

@media (min-width: 900px) {
    .stats-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

.stats-grid {
    display: grid;
    gap: 12px;
}

.stat-card {
    background: linear-gradient(180deg, rgba(15, 139, 141, 0.08), rgba(15, 139, 141, 0.02));
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
}

.stat-label {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 0.86rem;
}

.stat-value {
    margin: 0;
    font-size: clamp(1.15rem, 2.4vw, 1.8rem);
    font-weight: 800;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 18px 0 12px;
}

.tabs-top {
    margin: 0 0 12px;
}

.teacher-header-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.teacher-header-line .tabs {
    margin: 0;
    flex-wrap: nowrap;
}

.teacher-header-line .tab-button {
    white-space: nowrap;
}

.teacher-header-actions {
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 8px;
}

.teacher-header-actions .btn,
.teacher-header-actions button {
    min-width: 120px;
}

.tab-button {
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--ink);
}

.tab-button.is-active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

.tab-panel[hidden] {
    display: none !important;
}

.tab-panel {
    animation: fadeInUp 220ms ease-out;
}

.icon-button {
    width: 42px;
    min-width: 42px;
    padding: 0;
    border-radius: 999px;
}

.settings-gear {
    position: fixed;
    top: 8px;
    right: 12px;
    z-index: 70;
    font-size: 26px;
    line-height: 1;
    color: var(--accent-strong);
    text-decoration: none;
    background: transparent;
    border: none;
    padding: 4px;
}

.settings-gear:hover {
    text-decoration: none;
    color: var(--accent);
    transform: rotate(18deg);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(18, 28, 36, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 50;
}

.modal-backdrop.is-open {
    display: flex;
}

.modal {
    width: min(760px, 100%);
    max-height: 88vh;
    overflow: auto;
    background: var(--panel);
    border-radius: 18px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    padding: 18px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.modal-title {
    margin: 0;
}

.modal-close {
    width: 38px;
    min-width: 38px;
    border-radius: 999px;
}

.compact-grid {
    display: grid;
    gap: 12px;
}

.ghost-panel {
    background: color-mix(in srgb, var(--panel) 90%, transparent);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 16px;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

pre {
    background: #f0f4f6;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
    overflow-x: auto;
}

@media (max-width: 680px) {
    .container {
        width: 95vw;
    }

    .hero {
        padding: 18px;
    }

    .card {
        padding: 14px;
    }

    .split {
        grid-template-columns: 1fr;
    }

    .teacher-header-line {
        flex-direction: column;
        align-items: stretch;
    }

    .teacher-header-line .tabs,
    .teacher-header-actions {
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .settings-gear {
        top: 6px;
        right: 8px;
        font-size: 24px;
    }

}