:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #64748b;
    --line: #dbe4f0;
    --brand: #2557d6;
    --brand-dark: #173fa6;
    --accent: #15a66a;
    --warn: #b45309;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.landing { min-height: 100vh; display: grid; place-items: center; padding: 2rem; background: radial-gradient(circle at top left, #dbeafe, transparent 35%), var(--bg); }
.hero, .auth-card, .doc-card { max-width: 760px; background: var(--panel); padding: 2.5rem; border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 24px 80px rgba(23, 32, 51, 0.12); }
.hero h1 { font-size: clamp(2.4rem, 7vw, 5rem); line-height: 0.95; margin: 0.4rem 0 1rem; }
.hero p, .auth-card p, .doc-card p { color: var(--muted); font-size: 1.05rem; line-height: 1.65; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.16em; font-weight: 800; color: var(--brand); font-size: 0.78rem; }
.hero-actions { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: 1.5rem; }
.button { border: 0; border-radius: 999px; padding: 0.85rem 1.2rem; font-weight: 800; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.primary { background: var(--brand); color: white; }
.primary:hover { background: var(--brand-dark); text-decoration: none; }
.ghost { background: #eef4ff; color: var(--brand); }
.small { font-size: 0.9rem; }
.alert { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; padding: 0.8rem; border-radius: 12px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 310px minmax(0, 1fr); grid-template-rows: 64px 1fr; }
.dashboard-shell { grid-template-columns: 1fr; }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; padding: 0 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 3; }
.brand { color: var(--ink); font-weight: 900; font-size: 1.1rem; }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.link-button { border: 0; background: transparent; color: var(--brand); font: inherit; cursor: pointer; padding: 0; }

.sidebar { background: #101828; color: #e2e8f0; padding: 1rem; overflow: auto; }
.sidebar h2 { font-size: 0.9rem; letter-spacing: 0.08em; text-transform: uppercase; color: #93c5fd; }
.sidebar-classes { margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-classes h3 { font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: #93c5fd; margin: 0 0 0.5rem; }
.sidebar-muted { color: #94a3b8; font-size: 0.85rem; margin: 0.35rem 0 0; }
.sidebar-class-list { list-style: none; padding: 0; margin: 0.35rem 0 0.75rem; }
.sidebar-class-list li { padding: 0.25rem 0; }
.sidebar-join { display: flex; gap: 0.45rem; margin-top: 0.5rem; }
.sidebar-join input { flex: 1; min-width: 0; width: auto; padding: 0.55rem 0.65rem; border-radius: 8px; border: 1px solid rgba(255,255,255,0.15); background: rgba(0,0,0,0.25); color: white; font-weight: 700; letter-spacing: 0.08em; }
.sidebar-join input::placeholder { color: #64748b; font-weight: 500; letter-spacing: normal; }
.sidebar-join-button { width: auto; padding: 0.55rem 0.85rem; font-size: 0.85rem; background: var(--brand); color: white; }
.sidebar-join-status { margin-top: 0.45rem; }
.unit { border-bottom: 1px solid rgba(255,255,255,0.1); padding: 0.5rem 0; }
.unit summary { cursor: pointer; font-weight: 800; }
.lesson-link { display: block; margin: 0.35rem 0 0.35rem 1rem; color: #cbd5e1; border-radius: 8px; padding: 0.45rem 0.55rem; }
.lesson-link.active, .lesson-link:hover { background: rgba(255,255,255,0.1); color: white; text-decoration: none; }
.progress-dot { float: right; opacity: 0.8; }

.content-panel { padding: clamp(1rem, 3vw, 2.5rem); overflow: auto; }
.wide { max-width: 1180px; width: 100%; margin: 0 auto; }
.lesson-card, .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: clamp(1rem, 3vw, 2rem); margin-bottom: 1rem; box-shadow: 0 10px 30px rgba(23, 32, 51, 0.06); }
.lesson-card h1 { font-size: clamp(2rem, 5vw, 3.2rem); margin: 0.3rem 0 1rem; }
.meta { color: var(--muted); font-weight: 700; }
.expectations { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 1rem 0; }
.badge { border-radius: 999px; background: #e0ecff; color: #173fa6; padding: 0.28rem 0.55rem; font-weight: 800; font-size: 0.8rem; }
.lesson-body { line-height: 1.7; }
.lesson-body pre { background: #0f172a; color: #e2e8f0; padding: 1rem; border-radius: 14px; overflow: auto; }
.lesson-body code { font-family: "Cascadia Code", Consolas, monospace; }
.video-frame { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: 18px; background: #0f172a; margin: 1rem 0; }
.action-row { display: flex; flex-wrap: wrap; gap: 0.75rem; margin: 1rem 0; }
.panel h2 { margin-top: 0; }
textarea, input, select { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 0.8rem; font: inherit; background: white; }
textarea.code { min-height: 220px; font-family: "Cascadia Code", Consolas, monospace; tab-size: 4; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.table { width: 100%; border-collapse: collapse; background: white; border-radius: 12px; overflow: hidden; }
.table th, .table td { border-bottom: 1px solid var(--line); text-align: left; padding: 0.75rem; }
.empty { color: var(--muted); padding: 1rem; border: 1px dashed var(--line); border-radius: 14px; }

.muted { color: var(--muted); }

.practice .editor-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 0.4rem; }
.file-chip { font-family: "Cascadia Code", Consolas, monospace; font-weight: 800; background: #eef4ff; color: var(--brand-dark); border-radius: 8px; padding: 0.2rem 0.55rem; }
.code-input { min-height: 220px; }
.upload-label { position: relative; }

.practice-results { margin-top: 1rem; }
.result-summary { font-weight: 800; padding: 0.7rem 0.9rem; border-radius: 12px; }
.status-pass { background: #e7f8ef; color: #0f7a4d; border: 1px solid #b6e6cd; }
.status-fail { background: #fef2f2; color: #b91c1c; border: 1px solid #f6c9c9; }
.status-error { background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; }

.test-list { list-style: none; margin: 0.75rem 0 0; padding: 0; display: grid; gap: 0.4rem; }
.test-row { display: grid; grid-template-columns: 1.4rem 1fr; align-items: start; gap: 0.5rem; padding: 0.5rem 0.65rem; border: 1px solid var(--line); border-radius: 10px; background: white; }
.test-row .test-mark { font-weight: 900; }
.test-row.pass .test-mark { color: var(--accent); }
.test-row.fail .test-mark { color: #b91c1c; }
.test-row.skip .test-mark { color: var(--muted); }
.test-feedback { min-width: 0; }
.test-feedback-pass, .test-feedback-skip { margin: 0; }
.test-feedback-fail strong { display: block; margin-bottom: 0.35rem; }
.test-feedback-line { margin: 0.25rem 0 0; line-height: 1.5; }
.test-feedback-key { display: inline-block; min-width: 9.5rem; color: var(--muted); font-weight: 700; font-size: 0.9rem; }
.test-feedback-line code { font-family: "Cascadia Code", Consolas, monospace; background: #f8fafc; border: 1px solid var(--line); border-radius: 6px; padding: 0.1rem 0.35rem; }

/* Teacher test-authoring UI */
.authoring-title { margin: 0 0 1rem; }
.authoring-layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 1rem; align-items: start; }
.authoring-tree { position: sticky; top: 80px; max-height: calc(100vh - 110px); overflow: auto; }
.authoring-tree h2 { margin-top: 0; font-size: 1rem; }
.authoring-main { min-width: 0; }

.tree-unit { border-bottom: 1px solid var(--line); padding: 0.4rem 0; }
.tree-unit summary { cursor: pointer; font-weight: 800; padding: 0.3rem 0; }
.tree-lesson { margin: 0.4rem 0 0.6rem 0.5rem; }
.tree-lesson-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.tree-lesson-title { font-weight: 700; font-size: 0.92rem; }
.tree-empty { color: var(--muted); font-size: 0.85rem; margin: 0.25rem 0 0.25rem 0.5rem; }
.tree-exercise { display: flex; flex-direction: column; gap: 0.15rem; width: 100%; text-align: left; border: 1px solid var(--line); background: white; border-radius: 10px; padding: 0.5rem 0.65rem; margin: 0.35rem 0; cursor: pointer; }
.tree-exercise:hover { border-color: var(--brand); }
.tree-exercise.active { border-color: var(--brand); background: #eef4ff; }
.tree-exercise-title { font-weight: 700; }
.tree-meta { display: flex; gap: 0.4rem; color: var(--muted); font-size: 0.8rem; }
.tree-tag { background: #fef3c7; color: #92400e; border-radius: 999px; padding: 0 0.45rem; font-weight: 700; }

.field-label { display: block; font-weight: 700; margin: 0.75rem 0 0.25rem; }
.field-label input, .field-label select, .field-label textarea { font-weight: 400; margin-top: 0.3rem; }
.field-label .hint { display: block; font-weight: 400; color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; }
.code-mini { min-height: 90px; font-family: "Cascadia Code", Consolas, monospace; tab-size: 4; }
.check { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 700; }
.check input { width: auto; }

.case-card { border: 1px solid var(--line); border-radius: 14px; padding: 0.9rem 1rem; margin: 0.75rem 0; background: #fbfdff; }
.case-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.case-num { font-weight: 800; color: var(--brand-dark); font-size: 0.85rem; white-space: nowrap; }
.case-card-head .case-label { flex: 1 1 180px; min-width: 0; }
.case-card-head .case-mode { flex: 0 0 210px; width: auto; }
.case-card-actions { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-left: auto; }
.case-mode-hint { margin: 0.35rem 0 0.75rem; padding: 0.55rem 0.75rem; background: #eef4ff; border-radius: 10px; color: #334155; font-size: 0.88rem; line-height: 1.5; }
.case-mode-hint code { font-family: "Cascadia Code", Consolas, monospace; background: white; padding: 0.05rem 0.25rem; border-radius: 4px; }
.case-footnote { margin: 0.5rem 0 0; color: var(--muted); font-size: 0.85rem; }
.case-help { background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; padding: 0.75rem 1rem; margin-bottom: 0.75rem; font-size: 0.92rem; line-height: 1.55; }
.case-help ul { margin: 0.4rem 0 0 1.2rem; padding: 0; }
.case-help li { margin: 0.25rem 0; }
.case-pair-row {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.45rem 0.55rem;
    padding: 0.65rem 0.75rem; background: white; border: 1px solid var(--line); border-radius: 12px;
}
.pair-field { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.pair-field-grow { flex: 1 1 120px; }
.pair-key { font-size: 0.78rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.pair-field input { width: 100%; margin: 0; }
.pair-punct { font-weight: 800; color: var(--muted); padding-bottom: 0.55rem; font-size: 1.1rem; }
.pair-arrow { font-weight: 900; color: var(--brand); padding-bottom: 0.55rem; font-size: 1.2rem; }
.case-io-options { margin-top: 0.65rem; }
.io-extra { margin-top: 0.5rem; }
.btn-mini { padding: 0.35rem 0.6rem; font-size: 0.8rem; }
.button.danger, .btn-mini.danger { background: #fef2f2; color: #b91c1c; }
.io-inputs { display: grid; gap: 0.4rem; margin: 0.4rem 0; }
.io-input-row { display: flex; align-items: center; gap: 0.5rem; }
.io-input-num { flex: 0 0 1.5rem; height: 1.5rem; display: grid; place-items: center; background: #eef4ff; color: var(--brand-dark); border-radius: 6px; font-weight: 800; font-size: 0.8rem; }
.io-input-row .case-input { flex: 1; }

/* Rich text editor (teacher authoring) */
.rte-mount { margin-top: 0.35rem; }
.rte { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: white; }
.rte-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem;
    padding: 0.45rem 0.55rem; background: #1e293b; border-bottom: 1px solid #0f172a;
}
.rte-block {
    width: auto; min-width: 7.5rem; padding: 0.35rem 0.5rem; border-radius: 6px;
    border: 1px solid #334155; background: #0f172a; color: #e2e8f0; font-size: 0.85rem;
}
.rte-btn {
    border: 0; background: transparent; color: #e2e8f0; border-radius: 6px;
    padding: 0.35rem 0.55rem; font-size: 0.85rem; cursor: pointer; line-height: 1.2;
}
.rte-btn:hover { background: rgba(255,255,255,0.12); }
.rte-sep { width: 1px; height: 1.4rem; background: #475569; margin: 0 0.15rem; }
.rte-body {
    min-height: 140px; max-height: 320px; overflow: auto; padding: 0.85rem 1rem;
    line-height: 1.65; outline: none;
}
.rte-body:empty::before {
    content: attr(data-placeholder);
    color: var(--muted);
    pointer-events: none;
}
.rte-body h1 { font-size: 1.5rem; margin: 0.6rem 0 0.4rem; }
.rte-body h2 { font-size: 1.25rem; margin: 0.55rem 0 0.35rem; }
.rte-body h3 { font-size: 1.05rem; margin: 0.5rem 0 0.3rem; }
.rte-body ul, .rte-body ol { margin: 0.4rem 0 0.6rem 1.4rem; }
.rte-body table { border-collapse: collapse; width: 100%; margin: 0.5rem 0; }
.rte-body th, .rte-body td { border: 1px solid var(--line); padding: 0.4rem 0.55rem; }
.rte-body code { font-family: "Cascadia Code", Consolas, monospace; background: #f1f5f9; padding: 0.1rem 0.3rem; border-radius: 4px; }
.rte-body a { color: var(--brand); }

/* Student-facing exercise instructions (HTML from rich text) */
.panel.practice .instructions-body,
.panel.practice .instructions-body h1,
.panel.practice .instructions-body h2,
.panel.practice .instructions-body h3 { margin-top: 0.5rem; }
.panel.practice .instructions-body ul,
.panel.practice .instructions-body ol { margin: 0.4rem 0 0.6rem 1.4rem; }
.panel.practice .instructions-body table { border-collapse: collapse; width: 100%; margin: 0.5rem 0; }
.panel.practice .instructions-body th,
.panel.practice .instructions-body td { border: 1px solid var(--line); padding: 0.4rem 0.55rem; }
.panel.practice .instructions-body code { font-family: "Cascadia Code", Consolas, monospace; background: #f1f5f9; padding: 0.1rem 0.3rem; border-radius: 4px; }

@media (max-width: 980px) {
    .authoring-layout { grid-template-columns: 1fr; }
    .authoring-tree { position: static; max-height: none; }
}

@media (max-width: 820px) {
    .app-shell { grid-template-columns: 1fr; grid-template-rows: 64px auto 1fr; }
    .sidebar { max-height: 45vh; }
}
