:root {
	color-scheme: dark;
	font-family: Inter, system-ui, sans-serif;
	--ui-bg: rgba(12, 16, 24, 0.62);
	--ui-border: rgba(255, 255, 255, 0.14);
	--ui-border-strong: rgba(255, 255, 255, 0.26);
	--ui-text: #f4f7ff;
	--ui-muted: rgba(244, 247, 255, 0.78);
	--accent: #7cff7c;
	--accent-soft: rgba(124, 255, 124, 0.18);
	--danger: #ff847c;
	--shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
	--shadow-soft: 0 10px 24px rgba(0, 0, 0, 0.22);
	--overlay-glow: rgba(124, 255, 124, 0.22);
	--sky-top: #6fb7ff;
	--sky-bottom: #dff4ff;
}

* {
	box-sizing: border-box;
	-webkit-tap-highlight-color: transparent;
}

html,
body {
	margin: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
	background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
	touch-action: none;
}

body {
	font-family: Inter, system-ui, sans-serif;
	overscroll-behavior: none;
	user-select: none;
}

canvas {
	display: block;
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	z-index: 0;
}

button {
	font: inherit;
}

#game {
	position: fixed;
	inset: 0;
	overflow: hidden;
	background: linear-gradient(180deg, var(--sky-top), var(--sky-bottom));
}

#overlay {
	position: absolute;
	inset: 0;
	display: grid;
	place-items: center;
	padding: 1.25rem;
	background:
		radial-gradient(circle at 20% 20%, rgba(124, 255, 124, 0.12), transparent 28%),
		radial-gradient(circle at 80% 18%, rgba(255, 255, 255, 0.08), transparent 26%),
		linear-gradient(180deg, rgba(8, 11, 18, 0.3), rgba(8, 11, 18, 0.84));
	z-index: 30;
}

#overlay.hidden {
	display: none;
}

.overlay__panel {
	position: relative;
	overflow: hidden;
	width: min(100%, 34rem);
	display: grid;
	gap: 0.9rem;
	padding: 1.45rem 1.2rem;
	border: 1px solid var(--ui-border);
	border-radius: 1.6rem;
	background: linear-gradient(180deg, rgba(24, 30, 44, 0.84), rgba(11, 15, 23, 0.88));
	backdrop-filter: blur(14px);
	box-shadow: var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
	color: white;
	text-align: center;
}

.overlay__panel::before {
	content: "";
	position: absolute;
	inset: -20% auto auto -10%;
	width: 12rem;
	height: 12rem;
	border-radius: 50%;
	background: radial-gradient(circle, var(--overlay-glow), transparent 70%);
	pointer-events: none;
}

.overlay__panel::after {
	content: "";
	position: absolute;
	inset: auto -8% -18% auto;
	width: 13rem;
	height: 13rem;
	border-radius: 50%;
	background: radial-gradient(circle, rgba(94, 164, 255, 0.16), transparent 72%);
	pointer-events: none;
}

.overlay__eyebrow,
.overlay__stats,
.overlay__actions,
#overlay h1,
.overlay__subtitle,
#overlay ul {
	position: relative;
	z-index: 1;
}

.overlay__eyebrow {
	justify-self: center;
	padding: 0.38rem 0.7rem;
	border: 1px solid rgba(255, 255, 255, 0.16);
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.06);
	font-size: 0.76rem;
	font-weight: 700;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: rgba(255, 255, 255, 0.88);
}

#overlay h1 {
	margin: 0;
	font-size: clamp(2.1rem, 6vw, 4.4rem);
	line-height: 0.95;
	letter-spacing: -0.04em;
	text-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.overlay__subtitle {
	margin: 0;
	font-size: 0.98rem;
	color: var(--ui-muted);
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.overlay__stats {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 0.65rem;
}

.overlay__stat {
	display: grid;
	gap: 0.24rem;
	padding: 0.72rem 0.6rem;
	border: 1px solid rgba(255, 255, 255, 0.1);
	border-radius: 1rem;
	background: rgba(255, 255, 255, 0.05);
	box-shadow: var(--shadow-soft);
}

.overlay__stat strong {
	font-size: 0.92rem;
}

.overlay__stat span {
	font-size: 0.75rem;
	color: rgba(255, 255, 255, 0.74);
}

#overlay ul {
	margin: 0;
	padding: 0.85rem 0.9rem;
	list-style: none;
	display: grid;
	gap: 0.5rem;
	border: 1px solid rgba(255, 255, 255, 0.1);
	border-radius: 1rem;
	background: rgba(255, 255, 255, 0.04);
	text-align: left;
	font-size: 0.96rem;
	color: rgba(255, 255, 255, 0.92);
}

#startBtn,
.mobile-btn,
.mobile-action {
	appearance: none;
	border: 1px solid var(--ui-border-strong);
	color: var(--ui-text);
	background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.06));
	backdrop-filter: blur(10px);
	box-shadow: var(--shadow);
}

.overlay__actions {
	display: grid;
	gap: 0.5rem;
}

#startBtn {
	border-radius: 999px;
	padding: 0.95rem 1.4rem;
	font-weight: 800;
	letter-spacing: 0.01em;
	transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
	background: linear-gradient(180deg, #9cff84, #62d85b);
	color: #102010;
	border-color: rgba(255, 255, 255, 0.28);
	box-shadow: 0 14px 28px rgba(80, 180, 70, 0.26), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

#startBtn:hover,
#startBtn:focus-visible {
	transform: translateY(-1px);
	filter: brightness(1.04);
}

.overlay__hint {
	margin: 0;
	font-size: 0.78rem;
	color: rgba(255, 255, 255, 0.64);
}

#hud {
	position: absolute;
	inset: 0;
	pointer-events: none;
	z-index: 20;
}

#game>canvas {
	pointer-events: auto;
}

#crosshair {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 28px;
	height: 28px;
	transform: translate(-50%, -50%);
	z-index: 12;
	filter: drop-shadow(0 0 8px rgba(0, 0, 0, 0.8));
}

#crosshair::before,
#crosshair::after {
	content: "";
	position: absolute;
	left: 50%;
	top: 50%;
	background: #fff;
	transform: translate(-50%, -50%);
	border-radius: 999px;
}

#crosshair::before {
	width: 3px;
	height: 28px;
	box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
}

#crosshair::after {
	width: 28px;
	height: 3px;
	box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
}

#hudTop,
#mobileTopActions {
	position: absolute;
	top: env(safe-area-inset-top, 0);
	padding-top: 0.9rem;
}

#hudTop {
	left: 1rem;
	display: grid;
	gap: 0.5rem;
	color: white;
	font-weight: 700;
	text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

#health,
#saveState {
	padding: 0.5rem 0.78rem;
	border-radius: 0.85rem;
	background: linear-gradient(180deg, rgba(15, 19, 28, 0.8), rgba(15, 19, 28, 0.58));
	border: 1px solid var(--ui-border);
	backdrop-filter: blur(8px);
}

#mobileTopActions {
	right: 1rem;
	display: flex;
	gap: 0.55rem;
	pointer-events: auto;
}

.mobile-btn {
	padding: 0.72rem 0.92rem;
	border-radius: 999px;
	font-weight: 700;
	min-width: 4.3rem;
}

#hotbarWrap {
	position: absolute;
	left: 50%;
	bottom: max(1rem, env(safe-area-inset-bottom, 0px));
	transform: translateX(-50%);
	width: min(100vw - 1rem, 42rem);
	pointer-events: none;
}

#hotbar {
	display: flex;
	gap: 0.55rem;
	padding: 0.7rem;
	border-radius: 1.15rem;
	background: linear-gradient(180deg, rgba(20, 23, 31, 0.74), rgba(14, 16, 22, 0.58));
	backdrop-filter: blur(10px);
	pointer-events: auto;
	box-shadow: 0 14px 38px rgba(0, 0, 0, 0.32);
	overflow-x: auto;
	scrollbar-width: none;
}

#hotbar::-webkit-scrollbar {
	display: none;
}

.slot {
	appearance: none;
	position: relative;
	display: grid;
	justify-items: center;
	gap: 0.45rem;
	min-width: 82px;
	padding: 0.55rem 0.5rem 0.65rem;
	border: 2px solid rgba(255, 255, 255, 0.16);
	background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.06));
	color: white;
	border-radius: 0.9rem;
	font-weight: 700;
	cursor: pointer;
	transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.slot.active {
	border-color: var(--accent);
	background: linear-gradient(180deg, rgba(124, 255, 124, 0.18), rgba(255, 255, 255, 0.08));
	box-shadow: 0 0 0 2px rgba(124, 255, 124, 0.18) inset, 0 10px 24px rgba(0, 0, 0, 0.28);
}

.slotKey {
	position: absolute;
	top: 0.35rem;
	left: 0.4rem;
	padding: 0.12rem 0.34rem;
	border-radius: 999px;
	font-size: 0.72rem;
	line-height: 1;
	background: rgba(0, 0, 0, 0.4);
	color: rgba(255, 255, 255, 0.92);
}

.slotPreview {
	width: 42px;
	height: 42px;
	margin-top: 0.35rem;
	border-radius: 0.45rem;
	border: 1px solid rgba(255, 255, 255, 0.16);
	box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 4px 12px rgba(0, 0, 0, 0.22);
	background-size: cover;
	background-position: center;
}

.slotLabel {
	font-size: 0.8rem;
	letter-spacing: 0.02em;
	color: rgba(255, 255, 255, 0.94);
}

.slot--grass .slotPreview {
	background:
		linear-gradient(180deg, #78d64d 0 34%, #5baa34 34% 48%, #7a5a3a 48% 100%),
		repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.08) 0 4px, rgba(0, 0, 0, 0.08) 4px 8px);
}

.slot--dirt .slotPreview {
	background:
		radial-gradient(circle at 25% 30%, #9a7953 0 10%, transparent 11%),
		radial-gradient(circle at 70% 62%, #5b4128 0 10%, transparent 11%),
		radial-gradient(circle at 52% 24%, #7f5d3c 0 12%, transparent 13%),
		linear-gradient(135deg, #8b6845, #6a4b2f);
}

.slot--stone .slotPreview {
	background:
		radial-gradient(circle at 28% 28%, #c4c7ce 0 9%, transparent 10%),
		radial-gradient(circle at 64% 64%, #70747d 0 10%, transparent 11%),
		radial-gradient(circle at 72% 24%, #9ea3ac 0 9%, transparent 10%),
		linear-gradient(135deg, #9ba0a8, #6e727a);
}

.slot--wood .slotPreview {
	background:
		repeating-linear-gradient(0deg, rgba(91, 54, 20, 0.45) 0 3px, rgba(169, 111, 58, 0.18) 3px 6px),
		linear-gradient(135deg, #b17337, #7a4d24);
}

.slot--leaves .slotPreview {
	background:
		radial-gradient(circle at 28% 30%, #6fe27d 0 10%, transparent 11%),
		radial-gradient(circle at 68% 38%, #2f8f3a 0 13%, transparent 14%),
		radial-gradient(circle at 52% 72%, #46b853 0 12%, transparent 13%),
		linear-gradient(135deg, #3ea548, #226b2b);
}

.slot--water .slotPreview {
	background:
		linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.05)),
		repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.14) 0 5px, rgba(255, 255, 255, 0.02) 5px 10px),
		linear-gradient(135deg, #5ea4ff, #2f63c8);
}

#mobileControls {
	position: absolute;
	left: 0;
	right: 0;
	bottom: calc(6.7rem + env(safe-area-inset-bottom, 0px));
	display: flex;
	justify-content: space-between;
	align-items: flex-end;
	padding: 0 1rem;
	pointer-events: none;
	z-index: 21;
}

#joystickZone,
#mobileActions {
	pointer-events: auto;
}

#joystickZone {
	width: min(40vw, 170px);
	height: min(40vw, 170px);
	display: grid;
	place-items: center;
}

#joystickBase {
	position: relative;
	width: min(34vw, 138px);
	height: min(34vw, 138px);
	border-radius: 50%;
	background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.1), rgba(15, 18, 28, 0.38));
	border: 1px solid rgba(255, 255, 255, 0.14);
	backdrop-filter: blur(10px);
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), var(--shadow);
}

#joystickKnob {
	position: absolute;
	left: 50%;
	top: 50%;
	width: min(15vw, 62px);
	height: min(15vw, 62px);
	border-radius: 50%;
	transform: translate(-50%, -50%);
	background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.08));
	border: 1px solid rgba(255, 255, 255, 0.2);
	box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
}

#mobileActions {
	display: grid;
	gap: 0.8rem;
	justify-items: end;
}

.mobileActions__cluster {
	display: flex;
	gap: 0.75rem;
}

.mobile-action {
	min-width: 4.8rem;
	min-height: 4.8rem;
	padding: 0.9rem;
	border-radius: 1.2rem;
	font-weight: 800;
	pointer-events: auto;
}

.mobile-action--wide {
	min-width: 5.6rem;
}

#lookZone {
	position: absolute;
	right: 0;
	top: 0;
	width: 52vw;
	height: calc(100% - 7.2rem - env(safe-area-inset-bottom, 0px));
	pointer-events: auto;
	background: transparent;
	z-index: 19;
}

body:not(.is-mobile) #mobileControls,
body:not(.is-mobile) #mobileTopActions,
body:not(.is-mobile) #lookZone {
	display: none;
}

.is-mobile #crosshair {
	opacity: 0.92;
}

@media (max-width: 900px) {
	#hudTop {
		left: 0.7rem;
		padding-top: 0.7rem;
	}

	#mobileTopActions {
		right: 0.7rem;
		padding-top: 0.7rem;
	}

	#health,
	#saveState {
		font-size: 0.88rem;
		padding: 0.46rem 0.66rem;
	}

	.mobile-btn {
		padding: 0.68rem 0.84rem;
		font-size: 0.88rem;
	}

	#hotbarWrap {
		width: calc(100vw - 0.8rem);
		bottom: max(0.4rem, env(safe-area-inset-bottom, 0px));
	}

	#hotbar {
		gap: 0.42rem;
		padding: 0.5rem;
		border-radius: 1rem;
	}

	.slot {
		min-width: 68px;
		padding: 0.44rem 0.38rem 0.54rem;
	}

	.slotPreview {
		width: 34px;
		height: 34px;
	}

	.slotLabel {
		font-size: 0.7rem;
	}

	.slotKey {
		font-size: 0.65rem;
	}

	#mobileControls {
		padding: 0 0.7rem;
		bottom: calc(5.9rem + env(safe-area-inset-bottom, 0px));
	}

	.mobile-action {
		min-width: 4.2rem;
		min-height: 4.2rem;
		border-radius: 1rem;
		font-size: 0.9rem;
	}
}

@media (max-width: 560px) {
	.overlay__panel {
		padding: 1.1rem 0.95rem;
		gap: 0.75rem;
	}

	.overlay__stats {
		grid-template-columns: 1fr;
	}

	#overlay ul {
		font-size: 0.88rem;
	}

	#crosshair {
		width: 22px;
		height: 22px;
	}

	#crosshair::before {
		height: 22px;
	}

	#crosshair::after {
		width: 22px;
	}
}