:root {
	--bg-1: #fff7e6;
	--bg-2: #ffe9c4;
	--panel: rgba(255, 255, 255, 0.86);
	--panel-strong: #ffffff;
	--ink: #2d2410;
	--muted: #7c6a4a;
	--line: rgba(60, 40, 10, 0.14);
	--accent: #f59e0b;
	--accent-2: #ec4899;
	--success: #16a34a;
	--tile-1: #fef3c7;
	--tile-2: #fde68a;
	--tile-3: #fbbf24;
	--tile-shadow: 0 6px 14px rgba(120, 80, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

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

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

body {
	font-family: Nunito, 'Segoe UI', system-ui, sans-serif;
	color: var(--ink);
	background:
		radial-gradient(circle at 18% 14%, rgba(245, 158, 11, 0.22), transparent 30%),
		radial-gradient(circle at 82% 22%, rgba(236, 72, 153, 0.18), transparent 30%),
		linear-gradient(160deg, var(--bg-1) 0%, var(--bg-2) 100%);
}

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

.toolbar,
.mission-card,
.board-wrap {
	position: relative;
}

.toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.6rem;
	padding: 0.6rem 0.85rem;
	border-radius: 1.1rem;
	background: var(--panel);
	border: 1px solid var(--line);
	box-shadow: 0 8px 18px rgba(120, 80, 0, 0.1);
}

.brand .eyebrow,
.label {
	margin: 0;
	color: var(--accent);
	font-size: 0.7rem;
	font-weight: 800;
	letter-spacing: 0.2em;
	text-transform: uppercase;
}

h1, h2, p {
	margin: 0;
}

h1 {
	font-size: clamp(1.3rem, 4vw, 1.8rem);
	line-height: 1.05;
}

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

button, #goBack {
	border: 1px solid var(--line);
	border-radius: 999px;
	padding: 0.55rem 0.85rem;
	background: var(--panel-strong);
	color: var(--ink);
	font: inherit;
	font-weight: 700;
	text-decoration: none;
	cursor: pointer;
	transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
	box-shadow: 0 4px 10px rgba(120, 80, 0, 0.12);
}

button:hover, button:focus-visible {
	outline: none;
	transform: translateY(-1px);
	border-color: var(--accent);
	box-shadow: 0 8px 16px rgba(245, 158, 11, 0.28);
}

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

#soundToggle[aria-pressed="false"] {
	opacity: 0.65;
}

.mission-card {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.6rem;
	padding: 0.55rem 0.85rem;
	border-radius: 1rem;
	background: var(--panel);
	border: 1px solid var(--line);
	box-shadow: 0 8px 18px rgba(120, 80, 0, 0.1);
}

#missionText {
	margin-top: 0.2rem;
	color: var(--muted);
	font-size: 0.92rem;
}

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

.stat-chip {
	white-space: nowrap;
	border-radius: 999px;
	padding: 0.35rem 0.7rem;
	background: rgba(245, 158, 11, 0.16);
	color: var(--accent);
	font-weight: 700;
	font-size: 0.85rem;
}

.stat-chip strong {
	color: var(--ink);
}

.board-wrap {
	position: relative;
	display: grid;
	place-items: center;
	min-height: 0;
}

.board {
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	grid-template-rows: repeat(4, 1fr);
	gap: clamp(4px, 1vw, 8px);
	width: min(92vw, 60vh, 480px);
	aspect-ratio: 1 / 1;
	padding: clamp(6px, 1.4vw, 12px);
	background: linear-gradient(135deg, #4b3a1f, #6b5331);
	border-radius: 1.2rem;
	box-shadow: 0 18px 36px rgba(60, 40, 10, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.1);
	touch-action: none;
	user-select: none;
	-webkit-user-select: none;
}

.tile {
	position: relative;
	display: grid;
	place-items: center;
	border-radius: 0.7rem;
	font-size: clamp(1.2rem, 5vw, 2rem);
	font-weight: 800;
	color: #3b2a10;
	background: linear-gradient(150deg, var(--tile-1), var(--tile-2) 55%, var(--tile-3));
	box-shadow: var(--tile-shadow);
	cursor: pointer;
	transition: transform 240ms cubic-bezier(0.34, 1.3, 0.64, 1), box-shadow 0.15s ease;
	will-change: transform;
	overflow: hidden;
	-webkit-tap-highlight-color: transparent;
}

.tile.empty {
	background: transparent;
	box-shadow: none;
	cursor: default;
	color: transparent;
}

.tile:not(.empty):hover {
	box-shadow: 0 10px 20px rgba(245, 158, 11, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.tile:not(.empty):active {
	transform: scale(0.94);
}

.tile.solved {
	background: linear-gradient(150deg, #bbf7d0, #86efac 55%, #4ade80);
	color: #14532d;
}

.tile-label {
	position: relative;
	z-index: 1;
	text-shadow: 0 2px 6px rgba(255, 255, 255, 0.65);
}

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

.confetti-piece {
	position: absolute;
	top: -8vh;
	width: 12px;
	height: 20px;
	border-radius: 999px;
	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), -8vh, 0) rotate(0deg); }
	10% { opacity: 1; }
	100% { opacity: 0; transform: translate3d(var(--x, 0), 112vh, 0) rotate(var(--spin, 540deg)); }
}

@media (max-width: 560px) {
	.app-shell {
		gap: 0.45rem;
		padding: 0.4rem 0.4rem calc(0.4rem + env(safe-area-inset-bottom));
	}
	.toolbar { padding: 0.45rem 0.6rem; border-radius: 0.9rem; }
	h1 { font-size: 1.2rem; }
	.eyebrow { font-size: 0.62rem; letter-spacing: 0.16em; }
	.mission-card { padding: 0.45rem 0.6rem; border-radius: 0.85rem; flex-direction: column; align-items: flex-start; gap: 0.3rem; }
	#missionText { font-size: 0.82rem; }
	.stats { gap: 0.3rem; }
	.stat-chip { font-size: 0.75rem; padding: 0.28rem 0.55rem; }
	button { padding: 0.45rem 0.7rem; font-size: 0.85rem; }
	.board { width: min(94vw, 56vh); }
}

#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);
}
