/* Menus (menu.js): Material 3's menu on glass. The surface is Everforest's
   popup-menu background, bg2, at 80% over a 24px backdrop blur, after
   NN/g's glassmorphism guidance to blur generously so text keeps its
   contrast; with reduced transparency or more contrast asked for, it is
   opaque. Measurements follow M3's vertical menu: 16px container corners
   (corner-large), items of 12px corners inset 4px (16 - 4, for optical
   roundness), 12px between icon, label, and keys, and 20px icons. Items are
   40px tall rather than 44px, one step of M3's web density, as befits a
   desktop menu. Elevation is M3 level 2. */
.menu {
	position: fixed;
	z-index: 9000;
	min-width: 200px;
	max-width: 280px;
	padding: 4px;
	border-radius: 16px;
	background: color-mix(in srgb, var(--popup) 80%, transparent);
	-webkit-backdrop-filter: blur(24px) saturate(1.4);
	backdrop-filter: blur(24px) saturate(1.4);
	box-shadow:
		inset 0 0 0 1px color-mix(in srgb, var(--text) 9%, transparent),
		0 1px 2px rgb(0 0 0 / 0.3),
		0 2px 6px 2px rgb(0 0 0 / 0.15);
	color: var(--text);
	font-size: 14px;
	line-height: 20px;
	user-select: none;
	--selection-line: none;
}

html[data-theme="light"] .menu {
	box-shadow:
		inset 0 0 0 1px color-mix(in srgb, var(--text) 9%, transparent),
		0 1px 2px rgb(0 0 0 / 0.12),
		0 2px 6px 2px rgb(0 0 0 / 0.08);
}

@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
	.menu {
		background: var(--popup);
		-webkit-backdrop-filter: none;
		backdrop-filter: none;
	}
}

.menu.menu-closing {
	pointer-events: none;
}

.menu-list {
	max-height: min(440px, calc(100dvh - 32px));
	margin: 0;
	padding: 0;
	list-style: none;
	overflow-y: auto;
	overscroll-behavior: contain;
}

/* A quiet label over a group of items, M3's menu section header. */
.menu-heading {
	padding: 12px 12px 4px;
	font-size: 12px;
	line-height: 16px;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--muted);
}

.menu-heading:first-child {
	padding-top: 6px;
}

/* A detail at the item's end, like its keys. */
.menu-detail {
	font-size: 12px;
	color: var(--muted);
	white-space: nowrap;
}

.menu-list:focus {
	outline: none;
}

.menu-item {
	appearance: none;
	position: relative;
	display: grid;
	grid-template-columns: 20px minmax(0, 1fr);
	grid-auto-columns: auto;
	grid-auto-flow: column;
	align-items: center;
	column-gap: 12px;
	width: 100%;
	height: 40px;
	padding: 0 12px;
	border: 0;
	border-radius: 12px;
	background: transparent;
	color: inherit;
	font: inherit;
	text-align: start;
	/* Options sit flush, so the cursor's highlight keeps to the one it's
	   on rather than reaching into its neighbours (the chosen one's tint
	   among them). */
	--cursor-pad: 0px;
}

/* State layers in on-surface: 8% hover, 12% focus and pressed. With the
   custom cursor, the cursor is the hover layer. */
.menu-item::before {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: inherit;
	background: currentColor;
	opacity: 0;
	transition: opacity 15ms linear;
}

.menu-item:hover::before {
	opacity: 0.08;
}

html.custom-cursor .menu-item:hover::before {
	opacity: 0;
}

.menu-item:focus-visible::before,
.menu-item:active::before,
html.custom-cursor .menu-item:is(:focus-visible, :active)::before {
	opacity: 0.12;
	transition-duration: 105ms;
}

.menu-item:focus-visible {
	outline: 3px solid var(--accent);
	outline-offset: -3px;
}

/* The chosen option, in a secondary-container-like tint of the accent. */
.menu-item[aria-checked="true"] {
	background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.menu-item[aria-checked="true"] .menu-icon {
	color: var(--accent);
}

.menu-item[aria-disabled="true"] {
	color: color-mix(in srgb, var(--text) 38%, transparent);
}

.menu-item[aria-disabled="true"]::before {
	display: none;
}

.menu-icon {
	display: flex;
	color: var(--muted);
}

.menu-item[aria-disabled="true"] .menu-icon {
	color: inherit;
}

.menu-icon svg {
	width: 20px;
	height: 20px;
}

.menu-label {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.menu-keys {
	display: flex;
	gap: 3px;
	color: var(--muted);
}

.menu-item[aria-disabled="true"] .menu-keys {
	color: inherit;
}

.menu-keys kbd {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	font-family: var(--font-mono);
	font-size: 11px;
	line-height: 1;
	border: 1px solid color-mix(in srgb, currentColor 40%, transparent);
	border-radius: 4px;
}

.menu-keys kbd svg {
	width: 12px;
	height: 12px;
}

.menu-divider {
	height: 1px;
	margin: 4px 12px;
	background: color-mix(in srgb, var(--text) 12%, transparent);
}

.menu-hint {
	margin: 4px 12px 6px;
	font-size: 11px;
	line-height: 16px;
	color: var(--muted);
}

/* A confirmation shown in place of its item, such as after copying. */
.menu-item-done,
.menu-item-done .menu-icon {
	color: var(--accent);
}
