* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

html, body {
	width: 100%;
	height: 100%;
	overflow: hidden;
	background-color: #07111c;
	touch-action: manipulation;
}

/* Font1, Font2 and Font4 (the game text) are built from the ROM and registered by js/rom-play.js; no font file ships. */

/* Title and registration text: a system face, so no font file ships (the previous face was a commercial typeface). */
@font-face {
	font-family: 'Font3';
	src: local('Segoe UI'), local('Helvetica Neue'), local('Noto Sans'), local('Liberation Sans'), local('DejaVu Sans'), local('Arial');
}

#canvasContainer {
	position: fixed;
	left: 50%;
	top: 50%;
	width: 800px;
	height: 600px;
}

#canvas {
	display: block;
	width: 800px;
	height: 600px;
	touch-action: none;
	/* The canvas backing buffer is a fixed 800x600 (Main.hx); on a scaled display (devicePixelRatio
	   > 1, common on Windows/Linux at 125-200% or a retina screen) the browser stretches that buffer
	   to the CSS size with smooth (bilinear) scaling by default, which blurs and distorts small pixel
	   art — item icons most visibly. This keeps that upscale crisp, nearest-neighbor, same as the
	   in-canvas drawImage calls that already set ctx.imageSmoothingEnabled = false. */
	image-rendering: pixelated;
	image-rendering: -moz-crisp-edges;
}

#bootError {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 30;
	align-items: center;
	justify-content: center;
	padding: 24px;
	text-align: center;
	background: #07111c;
	color: #e7eef8;
	font: 20px sans-serif;
}

#bootError.is-visible {
	display: flex;
}

#rotateGate {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 20;
	align-items: center;
	justify-content: center;
	padding: 24px;
	text-align: center;
	background: #07111c;
	color: #e7eef8;
	font: 22px sans-serif;
}

body[data-mode="mobile"] #rotateGate {
	display: none;
}

@media (orientation: portrait) {
	body[data-mode="mobile"] #rotateGate {
		display: flex;
	}

	body[data-mode="mobile"] #canvasContainer,
	body[data-mode="mobile"] .controls,
	body[data-mode="mobile"] .auth-ui {
		visibility: hidden;
	}
}

.auth-ui {
	position: fixed;
	z-index: 6;
}

#googleLogin {
	display: none;
	position: fixed;
	z-index: 6;
	left: 50%;
	top: 50%;
	transform: translate(-50%, -50%);
	min-height: 44px;
}

#preloader {
	position: fixed;
	inset: 0;
	z-index: 40;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #102030;
	color: #fff;
	font-family: sans-serif;
}

#preloader[hidden] {
	display: none;
}

.preloader-card {
	width: 280px;
	text-align: center;
}

.preloader-title {
	font-size: 28px;
	letter-spacing: 0.08em;
	margin-bottom: 18px;
}

.preloader-track {
	height: 8px;
	background: #2a3a4a;
	border-radius: 4px;
	overflow: hidden;
}

#preloaderBar {
	display: block;
	height: 100%;
	width: 0;
	background: #66bbff;
}

#preloaderLabel {
	margin-top: 12px;
	font-size: 14px;
}

#preloaderVersion {
	margin-top: 8px;
	font-size: 12px;
	opacity: 0.7;
}

#soundBtn {
	position: fixed;
	z-index: 10;
	top: max(12px, env(safe-area-inset-top));
	right: max(12px, env(safe-area-inset-right));
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 4px;
	border-top: 2px solid rgba(176, 200, 216, 0.55);
	background: #1c3f60;
	color: #fff;
	font-size: 20px;
	line-height: 38px;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
}

#soundBtn:hover {
	background: #2c6290;
}

#soundBtn[aria-pressed="true"] {
	background: #7a3430;
}

/* While playing, the game draws these two in its own top bar. */
body.hud #soundBtn,
body.hud #logoutBtn {
	display: none !important;
}

#logoutBtn {
	display: none;
	top: max(12px, env(safe-area-inset-top));
	right: calc(max(12px, env(safe-area-inset-right)) + 52px);
	border: 0;
	border-top: 2px solid rgba(176, 200, 216, 0.55);
	border-radius: 4px;
	padding: 8px 14px;
	background: #7a3430;
	color: #fff;
	font: 700 14px sans-serif;
}

.controls {
	position: fixed;
	z-index: 5;
	touch-action: none;
	user-select: none;
}

.stick {
	left: max(16px, env(safe-area-inset-left));
	bottom: max(16px, env(safe-area-inset-bottom));
	width: 148px;
	height: 148px;
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.28);
	border: 3px solid rgba(255, 255, 255, 0.45);
}

.stick-knob {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 68px;
	height: 68px;
	margin: -34px 0 0 -34px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.72);
	box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
	pointer-events: none;
}

.actions {
	right: max(16px, env(safe-area-inset-right));
	bottom: max(28px, env(safe-area-inset-bottom));
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 14px;
}

.ab-row {
	display: flex;
	gap: 16px;
}

.controls button {
	width: 76px;
	height: 76px;
	border: 3px solid rgba(255, 255, 255, 0.55);
	border-radius: 50%;
	background: rgba(0, 0, 0, 0.35);
	color: #fff;
	font: 700 26px sans-serif;
}

.controls button.menu-key {
	width: auto;
	min-width: 92px;
	height: 46px;
	padding: 0 16px;
	border-radius: 23px;
	font: 700 15px sans-serif;
	letter-spacing: 0.04em;
}

body[data-mode="desktop"] .controls {
	display: none;
}

@media (pointer: coarse) {
	body[data-mode="desktop"] .controls.stick {
		display: block;
	}

	body[data-mode="desktop"] .controls.actions {
		display: flex;
	}
}

.controls button.is-down {
	background: rgba(255, 255, 255, 0.55);
	color: #14324a;
}

/* The ROM gate lives in the existing game preloader, including short mobile screens. */
#preloader:has(#rom-play) { overflow: auto; padding: 16px; }
#preloader:has(#rom-play) .preloader-card { margin: auto; max-height: none; }
#rom-play { max-width: 480px; text-align: left; font: 14px/1.5 sans-serif; }
#rom-play h2 { font-size: 20px; margin: 12px 0; }
#rom-play p, #rom-play label { display: block; margin: 10px 0; }
#rom-play input[type="file"] { display: block; max-width: 100%; margin: 12px 0; }
#rom-play button { padding: 8px; margin: 4px; cursor: pointer; }
#rom-play input[type="checkbox"] { margin-right: 6px; }
#rom-play button:disabled { cursor: default; }
#rom-play-entry, #rom-play-active-forget {
  position: fixed; left: 10px; top: 10px; z-index: 16; padding: 7px 10px;
  background: #172a40; color: #fff; border: 1px solid #567; border-radius: 6px;
  font: 12px sans-serif; text-decoration: none; cursor: pointer;
}
body:has(#rom-play) #rom-play-entry { display: none; }

#rom-play-notice {
  position: fixed; top: 48px; left: 10px; z-index: 16; max-width: calc(100vw - 20px);
  padding: 7px; background: #172a40; color: #fff; font: 12px sans-serif;
}

/* Entry overlays own focus until the authenticated game stage begins. */
body.pocketpe-launcher:not([data-entry-stage="game"]) .controls,
body.pocketpe-launcher:not([data-entry-stage="game"]) #soundBtn,
body.pocketpe-launcher:not([data-entry-stage="game"]) #logoutBtn {
	display: none !important;
}

/* Original PocketPe colors on the existing touch controls; keep their geometry and key bindings. */
body.pocketpe-launcher[data-entry-stage="game"] .stick {
	border-color: rgba(242, 244, 251, 0.85);
	background: rgba(37, 36, 62, 0.92);
}

body.pocketpe-launcher[data-entry-stage="game"] .stick-knob {
	background: #ffd13f;
	box-shadow: 0 2px 6px rgba(8, 13, 32, 0.45);
}

body.pocketpe-launcher[data-entry-stage="game"] .controls button {
	border-color: rgba(242, 244, 251, 0.88);
	background: #25243e;
	color: #fff;
	transition: transform 0.18s ease, opacity 0.18s ease;
}

body.pocketpe-launcher[data-entry-stage="game"] .controls button:not(.menu-key) {
	border-radius: 50%;
}

body.pocketpe-launcher[data-entry-stage="game"] .controls button[data-key="90"] {
	background: #ffd13f;
	color: #25243e;
}

body.pocketpe-launcher[data-entry-stage="game"] .controls button[data-key="88"] {
	background: #2867d6;
}

body.pocketpe-launcher[data-entry-stage="game"] .controls button:active {
	transform: translateY(1px);
	opacity: 0.86;
}

body.pocketpe-launcher[data-entry-stage="game"] .controls button.is-down {
	transform: translateY(1px);
	background: #fff;
	color: #25243e;
}

body.pocketpe-launcher[data-entry-stage="game"] #soundBtn,
body.pocketpe-launcher[data-entry-stage="game"] #logoutBtn {
	border-radius: 999px;
	background: #25243e;
	color: #fff;
}

body.pocketpe-launcher[data-entry-stage="game"] #soundBtn[aria-pressed="true"] {
	background: #ffd13f;
	color: #25243e;
}

body.pocketpe-launcher[data-entry-stage="game"] .controls button:focus-visible,
body.pocketpe-launcher[data-entry-stage="game"] #soundBtn:focus-visible,
body.pocketpe-launcher[data-entry-stage="game"] #logoutBtn:focus-visible {
	outline: 3px solid #ffd13f;
	outline-offset: 3px;
}

body.pocketpe-launcher[data-entry-stage="game"] .controls button[data-key="90"]:focus-visible,
body.pocketpe-launcher[data-entry-stage="game"] #soundBtn[aria-pressed="true"]:focus-visible {
	outline-color: #25243e;
}

@media (prefers-reduced-motion: reduce) {
	body.pocketpe-launcher[data-entry-stage="game"] .controls,
	body.pocketpe-launcher[data-entry-stage="game"] .controls *,
	body.pocketpe-launcher[data-entry-stage="game"] #soundBtn,
	body.pocketpe-launcher[data-entry-stage="game"] #logoutBtn {
		animation: none !important;
		transition: none !important;
	}
}
