sh-button-group {
	/* Focus stacking */

	& :is(sh-button, sh-dropdown):focus-within {
		z-index: 1;
	}

	/* Active press */

	& > sh-button::part(button):active,
	& > sh-dropdown > sh-button[slot="trigger"]::part(button):active {
		translate: 0 0;
	}
}

/* Vertical layout */

sh-button-group[orientation="vertical"] {
	& > sh-button::part(button),
	& > sh-dropdown > sh-button[slot="trigger"]::part(button) {
		inline-size: 100%;
	}
}

sh-button-group[orientation="vertical"] {
	& > sh-button:not(:first-child)::part(button),
	& > sh-dropdown:not(:first-child) > sh-button[slot="trigger"]::part(button) {
		margin-block-start: -2px;
	}
}

sh-button-group:not([orientation="vertical"]) {
	/* Overlap the flex items so every following button advances by the same width. */
	& > sh-button:not(:first-child),
	& > sh-dropdown:not(:first-child) {
		margin-inline-start: -2px;
	}
}

sh-button-group[orientation="vertical"] {
	& > sh-button:first-child:not(:last-child)::part(button),
	& > sh-dropdown:first-child:not(:last-child) > sh-button[slot="trigger"]::part(button) {
		border-end-start-radius: 0;
		border-end-end-radius: 0;
	}

	& > sh-button:not(:first-child):not(:last-child)::part(button),
	& > sh-dropdown:not(:first-child):not(:last-child) > sh-button[slot="trigger"]::part(button) {
		border-radius: 0;
	}

	& > sh-button:last-child:not(:first-child)::part(button),
	& > sh-dropdown:last-child:not(:first-child) > sh-button[slot="trigger"]::part(button) {
		border-start-start-radius: 0;
		border-start-end-radius: 0;
	}
}

sh-button-group:not([orientation="vertical"]) {
	& > sh-button:first-child:not(:last-child)::part(button),
	& > sh-dropdown:first-child:not(:last-child) > sh-button[slot="trigger"]::part(button) {
		border-start-end-radius: 0;
		border-end-end-radius: 0;
	}

	& > sh-button:not(:first-child):not(:last-child)::part(button),
	& > sh-dropdown:not(:first-child):not(:last-child) > sh-button[slot="trigger"]::part(button) {
		border-radius: 0;
	}

	& > sh-button:last-child:not(:first-child)::part(button),
	& > sh-dropdown:last-child:not(:first-child) > sh-button[slot="trigger"]::part(button) {
		border-start-start-radius: 0;
		border-end-start-radius: 0;
	}
}
