/* =========================================================================
   Mostacho — base layer
   Tokens, reset, typography, accessibility, motion.

   Token source of truth is theme.json. This file aliases the generated
   --wp--preset--* / --wp--custom--* properties to the short semantic names
   used by every component (Visual DNA §1.2 semantic layer, §8 shared CSS).
   Components consume the SEMANTIC names only — never --core-* and never a hex.
   ========================================================================= */

/* -------------------------------------------------------------------------
   1. Metric-matched fallbacks (CLS control — Visual DNA §2.1)
   size-adjust values are ESTIMATES and must be measured against the real
   font files before launch. See README "Open items".
   ------------------------------------------------------------------------- */
@font-face {
	font-family: "Onest Fallback";
	src: local("Arial"), local("Helvetica"), local("Liberation Sans");
	size-adjust: 102%;
	ascent-override: 95%;
	descent-override: 25%;
	line-gap-override: 0%;
}

@font-face {
	font-family: "Space Grotesk Fallback";
	src: local("Arial"), local("Helvetica"), local("Liberation Sans");
	size-adjust: 100%;
	ascent-override: 95%;
	descent-override: 25%;
	line-gap-override: 0%;
}

/* Lost in South — commercial licence NOT yet purchased (Visual DNA §2.1).
   The @font-face below stays commented out until the licence is bought and a
   subsetted woff2 is placed at assets/fonts/. Until then the signature role
   falls back to Onest via the theme.json font-family stack. DO NOT uncomment
   without the licence. */
/*
@font-face {
	font-family: "Lost in South";
	src: url("../fonts/lost-in-south-light.woff2") format("woff2");
	font-weight: 300;
	font-style: normal;
	font-display: swap;
	unicode-range: U+0000-00FF;
}
*/

/* -------------------------------------------------------------------------
   2. Token aliases
   ------------------------------------------------------------------------- */
:root {
	/* Raw / CORE — never consumed directly by a component */
	--core-coal: var(--wp--preset--color--core-coal, #0b0d10);
	--core-black: var(--wp--preset--color--core-black, #000);
	--core-chalk: var(--wp--preset--color--core-chalk, #f4f6f8);
	--core-offwhite: var(--wp--preset--color--core-offwhite, #f9f9f9);
	--core-grey: var(--wp--preset--color--core-grey, #7a7a7a);
	--core-signal: var(--wp--preset--color--core-signal, #ffd400);
	--text-secondary-strong: var(--wp--preset--color--text-secondary-strong, #5a5a5a);
	--util-proof: var(--wp--preset--color--util-proof, #22c55e);
	--util-error: var(--wp--preset--color--util-error, #ed5838);
	--util-field-grey: var(--wp--preset--color--util-field-grey, #e9ecef);

	/* Adaptation slot — unset for Mostacho's own site (Component Library §0.2) */
	--flex-accent: initial;

	/* Semantic — LIGHT is the document default; sections opt into dark */
	--surface-base: var(--core-offwhite);
	--surface-panel: var(--util-field-grey);
	--surface-card: var(--core-chalk);
	--text-primary: var(--core-black);
	--text-secondary: var(--text-secondary-strong);
	--text-caption: var(--core-grey);
	--action-bg: var(--core-signal);
	--action-fg: var(--core-black);
	--border-hairline: rgb(122 122 122 / 20%);
	--focus-ring: var(--core-coal);
	--state-success: var(--util-proof);
	--state-error: var(--util-error);
	--body-font-weight: 500;

	/* Type */
	--font-body: var(--wp--preset--font-family--onest, Onest, Arial, sans-serif);
	--font-ui: var(--wp--preset--font-family--space-grotesk, "Space Grotesk", Arial, sans-serif);
	--font-signature: var(--wp--preset--font-family--signature, Onest, Arial, sans-serif);

	--fs-impact: var(--wp--preset--font-size--impact, clamp(40px, 8vw, 72px));
	--fs-title: var(--wp--preset--font-size--title, clamp(34px, 6.5vw, 60px));
	--fs-heading: var(--wp--preset--font-size--heading, clamp(28px, 4.4vw, 42px));
	--fs-subheading: var(--wp--preset--font-size--subheading, clamp(20px, 2.2vw, 24px));
	--fs-section-header: var(--wp--preset--font-size--section-header, 20px);
	--fs-body: var(--wp--preset--font-size--body, clamp(17px, 1.4vw, 21px));
	--fs-body-small: var(--wp--preset--font-size--body-small, 16px);
	--fs-quote: var(--wp--preset--font-size--quote, clamp(17px, 1.2vw, 21px));
	--fs-caption-signature: var(--wp--preset--font-size--caption-signature, 24px);
	--fs-ui-label: var(--wp--preset--font-size--ui-label, 16px);
	--fs-data-value: var(--wp--preset--font-size--data-value, clamp(32px, 5vw, 56px));

	/* Space */
	--space-1: var(--wp--preset--spacing--1, 4px);
	--space-1-5: var(--wp--preset--spacing--1-5, 12px);
	--space-2: var(--wp--preset--spacing--2, 8px);
	--space-3: var(--wp--preset--spacing--3, 16px);
	--space-4: var(--wp--preset--spacing--4, 24px);
	--space-5: var(--wp--preset--spacing--5, 32px);
	--space-6: var(--wp--preset--spacing--6, 48px);
	--space-7: var(--wp--preset--spacing--7, 64px);
	--space-8: var(--wp--preset--spacing--8, 72px);
	--space-9: var(--wp--preset--spacing--9, 96px);
	--space-10: var(--wp--preset--spacing--10, 128px);

	/* Shape */
	--radius-none: var(--wp--custom--radius--none, 0);
	--radius-card: var(--wp--custom--radius--card, 16px);
	--radius-pill: var(--wp--custom--radius--pill, 999px);
	--border-hairline-width: var(--wp--custom--hairline--width, 1px);
	--line-system: var(--wp--custom--line--system, 2px);

	/* Motion */
	--ease-out: var(--wp--custom--motion--ease-out, cubic-bezier(0.215, 0.61, 0.355, 1));
	--dur-micro: var(--wp--custom--motion--dur-micro, 160ms);
	--dur-ui: var(--wp--custom--motion--dur-ui, 240ms);
	--dur-enter: var(--wp--custom--motion--dur-enter, 600ms);
	--dur-enter-max: var(--wp--custom--motion--dur-enter-max, 900ms);

	/* Layout */
	--measure-long-form: var(--wp--custom--measure--long-form, 720px);
	--measure-content: var(--wp--custom--measure--content, 1280px);
	--measure-shell: var(--wp--custom--measure--shell, 1920px);
	--gutter: var(--wp--custom--grid--gutter-mobile, 16px);
	--tap-min: var(--wp--custom--tap--min, 44px);
	--tap-floor: var(--wp--custom--tap--floor, 24px);

	/* Set by JS when the sticky CTA bar is mounted (WCAG 2.2 §2.4.11) */
	--cta-bar-height: 0px;
}

@media (min-width: 768px) {
	:root {
		--gutter: var(--wp--custom--grid--gutter-desktop, 24px);
	}
}

/* Per-section surface variations (block style variations on core/group).
   Editors pick a style from the toolbar; they never set a raw colour. */
.is-style-surface-dark {
	--surface-base: var(--core-coal);
	--surface-panel: color-mix(in srgb, var(--core-chalk) 4%, var(--core-coal));
	--surface-card: color-mix(in srgb, var(--core-chalk) 6%, var(--core-coal));
	--text-primary: var(--core-chalk);
	--text-secondary: rgb(244 246 248 / 72%);
	--text-caption: var(--core-grey);
	--border-hairline: rgb(244 246 248 / 12%);
	--focus-ring: var(--core-signal);
	--body-font-weight: 400;

	background-color: var(--surface-base);
	color: var(--text-primary);
}

.is-style-surface-light {
	--surface-base: var(--core-offwhite);
	--surface-panel: var(--util-field-grey);
	--surface-card: var(--core-chalk);
	--text-primary: var(--core-black);
	--text-secondary: var(--text-secondary-strong);
	--text-caption: var(--core-grey);
	--border-hairline: rgb(122 122 122 / 20%);
	--focus-ring: var(--core-coal);
	--body-font-weight: 500;

	background-color: var(--surface-base);
	color: var(--text-primary);
}

/* -------------------------------------------------------------------------
   3. Reset
   ------------------------------------------------------------------------- */
*,
*::before,
*::after {
	box-sizing: border-box;
}

html {
	-webkit-text-size-adjust: 100%;
	/* Lenis / smooth-scroll libraries are banned (Visual DNA §4). Native only. */
	scroll-behavior: smooth;
	scroll-padding-bottom: var(--cta-bar-height);
}

body {
	margin: 0;
	background-color: var(--surface-base);
	color: var(--text-primary);
	font-family: var(--font-body);
	font-size: var(--fs-body);
	font-weight: var(--body-font-weight);
	line-height: 1.5;
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
	overflow-x: hidden;
}

img,
svg,
video {
	max-width: 100%;
	height: auto;
	display: block;
}

button,
input,
select,
textarea {
	font: inherit;
	color: inherit;
}

/* -------------------------------------------------------------------------
   4. Typography
   Visual style is not heading level (Visual DNA §2.3). h1 → h2 → h3, never
   skipped. Left-align anything longer than two words; no centred paragraph
   walls.
   ------------------------------------------------------------------------- */
h1,
h2,
h3,
h4,
h5,
h6 {
	font-family: var(--font-body);
	font-weight: 700;
	margin: 0;
	text-wrap: balance;
}

h1 {
	font-size: var(--fs-title);
	line-height: 1.05;
	letter-spacing: -0.015em;
}

h2 {
	font-size: var(--fs-heading);
	line-height: 1.15;
	letter-spacing: -0.01em;
}

h3 {
	font-size: var(--fs-subheading);
	font-weight: 600;
	line-height: 1.25;
	letter-spacing: 0;
}

h4 {
	font-family: var(--font-ui);
	font-size: var(--fs-section-header);
	font-weight: 600;
	line-height: 1.2;
	letter-spacing: 0.02em;
}

p {
	margin: 0;
	text-wrap: pretty;
}

/* Body measure never over 75ch or under 45ch (Visual DNA §2.3) */
.u-measure {
	max-width: min(var(--measure-long-form), 68ch);
}

.u-caption {
	font-size: var(--fs-body-small);
	color: var(--text-caption);
}

.u-secondary {
	color: var(--text-secondary);
}

/* Lost in South signature role only — 1–3 words, ≤5% of visible text. */
.u-signature {
	font-family: var(--font-signature);
	font-size: var(--fs-caption-signature);
	font-weight: 300;
	line-height: 1;
}

/* -------------------------------------------------------------------------
   5. Layout primitives
   ------------------------------------------------------------------------- */
.u-shell {
	width: 100%;
	max-width: var(--measure-content);
	margin-inline: auto;
	padding-inline: var(--gutter);
}

.u-section {
	padding-block: var(--space-6);
	background-color: var(--surface-base);
	color: var(--text-primary);
}

@media (min-width: 768px) {
	.u-section {
		padding-block: var(--space-9);
	}

	.u-section--tight {
		padding-block: var(--space-8);
	}
}

.u-stack {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
}

.u-stack--4 {
	gap: var(--space-4);
}

.u-stack--5 {
	gap: var(--space-5);
}

.u-stack--6 {
	gap: var(--space-6);
}

/* -------------------------------------------------------------------------
   6. Accessibility
   ------------------------------------------------------------------------- */
.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

/* Visible ring on every interactive element (Visual DNA §5.1) */
:focus-visible {
	outline: 2px solid var(--focus-ring);
	outline-offset: 2px;
}

/* On Signal Yellow surfaces the ring flips to Coal — yellow-on-yellow fails
   the 3:1 non-text contrast rule. */
.btn--primary:focus-visible,
.signal-chip--signal:focus-visible {
	outline-color: var(--core-coal);
}

.skip-link {
	position: absolute;
	inset-inline-start: var(--space-3);
	inset-block-start: var(--space-3);
	z-index: 200;
	display: inline-block;
	padding: var(--space-2) var(--space-3);
	background-color: var(--core-signal);
	color: var(--core-coal);
	font-family: var(--font-ui);
	font-size: var(--fs-ui-label);
	font-weight: 600;
	letter-spacing: 0.04em;
	text-decoration: none;
	border-radius: var(--radius-card);
	transform: translateY(-200%);
}

.skip-link:focus {
	transform: translateY(0);
}

/* -------------------------------------------------------------------------
   7. Motion
   Transform and opacity only. No blur, morph, parallax, background-attachment
   or animation of layout properties (Visual DNA §4).
   ------------------------------------------------------------------------- */

/* Scroll-triggered section entrances — Home only (Wireframe §2.4).
   v1.2.0: driven by reveal.js (IntersectionObserver), replacing CSS
   animation-timeline: view(), which only Chromium ships — Safari and Firefox
   rendered the page fully static. The html.js-anim class gates every hidden
   state and is only added when IO exists and reduced motion is off, so
   no JS / old browser / reduced motion always means visible content. */
@keyframes reveal-rise {
	from {
		opacity: 0;
		transform: translateY(8px);
	}

	to {
		opacity: 1;
		transform: none;
	}
}

html.js-anim .u-reveal > *,
html.js-anim .u-reveal-group > * {
	opacity: 0;
}

html.js-anim .u-reveal.is-inview > *,
html.js-anim .u-reveal-group.is-inview > * {
	animation: reveal-rise var(--dur-enter) var(--ease-out) both;
}

/* ≤80ms stagger per sibling (Visual DNA §10). */
html.js-anim .u-reveal.is-inview > :nth-child(2),
html.js-anim .u-reveal-group.is-inview > :nth-child(2) {
	animation-delay: 80ms;
}

html.js-anim .u-reveal.is-inview > :nth-child(3),
html.js-anim .u-reveal-group.is-inview > :nth-child(3) {
	animation-delay: 160ms;
}

html.js-anim .u-reveal.is-inview > :nth-child(n + 4),
html.js-anim .u-reveal-group.is-inview > :nth-child(n + 4) {
	animation-delay: 240ms;
	animation-duration: var(--dur-enter-max);
}

/* Safety net: if reduced motion flips on mid-session, never hide content. */
@media (prefers-reduced-motion: reduce) {
	html.js-anim .u-reveal > *,
	html.js-anim .u-reveal-group > * {
		opacity: 1;
	}
}

/* Above-the-fold entrance. A view() timeline cannot animate an element that is
   already inside the viewport at load, so the hero runs a time-based entrance
   instead. Transform and opacity only (Visual DNA §4). */
@media (prefers-reduced-motion: no-preference) {
	.u-enter > * {
		animation: reveal-rise var(--dur-enter) var(--ease-out) both;
	}

	.u-enter > :nth-child(1) {
		animation-delay: 80ms;
	}

	.u-enter > :nth-child(2) {
		animation-delay: 160ms;
	}

	.u-enter > :nth-child(3) {
		animation-delay: 240ms;
	}

	.u-enter > :nth-child(n + 4) {
		animation-delay: 320ms;
	}
}

/* WCAG 2.2 compliance, not a preference. Mandatory on every build. */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
		scroll-behavior: auto !important;
	}
}
