/**
 * Nav Menu — Peak Starter's navigation, as a widget.
 *
 * This file is deliberately a mirror of the theme's own `.site-nav` block
 * (peak-starter/assets/css/base.css). A header assembled from Peak widgets and a
 * header the theme renders itself have to be indistinguishable, so the geometry,
 * the timings and the states are copied rather than reinvented: a muted label
 * that takes a filled pill on the current page, and a bordered dropdown 6px
 * below with a hover bridge across the gap. Hover LOOKS are the element's own
 * hover state now (Peak_Settings::STATES), not controls in here.
 *
 * Every value is a `--pkn-*` custom property whose default is the THEME token
 * with a literal fallback, so the widget inherits Peak Starter automatically,
 * follows a theme that defines the same tokens, and still looks right on one
 * that defines neither.
 *
 * @package Peak
 */

.peak-nav {
	--pkn-gap: 0.15rem;
	--pkn-dur: 150ms;
	--pkn-ease: var(--peak-ease, cubic-bezier(0.2, 0.7, 0.2, 1));

	--pkn-color: var(--peak-muted, #5f5d5a);
	--pkn-color-current: var(--peak-accent-fg, var(--peak-canvas, #fff));
	--pkn-bg-current: var(--peak-accent, var(--peak-ink, #191919));

	--pkn-radius: var(--peak-radius-pill, 9999px);
	--pkn-pad-x: 0.65em;
	--pkn-pad-y: 0.35em;
	--pkn-min-h: 36px;

	--pkn-sub-w: 220px;
	--pkn-sub-pad: 0.45em;
	--pkn-sub-bg: var(--peak-surface, #fcfbfa);
	--pkn-sub-color: inherit;
	--pkn-sub-radius: var(--peak-radius, 10px);
	--pkn-sub-border: var(--peak-border, rgba(25, 25, 25, 0.1));
	--pkn-sub-shadow: var(--peak-shadow-pop, 0 12px 32px rgba(25, 25, 25, 0.12), 0 1px 2px rgba(25, 25, 25, 0.08));

	--pkn-toggle-size: 24px;

	position: relative;
	display: flex;
	align-items: center;
	justify-content: var(--pkn-align, flex-start);
	min-width: 0;
}
.peak-nav *, .peak-nav *::before, .peak-nav *::after { box-sizing: border-box; }

.peak-nav__panel { display: contents; }

/* ---- lists ------------------------------------------------------------- */

/* Two classes deep on purpose: a theme's content styles reach these lists —
   Peak Starter's own `:is(.entry-content) ul { list-style: disc }` is (0,1,1) —
   so a single-class reset loses and the menu grows bullets. */
.peak-nav .peak-nav__list {
	display: flex;
	align-items: center;
	justify-content: var(--pkn-align, flex-start);
	flex-wrap: wrap;
	row-gap: var(--pkn-gap-r, var(--pkn-gap));
	column-gap: var(--pkn-gap-c, var(--pkn-gap));
	margin: 0;
	padding: 0;
	list-style: none;
}
.peak-nav .peak-nav__item { position: relative; list-style: none; margin: 0; }
.peak-nav .peak-nav__item::marker { content: ""; }
.peak-nav.is-nowrap .peak-nav__list--depth-0 { flex-wrap: nowrap; }

.peak-nav--vertical .peak-nav__list--depth-0 {
	flex-direction: column;
	align-items: var(--pkn-align, flex-start);
	justify-content: flex-start;
}

/* ---- the item ---------------------------------------------------------- */

.peak-nav__link {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 0.3em;
	min-height: var(--pkn-min-h);
	padding:
		var(--pkn-pad-t, var(--pkn-pad-y))
		var(--pkn-pad-r, var(--pkn-pad-x))
		var(--pkn-pad-b, var(--pkn-pad-y))
		var(--pkn-pad-l, var(--pkn-pad-x));
	border-radius: var(--pkn-radius);
	font-family: var(--pkn-ff, inherit);
	font-size: var(--pkn-fs, var(--peak-fs-small, 0.875rem));
	font-weight: var(--pkn-fw, 500);
	line-height: var(--pkn-lh, inherit);
	letter-spacing: var(--pkn-ls, normal);
	text-transform: var(--pkn-tt, none);
	color: var(--pkn-color);
	text-decoration: none;
	white-space: nowrap;
	transition: background-color var(--pkn-dur) var(--pkn-ease), color var(--pkn-dur) var(--pkn-ease);
}

/* An ancestor of the current page is emphasised but not filled — only the page
   you are actually on gets the pill. */
.peak-nav__item.is-ancestor > .peak-nav__link { color: var(--peak-ink, #191919); }
.peak-nav__item.is-current > .peak-nav__link {
	background-color: var(--pkn-bg-current);
	background-image: var(--pkn-bg-current-i, none);
	color: var(--pkn-color-current);
}

.peak-nav__index { font-size: 0.7em; opacity: 0.7; color: var(--pkn-index-color, inherit); }
.peak-nav__text { display: inline-block; }

.peak-nav.has-divider .peak-nav__list--depth-0 > .peak-nav__item + .peak-nav__item::before {
	content: "";
	position: absolute;
	left: calc(var(--pkn-gap) / -2);
	top: 50%;
	width: 1px;
	height: 1em;
	transform: translateY(-50%);
	background: var(--pkn-divider, currentColor);
	opacity: 0.35;
}

/* ---- the parent marker -------------------------------------------------- */

.peak-nav__sub-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 14px;
	height: 14px;
	margin-left: -0.1em;
	padding: 0;
	color: inherit;
	background: none;
	border: 0;
	cursor: pointer;
	opacity: 0.6;
	line-height: 0;
	transition: transform 0.2s var(--pkn-ease);
}
.peak-nav__sub-toggle svg { width: 14px; height: 14px; }
.peak-nav__item:hover > .peak-nav__sub-toggle,
.peak-nav__item:focus-within > .peak-nav__sub-toggle,
.peak-nav__item.is-open > .peak-nav__sub-toggle { transform: rotate(180deg); }

/* The submenu sits 6px below its parent; without a bridge the pointer crosses
   dead space on the way down and the menu closes under it. */
.peak-nav__item--has-sub > .peak-nav__link::before {
	content: "";
	position: absolute;
	inset: 100% 0 -8px;
}

/* ---- submenus ----------------------------------------------------------- */

.peak-nav .peak-nav__list--depth-1,
.peak-nav .peak-nav__list--depth-2,
.peak-nav .peak-nav__list--depth-3 {
	position: absolute;
	top: calc(100% + 6px);
	left: 0;
	z-index: 60;
	min-width: var(--pkn-sub-w);
	flex-direction: column;
	align-items: stretch;
	gap: 2px;
	padding: 6px;
	background-color: var(--pkn-sub-bg);
	background-image: var(--pkn-sub-bg-i, none);
	color: var(--pkn-sub-color);
	border: 1px solid var(--pkn-sub-border);
	border-radius: var(--pkn-sub-radius);
	box-shadow: var(--pkn-sub-shadow);
	opacity: 0;
	visibility: hidden;
	transform: translateY(-4px);
	transition: opacity var(--pkn-dur) var(--pkn-ease), transform var(--pkn-dur) var(--pkn-ease),
		visibility 0s linear var(--pkn-dur);
}
.peak-nav .peak-nav__list--depth-2,
.peak-nav .peak-nav__list--depth-3 { top: -6px; left: calc(100% + 4px); }
.peak-nav--vertical .peak-nav__list--depth-1 { top: -6px; left: calc(100% + 4px); }

.peak-nav--sub-hover .peak-nav__item:hover > .peak-nav__list,
.peak-nav--sub-hover .peak-nav__item:focus-within > .peak-nav__list,
.peak-nav__item.is-open > .peak-nav__list {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
	transition-delay: 0s;
}

.peak-nav .peak-nav__list--depth-1 .peak-nav__item,
.peak-nav .peak-nav__list--depth-2 .peak-nav__item { width: 100%; }

.peak-nav .peak-nav__list--depth-1 .peak-nav__link,
.peak-nav .peak-nav__list--depth-2 .peak-nav__link,
.peak-nav .peak-nav__list--depth-3 .peak-nav__link {
	display: flex;
	width: 100%;
	min-height: 34px;
	/* The sides used to be the vertical padding times 1.55 — a ratio nobody
	   could see or change. They are still that by default, and now they are
	   also four numbers somebody can type. */
	padding:
		var(--pkn-sub-pt, var(--pkn-sub-pad))
		var(--pkn-sub-pr, calc(var(--pkn-sub-pad) * 1.55))
		var(--pkn-sub-pb, var(--pkn-sub-pad))
		var(--pkn-sub-pl, calc(var(--pkn-sub-pad) * 1.55));
	border-radius: var(--peak-radius-sm, 6px);
	font-family: var(--pkn-sub-ff, inherit);
	font-size: var(--pkn-sub-fs, inherit);
	font-weight: var(--pkn-sub-fw, 400);
	line-height: var(--pkn-sub-lh, inherit);
	letter-spacing: var(--pkn-sub-ls, normal);
	text-transform: var(--pkn-sub-tt, none);
	white-space: normal;
}
.peak-nav .peak-nav__list--depth-1 .peak-nav__sub-toggle,
.peak-nav .peak-nav__list--depth-2 .peak-nav__sub-toggle {
	position: absolute;
	right: 0.6em;
	top: 50%;
	margin-top: -7px;
	transform: rotate(-90deg);
}
.peak-nav .peak-nav__list--depth-1 .peak-nav__item.is-open > .peak-nav__sub-toggle { transform: rotate(-90deg); }

/* A submenu that would open past the window's right edge opens leftwards; the
   runtime measures and sets this. */
.peak-nav__item.is-flipped > .peak-nav__list--depth-1 { left: auto; right: 0; }
.peak-nav__item.is-flipped > .peak-nav__list--depth-2,
.peak-nav__item.is-flipped > .peak-nav__list--depth-3 { left: auto; right: calc(100% + 4px); }

/* ---- mobile toggle -------------------------------------------------------- */

.peak-nav__toggle {
	display: none;
	align-items: center;
	gap: 0.5em;
	padding: 0;
	color: inherit;
	background: none;
	border: 0;
	cursor: pointer;
	font: inherit;
}
.peak-nav__burger {
	position: relative;
	display: block;
	width: var(--pkn-toggle-size);
	height: calc(var(--pkn-toggle-size) * 0.5);
}
.peak-nav__burger span {
	position: absolute;
	left: 0;
	width: 100%;
	height: 2px;
	background: currentColor;
	border-radius: 2px;
	transition: transform 0.2s var(--pkn-ease), opacity 0.2s var(--pkn-ease);
}
.peak-nav__burger span:first-child { top: 0; }
.peak-nav__burger span:last-child { bottom: 0; }
.peak-nav.is-open .peak-nav__burger span:first-child { transform: translateY(calc(var(--pkn-toggle-size) * 0.25 - 1px)) rotate(45deg); }
.peak-nav.is-open .peak-nav__burger span:last-child { transform: translateY(calc(var(--pkn-toggle-size) * -0.25 + 1px)) rotate(-45deg); }

/* ---- mobile ---------------------------------------------------------------
 * `is-mobile` comes from the runtime, because the breakpoint is a number the
 * author typed rather than something a media query can know.
 * ------------------------------------------------------------------------ */

.peak-nav.is-mobile .peak-nav__toggle { display: inline-flex; position: relative; z-index: 91; }

.peak-nav.is-mobile .peak-nav__panel {
	position: absolute;
	top: calc(100% + 0.75rem);
	left: 0;
	right: 0;
	z-index: 90;
	display: block;
	max-height: calc(100vh - var(--peak-header-h, 72px));
	padding: 0.75rem var(--peak-gutter, 1rem) 1.25rem;
	overflow-y: auto;
	overscroll-behavior: contain;
	background-color: var(--pkn-panel-bg, var(--peak-surface, #fcfbfa));
	background-image: var(--pkn-panel-bg-i, none);
	color: var(--pkn-panel-color, inherit);
	border-bottom: 1px solid var(--pkn-sub-border);
	box-shadow: var(--pkn-sub-shadow);
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.25s var(--pkn-ease), transform 0.25s var(--pkn-ease), visibility 0s linear 0.25s;
}
.peak-nav.is-mobile.is-open .peak-nav__panel {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: none;
	transition-delay: 0s;
}

.peak-nav.is-mobile .peak-nav__list { flex-direction: column; align-items: stretch; gap: 2px; }
.peak-nav.is-mobile .peak-nav__item { display: flex; flex-wrap: wrap; align-items: center; width: 100%; }
.peak-nav.is-mobile .peak-nav__link {
	flex: 1 1 auto;
	min-height: 44px;
	padding: 0.5em 0.9em;
	font-size: 1rem;
	white-space: normal;
	border-radius: var(--peak-radius-sm, 6px);
}
.peak-nav.is-mobile .peak-nav__item--has-sub > .peak-nav__link::before { display: none; }

/* The marker becomes a proper 44px target, beside the link rather than in it. */
.peak-nav.is-mobile .peak-nav__sub-toggle {
	position: static;
	width: 44px;
	height: 44px;
	margin: 0;
	opacity: 1;
	border-radius: var(--peak-radius-sm, 6px);
	transform: none;
}
.peak-nav.is-mobile .peak-nav__sub-toggle svg { width: 18px; height: 18px; }
.peak-nav.is-mobile .peak-nav__item.is-open > .peak-nav__sub-toggle { transform: rotate(180deg); }

.peak-nav.is-mobile .peak-nav__list--depth-1,
.peak-nav.is-mobile .peak-nav__list--depth-2,
.peak-nav.is-mobile .peak-nav__list--depth-3 {
	position: static;
	flex: 1 1 100%;
	min-width: 0;
	margin: 0;
	padding: 0 0 0.25rem 1rem;
	background: none;
	border: 0;
	box-shadow: none;
	opacity: 1;
	visibility: visible;
	transform: none;
	display: none;
}
.peak-nav.is-mobile .peak-nav__item.is-open > .peak-nav__list { display: flex; }
.peak-nav.is-mobile .peak-nav__list--depth-1 .peak-nav__link { border-left: 1px solid var(--peak-line, var(--pkn-sub-border)); border-radius: 0 var(--peak-radius-sm, 6px) var(--peak-radius-sm, 6px) 0; }

/* The two panel shapes Peak adds on top of the theme's dropdown. */
.peak-nav--m-drawer.is-mobile .peak-nav__panel {
	position: fixed;
	top: 0;
	bottom: 0;
	left: auto;
	right: 0;
	width: min(360px, 86vw);
	max-height: none;
	padding: 4.5rem 1.25rem 1.5rem;
	border-bottom: 0;
	opacity: 1;
	transform: translateX(100%);
}
.peak-nav--m-drawer.peak-nav--side-left.is-mobile .peak-nav__panel { left: 0; right: auto; transform: translateX(-100%); }
.peak-nav--m-drawer.is-mobile.is-open .peak-nav__panel { transform: none; }

.peak-nav--m-fullscreen.is-mobile .peak-nav__panel {
	position: fixed;
	inset: 0;
	display: flex;
	flex-direction: column;
	justify-content: center;
	max-height: none;
	padding: 4.5rem 1.25rem;
	border-bottom: 0;
}
.peak-nav--m-fullscreen.is-mobile .peak-nav__link { font-size: 1.5rem; }

body.peak-nav-menu-open { overflow: hidden; }

/* ---- editor placeholder --------------------------------------------------- */

.peak-nav--empty {
	display: block;
	padding: 16px 20px;
	border: 1px dashed rgba(0, 0, 0, 0.18);
	border-radius: 8px;
	background: rgba(0, 0, 0, 0.02);
	font: 500 13px/1.5 system-ui, sans-serif;
	color: rgba(0, 0, 0, 0.55);
}

@media (prefers-reduced-motion: reduce) {
	.peak-nav *, .peak-nav *::before, .peak-nav *::after { transition-duration: 0.01ms !important; }
}
