/* Button animations driven by public/js/button-fx.js.
   Timings here mirror the beat lengths in that file — change one, change the other.

   Scoped to .btn-fx-genie and never to .btn-addcart-lg, because vaga-mach-details.blade.php
   reuses that class for its claim submit, which must keep behaving like a plain button. */

/* =======================================================================
   Genie — Add to Cart on the product page (ButtonFx.genie)
   appear 600 → hold 700 → toss 450 → swirl 600 → done 900  (≈3.25s)
   ======================================================================= */

.btn-fx-genie {
  position: relative;
  /* The genie floats above the button's own box. */
  overflow: visible;
}

/* ---- cart icon, "+1", sparkles --------------------------------------- */

.btn-fx-genie .bfx-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.btn-fx-genie.is-done .ico-cart {
  animation: bfxCartBump .45s cubic-bezier(.34, 1.56, .64, 1);
}

.btn-fx-genie .bfx-plus {
  position: absolute;
  top: -11px;
  right: -12px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--gold-text);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.4;
  opacity: 0;
  transform: translateY(5px) scale(.5);
  transition: opacity .18s ease, transform .3s cubic-bezier(.34, 1.56, .64, 1);
}

.btn-fx-genie.is-done .bfx-plus {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* One dot plus five box-shadow copies of it = a six-point burst from a single element. */
.btn-fx-genie .bfx-sparkles {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow:
    0 -15px 0 var(--gold),
    13px -8px 0 #fff,
    13px 8px 0 var(--gold),
    0 15px 0 #fff,
    -13px 8px 0 var(--gold),
    -13px -8px 0 #fff;
  opacity: 0;
  pointer-events: none;
}

.btn-fx-genie.is-done .bfx-sparkles {
  animation: bfxSparkle .8s ease-out forwards;
}

/* ---- label ------------------------------------------------------------ */

.btn-fx-genie .bfx-label { transition: opacity .18s ease; }

.btn-fx-genie.is-appear .bfx-label,
.btn-fx-genie.is-hold .bfx-label,
.btn-fx-genie.is-toss .bfx-label,
.btn-fx-genie.is-swirl .bfx-label {
  opacity: .8;
}

/* A flex sibling of .bfx-label, so the button's own gap spaces it — no margin needed. */
.btn-fx-genie .bfx-check {
  display: none;
  font-weight: 700;
}

.btn-fx-genie.is-done .bfx-check { display: inline; }

/* ---- the genie -------------------------------------------------------- */

/* 90x120 = the images' 3:4 (they're 360x480, so still sharp on 3x screens). Parked to the right of centre so his toss (towards the
   viewer's left) points back at the cart icon. transform-origin is the tail tip: he
   rises out of the smoke from it, and spirals into the cart around it. */
.btn-fx-genie .bfx-genie {
  position: absolute;
  left: 64%;
  bottom: calc(100% - 16px);
  width: 90px;
  height: 120px;
  z-index: 5;
  transform-origin: 50% 100%;
  transform: translate(-50%, 24px) scale(.4);
  opacity: 0;
  pointer-events: none;
}

.btn-fx-genie .bfx-genie img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 3px 4px rgba(0, 12, 82, .25));
  transition: opacity .09s linear;
}

/* Hold pose by default; the toss pose takes over from the toss beat onwards. */
.btn-fx-genie .bfx-genie-toss { opacity: 0; }
.btn-fx-genie.is-toss .bfx-genie-hold,
.btn-fx-genie.is-swirl .bfx-genie-hold { opacity: 0; }
.btn-fx-genie.is-toss .bfx-genie-toss,
.btn-fx-genie.is-swirl .bfx-genie-toss { opacity: 1; }

.btn-fx-genie.is-appear .bfx-genie {
  animation: bfxGenieAppear .6s cubic-bezier(.2, .9, .3, 1.15) forwards;
}

.btn-fx-genie.is-hold .bfx-genie {
  opacity: 1;
  animation: bfxGenieFloat .9s ease-in-out infinite alternate;
}

.btn-fx-genie.is-toss .bfx-genie {
  opacity: 1;
  animation: bfxGenieToss .45s ease-out forwards;
}

/* --bfx-dx / --bfx-dy are set by button-fx.js: the distance from the tail tip to the
   centre of the cart icon, measured fresh on every run. */
.btn-fx-genie.is-swirl .bfx-genie {
  animation: bfxGenieSwirl .6s cubic-bezier(.55, 0, .85, .35) forwards;
}

/* ---- smoke puff he appears out of ------------------------------------- */

.btn-fx-genie .bfx-smoke {
  position: absolute;
  left: 64%;
  bottom: calc(100% - 26px);
  width: 96px;
  height: 44px;
  margin-left: -48px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(150, 195, 255, .75), rgba(150, 195, 255, 0));
  opacity: 0;
  transform: scale(.3);
  pointer-events: none;
  z-index: 4;
}

.btn-fx-genie.is-appear .bfx-smoke {
  animation: bfxSmoke .8s ease-out forwards;
}

/* ---- keyframes -------------------------------------------------------- */

@keyframes bfxGenieAppear {
  0%   { opacity: 0; transform: translate(-50%, 24px) scale(.4); }
  35%  { opacity: 1; }
  100% { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

@keyframes bfxGenieFloat {
  from { transform: translate(-50%, 0) rotate(0deg); }
  to   { transform: translate(-50%, -7px) rotate(-2deg); }
}

@keyframes bfxGenieToss {
  0%   { transform: translate(-50%, -4px) rotate(0deg); }
  50%  { transform: translate(-50%, -9px) rotate(-7deg); }
  100% { transform: translate(-50%, -4px) rotate(-4deg); }
}

@keyframes bfxGenieSwirl {
  0%   { opacity: 1; transform: translate(-50%, -4px) rotate(-4deg) scale(1); }
  70%  { opacity: 1; }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--bfx-dx, -60px)), var(--bfx-dy, 20px)) rotate(-340deg) scale(.06);
  }
}

@keyframes bfxSmoke {
  0%   { opacity: 0; transform: scale(.3); }
  30%  { opacity: 1; }
  100% { opacity: 0; transform: scale(1.5) translateY(-14px); }
}

@keyframes bfxSparkle {
  0%   { opacity: 1; transform: scale(.3); }
  100% { opacity: 0; transform: scale(1.5); }
}

@keyframes bfxCartBump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.35) rotate(-8deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ---- header cart badge ------------------------------------------------ */

.bfx-badge-pulse {
  animation: bfxBadgePop .45s cubic-bezier(.34, 1.56, .64, 1);
}

@keyframes bfxBadgePop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.45); }
  100% { transform: scale(1); }
}

/* ---- reduced motion ---------------------------------------------------
   No genie, no smoke, no sparkles, no bounce — button-fx.js skips straight to
   the done state and this makes sure nothing animates its way there. */

@media (prefers-reduced-motion: reduce) {
  .btn-fx-genie .bfx-genie,
  .btn-fx-genie .bfx-smoke,
  .btn-fx-genie .bfx-sparkles {
    display: none;
  }

  .btn-fx-genie.is-done .ico-cart { animation: none; }

  .btn-fx-genie .bfx-plus,
  .btn-fx-genie .bfx-label {
    transition: none;
  }

  .bfx-badge-pulse { animation: none; }
}

/* =======================================================================
   Order genie — Place Order on /review (ButtonFx.orderGenie)
   waiting (as long as the server takes, ≥1.3s) → granting 500 → done / flies away 1100
   ======================================================================= */

.btn-fx-order {
  position: relative;
  /* The genie floats above the button's own box. */
  overflow: visible;
  transition: background-color .3s ease;
}

/* Unlike the add-to-cart genie, he's centred: there's no cart icon to aim a toss at. */
.btn-fx-order .bfx-genie {
  position: absolute;
  left: 50%;
  bottom: calc(100% - 20px);
  width: 114px;
  height: 152px;
  z-index: 5;
  transform-origin: 50% 100%;
  transform: translate(-50%, 30px) scale(.4);
  opacity: 0;
  pointer-events: none;
}

.btn-fx-order .bfx-genie img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 3px 4px rgba(0, 12, 82, .25));
  transition: opacity .12s linear;
}

/* Arms crossed while he waits on the server; holding the order box once it says yes. */
.btn-fx-order .bfx-genie-hold { opacity: 0; }
.btn-fx-order.is-granting .bfx-genie-appear,
.btn-fx-order.is-done .bfx-genie-appear { opacity: 0; }
.btn-fx-order.is-granting .bfx-genie-hold,
.btn-fx-order.is-done .bfx-genie-hold { opacity: 1; }

/* Rises out of the smoke, then floats for as long as the request takes. The float starts
   only once the rise has finished, so the two animations never fight over transform. */
.btn-fx-order.is-waiting .bfx-genie {
  animation: bfxGenieAppear .6s cubic-bezier(.2, .9, .3, 1.15) forwards,
             bfxGenieFloat .9s .6s ease-in-out infinite alternate;
}

.btn-fx-order.is-granting .bfx-genie {
  opacity: 1;
  animation: bfxGeniePresent .5s cubic-bezier(.34, 1.56, .64, 1) forwards;
}

/* Order placed: he leans back for a wind-up, then flies off to the right with the box,
   leaving a puff of smoke behind. */
.btn-fx-order.is-done .bfx-genie {
  opacity: 1;
  animation: bfxGenieFlyAway .9s cubic-bezier(.5, 0, .75, .3) forwards;
}

.btn-fx-order.is-done .bfx-smoke {
  animation: bfxSmoke .8s ease-out forwards;
}

/* On only while he flies off: his path leaves the page on the right, which would
   otherwise flash a horizontal scrollbar (the body doesn't hide x-overflow). `clip`,
   not `hidden` — hidden would turn the page into a scroll container and break the
   sticky order summary. Never removed: the page navigates away right after. */
html.bfx-flying,
html.bfx-flying body {
  overflow-x: clip;
}

.btn-fx-order.is-failed .bfx-genie {
  animation: bfxGenieVanish .5s cubic-bezier(.55, 0, .85, .35) forwards;
}

/* ---- smoke ------------------------------------------------------------ */

.btn-fx-order .bfx-smoke {
  position: absolute;
  left: 50%;
  bottom: calc(100% - 32px);
  width: 120px;
  height: 54px;
  margin-left: -60px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(150, 195, 255, .75), rgba(150, 195, 255, 0));
  opacity: 0;
  transform: scale(.3);
  pointer-events: none;
  z-index: 4;
}

.btn-fx-order.is-waiting .bfx-smoke,
.btn-fx-order.is-failed .bfx-smoke {
  animation: bfxSmoke .8s ease-out forwards;
}

/* ---- sparkles around him once the order is placed --------------------- */

.btn-fx-order .bfx-sparkles {
  position: absolute;
  left: 50%;
  top: 45%;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow:
    0 -22px 0 var(--gold),
    19px -11px 0 #fff,
    19px 11px 0 var(--gold),
    0 22px 0 #fff,
    -19px 11px 0 var(--gold),
    -19px -11px 0 #fff;
  opacity: 0;
  pointer-events: none;
}

.btn-fx-order.is-granting .bfx-sparkles {
  animation: bfxSparkleWide .9s ease-out forwards;
}

/* ---- label and the green "placed" state ------------------------------- */

.btn-fx-order .bfx-label { transition: opacity .18s ease; }
.btn-fx-order.is-waiting .bfx-label { opacity: .85; }

/* A flex sibling of .bfx-label, so the button's own gap spaces it — no margin needed. */
.btn-fx-order .bfx-check {
  display: none;
  font-weight: 700;
}

.btn-fx-order.is-done .bfx-check { display: inline; }
.btn-fx-order.is-done { background: var(--green); }

/* ---- keyframes (appear / float / smoke are shared with the cart genie) -- */

@keyframes bfxGeniePresent {
  0%   { transform: translate(-50%, 0) scale(1); }
  45%  { transform: translate(-50%, -10px) scale(1.08); }
  100% { transform: translate(-50%, -4px) scale(1); }
}

@keyframes bfxGenieFlyAway {
  0%   { opacity: 1; transform: translate(-50%, -4px) rotate(0deg) scale(1); }
  22%  { opacity: 1; transform: translate(calc(-50% - 12px), 2px) rotate(-8deg) scale(1); }
  75%  { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + 440px), -110px) rotate(16deg) scale(.75); }
}

@keyframes bfxGenieVanish {
  0%   { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, 24px) scale(.4); }
}

@keyframes bfxSparkleWide {
  0%   { opacity: 1; transform: scale(.4); }
  100% { opacity: 0; transform: scale(2.4); }
}

/* No genie, no smoke, no sparkles — the label stays fully visible the whole time so the
   customer still gets "Placing your order…" feedback, then the green tick. */
@media (prefers-reduced-motion: reduce) {
  .btn-fx-order { transition: none; }

  .btn-fx-order .bfx-genie,
  .btn-fx-order .bfx-smoke,
  .btn-fx-order .bfx-sparkles {
    display: none;
  }

  .btn-fx-order.is-waiting .bfx-label { opacity: 1; }
}
