/*
 * PureCSS.com
 * https://purecss.com/split-button/
 * A split button whose menu is a native popover, placed with anchor positioning.
 */

.demo-split-button .sb-group {
	display: inline-flex;
}

.demo-split-button .sb-main,
.demo-split-button .sb-toggle {
	border: 0;
	font: inherit;
	font-weight: 600;
	color: var(--bg);
	background: var(--accent);
	cursor: pointer;
	transition: background-color .15s, box-shadow .15s;
}

/* each half answers on its own. The shades mix the accent with black:
   on dark green that adds contrast to the light label, and on lime the
   dark label keeps plenty */
.demo-split-button .sb-main:hover,
.demo-split-button .sb-toggle:hover {
	background: color-mix(in srgb, var(--accent) 80%, #000);
}

/* pressed, and the toggle held down while its menu is open */
.demo-split-button .sb-main:active,
.demo-split-button .sb-toggle:active,
.demo-split-button .sb-toggle:has(+ :popover-open) {
	background: color-mix(in srgb, var(--accent) 65%, #000);
	box-shadow: inset 0 2px 5px rgb(0 0 0 / .35);
}

.demo-split-button .sb-main {
	padding: .6rem 1rem;
	border-radius: 10px 0 0 10px;
}

.demo-split-button .sb-toggle {
	display: grid;
	place-items: center;
	padding: .6rem .6rem;
	margin-left: 1px;
	border-radius: 0 10px 10px 0;
	anchor-name: --sb-toggle;
}

.demo-split-button .sb-main:focus-visible,
.demo-split-button .sb-toggle:focus-visible,
.demo-split-button .sb-item:focus-visible {
	outline: 2px solid var(--text);
	outline-offset: 2px;
}

.demo-split-button .sb-chevron {
	width: 12px;
	height: 12px;
	transition: rotate .2s;
}

/* the toggle sits right before the popover, so this reads the popover's state */
.demo-split-button .sb-toggle:has(+ :popover-open) .sb-chevron {
	rotate: 180deg;
}

/* without anchor positioning a popover opens in the middle of the screen, which still works */
.demo-split-button .sb-menu {
	padding: .3rem;
	border: 1px solid var(--border);
	border-radius: 10px;
	color: var(--text);
	background: var(--surface);
	box-shadow: 0 10px 28px rgba(0, 0, 0, .35);
	opacity: 0;
	translate: 0 -4px;
	transition: opacity .15s, translate .15s, overlay .15s allow-discrete, display .15s allow-discrete;
}

.demo-split-button .sb-menu:popover-open {
	opacity: 1;
	translate: 0 0;
}

@starting-style {
	.demo-split-button .sb-menu:popover-open {
		opacity: 0;
		translate: 0 -4px;
	}
}

@supports (anchor-name: --sb-toggle) {
	.demo-split-button .sb-menu {
		position-anchor: --sb-toggle;
		inset: auto;
		top: anchor(bottom);
		right: anchor(right);
		margin: .35rem 0 0;
	}
}

.demo-split-button .sb-item {
	display: block;
	width: 100%;
	padding: .4rem .75rem;
	border: 0;
	border-radius: 6px;
	font: inherit;
	font-size: .85rem;
	text-align: left;
	color: inherit;
	background: none;
	cursor: pointer;
}

.demo-split-button .sb-item:hover {
	background: var(--border);
}

@media (prefers-reduced-motion: reduce) {
	.demo-split-button .sb-main,
	.demo-split-button .sb-toggle,
	.demo-split-button .sb-menu,
	.demo-split-button .sb-chevron { transition: none; }
}
