/*
 * The site's header (`SiteHeader`), its panels and its overlays. Measured
 * from the mockups in docs/mattrs/design/header.
 *
 * Two colours theme all of it: the surface and the ink. The block writes
 * them from its own colour settings; without those they are the site's base
 * and contrast. The bar is as wide as the screen, and what it holds keeps
 * to the site's wide width. No WordPress class is named here, on purpose: the
 * dashboard's header is meant to take the same rules.
 */

.mattrs-header {
	--mattrs-header-surface: var(--wp--preset--color--base, #f9f9fa);
	--mattrs-header-ink: var(--wp--preset--color--contrast, #000000);
	--mattrs-header-rule: color-mix(in srgb, var(--mattrs-header-ink) 9%, transparent);
	--mattrs-header-curtain: rgb(0 0 0 / 35%);
	--mattrs-header-height: 59px;
	--mattrs-header-icon: 32px;
	--mattrs-header-gutter: clamp(16px, 4.4vw, 66px);
	--mattrs-header-wide: var(--wp--style--global--wide-size, 1800px);
	--mattrs-header-slide: 0.45s;
	--mattrs-header-unfold: 0.45s;
	--mattrs-header-fold: 0.3s;
	position: relative;
	z-index: 10;
	box-sizing: border-box;
	padding-inline: var(--mattrs-header-gutter);
	background: var(--mattrs-header-surface);
	color: var(--mattrs-header-ink);
	font-size: 16px;
	font-weight: 600;
	line-height: 1.2;
}

.mattrs-header__bar {
	display: flex;
	align-items: center;
	max-width: var(--mattrs-header-wide);
	margin-inline: auto;
	height: var(--mattrs-header-height);
}

.mattrs-header a,
.mattrs-overlay a {
	color: inherit;
	text-decoration: none;
}

/* As the old theme had it for its navigation: nothing in the header is outlined. */
.mattrs-header :is(a, button, dialog):focus {
	outline: none;
}

/* The logo: the wordmark, and the mark alone on a phone. */

.mattrs-header__logo {
	display: flex;
	align-items: center;
	margin-right: auto;
}

.mattrs-header__logo svg {
	display: block;
}

.mattrs-header__logo .mattrs-header__mark {
	display: none;
}

/*
 * The main menu. It and its items are as tall as the bar, so the pointer
 * never leaves an item on its way down to that item's panel.
 */

.mattrs-header__nav {
	position: relative;
	align-self: stretch;
}

.mattrs-header__nav > ul {
	display: flex;
	gap: 37.5px;
	height: 100%;
	margin: 0;
	padding: 0;
	list-style: none;
}

.mattrs-header__nav > ul > li {
	display: flex;
	align-items: center;
}

.mattrs-header__nav > ul > li > a:hover {
	opacity: 0.7;
}

/*
 * An item's panel: under the bar, from the menu's left edge, on a surface
 * as wide as the screen. It unrolls from the bar and rolls back up into it,
 * as if the header grew: the clip that keeps the surface to the panel's
 * height is what moves. The surface is a shadow clipped to the panel's
 * height, so the panel itself can stay in the menu's box.
 */

.mattrs-header__panel {
	position: absolute;
	top: 100%;
	left: 0;
	visibility: hidden;
	padding: 44px 0 46px;
	background: var(--mattrs-header-surface);
	box-shadow: 0 0 0 100vmax var(--mattrs-header-surface);
	clip-path: inset(0 -100vmax 100% -100vmax);
	transition: clip-path var(--mattrs-header-fold) cubic-bezier(0.4, 0, 0.2, 1), visibility 0s var(--mattrs-header-fold);
}

.mattrs-header__parent:is(:hover, :focus-within) > .mattrs-header__panel {
	visibility: visible;
	clip-path: inset(0 -100vmax 0 -100vmax);
	transition: clip-path var(--mattrs-header-unfold) cubic-bezier(0.22, 1, 0.36, 1), visibility 0s;
}

/*
 * Search on a wide screen: a panel as a menu item's is, opened by the
 * script (`is-searching`).
 */

.mattrs-header__drop {
	position: absolute;
	top: 100%;
	right: 0;
	left: 0;
	box-sizing: border-box;
	visibility: hidden;
	min-height: 284px;
	padding: 44px max(var(--mattrs-header-gutter), (100% - var(--mattrs-header-wide)) / 2);
	background: var(--mattrs-header-surface);
	box-shadow: 0 0 0 100vmax var(--mattrs-header-surface);
	clip-path: inset(0 -100vmax 100% -100vmax);
	transition: clip-path var(--mattrs-header-fold) cubic-bezier(0.4, 0, 0.2, 1), visibility 0s var(--mattrs-header-fold);
}

.mattrs-header.is-searching .mattrs-header__drop {
	visibility: visible;
	clip-path: inset(0 -100vmax 0 -100vmax);
	transition: clip-path var(--mattrs-header-unfold) cubic-bezier(0.22, 1, 0.36, 1), visibility 0s;
}

/*
 * The curtain: the page under an open panel, dimmed. It hangs from the
 * bar's foot, behind the panels, and takes no clicks, so a click on the
 * page is still a click on the page. It is ordered from nought up, with the
 * panels one above it: a curtain below nought was drawn under a page's own
 * layers in some browsers.
 */

.mattrs-header__panel,
.mattrs-header__drop {
	z-index: 1;
}

.mattrs-header::after {
	content: "";
	position: absolute;
	z-index: 0;
	top: 100%;
	right: 0;
	left: 0;
	height: 100vh;
	visibility: hidden;
	opacity: 0;
	background: var(--mattrs-header-curtain);
	box-shadow: 0 0 0 100vmax var(--mattrs-header-curtain);
	clip-path: inset(0 -100vmax);
	pointer-events: none;
	transition: opacity var(--mattrs-header-fold), visibility 0s var(--mattrs-header-fold);
}

.mattrs-header:is(.is-searching, :has(.mattrs-header__parent:is(:hover, :focus-within)))::after {
	visibility: visible;
	opacity: 1;
	transition-delay: 0s;
}

/* A panel's lists, in the bar and in the phone's menu alike. */

.mattrs-menu {
	display: grid;
	grid-template-columns: minmax(271px, max-content) max-content;
	align-items: start;
	font-weight: 500;
}

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

.mattrs-menu a {
	display: block;
	white-space: nowrap;
}

.mattrs-menu a:hover {
	opacity: 0.7;
}

.mattrs-menu__major a {
	padding: 5px 0;
	font-size: 24px;
}

.mattrs-menu__minor a {
	padding: 4px 0;
}

/* Search, the basket, the menu button, the account button. */

.mattrs-header__tools {
	display: flex;
	align-items: center;
	gap: 16px;
	margin-left: 63px;
}

.mattrs-header__icon {
	display: grid;
	place-items: center;
	width: var(--mattrs-header-icon, 32px);
	height: var(--mattrs-header-icon, 32px);
	padding: 0;
	border: 0;
	border-radius: 2px;
	background: none;
	color: inherit;
	cursor: pointer;
}

.mattrs-header__icon:hover {
	opacity: 0.7;
}

.mattrs-header__glyph {
	display: block;
}

.mattrs-header__basket {
	display: flex;
}

/* The dot, in the slot's own icon, until the widget draws its own. */
.mattrs-header__dot {
	display: none;
	fill: var(--mattrs-header-accent, #3932e7);
}

[data-pmx-held] .mattrs-header__dot {
	display: inline;
}

.mattrs-header__burger {
	display: none;
}

.mattrs-header__rule {
	width: 1px;
	height: 19px;
	margin: 0 -1px 0 8px;
	background: var(--mattrs-header-rule);
}

.mattrs-header__account {
	display: grid;
	place-items: center;
	box-sizing: border-box;
	min-width: 111px;
	height: 34px;
	padding: 0 13px;
	border: 1px solid var(--mattrs-header-ink);
	border-radius: 2px;
	white-space: nowrap;
}

/* Filled on hover, and for good once the dashboard's widget marks it signed in. */
.mattrs-header .mattrs-header__account:is(:hover, [data-pmx-account="in"]) {
	background: var(--mattrs-header-ink);
	color: var(--mattrs-header-surface);
}

.mattrs-header__account[data-pmx-account="in"]:hover {
	opacity: 0.85;
}

/*
 * The phone's bar. With no script the menu stays in the page, under the bar,
 * and there is no button to open what cannot be opened.
 */

@media (max-width: 959px) {
	.mattrs-header {
		--mattrs-header-height: 50px;
	}

	.mattrs-header__logo .mattrs-header__wordmark {
		display: none;
	}

	.mattrs-header__logo .mattrs-header__mark {
		display: block;
	}

	.mattrs-header__bar {
		flex-wrap: wrap;
		height: auto;
		min-height: var(--mattrs-header-height);
	}

	.mattrs-header__nav {
		order: 3;
		width: 100%;
		padding-bottom: 12px;
	}

	.mattrs-header__nav > ul {
		flex-wrap: wrap;
		gap: 12px 24px;
	}

	.mattrs-header__panel,
	.mattrs-header__drop,
	.mattrs-header::after {
		display: none;
	}

	.mattrs-header__tools {
		margin-left: 0;
	}

	.mattrs-header--js .mattrs-header__nav,
	.mattrs-header--js .mattrs-header__bar .mattrs-header__rule,
	.mattrs-header--js .mattrs-header__bar .mattrs-header__account {
		display: none;
	}

	.mattrs-header--js .mattrs-header__burger {
		display: grid;
	}

	/* The last glyph ends at the gutter, not its box. */
	.mattrs-header--js .mattrs-header__tools {
		margin-right: -8px;
	}
}

/* An overlay: the whole screen, the bar included. */

.mattrs-overlay {
	position: fixed;
	inset: 0;
	box-sizing: border-box;
	width: 100%;
	max-width: none;
	height: 100%;
	max-height: none;
	margin: 0;
	padding: 78px 47px 32px;
	border: 0;
	overflow: hidden auto;
	overscroll-behavior: contain;
	background: var(--mattrs-header-surface);
	color: var(--mattrs-header-ink);
}

.mattrs-overlay:not([open]) {
	display: none;
}

/*
 * An overlay unrolls from the top of the screen, where the bar is, and rolls
 * back up. A dialog leaves the screen the moment it closes, so the script
 * holds it open (`is-closing`) until it has rolled up.
 */

.mattrs-overlay[open] {
	animation: mattrs-overlay-unfold var(--mattrs-header-unfold) cubic-bezier(0.22, 1, 0.36, 1);
}

.mattrs-overlay[open] > :is(nav, .mattrs-header__search, .mattrs-overlay__account) {
	animation: mattrs-overlay-settle var(--mattrs-header-unfold) cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.mattrs-overlay.is-closing {
	animation: mattrs-overlay-fold var(--mattrs-header-fold) cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.mattrs-overlay:focus {
	outline: none;
}

@keyframes mattrs-overlay-unfold {
	from {
		clip-path: inset(0 0 100% 0);
	}

	to {
		clip-path: inset(0);
	}
}

@keyframes mattrs-overlay-fold {
	from {
		clip-path: inset(0);
	}

	to {
		clip-path: inset(0 0 100% 0);
	}
}

@keyframes mattrs-overlay-settle {
	from {
		opacity: 0;
		transform: translateY(-12px);
	}
}

.mattrs-overlay::backdrop {
	background: none;
}

html:has(.mattrs-overlay[open]) {
	overflow: hidden;
}

.mattrs-overlay__close {
	position: absolute;
	z-index: 1;
	top: 9px;
	right: 8px;
	margin: 0;
}

.mattrs-header__search {
	display: flex;
	align-items: center;
	gap: 16px;
	margin: 0;
	padding: 0;
}

.mattrs-overlay > .mattrs-header__search {
	margin-top: -16px;
}

.mattrs-header__search label {
	display: flex;
}

.mattrs-header__search label svg {
	width: 22px;
	height: 22px;
}

.mattrs-header__search input {
	flex: 1;
	min-width: 0;
	padding: 8px 0;
	border: 0;
	outline: 0;
	background: none;
	color: inherit;
	font: inherit;
	font-size: 20px;
	font-weight: 400;
	appearance: none;
}

.mattrs-header__search input::placeholder {
	color: inherit;
	opacity: 0.6;
}

.mattrs-header__search input::-webkit-search-cancel-button {
	display: none;
}

/* The phone's menu, and the panels that slide over it. */

.mattrs-overlay__menu ul {
	margin: 0;
	padding: 0;
	list-style: none;
}

.mattrs-overlay__menu :is(a, button) {
	display: block;
	width: 100%;
	padding: 16px 0;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	font-size: 22px;
	font-weight: 500;
	text-align: left;
	cursor: pointer;
}

.mattrs-overlay__account {
	margin-top: 24px;
	padding-top: 32px;
	border-top: 1px solid var(--mattrs-header-rule);
}

.mattrs-overlay__account .mattrs-header__account {
	height: 44px;
}

.mattrs-overlay__panel {
	position: absolute;
	inset: 62px 0 0;
	box-sizing: border-box;
	visibility: hidden;
	padding: 16px 44px 32px;
	overflow: hidden auto;
	background: var(--mattrs-header-surface);
	transform: translateX(100%);
	transition: transform var(--mattrs-header-slide) cubic-bezier(0.22, 1, 0.36, 1), visibility 0s var(--mattrs-header-slide);
}

.mattrs-overlay__panel.is-open {
	visibility: visible;
	transform: none;
	transition-delay: 0s;
}

/* Back waits for the panel to arrive, and leaves as the panel sets off. */
.mattrs-overlay__back {
	position: absolute;
	top: 9px;
	left: 8px;
	visibility: hidden;
	opacity: 0;
	transition: opacity 0.15s ease, visibility 0s 0.15s;
}

.mattrs-overlay.is-deep .mattrs-overlay__back {
	visibility: visible;
	opacity: 1;
	transition: opacity 0.25s ease var(--mattrs-header-slide), visibility 0s var(--mattrs-header-slide);
}

.mattrs-overlay__panel .mattrs-menu {
	display: block;
}

.mattrs-overlay__panel .mattrs-menu__major a {
	padding: 16px 0;
	font-size: 22px;
}

.mattrs-overlay__panel .mattrs-menu__minor {
	margin-top: 40px;
}

.mattrs-overlay__panel .mattrs-menu__minor a {
	padding: 14px 0;
	font-size: 15px;
}

@media (prefers-reduced-motion: reduce) {
	.mattrs-header__panel,
	.mattrs-header__drop,
	.mattrs-header::after,
	.mattrs-overlay__panel,
	.mattrs-overlay .mattrs-overlay__back {
		transition: none;
	}

	.mattrs-overlay[open],
	.mattrs-overlay[open] > *,
	.mattrs-overlay.is-closing {
		animation: none;
	}
}
