#paint-editor {
	container-type: inline-size;
}

.paint-toolbar {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	align-items: start;
	gap: 0.75rem;
	padding: 0.65rem;
	background: var(--face-soft);
	border: 1px solid var(--border);
	margin-bottom: 0.75rem;
}

.paint-toolbar-group {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	min-width: 0;
	margin: 0;
	padding: 0;
	border: 0;
}

.paint-draw-tools {
	justify-content: center;
}

.paint-file-actions {
	justify-content: flex-end;
}

.paint-toolbar button {
	display: grid;
	place-items: center;
	width: 2.75rem;
	height: 2.75rem;
	padding: 0.5rem;
	flex-shrink: 0;
}

.paint-toolbar svg,
.paint-shift svg {
	width: 1.5rem;
	height: 1.5rem;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.paint-toolbar button[aria-pressed="true"],
.paint-swatch[aria-pressed="true"] {
	border-color: var(--deep-shadow) var(--highlight) var(--highlight) var(--deep-shadow);
	box-shadow: inset 1px 1px 0 var(--shadow);
	background-color: var(--surface);
	background-image: repeating-linear-gradient(
		135deg,
		transparent 0 2px,
		var(--border) 2px 3px,
		transparent 3px 5px
	);
}

.paint-toolbar button[aria-pressed="true"]:disabled {
	background-image: none;
	border-color: var(--border);
	box-shadow: none;
}

.paint-workspace {
	display: grid;
	grid-template-columns: minmax(0, 1fr);
	align-items: start;
	gap: 1rem;
	margin-bottom: 1rem;
}

.paint-sidebar {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	align-items: stretch;
	gap: 1rem;
}

.paint-colors-panel {
	container-type: inline-size;
	min-width: 0;
	margin: 0;
}

.paint-paper {
	grid-area: 2 / 2;
	min-width: 0;
	padding: 0.3rem;
	background: var(--face);
	border: 2px solid;
	border-color: var(--shadow) var(--highlight) var(--highlight) var(--shadow);
}

.paint-drawing {
	--paint-shift-size: clamp(2rem, 6cqi, 2.5rem);
	min-width: 0;
	display: grid;
	grid-template-columns: var(--paint-shift-size) minmax(0, 1fr) var(--paint-shift-size);
	grid-template-rows: var(--paint-shift-size) auto var(--paint-shift-size);
	gap: 0.4rem;
	margin: 0;
	padding: 0;
	border: 0;
}

.paint-shift {
	display: grid;
	place-items: center;
	width: var(--paint-shift-size);
	height: var(--paint-shift-size);
	min-width: var(--paint-shift-size);
	min-height: var(--paint-shift-size);
	padding: 0;
}

.paint-shift svg {
	max-width: 100%;
	max-height: 100%;
}

#paint-shift-up {
	grid-area: 1 / 2;
}

#paint-shift-left {
	grid-area: 2 / 1;
}

#paint-shift-right {
	grid-area: 2 / 3;
}

#paint-shift-down {
	grid-area: 3 / 2;
}

#paint-shift-up,
#paint-shift-down {
	justify-self: center;
	width: 33.333%;
}

#paint-shift-left,
#paint-shift-right {
	align-self: center;
	height: 33.333%;
}

#paint-crop {
	width: min(26rem, calc(100% - 1rem));
	max-height: calc(100dvh - 2rem);
	padding: 0.75rem;
	color: var(--text);
	background: var(--face-soft);
	border: 2px solid;
	border-color: var(--highlight) var(--deep-shadow) var(--deep-shadow) var(--highlight);
}

#paint-crop::backdrop {
	background: #0009;
}

#paint-crop-viewport {
	display: block;
	width: min(100%, 20rem, 50dvh);
	height: auto;
	aspect-ratio: 1;
	margin: 0.75rem auto;
	background: #000;
	outline: 2px solid var(--shadow);
	touch-action: none;
	cursor: grab;
	forced-color-adjust: none;
}

#paint-crop-viewport:active {
	cursor: grabbing;
}

#paint-crop-viewport:focus-visible {
	outline: 3px solid var(--text);
	outline-offset: 3px;
}

.paint-zoom {
	display: flex;
	justify-content: space-between;
}

#paint-crop-zoom {
	width: 100%;
	min-height: 2.5rem;
	appearance: none;
	background: transparent;
	cursor: ew-resize;
}

#paint-crop-zoom::-webkit-slider-runnable-track {
	height: 0.5rem;
	background: var(--field);
	border: 2px solid;
	border-color: var(--shadow) var(--highlight) var(--highlight) var(--shadow);
}

#paint-crop-zoom::-moz-range-track {
	height: 0.5rem;
	background: var(--field);
	border: 2px solid;
	border-color: var(--shadow) var(--highlight) var(--highlight) var(--shadow);
}

#paint-crop-zoom::-webkit-slider-thumb {
	appearance: none;
	width: 1.5rem;
	height: 1.5rem;
	margin-top: calc(-0.5rem - 2px);
	background: var(--face);
	border: 2px solid;
	border-color: var(--highlight) var(--deep-shadow) var(--deep-shadow) var(--highlight);
	border-radius: 0;
}

#paint-crop-zoom::-moz-range-thumb {
	width: 1.5rem;
	height: 1.5rem;
	background: var(--face);
	border: 2px solid;
	border-color: var(--highlight) var(--deep-shadow) var(--deep-shadow) var(--highlight);
	border-radius: 0;
}

.paint-crop-actions {
	display: flex;
	justify-content: flex-end;
	gap: 0.5rem;
	margin-top: 0.5rem;
}

#paint-grid {
	width: 100%;
	aspect-ratio: 1;
	display: grid;
	grid-template-rows: repeat(16, minmax(0, 1fr));
	background: #000;
	touch-action: none;
	user-select: none;
}

#paint-grid [role="row"] {
	display: grid;
	grid-template-columns: repeat(16, minmax(0, 1fr));
	min-height: 0;
}

#paint-grid [role="gridcell"] {
	min-width: 0;
	min-height: 0;
	padding: 0;
}

#paint-grid button {
	display: block;
	width: 100%;
	height: 100%;
	min-height: 0;
	padding: 0;
	border: 0;
	border-right: 1px solid #ffffff40;
	border-bottom: 1px solid #ffffff40;
	box-shadow: none;
	cursor: crosshair;
	forced-color-adjust: none;
}

#paint-grid button:focus-visible {
	position: relative;
	z-index: 1;
	outline: 2px solid #fff;
	outline-offset: -3px;
	box-shadow: inset 0 0 0 5px #000;
}

#paint-palette {
	display: grid;
	grid-template-columns: repeat(8, minmax(0, 1fr));
	gap: 0.125rem;
}

.paint-swatch {
	min-height: 1.5rem;
	aspect-ratio: 1;
	padding: 0.2rem;
}

.paint-swatch-black {
	grid-column: span 2;
	grid-row: span 2;
}

.paint-swatch > span {
	display: block;
	height: 100%;
	border: 1px solid #000;
	forced-color-adjust: none;
}

.paint-current {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5rem;
	margin: 0.75rem 0;
}

#paint-color-chip {
	width: 1.5rem;
	height: 1.5rem;
	border: 1px solid var(--text);
	forced-color-adjust: none;
}

.paint-preview-panel {
	display: grid;
	grid-template-rows: minmax(0, 1fr);
	min-width: 0;
	min-height: 0;
	margin: 0;
	text-align: center;
}

.paint-preview-screen {
	container-type: size;
	display: grid;
	place-items: center;
	min-width: 0;
	min-height: 0;
	padding: clamp(1rem, 3cqi, 2rem);
	overflow: hidden;
	background: #0a0a0a;
	forced-color-adjust: none;
}

.paint-filters {
	position: absolute;
	pointer-events: none;
}

#paint-preview {
	display: block;
	width: min(100cqi, 100cqb);
	height: auto;
	aspect-ratio: 1;
	background: #000;
	image-rendering: pixelated;
	filter: url("#paint-preview-glow");
	forced-color-adjust: none;
}

.paint-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
	border: 0;
}

@container (max-width: 12rem) {
	.paint-toolbar {
		grid-template-columns: minmax(0, 1fr);
	}

	.paint-drawing {
		--paint-shift-size: 1.5rem;
	}
}

@container (max-width: 30rem) {
	.paint-sidebar {
		grid-template-columns: minmax(0, 1fr);
	}

	.paint-preview-screen {
		container-type: inline-size;
		aspect-ratio: 1;
	}

	#paint-preview {
		width: 100cqi;
	}
}

@container (max-width: 13rem) {
	#paint-palette {
		grid-template-columns: repeat(4, minmax(0, 1fr));
	}
}

@container (max-width: 8rem) {
	#paint-palette {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

@media (forced-colors: active) {
	#paint-preview {
		filter: none;
	}

	.paint-toolbar button[aria-pressed="true"],
	.paint-swatch[aria-pressed="true"] {
		outline: 2px solid Highlight;
		outline-offset: -4px;
	}
}
