/*
 * Webfont for rendering language forms.
 *
 * The UI's default stack (-apple-system / BlinkMacSystemFont / Segoe UI)
 * resolves to San Francisco on macOS and Segoe UI on Windows. Neither covers
 * the Greek Extended block (U+1F00-1FFF), and both are patchy across Latin
 * Extended-A/B. Safari masks this because Core Text falls back deeply; Chrome
 * does its own per-glyph fallback and picks a different face per missing
 * character, which produced tofu boxes, macrons off the baseline, and a psili
 * that looked almost identical to an oxia.
 *
 * Currently Noto Serif, subsetted to the ~262 characters that actually appear
 * in data/language_data/. See static/fonts/SOURCE.txt for provenance.
 *
 * The family name below is deliberately generic. scripts/build_fonts.py always
 * writes forms-regular / forms-italic / forms-bold, so switching typeface is a
 * one-line change to that script's DEFAULT_FONT — nothing here needs editing.
 *
 *     python scripts/build_fonts.py --list      # see the options
 *     python scripts/build_fonts.py --font cardo
 *
 * If the woff2 files are absent the @font-face rules simply don't match and
 * the fallback chain takes over. The app still works, it just looks less
 * consistent across machines.
 */

@font-face {
  font-family: 'Rote Forms';
  src: url('/static/fonts/forms-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  /* swap: render immediately in the fallback, restyle when the font lands.
     Better than invisible text on a slow connection. */
  font-display: swap;
}

@font-face {
  font-family: 'Rote Forms';
  src: url('/static/fonts/forms-italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: 'Rote Forms';
  src: url('/static/fonts/forms-bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /*
   * Fallback chain, in descending order of polytonic Greek coverage. Every
   * name after the webfont either ships with an OS or is commonly installed,
   * and genuinely covers Greek Extended:
   *   Noto Serif                   — if the user already has it
   *   Gentium / Cardo / New Athena — common among classicists
   *   Palatino Linotype            — Windows, full polytonic
   *   Times New Roman              — Windows + macOS, good polytonic
   *   New York                     — macOS 10.15+, good coverage
   *   Georgia / serif              — last resort
   *
   * Deliberately does NOT start with -apple-system. That was the bug: it
   * resolves to San Francisco, which has no Greek Extended at all.
   */
  --font-forms:
    'Rote Forms',
    'Noto Serif',
    'Gentium Book Plus', 'Gentium Plus', 'Cardo', 'New Athena Unicode',
    'Palatino Linotype', 'Times New Roman', 'New York',
    Georgia, serif;
}

/*
 * Apply to anything displaying an actual language form. The surrounding UI
 * keeps the system sans.
 *
 * font-variant-ligatures: none — serifs commonly ligate fi/fl, which is wrong
 * when the "word" is a grammatical form being checked character by character.
 * font-feature-settings 'kern' keeps pair kerning on, which matters for
 * base + diacritic pairs.
 */
.lang-form {
  font-family: var(--font-forms);
  font-variant-ligatures: none;
  font-feature-settings: 'kern' 1;
}
