/* Falling leaves or hearts. Both are glyphs in Yarndings 20, a dingbat font hosted with the site (SIL Open Font License;
   see assets/fonts/fonts-license.txt). Each piece nests two layers so the motions do not fight:
     .leaf       falls from above the top edge to below the bottom edge (gusts sweep the whole layer, see below)
     .leaf-glyph sways in an arc and tumbles
   Positions, timing and colours come from assets/js/leaves.js through CSS custom properties (CSP-safe). */
@font-face {
  font-family: "Yarndings 20";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/yarndings-20.ttf") format("truetype");
}

.leaves { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: -1; }

.leaf {
  position: absolute; top: 0; left: var(--x);
  /* "backwards" holds the leaf above the screen during its start delay */
  animation: leaf-fall var(--dur) linear var(--delay) infinite backwards;
  will-change: transform;
}
.leaf-glyph {
  display: block;
  font-family: "Yarndings 20", serif; font-weight: 400; line-height: 1;
  font-size: var(--size); color: var(--c); opacity: var(--op);
  animation: leaf-sway var(--sway-dur) ease-in-out var(--sway-delay) infinite;
  will-change: transform;
}

/* Hearts: a soft dark halo keeps the white ones visible on pale pages (same idea as the snow flakes). */
.leaves.hearts .leaf-glyph {
  text-shadow: 0 0 2px rgba(0, 0, 0, 0.25), 0 0 1px rgba(0, 0, 0, 0.2);
}

@keyframes leaf-fall {
  from { transform: translate3d(0, -12vh, 0); }
  to   { transform: translate3d(0, 112vh, 0); }
}

/* A gust sweeps the whole layer off one edge of the screen, on an angle (down and across, so it reads as a gust carrying
   the leaves along). The layer stays off-screen after the sweep (forwards), so the leaves do not come back. The script
   swaps in a fresh set while they are out of view. */
@keyframes sweep-left {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  100% { transform: translate3d(-115vw, 22vh, 0) rotate(-12deg); }
}
@keyframes sweep-right {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); }
  100% { transform: translate3d(115vw, 22vh, 0) rotate(12deg); }
}
.leaves.blow-left { animation: sweep-left 2s cubic-bezier(0.5, 0, 0.8, 0.6) 1 forwards; }
.leaves.blow-right { animation: sweep-right 2s cubic-bezier(0.5, 0, 0.8, 0.6) 1 forwards; }
/* An arc, not a straight sway: the leaf swings out, back, out the other way and back, turning all the while. */
@keyframes leaf-sway {
  0%   { transform: translate3d(0, 0, 0) rotate(var(--rot)); }
  25%  { transform: translate3d(calc(var(--amp) * 1px), -6px, 0) rotate(calc(var(--rot) + 70deg)); }
  50%  { transform: translate3d(0, 0, 0) rotate(calc(var(--rot) + 150deg)); }
  75%  { transform: translate3d(calc(var(--amp) * -1px), 6px, 0) rotate(calc(var(--rot) + 230deg)); }
  100% { transform: translate3d(0, 0, 0) rotate(calc(var(--rot) + 360deg)); }
}

/* On/off button: same look and place as the snow button. */
.leaves-toggle {
  position: fixed; top: 0.6rem; right: 0.6rem; z-index: 10;
  font: italic 0.72rem/1 var(--font-body); padding: 0.3rem 0.5rem; border: 0; border-radius: 3px;
  background: rgba(255, 255, 255, 0.6); color: var(--muted); cursor: pointer; opacity: 0.8;
}
.leaves-toggle:hover { opacity: 1; color: var(--ink); }
.leaves-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; opacity: 1; }
@media (max-width: 899px) { .leaves-toggle { top: auto; bottom: 0.6rem; } }

@media (prefers-reduced-motion: reduce) {
  .leaves, .leaves-toggle { display: none; }
}
