/* Copyright (c) 2026 Web Upp Limited. Licensed under the GPL-2.0-or-later; see LICENSE. */
/*
 * The header's state (from 3.25.1, inc/header-state.php): the header part,
 * `.wp-site-blocks > header.wp-block-template-part`, pinned and over the
 * hero by the header template's switches, through the body classes
 * `wu-header-pinned`, `wu-header-pinned-phones` and `wu-header-over` (from
 * 4.6.0 `wu-header-solid-phones` beside it: over from 768px only, a solid
 * bar below). Loaded on every page (handle `webupp-header-state`), never
 * from the header block's own sheet, which loads only where that block is.
 *
 * Never a transform, filter, backdrop-filter, contain or will-change on the
 * part: any of them makes it the containing block of the navigation's
 * position: fixed overlay (and from 4.6.0 of webupp/menu's overlay sheet),
 * which then opens inside the header instead of over the screen. From
 * 4.6.0 the parent draws the part's ::before from three slots (below): a
 * child sets them, and a child's own rule on the ::before still wins.
 * CONTRACT.md, "The header's state".
 */

/* The part's place: in the stacking order above the page (--wu-header-z,
   50 when unset; a child under its pinned button's 40 would put the open
   menu under the button). */
.wp-site-blocks > header.wp-block-template-part {
	position: relative;
	z-index: var(--wu-header-z, 50);
}

/* An anchor, and the browser's own scroll to a focused element, stop
   below WordPress's toolbar with 16px to spare; below a pinned header, its
   measured height too (--wu-header-over-h, the header's script). The page's
   own WCAG 2.2 Focus Not Obscured, technique C43. */
html {
	scroll-padding-top: calc(var(--wp-admin--admin-bar--height, 0px) + 16px);
}

/* From 4.6.0 (Platform 5.0.0 ticket section 59 item 2) the pin holds only
   where the screen is at least 480px high, at every width and for both
   switches: every rule keyed on wu-header-pinned sits in a query with
   (min-height: 480px), so on a phone held sideways or a zoomed window the
   page draws as with the pin off (W3C technique C34; the ruling,
   records/b31d-sticky-header-ruling-2026-11-24.txt section 8). The value is
   fixed here, like 768: a media query takes no slot. */

/* Pinned, from 768px up: under WordPress's toolbar where there is one. */
@media (min-width: 768px) and (min-height: 480px) {
	body.wu-header-pinned .wp-site-blocks > header.wp-block-template-part {
		position: sticky;
		top: var(--wp-admin--admin-bar--height, 0px);
	}

	html:has(> body.wu-header-pinned) {
		scroll-padding-top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--wu-header-over-h, var(--wu-header-h, 72px)) + 16px);
	}
}

/* Pinned on phones, below 768px, only with pinned on. */
@media (max-width: 767.98px) and (min-height: 480px) {
	body.wu-header-pinned.wu-header-pinned-phones .wp-site-blocks > header.wp-block-template-part {
		position: sticky;
		top: var(--wp-admin--admin-bar--height, 0px);
	}

	html:has(> body.wu-header-pinned.wu-header-pinned-phones) {
		scroll-padding-top: calc(var(--wp-admin--admin-bar--height, 0px) + var(--wu-header-over-h, var(--wu-header-h, 72px)) + 16px);
	}
}

/* Below 600px WordPress's toolbar scrolls away with the page, so a pinned
   header pins at the top of the screen (no gap where the toolbar was). The
   selector carries the phones rule's own classes: with fewer, that rule's
   top (the toolbar's 46px) wins and leaves the gap (measured, 3.25.1). */
@media (max-width: 600px) and (min-height: 480px) {
	body.wu-header-pinned.wu-header-pinned-phones .wp-site-blocks > header.wp-block-template-part {
		top: 0;
	}

	html:has(> body.wu-header-pinned.wu-header-pinned-phones) {
		scroll-padding-top: calc(var(--wu-header-over-h, var(--wu-header-h, 72px)) + 16px);
	}
}

/* Over the hero: the part lies over the page's first section, from the
   top of the page; pinned, it stays pinned with no height of its own, its
   blocks drawn over the page. From 4.6.0 (Platform 5.0.0 ticket section 42)
   a page with wu-header-solid-phones is over from 768px only: below 768px
   every over rule is written with :where(:not(.wu-header-solid-phones)),
   so its weight is as before and the part is in the flow there. */
@media (min-width: 768px) {
	body.wu-header-over .wp-site-blocks > header.wp-block-template-part {
		position: absolute;
		inset: 0 0 auto;
	}
}

@media (max-width: 767.98px) {
	body.wu-header-over:where(:not(.wu-header-solid-phones)) .wp-site-blocks > header.wp-block-template-part {
		position: absolute;
		inset: 0 0 auto;
	}
}

@media (min-width: 768px) and (min-height: 480px) {
	body.wu-header-over.wu-header-pinned .wp-site-blocks > header.wp-block-template-part {
		position: sticky;
		inset: auto;
		top: var(--wp-admin--admin-bar--height, 0px);
		height: 0;
	}
}

@media (max-width: 767.98px) and (min-height: 480px) {
	body.wu-header-over.wu-header-pinned.wu-header-pinned-phones:where(:not(.wu-header-solid-phones)) .wp-site-blocks > header.wp-block-template-part {
		position: sticky;
		inset: auto;
		top: var(--wp-admin--admin-bar--height, 0px);
		height: 0;
	}
}

@media (max-width: 600px) and (min-height: 480px) {
	body.wu-header-over.wu-header-pinned.wu-header-pinned-phones:where(:not(.wu-header-solid-phones)) .wp-site-blocks > header.wp-block-template-part {
		top: 0;
	}
}

/* Under the parent's own header block (webupp/header), the section after
   the part starts at the top and the hero there begins its words below the
   header: its measured height through the hero's own slots, as the block
   did until 3.25.1. A child's own header leaves its hero's top space to the
   child: Canine Sense sets --wu-hero-pad-top on the root, which a rule here
   on the main would override (measured: its home hero's words 27px lower).
   From 4.6.0 below 768px only where the header is over there. */
@media (min-width: 768px) {
	body.wu-header-over .wp-site-blocks > header.wp-block-template-part:has(.wu-site-header) + * {
		--wu-hero-pad-top: calc(var(--wu-header-over-h, var(--wu-header-h, 72px)) + var(--wu-section-y, 64px));
		--wu-hero-top: calc(var(--wu-header-over-h, var(--wu-header-h, 72px)) + 72px);
		margin-block-start: 0;
	}
}

@media (max-width: 767.98px) {
	body.wu-header-over:where(:not(.wu-header-solid-phones)) .wp-site-blocks > header.wp-block-template-part:has(.wu-site-header) + * {
		--wu-hero-pad-top: calc(var(--wu-header-over-h, var(--wu-header-h, 72px)) + var(--wu-section-y, 64px));
		--wu-hero-top: calc(var(--wu-header-over-h, var(--wu-header-h, 72px)) + 72px);
		margin-block-start: 0;
	}
}

/*
 * From 4.6.0 (merged gap item 11 with P3c: Platform 5.0.0 ticket section 31
 * items P3b and P3c): the part's ground, its frost and its line on scroll,
 * drawn by the parent on the part's ::before from three slots, all off by
 * default: --wu-header-part-ground (a background, transparent),
 * --wu-header-frost (a backdrop-filter value, none) and
 * --wu-header-scrolled-line (a colour, transparent), the line a 1px shadow
 * under the part once the page has scrolled (html.wu-scrolled, the header's
 * script), so it adds nothing to the part's height. The filter stays off the
 * part itself (above). Over the hero none is drawn until a pinned header
 * has scrolled; then the pseudo covers the header's measured height.
 * Every rule weighs (0,2,2), the body and root classes in :where(), the
 * weight of the webupp and VirtualCRO children's own rule on the ::before,
 * which loads later and still wins.
 */
.wp-site-blocks > header.wp-block-template-part::before {
	content: "";
	position: absolute;
	inset: 0;
	z-index: -1;
	pointer-events: none;
	background: var(--wu-header-part-ground, transparent);
	-webkit-backdrop-filter: var(--wu-header-frost, none);
	backdrop-filter: var(--wu-header-frost, none);
	box-shadow: 0 1px 0 transparent;
	transition: box-shadow 0.2s;
}

:where(html.wu-scrolled) .wp-site-blocks > header.wp-block-template-part::before {
	box-shadow: 0 1px 0 var(--wu-header-scrolled-line, transparent);
}

@media (min-width: 768px) {
	:where(body.wu-header-over) .wp-site-blocks > header.wp-block-template-part::before {
		background: none;
		-webkit-backdrop-filter: none;
		backdrop-filter: none;
		box-shadow: none;
	}
}

@media (min-width: 768px) and (min-height: 480px) {
	:where(html.wu-scrolled body.wu-header-over.wu-header-pinned) .wp-site-blocks > header.wp-block-template-part::before {
		inset: 0 0 auto;
		height: var(--wu-header-over-h, var(--wu-header-h, 72px));
		background: var(--wu-header-part-ground, transparent);
		-webkit-backdrop-filter: var(--wu-header-frost, none);
		backdrop-filter: var(--wu-header-frost, none);
		box-shadow: 0 1px 0 var(--wu-header-scrolled-line, transparent);
	}
}

@media (max-width: 767.98px) {
	:where(body.wu-header-over:not(.wu-header-solid-phones)) .wp-site-blocks > header.wp-block-template-part::before {
		background: none;
		-webkit-backdrop-filter: none;
		backdrop-filter: none;
		box-shadow: none;
	}
}

@media (max-width: 767.98px) and (min-height: 480px) {
	:where(html.wu-scrolled body.wu-header-over.wu-header-pinned.wu-header-pinned-phones:not(.wu-header-solid-phones)) .wp-site-blocks > header.wp-block-template-part::before {
		inset: 0 0 auto;
		height: var(--wu-header-over-h, var(--wu-header-h, 72px));
		background: var(--wu-header-part-ground, transparent);
		-webkit-backdrop-filter: var(--wu-header-frost, none);
		backdrop-filter: var(--wu-header-frost, none);
		box-shadow: 0 1px 0 var(--wu-header-scrolled-line, transparent);
	}
}

@media (prefers-reduced-motion: reduce) {
	.wp-site-blocks > header.wp-block-template-part::before {
		transition: none;
	}
}
