:root {
	--bg: #08090b;
	--panel: #111417;
	--line: #34383a;
	--text: #f7f5ff;
	--muted: #d8d5c5;
	--gold: #ffd869;
	--gold-dark: #7b4d12;
	color-scheme: dark;
}

html, body {
	margin: 0;
	width: 100%;
	height: 100%;
	height: 100dvh;
	overflow: hidden;
	overscroll-behavior: none;
	background: var(--bg);
	color: var(--text);
	font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	-webkit-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
	-webkit-tap-highlight-color: transparent;
}

#stage {
	position: fixed;
	top: env(safe-area-inset-top, 0px);
	right: env(safe-area-inset-right, 0px);
	bottom: env(safe-area-inset-bottom, 0px);
	left: env(safe-area-inset-left, 0px);
	display: grid;
	place-content: center;
	place-items: center;
	overflow: hidden;
}

/* The HD (WebGL2) canvas shares #game's grid cell under it; #game stays the input surface. */
#game, #game_gl {
	grid-area: 1 / 1;
	display: block;
	image-rendering: pixelated;
}

#game {
	z-index: 1;
	outline: none;
	touch-action: none;
}

#game_gl {
	background: #000;
	pointer-events: none;
}

#game_gl[hidden] {
	display: none;
}

#keyboard {
	position: fixed;
	left: 0;
	bottom: 0;
	width: 1px;
	height: 1px;
	padding: 0;
	border: 0;
	opacity: 0;
	font-size: 16px;
	pointer-events: none;
}

#loading {
	position: fixed;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: radial-gradient(ellipse at center, #15191c 0%, var(--bg) 70%);
	z-index: 10;
	transition: opacity 0.4s ease;
}

#loading.done {
	opacity: 0;
	pointer-events: none;
}

#loading .panel {
	width: min(360px, calc(100vw - 48px));
	padding: 28px 24px 22px;
	text-align: center;
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 10px;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

#loading .logo {
	display: block;
	margin: 0 auto 8px;
}

#loading h1 {
	margin: 0 0 18px;
	color: var(--gold);
	font: 600 26px/1.2 Georgia, "Times New Roman", serif;
	letter-spacing: 0.12em;
	text-transform: uppercase;
}

#loading .bar {
	height: 10px;
	overflow: hidden;
	background: #0b0d0f;
	border: 1px solid var(--line);
	border-radius: 5px;
}

#loading .fill {
	width: 0;
	height: 100%;
	background: linear-gradient(90deg, var(--gold-dark), var(--gold));
	transition: width 0.15s linear;
}

#loading .fill.indeterminate {
	width: 30%;
	animation: slide 1.2s ease-in-out infinite;
}

@keyframes slide {
	from { transform: translateX(-100%); }
	to { transform: translateX(340%); }
}

#loading p {
	min-height: 1.4em;
	margin: 12px 0 0;
	color: var(--muted);
}

#loading .actions {
	display: flex;
	flex-direction: column;
	gap: 10px;
	align-items: center;
	margin-top: 16px;
}

#loading button {
	padding: 8px 22px;
	color: var(--bg);
	background: var(--gold);
	border: 0;
	border-radius: 6px;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
}

#loading a {
	color: var(--gold);
}

#toolbar {
	position: fixed;
	top: calc(env(safe-area-inset-top, 0px) + 6px);
	left: calc(env(safe-area-inset-left, 0px) + 6px);
	display: flex;
	gap: 6px;
	z-index: 5;
	opacity: 0.35;
	transition: opacity 0.2s;
}

#toolbar:hover, #toolbar:focus-within {
	opacity: 1;
}

/* The canvas reaches the top left corner: only a handle shows until the toolbar is hovered or tapped. */
#toolbar.tuck {
	top: 0;
	padding: calc(env(safe-area-inset-top, 0px) + 6px) 6px 10px;
	background: rgba(8, 9, 11, 0.85);
	border: 1px solid var(--line);
	border-top: 0;
	border-radius: 0 0 8px 8px;
	opacity: 1;
	transform: translateY(calc(-100% + 6px));
	transition: transform 0.2s ease;
}

#toolbar.tuck::after {
	content: "";
	position: absolute;
	left: 50%;
	bottom: 2px;
	width: 24px;
	height: 2px;
	margin-left: -12px;
	border-radius: 1px;
	background: var(--gold);
	opacity: 0.7;
}

#toolbar.tuck.open, #toolbar.tuck:focus-within {
	transform: none;
}

@media (hover: hover) {
	#toolbar.tuck:hover {
		transform: none;
	}
}

@media (hover: none) {
	#toolbar.tuck:not(.open) button {
		pointer-events: none;
	}
}

#toolbar button {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 30px;
	height: 30px;
	padding: 0;
	color: var(--gold);
	background: rgba(8, 9, 11, 0.75);
	border: 1px solid var(--line);
	border-radius: 6px;
	cursor: pointer;
}

#toolbar button[hidden] {
	display: none;
}

#toolbar button svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
}

#toolbar button img {
	max-width: 20px;
	max-height: 20px;
}

#toolbar button.active {
	border-color: var(--gold);
}

#btn-keyboard {
	display: none !important;
}

#rotate {
	display: none;
	position: fixed;
	left: 50%;
	bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
	transform: translateX(-50%);
	padding: 6px 12px;
	color: var(--text);
	background: rgba(8, 9, 11, 0.85);
	border: 1px solid var(--gold-dark);
	border-radius: 6px;
	z-index: 6;
	pointer-events: none;
	white-space: nowrap;
}

@media (pointer: coarse) {
	#btn-keyboard {
		display: flex !important;
	}

	#toolbar:not(.tuck) {
		opacity: 0.7;
	}

	#toolbar button {
		width: 38px;
		height: 38px;
	}
}

@media (pointer: coarse) and (orientation: portrait) {
	#rotate {
		display: block;
	}
}
