:root {
    --bg: #f4f2ec;
    --ink: #18211d;
    --muted: #617069;
    --line: #d6d0c3;
    --panel: #fffdf8;
    --accent: #1f7a5a;
    --accent-strong: #12543e;
    --warn: #9b6218;
    --bad: #a43b39;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--bg);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.36;
}

.app-shell {
    width: min(980px, calc(100% - 24px));
    margin: 0 auto;
    padding: 12px 0 22px;
}

.topbar,
.controls,
.quiz-card {
    background: var(--panel);
    border: 1px solid var(--line);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 14px;
    border-radius: 8px;
}

.eyebrow {
    margin: 0 0 2px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: 30px;
    line-height: 1;
    letter-spacing: 0;
}

.nav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.nav-links a,
button {
    min-height: 34px;
    border-radius: 6px;
    border: 1px solid var(--accent);
    padding: 0 10px;
    color: #fff;
    background: var(--accent);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.nav-links a {
    background: transparent;
    color: var(--accent-strong);
}

.controls {
    margin-top: 8px;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.segmented {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
    background: #ede7db;
}

.segmented button {
    border: 0;
    border-radius: 0;
    color: var(--muted);
    background: transparent;
}

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

.ghost-button {
    color: var(--accent-strong);
    background: transparent;
}

.progress-copy {
    margin-left: auto;
    color: var(--muted);
    font-size: 14px;
    display: flex;
    gap: 12px;
    font-weight: 700;
}

.progress-track {
    height: 7px;
    margin: 8px 0;
    border-radius: 999px;
    background: #ded7c9;
    overflow: hidden;
}

#progress-fill {
    width: 0;
    height: 100%;
    background: var(--accent);
    transition: width 160ms ease;
}

.quiz-card {
    border-radius: 8px;
    padding: 14px;
}

.question-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    color: #fff;
    background: var(--accent);
}

h2 {
    margin: 10px 0 10px;
    font-size: clamp(20px, 3vw, 27px);
    line-height: 1.12;
    letter-spacing: 0;
}

.answer-label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

textarea {
    width: 100%;
    min-height: 88px;
    resize: vertical;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    color: var(--ink);
    background: #fff;
    font: 16px/1.32 Arial, Helvetica, sans-serif;
}

textarea:focus,
button:focus-visible,
.nav-links a:focus-visible {
    outline: 3px solid rgba(31, 122, 90, 0.28);
    outline-offset: 2px;
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.written-stats-status {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.written-stats-status[data-state="success"] {
    color: var(--accent-strong);
}

.written-stats-status[data-state="error"] {
    color: var(--bad);
}

.feedback {
    margin-top: 10px;
    border-top: 1px solid var(--line);
    padding-top: 10px;
}

.feedback-title {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
}

.feedback-score {
    margin: 3px 0 10px;
    color: var(--muted);
}

.feedback[data-state="correct"] .feedback-title {
    color: var(--accent-strong);
}

.feedback[data-state="close"] .feedback-title {
    color: var(--warn);
}

.feedback[data-state="incorrect"] .feedback-title {
    color: var(--bad);
}

.answer-box {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    background: #f8f5ee;
}

.answer-box-label {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

#correct-answer {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.32;
    white-space: pre-line;
}

@media (max-width: 640px) {
    .app-shell {
        width: min(100% - 14px, 980px);
        padding-top: 8px;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .progress-copy {
        width: 100%;
        margin-left: 0;
        justify-content: space-between;
    }

    .segmented,
    .segmented button {
        width: 100%;
    }

    .actions button {
        flex: 1 1 120px;
    }
}
