:root {
	/* Design system - roles, not one-off hex dumps */
	--slate: #526575;
	--coral: #f07868;
	--coral-deep: #e05a4c;
	--turquoise: #32b8a6;
	--gold: #ffc857;
	--danger: #d94b4b;
	--ivory: #f4f1e8;
	--anthracite: #26313a;
	--cream: #fff6eb;
	--cream-soft: #ffe8d4;
	--sage: #6fa87a;
	--sky: #a8d8f0;
	--ink: #26313a;
	--ink-soft: #4a5560;
	--panel-bg: rgba(38, 49, 58, 0.82);
	--panel-bg-soft: rgba(38, 49, 58, 0.76);
	--panel-border: rgba(244, 241, 232, 0.18);

	--display-font: "Fredoka", "Nunito", sans-serif;
	--ui-font: "Nunito", "Fredoka", sans-serif;

	--safe-top: env(safe-area-inset-top, 0px);
	--safe-right: env(safe-area-inset-right, 0px);
	--safe-bottom: env(safe-area-inset-bottom, 0px);
	--safe-left: env(safe-area-inset-left, 0px);

	/* Fallback first, then dynamic viewport when supported */
	--app-height: 100vh;
	--app-height: 100dvh;
}

*,
*::before,
*::after {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
	user-select: none;
	-webkit-user-select: none;
	-webkit-tap-highlight-color: transparent;
}

html {
	width: 100%;
	height: var(--app-height);
	overflow: hidden;
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}

body {
	position: fixed;
	inset: 0;
	width: 100%;
	height: var(--app-height);
	overflow: hidden;
	overscroll-behavior: none;
	touch-action: manipulation;
	background:
		radial-gradient(ellipse 120% 80% at 50% -10%, #dff3fc 0%, transparent 55%),
		linear-gradient(180deg, var(--sky) 0%, #c8e8c4 55%, var(--sage) 100%);
	font-family: var(--ui-font);
	color: var(--ink);
}

#game-container {
	position: absolute;
	inset: 0;
	width: 100%;
	height: var(--app-height);
	z-index: 1;
	overflow: hidden;
	touch-action: none;
}

#game-container canvas {
	display: block;
	width: 100%;
	height: 100%;
	touch-action: none;
}

#ui-layer {
	position: absolute;
	inset: 0;
	width: 100%;
	height: var(--app-height);
	z-index: 10;
	pointer-events: none;
	overflow: hidden;
}

button,
a {
	pointer-events: auto;
	touch-action: manipulation;
}

.center-screen {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	width: min(92vw, 34rem);
	max-width: calc(100% - var(--safe-left) - var(--safe-right) - 1.5rem);
	max-height: calc(
		var(--app-height) - var(--safe-top) - var(--safe-bottom) - 1.5rem
	);
	overflow: hidden;
	text-align: center;
	background: var(--panel-bg);
	padding: clamp(1.15rem, 4vw, 2rem) clamp(1.2rem, 5.5vw, 3rem);
	border-radius: 1.15rem;
	backdrop-filter: blur(10px);
	-webkit-backdrop-filter: blur(10px);
	border: 1px solid var(--panel-border);
	box-shadow: 0 12px 32px rgba(38, 49, 58, 0.28);
	animation: panel-in 0.4s ease-out;
	color: var(--ivory);
}

@keyframes panel-in {
	from {
		opacity: 0;
		transform: translate(-50%, -46%) scale(0.98);
	}
	to {
		opacity: 1;
		transform: translate(-50%, -50%) scale(1);
	}
}

.brand-mark {
	font-family: var(--ui-font);
	font-weight: 800;
	font-size: clamp(0.68rem, 2.2vw, 0.8rem);
	letter-spacing: 0.2em;
	text-transform: uppercase;
	color: rgba(244, 241, 232, 0.55);
	margin-bottom: 0.3rem;
}

.brand-logo {
	display: block;
	width: clamp(4.5rem, 18vw, 7rem);
	height: auto;
	margin: 0.15rem auto 0.55rem;
	filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.18));
	pointer-events: none;
	user-select: none;
}

.title {
	font-family: var(--display-font);
	font-weight: 700;
	font-size: clamp(1.85rem, 8.5vw, 3.75rem);
	color: var(--ivory);
	letter-spacing: -0.02em;
	text-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
	margin-bottom: 0.3rem;
	line-height: 0.95;
	word-break: break-word;
}

.title-over {
	color: var(--danger);
	text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.subtitle {
	font-family: var(--ui-font);
	font-weight: 700;
	font-size: clamp(1rem, 3.8vw, 1.45rem);
	color: rgba(244, 241, 232, 0.78);
	margin-bottom: clamp(1rem, 2.8vw, 1.55rem);
	line-height: 1.3;
}

.insta-cta {
	margin-top: clamp(0.85rem, 2.5vw, 1.15rem);
	font-family: var(--ui-font);
	font-weight: 700;
	font-size: clamp(0.85rem, 3vw, 1rem);
	line-height: 1.35;
	color: rgba(244, 241, 232, 0.65);
}

.insta-cta a {
	display: inline-block;
	margin-top: 0.2rem;
	color: var(--coral);
	font-weight: 800;
	text-decoration: none;
	border-bottom: 2px solid rgba(240, 120, 104, 0.45);
}

@media (hover: hover) and (pointer: fine) {
	.insta-cta a:hover {
		color: #ff8f80;
		border-bottom-color: #ff8f80;
	}
}

button {
	background: var(--coral);
	color: #fff;
	border: none;
	min-height: 3rem;
	min-width: 8.5rem;
	padding: 0.8rem 1.75rem;
	font-size: clamp(1.15rem, 4.2vw, 1.65rem);
	font-family: var(--ui-font);
	font-weight: 800;
	letter-spacing: 0.02em;
	cursor: pointer;
	border-radius: 0.9rem;
	transition: transform 0.1s, box-shadow 0.1s, background 0.15s;
	box-shadow: 0 4px 0 var(--coral-deep);
}

button:active {
	transform: translateY(3px);
	box-shadow: 0 1px 0 var(--coral-deep);
}

@media (hover: hover) and (pointer: fine) {
	button:hover {
		background: #ff8a7a;
	}
}

.btn-secondary {
	display: block;
	margin: 0.65rem auto 0;
	min-width: 7.5rem;
	min-height: 2.55rem;
	padding: 0.45rem 1.2rem;
	font-size: clamp(0.95rem, 3.4vw, 1.15rem);
	background: transparent;
	color: var(--ivory);
	border: 1px solid rgba(244, 241, 232, 0.35);
	box-shadow: none;
}

.btn-secondary:active {
	transform: translateY(1px);
	box-shadow: none;
}

@media (hover: hover) and (pointer: fine) {
	.btn-secondary:hover {
		background: rgba(244, 241, 232, 0.1);
		border-color: rgba(244, 241, 232, 0.55);
	}
}

/* Compact first-visit / rules card - scene stays partly visible */
.onboarding-screen {
	width: min(92vw, 26rem);
	padding: clamp(0.95rem, 3.2vw, 1.45rem) clamp(1rem, 4vw, 1.65rem);
	background: rgba(38, 49, 58, 0.72);
	pointer-events: auto;
}

.onboarding-title {
	font-family: var(--display-font);
	font-weight: 700;
	font-size: clamp(1.55rem, 6.5vw, 2.15rem);
	color: var(--ivory);
	letter-spacing: -0.02em;
	line-height: 1;
	margin-bottom: clamp(0.7rem, 2.2vw, 1rem);
}

.onboarding-list {
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 0.45rem;
	margin: 0 0 clamp(0.85rem, 2.4vw, 1.2rem);
	text-align: left;
}

.onboarding-item {
	display: flex;
	align-items: center;
	gap: 0.65rem;
	padding: 0.42rem 0.55rem;
	border-radius: 0.7rem;
	border: 1px solid rgba(244, 241, 232, 0.12);
	background: rgba(255, 255, 255, 0.06);
}

.onboarding-item--bonus {
	border-color: rgba(76, 184, 74, 0.35);
}

.onboarding-item--malus {
	border-color: rgba(217, 75, 75, 0.4);
}

.onboarding-item--shield {
	border-color: rgba(255, 200, 87, 0.4);
}

.onboarding-item--controls {
	border-color: rgba(50, 184, 166, 0.35);
}

.onboarding-emoji {
	flex: 0 0 auto;
	width: 1.85rem;
	text-align: center;
	font-size: 1.35rem;
	line-height: 1;
}

.onboarding-copy {
	display: flex;
	flex-direction: column;
	gap: 0.08rem;
	min-width: 0;
}

.onboarding-verb {
	font-family: var(--ui-font);
	font-weight: 800;
	font-size: clamp(0.82rem, 2.9vw, 0.98rem);
	letter-spacing: 0.04em;
	text-transform: uppercase;
	color: var(--ivory);
	line-height: 1.15;
}

.onboarding-detail {
	font-family: var(--ui-font);
	font-weight: 700;
	font-size: clamp(0.78rem, 2.7vw, 0.92rem);
	color: rgba(244, 241, 232, 0.72);
	line-height: 1.2;
}

.onboarding-item--bonus .onboarding-detail {
	color: #9be08f;
}

.onboarding-item--malus .onboarding-detail {
	color: #ff9a9a;
}

.onboarding-item--shield .onboarding-detail {
	color: var(--gold);
}

#score-display {
	position: absolute;
	top: max(0.65rem, calc(var(--safe-top) + 0.4rem));
	left: max(0.65rem, calc(var(--safe-left) + 0.4rem));
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 0.02rem;
	font-family: var(--ui-font);
	font-weight: 800;
	font-size: clamp(1.35rem, 5vw, 1.95rem);
	color: var(--ivory);
	text-shadow: 0 1px 3px rgba(38, 49, 58, 0.55);
	line-height: 1.05;
}

.score-label {
	font-family: var(--ui-font);
	font-size: 0.42em;
	font-weight: 800;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	opacity: 0.85;
}

.score-label--best {
	margin-top: 0.28rem;
	opacity: 0.75;
}

#best-score {
	font-size: 0.62em;
	font-weight: 700;
	opacity: 0.92;
	line-height: 1.05;
}

.best-line {
	font-family: var(--ui-font);
	font-weight: 800;
	font-size: clamp(0.95rem, 3.6vw, 1.25rem);
	color: var(--gold);
	margin: -0.55rem 0 clamp(0.85rem, 2.4vw, 1.25rem);
	line-height: 1.25;
	text-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.best-line #start-best-score {
	color: var(--cream);
	font-variant-numeric: tabular-nums;
}

/* Reserve a slim top band so the corner chip never crowds "Perdu". */
#game-over-screen {
	padding-top: clamp(1.45rem, 4.8vw, 2.25rem);
}

/* Corner chip - absolute so absence never shifts score/buttons */
.new-record-banner {
	position: absolute;
	top: 0.4rem;
	left: 0.45rem;
	z-index: 1;
	display: inline-flex;
	align-items: center;
	gap: 0.22rem;
	margin: 0;
	padding: 0.14rem 0.4rem 0.14rem 0.3rem;
	border-radius: 0.55rem;
	border: 1px solid rgba(240, 120, 104, 0.28);
	background: var(--ivory);
	color: var(--coral);
	font-family: var(--ui-font);
	font-weight: 800;
	font-size: clamp(0.6rem, 2.2vw, 0.7rem);
	letter-spacing: 0.03em;
	line-height: 1.1;
	text-transform: none;
	pointer-events: none;
	animation: record-pop 0.28s ease-out;
}

.new-record-banner__icon {
	flex: 0 0 auto;
	color: var(--gold);
	font-size: 0.95em;
	line-height: 1;
	text-shadow: 0 0 0.35rem rgba(255, 200, 87, 0.35);
}

@keyframes record-pop {
	from {
		opacity: 0;
		transform: translateY(-0.15rem) scale(0.96);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

/* Compact spaghetti timer under score */
.shield-hud {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	gap: 0.15rem;
	margin-top: 0.35rem;
	min-width: 5.5rem;
	padding: 0.28rem 0.4rem 0.32rem;
	border-radius: 0.65rem;
	background: var(--panel-bg-soft);
	border: 1px solid rgba(255, 200, 87, 0.4);
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16);
}

.shield-hud__label {
	font-family: var(--ui-font);
	font-size: 0.62rem;
	font-weight: 800;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--gold);
	text-shadow: none;
	line-height: 1;
}

.shield-hud__track {
	height: 0.35rem;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.12);
	overflow: hidden;
}

.shield-hud__fill {
	height: 100%;
	width: 100%;
	border-radius: inherit;
	background: linear-gradient(90deg, var(--coral-deep), var(--gold));
	transform-origin: left center;
	transform: scaleX(1);
}

/* Mute stays top-right on its own - no rival avatar beside it. */
.mute-btn {
	position: absolute;
	top: max(0.75rem, calc(var(--safe-top) + 0.5rem));
	right: max(0.75rem, calc(var(--safe-right) + 0.5rem));
	z-index: 15;
	min-width: 3.25rem;
	min-height: 2.75rem;
	padding: 0.35rem 0.7rem;
	font-size: clamp(0.85rem, 2.8vw, 1.05rem);
	font-family: var(--ui-font);
	font-weight: 800;
	line-height: 1;
	border-radius: 0.75rem;
	border: 1px solid var(--panel-border);
	background: var(--panel-bg-soft);
	color: var(--ivory);
	box-shadow: 0 2px 8px rgba(38, 49, 58, 0.25);
	pointer-events: auto;
	touch-action: manipulation;
}

.mute-btn[aria-pressed="true"] {
	background: rgba(240, 120, 104, 0.88);
	border-color: rgba(255, 255, 255, 0.25);
}

.mute-btn:active {
	transform: translateY(2px);
	box-shadow: 0 0 0 rgba(38, 49, 58, 0.2);
}

/* Compact translucent cue - top band, track stays readable */
#taunt-display {
	position: absolute;
	top: max(3.55rem, calc(var(--safe-top) + 2.85rem));
	left: 50%;
	transform: translateX(-50%);
	max-width: min(68vw, 12.5rem);
	padding: 0.28rem 0.65rem;
	border-radius: 0.75rem;
	border: 1px solid var(--panel-border);
	background: var(--panel-bg);
	color: var(--ivory);
	font-family: var(--ui-font);
	font-weight: 800;
	font-size: clamp(0.78rem, 2.8vw, 0.98rem);
	letter-spacing: 0.04em;
	line-height: 1.15;
	text-align: center;
	text-shadow: none;
	pointer-events: none;
	z-index: 12;
	opacity: 1;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
	backdrop-filter: blur(4px);
	-webkit-backdrop-filter: blur(4px);
}

#taunt-display.taunt-in {
	animation: taunt-pop 0.2s ease-out;
}

#taunt-display.taunt-out {
	animation: taunt-fade 0.18s ease-in forwards;
}

#taunt-display.taunt-invincible {
	color: #fff8e8;
	border-color: rgba(79, 214, 196, 0.55);
	background: rgba(28, 42, 38, 0.82);
	box-shadow:
		0 0 0 1px rgba(255, 210, 74, 0.25),
		0 2px 12px rgba(79, 214, 196, 0.28);
}

@keyframes taunt-pop {
	from {
		opacity: 0;
		transform: translateX(-50%) translateY(-0.3rem) scale(0.97);
	}
	to {
		opacity: 1;
		transform: translateX(-50%) translateY(0) scale(1);
	}
}

@keyframes taunt-fade {
	to {
		opacity: 0;
		transform: translateX(-50%) translateY(-0.2rem) scale(0.98);
	}
}

@media (orientation: landscape) and (max-height: 500px) {
	.mute-btn {
		min-height: 2.4rem;
		font-size: clamp(0.8rem, 3vh, 1rem);
		padding: 0.25rem 0.55rem;
	}

	#taunt-display {
		top: max(0.55rem, calc(var(--safe-top) + 0.35rem));
		left: max(0.65rem, calc(var(--safe-left) + 0.4rem));
		right: auto;
		transform: none;
		max-width: min(36vw, 10rem);
		font-size: clamp(0.72rem, 2.8vh, 0.9rem);
		padding: 0.2rem 0.45rem;
		letter-spacing: 0.04em;
	}

	#taunt-display.taunt-in,
	#taunt-display.taunt-out {
		animation: none;
	}
}

.hidden {
	display: none !important;
}

@media (orientation: landscape) and (max-height: 500px) {
	.center-screen {
		padding: 0.7rem 1.35rem;
		box-shadow: 0 8px 22px rgba(38, 49, 58, 0.25);
	}

	.brand-mark {
		font-size: 0.62rem;
		margin-bottom: 0.12rem;
	}

	.title {
		font-size: clamp(1.45rem, 6.5vh, 2.35rem);
		margin-bottom: 0.15rem;
	}

	.subtitle {
		font-size: clamp(0.9rem, 3.6vh, 1.2rem);
		margin-bottom: 0.55rem;
	}

	.best-line {
		font-size: clamp(0.85rem, 3.4vh, 1.1rem);
		margin: -0.35rem 0 0.55rem;
	}

	#game-over-screen {
		padding-top: 1.15rem;
	}

	.new-record-banner {
		top: 0.28rem;
		left: 0.35rem;
		font-size: clamp(0.56rem, 2.1vh, 0.66rem);
		padding: 0.1rem 0.32rem 0.1rem 0.24rem;
		gap: 0.16rem;
	}

	.insta-cta {
		margin-top: 0.55rem;
		font-size: clamp(0.75rem, 3vh, 0.9rem);
	}

	button {
		min-height: 2.5rem;
		padding: 0.45rem 1.15rem;
		font-size: clamp(1rem, 4.5vh, 1.35rem);
		box-shadow: 0 3px 0 var(--coral-deep);
	}

	button:active {
		transform: translateY(2px);
	}

	.btn-secondary {
		margin-top: 0.4rem;
		min-height: 2.15rem;
		padding: 0.3rem 0.9rem;
		font-size: clamp(0.85rem, 3.4vh, 1rem);
	}

	.onboarding-screen {
		width: min(88vw, 34rem);
		padding: 0.55rem 1rem;
	}

	.onboarding-title {
		font-size: clamp(1.2rem, 5.5vh, 1.65rem);
		margin-bottom: 0.45rem;
	}

	.onboarding-list {
		display: grid;
		grid-template-columns: 1fr 1fr;
		gap: 0.35rem;
		margin-bottom: 0.55rem;
	}

	.onboarding-item {
		padding: 0.3rem 0.4rem;
		gap: 0.45rem;
	}

	.onboarding-emoji {
		width: 1.45rem;
		font-size: 1.1rem;
	}

	.onboarding-verb {
		font-size: clamp(0.68rem, 2.6vh, 0.82rem);
	}

	.onboarding-detail {
		font-size: clamp(0.65rem, 2.4vh, 0.78rem);
	}

	#score-display {
		font-size: clamp(1.25rem, 5.5vh, 1.85rem);
	}
}

@media (max-width: 360px) {
	.center-screen {
		padding: 1rem 1.15rem;
	}
}
