/* ---------- Pulse Motion (public/js/pulse-motion.js) ----------
   The motion layer in the CSS 3D table plane and the engine's own elements in it: ghosts (card
   pictures in flight), their cast shadows on the plane, the feedback rings and the game-over
   bloom; plus the classes the engine puts on a real card only while it moves it. Every rule is
   scoped to those classes. The engine sets the resting geometry through the CSSOM (transform,
   width, height, --h, --rh, --hb-sh-blur, --hb-sh-a, opacity, z-index) and all motion is Web
   Animations on transform and opacity, so nothing here transitions or animates by itself.

   The layer and the ghosts keep 3D (transform-style: preserve-3d), so a ghost's translateZ lifts it
   off the felt in the stage's camera and its card's rotateY turns it over inside the plane. No rule
   here sets a grouping property on them (no overflow other than visible, opacity, filter, clip,
   contain: paint or will-change of such a property), as any of those would flatten the 3D.

   Tokens (reused from pulse.css, with the same defaults): --hb-silver, --hb-silver-2, --hb-crimson,
   --hb-crimson-2, --hb-ink. Shadow variables shared with pulse-stage.css: --hb-sh-blur, --hb-sh-a. */

/* The layer: the whole plane (absolute, inset 0), above the plane's resting cards in paint order
   (its z-index matters only where the host is flat), never taking a pointer. */
.hb-fx {
  position: absolute; inset: 0; z-index: 3;
  overflow: visible; pointer-events: none;
  transform-style: preserve-3d; -webkit-transform-style: preserve-3d;
}

/* A ghost: laid out at the layer's top left, placed by its transform (translate3d rotate scale),
   turning about its own centre. Its card fills it and takes its size from the ghost's --h, like any
   Heartbeat Deck card. Only the ghost itself is ever faded: opacity or a filter on a turned or
   turning .hb-card would flatten its 3D flip. */
.hb-fx > .hb-ghost {
  position: absolute; top: 0; left: 0; margin: 0;
  transform-origin: 50% 50% 0;
  transform-style: preserve-3d; -webkit-transform-style: preserve-3d;
  will-change: transform;
  pointer-events: none;
}
.hb-fx > .hb-ghost > .card.hb-card {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0;
  transition: none; animation: none;
  pointer-events: none;
}

/* A cast shadow the engine makes (hb-cast): the card's footprint on the plane at z 0, placed by its
   transform, offset away from the key light by the card's height, spreading (scale) and fading
   (opacity) as the card rises; its blur (--hb-sh-blur) and darkness (--hb-sh-a) are set through the
   CSSOM. The same properties as pulse-stage.css's .hb-shadow, so the two stylesheets agree. A
   ghost's shadow sits right before the ghost in the layer; a lifted card's right before the card. */
.hb-fx > .hb-shadow, .hb-shadow.hb-cast {
  position: absolute; left: 0; top: 0; margin: 0;
  width: 140px; height: 200px;
  border-radius: calc(var(--h, 200px) * .1);
  background: rgba(0, 0, 0, var(--hb-sh-a, .5));
  filter: blur(var(--hb-sh-blur, 3px));
  transform-origin: 50% 50% 0;
  pointer-events: none;
  will-change: transform, opacity;
}

/* A real card while the engine moves it (FLIP) or holds it lifted: its own transitions are off, so
   they cannot override the animation or start from where it ends. .hb-airborne says a cast shadow
   of the engine's travels with it. In a 3D host the card's own contact shadow stays as the host
   draws it (a tight edge on the felt, invisible at height); nothing here deepens it. */
.hb-flying { z-index: 2; transition: none !important; }
.hb-lifted { transition: none !important; }

/* Feedback rings: one hairline outline the size of the target (a circle on a seat or a turn),
   lying on the plane just above its target, which grows a little and fades once. The kind picks
   the line. */
.hb-fx > .hb-ring {
  position: absolute; top: 0; left: 0; box-sizing: border-box;
  border: 1.5px solid rgba(207, 199, 230, .8);
  border: 1.5px solid color-mix(in srgb, var(--hb-silver, #cfc7e6) 80%, transparent);
  border-radius: calc(var(--rh, 100px) * .14);
  opacity: 0;
  transform-origin: 50% 50% 0;
  will-change: transform, opacity;
}
.hb-fx > .hb-ring.hb-ring-round { border-radius: 999px; }
/* The heartbeat's light is violet: the capture's beat, the turn's double pulse, the release ripple
   (hb-ring-beat, a soft violet ring that travels across the felt) and the anticipation's edge light
   on the deck (hb-beat-edge). A chkoba keeps its crimson. */
.hb-fx > .hb-ring.hb-ring-capture {
  border-width: 2px;
  border-color: rgba(155, 92, 255, .92);
  border-color: color-mix(in srgb, var(--hb-violet, #9b5cff) 92%, transparent);
}
.hb-fx > .hb-ring.hb-ring-chkoba {
  border-width: 2px;
  border-color: rgba(217, 32, 63, .95);
  border-color: color-mix(in srgb, var(--hb-crimson-2, #d9203f) 95%, transparent);
}
.hb-fx > .hb-ring.hb-ring-turn {
  border-width: 1.5px;
  border-color: rgba(155, 92, 255, .75);
  border-color: color-mix(in srgb, var(--hb-violet, #9b5cff) 75%, transparent);
}
.hb-fx > .hb-ring.hb-ring-beat {
  border-width: 2px;
  border-color: rgba(155, 92, 255, .7);
  border-color: color-mix(in srgb, var(--hb-violet, #9b5cff) 70%, transparent);
  box-shadow: 0 0 14px rgba(155, 92, 255, .35), inset 0 0 10px rgba(155, 92, 255, .2);
}
.hb-fx > .hb-beat-edge {
  position: absolute; top: 0; left: 0; box-sizing: border-box;
  border-radius: calc(var(--rh, 100px) * .1);
  border: 1.5px solid rgba(155, 92, 255, .9);
  border: 1.5px solid color-mix(in srgb, var(--hb-violet, #9b5cff) 90%, transparent);
  box-shadow: 0 0 16px rgba(155, 92, 255, .5), 0 0 3px rgba(155, 92, 255, .8);
  opacity: 0;
  transform-origin: 50% 50% 0;
  will-change: transform, opacity;
}

/* The bloom (a won game): one soft violet disc on the felt beating twice and fading out from the
   centre, followed by the ripple of light. It passes under the table cards' height but over the
   felt, so even at its peak (the engine's opacity .6) it only tints them: about a third of violet at
   its very centre, much less where the cards are. */
.hb-fx > .hb-bloom {
  position: absolute; top: 0; left: 0;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(124, 58, 237, .62), rgba(124, 58, 237, .26) 45%, rgba(124, 58, 237, .07) 72%, rgba(124, 58, 237, 0));
  background: radial-gradient(closest-side,
    color-mix(in srgb, var(--hb-violet-2, #7c3aed) 62%, transparent),
    color-mix(in srgb, var(--hb-violet-2, #7c3aed) 26%, transparent) 45%,
    color-mix(in srgb, var(--hb-violet-2, #7c3aed) 7%, transparent) 72%,
    transparent);
  opacity: 0;
  transform-origin: 50% 50% 0;
  will-change: transform, opacity;
}

/* Stand-in cards, only when the Heartbeat Deck module is not loaded (create({ deck: null })). */
.hb-fx .card.hb-plain {
  display: block; padding: 0; border: 0; background: none; box-shadow: none; overflow: visible;
  border-radius: calc(var(--h, 96px) * .1);
  transform-style: preserve-3d;
}
.hb-fx .card.hb-plain::before, .hb-fx .card.hb-plain::after { content: none; }
.hb-fx .card.hb-plain[data-side="back"] { transform: rotateY(180deg); }
.hb-fx .card.hb-plain > .hb-front, .hb-fx .card.hb-plain > .hb-back {
  position: absolute; inset: 0; border-radius: inherit;
  -webkit-backface-visibility: hidden; backface-visibility: hidden;
}
.hb-fx .card.hb-plain > .hb-front {
  display: flex; align-items: center; justify-content: center;
  background: var(--hb-silver-2, #f1edf8); color: var(--hb-ink, #0a0612);
  font: 700 calc(var(--h, 96px) * .2)/1 system-ui, sans-serif;
}
.hb-fx .card.hb-plain > .hb-back {
  transform: rotateY(180deg);
  background: var(--hb-ink, #0a0612);
  box-shadow: inset 0 0 0 max(1px, calc(var(--h, 96px) * .02)) var(--hb-silver, #cfc7e6);
}
.hb-fx .card.hb-plain.back > .hb-back { transform: none; -webkit-backface-visibility: visible; backface-visibility: visible; }

/* Reduced motion: the engine creates nothing then; the layer and any cast shadow are hidden as
   well, in case a sequence started just before the preference changed. Nothing in it is ever
   printed. */
@media (prefers-reduced-motion: reduce) {
  .hb-fx, .hb-shadow.hb-cast { display: none; }
}

/* The Lite performance profile (.pa-lite on the felt, public/js/perf-profile.js): the motion still
   runs (faster, through the engine's speed), but without the blurred cast shadows under the flying
   cards, the feedback rings and the bloom, which are the expensive layers. */
.pa-felt.pa-lite .hb-fx > .hb-shadow, .pa-felt.pa-lite .hb-shadow.hb-cast,
.pa-felt.pa-lite .hb-fx > .hb-ring, .pa-felt.pa-lite .hb-fx > .hb-bloom, .pa-felt.pa-lite .hb-fx > .hb-beat-edge { display: none; }
@media (forced-colors: active) {
  .hb-fx > .hb-shadow, .hb-shadow.hb-cast { display: none; }
}
@media print {
  .hb-fx, .hb-shadow.hb-cast { display: none; }
}

/* A burst of sparks (pulse 'spark', the flat table's capture): a point on the plane with small
   lights thrown from it; the engine animates each one's transform and opacity. */
.hb-fx > .hb-sparks { width: 0; height: 0; pointer-events: none; transform-style: preserve-3d; -webkit-transform-style: preserve-3d; }
.hb-fx > .hb-sparks > i {
  position: absolute; left: -4px; top: -4px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--c, #ffd166); box-shadow: 0 0 8px var(--c, #ffd166), 0 0 2px #fff;
  will-change: transform, opacity;
}
.pa-felt.pa-lite .hb-fx > .hb-sparks { display: none; }
