/**
 * Site header.
 *
 * Two states, driven by custom properties so every colour transitions together:
 *   Solid (default, scrolled, menu open, no-JS, pages without a hero): cream bar, dark text.
 *   Over the hero (front page, at the top): transparent, light text. The cream
 *   bar is clipped down to a small "label" behind the logo (the logo is made for
 *   cream); on scroll the label unfurls across the full width into the bar.
 */

.scroll-sentinel {
	position: absolute;
	top: 0;
	left: 0;
	width: 1px;
	height: 40px; /* scroll distance before the header turns solid */
	pointer-events: none;
	visibility: hidden;
}

.site-header {
	/* Solid state */
	--hdr-h: var(--ph-header-h);
	--hdr-fg: var(--ph-deep);
	--hdr-underline: var(--ph-forest);
	--ph-focus: var(--ph-forest);
	--ph-top: 0px;

	position: fixed;
	top: var(--ph-top);
	right: 0;
	left: 0;
	z-index: var(--ph-z-header);
	color: var(--hdr-fg);
	animation: ph-header-in 1.1s var(--ph-ease-out) 0.1s both;
}

.site-header.is-scrolled,
.site-header.is-open {
	--hdr-h: var(--ph-header-h-compact);
}

/* Over the hero, at the top of the page */
.js .has-hero .site-header:not(.is-scrolled, .is-open) {
	--hdr-fg: var(--ph-cream);
	--hdr-underline: var(--ph-gold);
	--ph-focus: var(--ph-gold);

	/* The hero photo has no shading layer, so light links and the menu icon
	   carry a soft shadow to stay readable on bright sky. */
	text-shadow: 0 1px 2px rgb(0 0 0 / 0.5), 0 1px 12px rgb(0 0 0 / 0.35);
}

.js .has-hero .site-header:not(.is-scrolled, .is-open) .nav-toggle__icon {
	filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.55));
}

/* WordPress admin bar */
.admin-bar .site-header {
	--ph-top: 32px;
}

@media (max-width: 782px) {
	.admin-bar .site-header {
		--ph-top: 46px;
	}
}

@media (max-width: 600px) {
	/* The admin bar scrolls away on small screens. */
	.admin-bar .site-header.is-scrolled {
		--ph-top: 0px;
	}
}

/* Background bar ------------------------------------------------------- */

.site-header__bar {
	/* Edges of the logo label, measured from the bar's own edges. */
	--logo-x: max((100% - var(--ph-container)) / 2, var(--ph-gutter));
	--tab-l: calc(var(--logo-x) - var(--ph-tab-pad-l));
	--tab-r: calc(100% - var(--logo-x) - var(--ph-logo-w) - var(--ph-tab-pad-r));

	position: absolute;
	inset: 0;
	z-index: 2;
	background: var(--ph-cream);
	clip-path: inset(0 0 0 0 round 0 0 0 0);
}

.site-header__bar::after {
	content: "";
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	height: 1px;
	background: var(--ph-color-hairline);
}

.js .has-hero .site-header:not(.is-scrolled, .is-open) .site-header__bar {
	clip-path: inset(0 var(--tab-r) 0 var(--tab-l) round 0 0 var(--ph-tab-radius-r) var(--ph-tab-radius-l));
}

.js .has-hero .site-header:not(.is-scrolled, .is-open) .site-header__bar::after {
	opacity: 0;
}

/* With a light logo there is no label: the bar simply settles in from above. */
.js .has-hero.has-light-logo .site-header:not(.is-scrolled, .is-open) .site-header__bar {
	clip-path: inset(0 0 100% 0 round 0 0 0 0);
}

/* Transitions start only after the initial state is set, so a page that
   loads part-way down does not animate from the transparent state. */
.site-header.is-ready .site-header__bar {
	transition: clip-path 0.75s var(--ph-ease-in-out);
}

.site-header.is-ready .site-header__bar::after {
	transition: opacity var(--ph-dur-base) var(--ph-ease-out) 0.3s;
}

/* Layout -------------------------------------------------------------- */

.site-header__inner {
	position: relative;
	display: flex;
	align-items: center;
	gap: var(--ph-space-s);
	min-height: var(--hdr-h);
}

.site-header.is-ready .site-header__inner {
	transition: min-height 0.6s var(--ph-ease-in-out);
}

/* Logo and toggle sit above the bar; the nav itself stays out of the
   stacking order so the mobile panel can slide in beneath the bar. */
.site-branding,
.nav-toggle {
	position: relative;
	z-index: 3;
}

.site-branding {
	flex: none;
	margin-right: auto;
	line-height: 0;
}

.site-logo,
.custom-logo-link {
	display: inline-block;
	border-radius: 0.25rem;
}

.site-logo__img,
.custom-logo {
	width: var(--ph-logo-w);
	height: auto;
	transform-origin: left center;
	transition: transform 0.6s var(--ph-ease-in-out), opacity var(--ph-dur-base) var(--ph-ease-out);
}

.site-header.is-scrolled .site-logo__img,
.site-header.is-scrolled .custom-logo,
.site-header.is-open .site-logo__img {
	transform: scale(var(--ph-logo-scale-compact));
}

/* Light logo swap (only when assets/images/logo-light.svg exists) */
.site-logo {
	display: inline-grid;
}

.site-logo > .site-logo__img {
	grid-area: 1 / 1;
}

.site-logo__img--light {
	opacity: 0;
}

.js .has-light-logo .site-header:not(.is-scrolled, .is-open) .site-logo__img:not(.site-logo__img--light) {
	opacity: 0;
}

.js .has-light-logo .site-header:not(.is-scrolled, .is-open) .site-logo__img--light {
	opacity: 1;
}

/* Desktop navigation -------------------------------------------------- */

.primary-menu {
	margin: 0;
	padding: 0;
	list-style: none;
}

@media (min-width: 68rem) {
	.primary-nav__panel {
		position: relative;
		z-index: 3;
		display: flex;
		align-items: center;
	}

	.primary-menu {
		display: flex;
		align-items: center;
		gap: clamp(1.5rem, 2.6vw, 2.5rem);
	}

	.primary-menu a {
		position: relative;
		display: inline-flex;
		align-items: center;
		min-height: var(--ph-tap);
		color: var(--hdr-fg);
		font-size: var(--ph-fs-nav);
		font-weight: 500;
		letter-spacing: 0.01em;
		text-decoration: none;
		transition: color var(--ph-dur-base) var(--ph-ease-out);
	}

	.primary-menu a::after {
		content: "";
		position: absolute;
		right: 0;
		bottom: 0.625rem;
		left: 0;
		height: 1px;
		background: var(--hdr-underline);
		transform: scaleX(0);
		transform-origin: right center;
		transition: transform 0.5s var(--ph-ease-out), background-color var(--ph-dur-base) var(--ph-ease-out);
	}

	.primary-menu a:hover::after,
	.primary-menu a:focus-visible::after,
	.primary-menu .current-menu-item > a::after {
		transform: scaleX(1);
		transform-origin: left center;
	}
}

/* Menu toggle ---------------------------------------------------------- */

.nav-toggle {
	display: inline-grid;
	place-items: center;
	flex: none;
	width: var(--ph-tap);
	height: var(--ph-tap);
	margin-right: -0.625rem; /* optically align the icon with the gutter */
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--hdr-fg);
	cursor: pointer;
	transition: color var(--ph-dur-base) var(--ph-ease-out);
}

.nav-toggle__icon {
	position: relative;
	display: block;
	width: 1.375rem;
	height: 0.5rem;
}

.nav-toggle__icon > span {
	position: absolute;
	left: 0;
	width: 100%;
	height: 1.5px;
	border-radius: 1px;
	background: currentColor;
	transition: transform var(--ph-dur-base) var(--ph-ease-in-out), top var(--ph-dur-base) var(--ph-ease-in-out);
}

.nav-toggle__icon > span:first-child {
	top: 0;
}

.nav-toggle__icon > span:last-child {
	top: calc(100% - 1.5px);
}

.nav-toggle[aria-expanded="true"] .nav-toggle__icon > span:first-child {
	top: calc(50% - 0.75px);
	transform: rotate(45deg);
}

.nav-toggle[aria-expanded="true"] .nav-toggle__icon > span:last-child {
	top: calc(50% - 0.75px);
	transform: rotate(-45deg);
}

@media (min-width: 68rem) {
	.nav-toggle {
		display: none;
	}
}

/* Mobile and tablet panel --------------------------------------------- */

@media (max-width: 67.999rem) {
	.primary-nav__panel {
		--ph-focus: var(--ph-gold);

		position: fixed;
		inset: 0;
		z-index: 1;
		display: flex;
		flex-direction: column;
		gap: var(--ph-space-l);
		padding:
			calc(var(--ph-top) + var(--hdr-h) + var(--ph-space-l))
			var(--ph-gutter)
			calc(var(--ph-space-l) + env(safe-area-inset-bottom, 0px));
		overflow-y: auto;
		overscroll-behavior: contain;
		background: var(--ph-deep);
		color: var(--ph-cream);
		visibility: hidden;
		opacity: 0;
		transition:
			opacity var(--ph-dur-base) var(--ph-ease-out),
			visibility 0s linear var(--ph-dur-base);
	}

	.site-header.is-open .primary-nav__panel {
		visibility: visible;
		opacity: 1;
		transition: opacity var(--ph-dur-base) var(--ph-ease-out);
	}

	.primary-menu {
		width: 100%;
		max-width: var(--ph-container);
		margin-inline: auto;
	}

	.primary-menu li {
		border-bottom: 1px solid rgb(var(--ph-cream-rgb) / 0.14);
		opacity: 0;
		transform: translateY(0.75rem);
		transition:
			opacity var(--ph-dur-base) var(--ph-ease-out),
			transform var(--ph-dur-slow) var(--ph-ease-out);
	}

	.site-header.is-open .primary-menu li {
		opacity: 1;
		transform: none;
		transition-delay: calc(0.12s + var(--i, 0) * 0.055s);
	}

	.primary-menu li:nth-child(2) { --i: 1; }
	.primary-menu li:nth-child(3) { --i: 2; }
	.primary-menu li:nth-child(4) { --i: 3; }
	.primary-menu li:nth-child(5) { --i: 4; }
	.primary-menu li:nth-child(6) { --i: 5; }
	.primary-menu li:nth-child(7) { --i: 6; }
	.primary-menu li:nth-child(n + 8) { --i: 7; }

	.primary-menu a {
		display: flex;
		align-items: center;
		min-height: var(--ph-tap);
		padding: 0.875rem 0;
		color: var(--ph-cream);
		font-family: var(--ph-font-heading);
		font-size: var(--ph-fs-panel-nav);
		font-weight: var(--ph-fw-display);
		letter-spacing: -0.015em;
		line-height: 1.15;
		text-decoration: none;
		transition: color var(--ph-dur-fast) var(--ph-ease-out);
	}

	.primary-menu a:hover,
	.primary-menu .current-menu-item > a {
		color: var(--ph-gold);
	}


	html.ph-nav-open {
		overflow: hidden;
	}
}

/* Load-in --------------------------------------------------------------- */

@keyframes ph-header-in {
	from {
		opacity: 0;
	}

	to {
		opacity: 1;
	}
}
