/* Train 'Em — warm golden-hour camp theme. One accent (banner gold),
   14px radius family, dark dusk neutrals matching the painterly art. */

:root {
	--bg: #171310;
	--bg-2: #211a14;
	--ink: #f4ead8;
	--ink-dim: #c9b89d;
	--gold: #e2a93b;
	--gold-deep: #b9821f;
	--danger: #d5543f;
	--panel: rgba(28, 22, 16, 0.82);
	--line: rgba(226, 169, 59, 0.28);
	--radius: 14px;
	--safe-top: env(safe-area-inset-top, 0px);
	--safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}
[hidden] {
	display: none !important;
}
html,
body {
	height: 100%;
}
body {
	background: var(--bg);
	color: var(--ink);
	font-family: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
	overflow: hidden;
	-webkit-tap-highlight-color: transparent;
	touch-action: manipulation;
	user-select: none;
	-webkit-user-select: none;
}

.view {
	position: fixed;
	inset: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

/* ------------------------------ backdrop ------------------------------ */

.camp-bg {
	position: absolute;
	inset: 0;
	background:
		url("/assets/lobby_backdrop.webp") center 30% / cover no-repeat,
		var(--bg-2);
	transform: scale(1.03);
	animation: campDrift 26s ease-in-out infinite alternate;
}
.camp-bg--cave {
	background:
		url("/assets/bg_cave.webp") center / cover no-repeat,
		var(--bg-2);
}
@keyframes campDrift {
	from {
		transform: scale(1.03) translateY(0);
	}
	to {
		transform: scale(1.08) translateY(-1.6%);
	}
}
@media (prefers-reduced-motion: reduce) {
	.camp-bg {
		animation: none;
	}
}
.camp-veil {
	position: absolute;
	inset: 0;
	background: linear-gradient(
		180deg,
		rgba(23, 19, 16, 0.72) 0%,
		rgba(23, 19, 16, 0.3) 34%,
		rgba(23, 19, 16, 0.66) 78%,
		rgba(23, 19, 16, 0.9) 100%
	);
}
.camp-veil--lobby {
	background: linear-gradient(
		180deg,
		rgba(23, 19, 16, 0.78) 0%,
		rgba(23, 19, 16, 0.45) 40%,
		rgba(23, 19, 16, 0.86) 100%
	);
}

/* ------------------------------ landing ------------------------------- */

.landing-inner,
.lobby-inner,
.results-inner {
	position: relative;
	z-index: 1;
	width: 100%;
	max-width: 430px;
	margin: 0 auto;
	padding: calc(var(--safe-top) + 22px) 20px calc(var(--safe-bottom) + 22px);
	display: flex;
	flex-direction: column;
	height: 100%;
	overflow-y: auto;
}

.brand {
	font-size: 12px;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--ink-dim);
}
.title {
	margin-top: 8px;
	font-size: 56px;
	line-height: 0.95;
	font-weight: 800;
	text-shadow: 0 3px 18px rgba(0, 0, 0, 0.55);
}
.title span {
	color: var(--gold);
}
.tagline {
	margin-top: 10px;
	font-size: 16px;
	color: var(--ink-dim);
}

.landing-card {
	margin-top: auto;
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 18px;
	backdrop-filter: blur(8px);
	-webkit-backdrop-filter: blur(8px);
	display: flex;
	flex-direction: column;
	gap: 12px;
}
.field-label {
	font-size: 12px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--ink-dim);
}
input[type="text"] {
	width: 100%;
	padding: 13px 14px;
	font-size: 17px;
	color: var(--ink);
	background: rgba(0, 0, 0, 0.35);
	border: 1px solid var(--line);
	border-radius: 10px;
	outline: none;
}
input[type="text"]:focus {
	border-color: var(--gold);
}
input::placeholder {
	color: rgba(201, 184, 157, 0.5);
}

.btn {
	appearance: none;
	border: none;
	cursor: pointer;
	font: inherit;
	font-weight: 700;
	border-radius: 10px;
	padding: 13px 18px;
	transition:
		transform 0.08s ease,
		filter 0.15s ease;
}
.btn:active {
	transform: translateY(1px) scale(0.985);
}
.btn-primary {
	background: linear-gradient(180deg, var(--gold), var(--gold-deep));
	color: #241a08;
	box-shadow: 0 4px 16px rgba(226, 169, 59, 0.25);
}
.btn-primary:disabled {
	filter: grayscale(0.6) brightness(0.7);
}
.btn-ghost {
	background: rgba(244, 234, 216, 0.08);
	color: var(--ink);
	border: 1px solid var(--line);
}
.btn-danger {
	background: var(--danger);
	color: #fff;
}
.btn-small {
	padding: 9px 13px;
	font-size: 14px;
}
.btn-big {
	font-size: 19px;
	padding: 16px 18px;
}

.join-row {
	display: grid;
	grid-template-columns: 1fr auto;
	gap: 10px;
}
.landing-error {
	color: #ff9d8a;
	font-size: 14px;
}
.landing-note {
	margin-top: 14px;
	text-align: center;
	font-size: 13px;
	color: var(--ink-dim);
}

/* ------------------------------- lobby -------------------------------- */

.lobby-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
	margin-top: 26px;
}
.lobby-eyebrow {
	font-size: 13px;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--gold);
	font-weight: 700;
	max-width: 140px;
}
.lobby-code-wrap {
	text-align: right;
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 12px;
	padding: 8px 14px;
}
.lobby-code-label {
	display: block;
	font-size: 11px;
	color: var(--ink-dim);
	letter-spacing: 0.1em;
	text-transform: uppercase;
}
.lobby-code {
	font-size: 30px;
	font-weight: 800;
	letter-spacing: 0.12em;
	color: var(--ink);
}

.banner-row {
	display: flex;
	gap: 10px;
	justify-content: center;
	margin: 20px 0 6px;
	height: 44px;
}
.banner {
	width: 26px;
	height: 44px;
	background: linear-gradient(180deg, var(--gold), var(--gold-deep));
	clip-path: polygon(0 0, 100% 0, 100% 78%, 50% 100%, 0 78%);
	opacity: 0.9;
	transform-origin: top center;
	animation: bannerSway 3.4s ease-in-out infinite alternate;
}
.banner.b2 {
	animation-delay: 0.6s;
	filter: brightness(0.82);
}
.banner.b3 {
	animation-delay: 1.1s;
	filter: brightness(0.66);
}
@keyframes bannerSway {
	from {
		transform: rotate(-4deg);
	}
	to {
		transform: rotate(4deg);
	}
}
@media (prefers-reduced-motion: reduce) {
	.banner {
		animation: none;
	}
}

.lobby-players {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin-top: 8px;
}
.lobby-players li {
	display: flex;
	align-items: center;
	gap: 12px;
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 12px;
	padding: 11px 14px;
	font-size: 16px;
	font-weight: 600;
}
.hero-chip {
	width: 26px;
	height: 26px;
	border-radius: 8px;
	flex: none;
	box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.28);
	position: relative;
}
.hero-chip::after {
	content: "";
	position: absolute;
	top: -7px;
	left: 50%;
	transform: translateX(-50%);
	width: 12px;
	height: 12px;
	border-radius: 50%;
	background: #e8c9a2;
}
.player-off {
	opacity: 0.45;
}
.player-host-tag {
	margin-left: auto;
	font-size: 10px;
	font-weight: 800;
	letter-spacing: 0.1em;
	color: #241a08;
	background: var(--gold);
	border-radius: 6px;
	padding: 3px 7px;
}
.lobby-count {
	text-align: center;
	margin-top: 10px;
	font-size: 13px;
	color: var(--ink-dim);
}

.invite-card {
	margin-top: 16px;
	background: var(--panel);
	border: 1px dashed var(--line);
	border-radius: var(--radius);
	padding: 14px 16px;
}
.invite-title {
	font-weight: 800;
	font-size: 15px;
}
.invite-sub {
	font-size: 13px;
	color: var(--ink-dim);
	margin-top: 2px;
}
.invite-line {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-top: 10px;
}
.invite-url {
	flex: 1;
	font-size: 12px;
	color: var(--ink-dim);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.invite-copied {
	margin-top: 8px;
	font-size: 13px;
	color: var(--gold);
}

.host-controls {
	margin-top: auto;
	padding-top: 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.host-hint {
	text-align: center;
	font-size: 12.5px;
	color: var(--ink-dim);
}
.guest-wait {
	margin-top: auto;
	padding: 22px 0;
	text-align: center;
	color: var(--ink-dim);
	font-size: 15px;
}

/* ------------------------------ exit btn ------------------------------ */

.exit-btn {
	position: absolute;
	top: calc(var(--safe-top) + 10px);
	left: 12px;
	z-index: 30;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	border: 1px solid var(--line);
	background: rgba(23, 19, 16, 0.72);
	color: var(--ink);
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
}

/* ------------------------------- game --------------------------------- */

.view-game {
	background: var(--bg);
}

.hud {
	position: relative;
	z-index: 10;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: calc(var(--safe-top) + 8px) 12px 6px 60px;
	min-height: calc(var(--safe-top) + 52px);
	background: linear-gradient(
		180deg,
		rgba(13, 10, 8, 0.88),
		rgba(13, 10, 8, 0)
	);
}
.hud-hearts {
	display: flex;
	gap: 4px;
	font-size: 20px;
	filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}
.hud-hearts .lost {
	opacity: 0.22;
}
.hud-scores {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
	justify-content: flex-end;
	max-width: 70%;
}
.score-chip {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 12.5px;
	font-weight: 700;
	background: rgba(23, 19, 16, 0.72);
	border: 1px solid rgba(226, 169, 59, 0.18);
	border-radius: 999px;
	padding: 4px 10px 4px 5px;
}
.score-chip .dot {
	width: 14px;
	height: 14px;
	border-radius: 50%;
}
.score-chip .pts {
	color: var(--gold);
	font-variant-numeric: tabular-nums;
}
.score-chip.me {
	border-color: var(--gold);
}

.stage-wrap {
	position: relative;
	flex: 1;
	min-height: 0;
}
#game-canvas {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	display: block;
}

.lesson-card {
	position: absolute;
	top: 8%;
	left: 50%;
	transform: translateX(-50%);
	z-index: 12;
	text-align: center;
	background: linear-gradient(
		180deg,
		rgba(30, 23, 15, 0.92),
		rgba(23, 18, 12, 0.92)
	);
	border: 1px solid var(--gold);
	border-radius: var(--radius);
	padding: 12px 22px;
	box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
	animation: cardIn 0.35s cubic-bezier(0.16, 1, 0.3, 1);
	max-width: 86%;
}
@keyframes cardIn {
	from {
		opacity: 0;
		transform: translate(-50%, -12px);
	}
	to {
		opacity: 1;
		transform: translate(-50%, 0);
	}
}
.lesson-title {
	font-size: 19px;
	font-weight: 800;
	color: var(--gold);
}
.lesson-sub {
	font-size: 13.5px;
	color: var(--ink-dim);
	margin-top: 3px;
}

.warning-flash {
	position: absolute;
	inset: 0;
	z-index: 11;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding-top: 22%;
	background: radial-gradient(
		ellipse at center,
		rgba(213, 84, 63, 0) 40%,
		rgba(213, 84, 63, 0.28) 100%
	);
	animation: warnPulse 0.5s ease-in-out 3;
	pointer-events: none;
}
.warning-flash p {
	font-size: 24px;
	font-weight: 900;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: #ffd9c9;
	text-shadow: 0 0 18px rgba(213, 84, 63, 0.9);
}
@keyframes warnPulse {
	0%,
	100% {
		opacity: 0.55;
	}
	50% {
		opacity: 1;
	}
}

.host-line {
	position: absolute;
	bottom: 12px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 12;
	max-width: 88%;
	text-align: center;
	background: rgba(23, 19, 16, 0.85);
	border: 1px solid var(--line);
	border-radius: 999px;
	padding: 8px 18px;
	font-size: 14px;
	font-style: italic;
	color: var(--ink);
	pointer-events: none;
}

.countdown {
	position: absolute;
	inset: 0;
	z-index: 14;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 110px;
	font-weight: 900;
	color: var(--gold);
	text-shadow: 0 6px 40px rgba(0, 0, 0, 0.8);
	pointer-events: none;
}

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

.touch-layer {
	position: absolute;
	inset: 0;
	z-index: 20;
	pointer-events: none;
}
.joystick {
	position: absolute;
	width: 116px;
	height: 116px;
	margin: -58px 0 0 -58px;
	border-radius: 50%;
	border: 2px solid rgba(244, 234, 216, 0.35);
	background: rgba(23, 19, 16, 0.3);
	backdrop-filter: blur(2px);
	pointer-events: none;
}
.joystick-knob {
	position: absolute;
	left: 50%;
	top: 50%;
	width: 52px;
	height: 52px;
	margin: -26px 0 0 -26px;
	border-radius: 50%;
	background: radial-gradient(circle at 35% 30%, #f7dfae, var(--gold-deep));
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}
.action-cluster {
	position: absolute;
	right: 18px;
	bottom: calc(var(--safe-bottom) + 26px);
	display: flex;
	align-items: flex-end;
	gap: 14px;
	pointer-events: none;
}
.attack-btn,
.jump-btn {
	border-radius: 50%;
	font-weight: 900;
	letter-spacing: 0.04em;
	cursor: pointer;
	pointer-events: auto;
	box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
	transition: transform 0.06s ease;
	color: #241a08;
}
.attack-btn {
	width: 96px;
	height: 96px;
	border: 2px solid rgba(226, 169, 59, 0.6);
	background: radial-gradient(
		circle at 35% 30%,
		rgba(226, 169, 59, 0.95),
		rgba(155, 100, 18, 0.95)
	);
}
.jump-btn {
	width: 78px;
	height: 78px;
	margin-bottom: 6px;
	border: 2px solid rgba(120, 200, 140, 0.6);
	background: radial-gradient(
		circle at 35% 30%,
		rgba(126, 214, 152, 0.95),
		rgba(46, 138, 84, 0.95)
	);
	color: #0e2417;
}
.attack-btn:active,
.jump-btn:active {
	transform: scale(0.93);
}
.action-label {
	font-size: 14px;
}
.jump-btn .action-label {
	font-size: 13px;
}
body.kb-mode .action-cluster {
	display: none;
}

/* ------------------------------ results ------------------------------- */

.results-inner {
	max-width: 470px;
}
.results-eyebrow {
	margin-top: 30px;
	font-size: 13px;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--gold);
	font-weight: 700;
	text-align: center;
}
.results-title {
	text-align: center;
	font-size: 36px;
	font-weight: 800;
	margin-top: 4px;
}

.podium {
	list-style: none;
	margin-top: 18px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.podium li {
	display: flex;
	align-items: center;
	gap: 12px;
	background: var(--panel);
	border: 1px solid var(--line);
	border-radius: 12px;
	padding: 12px 14px;
	font-size: 16px;
	font-weight: 700;
}
.podium li.first {
	border-color: var(--gold);
	box-shadow: 0 0 22px rgba(226, 169, 59, 0.18);
}
.podium .rank {
	font-size: 20px;
	width: 34px;
	text-align: center;
}
.podium .pscore {
	margin-left: auto;
	color: var(--gold);
	font-variant-numeric: tabular-nums;
	font-size: 18px;
}
.podium .left-tag {
	font-size: 11px;
	color: var(--ink-dim);
	font-weight: 600;
}

.awards {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-top: 14px;
}
.award {
	display: flex;
	align-items: baseline;
	gap: 10px;
	font-size: 14px;
	background: rgba(226, 169, 59, 0.08);
	border: 1px solid rgba(226, 169, 59, 0.2);
	border-radius: 10px;
	padding: 9px 13px;
}
.award b {
	color: var(--gold);
}
.award span {
	color: var(--ink-dim);
	font-size: 13px;
}

.stat-details {
	margin-top: 16px;
}
.stat-details summary {
	cursor: pointer;
	font-size: 13px;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--ink-dim);
	margin-bottom: 8px;
}
.results-table {
	overflow-x: auto;
}
.results-table table {
	width: 100%;
	border-collapse: collapse;
	font-size: 12.5px;
}
.results-table th {
	text-align: right;
	font-weight: 600;
	color: var(--ink-dim);
	padding: 6px 8px;
	border-bottom: 1px solid var(--line);
}
.results-table th:first-child,
.results-table td:first-child {
	text-align: left;
}
.results-table td {
	text-align: right;
	padding: 7px 8px;
	font-variant-numeric: tabular-nums;
}
.results-actions {
	margin-top: auto;
	padding-top: 18px;
	display: flex;
}
.results-actions .btn {
	flex: 1;
}

/* ------------------------------- modal -------------------------------- */

.modal {
	position: fixed;
	inset: 0;
	z-index: 50;
	background: rgba(10, 8, 6, 0.7);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
}
.modal-card {
	background: var(--bg-2);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 22px;
	max-width: 340px;
	width: 100%;
}
.modal-title {
	font-size: 20px;
	font-weight: 800;
}
.modal-sub {
	margin-top: 6px;
	font-size: 14px;
	color: var(--ink-dim);
}
.modal-actions {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px;
	margin-top: 18px;
}

.toast {
	position: fixed;
	bottom: calc(var(--safe-bottom) + 18px);
	left: 50%;
	transform: translateX(-50%);
	z-index: 60;
	background: rgba(23, 19, 16, 0.94);
	border: 1px solid var(--line);
	border-radius: 999px;
	padding: 10px 18px;
	font-size: 14px;
	max-width: 88%;
	text-align: center;
}

/* wider screens: keep the phone layout centered, scale the stage */
@media (min-width: 700px) {
	.title {
		font-size: 68px;
	}
}
