/* ==========================================================================
   Study notebook — design system
   Layout concept: a squared school notebook (light) / a classroom blackboard (dark).
   One reading column of ~68ch, a handwritten margin on wide screens, figures and
   widget stages drawn on 5 mm squared paper. Everything else stays quiet.

   Faces (all four ship Cyrillic on Google Fonts):
     Geologica      — display + UI: a geometric sans designed Cyrillic-first, so headings
                      and controls do not look like a Latin face with borrowed letters.
     Literata       — long-form body: a book face made for hours of screen reading.
     Caveat         — handwriting: margin notes, lesson number, diagram annotations only.
     JetBrains Mono — code, data, axis ticks.
   ========================================================================== */

/* -------------------------------------------------------------------------
   1. Tokens — every colour is defined here first (light = notebook)
   ------------------------------------------------------------------------- */
:root {
  /* paper & ink */
  --paper:   #f6f8fc;   /* page: cool off-white */
  --paper-2: #ebf0f8;   /* quiet blocks, control strips */
  --paper-3: #dfe7f3;   /* pressed / hover */
  --stage:   #fbfcfe;   /* the sheet figures and plots are drawn on */
  --ink:     #16223d;   /* navy fountain-pen ink */
  --ink-2:   #3d4963;   /* secondary text */
  --ink-3:   #5a6681;   /* muted text, axis ticks (AA on paper) */
  --line:    #cdd6e6;   /* hairlines */
  --line-2:  #7c89a4;   /* control borders (3:1) */
  --grid:    #d6e0f0;   /* 5 mm squares on figures */
  --grid-2:  #aebfdc;   /* every 5th line, axes */
  --grid-page: rgba(120, 150, 205, 0.09); /* the same squares, very quiet, behind the page */
  --link:    #1a4fb8;
  --focus:   #1a4fb8;

  /* semantic — each used ONLY for its meaning */
  --key:     #ffd83d;   /* highlighter yellow: fills, wide underlays, halos (1.35:1 on paper — never a thin line, never text) */
  --key-line:#9a7400;   /* the same "look here" as a thin line or an arrowhead: dark enough to be seen on paper */
  --key-bg:  #ffe76a;   /* highlighter stroke behind text */
  --key-fg:  #16223d;
  --bad:     #bf2029;   /* red pen */
  --bad-bg:  #fbe9e7;
  --good:    #16733a;   /* green tick */
  --good-bg: #e2f3e6;

  /* series: 6 categorical slots, validated (dataviz validate_palette.js) on --stage.
     s1 data / class A · s2 class B · s3 model / prediction · s4 train · s5 validation · s6 target */
  --s1: #1764cb;
  --s2: #ec6e20;
  --s3: #6a2f99;
  --s4: #00a293;
  --s5: #b53c99;
  --s6: #946d03;

  --shadow: 0 1px 2px rgba(22, 34, 61, 0.08), 0 8px 24px rgba(22, 34, 61, 0.10);
  --scrim: rgba(22, 34, 61, 0.38);

  /* type */
  --f-display: "Geologica", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --f-body: "Literata", Georgia, "Times New Roman", serif;
  --f-hand: "Caveat", "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  --f-mono: "JetBrains Mono", "Cascadia Mono", Consolas, "Courier New", monospace;

  --t-xs: 0.75rem;
  --t-sm: 0.875rem;
  --t-md: 1rem;         /* secondary copy: callouts, options, tables of text */
  --t-base: 1.125rem;   /* body copy */
  --t-lg: 1.3rem;
  --t-h3: 1.25rem;
  --t-h2: 1.7rem;
  --t-h1: clamp(2rem, 1.35rem + 2.9vw, 3.1rem);

  /* layout */
  --sq: 20px;            /* one notebook square (5 mm) */
  --measure: 42rem;      /* about 68 characters of body copy */
  --margin-w: 13rem;     /* handwritten margin */
  --margin-gap: 2rem;
  --sidebar-w: 17rem;
  --bar-h: 3.25rem;
  --pad: clamp(1rem, 4vw, 3rem);
  --flow: 1.15rem;
  --radius: 3px;

  color-scheme: light;
}

/* dark = blackboard. Same tokens, chalk values. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:   #1c2723;
    --paper-2: #243029;
    --paper-3: #2d3b34;
    --stage:   #18221f;
    --ink:     #eceee6;
    --ink-2:   #c6cec5;
    --ink-3:   #9eaaa1;
    --line:    #34433c;
    --line-2:  #6f8178;
    --grid:    #24322d;
    --grid-2:  #3a4c44;
    --grid-page: rgba(236, 238, 230, 0.028);
    --link:    #9ec5f4;
    --focus:   #9ec5f4;
    --key:     #f2d75c;
    --key-line:#f2d75c;
    --key-bg:  rgba(242, 215, 92, 0.16);
    --key-fg:  #f2d75c;
    --bad:     #ffa8a0;   /* light enough to stand apart from s2 orange and s5 magenta on the board */
    --bad-bg:  rgba(255, 168, 160, 0.13);
    --good:    #86d39a;
    --good-bg: rgba(134, 211, 154, 0.13);
    --s1: #4098e4;
    --s2: #d77340;
    --s3: #755cc2;
    --s4: #088e80;
    --s5: #c86db0;
    --s6: #866713;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.35);
    --scrim: rgba(8, 12, 11, 0.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper:   #1c2723;
  --paper-2: #243029;
  --paper-3: #2d3b34;
  --stage:   #18221f;
  --ink:     #eceee6;
  --ink-2:   #c6cec5;
  --ink-3:   #9eaaa1;
  --line:    #34433c;
  --line-2:  #6f8178;
  --grid:    #24322d;
  --grid-2:  #3a4c44;
  --grid-page: rgba(236, 238, 230, 0.028);
  --link:    #9ec5f4;
  --focus:   #9ec5f4;
  --key:     #f2d75c;
  --key-line:#f2d75c;
  --key-bg:  rgba(242, 215, 92, 0.16);
  --key-fg:  #f2d75c;
  --bad:     #ffa8a0;
  --bad-bg:  rgba(255, 168, 160, 0.13);
  --good:    #86d39a;
  --good-bg: rgba(134, 211, 154, 0.13);
  --s1: #4098e4;
  --s2: #d77340;
  --s3: #755cc2;
  --s4: #088e80;
  --s5: #c86db0;
  --s6: #866713;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px rgba(0, 0, 0, 0.35);
  --scrim: rgba(8, 12, 11, 0.6);
  color-scheme: dark;
}

/* -------------------------------------------------------------------------
   2. Base
   ------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--bar-h) + 1rem); }
body {
  margin: 0;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-page) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-page) 1px, transparent 1px);
  background-size: var(--sq) var(--sq);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: var(--t-base);
  line-height: 1.68;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}
:where(h1, h2, h3, h4, p, ul, ol, dl, dd, figure, blockquote, pre, table) { margin: 0; }
:where(ul, ol) { padding-inline-start: 1.35em; }
:where(li) + :where(li) { margin-top: 0.35em; }
[hidden] { display: none !important; }
img, svg, canvas { max-width: 100%; }
a { color: var(--link); text-decoration-thickness: 1px; text-underline-offset: 0.18em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
::selection { background: var(--key-bg); color: var(--key-fg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
strong, b { font-weight: 650; }
sub, sup { font-size: 0.72em; line-height: 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 2rem 0; }

h1, h2, h3, h4 { font-family: var(--f-display); text-wrap: balance; color: var(--ink); }
h1 { font-size: var(--t-h1); font-weight: 720; line-height: 1.06; letter-spacing: -0.022em; }
h2 { font-size: var(--t-h2); font-weight: 660; line-height: 1.16; letter-spacing: -0.014em; }
h3 { font-size: var(--t-h3); font-weight: 620; line-height: 1.25; letter-spacing: -0.006em; }
h4 { font-size: var(--t-md); font-weight: 620; line-height: 1.3; }
p { text-wrap: pretty; }

code, kbd, samp, pre { font-family: var(--f-mono); font-size: 0.86em; font-variant-ligatures: none; }
:where(p, li, dd, td, th, figcaption, summary) code {
  background: var(--paper-2); border: 1px solid var(--line); border-radius: 2px; padding: 0.06em 0.32em;
}
pre { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1rem; overflow-x: auto; line-height: 1.5; tab-size: 2; }
pre code { background: none; border: 0; padding: 0; font-size: 1em; }
kbd { border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 3px; padding: 0.02em 0.36em; background: var(--stage); }
abbr[title] { text-decoration: underline dotted var(--ink-3); text-underline-offset: 0.18em; cursor: help; }

/* inline semantics */
mark.key {
  background: var(--key-bg); color: var(--key-fg);
  padding: 0.04em 0.22em; margin-inline: -0.04em;
  border-radius: 0.3em 0.12em 0.34em 0.14em;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
  font-weight: 560;
}
.en { font-family: var(--f-display); font-size: 0.93em; font-style: normal; font-weight: 450; letter-spacing: 0.002em; white-space: normal; }
/* an English term inside a heading or a title keeps the heading's own face, size and weight */
:where(h1, h2, h3, h4, .widget-title, .q-text, dfn, summary, .res-title, .lcard-title) .en { font: inherit; letter-spacing: inherit; }
.hand { font-family: var(--f-hand); font-size: 1.22em; line-height: 1.2; }
.num { font-family: var(--f-mono); font-variant-numeric: tabular-nums; font-size: 0.9em; }
.nw { white-space: nowrap; }
.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* icons (sprite injected by course.js) */
.ico { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.2em; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45em;
  min-height: 2.5rem; padding: 0.4rem 0.95rem;
  font-family: var(--f-display); font-size: var(--t-sm); font-weight: 560; line-height: 1.2; text-decoration: none;
  color: var(--ink); background: transparent;
  border: 1.5px solid var(--ink); border-radius: var(--radius);
  transition: background-color 0.12s, color 0.12s, border-color 0.12s;
}
.btn:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { background: var(--ink); color: var(--paper); }
.btn--primary:hover:not(:disabled) { background: var(--ink-2); border-color: var(--ink-2); color: var(--paper); }
.btn--ghost { border-color: var(--line-2); color: var(--ink-2); }
.btn--ghost:hover:not(:disabled) { background: var(--paper-3); color: var(--ink); border-color: var(--ink); }
.btn--sm { min-height: 2rem; padding: 0.2rem 0.7rem; font-size: var(--t-xs); }

/* -------------------------------------------------------------------------
   3. Chrome: top bar, sidebar / drawer, footer
   ------------------------------------------------------------------------- */
.skip { position: absolute; left: 0.75rem; top: -4rem; z-index: 60; background: var(--ink); color: var(--paper); padding: 0.5rem 0.9rem; border-radius: var(--radius); font-family: var(--f-display); font-size: var(--t-sm); }
.skip:focus { top: calc(env(safe-area-inset-top, 0px) + 0.5rem); }

.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  display: flex; align-items: center; gap: 0.5rem;
  height: var(--bar-h); padding-inline: clamp(0.75rem, 2.5vw, 1.5rem);
  background: var(--paper); border-bottom: 1px solid var(--line);
  font-family: var(--f-display); font-size: var(--t-sm);
}
.tb-btn {
  display: inline-grid; place-items: center; width: 2.5rem; height: 2.5rem; flex: none;
  background: none; border: 0; border-radius: var(--radius); color: var(--ink);
}
.tb-btn:hover { background: var(--paper-3); }
.tb-btn .ico { width: 1.35rem; height: 1.35rem; }
.tb-brand { display: inline-flex; align-items: center; gap: 0.5rem; min-width: 0; flex: 0 1 auto; overflow: hidden; min-height: 2.5rem; color: var(--ink); text-decoration: none; font-weight: 680; letter-spacing: -0.01em; font-size: var(--t-md); white-space: nowrap; }
.tb-brand:hover { text-decoration: underline; text-decoration-thickness: 2px; }
.tb-brand .ico { width: 1.3rem; height: 1.3rem; }
.tb-brand span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tb-pos { color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; padding-left: 0.75rem; margin-left: 0.25rem; border-left: 1px solid var(--line); }
.tb-space { flex: 1 1 auto; min-width: 0; }
.tb-progress { display: inline-flex; align-items: center; gap: 0.55rem; color: var(--ink-2); text-decoration: none; min-height: 2.5rem; padding-inline: 0.4rem; border-radius: var(--radius); white-space: nowrap; }
.tb-progress:hover { background: var(--paper-3); }
.tb-progress-bar { width: 4.5rem; height: 6px; background: var(--paper-3); border: 1px solid var(--line-2); border-radius: 3px; overflow: hidden; }
.tb-progress-bar > span { display: block; height: 100%; background: var(--good); }
.tb-progress-num { font-family: var(--f-mono); font-size: var(--t-xs); font-variant-numeric: tabular-nums; }
.tb-theme { display: inline-flex; flex: none; border: 1px solid var(--line-2); border-radius: var(--radius); overflow: hidden; }
.tb-theme button { display: grid; place-items: center; width: 2.1rem; height: 2.1rem; background: none; border: 0; color: var(--ink-3); }
.tb-theme button + button { border-left: 1px solid var(--line); }
.tb-theme button:hover { background: var(--paper-3); color: var(--ink); }
.tb-theme button[aria-checked="true"] { background: var(--ink); color: var(--paper); }
.tb-theme button:focus-visible { outline-offset: -3px; }
.tb-theme .ico { width: 1.05rem; height: 1.05rem; }

.shell { display: block; }
.page { min-width: 0; }

.sidebar {
  position: fixed; z-index: 50; inset: 0 auto 0 0; width: min(21rem, 88vw);
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--paper); border-right: 1px solid var(--line);
  overflow-y: auto; overscroll-behavior: contain;
  transform: translateX(-104%); visibility: hidden;
  transition: transform 0.2s ease, visibility 0s linear 0.2s;
  font-family: var(--f-display); font-size: var(--t-sm); line-height: 1.35;
}
.nav-open .sidebar { transform: none; visibility: visible; transition: transform 0.2s ease; box-shadow: var(--shadow); }
.scrim { position: fixed; inset: 0; z-index: 45; background: var(--scrim); border: 0; padding: 0; width: 100%; cursor: default; }
.sb-inner { padding: 0.75rem 0.75rem 2.5rem; display: flex; flex-direction: column; gap: 1.4rem; }
.sb-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.sb-home { display: inline-flex; align-items: center; gap: 0.45rem; min-height: 2.5rem; padding-inline: 0.5rem; color: var(--ink); font-weight: 600; text-decoration: none; border-radius: var(--radius); }
.sb-home:hover { background: var(--paper-3); }
.sb-mod-title { padding-inline: 0.5rem; color: var(--ink); font-weight: 640; }
.sb-mod-n { display: block; font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 0.1rem; }
.sb-list { list-style: none; padding: 0; margin-top: 0.4rem; }
.sb-list > li + li { margin-top: 1px; }
.sb-link { display: grid; grid-template-columns: 1.7rem minmax(0, 1fr) 1rem; align-items: baseline; gap: 0.25rem; padding: 0.42rem 0.5rem; color: var(--ink-2); text-decoration: none; border-radius: var(--radius); }
.sb-link:hover { background: var(--paper-3); color: var(--ink); }
.sb-link[aria-current="page"] { background: var(--paper-2); color: var(--ink); font-weight: 620; box-shadow: inset 0 0 0 1px var(--line); }
.sb-n { font-family: var(--f-mono); font-size: var(--t-xs); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.sb-tick { align-self: center; width: 0.95rem; height: 0.95rem; color: var(--good); stroke-width: 2.6; visibility: hidden; }
.sb-link.is-done .sb-tick { visibility: visible; }
/* a lesson that is not written yet: listed, but not a link */
.sb-link.is-soon { grid-template-columns: 1.7rem minmax(0, 1fr) auto; color: var(--ink-3); cursor: default; }
.sb-link.is-soon:hover { background: none; color: var(--ink-3); }
.sb-soon { font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }
.sb-toc { list-style: none; padding: 0.3rem 0 0.5rem 2.45rem; margin: 0; font-size: 0.8125rem; }
.sb-toc li + li { margin-top: 0; }
.sb-toc a { display: block; padding: 0.24rem 0.4rem; color: var(--ink-3); text-decoration: none; border-radius: 2px; }
.sb-toc a:hover { color: var(--ink); background: var(--paper-3); }
.sb-toc a.is-active { color: var(--ink); font-weight: 600; box-shadow: inset 2px 0 0 var(--ink); }

@media (min-width: 68.75em) {
  .page-lesson .shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); align-items: start; }
  .page-lesson .sidebar {
    /* `inset` first, `top` after it: the shorthand written last would reset top to auto and the sidebar would scroll away */
    position: sticky; inset: auto; top: calc(env(safe-area-inset-top, 0px) + var(--bar-h)); align-self: start; z-index: 1;
    width: auto; height: calc(100vh - var(--bar-h)); height: calc(100dvh - var(--bar-h) - env(safe-area-inset-top, 0px)); padding-top: 0;
    transform: none; visibility: visible; transition: none; box-shadow: none;
    background: transparent;
  }
  .page-lesson .tb-menu, .page-lesson .scrim, .page-lesson .sb-close { display: none; }
}
@media (max-width: 40em) {
  .tb-pos { display: none; }
  .tb-progress-bar { width: 2.6rem; }
}
@media (max-width: 30em) {
  .topbar { gap: 0.3rem; padding-inline: 0.5rem; }
  .page-lesson .tb-brand .ico, .tb-progress-bar { display: none; }
  .tb-progress { padding-inline: 0.25rem; }
  .tb-theme button { width: 1.95rem; height: 2rem; }
}

.site-foot {
  margin-top: 4rem; padding: 1.5rem var(--pad) calc(2.5rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  font-family: var(--f-display); font-size: var(--t-xs); line-height: 1.55; color: var(--ink-3);
}
.site-foot p { max-width: 34rem; }
.site-foot p + p { margin-top: 0.4rem; }
.site-foot a { color: var(--ink-2); }

/* -------------------------------------------------------------------------
   4. Lesson page: column, flow, margin
   ------------------------------------------------------------------------- */
.lesson {
  display: flow-root;
  max-width: calc(var(--measure) + 2 * var(--pad));
  margin-inline: auto;
  padding-inline: var(--pad);
  padding-block: 2.25rem 1rem;
}
/* one spacing rule for all prose containers; zero specificity so components can override */
:where(.lesson, .lesson section, .lesson article, .lesson aside, .lesson li, .lesson dd, .lesson details, .lesson blockquote,
       .lesson td, .lesson .flow, .lesson .tab, .lesson .compare-col, .lesson .q, .lesson .exam, .lesson .exam-q,
       .lesson .exam-answer, .lesson .exam-note, .lesson .def, .lesson .theorem, .lesson div:not([class]))
  > * + :where(:not(span, a, svg, button, input, label, select, output, b, i, em, strong, code, mark, sub, sup, abbr, br, small)) {
  margin-block-start: var(--flow);
}
.lesson > section, .lesson > .toc + *, .lesson > section + * { margin-block-start: 3.75rem; }
.lesson h2 + *, .lesson h3 + * { margin-block-start: 0.85rem; }
.lesson :where(section) > h3 { margin-block-start: 2.4rem; }
.lesson :where(section) > h4 { margin-block-start: 1.8rem; }
.lesson > section > h2 { counter-increment: sec; scroll-margin-top: calc(var(--bar-h) + 1rem); }
.lesson { counter-reset: sec; }
.lesson > section:not(.quiz):not(.recap):not(.resources):not(.no-num) > h2::before {
  content: counter(sec); display: block;
  font-family: var(--f-mono); font-size: var(--t-sm); font-weight: 600; letter-spacing: 0.04em; color: var(--ink-3);
  margin-bottom: 0.35rem;
}
.lesson > section.quiz > h2, .lesson > section.recap > h2, .lesson > section.resources > h2, .lesson > section.no-num > h2 { counter-increment: none; }
.lesson :where(p, li, dd) { hyphens: manual; }
@media (max-width: 30em) { .lesson :where(p, li, dd) { hyphens: auto; } }

/* the handwritten margin: active when there is room for it */
.margin-note {
  display: block;
  font-family: var(--f-hand); font-size: 1.28rem; line-height: 1.22; font-weight: 500; color: var(--ink-2);
  padding: 0.1rem 0 0.1rem 0.9rem; border-left: 2px solid var(--line-2);
}
.margin-note :where(code, .en) { font-size: 0.78em; }
.margin-note > * + * { margin-top: 0.4rem; }
@media (min-width: 60em) and (max-width: 68.74em), (min-width: 77.5em) {
  .lesson {
    max-width: calc(var(--measure) + var(--margin-w) + var(--margin-gap) + 2 * var(--pad));
    padding-right: calc(var(--pad) + var(--margin-w) + var(--margin-gap));
  }
  .margin-note {
    float: right; clear: right;
    width: var(--margin-w); margin-right: calc(-1 * (var(--margin-w) + var(--margin-gap)));
    padding: 0; border-left: 0;
    position: relative;
  }
  .margin-note::before { content: ""; position: absolute; left: -1.1rem; top: 0.55em; width: 0.7rem; border-top: 1.5px solid var(--line-2); }
  .lesson .wide { width: calc(100% + var(--margin-w) + var(--margin-gap)); max-width: none; clear: both; }
}

/* lesson head */
.lesson-head { padding-bottom: 1.6rem; border-bottom: 2px solid var(--ink); }
.lesson-head > * + * { margin-top: 0; }
.lesson-no { font-family: var(--f-hand); font-size: 1.75rem; font-weight: 700; line-height: 1; color: var(--ink-2); margin-bottom: 0.15rem; }
.eyebrow { font-family: var(--f-display); font-size: var(--t-xs); font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); }
.lesson-head h1 { margin-top: 0.7rem; }
.lede { margin-top: 1rem; font-size: var(--t-lg); line-height: 1.45; color: var(--ink-2); max-width: 36rem; }
.meta { list-style: none; padding: 0; margin-top: 1.25rem; display: flex; flex-wrap: wrap; gap: 0.4rem 1.4rem; font-family: var(--f-display); font-size: var(--t-sm); color: var(--ink-2); }
.meta li { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; }
.meta .ico { color: var(--ink-3); }

/* "В этом уроке" */
.toc { font-family: var(--f-display); font-size: var(--t-sm); line-height: 1.4; padding: 1rem 0 1.1rem; border-block: 1px solid var(--line); }
.toc-title { font-size: var(--t-xs); font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); }
.toc ol { list-style: none; padding: 0; margin-top: 0.6rem; columns: 2 15rem; column-gap: 2rem; counter-reset: toc; }
.toc li { break-inside: avoid; margin: 0; padding-block: 0.16rem; }
.toc a { display: grid; grid-template-columns: 1.5rem minmax(0, 1fr); width: fit-content; max-width: 100%; color: var(--ink); text-decoration: none; }
.toc-n:empty::before { content: "\00a0"; }   /* service sections carry no number on the page, so none here: the slot keeps the text aligned */
.toc a:hover span:last-child { text-decoration: underline; }
.toc-n { font-family: var(--f-mono); font-size: var(--t-xs); color: var(--ink-3); padding-top: 0.12em; }

/* -------------------------------------------------------------------------
   5. Lesson components
   ------------------------------------------------------------------------- */
/* shared label line of callouts */
.label, .hook::before, .pitfall::before, .tip::before, .story::before, .redpen::before, .cheat::before, .exam::before,
.tasks::before, .bridge::before, .formula > .legend::before {
  font-family: var(--f-display); font-size: var(--t-xs); font-weight: 640; letter-spacing: 0.09em; text-transform: uppercase; line-height: 1.3;
}

/* 2 hook */
.hook { border-top: 2px solid var(--ink); padding: 1rem 0 0.4rem; font-size: var(--t-base); line-height: 1.6; }
.hook::before { content: "Для разгона"; display: block; color: var(--ink-3); margin-bottom: 0.6rem; }
.hook[data-label]::before { content: attr(data-label); }
.hook > * + * { margin-top: 0.9rem; }
.lesson-head + .hook { border-top: 0; }

/* 5 definition & theorem: boxed with a ruler, the way one boxes them in a notebook */
.def, .theorem { position: relative; border: 1.5px solid var(--ink); padding: 1.15rem 1.25rem 1.1rem; margin-top: calc(var(--flow) + 0.7rem) !important; background: var(--paper); }
.theorem { border-width: 4px; border-style: double; }
.def::before, .theorem::before {
  /* the label sits on the top rule like a fieldset legend; in flow, so a long name may wrap */
  content: "Определение"; display: block; width: fit-content; max-width: 100%;
  margin: -1.66rem 0 0.68rem -0.5em; padding: 0 0.5em;
  background: var(--paper);
  font-family: var(--f-display); font-size: var(--t-xs); font-weight: 640; letter-spacing: 0.09em; text-transform: uppercase; line-height: 1.3; color: var(--ink);
}
.theorem::before { content: "Теорема"; margin-top: -1.74rem; }
.theorem[data-name]::before { content: "Теорема · " attr(data-name); }
.def[data-label]::before, .theorem[data-label]::before { content: attr(data-label); }
dfn { font-family: var(--f-display); font-style: normal; font-weight: 660; }

/* 6 formula */
.formula { border-block: 1px solid var(--line); padding: 0.9rem 0 1rem; position: relative; }
.formula > * + * { margin-top: 0.6rem; }
/* the equation number has its own line above the formula: on a phone (or when MathJax is missing) nothing prints over it */
.formula[data-label] { padding-top: 1.75rem; }
.formula[data-label]::after { content: attr(data-label); position: absolute; right: 0; top: 0.45rem; font-family: var(--f-mono); font-size: var(--t-xs); line-height: 1.3; color: var(--ink-3); }
.formula > .legend { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.3rem 0.9rem; font-size: var(--t-md); line-height: 1.45; color: var(--ink-2); padding-top: 0.7rem; border-top: 1px dashed var(--line); }
.formula > .legend::before { content: "где"; grid-column: 1 / -1; color: var(--ink-3); }
.formula > .legend dt { color: var(--ink); text-align: right; }
.formula > .legend dd { margin: 0; }
mjx-container[jax="SVG"][display="true"] { margin: 0.4em 0 !important; overflow-x: auto; overflow-y: hidden; max-width: 100%; padding-block: 0.2em; }
mjx-container[jax="SVG"] { color: inherit; }
mjx-container[jax="SVG"] > svg { max-width: none; }
/* content that is cut at the edge and scrolls sideways says so: it fades out on the cut side (set by course.js) */
.is-scrollable { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 2.25rem), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 2.25rem), transparent); }
.is-scrollable.is-end { -webkit-mask-image: none; mask-image: none; }
.is-scrollable:focus-visible { outline-offset: -2px; }

/* 7 derivation stepper */
.steps { list-style: none; padding: 0; counter-reset: step; border-top: 1px solid var(--line); }
.steps > li { counter-increment: step; position: relative; margin: 0; padding: 1rem 0 1rem 3rem; border-bottom: 1px solid var(--line); }
.steps > li::before { content: counter(step); position: absolute; left: 0; top: 1rem; width: 2rem; height: 2rem; display: grid; place-items: center; border: 1.5px solid var(--ink); border-radius: 50%; font-family: var(--f-mono); font-size: var(--t-sm); font-weight: 600; line-height: 1; }
.steps > li > * + * { margin-top: 0.7rem; }
.js .steps > li.is-new { animation: step-in 0.35s ease-out; }
@keyframes step-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.steps-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-top: 0.9rem !important; font-family: var(--f-display); font-size: var(--t-sm); }
.steps-count { color: var(--ink-3); margin-left: auto; font-family: var(--f-mono); font-size: var(--t-xs); }

/* 8 figures */
.fig { display: block; }
.fig > svg, .fig-panel > svg, .fig > .net, .fig > canvas {
  display: block; width: 100%; height: auto;
  background-color: var(--stage);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--sq) var(--sq); background-position: -1px -1px;
  border: 1px solid var(--line);
}
.fig--plain > svg, .fig--plain .fig-panel > svg, .fig--plain > .net { background-image: none; }
.fig figcaption, .widget-caption { margin-top: 0.6rem; font-family: var(--f-display); font-size: var(--t-sm); line-height: 1.5; color: var(--ink-2); }
.fig figcaption b:first-child, .fig figcaption strong:first-child { color: var(--ink); font-weight: 640; }
.fig--pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem 1rem; }
.fig--pair > figcaption { grid-column: 1 / -1; margin-top: 0; }
.fig-panel { min-width: 0; }
.fig-label { margin-top: 0.4rem; font-family: var(--f-display); font-size: 0.8125rem; font-weight: 640; color: var(--ink-2); }
@media (max-width: 34em) { .fig--pair { grid-template-columns: minmax(0, 1fr); } }

/* SVG authoring: unclassed shapes are ink outlines, unclassed text is ink.
   Lettering sizes are variables, so the phone scale below is one place (and the self-test can simulate it). */
svg.dia, .fig > svg, .fig-panel > svg {
  color: var(--ink); font-family: var(--f-display); overflow: visible;
  --tx: 14px; --tx-mono: 12px; --tx-hand: 23px; --tx-sm: 11px; --tx-lg: 16px;
}
.stage-svg { display: block; width: 100%; height: auto; }
:where(svg.dia, .fig > svg, .fig-panel > svg) :where(path, line, polyline, polygon, circle, ellipse, rect) { fill: none; stroke: var(--ink); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; vector-effect: none; }
:where(svg.dia, .fig > svg, .fig-panel > svg) :where(text) { fill: var(--ink); stroke: none; font-size: var(--tx); font-weight: 500; }
.st-ink { stroke: var(--ink) !important; } .st-muted { stroke: var(--ink-3) !important; } .st-line { stroke: var(--line-2) !important; }
.st-grid { stroke: var(--grid-2) !important; } .st-paper { stroke: var(--stage) !important; } .st-none { stroke: none !important; }
.st-s1 { stroke: var(--s1) !important; } .st-s2 { stroke: var(--s2) !important; } .st-s3 { stroke: var(--s3) !important; }
.st-s4 { stroke: var(--s4) !important; } .st-s5 { stroke: var(--s5) !important; } .st-s6 { stroke: var(--s6) !important; }
.st-good { stroke: var(--good) !important; } .st-bad { stroke: var(--bad) !important; }
/* yellow as a thin stroke is the darker line version; the highlighter itself is .hl (a wide underlay) or a fill */
.st-key { stroke: var(--key-line) !important; }
.hl { stroke: var(--key) !important; stroke-width: 10 !important; stroke-linecap: round; stroke-linejoin: round; fill: none !important; opacity: 0.8; }
.fi-ink { fill: var(--ink) !important; } .fi-muted { fill: var(--ink-3) !important; } .fi-paper { fill: var(--stage) !important; }
.fi-soft { fill: var(--paper-2) !important; } .fi-none { fill: none !important; } .fi-keyline { fill: var(--key-line) !important; }
.fi-s1 { fill: var(--s1) !important; } .fi-s2 { fill: var(--s2) !important; } .fi-s3 { fill: var(--s3) !important; }
.fi-s4 { fill: var(--s4) !important; } .fi-s5 { fill: var(--s5) !important; } .fi-s6 { fill: var(--s6) !important; }
.fi-good { fill: var(--good) !important; } .fi-bad { fill: var(--bad) !important; } .fi-key { fill: var(--key) !important; }
.fw-s1 { fill: color-mix(in srgb, var(--s1) 16%, transparent) !important; } .fw-s2 { fill: color-mix(in srgb, var(--s2) 16%, transparent) !important; }
.fw-s3 { fill: color-mix(in srgb, var(--s3) 16%, transparent) !important; } .fw-s4 { fill: color-mix(in srgb, var(--s4) 16%, transparent) !important; }
.fw-s5 { fill: color-mix(in srgb, var(--s5) 16%, transparent) !important; } .fw-s6 { fill: color-mix(in srgb, var(--s6) 16%, transparent) !important; }
.fw-ink { fill: color-mix(in srgb, var(--ink) 9%, transparent) !important; } .fw-key { fill: color-mix(in srgb, var(--key) 45%, transparent) !important; }
.fw-good { fill: color-mix(in srgb, var(--good) 18%, transparent) !important; } .fw-bad { fill: color-mix(in srgb, var(--bad) 16%, transparent) !important; }
.sw-1 { stroke-width: 1 !important; } .sw-2 { stroke-width: 2 !important; } .sw-3 { stroke-width: 3 !important; } .sw-4 { stroke-width: 4.5 !important; }
.dash { stroke-dasharray: 6 5; } .dots { stroke-dasharray: 0.1 5; stroke-linecap: round; }
.tx-muted { fill: var(--ink-3) !important; } .tx-good { fill: var(--good) !important; } .tx-bad { fill: var(--bad) !important; }
.tx-mono { font-family: var(--f-mono); font-size: var(--tx-mono, 12px) !important; font-weight: 400 !important; }
.tx-hand { font-family: var(--f-hand); font-size: var(--tx-hand, 23px) !important; font-weight: 600 !important; }
.tx-sm { font-size: var(--tx-sm, 11px) !important; } .tx-lg { font-size: var(--tx-lg, 16px) !important; } .tx-bold { font-weight: 680 !important; }
.tx-mid { text-anchor: middle; } .tx-end { text-anchor: end; }
.halo { paint-order: stroke fill; stroke: var(--stage) !important; stroke-width: 4px; stroke-linejoin: round; }
#course-sprite marker path { stroke: none; }
/* Phones: a 560-unit drawing is shown at about 0.64 scale, so its lettering is set ~30 % larger there —
   that keeps every label at 11 px or more on screen. A .fig--pair panel (300 units) is shown near 1:1 and keeps its sizes.
   svg.sim-phone is the same scale switched on by the self-test, to find labels that collide at phone size. */
@media (max-width: 34em) {
  svg.dia, .fig > svg { --tx: 18px; --tx-mono: 17px; --tx-hand: 27px; --tx-sm: 17px; --tx-lg: 20px; }
  .fig--pair svg.dia, .fig-panel > svg { --tx: 14px; --tx-mono: 12px; --tx-hand: 23px; --tx-sm: 11px; --tx-lg: 16px; }
}
svg.dia.sim-phone, .fig > svg.sim-phone { --tx: 18px; --tx-mono: 17px; --tx-hand: 27px; --tx-sm: 17px; --tx-lg: 20px; }

/* 11 callouts */
.pitfall, .tip, .story { background: var(--paper-2); padding: 1rem 1.25rem 1.1rem; position: relative; }
.pitfall > * + *, .tip > * + *, .story > * + * { margin-top: 0.7rem; }
.pitfall::before, .tip::before, .story::before { display: block; color: var(--ink); margin-bottom: 0.55rem; }
.pitfall::before { content: "Ловушка"; }
.pitfall { padding-top: 1.45rem; }
.pitfall::after { content: ""; position: absolute; inset: 0 0 auto 0; height: 7px; background: repeating-linear-gradient(-45deg, var(--ink) 0 5px, transparent 5px 11px); opacity: 0.85; }
.tip::before { content: "Совет"; }
.story { font-size: var(--t-md); }
.story::before { content: "Как это было"; color: var(--ink-3); }
.story[data-year]::before { content: attr(data-year) " · как это было"; }
.pitfall[data-label]::before, .tip[data-label]::before, .story[data-label]::before { content: attr(data-label); }

.why { border-block: 1px solid var(--line); }
.why > summary, .answer > summary, .exam-solution > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 0.5rem;
  font-family: var(--f-display); font-size: var(--t-sm); font-weight: 600; color: var(--ink);
}
.why > summary::-webkit-details-marker, .answer > summary::-webkit-details-marker, .exam-solution > summary::-webkit-details-marker { display: none; }
.why > summary::before, .answer > summary::before, .exam-solution > summary::before {
  content: ""; width: 0.5em; height: 0.5em; flex: none; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform 0.15s; margin-inline: 0.2em 0.15em;
}
.why[open] > summary::before, .answer[open] > summary::before, .exam-solution[open] > summary::before { transform: rotate(45deg); }
.why > summary { padding: 0.75rem 0; font-size: var(--t-md); }
.why > summary:hover { color: var(--link); }
.why[open] { padding-bottom: 1rem; }
.why > summary + * { margin-top: 0.2rem; }

/* red pen: a correction of the source. The red rule is the notebook's margin line. */
.redpen { border-left: 2px solid var(--bad); padding: 0.15rem 0 0.25rem 1.15rem; }
.redpen > * + * { margin-top: 0.65rem; }
/* the two caption texts are set by course.js from the syllabus (course.redpenLabel, course.sourceLabel); these are the fallbacks */
.redpen::before { content: var(--redpen-label, "Красная ручка"); display: block; color: var(--bad); }
.redpen[data-page]::before { content: var(--redpen-page-label, "Красная ручка · источник, стр. ") attr(data-page); }
.redpen .claim { font-style: italic; color: var(--ink-2); text-decoration: underline wavy var(--bad); text-decoration-thickness: 1.5px; text-underline-offset: 0.26em; text-decoration-skip-ink: none; }
.redpen .fix::before, .redpen .because::before { font-family: var(--f-hand); font-size: 1.35rem; font-weight: 700; line-height: 1; color: var(--bad); margin-right: 0.4rem; }
.redpen .fix::before { content: "Правильно:"; }
.redpen .because::before { content: "Почему:"; }
.redpen .because { color: var(--ink-2); }

/* 12 exam */
.exam { position: relative; border: 1px solid var(--ink); background: var(--stage); padding: 1.1rem 1.25rem 1.15rem; }
.exam::before { content: var(--exam-head, "Exam question"); display: block; font-family: var(--f-mono); letter-spacing: 0.06em; font-weight: 600; color: var(--ink-3); margin-bottom: 0.7rem; }
.exam[data-kind="open"]::before { content: var(--exam-head-open, "Exam question · open"); }
.exam[data-kind="numeric"]::before { content: var(--exam-head-numeric, "Exam question · numeric"); }
.exam[data-kind="mcq"]::before { content: var(--exam-head-mcq, "Exam question · multiple choice"); }
/* the label leaves room for the points in the corner: on a narrow screen it wraps instead of printing over them */
.exam[data-points]::before { padding-right: 3.5rem; }
.exam[data-points]::after { content: attr(data-points) var(--exam-points, " pt"); position: absolute; top: 1.1rem; right: 1.25rem; font-family: var(--f-mono); font-size: var(--t-xs); line-height: 1.3; color: var(--ink-3); }
.exam.is-ok .q-verdict { color: var(--good); } .exam.is-fail .q-verdict { color: var(--bad); }
.exam .opt { font-family: var(--f-display); font-size: var(--t-md); }
.exam [lang="en"], .exam-q { font-family: var(--f-display); font-size: var(--t-md); line-height: 1.6; }
.exam-q { font-weight: 480; }
.exam-try { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 0.75rem; font-family: var(--f-display); font-size: var(--t-sm); }
.exam-try label { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--ink-2); }
.exam-try input { width: 8.5rem; min-height: 2.5rem; padding: 0.3rem 0.6rem; font-family: var(--f-mono); font-size: var(--t-md); background: var(--paper); border: 1.5px solid var(--line-2); border-radius: var(--radius); }
.exam-verdict { font-weight: 600; display: inline-flex; align-items: center; gap: 0.35rem; }
.exam-verdict.is-right { color: var(--good); } .exam-verdict.is-wrong { color: var(--bad); }
.exam-solution { border-top: 1px dashed var(--line-2); padding-top: 0.75rem; }
.exam-solution > summary { color: var(--link); }
.exam-solution > summary + * { margin-top: 0.8rem; }
.exam-solution > * + * { margin-top: 0.8rem; }
.exam-answer { padding-left: 1rem; border-left: 1px solid var(--line-2); }
.exam-note { font-family: var(--f-body); font-size: var(--t-md); line-height: 1.6; color: var(--ink-2); }
.exam-note::before { content: "Комментарий"; display: block; font-family: var(--f-display); font-size: var(--t-xs); font-weight: 640; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 0.3rem; }

/* 13 quiz (also the option list of mcq exam questions) */
.quiz .q { padding-top: 1.4rem; border-top: 1px solid var(--line); }
.quiz .q + .q, .quiz > h2 + .q { margin-top: 1.6rem; }
.q-head { font-family: var(--f-mono); font-size: var(--t-xs); color: var(--ink-3); letter-spacing: 0.04em; }
.q-head + * { margin-top: 0.4rem !important; }
.q-text { font-family: var(--f-display); font-size: var(--t-md); font-weight: 560; line-height: 1.45; }
.options { list-style: none; padding: 0; display: grid; gap: 0.5rem; counter-reset: opt; }
.options > li { margin: 0; counter-increment: opt; }
.opt {
  display: grid; grid-template-columns: 1.9rem minmax(0, 1fr); align-items: start; gap: 0.6rem; width: 100%;
  padding: 0.6rem 0.8rem; text-align: left; line-height: 1.5;
  font-family: var(--f-body); font-size: var(--t-md); color: var(--ink);
  background: var(--stage); border: 1.5px solid var(--line-2); border-radius: var(--radius);
}
.opt:hover:not(:disabled) { border-color: var(--ink); background: var(--paper-2); }
.opt:disabled { cursor: default; color: var(--ink); opacity: 1; }
.opt-mark { display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border: 1.5px solid currentColor; border-radius: 50%; font-family: var(--f-mono); font-size: var(--t-xs); font-weight: 600; line-height: 1; margin-top: 0.05rem; }
.q[data-type="multi"] .opt-mark, .options[data-type="multi"] .opt-mark { border-radius: 3px; }
.opt-mark::before { content: counter(opt, upper-latin); }
.opt[aria-checked="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.opt[aria-checked="true"] .opt-mark { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.options > li.is-right .opt { border-color: var(--good); background: var(--good-bg); box-shadow: inset 0 0 0 1px var(--good); }
.options > li.is-right .opt-mark { background: var(--good); border-color: var(--good); color: var(--paper); }
.options > li.is-wrong .opt { border-color: var(--bad); background: var(--bad-bg); box-shadow: inset 0 0 0 1px var(--bad); }
.options > li.is-wrong .opt-mark { background: var(--bad); border-color: var(--bad); color: var(--paper); }
.options > li.is-missed .opt { border-color: var(--good); border-style: dashed; }
.options > li.is-missed .opt-mark { border-color: var(--good); color: var(--good); }
.options > li.is-right .opt-mark::before, .options > li.is-missed .opt-mark::before { content: "✓"; font-family: var(--f-display); font-size: var(--t-md); }
.options > li.is-wrong .opt-mark::before { content: "✗"; font-family: var(--f-display); font-size: var(--t-md); }
.js .options .fb, .js .q-fb { display: none; }
.js .options > li.is-shown .fb, .js .q.is-graded .q-fb, .js .exam.is-graded .q-fb { display: block; }
.fb, .q-fb { font-family: var(--f-display); font-size: var(--t-sm); line-height: 1.5; color: var(--ink-2); }
.options .fb { margin: 0.35rem 0 0.3rem 3.3rem; }
.options > li.is-right .fb::before { content: "Верно. "; color: var(--good); font-weight: 640; }
.options > li.is-wrong .fb::before { content: "Нет. "; color: var(--bad); font-weight: 640; }
.options > li.is-missed .fb::before { content: "Это тоже верный ответ. "; color: var(--good); font-weight: 640; }
.options[data-type="single"] > li.is-missed .fb::before { content: "Правильный ответ. "; }
.q-fb { padding: 0.6rem 0.85rem; background: var(--paper-2); }
.q-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.q-verdict { font-family: var(--f-display); font-size: var(--t-sm); font-weight: 640; display: inline-flex; align-items: center; gap: 0.35rem; }
.q.is-ok .q-verdict { color: var(--good); } .q.is-fail .q-verdict { color: var(--bad); }
.quiz-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem; margin-top: 1.6rem; padding-top: 1rem; border-top: 1px solid var(--line-2); font-family: var(--f-display); font-size: var(--t-sm); }
.quiz-score { font-weight: 600; }
.quiz-score b { font-family: var(--f-mono); font-size: var(--t-md); }
.quiz-foot.is-perfect .quiz-score { color: var(--good); }

/* 14 recap & cheat sheet */
.recap { border-top: 3px solid var(--ink); padding-top: 1.4rem; }
.recap > ul { list-style: none; padding: 0; }
.recap > ul > li { position: relative; padding-left: 1.6rem; }
.recap > ul > li + li { margin-top: 0.7rem; }
.recap > ul > li::before { content: ""; position: absolute; left: 0.15rem; top: 0.62em; width: 0.55rem; height: 0.55rem; background: var(--ink); }
.cheat { position: relative; border: 1.5px dashed var(--ink-3); padding: 1.3rem 1.25rem 1.15rem; margin-top: calc(var(--flow) + 0.7rem) !important;
  background-color: var(--stage);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--sq) var(--sq); }
.cheat::before { content: "✂ Шпаргалка"; position: absolute; top: -0.72em; left: 0.9rem; padding: 0 0.5em; background: var(--paper); color: var(--ink); }
.cheat > * + * { margin-top: 0.7rem; }
.cheat dl { display: grid; grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); gap: 0.55rem 1.1rem; align-items: baseline; font-size: var(--t-md); line-height: 1.45; }
.cheat dt { font-family: var(--f-display); font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); }
.cheat dd { margin: 0; min-width: 0; overflow-x: auto; }
@media (max-width: 34em) { .cheat dl { grid-template-columns: minmax(0, 1fr); gap: 0.15rem; } .cheat dd + dt { margin-top: 0.6rem; } }

/* 15 resources */
.res-list { list-style: none; padding: 0; border-top: 1px solid var(--line); }
.res { margin: 0 !important; padding: 0.95rem 0; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.25rem; font-family: var(--f-display); font-size: var(--t-sm); line-height: 1.45; }
.res > * + * { margin-top: 0; }
.res-kind { display: inline-flex; align-items: center; gap: 0.45rem; font-size: var(--t-xs); font-weight: 640; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); }
html:not(.js) .res::before { content: attr(data-kind) " · " attr(data-when); font-size: var(--t-xs); font-weight: 640; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); }
.res-when { font-weight: 600; letter-spacing: 0.02em; text-transform: none; color: var(--ink-2); border: 1px solid var(--line-2); border-radius: 2px; padding: 0.02rem 0.4rem; }
.res-title { font-size: var(--t-md); font-weight: 620; color: var(--ink); text-decoration-color: var(--line-2); }
.res-title:hover { color: var(--link); text-decoration-color: currentColor; }
.res-title .ico { width: 0.9em; height: 0.9em; margin-left: 0.3em; color: var(--ink-3); }
.res-by, .res-dur { color: var(--ink-2); }
.res-by + .res-dur::before { content: "· "; color: var(--ink-3); }
.res-src { display: flex; flex-wrap: wrap; gap: 0 0.3rem; }
.res-why { font-family: var(--f-body); font-size: var(--t-md); line-height: 1.55; color: var(--ink-2); margin-top: 0.15rem; max-width: 38rem; }

/* 16 bridge to the next lesson */
.bridge { border-top: 1px dashed var(--line-2); padding-top: 1.1rem; }
.bridge::before { content: "Дальше"; display: block; color: var(--ink-3); margin-bottom: 0.4rem; }
.bridge > * + * { margin-top: 0.7rem; }
.bridge-link { display: inline-flex; align-items: center; gap: 0.5rem; font-family: var(--f-display); font-weight: 620; font-size: var(--t-md); color: var(--ink); }
.bridge-link:hover { color: var(--link); }

/* 17 tables, tabs, compare */
.scroll-x { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.tbl { border-collapse: collapse; width: 100%; font-family: var(--f-display); font-size: var(--t-sm); line-height: 1.4; font-variant-numeric: tabular-nums; }
.tbl caption { caption-side: top; text-align: left; font-weight: 600; color: var(--ink-2); padding-bottom: 0.5rem; }
.tbl-fig > figcaption { font-family: var(--f-display); font-size: var(--t-sm); font-weight: 600; line-height: 1.45; color: var(--ink-2); margin-bottom: 0.55rem; }
.tbl th, .tbl td { padding: 0.5rem 0.9rem 0.5rem 0; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.tbl td > * + *, .tbl th > * + * { margin-top: 0.3rem; }
.tbl thead th { font-size: 0.8125rem; font-weight: 640; color: var(--ink-2); border-bottom: 1.5px solid var(--ink); white-space: nowrap; }
.tbl tbody th { font-weight: 620; }
.tbl .n, .tbl td[data-n] { text-align: right; font-family: var(--f-mono); font-size: 0.82rem; }
.tbl tr.is-key > * { background: var(--key-bg); color: var(--key-fg); }
.tbl--center th, .tbl--center td { text-align: center; padding-inline: 0.7rem; }

.tabs-list { display: flex; flex-wrap: wrap; gap: 0 0.25rem; border-bottom: 1px solid var(--line-2); }
.tabs-list button { background: none; border: 0; padding: 0.55rem 0.85rem; min-height: 2.5rem; font-family: var(--f-display); font-size: var(--t-sm); font-weight: 560; color: var(--ink-3); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs-list button:hover { color: var(--ink); background: var(--paper-2); }
.tabs-list button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs > .tab { padding-top: 1rem; }
html:not(.js) .tabs > .tab::before { content: attr(data-tab); display: block; font-family: var(--f-display); font-weight: 640; margin-bottom: 0.4rem; }

.compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-block: 1px solid var(--line); }
.compare-col { padding: 0.9rem 1.2rem 1rem 0; min-width: 0; }
.compare-col + .compare-col { padding: 0.9rem 0 1rem 1.2rem; border-left: 1px solid var(--line); }
.compare-col::before { content: attr(data-label); display: block; font-family: var(--f-display); font-size: 0.8125rem; font-weight: 640; color: var(--ink-3); margin-bottom: 0.5rem; }
.compare-col > * + * { margin-top: 0.7rem; }
.compare-col { font-size: var(--t-md); line-height: 1.55; }
@media (max-width: 34em) {
  .compare { grid-template-columns: minmax(0, 1fr); }
  .compare-col, .compare-col + .compare-col { padding: 0.9rem 0 1rem; border-left: 0; }
  .compare-col + .compare-col { border-top: 1px solid var(--line); }
}

/* the sentence worth memorising */
.memo { font-size: var(--t-base); line-height: 1.55; }
.memo mark.key { font-weight: 500; padding-block: 0.1em; }

/* 18 slide reference: a link that opens a slide of an official deck in the slide viewer (course.js) */
/* the icon lives in the left padding of the link, out of the text flow: an inline icon would be a place where the line
   may break, and a line would end with "(" or start with the icon alone */
a.slide-ref--ico { padding-left: 1.24em; }
.slide-ref-ico { position: relative; }                   /* a zero-width inline box at the start of the link: the anchor of the icon */
.slide-ref-ico::before { content: "\2060"; }             /* a word joiner: gives the box a line to stand on and allows no break */
.slide-ref-ico > .ico { position: absolute; right: 0.24em; top: 50%; width: 1em; height: 1em; max-width: none; margin-top: -0.46em; }
.meta-text { min-width: 0; }
.meta a.slide-ref { color: inherit; text-decoration-color: var(--line-2); }
.meta a.slide-ref:hover { color: var(--link); text-decoration-color: currentColor; }

/* the slide viewer: one native <dialog> per page, created on first use */
.slide-view {
  width: min(80rem, calc(100vw - 1.5rem)); max-width: none;
  max-height: calc(100vh - 1.5rem); max-height: calc(100dvh - 1.5rem);
  margin: auto; padding: 0; overflow: hidden;
  background: var(--paper); color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: var(--radius); box-shadow: var(--shadow);
  font-family: var(--f-display); font-size: var(--t-sm); line-height: 1.4;
}
.slide-view::backdrop { background: var(--scrim); }
.sv-box { display: flex; flex-direction: column; max-height: calc(100vh - 1.5rem - 3px); max-height: calc(100dvh - 1.5rem - 3px); }
.sv-head { display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.35rem 0.4rem 0.35rem 1rem; border-bottom: 1px solid var(--line); }
.sv-title { flex: 1 1 auto; min-width: 0; margin: 0; padding-block: 0.55rem 0.45rem; color: var(--ink-2); }
.sv-title b { color: var(--ink); font-weight: 640; }
.sv-pos { color: var(--ink); font-weight: 560; white-space: nowrap; }
.sv-mark { display: inline-block; margin-left: 0.5rem; padding: 0 0.4rem; border: 1px solid var(--line-2); border-radius: 2px; font-size: var(--t-xs); font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.sv-close { margin-left: auto; }
/* the stage has the proportions of the slide (16:9 until the image has loaded: course.js then sets --sv-ratio) and never
   grows past the window; the image is fitted into it, so a slide is never cropped */
.sv-stage { position: relative; flex: 0 1 auto; min-height: 0; background: var(--stage); aspect-ratio: var(--sv-ratio, 16 / 9); max-height: calc(100vh - 12.5rem); max-height: calc(100dvh - 12.5rem); }
.sv-img { position: absolute; inset: 0; width: 100%; height: 100%; max-width: none; object-fit: contain; }
.sv-miss { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 1rem; color: var(--bad); text-align: center; overflow-wrap: anywhere; }
.sv-foot { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 0.45rem 0.75rem; padding: 0.6rem 0.75rem 0.65rem; border-top: 1px solid var(--line); background: var(--paper-2); }
.sv-info { min-width: 0; display: grid; justify-items: center; gap: 0.35rem; text-align: center; }
.sv-cited { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0.3rem; max-height: 8.2rem; overflow-y: auto; font-size: var(--t-xs); color: var(--ink-3); }
.sv-cited button { min-width: 2rem; min-height: 1.75rem; padding: 0 0.4rem; font-family: var(--f-mono); font-size: var(--t-xs); line-height: 1; color: var(--ink-2); background: var(--paper); border: 1.5px solid var(--line-2); border-radius: var(--radius); }
.sv-cited button:hover { border-color: var(--ink); color: var(--ink); }
.sv-cited button[aria-current="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.sv-cap { margin: 0; font-size: var(--t-xs); color: var(--ink-3); overflow-wrap: anywhere; }
.sv-cap a { color: var(--ink-2); white-space: nowrap; }
.sv-cap .ico { width: 0.95em; height: 0.95em; margin-left: 0.25em; }
@media (max-width: 40em) {
  .slide-view { width: calc(100vw - 0.75rem); }
  .sv-head { padding-left: 0.75rem; }
  .sv-foot { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sv-info { grid-column: 1 / -1; grid-row: 1; }
}

/* -------------------------------------------------------------------------
   6. Widgets
   ------------------------------------------------------------------------- */
.widget { border: 1.5px solid var(--ink); background: var(--paper); border-radius: var(--radius); overflow: hidden; }
.widget > * + * { margin-top: 0; }
.widget-head { padding: 0.8rem 1rem 0.85rem; border-bottom: 1px solid var(--line); }
.widget-tag { display: inline-flex; align-items: center; gap: 0.4rem; font-family: var(--f-display); font-size: var(--t-xs); font-weight: 640; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); }
.widget-title { font-size: var(--t-base); font-weight: 640; margin-top: 0.15rem; }
html:not(.js) .widget > .widget-title, html:not(.js) .widget > .widget-intro { margin: 0.8rem 1rem 0; }
.widget-intro { font-family: var(--f-display); font-size: var(--t-sm); line-height: 1.5; color: var(--ink-2); margin-top: 0.3rem; }
html:not(.js) .widget::after { content: "Интерактивная часть появится, когда в браузере включён JavaScript."; display: block; margin: 0.8rem 1rem; font-family: var(--f-display); font-size: var(--t-sm); color: var(--ink-3); }
.widget-stage { background: var(--stage); min-height: 3rem; position: relative; }
.widget-stage > svg.net, .widget-stage > .net { display: block; }
.plot { position: relative; line-height: 0; }
/* a plot never traps the page scroll: a finger scrolls over it. Only a drag handle takes the finger (course.js),
   and only a plot with a pointer-move handler (.is-capture: free drawing) switches the browser's panning off. */
.plot canvas { display: block; width: 100%; touch-action: pan-y; outline-offset: -3px; }
.plot canvas.is-interactive { cursor: crosshair; }
.plot canvas.is-capture { touch-action: none; }
.plot canvas.is-grab { cursor: grab; } .plot canvas.is-grabbing { cursor: grabbing; }
.widget-legend { display: flex; flex-wrap: wrap; gap: 0.3rem 1.2rem; padding: 0.55rem 1rem; border-top: 1px solid var(--line); background: var(--stage); font-family: var(--f-display); font-size: var(--t-xs); color: var(--ink-2); list-style: none; margin: 0; }
.widget-legend li { display: inline-flex; align-items: center; gap: 0.4rem; margin: 0; }
.lg-key { width: 1.5rem; height: 0.9rem; flex: none; overflow: visible; }
.widget-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12.5rem), 1fr)); gap: 0.85rem 1.4rem; align-items: end; padding: 0.95rem 1rem 1rem; border-top: 1px solid var(--line); background: var(--paper-2); font-family: var(--f-display); font-size: var(--t-sm); }
.widget-controls:empty, .widget-readouts:empty { display: none; }
.ctl { min-width: 0; display: grid; gap: 0.3rem; }
.ctl > label:not(.ctl-toggle), .ctl-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; color: var(--ink-2); font-weight: 520; line-height: 1.3; }
.ctl-val { font-family: var(--f-mono); font-size: var(--t-sm); font-weight: 500; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ctl-btns, .ctl-stepper, .ctl-wide { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.6rem; }
.ctl-stepper .step-label { flex: 1 1 100%; min-width: 0; min-height: 1.6em; color: var(--ink); font-weight: 520; font-size: 0.9375rem; line-height: 1.45; }
.ctl-stepper .step-count { font-family: var(--f-mono); font-size: var(--t-xs); color: var(--ink); white-space: nowrap; padding-inline: 0.2rem; }
.ctl select { width: 100%; min-height: 2.5rem; padding: 0.3rem 0.6rem; background: var(--paper); border: 1.5px solid var(--line-2); border-radius: var(--radius); }
.ctl-toggle { display: inline-flex; align-items: center; gap: 0.6rem; min-height: 2.5rem; color: var(--ink-2); font-weight: 520; cursor: pointer; }
.ctl-toggle input { appearance: none; -webkit-appearance: none; flex: none; width: 2.5rem; height: 1.4rem; margin: 0; border: 1.5px solid var(--line-2); border-radius: 1rem; background: var(--paper); position: relative; cursor: pointer; transition: background-color 0.12s, border-color 0.12s; }
.ctl-toggle input::before { content: ""; position: absolute; top: 2px; left: 2px; width: calc(1.4rem - 7px); height: calc(1.4rem - 7px); border-radius: 50%; background: var(--line-2); transition: transform 0.12s, background-color 0.12s; }
.ctl-toggle input:checked { background: var(--ink); border-color: var(--ink); }
.ctl-toggle input:checked::before { transform: translateX(1.1rem); background: var(--paper); }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 1.75rem; margin: 0; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; background: var(--line-2); border-radius: 2px; }
input[type="range"]::-moz-range-track { height: 4px; background: var(--line-2); border-radius: 2px; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 1.2rem; height: 1.2rem; margin-top: calc(-0.6rem + 2px); border-radius: 50%; background: var(--ink); border: 2px solid var(--paper-2); box-shadow: 0 0 0 1.5px var(--ink); }
input[type="range"]::-moz-range-thumb { width: 1rem; height: 1rem; border-radius: 50%; background: var(--ink); border: 2px solid var(--paper-2); box-shadow: 0 0 0 1.5px var(--ink); }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 1.5px var(--ink), 0 0 0 4.5px var(--focus); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 1.5px var(--ink), 0 0 0 4.5px var(--focus); }

.widget-readouts { display: flex; flex-wrap: wrap; gap: 0.6rem 2rem; padding: 0.8rem 1rem 0.85rem; border-top: 1px solid var(--line); font-family: var(--f-display); }
.ro { min-width: 0; }
.ro-label { display: block; font-size: var(--t-xs); font-weight: 600; color: var(--ink-3); line-height: 1.3; }
.ro-val { display: block; font-family: var(--f-mono); font-size: var(--t-md); line-height: 1.45; color: var(--ink); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ro.is-good .ro-val { color: var(--good); font-weight: 600; } .ro.is-bad .ro-val { color: var(--bad); font-weight: 600; }
.ro.is-key .ro-val { background: var(--key-bg); color: var(--key-fg); padding-inline: 0.3em; margin-inline: -0.3em; display: inline-block; }
.widget-note { grid-column: 1 / -1; font-family: var(--f-display); font-size: var(--t-sm); line-height: 1.5; color: var(--ink-2); margin: 0; }
.widget > .widget-note { padding: 0.7rem 1rem; border-top: 1px solid var(--line); }
.widget-error { padding: 1.2rem 1rem; font-family: var(--f-display); font-size: var(--t-sm); color: var(--bad); line-height: 1.5; }
.widget-error code { display: block; margin-top: 0.3rem; color: var(--ink-2); background: none; border: 0; padding: 0; white-space: pre-wrap; }

.tasks { list-style: none; padding: 1rem 1rem 1.1rem; border-top: 1.5px solid var(--ink); counter-reset: task; font-size: var(--t-md); line-height: 1.55; }
.tasks::before { content: "Попробуй"; display: block; color: var(--ink); margin-bottom: 0.7rem; }
.tasks > li { counter-increment: task; position: relative; padding-left: 2rem; margin: 0; }
.tasks > li + li { margin-top: 0.85rem; }
.tasks > li::before { content: counter(task); position: absolute; left: 0; top: 0.02em; font-family: var(--f-hand); font-size: 1.5rem; font-weight: 700; line-height: 1.15; color: var(--ink-2); }
.tasks > li > * + * { margin-top: 0.45rem; }
.answer { font-size: var(--t-md); }
.answer > summary { display: inline-flex; color: var(--link); font-weight: 560; padding: 0.15rem 0; }
.answer > summary + * { margin-top: 0.35rem; }
.answer > :not(summary) { color: var(--ink-2); padding-left: 1.05rem; border-left: 1px solid var(--line-2); }
/* a standalone "predict first" reveal outside widgets */
.lesson > section > .answer, .lesson > section > * > .answer { font-size: var(--t-md); }

/* -------------------------------------------------------------------------
   7. Course.net — feed-forward network diagram
   ------------------------------------------------------------------------- */
.net { display: block; width: 100%; }
svg.net-svg { display: block; width: 100%; height: auto; margin-inline: auto; font-family: var(--f-display); overflow: visible; }
.net-edge { stroke: var(--ink-3); stroke-width: 1.2; stroke-linecap: round; fill: none; transition: stroke 0.15s, stroke-width 0.15s, opacity 0.15s; }
.net-edge.is-pos { stroke: var(--s1); } .net-edge.is-neg { stroke: var(--s2); stroke-dasharray: 7 4; }
.net-edge.is-hi { stroke: var(--ink); stroke-width: 2.6; } .net-edge.is-dim { opacity: 0.16; }
.net-edge.is-drop { opacity: 0.1; stroke-dasharray: 2 5; }
/* net.flow(): dots travel over the connection (which keeps its own colour and dash: + solid, − dashed),
   and an arrowhead at the end gives the direction even in a still frame or with reduced motion */
.net-flow { stroke: var(--ink); stroke-width: 4.5; stroke-linecap: round; stroke-dasharray: 0.1 16; fill: none; pointer-events: none; animation: net-flow 0.9s linear infinite; }
.net-flow.is-back { animation-direction: reverse; }
@keyframes net-flow { to { stroke-dashoffset: -16.1; } }
.net-edge.c-s1 { stroke: var(--s1); } .net-edge.c-s2 { stroke: var(--s2); } .net-edge.c-s3 { stroke: var(--s3); } .net-edge.c-s4 { stroke: var(--s4); }
.net-edge.c-s5 { stroke: var(--s5); } .net-edge.c-s6 { stroke: var(--s6); } .net-edge.c-good { stroke: var(--good); } .net-edge.c-bad { stroke: var(--bad); }
.net-edge.c-key { stroke: var(--key-line); } .net-edge.c-ink { stroke: var(--ink); } .net-edge.c-muted { stroke: var(--ink-3); }
.net-node circle { fill: var(--stage); stroke: var(--ink); stroke-width: 1.6; transition: fill 0.15s, stroke 0.15s, opacity 0.15s; }
.net-node text { fill: var(--ink); font-size: 14px; font-weight: 560; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.net-node .net-val { font-family: var(--f-mono); font-size: 11px; font-weight: 500; fill: var(--ink-2); paint-order: stroke fill; stroke: var(--stage); stroke-width: 3.5px; stroke-linejoin: round; }
.net-node.is-bias circle { stroke-dasharray: 3 3; stroke: var(--ink-3); }
.net-node.is-bias text { fill: var(--ink-3); }
.net-node.is-hi circle { stroke-width: 3; fill: var(--paper-3); }
.net-node.is-dim { opacity: 0.25; }
.net-node.is-drop circle { stroke-dasharray: 3 4; stroke: var(--ink-3); fill: var(--stage); }
.net-node.is-drop text { opacity: 0.35; }
.net-node .net-x { stroke: var(--ink-3); stroke-width: 1.6; stroke-linecap: round; display: none; }
.net-node.is-drop .net-x { display: block; }
.net-node.c-s1 circle { fill: color-mix(in srgb, var(--s1) 22%, var(--stage)); stroke: var(--s1); }
.net-node.c-s2 circle { fill: color-mix(in srgb, var(--s2) 22%, var(--stage)); stroke: var(--s2); }
.net-node.c-s3 circle { fill: color-mix(in srgb, var(--s3) 22%, var(--stage)); stroke: var(--s3); }
.net-node.c-s4 circle { fill: color-mix(in srgb, var(--s4) 22%, var(--stage)); stroke: var(--s4); }
.net-node.c-s5 circle { fill: color-mix(in srgb, var(--s5) 22%, var(--stage)); stroke: var(--s5); }
.net-node.c-s6 circle { fill: color-mix(in srgb, var(--s6) 22%, var(--stage)); stroke: var(--s6); }
.net-node.c-good circle { fill: var(--good-bg); stroke: var(--good); } .net-node.c-bad circle { fill: var(--bad-bg); stroke: var(--bad); }
.net-node.c-key circle { fill: color-mix(in srgb, var(--key) 45%, var(--stage)); }
.net-node[role="button"] { cursor: pointer; }
.net-node[role="button"]:focus-visible { outline: none; }
.net-node[role="button"]:focus-visible circle { stroke: var(--focus); stroke-width: 3; }
.net-dots { fill: var(--ink-3); font-size: 18px; text-anchor: middle; dominant-baseline: central; }
.net-layer-label { fill: var(--ink-3); font-size: 12px; font-weight: 600; text-anchor: middle; }
/* a weight on a connection: the number on a paper-coloured plate, so the line never strikes it through */
.net-edge-label { pointer-events: none; transition: opacity 0.15s; }
.net-edge-label rect { fill: var(--stage); stroke: var(--line); stroke-width: 1; }
.net-edge-label text { font-family: var(--f-mono); font-size: 11px; font-weight: 500; fill: var(--ink); text-anchor: middle; dominant-baseline: central; }
.net-edge-label.is-dim { opacity: 0.2; }
.net-io { stroke: var(--ink-3); stroke-width: 1.3; fill: none; }

/* -------------------------------------------------------------------------
   8. Lesson end: done, prev / next
   ------------------------------------------------------------------------- */
.lesson-end { max-width: calc(var(--measure) + 2 * var(--pad)); margin: 3.5rem auto 0; padding-inline: var(--pad); font-family: var(--f-display); }
@media (min-width: 60em) and (max-width: 68.74em), (min-width: 77.5em) {
  .lesson-end { max-width: calc(var(--measure) + var(--margin-w) + var(--margin-gap) + 2 * var(--pad)); padding-right: calc(var(--pad) + var(--margin-w) + var(--margin-gap)); }
}
.done-box { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem 1.25rem; padding: 1.15rem 0; border-block: 2px solid var(--ink); }
.done-btn { min-height: 2.9rem; padding-inline: 1.1rem; font-size: var(--t-md); }
.done-btn .done-check { width: 1.35rem; height: 1.35rem; border: 1.5px solid currentColor; border-radius: 3px; display: grid; place-items: center; flex: none; }
.done-btn .done-check .ico { width: 1.05rem; height: 1.05rem; stroke-width: 2.8; opacity: 0; }
.done-btn[aria-pressed="true"] { background: var(--good-bg); color: var(--good); border-color: var(--good); }
.done-btn[aria-pressed="true"]:hover { background: var(--good-bg); color: var(--good); }
.done-btn[aria-pressed="true"] .done-check .ico { opacity: 1; }
.done-note { font-size: var(--t-sm); color: var(--ink-2); }
.pager { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-top: 1.25rem; }
.pager a { display: grid; gap: 0.15rem; padding: 0.7rem 0; color: var(--ink); text-decoration: none; min-width: 0; }
.pager a:hover .pager-title { text-decoration: underline; text-decoration-thickness: 2px; }
.pager-dir { display: inline-flex; align-items: center; gap: 0.35rem; font-size: var(--t-xs); font-weight: 640; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); }
.pager-title { font-size: var(--t-md); font-weight: 620; line-height: 1.3; }
.pager-next { text-align: right; grid-column: 2; }
.pager-next .pager-dir { justify-content: flex-end; }
@media (max-width: 30em) { .pager { grid-template-columns: minmax(0, 1fr); } .pager-next { grid-column: 1; } }

/* -------------------------------------------------------------------------
   9. Hub
   ------------------------------------------------------------------------- */
.hub { max-width: 72rem; margin-inline: auto; padding-inline: var(--pad); padding-block: clamp(1.5rem, 4vw, 3.5rem) 1rem; }
.hub > * + * { margin-top: clamp(2.5rem, 6vw, 4.25rem); }
.hub-head { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr); gap: 2rem 3rem; align-items: center; }
.hub-head > div > * + * { margin-top: 1.1rem; }
.hub-head h1 { font-size: clamp(2.5rem, 1.5rem + 5vw, 4.6rem); font-weight: 760; letter-spacing: -0.035em; line-height: 0.98; }
.hub-lede { font-size: var(--t-lg); line-height: 1.45; color: var(--ink-2); max-width: 34rem; }
.hub-sketch { min-width: 0; }
.hub-sketch svg { display: block; width: 100%; height: auto; background-color: var(--stage);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--sq) var(--sq); background-position: -1px -1px; border: 1px solid var(--line); }
.hub-progress { display: flex; flex-wrap: wrap; align-items: center; gap: 0.9rem 1.5rem; font-family: var(--f-display); padding-top: 0.4rem; }
.hub-meter { flex: 1 1 14rem; max-width: 22rem; min-width: 0; }
.hub-meter-top { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; font-size: var(--t-sm); color: var(--ink-2); }
.hub-meter-top b { font-family: var(--f-mono); font-weight: 600; color: var(--ink); }
.hub-meter-bar { margin-top: 0.35rem; height: 10px; border: 1.5px solid var(--ink); border-radius: 2px; background: var(--stage); overflow: hidden; }
.hub-meter-bar > span { display: block; height: 100%; background: var(--good); }
@media (max-width: 52em) { .hub-head { grid-template-columns: minmax(0, 1fr); } .hub-sketch { max-width: 30rem; } }

.hub h2 { font-size: var(--t-h2); }
/* four steps: 1, 2 or 4 columns — never 3 + 1 */
.hub-how { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.25rem 2.5rem; list-style: none; padding: 1.4rem 0 0; margin-top: 1.25rem; border-top: 2px solid var(--ink); counter-reset: how; }
@media (min-width: 34em) { .hub-how { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 62em) { .hub-how { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.25rem 2rem; } }
.hub-how li { margin: 0; counter-increment: how; position: relative; padding-left: 2.4rem; font-size: var(--t-md); line-height: 1.55; color: var(--ink-2); }
.hub-how li::before { content: counter(how); position: absolute; left: 0; top: -0.2rem; font-family: var(--f-hand); font-weight: 700; font-size: 2.1rem; line-height: 1; color: var(--ink); }
.hub-how b { display: block; font-family: var(--f-display); font-weight: 640; color: var(--ink); font-size: var(--t-md); margin-bottom: 0.15rem; }

.hub-mod + .hub-mod { margin-top: 3rem; }
.hub-mod-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 0.3rem 1.5rem; padding-bottom: 0.8rem; border-bottom: 2px solid var(--ink); }
.hub-mod-n { grid-column: 1 / -1; font-family: var(--f-display); font-size: var(--t-xs); font-weight: 640; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-3); }
.hub-mod-src { font-family: var(--f-display); font-size: var(--t-sm); color: var(--ink-3); text-align: right; }
.hub-mod-count { font-family: var(--f-mono); color: var(--ink-2); }
.hub-list { list-style: none; padding: 0; margin: 0; }
.hub-list > li { margin: 0; border-bottom: 1px solid var(--line); }
.lcard { display: grid; grid-template-columns: 2.6rem minmax(0, 1fr) auto 1.6rem; gap: 0.2rem 1rem; align-items: baseline; padding: 0.95rem 0.5rem 1rem 0.25rem; color: var(--ink); text-decoration: none; }
.lcard:hover { background: var(--paper-2); }
.lcard:hover .lcard-title { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 0.16em; }
.lcard-n { font-family: var(--f-mono); font-size: var(--t-sm); color: var(--ink-3); font-variant-numeric: tabular-nums; grid-row: 1 / span 2; padding-top: 0.2rem; }
.lcard-title { font-family: var(--f-display); font-size: var(--t-base); font-weight: 620; line-height: 1.3; }
.lcard-teaser { grid-column: 2; font-size: var(--t-md); line-height: 1.5; color: var(--ink-2); max-width: 44rem; }
.lcard-meta { grid-column: 3; grid-row: 1; font-family: var(--f-display); font-size: var(--t-xs); color: var(--ink-3); white-space: nowrap; text-align: right; }
/* the tick exists only on finished lessons (an empty box in a row that is a link would read as a checkbox) */
.lcard-box { grid-column: 4; grid-row: 1; align-self: center; width: 1.25rem; height: 1.25rem; border: 1.5px solid var(--good); background: var(--good-bg); border-radius: 3px; display: grid; place-items: center; color: var(--good); }
.lcard-box .ico { width: 1rem; height: 1rem; stroke-width: 2.8; }
.lcard.is-next .lcard-n { color: var(--ink); font-weight: 600; }
.lcard.is-soon, .xcard.is-soon { cursor: default; }
.lcard.is-soon:hover, .xcard.is-soon:hover { background: none; }
.lcard.is-soon .lcard-title, .lcard.is-soon .lcard-teaser, .xcard.is-soon { color: var(--ink-3); }
.lcard.is-soon:hover .lcard-title, .xcard.is-soon:hover .xcard-title { text-decoration: none; }
.lcard-flag { display: inline-block; margin-left: 0.6rem; font-family: var(--f-hand); font-size: 1.25rem; font-weight: 700; line-height: 1; color: var(--ink-2); vertical-align: 0.02em; white-space: nowrap; }
@media (max-width: 40em) {
  .lcard { grid-template-columns: 2rem minmax(0, 1fr) 1.6rem; column-gap: 0.6rem; }
  .lcard-meta { grid-column: 2; grid-row: 3; text-align: left; margin-top: 0.15rem; }
  .lcard-box { grid-column: 3; }
  .hub-mod-head { grid-template-columns: minmax(0, 1fr); } .hub-mod-src { text-align: left; }
}
/* like the four steps above: 1, 2 or 4 in a row — never 3 + 1 */
.hub-extras { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; list-style: none; padding: 0; margin-top: 1.25rem; border-top: 2px solid var(--ink); }
@media (min-width: 34em) { .hub-extras { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 62em) { .hub-extras { grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); } }
.hub-extras li { margin: 0; border-bottom: 1px solid var(--line); }
.xcard { display: grid; gap: 0.25rem; align-content: start; padding: 1rem 1.25rem 1.1rem 0.25rem; height: 100%; color: var(--ink); text-decoration: none; }
.xcard:hover { background: var(--paper-2); }
.xcard:hover .xcard-title { text-decoration: underline; text-decoration-thickness: 2px; }
/* icon on the first line of the title; a fixed two-line block, so the teasers of all cards start at the same height */
.xcard-title { font-family: var(--f-display); font-size: var(--t-md); font-weight: 620; line-height: 1.3; display: flex; align-items: flex-start; gap: 0.5rem; min-height: 2.6em; }
.xcard-title .ico { margin-top: 0.1em; }
.xcard-teaser { font-size: var(--t-md); line-height: 1.5; color: var(--ink-2); }
.hub-fallback { font-family: var(--f-display); }
.page-hub .site-foot { max-width: 72rem; margin-inline: auto; }

/* -------------------------------------------------------------------------
   10. Motion & forced colours
   ------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}
@media (forced-colors: active) {
  .btn, .opt, .widget, .def, .theorem, .exam, .slide-view { border-color: CanvasText; }
  mark.key { outline: 1px solid Highlight; }
}
