:root {
    color-scheme: light;
    --bg: #eef2f6;
    --panel: #ffffff;
    --panel-soft: #f7f9fc;
    --line: #d9e3ee;
    --line-strong: #b9c7d6;
    --text: #102235;
    --muted: #65768a;
    --primary: #1769aa;
    --primary-dark: #0f548b;
    --success: #157f55;
    --danger: #b9362d;
    --warning: #946812;
    --shadow: 0 16px 40px rgba(16, 34, 53, 0.1);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
    letter-spacing: 0;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.topbar {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 18px;
    background: #102235;
    color: #fff;
}

.topbar h1,
.section-title h2,
.question-head h2 {
    margin: 0;
}

.topbar h1 {
    font-size: 20px;
}

.topbar p,
.section-title p {
    margin: 3px 0 0;
    color: #b9c8d9;
    font-size: 13px;
}

.app-shell {
    display: grid;
    gap: 14px;
    width: min(1180px, calc(100vw - 24px));
    margin: 14px auto;
}

.panel {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    padding: 16px;
}

.section-title,
.question-head,
.actions,
.spread,
.option-row,
.score-line,
.history-head,
.review-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.section-title,
.question-head,
.spread,
.history-head,
.review-head {
    justify-content: space-between;
}

.section-title {
    margin-bottom: 14px;
}

.step-chip,
.meta-chip,
.status-chip {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    background: #edf4fa;
    color: #40566d;
    padding: 0 9px;
    font-size: 12px;
    font-weight: 800;
}

.status-chip.correct {
    color: var(--success);
    background: #eaf8f1;
}

.status-chip.wrong {
    color: var(--danger);
    background: #fff1ef;
}

.status-chip.manual {
    color: var(--warning);
    background: #fff8e8;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.field {
    display: grid;
    gap: 6px;
}

.field span {
    color: #41546b;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    padding: 8px 10px;
}

.btn {
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    padding: 0 13px;
    font-size: 13px;
    font-weight: 700;
}

.btn:hover {
    border-color: var(--line-strong);
    background: #f1f5f9;
}

.btn.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.btn.primary:hover {
    background: var(--primary-dark);
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.wide-btn {
    width: 100%;
}

.hint-box,
.error-box,
.quiz-summary {
    margin-top: 12px;
    border-radius: 8px;
    padding: 11px 12px;
    font-size: 14px;
}

.hint-box,
.quiz-summary {
    border: 1px solid #cce2f5;
    background: #f0f7fd;
    color: #244660;
}

.error-box {
    border: 1px solid #efc8c3;
    background: #fff7f6;
    color: #65211c;
}

.quiz-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 14px;
}

.nav-panel {
    align-self: start;
    position: sticky;
    top: 14px;
}

.question-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 7px;
}

.question-nav button {
    aspect-ratio: 1;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    font-weight: 800;
}

.question-nav button.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.question-nav button.answered {
    border-color: #9bd2b8;
    background: #eaf8f1;
}

.question-nav button.active.answered {
    background: var(--primary);
}

.meta-line {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.rich-content {
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.rich-content img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    vertical-align: middle;
}

.rich-content table {
    border-collapse: collapse;
    max-width: 100%;
    margin: 8px 0;
}

.rich-content td,
.rich-content th {
    border: 1px solid var(--line-strong);
    padding: 6px 8px;
}

.answer-area {
    display: grid;
    gap: 10px;
    margin: 16px 0;
}

.option-card,
.text-answer,
.review-card,
.history-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-soft);
    padding: 12px;
}

.option-card {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.option-card input {
    margin-top: 4px;
}

.text-answer textarea,
.fib-input {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 9px 10px;
    resize: vertical;
}

.review-list,
.history-list {
    display: grid;
    gap: 10px;
}

.review-card,
.history-card {
    display: grid;
    gap: 9px;
}

.score-line {
    color: var(--muted);
    font-size: 13px;
}

.toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    min-width: 220px;
    max-width: calc(100vw - 32px);
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    border-radius: 8px;
    background: #102235;
    color: #fff;
    padding: 11px 13px;
    box-shadow: var(--shadow);
    transition: opacity 0.18s, transform 0.18s;
    font-size: 13px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 900px) {
    .form-grid,
    .quiz-layout {
        grid-template-columns: 1fr;
    }

    .nav-panel {
        position: static;
    }

    .question-nav {
        grid-template-columns: repeat(10, minmax(34px, 1fr));
    }
}

@media (max-width: 620px) {
    .topbar,
    .section-title,
    .question-head,
    .spread {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar .btn,
    .actions .btn,
    .spread .btn {
        width: 100%;
    }

    .question-nav {
        grid-template-columns: repeat(5, 1fr);
    }

    .panel {
        padding: 12px;
    }
}
