/* The palette, type, paper and pen marks the site is drawn with. The font, the paper, the marker's grain and
   the smudges are most of what a visit downloads, so browsers keep them for a year without asking again
   (vercel.json): a changed one needs a new file name, or visitors keep the old one. */

/* Inter: Google Fonts' Latin cut (v20), the variable font with every weight, hosted here, less the glyphs no
   character in its unicode-range below can reach (pyftsubset, every feature kept). Each page preloads
   it in its <head>, and with font-display: optional Chrome holds the first paint up to about 100ms for a
   preloaded font. So a reload shows the page in Inter straight away, never a frame in the fallback first.
   If it's ever later than that, that visit stays in the fallback, which never swaps and is sized to match.
   Safari has no such hold, and optional would leave a first visit in the fallback, so it swaps instead.
   It goes by a name of its own, not 'Inter': extensions add their own Inter to every page (Grammarly adds
   one at each fixed weight), and Chrome would draw text that lands on exactly one of those weights in
   theirs, swapping it in mid-animation the first time.
   Inter is copyright The Inter Project Authors (https://github.com/rsms/inter), under the SIL Open Font
   License 1.1 (https://openfontlicense.org). A new version gets a new file name, since it's cached for good. */
@font-face {
  font-family: 'alvi.sh Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: optional;
  src: url('/kit/inter-latin-v20.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@supports (font: -apple-system-body) {
  @font-face {
    font-family: 'alvi.sh Inter';
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
    src: url('/kit/inter-latin-v20.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  }
}

/* Arial, sized and spaced to take up Inter's room, so text set in it lines up the same */
@font-face {
  font-family: 'alvi.sh Inter fallback';
  font-style: normal;
  font-weight: 100 900;
  src: local('Arial');
  size-adjust: 107.06%;
  ascent-override: 90.49%;
  descent-override: 22.56%;
  line-gap-override: 0%;
}

:root {
  /* General */
  --color-accent: #009966;
  --color-background: #FAFAF8;
  --color-tile: #F2F2F0;
  --color-tile-dark: #094531;
  --color-white: #FFFFFF;
  --color-border: #C2C6D1;
  --color-highlight: #94FBD7;
  --color-focus: #64D19C;

  /* Text */
  --color-text-primary: #2B3A67;
  --color-text-secondary: #646E86;
  --color-text-tertiary: #7A849D;
  --color-text-accent: #007A52;

  /* Derived */
  --color-ring: color-mix(in srgb, var(--color-text-primary) 16%, transparent);
  /* The text's ink thinned right down, for selected text. Mixed with white, not see-through, because the
     strokes multiply over the page, which comes out the same and gives the streaks a solid color to work from. */
  --color-selection: color-mix(in srgb, var(--color-text-primary) 20%, white);
  /* For the marks a layout draws on its own content (kit/sketch.js). Pencil is for asides, so it's
     the tertiary grey. Tape is paper tape, multiplied, so whatever it's stuck over shows through. */
  --color-pencil: var(--color-text-tertiary);
  /* A red pen, for what's put in afterwards: warm, a little soft, so it sits with the blue-black ink, and dark
     enough to read at 4.5:1 */
  --color-red-pen: #CC4139;
  --color-tape: #EAE4D3;
  --color-redact: color-mix(in srgb, var(--color-text-primary) 90%, var(--color-background));

  /* Heading type */
  --font-display: var(--font-body);
  --font-weight-display: 600;
  --letter-spacing-display: -0.02em;

  /* Body type */
  --font-body: 'alvi.sh Inter', 'alvi.sh Inter fallback', sans-serif;
  --font-size-body: 16px;
  --line-height-body: 24px;
  --letter-spacing-body: -0.01em;
  --font-weight-body: 500;

  /* Small body type */
  --font-size-small: 14px;
  --line-height-small: 20px;
  --letter-spacing-small: 0;

  /* Ink bleed for text written on the paper, and the same grown for 24px titles and 36px display type */
  --ink: url(#ink);
  --ink-title: url(#ink-title);
  --ink-display: url(#ink-display);
  --ink-marker: url(#ink-marker);
}

/* WebKit (Safari, and every browser on an iPhone) works these filters out in software at 1x, so the ink
   edge comes out pixelated on a sharp screen, and it's redone whenever anything near it is redrawn. So
   there kit/ink-gl.js draws the ink on the GPU, and the page is drawn at twice the size and scaled back
   down, which keeps anything still on the filter sharp. Without WebGL, the text takes the paper's grain
   instead, picked out by kit/ink.js, and the drawings keep the filter. Only WebKit knows the
   -apple-system-body font. The paper moves to the root, or it would be drawn at twice the size too.
   A page with fixed parts would need them outside the body. */
@supports (font: -apple-system-body) {
  html {
    background: url('/kit/paper.png') 0 0 / 512px 512px, var(--color-background);
  }

  html body {
    zoom: 2;
    transform: scale(0.5);
    transform-origin: 0 0;
    width: 200%;
    min-height: 200%;
    background: none;
  }

  /* Text, and the selection strokes over it, without the filter: kit/ink-gl.js inks them, or the grain
     takes over. Drawings keep it, for any kit/ink-gl.js can't draw. */
  :root:root {
    --ink: none;
    --ink-title: none;
    --ink-display: none;
  }

  svg {
    --ink: url(#ink);
  }

  /* The text's ink, drawn by kit/ink-gl.js into canvases over it, under the selection's strokes. The text
     itself stays, see-through, to be selected, copied and read out. */
  .ink-gl-layer {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 3;
    pointer-events: none;
  }

  .ink-gl-canvas {
    position: absolute;
    pointer-events: none;
  }

  /* The drawings too, each into a canvas beside its SVG, which stays, unseen, as the drawing. A button's words
     into one inside them, so it moves with the face. */
  .ink-gl-drawn {
    visibility: hidden;
  }

  .btn-drawn > span.ink-gl {
    position: relative;
  }

  /* And the highlighter strokes, a link's and selected text's, which Chrome inks with the words */
  a.link.ink-gl-stroke::after,
  .selection-marks.ink-gl-marked > div > div {
    visibility: hidden;
  }

  .ink-gl,
  .ink-gl * {
    -webkit-text-fill-color: transparent;
  }

  .ink-gl a.link > span {
    background: none;
  }

  /* Without WebGL, the ink thins where the sheet is raised, the way the marker does */
  .ink-grain {
    mask: url('/kit/marker-grain.png') 0 0 / 512px 512px;
  }

  /* A mask stops at its element's edge, so text past it is cut off. Words added over a line reach above
     their paragraph, and the heading, trimmed to its capitals and baseline, has round letters that dip just
     under the line, and tails below it. So these reach out over their text, the room taken back so nothing moves. */
  .ink-grain:has(.mark-insert) {
    padding-top: 24px;
    margin-top: -24px;
  }

  .hero-heading.ink-grain {
    padding-block: 0.3em;
    margin-block: -0.3em;
  }
}

html {
  height: 100%;
  overscroll-behavior: none;
  /* Phones enlarge text they take to be in a column too wide to read. In WebKit the page is drawn at twice
     its size (above), so an iPhone would take every paragraph for one twice the screen's width and set it
     that way: smaller letters, lines far apart. The page is laid out for the phone, so its text stays as set. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* The paper tile, which scrolls with the page like a real sheet */
body {
  margin: 0;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  font-family: var(--font-body);
  font-weight: var(--font-weight-body);
  color: var(--color-text-primary);
  background-color: var(--color-background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: var(--font-size-body);
  line-height: var(--line-height-body);
  letter-spacing: var(--letter-spacing-body);
  background-image: url('/kit/paper.png');
  background-size: 512px 512px;
}

body::before,
body::after {
  content: none;
}

/* How far the stroke has moved off the link on hover. Registered so it can transition. */
@property --link-wipe {
  syntax: '<percentage>';
  inherits: true;
  initial-value: 0%;
}

a.link,
a.link:visited {
  position: relative;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: inherit;
  line-height: inherit;
  white-space: nowrap;
  text-decoration: none;
  font-feature-settings: 'zero';
  color: var(--color-text-primary);
  padding-bottom: 0;
  isolation: isolate;
  transition: --link-wipe 0.35s ease-in-out;
}

a.link:hover,
a.link:focus-visible {
  --link-wipe: 100%;
}

/* 4px more to hit on every side, without moving anything */
a.link::before {
  content: '';
  position: absolute;
  inset: -4px;
}

/* A marker stroke behind the link instead of an underline: the brush (kit/highlight.svg), stretched to fit.
   Keep it opaque, because the ink filter around the text drops anything see-through.
   So the paper shows through as color instead: the paper tile multiplied by the highlight and its
   streaks, which kit/sketch.js draws for each link. */
a.link::after,
a.link:hover::after {
  content: '';
  position: absolute;
  z-index: -1;
  top: calc(50% - 7.25px);
  bottom: auto;
  left: -2.5px;
  width: calc(100% + 2px);
  height: 18px;
  background:
    url('/kit/paper.png') 0 0 / 512px 512px,
    var(--streaks, none) 0 0 / 100% 100% no-repeat,
    var(--color-highlight);
  background-blend-mode: multiply, normal;
  mask: url('/kit/highlight.svg') 0 0 / 100% 100% no-repeat;
  clip-path: inset(0 0 0 var(--link-wipe));
}

/* Selected text gets a highlighter stroke a line, drawn by kit/sketch.js, so the browser's own fill
   only goes once the script is there to draw them. They sit over the page and multiply, like ink over print. */
.drawn-selection ::selection {
  background: transparent;
}

.selection-marks {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 4;
  pointer-events: none;
  mix-blend-mode: multiply;
}

/* Each line: the letters' ink edge round the outside, then the brush's shape and the line's streaks */
.selection-marks > div {
  position: absolute;
  transform-origin: 0 50%;
  filter: var(--ink);
}

.selection-marks > div > div {
  height: 100%;
  background-color: var(--color-selection);
  background-repeat: repeat-x;
  mask: url('/kit/highlight.svg') 0 0 / 100% 100% no-repeat;
}

/* Only the brush's middle stretches with the line. Its frayed start (the first 5 of its 75 units) and dry end
   (the last 12) stay the size they're drawn at, so a drag lengthens the stroke from its tip, like a
   highlighter, and a long line's first letters aren't left in a long faint start. --brush is the line's px
   per unit of the brush, from kit/sketch.js. Firefox has no 9-slice mask and keeps the whole brush stretched. */
@supports (-webkit-mask-box-image: none) {
  .selection-marks > div > div {
    mask: none;
    -webkit-mask-box-image: url('/kit/highlight.svg') 0 12 0 5 / 0 calc(12 * var(--brush)) 0 calc(5 * var(--brush)) stretch;
  }
}

/* Drawn by kit/sketch.js. The default outline stays if the script doesn't run. */
:has(> .focus-ring) {
  outline: none;
}

/* The box is the element's own, and the loop is drawn out past it.
   Multiplied, like ink: darker where it runs over a button or a letter, not painted on top. */
.focus-ring {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  mix-blend-mode: multiply;
}

/* The color under the paper in its fill (kit/sketch.js) */
.focus-ring rect {
  fill: var(--color-focus);
}

.focus-ring image {
  mix-blend-mode: multiply;
}

/* Pen, not marker, so it takes the letters' ink edge. The second time round goes over the first. */
.focus-ring path {
  filter: var(--ink);
}

.focus-ring path + path {
  mix-blend-mode: multiply;
}

/* Marks a layout makes on its own content, drawn by kit/sketch.js: a line through a draft, a loop round
   a pick, a cross, an arrow, contents dots, tape, album corners and freehand rules. Like the focus ring,
   each sits in its element's box, draws out past it where it needs to and multiplies like ink. */
.mark-strike,
.mark-arrow,
.mark-leader,
.mark-tape,
.mark-rule {
  position: relative;
}

.mark {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  mix-blend-mode: multiply;
}

.mark-pen rect {
  fill: var(--color-text-primary);
}

.mark-pen image {
  mix-blend-mode: multiply;
}

.mark-pen path {
  filter: var(--ink);
}

.mark-pen path + path {
  mix-blend-mode: multiply;
}

/* Pencil: grey, and it skips over the paper's raised grain */
.mark-pencil > .mark {
  mask: url('/kit/marker-grain.png') 0 0 / 512px 512px;
}

.mark-pencil > .mark rect {
  fill: var(--color-pencil);
}

/* Paper tape, so no ink edge */
.mark-tape > .mark rect {
  fill: var(--color-tape);
}

.mark-tape > .mark path {
  filter: none;
}

.mark-rule {
  display: block;
  height: 2px;
}

/* A name blacked out with a marker, for clients under NDA: the links' brush, in ink. The name under it
   is a stand-in, never the real one, and it can't be selected or copied. */
.mark-redact {
  position: relative;
  isolation: isolate;
  color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.mark-redact::after {
  content: '';
  position: absolute;
  z-index: -1;
  top: calc(50% - 7.25px);
  left: -2.5px;
  width: calc(100% + 5px);
  height: 18px;
  background: url('/kit/paper.png') 0 0 / 512px 512px, var(--color-redact);
  background-blend-mode: multiply;
  mask: url('/kit/highlight.svg') 0 0 / 100% 100% no-repeat;
}

/* Words added after it was written, as in notes: a caret in the gap and the words written in above it, in
   red pen and a little askew. They're in the line in the markup, between two spaces,
   <ins class="mark-insert"><span class="mark-written">the words</span></ins>, so they're read and copied
   where they go. The caret stands in the middle of the gap, which stays one word space: the box is a
   hairline from the line up 1em, pulled back by half a space on each side, so the two spaces round it
   overlap. 0.257em is Inter's word space with the body's tracking. kit/sketch.js draws the caret from the
   box, its feet under the line. */
.mark-insert {
  position: relative;
  display: inline-block;
  width: 1px;
  height: 1em;
  margin-inline: calc((1px + 0.257em) / -2);
  text-decoration: none;
}

.mark-insert > span {
  position: absolute;
  bottom: calc(100% - 1px);
  left: 50%;
  translate: -50% 0;
  rotate: -2deg;
  white-space: nowrap;
  /* Its own weight, so it doesn't thicken with the line under it while Bloom fills that, which would
     have the words drawn again every frame */
  font-weight: var(--font-weight-body);
  font-size: var(--font-size-small);
  line-height: var(--line-height-small);
  letter-spacing: var(--letter-spacing-small);
}

.mark-insert > .mark rect,
.mark-written > .mark rect {
  fill: var(--color-red-pen);
}

/* Words written by hand over their own text (kit/sketch.js), which goes clear once they're drawn, so it's
   only there to read and copy. Only letters the hand has; anything else stays in type. */
.mark-written[data-written] {
  color: transparent;
}

/* The pen's path through them, which shows the strokes as far as it's got: all of them, unless Bloom is
   writing them out (kit/bloom.css). Each run's share of the whole is on it, --from and --to. A run the pen
   hasn't reached has no width at all, or its empty dash would still leave a round dot where it starts. */
.mark-written {
  --pen: 1;
}

.mark-written mask path {
  fill: none;
  stroke: white;
  stroke-width: calc(4px * min(1, max(0, (var(--pen) - var(--from)) * 400)));
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1 2;
  stroke-dashoffset: calc(1 - clamp(0, (var(--pen) - var(--from)) / (var(--to) - var(--from)), 1));
  filter: none;
  mix-blend-mode: normal;
}

/* An ink blot behind the start of the text it wraps, as if the pen dripped there before writing.
   It's on a wrapper, not the text, because the text's ink filter would turn the blot's soft edge solid. */
.ink-blot {
  position: relative;
}

.ink-blot::before {
  content: '';
  position: absolute;
  z-index: -1;
  top: -64px;
  left: -62px;
  width: 150px;
  height: 150px;
  background: url('/kit/smudges/blot.png') 0 0 / 100% 100% no-repeat;
  pointer-events: none;
}

/* Read out, never shown, like what a redaction stands for */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The ink edge comes from the letters' transparent edges, and the stroke fills those in for the
   filter around the text. So the letters get their own pass, before the stroke goes behind them.
   The gradient turns them text-accent at the same point the stroke has left. */
a.link > span {
  filter: var(--ink);
  color: transparent;
  background: linear-gradient(to right, var(--color-text-accent) var(--link-wipe), var(--color-text-primary) 0);
  background-clip: text;
}

@media (prefers-reduced-motion: reduce) {
  a.link,
  a.link:visited {
    transition: none;
  }
}

/* Links in a row, like a nav or a footer. A row of strokes shouts over the one in a sentence, so these
   only get theirs under the cursor or a finger, and it swipes on, since there's no stroke at rest to move away. */
.link-row {
  filter: var(--ink);
}

.link-row a.link:not(:hover, :focus-visible)::after {
  content: none;
}

/* No stroke behind them, so the filter around the text is enough */
.link-row a.link:not(:hover, :focus-visible) > span {
  filter: none;
}

.link-row a.link {
  --link-wipe: 0%;
}

@media (prefers-reduced-motion: no-preference) {
  .link-row a.link:is(:hover, :focus-visible)::after {
    animation: link-stroke 0.3s ease-out;
  }
}

@keyframes link-stroke {
  from {
    clip-path: inset(0 100% 0 0);
  }

  to {
    clip-path: inset(0);
  }
}

.hero-heading {
  letter-spacing: var(--letter-spacing-display);
}

.text-small {
  font-size: var(--font-size-small);
  line-height: var(--line-height-small);
  letter-spacing: var(--letter-spacing-small);
}
