/* Design v2 (2026-12-03), loaded after the other stylesheets. Shell inspired by Linear (dark, quiet, one accent),
   lesson pages inspired by Stripe Docs (wide readable column, clean code). v1 is archived in design/v1 (git tag design-v1).
   Fonts: IBM Plex Sans / Plex Mono, self-hosted in fonts/ (SIL OFL). */
@font-face { font-family: "Plex"; src: url("../fonts/ibm-plex-sans-400-normal.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex"; src: url("../fonts/ibm-plex-sans-400-italic.woff2") format("woff2"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Plex"; src: url("../fonts/ibm-plex-sans-500-normal.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex"; src: url("../fonts/ibm-plex-sans-600-normal.woff2") format("woff2"); font-weight: 600 800; font-style: normal; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("../fonts/ibm-plex-mono-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex Mono"; src: url("../fonts/ibm-plex-mono-500-normal.woff2") format("woff2"); font-weight: 500 700; font-display: swap; }

:root {
  --bg: #0c0d0f;          /* app frame and sidebar */
  --panel: #111214;       /* main panel */
  --bg-elev: #17181b;     /* cards */
  --bg-sunk: #1c1d21;     /* hover, wells */
  --border: #232428;
  --border-strong: #303237;
  --text: #e6e6e8;
  --text-muted: #8a8c93;
  --text-faint: #5f6168;
  --accent: #8a8ff0;
  --accent-strong: #6d73e6;
  --accent-soft: rgba(138, 143, 240, 0.12);
  --good: #4cb782; --good-soft: rgba(76, 183, 130, 0.12);
  --mid: #e0a24a; --mid-soft: rgba(224, 162, 74, 0.12);
  --bad: #eb5757; --bad-soft: rgba(235, 87, 87, 0.12);
  --code-bg: #0e0f11;
  --radius: 8px;
  --sidebar: 244px;
  --sans: "Plex", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
[data-theme="light"] {
  --bg: #f4f4f5; --panel: #ffffff; --bg-elev: #ffffff; --bg-sunk: #f1f1f3;
  --border: #e6e6e9; --border-strong: #d4d4d8;
  --text: #18181b; --text-muted: #63636b; --text-faint: #9a9aa2;
  --accent: #5b5fd6; --accent-strong: #4b4fc4; --accent-soft: rgba(91, 95, 214, 0.09);
  --good: #1f8a5b; --good-soft: rgba(31, 138, 91, 0.09); --mid: #b26b00; --mid-soft: rgba(178, 107, 0, 0.09);
  --bad: #d23b3b; --bad-soft: rgba(210, 59, 59, 0.08); --code-bg: #f7f7f8;
}

html, body { background: var(--bg); font: 14px/1.55 var(--sans); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
code, pre, textarea.mono { font-family: var(--mono); }
h1, h2, h3 { font-weight: 600; letter-spacing: -0.012em; }
h1 { font-size: 24px; } h2 { font-size: 19px; } h3 { font-size: 15.5px; }
h4 { font-size: 11.5px; font-weight: 500; letter-spacing: 0.06em; }
a { color: var(--accent); }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

/* ---------------------------------------------------------------- shell: sidebar on the frame, content in a panel */
#sidebar { background: var(--bg); border-right: 0; padding: 12px 10px 32px; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
#content { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; margin: 8px 8px 8px 0; min-height: calc(100vh - 16px); }
#topbar { background: color-mix(in srgb, var(--panel) 85%, transparent); border-bottom: 1px solid var(--border); padding: 8px 20px; border-radius: 12px 12px 0 0; top: 0; }
#main { max-width: 1480px; margin: 0 auto; padding: 32px 48px 96px; }

.brand { padding: 4px 8px 16px; gap: 9px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: #f2c94c; color: #0c0d0f; font-size: 12px; font-weight: 700; font-family: var(--mono); }
.brand-text { font-weight: 600; font-size: 14px; letter-spacing: -0.01em; }
.brand-text small { display: none; }

.nav-group { display: flex; flex-direction: column; gap: 1px; margin-bottom: 14px; }
.nav-item, .nav-module, .nav-topic { padding: 5px 8px; border-radius: 6px; font-size: 13.5px; color: var(--text-muted); gap: 9px; }
.nav-item { font-weight: 500; }
.nav-item:hover, .nav-module:hover, .nav-topic:hover { background: var(--bg-sunk); color: var(--text); }
.nav-item.active, .nav-module.active, .nav-topic.active { background: var(--bg-sunk); color: var(--text); }
.nav-item .icon { color: var(--text-faint); }
.nav-item.active .icon, .nav-item:hover .icon { color: var(--text); }
.nav-key { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; background: none; }
.nav-count { background: var(--bg-sunk); color: var(--text-muted); border: 1px solid var(--border-strong); font-weight: 500; }
.nav-label { margin: 6px 8px 4px; font-size: 11.5px; letter-spacing: 0; text-transform: none; color: var(--text-faint); font-weight: 500; }
.nav-track { font-size: 12.5px; font-weight: 500; color: var(--text-muted); text-transform: none; letter-spacing: 0; }
.nav-topic { font-size: 12.5px; }

.icon { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-button { display: inline-grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 1px solid transparent; border-radius: 7px; color: var(--text-muted); background: none; }
.icon-button:hover { background: var(--bg-sunk); color: var(--text); border-color: var(--border); }
.lang-toggle { width: auto; padding: 0 8px; font-size: 12px; font-weight: 500; }
#account-button.signed-in { color: var(--accent); border-color: transparent; background: var(--accent-soft); }

/* Search as a command bar */
#search-form { max-width: 440px; }
#search-input { background: var(--bg-sunk); border: 1px solid var(--border); border-radius: 7px; padding: 6px 12px; font-size: 13px; }
#search-input::placeholder { color: var(--text-faint); }
#search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------------------------------------------------------------- generic pieces */
.page-head { margin-bottom: 24px; }
.page-head h1 { margin-bottom: 4px; }
.page-sub { font-size: 14px; }
.card { background: var(--bg-elev); border-color: var(--border); border-radius: 10px; padding: 18px 20px; }
[data-theme="light"] .card { box-shadow: 0 1px 2px rgba(16, 16, 20, 0.04); }
.hero { background: var(--bg-elev); border-radius: 12px; border-top: 1px solid var(--border) !important; }
.eyebrow { color: var(--text-muted); font-weight: 500; letter-spacing: 0.04em; font-size: 11.5px; }
.callout { background: var(--bg-sunk); border-left: 2px solid var(--accent); border-radius: 0 6px 6px 0; }
.callout.warn { background: var(--mid-soft); }

.btn { border-radius: 7px; padding: 6px 13px; font-size: 13.5px; font-weight: 500; background: var(--bg-sunk); border-color: var(--border-strong); }
.btn:hover { border-color: var(--text-faint); background: var(--border); }
.btn-primary, .btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); filter: none; }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; }
.pill { border-radius: 6px; padding: 2px 8px; background: var(--bg-sunk); font-size: 12px; }
.badge { border-radius: 6px; font-weight: 500; }
.tag { border-radius: 5px; background: var(--bg-sunk); }
.chip { border-radius: 6px; }
.tile { background: var(--bg-elev); border-radius: 10px; padding: 14px 16px; }
.tile-label { font-size: 12px; }
.tile-value { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.bar { height: 4px; background: var(--bg-sunk); }
.bar-fill { background: var(--accent); }
.list-row:hover, .path-module:hover, .module-tile:hover { background: var(--bg-sunk); border-color: var(--border-strong); }
.module-tile { border-top-width: 2px; border-radius: 8px; }
table { font-size: 13.5px; }
th { font-weight: 500; color: var(--text-muted); }
.num-input, .text-input { background: var(--bg-sunk); border-color: var(--border); border-radius: 7px; }
.num-input:focus, .text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------------------------------------------------------------- tabs: underline like docs */
.tabs { gap: 2px; }
.tab { padding: 8px 12px; font-size: 13.5px; font-weight: 500; }
.tab.active { color: var(--text); border-bottom-color: var(--text); }

/* ---------------------------------------------------------------- lessons: Stripe-Docs-like reading */
.lesson-layout { grid-template-columns: minmax(0, 1fr) 230px; gap: 48px; }
.lesson { font-size: 16px; line-height: 1.72; color: var(--text); }
.lesson .md > p, .lesson .md > ul, .lesson .md > ol, .lesson .md > blockquote { max-width: 80ch; }
.lesson .md h2 { font-size: 22px; margin: 2.2em 0 0.6em; padding-top: 0.2em; }
.lesson .md h3 { font-size: 17px; margin: 1.8em 0 0.5em; }
.lesson .md li { margin: 0.25em 0; }
.md code { font-size: 0.86em; background: var(--bg-sunk); border: 1px solid var(--border); border-radius: 5px; padding: 0.08em 0.38em; }
.md pre, pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px; line-height: 1.6; }
.md pre code { font-size: 13.5px; }
.lesson .md table { font-size: 14.5px; }
.toc { top: 84px; border-left: 1px solid var(--border); padding-left: 16px; gap: 2px; font-size: 13px; }
.toc a { color: var(--text-muted); padding: 2px 0; line-height: 1.4; }
.toc a:hover { color: var(--text); }
.toc-title { color: var(--text-faint); letter-spacing: 0.04em; font-weight: 500; }

/* Reading progress (idea from Execute Program): a thin line under the top bar on lesson pages. */
#read-progress { position: sticky; top: 54px; z-index: 6; height: 2px; margin-top: -2px; background: transparent; pointer-events: none; }
#read-progress > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s linear; }

/* ---------------------------------------------------------------- account: a real sign-in page */
.auth-page { min-height: calc(100vh - 220px); display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 380px; display: grid; gap: 12px; padding: 32px 30px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 14px; }
.auth-card .auth-mark { width: 40px; height: 40px; border-radius: 10px; background: #f2c94c; color: #0c0d0f; font: 700 16px var(--mono); display: grid; place-items: center; margin: 0 auto 4px; }
.auth-card h1 { text-align: center; font-size: 21px; margin: 0; }
.auth-card .auth-sub { text-align: center; color: var(--text-muted); margin: 0 0 8px; font-size: 13.5px; }
.auth-card .text-input { width: 100%; padding: 9px 12px; font-size: 14px; }
.auth-card .btn { justify-content: center; width: 100%; padding: 9px 14px; }
.auth-card .account-actions { display: grid; gap: 8px; margin: 2px 0 0; }
.auth-card .link-button { justify-self: center; font-size: 13px; color: var(--text-muted); }
.auth-card .account-or { display: flex; align-items: center; gap: 10px; color: var(--text-faint); }
.auth-card .account-or::before, .auth-card .account-or::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.auth-card .small { text-align: center; color: var(--text-faint); line-height: 1.5; }

/* ---------------------------------------------------------------- overlays */
.help-box { background: var(--bg-elev); border-radius: 14px; box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55); }

@media (max-width: 860px) {
  #content { margin: 0; border-radius: 0; border: 0; min-height: 100vh; }
  #topbar { border-radius: 0; top: 0; }
  #main { padding: 20px 16px 72px; }
  .lesson { font-size: 15.5px; }
  #read-progress { top: 46px; }
}

/* Read sections in the table of contents: a drawn check (the ✓ glyph fell back to a colour emoji). */
.toc a.read::after { content: ''; display: inline-block; width: 4px; height: 8px; margin-left: 7px; border: solid var(--good); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg) translateY(-2px); }

/* Anecdotes and history boxes: a full-width card that opens in place. The text inside uses the whole card
   (the 80ch reading cap is for the lesson's own paragraphs, not for these boxes). */
.anecdote, .history { margin: 18px 0; padding: 0; background: var(--bg-elev); border: 1px solid var(--border); border-left: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.anecdote summary, .history summary { list-style: none; display: flex; align-items: baseline; gap: 10px; padding: 12px 16px; cursor: pointer; font-size: 14.5px; font-weight: 500; color: var(--text); }
.anecdote summary::-webkit-details-marker, .history summary::-webkit-details-marker { display: none; }
.anecdote summary::after, .history summary::after { content: ''; margin-left: auto; align-self: center; width: 7px; height: 7px; border: solid var(--text-faint); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg) translateY(-2px); transition: transform 0.15s; flex-shrink: 0; }
.anecdote[open] summary::after, .history[open] summary::after { transform: rotate(-135deg) translateY(-1px); }
.anecdote summary:hover, .history summary:hover { color: var(--text); background: var(--bg-sunk); }
.anecdote[open] summary, .history[open] summary { margin: 0; border-bottom: 1px solid var(--border); }
.anecdote-kind { flex-shrink: 0; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; padding: 2px 7px; border-radius: 5px; color: #b9a3f0; background: rgba(185, 163, 240, 0.12); margin: 0; }
.history .anecdote-kind { color: var(--mid); background: var(--mid-soft); }
[data-theme="light"] .anecdote-kind { color: #6d4fc9; background: rgba(109, 79, 201, 0.09); }
.anecdote > .md, .history > .md { padding: 14px 18px 16px; font-size: 15px; line-height: 1.7; }
.lesson .anecdote .md > p, .lesson .anecdote .md > ul, .lesson .anecdote .md > ol,
.lesson .history .md > p, .lesson .history .md > ul, .lesson .history .md > ol { max-width: none; }

/* Key takeaway marker in the table of contents: a small dot instead of an emoji. */
.toc-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); flex-shrink: 0; margin-left: 6px; align-self: center; }

/* Key point: same card shape as the anecdotes, green tint. */
.keypoint { border: 1px solid color-mix(in srgb, var(--good) 35%, transparent) !important; border-radius: 10px !important; background: var(--good-soft) !important; padding: 12px 16px !important; }
.lesson .keypoint .md > p, .lesson .md .keypoint > p { max-width: none; }

/* Key takeaway marker in the table of contents: a thin key icon. */
.toc-key { display: inline-flex; margin-left: 6px; color: var(--mid); align-self: center; }
.toc-key .icon { width: 12px; height: 12px; stroke-width: 1.7; }

/* Beginner glossary (js/glossary.js): dotted underline, plain-language definition on hover, focus or tap. */
.gloss { position: relative; text-decoration: underline dotted; text-decoration-color: var(--text-faint); text-underline-offset: 3px; cursor: help; outline: none; }
.gloss:hover, .gloss:focus { text-decoration-color: var(--accent); }
.gloss::after { content: attr(data-def); position: absolute; left: 0; top: calc(100% + 6px); z-index: 20; width: max-content; max-width: min(320px, 80vw);
  padding: 9px 12px; border-radius: 8px; background: var(--bg-elev); border: 1px solid var(--border-strong); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color: var(--text); font-size: 13.5px; font-weight: 400; font-style: normal; line-height: 1.5; white-space: normal; text-align: left;
  opacity: 0; visibility: hidden; transform: translateY(-2px); transition: opacity 0.12s, transform 0.12s; pointer-events: none; }
.gloss:hover::after, .gloss:focus::after { opacity: 1; visibility: visible; transform: none; }
.res-icon:empty { display: none; }
.train-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; background: var(--bg-sunk); border: 1px solid var(--border); color: var(--text-muted); font-size: 0; }
.train-icon .icon { width: 17px; height: 17px; }

/* Mon mémo (js/mymemo.js) */
.mm-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.mm-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.mm-chip { display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 7px; border: 1px solid var(--border); background: transparent; color: var(--text-muted); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; }
.mm-chip:hover { color: var(--text); background: var(--bg-sunk); }
.mm-chip.active { color: var(--text); background: var(--bg-sunk); border-color: var(--border-strong); }
.mm-count { font-size: 11.5px; color: var(--text-faint); font-variant-numeric: tabular-nums; }
.mm-search { width: 280px; max-width: 100%; }
.mm-add { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.mm-slot:not(:empty) { margin-bottom: 16px; }
.mm-grid { columns: 2 420px; column-gap: 16px; }
.mm-card { break-inside: avoid; display: grid; gap: 10px; margin: 0 0 16px; padding: 16px 18px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; }
.mm-card.pinned { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.mm-head { display: flex; align-items: baseline; gap: 10px; }
.mm-head h3 { margin: 0; font-size: 15px; }
.mm-kind { flex-shrink: 0; font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; padding: 2px 7px; border-radius: 5px; color: var(--text-muted); background: var(--bg-sunk); }
.mm-chapter .mm-kind { color: var(--accent); background: var(--accent-soft); }
.mm-card.mm-code .mm-kind { color: var(--good); background: var(--good-soft); }
.mm-trap .mm-kind { color: var(--bad); background: var(--bad-soft); }
.mm-takeaway .mm-kind { color: var(--mid); background: var(--mid-soft); }
.mm-actions { display: flex; gap: 10px; align-items: baseline; opacity: 0; transition: opacity 0.12s; font-size: 12.5px; }
.mm-card:hover .mm-actions, .mm-card:focus-within .mm-actions { opacity: 1; }
.mm-action { font-size: 12.5px; color: var(--text-muted); }
.mm-card .md { font-size: 14px; line-height: 1.6; }
.mm-card .md p:last-child, .mm-card .md ul:last-child { margin-bottom: 0; }
.mm-fix { border-left: 2px solid var(--good); padding-left: 12px; }
.mm-fix-label { font-size: 11.5px; font-weight: 600; color: var(--good); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 2px; }
.mm-snippet { position: relative; }
.mm-snippet pre { margin: 0; }
.mm-copy { position: absolute; top: 6px; right: 6px; }
.mm-link { font-size: 13px; }
.mm-textarea { width: 100%; resize: vertical; font: inherit; font-size: 14px; line-height: 1.5; }
.mm-textarea.mono { font-family: var(--mono); font-size: 13px; }
.mm-editing .text-input { width: 100%; }
.mm-sub { margin: 4px 0; font-size: 12.5px; }
.mm-picker select { width: 100%; margin-top: 8px; }
@media (hover: none) { .mm-actions { opacity: 1; } }
.mm-grid > .mm-empty, .mm-grid > p { column-span: all; break-inside: avoid; }

/* Podcasts (announced) */
.nav-soon { margin-left: auto; font-size: 10.5px; color: var(--text-faint); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }
.soon-card { display: flex; gap: 18px; align-items: flex-start; max-width: 760px; padding: 22px 24px; }
.soon-icon { display: grid; place-items: center; width: 44px; height: 44px; flex-shrink: 0; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.soon-icon .icon { width: 22px; height: 22px; }
.soon-tag { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); border-radius: 5px; padding: 2px 8px; margin-bottom: 8px; }
.soon-card p { margin: 0 0 10px; }

/* Cards attached to a chapter sheet, and the chapter's suggestions */
.mm-children { display: grid; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.mm-card.mm-child { margin: 0; padding: 10px 12px; gap: 6px; background: var(--panel); border-radius: 8px; }
.mm-card.mm-child h3 { font-size: 14px; }
.mm-child-add { margin: 2px 0 0; }
.mm-suggest { display: grid; gap: 8px; padding: 12px; border: 1px dashed var(--border-strong); border-radius: 8px; }
.mm-suggest-list { display: grid; gap: 2px; max-height: 340px; overflow-y: auto; }
.mm-suggest-row { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 6px; }
.mm-suggest-row:hover { background: var(--bg-sunk); }
.mm-suggest-title { font-size: 13.5px; }
.mm-suggest-code { font-family: var(--mono); font-size: 12px; color: var(--text-muted); white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.mm-card { grid-template-columns: minmax(0, 1fr); }
.mm-snippet pre { overflow-x: auto; }
.mm-snippet pre { padding-top: 34px; }
.soon-card h2 { font-size: 18px; margin: 0 0 10px; }
.soon-points { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 18px; margin: 4px 0 14px; padding: 0; list-style: none; }
.soon-points li { position: relative; padding-left: 16px; font-size: 14px; }
.soon-points li::before { content: ''; position: absolute; left: 0; top: 0.6em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
@media (max-width: 640px) { .soon-points { grid-template-columns: 1fr; } }

/* Breathing room around buttons: never glued to a paragraph, a list, a code block or a title (above or below). */
:is(p, ul, ol, pre, .md, h1, h2, h3, h4, label, .callout, .mm-snippet, .muted, .verdict, .tf-label, table, .table-wrap)
  + :is(.btn, .account-actions, .mm-add, .action-group, .row:has(> .btn), .row:has(> a.btn), div:has(> .btn:only-child)) { margin-top: 16px; }
:is(.btn, .account-actions, .mm-add, .row:has(> .btn)) + :is(p, ul, ol, .md, .muted, h2, h3, h4, .callout, .card, section) { margin-top: 16px; }
.card > .btn:first-child + * { margin-top: 14px; }
.card > :last-child.btn, .card > .account-actions:last-child { margin-bottom: 2px; }
/* Text and buttons side by side: a real gap, and the button never squeezes the text. */
.row, .row.wrap, .account-actions, .mm-add, .action-group { column-gap: 12px; row-gap: 10px; }
.callout.row { gap: 14px; padding: 12px 16px; align-items: center; }
.list-row .btn { margin-left: 12px; flex-shrink: 0; }
p .btn, li .btn { margin-left: 8px; }

/* The Run / Step by step / Edit bar under a code block: a real footer of the block, with room around the buttons. */
.md pre:has(+ .snippet-bar), .md pre:has(+ .cb-bar), pre:has(+ .cb-bar) { border-bottom-left-radius: 0; border-bottom-right-radius: 0; margin-bottom: 0; }
.snippet-bar, .cb-bar { padding: 10px 12px; gap: 10px; background: var(--bg-elev); border-color: var(--border); border-radius: 0 0 10px 10px; margin-bottom: 1.2em; }
.snippet-bar .btn, .cb-bar .btn { padding: 4px 11px; }

/* ---------------------------------------------------------------- dashboard v2 (js/dashboard.js) */
.dash-row { display: grid; gap: 16px; margin-bottom: 16px; }
.dash-top { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); }
.dash-bottom { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.dash-row > .card { margin: 0; }
.dash-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 14px; }
.dash-head h3 { margin: 0; }
.dash-session .session-head { display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: center; }
.dash-session .session-next { margin: 14px 0 0; font-size: 13.5px; }
.dash-next-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }

.dash-continue { display: flex; flex-direction: column; }
.dash-continue-row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin: 0 -12px; border-radius: 8px; color: var(--text); }
.dash-continue-row:hover { background: var(--bg-sunk); text-decoration: none; }
.dash-continue-row + .dash-continue-row { border-top: 1px solid var(--border); border-radius: 0 0 8px 8px; }
.dash-continue-label { display: block; font-size: 12px; color: var(--text-muted); }
.dash-continue-title { display: block; font-weight: 500; margin-top: 2px; }
.dash-arrow { color: var(--text-faint); transition: transform 0.15s, color 0.15s; }
.dash-continue-row:hover .dash-arrow { color: var(--accent); transform: translateX(3px); }

/* Segmented controls */
.seg { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--bg-sunk); border: 1px solid var(--border); }
.seg-btn { border: 0; background: transparent; color: var(--text-muted); font: inherit; font-size: 12.5px; font-weight: 500; padding: 4px 10px; border-radius: 6px; cursor: pointer; }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }

/* Activity chart */
.dash-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.dash-stat { padding: 2px 0 2px 12px; border-left: 2px solid var(--border); }
.dash-stat-value { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.dash-stat-label { font-size: 12px; color: var(--text-muted); }
.dash-chart { position: relative; width: 100%; min-height: 190px; }
.dash-chart-svg { display: block; overflow: visible; }
.dash-grid { stroke: var(--border); stroke-width: 1; }
.dash-axis { fill: var(--text-faint); font-size: 11px; font-family: var(--sans); font-variant-numeric: tabular-nums; }
.dash-axis.today { fill: var(--text-muted); font-weight: 500; }
.dash-bar { fill: var(--accent); opacity: 0.85; transition: opacity 0.12s; }
.dash-bar.today { opacity: 1; }
.dash-hit { fill: transparent; cursor: default; }
.dash-hit.on { fill: color-mix(in srgb, var(--text) 5%, transparent); }
.dash-tooltip { position: absolute; transform: translateX(-50%); pointer-events: none; z-index: 5; min-width: 160px; padding: 8px 11px; border-radius: 8px;
  background: var(--bg-elev); border: 1px solid var(--border-strong); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); font-size: 13px; white-space: nowrap; }
.dash-tooltip-date { color: var(--text-muted); font-size: 12px; margin-bottom: 2px; }
.dash-tooltip-date::first-letter { text-transform: uppercase; }
.dash-note { margin: 10px 0 0; font-size: 13px; }

/* Where you stand */
.dash-status-bar { display: flex; gap: 2px; height: 10px; border-radius: 5px; overflow: hidden; margin-bottom: 12px; }
.dash-seg { min-width: 3px; }
.seg-mastered { background: var(--good); }
.seg-strong { background: color-mix(in srgb, var(--accent) 90%, var(--text)); }
.seg-practicing { background: color-mix(in srgb, var(--accent) 60%, var(--bg-sunk)); }
.seg-weak { background: var(--bad); }
.seg-learning { background: color-mix(in srgb, var(--accent) 30%, var(--bg-sunk)); }
.seg-not_started { background: var(--border-strong); }
.dash-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--text-muted); margin-bottom: 18px; }
.dash-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dash-swatch { width: 8px; height: 8px; border-radius: 2px; }
.dash-legend-count { color: var(--text); font-variant-numeric: tabular-nums; }
.dash-sub { font-size: 12px; color: var(--text-faint); margin-bottom: 6px; }
.dash-tracks { display: grid; gap: 2px; }
.dash-track { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) 42px; align-items: center; gap: 12px; padding: 5px 8px; margin: 0 -8px; border-radius: 6px; color: var(--text); font-size: 13px; }
.dash-track:hover { background: var(--bg-sunk); text-decoration: none; }
.dash-track-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-track-bar { position: relative; height: 6px; border-radius: 3px; background: var(--bg-sunk); overflow: hidden; }
.dash-track-started, .dash-track-solid { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; }
.dash-track-started { background: color-mix(in srgb, var(--accent) 30%, var(--bg-sunk)); }
.dash-track-solid { background: var(--accent); }
.dash-track-count { text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.dash-more { display: inline-block; margin-top: 14px; font-size: 13px; }

.dash-list { display: grid; gap: 1px; }
.dash-list .list-row { margin: 0 -8px; }

@media (max-width: 1000px) {
  .dash-top, .dash-bottom { grid-template-columns: minmax(0, 1fr); }
  .dash-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Site version at the bottom of the sidebar */
.site-version { display: inline-block; margin: 22px 8px 0; font-family: var(--mono); font-size: 11.5px; color: var(--text-faint); }
.site-version:hover { color: var(--text-muted); text-decoration: none; }

/* Icon buttons that are links (settings, account): same centring as the <button> ones. */
.topbar-right a.icon-button, a.icon-button { display: inline-grid; place-items: center; line-height: 0; text-decoration: none; }
.topbar-right a.icon-button[hidden] { display: none; }
.icon-button .icon { display: block; }

/* Wordmark: "Py" in the Python yellow of the mark, "Kad" in the text colour. */
.brand-name { display: inline; }
.brand-py { color: #f2c94c; }
[data-theme="light"] .brand-py { color: #b7860b; }

/* Version pinned at the bottom-left: last item of the sidebar, sticky so it stays visible when the module list scrolls. */
#sidebar { display: flex; flex-direction: column; padding-bottom: 0; }
.site-version { margin: auto 0 0; position: sticky; bottom: 0; padding: 14px 8px 12px; background: var(--bg); align-self: stretch; }

/* Status explanations: a quiet tooltip on hover or focus (no underline, the badge itself is the target). */
.tip { position: relative; cursor: help; outline: none; }
.tip::after { content: attr(data-tip); position: absolute; left: 0; top: calc(100% + 6px); z-index: 30; width: max-content; max-width: min(300px, 80vw);
  padding: 8px 11px; border-radius: 8px; background: var(--bg-elev); border: 1px solid var(--border-strong); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  color: var(--text); font-size: 12.5px; font-weight: 400; letter-spacing: 0; text-transform: none; line-height: 1.5; white-space: normal; text-align: left;
  opacity: 0; visibility: hidden; transition: opacity 0.12s 0.15s; pointer-events: none; }
.tip:hover::after, .tip:focus::after { opacity: 1; visibility: visible; }
.tip[data-tip=""]::after { display: none; }
.page-head .badge.tip::after, .topic-head .badge.tip::after { left: auto; right: 0; }

/* Scale up (~7 %), 2026-12-03: the screen has room. Sizes only; layout rules above stay. */
:root { --sidebar: 264px; }
html, body { font-size: 15px; }
#main { max-width: 1580px; padding: 36px 52px 100px; }
h1 { font-size: 26px; } h2 { font-size: 20px; } h3 { font-size: 16.5px; }
.page-sub { font-size: 15px; }
.brand-text { font-size: 15px; }
.brand-mark { width: 28px; height: 28px; font-size: 13px; }
.nav-item, .nav-module, .nav-topic { font-size: 14.5px; padding: 6px 9px; }
.nav-topic { font-size: 13.5px; }
.nav-track { font-size: 13.5px; }
.nav-label { font-size: 12.5px; }
.icon { width: 17px; height: 17px; }
.icon-button { width: 32px; height: 32px; }
#search-input { font-size: 14px; padding: 7px 13px; }
.pill { font-size: 13px; }
.btn { font-size: 14.5px; padding: 7px 14px; }
.btn-small { font-size: 13.5px; }
.tab { font-size: 14.5px; }
.card { padding: 20px 22px; }
.tile-value, .dash-stat-value { font-size: 22px; }
.dash-stat-label, .tile-label, .dash-legend, .dash-track, .seg-btn { font-size: 13.5px; }
.list-row { font-size: 15px; }
.lesson { font-size: 17px; }
.lesson .md h2 { font-size: 23.5px; }
.lesson .md h3 { font-size: 18px; }
.md pre code, .md pre { font-size: 14.5px; }
.toc { font-size: 13.5px; }
.lesson-layout { grid-template-columns: minmax(0, 1fr) 250px; }
.mm-card .md, .mm-suggest-title { font-size: 15px; }
.site-version { font-size: 12px; }

/* QCM express (js/drill.js) */
.drill-form { display: grid; gap: 22px; max-width: 1100px; }
.drill-form h3 { margin-bottom: 10px; }
.drill-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.drill-track { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.drill-track-name { font-size: 13.5px; color: var(--text-muted); padding-top: 5px; }
.drill-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.drill-row { display: flex; flex-wrap: wrap; gap: 28px; }
.drill-check { display: inline-flex; align-items: center; gap: 8px; font-size: 14.5px; }
.drill-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; padding-top: 16px; border-top: 1px solid var(--border); }
@media (max-width: 760px) { .drill-track { grid-template-columns: minmax(0, 1fr); gap: 6px; } }

/* Bottom-left of the sidebar: account, settings, version (moved out of the top bar). */
.sidebar-foot { margin-top: auto; position: sticky; bottom: 0; display: flex; align-items: center; gap: 4px; padding: 10px 4px 12px; background: var(--bg); border-top: 1px solid var(--border); }
.sidebar-foot .site-version { position: static; margin: 0 0 0 auto; padding: 0 6px; background: none; align-self: center; }
.foot-account { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1; padding: 6px 8px; border-radius: 7px; color: var(--text-muted); font-size: 14px; font-weight: 500; }
.foot-account:hover { background: var(--bg-sunk); color: var(--text); text-decoration: none; }
.foot-account.signed-in { color: var(--text); }
.foot-account.signed-in .icon { color: var(--accent); }
.foot-account-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.foot-account[hidden] + .foot-settings { margin-left: 4px; }

/* Account row and menu (claude.ai-like), bottom-left */
.sidebar-foot { position: sticky; }
.foot-account { border: 0; background: none; font: inherit; text-align: left; cursor: pointer; }
.sidebar-foot.with-account .foot-settings, .sidebar-foot.with-account .site-version { display: none; }
.foot-avatar { display: grid; place-items: center; width: 26px; height: 26px; flex-shrink: 0; border-radius: 50%; background: var(--accent-strong); color: #fff; font-size: 12.5px; font-weight: 600; }
.foot-account.signed-in { color: var(--text); background: none; }
.foot-account.signed-in:hover, .foot-account[aria-expanded="true"] { background: var(--bg-sunk); }
.account-menu { position: absolute; left: 6px; right: 6px; bottom: calc(100% + 6px); z-index: 40; padding: 6px; border-radius: 12px; background: var(--bg-elev);
  border: 1px solid var(--border-strong); box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45); display: grid; gap: 1px; }
.account-menu-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.account-menu-name { font-weight: 600; font-size: 14px; }
.account-menu-email { font-size: 12.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 7px; background: none; color: var(--text); font: inherit; font-size: 14px; text-align: left; cursor: pointer; }
.account-menu-item:hover { background: var(--bg-sunk); text-decoration: none; }
.account-menu-item .icon { color: var(--text-muted); }
.account-menu-meta { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--text-faint); }
.account-menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }
.auth-card .auth-legal { text-align: center; margin: 0; }
.auth-card .auth-legal a { color: var(--text-muted); }

/* Python console (js/console.js): docked at the bottom, to the right of the sidebar. */
.nav-button { width: 100%; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; }
.console-panel { position: fixed; z-index: 50; left: calc(var(--sidebar) + 8px); right: 8px; bottom: 8px; height: 40vh; min-height: 220px; display: flex; flex-direction: column;
  background: var(--code-bg); border: 1px solid var(--border-strong); border-radius: 12px; box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.35); overflow: hidden; }
.console-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--bg-elev); }
.console-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
.console-version { font-family: var(--mono); font-size: 12px; }
.console-transcript { flex: 1; overflow-y: auto; padding: 10px 14px 4px; font-family: var(--mono); font-size: 13.5px; line-height: 1.55; }
.console-line { margin: 0 0 4px; white-space: pre-wrap; word-break: break-word; font: inherit; background: none; border: 0; padding: 0; }
.console-line.prompt { color: var(--text-muted); }
.console-line.out { color: var(--text); }
.console-line.err { color: var(--bad); }
.console-line.note { color: var(--text-faint); font-family: var(--sans); font-size: 12.5px; }
.console-entry { display: flex; align-items: flex-start; gap: 8px; padding: 8px 14px 12px; border-top: 1px solid var(--border); }
.console-ps { font-family: var(--mono); font-size: 13.5px; color: var(--accent); line-height: 1.55; padding-top: 1px; }
.console-input { flex: 1; resize: none; border: 0; outline: none; background: none; color: var(--text); font-family: var(--mono); font-size: 13.5px; line-height: 1.55; padding: 0; min-height: 21px; }
.console-panel.busy .console-ps { opacity: 0.4; }
body.console-open #main { padding-bottom: calc(40vh + 40px); }
@media (max-width: 860px) { .console-panel { left: 8px; height: 50vh; } }

/* Sidebar footer: console entry above the account row */
.sidebar-foot { flex-direction: column; align-items: stretch; gap: 2px; }
.foot-row { display: flex; align-items: center; gap: 4px; position: relative; }
.foot-console { margin: 0 0 2px; }
.foot-console.active { background: var(--bg-sunk); color: var(--text); }
.foot-console.active .icon { color: var(--accent); }

/* Phones: nothing may be wider than the screen (found by tools/smoke.py). */
@media (max-width: 600px) {
  #main, #main .page, #main .card, #main section, .lesson-layout > * { min-width: 0; max-width: 100%; }
  .btn { white-space: normal; max-width: 100%; }
  .snippet-bar, .cb-bar, .row, .account-actions { flex-wrap: wrap; }
  .lc-choices .btn { text-align: left; }
  select, .py-select, .prio, input, textarea { max-width: 100%; }
  .memo-item, .memo-table { max-width: 100%; overflow-x: auto; }
  .table-wrap { max-width: 100%; }
  .path-progress { width: auto; }
}
/* After the 7 % scale-up (which set desktop paddings): phones keep 16 px side margins. */
@media (max-width: 860px) { #main { padding: 20px 16px 80px; } }
@media (max-width: 600px) { .memo-grid { grid-template-columns: minmax(0, 1fr); } .md pre, pre.code { max-width: 100%; overflow-x: auto; } }
/* Hidden tooltips must not take room: an invisible ::after still widened the page on phones (status badges, glossary). */
.tip::after, .gloss::after { display: none; }
.tip:hover::after, .tip:focus::after, .gloss:hover::after, .gloss:focus::after { display: block; }

/* ---------------------------------------------------------------- phones (audit 2026-12-04, iPhone 13 width) */
/* The lesson column: the 7 % scale-up set two grid columns again, while the table of contents is hidden below 1100 px. */
@media (max-width: 1100px) { .lesson-layout { grid-template-columns: minmax(0, 1fr); gap: 0; } }
@media (max-width: 600px) {
  /* Top bar: menu, search (full width), language, theme. Keyboard help and the review counter are in the menu. */
  #topbar { gap: 6px; padding: 8px 10px; }
  #search-form { flex: 1; max-width: none; min-width: 0; }
  #help-button, #review-pill { display: none; }
  /* Room: smaller cards and titles, readable text. */
  #main { padding: 18px 14px 80px; }
  .card { padding: 14px 14px; }
  h1 { font-size: 23px; }
  .page-head { margin-bottom: 16px; }
  .lesson { font-size: 16px; }
  .lesson .md h2 { font-size: 20px; }
  /* iOS zooms into any field under 16 px: keep fields at 16 px. */
  input, textarea, select, .console-input, #search-input { font-size: 16px; }
  /* Home "three steps": text, then the button under it. */
  .start-step { flex-wrap: wrap; align-items: flex-start; }
  .start-step .grow { flex-basis: calc(100% - 50px); }
  .start-step .btn { margin-left: 40px; }
  /* Tabs scroll sideways instead of stacking. */
  .lc-tabs { flex-wrap: nowrap; overflow-x: auto; }
  /* Touch targets of at least ~40 px. */
  .nav-item, .nav-module, .nav-topic, .list-row, .account-menu-item { min-height: 40px; }
  .btn-small { padding: 7px 12px; }
  /* Console: compact header, more room for the transcript. */
  .console-panel { left: 6px; right: 6px; bottom: 6px; height: 58vh; }
  .console-head { flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
  .console-version { display: none; }
  .console-transcript { padding: 8px 10px 4px; font-size: 13px; }
  .console-entry { padding: 8px 10px 10px; }
}
/* A Run button next to the console prompt: phone keyboards make Enter awkward (and it is handy everywhere). */
.console-run { align-self: flex-end; }

/* Phones and small tablets: dimmed page behind the menu, and a tab bar at the bottom. */
#menu-backdrop, #tabbar { display: none; }
@media (max-width: 860px) {
  #app.menu-open #menu-backdrop { display: block; position: fixed; inset: 0; z-index: 19; background: rgba(0, 0, 0, 0.55); }
  body:has(#app.menu-open) { overflow: hidden; }
  #tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--bg-elev) 94%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--border); }
  .tab-item { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 50px; padding: 4px 2px;
    border: 0; border-radius: 10px; background: none; color: var(--text-muted); font: inherit; font-size: 11px; font-weight: 500; text-decoration: none; cursor: pointer; }
  .tab-item .icon { width: 21px; height: 21px; }
  .tab-item.active { color: var(--accent); }
  .tab-item:hover { text-decoration: none; }
  #main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  body.console-open #main { padding-bottom: calc(60vh + 80px); }
  .console-panel { bottom: calc(66px + env(safe-area-inset-bottom)); }
  .py-loading { bottom: calc(76px + env(safe-area-inset-bottom)) !important; }
  /* The sidebar drawer covers the tab bar: the menu stays reachable with its own footer. */
  #sidebar { z-index: 50; padding-bottom: env(safe-area-inset-bottom); }
}
@media (max-width: 600px) { .console-panel { height: calc(100vh - 150px - env(safe-area-inset-bottom)); max-height: 62vh; } }
/* The tab bar has its own Menu entry: no second hamburger in the top bar. */
@media (max-width: 860px) { #menu-button { display: none !important; } }
