.tree-leaves { display: none; }
#desktopTreeLeaves { display: none; opacity: 0; }

@media (min-width: 769px) and (prefers-reduced-motion: no-preference) {
  html[data-sa-header-photo='wedding43'] #mainHeader.desktop-logo-colour:not(.header-scrolled) #desktopTreeLeaves {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
    contain: layout paint;
    -webkit-mask-image: linear-gradient(transparent, #000 5%, #000 88%, transparent);
    mask-image: linear-gradient(transparent, #000 5%, #000 88%, transparent);
  }
  #desktopTreeLeaves[data-active] { opacity: 1; }
  #desktopTreeLeaves .tree-leaf {
    position: absolute;
    top: -10px;
    left: var(--leaf-x);
    width: var(--leaf-size);
    height: calc(100% + 20px);
    animation: treeLeafFall var(--leaf-duration) linear var(--leaf-phase) infinite paused;
  }
  #desktopTreeLeaves .tree-leaf svg {
    display: block;
    width: 100%;
    height: auto;
    animation: treeLeafFlutter var(--leaf-flutter) ease-in-out var(--leaf-phase) infinite alternate paused;
  }
  #desktopTreeLeaves[data-active] .tree-leaf,
  #desktopTreeLeaves[data-active] .tree-leaf svg { animation-play-state: running; }
}

@media (max-width: 768px) and (prefers-reduced-motion: no-preference) {
  .tree-leaves {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 1;
    overflow: hidden;
    pointer-events: none;
    contain: layout paint;
    opacity: 0;
    transition: opacity 650ms ease-out;
    -webkit-mask-image: linear-gradient(transparent, #000 5%, #000 88%, transparent);
    mask-image: linear-gradient(transparent, #000 5%, #000 88%, transparent);
  }
  .tree-leaves[data-active] { opacity: 1; }
  :is(#treeHeaderLeaves, #treeCrossingLeaves)[data-concealed] { opacity: 0; transition: none; }
  body.menu-closing :is(#treeHeaderLeaves, #treeCrossingLeaves) { transition: none; }
  #treeCrossingLeaves {
    /* Outside both photo/slider clips. Its own fixed, paint-contained rectangle
       spans the rendered seam without enlarging either container or scroll area. */
    position: fixed;
    right: auto;
    bottom: auto;
    z-index: 3;
    -webkit-mask-image: linear-gradient(transparent, #000 6px, #000 var(--leaf-cross-fade), transparent 100%);
    mask-image: linear-gradient(transparent, #000 6px, #000 var(--leaf-cross-fade), transparent 100%);
  }
  #treeCrossingLeaves:not([data-active]) { transition: none; }
  #treeCrossingLeaves .tree-leaf { animation-duration: calc(var(--leaf-duration) * 1.8); }
  #treeMenuLeaves {
    /* Background photograph z=0, decoration z=1, navigation/controls z>=2. */
    bottom: auto;
    height: var(--leaf-field-height, 0px);
    -webkit-mask-image: linear-gradient(#000, #000 var(--leaf-fade-start), transparent 100%);
    mask-image: linear-gradient(#000, #000 var(--leaf-fade-start), transparent 100%);
    transition: none;
  }
  .tree-leaf {
    position: absolute;
    top: -10px;
    left: var(--leaf-x);
    width: var(--leaf-size);
    height: calc(100% + 20px);
    animation: treeLeafFall var(--leaf-duration) linear var(--leaf-phase) infinite;
    animation-play-state: paused;
  }
  .tree-leaf svg {
    display: block;
    width: 100%;
    height: auto;
    animation: treeLeafFlutter var(--leaf-flutter) ease-in-out var(--leaf-phase) infinite alternate;
    animation-play-state: paused;
  }
  .tree-leaves[data-active] .tree-leaf,
  .tree-leaves[data-active] .tree-leaf svg { animation-play-state: running; }
}

/* Invisible before wrapping to the top: no visible loop teleport. */
@keyframes treeLeafFall {
  0% { transform: translate3d(0, 0, 0); opacity: 0; }
  7% { opacity: .86; }
  36% { transform: translate3d(calc(var(--leaf-drift) * .35), 38%, 0); }
  52% { transform: translate3d(calc(var(--leaf-drift) * .7), 45%, 0); }
  90% { opacity: .86; }
  100% { transform: translate3d(var(--leaf-drift), 100%, 0); opacity: 0; }
}
@keyframes treeLeafFlutter {
  0% { transform: translateX(calc(var(--leaf-sway) * -1)) rotate(var(--leaf-turn)) scaleX(.65); }
  50% { transform: translateX(var(--leaf-sway)) rotate(calc(var(--leaf-turn) + 42deg)) scaleX(1); }
  100% { transform: translateX(calc(var(--leaf-sway) * -.4)) rotate(calc(var(--leaf-turn) + 95deg)) scaleX(.55); }
}
