/* Margin: one essay with its notes in the right margin.
   Type: Newsreader for every line of text. Its optical sizes do the work
   between 15px notes and a 68px title, so one family covers both.
   Alegreya SC for labels and dates, because it has drawn small caps and
   faked small caps (shrunken capitals) are the thing to avoid here.
   Color: Tufte's paper and ink, plus one red for what the eye should find:
   the drop cap and the note numbers, as in a rubricated manuscript.
   Radius: none. Shadow: none. Motion: none. */

:root {
  --paper: #fffff8;
  --ink: #161616;
  --red: #8a1c1c;
  --text: 34rem;
  --gap: 2.5rem;
  --note: 14rem;
  --serif: "Newsreader", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sc: "Alegreya SC", "Newsreader", Georgia, serif;
}

html {
  background: var(--paper);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.125rem, 0.95rem + 0.6vw, 1.25rem);
  line-height: 1.55;
  font-kerning: normal;
  font-variant-numeric: oldstyle-nums proportional-nums;
}

::selection { background: var(--red); color: var(--paper); }

a {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-color: var(--red);
  text-decoration-thickness: 1px;
  text-underline-offset: .18em;
}
a:hover { color: var(--red); }
:focus-visible { outline: 2px solid var(--red); outline-offset: 3px; }

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The page grid. Every band uses it; the margin column only exists at 60rem
   and up, where the notes can sit beside the line that calls them. */
.band {
  display: grid;
  grid-template-columns:
    [full-start] minmax(1.25rem, 1fr)
    [text-start] minmax(0, 36rem)
    [text-end note-start note-end] minmax(1.25rem, 1fr)
    [full-end];
}
.band > * { grid-column: text; }

@media (min-width: 60rem) {
  .band {
    grid-template-columns:
      [full-start] minmax(2rem, 1fr)
      [text-start] var(--text)
      [text-end] var(--gap)
      [note-start] var(--note)
      [note-end] minmax(2rem, 1fr)
      [full-end];
  }
}

/* Labels */
.site-name,
.site-head nav,
.dateline,
.tap-hint,
.more h2,
.about h2,
.essay-list time,
.colophon {
  font-family: var(--sc);
  font-weight: 400;
  letter-spacing: .04em;
  font-variant-numeric: oldstyle-nums;
}

/* Site header */
.site-head { padding-top: 1.4rem; align-items: baseline; }
.site-name {
  grid-row: 1;
  justify-self: start;
  margin: 0;
  font-size: 1.3rem;
  font-weight: 500;
}
.site-name a { text-decoration: none; }
.site-head nav { grid-row: 1; justify-self: end; font-size: 1.05rem; }
.site-head ul {
  display: flex;
  gap: 1.1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.site-head nav a { text-decoration: none; }
.site-head nav a:hover { text-decoration: underline; text-decoration-color: var(--red); }

@media (min-width: 60rem) {
  .site-head nav { grid-column: note; justify-self: start; }
}

/* Essay head */
.essay-head { padding-top: clamp(3rem, 9vw, 6.5rem); }
.dateline { margin: 0 0 .9rem; font-size: 1.05rem; }
h1 {
  margin: 0;
  font-size: clamp(2.6rem, 1.5rem + 4.4vw, 4.25rem);
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: -.012em;
  text-wrap: balance;
}
.dek {
  margin: 1.1rem 0 0;
  max-width: 30em;
  font-size: 1.3em;
  font-style: italic;
  line-height: 1.35;
  text-wrap: pretty;
}
.tap-hint { margin: 1.4rem 0 0; font-size: 1rem; }

@media (min-width: 60rem) {
  .essay-head { grid-column: text-start / note-end; }
  .dek { max-width: var(--text); }
  .tap-hint { display: none; }
}

/* Essay body: normal flow, so the floated notes stack against each other
   with clear: right and never overlap. */
.essay-body {
  counter-reset: sn;
  padding-top: 2.6rem;
  hyphens: auto;
  -webkit-hyphens: auto;
}
.essay-body p {
  margin: 0;
  text-wrap: pretty;
  /* Newsreader sets a narrow space; this opens sentence breaks slightly. */
  word-spacing: .04em;
}
.essay-body p + p { text-indent: 1.4em; }
.essay-body h2 {
  margin: 2.4rem 0 .5rem;
  font-size: 1.4em;
  font-style: italic;
  font-weight: 400;
  line-height: 1.2;
}

/* Three-line drop cap. The float is the fallback; initial-letter wins
   where the browser has it. */
.lead-in { font-family: var(--sc); letter-spacing: .03em; }
.lede::first-letter {
  float: left;
  margin: .19em .08em -.12em 0;
  font-family: var(--serif);
  font-size: 5.4em;
  font-weight: 400;
  line-height: .74;
  color: var(--red);
}
@supports (initial-letter: 3) or (-webkit-initial-letter: 3) {
  .lede::first-letter {
    float: none;
    margin: 0 .12em 0 0;
    font-size: inherit;
    line-height: inherit;
    -webkit-initial-letter: 3;
    initial-letter: 3;
  }
}

/* Sidenotes, numbered by a counter. */
.sn-toggle { display: none; }
.sn-ref { counter-increment: sn; }
.sn-ref::after {
  content: counter(sn);
  position: relative;
  top: -.5em;
  padding-left: .1em;
  font-size: .68em;
  font-weight: 600;
  font-variant-numeric: lining-nums;
  color: var(--red);
}
.sidenote {
  float: right;
  clear: right;
  width: var(--note);
  margin: .35rem calc(-1 * (var(--note) + var(--gap))) 1.2rem 0;
  font-size: .9375rem;
  line-height: 1.45;
  text-indent: 0;
  hyphens: manual;
  -webkit-hyphens: manual;
}
.sidenote::before {
  content: counter(sn) "\00a0\00a0";
  font-weight: 600;
  font-variant-numeric: lining-nums;
  color: var(--red);
}

/* Figure: image in the column, caption in the margin like a note. */
.fig { margin: 2rem 0; }
.fig img { display: block; width: 100%; height: auto; }
.fig figcaption {
  float: right;
  clear: right;
  width: var(--note);
  margin: 0 calc(-1 * (var(--note) + var(--gap))) 1rem 0;
  font-size: .9375rem;
  font-style: italic;
  line-height: 1.45;
}

/* Under 60rem: the Tufte checkbox. Notes stay hidden until their number
   is tapped, then open in the text below the line that called them. */
@media (max-width: 59.99rem) {
  .sn-toggle {
    display: inline;
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
  }
  .sn-ref {
    cursor: pointer;
    padding: .4em .25em;
    margin: -.4em -.25em;
  }
  .sn-ref::after { font-size: .78em; }
  .sn-toggle:focus-visible + .sn-ref { outline: 2px solid var(--red); outline-offset: 0; }
  .sidenote { display: none; }
  .sn-toggle:checked + .sn-ref + .sidenote {
    display: block;
    float: none;
    width: auto;
    margin: .7rem 0 .8rem;
    padding: .1rem 0 .1rem .9rem;
    border-left: 2px solid var(--red);
    font-size: 1rem;
  }
  .fig { display: flex; flex-direction: column-reverse; }
  .fig figcaption {
    float: none;
    width: auto;
    margin: .6rem 0 0;
  }
}

/* More essays: titles in the column, dates in the margin. */
.more { padding-top: 4.5rem; }
.more h2,
.about h2 {
  margin: 0 0 .9rem;
  padding-top: .7rem;
  border-top: 1px solid var(--ink);
  font-size: 1.15rem;
  font-weight: 500;
}
.essay-list { margin: 0; padding: 0; list-style: none; }
.essay-list li { padding: .5rem 0; }
.essay-list a { font-size: 1.15em; line-height: 1.3; }
.essay-list time { display: block; font-size: 1rem; }

@media (min-width: 60rem) {
  .more > *,
  .about h2 { grid-column: text-start / note-end; }
  .essay-list li {
    display: grid;
    grid-template-columns: var(--text) var(--note);
    column-gap: var(--gap);
    align-items: baseline;
  }
}

.about { padding-top: 3.5rem; }
.about p { margin: 0; overflow-wrap: break-word; }

/* Footer */
.site-foot { padding: 5rem 0 2.5rem; font-size: .9375rem; }
.site-foot p { margin: 0 0 .3rem; }
.sample { font-style: italic; }
