/* Rhythm bonus stage (js/rhythm-ui.js): one screen, HUD / note highway
   (canvas) / 4 pads. Lane colours are read by the canvas (--lane-N). */
:root {
	--lane-0: #ff6b1a;
	--lane-1: #ffc21a;
	--lane-2: #19b7f0;
	--lane-3: #ff3d7f;
}

/* Always dark, whatever the theme of the game: a night stage (its picture,
   its lanterns). The dark tokens of css/style.css, on the whole page while
   the stage or its results are on screen. */
:root:has(.app-rhythm, .app-results.is-rhythm) {
	--paper: #17141f;
	--panel: #26222f;
	--text: #f7f0e4;
	--muted: #b8afc2;
	--line: #050408;
	--halftone: rgba(255, 245, 227, 0.05);
	--accent-soft: #4a2611;
	--star-off: #3b3546;
	--good-soft: #113d25;
	--bad-soft: #4a1720;
	--review: #7fa8ff;
	color-scheme: dark;
}

.app-rhythm {
	height: 100dvh;
	overflow: hidden;
	gap: var(--sp-3);
}

/* Points of a right answer flying to the score (js/rhythm-ui.js), the score
   bumping when they land. Only transform and opacity animated. */
.rhythm-gain {
	position: fixed;
	left: 0;
	top: 0;
	z-index: 30;
	pointer-events: none;
	font-size: 22px;
	font-weight: 800;
	line-height: 1;
	white-space: nowrap;
	color: #fff5e3;
	text-shadow: 0 2px 0 #050408, 0 0 2px #050408;
	will-change: transform, opacity;
}

.rhythm-gain.is-perfect {
	font-size: 28px;
	color: var(--gold);
}

.rhythm-gain.is-combo {
	font-size: 32px;
	color: #dfe7f0;
	text-shadow: 0 2px 0 #050408, 0 0 10px rgba(207, 216, 227, 0.7);
}

.rhythm-gain.is-combo.is-gold {
	color: var(--gold);
	text-shadow: 0 2px 0 #050408, 0 0 12px rgba(255, 194, 26, 0.8);
}

.rhythm-gain small {
	margin-left: 3px;
	font-size: 0.6em;
}

.rhythm-gain.is-aided {
	font-size: 18px;
	color: var(--muted);
}

.app-rhythm .points b {
	display: inline-block;
}

.app-rhythm .points b.bump {
	animation: rhythm-bump 220ms var(--ease-back);
}

@keyframes rhythm-bump {
	50% {
		scale: 1.35;
		color: var(--gold);
	}
}

.rhythm-combo {
	flex: 1;
	display: flex;
	align-items: baseline;
	justify-content: center;
	gap: var(--sp-2);
	margin: 0;
	line-height: 1;
	font-variant-numeric: tabular-nums;
}

.rhythm-combo b {
	font-size: var(--fs-4);
	font-weight: 800;
}

.rhythm-combo span {
	padding: 2px var(--sp-2);
	border: 2px solid var(--line);
	border-radius: var(--r-full);
	background: var(--gold);
	color: var(--line);
	font-weight: 800;
}

/* A combo series not all perfect: silver (gold when every hit is perfect). */
.rhythm-combo span.is-silver {
	background: var(--silver);
}

/* Lanterns along both edges of the highway (placed by js/rhythm-ui.js in
   its perspective): a mistake puts one out, the song stops when all are
   out. The lit picture fades over the unlit one (opacity only). */
.rhythm-lanterns {
	position: absolute;
	inset: 0;
	pointer-events: none;
}

.lantern {
	position: absolute;
	left: var(--x, -100px);
	top: var(--y, 0);
	height: var(--h, 40px);
	aspect-ratio: 98 / 160;
	translate: -50% -50%;
}

.lantern img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}

.lantern .off {
	opacity: 0.7;
}

.lantern .on {
	transition: opacity 700ms var(--ease-out);
}

.lantern.is-out .on {
	opacity: 0;
}

/* Without the pictures (npm run art): the small icon. */
.lantern svg {
	width: 100%;
	height: 100%;
	fill: #ffb84a;
	stroke: var(--line);
	stroke-width: 1.6;
	transition: opacity 700ms var(--ease-out);
}

.lantern.is-out svg {
	fill: none;
	stroke: var(--muted);
	opacity: 0.5;
}

.rhythm-count {
	margin: 0;
	line-height: 1;
	font-variant-numeric: tabular-nums;
}

.rhythm-count b {
	font-size: var(--fs-3);
	font-weight: 800;
}

.rhythm-count span {
	margin-left: 2px;
	font-size: var(--fs-1);
	color: var(--muted);
}

.rhythm-wrap {
	flex: 1;
	min-height: 0;
	/* Never taller than a phone's: the fall lasts the same time on any
	   screen, on a tall tablet a note would cover many more pixels per frame
	   (it would look jerky). The stage and its pads stay centred. */
	max-height: 700px;
	margin-top: auto;
	position: relative;
	overflow: hidden;
	border: var(--bw) solid var(--line);
	border-radius: var(--r-3);
	background: var(--panel);
	box-shadow: var(--shadow);
}

.rhythm-wrap canvas {
	position: relative;
	/* Opaque, the picture drawn in it (js/rhythm-ui.js). */
	display: block;
	width: 100%;
	height: 100%;
}

.rhythm-live {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip-path: inset(50%);
}

.rhythm-ready {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	justify-content: center;
	gap: var(--sp-3);
	padding: var(--sp-4);
	overflow: auto;
	background: var(--panel);
}

.rhythm-ready[hidden] {
	display: none;
}

.rhythm-ready h1 {
	margin: 0;
	text-wrap: balance;
	font-size: var(--fs-5);
	line-height: 1.1;
}

.rhythm-ready p {
	margin: 0;
	color: var(--muted);
	line-height: 1.4;
}

.rhythm-sound {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--sp-2) var(--sp-3);
	padding: var(--sp-2) var(--sp-3);
	border: 2px dashed var(--muted);
	border-radius: var(--r-2);
}

.rhythm-sound p {
	flex: 1 1 12rem;
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	color: var(--text);
}

.rhythm-sound svg {
	flex: none;
	width: 22px;
	height: 22px;
}

.rhythm-sound .btn {
	display: inline-flex;
	align-items: center;
	gap: var(--sp-1);
	min-height: 44px;
	padding-inline: var(--sp-3);
	font-size: var(--fs-2);
}

.rhythm-kicker {
	margin: 0;
	font-size: var(--fs-1);
	font-weight: 800;
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--accent);
}

.rhythm-tempo {
	display: flex;
	align-items: center;
	gap: 2px;
	margin: 0;
	line-height: 1;
	font-variant-numeric: tabular-nums;
}

.rhythm-tempo svg {
	color: var(--lane-2);
}

.rhythm-tempo b {
	font-size: var(--fs-3);
	font-weight: 800;
}

.rhythm-pads {
	margin-bottom: auto;
	display: grid;
	grid-template-columns: repeat(4, 1fr);
	gap: var(--sp-2);
}

.pad {
	--c: var(--lane-0);
	position: relative;
	height: clamp(76px, 14vh, 108px);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: color-mix(in srgb, var(--c) 30%, var(--panel));
	box-shadow: 0 5px 0 var(--line), inset 0 -6px 0 var(--c);
	color: var(--text);
	font: inherit;
	font-size: clamp(1.5rem, 7vw, 2.1rem);
	font-weight: 800;
	font-variant-numeric: tabular-nums;
	cursor: pointer;
	touch-action: manipulation;
}

.pad:nth-child(2) {
	--c: var(--lane-1);
}

.pad:nth-child(3) {
	--c: var(--lane-2);
}

.pad:nth-child(4) {
	--c: var(--lane-3);
}

.pad:disabled {
	cursor: default;
	opacity: 0.6;
}

.pad kbd {
	position: absolute;
	top: 4px;
	left: 8px;
	font: inherit;
	font-size: var(--fs-1);
	text-transform: uppercase;
	color: var(--muted);
}

.pad.down {
	animation: pad-down 110ms ease-out;
}

.pad.is-answer {
	--c: var(--good);
	background: var(--good);
	color: var(--line);
	animation: pad-answer 600ms var(--ease-back) 3;
}

@keyframes pad-answer {
	50% {
		transform: scale(1.08);
	}
}

.pad.swap {
	animation: pad-swap 450ms var(--ease-back);
}

@keyframes pad-down {
	50% {
		transform: translateY(4px);
		box-shadow: 0 1px 0 var(--line), inset 0 -3px 0 var(--c);
		background: color-mix(in srgb, var(--c) 60%, var(--panel));
	}
}

@keyframes pad-swap {
	from {
		transform: scale(0.8);
		opacity: 0.3;
	}
}

.rhythm-detail dd {
	font-size: var(--fs-3);
}

/* Bonus stage offer (level sheet, results of a 3-star series). */
.rhythm-block {
	display: flex;
	align-items: center;
	gap: var(--sp-3);
	padding: var(--sp-3);
	border: var(--bw) solid var(--line);
	border-radius: var(--r-2);
	background: linear-gradient(110deg, color-mix(in srgb, var(--lane-2) 22%, var(--panel)), color-mix(in srgb, var(--lane-3) 22%, var(--panel)));
	text-align: left;
}

.rhythm-block.is-locked {
	border-style: dashed;
	background: none;
}

.rhythm-block .rhythm-text {
	flex: 1;
	margin: 0;
	line-height: 1.3;
}

.rhythm-block .rhythm-text b {
	display: block;
	font-size: var(--fs-3);
}

.rhythm-block .rhythm-text small {
	color: var(--muted);
}

.rhythm-block .btn {
	display: inline-flex;
	align-items: center;
	gap: var(--sp-1);
	flex: none;
	min-height: 44px;
	padding-inline: var(--sp-4);
	font-size: var(--fs-2);
	background: var(--gold);
	color: var(--line);
}

.results .rhythm-block {
	width: 100%;
}

@media (prefers-reduced-motion: reduce) {
	.lantern .on,
	.lantern svg {
		transition: none;
	}

	.pad.swap,
	.pad.down,
	.pad.is-answer {
		animation: none;
	}
}
