/*
 * The type system of VisualDesign.md section 12: three self-hosted families, the subsets the
 * twelve launch locales actually need, local fallbacks, and the type scale as tokens.
 * No page fetches a font from Google or any other font CDN, and a test reads every stylesheet and
 * every component off disk to keep it that way.
 *
 * Why three families and not two. Manrope is the interface face and Noto Sans Mono the practice
 * face, as the spec fixes. Noto Sans is here because the spec's next sentence says it is the
 * fallback for any launch-locale glyph Manrope lacks, and that turned out to be a live case rather
 * than a precaution: Manrope's own `latin` subset declares U+02BB-U+02BC and its binary has no
 * U+02BC, the modifier apostrophe Ukrainian writes with. Without Noto Sans in the stack that one
 * character drops to whatever the reader's system offers, in the middle of a word, in the one
 * launch locale nobody on the team reads. It is also short 13 letters of Latin Extended-A,
 * including the Dutch IJ digraph. tests/unit/type-coverage.test.ts reads the cmap out of each
 * shipped binary and walks the stacks in order, so this is measured rather than believed.
 *
 * Why the ranges look copied. They are the Google Fonts subset boundaries the files were cut on,
 * and they have to match the cut exactly or the browser downloads the wrong file. static/fonts/
 * PROVENANCE.md records where each file came from; the coverage test proves the range and the
 * binary agree for every character a launch locale needs.
 *
 * Local fallback faces keep text visible when a web font is slow or unavailable. Their metric
 * overrides retain the intended type scale. Optional loading uses early or cached web fonts and
 * leaves the local face in place after a late download, so the page does not reflow during typing.
 * tests/font-loading/browser-policy.test.mjs checks that policy on the emitted heading and exercise.
 */

/* --------------------------------------------------------------------------------------------
 * Manrope, the interface face. Variable weight, so one file covers 200 to 800.
 * -------------------------------------------------------------------------------------------- */

@font-face {
	font-family: 'Manrope';
	font-style: normal;
	font-weight: 200 800;
	font-display: optional;
	src: url('/fonts/manrope-latin-wght-normal.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;
}

@font-face {
	font-family: 'Manrope';
	font-style: normal;
	font-weight: 200 800;
	font-display: optional;
	src: url('/fonts/manrope-latin-ext-wght-normal.woff2') format('woff2');
	unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308,
		U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113,
		U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
	font-family: 'Manrope';
	font-style: normal;
	font-weight: 200 800;
	font-display: optional;
	src: url('/fonts/manrope-cyrillic-wght-normal.woff2') format('woff2');
	unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

/* --------------------------------------------------------------------------------------------
 * Noto Sans is the coverage face for interface text and the proportional choice for typing text.
 * The unicode ranges keep interface fallback selective while the complete stack remains available
 * when a reader chooses it for practice.
 * -------------------------------------------------------------------------------------------- */

@font-face {
	font-family: 'Noto Sans';
	font-style: normal;
	font-weight: 100 900;
	font-display: optional;
	src: url('/fonts/noto-sans-latin-wght-normal.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;
}

@font-face {
	font-family: 'Noto Sans';
	font-style: normal;
	font-weight: 100 900;
	font-display: optional;
	src: url('/fonts/noto-sans-cyrillic-wght-normal.woff2') format('woff2');
	unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
	font-family: 'Noto Sans';
	font-style: normal;
	font-weight: 100 900;
	font-display: optional;
	src: url('/fonts/noto-sans-latin-ext-wght-normal.woff2') format('woff2');
	unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308,
		U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113,
		U+2C60-2C7F, U+A720-A7FF;
}

/* --------------------------------------------------------------------------------------------
 * Noto Sans Mono, the practice face. Section 3 asks the typing face to separate I, l, 1, O and 0
 * without colour; tests/unit/type.test.ts checks the confusable set is in the binary, and the
 * story baselines are where a human reads whether they are actually distinguishable.
 * -------------------------------------------------------------------------------------------- */

@font-face {
	font-family: 'Noto Sans Mono';
	font-style: normal;
	font-weight: 100 900;
	font-display: optional;
	src: url('/fonts/noto-sans-mono-latin-wght-normal.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;
}

@font-face {
	font-family: 'Noto Sans Mono';
	font-style: normal;
	font-weight: 100 900;
	font-display: optional;
	src: url('/fonts/noto-sans-mono-latin-ext-wght-normal.woff2') format('woff2');
	unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308,
		U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113,
		U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
	font-family: 'Noto Sans Mono';
	font-style: normal;
	font-weight: 100 900;
	font-display: optional;
	src: url('/fonts/noto-sans-mono-cyrillic-wght-normal.woff2') format('woff2');
	unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

/* --------------------------------------------------------------------------------------------
 * The local fallback faces. The vertical overrides come from the shipped web font metrics.
 * Size adjustments retain the existing local type scale; they do not promise identical glyph
 * advances. Optional loading prevents a late substitution between those different shapes.
 *
 * Liberation Sans and Helvetica are Arial-compatible alternatives. Liberation Mono and Nimbus
 * Mono PS provide local alternatives to Courier New.
 * -------------------------------------------------------------------------------------------- */

@font-face {
	font-family: 'Manrope Fallback';
	src: local('Arial'), local('Helvetica'), local('Liberation Sans');
	ascent-override: 106.6%;
	descent-override: 30%;
	line-gap-override: 0%;
	size-adjust: 101.36%;
}

@font-face {
	font-family: 'Noto Sans Mono Fallback';
	src: local('Courier New'), local('Liberation Mono'), local('Nimbus Mono PS');
	ascent-override: 106.9%;
	descent-override: 29.3%;
	line-gap-override: 0%;
	size-adjust: 100%;
}

@font-face {
	font-family: 'Noto Sans Fallback';
	src: local('Arial'), local('Helvetica'), local('Liberation Sans');
	ascent-override: 106.9%;
	descent-override: 29.3%;
	line-gap-override: 0%;
	size-adjust: 104.08%;
}

:root {
	/*
	 * The stacks, in resolution order: the face, its coverage backstop, the local
	 * face used when the web font is late, and a generic so a browser that refuses all of them
	 * still renders text.
	 */
	--font-interface: 'Manrope', 'Noto Sans', 'Manrope Fallback', system-ui, sans-serif;
	--font-practice: 'Noto Sans Mono', 'Noto Sans Mono Fallback', ui-monospace, monospace;
	--font-readable: 'Noto Sans', 'Noto Sans Fallback', system-ui, sans-serif;

	/*
	 * The type scale of section 12, one token per cell. The root size stays the browser default
	 * and every size is relative, so a reader who has already enlarged their own text gets the
	 * whole scale enlarged rather than one heading. A role with no measure token is a role whose
	 * table cell states a rule instead of a width.
	 */
	--type-landing-heading-size: clamp(2.25rem, 5vw, 3.5rem);
	--type-landing-heading-leading: 1.02;
	/*
	 * `em`, not `ch`. `ch` resolves against the selected face's own U+0030 glyph, and that glyph is
	 * not what `size-adjust` above matches: the override is tuned against `OS/2.xAvgCharWidth`, the
	 * average advance across the whole face, and a digit is not an average glyph. Manrope's "0"
	 * measured 14% wider than Manrope Fallback's own at the heading's largest size, so a `ch` cap
	 * moved the heading's own box on every font swap, which is the one thing section 12 forbids.
	 * `em` is defined by the used font-size alone, never by which face is selected, so the box is
	 * stable by construction. 7.9em is the pixel width 12ch resolved to in Manrope before this
	 * change, so the heading's measured width is unchanged; only its font-dependence is gone.
	 */
	--type-landing-heading-measure: 7.9em;

	--type-practice-text-size: clamp(2.5rem, 5vw, 4.25rem);
	--type-practice-text-leading: 1.35;
	--type-practice-text-measure: 32ch;

	--type-result-numerals-size: clamp(3rem, 8vw, 6rem);
	--type-result-numerals-leading: 1;

	--type-section-heading-size: clamp(1.75rem, 3vw, 2.5rem);
	--type-section-heading-leading: 1.12;
	--type-section-heading-measure: 24ch;

	--type-body-size: 1.125rem;
	--type-body-leading: 1.6;
	--type-body-measure: 68ch;

	--type-control-and-metadata-size: 1rem;
	--type-control-and-metadata-leading: 1.4;

	/*
	 * The reading settings of section 3, at the reviewed position. A built page carries none of the
	 * attributes below, so this block is what a first visit renders in, and it is the practice role
	 * of the table above with nothing done to it.
	 *
	 * The three numbers are multipliers rather than replacements, which is the decision worth
	 * knowing about. A step that wrote its own `font-size` would be a second type scale living
	 * beside the table, and the table would stop being the contract the moment somebody adjusted
	 * anything. As multipliers they compose instead: the reader's browser size scales the `rem`,
	 * the viewport scales the `vw` term of the clamp, and the step scales the result.
	 */
        --font-reading: var(--font-practice);
        --reading-size-scale: 1;
        --reading-leading-scale: 1;
        --reading-tracking: 0em;

        /* The client records settings by their stable names. These are the current reviewed values those
         * names resolve to, and each matching data-attribute rule below consumes the named value. */
        --reading-size-small-scale: 0.85;
        --reading-size-large-scale: 1.2;
        --reading-size-largest-scale: 1.45;
        --reading-leading-tight-scale: 0.9;
        --reading-leading-loose-scale: 1.2;
        --reading-tracking-wide: 0.04em;
        --reading-tracking-wider: 0.08em;

        /* VisualDesign.md section 8 fixes interface state changes to the 120ms to 200ms convention.
         * Both interactive primitives consume this token, and reduced motion still overrides it. */
        --interface-state-transition-duration: 150ms;
}

/*
 * What each step of section 3's reading settings is worth.
 *
 * The steps themselves are src/lib/typing/reading-settings.ts, which owns which exist and writes
 * the attribute; the numbers are here, beside the scale they multiply, so nobody has to read two
 * files to find out how large "largest" is. tests/unit/reading-settings.test.ts fails when a step
 * exists on one side and not the other.
 *
 * None of these figures is fixed by the spec. They are registered in ValidationAndResearch.md
 * section 6 with the reasoning and the instrumentation plan, and they may be tuned.
 *
 * Font choices resolve to complete stack tokens. The setting never exposes a family name that can
 * lose a launch-locale subset or bypass its metric-matched fallback.
 */
:root[data-reading-size='small'] {
        --reading-size-scale: var(--reading-size-small-scale);
}

/* A stored preference includes this immutable policy version. The unqualified root above is the
 * policy new visitors receive. This block keeps an earlier cookie on its original scale when a
 * later reviewed policy changes the current root values. */
:root[data-reading-policy='reading-settings-1'] {
        --reading-size-small-scale: 0.85;
        --reading-size-large-scale: 1.2;
        --reading-size-largest-scale: 1.45;
        --reading-leading-tight-scale: 0.9;
        --reading-leading-loose-scale: 1.2;
        --reading-tracking-wide: 0.04em;
        --reading-tracking-wider: 0.08em;
}

:root[data-reading-size='large'] {
        --reading-size-scale: var(--reading-size-large-scale);
}

:root[data-reading-size='largest'] {
        --reading-size-scale: var(--reading-size-largest-scale);
}

:root[data-reading-leading='tight'] {
        --reading-leading-scale: var(--reading-leading-tight-scale);
}

:root[data-reading-leading='loose'] {
        --reading-leading-scale: var(--reading-leading-loose-scale);
}

:root[data-reading-tracking='wide'] {
        --reading-tracking: var(--reading-tracking-wide);
}

:root[data-reading-tracking='wider'] {
        --reading-tracking: var(--reading-tracking-wider);
}

:root[data-reading-font='humanist'] {
	--font-reading: var(--font-readable);
}

/*
 * The declarations that make any of it visible.
 *
 * The root carries the family and nothing else. Section 12 says the root size remains the browser
 * default, and it has to: `rem` on the root element resolves against the initial font size, so
 * `:root { font-size: 1.125rem }` would multiply every other `rem` in the scale by 1.125 and quietly
 * enlarge the whole product. Body text takes the body role one level down, where `rem` still means
 * what the reader's browser says it means.
 */
:root {
	font-family: var(--font-interface);
}

body {
	font-size: var(--type-body-size);
	line-height: var(--type-body-leading);
}
