/*
 * Cowry League branded motion.
 *
 * Every animation here is PRESENTATION ONLY. None of it is on the path of the
 * simulation tick, a command, score, Energy, lives, waves, deterministic
 * replay, an integrity decision, the leaderboard or settlement. The renderer
 * draws server snapshots; motion decorates the chrome around them.
 *
 * Restraint rule from the M14 brief: wallet, Support, settings and Admin
 * surfaces stay operationally focused. Those surfaces set `data-motion="calm"`
 * on their root, which switches ambient motion off without touching layout.
 */

/* ── Ambient Cowry drift ────────────────────────────────────────────────── */

.cl-cowry-field {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.cl-cowry-drift {
  position: absolute;
  width: var(--size, 28px);
  height: var(--size, 28px);
  opacity: 0;
  background-image: var(--cl-cowry-mark);
  background-size: contain;
  background-repeat: no-repeat;
  filter: drop-shadow(0 0 10px rgba(212, 175, 55, 0.35));
  animation: cl-drift var(--duration, 22s) linear var(--delay, 0s) infinite;
  will-change: transform, opacity;
}

@keyframes cl-drift {
  0% {
    transform: translate3d(0, 18vh, 0) rotate(0deg);
    opacity: 0;
  }
  12% {
    opacity: var(--peak, 0.32);
  }
  88% {
    opacity: var(--peak, 0.32);
  }
  100% {
    transform: translate3d(var(--drift-x, 6vw), -22vh, 0) rotate(var(--spin, 40deg));
    opacity: 0;
  }
}

/* ── Gold shimmer / light sweep over brand surfaces ─────────────────────── */

.cl-shimmer {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.cl-shimmer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--cl-gold-sheen);
  transform: translateX(-140%);
  animation: cl-sweep 6.5s var(--cl-ease) infinite;
  pointer-events: none;
  z-index: 1;
}

@keyframes cl-sweep {
  0%,
  62% {
    transform: translateX(-140%);
  }
  100% {
    transform: translateX(140%);
  }
}

/* Gold glow pulse for a live/active brand element. */
.cl-glow {
  animation: cl-glow-pulse 3.4s ease-in-out infinite;
}

@keyframes cl-glow-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.28);
  }
  50% {
    box-shadow: 0 0 22px 3px rgba(212, 175, 55, 0.2);
  }
}

/* ── Depth / parallax ───────────────────────────────────────────────────── */

.cl-parallax {
  transform: translate3d(
    calc(var(--cl-pointer-x, 0) * var(--depth, 8px)),
    calc(var(--cl-pointer-y, 0) * var(--depth, 8px)),
    0
  );
  transition: transform var(--cl-motion-slow) var(--cl-ease-out);
  will-change: transform;
}

/* ── Entry / reveal ─────────────────────────────────────────────────────── */

.cl-rise {
  animation: cl-rise var(--cl-motion-slow) var(--cl-ease-out) both;
  animation-delay: var(--stagger, 0ms);
}

@keyframes cl-rise {
  from {
    opacity: 0;
    transform: translate3d(0, 14px, 0);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.cl-fade {
  animation: cl-fade var(--cl-motion) var(--cl-ease) both;
}

@keyframes cl-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Leaderboard / result row reveal, staggered by index. */
.cl-reveal-row {
  animation: cl-reveal-row 420ms var(--cl-ease-out) both;
  animation-delay: calc(var(--row-index, 0) * 55ms);
}

@keyframes cl-reveal-row {
  from {
    opacity: 0;
    transform: translate3d(-10px, 0, 0);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ── Celebration: reward, wallet credit, winner ─────────────────────────── */

.cl-celebrate {
  animation: cl-celebrate 900ms var(--cl-ease-out) both;
}

@keyframes cl-celebrate {
  0% {
    transform: scale(0.86);
    opacity: 0;
  }
  55% {
    transform: scale(1.04);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.cl-spark {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cl-gold);
  animation: cl-spark 1100ms var(--cl-ease-out) both;
  animation-delay: var(--delay, 0ms);
  pointer-events: none;
}

@keyframes cl-spark {
  0% {
    transform: translate3d(0, 0, 0) scale(0.4);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--dx, 0), var(--dy, -40px), 0) scale(0);
    opacity: 0;
  }
}

/* ── Micro-interactions ─────────────────────────────────────────────────── */

.cl-press {
  transition:
    transform var(--cl-motion-fast) var(--cl-ease),
    box-shadow var(--cl-motion-fast) var(--cl-ease),
    background-color var(--cl-motion-fast) var(--cl-ease);
}

.cl-press:hover:not(:disabled) {
  transform: translateY(-1px);
}

.cl-press:active:not(:disabled) {
  transform: translateY(1px) scale(0.995);
}

.cl-lift {
  transition:
    transform var(--cl-motion) var(--cl-ease-out),
    border-color var(--cl-motion) var(--cl-ease),
    box-shadow var(--cl-motion) var(--cl-ease-out);
}

.cl-lift:hover {
  transform: translateY(-3px);
  border-color: var(--cl-hairline-strong);
  box-shadow: var(--cl-shadow-gold);
}

/* ── Overlays: modal, drawer, route ─────────────────────────────────────── */

.cl-overlay-enter {
  animation: cl-fade var(--cl-motion) var(--cl-ease) both;
}

.cl-sheet-enter {
  animation: cl-sheet var(--cl-motion) var(--cl-ease-out) both;
}

@keyframes cl-sheet {
  from {
    transform: translate3d(0, 100%, 0);
  }
  to {
    transform: none;
  }
}

.cl-drawer-enter {
  animation: cl-drawer var(--cl-motion) var(--cl-ease-out) both;
}

@keyframes cl-drawer {
  from {
    transform: translate3d(-100%, 0, 0);
  }
  to {
    transform: none;
  }
}

/* ── Loading and success ────────────────────────────────────────────────── */

.cl-skeleton {
  background: linear-gradient(
    90deg,
    var(--cl-surface-2) 25%,
    var(--cl-surface-3) 50%,
    var(--cl-surface-2) 75%
  );
  background-size: 200% 100%;
  animation: cl-skeleton 1.4s linear infinite;
  border-radius: var(--cl-radius-sm);
}

@keyframes cl-skeleton {
  to {
    background-position: -200% 0;
  }
}

.cl-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(212, 175, 55, 0.25);
  border-top-color: var(--cl-gold);
  border-radius: 50%;
  animation: cl-spin 720ms linear infinite;
}

@keyframes cl-spin {
  to {
    transform: rotate(360deg);
  }
}

.cl-check-in {
  animation: cl-celebrate 520ms var(--cl-ease-out) both;
}

/* ── Restraint: operationally focused surfaces ──────────────────────────── */

[data-motion="calm"] .cl-cowry-field,
[data-motion="calm"] .cl-shimmer::after {
  display: none;
}

[data-motion="calm"] .cl-glow,
[data-motion="calm"] .cl-spark,
[data-motion="calm"] .cl-celebrate {
  animation: none;
}

[data-motion="calm"] .cl-lift:hover {
  transform: none;
}

/*
 * ── Reduced motion ──────────────────────────────────────────────────────
 *
 * The accessible fallback is static, not broken: every element that animates
 * in must still end up visible and in its final position, so `both` fill on a
 * cancelled animation is replaced by explicit final state.
 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }

  .cl-cowry-field {
    display: none;
  }

  .cl-shimmer::after {
    display: none;
  }

  .cl-rise,
  .cl-fade,
  .cl-reveal-row,
  .cl-celebrate,
  .cl-check-in {
    opacity: 1;
    transform: none;
  }

  .cl-parallax {
    transform: none;
  }

  .cl-press:hover:not(:disabled),
  .cl-press:active:not(:disabled),
  .cl-lift:hover {
    transform: none;
  }
}
