/* Harppi — theme. Monospace, hairlines, no shadows, no rounding beyond 3px. Every colour is a
   custom property, so the widgets read them through PK.colors() and follow the theme. */

:root {
  --bg: #fcfcfb;
  --bg-2: #f4f3f0;
  --bg-inset: #efeee9;
  --ink: #16150f;
  --ink-2: #52514e;
  --ink-3: #8a8880;
  --line: #e3e1da;
  --line-2: #cfcdc4;
  --accent: #0e7c72;
  --accent-soft: #0e7c721a;

  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --good: #0ca30c; --warn: #fab219; --bad: #d03b3b;
  --pos: #2a78d6; --neg: #e34948; --mid: #f0efec;

  --mono: "JetBrains Mono", "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", ui-monospace, monospace;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "Source Serif 4", "Charter", Georgia, serif;
  --measure: 72ch;
  --fs: 14.5px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #1a1a19;
  --bg-2: #1f1f1e;
  --bg-inset: #141413;
  --ink: #e3e2dc;
  --ink-2: #a9a89f;
  --ink-3: #6f6e67;
  --line: #2e2e2c;
  --line-2: #3e3e3b;
  --accent: #5fd3c4;
  --accent-soft: #5fd3c422;

  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #22a822; --s7: #9085e9; --s8: #e66767;
  --good: #0ca30c; --warn: #fab219; --bad: #d03b3b;
  --pos: #3987e5; --neg: #e66767; --mid: #383835;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: var(--fs);
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  font-variant-ligatures: none;
}
::selection { background: var(--accent-soft); }
:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
button, input, textarea { font-family: var(--mono); }

/* ── layout: the header, then the notebook or the guide filling the window ──── */

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#body[hidden], #guide[hidden] { display: none; }

/* the header: brand and notebook on the left, notebook | board in the middle, actions on the right.
   Every control is 28px tall and 12px type; only ask carries a mark, only the theme an icon. */
#head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  height: 46px; padding: 0 10px 0 14px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.head-l, .head-r { display: flex; align-items: center; gap: 2px; min-width: 0; }
.head-r { justify-self: end; }
.head-sep { flex: none; width: 1px; height: 16px; background: var(--line); margin: 0 8px; }
.brand { flex: none; display: inline-flex; align-items: center; gap: 7px; color: var(--ink); text-decoration: none; }
.brand .mark { width: 19px; height: 19px; color: var(--accent); }
.brand .name { font-size: 12.5px; letter-spacing: 0.16em; font-weight: 600; }
.pad-doc, #head .pad-btn, .pad-tab {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; font: inherit; font-size: 12px; line-height: 1;
  color: var(--ink-2); background: none; border: 0; border-radius: 4px; padding: 0 10px; cursor: pointer; text-decoration: none;
}
.pad-doc { min-width: 0; max-width: 34vw; gap: 4px; color: var(--ink); padding: 0 8px; }
.pad-doc .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad-doc .v { display: inline-flex; color: var(--ink-3); }
.pad-doc .v .ico { width: 12px; height: 12px; }
.pad-doc:hover, #head .pad-btn:hover { background: var(--bg-2); color: var(--ink); }
#head .pad-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.pad-tabs { display: inline-flex; gap: 2px; padding: 2px; background: var(--bg-inset); border-radius: 5px; }
.pad-tab { height: 24px; padding: 0 12px; color: var(--ink-3); border: 1px solid transparent; border-radius: 3px; }
.pad-tab:hover { color: var(--ink); }
.pad-tab[aria-pressed="true"] { background: var(--bg); color: var(--ink); border-color: var(--line); }
#head .ico { flex: none; width: 14px; height: 14px; }
#head .ask-btn { color: var(--accent); }
#head .ask-btn .mark { font-family: KaTeX_Main, "Times New Roman", serif; font-size: 15px; line-height: 1; }
#head .lang { gap: 2px; padding: 0 5px; font-size: 10.5px; letter-spacing: 0.06em; }
#head .lang span { padding: 3px 4px; border-radius: 3px; color: var(--ink-3); }
#head .lang span.on { color: var(--ink); background: var(--bg-inset); }
#head .theme { padding: 0 7px; }
#head .theme .sun, :root[data-theme="dark"] #head .theme .moon { display: none; }
:root[data-theme="dark"] #head .theme .sun { display: block; }
@media (max-width: 760px) {
  #head { gap: 8px; padding: 0 6px 0 12px; }
  .brand .name, .head-sep, #head .ask-btn span:not(.mark), #head [data-act="export"], #head [data-act="guide"] { display: none; }
  .pad-doc { padding-left: 6px; }
  .pad-tab { padding: 0 9px; }
}

kbd {
  font: inherit; font-size: 10px; background: var(--bg-inset); border: 1px solid var(--line);
  border-radius: 3px; padding: 0 4px; color: var(--ink-3);
}

/* ── reading: the rendered notebook, the guide and the printed page in a serif ─── */

.pad-view, .guide-body, #print { font-family: var(--serif); font-size: 16px; line-height: 1.6; }
.pad-view h2, .pad-view h3, .guide-body h2, .guide-body h3, #print h2, #print h3, #print .ch-title { font-family: var(--serif); letter-spacing: 0; }
.pad-view code, .guide-body code, #print code, .pad-view pre, .guide-body pre, #print pre,
.pad-view .widget, .guide-body .widget, #print .widget, .pad-view table, .guide-body table, #print table,
.callout > .c-head, .ex > .c-head, details.sol > summary, .meta, .pad-view .wk-error, .guide-body .wk-error { font-family: var(--mono); }
.pad-view .katex, .guide-body .katex, #print .katex { font-size: 1.02em; }
.pad-view p, .guide-body p { margin: 0 0 12px; }
.pad-view li, .guide-body li { margin: 2px 0; }
.guide-body h2 { font-size: 22px; font-weight: 600; margin: 52px 0 14px; padding-bottom: 8px; }
.guide-body h3 { font-size: 17px; font-weight: 600; margin: 32px 0 10px; }
.guide-body table { font-size: 13px; }

/* ── the guide ──────────────────────────────────────────────────────────── */

#guide { flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: smooth; }
.guide-wrap {
  display: grid; grid-template-columns: minmax(0, var(--measure)) 220px; gap: 48px;
  justify-content: center; padding: 48px 40px 200px;
}
.guide-toc { position: sticky; top: 0; align-self: start; font-size: 12px; max-height: calc(100dvh - 48px); overflow-y: auto; }
.guide-toc .o-h { color: var(--ink-3); font-size: 10px; letter-spacing: 0.13em; text-transform: uppercase; margin-bottom: 8px; }
.guide-toc a {
  display: block; color: var(--ink-3); text-decoration: none; padding: 2px 0 2px 10px;
  border-left: 1px solid var(--line); line-height: 1.4;
}
.guide-toc a.lv3 { padding-left: 22px; }
.guide-toc a:hover { color: var(--ink-2); }
.guide-toc a.active { color: var(--accent); border-left-color: var(--accent); }
.guide-toc .katex { font-size: 1em; }
.guide-back + h2 { margin-top: 0; }
.guide-back {
  display: inline-block; font-family: var(--mono); font-size: 11px; letter-spacing: 0.02em; color: var(--ink-3);
  text-decoration: none; margin-bottom: 20px;
}
.guide-back:hover { color: var(--accent); }
.guide-toc .guide-back { display: block; margin-bottom: 16px; }
@media (max-width: 1100px) { .guide-wrap { grid-template-columns: minmax(0, var(--measure)); } .guide-toc { display: none; } }
@media (max-width: 700px) { .guide-wrap { padding: 28px 18px 120px; } }

/* the header block of a hand-in: name · course · date */
.meta { color: var(--ink-2); font-size: 12px; letter-spacing: 0.02em; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin: 0 0 16px; }
.meta span + span::before { content: " · "; color: var(--ink-3); }

article { min-width: 0; }
.ch-eyebrow { color: var(--ink-3); font-size: 11px; letter-spacing: 0.13em; text-transform: uppercase; }
.ch-title { font-size: 27px; line-height: 1.25; margin: 8px 0 6px; font-weight: 600; letter-spacing: -0.01em; }
.ch-blurb { color: var(--ink-2); margin: 0 0 12px; }
.ch-meta { color: var(--ink-3); font-size: 11.5px; border-bottom: 1px solid var(--line); padding-bottom: 20px; margin-bottom: 30px; }

article h2 {
  font-size: 17px; font-weight: 600; margin: 46px 0 14px; letter-spacing: -0.005em;
  padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
article h3 { font-size: 14.5px; font-weight: 600; margin: 30px 0 10px; color: var(--ink); }
article h2 .anchor, article h3 .anchor {
  opacity: 0; color: var(--ink-3); text-decoration: none; margin-left: 8px; font-weight: 400;
}
article h2:hover .anchor, article h3:hover .anchor { opacity: 1; }
article p { margin: 0 0 15px; }
article ul, article ol { margin: 0 0 15px; padding-left: 22px; }
article li { margin: 3px 0; }
article li > ul, article li > ol { margin: 3px 0; }
article a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
article a:hover { border-bottom-color: var(--accent); }
article hr { border: 0; border-top: 1px solid var(--line); margin: 34px 0; }
article strong { font-weight: 600; color: var(--ink); }
article em { font-style: italic; color: var(--ink); }
code {
  font-family: var(--mono); font-size: 0.9em; background: var(--bg-inset);
  border: 1px solid var(--line); border-radius: 3px; padding: 0.5px 4px;
}
pre { background: var(--bg-inset); border: 1px solid var(--line); border-radius: 3px; padding: 12px 14px; overflow-x: auto; margin: 0 0 16px; }
pre code { background: none; border: 0; padding: 0; font-size: 12.5px; line-height: 1.6; }
/* a ```try example: the source, and under it what the notebook makes of it */
.try { border: 1px solid var(--line); border-radius: 3px; margin: 0 0 16px; overflow: hidden; }
.try > pre { border: 0; border-radius: 0; border-bottom: 1px solid var(--line); margin: 0; white-space: pre-wrap; overflow-wrap: break-word; }
.try-out { padding: 12px 14px; }
.try-out > :first-child { margin-top: 0; }
.try-out > :last-child { margin-bottom: 0; }
.try-out .katex-display { margin: 8px 0; }

table { border-collapse: collapse; width: 100%; margin: 0 0 18px; font-size: 13px; }
th, td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; }
th { background: var(--bg-2); font-weight: 600; color: var(--ink-2); font-size: 11.5px; letter-spacing: 0.03em; }
tbody tr:hover { background: var(--bg-2); }

blockquote { margin: 0 0 16px; padding: 2px 0 2px 16px; border-left: 2px solid var(--line-2); color: var(--ink-2); }

/* ── callouts ───────────────────────────────────────────────────────────── */

.callout {
  border: 1px solid var(--line); border-left-width: 2px; border-radius: 3px;
  background: var(--bg-2); padding: 12px 16px 2px; margin: 0 0 18px;
}
.callout > .c-head {
  font-size: 10.5px; letter-spacing: 0.13em; text-transform: uppercase;
  color: var(--c, var(--ink-3)); margin-bottom: 8px; font-weight: 600;
}
.callout > .c-head .c-name { color: var(--ink); letter-spacing: 0; text-transform: none; font-size: 13px; font-weight: 600; }
.callout > .c-head .c-name::before { content: "· "; color: var(--ink-3); }
.callout p:last-child { margin-bottom: 12px; }
.callout ul, .callout ol { margin-bottom: 12px; }

.c-definition { --c: var(--s1); border-left-color: var(--s1); }
.c-theorem    { --c: var(--s7); border-left-color: var(--s7); }
.c-lemma, .c-proposition, .c-corollary { --c: var(--s7); border-left-color: var(--line-2); }
.c-proof      { --c: var(--ink-3); border-left-color: var(--line-2); background: transparent; }
.c-example    { --c: var(--s3); border-left-color: var(--s3); }
.c-intuition  { --c: var(--s4); border-left-color: var(--s4); }
.c-note       { --c: var(--ink-3); border-left-color: var(--line-2); }
.c-warning    { --c: var(--s2); border-left-color: var(--s2); }
.c-history    { --c: var(--s5); border-left-color: var(--s5); background: transparent; }
.c-recap      { --c: var(--accent); border-left-color: var(--accent); }
.c-proof > p:last-of-type::after { content: " ∎"; color: var(--ink-3); }

/* ── exercises ──────────────────────────────────────────────────────────── */

.ex { border: 1px solid var(--line); border-radius: 3px; margin: 0 0 14px; background: var(--bg-2); }
.ex > .c-head { padding: 11px 16px 0; }
.ex > .c-head .c-name::before { content: " · "; color: var(--ink-3); font-weight: 400; }
.ex > .c-head .tier {
  border: 1px solid currentColor; border-radius: 2px; padding: 0 4px; margin-left: 8px;
  font-size: 9px; letter-spacing: 0.1em;
}
.ex-body { padding: 8px 16px 4px; }
.ex-body > p:last-child { margin-bottom: 12px; }
.tier-warmup    { --c: var(--ink-3); }
.tier-core      { --c: var(--s1); }
.tier-hard      { --c: var(--s2); }
.tier-challenge { --c: var(--s8); }
.ex.tier-core      { border-left: 2px solid var(--s1); }
.ex.tier-hard      { border-left: 2px solid var(--s2); }
.ex.tier-challenge { border-left: 2px solid var(--s8); }
.ex.tier-warmup    { border-left: 2px solid var(--line-2); }

details.sol { border-top: 1px solid var(--line); background: var(--bg); border-radius: 0 0 3px 3px; }
details.sol > summary {
  cursor: pointer; list-style: none; padding: 7px 16px; font-size: 11px;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3);
}
details.sol > summary::-webkit-details-marker { display: none; }
details.sol > summary::before { content: "▸ "; }
details.sol[open] > summary::before { content: "▾ "; }
details.sol > summary:hover { color: var(--accent); }
.sol-body { padding: 4px 16px 2px; border-top: 1px solid var(--line); }
.sol-body > p:last-child { margin-bottom: 14px; }

/* ── widgets ────────────────────────────────────────────────────────────── */

.widget {
  border: 1px solid var(--line); border-radius: 3px; margin: 0 0 20px;
  background: var(--bg); overflow: hidden;
}
.widget-body { padding: 10px 12px 4px; }
.wk-controls {
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--bg-2);
  font-size: 11.5px; color: var(--ink-2);
}
.wk-controls label { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.wk-controls input[type="range"] { accent-color: var(--accent); width: 120px; height: 14px; }
.wk-controls input[type="number"], .wk-controls select {
  font: inherit; font-size: 11.5px; background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 3px; padding: 1px 5px;
}
.wk-controls button {
  font: inherit; font-size: 11px; background: var(--bg); color: var(--ink-2);
  border: 1px solid var(--line); border-radius: 3px; padding: 2px 8px; cursor: pointer;
}
.wk-controls button:hover { color: var(--ink); border-color: var(--line-2); }
.wk-controls button[aria-pressed="true"], .wk-controls button.on {
  background: var(--accent-soft); color: var(--accent); border-color: var(--accent);
}
.wk-readout { font-size: 11.5px; color: var(--ink-2); margin-left: auto; white-space: nowrap; }
/* PK.readout() emits .wk-out. Long readouts wrap rather than overflowing the control row. */
.wk-out {
  font-size: 11.5px; color: var(--ink-2); margin-left: auto; text-align: right;
  flex: 1 1 auto; min-width: 0; line-height: 1.45;
}
.wk-out b, .wk-out strong { color: var(--ink); font-weight: 600; }
.wk-caption {
  font-size: 12px; color: var(--ink-2); padding: 8px 12px 10px;
  border-top: 1px solid var(--line); background: var(--bg-2); line-height: 1.6;
}
.wk-tooltip {
  position: absolute; pointer-events: none; z-index: 5; font-size: 11px;
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 3px;
  padding: 3px 7px; color: var(--ink); white-space: pre; line-height: 1.45;
}
.wk-error { color: var(--bad); font-size: 12px; padding: 14px; }
.widget canvas { display: block; width: 100%; }
.fig { display: block; margin: 0 auto 18px; max-width: 100%; color: var(--ink-2); }
.fig text { font-family: var(--mono); font-size: 11px; fill: var(--ink-2); }

/* ── katex ──────────────────────────────────────────────────────────────── */

.katex { font-size: 1.04em; }
.katex-display { margin: 18px 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.katex-display > .katex { font-size: 1.06em; }

/* ── the notebook (pad.js) ──────────────────────────────────────────────── */

#pad { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; background: var(--bg); overflow: hidden; }

/* the title and export menus */
.pad-menu {
  position: absolute; z-index: 6; min-width: 250px; max-width: 380px; max-height: 70%; overflow-y: auto; padding: 4px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 1px 4px #0000000f;
}
.pad-menu .row { display: flex; align-items: stretch; }
.pad-menu .item {
  flex: 1; display: flex; justify-content: space-between; align-items: baseline; gap: 14px; min-width: 0; text-align: left;
  font: inherit; font-size: 12px; color: var(--ink-2); background: none; border: 0; border-radius: 3px; padding: 5px 8px; cursor: pointer;
}
.pad-menu .item:hover:not(:disabled) { background: var(--bg); color: var(--ink); }
.pad-menu .item.on { color: var(--accent); }
.pad-menu .item:disabled { color: var(--ink-3); cursor: default; font-size: 11px; }
.pad-menu .item .l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pad-menu .item .h { flex: none; color: var(--ink-3); font-size: 10.5px; }
.pad-menu .x { flex: none; font: inherit; font-size: 13px; color: var(--ink-3); background: none; border: 0; padding: 0 8px; cursor: pointer; border-radius: 3px; }
.pad-menu .x:hover { color: var(--bad); background: var(--bg); }
.pad-menu .sep { height: 1px; background: var(--line); margin: 4px 2px; }
.pad-btn {
  font: inherit; font-size: 11px; color: var(--ink-2); background: var(--bg);
  border: 1px solid var(--line); border-radius: 3px; padding: 2px 8px; cursor: pointer;
}
.pad-btn:hover { border-color: var(--line-2); color: var(--ink); }
.pad-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* the notebook: one column of blocks, each rendered in place; an outline beside it when maximised */
.pad-body { flex: 1; min-height: 0; display: flex; }
.pad-view { flex: 1; min-width: 0; min-height: 0; overflow-y: auto; padding: 16px 20px 40vh; font-size: 13.5px; }
.pad-outline { display: none; flex: none; width: 210px; overflow-y: auto; padding: 18px 14px 40px 18px; border-right: 1px solid var(--line); font-size: 12px; }
.pad-outline a {
  display: block; color: var(--ink-3); text-decoration: none; padding: 2px 0 2px 10px;
  border-left: 1px solid var(--line); line-height: 1.4; cursor: pointer;
}
.pad-outline a.lv3 { padding-left: 22px; }
.pad-outline a:hover { color: var(--ink-2); }
.pad-outline a.active { color: var(--accent); border-left-color: var(--accent); }
.pad-outline .katex { font-size: 1em; }
@media (min-width: 1000px) {
  body:not(.no-outline) #pad:not([data-mode="board"]) .pad-outline:not([hidden]) { display: block; }
  /* the notebook keeps a readable measure however wide the window */
  .pad-view { padding-left: max(24px, calc((100% - 84ch) / 2)); padding-right: max(24px, calc((100% - 84ch) / 2)); }
}
.pad-block {
  padding: 3px 10px; margin: 0 -10px 8px; border-left: 2px solid transparent; border-radius: 3px;
  cursor: text; transition: border-color 90ms;
}
.pad-block:not(.active):hover { border-left-color: var(--line-2); }
.pad-block.active { border-left-color: var(--accent); cursor: auto; }
.pad-block > :last-child { margin-bottom: 0; }
/* the block being edited: its source, and the live result right beneath */
.pad-src {
  display: block; width: 100%; margin: 0; padding: 7px 10px; resize: none; outline: none; overflow: hidden;
  font: inherit; font-family: var(--mono); font-size: 13px; line-height: 1.6; color: var(--ink); background: var(--bg-inset);
  border: 0; border-radius: 3px; tab-size: 2;
}
.pad-src::placeholder { color: var(--ink-3); }
.pad-live { padding-top: 10px; }
.pad-live > :last-child { margin-bottom: 0; }
.pad-view h2 { font-size: 21px; margin: 18px 0 8px; padding-bottom: 6px; }
.pad-view h3 { font-size: 17px; margin: 14px 0 6px; }
.pad-view .meta { margin-top: 4px; }
.pad-view .anchor { display: none; }
.pad-view p { margin: 0 0 8px; }
.pad-view ul, .pad-view ol { margin-bottom: 8px; }
.pad-view .katex-display { margin: 6px 0; }
.pad-view .callout, .pad-view .widget, .pad-view .ex { margin-bottom: 8px; }

/* the symbol strip: the common snippets to tap, or the completions for the word being typed */
.pad-strip {
  display: flex; align-items: center; gap: 4px; padding: 6px 10px;
  border-top: 1px solid var(--line); background: var(--bg-2); overflow-x: auto; scrollbar-width: none;
}
.pad-strip::-webkit-scrollbar { display: none; }
.pad-chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: 26px;
  font: inherit; font-size: 12px; line-height: 1.4; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 3px; padding: 1px 7px; cursor: pointer;
}
.pad-chip:hover { border-color: var(--line-2); }
.pad-chip.sel { border-color: var(--accent); background: var(--accent-soft); }
.pad-chip .katex { font-size: 1em; }
.pad-chip .k { font-size: 10.5px; color: var(--ink-3); }
.pad-chip.more { color: var(--ink-3); font-size: 11px; }
.pad-chip.tpl b { font-weight: 500; }
.pad-chip.tpl .k { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* "more": every snippet, grouped, with a search box; opens above the strip */
.pad-panel { flex: none; max-height: 50%; overflow-y: auto; border-top: 1px solid var(--line); background: var(--bg); }
.pad-search {
  display: block; width: 100%; font: inherit; font-size: 12.5px; color: var(--ink); background: var(--bg-inset);
  border: 0; border-bottom: 1px solid var(--line); padding: 7px 12px; outline: none;
}
.pad-search::placeholder { color: var(--ink-3); }
.pad-group { padding: 8px 10px 4px; }
.pad-group .g { font-size: 10px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 5px; }
.pad-group .chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 4px; }
.pad-group .pad-chip { justify-content: space-between; min-width: 0; }
.pad-group .pad-chip .k { overflow: hidden; text-overflow: ellipsis; }


/* ── print: the pdf export ──────────────────────────────────────────────── */

/* #print is built on screen at page width but invisible, so its canvases size themselves once;
   while printing it is the only thing on the page. */
#print { position: fixed; left: 0; top: 0; width: 170mm; visibility: hidden; z-index: -1; background: var(--bg); }
#print .anchor { display: none; }
#print .meta { margin: -8px 0 22px; }
#print .ch-title { font-size: 22pt; margin: 0 0 20px; }
#print h2 { margin-top: 30px; }
#print .mx { cursor: auto; }
#print details.sol > summary { list-style: none; }
#print details.sol > summary::before { content: ""; }
.bd-print { position: relative; overflow: hidden; margin: 0 auto; }
.bd-print img { display: block; }
@media print {
  @page { margin: 18mm 20mm 20mm; @bottom-center { content: counter(page); font-family: monospace; font-size: 9pt; color: #888; } }
  html, body { height: auto; background: #fff; }
  body.printing > :not(#print) { display: none !important; }
  body.printing #print { position: static; visibility: visible; width: 170mm; margin: 0 auto; font-size: 10.5pt; line-height: 1.55; }
  #print * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #print .callout, #print .widget, #print .ex, #print pre, #print table, #print .katex-display { break-inside: avoid; }
  #print h2, #print h3, #print .c-head { break-after: avoid; }
  #print .katex-display { overflow: visible; }
  #print .mx:hover, #print .mx.lit { background: none; box-shadow: none; }
}

/* ── whiteboard (board.js) ──────────────────────────────────────────────── */

#pad[data-mode="board"] .pad-view { display: none; }
#pad:not([data-mode="board"]) .pad-board { display: none; }
/* on the board the strip only matters while a note is being written */
#pad[data-mode="board"]:not(.editing) .pad-strip, #pad[data-mode="board"]:not(.editing) .pad-panel { display: none; }

.pad-board { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* The controls float over the canvas: undo and zoom top-left, the tools down the left edge,
 * colours and sizes down the right edge. Between the pills the canvas takes the pointer. */
.bd-ui { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.bd-pill {
  position: absolute; display: flex; align-items: center; gap: 2px; padding: 3px; pointer-events: auto;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 1px 4px #0000000f;
}
.bd-pill[hidden] { display: none; }
.bd-corner { left: 10px; top: 10px; }
.bd-tools, .bd-style { top: 50%; transform: translateY(-50%); flex-direction: column; }
.bd-tools { left: 10px; align-items: stretch; }
.bd-style { right: 10px; }
.bd-pill button {
  font: inherit; font-size: 11px; line-height: 1.4; color: var(--ink-2); background: none;
  border: 1px solid transparent; border-radius: 4px; padding: 2px 7px; cursor: pointer;
}
.bd-pill button:hover { color: var(--ink); background: var(--bg); }
.bd-pill button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.bd-tools button { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.bd-pill kbd { font: inherit; font-size: 9.5px; color: var(--ink-3); }
.bd-pill button[aria-pressed="true"] kbd { color: inherit; opacity: 0.7; }
.bd-pill .bd-color { width: 18px; height: 18px; padding: 0; margin: 2px; border-radius: 50%; background: var(--c); }
.bd-pill .bd-color:hover { background: var(--c); }
.bd-pill .bd-color[aria-pressed="true"] { background: var(--c); box-shadow: 0 0 0 2px var(--bg-2), 0 0 0 3px var(--accent); }
.bd-sizes { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.bd-pill [data-size] { width: 26px; padding: 2px 0; text-align: center; }
.bd-pill [data-act="zoom"] { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }
.bd-sep { width: 1px; height: 16px; background: var(--line); margin: 0 3px; }
.bd-style .bd-sep { width: 16px; height: 1px; margin: 3px 0; }

.bd-host { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; outline: none; background: var(--bg); }
.bd-host canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.bd-layer { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.bd-note { position: absolute; white-space: nowrap; font-size: 18px; padding: 2px 5px; border-radius: 3px; user-select: none; }
.bd-note.editing { outline: 1px dashed var(--accent); }
.bd-host[data-tool="pen"], .bd-host[data-tool="marker"], .bd-host[data-tool="line"], .bd-host[data-tool="arrow"], .bd-host[data-tool="rect"], .bd-host[data-tool="ellipse"] { cursor: crosshair; }
.bd-host[data-tool="eraser"] { cursor: none; }
.bd-host[data-tool="hand"], .bd-host.space { cursor: grab; }
.bd-host[data-tool="tex"] { cursor: text; }
.bd-host[data-tool="tex"] .bd-note, .bd-host[data-tool="select"] .bd-note { cursor: move; }
.bd-host[data-tool="pen"] .bd-note, .bd-host[data-tool="marker"] .bd-note, .bd-host[data-tool="eraser"] .bd-note, .bd-host[data-tool="hand"] .bd-note,
.bd-host[data-tool="line"] .bd-note, .bd-host[data-tool="arrow"] .bd-note, .bd-host[data-tool="rect"] .bd-note, .bd-host[data-tool="ellipse"] .bd-note { pointer-events: none; }
.bd-tools button span:first-child { text-transform: lowercase; }
.bd-edit {
  position: absolute; z-index: 3; width: min(320px, 80%); font: inherit; font-size: 13px; line-height: 1.5;
  padding: 6px 9px; color: var(--ink); background: var(--bg-inset); border: 1px solid var(--accent); border-radius: 3px;
  resize: none; outline: none; overflow: hidden;
}
.bd-hint { position: absolute; right: 10px; bottom: 12px; font-size: 10.5px; color: var(--ink-3); pointer-events: none; user-select: none; }
@media (max-width: 860px) { .bd-hint { display: none; } }

/* ── the working (lib/steps.js): notes in the margin of an aligned block, questions asked in the notebook ── */
.why { color: var(--ink-3); font-size: 0.74em; white-space: nowrap; }
.asked { font-family: var(--mono); font-size: 12px; color: var(--ink-3); margin: 0 0 2px; }
.asked::before { content: "? "; color: var(--accent); }
.asked + .mx-d .katex-display { margin-top: 2px; }

/* ── the ask panel (ask.js) ─────────────────────────────────────────────── */

.ask-bg { position: fixed; inset: 0; z-index: 60; display: none; background: color-mix(in srgb, var(--bg-inset) 55%, transparent); }
.ask-bg.open { display: block; }
.ask {
  width: min(720px, 94vw); margin: 9vh auto 0; max-height: 82vh; display: flex; flex-direction: column;
  background: var(--bg); border: 1px solid var(--line-2); border-radius: 5px; overflow: hidden;
}
.ask-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.ask-mark { font-family: KaTeX_Main, "Times New Roman", serif; font-size: 24px; line-height: 1; color: var(--accent); }
.ask-in { flex: 1; font: inherit; font-family: var(--mono); font-size: 15px; color: var(--ink); background: none; border: 0; outline: none; min-width: 0; }
.ask-in::placeholder { color: var(--ink-3); }
.ask-list { overflow-y: auto; padding: 6px 16px 10px; font-family: var(--serif); }
.ask-list:empty { display: none; }
.ask-q { color: var(--ink-3); font-size: 13px; padding: 8px 0 2px; text-align: right; }
.ask-card { padding: 10px 0 6px; border-top: 1px solid var(--line); }
.ask-card.first { border-top: 0; }
.ask-label { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 4px; }
.ask-card.first .ask-label { color: var(--accent); }
.ask-tex { font-size: 17px; overflow-x: auto; }
.ask-tex .katex-display { margin: 4px 0; text-align: left; }
.ask-tex .katex-display > .katex { text-align: left; }
.ask-error { color: var(--bad); font-family: var(--mono); font-size: 13px; padding: 12px 0 8px; }
.ask-insert {
  display: inline-flex; align-items: center; gap: 8px; margin: 8px 0 4px; font: inherit; font-family: var(--mono); font-size: 12px;
  color: var(--accent); background: var(--accent-soft); border: 1px solid transparent; border-radius: 3px; padding: 5px 10px; cursor: pointer;
}
.ask-insert:hover { border-color: var(--accent); }
.ask-insert kbd { color: inherit; background: none; border-color: currentColor; opacity: 0.7; }
.ask-hint { padding: 8px 16px 10px; font-size: 11.5px; color: var(--ink-3); line-height: 1.6; border-top: 1px solid var(--line); background: var(--bg-2); }
.ask-hint kbd { font-size: 9.5px; }
@media (max-width: 700px) { .ask { margin-top: 2vh; } }
