@font-face {
  font-family: "EB Garamond";
  src: url("assets/EBGaramond-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("assets/EBGaramond-Italic.woff2") format("woff2");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("assets/EBGaramond-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "EB Garamond";
  src: url("assets/EBGaramond-BoldItalic.woff2") format("woff2");
  font-weight: 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("assets/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  /* --bg is the sheet; --desk is the surface it rests on. Button and
     link hovers read --bg as "the paper tone", so it keeps that role. */
  --bg: #faf5e7;
  /* The contents pane's width, shared by the pane itself, the docked
     body inset and the breakout caps so the three cannot disagree. */
  --contents-width: 20rem;
  /* How much of the viewport the pane owns: 0 as an overlay, the pane
     width while docked. Wide pre/table breakouts subtract it. */
  --contents-inset: 0px;
  --desk: #ded0b6;
  --fg: #3a2f24;
  --accent: #7a3b1f;
  --code-bg: #efe5cc;
  --rule: #a8927a;
  --muted: #6b5b48;
  --sheet-shadow: rgba(58, 47, 36, 0.16);
  --plate-shadow: rgba(58, 47, 36, 0.20);
  --sheet-tint: rgba(120, 96, 60, 0.055);
  --sheet-sheen: rgba(255, 255, 255, 0.38);
  /* A box of coloured pencils for the pie charts: soft, a little worn. */
  --pencil-1: #c58470;
  --pencil-2: #7f9bb5;
  --pencil-3: #cfb470;
  --pencil-4: #8aa476;
  --pencil-5: #a584a0;
  --pencil-6: #78a5a0;
  --pencil-7: #b9937a;
  --pencil-8: #959cb3;
  /* Highlighter: the ink, where it pools along the nib's edges and
     where it pauses at each end, and the felt's streaks. The streaks
     are noise stretched along the stroke and thresholded into alpha:
     a regular stripe reads as scanlines, felt never repeats. */
  --highlighter-ink: #ffe94a;
  --highlighter-pool: rgba(232, 178, 0, 0.32);
  --highlighter-felt: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='40'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.006 0.45' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0.9 0 0 0 -0.3'/%3E%3C/filter%3E%3Crect width='400' height='40' filter='url(%23f)'/%3E%3C/svg%3E");
  /* Fibre. The feColorMatrix forces the noise to a fixed warm brown and
     puts the turbulence into the alpha channel instead: greyscale noise
     textures the sheet but desaturates the cream toward grey, and
     blending it soft-light to protect the hue erases the texture. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.40 0 0 0 0 0.31 0 0 0 0 0.19 0.28 0.28 0.28 0 0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23g)' opacity='0.55'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #221e19;
    --desk: #131110;
    --fg: #e5dac5;
    --accent: #d6a679;
    --code-bg: #322d25;
    --rule: #5a4f40;
    --muted: #9d8c75;
    --sheet-shadow: rgba(0, 0, 0, 0.5);
    --plate-shadow: rgba(0, 0, 0, 0.55);
    --sheet-tint: rgba(0, 0, 0, 0.16);
    --pencil-1: #d9a08a;
    --pencil-2: #9db8d0;
    --pencil-3: #e0c88a;
    --pencil-4: #a8c093;
    --pencil-5: #c0a0bc;
    --pencil-6: #95c0bb;
    --pencil-7: #d0ae94;
    --pencil-8: #b3bacf;
    --sheet-sheen: rgba(255, 245, 225, 0.045);
    /* Screen-blended on the dark sheet, so the ink is a dim gold that
       lightens toward yellow, and the felt's streaks darken instead. */
    --highlighter-ink: #7a6410;
    --highlighter-pool: rgba(150, 118, 8, 0.35);
    --highlighter-felt: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='40'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.006 0.45' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0 0 0 -0.18'/%3E%3C/filter%3E%3Crect width='400' height='40' filter='url(%23f)'/%3E%3C/svg%3E");
    /* Same trick inverted: on a dark sheet the fibre has to be lighter
       than the stock to register, so the matrix holds a pale warm tone
       and the opacity comes down hard — light speckle on a dark ground
       reads far stronger than the reverse. */
    --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='matrix' values='0 0 0 0 0.88 0 0 0 0 0.84 0 0 0 0 0.74 0.28 0.28 0.28 0 0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23g)' opacity='0.16'/%3E%3C/svg%3E");
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--desk);
  color: var(--fg);
  font-family: "EB Garamond", Georgia, serif;
  font-size: 19px;
  line-height: 1.6;
}

.screen { display: block; }
.screen[hidden] { display: none; }
/* ID-level specificity so [hidden] beats the #welcome/#reader display rules */
#welcome[hidden],
#reader[hidden] { display: none; }

/* ---------- Welcome ---------- */
#welcome {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 2rem;
  text-align: center;
}

.welcome-logo {
  width: 200px;
  height: auto;
  /* The logo is a self-contained cream card; a soft shadow lifts it
     off both the sepia (light) and warm-black (dark) backgrounds. */
  filter: drop-shadow(0 4px 14px rgba(31, 29, 26, 0.28));
}

.masthead {
  font-variant-caps: small-caps;
  letter-spacing: 0.04em;
  font-weight: 700;
  font-size: 2.5rem;
  margin: 0;
  /* Tighten the gap to the logo above it */
  margin-top: -0.25rem;
}

.welcome-error {
  color: var(--accent);
  font-style: italic;
  max-width: 40rem;
  word-break: break-all;
}

.open-button {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.6em 1.4em;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.open-button:hover { background: var(--code-bg); }

/* ---------- Recents ---------- */
/* A modest list beneath the open button. The welcome is centred via
   flex; the recents block keeps the same axis but limits its width so
   long paths don't span the viewport. */
.recents {
  width: min(32rem, 100%);
  margin-top: 0.5rem;
}
.recents-heading {
  font-variant-caps: small-caps;
  letter-spacing: 0.04em;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--rule);
  margin: 0 0 0.5rem 0;
  text-align: center;
}
.recents-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.recent-item {
  text-align: center;
}
.recent-link {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.35em 0.75em;
  background: transparent;
  color: var(--fg);
  border: none;
  border-radius: 3px;
  cursor: pointer;
  max-width: 100%;
  /* Long names get clipped with an ellipsis rather than wrapping; the
     full path is in the title attribute for hover. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s ease;
}
.recent-link:hover,
.recent-link:focus-visible {
  background: var(--code-bg);
  outline: none;
}

/* ---------- Reload toast ---------- */
/* Appears in the top-right of the reader when the document has reloaded
   itself after changing on disk (reload-toast.js). Ages while the window
   is unfocused; lingers then fades once the user is looking. */
.reload-toast {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  padding: 0.35em 0.8em;
  background: var(--code-bg);
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-family: "EB Garamond", Georgia, serif;
  font-size: 0.95rem;
  font-style: italic;
  box-shadow: 0 2px 8px rgba(31, 29, 26, 0.18);
  pointer-events: none;
  user-select: none;
}
.reload-toast.appearing {
  animation: reload-fade-in 0.25s ease both;
}
@keyframes reload-fade-in {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}
/* Fade-out is an animation rather than a transition: the pulse above is
   proof animations run in this webview, and a transition triggered by a
   class swap inside a timer callback was observed not to. */
.reload-toast.fading {
  animation: reload-fade-out 0.8s ease both;
}
@keyframes reload-fade-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}
.reload-toast.error {
  color: var(--accent);
  border-color: var(--accent);
}
.reload-toast[hidden] { display: none; }

/* ---------- Contents button (hamburger, top-left) ---------- */
/* Circular icon button, top-left, sharing the reload toast's fade-in.
   Hidden on the welcome screen and toggled by main.js. */
.contents-button {
  position: fixed;
  top: 1rem;
  left: 1rem;
  /* Above the sidebar (z-index 20) so the close-X stays clickable
     when the sidebar is open. */
  z-index: 30;
  width: 2.4rem;
  height: 2.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--code-bg);
  color: var(--accent);
  border: 1px solid var(--rule);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(31, 29, 26, 0.18);
  transition: background 0.15s ease, transform 0.15s ease;
}
.contents-button:hover {
  background: var(--bg);
  transform: scale(1.05);
}
.contents-button:active {
  transform: scale(0.95);
}
.contents-button[hidden] { display: none; }

/* Icon swap driven by aria-expanded. The button's aria-expanded is the
   single source of truth for sidebar state; CSS reads it directly so
   the icons stay in sync without extra JS gymnastics. */
.contents-button .icon-close { display: none; }
.contents-button[aria-expanded="true"] .icon-open { display: none; }
.contents-button[aria-expanded="true"] .icon-close { display: inline; }

/* ---------- Contents sidebar ---------- */
/* Overlay panel sliding in from the left edge. The reading column
   underneath does not shift — by design, since the prose is centred
   on the viewport and reflowing it would compromise the typography.
   Docked (body.contents-docked, below) is the exception: the column
   is re-centred once in the space beside the pane and stays put.
   Above the sticky chrome (z-index 20) so the hamburger stays
   tappable; the sidebar pulls focus when it's open. */
.contents-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: min(var(--contents-width), 80vw);
  height: 100vh;
  z-index: 20;
  background: var(--code-bg);
  border-right: 1px solid var(--rule);
  box-shadow: 2px 0 12px rgba(31, 29, 26, 0.18);
  /* Reserve space at the top so the list doesn't collide with the
     hamburger button when the sidebar is open. */
  padding: 4rem 1.25rem 2rem;
  overflow-y: auto;
  /* Wheeling past the end of the list must not carry on into the sheet. */
  overscroll-behavior: contain;
  /* No transition on the [hidden] toggle itself — display:none can't
     animate. We use [hidden] for the reveal, same as the rest of the
     app, and rely on the overlay nature for the visual handoff. */
}
.contents-sidebar[hidden] { display: none; }

/* Foot of the pane: the share pill. Sticky, so it stays at the bottom
   edge under a long list and (via margin-top:auto in the pane's column)
   drops to it under a short one. The negative margin spends the pane's
   bottom padding, so the strip reaches the edge. */
.contents-sidebar {
  display: flex;
  flex-direction: column;
}
.contents-sidebar > * { flex-shrink: 0; }
.contents-footer {
  position: sticky;
  /* Sticky insets measure from the pane's content edge, so reach down
     through its bottom padding as the margin does. */
  bottom: -2rem;
  margin: auto -1.25rem -2rem;
  padding: 1.25rem 1.25rem 0.9rem;
  /* The list fades out behind the strip rather than being cut by it. */
  background: linear-gradient(to bottom, transparent, var(--code-bg) 1rem);
  pointer-events: none;
}
/* Quiet by design: smaller and paler than the contents, no fill. It
   comes forward only under the pointer or keyboard focus. */
.share-link {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  max-width: 100%;
  padding: 0.2rem 0.65rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-family: "EB Garamond", Georgia, serif;
  font-size: 0.78rem;
  line-height: 1.4;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.share-link svg { flex: none; }
.share-link-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-link:hover,
.share-link:focus-visible,
.share-link[data-state] {
  opacity: 1;
  outline: none;
}
.share-link:hover,
.share-link:focus-visible {
  color: var(--fg);
}
.share-link[data-state="copied"] { color: var(--accent); border-color: var(--accent); }
.share-link[data-state="failed"] { color: var(--fg); }

/* Docked: the pane owns the left strip and the sheet is centred in
   what remains. Body padding does the centring — #reader's margin:auto
   already centres within its container — and the shadow goes, since
   the pane no longer floats over anything. */
body.contents-docked {
  --contents-inset: var(--contents-width);
  padding-left: var(--contents-width);
}
body.contents-docked .contents-sidebar {
  width: var(--contents-width);
  box-shadow: none;
}

.contents-sidebar-heading {
  font-variant-caps: small-caps;
  letter-spacing: 0.04em;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--rule);
  margin: 0 0 0.75rem 0;
}

.contents-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-family: "EB Garamond", Georgia, serif;
  font-size: 0.95rem;
  line-height: 1.4;
}
.contents-list .contents-item {
  margin: 0.15rem 0;
}
/* Indent by heading level. H1 sits flush; H2 indents one notch; H3
   indents two. Padding is on the link so the entire row is hit-target
   width. */
.contents-list .level-1 > .contents-link { padding-left: 0; }
.contents-list .level-2 > .contents-link { padding-left: 1rem; }
.contents-list .level-3 > .contents-link { padding-left: 2rem; }

.contents-link {
  display: block;
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
  padding-right: 0.5rem;
  background: transparent;
  border: none;
  border-radius: 3px;
  color: var(--fg);
  font-family: inherit;
  font-size: inherit;
  text-align: left;
  cursor: pointer;
  width: 100%;
  /* Long heading text is clipped with an ellipsis; the title attr on
     the button gives the full text on hover. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s ease;
}
.contents-link:hover,
.contents-link:focus-visible {
  background: var(--bg);
  outline: none;
}
/* The section the reader is in. */
.contents-link[aria-current="true"] {
  color: var(--accent);
}
/* The label truncates itself, so a long heading's underline ends at its
   ellipsis. The bottom padding is room for the pen line, given back by
   the margin so rows keep their height. */
.contents-label {
  position: relative;
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: top;
  padding-bottom: 0.25em;
  margin-bottom: -0.25em;
}
/* A quick pen line under the current label, rather than a fill, so the
   hover state stays distinguishable: a nib's shape, pointed at both ends
   and easing off towards the exit. The tapers keep their length on any
   label, so the line between stays even. */
.contents-link[aria-current="true"] .contents-label::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0.125em;
  height: 0.14em;
  background-color: var(--accent);
  --nib-in: min(0.5em, 12%);
  --nib-out: min(1.2em, 28%);
  clip-path: polygon(
    0 52%, calc(var(--nib-in) * 0.15) 24%, calc(var(--nib-in) * 0.4) 8%, var(--nib-in) 0%,
    calc(100% - var(--nib-out)) 29%, calc(100% - var(--nib-out) * 0.55) 33.8%,
    calc(100% - var(--nib-out) * 0.25) 39.5%, 100% 48%,
    calc(100% - var(--nib-out) * 0.25) 71.4%, calc(100% - var(--nib-out) * 0.55) 87%,
    calc(100% - var(--nib-out)) 100%, var(--nib-in) 100%,
    calc(var(--nib-in) * 0.4) 92%, calc(var(--nib-in) * 0.15) 78%
  );
}

/* ---------- Reader ---------- */
/* The sheet. Layer order is grain, then sheen, over the flat --bg:
   first-listed background sits on top. The sheen runs across the column
   at exactly 90deg, never a diagonal: the sheet is as tall as the
   document, so any other angle projects over that whole height and
   reads as a spotlight streak that slides as you scroll. */
#reader {
  max-width: 680px;
  margin: 2.5rem auto 4rem;
  padding: 4rem 3.5rem 6rem;
  /* A short document should still read as a page rather than a strip. */
  min-height: calc(100vh - 6.5rem);
  background-color: var(--bg);
  background-image: var(--grain),
    linear-gradient(90deg, var(--sheet-tint) 0%, var(--sheet-sheen) 45%, var(--sheet-tint) 100%);
  border-radius: 2px;
  box-shadow: 0 1px 2px var(--sheet-shadow),
    0 10px 30px var(--sheet-shadow),
    inset 0 0 60px var(--sheet-tint);
}

/* Below the sheet's natural width there is no desk left to show, so it
   goes edge to edge and drops the shadow and rounding. */
@media (max-width: 760px) {
  #reader {
    margin: 0 auto;
    padding: 3rem 1.5rem 6rem;
    border-radius: 0;
    box-shadow: inset 0 0 60px var(--sheet-tint);
  }
}

article#document h1,
article#document h2,
article#document h3,
article#document h4,
article#document h5,
article#document h6 {
  font-family: "EB Garamond", Georgia, serif;
  line-height: 1.2;
  margin-top: 1.6em;
  margin-bottom: 0.4em;
}

article#document h1 {
  font-variant-caps: small-caps;
  letter-spacing: 0.03em;
  font-size: 2.4rem;
  text-align: center;
  margin-top: 0.4em;
}

article#document p {
  margin: 0 0 1em;
  text-align: justify;
  hyphens: auto;
}

/* The sheet justifies paragraphs, and a stylesheet rule outranks the
   legacy align attribute's presentational hint, so an author's
   <p align="right"> has to be restated here to take effect. */
article#document [align="center"] { text-align: center; }
article#document [align="right"]  { text-align: right; }
article#document [align="left"]   { text-align: left; }
article#document img[align="right"] { float: right; margin: 0.3em 0 0.6em 1.2em; }
article#document img[align="left"]  { float: left;  margin: 0.3em 1.2em 0.6em 0; }

/* One long name (a package, a URL) has no break point: anywhere lets it
   break; no added hyphens. Table cells wrap between words instead (below). */
article#document a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
  hyphens: none;
}
article#document a:visited { color: var(--muted); }

article#document blockquote {
  margin: 1.2em 0;
  padding: 0 0 0 1.2em;
  border-left: 2px solid var(--rule);
  font-style: italic;
  color: var(--muted);
}

/* A remote image the renderer withheld. Inline-flex so it sits where
   the image would, inside whatever the author wrapped it in. */
article#document .remote-image {
  display: inline-flex;
  flex-direction: column;
  gap: 0.35em;
  max-width: 100%;
  margin: 0.3em 0;
  padding: 0.7em 0.9em;
  border: 1px dashed var(--rule);
  border-radius: 6px;
  background: var(--code-bg);
  font-size: 0.85em;
  font-style: normal;
  color: var(--muted);
  vertical-align: middle;
}
article#document .remote-image-title {
  font-variant-caps: small-caps;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--fg);
}
article#document .remote-image-url {
  font-size: 0.85em;
  background: none;
  padding: 0;
  word-break: break-all;
}
article#document .remote-image-warning {
  font-style: italic;
}
article#document .remote-image-load {
  align-self: flex-start;
  font: inherit;
  font-size: 0.95em;
  padding: 0.25em 0.8em;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--bg);
  color: var(--accent);
  cursor: pointer;
}
article#document .remote-image-load:hover {
  border-color: var(--accent);
}

/* Math and diagrams, rendered client-side after the document lands. A
   span or block the library rejects keeps its source and gets a rule
   in the caution colour; the reason is in the title. */
article#document .math-error,
article#document .diagram-error {
  border-bottom: 2px dotted #8f2f22;
  cursor: help;
}
article#document span[data-math-style="display"] {
  display: block;
  margin: 1em 0;
  overflow-x: auto;
}
article#document .katex-display {
  margin: 0;
}
/* Diagrams follow the code-block rule: one that fits the column sits
   centred in it as a drawing on the page; a wider one grows to its natural
   width, capped at (viewport - 2rem) and centred on the column midline,
   so its labels stay the size Mermaid set rather than shrinking to fit.
   Past the cap the drawing scrolls sideways inside the figure. The paper
   and lift shadow are added only when it leaves the column (.wide, set by
   diagrams.js); a plate around a small flowchart would read as a frame,
   and the diagram already carries the sheet colour in its own fills. */
article#document figure.diagram {
  margin: 1.5em 0;
  text-align: center;
  width: max-content;
  min-width: 100%;
  max-width: calc(100vw - var(--contents-inset) - 2rem);
  overflow-x: auto;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
}
/* The plate comes only when the drawing would leave the sheet (diagrams.js
   measures against #reader, not the text column): line art may run into
   the margins bare, where a code block could not. */
article#document figure.diagram.wide {
  padding: 1.5em 1.2em;
  background-color: var(--bg);
  background-image: var(--grain);
  box-shadow: 0 1px 2px var(--plate-shadow), 0 6px 18px var(--plate-shadow);
}
article#document figure.diagram svg {
  display: block;
  margin: 0 auto;
  height: auto;
}

/* Inside the drawing. Mermaid's hand-drawn look (rough.js) gives every
   box and line the slight wobble of a pen, and fills the boxes with a
   fine pencil hachure in the code-block tone, so a flowchart reads as
   sketched on the sheet rather than pasted onto it. The lettering is
   the body face in the ink colour. Edge labels are annotations beside
   the line: italic, the muted ink, no box; a thin halo in the paper tone
   lifts the glyphs off the line that runs beneath them. Cluster titles
   are set like the small-caps H1. Anything Mermaid colours by class is
   repeated here against the sheet variables so a theme change, or a
   diagram type whose colours its theme does not reach, still lands in
   the palette. */
article#document figure.diagram svg .label,
article#document figure.diagram svg .nodeLabel,
article#document figure.diagram svg .nodeLabel p,
article#document figure.diagram svg text,
article#document figure.diagram svg text > tspan,
article#document figure.diagram svg foreignObject div,
article#document figure.diagram svg foreignObject span,
article#document figure.diagram svg foreignObject p {
  color: var(--fg);
  fill: var(--fg);
  font-family: "EB Garamond", Georgia, serif;
}
article#document figure.diagram svg[aria-roledescription="eventmodeling"] text,
article#document figure.diagram svg[aria-roledescription="eventmodeling"] text > tspan {
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
article#document figure.diagram svg .edgeLabel,
article#document figure.diagram svg .edgeLabel p,
article#document figure.diagram svg .labelBkg {
  background-color: transparent;
}
article#document figure.diagram svg .edgeLabel rect {
  fill: none;
  opacity: 0;
}
article#document figure.diagram svg .edgeLabel .label span,
article#document figure.diagram svg .edgeLabel p,
article#document figure.diagram svg .edgeLabel text {
  font-style: italic;
  font-size: 0.95em;
  color: var(--muted);
  fill: var(--muted);
  text-shadow: 0 0 2px var(--bg), 0 0 2px var(--bg);
}
article#document figure.diagram svg .cluster-label foreignObject {
  overflow: visible;
}
article#document figure.diagram svg .cluster-label span,
article#document figure.diagram svg .cluster-label text {
  font-variant: small-caps;
  font-size: 0.95em;
  letter-spacing: 0.04em;
  color: var(--muted);
  fill: var(--muted);
}
article#document figure.diagram svg .flowchart-link,
article#document figure.diagram svg .edgePaths .path,
article#document figure.diagram svg .transition,
article#document figure.diagram svg .relation,
article#document figure.diagram svg .messageLine0,
article#document figure.diagram svg .messageLine1,
article#document figure.diagram svg .actor-line,
article#document figure.diagram svg .loopLine {
  stroke: var(--muted);
}
/* The arrows are drawn with the same pen as the boxes. */
article#document figure.diagram svg .flowchart-link,
article#document figure.diagram svg .edgePaths .path,
article#document figure.diagram svg .transition,
article#document figure.diagram svg .relation {
  stroke-width: 1.4px;
  stroke-linecap: round;
}
article#document figure.diagram svg .actor-line {
  stroke-width: 1px;
}
/* Node labels: centred and balanced across their lines, so a label that
   wraps does not leave a ragged first line over a single word. */
article#document figure.diagram svg .nodeLabel,
article#document figure.diagram svg .nodeLabel p {
  text-align: center;
  /* The longhand: the shorthand resets text-wrap-mode and would undo the
     white-space: nowrap Mermaid sized one-line labels for. */
  text-wrap-style: balance;
  hyphens: manual;
}
/* Sequence messages are annotations beside their arrow, like edge labels. */
article#document figure.diagram svg .messageText,
article#document figure.diagram svg .loopText,
article#document figure.diagram svg .loopText > tspan {
  font-style: italic;
  fill: var(--muted);
}
/* A message centred between two far actors lands on the lifeline
   between them; the paper-tone stroke under the glyphs lifts it off. */
article#document figure.diagram svg .messageText {
  stroke: var(--bg);
  stroke-width: 4px;
  stroke-linejoin: round;
  paint-order: stroke fill;
}
/* The pen and pencil diagrams.js adds where Mermaid left plain shapes:
   a hachure in the box tone, an outline in the rule colour, and the
   wash of pencil weight in the ink colour toward one corner. */
article#document figure.diagram svg .sketch-fill line {
  stroke: var(--code-bg);
  stroke-width: 1.6;
}
article#document figure.diagram svg .sketch-outline {
  fill: none;
  stroke: var(--rule);
  stroke-width: 1.1;
  stroke-linejoin: round;
}
article#document figure.diagram svg .sketch-wash-stop {
  stop-color: var(--fg);
}
/* Pie slices coloured in with pencils, lightly, so the paper shows through
   between the strokes; each legend swatch is coloured in with the same
   pencil at the same angle. */
article#document figure.diagram svg .sketch-pencil line {
  stroke-width: 1.7;
  stroke-linecap: round;
}
article#document figure.diagram svg .sketch-pencil .cross line {
  stroke-width: 1.4;
  opacity: 0.8;
}
article#document figure.diagram svg .sketch-pencil .faint line {
  stroke-width: 1.1;
  opacity: 0.5;
}
article#document figure.diagram svg .legend > rect[class^="pencil-"] {
  fill: none;
  stroke: var(--muted);
  stroke-width: 0.8;
}
article#document figure.diagram svg .legend .sketch-pencil line {
  stroke-width: 1.1;
}
article#document figure.diagram svg .pieCircle {
  stroke: var(--muted);
  stroke-width: 1.2;
}
article#document figure.diagram svg .pieOuterCircle {
  stroke: var(--muted);
  stroke-width: 1.4;
}
article#document figure.diagram svg .pencil-1 { stroke: var(--pencil-1); fill: var(--pencil-1); }
article#document figure.diagram svg .pencil-2 { stroke: var(--pencil-2); fill: var(--pencil-2); }
article#document figure.diagram svg .pencil-3 { stroke: var(--pencil-3); fill: var(--pencil-3); }
article#document figure.diagram svg .pencil-4 { stroke: var(--pencil-4); fill: var(--pencil-4); }
article#document figure.diagram svg .pencil-5 { stroke: var(--pencil-5); fill: var(--pencil-5); }
article#document figure.diagram svg .pencil-6 { stroke: var(--pencil-6); fill: var(--pencil-6); }
article#document figure.diagram svg .pencil-7 { stroke: var(--pencil-7); fill: var(--pencil-7); }
article#document figure.diagram svg .pencil-8 { stroke: var(--pencil-8); fill: var(--pencil-8); }
article#document figure.diagram svg .sketch-pencil line { fill: none; }
article#document figure.diagram svg .marker,
article#document figure.diagram svg .arrowheadPath,
article#document figure.diagram svg [id$="-arrowhead"] path,
article#document figure.diagram svg [id$="-crosshead"] path {
  fill: var(--muted);
  stroke: var(--muted);
}
article#document figure.diagram svg rect.actor,
article#document figure.diagram svg .note,
article#document figure.diagram svg .labelBox,
article#document figure.diagram svg [class^="activation"] {
  fill: var(--code-bg);
  stroke: var(--rule);
}

/* Renderers that paint colours no theme variable reaches: sankey's
   Tableau blues, c4's corporate blue, the stock icon sets, the grey
   packet and treemap frames, the journey faces. Each is taken back to
   the palette by class or role. The icon rule needs !important because
   the icons carry inline styles. */
article#document figure.diagram svg[aria-roledescription="sankey"] .node rect {
  fill: var(--muted);
}
article#document figure.diagram svg[aria-roledescription="sankey"] .link path {
  stroke: var(--rule);
  stroke-opacity: 0.35;
}
article#document figure.diagram svg[aria-roledescription="sankey"] .link {
  mix-blend-mode: normal;
}
article#document figure.diagram svg[aria-roledescription="c4"] [stroke]:not([stroke="none"]) {
  stroke: var(--rule);
}
article#document figure.diagram svg[aria-roledescription="c4"] path[stroke-width="1.5"] {
  stroke-opacity: 0.35;
}
article#document figure.diagram svg[aria-roledescription="architecture"] .node-icon svg rect:first-of-type,
article#document figure.diagram svg[aria-roledescription="architecture"] svg > g > rect:first-child {
  fill: var(--muted) !important;
}
article#document figure.diagram svg[aria-roledescription="architecture"] svg > g > *:not(:first-child),
article#document figure.diagram svg[aria-roledescription="architecture"] svg > g > g * {
  stroke: var(--bg) !important;
}
article#document figure.diagram svg[aria-roledescription="architecture"] svg > g > g path[style*="fill: #fff"] {
  fill: var(--bg) !important;
}
article#document figure.diagram svg .packetBlock,
article#document figure.diagram svg .treemapNode.section {
  fill: var(--code-bg);
  stroke: var(--rule);
}
article#document figure.diagram svg .treemapNode.leaf {
  stroke: var(--rule);
}
article#document figure.diagram svg .packetByte,
article#document figure.diagram svg .packetLabel,
article#document figure.diagram svg .packetTitle,
article#document figure.diagram svg .treemapValue {
  fill: var(--fg);
}
article#document figure.diagram svg .treeView-node-line {
  stroke: var(--rule);
}
article#document figure.diagram svg .treeView-node-icon {
  color: var(--muted);
}
article#document figure.diagram svg .treeView-node-description {
  fill: var(--muted);
}
article#document figure.diagram svg .treeView-highlight-bg {
  fill: var(--code-bg);
  stroke: var(--rule);
}
article#document figure.diagram svg .face {
  fill: var(--bg);
  stroke: var(--muted);
}
article#document figure.diagram svg .mouth {
  stroke: var(--muted);
}
/* journey.actorColours in initialize() is ignored by 12.0.0 (the
   renderer caches the default config at module load), so the dots are
   recoloured here, four tones in rotation. */
article#document figure.diagram svg circle[class^="actor-"] {
  stroke: var(--muted);
  fill: var(--code-bg);
}
article#document figure.diagram svg circle.actor-1,
article#document figure.diagram svg circle.actor-5 {
  fill: var(--rule);
}
article#document figure.diagram svg circle.actor-2,
article#document figure.diagram svg circle.actor-6 {
  fill: var(--muted);
}
article#document figure.diagram svg circle.actor-3,
article#document figure.diagram svg circle.actor-7 {
  fill: var(--bg);
}
article#document figure.diagram svg .alt-composit {
  fill: var(--code-bg);
}
article#document figure.diagram svg .vert {
  stroke: var(--muted);
}
article#document figure.diagram svg .vertText {
  fill: var(--muted) !important;
}
/* A sequence box or highlight rect carries the author's colour; kept as a
   wash so the sketched actors and italic messages stay legible on it. */
article#document figure.diagram svg[aria-roledescription="sequence"] rect.rect {
  fill-opacity: 0.25;
  stroke: var(--rule);
}
/* Block-diagram arrows are polygons with no fill of their own. */
article#document figure.diagram svg[aria-roledescription="block"] polygon.label-container {
  fill: var(--code-bg);
  stroke: var(--rule);
}
/* The Wardley renderer hard-codes white for pipeline components, market
   dots, forces and the annotation box, black for the anchor label and
   three greys for the sourcing overlays; none reads a theme variable. */
article#document figure.diagram svg[aria-roledescription="wardley"] [fill="white"] {
  fill: var(--bg);
}
article#document figure.diagram svg[aria-roledescription="wardley"] text[fill="#000"] {
  fill: var(--fg);
}
article#document figure.diagram svg[aria-roledescription="wardley"] .wardley-build-overlay { fill: var(--code-bg); }
article#document figure.diagram svg[aria-roledescription="wardley"] .wardley-buy-overlay { fill: var(--rule); }
article#document figure.diagram svg[aria-roledescription="wardley"] .wardley-outsource-overlay { fill: var(--muted); }
/* Mermaid's unknown-icon fallback: a blue tile with a white question mark,
   drawn wherever an icon pack is not registered. */
article#document figure.diagram svg svg rect[style*="#087ebf"] {
  fill: var(--muted) !important;
}
article#document figure.diagram svg svg rect[style*="#087ebf"] + text {
  fill: var(--bg) !important;
  font-family: "EB Garamond", Georgia, serif !important;
}
article#document figure.diagram svg[aria-roledescription="venn"] text.label {
  fill: var(--fg) !important;
}
article#document figure.diagram svg[aria-roledescription="timeline"] [class*="section-"] line,
article#document figure.diagram svg[aria-roledescription="timeline"] line[stroke="black"],
article#document figure.diagram svg[aria-roledescription="timeline"] .lineWrapper line {
  stroke: var(--muted);
}
@media (prefers-color-scheme: dark) {
  article#document .math-error,
  article#document .diagram-error {
    border-bottom-color: #e08a7c;
  }
}

/* GitHub-style alerts: a blockquote whose first line is [!NOTE] etc.
   Upright, with a coloured rule and a small-caps title. Ink colours
   sit in the sheet's palette rather than GitHub's saturated set. */
article#document .markdown-alert {
  --alert: var(--rule);
  margin: 1.2em 0;
  padding: 0.1em 0 0.1em 1.2em;
  border-left: 3px solid var(--alert);
}
article#document .markdown-alert > p {
  margin: 0.4em 0;
}
article#document .markdown-alert-title {
  font-variant-caps: small-caps;
  letter-spacing: 0.04em;
  font-weight: 600;
  color: var(--alert);
}
article#document .markdown-alert-note      { --alert: #3e5f8a; }
article#document .markdown-alert-tip       { --alert: #3f6b2a; }
article#document .markdown-alert-important { --alert: #5a3f82; }
article#document .markdown-alert-warning   { --alert: #8c5a1f; }
article#document .markdown-alert-caution   { --alert: #8f2f22; }
@media (prefers-color-scheme: dark) {
  article#document .markdown-alert-note      { --alert: #8fb0d8; }
  article#document .markdown-alert-tip       { --alert: #a8c884; }
  article#document .markdown-alert-important { --alert: #b0a5e0; }
  article#document .markdown-alert-warning   { --alert: #d6a679; }
  article#document .markdown-alert-caution   { --alert: #e08a7c; }
}

article#document img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.2em auto;
}

/* Tables are wrapped in <div class="table-scroll"> by main.js. The
   wrapper carries the same growth rule as code blocks: short tables fit
   the column, wider tables grow up to (viewport - 2rem), centred on the
   column midline. Tables exceeding even that cap scroll horizontally
   inside the wrapper rather than spilling text out of their cells.
   The surface is opaque and repeats the sheet's colour and fibre, so a
   table narrower than the measure is indistinguishable from the page
   while a wide one carries paper out over the desk instead of letting
   the desk show between its cells. */
article#document .table-scroll {
  margin: 1.5em 0;
  width: max-content;
  min-width: 100%;
  max-width: calc(100vw - var(--contents-inset) - 2rem);
  overflow-x: auto;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--bg);
  background-image: var(--grain);
  box-shadow: 0 1px 2px var(--plate-shadow), 0 6px 18px var(--plate-shadow);
}

article#document table {
  border-collapse: collapse;
  /* Width is governed by the wrapper; the table itself sizes to
     content so it can either fill the wrapper or be wider and let
     the wrapper scroll. */
  min-width: 100%;
}
article#document th,
article#document td {
  border: 1px solid var(--rule);
  padding: 0.4em 0.7em;
  text-align: left;
}
article#document th { background: var(--code-bg); }

/* Subtle zebra striping on body rows. A low-alpha tint of --rule keeps
   the warmth of the rest of the chrome and stays barely-there on both
   light and dark themes. */
article#document tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--rule) 8%, transparent);
}

article#document hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2em 0;
}

/* Task lists. Comrak marks the item only by its leading <input>, so the
   :has() selector is what finds it. The box takes the bullet's place in
   the marker gutter and is drawn as a slightly uneven inked square, with
   a pen tick over it when checked, rather than the platform's control. */
article#document li:has(> input[type="checkbox"]) {
  list-style: none;
}
article#document input[type="checkbox"] {
  appearance: none;
  width: 0.9em;
  height: 0.9em;
  margin: 0 0.45em 0 -1.35em;
  vertical-align: -0.1em;
  border: none;
  background: transparent no-repeat center / 100% 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M1.2 1.5 8.9 1.1 8.6 8.8 1.4 8.5Z' fill='none' stroke='%23a8927a' stroke-width='0.9' stroke-linejoin='round'/%3E%3C/svg%3E");
}
article#document input[type="checkbox"]:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M1.2 1.5 8.9 1.1 8.6 8.8 1.4 8.5Z' fill='none' stroke='%23a8927a' stroke-width='0.9' stroke-linejoin='round'/%3E%3Cpath d='M2.2 5.3 4.4 7.6 9.4 0.6' fill='none' stroke='%237a3b1f' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  article#document input[type="checkbox"] {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M1.2 1.5 8.9 1.1 8.6 8.8 1.4 8.5Z' fill='none' stroke='%235a4f40' stroke-width='0.9' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
  article#document input[type="checkbox"]:checked {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3E%3Cpath d='M1.2 1.5 8.9 1.1 8.6 8.8 1.4 8.5Z' fill='none' stroke='%235a4f40' stroke-width='0.9' stroke-linejoin='round'/%3E%3Cpath d='M2.2 5.3 4.4 7.6 9.4 0.6' fill='none' stroke='%23d6a679' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}

/* HTML inline elements the sanitizer lets through. kbd reads as a key;
   a bare mark uses the sheet's palette rather than the browser's
   fluorescent default (find-match overrides it further down). */
article#document kbd {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.75em;
  padding: 0.1em 0.45em 0.15em;
  border: 1px solid var(--rule);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--code-bg);
  white-space: nowrap;
}
article#document mark:not(.find-match) {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: inherit;
  padding: 0 0.15em;
  border-radius: 2px;
}
article#document summary {
  cursor: pointer;
  color: var(--accent);
  font-variant-caps: small-caps;
  letter-spacing: 0.03em;
}
article#document details {
  margin: 1em 0;
  padding: 0.5em 1em;
  border-left: 2px solid var(--rule);
}
article#document details[open] > summary {
  margin-bottom: 0.5em;
}

/* Inline code. Identifiers break nowhere on their own — underscore and
   dot are not break opportunities, which is why a path with a hyphen in
   it wraps and AWS_ENDPOINT_URL_header does not — so a long span runs
   through the column's right padding and onto the desk. break-word
   breaks such a token only when it cannot fit a line by itself, leaving
   ordinary spans alone. Hyphenation is off because the sheet sets
   hyphens:auto on p, and a soft hyphen rendered inside an identifier
   reads as part of it. Sized as block code is: at 1em the mono runs so
   much wider than Garamond that justified lines around it gap. */
article#document :not(pre) > code {
  overflow-wrap: break-word;
  hyphens: none;
  font-size: 0.82em;
}
/* Code in a link takes the link's anywhere, overriding break-word above. */
article#document a code {
  overflow-wrap: anywhere;
}
/* In a table cell a link wraps between words: anywhere would let auto
   layout squeeze a column of links below its longest word. */
article#document th a,
article#document td a,
article#document th a code,
article#document td a code {
  overflow-wrap: break-word;
}

/* Code blocks size to their content. Short code stays in the 680px
   reading column; long code grows to its natural width, capped at
   (viewport - 2rem). When the pre exceeds the column width it
   overflows symmetrically — left:50% + translateX(-50%) centres the
   pre on the column's midline regardless of its actual width. Lines
   longer than the viewport cap scroll horizontally inside the code,
   not the pre, so the label and copy control pinned to the pre stay put.
   The lift shadow is load-bearing: it is what makes a pre wider than
   the sheet read as a plate laid over the page rather than as paper
   spilling onto the desk. */
article#document pre {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  background: var(--code-bg);
  padding: 1em 0;
  border-radius: 6px;
  overflow: hidden;
  line-height: 1.45;
  color: var(--fg);
  width: max-content;
  min-width: 100%;
  max-width: calc(100vw - var(--contents-inset) - 2rem);
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 1px 2px var(--plate-shadow), 0 6px 18px var(--plate-shadow);
}
article#document pre code {
  display: block;
  overflow-x: auto;
  overflow-y: hidden;
  background: transparent;
  padding: 0 calc(1.2em / 0.82);
  font-size: 0.82em;
  color: var(--fg);
}

/* Fence language, copied to data-lang by code-lang.js, painted small
   and faded in the block's top-right corner. */
article#document pre[data-lang]::after {
  content: attr(data-lang);
  position: absolute;
  top: 0.45em;
  right: 0.7em;
  font-size: 0.68em;
  color: var(--muted);
  opacity: 0.75;
  user-select: none;
  pointer-events: none;
}

/* Copy control, added by code-copy.js, in the corner the label vacates. */
article#document pre[data-lang]:has(> .code-copy)::after {
  right: 2.3em;
}

/* While the control shows a result, the label slot says what happened.
   Generated content, so Find never matches it. */
article#document pre:has(> .code-copy[data-state])::after {
  position: absolute;
  top: 0.45em;
  right: 2.3em;
  font-size: 0.68em;
  opacity: 1;
  user-select: none;
  pointer-events: none;
}
article#document pre:has(> .code-copy[data-state="copied"])::after {
  content: "Copied";
  color: var(--accent);
}
article#document pre:has(> .code-copy[data-state="failed"])::after {
  content: "Copy failed";
  color: #8f2f22;
}
@media (prefers-color-scheme: dark) {
  article#document pre:has(> .code-copy[data-state="failed"])::after {
    color: #e08a7c;
  }
}

article#document pre > .code-copy {
  position: absolute;
  top: 0.3em;
  right: 0.45em;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.2em;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 0.85em;
  opacity: 0.6;
  cursor: pointer;
  transition: opacity 120ms ease, color 120ms ease;
}

article#document pre:hover > .code-copy,
article#document pre > .code-copy:focus-visible {
  opacity: 1;
}

article#document pre > .code-copy:hover {
  color: var(--fg);
}

article#document pre > .code-copy:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

article#document pre > .code-copy[data-state="copied"] {
  color: var(--accent);
  opacity: 1;
}

article#document pre > .code-copy[data-state="failed"] {
  color: #8f2f22;
  opacity: 1;
}

@media (prefers-color-scheme: dark) {
  article#document pre > .code-copy[data-state="failed"] {
    color: #e08a7c;
  }
}

@media print {
  article#document pre > .code-copy { display: none; }
}

/* Footnotes */
article#document .footnote-definition {
  font-size: 0.92em;
  color: var(--muted);
}

/* Task list */
article#document input[type="checkbox"] { margin-right: 0.4em; }

/* ---------- Syntect class-mode highlighting (ClassStyle::Spaced) ---------- */
/* comrak's syntect adapter in .css() mode emits scope-derived classes joined
   by spaces, e.g. <span class="keyword control rust">,
   <span class="storage type rust">, <span class="entity name function rust">,
   <span class="comment line rust">, <span class="string quoted double rust">.
   A CSS class selector matches any element whose class list contains that
   token, so we target the leading scope component. Spans whose scope we don't
   style inherit the code block's --fg color. */

/* Light (default) */
article#document .comment     { color: #8a7a60; font-style: italic; }
article#document .string      { color: #4d6b2a; }
article#document .constant    { color: #8c5a1f; }
article#document .keyword,
article#document .storage     { color: #7a3b1f; }
article#document .entity      { color: #4a3a82; }
article#document .support     { color: #5a5030; }
article#document .punctuation { color: #8a7060; }
article#document .deleted     { color: #8f2f22; background: rgba(143, 47, 34, 0.08); }
article#document .inserted    { color: #3f6b2a; background: rgba(63, 107, 42, 0.10); }

@media (prefers-color-scheme: dark) {
  article#document .comment     { color: #9d8c70; }
  article#document .string      { color: #a8c884; }
  article#document .constant    { color: #d6a679; }
  article#document .keyword,
  article#document .storage     { color: #d6a679; }
  article#document .entity      { color: #b0a5e0; }
  article#document .support     { color: #c9b48f; }
  article#document .punctuation { color: #7a6b58; }
  article#document .deleted     { color: #e08a7c; background: rgba(224, 138, 124, 0.10); }
  article#document .inserted    { color: #a8c884; background: rgba(168, 200, 132, 0.10); }
}

/* ---------- Find bar ---------- */
/* Browser-style "find in page" overlay (Cmd/Ctrl+F). Pinned bottom-right
   so it doesn't collide with the reload-toast / contents-button which
   live in the top corners. Hidden by default; revealed by find.js. */
.find-bar {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem;
  background: var(--code-bg);
  border: 1px solid var(--rule);
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(31, 29, 26, 0.22);
  font-family: "EB Garamond", Georgia, serif;
}
.find-bar[hidden] { display: none; }

.find-input {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 0.95rem;
  width: 14rem;
  padding: 0.2rem 0.5rem;
}
.find-input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}
/* Suppress the native "x" search-clear control in WebKit — looks
   stylistically off against the custom close button. */
.find-input::-webkit-search-cancel-button { display: none; }

.find-count {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  min-width: 3.5rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.find-button {
  width: 1.8rem;
  height: 1.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  color: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.12s ease;
}
.find-button:hover {
  background: var(--bg);
  transform: scale(1.08);
}
.find-button:active {
  transform: scale(0.94);
}

/* ---------- Find match highlights ---------- */
/* Two colours: a calmer wash for every match, and a stronger ring for
   the currently focused match. Both work in light and dark themes via
   the existing variable palette. */
mark.find-match {
  background: rgba(214, 166, 121, 0.35); /* warm tan, soft */
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
mark.find-match-current {
  background: var(--accent);
  color: var(--bg);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

@media (prefers-color-scheme: dark) {
  mark.find-match {
    background: rgba(214, 166, 121, 0.28);
  }
  mark.find-match-current {
    background: var(--accent);
    color: var(--bg);
  }
}

/* ---------- Selection as a highlighter stroke ---------- */
/* WebKit paints a selection out to the window edges past each line's
   end. The document hides that paint and highlighter.js draws marks
   from the selected text's own line boxes instead. */
article#document ::selection,
article#document::selection {
  background-color: transparent;
}

/* An image has no text to mark, and a diagram's labels are left
   unmarked on purpose, so both keep a tint, in the ink. */
article#document img::selection {
  background-color: color-mix(in srgb, var(--highlighter-ink) 45%, transparent);
}
article#document figure.diagram svg ::selection,
article#document figure.diagram svg::selection {
  background-color: color-mix(in srgb, var(--highlighter-ink) 45%, transparent);
}

/* Marks are placed against the document's box (highlighter.js). */
article#document {
  position: relative;
}

.highlighter-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  user-select: none;
}

/* Drawn over the text: code blocks and tables are positioned, opaque and
   later in the document, so at z-index auto they would cover the marks.
   The z-index sits here, not on the layer, because a stacking context
   there would isolate the blend from the page beneath. Multiply keeps
   the text dark and lets the paper's grain show through, as ink does. */
.highlighter-stroke {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  clip-path: var(--outline);
  mix-blend-mode: multiply;
  background:
    linear-gradient(90deg, var(--highlighter-pool) 0%, transparent 5%, transparent 95%, var(--highlighter-pool) 100%),
    linear-gradient(180deg, var(--highlighter-pool) 0%, transparent 22%, transparent 78%, var(--highlighter-pool) 100%),
    var(--highlighter-felt) 0 0 / 400px 40px,
    var(--highlighter-ink);
}

@media (prefers-color-scheme: dark) {
  .highlighter-stroke {
    mix-blend-mode: screen;
  }
}

@media print {
  .highlighter-layer { display: none; }
}
