/* ==========================================
   ChessAPit - Optimized Animations
   קובץ: mystyle-animations.css
   גרסה 2.0 - אופטימיזציה מלאה לביצועים
   ========================================== */

/* === משתני אנימציות === */
:root {
    --anim-duration-fast: 0.8s;
    --anim-duration-medium: 1s;
    --anim-duration-slow: 1.5s;
    --anim-duration-extra-slow: 2.5s;

    --anim-color-gold: rgba(255, 215, 0, 0.3);
    --anim-color-blue: rgba(100, 200, 255, 0.3);
    --anim-color-green: rgba(0, 200, 0, 0.2);
    --anim-color-red: rgba(255, 0, 0, 0.2);
}

/* === ביצועים - Compositor Layer Hints === */
#moveRevealAnimation,
.move-slot.animating,
.content.animating,
#statusIndicator.animating {
    /* יצירת שכבת compositor נפרדת */
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* הסרנו #chessContainer.floating-mode מכאן - ה-transform שלו מנוהל ב-mystyle-board.css */

/* === ניהול will-change חכם === */
/* ברירת מחדל: ללא will-change */
.move-slot,
.content,
.chess-piece,
#statusIndicator,
#moveRevealAnimation {
    will-change: auto;
}

/* הוספת will-change רק כשצריך */
.move-slot.will-animate,
.content.will-animate,
#moveRevealAnimation.animating,
#statusIndicator.status-checkmate,
#statusIndicator.status-check-white,
#statusIndicator.status-check-black,
#undoButton.suggest-undo {
    will-change: transform, opacity;
}

/* הסרת will-change אחרי אנימציה */
.move-slot.animation-complete,
.content.animation-complete {
    will-change: auto;
}

/* === אנימציות בסיס לחשיפת תוכן === */
@keyframes fadeInContent {
    from {
        opacity: 0;
        color: transparent;
    }
    to {
        opacity: 1;
        color: inherit;
    }
}

/* === אנימציות זוהר - מאוחד === */
@keyframes revealGlow {
    0% {
        background: var(--anim-color);
        border-left: 3px solid var(--border-color);
        box-shadow: 0 0 var(--glow-size) var(--glow-color);
        transform: var(--transform-start);
    }
    50% {
        background: color-mix(in srgb, var(--anim-color) 50%, transparent);
    }
    100% {
        background: transparent;
        border-left: 3px solid transparent;
        box-shadow: none;
        transform: scale(1) translateX(0);
    }
}

/* Classes לסוגי חשיפה שונים - משתמשים באותה אנימציה עם משתנים */
.new-reveal-highlight {
    --anim-color: var(--anim-color-blue);
    --border-color: #64C8FF;
    --glow-size: 10px;
    --glow-color: rgba(100, 200, 255, 0.4);
    --transform-start: translateX(10px);
    animation: revealGlow var(--anim-duration-slow) cubic-bezier(0.4, 0, 0.2, 1) forwards;
    /* אופטימיזציה */
    contain: layout style paint;
}

.golden-reveal {
    --anim-color: var(--anim-color-gold);
    --border-color: #ffd700;
    --glow-size: 10px;
    --glow-color: rgba(255, 215, 0, 0.4);
    --transform-start: scale(1.02);
    animation: revealGlow 2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    contain: layout style paint;
}

.winning-move-reveal {
    --anim-color: linear-gradient(to right, rgba(255, 215, 0, 0.4), rgba(255, 215, 0, 0.2));
    --border-color: #ffd700;
    --glow-size: 20px;
    --glow-color: rgba(255, 215, 0, 0.6);
    --transform-start: scale(1.05) translateX(5px);
    animation: revealGlow var(--anim-duration-extra-slow) cubic-bezier(0.4, 0, 0.2, 1) forwards;
    contain: layout style paint;
}

/* === אנימציות הדגשת תוכן - מאוחד === */
@keyframes contentPulse {
    0%, 100% {
        transform: scale(1);
        background-color: transparent;
    }
    30% {
        transform: scale(var(--pulse-scale));
        background-color: var(--pulse-color);
    }
}

.content-highlight {
    --pulse-scale: 1.08;
    --pulse-color: rgba(255, 215, 0, 0.15);
    animation: contentPulse 0.8s cubic-bezier(0.42, 0, 0.58, 1) forwards;
    display: inline-block;
    padding: 0 2px;
    border-radius: 3px;
}

.content-re-highlight {
    --pulse-scale: 1.14;
    --pulse-color: rgba(100, 200, 255, 0.2);
    animation: contentPulse var(--anim-duration-fast) cubic-bezier(0.42, 0, 0.58, 1) forwards;
    display: inline-block;
    padding: 0 2px;
    border-radius: 3px;
}

/* === אנימציות סטטוס - אופטימיזציה === */
@keyframes statusPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }
    25%, 75% {
        transform: scale(var(--pulse-max));
        box-shadow: 0 0 var(--shadow-size) var(--shadow-color);
    }
    50% {
        transform: scale(var(--pulse-mid));
        box-shadow: 0 0 calc(var(--shadow-size) * 0.8) var(--shadow-color);
    }
}

.status-checkmate {
    --pulse-max: 1.3;
    --pulse-mid: 1.2;
    --shadow-size: 30px;
    --shadow-color: rgba(255, 215, 0, 0.9);
    animation: statusPulse 2s cubic-bezier(0.42, 0, 0.58, 1) forwards;
    background: #ffd700 !important;
}

.status-check-white {
    --pulse-max: 1.15;
    --pulse-mid: 1.1;
    --shadow-size: 15px;
    --shadow-color: rgba(255, 0, 0, 0.6);
    animation: statusPulse var(--anim-duration-slow) cubic-bezier(0.42, 0, 0.58, 1) forwards;
}

.status-check-black {
    --pulse-max: 1.08;
    --pulse-mid: 1.05;
    --shadow-size: 10px;
    --shadow-color: rgba(255, 100, 100, 0.4);
    animation: statusPulse 0.8s cubic-bezier(0.42, 0, 0.58, 1) forwards;
}

/* === אנימציות כפתורים === */
@keyframes suggestUndo {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 2px 8px rgba(170, 170, 170, 0.2);
    }
    20%, 40%, 60% {
        transform: scale(1.25);
        box-shadow: 0 0 20px rgba(255, 200, 0, 0.8);
        background: #fffacd;
        border-color: #ffa500;
    }
    30%, 50%, 70% {
        transform: scale(1.15);
        box-shadow: 0 0 15px rgba(255, 200, 0, 0.5);
    }
}

#undoButton.suggest-undo {
    animation: suggestUndo 2.2s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* === אנימציית כותרת === */
@keyframes pulseAttention {
    0%, 100% {
        transform: scale(1);
        color: var(--text-primary);
    }
    25%, 75% {
        transform: scale(1.4) translateX(33px);
        color: #ff0000;
        text-shadow: 0 0 10px rgba(255, 0, 0, 0.5);
    }
    50% {
        transform: scale(0.7) translateX(11px);
        color: #ffaa00;
        text-shadow: 0 0 10px rgba(255, 200, 0, 0.5);
    }
}

.pulse-attention {
    animation: pulseAttention 3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* === אנימציית השלמת כל המהלכים (גרסה חגיגית, בהירה, כפולה) === */
@keyframes allWinningCelebration {
    0%, 100% {
        background-color: transparent;
        box-shadow: none;
    }
    20% {
        background-color: rgba(255, 230, 80, 0.8); /* זהוב בוהק */
        box-shadow: 0 0 25px rgba(255, 220, 0, 0.9), 0 0 50px rgba(255, 245, 150, 0.8);
    }
    40% {
        background-color: rgba(255, 240, 120, 0.85); /* חזרה לזהוב חזק יותר */
        box-shadow: 0 0 40px rgba(255, 230, 100, 1), 0 0 80px rgba(255, 240, 180, 0.9);
    }
    60% {
        background-color: rgba(255, 230, 80, 0.8); /* זהוב בוהק */
        box-shadow: 0 0 25px rgba(255, 220, 0, 0.9), 0 0 50px rgba(255, 245, 150, 0.8);
    }
    80% {
        background-color: rgba(255, 240, 120, 0.85); /* חזרה לזהוב חזק יותר */
        box-shadow: 0 0 40px rgba(255, 230, 100, 1), 0 0 80px rgba(255, 240, 180, 0.9);
    }
}

.all-winning-revealed {
    animation: allWinningCelebration 1.5s cubic-bezier(0.4, 0, 0.2, 1) 0s 2;
}

/* === Fade in לתוכן slots === */
.move-slot.revealed .content.new-content {
    animation: fadeInContent 0.7s cubic-bezier(0.4, 0, 0.6, 1) forwards;
}

.move-slot.revealed .content.new-content .chess-piece {
    animation: fadeInContent 0.7s cubic-bezier(0.4, 0, 0.6, 1) forwards;
}

/* === אנימציות סטטיסטיקות === */
@keyframes statsReveal {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stats-display-mode {
    animation: statsReveal 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* אנימציית הצלחה */
@keyframes successPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
        background: rgba(40, 167, 69, 0.1);
    }
}

.stats-tooltip.success-message {
    animation: successPulse 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* עיצוב tooltip סטטיסטיקות */
.stats-tooltip {
    font-family: 'Rubik', 'Varela Round', Arial, sans-serif;
}

.stats-tooltip .success-title {
    animation: successPulse 1s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

/* === אנימציית מונה מהלכים === */
@keyframes moveCounterBump {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
        color: #ff6b00;
    }
}

.stats-moves.move-updated {
    animation: moveCounterBump 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}

/* === אופטימיזציות ביצועים === */

/* CSS Containment - מגביל את ההשפעה של שינויים */
.move-slot,
#statusIndicator,
#moveRevealAnimation {
    contain: layout style;
}

.content {
    contain: style paint;
}

/* מניעת layout thrashing */
.animating {
    pointer-events: none; /* מניעת אינטראקציה במהלך אנימציה */
}

/* שימוש ב-transform במקום margin/padding לתזוזות */
.content-shift {
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === תמיכה ב-prefers-reduced-motion === */
@media (prefers-reduced-motion: reduce) {
    /* הגבלת השפעה רק לתוך chessContainer */
    .chessContainer *,
    .chessContainer *::before,
    .chessContainer *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    /* שמור על אנימציות קריטיות אבל קצר אותן */
    .move-slot.revealed .content.new-content,
    #moveRevealAnimation {
        animation-duration: 0.2s !important;
    }
}

/* === אנימציות מותאמות למובייל === */
@media (hover: none) and (pointer: coarse) {
    /* הפחת משך אנימציות במובייל */
    .new-reveal-highlight,
    .golden-reveal,
    .winning-move-reveal {
        animation-duration: 1s;
    }

    .content-highlight,
    .content-re-highlight {
        animation-duration: 0.5s;
    }
}

/* === Hardware Acceleration Hints === */
@media (prefers-reduced-motion: no-preference) {
    /* הבטח GPU acceleration לאנימציות מורכבות */
    #moveRevealAnimation,
    .move-slot.animating,
    #statusIndicator.status-checkmate,
    #undoButton.suggest-undo {
        transform: translate3d(0, 0, 0);
    }
}
