/*
 * Site-wide motion for the v2 pages (public/js/motion-v2.js).
 *
 * Every "before" state below is scoped to `html.skm-on`, which only
 * motion-v2.js sets, and which it never sets under prefers-reduced-motion.
 * So with no script, or reduced motion, every element is in its final state.
 * Only opacity and the independent `translate`/`scale` properties move:
 * they never cause layout, they run on the compositor on a phone, and they
 * never fight a `transform` the element already has.
 */

.skm-on [data-skm-reveal]:not(.skm-in) {
  opacity: 0;
  translate: 0 0.9rem;
}
.skm-on [data-skm-reveal] {
  transition: opacity 0.55s cubic-bezier(0.22, 1, 0.36, 1), translate 0.55s cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: calc(var(--skm-i, 0) * 60ms);
}

.skm-on [data-skm-fill]:not(.skm-in) { scale: 0 1; }
.skm-on [data-skm-fill="y"]:not(.skm-in) { scale: 1 0; }
.skm-on [data-skm-fill] {
  transform-origin: left center;
  transition: scale 0.8s cubic-bezier(0.22, 1, 0.36, 1);
  transition-delay: calc(var(--skm-i, 0) * 70ms + 0.1s);
}
.skm-on [data-skm-fill="y"] { transform-origin: center bottom; }

.skm-on [data-skm-pop]:not(.skm-in) { opacity: 0; scale: 0.6; }
.skm-on [data-skm-pop].skm-in {
  animation: skm-pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: calc(var(--skm-i, 0) * 70ms);
}
@keyframes skm-pop {
  0% { opacity: 0; scale: 0.6; }
  60% { opacity: 1; scale: 1.08; }
  100% { opacity: 1; scale: 1; }
}

/* A one-off highlight a page script puts on something that just changed
   (a killfeed row, a captured flag). Removed by the script when it ends. */
.skm-on .skm-flash { animation: skm-flash 1.4s ease-out both; }
@keyframes skm-flash {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--skm-flash, var(--sk-primary)) 70%, transparent); }
  100% { box-shadow: 0 0 0 0.75rem transparent; }
}

/* A burst of confetti over something of your own that just finished
   (data-skm-celebrate). Each piece is placed and moved by motion-v2.js and
   removed when it lands; the colours are the palette's own. */
.skm-confetti {
  position: fixed;
  z-index: 10050;
  width: 0.5rem;
  height: 0.3rem;
  border-radius: 1px;
  background: var(--sk-primary);
  pointer-events: none;
  translate: -50% -50%;
}
.skm-confetti[data-c="1"] { background: var(--sk-success); }
.skm-confetti[data-c="2"] { background: var(--sk-warning); }
.skm-confetti[data-c="3"] { background: var(--sk-info); }
.skm-confetti[data-c="4"] { background: var(--sk-danger); width: 0.35rem; height: 0.35rem; border-radius: 999px; }

/* The bell rings once when the unread count rises (public/js/notifications.js
   adds .skm-shake to both bell buttons and takes it off on animationend). */
.skm-on .skm-shake {
  transform-origin: 50% 15%;
  animation: skm-shake 0.8s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}
@keyframes skm-shake {
  0%, 100% { rotate: 0deg; }
  15% { rotate: 16deg; }
  30% { rotate: -14deg; }
  45% { rotate: 10deg; }
  60% { rotate: -7deg; }
  75% { rotate: 3deg; }
}

/* A new palette fades in instead of snapping (public/js/theme-v2.js puts
   .skm-theme-fade on <html> just before it changes data-theme and takes it
   off 350ms later). Only the colours move, once. */
html.skm-on.skm-theme-fade,
html.skm-on.skm-theme-fade *,
html.skm-on.skm-theme-fade *::before,
html.skm-on.skm-theme-fade *::after {
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease, fill 0.3s ease, stroke 0.3s ease, box-shadow 0.3s ease !important;
}

/* A player's name glides from the row that was clicked into the heading of
   their page (public/js/player-name.js names the row; views/player.ejs names
   the heading). Both ends must be one box, so the heading's name is
   inline-block. */
.cv2-player-name { display: inline-block; view-transition-name: skm-player; }
::view-transition-group(skm-player) { animation-duration: 0.45s; animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1); }

/* Page changes are a cross-document view transition on every v2 page
   (Skynet UI's data-sk-transition). Under reduced motion they become a plain
   page change: the framework does not say so itself. */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}

/* Belt and braces: the class is never set under reduced motion, but a
   preference changed after the page loaded must still stop everything. */
@media (prefers-reduced-motion: reduce) {
  .skm-on [data-skm-reveal],
  .skm-on [data-skm-fill],
  .skm-on [data-skm-pop] {
    opacity: 1 !important;
    translate: none !important;
    scale: none !important;
    transition: none !important;
    animation: none !important;
  }
  .skm-confetti { display: none; }
  .skm-on .skm-shake { animation: none !important; }
  html.skm-on.skm-theme-fade,
  html.skm-on.skm-theme-fade *,
  html.skm-on.skm-theme-fade *::before,
  html.skm-on.skm-theme-fade *::after { transition: none !important; }
}
@media print {
  .skm-on [data-skm-reveal],
  .skm-on [data-skm-fill],
  .skm-on [data-skm-pop] { opacity: 1 !important; translate: none !important; scale: none !important; }
}
