/* SPDX-License-Identifier: AGPL-3.0-or-later
 *
 * Every number here was measured against the binaries we ship, not taken from
 * convention. See docs/PLAN.md § Typography.
 */

/* Self-hosted from upstream. Google's CDN builds strip most OpenType features. */
@font-face {
  font-family: "Literata";
  src: url("/assets/Literata-Variable-606546fb.woff2") format("woff2-variations");
  font-weight: 200 900;
  font-stretch: normal;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Literata";
  src: url("/assets/Literata-Italic-Variable-7ed2159f.woff2") format("woff2-variations");
  font-weight: 200 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("/assets/InterVariable-dcaa11db.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("/assets/Fraunces-Variable-88104d3e.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/assets/JetBrainsMono-Regular-814a7d8a.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("/assets/JetBrainsMono-Medium-704705f0.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

/* Metric-matched fallbacks so the swap does not reflow the page. */
@font-face {
  font-family: "Literata Fallback";
  src: local("Georgia"), local("Times New Roman"), local("serif");
  size-adjust: 103%;
  ascent-override: 92%;
  descent-override: 24%;
}
@font-face {
  font-family: "Inter Fallback";
  src: local("Helvetica Neue"), local("Arial"), local("sans-serif");
  size-adjust: 107%;
  ascent-override: 90%;
  descent-override: 22%;
}

:root {
  --font-reading: "Literata", "Literata Fallback", Georgia, serif;
  --font-ui:      "Inter", "Inter Fallback", system-ui, sans-serif;
  --font-display: "Fraunces", "Literata Fallback", Georgia, serif;
  --font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Hand-tuned and integer-snapped below 24px: sub-pixel sizes round
     inconsistently across engines, so 13.44px is a rendering lottery. */
  /* wall.css reached past the bottom of the scale to a raw 11px in four
     places. The scale starts at 12. */
  --step--2: 12px;
  --step--1: 13px;
  --step-0:  16px;
  --step-1:  19px;
  --step-2:  23px;
  --step-3:  28px;
  --step-4:  36px;
  --step-5:  48px;
  --step-6:  64px;

  /* NOT 65ch. `ch` is the advance of `0` (0.579em in Literata) while real text
     averages 0.4435em in Slovenian and 0.4608em in English, so 65ch renders
     about 85 characters. 29.4em = 65 x 0.4522 gives 66.3 sl / 63.8 en. */
  --measure: 29.4em;

  /* The same measure, resolved at the reading size, for the places that
     cannot resolve it there themselves.
   *
     `em` in a grid track is computed against the GRID CONTAINER's font size,
     not against the text that ends up in the track - so `minmax(0,
     var(--measure))` on the Lectern was 29.4 x 16px = 470px, and capped the
     19px reading column 88px short of the width this line was chosen for.
     About 55 characters where the comment above specifies 66.3 sl / 63.8 en,
     which is the one number in this file that was measured against real
     text and then quietly not applied.
   *
     Derived rather than written out, so it still follows --step-1. */
  --measure-reading: calc(29.4 * var(--step-1));

  --leading-tight: 1.25;
  --leading-ui:    1.45;
  --leading-read:  1.58;
}

/* Carons rise above cap height and collide with descenders from the line
   above, so Slovenian needs more room than English. An optical adjustment,
   not decoration. */
:lang(sl) { --leading-read: 1.65; }

html {
  font-family: var(--font-ui);
  font-size: var(--step-0);
  line-height: var(--leading-ui);
  font-optical-sizing: auto;
  -webkit-text-size-adjust: 100%;
}

/* Tabular, slashed-zero numerals wherever digits line up. The slashed zero is
   one of the features the CDN build does not carry. */
.numeric, time, .ledger, .dragons-eye {
  font-variant-numeric: tabular-nums slashed-zero;
  /* "zero" 1 alone REPLACES the list, so the liga/calt kill from the mono
     rule was being dropped and JetBrains Mono's coding ligatures were live
     in every count and timestamp. != rendering as a single glyph in a log is
     a bug, not a flourish - and it is written down as one. */
  font-feature-settings: "liga" 0, "calt" 0, "zero" 1;
}

/* In a log, != collapsing to a glyph is a bug. JetBrains Mono has no `liga`
   feature at all - its coding ligatures ride entirely on `calt`, so
   font-variant-ligatures: none is not enough. */
code, pre, kbd, samp, .mono, .ledger, .dragons-eye {
  font-family: var(--font-mono);
  font-feature-settings: "liga" 0, "calt" 0, "zero" 1;
}

/* The Lectern. */
.prose {
  font-family: var(--font-reading);
  max-inline-size: var(--measure);
  font-size: var(--step-1);
  line-height: var(--leading-read);
  text-wrap: pretty;
  hyphens: auto;
  /* Until the dragon has read a capture, its title IS its URL - and a URL is
     one unbroken word. `https://arxiv.org/abs/2609.11482` set as an h1 at
     36px is about 560px of unbreakable text, against 358px of phone. hyphens
     does nothing about it: there are no hyphenation points in an arXiv id,
     so the page simply scrolled sideways, on the device it is read on most,
     for every item that had not been enriched yet.
   *
     break-word rather than anywhere: it breaks only a word that cannot fit
     on a line of its own, and leaves min-content sizing - which the wall's
     columns depend on - exactly as it was. */
  overflow-wrap: break-word;
}
.prose > * + * { margin-block-start: 1rlh; }

/* This block exists because a reset once deleted the heading scale entirely.
   Tailwind's preflight reset every heading to `font-size: inherit` and
   `font-weight: inherit`, and it was the first sheet the layout loaded - so
   an <h2> in the Lectern or in Settings rendered at 19px/400, the same size
   AND the same weight as the paragraph under it, while the display face was
   applied faithfully to type with no hierarchy left to carry. Tailwind is
   gone and reset.css deliberately does not touch headings, but the scale
   stays stated here rather than left to the UA.
 *
 * The scale is the one in docs/PLAN.md, and opsz is named per level rather
 * than left to font-optical-sizing for the reason below. Anything that wants
 * a different size says so where it lives: the masthead, a card title, the
 * Lectern's own h1.
 *
 * 600 rather than 700: Fraunces at 700 with SOFT 60 closes the counters in
 * `e` and `a` at text sizes, and this is a face that is going to be set at
 * 19px for a section heading far more often than at 36. */
h1, h2, h3, .display { font-weight: 600; }
h1 { font-size: var(--step-4); --fraunces-opsz: 36; }
h2 { font-size: var(--step-2); --fraunces-opsz: 23; }
h3 { font-size: var(--step-1); --fraunces-opsz: 19; }

/* A heading takes its space from above. The gap belongs to the break between
   sections, not between a heading and the sentence it introduces - and
   `.prose > * + *` was giving it the same 1rlh in both directions, which
   reads as a heading floating between two paragraphs rather than opening
   one. */
.prose :is(h2, h3) { margin-block-start: 1.9rlh; }
.prose :is(h2, h3) + * { margin-block-start: .5rlh; }

h1, h2, h3, .display {
  font-family: var(--font-display);
  /* SOFT below 50 turns the carons into hairlines that shimmer at text sizes. */
  /* opsz is named explicitly rather than left to font-optical-sizing: the
     moment font-variation-settings appears, whether the automatic axis still
     applies is engine-dependent, and a display face rendering at the text cut
     is exactly the kind of "almost right" this project is trying to avoid.
     Each surface sets --fraunces-opsz to its own size. */
  font-variation-settings: "opsz" var(--fraunces-opsz, 24), "SOFT" 60, "WONK" 1;
  line-height: var(--leading-tight);
  text-wrap: balance;
}

/* Safari is the only engine that has ever shipped this, and it is every one of
   Darko's devices. Progressive, never faked with a negative text-indent. */
@supports (hanging-punctuation: first) {
  .prose { hanging-punctuation: first last; }
}

/* Removes the half-leading above headings, which is what actually makes
   spacing look wrong. Chrome 133 / Safari 18.2 / Firefox 154. */
@supports (text-box-trim: trim-both) {
  h1, h2, h3 { text-box-trim: trim-both; text-box-edge: cap alphabetic; }
}

/* The reduced-motion block every project copies has a bug in it that only
   shows up once something loops. Collapsing the duration to 0.01ms does not
   stop an `infinite` animation - it runs it a hundred thousand times a
   second, burning a core to hold a still image. The iteration count is the
   half everyone leaves out, and `animation-play-state` is not enough either
   because the first frame still has to land somewhere. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    /* A scroll-driven animation has no duration to collapse: `view()` and
       `scroll()` timelines ignore animation-duration entirely, so the rule
       above misses every one of them. Cutting the timeline is what actually
       lands the element in its end state and leaves it there. */
    animation-timeline: auto !important;
    scroll-behavior: auto !important;
  }
}
