/* A reusable service-navigation scene. All scenery colours follow SJ's palette. */
.sj-game {
	--sj-game-sky: var(--color-navy);
	--sj-game-text: var(--color-offwhite);
	--sj-game-accent: var(--color-yellow);
	--sj-game-green: var(--color-lime);
	--sj-game-block: var(--color-green);
	--sj-game-ground: var(--color-forest);
	--sj-game-control-background: color-mix(in srgb, var(--color-offwhite) 12%, var(--color-navy));
	--sj-game-control-text: var(--color-offwhite);
	--sj-game-control-active-background: var(--color-yellow);
	--sj-game-control-active-text: var(--color-navy);
	--sj-game-harbour: color-mix(in oklab, var(--color-forest) 25%, var(--color-navy));
	--sj-game-water: color-mix(in srgb, var(--sj-game-harbour) 28%, var(--color-navy));
	--sj-game-reflection: color-mix(in srgb, var(--color-offwhite) 18%, var(--sj-game-harbour));
	--sj-game-skyline-shift: 0px;
	--sj-game-water-shift: 0px;
	--sj-game-line: color-mix(in srgb, var(--color-offwhite) 20%, var(--color-navy));
	position: relative;
	box-sizing: border-box;
	width: 100%;
	color: var(--sj-game-text);
	background: var(--sj-game-sky);
	border: 1px solid var(--sj-game-line);
	font-family: var(--font-body);
	font-size: 0.875rem;
	line-height: 1.5;
	isolation: isolate;
}

.sj-game *,
.sj-game *::before,
.sj-game *::after {
	box-sizing: border-box;
}

.sj-game [hidden] {
	display: none !important;
}

/* Keep long presses within the playable scene from opening browser callouts. */
.sj-game[data-sj-game-enhanced],
.sj-game[data-sj-game-enhanced] * {
	-webkit-touch-callout: none;
	-webkit-user-select: none;
	user-select: none;
}

.sj-game__toolbar {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto auto;
	align-items: center;
	gap: 8px 24px;
	padding: 20px 24px;
	border-bottom: 1px solid var(--sj-game-line);
}

.sj-game__toolbar h2 {
	margin: 0;
	color: var(--sj-game-text);
	font-family: var(--font-heading);
	font-size: clamp(1.125rem, 2vw, 1.375rem);
	font-weight: 600;
	line-height: 1.25;
}

.sj-game__toolbar p,
.sj-game__footer p {
	margin: 0;
	font-size: var(--font-size-body);
}

.sj-game__toolbar :is(p, .sj-game__instructions) {
	color: color-mix(in srgb, var(--sj-game-text) 76%, var(--sj-game-sky));

	font-size: var(--font-size-body);
}

.sj-game kbd {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 24px;
	min-height: 24px;
	padding: 0 5px;
	color: var(--sj-game-text);
	border: 1px solid var(--sj-game-line);
	background: transparent;
	border-radius: 3px;
	font: inherit;
	font-size: 0.75rem;
	line-height: 1;
	box-shadow: none;
}

.sj-game__viewport {
	position: relative;
	width: 100%;
	max-width: 100%;
	background-color: var(--sj-game-sky);
	overscroll-behavior-x: contain;
	outline: none;
}

/* The unenhanced markup is an ordinary grid of links, including without JS. */
.sj-game__world {
	position: relative;
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
	gap: 32px 16px;
	width: 100%;
	padding: 32px 24px;
}

.sj-game .sj-game__block {
	position: relative;
	display: grid;
	grid-template-columns: 80px;
	grid-template-rows: 80px auto;
	justify-content: center;
	justify-items: center;
	align-items: center;
	gap: 12px;
	min-width: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	color: var(--sj-game-text);
	font: inherit;
	text-align: center;
	text-decoration: none;
	box-shadow: none;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}

.sj-game__block-art {
	--sj-game-face: var(--sj-game-block);
	--sj-game-edge-light: color-mix(in srgb, var(--color-lime) 45%, var(--sj-game-block));
	--sj-game-edge-dark: color-mix(in srgb, var(--color-forest) 75%, var(--sj-game-block));
	grid-column: 1;
	grid-row: 1;
	display: block;
	width: 80px;
	height: 80px;
	background: linear-gradient(90deg,
		var(--sj-game-edge-light) 0 8px,
		var(--sj-game-face) 8px calc(100% - 8px),
		var(--sj-game-edge-dark) calc(100% - 8px) 100%);
	-webkit-mask: url("../../images/game/block.svg") center / 80px 80px no-repeat;
	mask: url("../../images/game/block.svg") center / 80px 80px no-repeat;
	image-rendering: pixelated;
	pointer-events: none;
}

.sj-game .sj-game__block-icon {
	grid-column: 1;
	grid-row: 1;
	z-index: 1;
	flex-basis: 48px;
	display: inline-block;
	width: 48px;
	height: 48px;
	color: var(--sj-game-accent);
	background: transparent;
	font-size: 48px;
	line-height: 1;
	box-shadow: none;
	pointer-events: none;
}

.sj-game__block-label {
	grid-column: 1;
	grid-row: 2;
	display: block;
	width: 176px;
	max-width: none;
	color: inherit;
	font-size: 0.875rem;
	font-weight: 500;
	line-height: 1.35;
	text-wrap: balance;
}

.sj-game .sj-game__block:hover {
	color: var(--sj-game-accent);
	background: transparent;
	text-decoration: none;
	box-shadow: none;
}

.sj-game .sj-game__block.is-hit .sj-game__block-art {
	--sj-game-face: var(--sj-game-accent);
	--sj-game-edge-light: color-mix(in srgb, var(--color-white) 35%, var(--sj-game-accent));
	--sj-game-edge-dark: color-mix(in srgb, var(--color-lime) 55%, var(--sj-game-accent));
}

.sj-game .sj-game__block.is-hit .sj-game__block-icon {
	color: var(--sj-game-block);
}

.sj-game__player,
.sj-game__ground,
.sj-game__landmark {
	display: none;
}

/* Physics use this fixed-size world; the camera moves within the viewport. */
.sj-game[data-sj-game-enhanced] .sj-game__viewport {
	height: 360px;
	overflow-x: hidden;
	overflow-y: hidden;
	scroll-behavior: auto;
	scrollbar-width: none;
	-ms-overflow-style: none;
	touch-action: pan-x pan-y;
}

.sj-game[data-sj-game-enhanced] .sj-game__viewport::-webkit-scrollbar {
	display: none;
	width: 0;
	height: 0;
}

.sj-game[data-sj-game-enhanced] .sj-game__world {
	display: block;
	width: var(--sj-game-world-width, 2144px);
	min-width: var(--sj-game-world-width, 2144px);
	max-width: none;
	height: 360px;
	min-height: 360px;
	padding: 0;
	overflow: clip;
}

.sj-game[data-sj-game-enhanced] .sj-game__world::before {
	position: absolute;
	z-index: 0;
	top: 0;
	left: 0;
	width: 100%;
	height: 256px;
	background: var(--sj-game-harbour);
	-webkit-mask: url("../../images/game/portsmouth-skyline.svg") left bottom / 1920px 256px no-repeat;
	mask: url("../../images/game/portsmouth-skyline.svg") left bottom / 1920px 256px no-repeat;
	transform: translate3d(var(--sj-game-skyline-shift), 0, 0);
	content: "";
	pointer-events: none;
}

/* Still water and a handful of square reflections, behind the playable shore. */
.sj-game[data-sj-game-enhanced] .sj-game__world::after {
	position: absolute;
	z-index: 0;
	top: 256px;
	left: 0;
	width: 100%;
	height: 64px;
	background-color: var(--sj-game-water);
	background-image:
		linear-gradient(var(--sj-game-reflection) 0 0),
		linear-gradient(var(--sj-game-reflection) 0 0),
		linear-gradient(var(--sj-game-reflection) 0 0),
		linear-gradient(var(--sj-game-reflection) 0 0),
		linear-gradient(var(--sj-game-reflection) 0 0),
		linear-gradient(var(--sj-game-reflection) 0 0),
		linear-gradient(var(--sj-game-reflection) 0 0);
	background-position: 96px 20px, 370px 44px, 680px 14px, 980px 36px, 1270px 22px, 1540px 50px, 1790px 28px;
	background-size: 40px 4px, 48px 4px, 32px 4px, 52px 4px, 40px 4px, 48px 4px, 32px 4px;
	background-repeat: no-repeat;
	transform: translate3d(var(--sj-game-water-shift), 0, 0);
	content: "";
	pointer-events: none;
}

.sj-game[data-sj-game-enhanced] .sj-game__block {
	position: absolute;
	z-index: 2;
	left: var(--sj-game-x, 288px);
	top: var(--sj-game-y, 88px);
	display: grid;
	grid-template-columns: 80px;
	grid-template-rows: 80px;
	width: 80px;
	height: 80px;
	gap: 0;
}

.sj-game[data-sj-game-enhanced] .sj-game__block-label {
	grid-area: auto;
	position: absolute;
	bottom: calc(100% + 12px);
	left: 50%;
	transform: translateX(-50%);
}

.sj-game[data-sj-game-enhanced] .sj-game__player {
	position: absolute;
	z-index: 3;
	top: 0;
	left: 0;
	display: block;
	width: 84px;
	height: 96px;
	pointer-events: none;
	will-change: transform;
}

.sj-game__sprite {
	display: block;
	width: 84px;
	height: 96px;
	max-width: none;
	object-fit: contain;
	image-rendering: pixelated;
	pointer-events: none;
	user-select: none;
	-webkit-user-drag: none;
}

.sj-game[data-sj-game-enhanced] .sj-game__player.is-entering {
	z-index: 0;
}

.sj-game .sj-game__tunnel {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-end;
	gap: 12px;
	min-width: 0;
	padding: 0;
	border: 0;
	background: transparent;
	color: var(--sj-game-text);
	font: inherit;
	text-align: center;
	text-decoration: none;
	box-shadow: none;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}

.sj-game__tunnel-art {
	display: block;
	width: 144px;
	height: 120px;
	max-width: none;
	image-rendering: pixelated;
	pointer-events: none;
	user-select: none;
	-webkit-user-drag: none;
}

.sj-game__tunnel-label {
	display: block;
	width: 176px;
	max-width: none;
	color: inherit;
	font-size: 0.875rem;
	font-weight: 500;
	line-height: 1.35;
	text-wrap: balance;
}

.sj-game__tunnel-hint {
	display: block;
	margin-top: 6px;
	color: color-mix(in srgb, var(--sj-game-text) 76%, var(--sj-game-sky));
	font-size: 0.75rem;
	font-weight: 400;
	line-height: 1.4;
}

.sj-game .sj-game__tunnel:hover {
	background: transparent;
	color: var(--sj-game-accent);
	text-decoration: none;
}

.sj-game[data-sj-game-enhanced] .sj-game__tunnel {
	position: absolute;
	z-index: 4;
	left: var(--sj-game-x, 1888px);
	top: var(--sj-game-y, 200px);
	width: 144px;
	height: 120px;
	gap: 0;
}

.sj-game[data-sj-game-enhanced] .sj-game__tunnel-label {
	position: absolute;
	bottom: calc(100% + 112px);
	left: 50%;
	transform: translateX(-50%);
}

.sj-game[data-sj-game-enhanced] .sj-game__ground {
	position: absolute;
	z-index: 1;
	top: 320px;
	left: 0;
	display: block;
	width: 100%;
	height: 40px;
	border-top: 6px solid var(--sj-game-green);
	background-color: var(--sj-game-ground);
	background-image: repeating-linear-gradient(90deg, transparent 0, transparent 46px, color-mix(in srgb, var(--color-navy) 18%, transparent) 46px, color-mix(in srgb, var(--color-navy) 18%, transparent) 48px);
	pointer-events: none;
}

.sj-game[data-sj-game-enhanced] .sj-game__landmark {
	position: absolute;
	z-index: 0;
	bottom: 40px;
	display: block;
	color: var(--sj-game-ground);
	opacity: 0.35;
	pointer-events: none;
}

.sj-game__footer {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 16px 24px;
	min-height: 88px;
	padding: 20px 24px;
	border-top: 1px solid var(--sj-game-line);
}

.sj-game__status {
	max-width: 48ch;
	color: color-mix(in srgb, var(--sj-game-text) 78%, var(--sj-game-sky));
	font-size: 0.8125rem;
}

.sj-game__controls {
	display: none;
	align-items: center;
	gap: 8px;
}

.sj-game[data-sj-game-enhanced] .sj-game__controls {
	display: flex;
}

body .sj-game :is(.sj-game__control, .sj-game__reset) {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	min-width: 44px;
	min-height: 44px;
	padding: 10px;
	border: 0;
	border-radius: var(--radius-full);
	background: var(--sj-game-control-background);
	color: var(--sj-game-control-text);
	font-family: var(--font-body);
	font-size: 0.8125rem;
	font-weight: 500;
	line-height: 1;
	text-transform: none;
	box-shadow: none;
	cursor: pointer;
	user-select: none;
	-webkit-tap-highlight-color: transparent;
}

body .sj-game .sj-game__control {
	touch-action: none;
}

body .sj-game .sj-game__control:is([data-sj-game-control="jump"], [data-sj-game-control="down"]) {
	min-width: 76px;
	gap: 6px;
	padding-inline: 16px;
}

body .sj-game .sj-game__control[data-sj-game-control="down"] {
	display: none;
}

body .sj-game.is-on-tunnel .sj-game__control[data-sj-game-control="down"] {
	display: inline-flex;
}

body .sj-game.is-on-tunnel .sj-game__control[data-sj-game-control="jump"] {
	display: none;
}

body .sj-game .sj-game__reset {
	gap: 6px;
	padding-inline: 14px;
}

body .sj-game .sj-game__toolbar .sj-game__reset {
	width: 44px;
	padding: 10px;
}

.sj-game__reset > span:not(.sj-icon) {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip-path: inset(50%);
	white-space: nowrap;
}

body .sj-game :is(.sj-game__control, .sj-game__reset):hover {
	border: 0;
	background: var(--sj-game-control-background);
	color: var(--sj-game-control-text);
	box-shadow: none;
}

body .sj-game .sj-game__control:not(.is-pressed):is(:focus, :active) {
	background: var(--sj-game-control-background);
	color: var(--sj-game-control-text);
	transition: none;
}

/* Only a direct screen press lights a game control; keys still drive gameplay. */
body .sj-game .sj-game__control.is-pressed,
body .sj-game .sj-game__reset:active {
	border: 0;
	background: var(--sj-game-control-active-background);
	color: var(--sj-game-control-active-text);
	box-shadow: none;
	transition: none;
}

/* Native links/buttons keep focus feedback, without outlining the whole scene. */
body .sj-game :is(a, button, [tabindex]):focus-visible {
	outline: 2px solid var(--sj-game-accent);
	outline-offset: 4px;
	box-shadow: 0 0 0 4px var(--sj-game-sky);
}
body .sj-game .sj-game__viewport:is(:focus, :focus-visible) {
	outline: none;
	box-shadow: none;
}

.sj-game .sj-game__block.is-bumped {
	animation: sj-game-block-bump 180ms ease-out;
}

.sj-game:not([data-sj-game-enhanced]) .sj-game__reset {
	display: none;
}

@keyframes sj-game-block-bump {
	0%, 100% { translate: 0 0; }
	45% { translate: 0 -10px; }
}

@media (max-width: 60rem) {
	.sj-game__toolbar {
		grid-template-columns: minmax(0, 1fr) auto;
		gap: 8px 12px;
	}

	.sj-game__instructions {
		grid-column: 1 / -1;
		grid-row: 2;
	}

	body .sj-game .sj-game__toolbar .sj-game__reset {
		grid-column: 2;
		grid-row: 1;
	}

	.sj-game__footer {
		align-items: flex-start;
		flex-direction: column;
	}

	.sj-game__controls {
		order: -1;
		justify-content: flex-start;
		flex-wrap: nowrap;
		width: 100%;
	}

	body .sj-game .sj-game__control:is([data-sj-game-control="jump"], [data-sj-game-control="down"]) {
		margin-inline-start: auto;
	}
}

@media (max-width: 37.5rem) {
	.sj-game__toolbar {
		padding: 12px 16px;
	}

	.sj-game__toolbar :is(p, .sj-game__instructions) {
		font-size: var(--font-size-body);
	}

	.sj-game__footer {
		gap: 12px;
		padding: 12px 16px;
	}

	/* Trim only the decorative ground; player, labels and physics stay full size. */
	.sj-game[data-sj-game-enhanced] .sj-game__viewport { height: 336px; }

	.sj-game__world {
		grid-template-columns: repeat(2, minmax(0, 1fr));
		gap: 32px 12px;
		padding: 24px 12px;
	}

	.sj-game__block-label {
		width: 132px;
		font-size: 0.8125rem;
	}

	.sj-game[data-sj-game-enhanced] .sj-game__block-label {
		width: 176px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.sj-game .sj-game__block.is-bumped {
		animation: none;
	}

	body .sj-game :is(.sj-game__control, .sj-game__reset) {
		transition: none;
	}
}
