/* Winter Scene Background: layered scene behind the page. The stage keeps the artwork's 1672:941 frame and
   covers the viewport with ~4% to spare on every side, so the parallax never shows an edge. Layer positions are
   in percent of the stage (from the layout the art was composed with). */

@media (min-width: 651px) {
	body {
		background-image: none !important;
		background-color: #dfe7f8 !important;
	}
}

#cfan-winter-scene {
	position: fixed;
	inset: 0;
	z-index: -1;
	overflow: hidden;
	pointer-events: none;
	user-select: none;
	background: #dfe7f8;
	contain: strict;
}

#cfan-winter-scene .ws-stage {
	--ar: 1.77683;
	--cover: 108;        /* stage size in % of the viewport, at least; the spare room absorbs the parallax */
	--shift: 0px;        /* moves the whole scene right on wide screens (see below) */
	position: absolute;
	width: max(calc(var(--cover) * 1vw), calc(var(--cover) * 1vh * var(--ar)));
	height: max(calc(var(--cover) * 1vh), calc(var(--cover) * 1vw / var(--ar)));
	/* keep the left third (the character) in view when the screen is narrower than 16:9 */
	left: 32%;
	top: 46%;
	transform: translate(calc(-32% + var(--shift)), -46%);
}

/* wide screens: the script lines her face up against the page column by setting --shift (positive = right);
   the stage grows here so that shift has room without showing an edge. */
@media (min-width: 2200px) {
	#cfan-winter-scene .ws-stage {
		--cover: 114;
		--shift: 0px;
	}
}

#cfan-winter-scene .ws-layer {
	position: absolute;
	inset: 0;
	will-change: transform;
}

/* each picture is a <picture> (AVIF, else WebP) that takes no room of its own: the image is laid out as before */
#cfan-winter-scene picture {
	display: contents;
}

#cfan-winter-scene img {
	position: absolute;
	display: block;
	max-width: none;
	height: auto;
	border: 0;
	box-shadow: none;
	-webkit-user-drag: none;
}

#cfan-winter-scene .ws-bg {
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
}

/* character */
#cfan-winter-scene .ws-float {
	position: absolute;
	inset: 0;
	transform-origin: 30% 100%;
	animation: ws-float 9s ease-in-out infinite;
}

/* Her size: 1 = as drawn. Scaling keeps the right edge of her face (31.40% of the stage, i.e. 50.49% into her
   image) and her bottom edge (the stage bottom) where they are. */
#cfan-winter-scene .ws-stage {
	--ws-girl-scale: 0.9;
}

#cfan-winter-scene .ws-girl {
	width: calc(67.6435% * var(--ws-girl-scale));
	left: calc(31.40% - 34.150% * var(--ws-girl-scale));
	top: calc(100% - 97.6621% * var(--ws-girl-scale));
}

@keyframes ws-float {
	0%, 100% { transform: translate3d(0, 0, 0) rotate(0deg); }
	25%      { transform: translate3d(0.15%, -0.55%, 0) rotate(-0.25deg); }
	50%      { transform: translate3d(0, -0.95%, 0) rotate(0.1deg); }
	75%      { transform: translate3d(-0.15%, -0.45%, 0) rotate(0.25deg); }
}

/* foreground */
#cfan-winter-scene .ws-branch {
	position: absolute;
	left: -8.9713%;
	top: -10.8395%;
	width: 56.1603%;
	height: 43.8895%;
	transform-origin: 6% 62%;
	animation: ws-sway 11s ease-in-out infinite;
}

#cfan-winter-scene .ws-branch-img,
#cfan-winter-scene .ws-lantern-img {
	left: 0;
	top: 0;
	width: 100%;
}

@keyframes ws-sway {
	0%, 100% { transform: rotate(0deg); }
	30%      { transform: rotate(0.8deg); }
	65%      { transform: rotate(-0.5deg); }
}

#cfan-winter-scene .ws-lantern {
	position: absolute;
	left: -3.5287%;
	top: 56.9607%;
	width: 37.6196%;
	height: 43.2519%;
}

/* warm light breathing in the lantern glass */
#cfan-winter-scene .ws-glow {
	position: absolute;
	left: 24.4%;
	top: 30.4%;
	width: 34%;
	aspect-ratio: 1;
	transform: translate(-50%, -50%);
	border-radius: 50%;
	background: radial-gradient(circle, rgba(255, 222, 160, 0.55) 0%, rgba(255, 210, 150, 0.22) 35%, rgba(255, 205, 150, 0) 70%);
	mix-blend-mode: screen;
	animation: ws-glow 4.6s ease-in-out infinite;
}

@keyframes ws-glow {
	0%, 100% { opacity: 0.75; }
	20%      { opacity: 0.95; }
	45%      { opacity: 0.7; }
	60%      { opacity: 1; }
	80%      { opacity: 0.8; }
}

#cfan-winter-scene .ws-snow {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}

/* ── Night ──────────────────────────────────────────────────────────────────────────────────────────────
   When the page is dark (<html data-theme="dark">, as the Yukimi theme sets it) the scene turns to a snowy
   night: a deep blue wash over the art (lighter round her face), and the lantern lit, its warm light falling
   on her coat, the flowers and the fence, the snow around it and the air, flickering like a candle; a faint
   cool light from the sky catches her hair. The light layers are blended onto the scene (screen); the light on
   her and on the flowers is cut to their shapes with their own pictures. The snowflakes near the lamp turn
   warm (winter-scene.js). */

#cfan-winter-scene .ws-filters {
	position: absolute;
	width: 0;
	height: 0;
}

#cfan-winter-scene .ws-night-tint,
#cfan-winter-scene .ws-night-art,
#cfan-winter-scene .ws-lights {
	opacity: 0;
	visibility: hidden;
	transition: opacity 0.9s ease, visibility 0s linear 0.9s;
	pointer-events: none;
}

html[data-theme="dark"] #cfan-winter-scene {
	background: #0c1325;
}

html[data-theme="dark"] #cfan-winter-scene .ws-night-tint,
html[data-theme="dark"] #cfan-winter-scene .ws-night-art,
html[data-theme="dark"] #cfan-winter-scene .ws-lights {
	opacity: 1;
	visibility: visible;
	transition: opacity 0.9s ease, visibility 0s;
}

/* the foreground at night: a recoloured copy of the branch and the lantern group (the same deep blue as the
   wash; a filter rather than a blended layer, so their soft edges stay clean), crossfading with the day art */
#cfan-winter-scene .ws-night-art {
	filter: url(#ws-night-art);
}

#cfan-winter-scene .ws-day-art {
	transition: opacity 0.9s ease;
}

html[data-theme="dark"] #cfan-winter-scene .ws-day-art {
	opacity: 0;
}

#cfan-winter-scene .ws-night-tint {
	position: absolute;
	inset: 0;
	mix-blend-mode: multiply;
	background:
		radial-gradient(ellipse 28% 36% at 30% 30%, #7685ba 0%, rgba(118, 133, 186, 0) 100%),
		radial-gradient(ellipse 80% 90% at 30% 45%, #45528a 0%, #2b3564 55%, #192046 100%);
}

#cfan-winter-scene .ws-lights {
	mix-blend-mode: screen;
}

#cfan-winter-scene .ws-lights span {
	position: absolute;
	display: block;
}

/* the sky: a faint glow behind the snow clouds */
#cfan-winter-scene .ws-sky-glow {
	inset: 0;
	background: radial-gradient(ellipse 55% 38% at 50% 0%, rgba(110, 140, 220, 0.18) 0%, rgba(110, 140, 220, 0) 100%);
}

/* the lamp's light on the snow around its post (the lamp is at 5.65% / 70.1% of the stage) */
#cfan-winter-scene .ws-lamp-pool {
	left: 5.65%;
	top: 84%;
	width: 46%;
	aspect-ratio: 2.6;
	transform: translate(-50%, -50%);
	border-radius: 50%;
	background: radial-gradient(ellipse closest-side, rgba(255, 176, 96, 0.42) 0%, rgba(255, 160, 80, 0.14) 55%, rgba(255, 160, 80, 0) 100%);
}

/* the light on her: positioned and cut out like her picture (see .ws-girl); the lamp's place in her picture
   follows from its place on the stage and her scale */
#cfan-winter-scene .ws-girl-light {
	width: calc(67.6435% * var(--ws-girl-scale));
	left: calc(31.40% - 34.150% * var(--ws-girl-scale));
	top: calc(100% - 97.6621% * var(--ws-girl-scale));
	aspect-ratio: 1810 / 1470;
	-webkit-mask: var(--ws-girl-mask) 0 0 / 100% 100% no-repeat;
	mask: var(--ws-girl-mask) 0 0 / 100% 100% no-repeat;
}

#cfan-winter-scene .ws-girl-warm {
	--lamp-x: calc((5.65% - 31.40% + 34.150% * var(--ws-girl-scale)) / (0.676435 * var(--ws-girl-scale)));
	--lamp-y: calc((70.11% - 100% + 97.6621% * var(--ws-girl-scale)) / (0.976621 * var(--ws-girl-scale)));
	background: radial-gradient(ellipse 56% 48% at var(--lamp-x) var(--lamp-y), rgba(255, 176, 98, 0.72) 0%, rgba(255, 160, 86, 0.28) 36%, rgba(255, 150, 80, 0) 100%);
}

#cfan-winter-scene .ws-girl-cool {
	background: linear-gradient(212deg, rgba(160, 190, 255, 0.3) 0%, rgba(160, 190, 255, 0.08) 15%, rgba(160, 190, 255, 0) 28%);
}

/* the lantern group (lamp, flowers, fence): the glass, the light on the group, and the halo in the air */
#cfan-winter-scene .ws-lantern-light {
	inset: 0;
	-webkit-mask: var(--ws-lantern-mask) 0 0 / 100% 100% no-repeat;
	mask: var(--ws-lantern-mask) 0 0 / 100% 100% no-repeat;
	background: radial-gradient(circle at 24.4% 30.4%, rgba(255, 196, 116, 0.55) 0%, rgba(255, 178, 100, 0.42) 10%, rgba(255, 160, 86, 0.18) 28%, rgba(255, 150, 80, 0) 55%);
}

/* browsers that can choose a picture by its type cut the lights with the AVIF; others keep the WebP above */
@supports (mask-image: image-set(url("x.avif") type("image/avif"))) {
	#cfan-winter-scene .ws-girl-light {
		-webkit-mask: var(--ws-girl-mask-set) 0 0 / 100% 100% no-repeat;
		mask: var(--ws-girl-mask-set) 0 0 / 100% 100% no-repeat;
	}
	#cfan-winter-scene .ws-lantern-light {
		-webkit-mask: var(--ws-lantern-mask-set) 0 0 / 100% 100% no-repeat;
		mask: var(--ws-lantern-mask-set) 0 0 / 100% 100% no-repeat;
	}
}

#cfan-winter-scene .ws-lamp-halo {
	left: 24.4%;
	top: 30.4%;
	width: 150%;
	aspect-ratio: 1;
	transform: translate(-50%, -50%);
	border-radius: 50%;
	background: radial-gradient(circle closest-side, rgba(255, 196, 120, 0.4) 0%, rgba(255, 176, 100, 0.16) 22%, rgba(255, 160, 86, 0.05) 50%, rgba(255, 160, 86, 0) 100%);
}

#cfan-winter-scene .ws-lamp-core {
	left: 24.4%;
	top: 30.4%;
	width: 20%;
	aspect-ratio: 1;
	transform: translate(-50%, -50%);
	border-radius: 50%;
	background: radial-gradient(circle closest-side, rgba(255, 242, 206, 1) 0%, rgba(255, 208, 140, 0.62) 38%, rgba(255, 180, 100, 0) 100%);
}

/* a candle's flicker, the same on everything the lamp lights */
html[data-theme="dark"] #cfan-winter-scene :is(.ws-lamp-pool, .ws-girl-warm, .ws-lantern-light, .ws-lamp-halo, .ws-lamp-core) {
	animation: ws-flicker 3.4s linear infinite;
}

@keyframes ws-flicker {
	0%   { opacity: 1; }
	6%   { opacity: 0.93; }
	11%  { opacity: 1; }
	19%  { opacity: 0.96; }
	27%  { opacity: 0.86; }
	31%  { opacity: 0.98; }
	44%  { opacity: 0.94; }
	52%  { opacity: 1; }
	63%  { opacity: 0.9; }
	68%  { opacity: 0.99; }
	79%  { opacity: 0.95; }
	88%  { opacity: 0.88; }
	93%  { opacity: 1; }
	100% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
	#cfan-winter-scene .ws-float,
	#cfan-winter-scene .ws-branch,
	#cfan-winter-scene .ws-glow,
	html[data-theme="dark"] #cfan-winter-scene :is(.ws-lamp-pool, .ws-girl-warm, .ws-lantern-light, .ws-lamp-halo, .ws-lamp-core) {
		animation: none;
	}
	#cfan-winter-scene .ws-night-tint,
	#cfan-winter-scene .ws-lights {
		transition: none;
	}
}

/* phones: keep the theme's own plain look (it drops its background image there too) */
@media (max-width: 650px) {
	#cfan-winter-scene {
		display: none;
	}
}
