/* ═══════════════════════════════════════════════════════════
   CBGameFX — Duolingo-grade juice for gamification surfaces.
   Spring overshoots, celebration overlay, coin flight sprites,
   stagger entrances, legendary shine. Pairs with gamefx.js.
   ═══════════════════════════════════════════════════════════ */

:root {
  --gfx-spring: cubic-bezier(0.34, 1.56, 0.64, 1);   /* playful overshoot */
  --gfx-out: cubic-bezier(0.22, 1, 0.36, 1);
}

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

/* press squash (added on pointerdown, removed on release) */
.gfx-press { transform: scale(0.94) !important; transition: transform 0.08s ease-out !important; }

@keyframes gfx-bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.22); }
  100% { transform: scale(1); }
}
.gfx-bump { animation: gfx-bump 0.4s var(--gfx-spring); }

@keyframes gfx-pop-anim {
  0% { transform: scale(1); }
  30% { transform: scale(0.82); }
  65% { transform: scale(1.14); }
  100% { transform: scale(1); }
}
.gfx-pop-anim { animation: gfx-pop-anim 0.38s var(--gfx-spring); }

@keyframes gfx-wobble {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-7deg); }
  45% { transform: rotate(6deg); }
  70% { transform: rotate(-3deg); }
}
.gfx-wobble { animation: gfx-wobble 0.5s ease-in-out; }

/* ── Grid entrance stagger (set --gfx-i per child) ──────── */
@keyframes gfx-pop-in {
  0% { opacity: 0; transform: scale(0.4) translateY(14px); }
  70% { opacity: 1; transform: scale(1.06) translateY(-2px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}
.gfx-stagger > * {
  animation: gfx-pop-in 0.42s var(--gfx-spring) both;
  animation-delay: calc(var(--gfx-i, 0) * 45ms);
}

/* ── Legendary treatment ────────────────────────────────── */
@keyframes gfx-glow-pulse {
  0%, 100% { box-shadow: 0 0 14px oklch(0.8 0.15 85 / 0.25); }
  50% { box-shadow: 0 0 30px oklch(0.8 0.15 85 / 0.55); }
}
@keyframes gfx-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.gfx-legendary { animation: gfx-glow-pulse 2.6s ease-in-out infinite; }
.gfx-legendary .inv-slot-art img,
.gfx-legendary img { animation: gfx-float 3.2s ease-in-out infinite; }

/* ── Inspect art re-pop when selection changes ──────────── */
.gfx-art-pop { animation: gfx-pop-in 0.4s var(--gfx-spring) both; }

/* ── Coin flight sprite (positioned by JS) ──────────────── */
.gfx-coin-sprite {
  position: fixed;
  width: 34px; height: 34px;
  left: 0; top: 0;
  pointer-events: none;
  z-index: 9600;
  will-change: transform, opacity;
  filter: drop-shadow(0 3px 8px oklch(0.75 0.14 75 / 0.5));
}

/* ── Sparkle burst (JS spawns .gfx-star inside target) ──── */
@keyframes gfx-star-fly {
  0% { opacity: 1; transform: translate(0, 0) scale(0.3) rotate(0deg); }
  60% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--gfx-sx), var(--gfx-sy)) scale(1.1) rotate(120deg); }
}
.gfx-star {
  position: absolute;
  left: 50%; top: 50%;
  width: 12px; height: 12px;
  margin: -6px 0 0 -6px;
  pointer-events: none;
  z-index: 5;
  background: currentColor;
  color: var(--lime, #B8F000);
  clip-path: polygon(50% 0, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0 50%, 39% 39%);
  animation: gfx-star-fly 0.7s var(--gfx-out) both;
}

/* ── AAA reveal sequence (charge → detonate → slam) ─────── */

/* vertical rarity beam pillar */
@keyframes gfx-beam-grow {
  0% { transform: scaleY(0); opacity: 0; }
  100% { transform: scaleY(1); opacity: 1; }
}
.gfx-beam {
  position: absolute;
  left: 50%; top: -12vh; bottom: -12vh;
  width: 120px; margin-left: -60px;
  background: linear-gradient(90deg, transparent, var(--gfx-rc, #F5B942) 50%, transparent);
  opacity: 0.55;
  filter: blur(18px);
  transform-origin: 50% 100%;
  animation: gfx-beam-grow 0.45s var(--gfx-out) both;
  pointer-events: none;
}
.gfx-beam.thin {
  width: 8px; margin-left: -4px;
  filter: blur(1px);
  opacity: 0.9;
}

/* contracting charge ring */
@keyframes gfx-charge {
  0% { transform: scale(2.6); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: scale(0.22); opacity: 0.9; }
}
.gfx-charge-ring {
  position: absolute;
  left: 50%; top: 42%;
  margin: -130px 0 0 -130px;
  width: 260px; height: 260px;
  border-radius: 50%;
  border: 3px solid var(--gfx-rc, #F5B942);
  box-shadow: 0 0 30px var(--gfx-rc, #F5B942), inset 0 0 30px var(--gfx-rc, #F5B942);
  animation: gfx-charge 0.62s cubic-bezier(0.55, 0, 0.9, 0.4) both;
  pointer-events: none;
}

/* full-screen detonation flash */
@keyframes gfx-flash {
  0% { opacity: 0; }
  8% { opacity: 1; }
  100% { opacity: 0; }
}
.gfx-flash {
  position: fixed; inset: 0;
  background: radial-gradient(circle at 50% 42%, #fff 0%, var(--gfx-rc, #F5B942) 35%, transparent 75%);
  opacity: 0;
  pointer-events: none;
  z-index: 9700;
}
.gfx-flash.on { animation: gfx-flash 0.5s ease-out both; }

/* expanding shockwave rings */
@keyframes gfx-shockwave {
  0% { transform: scale(0.15); opacity: 1; border-width: 6px; }
  100% { transform: scale(3.4); opacity: 0; border-width: 1px; }
}
.gfx-shock {
  position: absolute;
  left: 50%; top: 84px;
  margin-left: -120px;
  width: 240px; height: 240px;
  border-radius: 50%;
  border: 6px solid var(--gfx-rc, #F5B942);
  box-shadow: 0 0 40px var(--gfx-rc, #F5B942);
  animation: gfx-shockwave 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
  pointer-events: none;
}
.gfx-shock.late { animation-delay: 0.12s; animation-duration: 0.9s; }

/* the item SLAMS in from the flash */
@keyframes gfx-slam-in {
  0% { opacity: 0; transform: scale(2.6) translateY(-24px); filter: blur(14px) brightness(3); }
  45% { opacity: 1; filter: blur(0) brightness(1.6); }
  62% { transform: scale(0.9) translateY(4px); filter: brightness(1); }
  80% { transform: scale(1.06) translateY(-2px); }
  100% { opacity: 1; transform: scale(1) translateY(0); filter: none; }
}
.gfx-slam { animation: gfx-slam-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) both !important; }

/* heading stamps in with chromatic split flicker */
@keyframes gfx-stamp {
  0% { opacity: 0; transform: scale(1.7); letter-spacing: 0.5em; filter: blur(6px); }
  60% { opacity: 1; transform: scale(0.96); letter-spacing: 0.03em; filter: blur(0); }
  100% { opacity: 1; transform: scale(1); letter-spacing: 0.05em; }
}
@keyframes gfx-chroma {
  0%, 100% { text-shadow: none; }
  20% { text-shadow: -3px 0 0 oklch(0.65 0.25 25 / 0.8), 3px 0 0 oklch(0.8 0.15 195 / 0.8); }
  40% { text-shadow: 2px 0 0 oklch(0.65 0.25 25 / 0.6), -2px 0 0 oklch(0.8 0.15 195 / 0.6); }
  60% { text-shadow: -1px 0 0 oklch(0.65 0.25 25 / 0.4), 1px 0 0 oklch(0.8 0.15 195 / 0.4); }
}
.gfx-heading.crazy {
  animation: gfx-stamp 0.45s var(--gfx-out) both, gfx-chroma 0.5s steps(1) 0.45s 1;
}

/* screen shake (applied to app root) */
@keyframes gfx-shake-kf {
  0%, 100% { transform: translate3d(0, 0, 0) rotate(0); }
  12% { transform: translate3d(-9px, 5px, 0) rotate(-0.35deg); }
  25% { transform: translate3d(8px, -7px, 0) rotate(0.3deg); }
  38% { transform: translate3d(-7px, -4px, 0) rotate(-0.25deg); }
  52% { transform: translate3d(6px, 5px, 0) rotate(0.2deg); }
  68% { transform: translate3d(-4px, 2px, 0) rotate(-0.12deg); }
  84% { transform: translate3d(2px, -2px, 0) rotate(0.06deg); }
}
.gfx-shake { animation: gfx-shake-kf 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
.gfx-shake-sm { animation: gfx-shake-kf 0.3s cubic-bezier(0.36, 0.07, 0.19, 0.97) both; animation-name: gfx-shake-kf; transform: scale(1); }

/* art sprite flying to a loadout slot */
.gfx-art-sprite {
  position: fixed;
  left: 0; top: 0;
  pointer-events: none;
  z-index: 9600;
  border-radius: 12px;
  will-change: transform, opacity;
  box-shadow: 0 8px 30px oklch(0 0 0 / 0.6), 0 0 24px var(--gfx-rc, #5CE1E6);
}

/* coin ghost trail */
.gfx-coin-ghost {
  position: fixed;
  width: 26px; height: 26px;
  left: 0; top: 0;
  border-radius: 50%;
  background: radial-gradient(circle, oklch(0.85 0.14 85 / 0.55), transparent 70%);
  pointer-events: none;
  z-index: 9590;
  will-change: transform, opacity;
}

/* ── Celebration overlay (Duolingo reward moment) ───────── */
.gfx-overlay {
  position: fixed; inset: 0;
  z-index: 9400;
  display: flex; align-items: center; justify-content: center;
  background: oklch(0.08 0.02 270 / 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.25s ease-out;
}
.gfx-overlay.on { opacity: 1; }
.gfx-overlay.off { opacity: 0; transition: opacity 0.22s ease-in; }

.gfx-celebrate {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  padding: 34px 40px 30px;
  max-width: 340px;
}

/* rotating sunburst behind the hero art */
@keyframes gfx-rays-spin { to { transform: rotate(360deg); } }
.gfx-rays {
  position: absolute;
  width: 340px; height: 340px;
  top: -40px; left: 50%; margin-left: -170px;
  border-radius: 50%;
  background: repeating-conic-gradient(
    from 0deg,
    oklch(0.85 0.14 85 / 0.22) 0deg 12deg,
    transparent 12deg 30deg
  );
  -webkit-mask-image: radial-gradient(circle, #000 0%, transparent 68%);
  mask-image: radial-gradient(circle, #000 0%, transparent 68%);
  animation: gfx-rays-spin 22s linear infinite;
  pointer-events: none;
}

@keyframes gfx-hero-in {
  0% { opacity: 0; transform: translateY(-70px) scale(0.2) rotate(-8deg); }
  55% { opacity: 1; transform: translateY(6px) scale(1.14) rotate(2deg); }
  78% { transform: translateY(-3px) scale(0.96) rotate(-1deg); }
  100% { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}
.gfx-hero {
  position: relative;
  width: 168px; height: 168px;
  margin-bottom: 18px;
  animation: gfx-hero-in 0.65s var(--gfx-spring) both;
  z-index: 2;
}
.gfx-hero img {
  width: 100%; height: 100%;
  object-fit: contain;
  border-radius: 18px;
  filter: drop-shadow(0 12px 34px oklch(0 0 0 / 0.55));
}

@keyframes gfx-rise {
  0% { opacity: 0; transform: translateY(18px) scale(0.9); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}
.gfx-heading {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 34px; letter-spacing: 0.05em; line-height: 1;
  color: var(--text, #F4F1FF);
  animation: gfx-rise 0.4s var(--gfx-out) 0.28s both;
  z-index: 2;
}
.gfx-sub {
  font-size: 14px;
  color: oklch(0.8 0.02 270);
  margin-top: 6px;
  animation: gfx-rise 0.4s var(--gfx-out) 0.36s both;
  z-index: 2;
}

.gfx-coins-pill {
  display: inline-flex; align-items: center; gap: 8px;
  margin-top: 16px;
  padding: 8px 18px;
  border-radius: 999px;
  background: oklch(0.75 0.14 75 / 0.14);
  border: 1px solid oklch(0.75 0.14 75 / 0.45);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 24px; letter-spacing: 0.04em;
  color: var(--amber, #F5B942);
  animation: gfx-rise 0.42s var(--gfx-spring) 0.46s both;
  z-index: 2;
}
.gfx-coins-pill img { width: 24px; height: 24px; }

.gfx-collect {
  margin-top: 22px;
  padding: 13px 42px;
  border: none; border-radius: 14px;
  font-family: 'DM Mono', monospace;
  font-size: 13px; font-weight: 700; letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #16130A;
  background: linear-gradient(180deg, #FFDD87, var(--amber, #F5B942));
  box-shadow: 0 6px 0 oklch(0.55 0.12 75), 0 12px 26px oklch(0 0 0 / 0.4);
  cursor: pointer;
  animation: gfx-rise 0.42s var(--gfx-spring) 0.58s both;
  transition: transform 0.1s ease-out, box-shadow 0.1s ease-out;
  z-index: 2;
}
.gfx-collect:hover { transform: translateY(-1px); }
.gfx-collect:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 oklch(0.55 0.12 75), 0 6px 16px oklch(0 0 0 / 0.4);
}

/* ── ELEGANT reveal (Duolingo-grade grace) ──────────────── */

/* soft radial light bloom swelling behind the item */
@keyframes gfx-bloom-in {
  0% { transform: scale(0.15); opacity: 0; }
  55% { opacity: 0.85; }
  100% { transform: scale(1.15); opacity: 0.55; }
}
.gfx-bloom {
  position: absolute;
  left: 50%; top: 34%;
  width: 460px; height: 460px;
  margin: -230px 0 0 -230px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--gfx-rc, #F5B942) 0%, transparent 70%);
  background: radial-gradient(circle,
    oklch(from var(--gfx-rc, #F5B942) l c h / 0.5) 0%,
    oklch(from var(--gfx-rc, #F5B942) l c h / 0.18) 38%,
    transparent 70%);
  filter: blur(6px);
  animation: gfx-bloom-in 1.1s var(--gfx-out) both;
  pointer-events: none;
}

/* the item rises gracefully out of the light */
@keyframes gfx-rise-hero {
  0% { opacity: 0; transform: translateY(90px) scale(0.72); filter: blur(12px) brightness(1.9); }
  55% { opacity: 1; filter: blur(0) brightness(1.25); }
  74% { transform: translateY(-8px) scale(1.035); filter: brightness(1.05); }
  100% { opacity: 1; transform: translateY(0) scale(1); filter: none; }
}
.gfx-hero.elegant { animation: gfx-rise-hero 1.05s cubic-bezier(0.19, 1, 0.22, 1) 0.42s both; }

/* one silk shine sweep across the art once it settles */
.gfx-hero.elegant::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: 18px;
  background: linear-gradient(115deg, transparent 30%, oklch(1 0 0 / 0.28) 50%, transparent 70%);
  background-size: 260% 100%;
  background-position: 130% 0;
  animation: gfx-silk 1.1s ease-out 1.5s both;
  pointer-events: none;
}
@keyframes gfx-silk { to { background-position: -130% 0; } }

/* thin refined halo rings */
@keyframes gfx-halo-out {
  0% { transform: scale(0.25); opacity: 0; }
  18% { opacity: 0.9; }
  100% { transform: scale(2.7); opacity: 0; }
}
.gfx-halo {
  position: absolute;
  left: 50%; top: 84px;
  width: 220px; height: 220px;
  margin-left: -110px;
  border-radius: 50%;
  border: 1.5px solid var(--gfx-rc, #F5B942);
  border-color: oklch(from var(--gfx-rc, #F5B942) calc(l + 0.15) c h / 0.9);
  box-shadow: 0 0 22px var(--gfx-rc, #F5B942);
  animation: gfx-halo-out 1.6s cubic-bezier(0.16, 1, 0.3, 1) 0.55s both;
  pointer-events: none;
}
.gfx-halo.late { animation-delay: 0.85s; animation-duration: 1.9s; }

/* floating light motes drifting up around the reveal */
@keyframes gfx-mote-rise {
  0% { transform: translateY(30px) translateX(0); opacity: 0; }
  18% { opacity: var(--gfx-mo, 0.8); }
  100% { transform: translateY(-170px) translateX(var(--gfx-mx, 0px)); opacity: 0; }
}
.gfx-mote {
  position: absolute;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--gfx-rc, #F5B942);
  box-shadow: 0 0 10px var(--gfx-rc, #F5B942), 0 0 22px var(--gfx-rc, #F5B942);
  filter: blur(0.4px);
  animation: gfx-mote-rise var(--gfx-md, 3.2s) ease-out var(--gfx-mdel, 0.8s) infinite;
  pointer-events: none;
}

/* graceful title: fade up, tracking settles, no glitch */
@keyframes gfx-title-in {
  0% { opacity: 0; transform: translateY(22px); letter-spacing: 0.42em; filter: blur(5px); }
  100% { opacity: 1; transform: translateY(0); letter-spacing: 0.05em; filter: blur(0); }
}
.gfx-heading.elegant { animation: gfx-title-in 0.85s cubic-bezier(0.19, 1, 0.22, 1) 1.05s both; }
.gfx-elegant .gfx-sub { animation-delay: 1.35s; animation-duration: 0.6s; }
.gfx-elegant .gfx-coins-pill { animation-delay: 1.55s; }
.gfx-elegant .gfx-collect { animation-delay: 1.8s; }
.gfx-elegant .gfx-rays { opacity: 0; animation: gfx-rays-spin 22s linear infinite, gfx-rays-in 1.6s ease-out 0.6s forwards; }
@keyframes gfx-rays-in { to { opacity: 1; } }

/* crazy mode: freeze card content until the detonation (boom) */
.gfx-crazy:not(.boom) .gfx-celebrate,
.gfx-crazy:not(.boom) .gfx-flash { visibility: hidden; }
.gfx-crazy:not(.boom) .gfx-celebrate *,
.gfx-crazy:not(.boom) .gfx-rays { animation-play-state: paused !important; }

/* rarity color variable feeding beam / rings / flash */
.gfx-overlay { --gfx-rc: #F5B942; }
.gfx-overlay[data-rarity="common"]   { --gfx-rc: #9CA3AF; }
.gfx-overlay[data-rarity="uncommon"] { --gfx-rc: #34D399; }
.gfx-overlay[data-rarity="rare"]     { --gfx-rc: #60A5FA; }
.gfx-overlay[data-rarity="epic"]     { --gfx-rc: #C084FC; }
.gfx-overlay[data-rarity="legendary"]{ --gfx-rc: #FBBF24; }

/* rarity accent variants for the pill + rays */
.gfx-overlay[data-rarity="uncommon"] .gfx-rays { background: repeating-conic-gradient(from 0deg, oklch(0.78 0.15 165 / 0.2) 0deg 12deg, transparent 12deg 30deg); }
.gfx-overlay[data-rarity="rare"] .gfx-rays { background: repeating-conic-gradient(from 0deg, oklch(0.72 0.14 255 / 0.2) 0deg 12deg, transparent 12deg 30deg); }
.gfx-overlay[data-rarity="epic"] .gfx-rays { background: repeating-conic-gradient(from 0deg, oklch(0.72 0.16 305 / 0.22) 0deg 12deg, transparent 12deg 30deg); }

/* ── Balance number roll ────────────────────────────────── */
.gfx-count { display: inline-block; min-width: 1ch; }

/* ── 3D hover tilt (JS sets --gfx-rx/--gfx-ry) ──────────── */
.gfx-tilt {
  transform: perspective(700px) rotateX(var(--gfx-rx, 0deg)) rotateY(var(--gfx-ry, 0deg));
  transition: transform 0.12s ease-out;
  will-change: transform;
}

/* ── Shine sweep across card art on hover ───────────────── */
@keyframes gfx-shine-sweep {
  0% { transform: translateX(-130%) skewX(-18deg); }
  100% { transform: translateX(230%) skewX(-18deg); }
}
.bc-card, .inv-slot { position: relative; overflow: hidden; }
.bc-card::after, .inv-slot::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; left: 0;
  width: 45%;
  background: linear-gradient(100deg, transparent, oklch(1 0 0 / 0.13), transparent);
  transform: translateX(-130%) skewX(-18deg);
  pointer-events: none;
  z-index: 3;
}
.bc-card:hover::after, .inv-slot:hover::after {
  animation: gfx-shine-sweep 0.75s ease-out;
}
/* legendary cards get a slow ambient sweep even without hover */
.gfx-legendary::after {
  animation: gfx-shine-sweep 3.4s ease-in-out 1.2s infinite;
}

/* ── Reduced motion: calm everything down ───────────────── */
@media (prefers-reduced-motion: reduce) {
  .gfx-stagger > *, .gfx-hero, .gfx-heading, .gfx-sub,
  .gfx-coins-pill, .gfx-collect, .gfx-art-pop { animation: none; opacity: 1; }
  .gfx-rays, .gfx-legendary, .gfx-legendary img,
  .gfx-legendary .inv-slot-art img { animation: none; }
  .gfx-star, .gfx-coin-sprite { display: none; }
  .gfx-tilt { transform: none; }
  .bc-card::after, .inv-slot::after, .gfx-legendary::after { animation: none; }
  .gfx-beam, .gfx-charge-ring, .gfx-shock, .gfx-flash,
  .gfx-art-sprite, .gfx-coin-ghost { display: none; }
  .gfx-shake, .gfx-shake-sm, .gfx-slam, .gfx-heading.crazy { animation: none; }
  .gfx-crazy:not(.boom) .gfx-celebrate { visibility: visible; }
  .gfx-crazy:not(.boom) .gfx-celebrate * { animation-play-state: running !important; }
}
