/*
  Weather on the /pictures gallery.

  The sky: a band behind the gallery row, below the photo. It takes a soft
  wash of the current photo's scene color. Lightning, rain, snow, and hail
  also play there once each time a photo comes forward, and sun adds a faint
  yellow glow. Every other scene is color only. Sizes are in container units
  (cqh, cqw) so the weather fits the band at any width.

  The preview: only ice shows anything under the current print, icicles
  growing down from its bottom edge. Each card's li carries its scene in
  data-tag for the page sky.
*/

.picture-sky .tag-icon {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- ice: icicles grow down from the print; a shine slides down each ---------- */

.picture-browser .picture-icicles {
  position: absolute;
  z-index: 1;
  top: 100%;
  right: 0;
  left: 0;
  display: block;
  height: 1.8rem;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  mask-image: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
  transition: opacity 400ms ease;
}

.picture-browser .is-current .picture-icicles {
  opacity: 1;
}

.picture-browser .picture-icicles i {
  position: absolute;
  top: 0;
  display: block;
  width: var(--w);
  height: var(--h);
  margin-left: calc(var(--w) / -2);
  background:
    linear-gradient(170deg, transparent 40%, rgb(255 255 255 / 95%) 50%, transparent 60%) 0 120% / 100% 300% no-repeat,
    linear-gradient(90deg, #a5f3fc, #f0fdff 45%, #cffafe 60%, #67e8f9);
  clip-path: polygon(0 0, 100% 0, 55% 100%, 45% 100%);
  scale: 1 0;
  transform-origin: 50% 0;
  filter: drop-shadow(0 1px 1px rgb(8 145 178 / 40%));
}

.picture-browser .picture-icicles i:nth-of-type(1) { --w: 0.3rem; --h: 0.9rem; --pd: 0s; left: 16%; }
.picture-browser .picture-icicles i:nth-of-type(2) { --w: 0.22rem; --h: 0.55rem; --pd: 0.28s; left: 29%; }
.picture-browser .picture-icicles i:nth-of-type(3) { --w: 0.4rem; --h: 1.6rem; --pd: 0.1s; left: 44%; }
.picture-browser .picture-icicles i:nth-of-type(4) { --w: 0.26rem; --h: 0.75rem; --pd: 0.44s; left: 57%; }
.picture-browser .picture-icicles i:nth-of-type(5) { --w: 0.34rem; --h: 1.2rem; --pd: 0.18s; left: 70%; }
.picture-browser .picture-icicles i:nth-of-type(6) { --w: 0.2rem; --h: 0.5rem; --pd: 0.36s; left: 83%; }

.picture-browser .is-current .picture-icicles i {
  animation:
    weather-icicle 900ms var(--cover-ease) calc(0.25s + var(--pd)) forwards,
    weather-glint 4s ease-in-out calc(1.4s + var(--pd));
}

@keyframes weather-icicle {
  from { scale: 1 0; }
  to { scale: 1 1; }
}

/* Only the first background layer moves. */
@keyframes weather-glint {
  0% { background-position: 0 120%, 0 0; }
  50%, 100% { background-position: 0 -20%, 0 0; }
}

/* ---------- the sky behind the gallery row ---------- */

/* The glow is the scene color (--tag-color in pictures.css). */
.picture-sky {
  --glow: var(--tag-color, #64748b);
  --rain: rgb(71 85 105 / 55%);
  --snow: #94a3b8;
  --bolt-ink: #7c3aed;
  --bolt-glow: #c4b5fd;
  --flash: rgb(196 181 253 / 40%);
  position: relative;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  container-type: size;
}

[data-theme="dark"] .picture-sky {
  --rain: rgb(186 230 253 / 55%);
  --snow: #fff;
  --bolt-ink: #fff;
  --bolt-glow: #a78bfa;
  --flash: rgb(237 233 254 / 30%);
}

/* The scene color, brightest behind the current print. */
.picture-sky::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 60% 90% at 50% 40%, color-mix(in srgb, var(--glow) 16%, transparent), transparent 80%);
}

.picture-sky.is-fresh::before {
  animation: sky-in 900ms ease-out;
}

.picture-sky > * {
  position: absolute;
  display: block;
  pointer-events: none;
}

/* rain: streaks across the band. */
.sky-drop {
  top: -20cqh;
  left: var(--x);
  width: 1.5px;
  height: var(--size);
  opacity: 0;
  background: linear-gradient(transparent, var(--rain));
  animation: sky-fall var(--dur) linear var(--delay) var(--runs) both;
}

/* snow: six-armed flakes, three crossed bars each, drifting as they fall. */
.sky-flake,
.sky-flake::before,
.sky-flake::after {
  width: var(--size);
  height: var(--size);
  background: linear-gradient(var(--snow), var(--snow)) center / 1.5px 100% no-repeat;
}

.sky-flake {
  top: -10cqh;
  left: var(--x);
  opacity: 0;
  animation: sky-snow var(--dur) linear var(--delay) both;
}

.sky-flake::before,
.sky-flake::after {
  content: "";
  position: absolute;
  inset: 0;
  rotate: 60deg;
}

.sky-flake::after {
  rotate: -60deg;
}

/* hail: stones that come down hard. */
.sky-stone {
  top: -10cqh;
  left: var(--x);
  width: var(--size);
  height: var(--size);
  border: 1px solid #94a3b8;
  border-radius: 50%;
  opacity: 0;
  background: #f8fafc;
  animation: sky-hail var(--dur) cubic-bezier(0.5, 0, 1, 1) var(--delay) var(--runs) both;
}

/* storm: branching bolts strike across the band, and the sky flashes. */
.sky-bolt {
  top: 0;
  left: var(--x);
  width: calc(50cqh * var(--scale, 1));
  height: calc(100cqh * var(--scale, 1));
  opacity: 0;
  background: var(--bolt-ink);
  filter: drop-shadow(0 0 6px var(--bolt-glow)) drop-shadow(0 0 14px var(--bolt-glow));
  mask: var(--bolt) center top / contain no-repeat;
  animation: sky-strike 1.6s linear var(--delay) both;
}

.sky-bolt-a {
  --bolt: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 40' fill='none' stroke='black' stroke-linejoin='round' stroke-linecap='round'><path d='M11 0 9 6 12 10 8 17 10 21 6 29 8 33 5 40' stroke-width='1.1'/><path d='M12 10 15 14 14 18 17 23M10 21 13 25 12 28' stroke-width='0.7'/></svg>");
}

.sky-bolt-b {
  --bolt: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 40' fill='none' stroke='black' stroke-linejoin='round' stroke-linecap='round'><path d='M8 0 10 5 7 9 9 14 6 20 9 24 7 31 9 36 8 40' stroke-width='1.1'/><path d='M7 9 3 13 4 17 1 21M9 24 12 28 11 31' stroke-width='0.7'/></svg>");
}

.sky-bolt-c {
  --bolt: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 40' fill='none' stroke='black' stroke-linejoin='round' stroke-linecap='round'><path d='M12 0 10 7 13 12 10 18 12 23 9 30 11 40' stroke-width='1.1'/><path d='M13 12 16 15 15 20M10 18 6 22 7 26 4 31' stroke-width='0.7'/></svg>");
}

.sky-flash {
  inset: 0;
  opacity: 0;
  background: radial-gradient(ellipse 90% 70% at 50% 25%, var(--flash), transparent 80%);
  animation: sky-flash 4.5s linear 0.3s both;
}

/* sun: a faint yellow glow behind the current print. */
.sky-sun {
  inset: 0;
  opacity: 0;
  background: radial-gradient(ellipse 55% 85% at 50% 40%, rgb(255 214 10 / 18%), transparent 75%);
  animation: sky-sunny 1.6s ease-out 0.2s forwards;
}

@keyframes sky-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sky-fall {
  0% { opacity: 0; translate: 0 0; }
  8% { opacity: 1; }
  92% { opacity: 1; }
  100% { opacity: 0; translate: -3cqw 135cqh; }
}

@keyframes sky-snow {
  0% { opacity: 0; translate: 0 0; rotate: 0deg; }
  8% { opacity: 1; }
  33% { translate: 3cqw 40cqh; }
  66% { translate: -2cqw 80cqh; }
  92% { opacity: 1; }
  100% { opacity: 0; translate: 1cqw 120cqh; rotate: 240deg; }
}

@keyframes sky-hail {
  0% { opacity: 0; translate: 0 0; }
  6% { opacity: 1; }
  94% { opacity: 1; }
  100% { opacity: 0; translate: 0 125cqh; }
}

@keyframes sky-strike {
  0% { opacity: 0; }
  3% { opacity: 1; }
  6% { opacity: 0.15; }
  10% { opacity: 0.95; }
  22%, 100% { opacity: 0; }
}

@keyframes sky-flash {
  0%, 36% { opacity: 0; }
  37% { opacity: 0.7; }
  39%, 86% { opacity: 0; }
  87% { opacity: 1; }
  88% { opacity: 0.1; }
  90% { opacity: 0.85; }
  93%, 100% { opacity: 0; }
}

@keyframes sky-sunny {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .picture-browser .picture-icicles,
  .picture-browser .picture-icicles i,
  .picture-sky::before,
  .picture-sky > * {
    transition: none;
    animation: none;
  }

  .sky-sun {
    opacity: 1;
  }

  .picture-browser .picture-icicles i {
    scale: 1 1;
  }
}
