/* === Damage and restoration effects (see js/fx.js) ===
 * Classes on each effect: fx-hp | fx-sanity, fx-damage | fx-restore, fx-creature | fx-card.
 * Every effect is centered on its target by fx.js (left/top) and removes itself.
 */

#fx-layer {
    position: fixed;
    inset: 0;
    z-index: 90;
    pointer-events: none;
    overflow: hidden;
}

.fx-float,
.fx-effect {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

/* Every effect part gets its own GPU layer from the start, so scaling and fading it
   never repaints the board underneath. No filter: blur anywhere (costly on every frame). */
.fx-float,
.fx-effect,
.fx-effect span,
.fx-effect::before {
    will-change: transform, opacity;
}

/* ---- Floating numbers ---- */

.fx-float {
    font-family: 'Cinzel', serif;
    font-size: 2.4rem;
    -webkit-text-stroke: 1px rgba(0, 0, 0, 0.8);
    font-weight: 900;
    text-shadow: 0 0 6px #000, 0 0 14px #000;
    z-index: 2;
    animation: fx-float-rise 1.3s ease-out forwards;
}

.fx-float.fx-hp.fx-damage { color: #f87171; }
.fx-float.fx-sanity.fx-damage { color: #c084fc; }
.fx-float.fx-hp.fx-restore { color: #86efac; }
.fx-float.fx-sanity.fx-restore { color: #ede9fe; }
.fx-float.fx-on-card { font-size: 2.8rem; }

/* Damage from creatures jolts sideways; card effects rise cleanly */
.fx-float.fx-damage.fx-creature { animation-name: fx-float-jolt; }

@keyframes fx-float-rise {
    0%   { opacity: 0; transform: translate(-50%, -20%) scale(0.6); }
    15%  { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
    70%  { opacity: 1; transform: translate(-50%, -140%) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -190%) scale(0.95); }
}

@keyframes fx-float-jolt {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(1.6); }
    10%  { opacity: 1; transform: translate(-58%, -55%) scale(1.2); }
    20%  { transform: translate(-42%, -60%) scale(1.1); }
    30%  { transform: translate(-50%, -70%) scale(1); }
    75%  { opacity: 1; transform: translate(-50%, -130%); }
    100% { opacity: 0; transform: translate(-50%, -170%); }
}

/* ---- HP damage from a creature: three claw slashes ---- */

.fx-effect.fx-hp.fx-damage.fx-creature {
    width: 130px;
    height: 100px;
}

.fx-effect.fx-hp.fx-damage.fx-creature span {
    position: absolute;
    left: 5px;
    top: calc(20px + var(--i) * 26px);
    width: 120px;
    height: 8px;
    border-radius: 3px;
    background: linear-gradient(90deg, transparent, #fecaca 30%, #dc2626 70%, transparent);
    box-shadow: 0 0 10px #dc2626;
    transform: rotate(-28deg) scaleX(0);
    transform-origin: left center;
    animation: fx-slash 0.7s ease-out forwards;
    animation-delay: calc(var(--i) * 70ms);
}

@keyframes fx-slash {
    0%   { opacity: 1; transform: rotate(-28deg) scaleX(0); }
    35%  { opacity: 1; transform: rotate(-28deg) scaleX(1); }
    100% { opacity: 0; transform: rotate(-28deg) scaleX(1); }
}

/* ---- HP damage from a card: crimson burst ---- */

.fx-effect.fx-hp.fx-damage.fx-card {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: radial-gradient(circle, #fecaca 0%, #dc2626 40%, rgba(127, 29, 29, 0.6) 65%, transparent 70%);
    box-shadow: 0 0 30px #dc2626;
    animation: fx-burst 0.8s ease-out forwards;
}

@keyframes fx-burst {
    0%   { opacity: 1; transform: translate(-50%, -50%) scale(0.3); }
    60%  { opacity: 0.85; transform: translate(-50%, -50%) scale(5.5); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(7); }
}

/* ---- Sanity damage from a creature: psychic ripples ---- */

.fx-effect.fx-sanity.fx-damage.fx-creature {
    width: 40px;
    height: 40px;
}

.fx-effect.fx-sanity.fx-damage.fx-creature span {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid #a855f7;
    box-shadow: 0 0 14px #7c3aed, inset 0 0 10px #7c3aed;
    animation: fx-ripple 1.1s ease-out forwards;
    animation-delay: calc(var(--i) * 180ms);
    opacity: 0;
}

@keyframes fx-ripple {
    0%   { opacity: 0.9; transform: scale(0.4) skewX(0deg); }
    50%  { opacity: 0.7; transform: scale(3.4) skewX(12deg); }
    100% { opacity: 0; transform: scale(5) skewX(-12deg); }
}

/* ---- Sanity damage from a card: spinning violet sigil ---- */

.fx-effect.fx-sanity.fx-damage.fx-card::before {
    content: '\2726';
    display: block;
    font-size: 110px;
    line-height: 1;
    color: #c084fc;
    text-shadow: 0 0 18px #7c3aed, 0 0 36px #6b21a8;
    animation: fx-sigil 1s ease-out forwards;
}

@keyframes fx-sigil {
    0%   { opacity: 0; transform: scale(0.3) rotate(0deg); }
    30%  { opacity: 1; transform: scale(1.2) rotate(120deg); }
    100% { opacity: 0; transform: scale(1.8) rotate(300deg); }
}

/* ---- Restoration from a creature: rising motes (golden-green for HP, silver for sanity) ---- */

.fx-effect.fx-restore.fx-creature {
    width: 10px;
    height: 10px;
}

.fx-effect.fx-restore.fx-creature span {
    position: absolute;
    left: var(--dx);
    top: 10px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    opacity: 0;
    animation: fx-mote 1.3s ease-out forwards;
    animation-delay: var(--delay);
}

.fx-effect.fx-hp.fx-restore.fx-creature span {
    background: #bef264;
    box-shadow: 0 0 8px #84cc16, 0 0 14px #facc15;
}

.fx-effect.fx-sanity.fx-restore.fx-creature span {
    background: #f5f3ff;
    box-shadow: 0 0 8px #c4b5fd, 0 0 14px #e5e7eb;
}

@keyframes fx-mote {
    0%   { opacity: 0; transform: translateY(10px) scale(0.5); }
    25%  { opacity: 1; }
    100% { opacity: 0; transform: translateY(-90px) scale(1.2); }
}

/* ---- HP restored by a card: warm golden glow ---- */

.fx-effect.fx-hp.fx-restore.fx-card {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #fde68a;
    background: radial-gradient(circle, rgba(253, 230, 138, 0.8), rgba(245, 158, 11, 0.3) 60%, transparent 70%);
    box-shadow: 0 0 24px #f59e0b;
    animation: fx-glow 1.1s ease-out forwards;
}

@keyframes fx-glow {
    0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    35%  { opacity: 1; transform: translate(-50%, -50%) scale(2.6); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(3.6); }
}

/* ---- Sanity restored by a card: pale beam from above ---- */

.fx-effect.fx-sanity.fx-restore.fx-card {
    width: 64px;
    height: 220px;
    transform: translate(-50%, -85%);
    /* Soft edges from the gradient itself (was a blur filter) */
    background: radial-gradient(ellipse 50% 50% at 50% 60%, rgba(237, 233, 254, 0.85), rgba(196, 181, 253, 0.4) 65%, transparent 100%);
    animation: fx-beam 1.2s ease-out forwards;
}

@keyframes fx-beam {
    0%   { opacity: 0; transform: translate(-50%, -85%) scaleX(0.2); }
    30%  { opacity: 1; transform: translate(-50%, -85%) scaleX(1); }
    100% { opacity: 0; transform: translate(-50%, -85%) scaleX(1.4); }
}

/* ---- Bigger effects on cards ---- */

.fx-effect.fx-on-card.fx-creature { transform: translate(-50%, -50%) scale(1.3); }

/* An entity that died: dark smoke where it stood */
.fx-effect.fx-puff {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(60, 50, 70, 0.9), rgba(20, 15, 25, 0.6) 45%, transparent 72%);
    animation: fx-puff 1.2s ease-out forwards;
    animation-delay: 0.3s;
    opacity: 0;
}

@keyframes fx-puff {
    0%   { opacity: 0.9; transform: translate(-50%, -50%) scale(0.6); }
    100% { opacity: 0; transform: translate(-50%, -80%) scale(2.2); }
}

/* ---- "When destroyed": a ring of pale fire and scattering embers where it fell ----
 * Plays just after the death puff. Only opacity and transform animate; glows are static. */

.fx-effect.fx-last-act {
    width: 96px;
    height: 96px;
}

.fx-effect.fx-last-act::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid rgba(253, 230, 138, 0.85);
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.6), inset 0 0 12px rgba(251, 191, 36, 0.4);
    opacity: 0;
    animation: fx-last-act-ring 0.9s ease-out 0.45s forwards;
}

.fx-effect.fx-last-act span {
    position: absolute;
    left: calc(50% - 3px);
    top: calc(50% - 3px);
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fde68a;
    box-shadow: 0 0 6px #f59e0b;
    opacity: 0;
    animation: fx-last-act-ember 1s ease-out forwards;
    animation-delay: calc(0.45s + var(--delay) / 3);
}

@keyframes fx-last-act-ring {
    0%   { opacity: 0.9; transform: scale(0.35); }
    100% { opacity: 0; transform: scale(1.5); }
}

@keyframes fx-last-act-ember {
    0%   { opacity: 1; transform: rotate(calc(var(--i) * 60deg)) translateY(0) scale(1); }
    100% { opacity: 0; transform: rotate(calc(var(--i) * 60deg)) translateY(-56px) scale(0.4); }
}

.fx-float.fx-last-act {
    font-size: 1.3rem;
    color: #fde68a;
    animation-delay: 0.45s;
    opacity: 0;
}

/* A relic's trigger fired: its name rises off the medallion */
.fx-float.fx-relic-name {
    font-size: 1.1rem;
    color: #fde68a;
    white-space: nowrap;
}

/* ---- Target reactions ---- */

.stat.fx-stat-hit {
    animation: fx-stat-shake 0.5s ease-in-out;
}

.stat.fx-stat-heal {
    animation: fx-stat-heal 0.8s ease-out;
}

@keyframes fx-stat-shake {
    0%, 100% { transform: none; }
    20% { transform: translateX(-5px) scale(1.15); }
    40% { transform: translateX(5px) scale(1.15); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

@keyframes fx-stat-heal {
    0%, 100% { transform: none; }
    40% { transform: scale(1.2); }
}

.card.fx-card-hit {
    animation: fx-card-shake 0.45s ease-in-out;
}

.card.fx-card-hit .card-inner {
    box-shadow: 0 0 1.2em rgba(239, 68, 68, 0.9);
}

@keyframes fx-card-shake {
    0%, 100% { translate: 0; }
    20% { translate: -6px 0; }
    40% { translate: 6px 0; }
    60% { translate: -4px 0; }
    80% { translate: 4px 0; }
}

/* Damage to you: the edges of the screen flash */
#fx-vignette {
    position: fixed;
    inset: 0;
    z-index: 89;
    pointer-events: none;
    opacity: 0;
    will-change: opacity; /* keep the full-screen gradient on its own layer: fading it never repaints */
}

/* Gradients, not huge blurred inset shadows: far cheaper to draw at full screen */
#fx-vignette.fx-hp { background: radial-gradient(ellipse at center, transparent 55%, rgba(220, 38, 38, 0.85) 100%); }
#fx-vignette.fx-sanity { background: radial-gradient(ellipse at center, transparent 50%, rgba(124, 58, 237, 0.85) 100%); }

#fx-vignette.show {
    animation: fx-vignette 0.9s ease-out;
}

@keyframes fx-vignette {
    0% { opacity: 0; }
    20% { opacity: 1; }
    100% { opacity: 0; }
}

/* ---- Combat ---- */

/* An attacking entity glows red and rises above the board while it lunges */
.card.fx-lunging {
    z-index: 30;
}

.card.fx-lunging .card-inner {
    border-color: #fca5a5;
    box-shadow: 0 0 1.5em rgba(239, 68, 68, 0.9), 0 0 3em rgba(239, 68, 68, 0.5);
}

/* Attacker meets blocker: crossed sparks and a shock ring */
.fx-effect.fx-clash {
    width: 10px;
    height: 10px;
}

.fx-effect.fx-clash::before,
.fx-effect.fx-clash::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 150px;
    height: 7px;
    border-radius: 4px;
    background: linear-gradient(90deg, transparent, #fff7ed 40%, #fbbf24 60%, transparent);
    box-shadow: 0 0 18px #f59e0b;
    animation: fx-clash-bar 0.6s ease-out forwards;
}

.fx-effect.fx-clash::before { --rot: 45deg; }
.fx-effect.fx-clash::after { --rot: -45deg; }

@keyframes fx-clash-bar {
    0%   { opacity: 1; transform: translate(-50%, -50%) rotate(var(--rot)) scaleX(0.1); }
    30%  { opacity: 1; transform: translate(-50%, -50%) rotate(var(--rot)) scaleX(1.1); }
    100% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--rot)) scaleX(1.3); }
}

/* (The expanding shock ring animated box-shadow, which repainted every frame; the sparks remain.) */

/* Unblocked attacker hits the player: a heavy shockwave on their stats */
.fx-effect.fx-impact {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 6px solid #fca5a5;
    background: radial-gradient(circle, rgba(254, 226, 226, 0.9), rgba(220, 38, 38, 0.5) 50%, transparent 70%);
    box-shadow: 0 0 40px #dc2626;
    animation: fx-impact 0.7s ease-out forwards;
}

@keyframes fx-impact {
    0%   { opacity: 1; transform: translate(-50%, -50%) scale(0.2); }
    40%  { opacity: 1; transform: translate(-50%, -50%) scale(2.4); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(3.4); }
}

/* The whole screen jolts when you're hit in combat. The container keeps its own GPU layer
   (nothing fixed lives inside it), so a jolt moves the drawn screen instead of redrawing it. */
/* `transform`, not `translate`: Firefox only runs transform/opacity off the main thread,
   and a main-thread shake rebuilt the whole board every frame (janky frames, 2026-11-21). */
#game-container { will-change: transform; }
#game-container.fx-screen-shake {
    animation: fx-screen-shake 0.45s ease-in-out;
}

@keyframes fx-screen-shake {
    0%, 100% { transform: translate(0, 0); }
    15% { transform: translate(-9px, 4px); }
    30% { transform: translate(8px, -5px); }
    45% { transform: translate(-6px, 3px); }
    60% { transform: translate(5px, -2px); }
    80% { transform: translate(-2px, 1px); }
}

@media (prefers-reduced-motion: reduce) {
    #game-container.fx-screen-shake { animation: none; }
    .fx-effect, #fx-vignette { display: none; }
    .stat.fx-stat-hit, .stat.fx-stat-heal, .card.fx-card-hit { animation: none; }
}
