/*
 * Attack effects (AttackFx.razor) over the battle arena. Each event lasts 1.3s: the projectile flies for the first
 * 0.55s (BattleField's wind-up), then the impact bursts on the target. "up" attacks go from your Skanimal (bottom
 * left) to the opponent (top right); "down" attacks the other way.
 */

.fx {
    --x0: 27%;
    --y0: 70%;
    --x1: 76%;
    --y1: 30%;
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
    color: var(--fx);
}

.fx-down {
    --x0: 76%;
    --y0: 30%;
    --x1: 27%;
    --y1: 70%;
}

/* A miss sails past the target and off into the arena */
.fx-up.is-miss { --x1: 96%; --y1: 6%; }
.fx-down.is-miss { --x1: 6%; --y1: 96%; }

.fx .fx-core { fill: var(--fx); }
.fx .fx-edge { stroke: var(--fx); }
.fx .fx-aura { fill: color-mix(in srgb, var(--fx) 45%, transparent); }
.fx .fx-tail { fill: color-mix(in srgb, var(--fx) 60%, transparent); }

/* Projectile flight */

.fx-projectile {
    position: absolute;
    left: var(--x0);
    top: var(--y0);
    animation: fx-travel 0.5s cubic-bezier(0.45, 0, 0.75, 1) 0.05s both;
}

.fx-lift {
    position: relative;
    filter: drop-shadow(0 0 6px var(--fx)) drop-shadow(0 0 14px var(--fx));
}

.fx-shape {
    position: absolute;
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
    overflow: visible;
}

/* Fire streaks with a flickering tail, pointing where it's going */
.fx-fire .fx-shape { animation: fx-flicker 0.12s steps(2) infinite; }
.fx-up.fx-fire .fx-shape { transform: rotate(-38deg); }
.fx-down.fx-fire .fx-shape { transform: rotate(142deg); }

/* Volleys: three shards, leaves or slashes, staggered and spinning */
.fx-ice .fx-shape,
.fx-leaf .fx-shape,
.fx-wind .fx-shape {
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    translate: calc((var(--i) - 1) * 16px) calc((var(--i) - 1) * -10px);
    animation: fx-spin 0.35s linear infinite;
    animation-delay: calc(var(--i) * -0.1s);
}

.fx-wind .fx-shape { animation-duration: 0.25s; width: 38px; height: 38px; }

/* Thrown things arc through the air */
.fx-rock .fx-lift,
.fx-toxic .fx-lift { animation: fx-arc 0.5s ease-in-out 0.05s both; }
.fx-rock .fx-shape { animation: fx-spin 0.5s linear infinite; }
.fx-toxic .fx-shape { animation: fx-wobble 0.18s ease-in-out infinite alternate; }

.fx-water .fx-shape { animation: fx-wobble 0.2s ease-in-out infinite alternate; }
.fx-shadow .fx-shape { width: 56px; height: 56px; margin: -28px 0 0 -28px; animation: fx-pulse 0.25s ease-in-out infinite alternate; }
.fx-psychic .fx-shape { animation: fx-pulse 0.15s ease-in-out infinite alternate; }

/* Lightning strikes the target from the sky instead of travelling */
.fx-bolt {
    position: absolute;
    left: calc(var(--x1) - 20px);
    top: 0;
    width: 40px;
    height: var(--y1);
    overflow: visible;
    opacity: 0;
    filter: drop-shadow(0 0 6px var(--fx)) drop-shadow(0 0 18px var(--fx));
    animation: fx-strike 0.5s ease-out 0.3s both;
}

.fx-bolt polyline {
    fill: none;
    stroke: #fff;
    stroke-width: 5;
    stroke-linejoin: bevel;
    vector-effect: non-scaling-stroke;
}

/* Claws rake across the target up close */
.fx-claw {
    position: absolute;
    left: calc(var(--x1) - 40px);
    top: calc(var(--y1) - 40px);
    width: 80px;
    height: 80px;
    overflow: visible;
    filter: drop-shadow(0 0 6px var(--fx));
}

.fx-claw path {
    fill: none;
    stroke: #fff;
    stroke-width: 4;
    stroke-linecap: round;
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    animation: fx-rake 0.3s ease-out 0.35s both;
}

/* Impact */

.fx-impact {
    position: absolute;
    left: var(--x1);
    top: var(--y1);
}

.fx-ring {
    position: absolute;
    width: 90px;
    height: 90px;
    margin: -45px 0 0 -45px;
    border: 3px solid var(--fx);
    border-radius: 50%;
    box-shadow: 0 0 18px var(--fx), inset 0 0 18px var(--fx);
    opacity: 0;
    animation: fx-ring 0.55s ease-out 0.55s both;
}

.fx-bit {
    position: absolute;
    width: 18px;
    height: 18px;
    margin: -9px 0 0 -9px;
    overflow: visible;
    opacity: 0;
    filter: drop-shadow(0 0 4px var(--fx));
    animation: fx-scatter 0.6s cubic-bezier(0.2, 0.7, 0.4, 1) 0.55s both;
}

.fx.is-critical .fx-ring { border-width: 5px; animation-name: fx-ring-big; }
.fx.is-critical .fx-bit { animation-name: fx-scatter-far; }

/* Shadow attacks implode instead of bursting out */
.fx-shadow .fx-ring { animation-name: fx-implode; }

/* Healing: plus signs rise around the healer */
.fx-heal {
    position: absolute;
    left: var(--x0);
    top: var(--y0);
}

.fx-heal span {
    position: absolute;
    color: var(--fx);
    font-size: 22px;
    font-weight: 900;
    text-shadow: 0 0 8px var(--fx);
    opacity: 0;
    translate: calc((var(--i) - 3.5) * 12px) 0;
    animation: fx-rise 0.9s ease-out calc(0.1s + var(--i) * 0.06s) both;
}

/* The attacker's rarity variant restyles its attacks */

.fx.fx-variant-holographic { animation: fx-holo 0.6s linear infinite; }
.fx.fx-variant-shiny { --fx: #ffc83d !important; }
.fx.fx-variant-shiny .fx-lift,
.fx.fx-variant-shiny .fx-impact { scale: 1.3; filter: drop-shadow(0 0 10px #ffc83d) drop-shadow(0 0 22px #ff9f43); }
.fx.fx-variant-chameleon .fx-lift { animation-timing-function: steps(5); filter: drop-shadow(3px 0 0 rgba(255, 0, 80, 0.8)) drop-shadow(-3px 0 0 rgba(0, 255, 240, 0.8)); }
.fx.fx-variant-chameleon .fx-projectile { animation-timing-function: steps(6); }
.fx.fx-variant-greyscale { filter: grayscale(1) contrast(1.4); }
.fx.fx-variant-greyscale::after {
    content: "";
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.06) 0 2px, transparent 2px 4px);
    animation: fx-flicker 0.1s steps(2) infinite;
}
.fx.fx-variant-metallic { --fx: #dfe8f5 !important; filter: contrast(1.2) brightness(1.1); }
.fx.fx-variant-pastel { filter: saturate(0.5) brightness(1.2); }

@keyframes fx-travel {
    0% { left: var(--x0); top: var(--y0); opacity: 0; }
    12% { opacity: 1; }
    100% { left: var(--x1); top: var(--y1); opacity: 1; }
}

@keyframes fx-arc {
    0% { transform: translateY(0); }
    50% { transform: translateY(-70px); }
    100% { transform: translateY(0); }
}

@keyframes fx-spin { to { rotate: 360deg; } }
@keyframes fx-flicker { 50% { opacity: 0.8; } }
@keyframes fx-wobble { to { scale: 1.15 0.88; } }
@keyframes fx-pulse { to { scale: 1.18; } }

@keyframes fx-strike {
    0% { opacity: 0; clip-path: inset(0 0 100% 0); }
    30% { opacity: 1; clip-path: inset(0 0 0 0); }
    60% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes fx-rake { to { stroke-dashoffset: 0; } }

/* Each starts invisible: fill-mode "both" shows the first frame while the impact waits for the hit */
@keyframes fx-ring {
    0% { opacity: 0; transform: scale(0.2); }
    8% { opacity: 1; }
    100% { opacity: 0; transform: scale(1.4); }
}

@keyframes fx-ring-big {
    0% { opacity: 0; transform: scale(0.2); }
    8% { opacity: 1; }
    100% { opacity: 0; transform: scale(2.1); }
}

@keyframes fx-implode {
    0% { opacity: 0; transform: scale(2); }
    40% { opacity: 1; }
    100% { opacity: 0; transform: scale(0.1); }
}

@keyframes fx-scatter {
    0% { opacity: 0; transform: rotate(var(--a)) translateX(4px) scale(1.2); }
    8% { opacity: 1; }
    100% { opacity: 0; transform: rotate(var(--a)) translateX(56px) scale(0.4) rotate(120deg); }
}

@keyframes fx-scatter-far {
    0% { opacity: 0; transform: rotate(var(--a)) translateX(4px) scale(1.6); }
    8% { opacity: 1; }
    100% { opacity: 0; transform: rotate(var(--a)) translateX(90px) scale(0.5) rotate(200deg); }
}

@keyframes fx-rise {
    0% { opacity: 0; transform: translateY(10px) scale(0.6); }
    30% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-70px) scale(1.1); }
}

@keyframes fx-holo { to { filter: hue-rotate(360deg) saturate(1.6); } }

@media (prefers-reduced-motion: reduce) {
    .fx { display: none; }
}
