:root {
	--ink: #0d0a1f;
	--ink-2: #1a1438;
	--ink-3: #2a2154;
	--lead: #130f26;
	--gold: #f2c879;
	--gold-2: #ffe3a6;
	--rose: #ff5d73;
	--text: #f6eedd;
	--muted: #b3a8d6;
	--font: ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
	--safe-top: env(safe-area-inset-top, 0px);
	--safe-bottom: env(safe-area-inset-bottom, 0px);
	--safe-left: env(safe-area-inset-left, 0px);
	--safe-right: env(safe-area-inset-right, 0px);
	color-scheme: dark;
}

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

html,
body {
	margin: 0;
	height: 100%;
	overflow: hidden;
	overscroll-behavior: none;
	background: var(--ink);
	color: var(--text);
	font-family: var(--font);
	-webkit-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
	-webkit-tap-highlight-color: transparent;
	-webkit-text-size-adjust: 100%;
}

body {
	position: fixed;
	inset: 0;
	touch-action: none;
}

button {
	font: inherit;
	color: inherit;
	touch-action: manipulation;
}

[hidden] {
	display: none !important;
}

.app {
	position: relative;
	display: flex;
	flex-direction: column;
	height: 100%;
	max-width: 560px;
	margin: 0 auto;
	padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
	background:
		radial-gradient(120% 70% at 50% 0%, rgba(110, 70, 200, 0.35), transparent 60%),
		radial-gradient(90% 60% at 50% 110%, rgba(242, 200, 121, 0.12), transparent 60%),
		linear-gradient(180deg, #120d2b, var(--ink) 70%);
	overflow: hidden;
}

@media (min-width: 561px) {
	body {
		background:
			radial-gradient(80% 60% at 50% 0%, rgba(80, 50, 160, 0.3), transparent 70%),
			var(--ink);
	}
	.app {
		box-shadow: 0 0 80px rgba(0, 0, 0, 0.6);
	}
}

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

.hud {
	display: grid;
	grid-template-columns: 1fr auto 1fr auto;
	align-items: center;
	gap: 10px;
	padding: 10px 14px 0;
	min-height: 58px;
}

.app[data-screen='title'] .hud {
	visibility: hidden;
}

.hud__label {
	display: block;
	font-size: 0.68rem;
	letter-spacing: 0.14em;
	text-transform: uppercase;
	color: var(--muted);
}

.hud__value {
	display: block;
	font-size: 1.7rem;
	font-weight: 800;
	line-height: 1.05;
	font-variant-numeric: tabular-nums;
	color: var(--gold-2);
	text-shadow: 0 0 14px rgba(242, 200, 121, 0.45);
}

.hud__value--small {
	font-size: 1.15rem;
	color: var(--text);
	text-shadow: none;
}

.hud__value.is-bump {
	animation: bump 0.25s ease-out;
}

@keyframes bump {
	40% {
		transform: scale(1.18);
	}
}

.hud__best {
	text-align: right;
}

.hud__mid {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
}

.hud__time {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 4px;
}

.hud__time-text {
	font-weight: 800;
	font-size: 1.1rem;
	font-variant-numeric: tabular-nums;
}

.hud__time.is-low .hud__time-text {
	color: var(--rose);
	animation: bump 0.5s ease-out infinite;
}

.hud__bar {
	display: block;
	width: 92px;
	height: 6px;
	border-radius: 3px;
	background: rgba(255, 255, 255, 0.1);
	overflow: hidden;
}

.hud__bar-fill {
	display: block;
	height: 100%;
	width: 100%;
	background: linear-gradient(90deg, var(--gold), var(--gold-2));
	transform-origin: left;
}

.hud__time.is-low .hud__bar-fill {
	background: var(--rose);
}

.hud__chip {
	font-size: 0.65rem;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	padding: 2px 8px;
	border-radius: 99px;
	border: 1px solid rgba(178, 133, 255, 0.6);
	color: #d9c6ff;
}

.icon-button {
	width: 44px;
	height: 44px;
	display: grid;
	place-items: center;
	border-radius: 14px;
	border: 2px solid rgba(242, 200, 121, 0.55);
	background: rgba(26, 20, 56, 0.8);
	cursor: pointer;
}

.icon-button svg {
	width: 20px;
	height: 20px;
	fill: var(--gold);
}

.icon-button:active {
	transform: scale(0.94);
}

/* ---- Stage ---- */

.stage {
	flex: 1;
	min-height: 0;
	width: 100%;
	display: block;
	touch-action: none;
}

/* ---- Screens ---- */

.screen {
	position: absolute;
	inset: 0;
	padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + 18px) calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 18px);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	z-index: 5;
}

.screen--title {
	gap: 10px;
	text-align: center;
}

.screen--modal {
	background: rgba(8, 6, 20, 0.72);
	-webkit-backdrop-filter: blur(6px);
	backdrop-filter: blur(6px);
	animation: fade-in 0.2s ease-out;
}

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

.logo__gems {
	display: flex;
	gap: 6px;
	justify-content: center;
	margin-bottom: 4px;
}

.logo__gems img {
	width: 44px;
	height: 44px;
	animation: gem-bob 2.4s ease-in-out infinite;
}

@keyframes gem-bob {
	50% {
		transform: translateY(-7px) rotate(4deg);
	}
}

.logo__name {
	margin: 0;
	font-size: clamp(2.8rem, 14vw, 4.2rem);
	font-weight: 900;
	letter-spacing: 0.04em;
	line-height: 1;
	background: linear-gradient(180deg, #fff4d6 10%, var(--gold) 55%, #d98a4a 100%);
	-webkit-background-clip: text;
	background-clip: text;
	color: transparent;
	filter: drop-shadow(0 3px 0 var(--lead)) drop-shadow(0 0 18px rgba(242, 200, 121, 0.45));
}

.logo__tag {
	margin: 0 0 18px;
	color: var(--muted);
	font-size: 0.95rem;
}

.menu {
	display: flex;
	flex-direction: column;
	gap: 10px;
	width: min(100%, 300px);
}

.menu--row {
	flex-direction: row;
	justify-content: center;
	width: 100%;
}

.menu--left {
	align-items: flex-start;
}

.menu__row {
	display: flex;
	gap: 10px;
}

.menu__row > * {
	flex: 1;
}

.button {
	position: relative;
	min-height: 46px;
	padding: 10px 16px;
	border-radius: 16px;
	border: 2px solid rgba(242, 200, 121, 0.5);
	background: linear-gradient(180deg, var(--ink-3), var(--ink-2));
	box-shadow: 0 4px 0 var(--lead), inset 0 1px 0 rgba(255, 255, 255, 0.12);
	font-weight: 700;
	font-size: 1rem;
	cursor: pointer;
	transition: transform 0.08s, box-shadow 0.08s;
}

.button:active {
	transform: translateY(3px);
	box-shadow: 0 1px 0 var(--lead), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.button:focus-visible,
.icon-button:focus-visible,
.toast:focus-visible {
	outline: 3px solid var(--gold-2);
	outline-offset: 2px;
}

.button--big {
	min-height: 58px;
	font-size: 1.2rem;
	font-weight: 800;
	border-color: var(--gold);
	background: linear-gradient(180deg, #4a3790, #2b2060);
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 1px;
}

.button--big small {
	font-size: 0.75rem;
	font-weight: 600;
	color: var(--gold-2);
	opacity: 0.85;
}

.button--small {
	min-height: 40px;
	font-size: 0.9rem;
	padding: 8px 14px;
}

.button--danger {
	border-color: rgba(255, 93, 115, 0.6);
}

.button--install {
	border-color: #7ef0a0;
	background: linear-gradient(180deg, #23604a, #173c30);
}

.ios-hint {
	position: relative;
	margin-top: 14px;
	max-width: 300px;
	padding: 10px 34px 10px 14px;
	border-radius: 14px;
	background: rgba(26, 20, 56, 0.9);
	border: 1px solid rgba(242, 200, 121, 0.35);
	font-size: 0.88rem;
	line-height: 1.4;
	text-align: left;
}

.ios-hint p {
	margin: 0;
}

.ios-hint__icon {
	width: 18px;
	height: 18px;
	vertical-align: -3px;
	fill: none;
	stroke: #6cb8ff;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.ios-hint__close {
	position: absolute;
	top: 2px;
	right: 2px;
	width: 32px;
	height: 32px;
	border: 0;
	background: none;
	font-size: 1.3rem;
	color: var(--muted);
	cursor: pointer;
}

.arcade-link {
	color: var(--muted);
	font-size: 0.9rem;
	margin-top: 6px;
}

.version {
	margin: 8px 0 0;
	font-size: 0.72rem;
	color: rgba(179, 168, 214, 0.6);
}

/* ---- Panels ---- */

.panel {
	width: min(100%, 360px);
	max-height: 100%;
	padding: 22px 20px 20px;
	border-radius: 24px;
	border: 2px solid var(--gold);
	background: linear-gradient(180deg, rgba(42, 33, 84, 0.97), rgba(20, 15, 44, 0.97));
	box-shadow: 0 0 0 4px var(--lead), 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 40px rgba(242, 200, 121, 0.15);
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	text-align: center;
	animation: panel-in 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
}

@keyframes panel-in {
	from {
		transform: scale(0.85) translateY(20px);
		opacity: 0;
	}
}

.panel--scroll {
	overflow-y: auto;
	touch-action: pan-y;
	overscroll-behavior: contain;
	align-items: stretch;
	text-align: left;
}

.panel--scroll .panel__title,
.panel--scroll > .menu {
	align-self: center;
}

.panel__title {
	margin: 0;
	font-size: 1.9rem;
	font-weight: 900;
	color: var(--gold-2);
}

.panel__kicker {
	margin: 0;
	font-size: 0.8rem;
	letter-spacing: 0.16em;
	text-transform: uppercase;
	color: var(--rose);
}

.panel__sub {
	margin: 10px 0 0;
	font-size: 1rem;
	letter-spacing: 0.12em;
	text-transform: uppercase;
	color: var(--gold);
}

.panel__note {
	margin: 0;
	font-size: 0.85rem;
	color: var(--muted);
}

.final {
	margin: 0;
	font-size: 3.2rem;
	font-weight: 900;
	line-height: 1;
	color: var(--gold-2);
	text-shadow: 0 0 22px rgba(242, 200, 121, 0.6);
	font-variant-numeric: tabular-nums;
}

.new-best {
	margin: -4px 0 0;
	font-weight: 900;
	color: #7ef0a0;
	letter-spacing: 0.08em;
	animation: bump 0.6s ease-out infinite;
}

.stats {
	margin: 0;
	width: 100%;
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 8px;
}

.stats div {
	padding: 8px;
	border-radius: 12px;
	background: rgba(255, 255, 255, 0.05);
}

.stats dt {
	font-size: 0.7rem;
	color: var(--muted);
}

.stats dd {
	margin: 2px 0 0;
	font-weight: 800;
	font-size: 1.1rem;
}

/* ---- Settings ---- */

.settings {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.toggle {
	display: flex;
	align-items: center;
	justify-content: space-between;
	min-height: 44px;
	padding: 4px 4px 4px 12px;
	border-radius: 12px;
	background: rgba(255, 255, 255, 0.05);
	font-weight: 600;
	cursor: pointer;
}

.toggle input {
	appearance: none;
	-webkit-appearance: none;
	width: 52px;
	height: 30px;
	margin: 0 6px 0 0;
	border-radius: 15px;
	background: #3a3166;
	position: relative;
	cursor: pointer;
	transition: background 0.15s;
}

.toggle input::after {
	content: '';
	position: absolute;
	top: 3px;
	left: 3px;
	width: 24px;
	height: 24px;
	border-radius: 50%;
	background: #d8d0f0;
	transition: transform 0.15s;
}

.toggle input:checked {
	background: var(--gold);
}

.toggle input:checked::after {
	transform: translateX(22px);
	background: #fff;
}

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

.lab {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.seg {
	margin: 0;
	padding: 0;
	border: 0;
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.seg legend {
	width: 100%;
	padding: 0;
	margin-bottom: 6px;
	font-size: 0.85rem;
	font-weight: 700;
	color: var(--text);
}

.seg label {
	flex: 1;
	min-width: 0;
	cursor: pointer;
}

.seg input {
	position: absolute;
	opacity: 0;
	pointer-events: none;
}

.seg span {
	display: flex;
	align-items: center;
	justify-content: center;
	min-height: 40px;
	padding: 6px 8px;
	border-radius: 10px;
	border: 1.5px solid rgba(179, 168, 214, 0.3);
	background: rgba(255, 255, 255, 0.04);
	font-size: 0.85rem;
	font-weight: 600;
	text-align: center;
}

.seg input:checked + span {
	border-color: #b285ff;
	background: rgba(178, 133, 255, 0.25);
	color: #fff;
}

.seg input:focus-visible + span {
	outline: 3px solid var(--gold-2);
}

/* ---- Tutorial ---- */

.tutorial {
	min-height: 330px;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
}

.tutorial canvas {
	width: 220px;
	height: 150px;
}

.tutorial h3 {
	margin: 0;
	font-size: 1.35rem;
	color: var(--gold-2);
}

.tutorial p {
	margin: 0;
	color: var(--text);
	line-height: 1.45;
	max-width: 290px;
}

.tutorial kbd {
	font-family: inherit;
	font-size: 0.8rem;
	padding: 1px 6px;
	border-radius: 6px;
	border: 1px solid var(--muted);
}

.tutorial__dots {
	display: flex;
	gap: 8px;
}

.tutorial__dots span {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
}

.tutorial__dots span.is-on {
	background: var(--gold);
}

/* ---- Banner and toast ---- */

.banner {
	position: absolute;
	left: 0;
	right: 0;
	top: 42%;
	z-index: 6;
	text-align: center;
	font-size: clamp(2.4rem, 12vw, 3.4rem);
	font-weight: 900;
	color: var(--gold-2);
	text-shadow: 0 4px 0 var(--lead), 0 0 26px rgba(242, 200, 121, 0.7);
	pointer-events: none;
	animation: banner-in 0.5s cubic-bezier(0.2, 1.5, 0.4, 1);
}

@keyframes banner-in {
	from {
		transform: scale(2);
		opacity: 0;
	}
}

.toast {
	position: absolute;
	left: 50%;
	bottom: calc(var(--safe-bottom) + 18px);
	z-index: 20;
	transform: translateX(-50%);
	padding: 12px 18px;
	border-radius: 99px;
	border: 2px solid var(--gold);
	background: var(--ink-2);
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
	font-weight: 700;
	white-space: nowrap;
	cursor: pointer;
	animation: toast-in 0.3s ease-out;
}

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

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

@media (max-height: 640px) {
	.logo__gems img {
		width: 34px;
		height: 34px;
	}
	.logo__tag {
		margin-bottom: 8px;
	}
	.button--big {
		min-height: 50px;
	}
}
