/**
 * The site header — the logo, and the rule that tracks the navigation.
 *
 * One rule, not one per item: a single bar under the list slides to whichever
 * item the pointer is over and settles back on the current page when it leaves.
 * It is drawn as an ::after on the list, positioned from two custom properties
 * that assets/js/header-nav.js measures and writes.
 *
 * Until that script has run — and if it never does — the active item carries a
 * border of its own instead, so the current page is marked either way. The
 * script adds .is-tracking to the list, which is what turns that border off.
 *
 * @package homewood_theme
 */

.hw-header {
	--hw-logo-height: clamp(3.5rem, 6vw, 5.5rem);

	--hw-nav-rule: var(--wp--preset--color--wheat, #C3A87F);
	--hw-nav-rule-size: 2px;
	/* How far under the labels the rule sits. */
	--hw-nav-rule-drop: 0.9em;
	--hw-nav-speed: 0.35s;
}

.hw-header__logo {
	display: block;
	line-height: 0;
}

.hw-header__logo img {
	display: block;
	width: auto;
	height: var(--hw-logo-height);
}

/*
 * The class lands on both the <nav> and the list inside it, so this is spelled
 * against the list specifically. Submenu lists carry a different class, which
 * keeps the rule to the top level where it belongs.
 */
.hw-header ul.hw-header__nav {
	position: relative;
}

.hw-header ul.hw-header__nav::after {
	content: "";
	position: absolute;
	top: 100%;
	left: 0;
	width: var(--hw-nav-rule-width, 0);
	height: var(--hw-nav-rule-size);
	margin-top: var(--hw-nav-rule-drop);
	background: var(--hw-nav-rule);
	/* Nothing measured yet, so nothing to show. */
	opacity: var(--hw-nav-rule-opacity, 0);
	transform: translateX(var(--hw-nav-rule-x, 0));
	transition:
		transform var(--hw-nav-speed) ease,
		width var(--hw-nav-speed) ease,
		opacity var(--hw-nav-speed) ease;
	pointer-events: none;
}

/* The rule slides; it should not slide in from nowhere on the first paint. */
.hw-header ul.hw-header__nav:not(.is-tracking)::after {
	transition: none;
}

/*
 * The fallback, and what is on screen for the moment before the script runs:
 * the current page, or the parent of one, underlines itself.
 */
.hw-header ul.hw-header__nav:not(.is-tracking) > .current-menu-item > .wp-block-navigation-item__content,
.hw-header ul.hw-header__nav:not(.is-tracking) > .current-menu-ancestor > .wp-block-navigation-item__content {
	padding-bottom: var(--hw-nav-rule-drop);
	border-bottom: var(--hw-nav-rule-size) solid var(--hw-nav-rule);
}

/* Stacked in the overlay, where a bar sliding across a column means nothing. */
.hw-header .is-menu-open ul.hw-header__nav::after {
	display: none;
}

@media (prefers-reduced-motion: reduce) {
	.hw-header ul.hw-header__nav::after {
		transition: opacity var(--hw-nav-speed) ease;
	}
}

/* -- Sticky --------------------------------------------------------------- */

/*
 * The sticky lives on the template part wrapper, not on .hw-header inside it.
 * A sticky element is held within its parent's box, and .hw-header's parent is
 * this wrapper — which is exactly as tall as the header, leaving it nowhere to
 * travel. The wrapper's own parent is the page, so that is what can stick.
 *
 * It carries the background as well: the page scrolls underneath, and cream on
 * cream is the difference between a header and a smear of overlapping text.
 */
header.wp-block-template-part {
	--hw-header-ground: var(--wp--preset--color--cream, #f6f1ea);
	padding: 10px 40px;
	position: sticky;
	top: 0;
	z-index: 20;
	background: var(--hw-header-ground);
	transition: box-shadow 0.3s ease;
}

/*
 * Added by assets/js/header-nav.js once the page has scrolled past 50px. A
 * hairline to draw the edge, and a soft drop under it to lift the band off
 * whatever is passing beneath.
 */
header.wp-block-template-part.is-scrolled {
	box-shadow:
		0 1px 0 rgba(37, 43, 35, 0.08),
		0 6px 18px -6px rgba(37, 43, 35, 0.18);
}

/* Clear of the admin bar, which is fixed over the top of the page. */
body.admin-bar header.wp-block-template-part {
	top: 32px;
}

/* Below this the admin bar scrolls away with the page, so there is nothing to clear. */
@media screen and (max-width: 600px) {
	body.admin-bar header.wp-block-template-part {
		top: 0;
	}
}

/* -- The overlay menu ----------------------------------------------------- */

/*
 * The colour is not set here. Core paints an unpainted overlay #fff from a
 * selector carrying more weight than anything scoped to .hw-header can, so it
 * comes from the block instead: overlayBackgroundColor on wp:navigation in
 * parts/header.html, which puts a preset class on the container, and preset
 * colour classes are !important. Change it there, not here.
 *
 * The rules below are spelled with core's own :not(.disable-default-overlay)
 * on the end so they carry more weight than the ones they replace, whichever
 * stylesheet the page happens to print last.
 */
.hw-header .wp-block-navigation__responsive-container.is-menu-open:not(.disable-default-overlay) {
	padding: clamp(1.5rem, 6vw, 3rem);
}

.hw-header .wp-block-navigation__responsive-container.is-menu-open:not(.disable-default-overlay) ul.hw-header__nav {
	gap: 0;
	padding-block: clamp(1rem, 5vw, 2.5rem);
}

/*
 * Set at H2, which steps down with the screen the way the headings do — so the
 * overlay is reading size on a phone rather than the desktop 46px.
 */
.hw-header .wp-block-navigation__responsive-container.is-menu-open:not(.disable-default-overlay) .wp-block-navigation-item__content {
	display: block;
	padding-block: 0.3em;
	font-size: var(--wp--preset--font-size--h-2, 2.875rem);
	line-height: 1.1;
}

/*
 * The same sage rule as the desktop, drawn per item rather than slid between
 * them — a bar travelling down a stacked column would be following the pointer
 * rather than saying anything. text-decoration rather than a border, so it sits
 * under the label at whatever width the label is, and not the full block.
 */
.hw-header .wp-block-navigation__responsive-container.is-menu-open:not(.disable-default-overlay) .wp-block-navigation-item__content {
	text-decoration: none;
	text-decoration-color: var(--hw-nav-rule);
	text-decoration-thickness: var(--hw-nav-rule-size);
	text-underline-offset: 0.3em;
}

.hw-header .wp-block-navigation__responsive-container.is-menu-open:not(.disable-default-overlay) .current-menu-item > .wp-block-navigation-item__content,
.hw-header .wp-block-navigation__responsive-container.is-menu-open:not(.disable-default-overlay) .current-menu-ancestor > .wp-block-navigation-item__content,
.hw-header .wp-block-navigation__responsive-container.is-menu-open:not(.disable-default-overlay) .wp-block-navigation-item__content:hover,
.hw-header .wp-block-navigation__responsive-container.is-menu-open:not(.disable-default-overlay) .wp-block-navigation-item__content:focus-visible {
	text-decoration: underline;
}
