/*
 * Ambient effects — the shared layer, switch and control.
 *
 * The framework (includes/effects.php + effects.js) owns the two fixed layer
 * slots, the visitor's button and the settings. An effect only fills a layer
 * with its own animation. Nothing here is specific to rain.
 *
 * Two rules drive every number below.
 *
 * 1. An effect must never sit between the visitor and the page: the layers are
 *    `pointer-events: none`, they carry no text, and they are `aria-hidden`.
 *    Text, the dialogue cloud, the navigation and the controls stay above them
 *    in every view.
 * 2. The layers are transparent. There is no background colour anywhere in this
 *    file, because a page is not a demo — the site's own scenery is what shows
 *    through.
 *
 * Both views use the same two numbers, and the page's own layers were moved to
 * sit clear of them:
 *
 *   -1  the scenery (street view)
 *    0  `behind`   above the scenery and the page background, behind the figure
 *    2  `front`    in front of the figure
 *    3  text       panels, article, lists, rail — the name and the reading column
 *    4  the cloud  the dialogue balloon stays above the rain
 *    5  the bar
 *
 * The container is not at the end of `<body>` any more: `effects.js` moves it
 * into the page's own stacking context before the first start — into
 * `.wp-site-blocks`, right after `.wl-scene`, in the street view, and into
 * `.wl-dscene`, right after the artwork, in the distant view. That is what
 * makes the three modes mean something. While the container sat outside
 * `.wp-site-blocks { isolation: isolate }`, a `-1` layer painted under the
 * body's opaque paper (behind: no rain at all) and a `0` layer painted over
 * every page element (front: rain across the whole screen) — exactly what the
 * owner saw.
 *
 * The container itself must not become a stacking context: it carries no
 * z-index and no isolation, so its two children take part in the page's own
 * ordering and can straddle the figure.
 *
 * The layer size differs by view because the two scenes are built differently.
 * The street view's effect area is the window. The distant view's is the
 * scenery band, and that band's bottom edge already *is* the window's bottom
 * edge, so a layer that fills the band is the same thing measured correctly.
 */
.wl-fx {
	/* Present for its children only. No box, no paint, no stacking context. */
	position: static;
	z-index: auto;
	isolation: auto;
	contain: none;
}

.wl-fx__layer {
	overflow: hidden;
	/* A scene is not a target. */
	pointer-events: none;
	/* Nothing selectable, nothing focusable, nothing announced. */
	user-select: none;
	-webkit-user-select: none;
	contain: strict;
}

/*
 * The layer size is the window in both views.
 *
 * The street view's effect area was always the window. The distant view's used
 * to be the scenery band — the layer was `absolute; inset: 0` inside
 * `.wl-dscene`, which is a fixed strip only as tall as the artwork at the foot
 * of the page. The result was rain that fell over the bottom third of the
 * screen and stopped there: the band's top edge, not the top of anything the
 * visitor could see.
 *
 * A fixed layer inside the band still paints inside the band's stacking
 * context — `z-index: 6` on `.wl-dscene` is what keeps the rain behind the
 * reading column and lets the figure sit between the two layers — but its
 * containing block is the window, so `inset: 0` means the whole visible screen
 * again. The band only has `overflow-x: clip`, and a fixed descendant is not
 * clipped by an ancestor that is not in its containing-block chain, so the
 * vertical extent is the window in both views.
 */
[data-view="street"] .wl-fx__layer,
[data-view="distant"] .wl-fx__layer {
	position: fixed;
	inset: 0;
}

[data-view="street"] .wl-fx__layer--behind,
[data-view="distant"] .wl-fx__layer--behind {
	z-index: 0;
}

[data-view="street"] .wl-fx__layer--front,
[data-view="distant"] .wl-fx__layer--front {
	z-index: 2;
}

/* The figure must not become a stacking context, or the dialogue cloud inside
   it could not be lifted above the front layer: a z-index on the figure would
   seal everything in its subtree at that number. The cloud lifts on its own
   below, which only works while its ancestors up to the page's stacking
   context stay `z-index: auto`. */
[data-view="street"] .wl-ip.is-scene-fixed {
	z-index: auto;
}

[data-view="distant"] .wl-dscene .wl-ip {
	z-index: auto;
}

/*
 * The page's own furniture, lifted above the front layer.
 *
 * The selectors hang off the body class, not off `[data-wl-fx-root]`: these
 * elements are the layer's *siblings*, so the effect container cannot reach
 * them. `body.wl-view-street` is printed by the theme on every page of the
 * street view.
 *
 * The numbers are the theme's own (1 for the panels, auto for the name and the
 * rail) raised by hand, and this file is enqueued only while an effect is on
 * the page: a site with the effect switched off keeps the theme's stacking
 * exactly as it was. Everything named here is a *reading* surface — a panel,
 * the article, the list, the rail, the name, the role line, the social row, the
 * dialogue cloud. The rain may pass in front of the character; it may never
 * pass in front of a word.
 */
body.wl-view-street .wl-home__panel,
body.wl-view-street .wl-article,
body.wl-view-street .wl-list {
	position: relative;
	z-index: 3;
}

/*
 * The rail is the one surface that must keep its own positioning.
 *
 * It was in the list above, which set `position: relative` on it — and the
 * theme's `.wl-rail` is `position: sticky` on a desktop. The effect file is
 * enqueued only on pages where an effect is allowed, so with the effect on the
 * rail stopped sticking and scrolled away with the article while the distant
 * view's rail did not. Only the number is set here; whatever the theme says
 * about `position` stays true, and the phone's `position: static` (which is
 * what lets the header scroll away on a narrow screen) is untouched too.
 */
body.wl-view-street .wl-rail {
	z-index: 3;
}

/* `isolation: isolate` on the head seals the name inside it, so lifting the
   title alone would lift nothing: the head is what has to clear the rain. */
body.wl-view-street .wl-lead__head {
	z-index: 3;
}

/* The name, the role line and the social row are already transformed, which
   makes them stacking contexts of their own; they only need the number. */
body.wl-view-street .wl-stage .wp-block-site-title,
body.wl-view-street .wl-stage .wl-lead__role,
body.wl-view-street .wl-social {
	position: relative;
	z-index: 3;
}

/* The cloud sits above the rain in both views: it is the one part of the
   character that is *talking*, and a sentence half-hidden behind a strand is
   worse than a drop that never reaches the figure. The slot is inside the
   figure, whose z-index is `auto`, so this number reaches the page's own
   stacking context instead of being sealed inside the figure. */
body.wl-view-street .wl-bubble-slot,
body.wl-view-distant .wl-bubble-slot {
	position: relative;
	z-index: 4;
}

/*
 * The distant view's reading surfaces.
 *
 * There the scenery is a single fixed sheet at z-index 6, and by design it
 * paints *over* the reading column: the artwork's own transparent sky is what
 * lets the words through, its painted ground covers whatever scrolls behind it,
 * and that is why a long article sinks into the picture instead of stopping on
 * a hard line above it.
 *
 * The column was lifted to 7 here for a while, to keep the rain off the words.
 * That fixed one symptom and broke the composition the view exists for: the
 * article then painted over the house, the trees and the ground, and the
 * transparent part of the artwork had nothing left to reveal. The rain is kept
 * out of the reading area geometrically instead — see `cutReadingSurfaces()` in
 * effects.js, which cuts the column's rectangle out of the two layers. The rail
 * keeps its own number because it is the page's navigation, not the article's
 * paper, and it never overlaps the sheet.
 */
body.wl-view-distant .wld-home__main,
body.wl-view-distant .wld-top {
	position: relative;
	z-index: 7;
}

/*
 * The reading column, cut out of the rain.
 *
 * Four gradients, unioned: everything left of the column, everything right of
 * it, everything above it and everything below it. Their union is the window
 * with one rectangle missing, so the drops keep falling over the scenery, the
 * margins and the rail while the reading area stays dry — including the gaps
 * between lines, images, video and tables, because the cut is the column's box
 * rather than the text's glyphs.
 *
 * The numbers come from the layout, not from this file: `cutReadingSurfaces()`
 * writes them as custom properties on the container, and the default values
 * here mean "no cut at all" (a zero-width left strip, a right strip that starts
 * at the far edge, zero-height strips top and bottom), so a page where the
 * function never runs is exactly what it was before.
 */
[data-view="distant"] .wl-fx__layer {
	-webkit-mask-image:
		linear-gradient(to right, #000 0 var(--wl-fx-cut-l, 0px), transparent var(--wl-fx-cut-l, 0px)),
		linear-gradient(to right, transparent 0 var(--wl-fx-cut-r, 100vw), #000 var(--wl-fx-cut-r, 100vw)),
		linear-gradient(to bottom, #000 0 var(--wl-fx-cut-t, 0px), transparent var(--wl-fx-cut-t, 0px)),
		linear-gradient(to bottom, transparent 0 var(--wl-fx-cut-b, 0vh), #000 var(--wl-fx-cut-b, 0vh));
	-webkit-mask-repeat: no-repeat;
	mask-image:
		linear-gradient(to right, #000 0 var(--wl-fx-cut-l, 0px), transparent var(--wl-fx-cut-l, 0px)),
		linear-gradient(to right, transparent 0 var(--wl-fx-cut-r, 100vw), #000 var(--wl-fx-cut-r, 100vw)),
		linear-gradient(to bottom, #000 0 var(--wl-fx-cut-t, 0px), transparent var(--wl-fx-cut-t, 0px)),
		linear-gradient(to bottom, transparent 0 var(--wl-fx-cut-b, 0vh), #000 var(--wl-fx-cut-b, 0vh));
	mask-repeat: no-repeat;
}

/*
 * The street view is not cut: its rail is a sticky column beside the article
 * rather than a sheet the article scrolls behind, and its rain already falls
 * behind every reading surface there (see the list at the top of this file).
 */

/*
 * A drop of rain.
 *
 * The animation is Aaron Rickle's CSS rain (MIT, see includes/effects.php):
 * a 120px box that falls the height of the viewport on a linear loop, carrying
 * a 60%-tall 1px stem that fades out at the end of each pass. Three things are
 * deliberately different from the original pen:
 *
 * - it falls to `--wl-fx-end` instead of `90vh`. That variable is the bottom of
 *   the visible window — the fall's own frame, not the character's feet —
 *   measured on every resize and converted into the layer's own coordinates
 *   (the distant view's layer is a band at the foot of the page, not the whole
 *   viewport), minus the stem's offset inside the box;
 * - there is no `.splat`. The pen's splash, ripple and puddle belong to a demo
 *   of standing water; this is rain in the air over a landscape;
 * - the colour comes from a custom property, so one stylesheet serves both
 *   views and any colour the owner picks.
 */
.wl-fx__drop {
	position: absolute;
	top: 0;
	width: 15px;
	height: var(--wl-fx-drop-h, 120px);
	pointer-events: none;
	animation-name: wl-fx-fall;
	animation-timing-function: linear;
	animation-iteration-count: infinite;
}

@keyframes wl-fx-fall {
	0% {
		transform: translateY(calc(-1 * var(--wl-fx-drop-h, 120px)));
	}

	72%,
	100% {
		transform: translateY(var(--wl-fx-end, 60vh));
	}
}

.wl-fx__stem {
	width: 1px;
	height: 60%;
	margin-left: 7px;
	pointer-events: none;
	background: linear-gradient(to bottom, var(--wl-fx-c0, rgba(59, 74, 92, 0)), var(--wl-fx-c1, rgba(59, 74, 92, 1)));
	animation-name: wl-fx-stem;
	animation-timing-function: linear;
	animation-iteration-count: infinite;
}

@keyframes wl-fx-stem {
	0%,
	65% {
		opacity: 1;
	}

	75%,
	100% {
		opacity: 0;
	}
}

/*
 * Reduced motion is honoured by not starting, not by animating more slowly —
 * effects.js never starts an effect on its own and stops one that is running
 * when the preference turns on. This block is the belt to that braces: if a
 * stylesheet is ever the only thing loaded, the strands still hold still
 * instead of drifting across the page.
 */
@media (prefers-reduced-motion: reduce) {
	[data-wl-fx-root][data-state="on"] .wl-fx__drop {
		animation: none;
		opacity: 0;
	}
}
