:root {
	--bg: #0f1218;
	--surface: #1a1f2a;
	--border: #2a3344;
	--text: #e8ecf3;
	--muted: #8b95a8;
	--accent: #5b8cff;
	--accent-hover: #7aa0ff;
	--danger: #e85d5d;
}

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

.svg-sprite {
	position: absolute;
	width: 0;
	height: 0;
	overflow: hidden;
}

.btn--with-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.45rem;
}

.icon {
	flex-shrink: 0;
}

.icon--sm {
	width: 1.125rem;
	height: 1.125rem;
}

body {
	margin: 0;
	min-height: 100vh;
	font-family:
		system-ui,
		-apple-system,
		'Segoe UI',
		sans-serif;
	background: var(--bg);
	color: var(--text);
	line-height: 1.5;
}

.app {
	width: 100%;
	max-width: none;
	margin: 0;
	min-height: 100vh;
	padding: clamp(0.75rem, 2vw, 1.25rem) clamp(0.75rem, 2vw, 1.5rem)
		clamp(1rem, 2vw, 1.5rem);
	display: flex;
	flex-direction: column;
	box-sizing: border-box;
	overflow: visible;
}

.header {
	margin-bottom: 1.25rem;
	flex-shrink: 0;
}

.app-main {
	display: flex;
	flex-direction: column;
	gap: 1.25rem;
	flex: 1;
	min-height: auto;
	overflow: visible;
}

.app-col {
	min-width: 0;
}

.app-col--upload {
	position: -webkit-sticky;
	position: sticky;
	top: 0.65rem;
	top: max(0.65rem, env(safe-area-inset-top, 0px));
	z-index: 4;
	background: var(--bg);
	max-height: calc(100vh - 1.25rem);
	max-height: calc(100dvh - 1.25rem);
	overflow-x: visible;
	overflow-y: auto;
	padding-bottom: 0.25rem;
}

.app-col--preview {
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: stretch;
	min-width: 0;
	gap: 1rem;
}

.composers-list {
	display: flex;
	flex-direction: column;
	gap: 1.5rem;
	width: 100%;
	align-items: stretch;
}

.composer {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	width: 100%;
}

.composer__row {
	display: grid;
	grid-template-columns: minmax(0, 1fr) minmax(12rem, 20rem);
	gap: 1.25rem 1.5rem;
	align-items: start;
	width: 100%;
}

.composer__preview {
	min-width: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
}

.composer__preview .stage-wrap {
	width: min(100%, calc(75vh * 4 / 3));
	margin-inline: auto;
}

.composer__export {
	align-self: start;
	min-width: 0;
	width: 100%;
}

.composer-actions {
	width: 100%;
	max-width: none;
	margin-inline: 0;
}

.composer-remove {
	margin-top: 0.65rem;
	width: 100%;
}

.preview-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 0.75rem;
	width: fit-content;
	max-width: 100%;
	margin-inline: auto;
	margin-top: 0.25rem;
}

.upload-sticky-bar {
	margin-top: 1rem;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.upload-sticky-bar__download-all,
.upload-sticky-bar__bookmark {
	width: 100%;
}

@media (min-width: 1024px) {
	.app {
		padding: clamp(0.75rem, 1.5vw, 1.25rem) clamp(0.75rem, 2vw, 1.5rem);
	}

	.app-main {
		display: grid;
		grid-template-columns: minmax(200px, 20rem) 1fr;
		gap: 1.25rem 1.5rem;
		align-items: start;
		overflow: visible;
	}

	.app-col--upload {
		align-self: start;
		border-right: 1px solid color-mix(in srgb, var(--border) 45%, transparent);
		padding-right: 1.25rem;
	}

	.bulk-toolbar {
		flex-direction: column;
		align-items: stretch;
		margin-top: 0;
	}

	.bulk-toolbar__hint {
		flex-basis: auto;
	}

	.bulk-upload-label {
		width: 100%;
	}

	.actions {
		margin-top: 0;
		width: 100%;
	}

	.actions .btn--primary {
		width: 100%;
	}
}

@media (max-width: 900px) {
	.composer__row {
		grid-template-columns: 1fr;
	}

	.composer__export {
		max-width: min(100%, 24rem);
		margin-inline: auto;
	}
}

h1 {
	font-size: 1.35rem;
	font-weight: 600;
	letter-spacing: -0.02em;
	margin: 0 0 0.35rem;
}

.subtitle {
	margin: 0 0 1.25rem;
	font-size: 0.9rem;
	color: var(--muted);
	max-width: 42rem;
}

.bulk-toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.75rem;
	padding: 0.75rem 1rem;
	border-radius: 10px;
	border: 1px dashed var(--border);
	background: rgba(26, 31, 42, 0.6);
	transition:
		border-color 0.15s,
		background 0.15s;
}

.bulk-toolbar.is-dragover {
	border-color: var(--accent);
	background: rgba(91, 140, 255, 0.08);
}

.bulk-toolbar__hint {
	flex-basis: 100%;
	font-size: 0.78rem;
	color: var(--muted);
	margin: 0;
}

.bulk-upload-label {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	margin: 0;
	gap: 0.45rem;
}

.bulk-upload-label__text {
	position: relative;
	z-index: 0;
	pointer-events: none;
	user-select: none;
}

.file-input-bulk {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	cursor: pointer;
	font-size: 1rem;
	z-index: 1;
}

.stage-wrap {
	border-radius: 12px;
	overflow: hidden;
	border: 1px solid var(--border);
	background: var(--surface);
	box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
	display: flex;
	flex-direction: column;
}

/* 4:3 frame; height never exceeds 75% of viewport */
.stage {
	position: relative;
	display: flex;
	width: 100%;
	aspect-ratio: 4 / 3;
	max-height: 75vh;
}

.pane {
	position: relative;
	flex: 1;
	min-width: 0;
	background: #12151c;
}

.pane__dropzone {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	padding: 1rem;
	border: 2px dashed var(--border);
	margin: 8px;
	border-radius: 8px;
	transition:
		border-color 0.15s,
		background 0.15s;
}

.pane__dropzone.is-dragover {
	border-color: var(--accent);
	background: rgba(91, 140, 255, 0.08);
}

.pane__dropzone.hidden {
	display: none;
}

.file-input {
	position: absolute;
	width: 0;
	height: 0;
	opacity: 0;
	pointer-events: none;
}

.hint {
	font-size: 0.8rem;
	color: var(--muted);
}

.pane__editor {
	position: absolute;
	inset: 0;
}

.pane__editor.hidden {
	display: none;
}

.pane__close {
	position: absolute;
	top: 8px;
	right: 8px;
	z-index: 5;
	width: 2rem;
	height: 2rem;
	padding: 0;
	margin: 0;
	border: none;
	border-radius: 999px;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	color: #fff;
	background: rgba(15, 18, 24, 0.72);
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
	transition:
		background 0.15s,
		transform 0.1s;
}

.pane__close:hover {
	background: rgba(232, 93, 93, 0.92);
}

.pane__close:active {
	transform: scale(0.96);
}

.pane__close--bottom {
	top: auto;
	bottom: 8px;
}

.pane__close-icon {
	display: block;
	width: 1.125rem;
	height: 1.125rem;
}

.viewport {
	position: absolute;
	inset: 0;
	overflow: hidden;
	cursor: grab;
	touch-action: none;
}

.viewport.is-dragging {
	cursor: grabbing;
}

.pane__img {
	position: absolute;
	top: 0;
	left: 0;
	max-width: none;
	max-height: none;
	user-select: none;
	-webkit-user-drag: none;
	transform-origin: 50% 50%;
	will-change: transform;
}

.stage-controls {
	display: grid;
	grid-template-columns: 1fr 1fr;
	background: rgba(0, 0, 0, 0.25);
	border-top: 1px solid var(--border);
}

.stage-controls__col {
	min-width: 0;
}

.stage-controls__col:first-child {
	border-right: 1px solid var(--border);
}

.controls {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 0.75rem;
	padding: 0.55rem 0.75rem;
}

.controls.hidden {
	display: none;
}

.control {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 0.2rem;
	min-width: 0;
}

.control__label {
	font-size: 0.7rem;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--muted);
}

.control input[type='range'] {
	width: 100%;
	accent-color: var(--accent);
}

.rotation-slider-row {
	display: flex;
	align-items: center;
	gap: 0.35rem;
	width: 100%;
}

.rotation-slider-row > input[type='range'] {
	position: relative;
	z-index: 0;
	flex: 1;
	min-width: 0;
	width: auto;
}

.rotation-slider-row > .btn.rotation-step {
	position: relative;
	z-index: 1;
	min-width: 2rem;
	padding-inline: 0.35rem;
	font-weight: 600;
	line-height: 1;
}

.divider {
	position: absolute;
	left: 50%;
	top: 0;
	bottom: 0;
	width: 2px;
	margin-left: -1px;
	background: linear-gradient(
		to bottom,
		transparent,
		rgba(255, 255, 255, 0.25) 15%,
		rgba(255, 255, 255, 0.25) 85%,
		transparent
	);
	pointer-events: none;
	z-index: 2;
}

.stage-swap {
	position: absolute;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	z-index: 6;
	white-space: nowrap;
	transition:
		background 0.15s,
		transform 0.1s;
}

.stage-swap.hidden {
	display: none;
}

.btn {
	font: inherit;
	cursor: pointer;
	border: none;
	border-radius: 8px;
	padding: 0.55rem 1rem;
	font-size: 0.875rem;
	transition:
		background 0.15s,
		color 0.15s;
}

.btn--ghost {
	background: rgba(91, 140, 255, 0.12);
	color: var(--accent);
	border: 1px solid rgba(91, 140, 255, 0.35);
}

.btn--ghost:hover {
	background: rgba(91, 140, 255, 0.2);
}

.btn--small {
	padding: 0.35rem 0.65rem;
	font-size: 0.8rem;
	background: transparent;
	color: var(--muted);
	border: 1px solid var(--border);
	flex-shrink: 0;
}

.btn--small:hover {
	color: var(--danger);
	border-color: var(--danger);
}

/* Match pane delete (×) control — overrides .btn--small transparency */
.btn.btn--small.stage-swap {
	background: rgba(15, 18, 24, 0.72);
	color: #fff;
	border: none;
	box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.btn.btn--small.stage-swap:hover:not(:disabled) {
	background: rgba(232, 93, 93, 0.92);
	color: #fff;
	border: none;
}

.btn.btn--small.stage-swap:active:not(:disabled) {
	transform: translate(-50%, -50%) scale(0.96);
}

.btn--primary {
	background: var(--accent);
	color: #fff;
	font-weight: 600;
	padding: 0.65rem 1.25rem;
}

.btn--primary:hover:not(:disabled) {
	background: var(--accent-hover);
}

.btn--primary:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.actions {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	gap: 1rem;
}

.actions.composer-actions {
	flex-wrap: nowrap;
	flex-direction: column;
	align-items: stretch;
}

.export-label {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	font-size: 0.85rem;
	color: var(--muted);
	width: 100%;
	min-width: 0;
}

.export-label input {
	font: inherit;
	padding: 0.45rem 0.65rem;
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	width: 100%;
	box-sizing: border-box;
}

.export-label input:focus {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}

.export-label select {
	font: inherit;
	padding: 0.45rem 0.65rem;
	border-radius: 8px;
	border: 1px solid var(--border);
	background: var(--surface);
	color: var(--text);
	width: 100%;
	box-sizing: border-box;
	cursor: pointer;
}

.export-label select:focus {
	outline: 2px solid var(--accent);
	outline-offset: 2px;
}
