/* Layout and typography. Colours come from themes.css.
   Sized for an 820px portrait viewport: 19px body in a 700px column, with code, outputs
   and tables in that same column. 14px code fits about 80 characters there; longer lines
   scroll sideways inside their block. */

/* ---- Bundled fonts ----
   Apple devices have Charter, SF Mono and San Francisco, and the stacks below name those
   first, so there these files are never fetched. Android and most other systems have
   nothing comparable; they get Charis SIL (drawn from Charter), JetBrains Mono and Inter.
   Latin only: a character outside the range comes from a system font. Licences are beside
   the files in fonts/. */

@font-face {
  font-family: "Lectern Serif";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/charis-sil-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Lectern Serif";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/charis-sil-400-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Lectern Serif";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/charis-sil-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Lectern Serif";
  font-style: italic;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/charis-sil-700-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Lectern Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/jetbrains-mono-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Lectern Mono";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/jetbrains-mono-400-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Lectern Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/jetbrains-mono-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Lectern Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/inter-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Lectern Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/inter-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --font-body: Charter, "Iowan Old Style", "Lectern Serif", ui-serif, "Noto Serif", Georgia, serif;
  --font-code: ui-monospace, "SF Mono", Menlo, "Lectern Mono", "Roboto Mono", monospace;
  /* The two Apple names come first because `system-ui` exists everywhere and would
     otherwise always win; elsewhere the bundled sans is reached before it. */
  --font-ui: -apple-system, BlinkMacSystemFont, "Lectern Sans", system-ui, "Segoe UI", Roboto, sans-serif;
  --leading: 1.6;
  --code-size: 0.737rem;   /* 14px at the default size */
  --stream-size: 0.71rem;  /* 13.5px */
  --gutter: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  font-size: var(--size);
  background: var(--bg);
  color: var(--fg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: var(--font-body);
  line-height: var(--leading);
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums;
  text-rendering: optimizeLegibility;
}

a { color: var(--link); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.16em; }

/* ---- Top bar ---- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: calc(44px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--gutter) 0;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  font: 0.74rem/1.2 var(--font-ui);
  transition: transform 0.22s ease;
}
/* Set by reader.js while reading downwards. */
.bar-away .bar { transform: translateY(-101%); }
.bar a, .bar button { color: var(--fg); text-decoration: none; }
.bar-button {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.bar-button.back, .bar-button.forward:first-child { margin-left: -13px; }
/* Added by reader.js once there is a document to go forward to. */
.bar-button.back + .forward { margin-left: -10px; }
.bar-button:last-child { margin-right: -11px; }
.crumbs {
  display: flex;
  flex: 1;
  align-items: center;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}
.crumbs::-webkit-scrollbar { display: none; }
.crumbs a { flex: none; padding: 14px 2px; }
.crumbs a:last-child { color: var(--fg-strong); }
/* The file being read. It is the part that gives way when the bar is too narrow. */
.crumbs .here {
  flex: 0 1 auto;
  min-width: 4ch;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--fg-strong);
}
.crumbs .sep { padding: 0 0.45em; color: var(--fg-muted); }

.banner {
  margin: 0;
  padding: 0.6rem var(--gutter);
  background: var(--bg-alt);
  border-bottom: 1px solid var(--rule);
  font: 0.74rem/1.4 var(--font-ui);
  color: var(--fg-strong);
}

/* ---- Document ---- */

.doc {
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 1.6rem var(--gutter) calc(5rem + env(safe-area-inset-bottom));
  overflow-wrap: break-word;
}
/* Anything still wider than the column is cut at its edge. A page wider than the screen is
   shrunk to fit by Safari on the iPad, text and all. Not the whole column: the cell numbers
   sit in the margin. */
.cell.md, .out { overflow-x: clip; }
/* The clip is at the padding edge: this much of the margin stays open, for the markers
   that fold a section. */
.cell.md { margin-left: -2rem; padding-left: 2rem; }

/* Room for the bar when a link or the contents list jumps to a heading. */
.cell, h1, h2, h3, h4 { scroll-margin-top: 3.4rem; }
.cell { margin: 0; }
.cell.code { position: relative; margin: 1.3rem 0; }


p, ul, ol, dl, blockquote { margin-top: 0; margin-bottom: 0.9em; }
/* A fold written as raw HTML in a markdown cell. */
.cell.md details { margin-bottom: 0.9em; }
.cell.md details > summary { cursor: pointer; }
.cell.md details[open] > summary { margin-bottom: 0.5em; }
p { text-wrap: pretty; hanging-punctuation: first; }

h1, h2, h3, h4, h5, h6 {
  color: var(--fg-strong);
  font-weight: 700;
  line-height: 1.22;
  text-wrap: balance;
  font-variant-numeric: lining-nums;
  margin-bottom: 0.5em;
}
h1 { font-size: 1.9rem; letter-spacing: -0.012em; margin-top: 2.2em; }
h2 { font-size: 1.4rem; letter-spacing: -0.006em; margin-top: 2em; }
h3 { font-size: 1.15rem; margin-top: 1.7em; }
h4, h5, h6 { font-size: 1rem; margin-top: 1.5em; }
.doc > .cell:first-child > :first-child { margin-top: 0.2em; }
/* Headings keep their ids for linking; the pilcrow after each one is not shown. */
.anchor-link { display: none; }

/* Folding a section. reader.js puts the marker in each heading that has something under
   it: in the margin where the screen has one, otherwise before the heading's text. The
   clamp flips between the two at the width where 2.6rem of margin appears. It is kept out
   of selections: on an iPad, a long press on the heading's first word otherwise selected
   the last word of the paragraph before. */
.fold {
  position: relative;
  width: 1.2rem;
  height: 1.22em;
  margin: 0 0.3rem 0 clamp(-1.5rem, (2.6rem - (100vw - var(--measure)) / 2) * 9999, 0px);
  padding: 0;
  border: 0;
  background: none;
  color: var(--fg-muted);
  font-size: inherit;
  vertical-align: top;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
/* A target for a finger, larger than the marker, but not over the heading's text: a point
   there would land in the button, not in the first word. */
.fold::after { content: ""; position: absolute; inset: -9px 0 -9px -10px; }
.fold::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  margin: -0.3rem 0 0 -0.2rem;
  border: solid transparent;
  border-width: 0.3rem 0 0.3rem 0.45rem;
  border-left-color: currentColor;
}
.fold[aria-expanded="true"]::before { transform: rotate(90deg); }
@media screen {
  .folded-away { display: none; }
}

strong, b { color: var(--fg-strong); font-weight: 700; }
ul, ol { padding-left: 1.4em; }
li { margin: 0.25em 0; }
li > p { margin-bottom: 0.4em; }
li > ul, li > ol { margin-bottom: 0.2em; }
blockquote {
  padding: 0 0 0 1em;
  border-left: 3px solid var(--rule);
  font-style: italic;
}
hr { height: 0; margin: 2.2em auto; border: 0; border-top: 1px solid var(--rule); }
img { max-width: 100%; height: auto; }
sup, sub { line-height: 0; }

code, kbd, samp, pre { font-family: var(--font-code); font-variant-numeric: normal; }
:not(pre) > code {
  padding: 0.08em 0.3em;
  border-radius: 3px;
  background: var(--bg-alt);
  color: var(--accent);
  font-size: 0.82em;
  overflow-wrap: anywhere;
}
a > code { color: inherit; }
h1 code, h2 code, h3 code { font-size: 0.86em; }

/* ---- Code: cells, and fenced blocks in prose ---- */

.highlight, .cell.md pre:not(.highlight pre), .diagram > pre {
  background: var(--bg-alt);
  border-radius: 6px;
}
.highlight pre, .cell.md pre, .diagram > pre {
  margin: 0;
  padding: 0.75rem 0.85rem;
  overflow-x: auto;
  font-size: var(--code-size);
  line-height: 1.5;
  color: var(--code-fg);
  tab-size: 4;
  -webkit-overflow-scrolling: touch;
}
.cell.md > .highlight, .cell.md > pre { margin-top: 0; margin-bottom: 0.9rem; }

.src { position: relative; }
/* "Show" and "Hide" sit in the same corner, in the same type, whichever state the cell is in. */
.src > summary {
  display: flex;
  justify-content: flex-end;
  padding: 0.62rem 0.7rem;
  border-radius: 6px;
  list-style: none;
  cursor: pointer;
  font: 0.66rem/1 var(--font-ui);
  color: var(--fg-muted);
  -webkit-user-select: none;
  user-select: none;
}
.src > summary::-webkit-details-marker { display: none; }
.src > summary .label { margin-right: auto; color: var(--fg); }
.src:not([open]) > summary { background: var(--bg-alt); }
.src:not([open]) > summary::after { content: "Show"; }
.src[open] > summary {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1;
  /* Opaque, so a long first line passes under it instead of through it. */
  border-radius: 0 6px 0 6px;
  background: var(--bg-alt);
}
.src[open] > summary .label { display: none; }
.src[open] > summary::after { content: "Hide"; }

/* The cell's number, to find it again in the notebook: in the margin where the screen has
   one, otherwise beside Show/Hide. The clamp flips between the two positions at the width
   where 3rem of margin appears beside the column. */
.cell-n {
  position: absolute;
  top: 0.62rem;
  left: clamp(-2.9rem, (3rem - (100vw - var(--measure)) / 2) * 9999, 100% - 6.3rem);
  z-index: 2;
  width: 2.5rem;
  text-align: right;
  /* Not below 10.5px: at small text sizes the brackets blur, most of all on Android. */
  font: max(0.6rem, 10.5px) / 1.1 var(--font-ui);
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--fg-muted);
  pointer-events: none;
}

/* ---- Outputs ---- */

.out {
  margin: 0.7rem 0 0 2px;
  padding-left: 0.75rem;
  border-left: 2px solid var(--rule);
}
.out > * + * { margin-top: 0.7rem; }

.stream, .error {
  margin: 0;
  font-size: var(--stream-size);
  line-height: 1.5;
  color: var(--fg);
  tab-size: 4;
}
/* Printed output is mostly sentences, so it wraps instead of scrolling sideways. */
.stream.wrap, .error { white-space: pre-wrap; overflow-wrap: anywhere; }
/* One per printed line: wrapped continuations hang, so they are not taken for new lines. */
.stream .l { display: block; padding-left: 2ch; text-indent: -2ch; }
.stream.stderr { padding-left: 0.6rem; border-left: 2px solid var(--accent); }
/* Both set by reader.js: a long block starts with its first 30 lines, and "No wrap" trades
   wrapping for scrolling sideways. */
.stream.clamped .l:nth-child(n + 31) { display: none; }
.stream:not(.wrap) { white-space: pre; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.stream:not(.wrap) .l { padding-left: 0; text-indent: 0; }
.out > .stream-tools { display: flex; gap: 1.1rem; margin-top: 0.3rem; }
.stream-tools button {
  padding: 0.35rem 0;
  border: 0;
  background: none;
  font: 0.66rem/1 var(--font-ui);
  color: var(--link);
  cursor: pointer;
}
.error { padding-left: 0.6rem; border-left: 2px solid var(--err); }

figure.img { margin: 0; }
figure.img img { display: block; }

/* A diagram's source, shown as code until reader.js draws it; and still, if it could not.
   A drawing too wide for the column is given room as a table is, then made smaller, and
   only then scrolls. */
figure.diagram { margin: 1.2rem 0 1.4rem; }
figure.diagram.drawn { overflow-x: auto; -webkit-overflow-scrolling: touch; }
figure.diagram.drawn > pre { display: none; }
figure.diagram > svg { display: block; height: auto; margin: 0 auto; }

/* TeX source, until reader.js typesets it; and still, if it could not. */
.math { font-family: var(--font-code); font-size: 0.82em; }
.math.display { display: block; margin: 0.9em 0; overflow-x: auto; white-space: pre-wrap; }
.math.typeset { font: inherit; white-space: normal; }
/* Wide math can still be dragged sideways; the bar that Android draws under any formula
   a pixel wider than the column is not shown. */
.math.display.typeset { overflow-y: hidden; scrollbar-width: none; }
.math.display.typeset::-webkit-scrollbar { display: none; }
.math .katex { font-size: 1.1em; }
.math .katex-display { margin: 0; }

.placeholder {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border: 1px dashed var(--fg-muted);
  border-radius: 6px;
  font: 0.74rem/1.5 var(--font-ui);
}

.traceback > summary {
  padding: 0.5rem 0 0.5rem 0.6rem;
  border-left: 2px solid var(--err);
  cursor: pointer;
  font-family: var(--font-code);
  font-size: var(--stream-size);
  overflow-wrap: anywhere;
}
.traceback > summary .label { font-family: var(--font-ui); color: var(--fg-muted); }
.traceback[open] > summary { margin-bottom: 0.4rem; }
.error strong { color: var(--err); }

/* ---- Tables ---- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.cell.md > .table-wrap { margin-top: 0; margin-bottom: 0.9em; }

table {
  border-collapse: collapse;
  font: 0.74rem/1.4 var(--font-ui);
  font-variant-numeric: tabular-nums lining-nums;
}
th, td {
  padding: 0.4em 0.75em;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}
th:first-child, td:first-child { padding-left: 0; }
thead th {
  border-bottom: 1px solid var(--fg-muted);
  color: var(--fg-strong);
  font-weight: 600;
  vertical-align: bottom;
}
/* The index column of a DataFrame. */
tbody th { color: var(--fg-muted); font-weight: 400; }
td.num { text-align: right; white-space: nowrap; }
/* Text wraps, and the browser shares the column out by how much each column holds, so the
   rows come out of a similar height. That would leave a column of short entries ("Fig. 1,
   p. 3") its longest word beside one of sentences, so a short entry stays on one line and a
   longer one keeps a few words to a line; when those cells cannot all fit, the table scrolls
   sideways in its wrapper. */
th.short, td.short { white-space: nowrap; }
th.wide, td.wide { min-width: 8em; }
.cell.md table { font-size: 0.8rem; }
/* A table that cannot fit even so is given room in the margins by reader.js, which keeps
   it on the screen; the cell around it must not cut it at the column's edge. A diagram too. */
.cell.md:has(.table-wrap.spread, .diagram.spread),
.out:has(.table-wrap.spread, .diagram.spread) { overflow-x: visible; }

/* ---- Listings and error pages ---- */

.listing {
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 1.6rem var(--gutter) calc(5rem + env(safe-area-inset-bottom));
}
.listing h1 { margin-top: 0.2em; margin-bottom: 0.9em; }
.group { margin-top: 2.2rem; }
.group > h2 {
  margin: 0 0 0.6rem;
  font: 600 0.68rem/1.3 var(--font-ui);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.group > h2 a { color: inherit; text-decoration: none; }

.card { padding: 0.95rem 0; border-top: 1px solid var(--rule); }
.card-link { display: block; color: inherit; text-decoration: none; }
.card-link > span { display: block; }
.card-title {
  color: var(--fg-strong);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.25;
  text-wrap: balance;
}
.card-summary {
  margin-top: 0.3rem;
  font-size: 0.86rem;
  line-height: 1.5;
  display: -webkit-box !important;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}
.meta { font: 0.68rem/1.4 var(--font-ui); color: var(--fg-muted); }
.card .meta { margin: 0.45rem 0 0; }
.meta a { color: inherit; }
.lede { max-width: 36rem; margin: -0.4rem 0 0; font-size: 1.05rem; }

.rows { margin: 0; padding: 0; list-style: none; }
.rows li { margin: 0; border-top: 1px solid var(--rule); }
.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  min-height: 44px;
  padding: 0.6rem 0;
  color: inherit;
  text-decoration: none;
}
.row-title { min-width: 0; color: var(--fg-strong); font-size: 0.92rem; line-height: 1.3; overflow-wrap: anywhere; }
.row .meta { flex: none; max-width: 55%; text-align: right; overflow-wrap: anywhere; }
.empty { color: var(--fg); }
.listing .error { margin-top: 1rem; }

/* The way out of an error page. */
.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1.6rem; }
.action {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 1.2rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--bg-alt);
  color: var(--fg-strong);
  font: 600 0.8rem/1 var(--font-ui);
  text-decoration: none;
}

/* A listing's two views: the overview of what there is to read, and the folder as files.
   Which one shows is set on <html> by boot.js; without it the overview shows. */
.listing-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 1rem; }
.listing-head h1 { min-width: 0; overflow-wrap: anywhere; }
.view-switch { flex: none; }
.view-switch button { min-width: 5.5rem; padding: 0 0.8rem; }
.files-view { display: none; margin-top: 1rem; }
[data-listing="files"] .files-view { display: block; }
[data-listing="files"] .overview { display: none; }
.files-view .row-title { display: flex; align-items: center; gap: 0.5rem; }
.files-view .row-title svg { flex: none; color: var(--fg-muted); }

/* ---- Sheets: contents and settings ---- */

/* Shown with show(), not showModal() (see reader.js), so it is placed and scrolled here
   and the shade under it stands in for the backdrop. */
dialog.sheet {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 21;
  overflow-y: auto;
  overscroll-behavior: contain;
  width: min(21rem, 88vw);
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0 0 0 auto;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--rule);
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
}
.sheet-shade { position: fixed; inset: 0; z-index: 20; background: var(--shade); }
/* Takes the focus when the sheet opens, so no button starts out ringed. */
.sheet-panel:focus { outline: none; }
.sheet-panel {
  min-height: 100%;
  padding: calc(env(safe-area-inset-top) + 0.4rem) max(1.1rem, env(safe-area-inset-right))
    calc(env(safe-area-inset-bottom) + 1.5rem) 1.1rem;
}
.sheet-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  background: var(--bg);
}
.sheet-head h2 {
  margin: 0;
  font: 600 0.68rem/1.3 var(--font-ui);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.sheet-head button {
  min-height: 44px;
  padding: 0 0 0 1rem;
  border: 0;
  background: none;
  font: 600 0.8rem/1 var(--font-ui);
  color: var(--link);
  cursor: pointer;
}
.sheet-note { margin: 1.6rem 0 0; font-size: 0.68rem; color: var(--fg-muted); }
.sheet-note.version { margin-top: 0.4rem; }
.reopenings { margin-top: 0.6rem; font-size: 0.68rem; color: var(--fg-muted); }
.reopenings summary { cursor: pointer; }
.reopenings .kept-at { margin: 0.4rem 0 0; overflow-wrap: anywhere; }
.reopenings ol { margin: 0.4rem 0 0; padding-left: 1.2rem; }
.reopenings li { margin-bottom: 0.5rem; white-space: pre-line; overflow-wrap: anywhere; }

.toc { display: flex; flex-direction: column; margin-top: 0.4rem; }
.toc a {
  padding: 0.5rem 0 0.5rem 0.7rem;
  border-left: 2px solid transparent;
  color: var(--fg);
  font-size: 0.8rem;
  line-height: 1.3;
  text-decoration: none;
}
.toc .toc-1 { color: var(--fg-strong); font-weight: 600; }
.toc .toc-2 { padding-left: 0.7rem; }
.toc .toc-3 { padding-left: 1.7rem; font-size: 0.74rem; }
.toc a[aria-current] { border-left-color: var(--accent); color: var(--fg-strong); }
/* A folded section, marked as its heading is on the page. */
.toc a[data-folded]::after {
  content: "";
  display: inline-block;
  margin-left: 0.5em;
  border: solid transparent;
  border-width: 0.26em 0 0.26em 0.4em;
  border-left-color: var(--fg-muted);
}
.sheet [data-folds] { margin-top: 0.5rem; }

.setting { margin-top: 1.3rem; }
.setting h3 { margin: 0 0 0.5rem; font: 400 0.74rem/1.3 var(--font-ui); color: var(--fg); letter-spacing: 0; }
.choice, .stepper {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 8px;
}
.choice + .choice { margin-top: 0.5rem; }
.choice button, .stepper button, .stepper output {
  flex: 1;
  min-height: 44px;
  padding: 0 0.3rem;
  border: 0;
  background: none;
  color: var(--fg);
  font: 0.76rem/1.2 var(--font-ui);
}
.choice button, .stepper button { cursor: pointer; }
.choice button + button, .stepper > * + * { border-left: 1px solid var(--rule); }
.choice button[aria-pressed="true"] { background: var(--bg-alt); color: var(--fg-strong); font-weight: 600; }
.stepper button { flex: 0 0 30%; font-size: 1.1rem; }
.stepper button:disabled { color: var(--fg-muted); cursor: default; }
.stepper output { display: grid; place-items: center; color: var(--fg-strong); font-variant-numeric: tabular-nums; }

/* ---- Finding words ---- */
/* Put in the bar by reader.js, in place of what is there, in a Home Screen app. */

.bar[data-finding] > :not(.find) { display: none; }
/* Fixed, not sticky: it must not move with the page for a moment each time the page is
   taken to the next match. A little taller than the bar it stands in for. */
.bar[data-finding] {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  min-height: calc(54px + env(safe-area-inset-top));
  border-bottom-color: var(--fg-muted);
  transition: none;
}
.find {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 2px;
  min-width: 0;
}
.find input {
  flex: 1;
  min-width: 0;
  height: 38px;
  margin: 0;
  padding: 0 10px;
  border: 1px solid var(--fg-muted);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg-strong);
  /* Not under 16px: Safari on a phone or tablet zooms the page in on a field with small text. */
  font: 16px/1.2 var(--font-ui);
  appearance: none;
}
.find input:focus { border-color: var(--link); outline: none; }
.find output {
  flex: none;
  padding: 0 4px 0 10px;
  color: var(--fg);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.find .bar-button:disabled { color: var(--fg-muted); cursor: default; }
.find [data-done] {
  flex: none;
  min-height: 44px;
  padding: 0 0 0 0.6rem;
  border: 0;
  background: none;
  font: 600 0.8rem/1 var(--font-ui);
  color: var(--link);
  cursor: pointer;
}

/* ---- Notes and highlights ---- */
/* Painted over the text by the script, which leaves the page's elements as they are. Only
   inside the document: WebKit also paints the first words of an open dialog as marked. */

.doc ::highlight(lectern-mark) { background-color: var(--mark); }
.doc ::highlight(lectern-note) {
  background-color: var(--mark);
  text-decoration: underline 2px var(--mark-line);
}
/* Black only: a tint would dither, so a mark is a heavy line under the text, heavier than
   a link's, and one with a note has two. */
[data-theme="eink"] .doc ::highlight(lectern-mark) { text-decoration: underline 3px var(--mark-line); }
[data-theme="eink"] .doc ::highlight(lectern-note) { text-decoration: underline double 3px var(--mark-line); }
/* Someone else's marks: the same, in a colour of their own; on black-only e-ink, dotted. */
.doc ::highlight(lectern-mark-other) { background-color: var(--mark-other); }
.doc ::highlight(lectern-note-other) {
  background-color: var(--mark-other);
  text-decoration: underline 2px var(--mark-other-line);
}
[data-theme="eink"] .doc ::highlight(lectern-mark-other) { text-decoration: underline dotted 3px var(--mark-other-line); }
[data-theme="eink"] .doc ::highlight(lectern-note-other) { text-decoration: underline dotted 3px var(--mark-other-line); }
/* What was looked for with the find field, and the one of them the page has gone to. */
.doc ::highlight(lectern-find) { background-color: var(--find); }
.doc ::highlight(lectern-find-current) { background-color: var(--find-current); }
/* Black only: a broken line under each, and the one gone to in white on black. */
[data-theme="eink"] .doc ::highlight(lectern-find) { text-decoration: underline dashed 2px var(--mark-line); }
[data-theme="eink"] .doc ::highlight(lectern-find-current) { background-color: var(--fg); color: var(--bg); }
/* Set for a moment on the block a mark was taken from, or on an SVG picture, to have it
   painted again. */
[data-repaint] { outline: 1px solid transparent; }

/* What can be done with a mark that was tapped, beside it on the page. */
.mark-pop {
  position: absolute;
  z-index: 8;
  width: max-content;
  max-width: min(22rem, calc(100vw - 16px));
  padding: 0.2rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--bg);
  box-shadow: 0 4px 18px var(--shade);
  color: var(--fg);
  font: 0.8rem/1.4 var(--font-ui);
  -webkit-user-select: none;
  user-select: none;
}
.mark-pop[hidden] { display: none; }
.mark-pop p {
  margin: 0.4rem 0.6rem 0.5rem;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  color: var(--fg-strong);
}
.mark-actions { display: flex; }
.mark-pop button, .note-actions button, .noted button {
  min-height: 40px;
  padding: 0 0.9rem;
  border: 0;
  background: none;
  color: var(--link);
  font: 600 0.8rem/1 var(--font-ui);
  white-space: nowrap;
  cursor: pointer;
}
.mark-actions button + button { border-left: 1px solid var(--rule); }
.mark-pen[hidden], .mark-list[hidden] { display: none; }
.mark-pen[aria-pressed="true"] { border-radius: 8px; background: var(--bg-alt); color: var(--accent); }
/* Something marked here has not reached the Mac yet. */
.mark-pen { position: relative; }
.mark-pen[data-unsaved]::after {
  content: "";
  position: absolute;
  top: 9px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--err);
}

/* The list of what is marked. */
.notes { margin-top: 0.4rem; }
.notes h3 { margin: 1.4rem 0 0.2rem; font: 400 0.74rem/1.3 var(--font-ui); color: var(--fg-muted); letter-spacing: 0; }
.noted {
  display: block;
  padding: 0.6rem 0 0.6rem 0.7rem;
  border-left: 2px solid var(--mark-line);
  color: var(--fg);
  font-size: 0.78rem;
  line-height: 1.4;
  text-decoration: none;
}
.noted + .noted { margin-top: 0.5rem; }
.noted q { display: block; quotes: none; }
.noted span { display: block; margin-top: 0.3rem; color: var(--fg-strong); white-space: pre-wrap; overflow-wrap: anywhere; }
.noted button { min-height: 32px; margin-top: 0.2rem; padding: 0; }
.noted-other { border-left-color: var(--mark-other-line); }
.noted-who { display: block; margin-top: 0.3rem; font: 400 0.74rem/1.3 var(--font-ui); color: var(--fg-muted); }
.notes-filter { margin: 0.2rem 0 0.9rem; }
.mark-pop .mark-who { margin: 0 0 0.3rem; font: 600 0.74rem/1.3 var(--font-ui); color: var(--fg-muted); }
/* The name written on notes, in the reading settings. */
.name-field {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: 0 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg-strong);
  font: 400 1rem/1.3 var(--font-ui);
}
.name-field:focus { border-color: var(--link); outline: none; }

dialog.note-editor {
  width: min(30rem, calc(100vw - 24px));
  margin: calc(env(safe-area-inset-top) + 4rem) auto auto;
  padding: 1rem 1rem 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
}
dialog.note-editor::backdrop { background: var(--shade); }
.note-editor blockquote {
  max-height: 4.4em;
  margin: 0 0 0.7rem;
  padding-left: 0.7rem;
  overflow: hidden;
  border-left: 2px solid var(--mark-line);
  font-size: 0.78rem;
  line-height: 1.45;
}
/* 16px and no less: below it, an iPhone or iPad zooms the page in on the field. */
.note-editor textarea {
  display: block;
  width: 100%;
  min-height: 7rem;
  padding: 0.6rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg-strong);
  font: 16px/1.45 var(--font-ui);
  resize: vertical;
}
.note-actions { display: flex; justify-content: flex-end; margin-top: 0.3rem; }

/* ---- "Lectern is not running", and the start page while it finds out ---- */

.offline {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem var(--gutter);
  background: var(--bg);
  text-align: center;
}
.offline[hidden] { display: none; }
.offline-icon { width: 72px; height: 72px; margin-bottom: 0.8rem; border-radius: 16px; }
.offline h1 { margin: 0 0 1.2rem; font-size: 1.9rem; }
.offline-msg { max-width: 24rem; font-size: 0.9rem; }
.offline-msg p { margin-bottom: 0.6em; }
.offline-msg button {
  min-height: 44px;
  margin-top: 0.6rem;
  padding: 0 1.4rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--bg-alt);
  color: var(--fg-strong);
  font: 600 0.8rem/1 var(--font-ui);
  cursor: pointer;
}
.offline-msg button:disabled { color: var(--fg-muted); }
[data-theme^="eink"] .offline-icon { border: 1px solid var(--rule); }

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

/* ---- Turning pages: the footer of the e-ink theme ---- */

.pager { display: none; }

/* ---- E-ink ----
   Nothing moves, nothing is grey, nothing scrolls sideways if it can wrap instead. */

[data-theme^="eink"] *,
[data-theme^="eink"] *::before,
[data-theme^="eink"] *::after {
  transition: none !important;
  animation: none !important;
  scroll-behavior: auto !important;
  box-shadow: none !important;
  text-shadow: none !important;
}
[data-theme^="eink"] body { font-weight: 500; }
[data-theme^="eink"] .bar { border-bottom: 1px solid var(--edge); }
/* Put away, and brought back, by a tap on the page number in the footer. */
[data-theme^="eink"][data-no-bar] .bar { display: none; }
[data-theme^="eink"] .highlight,
[data-theme^="eink"] .cell.md pre:not(.highlight pre),
[data-theme^="eink"] .src:not([open]) > summary,
[data-theme^="eink"] :not(pre) > code { border: 1px solid var(--rule); }
[data-theme^="eink"] :not(pre) > code { padding: 0 0.25em; }
/* The corner control sits over the block's border, so it carries the border on. */
[data-theme^="eink"] .src[open] > summary { border: 1px solid var(--rule); }
/* Panning a code block is a string of repaints; a wrapped line is one. */
[data-theme^="eink"] .highlight pre,
[data-theme^="eink"] .cell.md pre { white-space: pre-wrap; overflow-wrap: anywhere; font-weight: 500; }
[data-theme^="eink"] .stream,
[data-theme^="eink"] .error { font-weight: 500; }
[data-theme^="eink"] .out,
[data-theme^="eink"] .stream.stderr,
[data-theme^="eink"] .error { border-left-width: 3px; }
[data-theme^="eink"] .error { border-left-style: double; border-left-width: 6px; }
[data-theme^="eink"] blockquote { border-left-color: var(--rule); }
[data-theme^="eink"] dialog.sheet { border-left: 2px solid var(--rule); }
[data-theme^="eink"] .choice,
[data-theme^="eink"] .stepper { border-width: 1px; }
[data-theme^="eink"] .choice button[aria-pressed="true"] { background: #000; color: #fff; }
[data-theme^="eink"] .mark-pop, [data-theme^="eink"] dialog.note-editor { border: 2px solid var(--rule); box-shadow: none; }
[data-theme^="eink"] .mark-pen[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
[data-theme^="eink"] .toc a[aria-current] { border-left-width: 4px; }
/* With no grey to dim a button that does nothing here, its label is left out. */
[data-theme^="eink"] .stepper button:disabled,
[data-theme^="eink"] .pager button:disabled { color: transparent; }
/* Android draws a scrollbar as a grey strip that stays on an e-ink screen. What scrolls
   sideways still does. */
[data-theme^="eink"] .stream,
[data-theme^="eink"] .table-wrap,
[data-theme^="eink"] .diagram,
[data-theme^="eink"] .highlight pre { scrollbar-width: none; }
[data-theme^="eink"] .stream::-webkit-scrollbar,
[data-theme^="eink"] .table-wrap::-webkit-scrollbar,
[data-theme^="eink"] .diagram::-webkit-scrollbar,
[data-theme^="eink"] .highlight pre::-webkit-scrollbar { display: none; }

[data-theme^="eink"] .pager {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  align-items: stretch;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--edge);
  background: var(--bg);
  font: 600 0.76rem/1 var(--font-ui);
}
.pager button, .pager output {
  flex: 1;
  min-height: 48px;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
}
.pager output { display: grid; place-items: center; font-variant-numeric: tabular-nums lining-nums; }
.pager > * + * { border-left: 1px solid var(--edge-faint); }
.pager [data-turn="start"], .pager [data-turn="end"] { flex: 0 0 13%; }
.pager output { cursor: pointer; }
/* Over the line the footer would cut through; reader.js sets how tall after each turn. */
.page-trim { display: none; }
[data-theme^="eink"] .page-trim {
  position: fixed;
  right: 0;
  left: 0;
  z-index: 9;
  display: block;
  background: var(--bg);
  pointer-events: none;
}
[data-theme^="eink"] .doc,
[data-theme^="eink"] .listing { padding-bottom: calc(5rem + 48px + env(safe-area-inset-bottom)); }

@media (max-width: 480px) {
  h1 { font-size: 1.6rem; }
  h2 { font-size: 1.25rem; }
  .row { flex-direction: column; gap: 0.1rem; }
  .row .meta { max-width: none; text-align: left; }
}

@media print {
  .bar { display: none; }
  .src > summary { display: none; }
  .fold { display: none; }
  .mark-pop { display: none; }
}
