* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html, body {
    max-width: 100%;
    overflow-x: hidden;
}

:root {
    --paper: #FBFAF6;
    --teal: #0F6D5C;
    --teal-dark: #0B5347;
    --coral: #F4633A;
    --coral-dark: #DA4B23;
    --amber: #FDE68A;
    --amber-ink: #78350F;
    --ink: #2A2622;
    --ink-soft: #5C564C;
    --border: #E4DFD3;
    --font-display: "Space Grotesk", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-body: "Source Serif 4", Georgia, "Times New Roman", serif;
}

body {
    font-family: var(--font-display);
    margin: 0;
    padding: 0;
    background: var(--paper);
    color: var(--ink);
    line-height: 1.5;
}

.site-header {
    background: var(--teal);
    color: white;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
}

.site-title {
    color: white;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.01em;
}

.site-subtitle {
    color: #9FD9CC;
    font-size: 0.85rem;
}

.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 1.5rem 1.25rem 3rem;
}

h1 {
    font-family: var(--font-display);
    font-size: 1.7rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 0.25rem;
    color: var(--teal-dark);
}

h2 {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 1.75rem;
    margin-bottom: 0.5rem;
    color: var(--teal-dark);
}

.subtitle, .meta {
    color: var(--ink-soft);
    margin-top: 0;
}

.hint {
    color: var(--ink-soft);
    font-size: 0.85rem;
}

form {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 1rem;
}

label {
    font-weight: 600;
    font-size: 0.9rem;
    margin-top: 0.75rem;
}

input[type="text"], input[type="file"], select, textarea {
    font-size: 1rem;
    padding: 0.6rem;
    border: 1px solid var(--border);
    background: white;
    color: var(--ink);
    border-radius: 6px;
    width: 100%;
    font-family: var(--font-display);
}

input[type="text"]:focus, input[type="file"]:focus, select:focus, textarea:focus {
    outline: 2px solid var(--teal);
    outline-offset: 1px;
}

textarea {
    resize: vertical;
    font-family: var(--font-body);
}

button {
    margin-top: 1.25rem;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-display);
    background: var(--coral);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    width: 100%;
    transition: background-color 0.15s ease;
}

button:hover {
    background: var(--coral-dark);
}

button:focus-visible {
    outline: 3px solid var(--teal);
    outline-offset: 2px;
}

.rating-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.25rem;
}

.connections-panel, .future-panel {
    background: #EAF5F2;
    border-left: 4px solid var(--teal);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-top: 1rem;
}

.lesson-content {
    margin-top: 1.5rem;
}

.lesson-text {
    background: white;
    border: 1px solid var(--border);
    border-top: 5px solid var(--teal);
    border-radius: 8px;
    padding: 1.5rem;
    font-family: var(--font-body);
    font-size: 1.05rem;
    overflow-wrap: anywhere;
}

.lesson-text p {
    margin: 0 0 1.1rem 0;
}

.lesson-text p:last-child {
    margin-bottom: 0;
}

.keyword {
    background: var(--amber);
    color: var(--amber-ink);
    font-weight: 600;
    padding: 0.05em 0.3em;
    border-radius: 4px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.difficulty-dots {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.difficulty-dots .dot {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--border);
    display: inline-block;
}

.difficulty-dots .dot.filled {
    background: var(--coral);
}

.cost-note {
    color: var(--ink-soft);
    font-size: 0.85rem;
    margin-top: 1rem;
}

.error-box {
    background: #FDECEA;
    border-left: 4px solid #C0392B;
    padding: 1rem 1.25rem;
    border-radius: 6px;
}

.thank-you-box {
    text-align: center;
    padding: 2rem 1rem;
}

@media (min-width: 600px) {
    .rating-grid {
        grid-template-columns: 1fr 1fr;
        align-items: center;
        column-gap: 1rem;
    }
}

.quiz-panel {
    margin-top: 1.5rem;
}

.quiz-form {
    background: white;
    border: 1px solid var(--border);
    border-top: 5px solid var(--coral);
    border-radius: 8px;
    padding: 1.25rem;
    gap: 0.6rem;
}

.quiz-question {
    font-weight: 600;
    margin: 0 0 0.75rem 0;
    overflow-wrap: anywhere;
}

.quiz-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 400;
    margin-top: 0.4rem;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}

.quiz-option:has(input:checked) {
    border-color: var(--teal);
    background: #EAF5F2;
}

.quiz-result-box {
    max-width: 720px;
    margin: 0 auto;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
}

.quiz-correct {
    border-top: 5px solid var(--teal);
}

.quiz-correct h1 {
    color: var(--teal-dark);
}

.quiz-incorrect {
    border-top: 5px solid var(--coral);
}

.quiz-incorrect h1 {
    color: var(--coral-dark);
}

.quiz-review-options {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}

.quiz-review-options li {
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    margin-bottom: 0.4rem;
    border: 1px solid var(--border);
    overflow-wrap: anywhere;
}

.quiz-review-correct {
    background: #EAF5F2;
    border-color: var(--teal) !important;
    font-weight: 600;
    color: var(--teal-dark);
}

.quiz-review-selected {
    border-color: var(--coral) !important;
}

.quiz-explanation {
    color: var(--ink-soft);
    overflow-wrap: anywhere;
}

:root[data-theme="dark"] {
    --paper: #16211D;
    --ink: #EDEAE2;
    --ink-soft: #B8B3A8;
    --border: #2E3A34;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --paper: #16211D;
        --ink: #EDEAE2;
        --ink-soft: #B8B3A8;
        --border: #2E3A34;
    }
}

:root[data-theme="dark"] .lesson-text,
:root[data-theme="dark"] .quiz-form,
:root[data-theme="dark"] .quiz-result-box,
:root[data-theme="dark"] .glossary-panel {
    background: #1D2B25;
}

:root[data-theme="dark"] .connections-panel,
:root[data-theme="dark"] .future-panel {
    background: #16332C;
}

.quiz-result-inline {
    margin-top: 1rem;
}

.quiz-result-inline .quiz-result-box {
    max-width: none;
    margin: 0;
}

.theme-toggle {
    margin-left: auto;
    background: transparent;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    width: auto;
    margin-top: 0;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 6px;
}

body.study-page .container {
    max-width: min(1680px, 96vw);
}

.landing {
    max-width: 480px;
    margin: 3rem auto 0;
    text-align: center;
}

.landing-form {
    text-align: left;
}

.study-shell {
    display: grid;
    grid-template-columns: 240px 1fr 260px;
    gap: 1.25rem;
    align-items: start;
}

.syllabus {
    background: linear-gradient(180deg, var(--teal), var(--teal-dark));
    border-radius: 12px;
    padding: 1rem 0.75rem;
    box-shadow: 3px 0 14px rgba(11, 83, 71, 0.18);
    position: sticky;
    top: 1rem;
}

.syllabus-name-field {
    margin-bottom: 1rem;
}

.syllabus-name-field label {
    color: #B9E3D8;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 0;
}

.syllabus-name-field input {
    margin-top: 0.3rem;
}

.syllabus-area-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: transparent;
    border: none;
    padding: 0.5rem 0.4rem;
    margin: 0.25rem 0 0 0;
    cursor: pointer;
    text-align: left;
}

.syllabus-area-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
}

.syllabus-area-title {
    color: #B9E3D8;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}

.syllabus-area-chevron {
    color: #B9E3D8;
    font-size: 0.7rem;
    transition: transform 0.15s ease;
}

.syllabus-area.expanded .syllabus-area-chevron {
    transform: rotate(90deg);
}

.syllabus-area-topics {
    display: none;
}

.syllabus-area.expanded .syllabus-area-topics {
    display: block;
}

.syllabus-topic-link {
    display: block;
    color: #D7F0E9;
    text-decoration: none;
    font-size: 0.85rem;
    padding: 0.4rem 0.6rem;
    border-radius: 20px;
    margin: 0.15rem 0;
}

.syllabus-topic-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

.syllabus-topic-link.active {
    background: var(--coral);
    color: white;
    font-weight: 700;
    box-shadow: 0 3px 10px rgba(244, 99, 58, 0.4);
}

.study-main {
    min-width: 0;
}

.glossary-panel {
    background: white;
    border-radius: 12px;
    padding: 1rem;
    box-shadow: 0 6px 20px rgba(15, 109, 92, 0.1);
    position: sticky;
    top: 1rem;
}

.glossary-term {
    border-left: 4px solid var(--teal);
    border-radius: 6px;
    padding: 0.5rem 0.65rem;
    margin-bottom: 0.75rem;
    background: var(--paper);
}

.glossary-term:has(.glossary-term-contrast) {
    border-left-color: var(--coral);
}

.glossary-term-name {
    font-weight: 700;
    display: block;
    margin-bottom: 0.2rem;
}

.glossary-term-definition {
    margin: 0;
    font-size: 0.85rem;
    color: var(--ink-soft);
    overflow-wrap: anywhere;
}

.glossary-term-contrast {
    margin: 0.3rem 0 0 0;
    font-size: 0.8rem;
    font-style: italic;
    color: var(--coral-dark);
    overflow-wrap: anywhere;
}

.difficulty-dots {
    background: rgba(244, 99, 58, 0.12);
    padding: 0.15rem 0.5rem;
    border-radius: 20px;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
}

@media (max-width: 900px) {
    .container {
        padding: 1rem 1rem 1.5rem;
    }

    .study-shell {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .syllabus, .glossary-panel {
        position: static;
    }

    /* Lesson content is why someone opened this page -- show it first and
       let the syllabus tree (often a dozen+ topics once its active area is
       expanded) and glossary follow below, instead of forcing a long scroll
       past navigation before reaching any content. Visual order only: DOM
       order (and therefore tab order) is unchanged. */
    .study-main {
        order: -1;
    }

    .empty-state {
        padding: 1.5rem 1rem;
    }

    .syllabus {
        padding: 0.75rem 0.6rem;
    }
}
