/* ============================================================================
 * style.css — one unified, minimal theme.
 * Palette: neutral surfaces + ONE accent. Green/red appear only as functional
 * quiz feedback. Adapts to light/dark automatically.
 * ==========================================================================*/

:root {
  --accent: #4f46e5;
  --bg: #ffffff;
  --surface: #f6f7f9;
  --border: #e4e6eb;
  --text: #1b1d22;
  --muted: #6b7280;
  --ok: #15803d;
  --ok-weak: #eaf6ee;
  --bad: #b91c1c;
  --bad-weak: #fbebeb;
  --warn: #b45309;
  /* soft accent tint derives from the accent automatically, so accent swaps just work */
  --accent-weak: color-mix(in srgb, var(--accent) 13%, var(--bg));
  --radius: 10px;
  --sidebar-w: 270px;
  /* external-link glyph (box + arrow), recoloured via mask to match link colour */
  --ext-link-mask: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%23000'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Cpath%20d='M14%203h7v7'/%3E%3Cpath%20d='M21%203l-9%209'/%3E%3Cpath%20d='M19%2013v6a2%202%200%200%201-2%202H5a2%202%200%200%201-2-2V7a2%202%200%200%201%202-2h6'/%3E%3C/svg%3E");
}

/* dark palette — applied by system preference (unless user forced light),
   and by an explicit data-theme="dark". --accent is set inline by settings.js. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #8b8cf7;
    --bg: #17181c;
    --surface: #1f2127;
    --border: #2e3138;
    --text: #e8e9ec;
    --muted: #9aa0ab;
    --ok: #7ee2a8;
    --ok-weak: #172a1f;
    --bad: #f2a3a3;
    --bad-weak: #2c1a1a;
    --warn: #fbbf24;
  }
}
:root[data-theme="dark"] {
  --accent: #8b8cf7;
  --bg: #17181c;
  --surface: #1f2127;
  --border: #2e3138;
  --text: #e8e9ec;
  --muted: #9aa0ab;
  --ok: #7ee2a8;
  --ok-weak: #172a1f;
  --bad: #f2a3a3;
  --bad-weak: #2c1a1a;
}

* { box-sizing: border-box; }

/* stop the elastic "rubber-band" overscroll bounce at the top/bottom of scroll */
html, body { overscroll-behavior: none; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.9em;
}
h1, h2, h3 { line-height: 1.3; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 32px 40px 80px;
  max-width: 820px;
  margin: 0 auto;   /* center the content column in the available space */
}

/* ---------- sidebar ---------- */
.side-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.side-logo { color: var(--text); display: block; }
.side-logo:hover { text-decoration: none; }
.side-logo:hover .side-title { color: var(--accent); }
.side-title { font-weight: 700; font-size: 1.05rem; }
.side-sub { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.side-header-acts { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  flex-shrink: 0; width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--muted);
  cursor: pointer; font-size: 1rem; line-height: 1; display: grid; place-content: center;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.side-nav { display: flex; gap: 6px; margin: 16px 0; }
.side-nav a {
  flex: 1;
  text-align: center;
  padding: 7px 4px;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  border: 1px solid transparent;
}
.side-nav a:hover { text-decoration: none; background: var(--bg); }
.side-nav a.active { color: var(--accent); background: var(--accent-weak); font-weight: 600; }

.side-progress { margin: 16px 0 20px; }
.progress-label {
  display: flex; justify-content: space-between;
  font-size: 0.78rem; color: var(--muted); margin-bottom: 5px;
}
.progress-track { height: 7px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); transition: width .25s; }

.tree-chapter { margin-bottom: 14px; }
.tree-ch-title {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; margin-bottom: 6px;
}
.tree-sub {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 7px;
}
.tree-sub.active { background: var(--accent-weak); }
.tree-sub.active .tree-sub-link { color: var(--accent); font-weight: 600; }
.tree-sub-link { flex: 1; color: var(--text); font-size: 0.9rem; }
.tree-sub-link:hover { text-decoration: none; }

/* ---------- custom checkbox (unified, rounded) ---------- */
input[type="checkbox"].read-check {
  appearance: none; -webkit-appearance: none; margin: 0;
  width: 18px; height: 18px; flex-shrink: 0; cursor: pointer;
  border: 2px solid var(--border); border-radius: 6px; background: var(--bg);
  display: inline-grid; place-content: center;
  transition: background .15s, border-color .15s;
}
input[type="checkbox"].read-check:hover { border-color: var(--accent); }
input[type="checkbox"].read-check:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"].read-check:checked::before {
  content: '✓'; color: #fff; font-size: 12px; font-weight: 700; line-height: 1;
}

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-size: 0.9rem; cursor: pointer;
  border-radius: 8px; padding: 8px 16px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); transition: background .15s;
}
.btn:hover { background: var(--surface); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.07); }
.btn-ghost { background: transparent; }

/* ---------- notes ---------- */
.note-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.note-title { margin: 0 0 4px; }
.note-crumb { color: var(--muted); font-size: 0.85rem; }
/* ---------- prose / content styling (notes) ---------- */
.note-body { margin-top: 20px; }
.note-body > *:first-child { margin-top: 0; }
.note-body h2 { font-size: 1.4rem; margin: 30px 0 10px; }
.note-body h3 { font-size: 1.15rem; margin: 26px 0 8px; }
.note-body h4 { font-size: 1rem; margin: 22px 0 6px; }
.note-body p { margin: 0 0 14px; }
.note-body ul, .note-body ol { padding-left: 24px; margin: 0 0 14px; }
.note-body li { margin: 4px 0; }
.note-body li > ul, .note-body li > ol { margin: 4px 0; }
.note-body a { text-decoration: underline; text-underline-offset: 2px; }
.note-body hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }
.note-body img { max-width: 100%; height: auto; border-radius: 8px; }
.note-body figure { margin: 16px 0; }
.note-body figcaption { color: var(--muted); font-size: 0.82rem; margin-top: 6px; text-align: center; }
.note-body mark { background: color-mix(in srgb, var(--accent) 22%, var(--bg)); color: inherit; padding: 0 3px; border-radius: 3px; }
.note-body small { color: var(--muted); }

/* quoting */
.note-body blockquote {
  margin: 16px 0; padding: 8px 16px; border-left: 3px solid var(--accent);
  background: var(--surface); border-radius: 0 8px 8px 0;
}
.note-body blockquote p:last-child { margin-bottom: 0; }
.note-body blockquote cite, .note-body blockquote footer {
  display: block; margin-top: 6px; color: var(--muted); font-size: 0.85rem; font-style: normal;
}

/* code blocks + inline code + keys */
.note-body pre {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px; overflow-x: auto; margin: 0 0 16px; line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.88rem;
}
.note-body pre code { background: none; border: none; padding: 0; font-size: inherit; }
.note-body kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8em;
  background: var(--surface); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px;
}

/* tables — .table-wrap is added around each table for horizontal scroll */
.table-wrap { overflow-x: auto; margin: 0 0 16px; border: 1px solid var(--border); border-radius: 10px; }
.note-body table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.note-body th, .note-body td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.note-body thead th { background: var(--surface); font-weight: 600; white-space: nowrap; }
.note-body tbody tr:last-child td { border-bottom: none; }
.note-body tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface) 55%, var(--bg)); }
.note-body caption { caption-side: bottom; color: var(--muted); font-size: 0.82rem; padding-top: 6px; }

/* definition lists */
.note-body dl { margin: 0 0 14px; }
.note-body dt { font-weight: 600; margin-top: 8px; }
.note-body dd { margin: 2px 0 0 16px; }

/* diagrams (from COURSE.diagrams, referenced by id in notes) */
.diagram { margin: 18px 0; }
.diagram-title { font-weight: 600; font-size: 0.92rem; margin-bottom: 10px; }
.diagram-flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: 8px; }
.diagram-flow.vertical { flex-direction: column; align-items: flex-start; }
.diagram-node {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 8px 12px; font-size: 0.88rem; display: flex; align-items: center;
}
.diagram-arrow { color: var(--muted); font-size: 1.15rem; display: flex; align-items: center; }
.diagram-cycle-svg { display: block; width: 100%; max-width: 340px; height: auto; margin: 0 auto; font-family: inherit; }
.dc-ring { fill: none; stroke: var(--border); stroke-width: 2; }
.dc-node { fill: var(--accent); }
.dc-num { fill: #fff; font-size: 12px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
.dc-arrow { fill: var(--accent); }
.dc-center { fill: var(--text); font-size: 13px; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
.diagram-legend { margin: 14px 0 0; padding-left: 22px; font-size: 0.88rem; columns: 2; column-gap: 26px; }
.diagram-legend li { margin: 3px 0; break-inside: avoid; }

/* generic directed graph */
.diagram-scroll { overflow-x: auto; }
.diagram-graph { position: relative; margin: 0 auto; }
.diagram-graph-edges { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.gnode {
  position: absolute; box-sizing: border-box; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  font-size: 0.84rem; line-height: 1.3; text-align: center;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.gnode-rect { border-radius: 3px; }
.gnode-rounded { border-radius: 10px; }
.gnode-stadium { border-radius: 999px; }
.gnode-circle { border-radius: 50%; }
.gnode-ellipse { border-radius: 50% / 62%; }
.gnode-diamond, .gnode-hexagon { border: none; background: var(--accent-weak); color: var(--text); overflow: visible; }
.gnode-diamond { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); padding: 16px 28px; }
.gnode-hexagon { clip-path: polygon(24% 0, 76% 0, 100% 50%, 76% 100%, 24% 100%, 0 50%); padding: 12px 26px; }
.gnode-overflow { outline: 2px dashed var(--bad); outline-offset: 1px; }
.gnode code { background: var(--bg); }
.gedge { stroke: var(--muted); stroke-width: 1.6; }
.gedge-arrow { fill: var(--muted); }
.gedge-label-bg { fill: var(--bg); }
.gedge-label { fill: var(--text); font-size: 11px; text-anchor: middle; dominant-baseline: central; }

/* pyramid (hierarchy) */
.diagram-pyramid-svg { display: block; width: 100%; max-width: 340px; height: auto; margin: 0 auto; }
.pyr-band { stroke: var(--bg); stroke-width: 1.5; }
.pyr-label { fill: var(--text); font-size: 12px; font-weight: 600; text-anchor: middle; dominant-baseline: central; }

/* layout (struct / PE-style table, variable columns per row) */
.diagram-layout { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; font-size: 0.84rem; }
.layout-row { display: flex; align-items: stretch; border-top: 1px solid var(--border); }
.layout-row:first-child { border-top: none; }
.layout-off {
  flex: 0 0 auto; min-width: 56px; padding: 8px 10px; background: var(--surface); color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.78rem;
  display: flex; align-items: center; border-right: 1px solid var(--border);
}
.layout-cells { display: flex; flex: 1; min-width: 0; }
.layout-cell {
  min-width: 0; padding: 8px 10px; text-align: center; border-left: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
}
.layout-cell:first-child { border-left: none; }

/* bar chart — horizontal */
.diagram-bar { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { flex: 0 0 auto; min-width: 84px; font-size: 0.85rem; text-align: right; color: var(--muted); }
.bar-track { flex: 1; height: 18px; background: var(--surface); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 5px; min-width: 2px; }
.bar-value { flex: 0 0 auto; font-size: 0.82rem; font-variant-numeric: tabular-nums; min-width: 34px; }
/* bar chart — vertical */
.diagram-bar-v { display: flex; align-items: flex-end; gap: 14px; height: 200px; padding-top: 6px; }
.barv-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; min-width: 0; }
.barv-value { font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.barv-track { flex: 1; width: 60%; max-width: 46px; display: flex; align-items: flex-end; }
.barv-fill { width: 100%; background: var(--accent); border-radius: 5px 5px 0 0; min-height: 2px; }
.barv-label { font-size: 0.78rem; color: var(--muted); margin-top: 5px; text-align: center; }

/* pie / donut */
.diagram-pie { display: flex; flex-wrap: wrap; align-items: center; gap: 18px; }
.diagram-pie-svg { flex: 0 0 auto; width: 170px; height: 170px; }
.pie-slice { stroke: var(--bg); stroke-width: 1.5; }
.pie-legend { display: flex; flex-direction: column; gap: 5px; font-size: 0.86rem; }
.pie-leg-row { display: flex; align-items: center; gap: 8px; }
.pie-sw { width: 13px; height: 13px; border-radius: 3px; flex: 0 0 auto; }

/* line chart */
.diagram-line-svg { display: block; width: 100%; max-width: 420px; height: auto; }
.diagram-line-svg .axis { stroke: var(--border); stroke-width: 1; }
.diagram-line-svg .axis-label { fill: var(--muted); font-size: 10px; }
.diagram-line-svg .axis-label.ay { text-anchor: end; dominant-baseline: central; }
.diagram-line-svg .axis-label.ax { text-anchor: middle; }
.diagram-line-svg .line-path { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.diagram-line-svg .line-dot { fill: var(--accent); }

/* interactive diagram controls */
.diagram-controls {
  display: flex; flex-wrap: wrap; gap: 12px 20px; margin-bottom: 12px; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.ctrl-row { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.ctrl-label { color: var(--muted); }
.ctrl-range { accent-color: var(--accent); }
.ctrl-input {
  font: inherit; font-size: 0.85rem; padding: 3px 7px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--bg); color: var(--text);
}
.ctrl-input:focus, .ctrl-range:focus { outline: 2px solid var(--accent); }
.ctrl-val { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 2.5em; }

/* lightweight math (no library): equations, variables, fractions */
.equation { text-align: center; margin: 14px 0; font-size: 1.05rem; }
.math { font-family: 'Cambria Math', 'Latin Modern Math', Georgia, 'Times New Roman', serif; font-style: italic; }
.frac { display: inline-flex; flex-direction: column; text-align: center; vertical-align: middle; line-height: 1.05; font-size: 0.92em; margin: 0 .15em; }
.frac > .num { border-bottom: 1px solid currentColor; padding: 0 .35em; }
.frac > .den { padding: 0 .35em; }

/* callouts / admonitions:  <div class="callout tip"><div class="callout-title">Tip</div>…</div> */
.callout {
  margin: 16px 0; padding: 12px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--muted);
}
.callout > :first-child { margin-top: 0; }
.callout > :last-child { margin-bottom: 0; }
.callout-title { font-weight: 700; font-size: 0.9rem; margin-bottom: 4px; }
.callout.note { border-left-color: var(--accent); }
.callout.note .callout-title { color: var(--accent); }
.callout.tip { border-left-color: var(--ok); }
.callout.tip .callout-title { color: var(--ok); }
.callout.warning { border-left-color: var(--warn); }
.callout.warning .callout-title { color: var(--warn); }
.callout.danger { border-left-color: var(--bad); }
.callout.danger .callout-title { color: var(--bad); }

.read-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  cursor: pointer; white-space: nowrap; font-size: 0.9rem; background: var(--bg);
}
.read-toggle.done { border-color: var(--ok); color: var(--ok); background: var(--ok-weak); }
.read-toggle.done .read-check:checked { background: var(--ok); border-color: var(--ok); }

.section-divider {
  margin: 40px 0 20px; padding-top: 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;
}
.section-divider h2 { margin: 0; font-size: 1.25rem; }

/* ---------- quiz filter ---------- */
.quiz-filter { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filter-label {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
  color: var(--muted); margin-right: 4px; min-width: 40px;
}
.filter-chip {
  font: inherit; font-size: 0.78rem; cursor: pointer;
  padding: 5px 11px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--bg); color: var(--muted);
}
.filter-chip.active { background: var(--accent-weak); color: var(--accent); border-color: var(--accent); font-weight: 600; }

/* ---------- quiz card ---------- */
.quiz-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px; background: var(--surface);
}
.quiz-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.quiz-type {
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
  color: var(--accent); background: var(--accent-weak); padding: 3px 9px; border-radius: 99px;
}
.quiz-stats { font-size: 0.75rem; color: var(--muted); text-align: right; }
.quiz-prompt { font-weight: 600; margin: 4px 0 14px; }
.quiz-actions { margin-top: 14px; display: flex; gap: 8px; align-items: center; }
.kbd-hint { font-size: 0.72rem; color: var(--muted); }
.quiz-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a.btn, a.btn:hover { text-decoration: none; }

.quiz-feedback { margin-top: 12px; font-size: 0.9rem; }
.quiz-feedback.ok { color: var(--ok); }
.quiz-feedback.bad { color: var(--bad); }
.quiz-feedback .explain { color: var(--text); margin-top: 6px; font-weight: 400; }
.quiz-error { color: var(--bad); }

/* ---------- MCQ ---------- */
.q-options { display: flex; flex-direction: column; gap: 8px; }
.opt {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); font: inherit; font-size: 0.92rem; color: var(--text); cursor: pointer;
}
.opt:hover { border-color: var(--accent); }
.opt.chosen { border-color: var(--accent); background: var(--accent-weak); }
.opt-mark { color: var(--accent); width: 1em; }
.opt.correct { border-color: var(--ok); background: var(--ok-weak); }
.opt.incorrect { border-color: var(--bad); background: var(--bad-weak); }
.opt:disabled { cursor: default; }

/* ---------- chips / slots / bins (fill, matching, categorize) ---------- */
.chip {
  display: inline-block; padding: 6px 12px; margin: 3px;
  background: var(--accent-weak); color: var(--accent); border: 1px solid var(--accent);
  border-radius: 7px; cursor: grab; user-select: none; font-size: 0.88rem;
}
.chip.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip.dragging { opacity: .5; }
.chip.correct { background: var(--ok-weak); color: var(--ok); border-color: var(--ok); }
.chip.incorrect { background: var(--bad-weak); color: var(--bad); border-color: var(--bad); }

.bank {
  display: flex; flex-wrap: wrap; gap: 4px; min-height: 44px;
  padding: 8px; border: 1px dashed var(--border); border-radius: 8px; background: var(--bg);
}
.bank-label { font-size: 0.78rem; color: var(--muted); margin: 12px 0 6px; }
.drop-hover { border-color: var(--accent) !important; background: var(--accent-weak) !important; }

.slot {
  display: inline-block; min-width: 90px; min-height: 30px; vertical-align: middle;
  padding: 2px 6px; margin: 0 2px; border-bottom: 2px solid var(--accent);
  background: var(--bg); border-radius: 5px 5px 0 0;
}
.slot.correct { border-color: var(--ok); background: var(--ok-weak); }
.slot.incorrect { border-color: var(--bad); background: var(--bad-weak); }
.fill-line { font-size: 1rem; line-height: 2.4; }

.match-grid { display: flex; flex-direction: column; gap: 8px; }
.match-row { display: flex; align-items: center; gap: 12px; }
.match-left {
  min-width: 130px; font-weight: 600; padding: 8px 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
.match-row .slot { flex: 1; min-height: 36px; border-bottom-width: 2px; }

.bins { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.bin { flex: 1; min-width: 160px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.bin-title {
  font-weight: 600; font-size: 0.85rem; padding: 8px 12px;
  background: var(--accent-weak); color: var(--accent);
}
.bin-drop { min-height: 70px; padding: 8px; display: flex; flex-wrap: wrap; gap: 4px; align-content: flex-start; }

/* ---------- ranking ---------- */
.rank-list { display: flex; flex-direction: column; gap: 6px; }
.rank-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); cursor: grab;
}
.rank-item.dragging { opacity: .5; }
.rank-item.correct { border-color: var(--ok); background: var(--ok-weak); }
.rank-item.incorrect { border-color: var(--bad); background: var(--bad-weak); }
.rank-handle { color: var(--muted); cursor: grab; }
.rank-text { flex: 1; }
.rank-btns button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 5px; cursor: pointer; font-size: 0.7rem; width: 24px; height: 22px; line-height: 1;
}
.rank-btns button:disabled { opacity: .4; cursor: default; }

/* ---------- dashboard ---------- */
.dash-header { margin-bottom: 24px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 28px; }
.stat-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; background: var(--surface); }
.stat-value { font-size: 1.8rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.82rem; margin-top: 2px; }

.dash-section { margin-bottom: 32px; }
.dash-section h2 { font-size: 1.15rem; border-bottom: 1px solid var(--border); padding-bottom: 8px; }

.chapter-progress { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.chapter-progress .name { min-width: 200px; font-size: 0.9rem; }
.chapter-progress .progress-track { flex: 1; }
.chapter-progress .count { font-size: 0.8rem; color: var(--muted); width: 44px; text-align: right; }

table.quiz-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.quiz-table th, table.quiz-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.quiz-table th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: .04em; }
.acc-pill { padding: 2px 8px; border-radius: 99px; font-size: 0.78rem; font-weight: 600; }
.acc-good { background: var(--ok-weak); color: var(--ok); }
.acc-mid { background: var(--accent-weak); color: var(--accent); }
.acc-bad { background: var(--bad-weak); color: var(--bad); }

.data-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.dash-version { margin-top: 32px; color: var(--muted); font-size: 0.76rem; }

/* study plan (exam / deadlines) */
.study-plan { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; background: var(--surface); }
.study-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.study-head-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.plan-add { margin-bottom: 24px; }
.plan-exam-row { display: flex; gap: 8px; flex-wrap: wrap; }
.plan-exam-row .auth-input { flex: 1; min-width: 120px; }
.plan-edit-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; margin-bottom: 6px; }
.plan-edit-title { font-size: 0.88rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.plan-edit-row .auth-input { padding: 5px 8px; }
.plan-modal { max-width: 460px; }
.study-head h2 { margin: 0; border: none; padding: 0; font-size: 1.15rem; }
.exam-countdown { font-size: 0.82rem; font-weight: 600; padding: 4px 12px; border-radius: 99px; background: var(--accent-weak); color: var(--accent); }
.exam-countdown.soon { background: color-mix(in srgb, var(--warn) 18%, var(--bg)); color: var(--warn); }
.exam-countdown.over { background: var(--bad-weak); color: var(--bad); }
.plan-list { display: flex; flex-direction: column; }
.plan-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 9px 8px; border-top: 1px solid var(--border); color: var(--text);
}
.plan-row:first-child { border-top: none; }
.plan-row:hover { text-decoration: none; background: var(--bg); border-radius: 6px; }
.plan-row.done .plan-title { color: var(--muted); }
.plan-left { display: flex; align-items: center; gap: 9px; min-width: 0; flex-wrap: wrap; }
.plan-title { font-size: 0.92rem; }
.plan-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.plan-read { font-size: 0.8rem; color: var(--muted); }
.plan-due { font-size: 0.74rem; color: var(--muted); }
.plan-due.soon { color: var(--warn); font-weight: 600; }
.plan-due.over { color: var(--bad); font-weight: 600; }

/* priority badges (sidebar + study plan) */
.pri-badge {
  font-size: 0.6rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 700;
  padding: 1px 6px; border-radius: 99px; margin-left: 6px; white-space: nowrap;
}
.pri-high { background: var(--bad-weak); color: var(--bad); }
.pri-medium { background: color-mix(in srgb, var(--warn) 18%, var(--bg)); color: var(--warn); }
.pri-low { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.tree-ch-title { display: flex; align-items: center; }

.chapter-progress .name a { color: var(--text); }
.chapter-progress .name a:hover { color: var(--accent); }

/* ---------- chapter-page layout (all subchapters on one page) ---------- */
.chapter-section { scroll-margin-top: 20px; padding-top: 8px; }
.chapter-section + .chapter-section { border-top: 1px solid var(--border); margin-top: 36px; padding-top: 28px; }
.sub-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 8px; }
.sub-head h2 { margin: 0; font-size: 1.3rem; }

/* ---------- settings modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(0,0,0,.45);
}
.modal {
  width: 100%; max-width: 420px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 14px; padding: 24px;
  box-shadow: 0 24px 70px rgba(0,0,0,.35);
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; }
.modal h2 { margin: 0; font-size: 1.2rem; }
.modal-sub { color: var(--muted); font-size: 0.82rem; margin: 2px 0 20px; }
.modal-close { border: none; background: none; color: var(--muted); font-size: 1.4rem; line-height: 1; cursor: pointer; }
.modal-close:hover { color: var(--text); }

.setting-group { margin-bottom: 20px; }
.setting-group > .setting-label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 8px; }
.setting-hint { color: var(--muted); font-size: 0.76rem; margin-top: 6px; }

.segmented { display: flex; gap: 6px; }
.segmented button {
  flex: 1; padding: 8px 6px; border: 1px solid var(--border); background: var(--bg);
  border-radius: 8px; cursor: pointer; font: inherit; font-size: 0.82rem; color: var(--text);
}
.segmented button.active { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.swatches { display: flex; gap: 12px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; box-shadow: 0 0 0 1px var(--border);
}
.swatch.active { border-color: var(--bg); box-shadow: 0 0 0 2px var(--accent); }

/* ---------- keyboard shortcuts help ---------- */
.shortcut-list { display: flex; flex-direction: column; gap: 7px; }
.shortcut-row { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; }
.shortcut-row kbd {
  flex-shrink: 0; min-width: 74px; text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.78rem;
  background: var(--surface); border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 6px; padding: 3px 8px; color: var(--text);
}

/* ---------- glossary page ---------- */
.gloss-search {
  width: 100%; padding: 10px 14px; font: inherit; font-size: 0.95rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text);
  margin: 8px 0 20px;
}
.gloss-search:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.gloss-index { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 22px; }
.gloss-index a {
  display: inline-grid; place-content: center; min-width: 28px; height: 28px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 0.8rem; color: var(--muted);
}
.gloss-index a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
.gloss-group { margin-bottom: 22px; scroll-margin-top: 16px; }
.gloss-letter {
  font-size: 0.9rem; font-weight: 700; color: var(--accent);
  border-bottom: 1px solid var(--border); padding-bottom: 4px; margin-bottom: 8px;
}
.gloss-item { padding: 8px 12px; border-radius: 8px; scroll-margin-top: 16px; }
.gloss-item.flash { animation: gloss-flash 1.2s ease; }
@keyframes gloss-flash { from { background: var(--accent-weak); } to { background: transparent; } }
.gloss-term-name { font-weight: 700; }
.gloss-def { color: var(--text); }
.gloss-see { font-size: 0.82rem; color: var(--muted); margin-top: 4px; }

/* ---------- reference page ---------- */
.ref-item { padding: 9px 12px; border-radius: 8px; }
.ref-item + .ref-item { border-top: 1px solid var(--border); }
.ref-top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ref-title { font-weight: 600; }
.ref-type {
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
  background: var(--accent-weak); color: var(--accent); padding: 2px 7px; border-radius: 99px;
}
.ref-host { font-size: 0.78rem; color: var(--muted); }
.ref-desc { color: var(--muted); font-size: 0.86rem; margin-top: 3px; }

/* ---------- glossary term inside notes (auto-linked) ---------- */
.gloss-term {
  color: inherit; text-decoration: none; cursor: help; position: relative;
  border-bottom: 1px dashed var(--accent);
}
.gloss-term:hover, .gloss-term:focus-visible { color: var(--accent); }
.gloss-term:hover::after, .gloss-term:focus-visible::after {
  content: attr(data-def); position: absolute; left: 0; top: calc(100% + 8px); z-index: 10;
  width: max-content; max-width: min(320px, 80vw); white-space: normal;
  background: var(--text); color: var(--bg); font-size: 0.8rem; font-weight: 400; line-height: 1.45;
  padding: 8px 11px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.28); pointer-events: none;
}

/* ---------- content-validator banner (authoring aid) ---------- */
.validate-banner {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 16px; z-index: 60;
  width: min(680px, calc(100% - 32px)); max-height: 50vh; overflow: auto;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.3); padding: 12px 14px; font-size: 0.85rem;
}
.validate-banner.has-errors { border-color: var(--bad); }
.validate-banner.has-warns { border-color: var(--accent); }
.vb-head { display: flex; align-items: center; gap: 10px; }
.vb-head strong { flex: 1; }
.vb-head button {
  font: inherit; font-size: 0.78rem; cursor: pointer; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text);
}
.vb-list { margin: 10px 0 2px; padding-left: 18px; }
.vb-list li { margin: 3px 0; }
.vb-error { color: var(--bad); }
.vb-warn { color: var(--muted); }

/* ---------- auth (login) ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.auth-title { margin: 0 0 4px; font-size: 1.4rem; }
.auth-sub { margin: 0 0 18px; color: var(--muted); font-size: 0.88rem; }
.auth-label { display: block; font-size: 0.8rem; font-weight: 600; margin: 12px 0 5px; }
.auth-input {
  width: 100%; padding: 9px 12px; font: inherit; font-size: 0.95rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text);
}
.auth-input:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.auth-btn { width: 100%; margin-top: 18px; }
.auth-error { margin-top: 12px; color: var(--bad); font-size: 0.85rem; background: var(--bad-weak); border-radius: 8px; padding: 8px 10px; }

/* ---------- signed-in user block in sidebar ---------- */
.side-user { margin: 16px 0 4px; padding-top: 14px; border-top: 1px solid var(--border); }
.side-who { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.side-who-name { font-weight: 600; }
.side-who-role {
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
  background: var(--accent-weak); color: var(--accent); padding: 2px 7px; border-radius: 99px;
}
.side-user-acts { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; margin-top: 6px; }
.side-user-link {
  background: none; border: none; padding: 2px 0; font: inherit; font-size: 0.82rem;
  color: var(--muted); cursor: pointer; text-align: left;
}
.side-user-link:hover { color: var(--accent); text-decoration: none; }

/* ---------- admin page ---------- */
.admin-main { max-width: 820px; margin: 0 auto; }
.admin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.admin-head-actions { display: flex; gap: 8px; }
.admin-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.admin-form .auth-input { width: auto; flex: 1; min-width: 140px; }
.admin-form select.auth-input { flex: 0 0 auto; min-width: 90px; }
.admin-msg { margin-top: 10px; font-size: 0.85rem; }
.admin-msg.ok { color: var(--ok); }
.admin-msg.bad { color: var(--bad); }
.btn-sm { padding: 4px 10px; font-size: 0.78rem; }
#usersTable td:last-child { display: flex; gap: 6px; }

/* ---------- resources group (glossary / reference / cheat sheet) ---------- */
.side-resources { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.side-res-title {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; margin-bottom: 6px;
}
.side-res-link {
  display: block; padding: 5px 8px; border-radius: 7px; font-size: 0.9rem; color: var(--text);
}
.side-res-link:hover { background: var(--bg); text-decoration: none; }
.side-res-link.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }

/* ---------- external-link icon (auto-appended to new-tab links) ---------- */
a[target="_blank"]::after {
  content: ""; display: inline-block; width: 0.66em; height: 0.66em;
  margin-left: 0.2em; vertical-align: -0.02em; background-color: currentColor; opacity: 0.55;
  -webkit-mask: var(--ext-link-mask) center / contain no-repeat;
          mask: var(--ext-link-mask) center / contain no-repeat;
}
a[target="_blank"].no-ext-icon::after { content: none; }

/* ---------- cheat sheet ---------- */
.cheat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.cheat-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; background: var(--surface); }
.cheat-section {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
  color: var(--accent); margin-bottom: 10px;
}
.cheat-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 5px 0; border-top: 1px solid var(--border); }
.cheat-row:first-of-type { border-top: none; }
.cheat-label { color: var(--muted); font-size: 0.86rem; flex-shrink: 0; }
.cheat-val { text-align: right; }
.cheat-val code { background: var(--bg); }

/* ---------- desktop sidebar collapse ---------- */
@media (min-width: 820px) {
  body.sidebar-collapsed .sidebar { display: none; }
  body.sidebar-collapsed .menu-toggle { display: block; }
}

/* ---------- responsive ---------- */
.menu-toggle {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 30;
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  width: 42px; height: 42px; font-size: 1.2rem; cursor: pointer;
}
@media (max-width: 819px) {
  .menu-toggle { display: block; }
  .collapse-btn { display: none; }   /* mobile uses the overlay toggle, not collapse */
  .sidebar {
    position: fixed; z-index: 20; height: 100vh; left: 0; top: 0;
    transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 64px 20px 60px; margin: 0; }
  .match-left { min-width: 90px; }
}

/* ---------- checklist page ---------- */
.chk-overall { margin: 10px 0 4px; }
.chk-bar { height: 8px; border-radius: 6px; background: var(--accent-weak); overflow: hidden; }
.chk-bar-fill { height: 100%; background: var(--accent); border-radius: 6px; transition: width .2s; width: 0; }
.chk-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0 18px; flex-wrap: wrap; }
.chk-hide { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; cursor: pointer; }
.chk-group-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.chk-count { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.chk-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); margin: 6px 0; cursor: pointer; transition: background .12s, border-color .12s; }
.chk-row:hover { border-color: var(--accent); }
.chk-row.done { background: var(--accent-weak); }
.chk-row.done .chk-title { color: var(--muted); text-decoration: line-through; }
.chk-box { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.chk-body { display: flex; flex-direction: column; gap: 2px; }
.chk-title { color: var(--text); font-size: 0.92rem; line-height: 1.35; }
.chk-note { color: var(--muted); font-size: 0.78rem; }
