:root {
	--bg: #f3efe8;
	--surface: #fffdfb;
	--ink: #1c1917;
	--muted: #5c534c;
	--line: #e3dbd1;
	--line-strong: #c9bfb3;
	--sunken: #ebe4db;
	--accent: #9a3412;
	--accent-ink: #fffdfb;
	--sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
	--serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
	color-scheme: light;
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #12110f;
		--surface: #1c1a17;
		--ink: #f6f1ea;
		--muted: #c9bfb4;
		--line: #3a342c;
		--line-strong: #5c534a;
		--sunken: #26221e;
		--accent: #f0b089;
		--accent-ink: #2a140c;
		color-scheme: dark;
	}

	.error {
		background: #3c221c;
		color: #ffd2c8;
	}
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

[hidden] {
	display: none !important;
}

html {
	height: 100%;
}

body {
	margin: 0;
	min-height: 100%;
	background: var(--bg);
	color: var(--ink);
	font-family: var(--sans);
	font-size: 16px;
	line-height: 1.4;
	-webkit-font-smoothing: antialiased;
}

body.sheet-open {
	overflow: hidden;
}

button,
input {
	font: inherit;
	color: inherit;
}

button {
	cursor: pointer;
}

img {
	max-width: 100%;
}

.sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.app {
	width: min(1080px, 100%);
	margin: 0 auto;
	padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.brand {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-bottom: 18px;
}

.brand h1 {
	margin: 0;
	font-family: var(--serif);
	font-size: 28px;
	font-weight: 600;
	letter-spacing: -0.03em;
	line-height: 1;
}

.brand p {
	margin: 4px 0 0;
	color: var(--muted);
	font-size: 14px;
}

.error {
	margin: 0 0 12px;
	padding: 12px 14px;
	border-radius: 12px;
	background: #fde8e4;
	color: #6b2418;
}

.hint,
.save-note {
	margin: 8px 0 0;
	color: var(--muted);
	font-size: 13px;
	text-align: center;
}

.picker-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 12px;
}

.pick {
	position: relative;
	display: grid;
	place-items: center;
	min-height: 210px;
	padding: 16px;
	overflow: hidden;
	border: 1.5px dashed var(--line-strong);
	border-radius: 18px;
	background: var(--surface);
	cursor: pointer;
	text-align: center;
}

.pick.is-drag,
.hit.is-drag {
	border-color: var(--accent);
	box-shadow: inset 0 0 0 2px var(--accent);
}

.pick:focus-within {
	outline: 2px solid var(--accent);
	outline-offset: 3px;
}

.pick-empty {
	display: grid;
	justify-items: center;
	gap: 6px;
}

.pick.has-photo .pick-empty {
	display: none;
}

.pick img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.pick.has-photo::after {
	content: attr(data-label);
	position: absolute;
	z-index: 1;
	left: 10px;
	bottom: 10px;
	padding: 6px 10px;
	border-radius: 999px;
	background: rgba(20, 16, 12, 0.72);
	color: #fff;
	font-size: 13px;
	font-weight: 650;
}

.plus {
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: var(--sunken);
	font-size: 28px;
	line-height: 1;
}

.pick-title {
	font-weight: 700;
}

.pick-sub {
	color: var(--muted);
	font-size: 13px;
}

.workspace {
	display: grid;
	gap: 18px;
}

.workspace > * {
	min-width: 0;
}

.frame {
	position: relative;
	width: min(100%, calc((100dvh - 280px) * var(--rw) / var(--rh)));
	max-height: calc(100dvh - 280px);
	margin-inline: auto;
	aspect-ratio: var(--rw) / var(--rh);
	overflow: hidden;
	border-radius: 0;
	background: transparent;
	box-shadow: 0 16px 40px rgba(0, 0, 0, 0.14);
	--rw: 4;
	--rh: 5;
}

.frame canvas {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	pointer-events: none;
}

.hit {
	position: absolute;
	z-index: 1;
	touch-action: none;
	cursor: grab;
	-webkit-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
}

.hit.is-panning {
	cursor: grabbing;
}

.hit:focus-visible,
.hit.is-panning {
	box-shadow: inset 0 0 0 3px var(--accent);
}

.overlay-actions {
	position: absolute;
	z-index: 2;
	top: 8px;
	right: 8px;
	display: flex;
	gap: 6px;
}

.overlay-btn {
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(20, 16, 12, 0.72);
	color: #fff;
	cursor: pointer;
	touch-action: manipulation;
}

.overlay-btn svg {
	width: 22px;
	height: 22px;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.overlay-btn:focus-visible,
.overlay-btn:focus-within {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.photo-actions {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px;
	margin-top: 10px;
}

.pair-actions {
	flex-wrap: nowrap;
}

.pair-actions .text-btn {
	flex: 1;
}

.text-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-height: 44px;
	padding: 8px 14px;
	border: 1px solid var(--line);
	border-radius: 999px;
	background: var(--surface);
	color: var(--ink);
	font-weight: 600;
	font-size: 14px;
	text-decoration: none;
}

button:focus-visible,
.text-btn:focus-within,
.segment button:focus-visible {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.controls {
	padding: 8px 16px 16px;
	border: 1px solid var(--line);
	border-radius: 20px;
	background: var(--surface);
}

fieldset {
	margin: 0 0 18px;
	padding: 0;
	border: 0;
	min-inline-size: 0;
}

fieldset:last-of-type {
	margin-bottom: 0;
}

legend {
	display: block;
	width: 100%;
	margin: 0 0 8px;
	padding: 0;
	color: var(--ink);
	font-size: 15px;
	font-weight: 700;
	letter-spacing: -0.01em;
	line-height: 1.3;
}

fieldset:first-of-type > legend {
	padding-top: 6px;
}

fieldset + fieldset > legend {
	padding-top: 14px;
	border-top: 1px solid var(--line);
}

.segment {
	display: grid;
	gap: 4px;
	padding: 4px;
	border-radius: 14px;
	background: var(--sunken);
}

.segment.two {
	grid-template-columns: 1fr 1fr;
}

.segment.four {
	grid-template-columns: repeat(4, 1fr);
}

.segment button {
	display: grid;
	gap: 1px;
	align-content: center;
	justify-items: center;
	min-height: 44px;
	padding: 8px 4px;
	border: 0;
	border-radius: 10px;
	background: transparent;
	color: var(--ink);
	font-size: 14px;
	font-weight: 650;
}

.segment button[aria-pressed="true"] {
	background: var(--surface);
	box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 1px var(--line);
}

.seg-title {
	font-weight: 700;
}

.seg-sub {
	color: var(--muted);
	font-size: 11px;
	font-weight: 600;
}

.slider {
	display: grid;
	gap: 2px;
	margin-top: 12px;
}

.slider-top {
	display: flex;
	justify-content: space-between;
	color: var(--muted);
	font-size: 13px;
	font-weight: 650;
}

input[type="range"] {
	width: 100%;
	height: 36px;
	accent-color: var(--accent);
}

.swatches {
	display: grid;
	grid-template-columns: repeat(7, 1fr);
	margin-top: 12px;
}

.swatch {
	position: relative;
	display: grid;
	place-items: center;
	height: 44px;
}

.swatch span {
	width: 28px;
	height: 28px;
	border: 1px solid var(--line-strong);
	border-radius: 50%;
}

.swatch input[type="radio"] {
	position: absolute;
	opacity: 0;
	inset: 0;
	margin: 0;
}

.swatch input:checked + span,
.swatch.is-selected input[type="color"] {
	box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink);
}

.swatch:focus-within span,
.swatch-custom:focus-within input {
	outline: 2px solid var(--accent);
	outline-offset: 3px;
}

.swatch input[type="color"] {
	width: 28px;
	height: 28px;
	padding: 0;
	border: 1px solid var(--line-strong);
	border-radius: 50%;
	background: none;
	overflow: hidden;
}

.swatch input[type="color"]::-webkit-color-swatch-wrapper {
	padding: 0;
}

.swatch input[type="color"]::-webkit-color-swatch {
	border: 0;
	border-radius: 50%;
}

.check {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 44px;
	font-weight: 650;
}

.check input {
	width: 22px;
	height: 22px;
	accent-color: var(--accent);
}

.label-fields {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
	margin-bottom: 8px;
}

.label-fields label {
	display: grid;
	gap: 6px;
	color: var(--muted);
	font-size: 13px;
	font-weight: 650;
}

.label-fields input {
	width: 100%;
	min-height: 44px;
	padding: 0 12px;
	border: 1px solid var(--line);
	border-radius: 10px;
	background: var(--bg);
	font-size: 16px;
}

.controls .hint {
	text-align: left;
}

.savebar {
	margin-bottom: 12px;
}

@media (max-width: 879px) {
	.controls-col {
		display: flex;
		flex-direction: column;
	}

	.controls {
		order: 1;
	}

	.savebar {
		order: 2;
		margin-top: 16px;
		margin-bottom: 0;
	}
}

.save-actions {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
	width: min(720px, 100%);
	margin: 0 auto;
}

#share,
#download {
	min-height: 52px;
	border-radius: 14px;
	font-size: 17px;
	font-weight: 700;
}

#share {
	border: 1px solid var(--line);
	background: var(--surface);
	color: var(--ink);
}

#download {
	border: 0;
	background: var(--accent);
	color: var(--accent-ink);
}

#share:disabled,
#download:disabled {
	opacity: 0.6;
	cursor: progress;
}

#share:focus-visible,
#download:focus-visible {
	outline: 2px solid var(--ink);
	outline-offset: 3px;
}

.sheet {
	position: fixed;
	z-index: 20;
	inset: 0;
	display: grid;
	align-items: end;
	justify-items: center;
	padding: 16px;
	padding-bottom: calc(16px + env(safe-area-inset-bottom));
	background: rgba(20, 16, 12, 0.72);
}

.sheet-card {
	width: min(100%, 440px);
	padding: 16px;
	border-radius: 20px;
	background: var(--surface);
}

.sheet-card h2 {
	margin: 0 0 10px;
	font-family: var(--serif);
	font-size: 24px;
}

.sheet-card img {
	width: 100%;
	max-height: 52dvh;
	object-fit: contain;
	border-radius: 12px;
	background: #111;
	-webkit-touch-callout: default;
}

.sheet-card p {
	margin: 10px 0;
	color: var(--muted);
	font-size: 14px;
}

.sheet-actions {
	display: flex;
	gap: 8px;
}

.sheet-actions .text-btn,
.sheet-actions button {
	flex: 1;
}

#sheetClose {
	min-height: 44px;
	border: 0;
	border-radius: 999px;
	background: var(--accent);
	color: var(--accent-ink);
	font-weight: 700;
}

@media (max-width: 359px) {
	.picker-grid,
	.segment.four,
	.label-fields {
		grid-template-columns: 1fr 1fr;
	}

	.segment.four {
		grid-template-columns: 1fr 1fr;
	}
}

@media (min-width: 880px) {
	.app {
		padding: 28px 24px 48px;
	}

	.workspace {
		grid-template-columns: minmax(0, 1fr) 380px;
		align-items: start;
		gap: 28px;
	}

	.stage-wrap,
	.controls-col {
		align-self: start;
	}

	.stage-wrap {
		position: sticky;
		top: 16px;
	}

	.frame {
		width: min(100%, calc(78dvh * var(--rw) / var(--rh)));
		max-height: 78dvh;
	}

	.savebar {
		position: sticky;
		top: 12px;
		z-index: 2;
		margin-bottom: 12px;
		padding: 0 0 12px;
		border-top: 0;
		background: var(--bg);
		backdrop-filter: none;
	}

	.hint {
		text-align: center;
	}
}

@media (hover: hover) {
	#share:hover,
	#download:hover,
	#sheetClose:hover {
		filter: brightness(1.06);
	}
}

@media (prefers-reduced-motion: reduce) {
	* {
		scroll-behavior: auto !important;
	}
}
