:root {
	--bg: #0f172a;
	--surface: #111827;
	--text: #e5e7eb;
	--muted: #9ca3af;
	--primary: #22c55e;
	--primary-800: #166534;
	--secondary: #374151;
	--accent: #38bdf8;
	--danger: #ef4444;
	--grid-gap: 8px;
}

* {
	box-sizing: border-box;
}

html, body {
	height: 100%;
}

body {
	margin: 0;
	font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
	background: radial-gradient(1200px 800px at 80% -10%, #1f2937, transparent 60%), var(--bg);
	color: var(--text);
}

.screen.hidden {
	display: none;
}

.card {
	background: linear-gradient(180deg, rgba(31, 41, 55, 0.4), rgba(17, 24, 39, 0.55));
	border: 1px solid rgba(148, 163, 184, 0.12);
	border-radius: 12px;
	padding: 16px;
	backdrop-filter: blur(10px);
	box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.setup-grid {
	display: grid;
	grid-template-columns: 1fr;
	gap: 16px;
}

.setup-actions {
	margin-top: 12px;
	display: flex;
	justify-content: flex-end;
}

.setup-label {
	font-size: 16px;
	color: var(--text);
	font-weight: 600;
}

.setup-field .hint {
	display: block;
	margin-top: 6px;
	font-size: 12px;
	color: var(--muted);
}

.image-preview {
	margin-top: 8px;
	border-radius: 10px;
	border: 1px solid #1f2937;
	height: 180px;
	background: repeating-conic-gradient(from 45deg, #0b1220 0% 25%, #0e1526 0% 50%) 50% / 16px 16px;
	background-size: cover;
	background-position: center;
}

.theme-gallery {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 10px;
	margin-top: 8px;
}

.theme-card {
	position: relative;
	border: 2px solid transparent;
	border-radius: 12px;
	overflow: hidden;
	height: 88px;
	background: #0b1220;
	cursor: pointer;
	box-shadow: 0 6px 14px rgba(0,0,0,0.25);
	display: grid;
	place-items: center;
	font-size: 28px;
	user-select: none;
}

.theme-card.selected {
	border-color: #f59e0b;
	box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.4);
}

.theme-card .theme-label {
	position: absolute;
	left: 8px;
	bottom: 6px;
	font-size: 12px;
	background: rgba(0,0,0,0.45);
	padding: 2px 6px;
	border-radius: 8px;
	color: #fff;
}

.app-header {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 16px 20px;
	border-bottom: 1px solid #1f2937;
	background: rgba(17, 24, 39, 0.7);
	backdrop-filter: blur(6px);
	position: sticky;
	top: 0;
	z-index: 10;
}

.app-header h1 {
	margin: 0;
	font-size: 20px;
	letter-spacing: 0.4px;
}

.controls {
	display: flex;
	align-items: center;
	gap: 12px;
	flex-wrap: wrap;
}

label {
	font-size: 14px;
	color: var(--muted);
	display: inline-flex;
	align-items: center;
	gap: 8px;
}

select,
input[type="file"],
button {
	border: 1px solid #374151;
	background: #0b1220;
	color: var(--text);
	padding: 8px 10px;
	border-radius: 8px;
	font-size: 14px;
}

input[type="file"] {
	max-width: 220px;
}

button {
	cursor: pointer;
	background: linear-gradient(to bottom, #0b1220, #0b1220) padding-box, linear-gradient(to bottom right, #374151, #111827) border-box;
	border: 1px solid transparent;
}

button:hover {
	border-color: #4b5563;
}

button:active {
	transform: translateY(1px);
}

button.secondary {
	background: #0b1220;
}

.primary {
	background: linear-gradient(to bottom, #14532d, #064e3b) padding-box, linear-gradient(45deg, #22c55e, #16a34a) border-box;
	border: 1px solid transparent;
}

.xl {
	font-size: 16px;
	padding: 12px 16px;
	border-radius: 10px;
}

.stat {
	font-size: 14px;
	color: var(--muted);
}

.game-topbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
}

.stats {
	display: flex;
	align-items: center;
	gap: 12px;
}

.piece.selected {
	outline: 3px solid var(--accent);
	outline-offset: -3px;
}

.app-main {
	display: grid;
	grid-template-columns: 1fr;
	gap: 16px;
	padding: 16px;
	max-width: 1200px;
	margin: 0 auto;
}

.dragging-disable-scroll {
	overflow: hidden;
	height: 100%;
}

.tray {
	background: rgba(17, 24, 39, 0.55);
	border: 1px solid rgba(148, 163, 184, 0.12);
	border-radius: 12px;
	padding: 12px;
	backdrop-filter: blur(10px);
}

.tray h2,
.board-section h2 {
	margin: 0 0 8px 4px;
	font-size: 14px;
	color: var(--muted);
	font-weight: 600;
}

.tray-grid {
	--tray-cell: 88px;
	min-height: calc(var(--tray-cell) * 3 + var(--grid-gap) * 2);
	max-height: calc(var(--tray-cell) * 4 + var(--grid-gap) * 3);
	overflow: auto;
	-webkit-overflow-scrolling: touch;
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(var(--tray-cell), 1fr));
	grid-auto-rows: var(--tray-cell);
	gap: var(--grid-gap);
	align-content: start;
}

.board-section {
	position: relative;
	background: rgba(17, 24, 39, 0.55);
	border: 1px solid rgba(148, 163, 184, 0.12);
	border-radius: 12px;
	padding: 12px;
	backdrop-filter: blur(10px);
}

.board {
	--size: 3;
	--cell: clamp(64px, 30vw, 120px);
	display: grid;
	grid-template-columns: repeat(var(--size), var(--cell));
	grid-template-rows: repeat(var(--size), var(--cell));
	gap: var(--grid-gap);
	justify-content: center;
	align-content: center;
	margin: 0 auto;
	touch-action: none;
}

.board.jigsaw {
	gap: 2px;
}

.cell {
	width: var(--cell);
	height: var(--cell);
	border-radius: 10px;
	background: linear-gradient(180deg, rgba(15,23,42,0.7), rgba(15,23,42,0.4));
	border: 1px solid rgba(148, 163, 184, 0.12);
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: inset 0 0 0 1px rgba(0,0,0,0.35);
}

.board.jigsaw .cell {
	border: 1px solid rgba(148, 163, 184, 0.06);
}

.piece {
	position: relative;
	width: 100%;
	height: 100%;
	border-radius: 10px;
	overflow: hidden;
	border: 1px solid rgba(148, 163, 184, 0.18);
	background-size: var(--bg-size);
	background-image: var(--bg-image);
	background-position: var(--bg-x) var(--bg-y);
	box-shadow: 0 8px 20px rgba(0,0,0,0.35);
	user-select: none;
	touch-action: none;
	-webkit-user-drag: none;
}

.board.jigsaw .piece {
	border: 0;
	border-radius: 0;
	box-shadow: 0 6px 14px rgba(0,0,0,0.3);
}

.piece[draggable="true"] {
	cursor: grab;
}

.piece:active {
	cursor: grabbing;
}

.tray-grid .piece {
	width: 100%;
	height: 100%;
}

.ghost {
	opacity: 0.4;
}

.drop-ok {
	outline: 2px solid var(--accent);
	outline-offset: -2px;
}

.drop-bad {
	outline: 2px solid var(--danger);
	outline-offset: -2px;
}

.overlay {
	position: absolute;
	inset: 12px;
	background: rgba(0,0,0,0.6);
	display: grid;
	place-items: center;
	border-radius: 10px;
}

.overlay.hidden {
	display: none;
}

.overlay-card {
	background: rgba(6, 12, 24, 0.7);
	border: 1px solid rgba(148, 163, 184, 0.12);
	border-radius: 12px;
	padding: 20px;
	text-align: center;
	max-width: 420px;
	box-shadow: 0 10px 30px rgba(0,0,0,0.4);
	animation: pop-in 320ms ease-out;
}

.overlay-card h3 {
	margin-top: 0;
}

@keyframes pop-in {
	from { transform: scale(0.95); opacity: 0; }
	to { transform: scale(1); opacity: 1; }
}

.confetti {
	position: absolute;
	inset: 0;
	pointer-events: none;
}

@media (min-width: 900px) {
	.app-main {
		grid-template-columns: 320px 1fr;
		gap: 20px;
		padding: 20px;
	}
	.board {
		--cell: min(20vmin, 128px);
	}
	.tray-grid {
		--tray-cell: 96px;
	}
	.setup-grid {
		grid-template-columns: repeat(3, 1fr);
	}
}


