:root {
  --ink: #000;
  --paper: #fff;
  --faded: #5a5a5a;
  --typed: "Special Elite", "Courier Prime", "Courier New", Courier, monospace;
  --text: "Courier Prime", "Courier New", Courier, monospace;
  --gutter: clamp(20px, 5vw, 72px);
  --gap: clamp(16px, 2.4vw, 36px);
  --section: clamp(48px, 6vw, 84px);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--text);
  font-size: 1.0625rem;
  line-height: 1.62;
}

h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; font-weight: 400; }
ul, ol { padding: 0; list-style: none; }
img { display: block; max-width: 100%; height: auto; }

a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.22em; }
a:hover { text-decoration-thickness: 2px; }
a:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; }

.skip { position: absolute; left: var(--gutter); top: -100px; background: var(--ink); color: var(--paper); padding: 10px 14px; text-decoration: none; z-index: 10; }
.skip:focus { top: 12px; }

.sheet { max-width: 1180px; margin: 0 auto; padding: 0 var(--gutter); }

/* Top */

.top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 30px;
  padding-top: clamp(20px, 2.8vw, 34px);
  font-family: var(--typed);
}
.top a { text-decoration: none; }
.top a:hover,
.top .links a[aria-current] { text-decoration: underline; }
.top .links { display: flex; gap: 6px 30px; }

/* Header: a typed cover note */

.head {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gap);
  padding-top: clamp(44px, 7vw, 104px);
  padding-bottom: clamp(30px, 4vw, 52px);
  font-family: var(--typed);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 600 8' preserveAspectRatio='none'%3E%3Cpath d='M2 4.6c60-2.4 118 1.8 180-.4 70-2.4 131 2.2 204 .2 72-1.9 140 1.6 212-.9' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") bottom left / 100% 8px no-repeat;
}
.head > * { grid-column: 4 / -1; }
.head .kind { grid-column: 1 / span 3; align-self: start; padding-top: 0.5em; }
.head h1 {
  grid-row: 1;
  font-size: clamp(1.875rem, 4.4vw, 3.25rem);
  line-height: 1.12;
  letter-spacing: -0.015em;
  max-width: 22ch;
  text-wrap: balance;
}
.head .kind { grid-row: 1; }

.memo { margin-top: clamp(22px, 3vw, 36px); max-width: 62ch; }
.memo div { display: grid; grid-template-columns: 8.5em minmax(0, 1fr); column-gap: 1em; }
.memo div + div { margin-top: 2px; }
.memo dt { color: var(--faded); }

/* Document */

.doc { counter-reset: para; padding-bottom: 8px; }

.part {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gap);
  padding-top: var(--section);
}
.part > .flow { grid-column: 4 / -1; min-width: 0; }
.flow > * { max-width: 62ch; }
.part > h2 {
  grid-column: 1 / span 3;
  grid-row: 1;
  align-self: start;
  padding-right: 1.6rem;
  font-family: var(--typed);
  font-size: 1.125rem;
  line-height: 1.45;
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 0.3em;
  scroll-margin-top: 24px;
}
.flow > * + * { margin-top: 1.15em; }

.numbered .flow > p { position: relative; counter-increment: para; }
.numbered .flow > p::before {
  content: counter(para);
  position: absolute;
  right: calc(100% + 10px);
  top: 0.32em;
  font-family: var(--typed);
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--faded);
}

.doc em { font-style: italic; }
.doc strong { font-weight: 700; }

/* Source notes in the margin */

.ref { font-size: 0.72em; line-height: 0; vertical-align: 0.5em; padding-left: 1px; }
.ref a { text-decoration: none; }
.sidenote { display: none; }

.notelist { counter-reset: note; font-size: 0.9375rem; }
.notelist li { counter-increment: note; position: relative; padding-left: 2.4em; overflow-wrap: anywhere; }
.notelist li + li { margin-top: 0.5em; }
.notelist li::before { content: counter(note); position: absolute; left: 0; color: var(--faded); }
.notelist .back { color: var(--faded); font-size: 0.8125rem; white-space: nowrap; }

@media (min-width: 1000px) {
  .has-notes .part > .flow { grid-column: 4 / span 6; }
  .has-notes .part.sources > .flow { grid-column: 4 / -1; }
  .sidenote {
    display: block;
    float: right;
    clear: right;
    width: calc(50% - var(--gap) / 2);
    margin-right: calc(-50% - var(--gap) / 2);
    margin-bottom: 0.7em;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: var(--faded);
    overflow-wrap: anywhere;
  }
  .sidenote .sn { color: var(--ink); padding-right: 0.3em; }
  .part.endnotes { display: none; }
  .ref a { pointer-events: none; cursor: default; }
}

/* Sources */

.bib { padding-left: 2em; text-indent: -2em; overflow-wrap: anywhere; font-size: 0.9375rem; line-height: 1.55; }
.flow > .bib + .bib { margin-top: 0.9em; }
.annot, .annotauthor { margin-left: 2em; font-size: 0.9375rem; line-height: 1.55; color: var(--faded); }
.flow > .bib + .annot, .flow > .annot + .annotauthor, .flow > .bib + .annotauthor { margin-top: 0.3em; }
.section-authors { color: var(--faded); font-size: 0.9375rem; }
.flow > .section-authors + * { margin-top: 0.6em; }

/* Figures */

.figure img { width: min(100%, 340px); }
.figure p, .figure-held p { font-size: 0.875rem; line-height: 1.5; color: var(--faded); }
.figure p + p { margin-top: 10px; }
.figure-held { border: 1px dashed var(--ink); padding: 14px 16px; max-width: 46ch; }
.figure-held .held { display: block; color: var(--ink); }

.bio { border-top: 1px solid var(--ink); padding-top: 1.4em; font-size: 0.9375rem; line-height: 1.55; }
.bio img { width: 132px; margin-bottom: 1em; }
.bio p + p { margin-top: 1em; }

.poem img { width: min(100%, 522px); border: 1px solid var(--ink); }

/* A note written by pen */

.note { font-family: "Reenie Beanie", "Bradley Hand", "Segoe Print", cursive; font-size: clamp(2rem, 4.6vw, 2.75rem); line-height: 1.12; letter-spacing: 0.01em; max-width: 24em; }
.note p + p { margin-top: 0.55em; }
.note .sig { margin-top: 0.8em; text-align: right; padding-right: 1.5em; }

/* Letter */

.letterhead, .signoff { line-height: 1.5; }
.ps { margin-left: 2em; }
.ps-sub { margin-left: 4em; font-size: 0.9375rem; }
.flow > .ps + .ps, .flow > .ps + .ps-sub, .flow > .ps-sub + .ps-sub { margin-top: 0.6em; }
.signoff { margin-top: 2.2em !important; }

/* Journal */

.dedication { font-style: italic; }
.closing { margin-top: 2em !important; }
.flow > .closing + .closing { margin-top: 0.4em !important; }
.roll { line-height: 1.9; }

/* Bottom */

.next {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  column-gap: var(--gap);
  padding-top: var(--section);
  font-family: var(--typed);
}
.next p { grid-column: 4 / -1; }

footer {
  padding-top: var(--section);
  padding-bottom: clamp(28px, 4vw, 44px);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 32px;
  color: var(--faded);
  font-size: 0.9375rem;
  font-family: var(--typed);
}

@media (max-width: 820px) {
  .head > *, .head .kind, .part > .flow, .part > h2, .next p { grid-column: 1 / -1; }
  .head .kind { grid-row: auto; padding-top: 0; padding-bottom: 10px; color: var(--faded); }
  .head h1 { grid-row: auto; }
  .part > h2 { grid-row: auto; padding-right: 0; }
  .part > h2 + .flow { margin-top: 1em; }
  .numbered .flow > p::before { display: none; }
  .ps { margin-left: 1.2em; }
  .ps-sub { margin-left: 2.4em; }
}

@media (max-width: 520px) {
  body { font-size: 1rem; }
  .memo div { grid-template-columns: 6.5em minmax(0, 1fr); }
}

@media print {
  .top .links, .skip, .next { display: none; }
  .sidenote { display: none; }
  .part.endnotes { display: grid; }
}

:root { color-scheme: light only; }
html { -webkit-tap-highlight-color: rgba(0, 0, 0, 0.12); }
footer { align-items: center; row-gap: 0; }
footer .ends { display: flex; flex-wrap: wrap; gap: 0 28px; }
footer a, .top a { display: inline-block; padding: 11px 0; }
footer .views { flex-basis: 100%; max-width: 64ch; margin: 8px 0 0; font-size: 0.8125rem; line-height: 1.5; }
.top { row-gap: 0; padding-top: clamp(10px, 2vw, 24px); }
.top .links { gap: 0 26px; flex-wrap: wrap; }
.top .links a { padding-inline: 5px; margin-inline: -5px; }

/* Room for a thumb */
.next a, .memo a, .notelist .back { padding-block: 15px; }
.ref a { padding: 16px 17px; margin: 0 -16px; }
[id^="note-"], [id^="ref-"] { scroll-margin-top: 30vh; }
.notelist li:target { background: #f0f0f0; box-shadow: 0 0 0 8px #f0f0f0; }
@media (max-width: 820px) { .ref { font-size: 0.8em; } }
@media (max-width: 520px) { .top .links { gap: 0 18px; } }

/* Moving between pages: the new page comes up like a sheet fed into the roller.
   Off for visitors who ask their device for less motion. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root) { animation-duration: 0.16s; }
  ::view-transition-new(root) { animation: sheet-in 0.36s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
}
@keyframes sheet-in { from { opacity: 0; transform: translateY(10px); } }

/* Reading line: a pen line across the top of the window that is drawn as you read down the paper.
   Browsers that cannot tie an animation to scrolling simply do not show it. */
@supports (animation-timeline: scroll()) {
  @media screen and (prefers-reduced-motion: no-preference) {
    /* a strip of paper under the line, so the text slides beneath it instead of through it */
    body::before,
    body::after {
      content: "";
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 10px;
      z-index: 5;
      pointer-events: none;
    }
    body::before { background: var(--paper); }
    body::after {
      background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 600 8' preserveAspectRatio='none'%3E%3Cpath d='M2 4.6c60-2.4 118 1.8 180-.4 70-2.4 131 2.2 204 .2 72-1.9 140 1.6 212-.9' fill='none' stroke='%23000' stroke-width='1.8' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E") center / 100% 8px no-repeat;
      clip-path: inset(0 100% 0 0);
      animation: read-line linear both;
      animation-timeline: scroll(root block);
    }
  }
}
@keyframes read-line { to { clip-path: inset(0); } }
