/* Colours and font match customslipmats.co.uk. Override these variables to re-theme. */
.pd {
	--pd-primary: #1da4a6;
	--pd-hover: #121212;
	--pd-text: #3b3d40;
	--pd-muted: #9da6a8;
	--pd-border: #ddd;
	--pd-bg-alt: #eee;
	--pd-font: source-sans-pro, "Source Sans 3", "Source Sans Pro", system-ui, sans-serif;
	margin-bottom: 1em;
}

.pd-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	margin: 0;
	padding: .5em 1.6em;
	border: 2px solid var(--pd-primary);
	border-radius: 0;
	background: var(--pd-primary);
	color: #fff;
	font: 700 16px/1.2 var(--pd-font);
	text-transform: uppercase;
	text-decoration: none;
	cursor: pointer;
	transition: background .3s, border-color .3s, color .3s;
	box-sizing: border-box;
}
.pd-btn:hover,
.pd-btn:focus-visible {
	background: var(--pd-hover);
	border-color: var(--pd-hover);
	color: #fff;
}
.pd-btn-outline {
	background: transparent;
	color: var(--pd-primary);
}
.pd-btn[hidden] {
	display: none;
}
.pd-open {
	width: 100%;
	font-size: 18px;
}

/* Modal: canvas left, controls sidebar right. */
.pd-modal {
	width: min(96vw, 1100px);
	height: min(92vh, 760px);
	max-width: none;
	max-height: none;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: #fff;
	color: var(--pd-text);
	font-family: var(--pd-font);
	overflow: hidden;
}
.pd-modal[open] {
	display: grid;
	grid-template-columns: 1fr 340px;
}
.pd-modal::backdrop {
	background: rgba(0, 0, 0, .75);
}
.pd-modal * {
	box-sizing: border-box;
}

.pd-stage {
	position: relative;
	display: grid;
	place-items: center;
	min-height: 0;
	padding: 24px;
	background: var(--pd-bg-alt);
	container-type: size;
}
.pd-canvas {
	display: block;
	width: min(100cqw, 100cqh);
	height: auto;
	aspect-ratio: 1;
	background: #fff;
	box-shadow: 0 2px 12px rgba(0, 0, 0, .08);
	touch-action: none;
	cursor: move;
}
.pd-actions {
	position: absolute;
	top: 12px;
	right: 12px;
	display: flex;
	gap: 8px;
}
.pd-actions[hidden] {
	display: none;
}
.pd-actions .pd-btn {
	min-height: 36px;
	padding: .3em 1em;
	font-size: 14px;
}

.pd-snap {
	position: absolute;
	top: 12px;
	left: 12px;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 36px;
	margin: 0;
	padding: .3em .8em;
	border: 2px solid var(--pd-border);
	background: #fff;
	color: var(--pd-text);
	font: 700 14px/1.2 var(--pd-font);
	text-transform: uppercase;
	cursor: pointer;
	user-select: none;
}
.pd-history {
	position: absolute;
	bottom: 12px;
	left: 12px;
	display: flex;
	gap: 8px;
}
.pd-history button {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	min-height: 36px;
	margin: 0;
	padding: .3em .8em;
	border: 2px solid var(--pd-border);
	border-radius: 0;
	background: #fff;
	color: var(--pd-text);
	font: 700 14px/1.2 var(--pd-font);
	text-transform: uppercase;
	cursor: pointer;
}
.pd-history button:hover:not(:disabled),
.pd-history button:focus-visible {
	border-color: var(--pd-primary);
	color: var(--pd-primary);
}
.pd-history button:disabled {
	opacity: .45;
	cursor: default;
}
.pd-history svg {
	width: 16px;
	height: 16px;
}

.pd-snap:has(input:checked) {
	border-color: var(--pd-primary);
	color: var(--pd-primary);
}
.pd-snap input {
	width: 16px;
	height: 16px;
	margin: 0;
	accent-color: var(--pd-primary);
}

.pd-side {
	display: flex;
	flex-direction: column;
	min-height: 0;
	overflow-y: auto;
	border-left: 1px solid var(--pd-border);
}
.pd-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px 20px;
	border-bottom: 1px solid var(--pd-border);
}
.pd-head h2 {
	margin: 0;
	color: #000;
	font: 700 22px/1.2 var(--pd-font);
	text-transform: uppercase;
}
.pd-close {
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	background: none;
	color: var(--pd-text);
	font-size: 30px;
	line-height: 1;
	cursor: pointer;
}
.pd-close:hover {
	color: var(--pd-primary);
}

.pd-panel {
	display: grid;
	gap: 10px;
	padding: 20px;
	border-bottom: 1px solid var(--pd-border);
}
.pd-panel h3 {
	margin: 0;
	color: #000;
	font: 700 15px/1.2 var(--pd-font);
	letter-spacing: .04em;
	text-transform: uppercase;
}
.pd-row {
	display: flex;
	gap: 10px;
}
/* 16px text stops iOS zooming in on focus. */
.pd-modal .pd-text,
.pd-modal .pd-font {
	width: 100%;
	height: 44px;
	margin: 0;
	padding: 0 12px;
	border: 1px solid var(--pd-border);
	border-radius: 0;
	background: #fff;
	box-shadow: none;
	color: var(--pd-text);
	font: 400 16px var(--pd-font);
}
.pd-modal .pd-text:focus,
.pd-modal .pd-font:focus {
	outline: 0;
	border-color: var(--pd-primary);
	box-shadow: 0 0 0 1px var(--pd-primary);
}
.pd-color {
	flex: 0 0 44px;
	width: 44px;
	height: 44px;
	margin: 0;
	padding: 2px;
	border: 1px solid var(--pd-border);
	border-radius: 0;
	background: #fff;
	cursor: pointer;
}
/* Mat colour swatches: 40px circles, big enough to tap. */
.pd-swatches {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}
.pd-swatch {
	position: relative;
	flex: 0 0 40px;
	width: 40px;
	height: 40px;
	margin: 0;
	border-radius: 50%;
	background: var(--c);
	box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .2);
	cursor: pointer;
}
.pd-swatch input {
	position: absolute;
	inset: 0;
	margin: 0;
	opacity: 0;
	cursor: pointer;
}
.pd-swatch:has(:checked),
.pd-mat-custom.is-on {
	outline: 3px solid var(--pd-primary);
	outline-offset: 2px;
}
.pd-swatch:has(:focus-visible),
.pd-mat-custom:focus-visible {
	outline: 3px solid var(--pd-hover);
	outline-offset: 2px;
}
/* Rainbow ring so the picker reads as "any colour", with its current colour in the middle. */
.pd-modal .pd-mat-custom {
	padding: 6px;
	border: 0;
	background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
	box-shadow: none;
	appearance: none;
}
.pd-mat-custom::-webkit-color-swatch-wrapper {
	padding: 0;
}
.pd-mat-custom::-webkit-color-swatch {
	border: 2px solid #fff;
	border-radius: 50%;
}
.pd-mat-custom::-moz-color-swatch {
	border: 2px solid #fff;
	border-radius: 50%;
}
.pd-border-width {
	flex: 1;
	min-width: 0;
	height: 44px;
	margin: 0;
	accent-color: var(--pd-primary);
}

/* Layers: the top row draws on top. */
.pd-layers {
	display: grid;
	gap: 4px;
	max-height: 240px;
	margin: 0;
	padding: 0;
	overflow-y: auto;
	list-style: none;
}
.pd-layers:not(:empty) + .pd-hint {
	display: none;
}
.pd-layer {
	display: flex;
	border: 1px solid var(--pd-border);
}
.pd-layer.is-sel {
	border-color: var(--pd-primary);
}
.pd-modal .pd-layer button {
	min-height: 44px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: #fff;
	color: var(--pd-text);
	font: 400 16px/1.2 var(--pd-font);
	cursor: pointer;
}
.pd-modal .pd-layer-name {
	flex: 1;
	min-width: 0;
	padding: 0 12px;
	overflow: hidden;
	text-align: left;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.pd-layer.is-sel .pd-layer-name {
	color: var(--pd-primary);
	font-weight: 700;
}
.pd-modal .pd-layer-move {
	flex: 0 0 44px;
	border-left: 1px solid var(--pd-border);
}
.pd-modal .pd-layer-move:disabled {
	opacity: .3;
	cursor: default;
}

.pd-hint {
	margin: 0;
	color: var(--pd-muted);
	font-size: 14px;
}
.pd-tip {
	padding: 16px 20px;
}
.pd-tabs {
	display: none;
}
.pd-foot {
	margin-top: auto;
	padding: 20px;
	border-top: 1px solid var(--pd-border);
}
.pd-submit {
	width: 100%;
	font-size: 18px;
}

/* Mobile: full screen, canvas on top, options as a tab bar across the bottom. */
@media (max-width: 767px) {
	/* Undo bottom-left, redo bottom-right. The bar spans the stage, so let taps between the buttons reach the canvas. */
	.pd-history {
		right: 12px;
		justify-content: space-between;
		pointer-events: none;
	}
	.pd-history button {
		pointer-events: auto;
	}
	.pd-modal {
		width: 100vw;
		height: 100vh;
		height: 100dvh;
	}
	.pd-modal[open] {
		display: flex;
		flex-direction: column;
	}
	.pd-side {
		display: contents;
	}
	.pd-head {
		order: -1;
		padding: 8px 8px 8px 16px;
	}
	.pd-head h2 {
		font-size: 18px;
	}
	.pd-stage {
		flex: 1;
		padding: 12px;
	}
	.pd-panel {
		display: none;
		padding: 12px 16px;
		border-top: 1px solid var(--pd-border);
		border-bottom: 0;
	}
	.pd-panel h3,
	.pd-tip {
		display: none;
	}
	/* The mat panel has two groups, so keep its labels. */
	.pd-panel[data-panel="mat"] h3 {
		display: block;
		font-size: 13px;
	}
	.pd-modal[data-tab="mat"] [data-panel="mat"],
	.pd-modal[data-tab="text"] [data-panel="text"],
	.pd-modal[data-tab="image"] [data-panel="image"],
	.pd-modal[data-tab="layers"] [data-panel="layers"] {
		display: grid;
	}
	.pd-tabs {
		display: grid;
		grid-auto-columns: 1fr;
		grid-auto-flow: column;
		border-top: 1px solid var(--pd-border);
	}
	.pd-tab {
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 4px;
		margin: 0;
		padding: 8px 4px;
		border: 0;
		border-top: 3px solid transparent;
		border-radius: 0;
		background: #fff;
		color: var(--pd-text);
		font: 700 12px/1 var(--pd-font);
		text-transform: uppercase;
		cursor: pointer;
	}
	.pd-tab[aria-pressed="true"] {
		border-top-color: var(--pd-primary);
		color: var(--pd-primary);
	}
	.pd-tab svg {
		width: 22px;
		height: 22px;
	}
	.pd-foot {
		margin: 0;
		padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
	}
}
