:root {
  --bg: #f6f7f9; --surface: #fff; --text: #1b1f24; --muted: #5f6873; --line: #e2e5ea;
  --accent: #2f5bd3; --accent-ink: #fff; --ok: #1f7a4d; --ok-bg: #e5f4ec; --warn: #9a5b00; --warn-bg: #fff3dc;
  --bad: #b3261e; --bad-bg: #fde8e6; --code: #f0f2f5; --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --surface: #1a1e24; --text: #e7eaee; --muted: #9aa3ad; --line: #2c323a;
    --accent: #7b9cff; --accent-ink: #0c1020; --ok: #6fd3a0; --ok-bg: #133325; --warn: #f0b75c; --warn-bg: #3a2b10;
    --bad: #ff8a80; --bad-bg: #3d1a18; --code: #242a32;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.75rem; line-height: 1.25; margin: .6em 0 .5em; }
h2 { font-size: 1.25rem; margin: 0 0 .6em; }
h3 { font-size: 1.05rem; margin: 1.2em 0 .5em; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .92em; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-bottom: 48px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-inner { 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; font-size: 1.1rem; }
.nav { display: flex; gap: 4px 14px; align-items: center; flex-wrap: wrap; }
.nav a, .nav .linklike { color: var(--muted); text-decoration: none; padding: 6px 2px; }
.nav a.active, .nav a:hover, .nav .linklike:hover { color: var(--text); }
.nav a.active { box-shadow: inset 0 -2px 0 var(--accent); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin: 0 0 16px; }
.card.narrow { max-width: 440px; margin: 32px auto; }
details.card > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.course-card { display: block; text-decoration: none; color: var(--text); }
.course-card:hover { border-color: var(--accent); }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.title-row h1, .title-row h2 { margin-bottom: .4em; }
.crumbs { color: var(--muted); font-size: .92rem; margin: 18px 0 0; }
.crumbs a { color: var(--muted); }
.lead { font-size: 1.08rem; color: var(--muted); margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.nowrap { white-space: nowrap; }
.note { background: var(--warn-bg); color: var(--text); border-radius: var(--radius); padding: 10px 14px; }

.flash { border-radius: var(--radius); padding: 10px 14px; margin: 16px 0; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--bad-bg); color: var(--bad); }

.btn { display: inline-block; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 8px;
  padding: 8px 14px; font: inherit; cursor: pointer; text-decoration: none; line-height: 1.3; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn:disabled { opacity: .6; cursor: wait; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.linklike.danger { color: var(--bad); }
.icon-btn { background: none; border: 1px solid var(--line); border-radius: 6px; color: var(--text); cursor: pointer; width: 30px; height: 28px; }
.icon-btn:disabled { opacity: .3; cursor: default; }
form.inline { display: inline; }

.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-weight: 500; }
.form label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.form .row { display: flex; gap: 14px; flex-wrap: wrap; align-items: end; }
.form .row > label { flex: 1 1 200px; }
.table td.pick { width: 28px; }
.bulk-bar { border-top: 1px solid var(--line); padding-top: 12px; }
.bulk-bar label { display: flex; gap: 8px; align-items: center; font-weight: 500; white-space: nowrap; }
.listing { margin: 0 0 14px; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.inline-form input[type=text], .inline-form input:not([type]) { flex: 1 1 220px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
input[type=checkbox], input[type=radio] { width: auto; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.copy { width: 100%; max-width: 560px; }
.big { font-size: 1.3rem; letter-spacing: .08em; }
.danger-zone { border-top: 1px dashed var(--line); padding-top: 14px; margin-top: 8px; }

.badge { display: inline-block; font-size: .78rem; padding: 2px 8px; border-radius: 999px; background: var(--code); color: var(--muted); vertical-align: middle; white-space: nowrap; }
.badge.ok, .st-graded, .vis-public { background: var(--ok-bg); color: var(--ok); }
.st-submitted, .vis-members { background: var(--warn-bg); color: var(--warn); }
.st-returned { background: var(--bad-bg); color: var(--bad); }

.lesson-list { list-style: none; padding: 0; margin: 16px 0; }
.lesson-list li { display: flex; gap: 14px; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 8px; }
.lesson-list li > div { flex: 1; min-width: 0; }
.lesson-list .num { color: var(--muted); min-width: 1.6em; font-variant-numeric: tabular-nums; }
.lesson-list .lesson-title { font-weight: 600; }
.lesson-list li.locked .lesson-title { color: var(--muted); }
.rows { list-style: none; padding: 0; margin: 0; }
.rows li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; }
.rows li:last-child { border-bottom: 0; }
.files { padding-left: 20px; margin: 8px 0 0; }
.files li { margin: 4px 0; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .85rem; color: var(--muted); font-weight: 600; }
.table td.num { color: var(--muted); width: 2.5em; }
.card .table { margin: 0 -8px; width: calc(100% + 16px); }
@media (max-width: 640px) {
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }
  .table tr { border-bottom: 1px solid var(--line); padding: 6px 0; }
  .table td { border: 0; padding: 3px 8px; }
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--text); margin: 0; }
.stat-num { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
progress { width: 100%; height: 8px; accent-color: var(--accent); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); border: 1px solid var(--line); }
.tabs a.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.video { margin: 0 0 16px; }
.video iframe, .video video { width: 100%; aspect-ratio: 16 / 9; border: 0; border-radius: var(--radius); background: #000; display: block; }

.prose { overflow-wrap: anywhere; }
.prose img { max-width: 100%; height: auto; }
.prose pre { background: var(--code); padding: 12px; border-radius: 8px; overflow-x: auto; }
.prose code { background: var(--code); padding: 1px 5px; border-radius: 4px; }
.prose pre code { background: none; padding: 0; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 8px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.answer { background: var(--code); padding: 12px; border-radius: 8px; margin: 8px 0; }
.feedback { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; margin: 10px 0; }
.score { font-size: 1.15rem; }

.quiz { padding-left: 1.4em; }
.quiz > li { margin-bottom: 14px; }
.quiz .q { font-weight: 600; margin-top: 0; }
.option { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; cursor: pointer; }
.option:hover { border-color: var(--accent); }
.option input { margin-top: .3em; }
.options { list-style: none; padding: 0; }
.options li { padding: 6px 10px; border-radius: 8px; margin: 4px 0; }
.options li.correct { background: var(--ok-bg); color: var(--ok); }
.options li.chosen-wrong { background: var(--bad-bg); color: var(--bad); }
.quiz li.right { border-left: 4px solid var(--ok); }
.quiz li.wrong { border-left: 4px solid var(--bad); }
.explain { color: var(--muted); font-size: .94rem; margin-bottom: 0; }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
.footer { padding: 24px 16px 32px; font-size: .85rem; }
