/* Layout and components. Mobile first. Uses tokens only.
   Breakpoints: 48rem = tablet (larger toggle and frames), 64rem = desktop (spine nav, 12-column grid). */

/* Page container: one width rule for every top-level block */
:root {
  --page-width: min(100% - 2 * var(--gutter), var(--page-max));
}

.site-header,
.hero,
.section,
.divider,
.colophon {
  inline-size: var(--page-width);
  margin-inline: auto;
}

/* Sprite holder: takes no space */
.sprite {
  position: absolute;
}

/* Small-caps text: one rule for every label-style element */
.eyebrow,
.hero__handle,
.hero__link,
.index__link,
.site-nav a,
.menu-button,
.menu__close,
.theme-toggle__label,
.btn,
.colophon__year,
.specimen-label dt,
.plate__number {
  font-family: var(--font-label);
  letter-spacing: var(--tracking-caps);
  text-transform: lowercase;
}

/* Skip link: hidden until focused */
.skip-link {
  position: absolute;
  inset-block-start: var(--space-2);
  inset-inline-start: var(--space-2);
  z-index: 1;
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  transform: translateY(-300%);
}

.skip-link:focus {
  transform: none;
}

/* Header: the top spine. Full-bleed sunken paper; the sprig divider below marks its edge */
.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  inline-size: auto;
  margin: 0;
  padding-block: var(--space-3);
  padding-inline: max(var(--gutter), (100% - var(--page-max)) / 2);
  background: var(--paper-sunken);
}

.wordmark {
  display: flex; /* no inline gap under the image */
}

.wordmark img {
  block-size: 2.75rem; /* 44px, same as the header buttons */
  inline-size: auto;
}

/* Header text buttons and links: no ornament */
.menu-button,
.menu__close {
  min-block-size: 2.75rem; /* 44px touch target */
  padding: 0 var(--space-2);
  border: 0;
  background: transparent;
  color: var(--color-text);
  font-size: var(--text-base);
  cursor: pointer;
}

.menu-button:hover,
.menu__close:hover {
  text-decoration: underline;
  text-decoration-thickness: var(--rule-thin);
  text-underline-offset: .25em;
}

.site-nav {
  display: none;
}

.site-nav__list,
.menu__list,
.index {
  margin: 0;
  padding: 0;
  list-style: none;
}

.site-nav__list {
  display: flex;
  gap: var(--space-5);
}

.site-nav a {
  font-size: var(--text-sm);
  color: var(--color-text);
  text-decoration: none;
}

/* Hovered or current link: one mark under the whole label, numeral included: a line, a dot, a line.
   Drawn by a pseudo-element, because a text underline breaks at the numeral's dot and margin.
   Sizes are in em, so the mark scales from the small spine links to the large menu links. */
.site-nav a,
.menu__list a {
  --link-mark-dot: .07em;    /* dot radius */
  --link-mark-ink: color-mix(in srgb, currentColor 55%, transparent); /* same ink, lighter: a solid line reads darker than thin small caps */
  --link-mark-gap: .45em; /* from the centre to each line */
  position: relative;
}

.site-nav a::after,
.menu__list a::after {
  content: "";
  position: absolute;
  inset-inline: 0;
  inset-block-end: -.45em;
  block-size: .4em;
  background:
    radial-gradient(circle, currentColor var(--link-mark-dot), transparent calc(var(--link-mark-dot) + .5px)) center / .4em .4em no-repeat,
    linear-gradient(var(--link-mark-ink), var(--link-mark-ink)) left center / calc(50% - var(--link-mark-gap)) var(--rule-thin) no-repeat,
    linear-gradient(var(--link-mark-ink), var(--link-mark-ink)) right center / calc(50% - var(--link-mark-gap)) var(--rule-thin) no-repeat;
  opacity: 0;
  pointer-events: none;
}

.site-nav a:hover::after,
.site-nav a[aria-current]::after,
.menu__list a:hover::after,
.menu__list a[aria-current]::after {
  opacity: 1;
}

.site-nav__numeral,
.menu__numeral {
  color: var(--color-text-muted);
}

/* Small dot between the numeral and the name; empty alt text keeps it out of the a11y tree */
.site-nav__numeral::after {
  content: "·" / "";
  margin-inline-start: .35em;
}

/* Theme toggle: shows the target theme (D19). Opacity only; the cross-fade is in the motion block */
.theme-toggle {
  --toggle-art-size: 36px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-inline-start: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
}

.theme-toggle__art {
  display: grid;
}

.theme-toggle__img {
  grid-area: 1 / 1;
  block-size: var(--toggle-art-size);
  inline-size: auto;
  opacity: 0;
}

.theme-toggle__text {
  display: grid;
}

.theme-toggle__label {
  grid-area: 1 / 1;
  font-size: var(--text-sm);
  opacity: 0;
  visibility: hidden;
}

[data-theme="light"] .theme-toggle__img--night,
[data-theme="dark"] .theme-toggle__img--day {
  opacity: 1;
}

[data-theme="light"] .theme-toggle__label--night,
[data-theme="dark"] .theme-toggle__label--day {
  opacity: 1;
  visibility: visible;
}

.theme-toggle:hover .theme-toggle__label {
  text-decoration: underline;
  text-decoration-thickness: var(--rule-thin);
  text-underline-offset: .25em;
}

/* Mobile menu: full-screen paper panel (popover) */
.menu {
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  max-inline-size: none;
  max-block-size: none;
  margin: 0;
  padding: var(--space-3) var(--gutter) var(--gutter); /* top and sides match .site-header: Close sits where Menu was */
  border: 0;
  background: var(--paper);
  color: var(--color-text);
  /* Layout lives here, not on :popover-open, so the panel keeps it while it fades out */
  flex-direction: column;
  align-items: flex-end;
}

.menu:popover-open {
  display: flex;
}

/* The panel covers the screen, so the backdrop stays clear: it must not hide the page while the panel turns */
.menu::backdrop {
  background: transparent;
}

.menu__list {
  align-self: stretch;
  display: grid;
  gap: var(--space-5);
  margin-block-start: var(--space-7);
}

.menu__list a {
  font-size: var(--text-2xl);
  font-style: italic;
  line-height: var(--leading-tight);
  color: var(--color-text);
  text-decoration: none;
}

.menu__numeral {
  display: inline-block;
  min-inline-size: 3rem;
  font-size: var(--text-base);
  font-style: normal;
}

/* Hero and sections: stacked on mobile, 12-column facing pages from 64rem */
.hero,
.section {
  display: grid;
  gap: var(--space-7);
}

.hero {
  margin-block-start: var(--space-7);
}

.hero__text {
  max-inline-size: var(--measure);
}

.hero__title {
  margin-block: var(--space-2) var(--space-1);
}

.hero__handle {
  font-size: var(--text-lg);
  color: var(--color-text-muted);
}

.hero__subtitle {
  margin-block-start: var(--space-4);
  font-size: var(--text-lg);
  font-style: italic;
  color: var(--ink-soft);
}

.hero__link {
  font-size: var(--text-base);
}

/* Section rhythm lives on the divider that precedes each section */
.divider {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-block: var(--space-9);
  color: var(--ink-rule);
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  border-top: var(--rule-hair) solid currentColor;
}

.sprig {
  flex: none;
  inline-size: 48px;
  block-size: auto;
  color: var(--ink-rule);
}

/* The measure caps prose only, so blocks like the specimen label fill the column */
.section__text > p {
  max-inline-size: var(--measure);
}

.section__text > * + * {
  margin-block-start: var(--space-4);
}

.section h2 {
  margin-block-end: var(--space-5);
}

.section h2 .eyebrow {
  display: block;
  margin-block-end: var(--space-1);
}

/* Plates: image, then a centred caption under a hairline */
.plate {
  padding-inline: var(--space-4); /* paper around the drawing on mobile (§4.3) */
}

.plate img {
  inline-size: auto;
  max-block-size: 70vh; /* tall tulips stay calm (brief §4) */
  background: var(--plate-ground, transparent); /* set in dark theme only */
  margin-inline: auto;
}

.plate figcaption {
  margin-block-start: var(--space-4);
  padding-block-start: var(--space-3);
  border-top: var(--rule-hair) solid var(--ink-rule);
  font-size: var(--text-sm);
  text-align: center;
}

.plate__number {
  color: var(--color-text-muted);
}

/* The one framed element: double rule inside a raised sheet (§6.1) */
.plate-frame {
  --frame-ink: var(--ink-rule); /* inner rule, corner rules and corner plants share it */
  position: relative;
  padding: var(--space-5);
  background: var(--plate-ground, var(--paper-raised));
  box-shadow: var(--shadow-plate);
}

.plate-frame::before {
  content: "";
  position: absolute;
  inset: var(--frame-inset);
  border: var(--rule-hair) solid var(--frame-ink);
  outline: var(--rule-mid) solid var(--ornament-gilt); /* ink at balanced, gilt at rich */
  outline-offset: 3px;
  pointer-events: none;
}

/* Night: the drawings sit on a lighter ground, so the inner rule and the corner plants get more contrast */
[data-theme="dark"] .plate-frame {
  --frame-ink: var(--ink-faded);
}

/* Specimen label (§8.4) */
.specimen-label__title {
  font-style: italic;
  color: var(--ink-soft);
}

.specimen-label {
  display: grid;
  gap: var(--space-1);
  margin-block: var(--space-2) 0;
  padding: var(--space-4) var(--space-5);
  background: var(--paper-raised);
  border: var(--rule-thin) solid var(--ink-rule);
  border-radius: var(--radius-label);
  font-size: var(--text-sm);
}

.specimen-label dt {
  color: var(--color-text-muted);
}

.specimen-label dd {
  margin: 0 0 var(--space-2);
}

/* Project rows: hairline between rows, italic title, small-caps link (P07) */
.index {
  margin-block-start: var(--space-5);
}

.index__row {
  padding-block: var(--space-4);
}

.index__row + .index__row {
  border-top: var(--rule-hair) solid var(--ink-rule);
}

.index__title {
  font-size: var(--text-lg);
  font-style: italic;
  line-height: var(--leading-tight);
}

.index__blurb {
  color: var(--ink-soft);
}

.index__link {
  font-size: var(--text-sm);
}

.index__link + .index__blurb {
  margin-inline-start: var(--space-3);
}

.index__group {
  margin-block-start: var(--space-7);
}

.index__note {
  font-size: var(--text-base);
  font-style: italic;
  color: var(--color-text-muted);
}

/* Buttons (§8.1) */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-block-size: 2.75rem; /* 44px touch target */
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  border: var(--rule-thin) solid currentColor;
  border-radius: var(--radius-1);
  background: transparent;
  color: var(--color-text);
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease-ink), color var(--dur-fast) var(--ease-ink);
}

.btn:hover {
  background: var(--ink);
  color: var(--paper-raised);
}

.btn--primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
}

.btn--primary:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--color-on-primary);
}

.licence-line {
  font-size: var(--text-sm);
  font-style: italic;
  color: var(--color-text-muted);
}

/* Footer: colophon with double rule on top (§8.10) */
.colophon {
  margin-block-start: var(--space-9);
  padding-block-end: var(--space-7);
  text-align: center;
}

/* One column for the colophon; the closing note in it is left-aligned */
.colophon__body {
  max-inline-size: 52ch;
  margin-inline: auto;
}

.colophon__closing {
  text-align: start;
}

.colophon__title {
  margin-block-end: var(--space-3);
}

.colophon__title .eyebrow {
  display: block;
  margin-block-end: var(--space-1);
}

.colophon .sprig {
  margin: var(--space-6) auto 0;
}

.colophon__note {
  margin-block-start: var(--space-4);
}

/* Left-aligned like the closing note, no hyphens */
.colophon__line {
  margin-block-start: var(--space-4);
  text-align: start;
  hyphens: manual;
}

.colophon__credits {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.colophon__year {
  margin-block-start: var(--space-2);
  color: var(--color-text-muted);
}

/* Rich ornament (skill §6.2). Each rule keys off [data-ornament="rich"] or the .orn-rich guard,
   so at the balanced level the same markup shows plain text and no extra drawings. */

/* Leafy corners: one set per framed plate, the top-left drawing mirrored for the other three.
   Each corner thickens the frame's two rules into a bold, square L (same positions and colours
   as .plate-frame::before: gilt outline 3px outside the ink hairline), with the plant inside. */
.corners {
  --corner-outer: 3px;   /* bold gilt rule over the frame outline */
  --corner-angle: 9px;   /* radius of the solid quarter circle in the angle of the inner rule */
  --corner-inner: 2px;   /* bold ink rule over the frame hairline; Firefox snaps 1.5px borders to 1px */
  position: absolute;
  inset: var(--frame-inset); /* the frame hairline's outer edge */
  pointer-events: none;
}

.corner {
  position: absolute;
  inline-size: var(--corner-size);
  block-size: var(--corner-size);
  color: var(--frame-ink); /* the plant matches the inner rule */
}

.corner:nth-child(1) { inset-block-start: 0; inset-inline-start: 0; }
.corner:nth-child(2) { inset-block-start: 0; inset-inline-end: 0; scale: -1 1; }
.corner:nth-child(3) { inset-block-end: 0; inset-inline-start: 0; scale: 1 -1; }
.corner:nth-child(4) { inset-block-end: 0; inset-inline-end: 0; scale: -1 -1; }

.corner::before,
.corner::after {
  content: "";
  position: absolute;
  inline-size: 100%;
  block-size: 100%;
  border-style: solid;
  border-width: 0;
}

/* Centred on the outline: 3px offset + half its width outside the hairline */
.corner::before {
  inset-block-start: calc(-3px - var(--rule-mid) / 2 - var(--corner-outer) / 2);
  inset-inline-start: calc(-3px - var(--rule-mid) / 2 - var(--corner-outer) / 2);
  border-block-start-width: var(--corner-outer);
  border-inline-start-width: var(--corner-outer);
  border-color: var(--ornament-gilt);
}

/* Centred on the hairline, with a solid quarter circle in the angle (centred on the outer corner) */
.corner::after {
  inset-block-start: calc(var(--rule-hair) / 2 - var(--corner-inner) / 2);
  inset-inline-start: calc(var(--rule-hair) / 2 - var(--corner-inner) / 2);
  border-block-start-width: var(--corner-inner);
  border-inline-start-width: var(--corner-inner);
  border-color: var(--frame-ink);
  background: radial-gradient(circle at 0 0, var(--frame-ink) var(--corner-angle), transparent calc(var(--corner-angle) + .5px))
    border-box 0 0 / var(--corner-angle) var(--corner-angle) no-repeat;
}

/* The curls start at (14, 14) in the 48-unit drawing. Offset the drawing so that point stays 8px
   inside the frame at every corner size (as on desktop), clear of the quarter circle */
.corner svg {
  --plant-offset: calc(8px - var(--corner-size) * 14 / 48);
  position: absolute;
  inset: var(--plant-offset) auto auto var(--plant-offset);
  inline-size: 100%;
  block-size: 100%;
  overflow: visible;
}

/* Room for the corners, so they frame the drawing and do not cover it */
[data-ornament="rich"] .plate-frame {
  padding: calc(var(--corner-size) + var(--space-3));
}

/* Ornamental frame: triple rule with gilt corner dots, on the specimen label */
[data-ornament="rich"] .ornate {
  position: relative;
}

[data-ornament="rich"] .ornate::before {
  content: "";
  position: absolute;
  inset: var(--frame-inset);
  border: var(--rule-mid) solid var(--ink-rule);
  box-shadow: inset 0 0 0 3px var(--paper-raised), inset 0 0 0 3.5px var(--ornament-gilt);
  pointer-events: none;
}

[data-ornament="rich"] .ornate::after {
  content: "";
  position: absolute;
  inset: calc(var(--frame-inset) - 3px);
  background:
    radial-gradient(circle, var(--ornament-gilt) 2.5px, transparent 3px) top left / 8px 8px no-repeat,
    radial-gradient(circle, var(--ornament-gilt) 2.5px, transparent 3px) top right / 8px 8px no-repeat,
    radial-gradient(circle, var(--ornament-gilt) 2.5px, transparent 3px) bottom left / 8px 8px no-repeat,
    radial-gradient(circle, var(--ornament-gilt) 2.5px, transparent 3px) bottom right / 8px 8px no-repeat;
  pointer-events: none;
}

[data-ornament="rich"] .specimen-label.ornate {
  padding: calc(var(--frame-inset) + var(--space-4)) calc(var(--frame-inset) + var(--space-5));
}

/* Initial: a plain madder drop cap, two lines tall, on the longer sections (§ I, § IV) */
[data-ornament="rich"] .initial {
  float: left;
  margin: .195em .1em -.1em 0; /* top: cap of line one; negative bottom keeps the float within two lines */
  font-family: var(--font-display);
  font-size: 3.25em;
  line-height: .8;
  color: var(--madder);
}

/* Tailpiece: closes each section text */
.tailpiece {
  display: block;
  inline-size: 96px;
  block-size: auto;
  margin: var(--space-7) auto 0;
  color: var(--ink-rule); /* same as the sprig */
}

/* Wreath around the year in the colophon */
[data-ornament="rich"] .colophon__year {
  display: grid;
  place-items: center;
  inline-size: fit-content;
  margin-inline: auto;
}

.colophon__year > * {
  grid-area: 1 / 1;
}

/* Smaller, tighter year so it fits between the arcs */
[data-ornament="rich"] .colophon__year > span {
  font-size: var(--text-xs);
  letter-spacing: .04em;
}

.wreath {
  inline-size: 96px;
  block-size: auto;
  color: var(--ink-rule); /* same as the sprig */
}

/* Garland: replaces the sprig and its hairlines between sections. Below 600px the sprig stays (§6.2) */
.garland {
  display: none;
}

@media (min-width: 37.5rem) {
  [data-ornament="rich"] .divider .garland {
    display: block;
    inline-size: min(100%, 640px);
    block-size: auto;
    margin-inline: auto;
    color: var(--ink-soft);
  }

  [data-ornament="rich"] .divider:not(.divider--header) .sprig,
  [data-ornament="rich"] .divider:not(.divider--header)::before,
  [data-ornament="rich"] .divider:not(.divider--header)::after {
    display: none;
  }
}

/* Tablet: larger toggle drawing and plate frame. The menu button stays until the spine appears */
@media (min-width: 48rem) {
  .theme-toggle {
    --toggle-art-size: 48px;
  }

  .plate-frame {
    padding: var(--space-7);
  }
}

/* Desktop: 12-column grid, facing pages. The hero is the first <section>,
   so odd sections (§II, §IV) put the text on the right. */
@media (min-width: 64rem) {
  .hero,
  .section {
    grid-template-columns: repeat(12, 1fr);
    column-gap: var(--gutter);
  }

  .divider {
    margin-block: var(--space-10);
  }

  .hero {
    align-items: center;
  }

  .section {
    --text-col: 1 / 6;
    --plate-col: 7 / 13;
    align-items: start;
  }

  .section:nth-of-type(odd) {
    --text-col: 8 / 13;
    --plate-col: 1 / 7;
  }

  .hero__text {
    grid-column: 1 / 6;
  }

  .hero .plate {
    grid-column: 7 / 13;
  }

  .section__text {
    grid-row: 1;
    grid-column: var(--text-col);
  }

  .section .plate {
    grid-row: 1;
    grid-column: var(--plate-col);
  }
}

/* The header divider straddles the bottom edge of the header: its hairline sits on the edge */
.divider--header {
  position: relative;
  z-index: 1;
  flex: none;
  inline-size: 100%;
  margin-block: calc(-1 * var(--space-3)) 0; /* half of the 24px sprig */
  pointer-events: none;
}

/* Sheet mode (class set by the head script unless reduced motion is on): the page does not scroll.
   Each section is a page of a bound book. A turned page swings away on its hinge and shows the next one:
   bottom to top on mobile (a notebook bound at the top), right to left on desktop (a book bound at the spine).
   Without the class, or without JS, the page is a normal scrolling document. */
.sheet-mode body {
  display: flex;
  flex-direction: column;
  block-size: 100dvh;
  overflow: hidden;
}

.sheet-mode .site-header {
  flex: none;
}

/* overflow: clip hides the lifted edge of a turning page where it leaves the stack */
.sheet-mode .sheet-stack {
  position: relative;
  flex: 1;
  min-block-size: 0;
  overflow: clip;
  isolation: isolate; /* the sheet z-index stays inside, under the spine divider */
  background: inherit; /* paper and grain for every sheet */
}

.sheet-mode main {
  display: contents; /* sections and footer become direct sheets of the stack */
  background: inherit;
}

.sheet-mode .divider:not(.divider--header) {
  display: none;
}

/* The script stacks earlier pages on top (z-index), so a page turns away to show the next one.
   --turn runs from 0 (flat) to 1 (turned): a turned page stops edge-on (90deg) and backface-visibility
   hides it there. --shade is 1 while a page lies under another one. During a wheel or swipe the script
   sets both inline, so the page follows the gesture. */
.sheet-mode .sheet {
  --turn: 0;
  --shade: 0;
  position: absolute;
  inset: 0;
  inline-size: auto;
  margin: 0;
  padding-block: var(--space-7);
  padding-inline: max(var(--gutter), (100% - var(--page-max)) / 2);
  overflow-y: auto; /* a tall sheet scrolls inside itself */
  overscroll-behavior: contain;
  align-content: start;
  background: inherit;
  transform: perspective(var(--turn-depth)) rotateX(calc(var(--turn) * 90deg));
  transform-origin: top; /* the notebook hinge */
  backface-visibility: hidden;
  filter: brightness(calc((1 - var(--turn) * .4) * (1 - var(--shade) * .15)));
}

.sheet-mode .sheet:focus {
  outline: none;
}

/* Light falls off as the page lifts; the page under it waits in its shadow */
.sheet-mode .sheet.is-turned {
  --turn: 1;
}

.sheet-mode .sheet[inert]:not(.is-turned) {
  --shade: 1;
}

.sheet-mode .colophon {
  display: flex;
  flex-direction: column;
}

/* margin: auto centres the colophon and falls back to the top when it overflows */
.sheet-mode .colophon > :first-child {
  margin-block-start: auto;
}

.sheet-mode .colophon > :last-child {
  margin-block-end: auto;
}

/* Pages turn sideways only on wide landscape screens; portrait screens always turn upwards */
@media (min-width: 48rem) and (orientation: landscape) {
  .sheet-mode .sheet {
    transform: perspective(var(--turn-depth)) rotateY(calc(var(--turn) * -90deg));
    transform-origin: left; /* the book spine */
  }
}

/* Desktop: the two-column sheets fit the page exactly. The plate takes the full row height
   and its image shrinks inside the frame; the text column scrolls only on a very short window. */
@media (min-width: 64rem) {
  .sheet-mode .hero.sheet,
  .sheet-mode .section.sheet {
    overflow-y: hidden;
    grid-template-rows: minmax(0, 1fr);
  }

  .sheet-mode .hero__text,
  .sheet-mode .section__text {
    align-self: center;
    max-block-size: 100%;
    overflow-y: auto;
  }

  /* Room for the arrow dip: a transform that leaves the box would add a scrollbar */
  .sheet-mode .hero__text {
    padding-block-end: var(--space-2);
  }

  .sheet-mode .plate {
    display: flex;
    flex-direction: column;
    block-size: 100%;
    min-block-size: 0;
  }

  .sheet-mode .plate img {
    flex: 1 1 0;
    min-block-size: 0;
    inline-size: 100%;
    object-fit: contain;
  }

  .sheet-mode .plate figcaption {
    flex: none;
  }
}

/* Desktop spine: the header becomes a fixed rail on the left, like the binding of a book whose
   pages turn in from the right. The links are written vertically. The rail is out of flow, so the
   body reserves its width for both the scrolling page and sheet mode. */
@media (min-width: 64rem) {
  :root {
    --spine-width: 5.5rem;
  }

  body {
    padding-inline-start: var(--spine-width);
  }

  .site-header,
  .sheet-mode .site-header {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    inline-size: var(--spine-width);
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-2);
    border: 0;
    background: var(--paper-sunken);
    overflow-y: auto; /* a very short window scrolls the rail instead of clipping it */
    scrollbar-width: none;
  }

  .theme-toggle {
    --toggle-art-size: 36px;
    flex-direction: column;
    gap: var(--space-1);
    margin-inline-start: 0;
  }

  .site-nav {
    display: block;
  }

  .menu-button,
  .menu,
  .menu:popover-open {
    display: none; /* the spine links replace the menu */
  }

  .site-nav__list {
    flex-direction: row; /* in vertical writing mode the row runs top to bottom */
    writing-mode: vertical-rl;
    gap: var(--space-4);
  }

  .site-nav a {
    font-size: var(--text-xs);
  }

  /* The links run top to bottom here: the mark runs vertically beside them (block-end is the left) */
  .site-nav a::after {
    background:
      radial-gradient(circle, currentColor var(--link-mark-dot), transparent calc(var(--link-mark-dot) + .5px)) center / .4em .4em no-repeat,
      linear-gradient(var(--link-mark-ink), var(--link-mark-ink)) center top / var(--rule-thin) calc(50% - var(--link-mark-gap)) no-repeat,
      linear-gradient(var(--link-mark-ink), var(--link-mark-ink)) center bottom / var(--rule-thin) calc(50% - var(--link-mark-gap)) no-repeat;
  }

  .site-nav__numeral::after {
    margin-inline-start: .2em;
  }

  /* The sprig divider runs down the edge of the rail, turned 90 degrees anticlockwise. It replaces the horizontal
     divider under the header. The sprig box is 48 x 24 px; its margin makes room for the turned shape. */
  .divider--header,
  .sheet-mode .divider--header {
    --sprig-turn-margin: calc((48px - 24px) / 2);
    position: fixed;
    inset-block: 0;
    inset-inline-start: calc(var(--spine-width) - 12px); /* the hairline sits on the rail edge */
    z-index: 1;
    display: flex;
    flex-direction: column;
    inline-size: 24px;
    margin: 0;
    pointer-events: none;
  }

  .divider--header::before,
  .divider--header::after {
    border-top: 0;
    border-inline-start: var(--rule-hair) solid currentColor;
  }

  .divider--header .sprig {
    rotate: -90deg; /* the bud is at the right end of the drawing, so it points up */
    margin-block: var(--sprig-turn-margin);
  }
}

/* Motion: "ink drying" (skill §9). Each element animates once; the start state needs JS (class "js") */
@media (prefers-reduced-motion: no-preference) {
  .theme-toggle__img,
  .theme-toggle__label {
    transition: opacity var(--dur-slow) var(--ease-ink), visibility var(--dur-slow) var(--ease-ink);
  }

  /* Menu panel: a page of the top-bound notebook turning back down into view, the reverse of a sheet turn.
     It opens and closes at the same pace. allow-discrete keeps the panel displayed while it turns away */
  .menu {
    transform: perspective(var(--turn-depth)) rotateX(90deg);
    transform-origin: top;
    backface-visibility: hidden;
    filter: brightness(.6);
    transition: transform var(--dur-turn) var(--ease-ink), filter var(--dur-turn) var(--ease-ink),
      display var(--dur-turn) allow-discrete, overlay var(--dur-turn) allow-discrete;
  }

  .menu:popover-open {
    transform: perspective(var(--turn-depth)) rotateX(0deg);
    filter: none;
  }

  @starting-style {
    .menu:popover-open {
      transform: perspective(var(--turn-depth)) rotateX(90deg);
      filter: brightness(.6);
    }
  }

  /* The arrow dips twice on load to hint that the page turns; it does not loop */
  .hero__arrow {
    display: inline-block;
    animation: arrow-dip var(--dur-slow) var(--ease-ink) 2 .6s;
  }

  @keyframes arrow-dip {
    50% {
      translate: 0 .3em;
    }
  }

  /* Pages turn at the same pace as the menu */
  .sheet-mode .sheet {
    transition: transform var(--dur-turn) var(--ease-ink), filter var(--dur-turn) var(--ease-ink);
  }

  /* While a gesture drives the page, it follows the gesture with no delay */
  .sheet-mode .sheet.is-scrubbing {
    transition: none;
  }

  .js .reveal {
    opacity: 0;
    translate: 0 8px;
    transition: opacity var(--dur-slow) var(--ease-ink), translate var(--dur-slow) var(--ease-ink);
  }

  .js .reveal.is-visible {
    opacity: 1;
    translate: 0 0;
  }

  /* The sprite paths use pathLength="1"; the dash values inherit through <use>.
     Dash "1 2" keeps the round caps from leaving a dot when the line is hidden. */
  .js .divider .sprig,
  .js .divider .garland {
    stroke-dasharray: 1 2;
    stroke-dashoffset: 1;
    fill-opacity: 0;
    transition: stroke-dashoffset var(--dur-slow) var(--ease-ink), fill-opacity var(--dur-slow) var(--ease-ink) var(--dur-slow);
  }

  .js .divider.is-visible .sprig,
  .js .divider.is-visible .garland {
    stroke-dashoffset: 0;
    fill-opacity: 1;
  }
}
