/* ==========================================================================
   reyeschristian.com — blueberry palette, pixel-game chrome
   ========================================================================== */

:root {
	--night: #161a2e;
	--night-deep: #0e1122;
	--berry: #4f5bd5;
	--berry-bright: #7b86f0;
	--berry-pale: #c9cdfb;
	--cream: #f4f1e8;
	--ink: #1a1730;
	--gold: #f2c14e;

	--panel-border: 4px;
	--font-pixel: 'Press Start 2P', ui-monospace, 'Courier New', monospace;
	--font-body: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto,
		Helvetica, Arial, sans-serif;
}

* {
	box-sizing: border-box;
}

/* The rules below set display: flex/grid, which outrank the UA stylesheet's
   [hidden] { display: none }. Without this, hiding via .hidden = true does
   nothing and the modal/touch controls stay on screen. */
[hidden] {
	display: none !important;
}

html,
body {
	margin: 0;
	padding: 0;
	height: 100%;
	overflow: hidden;
	background: var(--night-deep);
	color: var(--cream);
	font-family: var(--font-body);
	/* Stop iOS from bouncing / zooming while you're walking around. */
	overscroll-behavior: none;
	touch-action: none;
	-webkit-text-size-adjust: 100%;
}

#game {
	display: block;
	width: 100%;
	height: 100%;
	image-rendering: pixelated;
	image-rendering: crisp-edges;
	cursor: default;
}

/* --------------------------------------------------------------------------
   HUD
   -------------------------------------------------------------------------- */

.hud {
	position: fixed;
	z-index: 10;
	pointer-events: none;
	text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.75);
}

.hud-left {
	top: max(1rem, env(safe-area-inset-top));
	left: max(1rem, env(safe-area-inset-left));
}

.hud-name {
	margin: 0;
	font-family: var(--font-pixel);
	font-size: clamp(0.7rem, 2.6vw, 1.05rem);
	letter-spacing: 0.02em;
	color: var(--cream);
}

.hud-tagline {
	margin: 0.55rem 0 0;
	font-family: var(--font-pixel);
	font-size: clamp(0.44rem, 1.5vw, 0.6rem);
	color: var(--berry-pale);
}

.hud-right {
	top: max(1rem, env(safe-area-inset-top));
	right: max(1rem, env(safe-area-inset-right));
	display: flex;
	align-items: center;
	gap: 0.5rem;
	font-family: var(--font-pixel);
	font-size: clamp(0.5rem, 1.8vw, 0.72rem);
}

.berry-icon {
	width: 0.85em;
	height: 0.85em;
	border-radius: 50%;
	background: var(--berry-bright);
	box-shadow:
		inset -2px -2px 0 rgba(0, 0, 0, 0.35),
		inset 2px 2px 0 rgba(255, 255, 255, 0.4);
}

.berry-total {
	color: var(--berry-pale);
	opacity: 0.7;
}

/* --------------------------------------------------------------------------
   "[E] Read" prompt
   -------------------------------------------------------------------------- */

.prompt {
	position: fixed;
	z-index: 12;
	left: 50%;
	bottom: clamp(5.5rem, 16vh, 9rem);
	transform: translateX(-50%);
	display: flex;
	align-items: center;
	gap: 0.6rem;
	padding: 0.7rem 1.1rem;
	background: var(--night);
	border: var(--panel-border) solid var(--cream);
	font-family: var(--font-pixel);
	font-size: clamp(0.5rem, 1.7vw, 0.68rem);
	pointer-events: none;
	animation: prompt-in 160ms steps(3, end);
}

@keyframes prompt-in {
	from {
		transform: translate(-50%, 8px);
		opacity: 0;
	}
}

.prompt .key {
	display: grid;
	place-items: center;
	min-width: 1.9em;
	padding: 0.35em 0.15em;
	background: var(--gold);
	color: var(--ink);
	border-radius: 2px;
}

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */

.modal {
	position: fixed;
	inset: 0;
	z-index: 30;
	display: grid;
	place-items: center;
	padding: 1.25rem;
	background: rgba(10, 12, 26, 0.82);
	animation: fade-in 140ms ease-out;
}

@keyframes fade-in {
	from {
		opacity: 0;
	}
}

.modal-box {
	width: min(34rem, 100%);
	max-height: min(78vh, 40rem);
	display: flex;
	flex-direction: column;
	background: var(--night);
	border: var(--panel-border) solid var(--cream);
	box-shadow: 0 0 0 4px var(--night-deep), 10px 10px 0 rgba(0, 0, 0, 0.45);
	animation: pop-in 160ms steps(4, end);
}

@keyframes pop-in {
	from {
		transform: scale(0.9);
	}
}

.modal-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.95rem 1.1rem;
	background: var(--berry);
	border-bottom: var(--panel-border) solid var(--cream);
}

.modal-bar h2 {
	margin: 0;
	font-family: var(--font-pixel);
	font-size: clamp(0.6rem, 2vw, 0.82rem);
	line-height: 1.5;
}

.modal-close {
	flex: none;
	width: 2rem;
	height: 2rem;
	background: var(--night);
	color: var(--cream);
	border: 2px solid var(--cream);
	font-size: 0.85rem;
	line-height: 1;
	cursor: pointer;
}

.modal-close:hover,
.modal-close:focus-visible {
	background: var(--gold);
	color: var(--ink);
}

.modal-body {
	padding: 1.35rem;
	overflow-y: auto;
	font-size: 1rem;
	line-height: 1.65;
}

.modal-body p {
	margin: 0 0 1rem;
}

.modal-body p:last-child {
	margin-bottom: 0;
}

.modal-body a {
	color: var(--berry-bright);
	text-underline-offset: 3px;
}

.modal-body a:hover {
	color: var(--gold);
}

.modal-body code {
	padding: 0.15em 0.4em;
	background: rgba(255, 255, 255, 0.09);
	border-radius: 3px;
	font-size: 0.9em;
}

.modal-body .muted {
	color: var(--berry-pale);
	opacity: 0.72;
	font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Intro card
   -------------------------------------------------------------------------- */

.intro {
	position: fixed;
	inset: 0;
	z-index: 40;
	display: grid;
	place-items: center;
	padding: 1.5rem;
	background: radial-gradient(
		circle at 50% 45%,
		rgba(30, 36, 74, 0.94),
		rgba(9, 11, 22, 0.97)
	);
	text-align: center;
	transition: opacity 400ms ease, visibility 400ms;
}

.intro.hidden {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
}

.intro-name {
	margin: 0;
	font-family: var(--font-pixel);
	font-size: clamp(1rem, 5.5vw, 2rem);
	line-height: 1.45;
	text-shadow: 4px 4px 0 var(--berry);
}

.intro-tagline {
	margin: 1.4rem 0 0;
	font-family: var(--font-pixel);
	font-size: clamp(0.55rem, 2.4vw, 0.85rem);
	color: var(--berry-pale);
}

.intro-hint {
	margin: 2.4rem 0 0;
	font-size: 0.82rem;
	color: var(--berry-pale);
	opacity: 0.85;
	line-height: 2.2;
}

.keys b {
	display: inline-grid;
	place-items: center;
	min-width: 1.75em;
	padding: 0.3em 0.35em;
	margin: 0 0.12em;
	background: var(--cream);
	color: var(--ink);
	border-radius: 3px;
	font-family: var(--font-pixel);
	font-size: 0.62rem;
	font-weight: 400;
}

.intro-start {
	margin-top: 2.2rem;
	padding: 1rem 1.9rem;
	background: var(--berry);
	color: var(--cream);
	border: var(--panel-border) solid var(--cream);
	font-family: var(--font-pixel);
	font-size: 0.72rem;
	cursor: pointer;
	transition: transform 120ms steps(2, end), background 120ms;
}

.intro-start:hover,
.intro-start:focus-visible {
	background: var(--berry-bright);
	transform: translate(-2px, -2px);
	box-shadow: 4px 4px 0 var(--night-deep);
}

.intro-sub {
	margin: 1.6rem 0 0;
	font-size: 0.78rem;
	opacity: 0.6;
}

.intro-sub a {
	color: var(--berry-pale);
}

/* --------------------------------------------------------------------------
   Touch controls
   -------------------------------------------------------------------------- */

.touch {
	position: fixed;
	z-index: 15;
	left: 0;
	right: 0;
	bottom: max(1.1rem, env(safe-area-inset-bottom));
	padding: 0 max(1.1rem, env(safe-area-inset-left));
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	pointer-events: none;
}

.dpad {
	position: relative;
	width: 10.5rem;
	height: 10.5rem;
	opacity: 0.75;
}

.dpad-btn,
.action-btn {
	position: absolute;
	display: grid;
	place-items: center;
	width: 3.5rem;
	height: 3.5rem;
	background: var(--night);
	color: var(--cream);
	border: 3px solid var(--cream);
	font-size: 1rem;
	pointer-events: auto;
	user-select: none;
	-webkit-user-select: none;
	-webkit-tap-highlight-color: transparent;
}

.dpad-btn:active,
.action-btn:active {
	background: var(--berry);
}

.dpad-btn.up {
	top: 0;
	left: 3.5rem;
}
.dpad-btn.left {
	top: 3.5rem;
	left: 0;
}
.dpad-btn.right {
	top: 3.5rem;
	left: 7rem;
}
.dpad-btn.down {
	top: 7rem;
	left: 3.5rem;
}

.action-btn {
	position: relative;
	width: 4.75rem;
	height: 4.75rem;
	margin-right: max(0.5rem, env(safe-area-inset-right));
	border-radius: 50%;
	background: var(--berry);
	font-family: var(--font-pixel);
	font-size: 1rem;
	opacity: 0.85;
}

/* --------------------------------------------------------------------------
   Text fallback — offscreen while the game is running, readable without JS
   -------------------------------------------------------------------------- */

.text-version {
	position: absolute;
	left: -10000px;
	top: 0;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

/* If JS never runs, .js-on is never added — show the readable page instead. */
body:not(.js-on) .text-version {
	position: static;
	width: auto;
	height: auto;
	max-width: 38rem;
	margin: 0 auto;
	padding: 3rem 1.5rem;
	overflow: visible;
}

body:not(.js-on) {
	overflow: auto;
}

body:not(.js-on) #game,
body:not(.js-on) .hud,
body:not(.js-on) .intro,
body:not(.js-on) .touch {
	display: none;
}

.text-version a {
	color: var(--berry-bright);
}

.text-tagline {
	color: var(--berry-pale);
}

/* Jumped to via the "read it as a plain page" link. */
.text-version:target {
	position: static;
	width: auto;
	height: auto;
	max-width: 38rem;
	margin: 0 auto;
	padding: 3rem 1.5rem;
	overflow: visible;
	background: var(--night-deep);
}

/* --------------------------------------------------------------------------
   Accessibility
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}

:focus-visible {
	outline: 3px solid var(--gold);
	outline-offset: 2px;
}
