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(8px, 3vw, 18px);
	padding: max(12px, env(safe-area-inset-top)) 64px 8px;
	pointer-events: none;
	z-index: 5;
	flex-wrap: wrap;
}
#score, #moves {
	background: rgba(18, 18, 42, 0.55);
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 999px;
	padding: 6px 16px;
	font-size: clamp(0.75rem, 2.6vw, 0.95rem);
	font-weight: 700;
	white-space: nowrap;
}
#score { color: #00e5ff; }
#moves { color: #ff2d78; }
#hud-bar span { color: #eaf0ff; }

#target-wrap {
	display: flex;
	align-items: center;
	gap: 8px;
	background: rgba(18, 18, 42, 0.55);
	border: 1px solid rgba(255, 255, 255, 0.12);
	border-radius: 999px;
	padding: 6px 14px;
}
#target-track {
	width: clamp(70px, 20vw, 140px);
	height: 7px;
	border-radius: 5px;
	background: rgba(255, 255, 255, 0.1);
	overflow: hidden;
}
#target-fill {
	height: 100%;
	width: 0%;
	background: linear-gradient(90deg, #00e5ff, #ffb64d);
	transition: width 0.25s ease;
}
#target-label {
	font-size: clamp(0.7rem, 2.4vw, 0.85rem);
	font-weight: 700;
	color: #ffb64d;
	white-space: nowrap;
}

/* ---- 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: 560px;
	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);
}

.tile {
	position: absolute;
	padding: 6%;
	transition: top 0.22s ease, left 0.22s ease, transform 0.18s ease, opacity 0.18s ease;
	cursor: pointer;
}
.tile.no-anim { transition: none; }

.tile-shape {
	width: 100%;
	height: 100%;
	clip-path: polygon(50% 2%, 98% 50%, 50% 98%, 2% 50%);
	box-shadow: 0 0 10px 1px var(--glow, rgba(0, 229, 255, 0.5));
}

.tile.selected .tile-shape {
	outline: 2px solid #ffffff;
	outline-offset: 2px;
	filter: brightness(1.25);
}
.tile.popping { transform: scale(0.15); opacity: 0; }
.tile.invalid { animation: nudge 0.3s ease; }

@keyframes nudge {
	0%, 100% { transform: translateX(0); }
	25% { transform: translateX(-8%); }
	75% { transform: translateX(8%); }
}

/* Six gem colors */
.g0 .tile-shape { background: radial-gradient(circle at 35% 30%, #7cf8ff, #00b6cc); --glow: rgba(0, 229, 255, 0.6); }
.g1 .tile-shape { background: radial-gradient(circle at 35% 30%, #ff8fc0, #d6115e); --glow: rgba(255, 45, 120, 0.6); }
.g2 .tile-shape { background: radial-gradient(circle at 35% 30%, #ffd28a, #cc7a00); --glow: rgba(255, 182, 77, 0.6); }
.g3 .tile-shape { background: radial-gradient(circle at 35% 30%, #9dffb0, #159a3c); --glow: rgba(60, 220, 100, 0.55); }
.g4 .tile-shape { background: radial-gradient(circle at 35% 30%, #d3b2ff, #7a2fd6); --glow: rgba(150, 80, 230, 0.55); }
.g5 .tile-shape { background: radial-gradient(circle at 35% 30%, #ff9a8a, #cc2a1a); --glow: rgba(255, 90, 60, 0.55); }

/* ---- 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.68rem; 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.82rem; }
}
@media (max-height: 480px) {
	#board-wrap { padding-top: 54px; }
	#hud-bar { padding-top: max(8px, env(safe-area-inset-top)); }
}
