/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
	width: 100%;
	height: 100%;
	overflow: hidden;
	overscroll-behavior: none;
	-webkit-user-select: none;
	user-select: none;
	touch-action: manipulation;
	font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body {
	background: linear-gradient(180deg, #87CEEB 0%, #90EE90 50%, #228B22 100%);
	background-attachment: fixed;
	display: flex;
	justify-content: center;
	align-items: center;
}

#game-container {
	position: relative;
	width: 100%;
	max-width: 500px;
	height: 100dvh;
	overflow: hidden;
}

/* === Screens === */
.screen {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	opacity: 0;
	pointer-events: none;
	transition: opacity 0.3s ease;
}
.screen.active {
	opacity: 1;
	pointer-events: auto;
}

/* === Menu Screen === */
#screen-menu {
	gap: 16px;
	padding: 20px;
}
#screen-menu h1 {
	color: #fff;
	font-size: 2rem;
	text-align: center;
	text-shadow: 2px 2px 0 #2d5a1e, 0 0 20px rgba(0,0,0,0.3);
	line-height: 1.2;
}
.menu-gnome {
	width: 120px;
	height: 150px;
	animation: menu-bob 2s ease-in-out infinite;
}
@keyframes menu-bob {
	0%, 100% { transform: translateY(0); }
	50% { transform: translateY(-10px); }
}
.menu-info {
	color: #fff;
	font-size: 1.1rem;
	text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
}
.btn-play {
	background: #4CAF50;
	color: #fff;
	border: none;
	border-radius: 50px;
	padding: 18px 60px;
	font-size: 1.6rem;
	font-weight: bold;
	cursor: pointer;
	letter-spacing: 2px;
	box-shadow: 0 4px 15px rgba(0,0,0,0.3), inset 0 -3px 0 rgba(0,0,0,0.2);
	animation: pulse-btn 2s ease-in-out infinite;
	transition: transform 0.1s;
}
.btn-play:active {
	transform: scale(0.95);
	animation: none;
}
@keyframes pulse-btn {
	0%, 100% { transform: scale(1); }
	50% { transform: scale(1.05); }
}
.btn-sound {
	position: absolute;
	bottom: 20px;
	right: 20px;
	background: rgba(255,255,255,0.2);
	border: none;
	border-radius: 50%;
	width: 48px;
	height: 48px;
	font-size: 1.4rem;
	cursor: pointer;
	backdrop-filter: blur(4px);
}
.btn-sound.muted { opacity: 0.5; }
.btn-reset {
	position: absolute;
	bottom: 20px;
	left: 20px;
	background: none;
	border: none;
	color: rgba(255,255,255,0.3);
	font-size: 0.7rem;
	cursor: pointer;
	font-family: inherit;
}
.btn-reset:hover { color: rgba(255,255,255,0.6); }
.game-version {
	position: absolute;
	bottom: 22px;
	left: 50%;
	transform: translateX(-50%);
	color: rgba(255,255,255,0.25);
	font-size: 0.6rem;
	pointer-events: none;
}
.achievement-row {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
	justify-content: center;
	max-width: 300px;
	margin: 0 auto;
}
.achievement-badge {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 0.9rem;
	color: #fff;
	box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* === Name Screen === */
#screen-name {
	gap: 20px;
	padding: 20px;
}
#screen-name h2 {
	color: #fff;
	font-size: 1.8rem;
	text-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}
#name-input {
	width: 80%;
	max-width: 300px;
	padding: 14px 20px;
	font-size: 1.3rem;
	border: 3px solid rgba(255,255,255,0.4);
	border-radius: 30px;
	background: rgba(255,255,255,0.9);
	color: #333;
	text-align: center;
	outline: none;
	font-family: inherit;
}
#name-input:focus {
	border-color: #4CAF50;
	box-shadow: 0 0 15px rgba(76,175,80,0.4);
}
#name-input::placeholder {
	color: #aaa;
}
#btn-start:disabled {
	opacity: 0.4;
	cursor: not-allowed;
	animation: none;
}

/* === Highscore Link === */
.link-highscore {
	background: none;
	border: none;
	color: #FFD700;
	font-size: 1rem;
	text-decoration: none;
	text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
	padding: 8px 16px;
	border-bottom: 1px solid rgba(255,215,0,0.4);
	cursor: pointer;
	font-family: inherit;
}
.link-highscore:hover {
	color: #fff;
}
.menu-link-highscore {
	background: rgba(255,255,255,0.15);
	border: 2px solid rgba(255,255,255,0.3);
	border-radius: 30px;
	color: #fff;
	font-size: 1.1rem;
	font-weight: bold;
	letter-spacing: 1px;
	padding: 12px 40px;
	text-decoration: none;
	text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
	cursor: pointer;
	font-family: inherit;
	backdrop-filter: blur(4px);
	transition: background 0.2s, transform 0.1s;
}
.menu-link-highscore:hover {
	background: rgba(255,255,255,0.25);
	color: #fff;
}
.menu-link-highscore:active {
	transform: scale(0.95);
}

/* === Highscore Modal === */
#screen-highscore {
	gap: 12px;
	padding: 20px;
	background: rgba(0,0,0,0.6);
	backdrop-filter: blur(8px);
	overflow-y: auto;
	justify-content: flex-start;
	padding-top: 40px;
}
#screen-highscore h2 {
	color: #fff;
	font-size: 1.8rem;
	text-shadow: 2px 2px 0 rgba(0,0,0,0.3);
	flex-shrink: 0;
}
.hs-tabs {
	display: flex;
	gap: 4px;
	background: rgba(0,0,0,0.2);
	border-radius: 10px;
	padding: 4px;
	width: 100%;
	max-width: 400px;
	flex-shrink: 0;
}
.hs-tab {
	flex: 1;
	background: transparent;
	border: none;
	color: rgba(255,255,255,0.5);
	padding: 8px 4px;
	font-size: 0.85rem;
	font-weight: bold;
	border-radius: 8px;
	cursor: pointer;
	font-family: inherit;
	transition: background 0.2s, color 0.2s;
}
.hs-tab.active {
	background: rgba(255,255,255,0.2);
	color: #fff;
}
.hs-tab:hover { color: #fff; }
#hs-scores {
	width: 100%;
	max-width: 400px;
	flex-shrink: 0;
}
#hs-scores table {
	width: 100%;
	border-collapse: collapse;
	background: rgba(0,0,0,0.3);
	border-radius: 12px;
	overflow: hidden;
}
#hs-scores th {
	background: rgba(0,0,0,0.3);
	padding: 8px 6px;
	font-size: 0.7rem;
	text-transform: uppercase;
	letter-spacing: 1px;
	color: #FFD700;
	text-align: left;
}
#hs-scores th:first-child { text-align: center; width: 30px; }
#hs-scores th:nth-child(3), #hs-scores th:nth-child(4) { text-align: center; }
#hs-scores td {
	padding: 8px 6px;
	font-size: 0.85rem;
	border-top: 1px solid rgba(255,255,255,0.1);
	color: #fff;
}
#hs-scores td:first-child { text-align: center; font-weight: bold; color: #ccc; }
#hs-scores td:nth-child(3), #hs-scores td:nth-child(4) { text-align: center; }
#hs-scores tr:nth-child(1) td:first-child { color: #FFD700; }
#hs-scores tr:nth-child(2) td:first-child { color: #C0C0C0; }
#hs-scores tr:nth-child(3) td:first-child { color: #CD7F32; }
.hs-score-val { font-weight: bold; color: #FFD700; }
#hs-scores th:nth-child(5), #hs-scores td:nth-child(5) { text-align: center; }
.hs-games { color: rgba(255,255,255,0.35); font-size: 0.75rem; }
.hs-empty {
	text-align: center;
	padding: 30px 20px;
	color: rgba(255,255,255,0.5);
	font-size: 0.95rem;
}
.hs-total {
	font-size: 0.8rem;
	color: rgba(255,255,255,0.4);
	flex-shrink: 0;
}

/* === HUD === */
#hud {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 10px 16px;
	background: rgba(0,0,0,0.5);
	backdrop-filter: blur(4px);
	z-index: 10;
	color: #fff;
	font-weight: bold;
}
#btn-home {
	background: rgba(255,255,255,0.15);
	border: none;
	border-radius: 50%;
	width: 30px;
	height: 30px;
	font-size: 1rem;
	color: rgba(255,255,255,0.7);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	-webkit-tap-highlight-color: transparent;
}
#btn-home:active { background: rgba(255,255,255,0.3); }
#hud-level {
	font-size: 0.9rem;
	color: #90EE90;
}
#hud-score {
	font-size: 1.4rem;
	transition: transform 0.1s;
}
#hud-score.bump {
	transform: scale(1.3);
}
#hud-timer {
	font-size: 1rem;
	min-width: 45px;
	text-align: right;
}
#hud-timer.urgent {
	color: #ff4444;
	animation: timer-pulse 0.5s ease-in-out infinite;
}
@keyframes timer-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.5; }
}
#hud-combo {
	position: absolute;
	top: 48px;
	left: 0;
	right: 0;
	text-align: center;
	z-index: 10;
	color: #FFD700;
	font-weight: bold;
	font-size: 1.1rem;
	text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
	transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#combo-multiplier {
	font-size: 1.3rem;
	margin-right: 8px;
}
#hud-powerup {
	position: absolute;
	top: 78px;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 8px;
	z-index: 10;
	background: rgba(0,0,0,0.4);
	padding: 4px 12px;
	border-radius: 20px;
}
#powerup-icon { font-size: 1.2rem; }
#powerup-bar {
	width: 80px;
	height: 6px;
	background: rgba(255,255,255,0.2);
	border-radius: 3px;
	overflow: hidden;
}
#powerup-bar-fill {
	height: 100%;
	background: #FFD700;
	border-radius: 3px;
	transition: width 0.1s linear;
}

/* === Level Flash === */
#level-flash {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 20;
	font-size: 3rem;
	font-weight: bold;
	color: #fff;
	text-shadow: 0 0 30px rgba(255,215,0,0.8), 2px 2px 0 rgba(0,0,0,0.3);
	background: rgba(0,0,0,0.3);
	animation: level-pop 0.8s ease-out forwards;
	pointer-events: none;
}
@keyframes level-pop {
	0% { transform: scale(0.3); opacity: 0; }
	40% { transform: scale(1.2); opacity: 1; }
	100% { transform: scale(1); opacity: 0; }
}

/* === Game Grid === */
#game-grid {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 8px;
	width: 95%;
	max-width: 450px;
	padding: 0 10px;
	margin-top: 50px;
}
.hole {
	position: relative;
	aspect-ratio: 1 / 0.85;
	cursor: pointer;
}
.dirt {
	position: absolute;
	bottom: 0;
	left: 5%;
	width: 90%;
	height: 40%;
	background: radial-gradient(ellipse at center, #8B6914 0%, #6B4F12 60%, #5A3E0E 100%);
	border-radius: 50% 50% 45% 45% / 60% 60% 40% 40%;
	z-index: 3;
	box-shadow: 0 3px 8px rgba(0,0,0,0.3);
}
.dirt::after {
	content: '';
	position: absolute;
	top: 2px;
	left: 10%;
	width: 80%;
	height: 30%;
	background: radial-gradient(ellipse, rgba(255,255,255,0.15) 0%, transparent 70%);
	border-radius: 50%;
}
.gnome-container {
	position: absolute;
	bottom: 0;
	left: 5%;
	width: 90%;
	height: 100%;
	overflow: visible;
	z-index: 4;
	display: flex;
	align-items: flex-end;
	justify-content: center;
	clip-path: inset(-100% 0 38% 0);
}
.gnome {
	transform: translateY(100%);
	transition: none;
	cursor: pointer;
	width: 65%;
	height: auto;
}
.gnome.gnome-up {
	animation: gnome-pop-up 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.gnome.gnome-down {
	animation: gnome-pop-down 0.2s ease-in forwards;
}
.gnome.gnome-hit {
	animation: gnome-squish 0.3s ease-out forwards;
}
@keyframes gnome-pop-up {
	0% { transform: translateY(100%); }
	100% { transform: translateY(-30%); }
}
@keyframes gnome-pop-down {
	0% { transform: translateY(-30%); }
	100% { transform: translateY(100%); }
}
@keyframes gnome-squish {
	0% { transform: translateY(-30%) scaleY(1); filter: brightness(1); }
	30% { transform: translateY(-30%) scaleY(0.6); filter: brightness(3); }
	100% { transform: translateY(100%) scaleY(0.8); filter: brightness(1); }
}

/* Fast gnome wobble */
.gnome.gnome-fast.gnome-up {
	animation: gnome-pop-up-fast 0.15s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes gnome-pop-up-fast {
	0% { transform: translateY(100%) rotate(-5deg); }
	100% { transform: translateY(-30%) rotate(0deg); }
}

/* Gold gnome shimmer */
.gnome.gnome-gold.gnome-up {
	animation: gnome-pop-up 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
	filter: drop-shadow(0 0 8px rgba(255,215,0,0.6));
}

/* Poop splat */
.gnome.gnome-poop.gnome-up {
	animation: gnome-pop-up 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.gnome.gnome-poop.gnome-hit {
	animation: gnome-poop-splat 0.3s ease-out forwards;
}
@keyframes gnome-poop-splat {
	0% { transform: translateY(-30%) scaleY(1) scaleX(1); }
	30% { transform: translateY(-30%) scaleY(0.4) scaleX(1.4); }
	100% { transform: translateY(100%) scaleY(0.3) scaleX(1.2); opacity: 0.4; }
}

/* === Score Float === */
.score-float {
	position: absolute;
	z-index: 30;
	font-weight: bold;
	font-size: 1.3rem;
	color: #FFD700;
	text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
	pointer-events: none;
	animation: float-up 0.7s ease-out forwards;
}
.score-float.miss {
	color: #ff4444;
	font-size: 1rem;
}
@keyframes float-up {
	0% { opacity: 1; transform: translateY(0) scale(1); }
	100% { opacity: 0; transform: translateY(-60px) scale(1.3); }
}

/* === Screen Shake === */
@keyframes shake-small {
	0%, 100% { transform: translateX(0); }
	25% { transform: translateX(-2px); }
	75% { transform: translateX(2px); }
}
@keyframes shake-medium {
	0%, 100% { transform: translateX(0); }
	25% { transform: translateX(-4px); }
	75% { transform: translateX(4px); }
}
@keyframes shake-large {
	0%, 100% { transform: translateX(0); }
	20% { transform: translateX(-5px); }
	40% { transform: translateX(5px); }
	60% { transform: translateX(-3px); }
	80% { transform: translateX(3px); }
}
#game-container.shake-small { animation: shake-small 0.1s ease; }
#game-container.shake-medium { animation: shake-medium 0.15s ease; }
#game-container.shake-large { animation: shake-large 0.2s ease; }

/* === New Record Badge === */
#new-record-badge {
	position: absolute;
	top: 100px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 15;
	background: linear-gradient(135deg, #FFD700, #FFA500);
	color: #fff;
	font-weight: bold;
	font-size: 1rem;
	padding: 6px 16px;
	border-radius: 20px;
	text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
	box-shadow: 0 2px 10px rgba(255,165,0,0.5);
	animation: record-pulse 1s ease-in-out infinite;
}
@keyframes record-pulse {
	0%, 100% { transform: translateX(-50%) scale(1); }
	50% { transform: translateX(-50%) scale(1.08); }
}

/* === Milestone Pop === */
.milestone-pop {
	position: absolute;
	top: 40%;
	left: 50%;
	transform: translate(-50%, -50%);
	z-index: 25;
	font-size: 3rem;
	font-weight: bold;
	color: #fff;
	text-shadow: 0 0 20px rgba(255,215,0,0.8);
	pointer-events: none;
	animation: milestone-anim 0.8s ease-out forwards;
}
@keyframes milestone-anim {
	0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
	30% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
	100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* === Particles === */
#particles-container {
	position: fixed;
	inset: 0;
	pointer-events: none;
	z-index: 100;
	overflow: hidden;
}
.particle {
	position: absolute;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	pointer-events: none;
	animation: particle-burst 0.5s ease-out forwards;
}
@keyframes particle-burst {
	0% { opacity: 1; transform: translate(0, 0) scale(1); }
	100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}
.confetti {
	position: absolute;
	width: 8px;
	height: 12px;
	pointer-events: none;
	animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
	0% { opacity: 1; transform: translateY(-20px) rotate(0deg); }
	100% { opacity: 0; transform: translateY(100vh) rotate(720deg); }
}

/* === Game Over Screen === */
#screen-gameover {
	gap: 12px;
	padding: 20px;
	background: rgba(0,0,0,0.6);
	backdrop-filter: blur(8px);
}
#screen-gameover h2 {
	color: #fff;
	font-size: 2rem;
	text-shadow: 2px 2px 0 rgba(0,0,0,0.3);
}
#final-score-display {
	text-align: center;
}
#final-score {
	font-size: 4rem;
	font-weight: bold;
	color: #FFD700;
	text-shadow: 0 0 20px rgba(255,215,0,0.5);
}
.final-label {
	color: #ccc;
	font-size: 1rem;
	letter-spacing: 3px;
}
#final-highscore {
	color: #FFD700;
	font-size: 1.4rem;
	font-weight: bold;
	text-align: center;
	width: 100%;
	text-shadow: 1px 1px 0 rgba(0,0,0,0.4), 0 0 10px rgba(255,215,0,0.3);
}
#final-highscore.new-record {
	color: #FFD700;
	font-size: 1.4rem;
	font-weight: bold;
	animation: new-record-pulse 1s ease-in-out infinite;
	text-shadow: 0 0 15px rgba(255,215,0,0.5);
}
@keyframes new-record-pulse {
	0%, 100% { transform: scale(1); }
	50% { transform: scale(1.08); }
}
#final-stats {
	color: #ccc;
	font-size: 0.95rem;
	line-height: 1.8;
	text-align: center;
}
.close-text {
	color: #ff9944;
	font-size: 1.2rem;
	font-weight: bold;
	animation: pulse-btn 1.5s ease-in-out infinite;
}

/* === Achievement Toast === */
.achievement-toast {
	position: fixed;
	top: -60px;
	right: 16px;
	background: rgba(0,0,0,0.85);
	color: #fff;
	padding: 10px 16px;
	border-radius: 12px;
	display: flex;
	align-items: center;
	gap: 10px;
	font-size: 0.85rem;
	z-index: 50;
	animation: toast-slide 2.5s ease forwards;
	backdrop-filter: blur(4px);
}
@keyframes toast-slide {
	0% { top: -60px; }
	15% { top: 16px; }
	85% { top: 16px; }
	100% { top: -60px; }
}

/* === Menu Highscore Big === */
.menu-hs-big {
	font-size: 1.4rem;
	font-weight: bold;
	color: #FFD700;
	text-shadow: 1px 1px 0 rgba(0,0,0,0.4), 0 0 10px rgba(255,215,0,0.3);
}
.menu-best-today {
	font-size: 0.95rem;
	color: rgba(255,255,255,0.85);
	text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
}
.menu-best-today strong {
	color: #fff;
}

/* === Highscore Player Highlight === */
#hs-scores tr.hs-me td {
	background: rgba(76,175,80,0.2);
}
#hs-scores tr.hs-me td:nth-child(2) {
	font-weight: bold;
	color: #90EE90;
}

/* === Power-up tints === */
#screen-playing.tint-freeze { background: rgba(100,150,255,0.1); }
#screen-playing.tint-double { background: rgba(255,215,0,0.1); }
#screen-playing.tint-slow { background: rgba(150,100,255,0.1); }
#screen-playing.tint-shield { background: rgba(100,255,100,0.1); }

/* === Responsive === */
@media (max-height: 600px) {
	#game-grid { gap: 4px; margin-top: 40px; }
	#screen-menu h1 { font-size: 1.5rem; }
	.menu-gnome { width: 80px; height: 100px; }
	.btn-play { padding: 14px 40px; font-size: 1.3rem; }
}
@media (min-width: 768px) {
	#game-grid { max-width: 420px; margin-left: auto; margin-right: auto; }
}
@media (min-width: 1024px) {
	.hole { cursor: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32"><text y="28" font-size="28">🔨</text></svg>') 16 16, pointer; }
}
