/* ── Self-hosted fonts — Fonts & Typography Performance (Checklist #10) ──
 * Satisfies:
 *  - Self-host where legally appropriate (Space Grotesk + Space Mono are OFL)
 *  - WOFF2 only
 *  - Only required weights/styles (Space Grotesk variable 300-700 covers
 *    exactly the 4 weights used in the app: 400 normal, 500 medium,
 *    600 semibold, 700 bold; Space Mono 400 + 700 only)
 *  - font-display: swap
 *  - Preload only critical font (Space Grotesk latin, see public/index.html)
 *  - Latin subset via unicode-range — avoids shipping vietnamese/latin-ext
 *    to en-IN users. Cuts each woff2 to ~22 KiB (Space Grotesk) / ~16 KiB
 *    (Space Mono) instead of full unicode range.
 *  - Strong system-font fallbacks with tuned metrics to minimise CLS
 *    when swap occurs. Fallback faces use local() + size-adjust /
 *    ascent-override / descent-override / line-gap-override computed from
 *    primary font metrics (hhea/OS/2). Values documented below.
 *
 *  Served from public/ (linked in index.html) so /fonts/ URLs resolve at
 *  runtime without webpack css-loader trying to bundle them.
 */

/* ── Space Grotesk — variable woff2 (latin subset) ───────────────────────
 * Google Fonts serves the same variable file for every weight (V8mDoQD…F4Cw)
 * with wght axis 300-700. One 22 KiB file replaces four static instances.
 *   metrics: unitsPerEm 1000, ascent 984 (98.4%), descent 292 (29.2%),
 *            lineGap 0, sxHeight 486, xAvgCharWidth 559, capHeight 700
 *   licence: SIL OFL 1.1 — self-host permitted.
 */
@font-face {
  font-family: "Space Grotesk";
  src: url("/fonts/SpaceGrotesk-latin.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
  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;
}

/* ── Space Mono — static instances (latin) ───────────────────────────────
 * 400 and 700 are the only weights used (see Tailwind `mono` + --ac-mono).
 *   metrics 400: units 1000, ascent 1120 (112%), descent 361 (36.1%), lineGap 0
 *            sxHeight 496, avg 612
 *   metrics 700: identical vertical metrics (same family metrics)
 *   licence: SIL OFL 1.1
 */
@font-face {
  font-family: "Space Mono";
  src: url("/fonts/SpaceMono-400-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  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;
}

@font-face {
  font-family: "Space Mono";
  src: url("/fonts/SpaceMono-700-latin.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  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;
}

/* ── Fallback faces — minimise CLS during swap ───────────────────────────
 * These faces are matched by the Tailwind stacks in
 * `tailwind.config.js` (e.g. `'Space Grotesk', 'Space Grotesk Fallback', ...`).
 * Each fallback maps a local system font to the primary's metrics via
 * `size-adjust` + overrides, so the swap from fallback → webfont does not
 * cause a measurable shift in line-height or block size.
 *
 * Calculations (see scripts/audit-font-fallback.py):
 *   Space Grotesk vs Arial (primary vs fallback):
 *     primary: ascent 98.4%, descent 29.2%, lineGap 0%, xHeight 48.6%, avg 0.559em
 *     Arial:   ascent 90.5% (1854/2048), descent 21.19%, lineGap 3.27%,
 *              xHeight 51.86% (1062/2048), avg 0.441em
 *     → size-adjust via xHeight ratio 48.6/51.86 = 93.72% shrinks Arial to
 *       match Space Grotesk x-height (vertical CLS driver). Horizontal width
 *       is secondary; the 93.7% value is the Chrome-recommended heuristic.
 *     → overrides are the primary's ascent/descent/lineGap percentages.
 *   Space Mono vs Courier New:
 *     primary mono: ascent 112%, descent 36.1%, lineGap 0%, xHeight 49.6%
 *     Courier New:  ascent 83.25% (1705/2048), descent 30.03% (615/2048),
 *                   xHeight 42.29% (866/2048)
 *     → size-adjust via xHeight 49.6/42.29 = 117.29% enlarges Courier to
 *       match Space Mono x-height.
 */
@font-face {
  font-family: "Space Grotesk Fallback";
  src: local("Arial"), local("Helvetica Neue"), local("Segoe UI");
  size-adjust: 93.72%;
  ascent-override: 98.4%;
  descent-override: 29.2%;
  line-gap-override: 0%;
  font-display: swap;
}

@font-face {
  font-family: "Space Mono Fallback";
  src: local("Courier New"), local("Consolas"), local("Menlo");
  size-adjust: 117.29%;
  ascent-override: 112%;
  descent-override: 36.1%;
  line-gap-override: 0%;
  font-display: swap;
}
