:root {
	--ink: #1a1330;
	--muted: #6a5d8a;
	--panel: rgba(255, 255, 255, 0.9);
	--accent: #7c3aed;
	--accent-2: #ec4899;
	--success: #16a34a;
	--shell-pad: clamp(0.5rem, 2vw, 1.4rem);
}

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

html, body {
	height: 100%;
	margin: 0;
	overflow: hidden;
	touch-action: none;
	-webkit-tap-highlight-color: transparent;
}

body {
	font-family: Nunito, 'Segoe UI', system-ui, sans-serif;
	color: var(--ink);
	background:
		radial-gradient(circle at 20% 15%, rgba(124, 58, 237, 0.18), transparent 35%),
		radial-gradient(circle at 80% 85%, rgba(236, 72, 153, 0.16), transparent 35%),
		linear-gradient(160deg, #faf5ff 0%, #f0e7ff 50%, #fce7f3 100%);
}

.app-shell {
	height: 100dvh;
	height: 100vh;
	width: 100%;
	display: grid;
	grid-template-rows: auto auto minmax(0, 1fr);
	gap: clamp(0.4rem, 1.5vh, 0.7rem);
	padding: calc(var(--shell-pad) + env(safe-area-inset-top)) calc(var(--shell-pad) + env(safe-area-inset-right)) calc(var(--shell-pad) + env(safe-area-inset-bottom)) calc(var(--shell-pad) + env(safe-area-inset-left));
}

.toolbar, .status-card, .play-wrap { position: relative; }

.toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.6rem;
	border-radius: 1.2rem;
	padding: 0.6rem 0.9rem;
	background: var(--panel);
	border: 2px solid rgba(124, 58, 237, 0.15);
	box-shadow: 0 8px 18px rgba(80, 40, 140, 0.1);
}

.eyebrow {
	margin: 0 0 0.1rem;
	color: var(--accent);
	font-weight: 800;
	letter-spacing: 0.16em;
	text-transform: uppercase;
	font-size: 0.68rem;
}

h1 {
	margin: 0;
	font-family: Fredoka, Nunito, sans-serif;
	font-size: clamp(1.3rem, 5vw, 2rem);
	line-height: 0.95;
}

.toolbar-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }

button, #goBack {
	border: 0;
	border-radius: 999px;
	padding: 0.55rem 0.85rem;
	background: #fff;
	color: var(--ink);
	font: inherit;
	font-weight: 800;
	text-decoration: none;
	cursor: pointer;
	transition: transform 0.12s ease, opacity 0.12s ease;
}

button:hover, button:focus-visible {
	outline: 3px solid rgba(124, 58, 237, 0.3);
	transform: translateY(-2px);
}

button:active { transform: translateY(0) scale(0.96); }

button:disabled {
	opacity: 0.4;
	cursor: not-allowed;
}

#hintBtn { background: linear-gradient(135deg, #84cc16, #22c55e); color: #fff; }

.status-card {
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 1rem;
	padding: 0.5rem 0.9rem;
	background: var(--panel);
	border: 2px solid rgba(124, 58, 237, 0.1);
}

#statusText {
	margin: 0;
	color: var(--muted);
	font-weight: 800;
	font-size: clamp(0.85rem, 2.3vw, 1rem);
	text-align: center;
}

.play-wrap {
	display: grid;
	place-items: center;
	min-height: 0;
}

#board {
	width: min(95vw, 70vh, 480px);
	height: min(95vw, 70vh, 480px);
	background: rgba(255, 255, 255, 0.6);
	border-radius: 1.2rem;
	box-shadow: 0 16px 36px rgba(80, 40, 140, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.5);
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
}

.silhouette-fill {
	fill: rgba(255, 255, 255, 0.95);
	stroke: rgba(124, 58, 237, 0.35);
	stroke-width: 1.5;
	stroke-dasharray: 6 4;
}

.tan {
	cursor: grab;
	transition: filter 0.15s ease;
}

.tan.selected {
	filter: drop-shadow(0 0 10px rgba(124, 58, 237, 0.7));
}

.tan.dragging { cursor: grabbing; }

.tan.complete {
	filter: drop-shadow(0 0 12px rgba(34, 197, 94, 0.7));
}

.tan.auto-solving {
	filter: drop-shadow(0 6px 10px rgba(124, 58, 237, 0.55));
}

#confettiLayer {
	position: fixed;
	inset: 0;
	pointer-events: none;
	overflow: hidden;
	z-index: 5;
}

.confetti-piece {
	position: absolute;
	top: -24px;
	width: 14px;
	height: 22px;
	border-radius: 4px;
	animation: confetti-fall var(--duration, 1800ms) linear forwards;
	will-change: transform, opacity;
}

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

@keyframes confetti-fall {
	0% { opacity: 0; transform: translate3d(var(--x, 0), -24px, 0) rotate(0deg); }
	10% { opacity: 1; }
	100% { opacity: 0; transform: translate3d(var(--x, 0), 110vh, 0) rotate(var(--spin, 540deg)); }
}

@media (max-width: 560px) {
	:root { --shell-pad: 0.4rem; }
	.toolbar { padding: 0.4rem 0.55rem; border-radius: 0.9rem; }
	.eyebrow { display: none; }
	h1 { font-size: clamp(1rem, 5vw, 1.4rem); }
	.status-card { padding: 0.35rem 0.5rem; border-radius: 0.8rem; }
	#statusText { font-size: 0.78rem; }
	#board { width: min(96vw, 60vh); height: min(96vw, 60vh); }
	.toolbar-actions button { padding: 0.4rem 0.5rem; font-size: 0.78rem; }
}

@media (prefers-reduced-motion: reduce) {
	*, *::before, *::after { animation: none !important; transition: none !important; }
}

#goBack {
	font: inherit;
	font-weight: 700;
	background: linear-gradient(180deg, #ff6b6b 0%, #e03131 100%);
	color: #fff;
	border: 2px solid rgba(255, 255, 255, 0.4);
	border-radius: 999px;
	padding: 0.5rem 0.85rem;
	font-size: 0.78rem;
	line-height: 1;
	box-shadow: 0 8px 18px rgba(224, 49, 49, 0.32);
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	flex: 0 0 auto;
	text-shadow: 0 1px 0 rgba(0, 0, 0, 0.16);
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#goBack:hover,
#goBack:focus-visible {
	transform: translateY(-2px);
	box-shadow: 0 12px 24px rgba(224, 49, 49, 0.38);
	outline: 3px solid rgba(255, 107, 107, 0.3);
	outline-offset: 2px;
}

#goBack:active {
	transform: translateY(1px);
}