/**
 * Spades Game Animations
 *
 * Comprehensive animations for enhanced game experience.
 * Includes score animations, card flips, victory effects, and more.
 */

/* ===========================================
   CSS Variables for Animation Timing
   =========================================== */
:root {
    --anim-fast: 0.15s;
    --anim-normal: 0.3s;
    --anim-slow: 0.5s;
    --anim-very-slow: 0.8s;
    --ease-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out-back: cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* ===========================================
   Reduce Motion - Accessibility
   =========================================== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.reduce-motion *, .reduce-motion *::before, .reduce-motion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

/* ===========================================
   Settings Button Styling
   =========================================== */
.settings-buttons {
    display: flex;
    gap: 8px;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 100;
}

.settings-toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all var(--anim-fast) var(--ease-smooth);
    backdrop-filter: blur(4px);
}

.settings-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.settings-toggle-btn:active {
    transform: scale(0.95);
}

/* ===========================================
   Score Number Animations
   =========================================== */

/* Score count up/down animation */
.score-counting {
    animation: scoreCount var(--anim-normal) var(--ease-smooth);
}

@keyframes scoreCount {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* Positive score flash */
.score-positive-flash {
    animation: positiveFlash var(--anim-slow) var(--ease-smooth);
}

@keyframes positiveFlash {
    0% { color: inherit; background-color: transparent; }
    30% { color: #fff; background-color: rgba(34, 197, 94, 0.4); }
    100% { color: inherit; background-color: transparent; }
}

/* Negative score flash and shake */
.score-negative-flash {
    animation: negativeFlash var(--anim-slow) var(--ease-smooth),
               screenShake var(--anim-normal) var(--ease-smooth);
}

@keyframes negativeFlash {
    0% { color: inherit; background-color: transparent; }
    30% { color: #fff; background-color: rgba(239, 68, 68, 0.5); }
    100% { color: inherit; background-color: transparent; }
}

@keyframes screenShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Gold shimmer for Nil success */
.score-nil-success {
    animation: nilSuccessShimmer var(--anim-very-slow) var(--ease-smooth);
}

@keyframes nilSuccessShimmer {
    0% {
        background: linear-gradient(90deg, transparent 0%, transparent 100%);
        color: inherit;
    }
    25% {
        background: linear-gradient(90deg, transparent 0%, rgba(255, 215, 0, 0.4) 50%, transparent 100%);
        color: #ffd700;
        text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
    }
    50% {
        background: linear-gradient(90deg, rgba(255, 215, 0, 0.4) 0%, transparent 50%, rgba(255, 215, 0, 0.4) 100%);
    }
    100% {
        background: linear-gradient(90deg, transparent 0%, transparent 100%);
        color: inherit;
        text-shadow: none;
    }
}

/* ===========================================
   Bid Lock Animations
   =========================================== */

/* Card flip animation when bids are locked */
.bid-card-flip {
    animation: cardFlip var(--anim-slow) var(--ease-out-back);
    transform-style: preserve-3d;
}

@keyframes cardFlip {
    0% { transform: rotateY(0deg) scale(1); }
    50% { transform: rotateY(90deg) scale(0.9); }
    100% { transform: rotateY(0deg) scale(1); }
}

/* Staggered flip for multiple cards */
.player-bid-card.bid-locked:nth-child(1) { animation-delay: 0s; }
.player-bid-card.bid-locked:nth-child(2) { animation-delay: 0.1s; }
.player-bid-card.bid-locked:nth-child(3) { animation-delay: 0.2s; }
.player-bid-card.bid-locked:nth-child(4) { animation-delay: 0.3s; }

/* Bid button selection animation */
.bid-btn.selecting {
    animation: bidSelect var(--anim-fast) var(--ease-bounce);
}

@keyframes bidSelect {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* Bid lock button pulse */
.lock-bids-ready {
    animation: lockPulse 1.5s ease-in-out infinite;
}

@keyframes lockPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
    }
}

/* ===========================================
   Bag Penalty Animation
   =========================================== */

/* Screen shake for bag penalty */
.bag-penalty-shake {
    animation: bagPenaltyShake 0.6s var(--ease-smooth);
}

@keyframes bagPenaltyShake {
    0%, 100% { transform: translateX(0) rotate(0); }
    10% { transform: translateX(-10px) rotate(-1deg); }
    20% { transform: translateX(10px) rotate(1deg); }
    30% { transform: translateX(-10px) rotate(-1deg); }
    40% { transform: translateX(10px) rotate(1deg); }
    50% { transform: translateX(-5px) rotate(-0.5deg); }
    60% { transform: translateX(5px) rotate(0.5deg); }
    70% { transform: translateX(-3px) rotate(-0.3deg); }
    80% { transform: translateX(3px) rotate(0.3deg); }
    90% { transform: translateX(-1px) rotate(0); }
}

/* Bag icon explosion */
.bag-explode {
    animation: bagExplode 0.8s var(--ease-smooth) forwards;
}

@keyframes bagExplode {
    0% { transform: scale(1); opacity: 1; }
    20% { transform: scale(1.5); opacity: 1; }
    40% { transform: scale(0.8); }
    60% { transform: scale(1.3) rotate(15deg); }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}

/* Flying -100 text */
.flying-penalty {
    position: fixed;
    font-size: 3rem;
    font-weight: 900;
    color: #ef4444;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 9999;
    animation: flyPenalty 1.5s var(--ease-smooth) forwards;
}

@keyframes flyPenalty {
    0% {
        opacity: 0;
        transform: translate(-50%, 0) scale(0.5);
    }
    20% {
        opacity: 1;
        transform: translate(-50%, 0) scale(1.2);
    }
    80% {
        opacity: 1;
        transform: translate(-50%, -100px) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -150px) scale(0.8);
    }
}

/* ===========================================
   Victory Animations
   =========================================== */

/* Confetti container */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9998;
    overflow: hidden;
}

/* Individual confetti piece */
.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    top: -10px;
    animation: confettiFall var(--confetti-duration, 3s) linear forwards;
}

@keyframes confettiFall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.confetti.square { border-radius: 0; }
.confetti.circle { border-radius: 50%; }
.confetti.triangle {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 10px solid currentColor;
    background: transparent !important;
}

/* Trophy bounce */
.trophy-bounce {
    animation: trophyBounce 1s var(--ease-bounce);
}

@keyframes trophyBounce {
    0% { transform: scale(0) rotate(-15deg); }
    50% { transform: scale(1.2) rotate(5deg); }
    70% { transform: scale(0.9) rotate(-3deg); }
    100% { transform: scale(1) rotate(0); }
}

/* Winner name glow */
.winner-glow {
    animation: winnerGlow 2s ease-in-out infinite;
}

@keyframes winnerGlow {
    0%, 100% {
        text-shadow:
            0 0 5px rgba(255, 215, 0, 0.5),
            0 0 10px rgba(255, 215, 0, 0.3),
            0 0 20px rgba(255, 215, 0, 0.2);
    }
    50% {
        text-shadow:
            0 0 10px rgba(255, 215, 0, 0.8),
            0 0 20px rgba(255, 215, 0, 0.6),
            0 0 40px rgba(255, 215, 0, 0.4),
            0 0 60px rgba(255, 215, 0, 0.2);
    }
}

/* Final score reveal */
.score-reveal {
    animation: scoreReveal 0.8s var(--ease-out-back);
}

@keyframes scoreReveal {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    60% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ===========================================
   SET Animation
   =========================================== */

/* SET stamp animation */
.set-stamp {
    position: absolute;
    font-size: 4rem;
    font-weight: 900;
    color: #ef4444;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    transform: rotate(-15deg);
    animation: setStamp 0.5s var(--ease-bounce) forwards;
    z-index: 100;
}

@keyframes setStamp {
    0% {
        transform: rotate(-15deg) scale(3);
        opacity: 0;
    }
    50% {
        transform: rotate(-15deg) scale(0.9);
        opacity: 1;
    }
    70% {
        transform: rotate(-15deg) scale(1.1);
    }
    100% {
        transform: rotate(-15deg) scale(1);
        opacity: 1;
    }
}

/* Score turns red momentarily */
.score-set-flash {
    animation: setFlash 1s var(--ease-smooth);
}

@keyframes setFlash {
    0%, 100% { color: inherit; }
    20%, 80% { color: #ef4444; }
}

/* ===========================================
   Nil Animations
   =========================================== */

/* Golden sparkle burst for Nil Made */
.nil-sparkle {
    position: relative;
}

.nil-sparkle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100px;
    height: 100px;
    transform: translate(-50%, -50%);
    background: radial-gradient(circle, rgba(255, 215, 0, 0.8) 0%, transparent 70%);
    animation: sparkleburst 0.8s var(--ease-smooth) forwards;
    pointer-events: none;
}

@keyframes sparkleburst {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0.8;
    }
    100% {
        transform: translate(-50%, -50%) scale(2);
        opacity: 0;
    }
}

/* Nil badge crack/shatter for failure */
.nil-crack {
    position: relative;
    animation: nilCrack 0.6s var(--ease-smooth);
}

@keyframes nilCrack {
    0% { transform: scale(1); filter: none; }
    20% { transform: scale(1.1); }
    40% { transform: scale(0.95) rotate(-5deg); filter: brightness(0.8); }
    60% { transform: scale(1.05) rotate(3deg); }
    80% { transform: scale(0.98) rotate(-2deg); }
    100% { transform: scale(1) rotate(0); filter: grayscale(0.5); }
}

/* Nil badge pulse when active */
.nil-active-pulse {
    animation: nilPulse 2s ease-in-out infinite;
}

@keyframes nilPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(99, 102, 241, 0);
    }
}

/* ===========================================
   Round Transition Animations
   =========================================== */

/* Cards sweep across screen */
.card-sweep-left {
    animation: sweepLeft 0.5s var(--ease-smooth);
}

.card-sweep-right {
    animation: sweepRight 0.5s var(--ease-smooth);
}

@keyframes sweepLeft {
    0% { transform: translateX(0); opacity: 1; }
    100% { transform: translateX(-100%); opacity: 0; }
}

@keyframes sweepRight {
    0% { transform: translateX(100%); opacity: 0; }
    100% { transform: translateX(0); opacity: 1; }
}

/* Dealer indicator slide */
.dealer-slide {
    animation: dealerSlide var(--anim-normal) var(--ease-smooth);
}

@keyframes dealerSlide {
    0% { transform: translateX(-20px); opacity: 0; }
    100% { transform: translateX(0); opacity: 1; }
}

/* Page transition fade */
.page-fade-in {
    animation: pageFadeIn var(--anim-normal) var(--ease-smooth);
}

@keyframes pageFadeIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

.page-fade-out {
    animation: pageFadeOut var(--anim-fast) var(--ease-smooth);
}

@keyframes pageFadeOut {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-10px); }
}

/* ===========================================
   Ambient Background Animations
   =========================================== */

/* Floating card suit symbols */
.ambient-suits {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    overflow: hidden;
    opacity: 0.03;
}

.floating-suit {
    position: absolute;
    font-size: 3rem;
    animation: floatSuit 20s linear infinite;
}

@keyframes floatSuit {
    0% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        transform: translateY(-100px) rotate(360deg);
        opacity: 0;
    }
}

/* Subtle felt texture movement */
.felt-texture {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -2;
    background:
        radial-gradient(ellipse at 20% 30%, rgba(255,255,255,0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 70%, rgba(255,255,255,0.02) 0%, transparent 50%);
    animation: feltMove 30s ease-in-out infinite;
}

@keyframes feltMove {
    0%, 100% {
        background-position: 0% 0%, 100% 100%;
    }
    50% {
        background-position: 10% 10%, 90% 90%;
    }
}

/* ===========================================
   Trick Entry Animations
   =========================================== */

/* Stepper button press */
.stepper-btn:active {
    transform: scale(0.9);
    transition: transform 0.1s;
}

/* Trick count change */
.trick-value-change {
    animation: trickChange var(--anim-fast) var(--ease-bounce);
}

@keyframes trickChange {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* Valid tricks indicator */
.tricks-valid-pulse {
    animation: validPulse 0.5s var(--ease-smooth);
}

@keyframes validPulse {
    0% {
        background-color: rgba(34, 197, 94, 0);
    }
    50% {
        background-color: rgba(34, 197, 94, 0.3);
    }
    100% {
        background-color: rgba(34, 197, 94, 0);
    }
}

/* ===========================================
   Button Hover Effects
   =========================================== */

.btn-hover-lift {
    transition: transform var(--anim-fast) var(--ease-smooth),
                box-shadow var(--anim-fast) var(--ease-smooth);
}

.btn-hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-hover-lift:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ===========================================
   Loading States
   =========================================== */

.loading-dots::after {
    content: '';
    animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
    100% { content: ''; }
}

/* Skeleton loading */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s infinite;
}

@keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===========================================
   Score History Table Animations
   =========================================== */

.history-row-enter {
    animation: rowEnter var(--anim-normal) var(--ease-smooth);
}

@keyframes rowEnter {
    0% {
        opacity: 0;
        transform: translateX(-20px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Highlight new row */
.history-row-new {
    animation: rowHighlight 2s var(--ease-smooth);
}

@keyframes rowHighlight {
    0% {
        background-color: rgba(59, 130, 246, 0.3);
    }
    100% {
        background-color: transparent;
    }
}

/* ===========================================
   Team Block Animations
   =========================================== */

/* Leading team glow */
.team-leading {
    animation: leadingGlow 3s ease-in-out infinite;
}

@keyframes leadingGlow {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
    50% {
        box-shadow: 0 0 20px 5px rgba(34, 197, 94, 0.2);
    }
}

/* Score difference indicator */
.score-diff-positive {
    color: #22c55e;
    animation: diffBounce var(--anim-fast) var(--ease-bounce);
}

.score-diff-negative {
    color: #ef4444;
    animation: diffBounce var(--anim-fast) var(--ease-bounce);
}

@keyframes diffBounce {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ===========================================
   Utility Classes
   =========================================== */

.animate-fade-in {
    animation: fadeIn var(--anim-normal) var(--ease-smooth);
}

@keyframes fadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

.animate-slide-up {
    animation: slideUp var(--anim-normal) var(--ease-smooth);
}

@keyframes slideUp {
    0% { opacity: 0; transform: translateY(20px); }
    100% { opacity: 1; transform: translateY(0); }
}

.animate-scale-in {
    animation: scaleIn var(--anim-normal) var(--ease-bounce);
}

@keyframes scaleIn {
    0% { opacity: 0; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1); }
}

.animate-pulse {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Delay utilities */
.delay-100 { animation-delay: 0.1s; }
.delay-200 { animation-delay: 0.2s; }
.delay-300 { animation-delay: 0.3s; }
.delay-400 { animation-delay: 0.4s; }
.delay-500 { animation-delay: 0.5s; }
