/* 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`. 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, which then opens inside the header instead of
 * over the screen. A child that wants a frosted ground puts it on the
 * part's ::before (webupp's and VirtualCRO's). 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);
}

/* Pinned, from 768px up: under WordPress's toolbar where there is one. */
@media (min-width: 768px) {
	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) {
	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) {
	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. */
body.wu-header-over .wp-site-blocks > header.wp-block-template-part {
	position: absolute;
	inset: 0 0 auto;
}

@media (min-width: 768px) {
	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) {
	body.wu-header-over.wu-header-pinned.wu-header-pinned-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) {
	body.wu-header-over.wu-header-pinned.wu-header-pinned-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). */
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;
}
