/* Christmas snow over the home page slider (Pages/Shared/_XmasSnowSlider.cshtml; switched by HomePage:ChristmasSlider).
   The legacy effect (index_____SNOW.asp) was three tiled snow images drifting behind each other. Same idea here, but the layers are
   moved with transform instead of background-position, so the browser does not repaint the slider on every frame. */

#slider.xmas-slider { background-color: #020816; } /* the image's own dark blue, shown until the slider has started */

.xmas-snow {
    position: absolute;
    inset: 0;
    z-index: 100; /* over the slide and its captions, under the header */
    overflow: hidden;
    pointer-events: none; /* the slide's buttons stay clickable */
    animation: xmas-snow-appear 3s ease-in-out both;
}

/* Each flake layer sways gently from side to side; its ::before falls. */
.xmas-snow > span {
    position: absolute;
    inset: 0;
    animation: xmas-snow-sway var(--sway-time) ease-in-out infinite alternate;
}

.xmas-snow > span::before {
    content: "";
    position: absolute;
    /* one tile above the slider, so falling by exactly one tile loops without a jump; wider than the slider, so swaying shows no edge */
    inset: calc(-1 * var(--tile)) calc(-1 * var(--sway)) 0;
    background: var(--flakes) 0 0 / var(--tile) var(--tile) repeat;
    animation: xmas-snow-fall var(--fall-time) linear infinite;
}

/* Speed of fall = --tile / --fall-time: about 50, 33 and 20 pixels a second. A longer --fall-time is a gentler fall. */
.xmas-snow-far  { --flakes: url("/images/xmas/snow-far.svg");  --tile: 400px; --fall-time: 20s; --sway: 12px; --sway-time: 7s; }
.xmas-snow-mid  { --flakes: url("/images/xmas/snow-mid.svg");  --tile: 500px; --fall-time: 15s; --sway: 24px; --sway-time: 6s; }
.xmas-snow-near { --flakes: url("/images/xmas/snow-near.svg"); --tile: 600px; --fall-time: 12s; --sway: 40px; --sway-time: 5s; }

/* Phones: smaller tiles keep a similar amount of snow on a narrow screen. */
@media (max-width: 767.98px) {
    .xmas-snow-far  { --tile: 300px; --fall-time: 17s; }
    .xmas-snow-mid  { --tile: 380px; --fall-time: 13s; --sway: 18px; }
    .xmas-snow-near { --tile: 460px; --fall-time: 11s; --sway: 26px; }
}

@keyframes xmas-snow-appear { from { opacity: 0; } to { opacity: 1; } }
@keyframes xmas-snow-fall   { from { transform: translate3d(0, 0, 0); } to { transform: translate3d(0, var(--tile), 0); } }
@keyframes xmas-snow-sway   { from { transform: translate3d(calc(-1 * var(--sway)), 0, 0); } to { transform: translate3d(var(--sway), 0, 0); } }

/* Visitors who have asked their device for less motion see still snow. */
@media (prefers-reduced-motion: reduce) {
    .xmas-snow, .xmas-snow > span, .xmas-snow > span::before { animation: none; }
}
