/* =============================================================
   にげろ！マンボウ  -  Escape Sunfish
   Aesthetic: a marine-research observation rig framing a bright,
   cute irasutoya ocean. The tension between the clinical dive
   computer chrome and the cartoon prey mirrors the article:
   a brutal ram wrapped around something playful.
   ============================================================= */

:root {
	--abyss: #04121c;
	--abyss-2: #071e2c;
	--deep: #0b3a54;
	--phosphor: #35f0d0;
	--phosphor-dim: #1f8f7e;
	--amber: #ffb02e;
	--vermilion: #ff453a;
	--foam: #e9f7f8;
	--muted: #6f97a8;
	--rig-line: rgba(53, 240, 208, 0.28);

	--font-display: "Dela Gothic One", system-ui, sans-serif;
	--font-hud: "DotGothic16", monospace;
	--font-body: "Zen Kaku Gothic New", system-ui, sans-serif;
}

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

html,
body {
	height: 100%;
	/* スマホでのプルリフレッシュ/バウンススクロールを抑制 */
	overscroll-behavior: none;
}

body {
	background:
		radial-gradient(ellipse at 50% -20%, #0d2b3d 0%, var(--abyss) 62%, #020a11 100%);
	color: var(--foam);
	font-family: var(--font-body);
	display: grid;
	place-items: center;
	padding: 0;
	overflow: hidden;
	-webkit-font-smoothing: antialiased;
	/* ゲーム中のテキスト選択・ダブルタップズームを防ぐ */
	user-select: none;
	-webkit-user-select: none;
	touch-action: none;
}

/* ---- The research rig: fills the whole viewport like a monitor ---- */
.rig {
	position: relative;
	width: 100vw;
	height: 100vh;
	height: 100dvh;
	display: flex;
	flex-direction: column;
	background: var(--abyss-2);
	box-shadow: inset 0 0 90px -40px rgba(53, 240, 208, 0.4);
	overflow: hidden;
}

/* Corner brackets — the "instrument" signature */
.rig__bracket {
	position: absolute;
	width: 18px;
	height: 18px;
	border: 2px solid var(--phosphor);
	z-index: 40;
	pointer-events: none;
	opacity: 0.9;
}
.rig__bracket--tl { top: 8px; left: 8px; border-right: 0; border-bottom: 0; }
.rig__bracket--tr { top: 8px; right: 8px; border-left: 0; border-bottom: 0; }
.rig__bracket--bl { bottom: 8px; left: 8px; border-right: 0; border-top: 0; }
.rig__bracket--br { bottom: 8px; right: 8px; border-left: 0; border-top: 0; }

/* ---- Top status strip ---- */
.rig__top {
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 9px max(16px, env(safe-area-inset-right)) 9px max(16px, env(safe-area-inset-left));
	font-family: var(--font-hud);
	font-size: 12px;
	letter-spacing: 0.06em;
	color: var(--muted);
	border-bottom: 1px solid var(--rig-line);
	background: linear-gradient(180deg, rgba(53, 240, 208, 0.06), transparent);
	flex: 0 0 auto;
	z-index: 30;
}

.rig__rec {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	color: var(--vermilion);
}
.rig__rec::before {
	content: "";
	width: 9px;
	height: 9px;
	border-radius: 50%;
	background: var(--vermilion);
	box-shadow: 0 0 8px var(--vermilion);
	animation: recBlink 1.1s steps(1) infinite;
}
/* 中央のログは可変幅にし、右側のボタン群を押し出す（あふれたら省略） */
.rig__log {
	flex: 1 1 auto;
	min-width: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.rig__code { color: var(--phosphor-dim); white-space: nowrap; }

/* Sound on/off toggle in the status strip */
.rig__mute {
	font-family: var(--font-hud);
	font-size: 11px;
	letter-spacing: 0.08em;
	color: var(--phosphor);
	background: transparent;
	border: 1px solid var(--rig-line);
	border-radius: 3px;
	padding: 3px 9px;
	cursor: pointer;
	transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.rig__mute:hover { background: rgba(53, 240, 208, 0.12); }
.rig__mute[aria-pressed="true"] {
	color: var(--muted);
	border-color: rgba(111, 151, 168, 0.4);
}
.rig__mute:focus-visible { outline: 2px solid var(--foam); outline-offset: 2px; }

@keyframes recBlink {
	0%, 60% { opacity: 1; }
	61%, 100% { opacity: 0.15; }
}

/* ---- Stage: the actual ocean viewport ---- */
.stage {
	position: relative;
	flex: 1 1 auto;
	min-height: 0;
	overflow: hidden;
	background: #4a9fd6;
}

#canvas {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	display: block;
	touch-action: none;
	cursor: none;
}

/* CRT scanline + vignette overlay across the whole rig */
.rig__scan {
	position: absolute;
	inset: 0;
	z-index: 35;
	pointer-events: none;
	background:
		repeating-linear-gradient(
			0deg,
			rgba(0, 0, 0, 0.16) 0px,
			rgba(0, 0, 0, 0.16) 1px,
			transparent 2px,
			transparent 3px
		);
	mix-blend-mode: multiply;
	opacity: 0.5;
}
.rig__scan::after {
	content: "";
	position: absolute;
	inset: 0;
	background: radial-gradient(ellipse at center, transparent 58%, rgba(2, 10, 17, 0.55) 100%);
}

/* ---- HUD (in-play readouts) ---- */
.hud {
	position: absolute;
	inset: 0;
	z-index: 20;
	pointer-events: none;
	font-family: var(--font-hud);
	display: none;
}
.hud.is-on { display: block; }

.hud__panel {
	position: absolute;
	top: 12px;
	left: max(12px, env(safe-area-inset-left));
	padding: 8px 12px 9px;
	background: rgba(4, 18, 28, 0.62);
	border: 1px solid var(--rig-line);
	border-radius: 4px;
	backdrop-filter: blur(2px);
}
.hud__label {
	font-size: 10px;
	letter-spacing: 0.12em;
	color: var(--phosphor);
	opacity: 0.75;
}
.hud__score {
	font-size: 30px;
	line-height: 1;
	color: var(--foam);
	text-shadow: 0 0 12px rgba(53, 240, 208, 0.5);
}
.hud__unit { font-size: 12px; color: var(--muted); }
.hud__time {
	font-size: 12px;
	color: var(--muted);
	margin-top: 4px;
}

/* Threat / predation-risk sonar meter */
.hud__threat {
	position: absolute;
	top: 12px;
	right: max(12px, env(safe-area-inset-right));
	width: 168px;
	padding: 8px 12px 10px;
	background: rgba(4, 18, 28, 0.62);
	border: 1px solid var(--rig-line);
	border-radius: 4px;
}
.hud__threat-row {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	font-size: 10px;
	letter-spacing: 0.1em;
	color: var(--phosphor);
	opacity: 0.8;
	margin-bottom: 6px;
}
.hud__threat-pct { color: var(--foam); opacity: 1; }
.hud__bar {
	height: 8px;
	border-radius: 2px;
	background: rgba(255, 255, 255, 0.08);
	overflow: hidden;
}
.hud__bar-fill {
	height: 100%;
	width: 0%;
	background: var(--phosphor);
	transition: width 0.12s linear, background-color 0.25s linear;
}
.hud__pods {
	font-size: 10px;
	letter-spacing: 0.08em;
	color: var(--muted);
	margin-top: 7px;
}

/* ---- Full-screen overlay screens (start / over) ---- */
.screen {
	position: absolute;
	inset: 0;
	/* スキャンライン(z-35)より前面に置き、大きな文字をくっきり見せる */
	z-index: 38;
	display: none;
	flex-direction: column;
	align-items: center;
	/* 縦幅が足りないときは中央寄せをやめて上詰め＋スクロール可にし、
	   ボタンが見切れないようにする */
	justify-content: safe center;
	overflow-y: auto;
	touch-action: pan-y;
	text-align: center;
	padding: 24px;
	background:
		linear-gradient(180deg, rgba(4, 18, 28, 0.82), rgba(4, 18, 28, 0.92));
	backdrop-filter: blur(3px);
}
.screen.is-on { display: flex; }

.eyebrow {
	font-family: var(--font-hud);
	font-size: 12px;
	letter-spacing: 0.22em;
	color: var(--phosphor);
	margin-bottom: 14px;
	opacity: 0.85;
}
.eyebrow::before { content: "// "; opacity: 0.6; }

.title {
	font-family: var(--font-display);
	font-size: clamp(38px, 8vw, 76px);
	line-height: 0.98;
	letter-spacing: 0.01em;
	color: var(--foam);
	/* ぼやけたグローをやめ、暗い縁取りでコントラストを確保 */
	text-shadow:
		3px 3px 0 rgba(4, 18, 28, 0.92),
		-1px -1px 0 rgba(4, 18, 28, 0.7),
		0 0 3px rgba(4, 18, 28, 0.9);
}
.title .em {
	color: var(--phosphor);
	text-shadow:
		3px 3px 0 rgba(4, 18, 28, 0.92),
		0 0 16px rgba(53, 240, 208, 0.4);
}

.lede {
	max-width: 40ch;
	margin: 18px auto 0;
	font-size: 14px;
	line-height: 1.85;
	color: #b9d3d9;
}
/* 句のまとまりを inline-block にして、句の途中では折り返さないようにする */
.lede span {
	display: inline-block;
}

.mascot {
	width: clamp(88px, 16vw, 132px);
	margin-bottom: 6px;
	filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.45));
	animation: bob 3.4s ease-in-out infinite;
}
@keyframes bob {
	0%, 100% { transform: translateY(0) rotate(-3deg); }
	50% { transform: translateY(-12px) rotate(3deg); }
}

.controls-hint {
	display: flex;
	gap: 20px;
	margin-top: 22px;
	font-family: var(--font-hud);
	font-size: 11px;
	color: var(--muted);
	letter-spacing: 0.06em;
	flex-wrap: wrap;
	justify-content: center;
}
.controls-hint b {
	color: var(--foam);
	font-weight: normal;
	border: 1px solid var(--rig-line);
	border-radius: 3px;
	padding: 2px 7px;
	margin-right: 6px;
}

/* Primary action button — a lit console key */
.btn {
	margin-top: 28px;
	font-family: var(--font-hud);
	font-size: 17px;
	letter-spacing: 0.14em;
	color: var(--abyss);
	background: var(--phosphor);
	border: none;
	border-radius: 4px;
	padding: 15px 40px;
	cursor: pointer;
	box-shadow: 0 0 0 1px var(--phosphor), 0 0 24px -4px var(--phosphor);
	transition: transform 0.08s ease, box-shadow 0.2s ease, background-color 0.2s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 0 0 1px var(--phosphor), 0 0 34px 0 var(--phosphor); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 3px solid var(--foam); outline-offset: 3px; }
.btn:disabled { background: var(--muted); box-shadow: none; cursor: progress; opacity: 0.6; }

/* Secondary (outline) button — "back to title" */
.btn--ghost {
	color: var(--phosphor);
	background: transparent;
	box-shadow: inset 0 0 0 1px var(--phosphor);
}
.btn--ghost:hover {
	transform: translateY(-2px);
	background: rgba(53, 240, 208, 0.12);
	box-shadow: inset 0 0 0 1px var(--phosphor), 0 0 22px -6px var(--phosphor);
}

/* X (Twitter) share button */
.btn--x {
	color: var(--foam);
	background: #14202a;
	box-shadow: inset 0 0 0 1px rgba(233, 247, 248, 0.25);
}
.btn--x::before {
	content: "𝕏 ";
	font-weight: 700;
}
.btn--x:hover {
	transform: translateY(-2px);
	background: #1c2c38;
	box-shadow: inset 0 0 0 1px rgba(233, 247, 248, 0.55);
}

/* Game-over button row */
.over__actions {
	display: flex;
	gap: 14px;
	margin-top: 28px;
	flex-wrap: wrap;
	justify-content: center;
}
.over__actions .btn { margin-top: 0; }

/* ---- Game over specifics ---- */
.over__tag {
	/* 装飾の重いフォントは画数の多い漢字が潰れるため、
	   可読性の高い太ゴシック(Zen Kaku Gothic New 900)を使う */
	font-family: var(--font-body);
	font-weight: 900;
	font-size: clamp(32px, 6.8vw, 60px);
	color: #ff6f5e;
	letter-spacing: 0.04em;
	text-shadow: 2px 2px 0 rgba(4, 18, 28, 0.9);
	line-height: 1.1;
	margin-top: 4px;
}
.over__sub {
	font-family: var(--font-hud);
	font-size: 12px;
	letter-spacing: 0.16em;
	color: var(--amber);
	margin-top: 10px;
}
.over__quote {
	max-width: 30ch;
	margin: 20px auto 0;
	font-size: 14px;
	line-height: 1.8;
	color: #c7dce1;
	border-left: 2px solid var(--phosphor-dim);
	padding-left: 14px;
	text-align: left;
}
.over__quote cite {
	display: block;
	margin-top: 8px;
	font-style: normal;
	font-family: var(--font-hud);
	font-size: 10px;
	letter-spacing: 0.1em;
	color: var(--muted);
}

.scoreboard {
	display: flex;
	gap: 34px;
	margin-top: 24px;
	font-family: var(--font-hud);
}
.scoreboard div { display: flex; flex-direction: column; gap: 5px; }
.scoreboard .k { font-size: 10px; letter-spacing: 0.12em; color: var(--phosphor); opacity: 0.8; }
.scoreboard .v { font-size: 30px; color: var(--foam); }
.scoreboard .v.best { color: var(--amber); }
.is-newbest {
	font-family: var(--font-hud);
	font-size: 11px;
	color: var(--amber);
	margin-top: 14px;
	letter-spacing: 0.14em;
	animation: recBlink 0.9s steps(1) infinite;
}

.footnote {
	position: absolute;
	bottom: 10px;
	left: 0;
	right: 0;
	/* スタート/ゲームオーバーのオーバーレイ(z38)より前面でクレジットを見せる */
	z-index: 39;
	text-align: center;
	font-family: var(--font-hud);
	font-size: 9px;
	letter-spacing: 0.08em;
	color: rgba(111, 151, 168, 0.7);
	padding: 0 16px;
	/* リンク以外はクリックを透過させ、操作を妨げない */
	pointer-events: none;
}
.footnote__link {
	color: rgba(53, 240, 208, 0.8);
	text-decoration: none;
	pointer-events: auto;
}
.footnote__link:hover { text-decoration: underline; }

/* ---- Responsive ---- */
@media (max-width: 640px) {
	.rig__top { gap: 8px; font-size: 10px; }
	.hud__threat { width: 132px; }
	.hud__score { font-size: 24px; }
	.controls-hint { gap: 12px; }
	.rig__code { display: none; }
	.title { font-size: clamp(34px, 11vw, 56px); }
	.lede { font-size: 13px; }
	.footnote { font-size: 8px; }
}

/* Short/landscape phones: compress the overlay screens so nothing clips */
@media (max-height: 480px) {
	.mascot { width: 68px; margin-bottom: 2px; }
	.eyebrow { margin-bottom: 8px; }
	.title { font-size: clamp(28px, 9vh, 44px); }
	.lede { margin-top: 10px; font-size: 12px; line-height: 1.55; }
	.controls-hint { margin-top: 12px; }
	.btn { margin-top: 16px; padding: 12px 30px; }
	.over__quote { margin-top: 12px; }
	.scoreboard { margin-top: 14px; }
	.scoreboard .v { font-size: 24px; }
	.over__actions { margin-top: 16px; }
	.is-newbest { margin-top: 10px; }
	.footnote { display: none; }
}

/* Bigger tap target for the sound toggle on touch devices */
@media (pointer: coarse) {
	.rig__mute { padding: 6px 12px; }
}

/* ---- Portrait rotate hint (landscape game) ---- */
.rotate-hint { display: none; }

@media (orientation: portrait) and (max-width: 640px) {
	.rotate-hint {
		display: flex;
		position: fixed;
		inset: 0;
		z-index: 100;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		gap: 24px;
		padding: 24px;
		text-align: center;
		background: var(--abyss);
	}
}
.rotate-hint__phone {
	width: 54px;
	height: 94px;
	border: 3px solid var(--phosphor);
	border-radius: 12px;
	box-shadow: 0 0 22px -6px var(--phosphor);
	animation: rotatePhone 2.4s ease-in-out infinite;
}
.rotate-hint__text {
	font-family: var(--font-hud);
	font-size: 14px;
	letter-spacing: 0.08em;
	color: var(--foam);
	line-height: 1.7;
}
@keyframes rotatePhone {
	0%, 35% { transform: rotate(0deg); }
	65%, 100% { transform: rotate(-90deg); }
}

/* Accessibility: honor reduced motion */
@media (prefers-reduced-motion: reduce) {
	.mascot, .rig__rec::before, .is-newbest, .rotate-hint__phone { animation: none; }
	.btn { transition: none; }
}
