/* Finally Digital. One ink, one paper, one sentence. */

/* Fonts. Built by tools/build-fonts.py; both families are OFL (see /fonts). */

@font-face {
  font-family: "Newsreader";
  src: url("/fonts/newsreader.woff2") format("woff2");
  font-weight: 400 500;
  font-style: normal;
  font-display: swap;
}

/* Italic 500 with only the letters of "Finally". Used by the wordmark and nothing else. */
@font-face {
  font-family: "Newsreader Wordmark";
  src: url("/fonts/newsreader-wordmark.woff2") format("woff2");
  font-weight: 500;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Instrument Sans";
  src: url("/fonts/instrument-sans.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}

/* System fonts resized to the web fonts' metrics, so text barely moves when they load.
   Georgia and Arial are on Apple and Windows; Android has neither and uses Noto Serif.
   Newsreader is narrower at reading sizes than at display sizes, so running text gets
   its own, smaller, pair. */

@font-face {
  font-family: "Newsreader Fallback";
  src: local("Georgia");
  size-adjust: 96.12%;
  ascent-override: 76.47%;
  descent-override: 27.57%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Newsreader Fallback Noto";
  src: local("Noto Serif"), local("NotoSerif"), local("Noto Serif Regular"), local("NotoSerif-Regular");
  size-adjust: 89%;
  ascent-override: 82.58%;
  descent-override: 29.78%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Newsreader Text Fallback";
  src: local("Georgia");
  size-adjust: 91.5%;
  ascent-override: 80.33%;
  descent-override: 28.96%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Newsreader Text Fallback Noto";
  src: local("Noto Serif"), local("NotoSerif"), local("Noto Serif Regular"), local("NotoSerif-Regular");
  size-adjust: 84.5%;
  ascent-override: 86.99%;
  descent-override: 31.36%;
  line-gap-override: 0%;
}

@font-face {
  font-family: "Instrument Sans Fallback";
  src: local("Arial");
  size-adjust: 102.74%;
  ascent-override: 94.42%;
  descent-override: 24.33%;
  line-gap-override: 0%;
}

:root {
  --paper: #f4f2ec;
  --ink: #1230c4;
  --ink-soft: rgba(18, 48, 196, 0.32);
  --paper-soft: rgba(244, 242, 236, 0.36);

  --serif: "Newsreader", "Newsreader Fallback", "Newsreader Fallback Noto", Georgia, "Times New Roman", serif;
  --serif-text: "Newsreader", "Newsreader Text Fallback", "Newsreader Text Fallback Noto", Georgia,
    "Times New Roman", serif;
  --sans: "Instrument Sans", "Instrument Sans Fallback", system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;

  --gutter: clamp(1.25rem, 3.4vw, 3.5rem);
  --gap: clamp(1rem, 2vw, 2rem);
  --wide: 100rem;
  --masthead: clamp(4.25rem, 1.75rem + 4.8vw, 5.75rem);
  --screen: 100vh;
}

/* Where the browser can tell, the height of the screen with its toolbars showing. */
@supports (height: 100svh) {
  :root {
    --screen: 100svh;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Room around whatever is scrolled into view, so a focus ring is never cut by the window. */
  scroll-padding-top: 1.5rem;
  scroll-padding-bottom: 1.5rem;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.1875rem;
  line-height: 1.45;
  font-optical-sizing: auto;
  /* Only real cuts: the site ships roman 400-500, so nothing is faked bold or slanted. */
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1,
h2,
p,
ol {
  margin: 0;
  padding: 0;
  font-weight: 400;
}

ol {
  list-style: none;
}

a {
  color: inherit;
}

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

:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
  border-radius: 2px;
}

.skip {
  position: absolute;
  /* The same left edge as the page frame, so it sits over the wordmark. */
  left: max(var(--gutter), (100% - var(--wide)) / 2);
  top: 0.75rem;
  z-index: 1;
  padding: 0.6rem 0.8rem;
  background: var(--ink);
  color: var(--paper);
  font: 500 0.875rem/1 var(--sans);
  text-decoration: none;
  transform: translateY(-300%);
}

.skip:focus {
  transform: none;
}

/* While it shows, the skip link stands in for the wordmark underneath it. On a narrow
   screen, enlarged text can bring "Contact" under it as well. */
@media screen {
  .skip:focus + .masthead .wordmark {
    opacity: 0;
  }
}

@media screen and (max-width: 40em) {
  .skip:focus + .masthead .masthead__link {
    opacity: 0;
  }
}

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

/* Page frame: one gutter, one maximum width, shared by every band. */

.masthead,
.statement,
.notes,
.contact,
.foot {
  padding-inline: max(var(--gutter), (100% - var(--wide)) / 2);
}

/* On a screen taller than the page, the contact band grows and the footer sits on the bottom edge. */
@media screen {
  body {
    display: flex;
    flex-direction: column;
    min-height: var(--screen);
  }

  main {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
  }

  .contact {
    flex-grow: 1;
  }
}

/* The skip link and the return arrows land here. A screen's worth of margin takes the
   page back to the very top, however tall the masthead is. */
main {
  scroll-margin-top: var(--screen);
}

/* Lets the two fitted lines (the sentence, the address) size themselves from the column. */
.measure {
  container-type: inline-size;
}

/* First screen: masthead on top, the sentence resting on the bottom edge. */

.masthead {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1.5rem;
  min-height: var(--masthead);
  /* Only shows when the two links wrap onto two rows: enlarged text, or a window under 255px. */
  padding-block: 0.5rem;
}

.wordmark {
  font-size: 1.4375rem;
  font-weight: 500;
  font-variation-settings: "opsz" 30;
  letter-spacing: -0.012em;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.wordmark em {
  font-family: "Newsreader Wordmark", var(--serif);
  font-style: italic;
}

.masthead__link {
  font: 500 0.9375rem/1 var(--sans);
  text-decoration: none;
  padding-block: 0.4rem;
  background: linear-gradient(currentColor, currentColor) 0 100% / 100% 1px no-repeat;
  transition: background-size 0.3s ease;
}

.masthead__link:hover {
  background-position: 100% 100%;
  background-size: 0 1px;
}

.statement {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: end;
  /* Masthead plus sentence stop short of the full screen, so the first note shows underneath. */
  min-height: calc(min(var(--screen) - 5.5rem, 54rem) - var(--masthead));
  padding-block: clamp(2.5rem, 8vh, 5rem) clamp(1.75rem, 5vh, 3.5rem);
}

/* The 404 has one short note and nothing after it: keep all of it on the first screen. */
.statement--alone {
  min-height: calc(min(var(--screen) - 14.5rem, 54rem) - var(--masthead));
}

.statement h1 {
  /* Sized from the width, held back by the height so a phone on its side shows the whole sentence. */
  font-size: clamp(2.125rem, min(12.4vw, var(--screen) * 0.13), 5.25rem);
  line-height: 1;
  letter-spacing: -0.024em;
  overflow-wrap: break-word;
  text-wrap: balance;
}

.br {
  display: none;
}

/* On wide screens and on paper the sentence is set in three lines. The middle one is
   12.35em wide at the largest optical size, so dividing the column by 12.4 takes it to
   the right edge. Half a gutter of extra room keeps a line that some renderer measures a
   little wider from wrapping; enlarged text still wraps instead of running off the page. */
@media print, (min-width: 60em) {
  .statement h1 {
    margin-inline-end: calc(var(--gutter) / -2);
    font-size: min(6.9vw, 8rem);
    font-size: calc(100cqi / 12.4);
    font-variation-settings: "opsz" 72;
    text-wrap: initial;
  }

  .br {
    display: inline;
  }
}

/* Each numbered phrase is a link to its note. */
.statement a {
  text-decoration: none;
  padding-inline: 0.05em;
  margin-inline: -0.05em;
  border-radius: 0.04em;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* The inversion is the focus indicator. The outline is kept, transparent, because
   contrast themes drop the two colors and draw the outline instead. */
.statement a:hover,
.statement a:focus-visible {
  background: var(--ink);
  color: var(--paper);
  outline-color: transparent;
}

.ref {
  margin-left: 0.04em;
  letter-spacing: 0;
}

/* The note numbers are drawn by the stylesheet, so selecting, copying or searching
   the sentence never picks them up. */
.ref::after {
  content: attr(data-n);
}

/* The sentence is there on arrival. Its three notes are added a beat later. */
@keyframes annotate {
  from {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .ref {
    animation: annotate 0.5s ease-out 0.95s both;
  }

  a:nth-of-type(1) > .ref {
    animation-delay: 0.55s;
  }

  a:nth-of-type(2) > .ref {
    animation-delay: 0.75s;
  }
}

/* Notes */

.notes {
  padding-bottom: clamp(1.5rem, 4vw, 3.5rem);
}

.note {
  display: grid;
  grid-template-columns: 1.5rem minmax(0, 1fr);
  column-gap: 0.5rem;
  row-gap: 0.875rem;
  padding-block: 1.5rem 2.75rem;
  border-top: 1px solid var(--ink);
}

.note__n {
  justify-self: start;
  align-self: start;
  margin-top: 0.42rem;
  font-size: 1.0625rem;
  line-height: 1;
}

.note__title {
  font-size: clamp(1.875rem, 1.3rem + 2.4vw, 3.25rem);
  line-height: 1.04;
  letter-spacing: -0.018em;
  overflow-wrap: break-word;
  text-wrap: balance;
}

.note__title a {
  text-decoration-thickness: 0.04em;
  text-underline-offset: 0.14em;
}

.note__body {
  grid-column: 2;
  max-width: 32.5em;
  font-family: var(--serif-text);
}

/* Even lines, so a note never ends in a two-word stub. */
.note__body p {
  text-wrap: balance;
}

/* Keeps the return arrow on the same line as the last words of its note. */
.nowrap {
  white-space: nowrap;
}

/* The return arrow at the end of a note, as in a book's endnotes. */
.note__back {
  display: inline-block;
  /* Padding with matching negative margin: a finger-sized target that takes no extra room. */
  padding: 0.4em;
  margin: -0.4em -0.4em -0.4em -0.25em;
  line-height: 0;
  vertical-align: -0.12em;
  opacity: 0.6;
  transition: opacity 0.15s ease;
}

.note__back:hover,
.note__back:focus-visible {
  opacity: 1;
}

.note__back svg {
  width: 0.95em;
  height: 0.95em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (min-width: 60em) {
  .note {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    column-gap: var(--gap);
    padding-block: 2rem 5rem;
  }

  .note__n {
    grid-column: 1;
    margin-top: 0.5rem;
    font-size: 1.25rem;
  }

  .note__title {
    grid-column: 2 / span 5;
    /* A long title takes two lines instead of running up to the text beside it. */
    max-width: 10em;
  }

  .note__body {
    grid-column: 7 / -1;
    padding-top: 0.3rem;
    font-size: 1.4375rem;
    line-height: 1.42;
  }
}

/* Arriving at a note from the sentence marks its number for a moment. */
@keyframes mark {
  0%,
  55% {
    background: var(--ink);
    box-shadow: 0 0 0 0.3em var(--ink);
    color: var(--paper);
  }
}

.note:target .note__n {
  animation: mark 1.8s ease-out;
}

/* Contact: the same two colors, reversed. */

.contact,
.foot {
  background: var(--ink);
  color: var(--paper);
}

.contact {
  padding-block: clamp(3.5rem, 9vw, 8rem) clamp(4rem, 10vw, 9rem);
}

.contact ::selection,
.foot ::selection {
  background: var(--paper);
  color: var(--ink);
}

.contact__label {
  font: 500 0.9375rem/1 var(--sans);
}

.contact__email {
  margin-top: clamp(0.75rem, 1.6vw, 1.5rem);
  /* The address is 11.41em wide at this optical size, so dividing the column by 11.46 makes
     it fill the line. As with the sentence, half a gutter of extra room keeps it on one line
     if a renderer measures it a little wider; enlarged text wraps and stays inside the band. */
  margin-inline-end: calc(var(--gutter) / -2);
  font-size: min(7.6vw, 8.7rem);
  font-size: calc(100cqi / 11.46);
  font-variation-settings: "opsz" 72;
  line-height: 1.1;
  letter-spacing: -0.02em;
  overflow-wrap: break-word;
  /* If it does wrap, prefer "hello@" over a lone ".com" on a line. */
  text-wrap: balance;
}

/* A real underline, so it steps around the descenders of g and y. */
.contact__email a {
  text-decoration-line: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: 0.03em;
  text-underline-offset: 0.1em;
  transition: text-decoration-color 0.2s ease;
}

.contact__email a:hover,
.contact__email a:focus-visible {
  text-decoration-color: currentColor;
}

.contact__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-top: clamp(1.25rem, 2.4vw, 2.25rem);
}

.contact__note {
  max-width: 30em;
  font-family: var(--serif-text);
  text-wrap: balance;
}

.copy {
  appearance: none;
  padding: 0.7rem 1.1rem;
  border: 1px solid var(--paper);
  border-radius: 999px;
  background: none;
  color: inherit;
  font: 500 0.875rem/1 var(--sans);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.copy[data-state="done"] {
  background: var(--paper);
  color: var(--ink);
}

/* Only where there is a pointer: on a touch screen the hover look would stick after a tap. */
@media (hover: hover) {
  .copy:hover {
    background: var(--paper);
    color: var(--ink);
  }
}

/* The ring stays paper while the button itself turns paper and its text ink. */
.copy:focus-visible {
  outline-color: var(--paper);
}

.colophon {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: "copy top" "where where";
  gap: 0.35rem 2rem;
  padding-block: 1.25rem 1.5rem;
  border-top: 1px solid var(--paper-soft);
  font: 400 0.875rem/1.4 var(--sans);
}

.colophon__copy {
  grid-area: copy;
}

.colophon__where {
  grid-area: where;
}

.colophon__top {
  grid-area: top;
}

.colophon a {
  display: inline-block;
  padding-block: 0.3rem;
  margin-block: -0.3rem;
  text-decoration: none;
}

.colophon a:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

@media (min-width: 40em) {
  .colophon {
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas: "copy where top";
  }

  .colophon__top {
    justify-self: end;
  }
}

/* Motion */

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* On paper it is still one page: the sentence in its three lines (see above), white paper,
   no controls. It fits one A4 or Letter sheet at a browser's usual margins. */

@media print {
  :root {
    --paper: #fff;
  }

  /* A fixed size: paper does not follow the reader's screen font setting. */
  html {
    font-size: 8.4pt;
  }

  .statement {
    min-height: 0;
    padding-block: 2.5rem 1.75rem;
  }

  .skip,
  .masthead__link,
  .note__back,
  .copy,
  .colophon__top {
    display: none !important;
  }

  .ref {
    animation: none;
  }

  .note {
    break-inside: avoid;
    padding-block: 1.125rem 1.75rem;
  }

  .contact,
  .foot {
    background: none;
    color: var(--ink);
  }

  .contact {
    padding-block: 0 2rem;
    break-inside: avoid;
  }

  .contact__label {
    padding-top: 1.25rem;
    border-top: 1px solid var(--ink);
  }

  .colophon {
    border-top-color: var(--ink-soft);
  }
}
