/*
 * PureCSS.com
 * https://purecss.com/falling-snow/
 * Falling snow in three depth layers, each flake one element: the element falls, its ::before sways.
 */

/*
 * The stage sets no ground of its own, so the snow sits on whatever is behind
 * it. Each flake is white with a cool blue halo: on a dark ground the halo
 * reads as a soft glow, on a light one it is the edge that shows the flake.
 */
.demo-falling-snow .snow-stage {
	position: relative;
	width: 100%;
	height: 260px;
	overflow: hidden;
	border-radius: var(--radius-lg);
}

/*
 * A flake element is a column as tall as the stage. Moving it down by 100% of
 * its own height plus a little moves the dot on top of it from just above the
 * stage to just below it, whatever height the stage has, so the loop wraps
 * out of sight. The cycles below set only custom properties, which the
 * duration and delay read, so no rule resets another's animation longhands.
 */
.demo-falling-snow .flake {
	position: absolute;
	top: 0;
	bottom: 0;
	width: var(--size);
	animation: fs-fall linear infinite;
	animation-duration: calc(var(--fall) * var(--speed) * var(--pace, 1));
	animation-delay: calc(var(--fall) * var(--speed) * var(--pace, 1) * var(--start) * -1);
}

/* the dot itself, which owns the sideways sway on its own clock */
.demo-falling-snow .flake::before {
	content: "";
	position: absolute;
	bottom: 100%;
	left: 0;
	width: var(--size);
	height: var(--size);
	border-radius: 50%;
	background: #ffffff;
	opacity: var(--glow, 1);
	box-shadow: 0 0 4px 1px rgba(96, 132, 184, .8), 0 1px 2px rgba(40, 70, 120, .35);
	animation: fs-sway ease-in-out infinite alternate;
	animation-duration: var(--sway);
	animation-delay: calc(var(--sway) * var(--start) * -2);
}

/* three depth layers, every third flake: far ones are small, dim and slow */
.demo-falling-snow .flake:nth-child(3n+1) { --size: 3px; --glow: .6; --fall: 15s; --sway: 4.2s; }

.demo-falling-snow .flake:nth-child(3n+2) { --size: 5px; --glow: .85; --fall: 10.5s; --sway: 3.4s; }

.demo-falling-snow .flake:nth-child(3n) { --size: 8px; --glow: 1; --fall: 7.5s; --sway: 2.7s; }

/* ten columns across */
.demo-falling-snow .flake:nth-child(10n+1) { left: 3%; }

.demo-falling-snow .flake:nth-child(10n+2) { left: 13%; }

.demo-falling-snow .flake:nth-child(10n+3) { left: 22%; }

.demo-falling-snow .flake:nth-child(10n+4) { left: 32%; }

.demo-falling-snow .flake:nth-child(10n+5) { left: 41%; }

.demo-falling-snow .flake:nth-child(10n+6) { left: 51%; }

.demo-falling-snow .flake:nth-child(10n+7) { left: 60%; }

.demo-falling-snow .flake:nth-child(10n+8) { left: 70%; }

.demo-falling-snow .flake:nth-child(10n+9) { left: 79%; }

.demo-falling-snow .flake:nth-child(10n) { left: 89%; }

/* a speed and a small sideways nudge, every fourth flake */
.demo-falling-snow .flake:nth-child(4n+1) { --speed: 1; }

.demo-falling-snow .flake:nth-child(4n+2) { --speed: 1.17; margin-left: 3%; }

.demo-falling-snow .flake:nth-child(4n+3) { --speed: .88; margin-left: -2%; }

.demo-falling-snow .flake:nth-child(4n) { --speed: 1.08; margin-left: 5%; }

/* where in its fall each flake starts, every seventh: negative delays, so the
   stage is already full on the first frame */
.demo-falling-snow .flake:nth-child(7n+1) { --start: .05; }

.demo-falling-snow .flake:nth-child(7n+2) { --start: .62; }

.demo-falling-snow .flake:nth-child(7n+3) { --start: .31; }

.demo-falling-snow .flake:nth-child(7n+4) { --start: .87; }

.demo-falling-snow .flake:nth-child(7n+5) { --start: .44; }

.demo-falling-snow .flake:nth-child(7n+6) { --start: .18; }

.demo-falling-snow .flake:nth-child(7n) { --start: .73; }

/* the fade at each end matters when the stage has no visible edge: without
   it a flake would pop in and out of nothing at the clip line */
@keyframes fs-fall {
	from { transform: translateY(0); opacity: 0; }
	10%  { opacity: 1; }
	88%  { opacity: 1; }
	to   { transform: translateY(calc(100% + 12px)); opacity: 0; }
}

/* a percentage of the dot's own width, so a near flake sways further than a
   far one, which is what parallax would do */
@keyframes fs-sway {
	from { transform: translateX(-160%); }
	to   { transform: translateX(160%); }
}

/* stopped, not removed: paused where their delays put them, the flakes stay
   on the stage as a still snowfall */
@media (prefers-reduced-motion: reduce) {
	.demo-falling-snow .flake,
	.demo-falling-snow .flake::before {
		animation-play-state: paused;
	}
}

/* ── Variant: a snow globe ── */

.demo-falling-snow .snow-globe {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding-block: .5rem;
}

.demo-falling-snow .globe-glass {
	position: relative;
	width: 200px;
	height: 200px;
	overflow: hidden;
	border-radius: 50%;
	background: radial-gradient(circle at 50% 35%, #2c4a7a 0%, #172a4d 60%, #0e1a33 100%);
	box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .22), inset -14px -18px 36px rgba(4, 10, 24, .55);
}

/* the glass's highlight, over the snow */
.demo-falling-snow .globe-glass::after {
	content: "";
	position: absolute;
	top: 14%;
	left: 18%;
	width: 34%;
	height: 22%;
	border-radius: 50%;
	background: radial-gradient(ellipse at 40% 40%, rgba(255, 255, 255, .38), rgba(255, 255, 255, 0) 70%);
	transform: rotate(-28deg);
}

/* the snow on the floor of the globe and the tree standing in it */
.demo-falling-snow .globe-ground {
	position: absolute;
	left: -10%;
	right: -10%;
	bottom: -38%;
	height: 60%;
	border-radius: 50%;
	background: radial-gradient(ellipse at 50% 20%, #ffffff, #d5e2f2 70%);
}

.demo-falling-snow .globe-tree {
	position: absolute;
	left: 50%;
	bottom: 24%;
	width: 64px;
	height: 86px;
	margin-left: -32px;
	background: linear-gradient(#2f8f5b, #1f6b44);
	clip-path: polygon(50% 0, 70% 30%, 62% 30%, 84% 62%, 74% 62%, 100% 100%, 0 100%, 26% 62%, 16% 62%, 38% 30%, 30% 30%);
}

.demo-falling-snow .globe-base {
	width: 150px;
	height: 40px;
	margin-top: -14px;
	border-radius: 6px 6px 14px 14px;
	background: linear-gradient(#7a4a2c, #4f2e1a);
	clip-path: polygon(8% 0, 92% 0, 100% 100%, 0 100%);
}

/* a smaller globe's snow falls faster and sways less far than the open sky's */
.demo-falling-snow .globe-glass .flake {
	--pace: .55;
}

/* ── Variant: a storm over a snowbank ── */

.demo-falling-snow .snow-storm {
	position: relative;
	width: 100%;
	height: 260px;
	overflow: hidden;
	border-radius: var(--radius-lg);
	background: linear-gradient(180deg, #3b4a63 0%, #5d6f8c 70%, #8193ae 100%);
}

/* the same flakes and cycles, on a slanted path at a third of the time */
.demo-falling-snow .snow-storm .flake {
	--pace: .32;
	animation-name: fs-gust;
}

/* the settled snow: three overlapping mounds, drawn in front of the flakes so
   the falling snow disappears into it */
.demo-falling-snow .snow-bank {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	height: 64px;
	background:
		radial-gradient(ellipse 40% 70% at 18% 100%, #ffffff 98%, transparent 100%),
		radial-gradient(ellipse 45% 60% at 62% 100%, #f3f7fc 98%, transparent 100%),
		radial-gradient(ellipse 35% 80% at 96% 100%, #e6eef8 98%, transparent 100%);
}

/* the path starts left of the flake's column and ends right of it, so the
   wind carries snow in from the left edge as well as out at the right */
@keyframes fs-gust {
	from { transform: translate(-70px, 0); }
	to   { transform: translate(70px, calc(100% + 12px)); }
}
