/* Self-hosted webfonts. Latin (Literata) loads for everyone; Bengali/Devanagari
   faces are scoped with unicode-range so browsers only fetch them when a page
   actually contains those code points (per contract section 8). */

@font-face {
	font-family: 'Literata';
	src: url('../fonts/literata-latin-400-normal.woff2') format('woff2');
	font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
	font-family: 'Literata';
	src: url('../fonts/literata-latin-400-italic.woff2') format('woff2');
	font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
	font-family: 'Literata';
	src: url('../fonts/literata-latin-500-normal.woff2') format('woff2');
	font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
	font-family: 'Literata';
	src: url('../fonts/literata-latin-600-normal.woff2') format('woff2');
	font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
	font-family: 'Literata';
	src: url('../fonts/literata-latin-700-normal.woff2') format('woff2');
	font-weight: 700; font-style: normal; font-display: swap;
}

/* Source Sans 3 — R3 reader rebuild: the UI/chrome sans, a live measured
   match for Wattpad's own reader chrome font ("Source Sans Pro", per
   spec/R3_layout_spec.md). SIL OFL, not a Wattpad brand asset — the real
   family, not a lookalike. Wired into --lore-font-ui below; prose stays on
   Literata (serif) regardless of this. font-display:swap, self-hosted. */
@font-face {
	font-family: 'Source Sans 3';
	src: url('../fonts/source-sans-3-latin-400-normal.woff2') format('woff2');
	font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
	font-family: 'Source Sans 3';
	src: url('../fonts/source-sans-3-latin-400-italic.woff2') format('woff2');
	font-weight: 400; font-style: italic; font-display: swap;
}
@font-face {
	font-family: 'Source Sans 3';
	src: url('../fonts/source-sans-3-latin-600-normal.woff2') format('woff2');
	font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
	font-family: 'Source Sans 3';
	src: url('../fonts/source-sans-3-latin-700-normal.woff2') format('woff2');
	font-weight: 700; font-style: normal; font-display: swap;
}

/* Kalpurush — Amit's licensed Bengali display/reader face. Copied in at
   integration time from seed/fonts/kalpurush.woff2 (see
   spec/04_contract_changes.md, "Bengali reader font"). Declared first in the
   :lang(bn) stack so it's preferred once present; if the file is missing the
   browser silently falls through to Noto Serif Bengali below — no error. */
@font-face {
	font-family: 'Kalpurush';
	src: url('../fonts/kalpurush.woff2') format('woff2');
	font-weight: 400 700; font-style: normal; font-display: swap;
	unicode-range: U+0980-09FF, U+200C-200D, U+20B9, U+25CC;
}

@font-face {
	font-family: 'Noto Serif Bengali';
	src: url('../fonts/noto-serif-bengali-bengali-400-normal.woff2') format('woff2');
	font-weight: 400; font-style: normal; font-display: swap;
	unicode-range: U+0980-09FF, U+200C-200D, U+20B9, U+25CC;
}
@font-face {
	font-family: 'Noto Serif Bengali';
	src: url('../fonts/noto-serif-bengali-bengali-700-normal.woff2') format('woff2');
	font-weight: 700; font-style: normal; font-display: swap;
	unicode-range: U+0980-09FF, U+200C-200D, U+20B9, U+25CC;
}

@font-face {
	font-family: 'Noto Serif Devanagari';
	src: url('../fonts/noto-serif-devanagari-devanagari-400-normal.woff2') format('woff2');
	font-weight: 400; font-style: normal; font-display: swap;
	unicode-range: U+0900-097F, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839;
}
@font-face {
	font-family: 'Noto Serif Devanagari';
	src: url('../fonts/noto-serif-devanagari-devanagari-700-normal.woff2') format('woff2');
	font-weight: 700; font-style: normal; font-display: swap;
	unicode-range: U+0900-097F, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839;
}

/* Noto Sans Devanagari — UI face for the Hindi interface (round 2 i18n).
   Reader body text keeps the serif face above; this is menus/buttons/labels. */
@font-face {
	font-family: 'Noto Sans Devanagari';
	src: url('../fonts/noto-sans-devanagari-devanagari-400-normal.woff2') format('woff2');
	font-weight: 400; font-style: normal; font-display: swap;
	unicode-range: U+0900-097F, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839;
}
@font-face {
	font-family: 'Noto Sans Devanagari';
	src: url('../fonts/noto-sans-devanagari-devanagari-700-normal.woff2') format('woff2');
	font-weight: 700; font-style: normal; font-display: swap;
	unicode-range: U+0900-097F, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839;
}

/* Tamil — self-hosted, subset to the Tamil block only (~24-27KB each), same
   pattern as Bengali/Devanagari above. Serif for reader body text, Sans for
   UI (menus/buttons/labels). Added for round 2 i18n; a Tamil story's reader
   previously fell back to Literata/Georgia (no Tamil glyphs) and rendered in
   the browser's default system Tamil font. */
@font-face {
	font-family: 'Noto Serif Tamil';
	src: url('../fonts/noto-serif-tamil-tamil-400-normal.woff2') format('woff2');
	font-weight: 400; font-style: normal; font-display: swap;
	unicode-range: U+0B80-0BFF, U+200C-200D, U+20B9, U+25CC;
}
@font-face {
	font-family: 'Noto Serif Tamil';
	src: url('../fonts/noto-serif-tamil-tamil-700-normal.woff2') format('woff2');
	font-weight: 700; font-style: normal; font-display: swap;
	unicode-range: U+0B80-0BFF, U+200C-200D, U+20B9, U+25CC;
}
@font-face {
	font-family: 'Noto Sans Tamil';
	src: url('../fonts/noto-sans-tamil-tamil-400-normal.woff2') format('woff2');
	font-weight: 400; font-style: normal; font-display: swap;
	unicode-range: U+0B80-0BFF, U+200C-200D, U+20B9, U+25CC;
}
@font-face {
	font-family: 'Noto Sans Tamil';
	src: url('../fonts/noto-sans-tamil-tamil-700-normal.woff2') format('woff2');
	font-weight: 700; font-style: normal; font-display: swap;
	unicode-range: U+0B80-0BFF, U+200C-200D, U+20B9, U+25CC;
}

/* CLS fix (perf regression audit): metric-matched local fallback faces for
   the two Latin faces that actually swap on first paint (Source Sans 3 = UI
   chrome, Literata = prose). size-adjust/ascent-override/descent-override
   computed with fontTools from the real webfont's hhea/OS-2 metrics against
   Arial (the local() match), per weight actually used on the site (400/600/
   700 for Source Sans 3; 400/500/600/700 for Literata) — see
   qa/lighthouse/r3_after/AFTER_R3.md story/mobile CLS regression. This makes
   the fallback-rendered text occupy (near enough) the exact same box as the
   webfont, so font-display:swap no longer reflows the page when the real
   face finishes loading. */
@font-face {
	font-family: 'Source Sans 3 Fallback';
	src: local('Arial'), local('Helvetica'), local('Helvetica Neue');
	font-weight: 400; font-style: normal;
	size-adjust: 106.704%; ascent-override: 95.966%; descent-override: 37.487%; line-gap-override: 0%;
}
@font-face {
	font-family: 'Source Sans 3 Fallback';
	src: local('Arial'), local('Helvetica'), local('Helvetica Neue');
	font-weight: 600; font-style: normal;
	size-adjust: 110.103%; ascent-override: 93.004%; descent-override: 36.330%; line-gap-override: 0%;
}
@font-face {
	font-family: 'Source Sans 3 Fallback';
	src: local('Arial'), local('Helvetica'), local('Helvetica Neue');
	font-weight: 700; font-style: normal;
	size-adjust: 113.274%; ascent-override: 90.400%; descent-override: 35.312%; line-gap-override: 0%;
}
@font-face {
	font-family: 'Literata Fallback';
	src: local('Georgia'), local('Times New Roman');
	font-weight: 400; font-style: normal;
	size-adjust: 129.790%; ascent-override: 90.685%; descent-override: 23.731%; line-gap-override: 0%;
}
@font-face {
	font-family: 'Literata Fallback';
	src: local('Georgia'), local('Times New Roman');
	font-weight: 500; font-style: normal;
	size-adjust: 131.608%; ascent-override: 89.432%; descent-override: 23.403%; line-gap-override: 0%;
}
@font-face {
	font-family: 'Literata Fallback';
	src: local('Georgia'), local('Times New Roman');
	font-weight: 600; font-style: normal;
	size-adjust: 133.200%; ascent-override: 88.364%; descent-override: 23.123%; line-gap-override: 0%;
}
@font-face {
	font-family: 'Literata Fallback';
	src: local('Georgia'), local('Times New Roman');
	font-weight: 700; font-style: normal;
	size-adjust: 135.700%; ascent-override: 86.736%; descent-override: 22.697%; line-gap-override: 0%;
}

:root {
	--lore-font-ui: 'Source Sans 3', 'Source Sans 3 Fallback', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;
	--lore-font-serif: 'Literata', 'Literata Fallback', Georgia, 'Source Serif 4', serif;
}
:lang(bn) { --lore-font-serif: 'Kalpurush', 'Noto Serif Bengali', 'Literata', serif; }
:lang(hi) { --lore-font-serif: 'Noto Serif Devanagari', 'Literata', serif; }
:lang(ta) { --lore-font-serif: 'Noto Serif Tamil', 'Literata', serif; }

/* UI font stack per interface language (round 2 i18n): set from `html[lang]`,
   which Lore_I18n drives to the current UI language (not necessarily the
   language of any one story on the page — see class-i18n.php). Falls back to
   the system UI stack. Bengali reuses Kalpurush for UI too (per spec: "Kalpurush
   for bn"), so only Hindi/Tamil need a dedicated Sans face. */
html[lang="bn"] { --lore-font-ui: 'Kalpurush', var(--lore-font-ui); }
html[lang^="bn-"] { --lore-font-ui: 'Kalpurush', var(--lore-font-ui); }
html[lang="hi"] { --lore-font-ui: 'Noto Sans Devanagari', var(--lore-font-ui); }
html[lang^="hi-"] { --lore-font-ui: 'Noto Sans Devanagari', var(--lore-font-ui); }
html[lang="ta"] { --lore-font-ui: 'Noto Sans Tamil', var(--lore-font-ui); }
html[lang^="ta-"] { --lore-font-ui: 'Noto Sans Tamil', var(--lore-font-ui); }
