:root {
	--ink: #20412b;
	--muted: #5f7f68;
	--panel: rgba(255, 255, 255, 0.88);
	--green: #61c469;
	--yellow: #ffe47a;
	--pink: #ff8bb3;
	--blue: #79cdf7;
	--shell-pad: clamp(0.5rem, 2vw, 1.4rem);
	--chrome-space: 11rem;
}

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

html, body {
	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 15% 18%, rgba(255, 228, 122, 0.8), transparent 26%),
		radial-gradient(circle at 85% 16%, rgba(255, 139, 179, 0.5), transparent 26%),
		radial-gradient(circle at 50% 88%, rgba(121, 205, 247, 0.4), transparent 30%),
		linear-gradient(160deg, #d7ffd9 0%, #edffe6 48%, #bcecff 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.8rem);
	padding: calc(var(--shell-pad) + env(safe-area-inset-top)) calc(var(--shell-pad) + env(safe-area-inset-right)) calc(var(--shell-pad) + max(env(safe-area-inset-bottom), 1rem)) calc(var(--shell-pad) + env(safe-area-inset-left));
}

.toolbar, .status-card, .memory-card {
	border: 3px solid rgba(32, 65, 43, 0.1);
	background: var(--panel);
	box-shadow: 0 14px 0 rgba(32, 65, 43, 0.06), 0 18px 40px rgba(43, 103, 65, 0.12);
}

.toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.6rem;
	border-radius: 1.6rem;
	padding: 0.7rem 1rem;
}

.toolbar-start {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 0.6rem;
}

.eyebrow {
	margin: 0 0 0.1rem;
	color: #e35a87;
	font-weight: 800;
	letter-spacing: 0.16em;
	text-transform: uppercase;
	font-size: 0.7rem;
}

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

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

button, #goBack {
	border: 0;
	border-radius: 999px;
	padding: 0.6rem 0.9rem;
	background: #fff;
	color: var(--ink);
	font: inherit;
	font-weight: 800;
	text-decoration: none;
	cursor: pointer;
	box-shadow: inset 0 -4px rgba(32, 65, 43, 0.07);
	transition: transform 0.12s ease;
}

#goBack {
	font-weight: 700;
	background: linear-gradient(180deg, #ff6b6b 0%, #e03131 100%);
	color: #fff;
	border: 2px solid rgba(255, 255, 255, 0.4);
	padding: 0.5rem 0.85rem;
	font-size: 0.78rem;
	line-height: 1;
	box-shadow: 0 8px 18px rgba(224, 49, 49, 0.32);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	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;
}

button:hover, button:focus-visible, #goBack:hover, #goBack:focus-visible {
	outline: 3px solid rgba(97, 196, 105, 0.4);
	transform: translateY(-2px);
}

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

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

#newGame {
	background: linear-gradient(135deg, var(--green), #4ade80);
	color: #fff;
}

#voiceToggle[aria-pressed="false"], #soundToggle[aria-pressed="false"] {
	opacity: 0.55;
}

.status-card {
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 1.2rem;
	padding: 0.6rem 1rem;
}

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

#statusText.countdown {
	color: var(--green);
	animation: countdown-pulse 1s ease-in-out infinite;
}

@keyframes countdown-pulse {
	0%, 100% { transform: scale(1); opacity: 1; }
	50% { transform: scale(1.06); opacity: 0.8; }
}

.card-grid {
	--board-size: min(440px, calc(100vw - (var(--shell-pad) * 2)), calc(100dvh - var(--chrome-space)));
	display: grid;
	grid-template-columns: repeat(4, minmax(0, 1fr));
	grid-template-rows: repeat(2, 1fr);
	gap: clamp(0.5rem, 1.8vmin, 1rem);
	row-gap: 0;
	width: clamp(280px, var(--board-size), 440px);
	margin: 0 auto;
	align-self: center;
}

.memory-card {
	position: relative;
	display: grid;
	place-items: center;
	aspect-ratio: 1;
	border-radius: 1.4rem;
	cursor: pointer;
	padding: 0.6rem;
	overflow: hidden;
	perspective: 1200px;
}

.card-inner {
	position: absolute;
	inset: 0.5rem;
	border-radius: 1rem;
	transform-style: preserve-3d;
	-webkit-transform-style: preserve-3d;
	transition: transform 0.3s ease;
}

.memory-card.flipped .card-inner, .memory-card.matched .card-inner {
	transform: rotateY(180deg);
}

.card-face {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	border-radius: inherit;
	backface-visibility: hidden;
	-webkit-backface-visibility: hidden;
}

.card-back {
	background: repeating-linear-gradient(45deg, var(--green) 0 12px, #80d787 12px 24px);
	color: #fff;
	font-size: clamp(2rem, 9vw, 3.5rem);
	font-weight: 800;
}

.card-front {
	transform: rotateY(180deg);
	-webkit-transform: rotateY(180deg);
	background: #fffef0;
}

.card-front img {
	width: 78%;
	height: 78%;
	object-fit: contain;
}

.memory-card.matched {
	border-color: rgba(97, 196, 105, 0.7);
}

.memory-card.matched .card-front {
	background: #f0fff0;
}

.memory-card.celebrate {
	animation: celebrate-bounce 0.5s ease;
}

@keyframes celebrate-bounce {
	0%, 100% { transform: scale(1); }
	50% { transform: scale(1.08); }
}

#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; --chrome-space: 9rem; }
	.toolbar { padding: 0.45rem 0.6rem; border-radius: 1.1rem; }
	.eyebrow { display: none; }
	h1 { font-size: clamp(1.1rem, 5vw, 1.5rem); }
	.status-card { padding: 0.4rem 0.5rem; border-radius: 0.9rem; }
	#statusText { font-size: 0.82rem; }
	.card-grid { gap: 0.35rem; row-gap: 0; width: min(100%, calc(100dvh - var(--chrome-space))); }
	.memory-card { border-radius: 0.9rem; padding: 0.3rem; }
	.card-inner { inset: 0.25rem; border-radius: 0.65rem; }
	.card-back { font-size: clamp(1.5rem, 7vw, 2.5rem); }
}

@media (max-height: 700px) {
	:root { --chrome-space: 8.5rem; }
	.toolbar { padding: 0.4rem 0.55rem; }
	h1 { font-size: clamp(1rem, 4vw, 1.3rem); }
	.status-card { padding: 0.35rem 0.5rem; }
	#statusText { font-size: 0.78rem; }
}

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