:root {
	--transparency: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" fill-opacity=".05"><rect width="50" height="50" /><rect x="50" y="50" width="50" height="50" /></svg>')
	0 0 / 20px 20px #f8f8f8;
}

body {
	display: flex;
	align-items: flex-start;
	justify-content: center;
	box-sizing: border-box;
	height: 100vh;
	padding: 1em 2em;
	margin: 0;
	font: 100%/1.6 Helvetica Neue, sans-serif;
	background: var(--transparency);
}

header {
	align-items: center;
	line-height: 1;
	letter-spacing: -.05em;
}

main {
	padding: 1.5em;
	border-radius: .5em;
	width: 40em;
	max-width: 90vw;
	margin: 1em auto;
	background: #f0f0f0;
	box-shadow: .05em .05em .1em rgba(0,0,0,.2), 0 0 0 100vmax var(--color);
	opacity: 0;

	&:has(color-picker:defined) {
		opacity: 1;
		/* We add the 0.3s delay to let the `<color-picker>` components settle down. */
		transition: opacity .25s .3s;
  	}
}

color-picker {
	/* Don't allow content to stretch the grid */
	grid-template-columns: min-max(0, 1fr);

	&::part(color-space) {
		box-sizing: content-box;
		inline-size: calc(100% - .2em);
		padding: 0;
		margin: 0;

		border: .1em solid hsl(220 10% 60%);

		font-size: 250%;
		font-weight: 700;

		field-sizing: initial;
	}

	&::part(color-space-base) {
		inline-size: 100%;
		block-size: 100%;
		padding: 0;
		margin: 0;

		font-size: 120%;

		field-sizing: initial;
		text-overflow: ellipsis;
	}

	&::part(sliders),
	&::part(details) {
		grid-column: 1 / -1;
	}

	&::part(channel-slider) {
		text-transform: uppercase;
		font-size: smaller;
		font-weight: bold;
		color: rgb(0 0 0 / .5);
	}

	&::part(swatch) {
		/* We need the gamut badge to be placed absolutely relative to the body, not the color swatch */
		display: contents;
	}

	&::part(swatch-base) {
		display: none;
	}

	&::part(gamut) {
		font-size: clamp(1rem, 2vw, 1.5rem);
	}
}

fieldset {
	border: 1px solid hsl(220 10% 80%);
	border-radius: .3em;
	margin: 0;
	margin-top: 1em;
}

label,
legend {
	display: block;
	text-transform: uppercase;
	font-size: smaller;
	margin-top: 1em;
	font-weight: bold;
	color: rgba(0,0,0,.5);
}

abbr {
	text-transform: initial;
}

input.color-css,
input.color-srgb {
	padding: .3em .5em .2em;
	border: 1px solid rgba(0, 0, 0, 0.2);
	border-radius: .3em;
	box-shadow: 0 0.05em 0.2em rgba(0, 0, 0, 0.2) inset;
	background: rgba(26, 26, 26, 0.05);
	width: 100% !important;
	box-sizing: border-box;
	font: 150% Consolas, Monaco, monospace;
}

.out-of-gamut input {
	border-color: rgba(200, 0, 0, 0.5);
}

.out-of-gamut-warning {
	margin-top: .4em;
	color: #b00;
	font-weight: bold;
	font-size: smaller;
	text-transform: initial;
}

	.out-of-gamut-warning::before {
		content: "⚠️ ";
		filter: invert() hue-rotate(-200deg);
	}

label:not(.out-of-gamut) .out-of-gamut-warning {
	display: none;
}

.precision input {
	font: inherit;
	color: inherit;
	background: none;
	border: none;
}
