/**
 * Silvalue — base.css
 *
 * Small, dependency-free stylesheet for behaviour that theme.json cannot
 * express on its own: visible keyboard focus on *every* focusable element
 * (not just the core link/button block elements), a skip-link utility class,
 * and a global `prefers-reduced-motion` safety net. Colour, type and spacing
 * values stay tokens (WordPress preset custom properties) — no hex codes.
 *
 * Loaded after style.css, see functions.php.
 */

/* ---------------------------------------------------------------------
 * Visible keyboard focus
 * 2px outline + 2px offset, never `outline: none`. Applies to links,
 * buttons, form fields and anything else that can receive focus.
 * `:focus-visible` avoids showing the ring on mouse clicks while still
 * falling back for browsers without support.
 *
 * Colour: `sv-accent` (2.48:1 on sv-paper, 2.78:1 on sv-white) does not
 * clear the 3:1 WCAG non-text-contrast minimum on the light default
 * background, so the outline uses `sv-ink` there instead (well over
 * 3:1 on both sv-paper and sv-white). On the dark contrast-island
 * sections (hero, approach, footer — background set to `sv-ink` via
 * the block editor colour picker), WordPress automatically adds a
 * `has-sv-ink-background-color` class to that block; the override
 * below swaps the outline to `sv-white` (17.69:1 on sv-ink) so focus
 * stays visible there too. Future patterns do not need to add any
 * extra class for this to work — only use the `sv-ink` background
 * colour from the palette as the plan already requires.
 * ------------------------------------------------------------------- */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
summary:focus,
[tabindex]:focus {
	outline: 2px solid var(--wp--preset--color--sv-ink);
	outline-offset: 2px;
}

a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible),
summary:focus:not(:focus-visible),
[tabindex]:focus:not(:focus-visible) {
	outline: none;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
	outline: 2px solid var(--wp--preset--color--sv-ink);
	outline-offset: 2px;
}

.has-sv-ink-background-color a:focus-visible,
.has-sv-ink-background-color button:focus-visible,
.has-sv-ink-background-color input:focus-visible,
.has-sv-ink-background-color select:focus-visible,
.has-sv-ink-background-color textarea:focus-visible,
.has-sv-ink-background-color summary:focus-visible,
.has-sv-ink-background-color [tabindex]:focus-visible {
	outline-color: var(--wp--preset--color--sv-white);
}

/* ---------------------------------------------------------------------
 * Dark contrast-island typography (heading / body text / link colour)
 *
 * theme.json sets the global default heading colour (sv-ink) and link
 * colour (sv-text / sv-ink on hover+focus) for the light default
 * background. Those defaults are unreadable on the dark contrast-island
 * sections (hero, approach, footer — background set to sv-ink via the
 * block editor colour picker), which is why WordPress core wraps its
 * own theme.json colour output for elements in `:where()`: zero
 * specificity, so the block-level colour a pattern author can still
 * pick from the editor always wins without needing `!important`.
 *
 * Same `has-sv-ink-background-color` class as the focus-ring fix above.
 * Originally this also wrapped `.has-sv-ink-background-color` itself in
 * `:where()`, on the assumption that a bare element selector (h1, p,
 * a, …) would already be enough to beat theme.json's zero-specificity
 * default while staying weak enough to lose to an explicit
 * `has-<slug>-color` class an author sets on that exact heading/
 * paragraph/link in the block editor.
 *
 * Hardening note (2026-08-23): that assumption was wrong — it only
 * happened to work while base.css loads after `global-styles-inline-css`
 * in <head>; it was never actually winning on specificity. Confirmed
 * empirically against the live global-styles-inline-css output on
 * silvalue-nz.local:
 * WordPress's own heading-colour rule is a bare, unwrapped element list,
 * `h1, h2, h3, h4, h5, h6{color: var(--wp--preset--color--sv-ink);...}`
 * — specificity 0-0-1 (only the element counts; comma-separated
 * selectors do not add up). Its base link-colour rule is
 * `a:where(:not(.wp-element-button)){color: var(--wp--preset--color--sv-text);...}`
 * — the `:where()` wrapper reduces the whole `:not()` clause to zero,
 * leaving 0-0-1 as well. `:where(.has-sv-ink-background-color) h1` etc.
 * above is *also* 0-0-1 (the `:where()` wrapper here contributes
 * nothing either) — a tie with both core rules, decided only by load
 * order, exactly the bug class already fixed once in header.css for
 * the mobile market-switch link.
 *
 * Fixed the same way: keep `.has-sv-ink-background-color` a plain,
 * unwrapped class (adds 0-1-0) while leaving the element itself bare —
 * `.has-sv-ink-background-color h1` etc. and `.has-sv-ink-background-color a`
 * are now 0-1-1, which beats both core defaults (0-0-1) outright, no
 * load-order dependency.
 *
 * That raises a second question the plan above already anticipated: does
 * 0-1-1 also beat an author's own explicit colour choice from the block
 * editor? Confirmed empirically: core prints that choice as
 * `.has-sv-ink-color{color: var(--wp--preset--color--sv-ink) !important;}`
 * (one class, 0-1-0, but with `!important`) directly on the heading/
 * paragraph/link element. Because our rule here carries no `!important`,
 * the author's rule wins regardless of the specificity comparison — an
 * `!important` declaration always beats a normal one, independent of
 * specificity. So the two cases resolve cleanly with one selector: wins
 * against the unwrapped, non-important core default (0-1-1 > 0-0-1),
 * loses against an author's explicit, `!important` colour choice
 * (any specificity loses to `!important` as long as we do not add it
 * here too) — no selector had to be sacrificed for the other.
 * ------------------------------------------------------------------- */
.has-sv-ink-background-color h1,
.has-sv-ink-background-color h2,
.has-sv-ink-background-color h3,
.has-sv-ink-background-color h4,
.has-sv-ink-background-color h5,
.has-sv-ink-background-color h6,
.has-sv-ink-background-color p,
.has-sv-ink-background-color li,
.has-sv-ink-background-color dt,
.has-sv-ink-background-color dd,
.has-sv-ink-background-color blockquote,
.has-sv-ink-background-color figcaption {
	color: var(--wp--preset--color--sv-white);
}

/* `:not(.wp-element-button)` added 2026-08-30, matching the same exclusion
   theme.json's own "link" element style already uses
   (`a:where(:not(.wp-element-button))`): without it, this unwrapped,
   0-1-1 rule beat the button element style's `:where()`-wrapped (zero
   specificity) color/text-decoration on any button placed inside a
   sv-ink section (e.g. the Hero's primary button) — confirmed at the
   rendered AT startseite, the button rendered underlined and with white
   instead of its intended sv-ink text. Buttons keep their own contrast
   handling (theme.json styles.elements.button) regardless of the
   section's background colour. */
.has-sv-ink-background-color a:not(.wp-element-button) {
	color: var(--wp--preset--color--sv-white);
	text-decoration: underline;
}

:where(.has-sv-ink-background-color) a:not(.wp-element-button):hover,
:where(.has-sv-ink-background-color) a:not(.wp-element-button):focus {
	color: var(--wp--preset--color--sv-accent);
}

/* ---------------------------------------------------------------------
 * Skip link
 * The visible header/navigation pattern (built in a later step) is
 * expected to place `<a href="#main" class="skip-link screen-reader-text">`
 * as the very first focusable element. The utility classes live here so
 * that step only has to add the markup.
 * ------------------------------------------------------------------- */
.screen-reader-text {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	width: 1px;
	word-wrap: normal !important;
}

.screen-reader-text.skip-link:focus {
	background-color: var(--wp--preset--color--sv-ink);
	color: var(--wp--preset--color--sv-white);
	clip: auto !important;
	clip-path: none;
	display: block;
	height: auto;
	width: auto;
	left: var(--wp--preset--spacing--sm);
	top: var(--wp--preset--spacing--sm);
	padding: var(--wp--preset--spacing--xs) var(--wp--preset--spacing--sm);
	z-index: 100000;
	text-decoration: none;
}

/* The skip link's own focus state turns it into an sv-ink chip, so its
   outline must switch to sv-white too — otherwise the default sv-ink
   outline (see above) would be invisible against its own background. */
.screen-reader-text.skip-link:focus-visible {
	outline-color: var(--wp--preset--color--sv-white);
}

/* ---------------------------------------------------------------------
 * Hero contour-line overlay (`sv-contour-overlay`)
 *
 * CLAUDE.md section 9 (`[FEST]`, ergänzt 2026-08-22): the hero's contour
 * overlay is a Media Library SVG attachment (one per installation, chosen
 * via the Customizer control registered in functions.php), read server-side
 * and rendered inline — not as an <img> — specifically so its stroke width
 * and stroke colour can be set centrally here, once, instead of being baked
 * into whichever landscape file the operator happens to upload. The
 * rendering function (`silvalue_render_contour_overlay()` in functions.php)
 * puts this class on the outgoing <svg> root element.
 *
 * `color` + `stroke: currentColor` keep the stroke on the same accent
 * token every other part of the design system uses, rather than a second,
 * SVG-only colour value.
 *
 * `vector-effect: non-scaling-stroke` is set on the *paths* deliberately,
 * not just the outer class rule: unlike `stroke`/`stroke-width`,
 * `vector-effect` is not an inherited SVG property, so it must sit on the
 * element that actually paints the line. Without it, `stroke-width` is
 * measured in each file's own internal user-space coordinates — and the
 * two contour source files (assets/img/AT_Contour_Inkscape.svg,
 * NZ_Contour_Inkscape.svg) do not share one: the AT file's geometry group
 * carries an internal scale factor of roughly 0.42, the NZ file's roughly
 * 1.0 (see the SVG-upload note in README.md for the full explanation). The
 * same stroke width would therefore render visibly thicker in one file
 * than the other. `non-scaling-stroke` measures the stroke in final
 * screen pixels instead, so both landscapes read as the same line weight
 * regardless of which one is uploaded on a given installation.
 *
 * `--sv-contour-stroke-width`: 1.25px (original) -> 1px (2026-08-27, "more
 * subdued" request, together with a lower opacity and a new left-right
 * fade, see the `.sv-hero__contour` comment in patterns.css) -> back to
 * 1.25px (2026-08-27, same day, corrected: on the real rendered page the
 * combination of lower opacity + lower stroke-width + the new fade was too
 * weak to see at all, even though each value individually was exactly as
 * set — the opacity variable in patterns.css was raised to compensate
 * instead of also changing this one, so only one variable moved per
 * correction). Plain CSS custom property, not a `--wp--preset--...` design
 * token: it is not part of the shared cross-page design system, only a
 * tuning knob for this one overlay, adjustable here without touching the
 * rule below.
 * ------------------------------------------------------------------- */
:root {
	--sv-contour-stroke-width: 1.25px;
}

.sv-contour-overlay {
	color: var(--wp--preset--color--sv-accent);
	stroke: currentColor;
	stroke-width: var(--sv-contour-stroke-width);
	overflow: visible;
}

/*
 * Stroke/colour repeated explicitly on the paths themselves, `!important`
 * (added 2026-08-27, live-page check on the AT install: the overlay's
 * <svg> carried the correct class and the CSS above was delivered
 * correctly, yet the lines stayed invisible after the source files were
 * cleaned of their own baked-in stroke attributes). `stroke`/`stroke-width`
 * are inherited SVG properties, so the rule above *should* be sufficient
 * on its own — but each `<path>` in both contour files still carries its
 * own presentation attributes and inline `style` from the Inkscape/QGIS
 * export (`fill="none"`, `style="...stroke-opacity:1"`, etc., though none
 * of those set `stroke` or `stroke-width` explicitly). Rather than keep
 * relying on inheritance reaching through that per-path styling
 * correctly, this rule sets both directly on every path, `!important` so
 * it cannot lose to any presentation attribute or export-tool inline
 * style regardless of specificity. `fill: none !important` guards the
 * same way against a stray `fill` value ever painting over the linework.
 */
.sv-contour-overlay path {
	stroke: currentColor !important;
	stroke-width: var(--sv-contour-stroke-width) !important;
	fill: none !important;
	vector-effect: non-scaling-stroke;
}

/* ---------------------------------------------------------------------
 * Reduced motion
 * Global safety net so that any future animation (patterns, plugins)
 * is neutralised for users who ask for less motion, without every
 * pattern having to repeat the media query.
 * ------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.001ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.001ms !important;
		scroll-behavior: auto !important;
	}
}
