/* lemmapad: a quiet page, where the only colour is where you are. */

:root {
  /* The height of the menu bar across the top. */
  --menubar: 68px;
  color-scheme: light dark;

  --paper: #fbfaf7;
  --ink: #1f2328;
  --muted: #6b7280;
  --rule: #e4e2dc;
  --panel: #ffffff;
  --shadow: 0 12px 40px rgb(15 23 42 / 0.16);

  --accent: #2f6fde;
  --visual: #8250df;
  --pending: #b7791f;
  --good: #2f855a;
  --warn: #b7791f;
  --bad: #c53030;

  /* One hue per nesting depth, outermost first. Each is used as a darker
     border and a light wash of the same colour. */
  --depth-0: 215 16% 47%;
  --depth-1: 217 78% 52%;
  --depth-2: 265 62% 56%;
  --depth-3: 172 66% 34%;
  --depth-4: 28 80% 46%;
  --wash: 0.07;

  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --tk-number: #0b7285;
  --tk-constant: #9c36b5;
  --tk-function: #1c7ed6;
  --tk-bracket-0: #d9480f;
  --tk-bracket-1: #2b8a3e;
  --tk-bracket-2: #5f3dc4;
  /* Code, coloured the way editors colour it. */
  --tk-keyword: #cf222e;
  --tk-string: #0a3069;
  --tk-comment: #6e7781;
  --tk-builtin: #8250df;
  --tk-decorator: #953800;
  --tk-definition: #6639ba;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #15171a;
    --ink: #e6e7e9;
    --muted: #9099a6;
    --rule: #2b2f36;
    --panel: #1d2025;
    --shadow: 0 12px 40px rgb(0 0 0 / 0.5);
    --accent: #6ea2ff;
    --visual: #b392f0;
    --pending: #e0a94a;
    --good: #5fbf8f;
    --warn: #e0a94a;
    --bad: #f08080;
    --depth-0: 215 16% 62%;
    --depth-1: 217 90% 68%;
    --depth-2: 265 80% 74%;
    --depth-3: 172 60% 52%;
    --depth-4: 28 86% 62%;
    --wash: 0.1;
    --tk-number: #66d9e8;
    --tk-constant: #e599f7;
    --tk-function: #74c0fc;
    --tk-bracket-0: #ffa94d;
    --tk-bracket-1: #8ce99a;
    --tk-bracket-2: #b197fc;
    --tk-keyword: #ff7b72;
    --tk-string: #a5d6ff;
    --tk-comment: #8b949e;
    --tk-builtin: #d2a8ff;
    --tk-decorator: #ffa657;
    --tk-definition: #d2a8ff;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--ui);
}

.page {
  max-width: 1120px;
  margin: 0 auto;
  /* Room below the last line, so that Ctrl-E can scroll on until it is near
     the top of the window, as in Vim. */
  padding: calc(28px + var(--menubar)) 20px calc(100vh - 160px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ---- Page title --------------------------------------------------------- */

/* Hidden text fields stay focusable, so that the keyboard can be handed
   to them before the page has been redrawn. */
.hidden {
  position: fixed !important;
  left: -200vw !important;
  opacity: 0;
  pointer-events: none;
}

.title {
  margin: 0 0 6px;
  padding: 6px 14px 12px 20px;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--rule);
  cursor: default;
  scroll-margin: 40px;
}

.title h1 {
  display: inline-block;
  margin: 0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.title.active {
  border-left-color: var(--accent);
}

.title.active h1 {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  outline: 1.5px solid color-mix(in srgb, var(--accent) 75%, transparent);
}

/* ---- Sections and panes ------------------------------------------------ */

/* Borders are always there but transparent, so nothing shifts when the
   focus moves; only the path to the focused pane takes colour. */
.section,
.pane {
  border: 1.5px solid transparent;
  border-radius: 10px;
}

.section {
  padding: 4px;
  /* The browser lays out and paints only the sections near the window, so
     that a change costs the same in a long book as on a short page. A
     section keeps the height it last had while it is skipped. */
  content-visibility: auto;
  contain-intrinsic-size: auto 200px;
}

.section.active {
  border-color: hsl(var(--depth-0) / 0.55);
  background: hsl(var(--depth-0) / var(--wash));
}

.container {
  display: grid;
  gap: 4px;
  align-items: stretch;
}

.pane {
  min-width: 0;
  padding: 10px 14px;
  --hue: var(--depth-1);
}

/* A pane that holds a container is only a frame around it, and the
   container fills it, so that a split divides the height it already has. */
.pane:has(> .container) {
  display: flex;
  padding: 4px;
}

.pane > .container {
  flex: 1;
}

/* Plain text at page level has no frame at all. */
.section.flow {
  padding: 0 4px;
}

.pane.flow,
.pane.flow.focused {
  border-color: transparent;
  background: none;
  box-shadow: none;
}

.pane.depth-1 { --hue: var(--depth-1); }
.pane.depth-2 { --hue: var(--depth-2); }
.pane.depth-3 { --hue: var(--depth-3); }
.pane.depth-4 { --hue: var(--depth-4); }

.pane.on-path {
  border-color: hsl(var(--hue) / 0.6);
  background: hsl(var(--hue) / var(--wash));
}

.pane.focused {
  border-color: hsl(var(--hue));
  box-shadow: 0 0 0 1.5px hsl(var(--hue) / 0.25);
}

.empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* ---- Lines ------------------------------------------------------------- */

.line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 2.1em;
  padding: 4px 6px 4px 0;
  border-left: 3px solid transparent;
  border-radius: 3px;
  cursor: default;
  /* Kept in step with MARGIN_TOP and MARGIN_BOTTOM in main.rs. */
  scroll-margin: 120px 0 150px;
}

.pane.focused .line.active {
  border-left-color: hsl(var(--hue));
  background: hsl(var(--hue) / 0.09);
}

.align-center .line { justify-content: center; }
.align-right .line { justify-content: flex-end; }
.align-center .note p { text-align: center; }
.align-right .note p { text-align: right; }

.mark {
  flex: none;
  width: 1.3em;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}

.derived .mark { color: var(--good); }
.edited .mark { color: var(--warn); }
/* Edited by hand, then checked by algebra: a tick of its own colour, apart
   from the one a rule earns. */
.edited.verified .mark { color: var(--accent); }
.edited.wrong .mark { color: var(--bad); font-weight: 700; }

/* What the algebra check found, under the line: always for a wrong step,
   and for one it could not decide only while the cursor is on it. */
.line.math {
  flex-wrap: wrap;
}
.check-note {
  flex-basis: 100%;
  margin: -6px 0 2px 0;
  padding-left: 6px;
  color: var(--muted);
  font: 12px var(--ui);
}
.line.edited:not(.wrong):not(.active) .check-note {
  display: none;
}
.line.wrong .check-note {
  color: var(--bad);
}

.tex {
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  /* Room for the selection outline around the tallest parts of a line.
     The scrolling clips anything that pokes out further. */
  padding: 14px 6px 10px;
  font-size: 1.12em;
}

.tex .katex-display {
  margin: 0;
  text-align: inherit;
}

.tex .katex-display > .katex {
  text-align: inherit;
}

/* ---- Graphs ------------------------------------------------------------- */

/* One colour per line of a graph. The same class colours the curve, its
   entry in the legend, and the line on the page while the two are tied. */
.curve-0 { --curve: #2f6fde; }
.curve-1 { --curve: #d9480f; }
.curve-2 { --curve: #2b8a3e; }
.curve-3 { --curve: #9c36b5; }
.curve-4 { --curve: #0b7285; }
.curve-5 { --curve: #c2255c; }
@media (prefers-color-scheme: dark) {
  .curve-0 { --curve: #6ea2ff; }
  .curve-1 { --curve: #ffa94d; }
  .curve-2 { --curve: #8ce99a; }
  .curve-3 { --curve: #e599f7; }
  .curve-4 { --curve: #66d9e8; }
  .curve-5 { --curve: #faa2c1; }
}

/* A graph fills the width it has. The picture is drawn at that width, so
   its text and lines keep their size. */
.line.graph figure {
  flex: 1;
  min-width: 0;
  margin: 4px 0;
}
/* The picture, with a button to fill the screen that shows on hover and
   while the cursor is on the graph as a whole. */
.plot-box {
  position: relative;
  border-radius: 4px;
}
.plot-box.selected {
  outline: 1.5px solid color-mix(in srgb, var(--accent) 90%, transparent);
  outline-offset: 2px;
}
.graph-open {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 120ms;
}
.line.graph:hover .graph-open,
.plot-box.selected .graph-open,
.graph-open:focus-visible {
  opacity: 1;
}
.graph-open:hover {
  color: var(--ink);
}
.graph-open svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.line.graph .plot svg {
  display: block;
  width: 100%;
  height: auto;
}
.line.graph figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  padding: 2px 0 0 46px;
  color: var(--muted);
  font-size: 13px;
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 6px 1px 4px;
  border-radius: 4px;
  color: var(--ink);
}
.legend .swatch {
  width: 14px;
  height: 3px;
  border-radius: 2px;
  background: var(--curve);
}
.legend li.off {
  opacity: 0.45;
  text-decoration: line-through;
}
.legend .problem {
  color: var(--warn);
  font-size: 12px;
}
.legend .problem:empty {
  display: none;
}
/* The line of the graph the cursor is on. */
.line.graph.active .legend li.current {
  background: color-mix(in srgb, var(--curve) 16%, transparent);
  outline: 1.5px solid color-mix(in srgb, var(--curve) 80%, transparent);
}

.graph-frame {
  fill: var(--panel);
  stroke: var(--rule);
}
.graph-grid {
  stroke: var(--rule);
  stroke-width: 1;
}
.graph-axis {
  stroke: var(--muted);
  stroke-width: 1.2;
}
.graph-label,
.graph-name,
.graph-point-label {
  fill: var(--muted);
  font: 11px var(--ui);
}
.graph-name {
  font-style: italic;
  font-size: 13px;
}
.graph-curve {
  fill: none;
  stroke: var(--curve, var(--accent));
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.line.graph.active .graph-curve.current {
  stroke-width: 3;
}
.graph-curve.dashed {
  stroke-dasharray: 7 5;
}
.graph-region {
  fill: var(--curve);
  fill-opacity: 0.16;
  stroke: none;
}
/* Where a curve runs off the page. */
.graph-pole {
  stroke: var(--curve);
  stroke-width: 1;
  stroke-dasharray: 4 4;
  opacity: 0.7;
}
.graph-point.dot {
  fill: var(--curve);
  stroke: var(--panel);
  stroke-width: 1.5;
}
/* A point that is missing from its curve. */
.graph-point.open {
  fill: var(--panel);
  stroke: var(--curve);
  stroke-width: 2;
}
.graph-point-label {
  fill: var(--ink);
  paint-order: stroke;
  stroke: var(--panel);
  stroke-width: 3px;
}

/* A graph filling the window: a panel of its expressions beside the
   picture. The bar at the bottom stays in view. */
.pane .line.graph.full {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: block;
  margin: 0;
  /* Room for the bar, which sits above the graph, so that nothing on the
     page shows between the two. */
  padding: 0 0 44px;
  border: 0;
  border-radius: 0;
  background: var(--paper);
  box-shadow: none;
}
.line.graph.full .mark {
  display: none;
}
.graph-minor {
  stroke: var(--rule);
  stroke-width: 0.6;
  opacity: 0.55;
}

.gl {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  height: 100%;
  font-family: var(--ui);
}
.gl h2,
.gl h3 {
  margin: 0;
  font-weight: 600;
}
.gl kbd {
  font: 11px var(--mono);
  padding: 1px 5px;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--paper);
  color: var(--muted);
}

/* The panel. */
.gl-side {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--rule);
}
.gl-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  font-size: 12px;
}
.gl-head h2 {
  color: var(--ink);
  font-size: 15px;
}
.gl-side section {
  padding: 12px 16px;
  border-top: 1px solid var(--rule);
}
.gl-side h3 {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* One row per expression. */
.gl-list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.gl-row {
  display: grid;
  grid-template-columns: 22px 18px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 6px 14px 6px 10px;
  border-bottom: 1px solid var(--rule);
  box-shadow: inset 3px 0 0 transparent;
  cursor: pointer;
}
.gl-row:hover {
  background: color-mix(in srgb, var(--ink) 3%, transparent);
}
.gl-row.current {
  background: color-mix(in srgb, var(--curve) 10%, transparent);
  box-shadow: inset 3px 0 0 var(--curve);
}
.gl-row.editing {
  box-shadow: inset 3px 0 0 var(--pending);
}
.gl-index {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}
.gl-dot {
  width: 16px;
  height: 16px;
  padding: 0;
  border: 2.5px solid var(--curve);
  border-radius: 50%;
  background: var(--curve);
  cursor: pointer;
}
.gl-row.off .gl-dot {
  background: transparent;
}
.gl-row.off .gl-formula {
  opacity: 0.45;
}
.gl-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  color: var(--ink);
  font-size: 15px;
}
.gl-text .problem {
  color: var(--warn);
  font-size: 12px;
}
.gl-text .problem:empty {
  display: none;
}
.gl-new {
  grid-template-columns: 22px minmax(0, 1fr);
  min-height: 40px;
  color: var(--muted);
}
.gl-new .gl-text {
  color: var(--muted);
  font-size: 13px;
}

/* Sliders for the other letters. */
.gl-slider {
  display: grid;
  grid-template-columns: 84px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font: 13px var(--mono);
  color: var(--muted);
}
.gl-slider.set {
  color: var(--ink);
}
.gl-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gl-slider input {
  width: 100%;
  accent-color: var(--accent);
}

/* The keys that work here. */
.gl-keys ul {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 5px 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--muted);
}
.gl-keys li {
  display: contents;
}
.gl-keys kbd {
  justify-self: start;
}

/* The picture fills the rest, exactly: its size is reported to the
   editor. */
.gl-plot {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.gl-plot .plot,
.gl-plot .plot svg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}
.gl-plot .graph-frame {
  fill: var(--paper);
  stroke: none;
}
.gl-buttons {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.gl-group {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgb(15 23 42 / 0.08);
}
.gl-group button {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 17px var(--ui);
  cursor: pointer;
}
.gl-group button + button {
  border-top: 1px solid var(--rule);
}
.gl-group button:hover {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.gl-group button.on {
  color: var(--accent);
}

/* A line tied to the line under the cursor: the lines a graph draws, or
   the graphs that draw a line. */
.line.linked {
  background: color-mix(in srgb, var(--curve) 9%, transparent);
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--curve) 75%, transparent);
}
.line.linked.current {
  background: color-mix(in srgb, var(--curve) 18%, transparent);
  box-shadow: inset 4px 0 0 var(--curve);
}

/* ---- Blocks: theorems, proofs and the like ----------------------------- */

/* A block is a pane with its name at the top. Statements are framed and
   set off by a band of colour; a proof is plain, and ends with a square. */
.pane.block {
  padding-top: 8px;
}
.pane.block:not(.on-path) {
  border-color: var(--rule);
}
/* Each kind has a colour: a rule down its side, a faint wash, and its name
   in small capitals on a band of the same colour, as textbooks set them. */
.pane.block {
  --kind: var(--muted);
  background: color-mix(in srgb, var(--kind) 3%, transparent);
  box-shadow: inset 3px 0 0 var(--kind);
}
.pane.block.block-theorem,
.pane.block.block-lemma,
.pane.block.block-proposition,
.pane.block.block-corollary {
  --kind: var(--accent);
}
.pane.block.block-definition {
  --kind: var(--good);
}
.pane.block.block-example,
.pane.block.block-exercise {
  --kind: var(--pending);
}
.pane.block.block-remark {
  --kind: var(--muted);
}
.block-head {
  margin: 0 8px 6px 6px;
  padding: 2px 8px;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    color-mix(in srgb, var(--kind) 14%, transparent),
    transparent 75%
  );
  color: color-mix(in srgb, var(--kind) 80%, var(--ink));
  font: 650 14px var(--ui);
  font-variant: small-caps;
  letter-spacing: 0.04em;
}
.pane.block.block-proof {
  background: none;
  box-shadow: none;
}
.block-proof .block-head {
  background: none;
  color: var(--ink);
  font-style: italic;
  font-variant: normal;
  font-weight: 500;
  letter-spacing: 0;
}
.pane.block.block-proof:not(.on-path) {
  border-color: transparent;
}
.block-proof::after {
  content: "\220e";
  display: block;
  padding-right: 6px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  text-align: right;
}

/* ---- Numbered lines and references -------------------------------------- */

/* A numbered line has its number at the far right, as in a book. */
.eq-number {
  margin-left: auto;
  padding-left: 16px;
  color: var(--muted);
  font: 14px var(--ui);
  white-space: nowrap;
}
.eq-ref,
.pad-link {
  color: var(--accent);
  cursor: pointer;
}
.eq-ref:hover,
.pad-link:hover {
  text-decoration: underline;
}
.eq-ref.missing {
  color: var(--bad);
}
.pad-link {
  border-bottom: 1px dotted color-mix(in srgb, var(--accent) 60%, transparent);
}

/* ---- Notes in Markdown -------------------------------------------------- */

.note p.md-h1 {
  color: var(--ink);
  font-size: 22px;
  font-weight: 650;
  line-height: 1.3;
}
.note p.md-h2 {
  color: var(--ink);
  font-size: 18px;
  font-weight: 650;
  line-height: 1.3;
}
.note p.md-h3 {
  color: var(--ink);
  font-size: 15px;
  font-weight: 650;
}
/* A heading part way down a pane starts a new part of it, so it stands
   apart from what is above. */
.line.note:has(p.md-h1, p.md-h2):not(:first-child) {
  margin-top: 26px;
}
.line.note:has(p.md-h3):not(:first-child) {
  margin-top: 14px;
}
.note p.md-item {
  padding-left: 0.4em;
}
.note p.md-quote {
  padding-left: 12px;
  border-left: 3px solid var(--rule);
  font-style: italic;
}
/* The mark that makes a heading or a quote shows only where the cursor is. */
.md-marker {
  display: none;
  opacity: 0.45;
}
.pane.focused .line.active .md-marker {
  display: inline;
}
.md-marker.bullet {
  display: inline;
  opacity: 0.8;
}
/* Numbered items count up along a run of them, starting again after any
   other line. */
.line:not(.enum-item) + .line.enum-item,
.line.enum-item:first-child {
  counter-reset: enum-item;
}
.line.enum-item {
  counter-increment: enum-item;
}
.md-marker.number,
.md-marker.written {
  display: inline;
  opacity: 0.8;
}
.md-marker.number::before {
  content: counter(enum-item) ".";
}
.note p.md-term {
  padding-left: 1.2em;
  text-indent: -1.2em;
}
.note p code {
  padding: 1px 4px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--muted) 14%, transparent);
  color: var(--ink);
  font: 0.92em var(--mono);
}
.note p strong {
  color: var(--ink);
  font-weight: 650;
}
.note p a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.note p .md-math {
  color: var(--ink);
}

.tex-error {
  color: var(--bad);
  font-size: 13px;
}

/* Notes fill the width they have, on the page as in a pane. However
   short the words, the text takes the whole line, so that the field laid
   over it while typing is as wide as the line, not as the words were. */
.note p {
  flex: 1;
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

/* In a note the cursor sits on a word, marked like an atom of mathematics. */
.pane.focused .note.active p {
  color: var(--ink);
}

.note p span {
  cursor: default;
}
/* What a click in a note goes somewhere from: references, citations, pad
   links and uses of a term. */
.note p .eq-ref,
.note p .pad-link,
.note p .term-use,
.note p .term-use span {
  cursor: pointer;
}
.note p .term-card,
.note p .term-card * {
  cursor: default;
}

/* The cursor (normal mode), the selection (visual mode) and the operand
   still being typed. Inline blocks, so a mark covers tall things like
   fractions and not just the text line. */
.lp-cursor,
.lp-sel,
.lp-pending {
  display: inline-block;
  border-radius: 3px;
  /* A hanging indent, as a term has, belongs to the paragraph: inherited by
     the mark, it would move the word out of its own box. */
  text-indent: 0;
  /* Hug the glyphs: KaTeX sizes a line from the heights of its glyphs, and
     a taller line box would push the mark of a numerator above the line,
     where the scrolling box cuts its top off. */
  line-height: 1;
}

.lp-cursor {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  outline: 1.5px solid color-mix(in srgb, var(--accent) 90%, transparent);
  outline-offset: 1px;
}

.lp-sel {
  background: color-mix(in srgb, var(--visual) 24%, transparent);
  outline: 1.5px solid color-mix(in srgb, var(--visual) 85%, transparent);
  outline-offset: 1px;
}

.lp-pending {
  background: color-mix(in srgb, var(--pending) 18%, transparent);
  outline: 1.5px dashed color-mix(in srgb, var(--pending) 85%, transparent);
  outline-offset: 1px;
}

/* ---- Bars at the bottom ------------------------------------------------ */

.bars {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 16;
  /* A layer of its own, so that scrolling the page does not repaint it. */
  will-change: transform;
  background: var(--panel);
  border-top: 1px solid var(--rule);
}

.status {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 7px 20px;
}

/* The prompt opens right under the line being edited. Its position is set
   from script each time the line moves. */
.prompt {
  position: absolute;
  /* Above a graph filling the window, whose rows it is typed over. */
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  min-width: 280px;
  margin-top: 4px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid color-mix(in srgb, var(--pending) 55%, var(--rule));
  border-radius: 8px;
  box-shadow: var(--shadow);
}

/* The button that deletes the line being typed, at the top right. */
.prompt-delete {
  position: absolute;
  top: -9px;
  right: -9px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: var(--panel);
  color: var(--muted);
  font: 14px/1 var(--sans, system-ui);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.prompt-delete:hover {
  color: var(--bad);
  border-color: var(--bad);
}
.prompt-delete.hidden {
  display: none;
}

.prompt label {
  color: var(--pending);
  font-size: 12px;
  white-space: nowrap;
}

.prompt textarea,
.palette input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: 15px/1.4 var(--mono);
}

.prompt textarea {
  field-sizing: content;
  min-height: 1.4em;
  min-width: 12ch;
  padding: 0;
  resize: none;
}

.prompt .error {
  flex-basis: 100%;
}

/* The typed text is drawn twice, one exactly over the other: coloured
   underneath, and in the text field with see-through letters on top. */
.prompt .field {
  display: grid;
  flex: 1;
  min-width: 12ch;
}
.prompt .field > * {
  grid-area: 1 / 1;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.prompt .highlight {
  margin: 0;
  font: 15px/1.4 var(--mono);
  pointer-events: none;
}
.prompt:not(.inline) textarea {
  color: transparent;
  caret-color: var(--ink);
}
.prompt textarea::selection {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
}
/* With keys as commands, the selected character is the cursor. */
.prompt.commanding textarea::selection {
  background: color-mix(in srgb, var(--accent) 45%, transparent);
}
.tk-number { color: var(--tk-number); }
.tk-variable { color: var(--ink); font-style: italic; }
.tk-constant { color: var(--tk-constant); }
.tk-function { color: var(--tk-function); }
.tk-operator { color: var(--muted); }
.tk-bracket-0 { color: var(--tk-bracket-0); font-weight: 600; }
.tk-bracket-1 { color: var(--tk-bracket-1); font-weight: 600; }
.tk-bracket-2 { color: var(--tk-bracket-2); font-weight: 600; }
.tk-unknown { color: var(--bad); text-decoration: underline wavy; }
.tk-note { color: var(--muted); }
.tk-keyword { color: var(--tk-keyword); font-weight: 600; }
.tk-string { color: var(--tk-string); }
.tk-comment { color: var(--tk-comment); font-style: italic; }
.tk-builtin { color: var(--tk-builtin); }
.tk-decorator { color: var(--tk-decorator); }
.tk-definition { color: var(--tk-definition); font-weight: 600; }
.tk-name { color: var(--ink); }
/* In code, names are not letters of mathematics. */
.cell-source .tk-variable { font-style: normal; }

/* A note or the title is edited in place: the text field lies exactly over
   the text, which only keeps the room. */
.prompt.inline {
  display: block;
  min-width: 0;
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.prompt.inline label,
.prompt.inline .highlight,
.prompt.inline .error {
  display: none;
}
.prompt.inline .field {
  min-width: 0;
}
.prompt.inline textarea {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.line.editing p,
.title.editing h1 {
  min-height: 1lh;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.title.editing h1 {
  display: block;
}
.line.editing p,
.title.editing h1 {
  -webkit-text-fill-color: transparent;
}

.prompt .error:empty {
  display: none;
}

.error,
.message {
  color: var(--muted);
  font-size: 13px;
}

.error {
  color: var(--bad);
}

.mode {
  padding: 1px 8px;
  border-radius: 4px;
  background: var(--rule);
  font: 600 11px/1.7 var(--mono);
  letter-spacing: 0.06em;
}

.mode-insert,
.mode-resize {
  background: var(--pending);
  color: var(--paper);
}

.mode-palette {
  background: var(--accent);
  color: var(--paper);
}

.mode-visual {
  background: var(--visual);
  color: var(--paper);
}

.pending {
  min-width: 3ch;
  font: 13px var(--mono);
}

.message {
  flex: 1;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

kbd {
  display: inline-block;
  margin: 0 3px 0 8px;
  padding: 0 5px;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--paper);
  font: 12px/1.6 var(--mono);
  white-space: nowrap;
}

/* ---- Palette ----------------------------------------------------------- */

.palette {
  position: fixed;
  top: 12vh;
  left: 50%;
  width: min(580px, calc(100vw - 32px));
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.palette input {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border-bottom: 1px solid var(--rule);
  font-family: var(--ui);
}

.palette ul {
  max-height: 52vh;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  list-style: none;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  border-radius: 7px;
  scroll-margin: 6px;
}

.palette-item.selected {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.palette-item .title {
  flex: 1;
}

.palette-item .preview {
  color: var(--muted);
}

.palette-item code {
  color: var(--muted);
  font: 12px var(--mono);
  white-space: nowrap;
}

.palette-more {
  padding: 8px 10px;
  color: var(--muted);
  font-size: 13px;
}

/* ---- Key reference ----------------------------------------------------- */

.help {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(820px, 100vw);
  padding: 20px 24px 120px;
  overflow-y: auto;
  columns: 2 300px;
  column-gap: 32px;
  background: var(--panel);
  border-left: 1px solid var(--rule);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.help table {
  break-inside: avoid;
}

.help h2 {
  break-after: avoid;
}

.help h1 {
  margin: 0 0 4px;
  font-size: 16px;
}

.help h2 {
  margin: 0 0 4px;
  padding-top: 16px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.help table {
  width: 100%;
  border-collapse: collapse;
}

.help td {
  padding: 3px 0;
  vertical-align: top;
}

.help td:first-child {
  width: 42%;
  padding-right: 10px;
}

.help kbd {
  margin-left: 0;
}

.help-foot {
  margin-top: 18px;
  color: var(--muted);
}

@media (prefers-reduced-motion: no-preference) {
  .section,
  .pane {
    transition: border-color 120ms, background-color 120ms;
  }
}

/* ---- Menu bar ------------------------------------------------------------ */

/* Across the top: menus on the left, the page's file on the right. A graph
   filling the window covers it. */
.menubar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 14;
  display: flex;
  flex-direction: column;
  height: var(--menubar);
  padding: 0 12px 0 16px;
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
  font: 13px var(--ui);
  /* A layer of its own, so that scrolling the page does not repaint it. */
  will-change: transform;
}
.brand {
  margin-right: 14px;
  color: var(--ink);
  font-weight: 650;
  letter-spacing: -0.01em;
}
.menu {
  position: relative;
}
.menu-name {
  padding: 5px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.menu-name:hover,
.menu.open .menu-name {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}
.menu-items {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  display: none;
  min-width: 250px;
  margin: 0;
  padding: 5px;
  list-style: none;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.menu.open .menu-items {
  display: block;
}
.menu-items button {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.menu-items button:hover {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.menu-items kbd {
  color: var(--muted);
  font: 12px var(--ui);
}
/* A choice among several, with a tick by the one in use. */
.menu-items .menu-choice {
  justify-content: flex-start;
  gap: 8px;
}
.menu-check {
  width: 14px;
  flex: none;
  color: var(--accent);
  font-weight: 700;
}
.menu-label small {
  display: block;
  color: var(--muted);
  font-size: 11.5px;
}
.menu-heading {
  padding: 4px 10px 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.menu-rule {
  height: 1px;
  margin: 5px 6px;
  background: var(--rule);
}
.file-name {
  margin-left: auto;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-name.none {
  font-style: italic;
}
.file-dot {
  visibility: hidden;
  margin-left: 6px;
  color: var(--accent);
  font-size: 10px;
}
.file-dot.shown {
  visibility: visible;
}

/* The open pad's title, which opens the list of pads. */
.pad-button {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 320px;
  margin-right: 10px;
  padding: 4px 8px 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.pad-button:hover {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.pad-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pad-count {
  padding: 0 6px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--muted) 18%, transparent);
  color: var(--muted);
  font-size: 11px;
}
.pad-caret {
  color: var(--muted);
  font-size: 10px;
}

.switcher {
  position: fixed;
  top: calc(var(--menubar) + 4px);
  left: 96px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(460px, calc(100vw - 32px));
  max-height: 70vh;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font: 13px var(--ui);
}
.switcher input {
  margin: 8px;
  padding: 7px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  outline: none;
}
.switcher input:focus {
  border-color: var(--accent);
}
.switcher ul {
  margin: 0;
  padding: 0 6px;
  overflow-y: auto;
  list-style: none;
}
.switcher-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 22px;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.switcher-row:hover {
  background: color-mix(in srgb, var(--ink) 5%, transparent);
}
.switcher-row.selected {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.switcher-title {
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.switcher-row.current .switcher-title {
  font-weight: 650;
}
.switcher-row.current .switcher-title::after {
  content: " \00b7  open";
  color: var(--accent);
  font-weight: 400;
}
.switcher-meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.switcher-file {
  margin-right: 8px;
  font-style: italic;
}
.switcher-delete {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  opacity: 0;
  cursor: pointer;
}
/* A textbook as it came has nothing to reset. */
.switcher-delete.untouched {
  visibility: hidden;
}

.switcher-row:hover .switcher-delete,
.switcher-row.selected .switcher-delete {
  opacity: 1;
}
.switcher-delete:hover {
  background: color-mix(in srgb, var(--bad) 18%, transparent);
  color: var(--bad);
}
.switcher-none {
  margin: 4px 16px;
  color: var(--muted);
}
.switcher-new {
  margin: 6px 8px 8px;
  padding: 7px 10px;
  border: 1px dashed var(--rule);
  border-radius: 6px;
  background: none;
  color: var(--accent);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.switcher-new:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* ---- Contents ------------------------------------------------------------ */

/* The headings of the notes, down the left of the window. The page moves
   over to make room while there are any. */
.toc {
  position: fixed;
  inset: var(--menubar) auto 44px 0;
  z-index: 4;
  /* A layer of its own that nothing inside reaches out of, so that
     scrolling the page does not repaint it. */
  will-change: transform;
  contain: layout paint;
  width: 236px;
  overflow-y: auto;
  padding: 26px 14px 20px 18px;
  border-right: 1px solid var(--rule);
  background: var(--paper);
  font: 13px/1.35 var(--ui);
}
.toc h2 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.toc ol {
  margin: 0;
  padding: 0;
  list-style: none;
}
.toc li {
  padding: 4px 8px;
  border-left: 2px solid transparent;
  border-radius: 0 4px 4px 0;
  color: var(--muted);
  cursor: pointer;
}
.toc li:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}
.toc li.current {
  color: var(--ink);
  border-left-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 9%, transparent);
}
.toc .toc-level-1 {
  font-weight: 600;
}
.toc .toc-level-2 {
  padding-left: 18px;
}
.toc .toc-level-3 {
  padding-left: 30px;
  font-size: 12px;
}
.page:has(.toc) {
  margin-left: max(256px, calc((100vw - 1120px) / 2));
  margin-right: auto;
}
/* A narrow window keeps the whole width for the page. */
@media (max-width: 900px) {
  .toc {
    display: none;
  }
  .page:has(.toc) {
    margin: 0 auto;
  }
}

/* ---- Figures ------------------------------------------------------------ */

/* A figure is drawn at its own size, never stretched: text keeps its size
   whatever the width of the pane. */
.line.figure .fig-box {
  flex: 1;
  min-width: 0;
  margin: 4px 0;
}
/* Figures sit in the middle of their pane, the way a book sets them. */
.fig {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  font-family: var(--ui);
}
.fig-error {
  color: var(--warn);
  font: 13px var(--ui);
}
/* A drawing: shapes at coordinates, in the page's ink unless coloured. */
.fig-draw .draw-stroke {
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.fig-draw .draw-stroke.painted {
  stroke: var(--curve, var(--paint));
}
.fig-draw .draw-fill > * {
  fill: color-mix(in srgb, var(--curve, var(--paint, var(--accent))) 22%, transparent);
}
.fig-draw .draw-grid {
  stroke: var(--rule);
  stroke-width: 0.8;
}
.fig-draw .draw-head {
  fill: context-stroke;
}
.fig-draw .draw-math {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--ink);
  font-size: 15px;
}
.fig-draw .draw-math.draw-start {
  justify-content: flex-start;
}
.fig-draw .draw-math.draw-end {
  justify-content: flex-end;
}

.fig-shape {
  fill: color-mix(in srgb, var(--accent) 8%, transparent);
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linejoin: round;
}
.fig-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.2;
}
.fig-line.dashed {
  stroke-dasharray: 5 4;
}
.fig-mark {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.4;
}
.fig-name {
  fill: var(--ink);
  font-size: 15px;
  font-style: italic;
  font-weight: 600;
}
.fig-angle {
  fill: var(--accent);
  font-size: 12px;
}
.fig-label,
.fig-value {
  fill: var(--muted);
  font-size: 12px;
}
.fig-value {
  fill: var(--ink);
  font-weight: 600;
}
.fig-title {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 600;
}
.fig-edge,
.fig-axis,
.fig-tick {
  stroke: var(--muted);
  stroke-width: 1.4;
}
.fig-arrow {
  fill: var(--muted);
}
.fig-grid {
  stroke: var(--rule);
  stroke-width: 1;
}
/* Parts coloured by kind take the colour of their curve-N class, the same
   colours a graph uses for its lines. */
.fig-node,
.fig-key,
.fig-bar,
.fig-dot {
  fill: var(--curve);
}
.fig-node {
  fill: color-mix(in srgb, var(--curve) 22%, var(--panel));
  stroke: var(--curve);
  stroke-width: 1.6;
}
.fig-plain .fig-node,
.fig-node.fig-plain {
  fill: var(--panel);
  stroke: var(--muted);
}
.fig-node-label {
  fill: var(--ink);
  font-size: 13px;
}
.fig-open {
  fill: var(--panel);
  stroke: var(--curve, var(--ink));
  stroke-width: 2.2;
}
.fig-number-line .fig-dot {
  stroke: var(--panel);
  stroke-width: 1.5;
}
.fig-range {
  stroke: var(--curve);
  stroke-width: 5;
  stroke-linecap: round;
  opacity: 0.75;
}
.fig-series {
  fill: none;
  stroke: var(--curve);
  stroke-width: 2.2;
  stroke-linejoin: round;
}
/* Words in a series are written, not outlined. */
.fig-series text {
  stroke: none;
}

/* Tables: headings tinted, entries plain. */
.fig-head,
.fig-cell {
  stroke: var(--rule);
  stroke-width: 1;
}
.fig-head {
  fill: color-mix(in srgb, var(--accent) 10%, var(--panel));
}
.fig-cell {
  fill: var(--panel);
}
.fig-head-text,
.fig-cell-text {
  fill: var(--ink);
  font-size: 13px;
  pointer-events: none;
}
.fig-head-text {
  font-weight: 600;
  font-style: italic;
}
/* Pie charts. */
.fig-wedge {
  fill: var(--curve);
  stroke: var(--panel);
  stroke-width: 2;
}
.fig-share {
  fill: #fff;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
}
/* Venn diagrams: each region is opaque, so a smaller one drawn over a
   bigger one shows its own shading. */
.fig-region {
  fill: var(--panel);
}
.fig-shaded .fig-region {
  fill: color-mix(in srgb, var(--accent) 28%, var(--panel));
}
rect.fig-region {
  stroke: var(--muted);
  stroke-width: 1.4;
}
.fig-set {
  fill: none;
  stroke: var(--curve);
  stroke-width: 2.2;
  pointer-events: none;
}
.fig-set-name {
  fill: var(--curve);
  font-size: 14px;
  font-weight: 600;
}
.fig-venn-label {
  pointer-events: none;
}
/* Scatter plots and vectors. */
.fig-axis-name {
  fill: var(--ink);
  font-size: 12px;
}
.fig-fit {
  stroke: var(--ink);
  opacity: 0.7;
  stroke-width: 1.8;
  stroke-dasharray: 6 4;
}
.fig-fit-text {
  fill: var(--muted);
  font-size: 12px;
  font-style: italic;
}
.fig-vector {
  stroke: var(--curve);
  stroke-width: 2.4;
  stroke-linecap: round;
}
.fig-vector-tip {
  fill: var(--curve);
}
.fig-vector-name {
  fill: var(--curve);
  font-size: 15px;
  font-style: italic;
  font-weight: 600;
}
.fig-again {
  opacity: 0.55;
  pointer-events: none;
}
.fig-again .fig-vector {
  stroke-dasharray: 5 4;
}
.fig-sum {
  --curve: var(--ink);
  pointer-events: none;
}

/* ---- Editing figures ---------------------------------------------------- */

/* Each part of a figure can be clicked to pick it. Thin parts get a wide,
   unseen line or spot to click. */
.fig-part {
  cursor: pointer;
}
.fig-hit {
  fill: transparent;
}
.fig-hit-line {
  fill: none;
  stroke: transparent;
  stroke-width: 16;
  stroke-linecap: round;
}
.fig-part:hover .fig-hit,
.fig-part.selected .fig-hit {
  fill: color-mix(in srgb, var(--accent) 16%, transparent);
}
.fig-part:hover .fig-hit-line {
  stroke: color-mix(in srgb, var(--accent) 12%, transparent);
}
.fig-part.selected .fig-hit-line {
  stroke: color-mix(in srgb, var(--accent) 24%, transparent);
}
.fig-tree-node:hover .fig-node {
  stroke-width: 2.4;
}
.fig-part.selected .fig-node {
  stroke: var(--accent);
  stroke-width: 3;
}
.fig-part.selected .fig-bar,
.fig-part:hover .fig-bar {
  stroke: var(--ink);
  stroke-width: 2;
}
.fig-part.selected .fig-bar {
  stroke-width: 3;
}
.fig-part.selected .fig-series {
  stroke-width: 4;
}
.fig-part.selected .fig-dot,
.fig-part.selected .fig-open {
  stroke: var(--accent);
  stroke-width: 3;
}
.fig-part.selected .fig-range {
  stroke-width: 8;
  opacity: 1;
}
.fig-part.selected .fig-head,
.fig-part.selected .fig-cell {
  fill: color-mix(in srgb, var(--accent) 24%, var(--panel));
  stroke: var(--accent);
  stroke-width: 2;
}
.fig-part:hover .fig-cell,
.fig-part:hover .fig-head {
  stroke: var(--accent);
}
.fig-part.selected .fig-wedge,
.fig-part:hover .fig-wedge {
  stroke: var(--ink);
}
.fig-venn-region:hover .fig-region {
  fill: color-mix(in srgb, var(--accent) 10%, var(--panel));
}
.fig-shaded.fig-venn-region:hover .fig-region {
  fill: color-mix(in srgb, var(--accent) 36%, var(--panel));
}
.fig-part.selected .fig-region {
  fill: color-mix(in srgb, var(--accent) 18%, var(--panel));
  stroke: var(--accent);
  stroke-width: 3;
}
.fig-shaded.fig-part.selected .fig-region {
  fill: color-mix(in srgb, var(--accent) 40%, var(--panel));
}
.fig-part.selected .fig-set {
  stroke-width: 4;
}
.fig-part.selected .fig-vector {
  stroke-width: 4;
}
/* The + under a node of a tree, shown while the pointer is on the node. */
.fig-add {
  opacity: 0;
  transition: opacity 120ms;
  cursor: pointer;
}
.fig-add circle {
  fill: var(--panel);
  stroke: var(--accent);
  stroke-width: 1.5;
}
.fig-add text {
  fill: var(--accent);
  font-size: 15px;
  font-weight: 700;
}
.fig-part:hover .fig-add,
.fig-part.selected .fig-add {
  opacity: 1;
}
.fig-add:hover circle {
  fill: color-mix(in srgb, var(--accent) 18%, var(--panel));
}

/* The panel under a figure the cursor is on. */
.line.figure {
  flex-wrap: wrap;
}
.fig-inspector {
  display: flex;
  flex-basis: 100%;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px 14px;
  margin: 2px 0 6px 1.3em;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--panel);
  font: 12px var(--ui);
  cursor: default;
}
.fig-inspector-title {
  align-self: center;
  color: var(--ink);
  font-weight: 600;
}
.fig-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: var(--muted);
}
.fig-field input[type="text"] {
  width: 12em;
  padding: 4px 7px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  font: 13px var(--ui);
}
.fig-field input:focus {
  outline: 1.5px solid var(--accent);
  outline-offset: 0;
}
.fig-field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 5px 0;
  accent-color: var(--accent);
}
.fig-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}
.fig-actions button {
  padding: 5px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: 12px var(--ui);
  cursor: pointer;
}
.fig-actions button:hover {
  border-color: var(--accent);
}
.fig-actions button.danger {
  color: var(--bad);
}

/* The grid of the matrix the cursor is in. */
.matrix-panel {
  align-items: center;
}
/* The grid of the matrix the cursor is in is drawn once for the page and
   placed over the room its line keeps for it. */
.matrix-overlay {
  position: absolute;
  z-index: 15;
}
.matrix-slot {
  flex-basis: 100%;
  margin: 2px 0 6px 1.3em;
}
.matrix-overlay .fig-inspector {
  margin: 0;
}

.matrix-grid {
  border-collapse: separate;
  border-spacing: 4px;
  border-left: 2px solid var(--muted);
  border-right: 2px solid var(--muted);
  border-radius: 4px;
}
.matrix-grid input {
  width: 6em;
  padding: 4px 6px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  font: 13px var(--mono);
  text-align: center;
}
.matrix-grid input:focus {
  outline: 1.5px solid var(--accent);
}
.matrix-grid td.current input {
  border-color: color-mix(in srgb, var(--accent) 70%, var(--rule));
  background: color-mix(in srgb, var(--accent) 8%, var(--paper));
}

/* ---- Python cells ------------------------------------------------------- */

.line.code .cell {
  flex: 1;
  min-width: 0;
  margin: 4px 0;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--panel);
}
.cell-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 12px;
  border-bottom: 1px solid var(--rule);
  color: var(--muted);
  font: 12px var(--ui);
}
.cell-language {
  flex: 1;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.cell-head button {
  padding: 3px 9px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--muted);
  font: 12px var(--ui);
  cursor: pointer;
}
.cell-head button:hover {
  color: var(--ink);
}
.cell-head .cell-print.on {
  color: var(--good);
}
.cell-head .cell-run {
  color: var(--accent);
  font-weight: 600;
}
.cell-source,
.cell-output {
  margin: 0;
  padding: 9px 12px;
  overflow-x: auto;
  font: 13px/1.5 var(--mono);
  white-space: pre;
}
.cell-source {
  min-height: 1.5em;
  color: var(--ink);
  cursor: text;
}
/* The program of a cell typed in place: the field lies over the program
   with the same letters, its colours showing through. */
.prompt.code {
  display: block;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--panel);
  box-shadow: none;
  outline: 1.5px solid var(--accent);
}
.prompt.code label,
.prompt.code .error {
  display: none;
}
.prompt.code .highlight,
.prompt.code textarea {
  margin: 0;
  padding: 9px 12px;
  font: 13px/1.5 var(--mono);
  white-space: pre;
  overflow-wrap: normal;
}
.prompt.code textarea {
  overflow: hidden;
}
.cell-output {
  border-top: 1px dashed var(--rule);
  background: color-mix(in srgb, var(--paper) 60%, var(--panel));
  color: var(--muted);
}
.cell-output.error {
  color: var(--bad);
}
.cell-output.running {
  font-style: italic;
}

/* ---- Print --------------------------------------------------------------- */

/* A printed page is the work alone: no cursor or selection, no bars, panels
   or buttons, and the light colours whatever the screen uses. A cell of
   Python prints its output only if it was asked to (gp). */
@media print {
  :root {
    color-scheme: light;
    --paper: #ffffff;
    --ink: #1f2328;
    --muted: #57606a;
    --rule: #d8dee4;
    --panel: #ffffff;
    --accent: #2f6fde;
    --good: #2f855a;
    --warn: #b7791f;
    --bad: #c53030;
    --tk-number: #0b7285;
    --tk-constant: #9c36b5;
    --tk-function: #1c7ed6;
    --tk-bracket-0: #d9480f;
    --tk-bracket-1: #2b8a3e;
    --tk-bracket-2: #5f3dc4;
    --tk-keyword: #cf222e;
    --tk-string: #0a3069;
    --tk-comment: #6e7781;
    --tk-builtin: #8250df;
    --tk-decorator: #953800;
    --tk-definition: #6639ba;
  }
  .curve-0 { --curve: #2f6fde; }
  .curve-1 { --curve: #d9480f; }
  .curve-2 { --curve: #2b8a3e; }
  .curve-3 { --curve: #9c36b5; }
  .curve-4 { --curve: #0b7285; }
  .curve-5 { --curve: #c2255c; }
  body {
    background: #ffffff;
  }
  .toc,
  .menubar,
  .switcher,
  .bars,
  .prompt,
  .palette,
  .help,
  .graph-open,
  .cell-head button,
  .fig-inspector,
  .fig-add,
  .line.code.no-print-output .cell-output,
  .line:not(.wrong) .check-note {
    display: none !important;
  }
  .page,
  .page:has(.toc) {
    max-width: none;
    margin: 0;
    padding: 0;
  }
  /* Where the cursor was, nothing shows. */
  .pane.block,
  .pane.block.on-path,
  .pane.block.focused {
    border-color: #d0d7de !important;
    background: none !important;
  }
  .pane.focused .line.active,
  .line.linked,
  .line.linked.current {
    border-left-color: transparent;
    background: none;
    box-shadow: none;
  }
  .lp-cursor,
  .lp-sel,
  .lp-pending {
    background: none;
    outline: none;
  }
  .plot-box.selected {
    outline: none;
  }
  .pane.on-path,
  .pane.focused {
    border-color: var(--rule);
    background: none;
    box-shadow: none;
  }
  .line,
  .line.graph figure,
  .line.figure .fig-box,
  .line.code .cell {
    break-inside: avoid;
  }
  /* A graph filling the window prints in its place on the page. */
  .pane .line.graph.full {
    position: static;
    padding: 0;
  }
}

/* ---- Versions of a pad ---------------------------------------------------- */

.history {
  position: fixed;
  top: calc(var(--menubar) + 24px);
  left: 50%;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(560px, calc(100vw - 32px));
  max-height: 70vh;
  transform: translateX(-50%);
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font: 13px var(--ui);
}
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.history-head h2 {
  margin: 0;
  font-size: 15px;
}
.history-head button {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}
.history-note,
.history-none {
  margin: 6px 0 10px;
  color: var(--muted);
}
.history ul {
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}
.history-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  border-top: 1px solid var(--rule);
}
.history-when {
  color: var(--muted);
}
.history-what {
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-row button {
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}
.history-row button:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
@media print {
  .history {
    display: none !important;
  }
}

/* The badge that says simple keys are on. */
.keys-simple {
  padding: 1px 8px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font: 600 11px var(--ui);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---- Touch screens and narrow windows -------------------------------------- */

/* Buttons for what a keyboard would do: only where the pointer is a finger. */
.touchbar {
  display: none;
  gap: 6px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 6px 12px 0;
  overflow-x: auto;
}
.touchbar button {
  flex: none;
  min-height: 40px;
  padding: 6px 14px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: 14px var(--ui);
}
.touchbar button:active {
  background: color-mix(in srgb, var(--accent) 16%, var(--paper));
}
@media (pointer: coarse) {
  .touchbar {
    display: flex;
  }
  /* Room for a finger. */
  .line {
    min-height: 2.6em;
  }
  .menu-name,
  .menu-items button,
  .switcher-row,
  .pad-button {
    min-height: 40px;
  }
  .switcher-delete {
    opacity: 1;
  }
  .page {
    padding-bottom: calc(100vh - 100px);
  }
}

/* A narrow window: panes one under another, and a smaller bar. */
@media (max-width: 700px) {
  .container {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-rows: none !important;
  }
  .page,
  .page:has(.toc) {
    padding-left: 8px;
    padding-right: 8px;
  }
  .brand,
  .file-name,
  .status .hint {
    display: none;
  }
  .menubar {
    padding: 0 6px;
  }
  .pad-button {
    max-width: 46vw;
  }
  .switcher {
    left: 8px;
  }
  .menu-items {
    position: fixed;
    top: calc(var(--menubar) + 2px);
    left: 8px;
    right: 8px;
    min-width: 0;
  }
  .title h1 {
    font-size: 21px;
  }
}

@media print {
  .touchbar {
    display: none !important;
  }
}

/* A part of a formula marked with highlight(...). */
.math-highlight {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  border-radius: 3px;
  padding: 0 2px;
}

/* The caption under a line that is not a note. */
.line .caption {
  margin: 6px 0 2px;
  color: var(--muted);
  font-size: 0.92em;
  font-variant: small-caps;
  letter-spacing: 0.03em;
  text-align: center;
}
.line.math .caption {
  flex-basis: 100%;
}

/* Back and forward after a jump, in the menu bar. */
.menubar .jumps {
  display: inline-flex;
  gap: 2px;
  margin-left: 6px;
}
.menubar .jump {
  padding: 2px 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
}
.menubar .jump:hover:not(:disabled) {
  border-color: var(--rule);
}
.menubar .jump:disabled {
  opacity: 0.3;
  cursor: default;
}

/* Names whose order can be changed: chips to drag, or move with H and L. */
.order-chips {
  display: inline-flex;
  gap: 6px;
}
.order-chip {
  padding: 2px 10px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
  color: var(--ink);
  font: italic 600 14px var(--serif, Georgia, serif);
  cursor: grab;
}
/* Hovering only lightens a chip; the one chosen with the keys has a ring,
   and the one being dragged is lifted. */
.order-chip:hover {
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
}
.order-chip:focus {
  outline: none;
}
.order-chip:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
}
.order-chip.dragging {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 30%, var(--panel));
  box-shadow: var(--shadow);
  cursor: grabbing;
  transform: translateY(-2px);
}
.order-chips {
  touch-action: none;
  user-select: none;
}

/* The two rows at the top: the program's, then where you are. */
.menubar-row {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.menubar-row.place {
  gap: 6px;
  border-top: 1px solid color-mix(in srgb, var(--rule) 60%, transparent);
}
.menubar-gap {
  flex: 1;
}
.menubar .jumps {
  margin-left: -6px;
}
.section-name {
  overflow: hidden;
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.section-name.hidden {
  display: none;
}
.crumb-mark {
  margin-right: 6px;
  opacity: 0.6;
}

/* A use of a defined term: linked to its definition, which shows on
   hovering. */
.term-use {
  position: relative;
  text-decoration: underline dotted color-mix(in srgb, var(--accent) 70%, transparent);
  text-underline-offset: 3px;
  cursor: pointer;
}
.term-card {
  position: absolute;
  left: 0;
  bottom: calc(100% + 6px);
  z-index: 30;
  width: max-content;
  max-width: 320px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 13px;
  font-style: normal;
  font-weight: normal;
  line-height: 1.45;
  white-space: normal;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.12s 0.25s;
  pointer-events: none;
}
.term-use:hover .term-card,
.term-use:focus .term-card {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}
.term-unlink {
  display: block;
  margin-top: 6px;
  padding: 1px 8px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: 11px var(--ui);
  cursor: pointer;
}
.term-unlink:hover {
  border-color: var(--bad);
  color: var(--bad);
}

/* The headings of the pad list: your own pads, then those built in. */
.switcher-group {
  padding: 8px 12px 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: default;
}
.switcher-group:not(:first-child) {
  margin-top: 4px;
  border-top: 1px solid var(--rule);
}

/* On a term's definition: whether its uses link here, and the switch. It
   shows on the line being pointed at or worked on, and stays when on. */
.term-switch {
  flex: none;
  align-self: center;
  margin-left: auto;
  padding: 1px 8px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font: 11px var(--ui);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
}
.line:hover .term-switch,
.line.active .term-switch,
.term-switch.on {
  opacity: 1;
}
.term-switch.on {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  color: var(--accent);
}
.term-switch:hover {
  border-color: var(--accent);
}

/* ---- Marks in the margin ----------------------------------------------- */

/* The mark of a step (a tick, a pencil, a cross) and a line's number sit at
   the right, in the margin, as a book sets them; what is under a line comes
   after both. */
.line > .mark {
  order: 10;
  margin-left: auto;
  padding-left: 10px;
}
.line > .eq-number {
  order: 9;
}
.line:has(> .eq-number) > .mark {
  margin-left: 0;
}
.line > .mark:empty,
.line.note > .mark {
  display: none;
}
.line > .check-note {
  order: 11;
}
.line > .caption,
.line > .matrix-slot {
  order: 12;
}

/* ---- Arriving ----------------------------------------------------------- */

/* A step just taken draws its tick in; a line jumped to is lit, and fades. */
@keyframes tick-in {
  from {
    clip-path: inset(0 100% 0 0);
    opacity: 0.2;
    transform: scale(0.7);
  }
  to {
    clip-path: inset(0 0 0 0);
    opacity: 1;
    transform: none;
  }
}
.line.arrived > .mark {
  display: inline-block;
  animation: tick-in 0.45s ease-out;
}
@keyframes landed {
  from {
    background: color-mix(in srgb, var(--accent) 28%, transparent);
  }
  to {
    background: transparent;
  }
}
.line.landed {
  animation: landed 1.6s ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .line.arrived > .mark,
  .line.landed {
    animation: none;
  }
}

/* ---- The paper look ----------------------------------------------------- */

/* Set like a book: the words in a serif, warmer paper, and a narrower
   column; the program's own controls keep their type. */
:root {
  --serif: Charter, "Bitstream Charter", "Sitka Text", "Iowan Old Style", "Source Serif 4",
    "Source Serif Pro", Cambria, Georgia, serif;
}
html.paper {
  --paper: #f8f5ee;
  --panel: #fffdf8;
  --rule: #e4dccd;
  --ink: #26221c;
  --muted: #776f64;
}
@media (prefers-color-scheme: dark) {
  html.paper {
    --paper: #1b1a17;
    --panel: #23211d;
    --rule: #37332c;
    --ink: #ece6da;
    --muted: #a39b8e;
  }
}
html.paper .page {
  max-width: 1000px;
}
html.paper .note p,
html.paper .line .caption,
html.paper .term-card {
  font-family: var(--serif);
}
html.paper .note p {
  color: color-mix(in srgb, var(--ink) 84%, var(--paper));
  font-size: 16.5px;
  line-height: 1.62;
}
html.paper .note p.md-h1,
html.paper .note p.md-h2,
html.paper .note p.md-h3,
html.paper .title h1 {
  font-family: var(--serif);
  letter-spacing: -0.005em;
}
html.paper .note p.md-h1 {
  font-size: 25px;
}
html.paper .note p.md-h2 {
  font-size: 20px;
}
html.paper .note p code {
  font-size: 0.8em;
}
html.paper .block-head {
  font-family: var(--serif);
  font-size: 15.5px;
}
/* Graphs on paper: a light grid, the finer lines like squared paper. */
html.paper .graph-grid {
  stroke: color-mix(in srgb, var(--accent) 16%, var(--rule));
  stroke-width: 0.8;
}
html.paper .graph-minor {
  stroke: color-mix(in srgb, var(--accent) 22%, transparent);
  stroke-width: 0.5;
  opacity: 0.45;
}

/* ---- Figures drawn by hand ----------------------------------------------- */

/* The lines of graphs and figures wobble a little, as if sketched. */
html.sketch .graph-curve,
html.sketch .graph-region,
html.sketch .fig-shape,
html.sketch .fig-line,
html.sketch .fig-mark,
html.sketch .fig-edge,
html.sketch .fig-node,
html.sketch .fig-bar,
html.sketch .fig-wedge,
html.sketch .fig-set,
html.sketch .fig-arrow,
html.sketch .draw-stroke {
  filter: url(#sketchy);
  stroke-linecap: round;
}

/* ---- Blanks to fill in -------------------------------------------------- */

/* A blank is a line to write on; once filled, what is written sits on it in
   the colour of handwriting. */
.blank {
  display: inline-block;
  min-width: 5em;
  padding: 0 4px;
  border-bottom: 1.5px solid color-mix(in srgb, var(--ink) 55%, transparent);
  line-height: 1.2;
  text-align: center;
}
.note p .blank {
  cursor: text;
}
.blank.filled {
  min-width: 2.5em;
  color: var(--accent);
  font-style: italic;
}
.note p .blank:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.math-blank {
  color: var(--accent);
}
@media print {
  .blank.filled,
  .math-blank {
    color: inherit;
  }
}
