:root {
  /* Colours: Catppuccin Latte is the light default and Tokyo Night the dark one.
   * A theme picked in Settings sets the same base colours inline (web/themes.js);
   * the soft tints below are mixed from them, so they follow any theme. */
  --bg: #eff1f5;
  --surface: #eaecf1;
  --surface-2: #e2e4ea;
  --hover: #dbdee4;
  --border-strong: #d2d4dc;
  --border: #ced1d9;
  --text: #4c4f69;
  --muted: #6c6f85;
  --dim: #9ea0af;
  --accent: #1e66f5;
  --accent-hover: #2563e0;
  --accent-ink: #eff1f5;
  --red: #d20f39;
  --yellow: #df8e1d;
  --green: #40a02b;

  --accent-soft: color-mix(in srgb, var(--accent) 13%, var(--bg));
  --green-soft: color-mix(in srgb, var(--green) 15%, var(--bg));
  --yellow-fill: var(--yellow);
  --yellow-soft: color-mix(in srgb, var(--yellow) 17%, var(--bg));
  --red-soft: color-mix(in srgb, var(--red) 13%, var(--bg));
  /* Yellow and green as text: darkened on light themes so they stay readable. */
  --yellow-ink: color-mix(in srgb, var(--yellow) 62%, var(--text));
  --green-ink: color-mix(in srgb, var(--green) 80%, var(--text));
  --code-bg: var(--surface);
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.05), 0 8px 24px -12px rgba(20, 30, 50, 0.12);
  --radius: 10px;
  --top: 60px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --label: var(--font);
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
  /* Where you are: a faint wash of the accent, with a 1px accent rule beside it. */
  --sel: color-mix(in srgb, var(--accent) 9%, transparent);
  --r: 6px;
  color-scheme: light;
}
/* The typeface picked in Settings (web/themes.js loads it). */
:root[data-font="geist"] { --font: "Geist", system-ui, sans-serif; --mono: "Geist Mono", ui-monospace, monospace; }
:root[data-font="instrument"] { --font: "Instrument Sans", system-ui, sans-serif; --mono: "JetBrains Mono", ui-monospace, monospace; }
:root[data-font="system"] { --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace; }

:root[data-scheme="dark"] {
  --bg: #1a1b26;
  --surface: #1e202b;
  --surface-2: #252734;
  --hover: #2b2d3b;
  --border-strong: #343646;
  --border: #373949;
  --text: #a9b1d6;
  --muted: #8b91ae;
  --dim: #62667e;
  --accent: #7aa2f7;
  --accent-hover: #81a4f2;
  --accent-ink: #1a1b26;
  --red: #f7768e;
  --yellow: #e0af68;
  --green: #9ece6a;
  --yellow-ink: var(--yellow);
  --green-ink: var(--green);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px -12px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-padding-top: calc(var(--top) + 12px); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  caret-color: var(--accent);
}
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); color: var(--text); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; text-wrap: balance; }
h1 { font-size: 1.875rem; font-weight: 500; margin: 0 0 0.4rem; letter-spacing: -0.015em; }
code, pre, textarea.code-input { font-family: var(--mono); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.ic { flex: none; }
.boot { padding: 4rem; text-align: center; color: var(--muted); }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--top);
  display: flex; align-items: center; gap: 22px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  transition: border-color 0.2s, background-color 0.2s;
}
/* At the top of the page the bar sits flat on it; once the page scrolls it frosts and gains a hairline. */
body:not(.is-scrolled) .topbar { border-bottom-color: transparent; background: var(--bg); }
.brand { font-weight: 600; font-size: 1.06rem; letter-spacing: -0.03em; color: var(--text); }
.brand:hover { text-decoration: none; }
.topnav { display: flex; gap: 20px; font-size: 0.9rem; }
.topnav a { color: var(--muted); padding: 4px 0; }
.topnav a:hover { color: var(--text); text-decoration: none; }
.topnav a[aria-current] { color: var(--text); }
.crumb-sep { color: var(--border-strong); }
.crumbs { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 0.9rem; padding-left: 18px; border-left: 1px solid var(--border); }
.crumbs > .crumb-sep:first-child { display: none; }
.crumb { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb:last-child { color: var(--text); }
.spacer { flex: 1; }
.save-state { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.save-state.is-error { color: var(--red); font-weight: 600; }
.icon-btn {
  display: grid; place-items: center; width: 36px; height: 36px;
  border: 1px solid transparent; border-radius: 9px; background: none; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- layout ---------- */

.layout { display: grid; grid-template-columns: 248px minmax(0, 1fr); align-items: start; }
.main { min-width: 0; padding: 34px 42px 80px; }
.main.is-full { padding: 0 24px; }
/* Pages without a sidebar (a branch, a note) get the same breathing room above. */
.main.is-full > .page { padding-block: 34px 80px; }
.page { max-width: 860px; margin: 0 auto; }
.page.is-wide { max-width: 1560px; }
/* A text lesson has no code pane, so it stays centred rather than stretching. */
.page.is-wide.is-text { max-width: 1320px; }

/* The sidebar holds one course (or Settings): quiet headings, codes as small mono text. */
.sidebar {
  position: sticky; top: var(--top);
  height: calc(100vh - var(--top));
  overflow-y: auto;
  padding: 16px 12px 22px 14px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column;
  font-size: 0.93rem; line-height: 1.45;
}
.sidebar nav { flex: 1; }
.side-sec { margin-top: 15px; }
.side-sec:first-child { margin-top: 0; }
.side-h {
  display: flex; align-items: center; gap: 4px; width: 100%; padding: 4px 8px;
  border: 0; background: none; color: var(--muted); font-size: 0.83rem; text-align: left;
}
button.side-h { cursor: pointer; }
button.side-h:hover { color: var(--text); }
.side-h .n { margin-left: auto; }
.side-h .ic { transition: transform 0.15s ease-out; }
.side-h[aria-expanded="false"] .ic { transform: rotate(-90deg); }
.item {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: var(--r); color: var(--text);
}
.item:hover { background: var(--hover); text-decoration: none; }
.item > .ic { color: var(--muted); }
.item .code { flex: none; width: 28px; font: 0.76rem var(--mono); color: var(--muted); }
.item .lbl { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .aside { color: var(--muted); font-size: 0.83rem; }
.item[aria-current] { background: var(--sel); }
.item[aria-current]::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 1px; background: var(--accent); }
/* A lesson's state: hollow until tried, filled grey while under way, then its weakest rating. */
.mark { width: 6px; height: 6px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px var(--border-strong); }
.mark.is-going { background: var(--muted); box-shadow: none; }
.mark.green { background: var(--green); box-shadow: none; }
.mark.yellow { background: var(--yellow); box-shadow: none; }
.mark.red { background: var(--red); box-shadow: none; }
.side-foot { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border); }
.side-empty { margin: 6px 8px; font-size: 0.83rem; color: var(--muted); }

/* The course switcher at the top of a course's sidebar. */
.course-pick { position: relative; }
.course-pick > button {
  display: flex; align-items: center; gap: 6px; width: 100%; padding: 6px 8px;
  border: 0; border-radius: var(--r); background: none; cursor: pointer; text-align: left; font-weight: 600;
}
.course-pick > button:hover, .course-pick > button[aria-expanded="true"] { background: var(--hover); }
.course-pick > button span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course-pick > button .ic { color: var(--muted); }
.course-menu {
  position: absolute; z-index: 5; top: calc(100% + 4px); left: 0; right: 0; max-height: 60vh; overflow-y: auto;
  margin: 0; padding: 4px; list-style: none;
  border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--bg); box-shadow: var(--shadow);
}
.course-menu .item { padding: 6px 8px; }
.course-menu .area { padding: 8px 8px 2px; font-size: 0.8rem; color: var(--muted); }

/* ---------- progress primitives ---------- */

.ring { position: relative; display: inline-grid; place-items: center; flex: none; }
.ring svg { width: 100%; height: 100%; }
.ring-bg, .ring-fg { fill: none; stroke-width: 3.2; }
.ring-bg { stroke: var(--border); }
.ring-fg { stroke: var(--accent); stroke-linecap: round; transition: stroke-dasharray 0.3s; }
.is-done .ring-fg { stroke: var(--green); }
.ring-label { position: absolute; font-size: 0.62rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }

.bar { display: flex; gap: 2px; height: 8px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.seg { min-width: 3px; }
.seg.green { background: var(--green); }
.seg.yellow { background: var(--yellow-fill); }
.seg.red { background: var(--red); }
.seg.accent { background: var(--accent); }
.seg.rest { background: var(--border); }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; border: 2px solid var(--border-strong); }
.dot.green { background: var(--green); border-color: var(--green); }
.dot.yellow { background: var(--yellow-fill); border-color: var(--yellow-fill); }
.dot.red { background: var(--red); border-color: var(--red); }

.tag {
  display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  background: var(--surface-2); color: var(--muted); vertical-align: middle; white-space: nowrap;
}
.pill { margin-left: 12px; padding: 2px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; text-transform: capitalize; vertical-align: middle; }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.yellow { background: var(--yellow-soft); color: var(--yellow-ink); }
.pill.red { background: var(--red-soft); color: var(--red); }

.eyebrow { margin: 0 0 6px; font-size: 0.85rem; color: var(--muted); }
.eyebrow a { color: inherit; }
.lede { margin: 0 0 1rem; font-size: 1.08rem; color: var(--muted); max-width: 62ch; }
.meta { font-size: 0.82rem; color: var(--muted); }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: none; color: var(--text);
  font-weight: 500; font-size: 0.92rem; cursor: pointer; line-height: 1.3;
}
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-quiet { border-color: transparent; background: none; color: var(--muted); }
/* A secondary action: text that gains a soft background on hover. */
.btn-text { border-color: transparent; background: none; color: var(--muted); padding-inline: 8px; }
.btn-text:hover { color: var(--text); background: var(--hover); }

.chip-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font-size: 0.75rem; font-weight: 600; cursor: pointer;
}
.chip-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* ---------- course and branch pages: a facts line, then ruled sections of rows ---------- */

.page > h1 + .lede { margin-top: 8px; }
.facts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin: 12px 0 0; font-size: 0.9rem; color: var(--muted); }
.facts b { font-weight: 500; color: var(--text); }
.facts a { color: var(--muted); text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
.facts a:hover { color: var(--text); }
.rated { display: inline-flex; gap: 10px; }
.rated > span { display: inline-flex; align-items: center; gap: 5px; }
.rated i { width: 6px; height: 6px; border-radius: 50%; }
.rated .g { background: var(--green); }
.rated .y { background: var(--yellow); }
.rated .r { background: var(--red); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 20px; }
.btn small { font-size: 0.85em; font-weight: 400; opacity: 0.75; }
.sec { margin-top: 38px; }
.sec-h.is-ruled { margin: 0 0 4px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.mod-h { display: flex; align-items: baseline; gap: 10px; margin: 20px 0 2px; font-size: 0.86rem; color: var(--muted); scroll-margin-top: calc(var(--top) + 12px); }
.mod-h span { margin-left: auto; font-variant-numeric: tabular-nums; }
.lib-course.mod-line { grid-template-columns: 36px minmax(0, 1fr) 132px 3.6em; gap: 14px; padding-block: 9px; }
.mod-line .code { font: 0.78rem var(--mono); color: var(--muted); }
.lib-course .status { font-size: 0.84rem; color: var(--muted); }
.links { display: flex; flex-wrap: wrap; gap: 6px 20px; padding-top: 10px; font-size: 0.93rem; }
.links a { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.links a:hover { color: var(--text); text-decoration: none; }
.judge-status { margin: 10px 0 0; }
.branch-group { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 16px; padding-block: 12px; }
.branch-group + .branch-group { border-top: 1px solid var(--border); }
.branch-label { display: grid; align-content: start; gap: 2px; padding-top: 6px; font-size: 0.86rem; }
.branch-label a { color: var(--text); }
.branch-label small { font-size: 0.8rem; color: var(--muted); }

/* ---------- pieces the lesson page still uses ---------- */

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.relations { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 0.6rem; }
.chip {
  padding: 3px 11px; border-radius: 999px; border: 1px solid var(--border-strong);
  font-size: 0.85rem; font-weight: 600; color: var(--text);
}
.chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

.empty { padding: 40px 28px; text-align: center; border: 1px dashed var(--border-strong); border-radius: 16px; color: var(--muted); }
.empty h2 { margin: 0 0 6px; color: var(--text); font-size: 1.15rem; }
.empty p { margin: 0 0 14px; }

/* ---------- lesson page: a header with one progress line, then text tabs ---------- */

.lhead-row { display: flex; align-items: center; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; }
.lhead h1 { margin: 0; font-size: 1.6rem; }
.lhead h1 .code { margin-right: 12px; font: 500 0.9rem var(--mono); color: var(--muted); vertical-align: 0.2em; }
.progress-mini { display: flex; align-items: center; gap: 10px; font-size: 0.86rem; color: var(--muted); white-space: nowrap; }
.progress-mini .track { width: 96px; }
.lhead .facts { margin-top: 8px; }

.tabs {
  position: sticky; top: var(--top); z-index: 20;
  display: flex; gap: 22px; overflow-x: auto; overflow-y: hidden;
  margin: 14px 0 26px; padding-top: 4px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  scroll-margin-top: var(--top);
}
.tab { padding: 6px 0 9px; color: var(--muted); font-size: 0.93rem; white-space: nowrap; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-current] { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.tab-count { margin-left: 5px; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.reading { margin-bottom: 36px; }
.reading > h2 { font-size: 1.4rem; margin: 0 0 12px; }
.next-step { margin-top: 12px; }
.group-title { margin: 30px 0 12px; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.78rem; }

/* sources */
.sources-intro { margin-bottom: 18px; color: var(--muted); }
.source {
  display: grid; gap: 8px; align-content: start; padding: 18px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border);
}
.source-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 8px; min-height: 20px; }
.source-top .tag { margin: 0; background: var(--accent-soft); color: var(--accent); }
.domain { font-size: 0.78rem; color: var(--muted); font-family: var(--mono); }
.source-title { display: inline-flex; align-items: baseline; gap: 6px; font-weight: 650; font-size: 1.05rem; line-height: 1.3; }
.source-title .ic { align-self: center; opacity: 0.7; }
.source-note { font-size: 0.9rem; color: var(--muted); }
.link-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.link-list li { display: flex; gap: 12px; justify-content: space-between; align-items: baseline; padding: 9px 14px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }

/* ---------- a problem: the statement and the work, flat, split by one line ---------- */

.problem { min-width: 0; container-type: inline-size; }
.problem-title { margin: 14px 0 10px; font-size: 1.15rem; font-weight: 500; letter-spacing: -0.01em; }
.verified-note { display: inline-flex; align-items: center; gap: 4px; margin-left: 10px; font-size: 0.82rem; font-weight: 400; color: var(--muted); vertical-align: 0.15em; }
.verified-note .ic { color: var(--green); }
.group-intro { margin: 12px 0 0; color: var(--muted); }
.pnav { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 0.86rem; color: var(--muted); }
.pnav .sp { flex: 1; }
.steps { display: flex; flex-wrap: wrap; gap: 2px; }
.steps a { display: grid; place-items: center; width: 18px; height: 18px; }
.steps a i { width: 14px; height: 3px; border-radius: 2px; background: var(--border-strong); }
.steps a.green i { background: var(--green); }
.steps a.yellow i { background: var(--yellow); }
.steps a.red i { background: var(--red); }
.steps a[aria-current] i { height: 5px; background: var(--accent); }
.btn-sm { padding: 3px 8px; font-size: 0.86rem; }

.problem .work { display: grid; gap: 18px; align-content: start; margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--border); }
.field { display: grid; gap: 6px; }
.field-label { font-weight: 500; font-size: 0.88rem; }
.hint { font-size: 0.8rem; color: var(--muted); }
.text-input, .code-input {
  width: 100%; resize: vertical; min-height: 58px;
  padding: 8px 11px; border-radius: var(--r); border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text); font: inherit; line-height: 1.5;
}
.text-input:hover { border-color: var(--muted); }
.text-input::placeholder, .code-input::placeholder { color: var(--muted); opacity: 0.8; }
.code-input { font-family: var(--mono); font-size: 0.88rem; tab-size: 4; white-space: pre; overflow-x: auto; min-height: 120px; }
.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

/* The scratchpad: one bordered editor with a quiet bar, then its actions and output. */
.pad { display: grid; gap: 10px; }
.editor { border: 1px solid var(--border-strong); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.editor:focus-within { border-color: var(--accent); }
.editor-bar { display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 10px; border-bottom: 1px solid var(--border); font-size: 0.8rem; color: var(--muted); }
.editor-bar .hint { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor .code-input { display: block; border: 0; border-radius: 0; background: none; resize: none; }
.editor .code-input:focus { outline: none; box-shadow: none; }
.act { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.act .keys { margin-left: auto; font-size: 0.8rem; color: var(--muted); }
@media (hover: none) { .act .keys { display: none; } }
kbd { padding: 0 4px; border: 1px solid var(--border); border-radius: 4px; font: 0.72rem var(--mono); color: var(--muted); }
.pad-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.run-status { font-size: 0.82rem; color: var(--muted); }
.run-out {
  margin: 0; padding: 10px 0 0; max-height: 340px; overflow: auto; border-top: 1px solid var(--border);
  font: 0.86rem/1.55 var(--mono); color: var(--muted); white-space: pre-wrap; word-break: break-word;
}
.run-out.is-error { color: var(--red); }
.nudge {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-size: 0.88rem; color: var(--yellow-ink);
}
.verify { display: grid; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.verify > .field-label { color: var(--muted); font-weight: 400; }
.verify .pad-actions { margin-left: -8px; }
.check-msg { font-size: 0.85rem; color: var(--muted); margin: 0; }
.check-msg.is-ok { color: var(--green-ink); }
.check-msg.is-error { color: var(--red); }
.judge-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 0.88rem; }
.judge-list li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.judge-list li.is-accepted svg { color: var(--green); }
.judge-list .meta { font-size: 0.82rem; color: var(--muted); }
.judge-pick { font: inherit; font-size: 0.82rem; max-width: 100%; padding: 3px 6px; border-radius: var(--r); border: 1px solid var(--border); background: var(--bg); color: var(--text); }

/* How it went: three quiet choices, each with its rating's dot. */
.rate { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding-top: 16px; border-top: 1px solid var(--border); }
.rate .field-label { margin-right: 8px; }
.rate-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px;
  border: 1px solid transparent; border-radius: 999px; background: none; color: var(--muted); cursor: pointer;
}
.rate-btn:hover { color: var(--text); background: var(--hover); }
.rate-btn i { width: 7px; height: 7px; border-radius: 50%; }
.rate-btn.green i { background: var(--green); }
.rate-btn.yellow i { background: var(--yellow); }
.rate-btn.red i { background: var(--red); }
.rate-btn[aria-pressed="true"] { color: var(--text); border-color: var(--border-strong); }
.rate-btn.green[aria-pressed="true"] { border-color: var(--green); }
.rate-btn.yellow[aria-pressed="true"] { border-color: var(--yellow); }
.rate-btn.red[aria-pressed="true"] { border-color: var(--red); }

/* The rating cards a language or reading lesson still uses, made flat. */
.ratings { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.rating {
  display: grid; gap: 3px; text-align: left; padding: 9px 12px; border-radius: var(--r);
  border: 1px solid var(--border); background: none; cursor: pointer;
}
.rating strong { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; font-weight: 500; }
.rating small { color: var(--muted); font-size: 0.8rem; line-height: 1.35; }
.rating:hover { border-color: var(--border-strong); background: var(--hover); }
.rating.green.is-on { border-color: var(--green); }
.rating.yellow.is-on { border-color: var(--yellow); }
.rating.red.is-on { border-color: var(--red); }
.problem-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-left: -8px; }

/* A text lesson keeps the prompt above one short attempt and its feedback. */
.text-problem { width: 100%; }
.text-problem > .problem-body, .text-study, .text-problem > .problem-foot, .text-problem > .pnav { max-width: 820px; }
.text-problem > .problem-foot { margin-top: 18px; }
.text-cols, .text-main, .text-side { display: grid; gap: 16px; align-content: start; }
.text-cols { max-width: 820px; }
@container (min-width: 900px) {
  .text-cols.has-side { max-width: none; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 32px; }
  /* Beside the answer the supports are a plain column, not cards inside the card. */
  .text-side { position: sticky; top: 72px; padding-left: 32px; border-left: 1px solid var(--border); }
  .text-side .text-support, .text-side .text-model { padding: 0; border: 0; background: none; }
  .text-side > * + * { padding-top: 16px; border-top: 1px solid var(--border); }
}
.text-words h3 { margin: 0 0 8px; font-size: 0.95rem; }
.text-words ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.text-words li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; }
.word-ko { font-size: 1.15rem; }
.word-meaning { color: var(--muted); }
.text-workspace { display: grid; gap: 16px; margin-top: 22px; }
.text-workspace h3 { margin: 0 0 8px; font-size: 1.05rem; }
.text-workspace p { margin: 0 0 10px; }
.text-workspace .hint { margin: 0; line-height: 1.5; }
.text-study, .text-support, .text-model, .text-finish {
  padding: 16px 18px; border-radius: var(--r); background: var(--surface);
}
.text-study > .btn { margin-top: 14px; }
.text-support .md > :last-child, .text-model .md > :last-child { margin-bottom: 0; }
.text-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.text-finish .text-actions { margin-top: 14px; }
.text-feedback { padding: 16px 18px; border-radius: var(--r); background: var(--yellow-soft); }
.text-feedback.is-match { background: var(--green-soft); }
.text-feedback p:last-child { margin-bottom: 0; }
.text-problem [lang^="ko"], .language-answer[lang="ko"] {
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  font-size: 1.12em; line-height: 1.8; word-break: keep-all; overflow-wrap: anywhere;
}
.language-answer { min-height: 82px; }
/* A speaker after each word in the module's language. */
.say-word { white-space: nowrap; }
.say {
  display: inline-flex; align-items: center; justify-content: center; width: 1.6em; height: 1.6em; margin-left: 0.2em;
  padding: 0; border: 1px solid transparent; border-radius: 50%; background: none; color: var(--muted);
  vertical-align: -0.3em; cursor: pointer;
}
.say:hover, .say:focus-visible { color: var(--accent); background: var(--surface-2); border-color: var(--border); }
.say.is-playing { color: var(--accent); background: var(--surface-2); border-color: var(--accent); }
.say .ic { width: 0.95em; height: 0.95em; }
/* A meaning in a language lesson's example, hidden until asked for. */
.meaning-toggle { padding: 1px 9px; font-size: 0.8rem; vertical-align: 0.1em; }
.meaning:not([hidden]) { margin-left: 6px; }
.syllable-tiles { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.syllable-tiles .btn { min-width: 42px; min-height: 42px; justify-content: center; }
.text-workspace .rating:disabled { opacity: 0.5; cursor: not-allowed; }
.text-actions .btn.is-on { border-color: var(--accent); color: var(--accent); }
.text-notes summary { color: var(--muted); cursor: pointer; font-size: 0.88rem; }
.text-notes textarea { margin-top: 10px; }

/* checkpoint */
.checks { list-style: none; padding: 0; margin: 0 0 18px; }
.checks > li + li { border-top: 1px solid var(--border); }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 8px; margin-inline: -8px; border-radius: var(--r); cursor: pointer; }
.check:hover { background: var(--hover); }
.check input { width: 16px; height: 16px; margin: 4px 0 0; accent-color: var(--accent); flex: none; }
.check:has(input:checked) .check-text { color: var(--muted); }
.check-plain { padding: 8px 0; color: var(--muted); }
.check-text > :first-child { margin-top: 0; }
.check-text > :last-child { margin-bottom: 0; }
.checkpoint > .work { margin-top: 8px; }

/* review */
.review-list { display: grid; gap: 8px; margin-top: 22px; }
.review-row {
  display: flex; align-items: center; gap: 14px; padding: 13px 16px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--text);
}
.review-row:hover { border-color: var(--accent); text-decoration: none; }
.review-main { flex: 1; min-width: 0; display: grid; }
.review-main small { color: var(--muted); font-size: 0.82rem; }
.review-row > .ic { color: var(--muted); }

/* ---------- rendered Markdown ---------- */

.md { overflow-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: 0 0 0.9em; }
.md ul, .md ol { padding-left: 1.4em; }
.md li { margin: 0.25em 0; }
.md li > p { margin: 0 0 0.4em; }
.md h2 { font-size: 1.35rem; margin: 1.8em 0 0.5em; }
.md h3 { font-size: 1.12rem; margin: 1.6em 0 0.45em; }
.md h4 { font-size: 0.82rem; margin: 1.5em 0 0.4em; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }
.md img { max-width: 100%; }
.md a.wikilink { border-bottom: 1px dashed currentColor; }
.md a.wikilink:hover { text-decoration: none; border-bottom-style: solid; }
.md :not(pre) > code { padding: 0.12em 0.38em; border-radius: 5px; background: var(--code-bg); border: 1px solid var(--border); font-size: 0.86em; }
.md blockquote { margin: 0 0 1em; padding: 4px 16px; border-left: 3px solid var(--border-strong); color: var(--muted); }
.md blockquote > :last-child { margin-bottom: 0; }
.article { font-size: 1.02rem; }

.codeblock { position: relative; margin: 0 0 1em; }
.codeblock pre {
  margin: 0; padding: 14px 16px; border-radius: 10px; overflow-x: auto;
  background: var(--code-bg); border: 1px solid var(--border); font-size: 0.87rem; line-height: 1.55;
}
.code-tools { position: absolute; top: 7px; right: 7px; display: flex; gap: 5px; opacity: 0; transition: opacity 0.12s; }
.codeblock:hover .code-tools, .code-tools:focus-within { opacity: 1; }
@media (hover: none) { .code-tools { opacity: 1; } }
.hljs-keyword, .hljs-literal, .hljs-built_in { color: #7048e8; }
.hljs-string { color: #2b8a3e; }
.hljs-number { color: #c2410c; }
.hljs-comment { color: var(--muted); font-style: italic; }
.hljs-title, .hljs-function .hljs-title { color: #1971c2; }
:root[data-scheme="dark"] .hljs-keyword, :root[data-scheme="dark"] .hljs-literal, :root[data-scheme="dark"] .hljs-built_in { color: #b197fc; }
:root[data-scheme="dark"] .hljs-string { color: #8ce99a; }
:root[data-scheme="dark"] .hljs-number { color: #ffa94d; }
:root[data-scheme="dark"] .hljs-title { color: #74c0fc; }

.table-wrap { overflow-x: auto; margin: 0 0 1em; border: 1px solid var(--border); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 0.92rem; }
.md th, .md td { padding: 9px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.md th { background: var(--surface-2); font-weight: 650; white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }

.callout { margin: 0 0 1em; padding: 12px 16px; border-radius: var(--r); background: var(--accent-soft); }
.callout-title { font-weight: 600; font-size: 0.92rem; color: var(--accent); }
.callout-body { margin-top: 4px; }
.callout-body > :last-child { margin-bottom: 0; }
.callout-warning, .callout-important { background: var(--yellow-soft); }
.callout-warning .callout-title, .callout-important .callout-title { color: var(--yellow-ink); }
.callout-check, .callout-success, .callout-tip { background: var(--green-soft); }
.callout-check .callout-title, .callout-success .callout-title, .callout-tip .callout-title { color: var(--green); }
.math-block { overflow-x: auto; margin: 0 0 1em; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 60;
  padding: 10px 16px; border-radius: 10px; background: var(--text); color: var(--bg);
  font-size: 0.9rem; font-weight: 600; box-shadow: var(--shadow);
}

/* ---------- small screens ---------- */

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; z-index: 40; top: var(--top); left: 0; width: min(310px, 88vw);
    transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow);
  }
  .nav-open .sidebar { transform: none; }
  .main { padding: 24px 16px 80px; }
  .ratings { grid-template-columns: minmax(0, 1fr); }
  .crumbs { display: none; }
  h1 { font-size: 1.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- roadmap topic map: a transit line diagram ---------- */

/* Course-home summary of the roadmap. */

/* Every line has its own hue at one shared lightness, so none outranks another.
   --line has to be computed on the element that carries --h. */
.road { --line-l: 0.56; --line-c: 0.16; }
:root[data-scheme="dark"] .road { --line-l: 0.76; --line-c: 0.13; }
.road [style*="--h:"] {
  --line: oklch(var(--line-l) var(--line-c) var(--h));
  --line-soft: color-mix(in oklch, var(--line) 26%, var(--surface));
}

.road-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; margin-bottom: 24px; }
.road-head h1 { font-size: 2.4rem; }
.road-head .lede { margin: 0; }
.road-controls { display: flex; flex-wrap: wrap; gap: 8px; }

/* A pill row of mutually exclusive choices. */
.switch { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--surface-2); }
.switch button {
  padding: 4px 13px; border: 0; border-radius: 999px; background: none; cursor: pointer;
  color: var(--muted); font: 500 0.84rem var(--label);
}
.switch button:hover { color: var(--text); }
.switch button[aria-pressed="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px color-mix(in srgb, var(--text) 14%, transparent); }

/* ----- roadmap as a graph: the graph fills the page below the heading ----- */
.road.is-graph { max-width: none; padding-top: 22px; }
/* The graph is drawn in the theme's one accent unless Settings asks for a colour per area.
   Everything below colours itself with --line, which is the accent here or the area's hue. */
.road.is-graph:not(.is-by-area) [style*="--h:"] { --line: var(--accent); }
.road.is-graph .road-head { margin-bottom: 12px; }
.road.is-graph .road-head h1 { font-size: 2rem; }
.road.is-graph .lede { font-size: 0.92rem; }
.rg-stage {
  /* The graph sits on its own canvas: brighter than the page in light themes, deeper in dark ones. */
  --canvas: color-mix(in srgb, var(--bg) 45%, white);
  position: relative; height: calc(100dvh - var(--top) - 140px); min-height: 520px; margin: 0 -24px;
  overflow: hidden; background-color: var(--canvas);
}
:root[data-scheme="dark"] .rg-stage { --canvas: color-mix(in srgb, var(--bg) 62%, black); }
.rg-svg { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; user-select: none; }
.rg-svg:active { cursor: grabbing; }
.rg-guide { stroke: var(--border); stroke-dasharray: 2 5; }
.rg-guide-label { fill: var(--dim); font: 500 10.5px var(--mono, monospace); }

.rg-edge { fill: none; stroke: var(--edge); stroke-width: 1; stroke-linecap: round; vector-effect: non-scaling-stroke; transition: opacity 0.18s; }
.rg-tip { fill: var(--edge); transition: opacity 0.18s; }
/* Arrows take their source topic's colour, folded into the canvas so they stay quiet until lit. */
.rg-edge, .rg-tip { --edge: color-mix(in oklch, var(--line) 38%, var(--canvas)); }
.rg-edge.is-up { stroke: var(--line); stroke-width: 1.6; }
.rg-edge.is-down { stroke: var(--muted); stroke-width: 1.3; stroke-dasharray: 4 5; opacity: 0.85; }
.rg-tip.is-up { fill: var(--line); }
.rg-tip.is-down { fill: var(--muted); }
@media (prefers-reduced-motion: no-preference) {
  .rg-edge.is-up { stroke-dasharray: 7 5; animation: rg-flow 0.9s linear infinite; }
  .rg-edge.is-down { animation: rg-flow 1.4s linear infinite; }
}
@keyframes rg-flow { to { stroke-dashoffset: -12; } }

.rg-node { cursor: pointer; transition: opacity 0.18s; }
.rg-node:focus { outline: none; }
.rg-ring { fill: var(--canvas); stroke: var(--nc, var(--line)); stroke-width: calc(1.6px * var(--zs, 1)); }
.rg-disc { fill: var(--nc, var(--line)); }
.rg-prog { fill: none; stroke: var(--text); stroke-width: calc(2px * var(--zs, 1)); stroke-linecap: round; }
.rg-node:hover .rg-disc, .rg-node.is-focus .rg-disc, .rg-node.is-hit .rg-disc { filter: drop-shadow(0 0 5px color-mix(in srgb, var(--line) 70%, transparent)); }
.rg-node.is-focus .rg-ring, .rg-node.is-picked .rg-ring { stroke-width: calc(2.6px * var(--zs, 1)); }
.rg-node:focus-visible .rg-ring { stroke: var(--text); stroke-width: 2; }
/* Names stay quiet and only show when there is room for them (see labels() in road-graph.js). */
.rg-label {
  fill: var(--muted); font: 500 11px var(--label); text-anchor: middle; pointer-events: none;
  paint-order: stroke; stroke: var(--canvas); stroke-width: 3px; stroke-linejoin: round;
  opacity: 0; transition: opacity 0.18s;
}
.rg-node.is-labelled .rg-label, .rg-node:hover .rg-label, .rg-node.is-here .rg-label, .rg-node.is-hit .rg-label { opacity: 1; }
.rg-node.is-focus .rg-label, .rg-node.is-near .rg-label, .rg-node.is-picked .rg-label { opacity: 1; fill: var(--text); font-weight: 600; }
.is-focusing .rg-node.is-faded .rg-label { opacity: 0; }
.rg-here { fill: none; stroke: var(--text); stroke-width: 1.2; stroke-dasharray: 2 3; opacity: 0.7; }
.rg-here-tag { fill: var(--text); font: 600 10.5px var(--label); text-anchor: middle; paint-order: stroke; stroke: var(--canvas); stroke-width: 4px; }
.is-focusing .rg-node.is-faded { opacity: 0.16; }
.is-focusing .rg-node.is-far { opacity: 0.75; }
.is-focusing .rg-edge.is-faded, .is-focusing .rg-tip.is-faded { opacity: 0.08; }

/* Floating panels sit on a frosted ground rather than in boxes. */
.rg-float {
  position: absolute; z-index: 2; border-radius: 14px;
  background: color-mix(in srgb, var(--canvas) 72%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.rg-zoom { top: 14px; right: 14px; display: flex; flex-direction: column; gap: 2px; padding: 4px; }
.rg-stage.has-pick .rg-zoom { right: 396px; }
.rg-zoom button { width: 30px; height: 30px; border: 0; border-radius: 8px; background: none; cursor: pointer; color: var(--muted); font-size: 1rem; }
.rg-zoom button:hover { background: var(--hover); color: var(--text); }

.rg-key { left: 14px; bottom: 14px; display: grid; padding: 4px; max-height: calc(100% - 90px); }
.rg-key h3, .rg-route h3 { margin: 0 0 4px 8px; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); }
.rg-key-head {
  display: flex; align-items: center; gap: 8px; max-width: 250px; padding: 5px 10px 5px 8px; border: 0; border-radius: 10px;
  background: none; cursor: pointer; color: var(--muted); font-size: 0.8rem; text-align: left;
}
.rg-key-head h3 { margin: 0; }
.rg-key-head span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.rg-key-head svg { flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; transition: transform 0.2s; }
.rg-key-head:hover { color: var(--text); }
.rg-key.is-open .rg-key-head svg { transform: rotate(180deg); }
/* Folded, the list takes no room; it slides open upward from the button. */
.rg-key-body { display: grid; grid-template-rows: 0fr; min-height: 0; transition: grid-template-rows var(--rise, 0.22s) cubic-bezier(0.22, 1, 0.36, 1); }
.rg-key-body > div { display: grid; gap: 1px; min-height: 0; overflow: hidden; }
.rg-key:hover .rg-key-body, .rg-key:has(:focus-visible) .rg-key-body, .rg-key.is-open .rg-key-body { grid-template-rows: 1fr; }
.rg-key:hover .rg-key-body > div, .rg-key:has(:focus-visible) .rg-key-body > div, .rg-key.is-open .rg-key-body > div { overflow: auto; scrollbar-width: thin; padding: 6px 4px 4px; }
@media (prefers-reduced-motion: reduce) { .rg-key-body, .rg-key-head svg { transition: none; } }
.rg-area {
  display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 9px; align-items: center; max-width: 250px;
  padding: 3px 8px; border: 0; border-radius: 8px; background: none; cursor: pointer; text-align: left; color: var(--text); font-size: 0.82rem;
}
.rg-area i { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.rg-area span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.rg-area small { color: var(--dim); font-variant-numeric: tabular-nums; }
.rg-area:hover { background: var(--hover); }
.rg-area[aria-pressed="true"] { background: var(--surface-2); font-weight: 600; }
.rg-size { display: flex; align-items: center; gap: 8px; max-width: 250px; margin: 4px 0 0; padding: 8px 8px 2px; border-top: 1px solid var(--border); font-size: 0.75rem; line-height: 1.35; color: var(--muted); }
.rg-size svg { flex: none; }
.rg-size circle { fill: none; stroke: var(--muted); stroke-width: 1.4; }
.rg-size circle.dot { fill: var(--muted); stroke: none; }

/* Search: typing anywhere on the map lands here and lights the matching topics. */
.rg-find { top: 14px; left: 14px; width: min(340px, calc(100% - 80px)); padding: 4px 6px 4px 12px; }
.rg-find { display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 8px; }
.rg-find svg { fill: none; stroke: var(--dim); stroke-width: 1.6; stroke-linecap: round; }
.rg-find input { min-width: 0; padding: 6px 0; border: 0; outline: none; background: none; color: var(--text); font: 500 0.88rem var(--label); }
.rg-find input::placeholder { color: var(--dim); }
.rg-find input::-webkit-search-cancel-button { cursor: pointer; }
.rg-find:focus-within svg { stroke: var(--accent); }
.rg-find-note { grid-column: 1 / -1; margin: 0; padding: 6px 2px 6px; border-top: 1px solid var(--border); font-size: 0.8rem; line-height: 1.4; color: var(--muted); }
.rg-find-note b { color: var(--text); font-weight: 600; }
.rg-find-note small { display: block; margin-top: 3px; color: var(--dim); font-size: 0.76rem; }

.rg-route { right: 14px; bottom: 14px; max-width: min(640px, calc(100% - 320px)); padding: 10px 8px 8px; }
.rg-stage.has-pick .rg-route { display: none; }
.rg-stops { display: flex; flex-wrap: wrap; gap: 4px; }
.rg-stop { display: inline-flex; align-items: center; gap: 7px; padding: 3px 11px 3px 3px; border: 0; border-radius: 999px; background: none; cursor: pointer; color: var(--text); font-size: 0.8rem; }
.rg-stop b {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid currentColor; font-size: 0.72rem;
  background: linear-gradient(to top, color-mix(in srgb, currentColor 22%, transparent) var(--level), transparent var(--level));
}
.rg-stop:hover { background: var(--hover); }
.rg-stop[aria-pressed="true"] { background: var(--text); color: var(--bg); }
.rg-route .route-note { margin: 8px 8px 2px; font-size: 0.82rem; }

/* Hover card: the head of the topic card, beside the node. */
.rg-hover {
  z-index: 3; width: 330px; padding: 14px 16px 16px; pointer-events: none;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--text) 8%, transparent), 0 14px 40px -14px color-mix(in srgb, var(--text) 30%, transparent);
  opacity: 0; transform: translateY(4px); transition: opacity 0.14s, transform 0.14s;
}
.rg-hover.is-shown { opacity: 1; transform: none; }
.rh { display: grid; gap: 10px; }
.rh p { margin: 0; }
.rh-head { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: start; }
.rh-code { padding: 3px 8px; border-radius: 8px; background: var(--line); color: var(--bg); font: 700 0.78rem var(--label); }
.rh-head h2 { margin: 0; font-size: 1.02rem; line-height: 1.25; text-wrap: balance; }
.rh-meter { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.rh-meter span { display: block; height: 100%; border-radius: 4px; background: var(--line); }
.rh-block { display: grid; gap: 6px; }
.rh-block h3 { margin: 0; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--dim); }
.rh .st-badge { padding: 1px 9px 1px 2px; font-size: 0.78rem; }
.rh .st-badge b { min-width: 0; height: 19px; }
.rh .st-badge.is-code { padding-right: 2px; }
.rh-list { display: grid; gap: 4px; margin: 0; padding-left: 18px; font-size: 0.85rem; line-height: 1.4; }
.rh-list p { display: inline; }

/* The picked topic's full card, docked on the right of the graph. */
.rg-card {
  position: absolute; z-index: 4; top: 14px; right: 14px; bottom: 14px; width: 368px;
  display: flex; flex-direction: column;
}
.rg-card .station-card {
  position: static; max-height: none; min-height: 0; flex: 1 1 auto; overflow-y: auto; scrollbar-width: thin;
  box-shadow: 0 14px 40px -14px color-mix(in srgb, var(--text) 30%, transparent);
}
.rg-card:has(.station-card) { pointer-events: none; }
.rg-card .station-card, .rg-close { pointer-events: auto; }
.rg-close { position: absolute; top: 14px; right: 8px; z-index: 1; font-size: 1.2rem; }
.rg-card .sc-head { padding-right: 28px; }

/* The default route: a numbered strip of stops. */
.route-wrap { margin: 0 0 28px; }
.route-wrap h2 { margin: 0 0 14px; font-size: 1rem; }
.route {
  position: relative; display: grid; grid-template-columns: repeat(var(--stops), minmax(0, 1fr));
  margin: 0; padding: 0; list-style: none;
}
.route::before {
  content: ""; position: absolute; top: 15px; height: 3px; border-radius: 2px; background: var(--text);
  left: calc(50% / var(--stops)); right: calc(50% / var(--stops));
}
.stop {
  position: relative; display: grid; justify-items: center; gap: 7px; width: 100%; padding: 0 4px;
  border: 0; background: none; color: var(--text); cursor: pointer;
}
.stop-num {
  display: grid; place-items: center; width: 33px; height: 33px; border-radius: 50%;
  border: 3px solid var(--text); font-weight: 700; font-size: 0.95rem; transition: transform 0.12s;
  background: linear-gradient(to top, color-mix(in oklch, var(--text) 24%, var(--bg)) var(--level), var(--bg) var(--level));
}
.stop:hover .stop-num { transform: scale(1.1); }
.stop.is-on .stop-num { background: var(--text); color: var(--bg); }
.stop-name { max-width: 13ch; font: 600 0.84rem/1.2 var(--label); text-align: center; }
.stop.is-on .stop-name { text-decoration: underline; text-underline-offset: 3px; }
.route-note { margin: 16px 0 0; font-size: 0.92rem; color: var(--muted); }
.route-note .md { display: inline; }

.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 352px; gap: 24px; align-items: start; }
.map-sheet { min-width: 0; padding: 14px 16px 12px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); }
.lines-scroll { overflow-x: auto; overflow-y: hidden; padding-top: 8px; }
.lines { position: relative; }
.lines svg { position: absolute; inset: 0; pointer-events: none; }

.track { fill: none; stroke: var(--line-soft); stroke-width: 7; stroke-linecap: round; }
.track.is-travelled { stroke: var(--line); }
.track.is-open { stroke-dasharray: 0.1 12.4; }
.link { fill: none; stroke: var(--line); stroke-width: 2.4; stroke-linecap: round; }

.line-name { position: absolute; left: 0; display: flex; gap: 10px; align-items: flex-start; }
.line-bullet {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none; border-radius: 50%;
  background: var(--line); color: var(--surface); font-weight: 700;
}
.line-text { display: grid; gap: 1px; padding-top: 1px; }
.line-text strong { font: 600 0.88rem/1.2 var(--label); }
.line-text small { font-size: 0.74rem; color: var(--muted); }

.station { position: absolute; display: grid; justify-items: center; gap: 3px; color: var(--text); text-align: center; }
.station:hover { text-decoration: none; }
.st-dot { position: relative; display: block; width: 40px; height: 40px; border-radius: 50%; transition: transform 0.12s; }
.st-dot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.st-base { fill: var(--surface); }
.st-level { fill: var(--line-soft); }
.st-rim { fill: none; stroke: var(--line); stroke-width: 3; }
.st-code { font: 700 9.5px var(--label); fill: var(--text); }
.st-practice { fill: none; stroke: var(--text); stroke-width: 2; stroke-linecap: round; }
.is-covered .st-level, .is-shown .st-level { fill: var(--line); }
.is-covered .st-code, .is-shown .st-code { fill: var(--surface); }
.st-dot > .ic {
  position: absolute; right: -2px; top: -2px; width: 15px; height: 15px; padding: 2px;
  border-radius: 50%; background: var(--text); color: var(--surface); stroke-width: 3.2;
}
.st-name {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  max-width: 100%; padding: 0 3px; border-radius: 3px; background: var(--surface);
  font: 500 0.76rem/1.18 var(--label); color: var(--muted);
}
.station:hover .st-dot { transform: scale(1.1); }
.station:hover .st-name, .station.is-picked .st-name { color: var(--text); }
.station.is-picked .st-dot { outline: 3px solid var(--text); outline-offset: 2px; }
.station.is-picked .st-name { font-weight: 700; }
.station.is-needed .st-dot { outline: 2px dashed var(--text); outline-offset: 2px; }
.station.is-dim { opacity: 0.2; }

/* The one loud element: where to go next. */
.here-flag {
  position: absolute; left: 50%; top: -16px; transform: translateX(-50%); z-index: 2;
  padding: 1px 8px 2px; border-radius: 3px; background: var(--text); color: var(--surface);
  font: 700 0.7rem/1.3 var(--label); white-space: nowrap;
}
.here-flag::after {
  content: ""; position: absolute; left: 50%; bottom: -3px; width: 7px; height: 7px;
  background: var(--text); transform: translateX(-50%) rotate(45deg);
}
.station.is-here .st-dot::before {
  content: ""; position: absolute; inset: 3px; border-radius: 50%; border: 2px solid var(--text);
  animation: here-pulse 2.6s ease-out infinite; pointer-events: none;
}
@keyframes here-pulse { from { transform: scale(1); opacity: 0.8; } to { transform: scale(1.8); opacity: 0; } }

.map-key {
  display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border); font-size: 0.8rem; color: var(--muted);
}
.key-item { display: inline-flex; align-items: center; gap: 7px; }
.key-item .st-dot { width: 22px; height: 22px; }
.key-track svg { display: block; }

/* The selected station's card. */
.station-card {
  position: sticky; top: calc(var(--top) + 16px); max-height: calc(100vh - var(--top) - 32px); overflow-y: auto;
  padding: 20px 20px 22px; background: var(--surface);
  border: 1px solid var(--border); border-top: 6px solid var(--line); border-radius: 6px 6px 14px 14px;
}
.sc-head { display: flex; gap: 14px; align-items: flex-start; }
.sc-code {
  display: grid; place-items: center; flex: none; width: 54px; height: 54px; border-radius: 50%;
  border: 4px solid var(--line); font: 700 1.02rem var(--label);
}
.sc-head h2 { margin: 3px 0 4px; font-size: 1.24rem; line-height: 1.2; }
.sc-line { margin: 0; font-size: 0.86rem; color: var(--muted); }
.sc-progress { margin: 14px 0 0; font-size: 0.93rem; font-weight: 600; }
.sc-block { margin-top: 20px; }
.sc-block h3 { margin: 0 0 8px; font-size: 0.95rem; }
.sc-block .md { font-size: 0.9rem; }
.sc-block .md + .checks, .sc-block .md + .badge-row { margin-top: 10px; }
.badge-row { display: flex; flex-wrap: wrap; gap: 6px; }
.st-badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 3px; border-radius: 999px;
  border: 1px solid var(--border-strong); color: var(--text); font: 500 0.82rem var(--label);
}
.st-badge b {
  display: grid; place-items: center; min-width: 36px; height: 22px; padding: 0 5px; border-radius: 999px;
  background: var(--line); color: var(--surface); font-size: 0.72rem; font-weight: 700;
}
.st-badge:hover { border-color: var(--text); text-decoration: none; }

.checks.is-compact { gap: 4px; margin: 0; }
.checks.is-compact .check { gap: 10px; padding: 7px 10px; font-size: 0.88rem; }
.checks.is-compact .check input { width: 16px; height: 16px; margin-top: 2px; }
.lesson-row { display: grid; gap: 6px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); color: var(--text); }
.lesson-row:hover { border-color: var(--accent); text-decoration: none; }
.lesson-row + .lesson-row { margin-top: 6px; }
.src { padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); }
.src + .src { margin-top: 6px; }
.src summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; cursor: pointer; font-size: 0.9rem; font-weight: 600; }
.src .md { margin-top: 10px; font-size: 0.86rem; }

@media (max-width: 1180px) {
  .map-layout { grid-template-columns: minmax(0, 1fr); }
  .station-card { position: static; max-height: none; }
}
@media (max-width: 700px) {
  .road.is-graph .road-head h1 { font-size: 1.6rem; }
  .rg-stage { height: calc(100dvh - var(--top) - 190px); }
  .rg-key { max-height: 60%; }
  .rg-route { display: none; }
  .rg-hover { left: 12px !important; right: 12px; top: auto !important; bottom: 12px; width: auto; }
  .rg-card { left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; height: 62%; }
  .rg-stage.has-pick .rg-zoom { right: 14px; }
}
@media (max-width: 700px) {
  .route { grid-template-columns: repeat(4, minmax(0, 1fr)); row-gap: 16px; }
  .route::before { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .station.is-here .st-dot::before { animation: none; opacity: 0; }
}

/* ---------- lessons that explain first: inline checks, figures, diagrams ---------- */

.check-set { margin: 0 0 36px; padding: 16px 20px 18px; border-radius: var(--r); background: var(--surface); }
.check-set > h2 { margin: 0 0 4px; font-size: 1.05rem; }
.check-card { display: grid; gap: 10px; padding-top: 14px; }
.check-card + .check-card { margin-top: 16px; border-top: 1px solid var(--border); }
.check-card h3 { margin: 0; font-size: 0.98rem; }
.check-pad summary { cursor: pointer; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.check-pad[open] summary { margin-bottom: 8px; }
.ratings.is-compact { display: flex; flex-wrap: wrap; gap: 6px; }
.ratings.is-compact .rating { padding: 5px 12px; border-radius: 999px; }
.ratings.is-compact .rating strong { font-size: 0.84rem; }

/* Figures are drawn on white, so they keep a white card in the dark theme too. */
.md img.figure {
  display: block; max-width: 100%; height: auto; margin: 1.2em auto; padding: 10px;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
}
.diagram {
  margin: 1.2em 0; padding: 12px; overflow-x: auto; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.diagram svg { max-width: 100%; height: auto; }

/* ---------- finding lessons: search, and lessons grouped by section ---------- */

.search { position: relative; display: flex; align-items: center; gap: 8px; width: min(300px, 30vw); padding: 0 12px; height: 36px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--bg); color: var(--muted); }
.search:focus-within { border-color: var(--accent); }
.search-input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 0.92rem; }
.search-input::-webkit-search-cancel-button { display: none; }
.search kbd { padding: 0 5px; border: 1px solid var(--border); border-radius: 4px; font: 0.7rem var(--mono); color: var(--muted); }
.search:focus-within kbd { display: none; }
.search-results {
  position: absolute; top: 42px; left: 0; right: 0; z-index: 50; margin: 0; padding: 6px; list-style: none;
  min-width: 320px; max-height: min(70vh, 520px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: var(--shadow);
}
.search-results a { display: grid; grid-template-columns: 54px minmax(0, 1fr); gap: 1px 10px; padding: 7px 9px; border-radius: 8px; color: var(--text); }
.search-results a:hover, .search-results a.is-at { background: var(--accent-soft); text-decoration: none; }
.sr-kind { grid-row: span 2; align-self: center; font-size: 0.72rem; font-weight: 600; color: var(--muted); }
.sr-main { font-size: 0.92rem; font-weight: 600; }
.sr-main b { margin-right: 7px; color: var(--accent); }
.search-results small { font-size: 0.78rem; color: var(--muted); }
.sr-empty { padding: 10px; font-size: 0.9rem; color: var(--muted); }

.sc-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
a.line-name { color: var(--text); }
a.line-name:hover { text-decoration: none; }
a.line-name:hover strong { text-decoration: underline; text-underline-offset: 3px; }

@media (max-width: 860px) {
  .search { width: auto; flex: 1; min-width: 0; position: static; }
  .search kbd, .save-state, .topbar .spacer { display: none; }
  .search-results { position: fixed; top: calc(var(--top) + 4px); left: 8px; right: 8px; min-width: 0; }
  
  
  
}
/* On a phone the search box is an icon until tapped; the nav steps aside while you type. */
@media (max-width: 600px) {
  .search { flex: none; width: 36px; padding: 0; justify-content: center; gap: 0; transition: width 0.2s; }
  .search .search-input { width: 0; flex: 0 1 auto; }
  .search:focus-within { flex: 1; width: auto; padding: 0 12px; gap: 8px; }
  .search:focus-within .search-input { flex: 1; }
  .topbar:has(.search:focus-within) .topnav, .topbar:has(.search:focus-within) .brand { display: none; }
}

/* ---------- side panels that fold away ---------- */

@media (min-width: 861px) {
  .nav-hidden .layout { grid-template-columns: minmax(0, 1fr); }
  .nav-hidden .layout > .sidebar { display: none; }
}

/* ---------- problem and work side by side ---------- */

@container (min-width: 820px) {
  /* Two columns that fill the window below the tabs, split by one line, each
     with a scrollbar of its own when its content is taller than that. */
  .problem-split {
    display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    height: max(420px, calc(100vh - var(--top) - 150px));
  }
  .problem-statement, .problem-split > .work { min-height: 0; overflow-y: auto; }
  .problem-statement { padding-right: 30px; border-right: 1px solid var(--border); }
  .problem .problem-split > .work { margin: 0; padding: 0 2px 24px 30px; border-top: 0; }
}

/* ---------- scratchpad with Vim keys (CodeMirror) ---------- */

.vim-toggle.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.vim-mode { padding: 1px 8px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border-strong); font: 700 0.7rem var(--mono); letter-spacing: 0.04em; color: var(--muted); }

.pad .CodeMirror {
  height: auto; min-height: 120px; border-radius: 0; border: 0;
  background: var(--surface); color: var(--text); font-family: var(--mono); font-size: 0.88rem; line-height: 1.5;
}
.pad .CodeMirror-scroll { min-height: 84px; }
.pad .CodeMirror-gutters { background: var(--surface); border-right: 1px solid var(--border); }
.pad .CodeMirror-linenumber { color: var(--muted); }
.pad .CodeMirror-cursor { border-left-color: var(--text); }
.pad .cm-fat-cursor .CodeMirror-cursor { background: var(--accent); opacity: 0.55; }
.pad .cm-fat-cursor { caret-color: transparent; }
.pad .CodeMirror-selected, .pad .CodeMirror-focused .CodeMirror-selected { background: var(--accent-soft); }
.pad .CodeMirror-dialog { background: var(--surface-2); color: var(--text); border-top: 1px solid var(--border-strong); font-family: var(--mono); }
.pad .CodeMirror-dialog input { color: var(--text); font-family: var(--mono); }

.pad .cm-s-default .cm-keyword, .pad .cm-s-default .cm-builtin, .pad .cm-s-default .cm-atom { color: #7048e8; }
.pad .cm-s-default .cm-string { color: #2b8a3e; }
.pad .cm-s-default .cm-number { color: #c2410c; }
.pad .cm-s-default .cm-comment { color: var(--muted); font-style: italic; }
.pad .cm-s-default .cm-def { color: #1971c2; }
.pad .cm-s-default .cm-variable, .pad .cm-s-default .cm-variable-2, .pad .cm-s-default .cm-property, .pad .cm-s-default .cm-operator { color: var(--text); }
:root[data-scheme="dark"] .pad .cm-s-default .cm-keyword, :root[data-scheme="dark"] .pad .cm-s-default .cm-builtin, :root[data-scheme="dark"] .pad .cm-s-default .cm-atom { color: #b197fc; }
:root[data-scheme="dark"] .pad .cm-s-default .cm-string { color: #8ce99a; }
:root[data-scheme="dark"] .pad .cm-s-default .cm-number { color: #ffa94d; }
:root[data-scheme="dark"] .pad .cm-s-default .cm-def { color: #74c0fc; }

/* A roadmap with one line: its topics as a numbered path. */
.topic-path { display: grid; gap: 4px; margin: 0; padding: 0; list-style: none; }
.path-stop { display: flex; align-items: center; gap: 14px; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.path-stop:hover, .path-stop.is-picked { background: var(--bg); }
.path-stop.is-picked .st-dot { outline: 3px solid var(--text); outline-offset: 2px; }
.path-stop .st-dot { flex: none; }
.path-text { display: grid; gap: 2px; min-width: 0; }

/* ---------- home: the landing scene, then the library ---------- */

.landing {
  position: relative; display: grid; align-items: center; overflow: hidden;
  --h: max(560px, min(calc(100vh - var(--top)), 1400px));
  min-height: var(--h);
  margin-inline: -24px; padding-inline: 24px;
  --x: clamp(24px, 5vw, 120px);
}
/* The scene covers the landing: as wide as the page, or wider when the page is
   short, cropping sky rather than ground. Its left edge fades into the page.
   --ar is the scene's width over height, set when it mounts. */
.scene-art {
  position: absolute; right: 0; bottom: 0; height: auto; width: max(100%, calc(var(--h) * var(--ar, 2))) !important; pointer-events: none; color: var(--muted);
  -webkit-mask-image: linear-gradient(90deg, rgba(0, 0, 0, 0.35) 0, #000 30%), linear-gradient(0deg, #000 calc(var(--h) - 120px), transparent var(--h));
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(90deg, rgba(0, 0, 0, 0.35) 0, #000 30%), linear-gradient(0deg, #000 calc(var(--h) - 120px), transparent var(--h));
  mask-composite: intersect;
}
.scene-words {
  position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none;
  -webkit-mask-image: linear-gradient(90deg, rgba(0, 0, 0, 0.1) 0 26%, #000 50%); mask-image: linear-gradient(90deg, rgba(0, 0, 0, 0.1) 0 26%, #000 50%);
}
/* A soft, uneven glow of the page colour behind the greeting: overlapping ellipses, no straight edge. */
.landing::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 420px 300px at calc(var(--x) + 170px) 42%, color-mix(in srgb, var(--bg) 92%, transparent) 0, color-mix(in srgb, var(--bg) 70%, transparent) 45%, transparent 100%),
    radial-gradient(ellipse 340px 260px at calc(var(--x) + 120px) 66%, color-mix(in srgb, var(--bg) 85%, transparent) 0, transparent 100%),
    radial-gradient(ellipse 300px 160px at calc(var(--x) + 140px) 92%, color-mix(in srgb, var(--bg) 80%, transparent) 0, transparent 100%);
}
.hero-home { position: relative; z-index: 3; width: 100%; padding: 40px 0 96px calc(var(--x) - 24px); }
.hero-home > * { max-width: 360px; }
.hero-home h1 { margin: 0; font-size: clamp(30px, 3vw, 40px); line-height: 1.1; }
.hero-home p { margin: 12px 0 0; font-size: 0.97rem; color: var(--muted); }
.cta { margin-top: 24px; }
.go {
  display: inline-flex; align-items: center; gap: 10px; height: 44px; padding: 0 20px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-size: 0.94rem; font-weight: 500;
}
.go:hover { background: var(--accent); color: var(--accent-ink); text-decoration: none; }
.go .arrow { transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); }
.go:hover .arrow { transform: translateX(3px); }
.shortcuts { display: grid; justify-items: start; gap: 2px; margin-top: 22px; }
.shortcuts a { display: flex; align-items: baseline; gap: 10px; padding: 5px 0; color: var(--text); font-size: 0.92rem; }
.shortcuts a:hover { text-decoration: none; }
.shortcuts a:hover > span:first-child { color: var(--accent); }
.shortcuts .note { font-size: 0.85rem; color: var(--muted); }
.more-hint { display: none; position: absolute; margin-top: 22px; font-size: 0.85rem; color: var(--muted); pointer-events: none; transition: opacity 0.2s; }
/* The shortcuts show while the greeting is hovered, unless Settings says always. Touch screens always show them. */
@media (hover: hover) {
  [data-shortcuts="hover"] .shortcuts { opacity: 0; transform: translateY(-4px); transition: opacity 0.3s, transform 0.3s; }
  [data-shortcuts="hover"] .hero-home:hover .shortcuts, [data-shortcuts="hover"] .shortcuts:focus-within { opacity: 1; transform: none; }
  [data-shortcuts="hover"] .more-hint { display: block; }
  [data-shortcuts="hover"] .hero-home:hover .more-hint, [data-shortcuts="hover"] .hero-home:focus-within .more-hint { opacity: 0; }
}
.quote { position: absolute; z-index: 2; left: var(--x); bottom: 22px; max-width: 360px; margin: 0; cursor: pointer; transition: opacity 0.5s; }
.quote.is-out { opacity: 0; }
.quote blockquote { margin: 0; font-size: 0.92rem; font-style: italic; color: var(--text); }
.quote figcaption { margin-top: 2px; font-size: 0.8rem; color: var(--muted); }
.picker {
  position: absolute; z-index: 2; right: 24px; bottom: 18px; display: flex; align-items: center; gap: 2px; padding: 3px;
  font-size: 0.8rem; border-radius: 18px; background: color-mix(in srgb, var(--bg) 86%, transparent);
}
.picker button, .picker a { border: 0; background: none; padding: 4px 8px; border-radius: 999px; color: var(--muted); cursor: pointer; }
.picker button:hover, .picker a:hover { color: var(--text); text-decoration: none; }
.picker .cur { min-width: 8.5em; text-align: center; color: var(--text); }
.picker .sep { width: 1px; height: 14px; background: var(--border); margin: 0 4px; }

.below { max-width: 1320px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(260px, 1fr); gap: 64px; padding-block: 40px 72px; border-top: 1px solid var(--border); scroll-margin-top: var(--top); }
.sec-h { display: flex; align-items: baseline; justify-content: space-between; margin: 0 0 18px; }
.sec-h h2 { margin: 0; font-size: 0.97rem; font-weight: 500; }
.sec-h span { font-size: 0.82rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.lib-tools { display: flex; flex-wrap: wrap; gap: 4px; margin: -6px 0 14px; }
.lib-tools button { border: 0; background: none; padding: 4px 10px; border-radius: 999px; font-size: 0.82rem; color: var(--muted); cursor: pointer; }
.lib-tools button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }
.lib-branch { display: grid; grid-template-columns: 9rem minmax(0, 1fr); gap: 16px; padding-block: 12px; border-top: 1px solid var(--border); }
.lib-branch:first-child { border-top: 0; padding-top: 0; }
.lib-head { align-self: start; display: grid; gap: 2px; margin-top: 6px; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; font-size: 0.82rem; color: var(--muted); }
.lib-head span { font-size: 0.78rem; color: var(--muted); }
.lib-branch.is-shut .lib-list { display: none; }
.lib-branch.is-shut .lib-head { color: var(--muted); }
.lib-course {
  display: grid; grid-template-columns: minmax(0, 1fr) 132px 3.6em; align-items: center; gap: 18px;
  padding: 6px 10px; margin-inline: -10px; border-radius: var(--radius); color: var(--text);
}
.lib-course:hover { background: var(--surface); text-decoration: none; }
.lib-course .t { font-size: 0.95rem; font-weight: 500; }
.lib-course .s { display: block; font-size: 0.82rem; color: var(--muted); }
/* A branch course sits one step in from the course it grows from. */
.lib-course.is-sub { padding-left: 30px; }
.lib-course.is-planned .t { color: var(--muted); font-weight: 400; }
.lib-course .n { font-size: 0.82rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.track { display: flex; height: 4px; border-radius: 2px; overflow: hidden; background: var(--surface-2); }
.track i { display: block; height: 100%; }
.track .g, .key .g::before { background: var(--green); }
.track .y, .key .y::before { background: var(--yellow); }
.track .r, .key .r::before { background: var(--red); }
.lib-more { margin: 4px 0 0; padding: 4px 0; border: 0; background: none; font-size: 0.82rem; color: var(--muted); cursor: pointer; }
.lib-more:hover { color: var(--text); }
.lib-empty { margin: 0; font-size: 0.9rem; color: var(--muted); }
.key { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 18px; font-size: 0.82rem; color: var(--muted); }
.key span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.grow-hint { margin: 22px 0 0; font-size: 0.82rem; color: var(--muted); }
.grow-hint code { font-size: 0.78rem; }
.recent { list-style: none; margin: 0; padding: 0; }
.recent a { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); font-size: 0.9rem; color: var(--text); }
.recent li:first-child a { border-top: 0; padding-top: 0; }
.recent a:hover { text-decoration: none; color: var(--accent); }
.recent .w { color: var(--muted); }
.recent .d { font-size: 0.82rem; color: var(--muted); }

/* ---------- settings ---------- */

/* Settings has its own sidebar, the same component a course uses. */
.set-shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); align-items: start; margin-inline: -24px; }
.set-main { min-width: 0; padding: 34px 42px 80px; }
.settings { max-width: 760px; }
/* Themes and scenes share the older page's generous workspace. Other settings
   keep their compact reading width, including when the search has no matches. */
.settings:has(.set[data-s="appearance"]:not([hidden])) { max-width: 1320px; }
.settings h1 { font-size: 1.5rem; margin: 0 0 10px; }
.filter {
  display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 8px; margin-bottom: 14px;
  border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--bg); color: var(--muted);
}
.filter:focus-within { border-color: var(--accent); }
.filter input { flex: 1; min-width: 0; border: 0; background: none; color: var(--text); font: inherit; outline: none; }
/* While filtering, every section with a match shows, its title shrunk to a label. */
.settings.is-filtering .set + .set { margin-top: 22px; }
.settings.is-filtering h1 { font-size: 0.83rem; font-weight: 400; color: var(--muted); letter-spacing: 0; margin-bottom: 0; }
.settings.is-filtering .set > .lede { display: none; }
.settings .lede { font-size: 0.97rem; margin-bottom: 4px; }

.opt {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 24px; align-items: center;
  padding: 17px 0; border-bottom: 1px solid var(--border);
}
.opt.is-wide { grid-template-columns: minmax(0, 1fr); gap: 12px; }
.opt .ot { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.opt .od { margin-top: 2px; font-size: 0.9rem; color: var(--muted); max-width: 60ch; }
.opt > .text-input { width: 260px; min-height: 0; padding: 7px 11px; resize: none; }
.opt > select.text-input { width: 200px; }
.text-input.is-mono { font-family: var(--mono); font-size: 0.88rem; }
.opt code.path { font-size: 0.85rem; padding: 2px 6px; border-radius: 4px; background: var(--surface); word-break: break-all; }
.state { display: inline-flex; align-items: center; gap: 4px; font-size: 0.83rem; font-weight: 400; color: var(--muted); }
.state.is-on { color: var(--text); }
.state.is-on .ic { color: var(--green); }
.set-form .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 18px; }
.set-form .check-msg { margin-top: 10px; }
.set .check-msg:empty { display: none; }

/* An on/off switch. */
.toggle { position: relative; width: 34px; height: 20px; padding: 0; border: 0; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background-color 0.15s ease-out; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--bg); transition: transform 0.15s ease-out; }
.toggle[aria-checked="true"] { background: var(--accent); }
.toggle[aria-checked="true"]::after { transform: translateX(14px); }

/* Themes as chips: each one's accent on its page colour. */
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.sw {
  display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px 0 6px;
  border: 1px solid var(--border); border-radius: 999px; background: none; color: var(--muted); cursor: pointer;
}
.sw:hover { color: var(--text); border-color: var(--border-strong); }
.sw[aria-pressed="true"] { color: var(--text); border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.chip-sw {
  width: 20px; height: 20px; border-radius: 50%; flex: none;
  background: radial-gradient(circle, var(--a) 0 4.5px, var(--b) 5px);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 18%, transparent);
}
.chip-sw.is-split { background: radial-gradient(circle, var(--a) 0 4.5px, transparent 5px), linear-gradient(135deg, var(--c) 50%, var(--b) 50%); }
.sw-item { display: inline-flex; align-items: center; }
.sw-item .sw { padding-right: 30px; }
.sw-del { display: grid; place-items: center; width: 22px; height: 22px; margin-left: -27px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; }
.sw-del:hover { color: var(--red); background: var(--hover); }
.theme-tools { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0 0 -8px; }

.scene-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.scene-card { display: grid; gap: 6px; padding: 0; border: 0; background: none; cursor: pointer; text-align: left; font-size: 0.86rem; color: var(--muted); }
.scene-card[aria-pressed="true"] { color: var(--text); }
.scene-card[aria-pressed="true"] .pvw { outline: 2px solid var(--accent); outline-offset: 2px; }
.scene-card .pvw { position: relative; height: 96px; border-radius: var(--r); background: var(--surface); overflow: hidden; color: var(--muted); }
.scene-card .pvw canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.scene-card .nm-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.theme-item { position: relative; display: grid; }
.theme-del { position: absolute; top: 6px; right: 6px; display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: color-mix(in srgb, var(--bg) 80%, transparent); color: var(--muted); cursor: pointer; opacity: 0; transition: opacity 0.15s; }
.theme-item:hover .theme-del, .theme-del:focus-visible { opacity: 1; }
.theme-del:hover { color: var(--red); }
@media (hover: none) { .theme-del { opacity: 1; } }
.check-row { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; font-size: 0.9rem; color: var(--muted); cursor: pointer; }
.check-row input { accent-color: var(--accent); }
.set .field { display: grid; gap: 6px; max-width: 520px; margin-bottom: 16px; }

@media (max-width: 860px) {
  .set-shell { grid-template-columns: minmax(0, 1fr); margin-inline: -16px; }
  .set-side { position: static; width: auto; height: auto; transform: none; box-shadow: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .set-main { padding: 24px 16px 72px; }
  .opt { grid-template-columns: minmax(0, 1fr); }
  .opt > .text-input, .opt > select.text-input { width: 100%; }
  .opt:has(> .toggle) { grid-template-columns: minmax(0, 1fr) auto; }
}

/* While editing, keep theme choices in reach of the live preview on a roomy
   screen. Small or short viewports keep the normal document flow. */
@media (min-width: 1100px) and (min-height: 760px) {
  .set:has(.scene-maker) > .set-theme {
    position: sticky; top: var(--top); z-index: 2; background: var(--bg);
  }
}

/* Making a scene from a picture: give the preview the space left by a bounded
   controls column. Reflow by workspace width, even while the sidebar is open. */
.scene-workspace { container-type: inline-size; }
.scene-maker { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 320px); gap: 24px; margin-top: 18px; padding-top: 20px; border-top: 1px solid var(--border); }
.sm-view { display: grid; gap: 8px; align-content: start; min-width: 0; }
.sm-art { width: 100%; border-radius: var(--radius); background: var(--surface); }
.sm-status { margin: 0; }
.sm-notes { display: grid; gap: 6px; }
.sm-notes p { margin: 0; }
.sm-side { display: grid; gap: 14px; align-content: start; min-width: 0; }
.sm-side .field { margin: 0; }
.sm-ctl { display: grid; gap: 6px; font-size: 0.86rem; color: var(--muted); }
.sm-ctl > span { display: flex; justify-content: space-between; }
.sm-ctl output { font-family: var(--mono); color: var(--text); font-variant-numeric: tabular-nums; }
.sm-ctl input[type="range"] { width: 100%; accent-color: var(--accent); }
.sm-opts { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 999px; justify-self: start; }
.sm-opts button { padding: 4px 12px; border: 0; border-radius: 999px; background: none; color: var(--muted); font: inherit; cursor: pointer; }
.sm-opts button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }
.sm-crop { position: relative; width: min(100%, calc(180px * var(--a, 2))); aspect-ratio: var(--a, 2); border-radius: 8px; overflow: hidden; background: var(--surface); justify-self: start; }
.sm-crop img, .sm-crop video { display: block; width: 100%; height: 100%; object-fit: fill; }
.sm-frame { position: absolute; box-sizing: border-box; border: 2px solid var(--accent); border-radius: 4px; box-shadow: 0 0 0 999px color-mix(in srgb, var(--bg) 55%, transparent); cursor: grab; touch-action: none; }
.sm-frame:active { cursor: grabbing; }
.sm-frame:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
@container (max-width: 900px) { .scene-maker { grid-template-columns: minmax(0, 1fr); } }

@media (max-width: 900px) {
  .below { grid-template-columns: minmax(0, 1fr); gap: 40px; }
  .landing { min-height: 0; align-items: start; }
  .landing::after { display: none; }
  .hero-home { padding-block: 28px 20px; }
  .hero-home > * { max-width: none; }
  .scene-art { top: auto; bottom: 0; height: auto; width: 100% !important; -webkit-mask-image: linear-gradient(180deg, transparent 0, #000 30%); mask-image: linear-gradient(180deg, transparent 0, #000 30%); }
  .scene-words { -webkit-mask-image: linear-gradient(180deg, transparent 0 45%, #000 80%); mask-image: linear-gradient(180deg, transparent 0 45%, #000 80%); }
  .quote { position: static; margin: 4px 0 calc(50vw + 44px); max-width: none; }
  .picker { left: 24px; right: 24px; justify-content: center; }
}
@media (max-width: 600px) {
  .main.is-full { padding: 0 16px; }
  .rg-stage { margin: 0 -16px; }
  .landing { margin-inline: -16px; padding-inline: 16px; }
  .picker { left: 16px; right: 16px; }
  .topbar { gap: 14px; padding: 0 16px; }
  .topnav { gap: 14px; }
  .lib-branch { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .lib-course { grid-template-columns: minmax(0, 1fr) 72px 3em; gap: 10px; }
  .lib-course.mod-line { grid-template-columns: 30px minmax(0, 1fr) 3em; }
  .pnav .sp { flex-basis: 100%; height: 0; }
  .pnav .btn-sm:first-of-type { margin-left: -8px; }
  .rate .field-label { flex-basis: 100%; margin-bottom: 2px; }
  .rate { margin-left: 0; }
  .mod-line > :nth-child(3) { display: none; }
  .branch-group { grid-template-columns: minmax(0, 1fr); gap: 4px; }
}

:is(.sign-in, .enrollment) input { font: inherit; padding: .7rem; border: 1px solid #8791a5; border-radius: .4rem; background: transparent; color: inherit; }
.sign-in { display: grid; gap: 1rem; max-width: 28rem; }
.sign-in label { display: grid; gap: .4rem; }
.enrollment { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; margin-bottom: 1.5rem; }
.enrollment [role="status"] { flex-basis: 100%; }
