/* 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);

  /* A shade darker than the first curve's blue, so that links on the
     warmer paper of the book look reach a contrast of 4.5 to 1. */
  --accent: #2b66d0;
  --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;
}

/* A section not drawn keeps the room it took, border and padding too. */
.section.undrawn {
  box-sizing: border-box;
}

.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;
  /* The bar marking the line stands a little way out from its words, in
     the margin, so the words stay where they are. */
  padding: 4px 6px 4px 9px;
  margin-left: -12px;
  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;
}

/* In a pane of a grid there is less room before its edge. */
.pane:not(.flow) .line {
  padding-left: 6px;
  margin-left: -9px;
}

/* A heading gone to sits just under the bar at the top. */
.line[data-heading] {
  scroll-margin-top: calc(var(--menubar) + 14px);
}

.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;
}

/* KaTeX stacks the parts of a fraction, a matrix, a root or a script in
   tall boxes that reach over what is drawn above and below them, and draws
   roots and arrows as pictures across the whole part. These let the
   pointer through, so that a click, a right click or a drag reaches the
   part under it rather than the box over it. */
.tex .katex .vlist-t,
.tex .katex .vlist-r,
.tex .katex .vlist,
.tex .katex .vlist > span,
.tex .katex .pstrut,
.tex .katex svg {
  pointer-events: none;
}
.tex .katex [data-path] {
  pointer-events: auto;
}

/* ---- Rows lined up, and words beside a step ----------------------------- */

/* The rows of an aligned display share one grid: what comes before the
   sign, the sign and the rest, the words beside, then the number and the
   mark of the step at the right. Each row is a line of its own laid on that
   grid, so it keeps its bar, its colours and its clicks. */
.aligned {
  display: grid;
  grid-template-columns: max-content max-content minmax(0, 1fr) auto auto;
}
.align-center .aligned,
.align-right .aligned {
  grid-template-columns: max-content max-content minmax(0, max-content) auto auto;
  justify-content: center;
}
.align-right .aligned {
  justify-content: end;
}
.aligned > .line {
  grid-column: 1 / -1;
}
.aligned > .line.row {
  display: grid;
  grid-template-columns: subgrid;
  align-items: center;
  column-gap: 0;
}
.line.row > .tex-before {
  grid-area: 1 / 1;
  padding-right: 0;
  text-align: right;
}
.line.row > .tex-after {
  grid-area: 1 / 2;
  padding-left: 0;
}
.line.row > .beside { grid-area: 1 / 3; }
.line.row > .eq-number { grid-area: 1 / 4; }
.line.row > .mark { grid-area: 1 / 5; }
.line.row > .check-note,
.line.row > .caption,
.line.row > .matrix-slot {
  grid-column: 1 / -1;
}
/* An empty piece, before the sign of a line that goes on from the one
   above, still takes its place in the grid. */
.line.row > .tex:empty {
  min-height: 1px;
}

/* The words beside a step: its reason, at its right, as a book sets it. */
.beside {
  min-width: 0;
  margin: 0;
  padding-left: 2.5em;
  color: var(--muted);
  font-size: 14px;
}
.beside:empty {
  padding: 0;
}

/* ---- 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;
}

/* The boxes of a textbook beyond theorems and proofs. Each has a colour of
   its own, and some a sign before their name, so that a Try It is told
   from an example at a glance. A solution is set like a proof, without
   the square. */
.pane.block.block-tryit,
.pane.block.block-yourturn {
  --kind: var(--visual);
}
.pane.block.block-yourturn {
  box-shadow: none;
  border-left: 3px dashed var(--kind);
}
.pane.block.block-checkunderstanding,
.pane.block.block-question {
  --kind: var(--good);
}
.pane.block.block-beprepared {
  --kind: var(--warn);
}
.pane.block.block-howto,
.pane.block.block-media {
  --kind: var(--accent);
}
.pane.block.block-manipulative {
  --kind: var(--pending);
}
.pane.block.block-note {
  --kind: var(--muted);
  background: color-mix(in srgb, var(--kind) 7%, transparent);
}
/* A box of the author's own is framed all round, its name on a tab. */
.pane.block.block-feature {
  --kind: color-mix(in srgb, var(--ink) 55%, var(--paper));
  border: 1.5px solid color-mix(in srgb, var(--kind) 55%, transparent);
  border-radius: 8px;
  box-shadow: none;
}
.block-feature > .block-head {
  display: inline-block;
  font-variant: normal;
  letter-spacing: 0;
}
.block-tryit > .block-head::before,
.block-yourturn > .block-head::before,
.block-checkunderstanding > .block-head::before,
.block-beprepared > .block-head::before,
.block-howto > .block-head::before,
.block-question > .block-head::before,
.block-media > .block-head::before,
.block-manipulative > .block-head::before {
  display: inline-block;
  min-width: 1.1em;
  margin-right: 0.35em;
  font-variant: normal;
  text-align: center;
}
.block-tryit > .block-head::before {
  content: "\270e";
}
.block-yourturn > .block-head::before {
  content: "\2192";
}
.block-checkunderstanding > .block-head::before,
.block-question > .block-head::before {
  content: "?";
  font-weight: 800;
}
.block-beprepared > .block-head::before {
  content: "\2713";
}
.block-howto > .block-head::before {
  content: "\2630";
}
.block-media > .block-head::before {
  content: "\25b6";
  font-size: 0.8em;
}
.block-manipulative > .block-head::before {
  content: "\25c6";
  font-size: 0.85em;
}
.pane.block.block-solution {
  background: none;
  box-shadow: inset 2px 0 0 color-mix(in srgb, var(--muted) 45%, transparent);
}
.block-solution > .block-head {
  background: none;
  color: var(--ink);
  font-style: italic;
  font-variant: normal;
  font-weight: 500;
  letter-spacing: 0;
}

/* A box that folds: its heading is a button that shows or hides what the
   box holds. Closed, the heading is all there is. */
.pane > button.fold-head {
  display: flex;
  align-items: baseline;
  gap: 0.4em;
  width: calc(100% - 14px);
  border: 0;
  text-align: left;
  cursor: pointer;
}
button.fold-head:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.fold-mark {
  display: inline-block;
  width: 0.9em;
  font-style: normal;
  font-variant: normal;
}
.fold-word {
  margin-left: auto;
  color: var(--muted);
  font: 500 12px var(--ui);
  font-style: normal;
  font-variant: normal;
  letter-spacing: 0;
  opacity: 0;
}
button.fold-head:hover .fold-word,
button.fold-head:focus-visible .fold-word,
.pane.folds.closed > button.fold-head .fold-word {
  opacity: 1;
}
/* Paper shows every box open, as it is printed, unless the page setup
   says to print folded boxes folded. */
@media screen {
  .pane.folds.closed > :not(.block-head) {
    display: none;
  }
  .pane.folds.closed > .block-head {
    margin-bottom: 0;
  }
  .pane.folds.closed {
    padding-bottom: 6px;
  }
  /* The cursor on a closed box rests on its heading. */
  .pane.folds.closed.on-path > .block-head {
    outline: 2px solid hsl(var(--hue) / 0.7);
    outline-offset: 1px;
  }
}
@media print {
  .pane.folds.print-closed > :not(.block-head) {
    display: none;
  }
  .fold-mark,
  .fold-word {
    display: none;
  }
}

/* ---- 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;
}
/* Headings below the third get smaller and quieter, the last in italics,
   as a book sets its run-in headings. */
.note p.md-h4,
.note p.md-h5,
.note p.md-h6 {
  color: var(--ink);
  font-size: 14.5px;
}
.note p.md-h4 {
  font-weight: 650;
  font-style: italic;
}
.note p.md-h5 {
  font-weight: 600;
  font-variant: small-caps;
  letter-spacing: 0.03em;
}
.note p.md-h6 {
  font-weight: 500;
  font-style: italic;
}
/* A heading inside a box heads only the box, a step smaller than the
   same heading on the page. */
.pane.block .note p.md-h1 {
  font-size: 19px;
}
.pane.block .note p.md-h2 {
  font-size: 16.5px;
}
html.paper .pane.block .note p.md-h1 {
  font-size: 21px;
}
html.paper .pane.block .note p.md-h2 {
  font-size: 18px;
}
/* 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, p.md-h4):not(:first-child) {
  margin-top: 14px;
}
.line.note:has(p.md-h5, p.md-h6):not(:first-child) {
  margin-top: 8px;
}
/* An item of a list inside another is set in under the words of the item
   it is in. */
.note p.md-item {
  padding-left: calc(0.4em + var(--depth, 0) * 1.5em);
}
.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: 1;
  color: var(--muted);
}
.pane.focused .line.active .md-marker {
  display: inline;
  /* The line's highlight is behind it: muted would not stand out. */
  color: var(--ink);
}
.md-marker.bullet {
  display: inline;
  opacity: 1;
  color: var(--muted);
}
/* 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: 1;
  color: var(--muted);
}
.md-marker.number::before {
  content: var(--ordinal, counter(enum-item) ".");
}

/* Underlined words, and footnotes: the mark raised in the words, and the
   footnotes gathered under a short rule at the end of a section or of the
   page, each with a way back to its mark. */
.note u {
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}
/* Words lowered or raised, H₂O or the kth term: small, and kept from
   pushing the lines apart. */
sub,
sup {
  font-size: 0.72em;
  line-height: 0;
}
sub {
  vertical-align: -0.25em;
}
sup {
  vertical-align: 0.4em;
}
.fn-mark {
  margin-left: 0.05em;
  color: var(--accent);
  font: 600 0.68em var(--ui);
  line-height: 0;
  cursor: pointer;
}
.fn-mark:hover {
  text-decoration: underline;
}
.footnotes {
  margin: 14px 0 18px 12px;
  padding-top: 6px;
  border-top: 1px solid var(--rule);
  max-width: 34em;
  color: color-mix(in srgb, var(--ink) 82%, var(--paper));
  font-size: 13.5px;
  line-height: 1.5;
}
.footnotes ol {
  margin: 0;
  padding-left: 1.6em;
}
.footnotes li::marker {
  color: var(--muted);
  font: 600 0.9em var(--ui);
}
.footnotes li:target {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.fn-back {
  padding: 0 4px;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}
.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);
}
/* Code of several words is one chip, each word's part of it squared off
   where it meets the space to the next. */
.note p .code-on code,
.note p code.code-gap {
  padding-right: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.note p .code-from code,
.note p code.code-gap {
  padding-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.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: -10px;
  right: -9px;
  height: 20px;
  padding: 0 8px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font: 11px/1 var(--sans, system-ui);
  white-space: nowrap;
  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: #000;
}

.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;
  /* Under the bar at the top, which would cover its first rows. */
  inset: var(--menubar) 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;
  /* Over the row below, whose faint marks are drawn in layers of their
     own and would otherwise show through. */
  z-index: 5;
  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);
  /* A long menu on a short window scrolls rather than running off it. */
  max-height: calc(100vh - 56px);
  max-height: calc(100dvh - 56px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.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;
}
/* The choices under a heading, kept together for a screen reader. */
.menu-group {
  margin: 0;
  padding: 0;
  list-style: none;
}
.menu-rule {
  height: 1px;
  margin: 5px 6px;
  background: var(--rule);
}
.file-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-left: auto;
  color: var(--muted);
  white-space: nowrap;
}
.file-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-name.none {
  font-style: italic;
}
/* Changes not yet in the file: a dot drawn like the account's sync dot,
   so the two line up. */
.file-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  visibility: hidden;
}
.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);
  /* Darker than muted, to stand out from the tint behind it. */
  color: color-mix(in srgb, var(--muted) 55%, var(--ink));
  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 a {
  display: block;
  color: inherit;
  text-decoration: none;
}
.toc li a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}
.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;
}
/* A book of chapters: each chapter's arrow shows or hides its sections. */
.toc li.toc-hidden {
  display: none;
}
.toc li:has(> .toc-fold) {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding-left: 2px;
}
.toc .toc-fold {
  flex: none;
  width: 18px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  transition: transform 0.12s;
}
.toc .toc-fold[aria-expanded="true"] {
  transform: rotate(90deg);
}
.toc .toc-fold:hover {
  color: var(--ink);
}
.toc .toc-level-2 {
  padding-left: 18px;
}
.toc .toc-level-3 {
  padding-left: 30px;
  font-size: 12px;
}
.toc .toc-level-4,
.toc .toc-level-5,
.toc .toc-level-6 {
  padding-left: 42px;
  color: var(--muted);
  font-size: 12px;
}
.toc .toc-level-5 {
  padding-left: 52px;
}
.toc .toc-level-6 {
  padding-left: 62px;
}
.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;
}
/* Long division is set in the type of the mathematics. */
.fig-division-text {
  fill: var(--ink);
  font-family: KaTeX_Main, "Times New Roman", serif;
  font-size: 17px;
}
.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;
}

/* ---- Interactive components --------------------------------------------- */

/* Drawn like a cell of Python: a head with its name and buttons, then the
   component in its frame, or its source while that is typed. */
.line.interactive .component {
  flex: 1;
  min-width: 0;
  margin: 4px 0;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--panel);
}
.component .cell-language {
  flex: none;
}
.component-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.component-host {
  padding: 6px 10px;
}
/* The frame has no background of its own, so the component sits on the
   cell as if it were part of the page. */
.component-frame {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
}
.component-wait {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 12px;
  color: var(--muted);
  font: 14px var(--ui);
}
.component-wait p {
  flex: 1;
  margin: 0;
}
.component-left {
  margin: 0;
  padding: 6px 2px;
  color: var(--muted);
  font: 14px var(--ui);
}
.component-run {
  padding: 4px 12px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--accent);
  font: 600 13px var(--ui);
  cursor: pointer;
}
/* What printing shows in its place: a component runs only on the page. */
.component-print {
  display: none;
  margin: 0;
  padding: 10px 12px;
  color: var(--muted);
  font: italic 14px var(--ui);
}
@media print {
  .component .cell-head,
  .component .cell-source,
  .component-host,
  .component-wait {
    display: none !important;
  }
  .component-print {
    display: block;
  }
  .line.interactive .component {
    break-inside: avoid;
  }
}

/* ---- 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 {
  /* These outrank the paper look's colours, a theme's, and the dark ones,
     each of which is set on html with a class or an attribute. */
  html:root,
  html:root.paper,
  html:root[data-theme] {
    color-scheme: light;
    --paper: #ffffff;
    --ink: #1f2328;
    --muted: #57606a;
    --rule: #d8dee4;
    --panel: #ffffff;
    --accent: #2f6fde;
    --visual: #8250df;
    --pending: #b7791f;
    --wash: 0.07;
    --shadow: none;
    --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 Vim's keys are on, an advanced setting, and the
   button that turns them off: plain to see, so that nobody is left
   wondering why typing does not write. */
.keys-vim {
  padding: 2px 9px;
  border-radius: 4px;
  background: var(--pending);
  /* Black on the amber, which light words do not stand out from. */
  color: #000;
  font: 700 11px var(--ui);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.keys-off {
  padding: 2px 9px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font: 12px var(--ui);
  cursor: pointer;
}

.keys-off:hover {
  border-color: var(--accent);
  color: var(--accent);
}

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

@media (pointer: coarse) {
  /* 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;
    max-height: calc(100dvh - var(--menubar) - 12px);
  }
  .title h1 {
    font-size: 21px;
  }
}


/* 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;
}

/* A part of a formula circled with circled(...): a box with its corners
   rounded right round. */
.katex .math-circled .fbox {
  border-radius: 50%;
}
.katex .math-circled .boxpad {
  padding: 0 0.45em;
}

/* 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;
}
button.section-name {
  min-width: 0;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  font: inherit;
  text-align: left;
  cursor: default;
}
.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, the docs, then the books. */
.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 .note p.md-h4,
html.paper .note p.md-h5,
html.paper .note p.md-h6,
html.paper .footnotes,
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 ----------------------------------------------- */

/* Graphs and figures drawn as if by hand. crates/core/src/sketch.rs draws
   each line again, wobbling and gone over twice, shades a filled shape with
   hatching and makes a small mark a blob; the rules here colour what it
   draws, and set the words in a handwriting type: Coming Soon, by Open
   Window, under the Apache License 2.0 (see fonts/). Mathematics set by
   KaTeX, and long division, keep the type of the mathematics. */
@font-face {
  font-family: "Coming Soon";
  src: url("fonts/ComingSoon.ttf") format("truetype");
  font-display: swap;
}
html.sketch {
  --hand: "Coming Soon", "Comic Sans MS", "Chalkboard SE", cursive;
}
html.sketch .fig text:not(.fig-division-text),
html.sketch .plot svg text,
html.sketch .line.graph .graph-note {
  font-family: var(--hand);
  font-size-adjust: 0.56;
}
/* Words in a figure or graph are written over its hatching on a patch of
   paper, wide enough that the hatching stays clear of every letter. */
html.sketch .fig text:not(.fig-division-text),
html.sketch .plot svg text {
  paint-order: stroke;
  stroke: var(--panel);
  stroke-width: 5px;
  stroke-linejoin: round;
  stroke-opacity: 0.95;
}
/* A line drawn again is only a line: the fill is the copies' under it. */
html.sketch .sk-line {
  fill: none !important;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* Paper under a shape that hides what is behind it, and the shape's own
   colour, in hatching, over that. */
html.sketch .sk-paper {
  fill: var(--panel) !important;
  stroke: none !important;
}
html.sketch .sk-hatch,
html.sketch .sk-plain {
  stroke: none !important;
}
/* Shapes that are only filled get an edge in their colour. Picking one
   still marks it, as these rules weigh no more than a class. */
:where(html.sketch) .sk-line.fig-bar,
:where(html.sketch) .sk-line.fig-wedge {
  stroke: var(--curve);
  stroke-width: 1.5;
}
:where(html.sketch) .sk-line.sk-from-rect.fig-region {
  stroke: var(--muted);
  stroke-width: 1.4;
}
/* Hatching is lines, not a wash, so it takes a stronger colour than the
   wash it stands for. */
:where(html.sketch) .sk-hatch.fig-node {
  fill: color-mix(in srgb, var(--curve) 60%, var(--panel));
}
:where(html.sketch) .fig-plain .sk-hatch.fig-node,
:where(html.sketch) .sk-hatch.fig-node.fig-plain {
  fill: var(--panel);
}
:where(html.sketch) .fig-shaded .sk-hatch.fig-region {
  fill: color-mix(in srgb, var(--accent) 70%, var(--panel));
}
:where(html.sketch) .sk-hatch.fig-shape {
  fill: color-mix(in srgb, var(--accent) 50%, transparent);
}
:where(html.sketch) .fig-draw .draw-fill > .sk-hatch {
  fill: color-mix(in srgb, var(--curve, var(--paint, var(--accent))) 70%, transparent);
}
:where(html.sketch) .sk-hatch.fig-head {
  fill: color-mix(in srgb, var(--accent) 35%, var(--panel));
}
:where(html.sketch) .sk-hatch.graph-region {
  fill-opacity: 0.55;
}
/* A share written on its slice of a pie, which is now mostly paper. */
:where(html.sketch) .fig-share {
  fill: var(--ink);
  paint-order: stroke;
  stroke: var(--panel);
  stroke-width: 5px;
}
/* The frame drawn round a picture. */
html.sketch .sk-frame {
  stroke: var(--muted);
  stroke-width: 1.2;
}

/* ---- 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;
  }
}

/* With nothing selected (Escape let go of it), the cursor is not shown:
   no line is lit, no word or symbol marked, no figure's panel open. */
.page.resting .pane.focused .line.active {
  border-left-color: transparent;
  background: none;
}
.page.resting .lp-cursor {
  background: none;
  outline: none;
}
.page.resting .fig-inspector,
.page.resting .fig-part.selected .fig-hit,
.page.resting .term-switch:not(.on) {
  display: none;
}

/* ---- Narrow screens ------------------------------------------------------- */

@media (max-width: 900px) {
  /* The section's name opens the contents, over the page from the left. */
  button.section-name {
    border-color: var(--rule);
    color: var(--ink);
    cursor: pointer;
  }
  html.contents-open .toc {
    display: block;
    z-index: 16;
    width: min(320px, 86vw);
    box-shadow: var(--shadow);
  }
}

@media (max-width: 700px) {
  :root {
    --menubar: 76px;
  }
  .menubar-row.place .pad-button {
    align-self: center;
    margin-right: 2px;
    padding: 3px 8px;
  }
  /* Room for a thumb: taller rows in the bar, and the words a size for a
     phone held at reading distance. */
  .menubar-row {
    gap: 4px;
  }
  .menubar .jump {
    padding: 4px 9px;
    font-size: 17px;
  }
  html.paper .note p {
    font-size: 16px;
    line-height: 1.55;
  }
  .note p.md-h1,
  html.paper .note p.md-h1 {
    font-size: 21px;
  }
  .note p.md-h2,
  html.paper .note p.md-h2 {
    font-size: 18px;
  }
  /* Mathematics scrolls sideways within its line rather than the page. */
  .tex {
    font-size: 1em;
    padding-left: 2px;
    padding-right: 2px;
  }
  .line {
    gap: 4px;
    padding-right: 2px;
  }
  .line > .mark {
    padding-left: 4px;
  }
  .eq-number {
    padding-left: 6px;
  }
  /* Panes and blocks use the width; a pane's frame is thinner. */
  .pane {
    padding-left: 4px;
    padding-right: 4px;
  }
  .block-head {
    margin-left: 2px;
  }
  /* Cards and panels fit the screen. */
  .term-card {
    max-width: min(320px, 80vw);
  }
  .fig-inspector {
    max-width: 100%;
  }
  .prompt {
    min-width: 0;
    max-width: calc(100vw - 16px);
  }
  .help {
    columns: auto;
    padding: 16px 16px 120px;
  }
  .palette {
    width: calc(100vw - 16px);
  }
}

/* With no hover, what shows on pointing shows always. */
@media (hover: none) {
  .term-switch,
  .cell-head button {
    opacity: 1;
  }
}

/* On a touch screen, a bar tall enough for buttons a finger can hit, with
   room around them. Last, so that it wins over the narrow-screen height. */
@media (pointer: coarse) {
  :root {
    --menubar: 96px;
  }
}

/* ---- Read only, on a phone ---------------------------------------------- */

/* A phone reads: no cursor, no buttons for typing, no panels for changing
   figures, and a line at the bottom saying where to edit. */
.read-only-note {
  display: none;
}
html.read-only .read-only-note {
  display: block;
  margin: 0;
  padding: 10px 16px;
  color: var(--muted);
  font: 13px var(--ui);
  text-align: center;
}
html.read-only .toolbar,
html.read-only .status,
html.read-only .prompt,
html.read-only .fig-inspector,
html.read-only .fig-add,
html.read-only .term-switch,
html.read-only .term-unlink,
html.read-only .cell-head button,
html.read-only .gl-new {
  display: none !important;
}
html.read-only .pane.focused .line.active {
  border-left-color: transparent;
  background: none;
}
html.read-only .lp-cursor {
  background: none;
  outline: none;
}
html.read-only .note p .blank {
  cursor: default;
}
/* The marks that make a note a heading or a quote show only for editing. */
html.read-only .pane.focused .line.active .md-marker:not(.bullet):not(.number):not(.written) {
  display: none;
}

/* Lines selected whole in visual mode, with j and k. */
.line.selected,
.pane.focused .line.selected.active {
  background: color-mix(in srgb, var(--visual) 14%, transparent);
  box-shadow: inset 3px 0 0 color-mix(in srgb, var(--visual) 85%, transparent);
}

@media print {
  .line.selected {
    background: none;
    box-shadow: none;
  }
}

/* Panes selected to delete together. */
.pane.selected,
.pane.focused.selected {
  border-color: color-mix(in srgb, var(--visual) 85%, transparent);
  background: color-mix(in srgb, var(--visual) 12%, transparent);
  box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--visual) 40%, transparent);
}

@media print {
  .pane.selected {
    background: none;
    box-shadow: none;
  }
}

/* ---- Tables, pictures and page breaks ------------------------------------ */

.line.table,
.line.image {
  flex-wrap: wrap;
}
.table-box {
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
}
.lp-table {
  border-collapse: collapse;
  margin: 4px 0;
  font-size: 0.95em;
}
.lp-table td {
  min-width: 4em;
  padding: 5px 10px;
  border: 1px solid var(--rule);
  /* The first lines of a row stand on one baseline, so that a number
     sits level with the bar of a fraction beside it. */
  vertical-align: baseline;
  cursor: text;
}
.lp-table td p {
  margin: 0;
  min-height: 1lh;
  white-space: pre-wrap;
}
.lp-table tr.head td {
  border-bottom: 2px solid var(--muted);
  font-weight: 600;
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}
.lp-table td.current {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}
.page.resting .lp-table td.current,
.pane:not(.focused) .lp-table td.current {
  outline: none;
  background: none;
}
/* Only the cell being typed into hides its text under the field. */
.line.table.editing td:not(.editing) p {
  -webkit-text-fill-color: currentColor;
}
.table-panel .table-hint {
  align-self: center;
  color: var(--muted);
}
.fig-actions button.on {
  border-color: var(--accent);
  color: var(--accent);
}

.line.image .picture-row {
  flex: 1 1 0;
  min-width: 0;
}
.line.image .picture {
  display: block;
  margin-top: 4px;
  margin-bottom: 4px;
}
.picture img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 2px;
}
.line.image.active .picture img {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.picture-missing {
  padding: 2em;
  border: 1px dashed var(--rule);
  color: var(--muted);
  text-align: center;
}
/* A picture that could not be fetched from its address: a frame with what
   it shows written in it, as the browser writes it. */
.picture img.unfetched,
img.md-picture.unfetched {
  min-height: 2em;
  border: 1px dashed var(--rule);
  color: var(--muted);
  font-size: 0.85em;
}
.picture-panel input[type="range"] {
  width: 10em;
  accent-color: var(--accent);
}
.picture-panel .picture-address input {
  width: 22em;
  max-width: 100%;
}

/* A picture among the words of a note or a cell: no wider than its column,
   and one given no size no taller than the text. */
img.md-picture {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}
img.md-picture.text-height {
  max-height: 1.3em;
  width: auto;
}
.line.image .caption,
.line.table .caption {
  flex-basis: 100%;
  text-align: center;
}

.line.page-break .break-rule {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  color: var(--muted);
  font: 11px var(--ui);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.line.page-break .break-rule::before,
.line.page-break .break-rule::after {
  content: "";
  flex: 1;
  border-top: 1px dashed var(--rule);
}
.line.page-break.active .break-rule {
  color: var(--accent);
}

/* A picture being dragged over the page. */
body.dropping .page {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
}

/* ---- Page setup and templates -------------------------------------------- */

.dialog {
  gap: 10px;
  /* On a phone the page setup is taller than the room under the bars: it
     scrolls within its box, clear of the status bar. */
  max-height: min(70vh, calc(100dvh - var(--menubar) - 80px));
  overflow-y: auto;
}
.setup-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px 14px;
  align-items: end;
}
.setup-wide {
  grid-column: 1 / -1;
}
.setup-form select,
.setup-form input[type="number"],
.setup-form input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  padding: 5px 7px;
  border: 1px solid var(--rule);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  font: 13px var(--ui);
}
.setup-check {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}
.setup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.setup-actions button,
.template {
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: 13px var(--ui);
  cursor: pointer;
}
.setup-actions button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.templates {
  display: grid;
  gap: 8px;
}
.template {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
}
.template:hover,
.setup-actions button:hover {
  border-color: var(--accent);
}
.template-name {
  font-weight: 600;
}
.template-about {
  color: var(--muted);
}
@media (max-width: 520px) {
  .setup-form {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media print {
  .table-panel,
  .picture-panel,
  .dialog {
    display: none !important;
  }
  .lp-table td.current {
    outline: none;
    background: none;
  }
  /* Nor does the section the cursor is in. */
  .section.active {
    border-color: transparent;
    background: none;
  }
  .line.image.active .picture img {
    outline: none;
  }
  .line.table,
  .line.image {
    break-inside: avoid;
  }
  /* A line with nothing on it yet is room to write in. */
  .line.math.empty-line {
    min-height: 4.5em;
  }
  .line.math.empty-line .tex {
    visibility: hidden;
  }
  /* A page break shows nothing, and ends the page. */
  .line.page-break {
    display: block;
    height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    break-after: page;
  }
  .line.page-break .break-rule {
    display: none;
  }
}

/* ---- The toolbar --------------------------------------------------------- */

/* The actions a mouse or a finger needs most, in a row under the menus. The
   bar at the top, as the rest of the page measures it, takes it in. */
:root {
  --toolbar: 38px;
  --menubar: calc(68px + var(--toolbar));
}
@media (max-width: 700px) {
  :root {
    --menubar: calc(76px + var(--toolbar));
  }
}
@media (pointer: coarse) {
  :root {
    --toolbar: 52px;
    --menubar: calc(96px + var(--toolbar));
  }
}
/* A tablet held upright has no room for the buttons in one row, at the
   size a finger needs: they wrap onto two, so Delete and Done stay in
   reach. */
@media (pointer: coarse) and (max-width: 1000px) {
  :root {
    --toolbar: 100px;
  }
  .toolbar-row {
    flex-wrap: wrap;
    align-content: center;
    row-gap: 2px;
  }
  .tool-gap {
    display: none;
  }
}
html.read-only {
  --toolbar: 0px;
}
.menubar {
  height: calc(var(--menubar) - var(--toolbar));
}
.toolbar {
  position: fixed;
  top: calc(var(--menubar) - var(--toolbar));
  right: 0;
  left: 0;
  z-index: 13;
  height: var(--toolbar);
  border-bottom: 1px solid var(--rule);
  background: var(--panel);
  font: 13px var(--ui);
  will-change: transform;
}
.toolbar-row {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 100%;
  padding: 0 12px 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tool {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  white-space: nowrap;
  cursor: pointer;
}
.tool:hover {
  border-color: var(--rule);
}
.tool:active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}
.tool:focus-visible,
.menu-name:focus-visible,
.menubar button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.tool-math {
  pointer-events: none;
}
.tool-math .katex {
  font-size: 1.05em;
}
/* A fraction drawn whole, as big as the button allows. */
.tool-math .katex .mfrac {
  font-size: 0.8em;
}
.tool-rule {
  flex: none;
  width: 1px;
  height: 18px;
  margin: 0 6px;
  background: var(--rule);
}
.tool-gap {
  flex: 1;
}
.tool-done {
  display: none;
}
.tool-done.shown {
  display: inline-flex;
}
.tool-done .tool {
  border-color: var(--accent);
  color: var(--accent);
}
@media (pointer: coarse) {
  .toolbar-row {
    padding: 0 6px;
  }
  .tool {
    min-width: 44px;
    height: 44px;
    padding: 0 9px;
    font-size: 15px;
  }
  .tool-rule {
    margin: 0 2px;
  }
  .tool-math .katex {
    font-size: 1.2em;
  }
}

/* ---- The menu on right click --------------------------------------------- */

.ctx-menu {
  position: fixed;
  z-index: 30;
  min-width: 220px;
  margin: 0;
  padding: 5px;
  list-style: none;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font: 13px var(--ui);
  max-height: calc(100vh - 8px);
  overflow-y: auto;
}
.ctx-menu button {
  display: block;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
/* The kinds of box, listed under the button that opens them. */
.ctx-menu .menu-sub button {
  padding: 4px 10px 4px 24px;
  font-size: 0.94em;
}
.ctx-menu button:hover,
.ctx-menu button:focus-visible,
.menu-items button:focus-visible {
  outline: none;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
@media (pointer: coarse) {
  .ctx-menu button,
  .menu-items button {
    min-height: 44px;
  }
}

/* ---- Pointing and touching ----------------------------------------------- */

/* Dragging across a line selects its parts, not the letters drawn. */
.line.math .tex {
  -webkit-user-select: none;
  user-select: none;
}
/* A finger held on a line opens lemmapad's own menu, not the system's. */
.page .line {
  -webkit-touch-callout: none;
}
/* A tap is a tap at once, and two do not zoom the page. */
.page,
.toolbar,
.menubar,
.bars {
  touch-action: manipulation;
}
.palette-item {
  cursor: pointer;
}
.palette-item:hover:not(.selected) {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}

/* Read by screen readers, not shown. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media print {
  .toolbar,
  .ctx-menu {
    display: none !important;
  }
}

/* The account menu, at the right of the bar, and the panel it opens. */
.account-menu .menu-items {
  right: 0;
  left: auto;
}
/* Set apart from the file's name and its dot beside it. */
.account-menu {
  margin-left: 12px;
  padding-left: 12px;
  border-left: 1px solid var(--rule);
}
.account-menu .menu-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sync-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--muted);
}
.sync-dot.synced {
  background: var(--good);
}
.sync-dot.syncing {
  background: var(--accent);
  animation: sync-pulse 1s ease-in-out infinite alternate;
}
.sync-dot.offline {
  background: var(--warn);
}
.sync-dot.failed {
  background: var(--bad);
}
@keyframes sync-pulse {
  to {
    opacity: 0.35;
  }
}
@media (prefers-reduced-motion: reduce) {
  .sync-dot.syncing {
    animation: none;
  }
}
.menu-note {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 10px 8px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 4px;
}
.account-email {
  color: var(--ink);
  font-weight: 600;
}
.account-status {
  color: var(--muted);
  font-size: 12px;
}
.account-panel {
  position: fixed;
  top: calc(var(--menubar) + 24px);
  left: 50%;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(600px, calc(100vw - 32px));
  max-height: calc(100vh - var(--menubar) - 48px);
  overflow-y: auto;
  transform: translateX(-50%);
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--ink);
  font: 13px var(--ui);
}
.account-section {
  padding: 10px 0;
  border-top: 1px solid var(--rule);
}
.account-panel .history-head + .account-section {
  border-top: 0;
}
.account-section h3 {
  margin: 0 0 6px;
  font-size: 13px;
}
.account-note {
  margin: 4px 0 8px;
  color: var(--muted);
  line-height: 1.45;
}
.account-note strong {
  color: var(--ink);
}
.account-note.done {
  color: var(--good);
}
.account-buttons,
.account-email-form,
.account-invite {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0;
}
.account-panel button,
.account-panel input,
.account-panel select {
  padding: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}
.account-panel button {
  color: var(--accent);
  cursor: pointer;
}
.account-panel button:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.account-panel button.danger {
  color: var(--bad);
}
.account-panel button.danger:hover {
  background: color-mix(in srgb, var(--bad) 12%, transparent);
}
.account-panel button.link {
  padding: 0;
  border: 0;
  background: none;
  text-decoration: underline;
}
.account-panel .history-head button {
  border: 0;
  color: var(--muted);
  font-size: 18px;
}
.account-panel input {
  flex: 1 1 200px;
  min-width: 0;
}
.account-orgs,
.account-members {
  margin: 0;
  padding: 0;
  list-style: none;
}
.account-org {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}
.account-org .account-invite {
  flex-basis: 100%;
}
.account-member {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 4px 8px;
  padding: 6px 0;
  border-top: 1px solid var(--rule);
}
.account-member-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-member-detail {
  grid-column: 1;
  grid-row: 2;
  color: var(--muted);
  font-size: 12px;
}
.account-member button {
  grid-row: 1 / span 2;
}
@media (max-width: 520px) {
  .account-menu .menu-name {
    max-width: 110px;
  }
}
/* The narrowest phones: the bar's buttons sit closer, so that Sign in
   fits whole, and the pad's button leaves out how it is shared and the
   count beside it, which Share and the switcher show, for its name. */
@media (max-width: 360px) {
  .menubar .menu-name {
    padding: 5px 6px;
  }
  .account-menu {
    margin-left: 4px;
    padding-left: 4px;
  }
  .share-button {
    padding: 4px 7px;
  }
  .pad-button .share-badge,
  .pad-button .pad-count {
    display: none;
  }
}
@media print {
  .account-panel,
  .account-menu {
    display: none !important;
  }
}

/* A toast: a short note at the foot of the page, over the status bar, that
   goes by itself, such as pads synced with the account. */
.toast {
  position: fixed;
  bottom: 56px;
  left: 50%;
  z-index: 40;
  width: max-content;
  max-width: min(480px, calc(100vw - 32px));
  padding: 8px 14px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--ink);
  font: 13px var(--ui);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}

@media print {
  .toast {
    display: none;
  }
}

/* ---- Names and folders ----------------------------------------------------- */

/* A pad in the switcher: its name, with its title when named apart; where
   it lives; and, when found by what it says, those words underneath. */
.switcher-row {
  grid-template-columns: minmax(0, 1fr) auto auto;
}
.switcher-name {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 8px;
}
.switcher-also {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.switcher-place {
  margin-right: 8px;
}
/* A book of the catalogue whose chapter is open. */
.switcher-holds {
  margin-right: 8px;
  color: var(--accent);
}
.switcher-place::before {
  content: "\1F4C1\FE0E  ";
  opacity: 0.7;
}
.switcher-snippet {
  grid-column: 1 / -1;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.switcher-actions {
  display: flex;
  gap: 2px;
}
.switcher-action {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  cursor: pointer;
}
.switcher-row:hover .switcher-action,
.switcher-row.selected .switcher-action {
  opacity: 1;
}
.switcher-action:hover {
  background: color-mix(in srgb, var(--ink) 10%, transparent);
  color: var(--ink);
}
.switcher-action.switcher-delete:hover {
  background: color-mix(in srgb, var(--bad) 18%, transparent);
  color: var(--bad);
}
.switcher-foot {
  display: flex;
  gap: 6px;
  margin: 6px 8px 8px;
}
.switcher-foot .switcher-new {
  flex: 1;
  margin: 0;
}
.switcher-foot .switcher-new + .switcher-new {
  flex: 0 0 auto;
}

/* The field that renames a pad or folder in place. */
.switcher-rename,
.explorer-rename,
.pad-rename {
  min-width: 0;
  padding: 3px 7px;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  outline: none;
}
.switcher-rename,
.explorer-rename {
  flex: 1;
}
.switcher .switcher-rename {
  margin: 0;
}
.pad-rename {
  width: 260px;
  max-width: 46vw;
  margin-right: 10px;
}

/* The folders the open pad is in, before its name in the bar. */
.pad-folder {
  max-width: 140px;
  overflow: hidden;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  font: inherit;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.pad-folder:hover {
  border-color: var(--rule);
  color: var(--ink);
}
.pad-folder + .crumb-mark {
  margin: 0 4px 0 0;
}
.pad-menu {
  position: relative;
  margin: 0 10px 0 -6px;
}
.pad-menu.hidden {
  display: none;
}
.pad-more {
  padding: 2px 7px;
  color: var(--muted);
}
.pad-menu .menu-items {
  min-width: 200px;
}

/* The folders: your pads in their folders, the docs and the books. */
.explorer {
  position: fixed;
  top: calc(var(--menubar) + 24px);
  left: 50%;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(640px, calc(100vw - 32px));
  height: min(560px, calc(100vh - var(--menubar) - 48px));
  transform: translateX(-50%);
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--ink);
  font: 13px var(--ui);
}
.explorer-search {
  margin: 10px 0 8px;
  padding: 7px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  outline: none;
}
.explorer-search:focus {
  border-color: var(--accent);
}
.explorer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule);
}
.explorer-crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.explorer-crumb {
  padding: 3px 7px;
  border: 1px dashed transparent;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.explorer-crumb:hover {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.explorer-sep {
  color: var(--muted);
}
.explorer-action {
  padding: 4px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}
.explorer-action:hover {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.explorer-list {
  flex: 1;
  margin: 6px 0 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}
.explorer-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto 26px;
  align-items: center;
  gap: 8px;
  padding: 6px 6px 6px 10px;
  border: 1px dashed transparent;
  border-radius: 6px;
  cursor: pointer;
}
.explorer-row:hover {
  background: color-mix(in srgb, var(--ink) 5%, transparent);
}
.explorer-row.current .explorer-name {
  font-weight: 650;
}
.explorer-row.over,
.explorer-crumb.over {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.explorer-row.shipped .explorer-name {
  color: var(--muted);
}
.explorer-row.target.current {
  cursor: default;
  opacity: 0.6;
}
.explorer-icon {
  font-size: 14px;
  text-align: center;
}
.explorer-label {
  display: flex;
  min-width: 0;
  align-items: baseline;
  gap: 8px;
}
.explorer-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.explorer-meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.explorer-row .switcher-snippet {
  grid-column: 2 / -1;
}
.explorer-menu {
  position: relative;
}
.explorer-menu .menu-items {
  right: 0;
  left: auto;
  z-index: 2;
  min-width: 160px;
}
.explorer-more {
  width: 26px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
}
.explorer-more:hover,
.explorer-menu.open .explorer-more {
  background: color-mix(in srgb, var(--ink) 10%, transparent);
  color: var(--ink);
}
.explorer-empty {
  padding: 16px 10px;
  color: var(--muted);
}
/* Who wrote one of the catalogue's books, and its licence, over its
   chapters. */
.explorer-about {
  padding: 4px 10px 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}
.explorer-about a {
  color: var(--accent);
}
.explorer-moving {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px 10px;
  font-weight: 600;
}
@media (pointer: coarse) {
  .switcher-action {
    opacity: 1;
  }
  .explorer-row {
    min-height: 40px;
  }
}
@media print {
  .explorer {
    display: none !important;
  }
}

/* Items a menu leaves out can leave two rules together, or one at an end. */
.ctx-menu .menu-rule:first-child,
.ctx-menu .menu-rule:last-child,
.ctx-menu .menu-rule + .menu-rule {
  display: none;
}

/* Sharing: the Share button in the bar, the badge that says how a pad is
   shared (private, shared with people, or by a public link), and the share
   dialog. */
.share-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 2px 0 14px;
  padding: 3px 10px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.share-button:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}
.share-icon {
  display: inline-flex;
  color: var(--muted);
}
.share-icon svg {
  display: block;
}
.share-badge {
  flex: none;
  padding: 0 6px;
  border-radius: 9px;
  font-size: 11px;
  white-space: nowrap;
}
.share-badge.private {
  background: color-mix(in srgb, var(--muted) 14%, transparent);
  color: color-mix(in srgb, var(--muted) 55%, var(--ink));
}
.share-badge.people {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent);
}
.share-badge.public {
  background: color-mix(in srgb, var(--good) 18%, transparent);
  color: var(--good);
}
.share-badge.elsewhere {
  background: color-mix(in srgb, var(--warn) 18%, transparent);
  color: var(--ink);
}
.switcher-meta .share-badge {
  margin-right: 8px;
}
.switcher-owner {
  margin-right: 8px;
}
.share-people {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}
.share-person {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.share-email {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-role,
.share-waiting {
  color: var(--muted);
  font-size: 12px;
}
.share-panel .share-link {
  flex: 1;
  min-width: 0;
}
.share-panel .account-note.error {
  color: var(--bad, #c53030);
}
