:root {
	--bg-0: #eceef3;
	--bg-1: #f4f3f8;
	--card: #ffffff;
	--card-2: #ffffff;
	--card-border: #e7e5ef;
	--ink: #322b52;
	--ink-dim: #8d84ac;
	--ink-faint: #b3abcc;
	--coral: #ff6b6b;
	--coral-deep: #e2525a;
	--turquoise: #4ecdc4;
	--turquoise-deep: #2fa89f;
	--gold: #ffd166;
	--gold-deep: #f2a93a;
	--mint: #6bcf8f;
	--mint-deep: #45b06b;
	--violet: #a78bfa;
	--violet-deep: #7c5cff;
	--success: #3ddc97;
	--radius-lg: 26px;
	--radius-md: 18px;
	--radius-sm: 12px;
	--shadow-card: 0 10px 26px -12px rgba(40, 30, 80, 0.16);
	--shadow-pop: 0 5px 0 rgba(0,0,0,0.14);
	--font-display: "Fredoka", "Baloo 2", system-ui, sans-serif;
	--font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
	box-sizing: border-box;
}

html, body {
	margin: 0;
	padding: 0;
	background: var(--bg-0);
	color: var(--ink);
	height: 100%;
	font-family: var(--font-body);
	overflow-x: hidden;
}

body {
	opacity: 1;
}

button {
	font-family: inherit;
	cursor: pointer;
}

h1, h2, .level-name, .splash-title, .win-title, .world-map-logo, .world-title {
	font-family: var(--font-display);
}

/* subtle grain for depth/premium feel */
body::before {
	content: "";
	position: fixed;
	inset: 0;
	z-index: 1;
	pointer-events: none;
	opacity: 0.02;
	mix-blend-mode: multiply;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* custom scrollbar */
::-webkit-scrollbar {
	width: 8px;
	height: 8px;
}

::-webkit-scrollbar-track {
	background: transparent;
}

::-webkit-scrollbar-thumb {
	background: #d8d5e6;
	border-radius: 8px;
}

::-webkit-scrollbar-thumb:hover {
	background: var(--violet-deep);
}

* {
	scrollbar-width: thin;
	scrollbar-color: #d8d5e6 transparent;
}

/* accessible focus states */
button:focus-visible, .level-node:focus-visible {
	outline: 2px solid var(--turquoise-deep);
	outline-offset: 3px;
}

/* screen transitions */
.level-select-screen, .app-shell {
	animation: screenFade 0.35s ease;
}

@keyframes screenFade {
	from {
		opacity: 0;
		transform: translateY(8px);
	}

	to {
		opacity: 1;
		transform: translateY(0);
	}
}

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

/* ── Doodle background pattern ── */
.bg-blobs {
	position: fixed;
	inset: 0;
	z-index: 0;
	overflow: hidden;
	pointer-events: none;
	background-color: var(--bg-0);
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='340' height='340'%3E%3Cg fill='none' stroke='%23c9c5da' stroke-width='2.4' opacity='0.55'%3E%3Ccircle cx='40' cy='40' r='14'/%3E%3Ccircle cx='300' cy='70' r='7'/%3E%3Cpath d='M120 30 q10 -18 20 0 q10 18 20 0'/%3E%3Cpath d='M230 200 l12 12 l-12 12 l-12 -12 z'/%3E%3Cpath d='M60 180 q8 10 0 20 q-8 10 0 20'/%3E%3Crect x='270' y='250' width='16' height='16' rx='4' transform='rotate(15 278 258)'/%3E%3Ccircle cx='150' cy='260' r='5'/%3E%3Cpath d='M20 260 q10 -16 20 0 q10 16 20 0'/%3E%3Ccircle cx='190' cy='120' r='3'/%3E%3Cpath d='M280 140 l10 10 l-10 10 l-10 -10 z'/%3E%3C/g%3E%3C/svg%3E");
	background-size: 340px 340px;
}

.blob {
	display: none;
}

/* ── Splash screen ── */
.splash {
	position: fixed;
	inset: 0;
	z-index: 100;
	display: flex;
	align-items: center;
	justify-content: center;
	background: radial-gradient(circle at 50% 25%, #ffffff 0%, #eceef3 75%);
	transition: opacity 0.5s ease, visibility 0.5s ease;
}

.splash.hide {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
}

.splash-bg {
	position: absolute;
	inset: 0;
}

#splash-canvas {
	width: 100%;
	height: 100%;
}

.splash-center {
	position: relative;
	z-index: 2;
	text-align: center;
}

.splash-title-wrap {
	margin-bottom: 44px;
}

.splash-title {
	font-size: 58px;
	font-weight: 700;
	letter-spacing: -1px;
	color: var(--ink);
}

.splash-title span {
	color: var(--coral);
}

.splash-subtitle {
	margin-top: 8px;
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 6px;
	color: var(--ink-dim);
}

.splash-loader-wrap {
	width: 240px;
	margin: 0 auto;
}

.splash-bar-track {
	position: relative;
	height: 8px;
	border-radius: 8px;
	background: #e2dff0;
	overflow: hidden;
	box-shadow: inset 0 2px 4px rgba(0,0,0,0.06);
}

.splash-bar-fill {
	height: 100%;
	width: 0%;
	border-radius: 8px;
	background: linear-gradient(90deg, var(--coral), var(--gold), var(--turquoise));
	transition: width 0.15s ease;
}

.splash-bar-glow {
	position: absolute;
	top: 0;
	left: 0;
	height: 100%;
	width: 40px;
	background: linear-gradient(90deg, transparent, #ffffffcc, transparent);
	animation: splashGlow 1.2s linear infinite;
}

@keyframes splashGlow {
	from {
		transform: translateX(-40px);
	}

	to {
		transform: translateX(280px);
	}
}

.splash-pct {
	margin-top: 12px;
	font-size: 13px;
	font-weight: 600;
	color: var(--ink-dim);
}

/* ── World map (level select) ── */
.level-select-screen {
	position: fixed;
	inset: 0;
	z-index: 50;
	display: none;
	flex-direction: column;
	align-items: center;
	padding: 36px 0 60px;
	overflow-y: auto;
	background: var(--bg-0);
}

.level-select-screen.active {
	display: flex;
}

.world-map-header {
	text-align: center;
	margin-bottom: 20px;
	padding: 0 20px;
	position: relative;
	z-index: 2;
}

.world-map-logo {
	font-size: 32px;
	font-weight: 700;
	letter-spacing: -0.5px;
	color: var(--ink);
}

.world-map-logo span {
	color: var(--coral);
}

.world-map-tagline {
	color: var(--ink-dim);
	font-size: 13px;
	margin-top: 4px;
	font-weight: 500;
}

.world-map {
	width: 100%;
	max-width: 460px;
	padding: 0 24px;
	position: relative;
	z-index: 2;
}

.world-section {
	position: relative;
	margin-bottom: 18px;
}

.world-banner {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 12px 18px;
	border-radius: var(--radius-md);
	background: var(--card);
	border: 1px solid var(--card-border);
	box-shadow: var(--shadow-card);
	margin-bottom: 26px;
	position: relative;
	z-index: 2;
}

.world-banner-icon {
	width: 42px;
	height: 42px;
	border-radius: 12px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 20px;
	flex-shrink: 0;
	box-shadow: 0 4px 10px -3px rgba(0,0,0,0.25);
}

.world-title {
	font-size: 16px;
	font-weight: 600;
	color: var(--ink);
}

.world-sub {
	font-size: 11px;
	color: var(--ink-faint);
	margin-top: 1px;
}

.world-path-wrap {
	position: relative;
}

.world-path-svg {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	z-index: 0;
}

.level-node {
	position: absolute;
	width: 64px;
	height: 64px;
	transform: translate(-50%, -50%);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: var(--font-display);
	font-size: 20px;
	font-weight: 600;
	color: #ffffff;
	border: none;
	box-shadow: 0 5px 0 rgba(0,0,0,0.16), 0 10px 18px -8px rgba(40,30,80,0.3);
	z-index: 2;
	transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.level-node:active:not(.locked) {
	transform: translate(-50%, -46%);
	box-shadow: 0 2px 0 rgba(0,0,0,0.16), 0 6px 12px -6px rgba(40,30,80,0.3);
}

.level-node:hover:not(.locked) {
	filter: brightness(1.05);
}

.level-node.locked {
	background: #dbd7e8 !important;
	color: var(--ink-faint);
	box-shadow: 0 4px 0 rgba(0,0,0,0.08);
	opacity: 0.8;
	cursor: not-allowed;
}

.level-node.locked .lock-icon {
	font-size: 18px;
}

.level-node .ls-stars {
	position: absolute;
	bottom: -16px;
	left: 50%;
	transform: translateX(-50%);
	font-size: 9px;
	letter-spacing: 1px;
	color: var(--gold-deep);
	white-space: nowrap;
}

.level-node.current::after {
	content: "";
	position: absolute;
	inset: -6px;
	border-radius: 50%;
	border: 2px dashed rgba(255,107,107,0.6);
	animation: spin 6s linear infinite;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* ── App shell ── */
.app-shell {
	position: relative;
	z-index: 1;
	max-width: 640px;
	margin: 0 auto;
	padding: 18px 16px 30px;
	display: flex;
	flex-direction: column;
	min-height: 100vh;
}

.site-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	flex-wrap: wrap;
}

.level-name {
	font-size: 21px;
	font-weight: 600;
	color: var(--ink);
}

.level-meta {
	font-size: 12px;
	color: var(--violet-deep);
	margin-top: 2px;
	font-weight: 600;
}

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

.stat-pill {
	background: var(--card);
	border: 1px solid var(--card-border);
	border-radius: 14px;
	padding: 7px 12px;
	display: flex;
	align-items: center;
	gap: 8px;
	min-width: 68px;
	box-shadow: var(--shadow-card);
}

.stat-icon {
	font-size: 15px;
	line-height: 1;
}

.stat-text {
	display: flex;
	flex-direction: column;
}

.stat-label {
	font-size: 9px;
	text-transform: uppercase;
	letter-spacing: 1px;
	color: var(--ink-faint);
	font-weight: 700;
}

.stat-value {
	font-size: 16px;
	font-weight: 700;
	font-family: var(--font-display);
	line-height: 1.15;
	color: var(--ink);
}

.btn-sound-circle {
	width: 42px;
	height: 42px;
	border-radius: 50%;
	background: linear-gradient(160deg, var(--coral), var(--coral-deep));
	border: none;
	color: #ffffff;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 4px 0 rgba(0,0,0,0.14), 0 8px 14px -6px rgba(226,82,90,0.5);
	transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.btn-sound-circle:hover {
	transform: translateY(-1px);
}

.btn-sound-circle:active {
	transform: translateY(3px);
	box-shadow: 0 1px 0 rgba(0,0,0,0.14), 0 3px 8px -4px rgba(226,82,90,0.5);
}

.btn-sound-circle-lg {
	width: 56px;
	height: 56px;
	position: relative;
}

.hint-count {
	position: absolute;
	top: -4px;
	right: -4px;
	background: linear-gradient(135deg, var(--gold), var(--gold-deep));
	color: #ffffff;
	font-size: 10px;
	font-weight: 700;
	border-radius: 50%;
	width: 19px;
	height: 19px;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 2px 6px rgba(242,169,58,0.5);
}

/* ── Level bar ── */
.level-bar {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-top: 16px;
	overflow-x: auto;
	padding-bottom: 4px;
}

.level-bar-label {
	font-size: 11px;
	color: var(--ink-faint);
	flex-shrink: 0;
	font-weight: 700;
}

.level-btns {
	display: flex;
	gap: 6px;
}

.level-btn-chip {
	flex-shrink: 0;
	width: 32px;
	height: 32px;
	border-radius: 10px;
	border: 1px solid var(--card-border);
	background: var(--card);
	color: var(--ink-dim);
	font-size: 12px;
	font-weight: 700;
	font-family: var(--font-display);
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: var(--shadow-card);
}

.level-btn-chip.active {
	background: linear-gradient(135deg, var(--coral), var(--coral-deep));
	color: #fff;
	border-color: transparent;
	box-shadow: 0 3px 10px rgba(226,82,90,0.4);
}

/* ── Info row / progress ── */
.info-row {
	margin-top: 16px;
}

.progress-label {
	font-size: 11px;
	color: var(--ink-faint);
	margin-bottom: 6px;
	font-weight: 700;
}

.progress-track {
	height: 9px;
	border-radius: 9px;
	background: var(--card);
	overflow: hidden;
	box-shadow: inset 0 1px 3px rgba(0,0,0,0.08), var(--shadow-card);
}

.progress-bar {
	height: 100%;
	width: 0%;
	border-radius: 9px;
	background: linear-gradient(90deg, var(--coral), var(--gold), var(--turquoise));
	transition: width 0.2s ease;
}

/* ── Game area ── */
.game-area {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	margin-top: 18px;
}

.canvas-shell-outer {
	position: relative;
	width: 100%;
	max-width: 340px;
	aspect-ratio: 1;
}

.canvas-shell-outer::before {
	content: "";
	position: absolute;
	inset: -40px;
	z-index: 0;
	background: radial-gradient(ellipse 55% 45% at 8% 12%, #e0dcf180, transparent 70%),
    radial-gradient(ellipse 55% 45% at 92% 18%, #d8f1f080, transparent 70%),
    radial-gradient(ellipse 60% 50% at 22% 96%, #f1cfcf73, transparent 70%);
	filter: blur(36px);
	pointer-events: none;
}

.canvas-shell {
	position: relative;
	z-index: 1;
	width: 100%;
	height: 100%;
	background: #DFDEE9;
	border: 1px solid rgba(255,255,255,0.07);
	border-radius: 22px;
	padding: 10px;
	box-shadow: 0 26px 55px -18px rgba(20, 12, 45, 0.55),
    0 0 40px -10px #7c5cff40,
    inset 0 1px 0 rgba(255,255,255,0.05);
	touch-action: none;
}

#grid-canvas {
	width: 100%;
	height: 100%;
	display: block;
	border-radius: 18px;
}

.controls {
	display: flex;
	gap: 16px;
	margin-top: 22px;
}

.hint-text, .kb-hint {
	text-align: center;
	font-size: 12px;
	color: var(--ink-faint);
	margin: 16px 0 2px;
	font-weight: 500;
}

.kb-hint {
	display: none;
}

@media (min-width: 768px) {
	.kb-hint {
		display: block;
	}
}

/* ── Overlays ── */
.overlay {
	position: fixed;
	inset: 0;
	z-index: 200;
	display: none;
	align-items: center;
	justify-content: center;
	background: rgba(50, 43, 82, 0.35);
	backdrop-filter: blur(6px);
	padding: 20px;
}

.overlay.active {
	display: flex;
}

.confetti-canvas {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	z-index: 1;
	pointer-events: none;
}

.win-card, .howto-card {
	position: relative;
	z-index: 2;
}

.win-card, .howto-card {
	background: var(--card);
	border: 1px solid var(--card-border);
	border-radius: 26px;
	padding: 30px 26px;
	max-width: 380px;
	width: 100%;
	text-align: center;
	box-shadow: 0 30px 60px -20px rgba(40,30,80,0.35);
	animation: popIn 0.28s cubic-bezier(.2,1.4,.4,1);
}

@keyframes popIn {
	from {
		transform: scale(0.85);
		opacity: 0;
	}

	to {
		transform: scale(1);
		opacity: 1;
	}
}

.win-burst {
	font-size: 50px;
}

.win-title {
	font-size: 28px;
	font-weight: 700;
	margin: 8px 0 2px;
	color: var(--ink);
}

.win-subtitle {
	color: var(--ink-dim);
	margin-bottom: 16px;
	font-weight: 500;
}

.stars {
	font-size: 32px;
	letter-spacing: 8px;
	margin-bottom: 18px;
}

.star {
	opacity: 0.22;
	transition: opacity 0.2s ease, transform 0.2s ease;
	display: inline-block;
}

.star.lit {
	opacity: 1;
	transform: scale(1.1);
}

.win-stats {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 20px;
	margin-bottom: 22px;
}

.win-stat {
	display: flex;
	flex-direction: column;
}

.win-stat-val {
	font-size: 19px;
	font-weight: 700;
	font-family: var(--font-display);
	color: var(--ink);
}

.win-stat-lbl {
	font-size: 10px;
	color: var(--ink-faint);
	text-transform: uppercase;
	letter-spacing: 1px;
	font-weight: 700;
}

.win-stat-divider {
	width: 1px;
	height: 30px;
	background: var(--card-border);
}

.win-actions {
	display: flex;
	gap: 10px;
}

.btn {
	flex: 1;
	padding: 14px 16px;
	border-radius: 16px;
	border: 1px solid var(--card-border);
	font-weight: 700;
	font-size: 14px;
	font-family: var(--font-display);
	transition: transform 0.1s ease;
}

.btn:active {
	transform: translateY(2px);
}

.btn-ghost {
	background: var(--bg-1);
	color: var(--ink);
}

.btn-primary {
	background: linear-gradient(135deg, var(--coral), var(--coral-deep));
	color: #fff;
	border-color: transparent;
	box-shadow: 0 6px 16px -4px rgba(226,82,90,0.5);
}

/* ── How to play ── */
.howto-card {
	position: relative;
	text-align: left;
	max-width: 420px;
}

.howto-close {
	position: absolute;
	top: 14px;
	right: 14px;
	background: transparent;
	border: none;
	color: var(--ink-faint);
	font-size: 17px;
}

.howto-header {
	text-align: center;
	margin-bottom: 18px;
}

.howto-icon {
	font-size: 34px;
}

.howto-title {
	font-size: 21px;
	font-weight: 700;
	margin: 6px 0 0;
	color: var(--ink);
}

.howto-game-name {
	color: var(--ink-dim);
	font-size: 12px;
	margin-top: 2px;
	font-weight: 500;
}

.howto-section {
	margin-bottom: 18px;
}

.howto-section-label {
	font-size: 12px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 1px;
	color: var(--ink-faint);
	margin-bottom: 10px;
}

.howto-row {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-bottom: 9px;
	font-size: 13px;
}

.howto-keys {
	display: flex;
	gap: 4px;
	min-width: 70px;
	flex-shrink: 0;
	align-items: center;
}

kbd {
	background: var(--bg-1);
	border: 1px solid var(--card-border);
	border-radius: 7px;
	padding: 4px 8px;
	font-size: 11px;
	color: var(--ink);
	font-weight: 600;
}

.howto-dot {
	width: 15px;
	height: 15px;
	border-radius: 50%;
	display: inline-block;
	margin-right: 2px;
	box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.howto-fill-icon {
	font-size: 14px;
}

.howto-rules {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.howto-rule {
	font-size: 13px;
	color: var(--ink-dim);
	display: flex;
	gap: 7px;
}

.howto-rule-dot {
	color: var(--coral);
}

.howto-play-btn {
	width: 100%;
	margin-top: 8px;
	padding: 15px;
}

/* ── Responsive ── */
@media (max-width: 420px) {
	.splash-title {
		font-size: 42px;
	}

	.level-name {
		font-size: 18px;
	}

	.stat-pill {
		min-width: 48px;
		padding: 6px 10px;
	}

	.controls {
		gap: 12px;
	}

	.level-node {
		width: 56px;
		height: 56px;
		font-size: 17px;
	}
}