/* Gentle motion over still cover designs, chosen per design by "motion" in templates/manifest.json.
   Markup (src/helpers.php cover_motion_overlay / cover_motion_classes):
     <WRAPPER class="... has-motion motion-NAME">   positioned box around the cover <img>
       <img ...>
       <span class="cover-motion cover-motion--NAME" aria-hidden="true"></span>
     </WRAPPER>
   The wrapper must already be positioned (it is for .book-cover, .tpl and .tpl-preview-frame).
   NAME: sparkle confetti snow petals hearts glow float bubbles stars leaves.
   Pure CSS: gradients and one text glyph, animated with transform and opacity only.
   Particle sizes are percentages of the cover, so thumbnails and the full card look alike.
   Nothing moves with reduced motion, in print, or while the PDF is captured. */

.cover-motion { position: absolute; inset: 0; z-index: 1; pointer-events: none; overflow: hidden; border-radius: inherit;
  container-type: size; contain: strict; }
.cover-motion[hidden] { display: none; }
.cover-motion::before, .cover-motion::after { content: ""; position: absolute; pointer-events: none; }

/* Falling layers: twice the cover's height, tiles of a quarter of that, moved down by exactly one tile per loop. */
.cover-motion--snow::before, .cover-motion--snow::after,
.cover-motion--confetti::before, .cover-motion--confetti::after,
.cover-motion--petals::before, .cover-motion--petals::after,
.cover-motion--leaves::before, .cover-motion--leaves::after {
  top: -100%; left: -6%; width: 112%; height: 200%; background-repeat: repeat; background-size: 50% 25%;
  animation: cover-motion-fall var(--cm-time, 26s) linear infinite; will-change: transform; }
@keyframes cover-motion-fall {
  0%   { transform: translate3d(0, 0, 0); }
  25%  { transform: translate3d(1.5%, 6.25%, 0); }
  50%  { transform: translate3d(0, 12.5%, 0); }
  75%  { transform: translate3d(-1.5%, 18.75%, 0); }
  100% { transform: translate3d(0, 25%, 0); }
}

/* Rising layers (bubbles): the same idea, upwards. */
.cover-motion--bubbles::before, .cover-motion--bubbles::after {
  top: 0; left: -6%; width: 112%; height: 200%; background-repeat: repeat; background-size: 50% 25%;
  animation: cover-motion-rise var(--cm-time, 30s) linear infinite; will-change: transform; }
@keyframes cover-motion-rise {
  0%   { transform: translate3d(0, 0, 0); }
  25%  { transform: translate3d(-1.5%, -6.25%, 0); }
  50%  { transform: translate3d(0, -12.5%, 0); }
  75%  { transform: translate3d(1.5%, -18.75%, 0); }
  100% { transform: translate3d(0, -25%, 0); }
}

/* Twinkling layers: still points that fade in and out, the two layers out of step. */
@keyframes cover-motion-twinkle {
  0%, 100% { opacity: .15; transform: scale(.985); }
  50%      { opacity: 1; transform: scale(1); }
}

/* Snow: soft white flakes, small and far, bigger and nearer. */
.cover-motion--snow { opacity: .75; }
.cover-motion--snow::before { --cm-time: 34s;
  background-image:
    radial-gradient(1.76% 1.44% at 10% 14%, rgba(255,255,255,.95), rgba(255,255,255,0)),
    radial-gradient(1.44% 1.2% at 46% 38%, rgba(255,255,255,.9), rgba(255,255,255,0)),
    radial-gradient(1.92% 1.6% at 78% 8%, rgba(255,255,255,.95), rgba(255,255,255,0)),
    radial-gradient(1.28% 1.04% at 28% 72%, rgba(255,255,255,.85), rgba(255,255,255,0)),
    radial-gradient(1.6% 1.36% at 66% 86%, rgba(255,255,255,.9), rgba(255,255,255,0)); }
.cover-motion--snow::after { --cm-time: 22s; background-size: 62% 25%; background-position: 20% 0;
  background-image:
    radial-gradient(2.56% 2.16% at 22% 28%, rgba(255,255,255,.8), rgba(255,255,255,0)),
    radial-gradient(2.24% 1.92% at 70% 60%, rgba(255,255,255,.75), rgba(255,255,255,0)),
    radial-gradient(2.88% 2.4% at 44% 92%, rgba(255,255,255,.7), rgba(255,255,255,0)); }

/* Confetti: small flat pieces in party colours. */
.cover-motion--confetti { opacity: .8; }
.cover-motion--confetti::before { --cm-time: 24s;
  background-image:
    radial-gradient(1.76% 0.72% at 12% 10%, #ff5d8f 60%, rgba(255,93,143,0)),
    radial-gradient(0.72% 1.6% at 40% 34%, #ffc93c 60%, rgba(255,201,60,0)),
    radial-gradient(1.6% 0.64% at 74% 18%, #4cc9f0 60%, rgba(76,201,240,0)),
    radial-gradient(0.8% 1.44% at 24% 64%, #7b5cf0 60%, rgba(123,92,240,0)),
    radial-gradient(1.6% 0.72% at 62% 78%, #6bd968 60%, rgba(107,217,104,0)),
    radial-gradient(0.72% 1.52% at 88% 52%, #ff8a3d 60%, rgba(255,138,61,0)); }
.cover-motion--confetti::after { --cm-time: 17s; background-size: 58% 25%; background-position: 30% 0;
  background-image:
    radial-gradient(0.8% 1.76% at 18% 30%, #ffc93c 60%, rgba(255,201,60,0)),
    radial-gradient(1.92% 0.8% at 54% 12%, #ff5d8f 60%, rgba(255,93,143,0)),
    radial-gradient(0.8% 1.76% at 80% 70%, #4cc9f0 60%, rgba(76,201,240,0)),
    radial-gradient(1.76% 0.8% at 36% 88%, #7b5cf0 60%, rgba(123,92,240,0)); }

/* Petals: soft pink ovals drifting down slowly. */
.cover-motion--petals { opacity: .7; }
.cover-motion--petals::before { --cm-time: 36s;
  background-image:
    radial-gradient(2.88% 1.44% at 14% 16%, #ffc2d4 55%, rgba(255,194,212,0)),
    radial-gradient(2.24% 1.28% at 58% 40%, #ffd9e4 55%, rgba(255,217,228,0)),
    radial-gradient(2.56% 1.36% at 84% 12%, #ffb0c8 55%, rgba(255,176,200,0)),
    radial-gradient(2.08% 1.2% at 32% 78%, #ffe3ec 55%, rgba(255,227,236,0)); }
.cover-motion--petals::after { --cm-time: 26s; background-size: 64% 25%; background-position: 40% 0;
  background-image:
    radial-gradient(1.44% 2.72% at 26% 30%, #ffc2d4 55%, rgba(255,194,212,0)),
    radial-gradient(3.2% 1.6% at 72% 66%, #ffb0c8 55%, rgba(255,176,200,0)); }

/* Leaves: warm autumn ovals drifting down. */
.cover-motion--leaves { opacity: .65; }
.cover-motion--leaves::before { --cm-time: 32s;
  background-image:
    radial-gradient(3.2% 1.52% at 16% 14%, #e8a33c 55%, rgba(232,163,60,0)),
    radial-gradient(1.6% 3.04% at 60% 42%, #c8553d 55%, rgba(200,85,61,0)),
    radial-gradient(2.88% 1.44% at 82% 18%, #9aa83f 55%, rgba(154,168,63,0)),
    radial-gradient(2.56% 1.36% at 30% 80%, #d9822b 55%, rgba(217,130,43,0)); }
.cover-motion--leaves::after { --cm-time: 23s; background-size: 66% 25%; background-position: 25% 0;
  background-image:
    radial-gradient(1.6% 3.2% at 24% 34%, #e8a33c 55%, rgba(232,163,60,0)),
    radial-gradient(3.52% 1.68% at 70% 72%, #b5482f 55%, rgba(181,72,47,0)); }

/* Bubbles: thin rings with a small shine, rising. */
.cover-motion--bubbles { opacity: .6; }
.cover-motion--bubbles::before { --cm-time: 38s;
  background-image:
    radial-gradient(3.84% 2.88% at 14% 22%, rgba(255,255,255,0) 62%, rgba(255,255,255,.85) 78%, rgba(255,255,255,0) 92%),
    radial-gradient(2.56% 1.92% at 56% 48%, rgba(255,255,255,0) 60%, rgba(255,255,255,.8) 78%, rgba(255,255,255,0) 92%),
    radial-gradient(3.2% 2.4% at 82% 14%, rgba(255,255,255,0) 62%, rgba(255,255,255,.8) 78%, rgba(255,255,255,0) 92%),
    radial-gradient(2.08% 1.6% at 34% 84%, rgba(255,255,255,0) 58%, rgba(255,255,255,.75) 76%, rgba(255,255,255,0) 92%); }
.cover-motion--bubbles::after { --cm-time: 27s; background-size: 60% 25%; background-position: 35% 0;
  background-image:
    radial-gradient(4.8% 3.6% at 26% 40%, rgba(255,255,255,0) 64%, rgba(255,255,255,.7) 80%, rgba(255,255,255,0) 92%),
    radial-gradient(2.88% 2.16% at 74% 76%, rgba(255,255,255,0) 60%, rgba(255,255,255,.75) 78%, rgba(255,255,255,0) 92%); }

/* Sparkle: small four point glints in warm white, twinkling over the whole picture. */
.cover-motion--sparkle { opacity: .85; }
.cover-motion--sparkle::before, .cover-motion--sparkle::after {
  inset: 0; background-repeat: repeat; animation: cover-motion-twinkle 3.6s ease-in-out infinite; }
.cover-motion--sparkle::before { background-size: 50% 33.34%;
  background-image:
    radial-gradient(1.44% 1.12% at 20% 24%, #fffbe8, rgba(255,251,232,0)),
    radial-gradient(5.12% 0.4% at 20% 24%, rgba(255,240,190,.9), rgba(255,240,190,0)),
    radial-gradient(0.48% 3.84% at 20% 24%, rgba(255,240,190,.9), rgba(255,240,190,0)),
    radial-gradient(1.12% 0.88% at 72% 68%, #fffbe8, rgba(255,251,232,0)),
    radial-gradient(3.84% 0.32% at 72% 68%, rgba(255,240,190,.85), rgba(255,240,190,0)),
    radial-gradient(0.4% 2.88% at 72% 68%, rgba(255,240,190,.85), rgba(255,240,190,0)); }
.cover-motion--sparkle::after { background-size: 40% 28%; background-position: 15% 10%; animation-delay: -1.8s;
  background-image:
    radial-gradient(1.28% 0.96% at 60% 30%, #fffbe8, rgba(255,251,232,0)),
    radial-gradient(4.48% 0.35% at 60% 30%, rgba(255,236,180,.85), rgba(255,236,180,0)),
    radial-gradient(0.45% 3.36% at 60% 30%, rgba(255,236,180,.85), rgba(255,236,180,0)); }

/* Stars: tiny white points twinkling, mostly in the upper part. */
.cover-motion--stars { opacity: .85; }
.cover-motion--stars::before, .cover-motion--stars::after {
  inset: 0 0 42% 0; background-repeat: repeat; animation: cover-motion-twinkle 5.2s ease-in-out infinite;
  -webkit-mask-image: linear-gradient(#000 55%, transparent); mask-image: linear-gradient(#000 55%, transparent); }
.cover-motion--stars::before { background-size: 25% 33.34%;
  background-image:
    radial-gradient(2.24% 2.24% at 30% 30%, #fff, rgba(255,255,255,0)),
    radial-gradient(1.6% 1.6% at 78% 70%, rgba(240,246,255,.95), rgba(255,255,255,0)); }
.cover-motion--stars::after { background-size: 33.34% 25%; background-position: 12% 8%; animation-delay: -2.6s;
  background-image:
    radial-gradient(1.92% 1.92% at 60% 20%, #fff, rgba(255,255,255,0)),
    radial-gradient(1.44% 1.44% at 18% 76%, rgba(240,246,255,.9), rgba(255,255,255,0)); }

/* Glow: a warm light that slowly breathes, and a soft sheen passing now and then. */
.cover-motion--glow::before { inset: -10%;
  background: radial-gradient(60% 45% at 50% 32%, rgba(255,236,196,.4), rgba(255,236,196,0) 70%);
  mix-blend-mode: screen; animation: cover-motion-breathe 9s ease-in-out infinite alternate; }
.cover-motion--glow::after { top: 0; bottom: 0; left: -60%; width: 60%;
  background: linear-gradient(100deg, rgba(255,255,255,0) 20%, rgba(255,255,255,.14) 50%, rgba(255,255,255,0) 80%);
  animation: cover-motion-sheen 14s ease-in-out infinite; }
@keyframes cover-motion-breathe { from { opacity: .25; } to { opacity: .85; } }
@keyframes cover-motion-sheen {
  0%, 62% { transform: translate3d(0, 0, 0); opacity: 0; }
  66% { opacity: 1; }
  96% { opacity: 1; }
  100% { transform: translate3d(370%, 0, 0); opacity: 0; }
}

/* Hearts: a few small pink hearts floating up and fading. One glyph, copied by text-shadow. */
.cover-motion--hearts { opacity: .75; }
.cover-motion--hearts::before, .cover-motion--hearts::after {
  content: "\2665\FE0E"; left: 0; top: 100%; line-height: 1; color: transparent;
  font-size: 14px; font-size: 4.2cqw; font-family: Arial, sans-serif;
  animation: cover-motion-hearts 16s ease-in-out infinite; will-change: transform, opacity; }
.cover-motion--hearts::before {
  text-shadow: 12cqw 0 #ff7aa2, 44cqw -14cqh #ff9bb8, 78cqw -6cqh #ff6f96, 26cqw -34cqh #ffb3c8, 64cqw -42cqh #ff86a8; }
.cover-motion--hearts::after { font-size: 11px; font-size: 3.2cqw; animation-delay: -8s;
  text-shadow: 30cqw -4cqh #ffa7c0, 88cqw -22cqh #ff7aa2, 8cqw -38cqh #ff9bb8, 54cqw -26cqh #ffc2d4; }
@keyframes cover-motion-hearts {
  0%   { transform: translate3d(0, 0, 0); opacity: 0; }
  12%  { opacity: 1; }
  80%  { opacity: 1; }
  100% { transform: translate3d(0, -150cqh, 0); opacity: 0; }
}

/* Float: a slow Ken Burns zoom and drift of the picture itself. */
.has-motion.motion-float > img:not(.book-cover-fill) {
  animation: cover-motion-float 9s ease-in-out infinite alternate; transform-origin: 50% 40%; }
@keyframes cover-motion-float {
  from { transform: scale(1) translate3d(0, 0, 0); }
  to   { transform: scale(1.06) translate3d(-1%, -1%, 0); }
}

/* Design picker: thumbnails move only when hovered, focused or chosen, to save power. */
.tpl.has-motion .cover-motion { display: none; }
.tpl.has-motion:is(:hover, :focus-visible, .sel) .cover-motion { display: block; }
.tpl.has-motion.motion-float:not(:hover, :focus-visible, .sel) > img { animation: none; }
.tpl-preview-frame { position: relative; width: min(100%, calc(72vh * 3 / 4)); margin-inline: auto; border-radius: 12px; overflow: hidden; line-height: 0; }
.tpl-preview .tpl-preview-frame img { max-height: none; border-radius: 0; }

/* No motion for people who ask for less, in print, or in the PDF capture. */
@media (prefers-reduced-motion: reduce) {
  .cover-motion { display: none !important; }
  .has-motion > img { animation: none !important; }
}
.card-book.is-capturing .cover-motion, .card-book.is-print .cover-motion { display: none !important; }
.card-book.is-capturing .has-motion > img, .card-book.is-print .has-motion > img { animation: none !important; transform: none !important; }
@media print {
  .cover-motion { display: none !important; }
  .has-motion > img { animation: none !important; transform: none !important; }
}
