// Scrollbars are painted in every color scheme, so that a surface keeps the
// same scrollbar when the color scheme toggle is used. No scheme selector is
// needed: the `--scrollbar-*` tokens are declared on `:root` and resolve per
// scheme on their own, and the high contrast palette narrows them further
// where it applies.
//
// Styling any `::-webkit-scrollbar` pseudo-element opts the element out of the
// platform scrollbar and onto the browser's own, which is what lets the thumb
// be inset and rounded. Two things then have to be handled here rather than
// left to the default: the container paints a light background of its own
// unless it is given one, and the stepper arrows are drawn unless they are
// hidden. The scrollbar is then permanently visible and reserves
// `--scrollbar-size` from the content, which is inherent to painting it.
//
// `scrollbar-color` cannot stand in for this. It only recolors the platform
// scrollbar, so it can neither remove the steppers nor round the thumb. It is
// the best available fallback where the pseudo-elements do not exist.
//
// Guarded on the token being declared. The partial compiles into every Clay
// tree, but only the custom properties tree emits `--scrollbar-*`. Without the
// guard the other trees would still match and resolve every value to an
// invalid one.

@if (map-has-key($c-root, --scrollbar-thumb)) {
	::-webkit-scrollbar {
		background: $scrollbar-track;
		height: $scrollbar-size;
		width: $scrollbar-size;
	}

	::-webkit-scrollbar-button {
		display: none;
	}

	::-webkit-scrollbar-corner {
		background: $scrollbar-track;
	}

	::-webkit-scrollbar-thumb {
		background: $scrollbar-thumb;
		background-clip: padding-box;
		border: $scrollbar-inset solid transparent;
		border-radius: $scrollbar-radius;

		&:active {
			background: $scrollbar-thumb-active;
			background-clip: padding-box;
		}

		&:hover {
			background: $scrollbar-thumb-hover;
			background-clip: padding-box;
		}
	}

	@supports #{'not selector(::-webkit-scrollbar)'} {
		:root {
			scrollbar-color: $scrollbar-thumb $scrollbar-track;
		}
	}
}
