.nst-nav {
	--nst-nav-bg: #fff;
	--nst-nav-fg: inherit;
	--nst-nav-border: rgba(0, 0, 0, .12);
	--nst-nav-hover-bg: rgba(0, 0, 0, .05);
	--nst-nav-accent: currentColor;
	--nst-nav-gap-x: 1.25rem;
	--nst-nav-gap-y: .25rem;
	--nst-link-pad-y: .5rem;
	--nst-link-pad-x: .5rem;
	--nst-sub-width: 15rem;
	--nst-sub-max-h: min(70vh, 26rem);
	--nst-nav-z: 100;

	/* NEW: dropdown text color, so it doesn't inherit a light header color */
	--nst-sub-fg: #1a1a1a;
	--nst-sub-hover-bg: rgba(0, 0, 0, .06);
}

/* ---------- Reset ---------- */
.nst-nav .nst-menu,
.nst-nav .nst-menu ul {
	list-style: none;
	margin: 0;
	padding: 0;
}

.nst-nav .nst-menu a {
	display: block;
	padding: var(--nst-link-pad-y) var(--nst-link-pad-x);
	color: var(--nst-nav-fg);
	text-decoration: none;
	overflow-wrap: anywhere;
}

.nst-nav .nst-menu a:hover {
	background: var(--nst-nav-hover-bg);
}

.nst-nav .nst-menu a:focus-visible,
.nst-nav .nst-submenu-toggle:focus-visible,
.nst-nav .nst-nav__toggle:focus-visible {
	outline: 2px solid var(--nst-nav-accent);
	outline-offset: 2px;
}

/* ---------- Current page / ancestors ---------- */
.nst-nav .current_page_item > a,
.nst-nav .current-menu-item > a,
.nst-nav .current_page_ancestor > a,
.nst-nav .current-menu-ancestor > a {
	font-weight: 600;
	box-shadow: inset 0 -2px 0 var(--nst-nav-accent);
}

/* ---------- Items with children ---------- */
.nst-nav .page_item_has_children,
.nst-nav .menu-item-has-children {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
}

.nst-nav .page_item_has_children > a,
.nst-nav .menu-item-has-children > a {
	flex: 1 1 auto;
}

.nst-nav .page_item_has_children:not(.has-toggle) > a::after,
.nst-nav .menu-item-has-children:not(.has-toggle) > a::after {
	content: "";
	display: inline-block;
	inline-size: .4em;
	block-size: .4em;
	margin-inline-start: .5em;
	border: solid currentColor;
	border-width: 0 2px 2px 0;
	transform: translateY(-.15em) rotate(45deg);
}

/* Toggle button */
.nst-nav .nst-submenu-toggle {
	flex: 0 0 auto;
	inline-size: 2.5rem;
	block-size: 2.5rem;
	padding: 0;
	border: 0;
	background: transparent;
	color: inherit;
	cursor: pointer;
	position: relative;
}

.nst-nav .nst-submenu-toggle::before {
	content: "";
	position: absolute;
	inset-block-start: 50%;
	inset-inline-start: 50%;
	inline-size: .5em;
	block-size: .5em;
	border: solid currentColor;
	border-width: 0 2px 2px 0;
	transform: translate(-50%, -70%) rotate(45deg);
	transition: transform .15s ease;
}

.nst-nav .nst-submenu-toggle[aria-expanded="true"]::before {
	transform: translate(-50%, -30%) rotate(-135deg);
}

/* ======================================================================
 * MOBILE
 * ====================================================================== */
.nst-nav .nst-nav__bar {
	position: relative;
	flex-wrap: wrap;
}

.nst-nav .nst-nav__panel {
	display: none;
	flex: 1 0 100%;
	max-block-size: calc(100vh - 6rem);
	overflow-y: auto;
	overscroll-behavior: contain;
	border-block-start: 1px solid var(--nst-nav-border);
}

.nst-nav .nst-nav__toggle[aria-expanded="true"] + .nst-nav__panel,
.nst-nav .nst-nav__panel.is-open {
	display: block;
}

.nst-nav .nst-menu--main > li {
	border-block-end: 1px solid var(--nst-nav-border);
}

/* mobile: hidden by default, shown when .is-open */
.nst-nav .children,
.nst-nav .sub-menu {
	display: none;
	flex: 1 0 100%;
	margin-inline-start: 1rem;
	border-inline-start: 2px solid var(--nst-nav-border);
}

.nst-nav li.is-open > .children,
.nst-nav li.is-open > .sub-menu {
	display: block;
}

.nst-nav .children a,
.nst-nav .sub-menu a {
	white-space: normal;
}

/* ======================================================================
 * DESKTOP
 * ====================================================================== */
@media (min-width: 992px) {

	.nst-nav .nst-nav__toggle {
		display: none;
	}

	.nst-nav .nst-nav__panel {
		display: block;
		flex: 1 1 auto;
		max-block-size: none;
		overflow: visible;
		border: 0;
	}

	/* ensure dropdowns are never clipped by the bar */
	.nst-nav,
	.nst-nav .nst-nav__bar,
	.nst-nav .nst-nav__panel {
		overflow: visible;
	}

	.nst-nav .nst-menu--main {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
		justify-content: flex-end;
		gap: var(--nst-nav-gap-y) var(--nst-nav-gap-x);
	}

	.nst-nav .nst-menu--main > li {
		position: relative;
		border: 0;
	}

	.nst-nav .nst-menu--main > li > a {
		white-space: nowrap;
	}

	/* ---------- DROPDOWN PANEL ---------- */
	.nst-nav .children,
	.nst-nav .sub-menu {
		position: absolute;
		inset-block-start: 100%;
		inset-inline-start: 0;
		z-index: var(--nst-nav-z);

		inline-size: max-content;
		min-inline-size: var(--nst-sub-width);
		max-inline-size: 22rem;
		max-block-size: var(--nst-sub-max-h);
		overflow-y: auto;

		margin: 0;
		padding: .375rem;

		/* NEW: force the dropdown's own text + background colors */
		background: var(--nst-nav-bg);
		color: var(--nst-sub-fg);
		border: 1px solid var(--nst-nav-border);
		border-radius: .5rem;
		box-shadow: 0 .75rem 1.5rem rgba(0, 0, 0, .12);

		/* hidden state */
		display: block;
		visibility: hidden;
		opacity: 0;
		transform: translateY(.25rem);
		pointer-events: none;
		transition:
			opacity .15s ease,
			transform .15s ease,
			visibility 0s linear .15s;
	}

	/* items inside dropdown get the sub text color explicitly */
	.nst-nav .children a,
	.nst-nav .sub-menu a {
		color: var(--nst-sub-fg);
		border-radius: .375rem;
	}

	.nst-nav .children a:hover,
	.nst-nav .children a:focus-visible,
	.nst-nav .sub-menu a:hover,
	.nst-nav .sub-menu a:focus-visible {
		background: var(--nst-sub-hover-bg);
	}

	/* ---------- OPEN STATE ---------- */
	/* Re-assert display:block here so nothing else can hide it on hover */
	.nst-nav li:hover > .children,
	.nst-nav li:hover > .sub-menu,
	.nst-nav li:focus-within > .children,
	.nst-nav li:focus-within > .sub-menu,
	.nst-nav li.is-open > .children,
	.nst-nav li.is-open > .sub-menu {
		display: block;
		visibility: visible;
		opacity: 1;
		transform: none;
		pointer-events: auto;
		transition-delay: 0s;
	}

	/* third level and deeper: fly out to the side */
	.nst-nav .children .children,
	.nst-nav .sub-menu .sub-menu {
		inset-block-start: 0;
		inset-inline-start: 100%;
		margin-inline-start: .25rem;
	}

	/* last two top-level items: open towards the inside */
	.nst-nav .nst-menu--main > li:nth-last-child(-n+2) > .children,
	.nst-nav .nst-menu--main > li:nth-last-child(-n+2) > .sub-menu {
		inset-inline-start: auto;
		inset-inline-end: 0;
	}

	.nst-nav .nst-menu--main > li:nth-last-child(-n+2) .children .children,
	.nst-nav .nst-menu--main > li:nth-last-child(-n+2) .sub-menu .sub-menu {
		inset-inline-start: auto;
		inset-inline-end: 100%;
		margin-inline-start: 0;
		margin-inline-end: .25rem;
	}

	.nst-nav .children li,
	.nst-nav .sub-menu li {
		position: relative;
	}

	.nst-nav .nst-submenu-toggle {
		inline-size: 1.75rem;
		block-size: 1.75rem;
	}

	.nst-nav .nestora-menu-fallback > ul > li:nth-child(n+9) {
		display: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.nst-nav .children,
	.nst-nav .sub-menu {
		transition: none;
		transform: none;
	}
}