/* the pieces of a scene that move (scene-motion.js): over the bare surface and under the envelope, or over the invitation */
.sm { position: absolute; inset: 0; pointer-events: none; }
.sm--back { z-index: 0; }
/* the surface carried on beyond the picture, under it, out to the edges of the screen */
.sm-ground { position: absolute; z-index: -1; max-width: none; pointer-events: none; user-select: none; }
.sm-ground[hidden] { display: none; }
/* the surface goes on, so the picture's edges no longer fade into a blurred backdrop */
.room.room--ground .room__photo, .room.room--ground .room__fg { -webkit-mask-image: none; mask-image: none; }
.sm--front { z-index: 2; }
.sm__part {
  position: absolute; display: block; max-width: none; user-select: none;
  animation: var(--d, 10s) cubic-bezier(.45, 0, .55, 1) var(--delay, 0s) infinite alternate both;
  animation-play-state: paused;
}
.sm__part[data-kind="sway"] { animation-name: sm-sway; }
.sm__part[data-kind="ripple"] { animation-name: sm-ripple; }
.sm__part[data-kind="bob"] { animation-name: sm-bob; }
.sm__part[data-kind="drift"] { animation-name: sm-drift; }
.sm__part[data-kind="lean"] { animation-name: sm-lean; }
.sm__part[data-still] { animation: none; }
/* all that stands before the invitation moves slowly to one side and the other, as one (a scene's "drift"); it begins in
   the middle of the way */
.sm--drift { animation: sm-layer-drift var(--sm-drift-d, 9s) cubic-bezier(.45, 0, .55, 1) calc(var(--sm-drift-d, 9s) * -.5) infinite alternate both paused; }

/* with a mouse the scene follows it a little (scene-motion.js sets --sm-x and --sm-y, -1 to 1): the nearer, the more */
.sm--back { translate: calc(var(--sm-x, 0) * 5px) calc(var(--sm-y, 0) * 3px); }
.room .card, .room #roomEnv { translate: calc(var(--sm-x, 0) * 10px) calc(var(--sm-y, 0) * 7px); }
.sm--front, .room #roomFg { translate: calc(var(--sm-x, 0) * 16px) calc(var(--sm-y, 0) * 12px); }
/* where the invitation stands on a table, the leaves and flames stay on the vases and candles that hold them (those are
   part of the picture), so they follow the picture, not the mouse */
.room--standing .sm--back, .room--standing .sm--front { translate: none; }
/* and the invitation, standing on the table, moves only half as far, so it does not seem to slide over it */
.room--standing .card, .room--standing #roomEnv { translate: calc(var(--sm-x, 0) * 5px) calc(var(--sm-y, 0) * 3px); }

/* it moves only while the invitation is open, and rests while the tab is hidden */
.guest[data-state="open"] .sm__part { animation-play-state: running; }
.guest[data-state="open"] .sm__part[data-kind]:not([data-still]) { will-change: transform; }
.guest[data-state="open"] .sm--drift { animation-play-state: running; will-change: transform; }
.guest[data-state="open"] .sm-asleep .sm__part, .guest[data-state="open"] .sm-asleep .sm--drift { animation-play-state: paused; }

/* a sprig or a leaf sways round the end of its stem */
@keyframes sm-sway {
  from { transform: rotate(calc(var(--a) * -1)); }
  to   { transform: rotate(var(--a)); }
}
/* a tall branch leans: its foot (and the ribbon lying at it) stays, its head moves a little towards the invitation (--b)
   and far away from it (--a) */
@keyframes sm-lean {
  from { transform: skewX(var(--b, 0deg)); }
  to   { transform: skewX(var(--a)); }
}
@keyframes sm-layer-drift {
  from { transform: translateX(var(--sm-drift-l, 0%)); }
  to   { transform: translateX(var(--sm-drift-r, 0%)); }
}
/* a ribbon turns a little round its far end and its curls stretch and ease */
@keyframes sm-ripple {
  from { transform: rotate(calc(var(--a) * -1)) skewX(-1deg) scale(1, .99); }
  to   { transform: rotate(var(--a)) skewX(1deg) scale(1, 1.01); }
}
/* a balloon lifts a touch, turns a little and swells */
@keyframes sm-bob {
  from { transform: translate(0, 0) rotate(calc(var(--a) * -.5)) scale(1); }
  to   { transform: translate(var(--tx), var(--ty)) rotate(var(--a)) scale(1.015); }
}
/* a petal drifts a little way and turns */
@keyframes sm-drift {
  from { transform: translate(calc(var(--tx) * -1), 0) rotate(calc(var(--a) * -1)); }
  to   { transform: translate(var(--tx), var(--ty)) rotate(var(--a)); }
}

/* a candle flame flickers round its foot: it stretches, leans and settles */
.sm__part[data-kind="flicker"]:not([data-still]) { animation-name: sm-flicker; }
@keyframes sm-flicker {
  0%   { transform: scale(1, 1) skewX(0deg); }
  30%  { transform: scale(.97, 1.05) skewX(var(--a)); }
  60%  { transform: scale(1.02, .97) skewX(calc(var(--a) * -.6)); }
  100% { transform: scale(.99, 1.03) skewX(calc(var(--a) * .4)); }
}

@media (prefers-reduced-motion: reduce) {
  .sm__part, .sm__part[data-kind], .sm__part[data-kind="flicker"]:not([data-still]),
  .guest[data-state="open"] .sm__part[data-kind]:not([data-still]),
  .sm--drift, .guest[data-state="open"] .sm--drift { animation: none; will-change: auto; }
}

/* a piece that comes in from its side once the invitation is in its place, and goes back out when the guest leads back */
.sm__part[data-enter] { opacity: 0; transition: translate 450ms ease-in, opacity 300ms ease; }
.sm__part[data-enter="left"] { translate: -70% 0; }
.sm__part[data-enter="right"] { translate: 70% 0; }
.guest[data-state="open"] .sm__part[data-enter] { translate: 0 0; opacity: 1; transition: translate 1100ms cubic-bezier(.2, .7, .2, 1) 150ms, opacity 500ms ease 150ms; }
/* or it shows slowly where it stands, and goes the same way */
.guest[data-state="open"] .sm__part[data-enter="fade"] { transition: opacity 1100ms ease 200ms; }
@media (prefers-reduced-motion: reduce) { .sm__part[data-enter] { translate: 0 0; transition: opacity 300ms ease; } }
/* a side piece's copy, leaving above the flying envelope when the guest leads back from the open page (scene-motion.js) */
.sm-leave { position: fixed; z-index: 8; max-width: none; pointer-events: none; transition: translate 450ms ease-in, opacity 380ms ease 60ms; }
