/**
 * Following Pokémon sidebar — ambient cell background effects
 * Applied to the existing sidebar <td>, not a wrapper around the sprite.
 */

/* ── Cell base ── */
.sidebar .following td.wrp-following-bg,
.wrp-fpfx-mock-cell.wrp-following-bg {
    overflow: hidden !important;
    isolation: isolate;
}

.wrp-following-bg__fx {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    border-radius: inherit;
}

.wrp-following-bg__sky,
.wrp-following-bg__elements {
    position: absolute;
    inset: 0;
}

.wrp-following-bg__elements {
    z-index: 2;
}

/* Keep badges, sprite, bars above the effect */
.sidebar .following td.wrp-following-bg > *:not(.wrp-following-bg__fx),
.wrp-fpfx-mock-cell > *:not(.wrp-following-bg__fx) {
    position: relative;
    z-index: 3;
}

.sidebar .following td.wrp-following-bg .sidebar-following-pokemon-img,
.wrp-fpfx-mock-sprite {
    filter: drop-shadow(0 3px 10px rgba(0, 0, 0, 0.55));
}

/* ── Shared animated pieces ── */
.wrp-fx-piece {
    position: absolute;
    left: var(--fx-x, 50%);
    top: var(--fx-y, 10%);
    transform: translate(-50%, -50%) rotate(var(--fx-r, 0deg)) scale(var(--fx-s, 1));
    opacity: 0;
    animation-duration: var(--fx-t, 3s);
    animation-delay: var(--fx-d, 0s);
    animation-iteration-count: infinite;
    animation-timing-function: linear;
    will-change: transform, opacity;
}

.wrp-fx-svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* ── Snow ── */
.wrp-following-bg--snow .wrp-following-bg__sky {
    background:
        radial-gradient(ellipse at 50% 0%, rgba(186, 230, 253, 0.2) 0%, transparent 55%),
        linear-gradient(180deg, rgba(12, 36, 68, 0.92) 0%, rgba(20, 52, 88, 0.78) 100%);
}

.wrp-following-bg--snow .wrp-fx-piece--fall {
    width: 14px;
    height: 14px;
    color: rgba(240, 249, 255, 0.95);
    filter: drop-shadow(0 0 3px rgba(186, 230, 253, 0.8));
    animation-name: wrpFxFallGentle;
}

/* ── Blizzard ── */
.wrp-following-bg--blizzard .wrp-following-bg__sky {
    background:
        linear-gradient(115deg, rgba(255, 255, 255, 0.08) 0%, transparent 45%),
        linear-gradient(180deg, rgba(8, 24, 48, 0.95) 0%, rgba(15, 40, 72, 0.85) 100%);
    animation: wrpFxBlizzardPulse 2.5s ease-in-out infinite alternate;
}

.wrp-following-bg--blizzard .wrp-fx-piece--fall {
    width: 12px;
    height: 12px;
    color: #f8fafc;
    filter: drop-shadow(0 0 4px #e0f2fe);
    animation-name: wrpFxFallBlizzard;
}

.wrp-fx-piece--wind {
    position: absolute;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
    animation: wrpFxWindSweep 1.4s linear infinite;
}

.wrp-fx-piece--wind-a { top: 28%; width: 120%; left: -10%; animation-delay: 0s; }
.wrp-fx-piece--wind-b { top: 58%; width: 110%; left: -5%; animation-delay: 0.7s; opacity: 0.6; }

/* ── Fire ── */
.wrp-following-bg--fire .wrp-following-bg__sky {
    background:
        radial-gradient(ellipse at 50% 100%, rgba(251, 146, 60, 0.55) 0%, transparent 55%),
        radial-gradient(circle at 50% 80%, rgba(220, 38, 38, 0.35) 0%, transparent 50%),
        linear-gradient(180deg, rgba(40, 10, 5, 0.88) 0%, rgba(80, 20, 8, 0.75) 100%);
    animation: wrpFxFireGlow 2s ease-in-out infinite alternate;
}

.wrp-fx-piece--flame {
    bottom: 0;
    top: auto;
    width: 22px;
    height: 32px;
    color: #fb923c;
    filter: drop-shadow(0 0 8px rgba(251, 146, 60, 0.9));
    animation-name: wrpFxFlameDance;
    animation-timing-function: ease-in-out;
}

.wrp-fx-piece--ember {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: radial-gradient(circle, #fef08a 0%, #f97316 70%, transparent 100%);
    box-shadow: 0 0 6px #fb923c;
    bottom: 8%;
    top: auto;
    animation-name: wrpFxEmberFloat;
}

/* ── Electric ── */
.wrp-following-bg--electric .wrp-following-bg__sky {
    background:
        radial-gradient(circle at 50% 40%, rgba(250, 204, 21, 0.12) 0%, transparent 50%),
        linear-gradient(180deg, rgba(10, 15, 35, 0.94) 0%, rgba(25, 20, 60, 0.82) 100%);
    animation: wrpFxElectricBgFlash 4s steps(1, end) infinite;
}

.wrp-fx-piece--bolt {
    width: 28px;
    height: 42px;
    color: #fde047;
    filter: drop-shadow(0 0 10px #facc15) drop-shadow(0 0 20px rgba(250, 204, 21, 0.6));
    opacity: 0;
    animation: wrpFxBoltFlash 3.2s ease-in-out infinite;
}

.wrp-fx-piece--bolt-main { left: 38%; top: 18%; --fx-r: -8deg; animation-delay: 0s; }
.wrp-fx-piece--bolt-alt { left: 62%; top: 22%; width: 20px; height: 30px; --fx-r: 12deg; animation-delay: 1.6s; opacity: 0.7; }

.wrp-fx-piece--spark {
    width: 10px;
    height: 10px;
    color: #fef9c3;
    filter: drop-shadow(0 0 4px #facc15);
    animation-name: wrpFxSparkPop;
    animation-timing-function: ease-out;
}

/* ── Aurora ── */
.wrp-following-bg--aurora .wrp-following-bg__sky {
    background: linear-gradient(180deg, rgba(6, 12, 28, 0.95) 0%, rgba(10, 20, 40, 0.8) 100%);
}

.wrp-fx-piece--aurora {
    position: absolute;
    inset: -20% -30%;
    border-radius: 45%;
    filter: blur(10px);
    opacity: 0.55;
    mix-blend-mode: screen;
}

.wrp-fx-piece--aurora-a {
    background: linear-gradient(120deg, transparent, rgba(52, 211, 153, 0.5), rgba(59, 130, 246, 0.35), transparent);
    animation: wrpFxAuroraShift 6s ease-in-out infinite alternate;
}

.wrp-fx-piece--aurora-b {
    background: linear-gradient(240deg, transparent, rgba(167, 139, 250, 0.4), rgba(34, 211, 238, 0.3), transparent);
    animation: wrpFxAuroraShift 8s ease-in-out infinite alternate-reverse;
}

.wrp-fx-piece--aurora-c {
    inset: 10% -20%;
    background: linear-gradient(90deg, transparent, rgba(110, 231, 183, 0.25), transparent);
    animation: wrpFxAuroraShift 5s ease-in-out infinite;
}

/* ── Rain ── */
.wrp-following-bg--rain .wrp-following-bg__sky {
    background:
        radial-gradient(ellipse at 50% 0%, rgba(100, 116, 139, 0.25) 0%, transparent 50%),
        linear-gradient(180deg, rgba(15, 23, 42, 0.92) 0%, rgba(30, 41, 59, 0.78) 100%);
}

.wrp-fx-piece--rain {
    width: 8px;
    height: 18px;
    color: rgba(191, 219, 254, 0.75);
    animation-name: wrpFxRainStreak;
}

/* ── Leaves ── */
.wrp-following-bg--leaves .wrp-following-bg__sky {
    background:
        radial-gradient(ellipse at 30% 0%, rgba(134, 239, 172, 0.12) 0%, transparent 50%),
        linear-gradient(180deg, rgba(20, 40, 25, 0.9) 0%, rgba(35, 55, 30, 0.75) 100%);
}

.wrp-fx-piece--leaf {
    width: 16px;
    height: 16px;
    animation-name: wrpFxLeafDrift;
    animation-timing-function: ease-in-out;
}

.wrp-fx-piece--leaf:nth-child(3n) { color: #fbbf24; }
.wrp-fx-piece--leaf:nth-child(3n+1) { color: #84cc16; }
.wrp-fx-piece--leaf:nth-child(3n+2) { color: #ea580c; }

/* ── Cosmic ── */
.wrp-following-bg--cosmic .wrp-following-bg__sky {
    background: radial-gradient(circle at 50% 50%, rgba(8, 6, 22, 0.95) 0%, rgba(4, 4, 12, 0.85) 100%);
}

.wrp-fx-piece--nebula {
    inset: -15%;
    background:
        radial-gradient(circle at 25% 35%, rgba(139, 92, 246, 0.45) 0%, transparent 45%),
        radial-gradient(circle at 75% 65%, rgba(59, 130, 246, 0.35) 0%, transparent 42%);
    animation: wrpFxNebulaPulse 10s ease-in-out infinite alternate;
}

.wrp-fx-piece--cosmic-star {
    width: 8px;
    height: 8px;
    color: #e9d5ff;
    filter: drop-shadow(0 0 4px rgba(255, 255, 255, 0.9));
    animation-name: wrpFxStarPulse;
    animation-timing-function: ease-in-out;
}

/* ── Sparkle ── */
.wrp-following-bg--sparkle .wrp-following-bg__sky {
    background:
        radial-gradient(circle at 50% 50%, rgba(253, 224, 71, 0.1) 0%, transparent 55%),
        linear-gradient(160deg, rgba(30, 25, 10, 0.88) 0%, rgba(15, 12, 6, 0.72) 100%);
}

.wrp-fx-piece--glint {
    width: 12px;
    height: 12px;
    color: #fde68a;
    filter: drop-shadow(0 0 6px rgba(253, 224, 71, 0.95));
    animation-name: wrpFxGlintFlash;
    animation-timing-function: ease-in-out;
}

/* ── Keyframes ── */
@keyframes wrpFxFallGentle {
    0% { transform: translate(-50%, -15%) rotate(var(--fx-r, 0deg)) scale(var(--fx-s, 1)); opacity: 0; }
    10% { opacity: 0.95; }
    100% { transform: translate(calc(-50% + (var(--fx-i, 0) - 5) * 4px), 115%) rotate(calc(var(--fx-r, 0deg) + 180deg)) scale(var(--fx-s, 1)); opacity: 0; }
}

@keyframes wrpFxFallBlizzard {
    0% { transform: translate(-50%, -20%) rotate(var(--fx-r, 0deg)) scale(var(--fx-s, 1)); opacity: 0; }
    8% { opacity: 1; }
    100% { transform: translate(calc(-50% + (var(--fx-i, 0) - 7) * 10px), 120%) rotate(calc(var(--fx-r, 0deg) + 360deg)) scale(calc(var(--fx-s, 1) * 0.8)); opacity: 0; }
}

@keyframes wrpFxBlizzardPulse {
    0% { filter: brightness(1); }
    100% { filter: brightness(1.1); }
}

@keyframes wrpFxWindSweep {
    0% { transform: translateX(-30%) skewX(-15deg); opacity: 0; }
    30% { opacity: 0.7; }
    100% { transform: translateX(30%) skewX(-15deg); opacity: 0; }
}

@keyframes wrpFxFireGlow {
    0% { filter: brightness(1) saturate(1); }
    100% { filter: brightness(1.15) saturate(1.2); }
}

@keyframes wrpFxFlameDance {
    0%, 100% { transform: translate(-50%, 0) scale(var(--fx-s, 1)) rotate(-3deg); opacity: 0.75; }
    50% { transform: translate(-50%, -6px) scale(calc(var(--fx-s, 1) * 1.08)) rotate(3deg); opacity: 1; }
}

@keyframes wrpFxEmberFloat {
    0% { transform: translate(-50%, 0) scale(1); opacity: 0; }
    15% { opacity: 1; }
    100% { transform: translate(calc(-50% + (var(--fx-i, 0) - 5) * 5px), -90px) scale(0.2); opacity: 0; }
}

@keyframes wrpFxElectricBgFlash {
    0%, 86%, 100% { box-shadow: inset 0 0 0 0 transparent; }
    88% { box-shadow: inset 0 0 24px rgba(250, 204, 21, 0.35); }
    90% { box-shadow: inset 0 0 0 0 transparent; }
}

@keyframes wrpFxBoltFlash {
    0%, 78%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.85) rotate(var(--fx-r, 0deg)); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1.05) rotate(var(--fx-r, 0deg)); }
    84% { opacity: 0.15; }
}

@keyframes wrpFxSparkPop {
    0% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    100% { transform: translate(calc(-50% + (var(--fx-i, 0) - 4) * 7px), calc(-50% - 25px)) scale(0.2); opacity: 0; }
}

@keyframes wrpFxAuroraShift {
    0% { transform: translateX(-8%) skewY(-5deg); opacity: 0.45; }
    100% { transform: translateX(8%) skewY(5deg); opacity: 0.8; }
}

@keyframes wrpFxRainStreak {
    0% { transform: translate(-50%, -25%) skewX(-12deg); opacity: 0; }
    15% { opacity: 0.8; }
    100% { transform: translate(-50%, 115%) skewX(-12deg); opacity: 0; }
}

@keyframes wrpFxLeafDrift {
    0% { transform: translate(-50%, -10%) rotate(var(--fx-r, 0deg)) scale(var(--fx-s, 1)); opacity: 0; }
    12% { opacity: 0.95; }
    100% { transform: translate(calc(-50% + (var(--fx-i, 0) - 5) * 6px), 110%) rotate(calc(var(--fx-r, 0deg) + 420deg)) scale(calc(var(--fx-s, 1) * 0.85)); opacity: 0; }
}

@keyframes wrpFxNebulaPulse {
    0% { transform: scale(1) rotate(0deg); opacity: 0.6; }
    100% { transform: scale(1.08) rotate(3deg); opacity: 0.85; }
}

@keyframes wrpFxStarPulse {
    0%, 100% { opacity: 0.2; transform: translate(-50%, -50%) scale(0.5); }
    50% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes wrpFxGlintFlash {
    0%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(0deg); }
    40% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(45deg); }
    65% { opacity: 0.3; transform: translate(-50%, -50%) scale(0.7) rotate(90deg); }
}

/* ── Admin preview ── */
.wrp-fpfx-mock-cell {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 110px;
    min-width: 110px;
    padding: 12px;
    border-radius: 0 0 8px 8px;
    background: #193c69;
    border: 2px solid #000;
    border-top: none;
}

.wrp-fpfx-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.wrp-fpfx-preview-card {
    border: 2px solid rgba(100, 149, 237, 0.25);
    border-radius: 12px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.35);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
    text-align: center;
}

.wrp-fpfx-preview-card:hover {
    border-color: rgba(100, 149, 237, 0.55);
    transform: translateY(-1px);
}

.wrp-fpfx-preview-card.is-selected {
    border-color: #60a5fa;
    box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.45), 0 8px 20px rgba(37, 99, 235, 0.2);
}

.wrp-fpfx-preview-card .wrp-fpfx-mock-cell {
    min-height: 96px;
    min-width: 96px;
    margin: 0 auto 6px;
}

.wrp-fpfx-preview-label {
    font-size: 12px;
    font-weight: 700;
    color: #e2e8f0;
    margin-top: 4px;
}

.wrp-fpfx-preview-desc {
    font-size: 10px;
    color: #94a3b8;
    line-height: 1.35;
    margin-top: 2px;
}

.wrp-fpfx-live-preview {
    margin: 18px 0 8px;
    padding: 18px;
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(25, 60, 105, 0.95) 0%, rgba(12, 28, 52, 0.9) 100%);
    border: 2px solid #000;
    text-align: center;
    max-width: 200px;
}

.wrp-fpfx-live-caption {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 8px;
}

.wrp-fpfx-admin-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 14px 0;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid rgba(100, 149, 237, 0.25);
}

.wrp-fpfx-admin-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #60a5fa;
}

@media (prefers-reduced-motion: reduce) {
    .wrp-following-bg__fx *,
    .wrp-following-bg__sky {
        animation: none !important;
    }
    .wrp-fx-piece {
        opacity: 0.35 !important;
    }
}
