:root {
    --bg: #fbfaf7;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #5d6573;
    --border: #dcdfe4;
    --accent: #1f5fae;
    --accent-text: #ffffff;
    --accent-soft: #e7eef8;
    --focus: #f0a400;
    --radius: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171c;
        --surface: #1d2128;
        --text: #e7e9ee;
        --muted: #a1a8b5;
        --border: #343a45;
        --accent: #7fb0ef;
        --accent-text: #0e1726;
        --accent-soft: #223249;
        color-scheme: dark;
    }
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
    color: var(--accent);
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

h1, h2, h3 {
    line-height: 1.25;
}

h1 {
    font-size: 2rem;
    margin: 0.4em 0 0.3em;
}

h2 {
    font-size: 1.4rem;
    margin-top: 2em;
}

h3 {
    font-size: 1.1rem;
}

.container {
    max-width: 920px;
    margin: 0 auto;
    padding: 0 16px;
}

.muted {
    color: var(--muted);
    font-weight: normal;
}

.lead {
    font-size: 1.15rem;
    color: var(--muted);
}

.eyebrow {
    margin: 0;
    color: var(--muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.note {
    color: var(--muted);
    border-left: 3px solid var(--border);
    padding-left: 12px;
}

/* Prototype banner */

.prototype-banner {
    background: var(--accent-soft);
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
    padding: 8px 0;
}

.prototype-banner a {
    font-weight: 600;
}

/* Header / footer */

.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.site-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 56px;
    flex-wrap: wrap;
}

.brand {
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}

.site-header nav {
    display: flex;
    gap: 20px;
}

.site-header nav a {
    text-decoration: none;
}

.site-header nav a[aria-current="page"] {
    font-weight: 700;
}

.site-footer {
    margin-top: 64px;
    padding-bottom: 32px;
    color: var(--muted);
    font-size: 0.9rem;
}

/* Buttons */

.button {
    display: inline-block;
    padding: 10px 18px;
    border: 2px solid var(--accent);
    border-radius: 8px;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

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

.button.small {
    padding: 5px 12px;
    font-size: 0.9rem;
}

.button[aria-pressed="true"] {
    background: var(--accent);
    color: var(--accent-text);
}

.button:disabled {
    opacity: 0.4;
    cursor: default;
}

.button[hidden] {
    display: none;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

/* Cards and lists */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    margin: 24px 0;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

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

.card-list {
    list-style: none;
    padding: 0;
    display: grid;
    gap: 14px;
}

.topic-list {
    list-style: none;
    padding: 0;
}

.topic-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.topic-list li p {
    margin: 4px 0 0;
    color: var(--muted);
}

.topic-list.compact li {
    padding: 6px 0;
}

/* Doenet embeds */

.embed {
    width: 100%;
    min-height: 300px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    overflow: hidden;
}

.embed iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

/* Diagnostic */

.runner-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.dots {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0;
    margin: 0;
}

.dot {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.dot.answered {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.dot[aria-current="step"] {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-text);
}

.status {
    margin: 12px 0;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.status p {
    margin: 4px 0;
}

.runner-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: space-between;
}

/* Results */

.save-box {
    background: var(--accent-soft);
    border-radius: var(--radius);
    padding: 4px 20px 16px;
}

.save-box h2 {
    margin-top: 0.8em;
}

.results-link {
    font-size: 0.85rem;
    word-break: break-all;
}

/* Topic page */

.breadcrumbs {
    margin: 20px 0 0;
}

.practice-list {
    padding: 0;
    list-style: none;
}

.practice-list li {
    margin: 24px 0;
}

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

.video {
    aspect-ratio: 16 / 9;
}

.video iframe {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: var(--radius);
}

figure {
    margin: 0;
}

figcaption {
    color: var(--muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

.placeholder {
    color: var(--muted);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
}

.pager {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-top: 48px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* Print: results page is the main thing students print */

@media print {
    :root {
        --bg: #fff;
        --surface: #fff;
        --text: #000;
        --muted: #333;
        --accent: #000;
        --accent-soft: #fff;
    }

    .site-header nav,
    .no-print,
    .card .button {
        display: none !important;
    }

    .card {
        break-inside: avoid;
    }

    .save-box {
        border: 1px solid #999;
    }
}

/* Problem library */

.container.wide {
    max-width: 1440px;
}

.library {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 28px;
    align-items: start;
    padding-top: 16px;
}

.lib-sidebar {
    position: sticky;
    top: 0;
    max-height: 100vh;
    overflow-y: auto;
    padding: 4px 4px 24px 0;
}

.lib-title {
    font-size: 1.4rem;
    margin: 0.3em 0 0.8em;
}

.lib-sidebar label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 4px;
}

.lib-sidebar select {
    width: 100%;
    font: inherit;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    margin-bottom: 16px;
}

.chapter {
    border-bottom: 1px solid var(--border);
}

.chapter summary {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    padding: 9px 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
}

.chapter ul {
    list-style: none;
    margin: 0 0 8px;
    padding: 0;
}

.chapter li a {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 8px 6px 18px;
    border-radius: 6px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.92rem;
}

.chapter li a:hover {
    background: var(--accent-soft);
}

.chapter li a[aria-current] {
    background: var(--accent);
    color: var(--accent-text);
}

.count {
    flex-shrink: 0;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: normal;
}

.chapter li a[aria-current] .count {
    color: inherit;
}

.lib-section h2 {
    margin-top: 0.2em;
}

.problem-list {
    list-style: none;
    padding: 0;
    display: grid;
    gap: 10px;
}

.problem-list a {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 12px;
    row-gap: 4px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    text-decoration: none;
}

.problem-list a:hover {
    border-color: var(--accent);
}

.problem-list a[aria-current] {
    border-color: var(--accent);
    box-shadow: inset 4px 0 0 var(--accent);
}

.problem-number {
    font-weight: 700;
    color: var(--accent);
}

.problem-title {
    font-weight: 600;
}

.problem-about,
.problem-meta {
    grid-column: 2;
    color: var(--muted);
    font-size: 0.9rem;
    white-space: pre-line;
}

.problem-meta {
    font-size: 0.8rem;
}

.lib-preview {
    background: var(--bg);
}

.preview-head {
    padding-bottom: 12px;
}

.preview-head h2 {
    margin: 0.2em 0 0.5em;
    font-size: 1.25rem;
}

#preview-close {
    float: right;
}

.preview-about {
    color: var(--muted);
    font-size: 0.92rem;
    white-space: pre-line;
}

/* Wide screens: tree | list | preview side by side */
@media (min-width: 1100px) {
    body.preview-open .library {
        grid-template-columns: 280px minmax(280px, 0.8fr) minmax(460px, 1.3fr);
    }

    body.preview-open .problem-about {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .lib-preview {
        position: sticky;
        top: 0;
        max-height: 100vh;
        overflow-y: auto;
        padding: 4px 4px 24px 20px;
        border-left: 1px solid var(--border);
    }
}

/* Narrower screens: preview opens as an overlay */
@media (max-width: 1099px) {
    .lib-preview {
        position: fixed;
        inset: 0;
        z-index: 50;
        overflow-y: auto;
        padding: 16px;
    }

    body.preview-open {
        overflow: hidden;
    }
}

@media (max-width: 799px) {
    .library {
        grid-template-columns: minmax(0, 1fr);
    }

    .lib-sidebar {
        position: static;
        max-height: none;
    }
}
