html, body {
	margin: 0;
	padding: 0;
	height: 100%;
	overflow: hidden;
	background: #06060c;
	background-image:
		radial-gradient(ellipse at 15% 0%, rgba(0, 229, 255, 0.08), transparent 55%),
		radial-gradient(ellipse at 90% 100%, rgba(255, 45, 120, 0.08), transparent 55%);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	color: #eaf0ff;
	touch-action: manipulation;
	-webkit-user-select: none;
	user-select: none;
}
* { box-sizing: border-box; }
.hidden { display: none !important; }

/* ---- Persistent mute control ---- */
#sound-toggle {
	position: fixed;
	top: max(14px, env(safe-area-inset-top));
	right: max(14px, env(safe-area-inset-right));
	pointer-events: auto;
	cursor: pointer;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: rgba(18, 18, 42, 0.6);
	border: 1px solid rgba(255, 255, 255, 0.14);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 17px;
	z-index: 20;
	color: #00e5ff;
	box-shadow: 0 0 14px rgba(0, 229, 255, 0.25);
}
#sound-toggle.muted { color: #92a0c9; box-shadow: none; }

/* ---- HUD ---- */
#hud-bar {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: clamp(6px, 2.6vw, 16px);
	padding: max(12px, env(safe-area-inset-top)) 64px 8px;
	pointer-events: none;
	z-index: 5;
	flex-wrap: wrap;
}
#score, #goal, #best-hud {
	background: rgba(18, 18, 42, 0.55);
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 999px;
	padding: 6px 14px;
	font-size: clamp(0.7rem, 2.4vw, 0.9rem);
	font-weight: 700;
	white-space: nowrap;
}
#score { color: #00e5ff; }
#goal { color: #ffb64d; }
#best-hud { color: #ff2d78; }
#hud-bar span { color: #eaf0ff; }

/* ---- Board ---- */
#board-wrap {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	padding:
		calc(64px + env(safe-area-inset-top))
		max(10px, env(safe-area-inset-right))
		max(10px, env(safe-area-inset-bottom))
		max(10px, env(safe-area-inset-left));
	touch-action: none;
}

#board {
	position: relative;
	width: min(94vw, calc((100vh - 150px) * 1));
	max-width: 480px;
	aspect-ratio: 1 / 1;
	background: rgba(12, 12, 26, 0.5);
	border: 1px solid rgba(255, 255, 255, 0.08);
	border-radius: 14px;
	box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.4);
}

.cell-slot {
	position: absolute;
	padding: 5%;
}
.cell-slot::after {
	content: "";
	display: block;
	width: 100%;
	height: 100%;
	border-radius: 20%;
	background: rgba(255, 255, 255, 0.04);
}

.tile {
	position: absolute;
	padding: 5%;
	transition: top 0.16s ease, left 0.16s ease;
}
.tile.no-anim { transition: none; }

.tile-shape {
	width: 100%;
	height: 100%;
	border-radius: 20%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 800;
	color: #06060c;
	text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
	box-shadow: 0 0 14px 1px var(--glow, rgba(0, 229, 255, 0.45));
	transition: transform 0.14s ease;
}
.tile.spawn .tile-shape { animation: pop-in 0.18s ease; }
.tile.merged .tile-shape { animation: pop 0.2s ease; }

@keyframes pop-in {
	from { transform: scale(0.3); opacity: 0.3; }
	to { transform: scale(1); opacity: 1; }
}
@keyframes pop {
	0% { transform: scale(1); }
	45% { transform: scale(1.18); }
	100% { transform: scale(1); }
}

.tile-shape.len1 { font-size: clamp(1.1rem, 6vw, 2rem); }
.tile-shape.len2 { font-size: clamp(1rem, 5.4vw, 1.8rem); }
.tile-shape.len3 { font-size: clamp(0.82rem, 4.6vw, 1.5rem); }
.tile-shape.len4 { font-size: clamp(0.68rem, 3.8vw, 1.25rem); }

.v2    { background: linear-gradient(155deg, #dff8ff, #7cf8ff); --glow: rgba(0, 229, 255, 0.35); }
.v4    { background: linear-gradient(155deg, #bdeaff, #45d6ff); --glow: rgba(0, 229, 255, 0.4); }
.v8    { background: linear-gradient(155deg, #9be2ff, #00c2e6); --glow: rgba(0, 229, 255, 0.45); color: #06060c; }
.v16   { background: linear-gradient(155deg, #ffe2a8, #ffb64d); --glow: rgba(255, 182, 77, 0.5); }
.v32   { background: linear-gradient(155deg, #ffc98a, #ff9838); --glow: rgba(255, 152, 56, 0.55); }
.v64   { background: linear-gradient(155deg, #ffab8a, #ff5f2d); --glow: rgba(255, 95, 45, 0.55); color: #fff; }
.v128  { background: linear-gradient(155deg, #ffa4c6, #ff5c9b); --glow: rgba(255, 92, 155, 0.55); color: #fff; }
.v256  { background: linear-gradient(155deg, #ff8fc0, #ff2d78); --glow: rgba(255, 45, 120, 0.6); color: #fff; }
.v512  { background: linear-gradient(155deg, #e2b6ff, #b25bff); --glow: rgba(178, 91, 255, 0.6); color: #fff; }
.v1024 { background: linear-gradient(155deg, #c79bff, #8a2be2); --glow: rgba(138, 43, 226, 0.65); color: #fff; }
.v2048 { background: linear-gradient(155deg, #fff3b0, #ffd23f); --glow: rgba(255, 210, 63, 0.75); color: #4a3400; }

/* ---- Overlays ---- */
.overlay {
	position: fixed;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
	text-align: center;
	background: radial-gradient(circle at 50% 40%, rgba(18, 18, 42, 0.9), rgba(6, 6, 12, 0.97));
	padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
	z-index: 10;
	overflow-y: auto;
}
.overlay h1 {
	margin: 0 0 4px;
	font-size: clamp(1.7rem, 7vw, 2.3rem);
	font-weight: 800;
	letter-spacing: -0.02em;
	background: linear-gradient(90deg, #00e5ff, #7cf8ff 40%, #ff2d78);
	-webkit-background-clip: text;
	background-clip: text;
	color: transparent;
}
.overlay p {
	margin: 0;
	color: #c7c8d1;
	max-width: 380px;
	font-size: 0.95rem;
}

#difficulty-picker {
	display: flex;
	gap: 10px;
	margin-top: 12px;
	flex-wrap: wrap;
	justify-content: center;
}
.diff-btn {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 2px;
	background: rgba(18, 18, 42, 0.6);
	border: 1px solid rgba(255, 255, 255, 0.14);
	color: #eaf0ff;
	border-radius: 12px;
	padding: 10px 16px;
	font-size: 0.92rem;
	font-weight: 700;
	cursor: pointer;
}
.diff-btn span { font-size: 0.66rem; font-weight: 500; color: #92a0c9; }
.diff-btn.selected {
	border-color: #00e5ff;
	box-shadow: 0 0 16px rgba(0, 229, 255, 0.3);
	color: #00e5ff;
}
.diff-btn.selected span { color: #7cf8ff; }

.score-line { font-size: 1.15rem; color: #fff; font-weight: 700; }
.score-line.sub { font-size: 0.9rem; color: #c7c8d1; font-weight: 500; }
.score-line.best { font-size: 0.85rem; color: #9a9ba7; font-weight: 500; }

.btn {
	margin-top: 10px;
	background: linear-gradient(90deg, #00e5ff, #7cf8ff);
	color: #06060c;
	border: none;
	border-radius: 999px;
	padding: 14px 36px;
	font-size: 1rem;
	font-weight: 800;
	letter-spacing: 0.02em;
	cursor: pointer;
	box-shadow: 0 0 24px rgba(0, 229, 255, 0.35);
	transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 0 32px rgba(0, 229, 255, 0.5); }
.btn:active { transform: translateY(0) scale(0.98); }

@media (max-width: 380px) {
	.overlay p { font-size: 0.86rem; }
	.diff-btn { padding: 8px 12px; font-size: 0.8rem; }
}
@media (max-height: 480px) {
	#board-wrap { padding-top: 54px; }
	#hud-bar { padding-top: max(8px, env(safe-area-inset-top)); }
}
