/* theme.css */
/* Fonts and colour tokens, ported (values only) from course-lecture-note-template:
   quartz.config.ts palette + quartz/styles/notes/theme.scss. */
@font-face { font-family: "Latin Modern Roman"; src: url("fonts/LatinModernRoman-Regular.otf") format("opentype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Latin Modern Roman"; src: url("fonts/LatinModernRoman-Bold.otf") format("opentype"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Latin Modern Roman"; src: url("fonts/LatinModernRoman-Italic.otf") format("opentype"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Latin Modern Roman"; src: url("fonts/LatinModernRoman-BoldItalic.otf") format("opentype"); font-weight: 700; font-style: italic; font-display: swap; }
@font-face { font-family: "Latin Modern Sans"; src: url("fonts/LatinModernSans-Regular.otf") format("opentype"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Latin Modern Sans"; src: url("fonts/LatinModernSans-Bold.otf") format("opentype"); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: "Latin Modern Mono"; src: url("fonts/LatinModernMono-Regular.otf") format("opentype"); font-weight: 400; font-style: normal; font-display: swap; }
/* qecdk patch (c): JuliaMono (SIL OFL 1.1) covers box-drawing and math Unicode: ─ │ ┌ ⊗ ⊕ ⟨⟩ ∈ ≤ */
@font-face { font-family: "JuliaMono"; src: url("fonts/JuliaMono-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "JuliaMono"; src: url("fonts/JuliaMono-Bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }

:root {
  --light: #fffdf8;
  --lightgray: #e5e0d8;
  --gray: #81796f;
  --darkgray: #2e2a25;
  --dark: #111111;
  --secondary: #2c5f9e;
  --tertiary: #2c7d54;
  --highlight: rgba(44, 95, 158, 0.1);

  --surface: #fffdf8;
  --book-ink: #24201c;
  --line: color-mix(in srgb, var(--lightgray) 82%, var(--dark) 18%);
  --line-strong: color-mix(in srgb, var(--gray) 62%, var(--dark) 38%);
  --shadow-soft: 0 12px 32px rgba(45, 38, 28, 0.06);
  --book-green: #228b22;
  --book-blue: #2d62a0;
  --book-sienna: #a65f2e;
  --book-gold: #b88714;
  --book-orange: #c06318;
  --book-red: #9a0404;

  --font-body: "Latin Modern Roman", "Computer Modern Serif", Georgia, serif;
  --font-sans: "Latin Modern Sans", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JuliaMono", "Latin Modern Mono", "SFMono-Regular", Menlo, monospace;
  color-scheme: light;
}

:root[saved-theme="dark"] {
  --light: #171612;
  --lightgray: #37322c;
  --gray: #95897d;
  --darkgray: #ded7ce;
  --dark: #f7f2e9;
  --secondary: #8ab7f2;
  --tertiary: #8bcfa8;
  --highlight: rgba(138, 183, 242, 0.14);

  --surface: #201f1a;
  --book-ink: #eee7dd;
  --line-strong: color-mix(in srgb, var(--gray) 70%, var(--dark) 30%);
  --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.28);
  --book-green: #7fcf7f;
  --book-blue: #8ab7f2;
  --book-sienna: #e1a06f;
  --book-gold: #e3c363;
  --book-orange: #f0a15f;
  --book-red: #e57373;
  color-scheme: dark;
}

/* Tag colours (dots, chips): per-tag rules come from sheet.yaml; tags without a colour stay gray. */
:root { --tag-default: var(--gray); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--light);
  color: var(--book-ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  text-rendering: optimizeLegibility;
}
a { color: var(--secondary); }
/* JuliaMono's contextual alternates draw `=>` as ⇒ and `->` as →; a reader copying Lean must see
   the characters actually typed, so ligatures stay off in code */
code, kbd { font-family: var(--font-mono); font-size: 0.92em; font-variant-ligatures: none; font-feature-settings: "calt" 0, "liga" 0; }
/* Shiki output (patch a): colours come from per-token CSS variables, one set per theme */
pre.shiki { font-family: var(--font-mono); line-height: 1.45; tab-size: 2; }
pre.shiki code { font-size: 0.86em; }
.shiki span { color: var(--shiki-light); }
:root[saved-theme="dark"] .shiki span { color: var(--shiki-dark); }
kbd {
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  padding: 0 0.3em; background: var(--surface);
}
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
::selection { background: color-mix(in srgb, var(--secondary) 25%, transparent); }
:focus-visible { outline: 2px solid var(--secondary); outline-offset: 2px; }

/* layout.css */
/* Masthead, toolbar, module sections and the 3-column grid. */
.masthead {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--light) 90%, transparent);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
.masthead-row, .toolbar, main, .page-foot { max-width: 1480px; margin: 0 auto; padding-inline: 20px; }
.masthead-row { display: flex; align-items: end; justify-content: space-between; gap: 16px; padding-top: 10px; flex-wrap: wrap; }
.title-block h1 { margin: 0; font-size: 1.55rem; line-height: 1.15; color: var(--dark); }
.course { margin: 0; font-family: var(--font-sans); font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gray); }
.subtitle { margin: 2px 0 0; color: var(--gray); font-style: italic; font-size: 0.95rem; }
.module-nav { display: flex; gap: 4px; flex-wrap: wrap; font-family: var(--font-sans); font-size: 0.85rem; }
.module-nav a { text-decoration: none; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--darkgray); }
.module-nav a:hover { border-color: var(--secondary); color: var(--secondary); }

.toolbar { display: flex; align-items: center; gap: 10px; padding-top: 8px; padding-bottom: 8px; flex-wrap: wrap; }
.search input {
  width: min(260px, 60vw); padding: 5px 10px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--book-ink);
  font-family: var(--font-sans); font-size: 0.9rem;
}
.search input:focus { outline: none; border-color: var(--secondary); box-shadow: 0 0 0 3px var(--highlight); }
.tag-filter { display: flex; gap: 5px; flex-wrap: wrap; }
.match-count { font-family: var(--font-sans); font-size: 0.8rem; color: var(--gray); min-width: 6em; }
.tool-buttons { margin-left: auto; display: flex; gap: 6px; }
.tool {
  font-family: var(--font-sans); font-size: 0.85rem; padding: 4px 11px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface);
}
.tool:hover { border-color: var(--secondary); color: var(--secondary); }
.tool[aria-pressed="true"] { background: var(--secondary); border-color: var(--secondary); color: var(--light); }
.theme-icon::before { content: "☾"; }
:root[saved-theme="dark"] .theme-icon::before { content: "☀"; }

.chip {
  --c: var(--tag-default);
  font-family: var(--font-sans); font-size: 0.75rem; line-height: 1.3;
  padding: 2px 8px; border-radius: 999px; cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--c) 45%, transparent);
  background: color-mix(in srgb, var(--c) 7%, transparent);
  color: var(--c);
}
.chip[aria-pressed="true"] { background: var(--c); color: var(--surface); border-color: var(--c); }
/* .tag-<name> colours come from sheet.yaml (tags: {<name>: {color}}), emitted inline by page.mjs */

/* optional sheet.yaml `intro:` prose above the first module (tutorial / explainer pages) */
.intro { max-width: 72ch; margin: 4px 0 28px; font-size: 1.02rem; line-height: 1.5; }
.intro p { margin: 0 0 0.7em; }

main { padding-top: 14px; padding-bottom: 30px; }
.module { margin-bottom: 34px; scroll-margin-top: 120px; }
/* like \modhead in the PDF: blue bold title with a rule under it */
.module-head { border-bottom: 1.5px solid var(--book-blue); margin-bottom: 12px; padding-bottom: 3px; display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.module-head h2 { margin: 0; font-size: 1.3rem; color: var(--book-blue); }
.module-num { font-family: var(--font-sans); font-size: 0.8em; padding: 0 6px; border-radius: 4px; background: var(--book-blue); color: var(--surface); margin-right: 4px; vertical-align: 0.1em; }
.module-idea { margin: 0; color: var(--gray); font-style: italic; }
.module-sources { margin: 8px 0 0; font-size: 0.8rem; color: var(--gray); font-family: var(--font-sans); }

/* 3 explicit columns with thin rules between them (as in the TikZ sheets). */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; align-items: start; }
.col { display: flex; flex-direction: column; gap: 12px; padding-inline: 12px; min-width: 0; }
.col:first-child { padding-left: 0; }
.col:last-child { padding-right: 0; }
.col + .col { border-left: 1px solid var(--line); }

/* Medium screens: 2 balanced columns; card order is still col 1 → 2 → 3. */
@media (max-width: 1100px) {
  .grid { display: block; column-count: 2; column-gap: 24px; column-rule: 1px solid var(--line); }
  .col { display: contents; }
  .card { break-inside: avoid; margin-bottom: 12px; }
}
@media (max-width: 700px) {
  .grid { column-count: 1; }
  .masthead { position: static; }
  .masthead-row, .toolbar, main, .page-foot { padding-inline: 12px; }
  .tool-buttons { margin-left: 0; }
}

.page-foot { border-top: 1px solid var(--line); padding-top: 10px; padding-bottom: 30px; color: var(--gray); font-size: 0.85rem; font-family: var(--font-sans); }
.page-foot p { margin: 4px 0; }
.references { margin: 16px 0; }
.references summary { cursor: pointer; color: var(--secondary); font-weight: bold; }
.references li { margin: 12px 0; overflow-wrap: anywhere; }
.references a { color: var(--secondary); }

/* Optional group filter (sheet.yaml `groups:`): one part of a large sheet at a time. */
.module[hidden], .nav-group[hidden] { display: none !important; }
.group-filter { display: flex; gap: 4px; flex-wrap: wrap; }
.group-chip { --c: var(--secondary); cursor: pointer; }
.group-chip[aria-pressed="true"] { background: var(--secondary); border-color: var(--secondary); color: var(--light); }
.nav-group { display: inline-flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.nav-group + .nav-group { padding-left: 6px; border-left: 1px solid var(--line); }
.nav-group-label { font-weight: 600; font-size: 0.75rem; letter-spacing: 0.04em; color: var(--gray); padding-right: 2px; }

/* card.css */
/* Cards: template's home-module card (1px line border, 6px radius, surface, soft shadow). */
.card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 10px 12px 8px;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, opacity 0.2s, transform 0.15s;
  scroll-margin-top: 130px;
}
.card:hover, .card:focus-visible {
  border-color: var(--secondary);
  background: color-mix(in srgb, var(--surface) 88%, var(--highlight));
}
.card:active { transform: translateY(1px); }
.card-title { margin: 0 0 6px; font-size: 1.02rem; line-height: 1.2; color: var(--dark); }
.card-face { font-size: 0.92rem; line-height: 1.38; }
.card-face p { margin: 0.2em 0; }
.card-face ul { margin: 0.2em 0; padding-left: 1.2em; }
.card-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.tagdots { display: flex; gap: 4px; }
.tagdot { --c: var(--tag-default); width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.card-more { font-family: var(--font-sans); font-size: 0.72rem; color: var(--gray); opacity: 0; transition: opacity 0.15s; }
.card:hover .card-more, .card:focus-visible .card-more { opacity: 1; color: var(--secondary); }

/* Search / tag filter: dim, don't remove, so the layout never jumps. */
.card.dim { opacity: 0.22; }
.card.dim:hover { opacity: 0.6; }
.card.hit { border-color: color-mix(in srgb, var(--secondary) 60%, var(--line)); }
.module.all-dim .module-head { opacity: 0.4; }

/* Callouts inside cards and modals (3px bar + 6% tint, like the template). */
.callout { --c: var(--secondary); margin: 0.5em 0; padding: 4px 10px; border-left: 3px solid var(--c); background: color-mix(in srgb, var(--c) 6%, transparent); border-radius: 0 4px 4px 0; }
.callout p { margin: 0.25em 0; }
.callout-title { color: var(--c); font-family: var(--font-sans); font-size: 0.85em; text-transform: uppercase; letter-spacing: 0.04em; margin-right: 4px; }
.callout-trap { --c: var(--book-red); }
.callout-key { --c: var(--book-gold); }
.callout-example { --c: var(--tertiary); }
.callout-paper { --c: var(--book-sienna); }
.callout-lecture { --c: var(--book-blue); }

/* Self-test mode: quiz cards show a question that flips to the answer. */
.card-quiz { display: none; }
body.quiz-mode .card[data-quiz] .card-front { display: none; }
body.quiz-mode .card[data-quiz] .card-quiz { display: block; perspective: 900px; }
body.quiz-mode .card:not([data-quiz]) { opacity: 0.35; }
.flip { display: grid; transition: transform 0.45s cubic-bezier(0.4, 0.2, 0.2, 1); transform-style: preserve-3d; }
.flip-q, .flip-a { grid-area: 1 / 1; backface-visibility: hidden; -webkit-backface-visibility: hidden; padding: 4px 0; min-height: 4.5em; font-size: 0.95rem; }
.flip-a { transform: rotateY(180deg); }
.card.flipped .flip { transform: rotateY(180deg); }
.quiz-label {
  display: inline-block; font-family: var(--font-sans); font-weight: 700; font-size: 0.72rem;
  width: 1.5em; height: 1.5em; line-height: 1.5em; text-align: center; border-radius: 50%;
  background: var(--secondary); color: var(--surface); margin-right: 6px; vertical-align: 0.1em;
}
.flip-a .quiz-label { background: var(--book-green); }
@media (prefers-reduced-motion: reduce) { .flip { transition: none; } }

mjx-container[jax="SVG"] { color: inherit; }
.nowrap { white-space: nowrap; }
mjx-container[jax="SVG"][display="true"] { margin: 0.4em 0; overflow-x: auto; overflow-y: hidden; }

/* modal.css */
/* Modal, from the template's figure lightbox (blurred backdrop, 20px frame). */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; }
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(18, 19, 21, 0.5);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  opacity: 0; transition: opacity 0.2s;
}
.modal-frame {
  position: relative;
  width: min(92vw, 1080px); max-height: 88vh;
  display: flex; flex-direction: column;
  border-radius: 20px;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
  opacity: 0; transform: translateY(14px) scale(0.98);
  transition: opacity 0.2s, transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
  outline: none;
}
.modal.open .modal-backdrop { opacity: 1; }
.modal.open .modal-frame { opacity: 1; transform: none; }
@media (prefers-reduced-motion: reduce) { .modal-frame, .modal-backdrop { transition: none; } }

.modal-head { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; column-gap: 12px; padding: 16px 22px 10px; border-bottom: 1px solid var(--line); }
.crumb { grid-column: 1; margin: 0; font-family: var(--font-sans); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--gray); }
/* qecdk patch (g): break-word (not anywhere) and a smaller title on phones, so a long
   identifier such as "native_decide" is never split mid-word at 320 px */
.modal-head h2 { grid-column: 1; margin: 0; font-size: clamp(1.1rem, 5vw, 1.45rem); color: var(--dark); line-height: 1.2; overflow-wrap: break-word; min-width: 0; }
.modal-nav { grid-column: 2; grid-row: 1 / 3; display: flex; gap: 6px; align-items: center; }
.round {
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 1.2rem; line-height: 1;
  border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center;
}
.round:hover { border-color: var(--secondary); color: var(--secondary); }
.round:disabled { opacity: 0.35; cursor: default; }

.modal-body { overflow-y: auto; padding: 14px 22px 22px; overscroll-behavior: contain; }
.modal-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.modal-meta .chip { cursor: default; }
.srcs { display: inline-flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.src { font-family: var(--font-mono); font-size: 0.75rem; color: var(--gray); border: 1px dashed var(--line); border-radius: 4px; padding: 1px 6px; }
.modal-fig { margin: 0 0 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.modal-face { font-size: 1.02rem; padding: 2px 0 8px; border-bottom: 1px dashed var(--line); margin-bottom: 8px; }
.modal-face p { margin: 0.3em 0; }

.prose { font-size: 1rem; line-height: 1.55; }
/* Long chapter equations scroll locally without widening the reading pane. */
.prose .nowrap, .prose mjx-container[jax="SVG"]:not([display="true"]) {
  display: inline-block; max-width: 100%; overflow-x: auto; overflow-y: hidden; vertical-align: middle;
}
.prose mjx-container[jax="SVG"][display="true"] { max-width: 100%; }
/* qecdk patch (h): a long dotted path in inline code (`deltakit.explorer.analysis.calculate_lep_and_lep_stddev`)
   has no break point and pushed the chapter wider than 320 px. break-word splits it only when
   it cannot fit on a line of its own. Code blocks keep their own horizontal scroll. */
.prose :not(pre) > code { overflow-wrap: break-word; }
/* qecdk patch (i): the quiz sits outside .prose; same rule so long inline code there wraps at 320 px. */
.modal-quiz :not(pre) > code, .card-quiz :not(pre) > code { overflow-wrap: break-word; }
.prose h3, .prose h4 { margin: 1em 0 0.3em; color: var(--dark); }
.prose h3 { font-size: 1.12rem; }
.prose h4 { font-size: 1rem; }
.prose p { margin: 0.5em 0; }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0.4em 0; }
.prose li { margin: 0.15em 0; }
.prose table { border-collapse: collapse; margin: 0.6em 0; font-size: 0.93rem; width: 100%; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: 4px 8px; text-align: left; vertical-align: top; }
.prose th { border-bottom: 1.5px solid var(--line-strong); font-family: var(--font-sans); font-size: 0.85rem; }
.prose pre { background: color-mix(in srgb, var(--lightgray) 40%, transparent); padding: 8px 12px; border-radius: 6px; overflow-x: auto; font-size: 0.85rem; }

.modal-quiz { margin-top: 14px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; background: color-mix(in srgb, var(--secondary) 4%, transparent); }
.modal-quiz summary { cursor: pointer; }
.modal-quiz p { margin: 8px 0 2px; }
.modal-quiz p .quiz-label { background: var(--book-green); }

body.modal-open { overflow: hidden; }
@media (max-width: 700px) {
  .modal-frame { width: 100vw; max-height: 100vh; height: 100%; border-radius: 0; }
  .modal-head, .modal-body { padding-inline: 14px; }
  /* Phones: a wide table scrolls inside itself instead of widening the chapter. */
  .prose table { display: block; max-width: 100%; overflow-x: auto; }
}

/* figure.css */
/* SVG figure vocabulary, mirroring the TikZ styles of the PDF sheets.
   box = neutral, good = safe/result, warn = rule/condition, bad = failure, flow = blue arrow, msg = ink. */
.fig-wrap { margin: 2px 0 6px; }
.fig { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--font-body); }
.modal-fig .fig, .modal-fig .d3fig { max-width: 760px; max-height: 56vh; margin: 0 auto; }

.fig .n { stroke-width: 1.1; }
.fig .n-box { fill: var(--surface); stroke: var(--line-strong); }
.fig .n-good { fill: color-mix(in srgb, var(--book-green) 10%, var(--surface)); stroke: var(--book-green); }
.fig .n-warn { fill: color-mix(in srgb, var(--book-gold) 13%, var(--surface)); stroke: var(--book-sienna); }
.fig .n-bad { fill: color-mix(in srgb, var(--book-red) 9%, var(--surface)); stroke: var(--book-red); }
.fig .n-accent { fill: color-mix(in srgb, var(--book-blue) 10%, var(--surface)); stroke: var(--book-blue); }
.fig .n-muted { fill: color-mix(in srgb, var(--lightgray) 45%, var(--surface)); stroke: var(--line); stroke-dasharray: 3 2; }

.fig text, .fig .math { fill: var(--book-ink); color: var(--book-ink); }
.fig text { font-family: var(--font-body); }
.fig .t-bold { font-weight: 700; }
.fig .t-it { font-style: italic; }
.fig .t-good { fill: var(--book-green); color: var(--book-green); }
.fig .t-bad { fill: var(--book-red); color: var(--book-red); }
.fig .t-warn { fill: var(--book-sienna); color: var(--book-sienna); }
.fig .t-accent, .fig .t-flow { fill: var(--book-blue); color: var(--book-blue); }
.fig .t-muted, .fig .t-dash { fill: var(--gray); color: var(--gray); }
.fig .t-msg { fill: var(--book-ink); color: var(--book-ink); }
/* label background: a halo in the surface colour so labels stay readable over lines */
.fig text.halo { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }

.fig .e { fill: none; stroke-width: 1.3; }
.fig .e-flow { stroke: var(--book-blue); }
.fig .e-msg { stroke: var(--book-ink); }
.fig .e-good { stroke: var(--book-green); }
.fig .e-warn { stroke: var(--book-sienna); }
.fig .e-bad { stroke: var(--book-red); stroke-dasharray: 4 3; }
.fig .e-dash, .fig .e-muted { stroke: var(--gray); stroke-dasharray: 3 3; }
.fig .e-accent { stroke: var(--book-blue); stroke-width: 1.8; }
.ah-flow, .ah-accent { fill: var(--book-blue); }
.ah-msg { fill: var(--book-ink); }
.ah-good { fill: var(--book-green); }
.ah-warn { fill: var(--book-sienna); }
.ah-bad { fill: var(--book-red); }
.ah-dash, .ah-muted { fill: var(--gray); }

.fig .life { stroke: var(--line-strong); stroke-dasharray: 2 3; }
.fig .brace { fill: none; stroke: var(--line-strong); stroke-width: 1.1; }
.fig .fr { fill: none; stroke-width: 1.2; }
.fig .fr-dash { stroke: var(--gray); stroke-dasharray: 4 3; }
.fig .fr-good { stroke: var(--book-green); fill: color-mix(in srgb, var(--book-green) 5%, transparent); }
.fig .fr-warn { stroke: var(--book-sienna); fill: color-mix(in srgb, var(--book-gold) 7%, transparent); }
.fig .fr-bad { stroke: var(--book-red); fill: color-mix(in srgb, var(--book-red) 5%, transparent); stroke-dasharray: 4 3; }
.fig .fr-accent { stroke: var(--book-blue); fill: color-mix(in srgb, var(--book-blue) 5%, transparent); }

/* Stepper: future steps are hidden; the current step is emphasised.
   qecdk patch (ii): was opacity 0.08, but ghosts of later steps drawn at the same spot
   overlapped the current labels (stab-tableau, codes-repetition, tools figures). */
.fig [data-step], .fig [data-until] { transition: opacity 0.3s; }
.fig .is-future { opacity: 0; }
.fig [data-past] { opacity: 0; pointer-events: none; }
.fig .is-current .n, .fig .is-current.e, .fig .is-current .e { stroke-width: 2; }

.stepper { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.stepper .round { width: 30px; height: 30px; font-size: 0.95rem; }
.step-count { font-family: var(--font-sans); font-size: 0.8rem; color: var(--gray); min-width: 3.5em; }
.step-caption { flex: 1 1 260px; font-size: 0.98rem; }
.step-dots { display: flex; gap: 4px; }
.step-dots button { width: 9px; height: 9px; padding: 0; border-radius: 50%; border: 1px solid var(--line-strong); background: transparent; cursor: pointer; }
.step-dots button[aria-current="true"] { background: var(--secondary); border-color: var(--secondary); }
.fig-toggles { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }

/* D3 figures share the vocabulary above; these are their extras. */
.d3fig svg { display: block; width: 100%; height: auto; overflow: visible; }
.d3fig .server-ring { stroke-width: 2.4; stroke-dasharray: none; }

/* print.css */
/* Print / save as PDF: A4 landscape, 3 columns, card faces only, one module per page. */
@page { size: A4 landscape; margin: 8mm 9mm; }
@media print {
  :root, :root[saved-theme="dark"] {
    /* always print the light palette */
    --light: #ffffff; --surface: #ffffff; --book-ink: #111; --dark: #111; --gray: #666;
    --lightgray: #e5e0d8; --secondary: #2c5f9e; --tertiary: #2c7d54;
    --line: #cfc8bd; --line-strong: #6f665c;
    --book-green: #228b22; --book-blue: #2d62a0; --book-sienna: #a65f2e; --book-gold: #b88714; --book-orange: #c06318; --book-red: #9a0404;
    color-scheme: light;
  }
  body { font-size: 9pt; line-height: 1.25; background: #fff; }
  .masthead { position: static; border: 0; backdrop-filter: none; }
  .toolbar, .module-nav, .group-filter, .modal, .page-foot .hint, .card-more, .tag-filter, .page-foot, .intro { display: none !important; }
  .masthead-row { padding: 0 0 2mm; }
  .title-block h1 { font-size: 13pt; }
  .subtitle, .course { font-size: 8pt; }
  main { padding: 0; max-width: none; }
  /* one module per A4 page, like the LaTeX sheets: scale the whole module rather than every rule */
  .module { zoom: var(--print-zoom, 0.82); }
  .module { break-before: page; margin: 0; }
  /* the intro is a <section> too, so the first module is not always section:first-of-type */
  .module:first-of-type, .intro + .module { break-before: auto; }
  .module-head { margin-bottom: 2mm; }
  .module-head h2 { font-size: 11pt; }
  .grid { display: grid !important; column-count: initial; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .col { display: flex !important; gap: 1.5mm; padding-inline: 2.5mm; }
  .card { box-shadow: none; padding: 1.5mm 2mm; break-inside: avoid; border-radius: 3px; opacity: 1 !important; margin: 0; }
  .card-title { font-size: 9.5pt; margin-bottom: 1mm; }
  .card-face { font-size: 7.6pt; line-height: 1.2; }
  .card-front { display: block !important; }
  .card-quiz { display: none !important; }
  .tagdots { display: none; }
  .card-meta { display: none; }
  .fig .is-future { opacity: 1; }
  /* figures are full column width on screen; on paper cap their height so a module fits one page */
  .card .fig-wrap { margin: 0.5mm 0 1mm; }
  .card .fig-wrap svg { max-height: 31mm; width: auto; max-width: 100%; margin: 0 auto; }
  .module-sources { font-size: 7pt; }
}

/* MathJax */

mjx-container[jax="SVG"] {
  direction: ltr;
}

mjx-container[jax="SVG"] > svg {
  overflow: visible;
  min-height: 1px;
  min-width: 1px;
}

mjx-container[jax="SVG"] > svg a {
  fill: blue;
  stroke: blue;
}

mjx-container[jax="SVG"][display="true"] {
  display: block;
  text-align: center;
  margin: 1em 0;
}

mjx-container[jax="SVG"][display="true"][width="full"] {
  display: flex;
}

mjx-container[jax="SVG"][justify="left"] {
  text-align: left;
}

mjx-container[jax="SVG"][justify="right"] {
  text-align: right;
}

g[data-mml-node="merror"] > g {
  fill: red;
  stroke: red;
}

g[data-mml-node="merror"] > rect[data-background] {
  fill: yellow;
  stroke: none;
}

g[data-mml-node="mtable"] > line[data-line], svg[data-table] > g > line[data-line] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > rect[data-frame], svg[data-table] > g > rect[data-frame] {
  stroke-width: 70px;
  fill: none;
}

g[data-mml-node="mtable"] > .mjx-dashed, svg[data-table] > g > .mjx-dashed {
  stroke-dasharray: 140;
}

g[data-mml-node="mtable"] > .mjx-dotted, svg[data-table] > g > .mjx-dotted {
  stroke-linecap: round;
  stroke-dasharray: 0,140;
}

g[data-mml-node="mtable"] > g > svg {
  overflow: visible;
}

[jax="SVG"] mjx-tool {
  display: inline-block;
  position: relative;
  width: 0;
  height: 0;
}

[jax="SVG"] mjx-tool > mjx-tip {
  position: absolute;
  top: 0;
  left: 0;
}

mjx-tool > mjx-tip {
  display: inline-block;
  padding: .2em;
  border: 1px solid #888;
  font-size: 70%;
  background-color: #F8F8F8;
  color: black;
  box-shadow: 2px 2px 5px #AAAAAA;
}

g[data-mml-node="maction"][data-toggle] {
  cursor: pointer;
}

mjx-status {
  display: block;
  position: fixed;
  left: 1em;
  bottom: 1em;
  min-width: 25%;
  padding: .2em .4em;
  border: 1px solid #888;
  font-size: 90%;
  background-color: #F8F8F8;
  color: black;
}

foreignObject[data-mjx-xml] {
  font-family: initial;
  line-height: normal;
  overflow: visible;
}

mjx-container[jax="SVG"] path[data-c], mjx-container[jax="SVG"] use[data-c] {
  stroke-width: 3;
}
