/* teachme: calm, document-like (in the spirit of Notion). Soft neutrals, rounded blocks, one blue,
   quiet borders, smooth hover states. Luciole Mono is for code only; everything else is the system sans.
   Layout rule: things that can change (output, step through, results) get reserved space, so clicking never shoves the page. */

@font-face { font-family: "Luciole Mono"; src: url(/fonts/LucioleMono-Regular.ttf) format("truetype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Luciole Mono"; src: url(/fonts/LucioleMono-Bold.ttf) format("truetype"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Luciole Mono"; src: url(/fonts/LucioleMono-Italic.ttf) format("truetype"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Luciole Mono"; src: url(/fonts/LucioleMono-BoldItalic.ttf) format("truetype"); font-weight: 700; font-style: italic; font-display: swap; }

:root {
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
  --mono: "Luciole Mono", ui-monospace, Menlo, monospace;
  --bg: #ffffff;
  --side: #f7f7f5;
  --ink: #37352f;
  --muted: #73726e;
  --faint: #a5a4a0;
  --line: #ebebea;
  --line-strong: #dcdbd8;
  --hover: rgba(55, 53, 47, .06);
  --hover-strong: rgba(55, 53, 47, .1);
  --code-bg: #f7f6f3;
  --code-inline-bg: rgba(135, 131, 120, .14);
  --code-ink: #c4453c;
  --accent: #1d6fc2;
  --btn-primary: #2383e2;
  --btn-primary-hover: #0f6ed3;
  --focus: rgba(35, 131, 226, .28);
  --right: #2e7d4f;
  --wrong: #c4453c;
  --callout: #f7f7f5;
  --note-bg: #f2f7fc;
  --hint-bg: #fbf3db;
  --term-bg: #1e1e1e;
  --term-ink: #e3e1dc;
  --shadow: 0 1px 2px rgba(15, 15, 15, .06), 0 4px 12px rgba(15, 15, 15, .08);
  --hl-kw: #7a3e9d; --hl-str: #2e6b3a; --hl-num: #9a5b00; --hl-com: #75736c; --hl-fn: #1d6fc2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191919; --side: #202020; --ink: #e3e2e0; --muted: #9b9a97; --faint: #5a5a58;
    --line: #2c2c2c; --line-strong: #3a3a3a; --hover: rgba(255, 255, 255, .055); --hover-strong: rgba(255, 255, 255, .09);
    --code-bg: #232323; --code-inline-bg: rgba(135, 131, 120, .18); --code-ink: #ff8a80;
    --accent: #6fb1e6; --btn-primary: #2f7cc7; --btn-primary-hover: #3a89d6; --focus: rgba(82, 156, 202, .35);
    --right: #5fbf8f; --wrong: #ff8a80; --callout: #232323; --note-bg: #1e2732; --hint-bg: #37311c;
    --term-bg: #141414; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 16px rgba(0, 0, 0, .35);
    --hl-kw: #c9a2e6; --hl-str: #9fd4a8; --hl-num: #e8b770; --hl-com: #8f8c85; --hl-fn: #8dc0ee;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) var(--term-w, 40%);
  grid-template-rows: 44px minmax(0, 1fr);
  grid-template-areas: "head head head" "nav main term";
}
body.no-term { grid-template-columns: 220px minmax(0, 1fr) 0; }
body.no-term #term-pane { display: none; }
::selection { background: var(--focus); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus); border-radius: 4px; }
p { margin: 0 0 10px; }
.hint { color: var(--muted); font-size: 13px; }
code, pre, kbd, textarea.mono { font-family: var(--mono); }
code { font-size: .85em; color: var(--code-ink); background: var(--code-inline-bg); padding: .15em .38em; border-radius: 4px; }
pre code { color: inherit; background: none; padding: 0; font-size: inherit; }
kbd { font: 11px var(--mono); color: var(--muted); border: 1px solid var(--line-strong); border-radius: 4px; padding: 0 4px; background: var(--bg); box-shadow: 0 1px 0 var(--line-strong); }
button, a, .step-compact > summary, nav a { transition: background-color .12s ease, color .12s ease, border-color .12s ease, opacity .12s ease; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- header ---------- */
header { grid-area: head; display: flex; align-items: center; gap: 14px; padding: 0 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; background: var(--bg); }
.brand { font-weight: 650; color: var(--ink); padding: 3px 6px; border-radius: 4px; }
.brand:hover { background: var(--hover); text-decoration: none; }
#save-status { color: var(--muted); }
#save-status.busy { color: var(--ink); }
.spacer { flex: 1; }
#conn { font-size: 13px; color: var(--wrong); }
#conn:empty { display: none; }
.keys-wrap { position: relative; }
#keys-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); padding: 8px 4px; min-width: 320px; animation: appear .14s ease-out; }
#keys-pop > div { display: grid; grid-template-columns: 92px 1fr; align-items: center; padding: 5px 12px; font-size: 13px; color: var(--muted); white-space: nowrap; }
#keys-pop .k { display: inline-flex; gap: 3px; align-items: center; }
#keys-pop .l { color: var(--ink); }
@media (prefers-color-scheme: dark) { #keys-pop { background: #252525; border-color: #333; } }
header button.ghost { color: var(--muted); }
header button.ghost:hover { color: var(--ink); }
header button[aria-pressed="true"], header button[aria-expanded="true"] { color: var(--ink); background: var(--hover-strong); }

/* ---------- sidebar ---------- */
nav { grid-area: nav; overflow-y: auto; padding: 14px 8px; background: var(--side); border-right: 1px solid var(--line); font-size: 14px; }
nav a { display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 4px; color: var(--ink); min-height: 28px; }
nav a:hover { background: var(--hover); text-decoration: none; }
nav a.active { font-weight: 600; }
nav .num { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.nav-ex { margin-top: 12px; }
nav a.nav-part { padding-left: 30px; color: var(--muted); }
nav a.nav-part:hover { color: var(--ink); }
nav a.nav-part.on { color: var(--ink); background: var(--hover-strong); font-weight: 500; }
.mark { font-family: var(--mono); font-size: 12px; width: 1.1em; text-align: center; flex: none; color: var(--muted); }
.mark.started { color: var(--ink); }
.mark.submitted { color: var(--accent); }
.mark.reviewed { color: var(--right); }
.badge-new { font-size: 11.5px; font-weight: 500; color: var(--accent); margin-left: auto; }

/* ---------- main column ---------- */
main { grid-area: main; overflow-y: auto; container-type: inline-size; scroll-behavior: smooth; }
.page { max-width: 740px; margin: 0 auto; padding: 44px 48px 160px; }
h1 { font-size: 30px; font-weight: 700; letter-spacing: -0.015em; line-height: 1.2; margin: 0 0 8px; }
h2, h1.part-title { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.3; margin: 0; }
h3 { font-size: 16px; font-weight: 600; margin: 20px 0 6px; }
.lede { color: var(--muted); margin-bottom: 28px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--ink); }

/* Home */
.sec { padding: 20px 0; border-top: 1px solid var(--line); }
.sec:first-of-type { border-top: 0; }
.sec-h { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
details.sec > summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); list-style: none; padding: 2px 6px; margin: -2px -6px; border-radius: 4px; width: fit-content; }
details.sec > summary:hover { background: var(--hover); }
details.sec > summary::before { content: "▸ "; }
details.sec[open] > summary::before { content: "▾ "; }
.profile { font-size: 14px; margin-top: 10px; }
.profile table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.profile td, .profile th { border-bottom: 1px solid var(--line); padding: 6px; text-align: left; vertical-align: top; }
.continue { display: flex; align-items: baseline; gap: 10px; padding: 14px 16px; margin: 8px 0 20px; border-radius: 6px; background: var(--callout); color: var(--ink); border: 1px solid var(--line); }
.continue:hover { background: var(--hover-strong); text-decoration: none; }
.continue .hint { color: var(--muted); }
.continue-title { font-weight: 600; }
.arrow { margin-left: auto; color: var(--muted); }
.fresh-line { margin: 0; }
.fresh-line a { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.ex-row { padding: 6px 0 12px; }
.ex-row > a { color: var(--ink); font-weight: 600; }
.ex-parts { display: flex; gap: 4px 14px; flex-wrap: wrap; margin-top: 6px; font-size: 13.5px; }
.ex-parts a { color: var(--muted); display: inline-flex; gap: 6px; align-items: center; padding: 1px 6px; margin: 0 -6px; border-radius: 4px; }
.ex-parts a:hover { background: var(--hover); color: var(--ink); text-decoration: none; }
.note p:last-child { margin-bottom: 0; }
.roadmap { display: grid; gap: 12px; margin-bottom: 10px; }
.rm-h { font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.rm-units { display: flex; flex-wrap: wrap; gap: 2px 16px; font-size: 14px; }
.rm-u { display: inline-flex; gap: 4px; color: var(--muted); }
.rm-u.done { color: var(--ink); }
.rm-u.done .mark { color: var(--right); }
.rm-u.now { color: var(--ink); font-weight: 600; }
.rm-u.now .mark { color: var(--accent); }

/* ---------- exercise: part tabs, page bar ---------- */
.tabs { display: flex; gap: 2px; flex-wrap: wrap; margin: 12px 0 28px; border-bottom: 1px solid var(--line); font-size: 14px; }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px 8px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: 4px 4px 0 0; }
.tab:hover { color: var(--ink); background: var(--hover); text-decoration: none; }
.tab.on { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.part-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.part-status { font-size: 13px; color: var(--muted); }
.intro { margin-bottom: 14px; }
.blocked { color: var(--wrong); font-size: 14px; }
.pagebar { display: flex; flex-wrap: wrap; gap: 2px; margin: 0 0 18px; font-size: 13.5px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.pagebar a { display: inline-flex; gap: 6px; align-items: baseline; color: var(--muted); padding: 3px 9px; border-radius: 4px; }
.pagebar a:hover { background: var(--hover); color: var(--ink); text-decoration: none; }
.pagebar a.on { color: var(--ink); font-weight: 600; background: var(--hover-strong); }
.pg-n { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.pagebar a.on .pg-n { color: var(--accent); }
.pg-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 24px; }
.pg-next { margin-left: auto; padding: 6px 14px; border-radius: 4px; background: var(--btn-primary); color: #fff; font-size: 14px; font-weight: 500; }
.pg-next:hover { background: var(--btn-primary-hover); text-decoration: none; }
.pager { display: flex; justify-content: space-between; gap: 10px; margin-top: 36px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 14px; }
.ghost-btn { color: var(--muted); padding: 4px 8px; margin: 0 -8px; border-radius: 4px; }
.ghost-btn:hover { color: var(--ink); background: var(--hover); text-decoration: none; }

/* ---------- steps ---------- */
.steps { display: flex; flex-direction: column; }
.step { display: grid; grid-template-columns: 32px minmax(0, 1fr); padding: 18px 0 20px; border-bottom: 1px solid var(--line); position: relative; }
.step:last-child { border-bottom: 0; }
.step.current::before { content: ""; position: absolute; left: -16px; top: 20px; height: 22px; width: 3px; border-radius: 3px; background: var(--btn-primary); }
.step.locked { opacity: .5; }
.step-info, .step-lesson { border-bottom-color: transparent; }
.step-info > .info { grid-column: 1 / -1; }
.step-num { font: 12px/1.9 var(--mono); color: var(--muted); }
.body { min-width: 0; }
.q > :first-child, .info > :first-child { margin-top: 0; }
.q p { margin: 0 0 10px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14.5px; }

pre.code, .info pre, .q pre, .lesson-text pre, .feedback pre, .step-note pre, .hint-box pre {
  background: var(--code-bg); color: var(--ink); padding: 11px 14px; border-radius: 6px;
  font: 14px/1.6 var(--mono); overflow-x: auto; white-space: pre; margin: 4px 0 10px;
}
pre.out { font: 14px/1.6 var(--mono); white-space: pre-wrap; margin: 4px 0 10px; padding: 9px 14px; border-radius: 6px; background: var(--callout); border: 1px solid var(--line); }
pre.out.error { color: var(--wrong); }
.prompt { color: var(--faint); user-select: none; }

textarea {
  width: 100%; min-height: 42px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: 4px;
  background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); resize: none; overflow: hidden; display: block;
  transition: border-color .12s ease, box-shadow .12s ease;
}
textarea.mono { font: 14px/1.55 var(--mono); }
textarea::placeholder { color: var(--muted); }
textarea:hover { border-color: var(--faint); }
textarea:focus { outline: none; border-color: var(--btn-primary); box-shadow: 0 0 0 3px var(--focus); }
textarea:disabled { color: var(--ink); background: var(--callout); border-color: transparent; }

button { font: 500 14px var(--sans); border-radius: 4px; padding: 5px 12px; cursor: pointer; border: 1px solid var(--line-strong); background: var(--bg); color: var(--ink); line-height: 1.4; }
button:hover:not(:disabled) { background: var(--hover); }
button:active:not(:disabled) { background: var(--hover-strong); }
button.primary { background: var(--btn-primary); color: #fff; border-color: transparent; }
button.primary:hover:not(:disabled) { background: var(--btn-primary-hover); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { color: var(--ink); }
button.small { font-size: 13px; padding: 3px 10px; }
button:disabled { opacity: .45; cursor: default; }
button.primary:disabled { background: var(--hover-strong); color: var(--muted); opacity: 1; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.verdict > span:first-child { font-size: 14px; color: var(--muted); }
.v.right.on { color: var(--right); border-color: var(--right); background: color-mix(in srgb, var(--right) 10%, transparent); }
.v.wrong.on { color: var(--wrong); border-color: var(--wrong); background: color-mix(in srgb, var(--wrong) 10%, transparent); }

.hints { margin-top: 10px; }
.hint-box { background: var(--hint-bg); padding: 9px 13px; margin-bottom: 6px; font-size: 14px; border-radius: 6px; }
.hint-box p { display: inline; margin: 0; }

/* things that appear after you click fade in, instead of popping */
@keyframes appear { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.result:not(:empty), .check-box, .hint-box, .why:not(:empty), .ex-out-in.fresh > :not(.out-label), .trace { animation: appear .18s ease-out; }

/* ---------- code editor (code steps) ---------- */
.file-tab { font: 12.5px var(--mono); color: var(--muted); margin-top: 10px; padding-bottom: 5px; }
.file-tab .hint { margin-left: 6px; }
.editor, .ex-editor { border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; background: var(--bg); transition: border-color .12s ease, box-shadow .12s ease; }
.editor:focus-within { border-color: var(--btn-primary); box-shadow: 0 0 0 3px var(--focus); }
.editor .cm-editor { min-height: 190px; font-size: 14px; }
.editor .cm-scroller, .ex-editor .cm-scroller { font-family: var(--mono); line-height: 1.6; }
.editor .cm-focused, .ex-editor .cm-focused { outline: none; }
.editor .cm-gutters { background: var(--bg); border-right: 1px solid var(--line); color: var(--muted); }
.editor .cm-activeLine { background: var(--hover); }
.editor .cm-activeLineGutter { background: transparent; color: var(--ink); }
@media (prefers-color-scheme: dark) { .cm-content { caret-color: #fff; } .cm-cursor { border-left-color: #fff !important; } }
.check-box { margin-top: 12px; padding: 10px 14px; border-radius: 6px; background: var(--callout); }
.check-box > b { font-weight: 600; }
.check-box.pass > b { color: var(--right); }
.check-box.fail > b { color: var(--wrong); }
.check-box pre.out { background: var(--bg); }
.check-msg { margin: 4px 0; white-space: pre-wrap; }
.submit-row { display: flex; align-items: center; gap: 12px; margin-top: 24px; flex-wrap: wrap; }

/* ---------- feedback (a callout, like a teacher's note on the page) ---------- */
.feedback { background: var(--callout); border-radius: 6px; padding: 16px 18px; margin: 0 0 28px; }
.fb-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.score { color: var(--muted); }
.fb-headline { font-size: 15.5px; }
.fb-headline p { margin: 0 0 8px; }
.fb-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 28px; margin-top: 10px; }
.fb-col ul { margin: 0; padding-left: 18px; font-size: 14.5px; }
.fb-col li { margin: 3px 0; }
.fb-col-h { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
.fb-col.got .fb-col-h::before { content: "✓ "; color: var(--right); }
.fb-col.work .fb-col-h::before { content: "→ "; color: var(--accent); }
@container (max-width: 640px) { .fb-cols { grid-template-columns: 1fr; } }
.note-jumps { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 13.5px; align-items: center; }
.jump { color: var(--ink); padding: 2px 8px; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); }
.jump:hover { background: var(--hover); text-decoration: none; }
.jump b { font-weight: 400; color: var(--muted); font-family: var(--mono); font-size: 12px; }
.jump code { background: none; padding: 0; }
.tag { font-size: 12px; color: var(--muted); font-style: italic; }
details.more { margin-top: 6px; }
details.more > summary { cursor: pointer; font-size: 13px; color: var(--muted); list-style: none; padding: 1px 6px; margin-left: -6px; border-radius: 4px; width: fit-content; }
details.more > summary:hover { background: var(--hover); color: var(--ink); }
details.more > summary::before { content: "▸ "; }
details.more[open] > summary::before { content: "▾ "; }
details.more[open] > summary { margin-bottom: 6px; }
.step-note { margin-top: 12px; background: var(--note-bg); padding: 10px 14px; font-size: 14.5px; border-radius: 6px; }
.step-note p { margin: 0 0 6px; }
.step-note p:last-child { margin-bottom: 0; }
.note-who { font-size: 12.5px; font-weight: 600; color: var(--accent); margin-bottom: 3px; }
.step.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0% { background: var(--note-bg); } 100% { background: transparent; } }
.review-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.reopened-note { margin: 0 0 12px; }

/* reviewed steps */
.rv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.rv-grid label { margin-top: 4px; }
.rv-grid pre.out { margin: 0; }
.rv-you { white-space: pre-wrap; font-size: 14.5px; padding: 8px 12px; border-radius: 6px; background: var(--callout); }
.rv-verdict { font-size: 13px; margin-top: 8px; color: var(--muted); }
.rv-verdict.right { color: var(--right); }
.rv-verdict.wrong { color: var(--wrong); }
@container (max-width: 640px) { .rv-grid { grid-template-columns: 1fr; gap: 0; } }
.step-compact { border-bottom: 1px solid var(--line); }
.step-compact > summary { display: flex; align-items: center; gap: 12px; padding: 7px 8px; margin: 2px -8px; cursor: pointer; list-style: none; font-size: 14px; white-space: nowrap; overflow: hidden; border-radius: 4px; }
.step-compact > summary::-webkit-details-marker { display: none; }
.step-compact > summary:hover { background: var(--hover); }
.step-compact > summary code { flex: none; }
.step-compact > summary .hint { flex: none; max-width: 40%; overflow: hidden; text-overflow: ellipsis; }
.step-compact > summary > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.step-compact > summary::after { content: ""; flex: none; width: 6px; height: 6px; margin: 0 4px 0 auto; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted); transform: rotate(-45deg); transition: transform .15s ease-out; }
.step-compact[open] > summary::after { transform: rotate(45deg); }
.step-compact > .step { border-bottom: 0; padding-top: 4px; }
.step-compact[open] > .step .step-num { visibility: hidden; }
.step-compact[open] > .step-predict .body > pre.code { display: none; }
.cnum { flex: none; width: 24px; font: 12px var(--mono); color: var(--muted); }
.ok { color: var(--right); } .bad { color: var(--wrong); } .qm { color: var(--muted); }

/* ---------- lessons ---------- */
.lesson-title { font-size: 19px; font-weight: 700; margin: 0 0 8px; }
.lesson-text { max-width: 64ch; }
.lesson-text p { margin: 0 0 12px; }
.lesson-text ul { margin: 0 0 12px; padding-left: 20px; }
.lesson-text li { margin: 4px 0; }
.ex-intro { margin: 16px 0 8px; }

/* An example is one fixed block: code on the left, output on the right. Run fills the output in place,
   and Step through swaps into the same block, so nothing below moves. */
.example { border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; margin: 0 0 14px; background: var(--bg); }
.ex-bar { display: flex; align-items: center; gap: 6px; padding: 5px 6px 5px 12px; border-bottom: 1px solid var(--line); background: var(--side); }
.ex-name { margin-right: auto; font-size: 12.5px; color: var(--muted); }
.ex-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(190px, 36%); min-height: 116px; }
.ex-editor { border: 0; border-radius: 0; border-right: 1px solid var(--line); min-width: 0; }
.ex-editor .cm-editor { font-size: 14px; height: 100%; }
.ex-editor .cm-content { padding: 9px 0; }
.ex-editor .cm-line { padding: 0 12px; }
.ex-editor .cm-activeLine { background: transparent; }
.ex-out { position: relative; background: var(--callout); min-width: 0; }
.ex-out-in { position: absolute; inset: 0; overflow: auto; padding: 8px 12px; }
.out-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 3px; }
pre.out-text { margin: 0 0 4px; font: 13.5px/1.55 var(--mono); white-space: pre-wrap; }
pre.out-text.placeholder { font: 13px/1.5 var(--sans); color: var(--muted); }
pre.out-text.error { color: var(--wrong); }
pre.tr-in, pre.tr-out { margin: 0; font: 13.5px/1.55 var(--mono); white-space: pre-wrap; }
pre.tr-out.error { color: var(--wrong); }
@container (max-width: 560px) {
  .ex-body { grid-template-columns: 1fr; }
  .ex-editor { border-right: 0; border-bottom: 1px solid var(--line); }
  .ex-out { min-height: 84px; }
}

/* ---------- step through: a large overlay above the page ---------- */
.trace-overlay { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 4vh 4vw;
  background: rgba(15, 15, 15, .45); animation: fadein .14s ease-out; }
.trace-overlay.closing { opacity: 0; transition: opacity .12s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.trace-dialog { width: min(1180px, 100%); height: min(820px, 100%); display: flex; flex-direction: column; background: var(--bg);
  border-radius: 8px; box-shadow: 0 12px 40px rgba(15, 15, 15, .3); overflow: hidden; outline: none; animation: appear .16s ease-out; }
@media (prefers-color-scheme: dark) { .trace-dialog { border: 1px solid #333; } }
.tr-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--side); flex: none; }
.tr-title { font-weight: 600; margin-right: 10px; }
.tr-count { margin-left: 4px; font-variant-numeric: tabular-nums; }
.tr-keys { margin-left: auto; }
.tr-bar .tr-close { margin-left: 8px; }
.tr-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 34%); }
.tr-code { font: 15px/1.7 var(--mono); padding: 14px 0; overflow: auto; border-right: 1px solid var(--line); }
.tl { display: flex; white-space: pre; padding-right: 20px; min-width: max-content; }
.tl.cur { background: color-mix(in srgb, var(--btn-primary) 14%, transparent); }
.ln { width: 3em; text-align: right; color: var(--muted); flex: none; padding-right: 4px; user-select: none; }
.ar { width: 1.8em; text-align: center; color: var(--btn-primary); flex: none; font-weight: 700; }
.tr-side { min-width: 0; overflow: auto; padding: 14px 18px; background: var(--callout); }
.tr-cap { font-size: 14px; margin-bottom: 14px; min-height: 2.6em; }
.tr-h { font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 0 0 4px; }
.tr-h + .tr-vars-wrap { margin-bottom: 18px; }
.tr-vars { border-collapse: collapse; font: 14px/1.6 var(--mono); width: 100%; }
.tr-vars td { padding: 1px 12px 1px 0; vertical-align: top; word-break: break-word; }
.tr-vars td:first-child { color: var(--muted); width: 1%; white-space: nowrap; }
.tr-vars tr.changed td:last-child { color: var(--btn-primary); font-weight: 700; }
pre.tr-printed { margin: 0; font: 14px/1.6 var(--mono); white-space: pre-wrap; max-height: 40vh; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
pre.tr-printed.empty { color: var(--muted); font-family: var(--sans); font-size: 13px; }
@media (max-width: 900px) {
  .tr-body { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .tr-code { border-right: 0; border-bottom: 1px solid var(--line); }
  .tr-side { max-height: 42vh; }
  .tr-keys { display: none; }
}

/* ---------- syntax colours outside the editor (same palette as the editor) ---------- */
.tk-kw { color: var(--hl-kw); }
.tk-str { color: var(--hl-str); }
.tk-num { color: var(--hl-num); }
.tk-com { color: var(--hl-com); font-style: italic; }
.tk-fn { color: var(--hl-fn); }

/* ---------- terminal ---------- */
#term-pane { grid-area: term; display: flex; flex-direction: column; background: var(--term-bg); min-width: 0; position: relative; }
#term-drag { position: absolute; left: -3px; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 2; }
#term-drag:hover { background: var(--focus); }
.term-head { display: flex; align-items: center; gap: 10px; color: #9b9890; font-size: 12.5px; padding: 8px 14px; border-bottom: 1px solid #2a2a2a; min-height: 37px; }
.term-mode { font-weight: 600; color: var(--term-ink); }
.term-mode.python { color: #f0c674; }
.term-where { font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#terminal { flex: 1; min-height: 0; padding: 8px 4px 8px 12px; background: var(--term-bg); }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 8px); background: #2f2f2f; color: #f1f1ef; padding: 9px 14px; border-radius: 6px; font-size: 14px; opacity: 0; transition: opacity .18s ease, transform .18s ease; pointer-events: none; z-index: 10; max-width: min(640px, 90vw); box-shadow: var(--shadow); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1000px) {
  body { grid-template-columns: 0 minmax(0, 1fr) var(--term-w, 44%); }
  body.no-term { grid-template-columns: 0 minmax(0, 1fr) 0; }
  nav { display: none; }
  .page { padding: 28px 22px 120px; }
}
.context { font-size: 13.5px; color: var(--muted); background: var(--callout); border-radius: 6px; padding: 7px 12px; margin: 0 0 10px; }
.context-h { font-weight: 600; }

/* ---------- courses ---------- */
.courses { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.course-card { display: block; padding: 14px 16px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--bg); }
.course-card:hover { background: var(--hover); text-decoration: none; }
.course-card.new { border-style: dashed; color: var(--muted); }
.course-card.new .cc-title { color: var(--ink); }
.cc-title { font-weight: 600; margin-bottom: 2px; }
.cc-goal { font-size: 13.5px; color: var(--muted); line-height: 1.45; }
.cc-meta { margin-top: 8px; }
.nav-course { margin-top: 10px; }
nav a.nav-c { font-weight: 600; }
nav a.nav-new { margin-top: 14px; color: var(--muted); }
nav a.nav-new:hover { color: var(--ink); }
.nav-course .nav-ex { margin-top: 2px; }
.nav-course .nav-ex > a { padding-left: 18px; }
.nav-course a.nav-part { padding-left: 42px; }

/* ---------- Claude panel ---------- */
.claude-wrap { position: relative; }
#claude-btn.busy { color: var(--ink); }
#claude-pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: 400px; max-height: 75vh; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); animation: appear .14s ease-out; }
@media (prefers-color-scheme: dark) { #claude-pop { background: #252525; border-color: #333; } }
.cp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.cp-jobs { padding: 6px 6px; }
.job { padding: 8px 8px; border-radius: 4px; }
.job + .job { border-top: 1px solid var(--line); }
.job-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.job-title { font-weight: 500; }
.job-status { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.job.running .job-status { color: var(--accent); }
.job.failed .job-status { color: var(--wrong); }
.job-sum { font-size: 13px; color: var(--muted); margin-top: 3px; }
.job-actions { display: flex; gap: 6px; margin-top: 4px; }
.job-actions:empty { display: none; }
.cp-settings { padding: 10px 14px 12px; border-top: 1px solid var(--line); font-size: 13.5px; }
.cp-num { display: flex; justify-content: space-between; align-items: center; color: var(--ink); font-size: 13.5px; margin: 6px 0; }
.cp-num input { width: 64px; padding: 3px 6px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--bg); color: var(--ink); font: inherit; }
.cp-settings .hint { margin: 8px 0 0; }

/* ---------- new course form ---------- */
.nc { max-width: 620px; }
.nc label { color: var(--ink); font-size: 14px; font-weight: 500; margin-top: 18px; }
.nc label.check { font-weight: 400; margin: 8px 0; }
.nc textarea { min-height: 64px; }
.nc-goal { border: 0; padding: 0; margin: 18px 0 0; }
.nc-goal legend { font-size: 14px; font-weight: 500; padding: 0; }
.nc-goal textarea { margin: 2px 0 6px 26px; width: calc(100% - 26px); }
.nc-input { width: 100%; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--bg); color: var(--ink); font: 15px var(--sans); }
.nc-input:focus { outline: none; border-color: var(--btn-primary); box-shadow: 0 0 0 3px var(--focus); }
.nc-actions { margin-top: 22px; }

/* ---------- Ask Claude ---------- */
.ask-open { float: right; margin: 0 0 4px 14px; padding: 1px 7px; border: 0; background: transparent; color: var(--faint); font-size: 12.5px; font-weight: 500; border-radius: 4px; position: relative; z-index: 1; }
.step:hover .ask-open, .step:focus-within .ask-open { color: var(--muted); }
.ask-open:hover, .ask-open.on { color: var(--ink) !important; background: var(--hover) !important; }
.ask-box { margin-top: 10px; clear: both; padding: 10px 12px; border-radius: 6px; background: var(--callout); animation: appear .16s ease-out; }
.ask-box textarea { min-height: 54px; background: var(--bg); }
.ask-note { margin-left: 4px; }
.ask-a { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); animation: appear .18s ease-out; }
.ask-you { font-size: 13.5px; color: var(--muted); margin-bottom: 4px; }
.ask-you::before { content: "You: "; font-weight: 600; }
.ask-hint p { margin: 0 0 6px; }

/* ---------- maths ---------- */
.katex { font-size: 1.08em; }
.math-block { margin: 8px 0 12px; overflow-x: auto; overflow-y: hidden; }
.lesson-text .math-block, .q .math-block { padding: 4px 0; }
.math-editor { margin-top: 4px; }
.me-label { margin: 4px 0 4px; color: var(--muted); font-size: 14px; }
.me-field math-field { display: block; width: 100%; min-height: 48px; padding: 8px 12px; font-size: 20px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg); color: var(--ink);
  --caret-color: var(--btn-primary); --selection-background-color: var(--focus); --contains-highlight-background-color: var(--hover); --primary: var(--btn-primary); }
.me-field math-field:focus-within { outline: none; border-color: var(--btn-primary); box-shadow: 0 0 0 3px var(--focus); }
.me-field math-field::part(virtual-keyboard-toggle), .me-field math-field::part(menu-toggle) { display: none; }
.me-keys { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.me-key { min-width: 34px; padding: 3px 8px; font-size: 14px; font-family: var(--sans); }
.me-help { margin-top: 4px; }
.me-help ul { margin: 4px 0 0; padding-left: 18px; font-size: 13.5px; color: var(--muted); }
.me-help li { margin: 3px 0; }
.ins-row { margin-top: 8px; }
.ins-panel { margin-top: 8px; padding: 10px 12px; border-radius: 6px; background: var(--callout); animation: appear .16s ease-out; }
.math-preview:not(:empty) { margin-top: 8px; padding: 8px 12px; border-radius: 6px; background: var(--callout); }
.math-preview .hint { display: block; margin-bottom: 2px; }
.math-preview p { margin: 0; }
.rv-math { font-size: 15px; }

/* ---------- graphs (colors validated for color-blind readers, light + dark) ---------- */
:root { --g1: #2a78d6; --g2: #eb6834; --g3: #1baf7a; }
@media (prefers-color-scheme: dark) { :root { --g1: #3987e5; --g2: #d95926; --g3: #199e70; } }
.graph { margin: 12px 0 6px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--bg); overflow: hidden; }
.g-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 8px 12px 0; font-size: 13.5px; }
.g-key { display: inline-flex; align-items: center; gap: 6px; }
.g-key i { width: 14px; height: 2px; border-radius: 2px; display: inline-block; }
.g-stage { position: relative; touch-action: none; user-select: none; }
.g-svg { display: block; width: 100%; height: auto; overflow: visible; }
.g-grid line { stroke: var(--line); stroke-width: 1; }
.g-axis { stroke: var(--faint); stroke-width: 1.25; }
.g-tick { fill: var(--muted); font: 11.5px var(--sans); font-variant-numeric: tabular-nums; }
.g-curve { fill: none; stroke-width: 2.25; stroke-linejoin: round; stroke-linecap: round; }
.g-secant { stroke: var(--g2); stroke-width: 2; }
.g-tangent { stroke: var(--g3); stroke-width: 2; }
.g-guide { fill: none; stroke: var(--muted); stroke-width: 1.25; stroke-dasharray: 3 4; }
.g-area { fill: var(--g3); opacity: .22; }
.g-area.faint { opacity: .1; }
.g-rect { fill: var(--g3); opacity: .28; stroke: var(--g3); stroke-width: 1.25; stroke-opacity: .9; }
.g-pt { fill: var(--ink); stroke: var(--bg); stroke-width: 2.5; }
.g-pt.drag { fill: var(--btn-primary); }
.g-hit { fill: transparent; cursor: grab; outline: none; }
.g-hit:focus-visible { stroke: var(--focus); stroke-width: 6; }
.g-stage.dragging, .g-stage.dragging .g-hit { cursor: grabbing; }
.g-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; pointer-events: none; }
.g-labels { position: absolute; inset: 0; pointer-events: none; }
.g-lab { position: absolute; transform: translate(0, -50%); white-space: nowrap; font-size: 14px; color: var(--ink); }
.g-lab.r { transform: translate(-100%, -50%); }
.g-lab.c { transform: translate(-50%, -50%); }
.g-lab.g-small { font-size: 12.5px; color: var(--muted); }
.g-curve-lab { background: color-mix(in srgb, var(--bg) 85%, transparent); padding: 0 4px; border-radius: 3px; }
.g-pt-lab { font-size: 12.5px; color: var(--muted); transform: translate(-100%, -50%); }
.g-pt-lab b { font-weight: 600; color: var(--ink); }
.g-tip { position: absolute; z-index: 2; pointer-events: none; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); padding: 6px 10px; font-size: 13px; min-width: 110px; }
@media (prefers-color-scheme: dark) { .g-tip { background: #252525; border-color: #333; } }
.g-tip-x { color: var(--muted); margin-bottom: 2px; }
.g-tip-row { display: flex; align-items: center; gap: 6px; }
.g-tip-row b { font-variant-numeric: tabular-nums; }
.g-tip-name { color: var(--muted); }
.g-key-line { display: inline-block; width: 12px; height: 2px; border-radius: 2px; flex: none; }
.g-key-rect { display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--g3); opacity: .5; flex: none; }
.g-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; padding: 8px 12px 10px; border-top: 1px solid var(--line); background: var(--callout); min-height: 46px; }
.g-readout { display: grid; gap: 4px; font-size: 14px; min-width: 0; }
.g-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.g-sep { display: inline-block; width: 14px; }
.g-actions { display: flex; align-items: center; gap: 8px; flex: none; }
@container (max-width: 560px) { .g-foot { flex-direction: column; align-items: flex-start; } }

/* ---------- recall (summarize from memory) + notes ---------- */
.recall-h { font-size: 13px; font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.recall-h .katex { font-size: 1em; }
.recall-compare { margin-top: 12px; animation: appear .18s ease-out; }
.recall-lesson { background: var(--callout); border-radius: 6px; padding: 10px 14px; font-size: 14.5px; }
.recall-lesson > .hint { display: block; margin-bottom: 4px; }
.recall-lesson p:last-child, .recall-lesson ul:last-child { margin-bottom: 0; }
.notes { display: grid; gap: 8px; }
.notes-lede { margin: -4px 0 10px; }
.note-card { display: block; padding: 10px 14px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: var(--bg); }
.note-card:hover { background: var(--hover); text-decoration: none; }
.note-t { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.note-t .hint { font-weight: 400; }
.note-b { font-size: 14.5px; }
.note-b p { margin: 0 0 4px; }
.note-fix { font-size: 13.5px; margin-top: 4px; }

/* ---------- math answer check ---------- */
.math-check { margin-top: 8px; }
.math-result { font-size: 14px; font-weight: 500; }
.math-result.ok { color: var(--right); }
.math-result.bad { color: var(--wrong); }
.math-result:empty { display: none; }
