/* Scene of a level series (js/series-scene.js): picture, guardian in the
   top right corner, petals. Calm on purpose: a veil so that the calculation
   reads first, few slow petals, the guardian moves only between questions.
   Only transform and opacity animated. */
.series-scene {
	position: fixed;
	inset: 0;
	z-index: 0;
	pointer-events: none;
	background: #0c0a16;
}

/* Wide screens: the same picture on both sides of the game column, darker. */
.scene-wide {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	opacity: 0.35;
}

/* The placed scene, as wide as the game column (js/series-scene.js). */
.scene-back {
	position: absolute;
	top: 0;
	bottom: 0;
	left: 0;
	width: 100%;
	overflow: hidden;
	background: #1d2a1f;
	box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
}

.scene-bg {
	position: absolute;
	left: 0;
	top: 0;
	max-width: none;
	transform-origin: 0 0;
}

/* A fixed scene not reaching the top or the bottom: a blurred copy of it
   fills the rest. */
.scene-fill {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	filter: blur(18px) brightness(0.85);
	transform: scale(1.1);
}

/* A frame around the column (a picture transparent in the middle), its
   edges always on the column's edges; not veiled. */
.scene-frame {
	position: absolute;
	inset: 0;
	z-index: 1;
	width: 100%;
	height: 100%;
	max-width: none;
}

.scene-back::after {
	content: '';
	position: absolute;
	inset: 0;
	/* --veil: the level's veil (js/series-scene.js), 0.35 by default. */
	background: rgba(12, 10, 22, var(--veil, 0.35));
}

.app.has-scene {
	position: relative;
	z-index: 1;
}

/* The question card under the guardian. The interface comes first: the
   screen never scrolls, the room kept for the guardian (a spacer, the card
   right under it) shrinks when the screen is short, the card then going
   over the guardian. */
.app-play.has-scene {
	height: 100vh;
	height: 100dvh;
	min-height: 0;
}

.app-play.has-scene .stage {
	justify-content: flex-start;
	min-height: 0;
}

.app-play.has-scene .stage::before {
	content: '';
	flex: 0 1 var(--scene-room, 0px);
	min-height: 0;
	margin-bottom: calc(-1 * var(--sp-4));
}

.scene-petals {
	position: absolute;
	inset: 0;
	overflow: hidden;
}

.scene-petals.is-leaves i {
	width: 13px;
	height: 11px;
	border-radius: 10% 80% 10% 80%;
	background: linear-gradient(135deg, #ffb15a, #e2562d);
	opacity: 0.65;
}

.scene-petals.is-wind i {
	width: 13px;
	height: 8px;
	border-radius: 10% 80% 10% 80%;
	background: linear-gradient(135deg, #c8f07a, #5fae3a);
	opacity: 0.65;
}

.scene-petals.is-snow i {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: radial-gradient(circle, #fff 35%, rgba(255, 255, 255, 0.35) 65%, transparent 72%);
	opacity: 0.85;
	animation-duration: calc(var(--dur) * 1.35);
}

/* One in three: a small ice crystal, catching the light as it turns. */
.scene-petals.is-snow i:nth-child(3n) {
	width: 9px;
	height: 11px;
	border-radius: 0;
	background: linear-gradient(135deg, #ffffff 10%, #bfe8ff 45%, #6cc0ff 80%);
	clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
	opacity: 0.8;
}

.scene-petals i {
	position: absolute;
	top: -6vh;
	left: var(--left);
	width: 12px;
	height: 9px;
	border-radius: 80% 10% 80% 10%;
	background: linear-gradient(135deg, #ffd6e8, #ff9fc8);
	opacity: 0.7;
	animation: scene-petal var(--dur) linear var(--delay) infinite;
}

@keyframes scene-petal {
	0% {
		transform: translate(0, 0) rotate(0deg);
	}
	50% {
		transform: translate(var(--drift), 55vh) rotate(160deg);
	}
	100% {
		transform: translate(calc(var(--drift) * -0.4), 112vh) rotate(320deg);
	}
}

.scene-guardian {
	position: fixed;
	z-index: 2;
	left: var(--gx);
	top: var(--gy);
	width: var(--gw);
	height: var(--gh);
	transform-origin: 50% 70%;
}

/* On the left of the screen: mirrored, to look at the calculation. */
.scene-guardian.is-mirrored {
	scale: -1 1;
}

.scene-guardian img {
	position: absolute;
	bottom: 0;
	left: 50%;
	height: 100%;
	translate: -50% 0;
	transition: opacity 120ms;
}

/* The right answer pose in the guardian's box: height, bottom and shift
   from the scene (cheer of SCENES, js/series-scene.js); by default standing
   on the stone, the feet where the sitting pose sits. */
.scene-guardian .cheer {
	opacity: 0;
	height: calc(var(--ch, 0.82) * 100%);
	bottom: calc(var(--cb, 0.3) * 100%);
	left: calc(50% + var(--cx, 0) * 100%);
}

/* The swaying pose (js/sway.js), placed by js/series-scene.js. */
.scene-guardian canvas.sway {
	transition: opacity 120ms;
}

.scene-guardian.is-cheering .sit {
	opacity: 0;
}

.scene-guardian.is-cheering .cheer {
	opacity: 1;
	animation: scene-hop 520ms var(--ease-back);
}

/* No right answer pose: the pose itself hops. */
.scene-guardian.is-hopping {
	animation: scene-hop-pose 520ms var(--ease-back);
}

@keyframes scene-hop-pose {
	40% {
		translate: 0 -8%;
	}
}

.scene-guardian.is-sad {
	animation: scene-tilt 700ms ease-in-out;
}

/* --cj: height of the hop (cheer j of SCENES), low for a pose that stays
   sitting. */
@keyframes scene-hop {
	40% {
		translate: -50% calc(var(--cj, 0.14) * -100%);
	}
}

@keyframes scene-tilt {
	30% {
		rotate: -4deg;
	}
	70% {
		rotate: 3deg;
	}
}

/* The scene's foreground (a railing...) over the guardian, placed and cut
   around it by js/series-scene.js; darker like the veil of the scene. */
.scene-front {
	position: absolute;
	top: 0;
	bottom: 0;
	z-index: 2;
	overflow: hidden;
}

.scene-front img {
	-webkit-mask-size: 100% 100%;
	mask-size: 100% 100%;
	-webkit-mask-repeat: no-repeat;
	mask-repeat: no-repeat;
	filter: brightness(calc(1 - var(--veil, 0.35)));
}

.series-bubble {
	position: fixed;
	z-index: 3;
	/* left, right, top, bottom from sceneLayout (js/series-scene.js). */
	max-width: min(60vw, 250px);
	margin: 0;
	padding: var(--sp-2) var(--sp-3);
	/* Comic / manga speech bubble: white, a thick black outline. */
	--bubble-border: 2px;
	border: var(--bubble-border) solid #000;
	border-radius: 20px;
	background: #fff;
	color: #000;
	font-weight: 800;
	line-height: 1.25;
	opacity: 0;
	translate: 0 6px;
	transition: opacity 200ms, translate 200ms var(--ease-back);
}

.series-bubble.show {
	opacity: 1;
	translate: 0 0;
}

/* The tail pointing at the guardian's mouth (drawBubbleTail): its black
   outline, then the white tail over the bubble's border; polygons in a box
   80 px larger than the bubble (TAIL_ROOM). None when the bubble had to go
   elsewhere. */
.series-bubble.has-tail::before,
.series-bubble.has-tail::after {
	content: '';
	position: absolute;
	inset: calc(-80px - var(--bubble-border));
	pointer-events: none;
}

.series-bubble.has-tail::before {
	background: #000;
	clip-path: var(--tail-out);
}

.series-bubble.has-tail::after {
	background: #fff;
	clip-path: var(--tail-in);
}

@media (prefers-reduced-motion: reduce) {
	.scene-petals {
		display: none;
	}

	.scene-guardian.is-cheering .cheer,
	.scene-guardian.is-hopping,
	.scene-guardian.is-sad {
		animation: none;
	}
}
