:root {
    --bg: #f5f1ea;
    --card: #fffaf2;
    --text: #201a14;
    --muted: #75695d;
    --border: #e1d5c8;
    --primary: #33251b;
    --primary-hover: #1e1510;
    --green: #13795b;
    --red: #b42318;
    --shadow: 0 18px 50px rgba(41, 29, 18, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: radial-gradient(circle at top left, #fff7e7 0, var(--bg) 42%, #eee5da 100%);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.quiz-shell {
    width: min(1050px, calc(100% - 32px));
    margin: 40px auto;
}

.quiz-header {
    display: grid;
    grid-template-columns: 1fr minmax(220px, 300px);
    gap: 24px;
    align-items: stretch;
    margin-bottom: 24px;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: .12em;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    margin: 0 0 8px;
}

h1 {
    font-size: clamp(34px, 5vw, 56px);
    margin: 0;
    letter-spacing: -0.04em;
}

.intro {
    max-width: 720px;
    color: var(--muted);
    line-height: 1.7;
    font-size: 17px;
}

.card,
.stats-card {
    background: rgba(255, 250, 242, 0.92);
    border: 1px solid var(--border);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.card {
    padding: clamp(20px, 3vw, 34px);
    margin-bottom: 22px;
}

.stats-card {
    padding: 22px;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    align-content: center;
}

.stats-card strong {
    font-size: 24px;
}

.stats-card span {
    color: var(--muted);
    align-self: center;
}

.question-card {
    min-height: 420px;
    scroll-margin-top: var(--daily-goal-offset, 170px);
}

.daily-goal {
    position: sticky;
    top: 8px;
    z-index: 10;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 0 16px;
    align-items: center;
    padding: 18px 22px 14px;
    margin-bottom: 22px;
    border: 2px solid #d5bd83;
    border-radius: 22px;
    background: #fffdf5;
    box-shadow: 0 5px 0 #e4d8b9, 0 12px 24px #33251b0d;
}
.xp-star { color: #b27600; background: #fff0b8; border-radius: 14px; text-align: center; font-size: 30px; line-height: 46px; }
.xp-star .flame-icon { width: 28px; height: 32px; vertical-align: middle; }
.flame-icon { display: inline-block; width: 21px; height: 24px; vertical-align: middle; flex-shrink: 0; }
.streak-card { padding: 18px 22px; margin-bottom: 22px; border: 1px solid var(--border); border-radius: 22px; background: #fffaf2; box-shadow: var(--shadow); }
.streak-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.streak-heading h2 { font-size: 17px; margin: 0; }
.streak-heading strong { display: inline-flex; align-items: center; gap: 6px; color: #a44a0b; font-size: 17px; }
.streak-hint { margin: 9px 0 13px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.recent-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; list-style: none; margin: 0; padding: 0; }
.day-status { display: grid; justify-items: center; gap: 5px; min-width: 0; font-size: 12px; color: var(--muted); }
.day-label { font-weight: 700; }
.day-mark { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; border: 1px solid #ddd5c9; border-radius: 50%; background: #f4efe7; font-size: 19px; }
.day-completed .day-mark { border-color: #a9c98f; background: #edf8e2; }
.day-completed .day-xp { color: #276524; }
.day-partial .day-mark { color: #a45908; background: #fff0d3; border-color: #e1b778; }
.day-missed .day-mark { color: #a52525; background: #fff0ed; border-color: #e4b2a9; }
.day-pending .day-mark { border-style: dashed; border-color: #d2a14d; background: #fff8e9; color: #90641e; }
.day-status.is-today .day-label { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.day-xp { font-size: 11px; white-space: nowrap; }
.level-badge { display: inline-flex; width: fit-content; align-items: center; border: 1px solid transparent; border-radius: 999px; padding: 5px 10px; font-size: 13px; line-height: 1.25; font-weight: 800; }
.level-badge.level-red { color: #9c2424; background: #ffebe7; border-color: #e9b5ac; }
.level-badge.level-orange { color: #8b5208; background: #fff0d2; border-color: #e7c388; }
.level-badge.level-green { color: #17633e; background: #e3f2de; border-color: #abcfa4; }
.daily-goal-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.daily-goal-heading h2 { font-size: 18px; margin: 0; }
.daily-goal-heading strong { white-space: nowrap; color: #8a5800; font-size: 20px; font-variant-numeric: tabular-nums; }
.daily-goal progress { display: block; width: 100%; height: 15px; margin: 9px 0; border: 0; border-radius: 999px; overflow: hidden; background: #ece6d7; accent-color: #609a24; }
.daily-goal progress::-webkit-progress-bar { background: #ece6d7; border-radius: 999px; }
.daily-goal progress::-webkit-progress-value { background: #7eb637; border-radius: 999px; }
.daily-goal progress::-moz-progress-bar { background: #7eb637; border-radius: 999px; }
.daily-goal.goal-complete { border-color: #7dab53; background: #f3fae9; box-shadow: 0 5px 0 #d5e8bd, 0 12px 24px #13795b0a; }
.goal-complete .xp-star { background: #dff0c6; color: #3e721a; }
.goal-complete .daily-goal-heading strong { color: #386b16; }
.xp-feedback { grid-column: 1 / -1; color: #13795b; font-size: 13px; font-weight: 800; margin: 8px 0 0; }
.xp-feedback:empty { display: none; }
.question-card.is-mastered { background: #f0f9ee; border: 2px solid #7baa74; }
.question-card.is-mastered #questionText { color: #17633e; }
.mastery-badge { display: inline-block; padding: 7px 12px; margin: 0 0 18px; font-size: 13px; font-weight: 800; border-radius: 999px; background: #dcefdc; color: #17633e; }
.mastery-badge.review-due { color: #945000; background: #fff0cc; }
.hardest-item.is-mastered { padding-left: 14px; border-left: 4px solid #7baa74; background: #f0f9ee; }
.hardest-item.is-mastered strong { color: #17633e; }
.hardest-item .review-due, .stats-card .review-due { color: #945000; }

@media (max-width: 480px) {
    .streak-card { padding: 15px 14px; }
    .streak-heading { gap: 8px; }
    .streak-heading h2 { font-size: 15px; }
    .streak-heading strong { font-size: 14px; }
    .recent-days { gap: 3px; }
    .day-mark { width: 29px; height: 29px; }
    .day-label, .day-xp { font-size: 10px; }
    .daily-goal { padding: 12px 14px 10px; gap: 0 10px; grid-template-columns: 34px minmax(0, 1fr); }
    .xp-star { font-size: 25px; line-height: 38px; }
    .daily-goal-heading h2 { font-size: 15px; }
    .daily-goal-heading strong { font-size: 17px; }
}

.question-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 20px;
}

#questionText {
    font-size: clamp(25px, 4vw, 40px);
    line-height: 1.15;
    letter-spacing: -0.03em;
    margin: 0 0 28px;
}

label,
.label {
    display: block;
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: 10px;
}

textarea {
    width: 100%;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 16px;
    background: #fffdf8;
    color: var(--text);
    font: inherit;
    line-height: 1.5;
    outline: none;
}

textarea:focus {
    border-color: #9f8a75;
    box-shadow: 0 0 0 4px rgba(159, 138, 117, 0.16);
}

.actions,
.self-grade {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 18px;
}

button {
    border: 0;
    border-radius: 999px;
    padding: 13px 18px;
    font-weight: 850;
    cursor: pointer;
    transition: transform .15s ease, opacity .15s ease, background .15s ease;
}

button:hover {
    transform: translateY(-1px);
}

button:disabled {
    opacity: .6;
    cursor: wait;
}

.primary-btn {
    background: var(--primary);
    color: white;
}

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

.secondary-btn {
    background: #ede3d8;
    color: var(--text);
}

.correct-btn {
    background: var(--green);
    color: white;
}

.wrong-btn {
    background: var(--red);
    color: white;
}

.hidden {
    display: none !important;
}

.correction {
    display: grid;
    gap: 24px;
}

.answer-preview,
.correct-answer {
    background: #fffdf8;
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    line-height: 1.6;
    margin: 0;
}

.correct-answer {
    font-size: 22px;
    font-weight: 850;
}

.hardest-list {
    display: grid;
    gap: 12px;
}

.hardest-item {
    display: grid;
    gap: 5px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.hardest-item:last-child {
    border-bottom: 0;
}

.hardest-item span {
    color: var(--muted);
    font-size: 14px;
}

.hardest-item-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.hardest-item-heading strong { min-width: 0; overflow-wrap: anywhere; }
.hardest-answer { margin: 4px 0; padding: 12px 14px; background: #fffdf8; border: 1px solid var(--border); border-radius: 12px; color: var(--text); font-size: 16px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.hardest-item .hardest-answer-label { display: block; margin-bottom: 3px; font-size: 12px; font-weight: 700; color: var(--muted); }
.question-footer { display: flex; justify-content: flex-end; margin-top: 18px; }
.question-deactivate { flex-shrink: 0; width: auto; min-height: 34px; padding: 5px 8px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); font: inherit; font-size: 12px; font-weight: 500; box-shadow: none; }
.question-deactivate:hover { background: #fff0ed; border-color: #e4b2a9; color: #9c2424; transform: none; }
.question-deactivate:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
.question-action-dialog { width: min(500px, calc(100% - 32px)); max-height: calc(100vh - 40px); overflow: auto; padding: 24px; border: 1px solid var(--border); border-radius: 20px; background: var(--card); color: var(--text); box-shadow: 0 24px 80px #201a1433; }
.question-action-dialog::backdrop { background: #201a1477; }
.question-action-dialog h2 { margin: 0 0 14px; font-size: 22px; }
.question-action-dialog p { line-height: 1.5; }
.question-action-dialog .dialog-question { padding: 12px; border-radius: 10px; background: #fffdf8; border: 1px solid var(--border); font-weight: 700; overflow-wrap: anywhere; white-space: pre-wrap; }
.dialog-auth { color: var(--muted); font-size: 14px; }
.dialog-error { color: var(--red); font-size: 14px; }
.dialog-error:empty { display: none; }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
@media (max-width: 480px) {
    .hardest-item-heading { flex-wrap: wrap; gap: 4px; }
    .hardest-item-heading .question-deactivate { margin-left: auto; }
    .question-action-dialog { padding: 20px; }
}

.revision-settings select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fffdf8;
    color: var(--text);
    font: inherit;
}

#themeSelect.theme-mastery-red { color: #9c2424; border-color: #d9988c; background-color: #fff3ef; }
#themeSelect.theme-mastery-orange { color: #8b5208; border-color: #d1ab69; background-color: #fff6e3; }
#themeSelect.theme-mastery-green { color: #17633e; border-color: #8fbd95; background-color: #edf7e9; }
#themeSelect option { background-color: #fffdf8; color: var(--text); }
#themeSelect option.theme-mastery-red { color: #9c2424; }
#themeSelect option.theme-mastery-orange { color: #8b5208; }
#themeSelect option.theme-mastery-green { color: #17633e; }

.help-text {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

#statusMessage:empty {
    display: none;
}

#statusMessage.error {
    color: var(--red);
}

@media (max-width: 760px) {
    .quiz-header {
        grid-template-columns: 1fr;
    }

    .quiz-shell {
        margin-top: 22px;
    }
}
