/* ===================================
   AREA 3: INTERACTIVE ELEMENTS & ANIMATIONS
   Optimized Kid-Friendly Playground Interactions
   Performance-First Animation System
   =================================== */

/* ===== CORE ANIMATION SYSTEM ===== */
/* Hardware-accelerated base for all interactive elements */
.playground-button {
    position: relative;
    overflow: hidden;
    border-radius: 25px;
    /* Optimized transition - shorter duration, natural easing */
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                background-color 0.15s ease-out;
    /* Hardware acceleration */
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ===== BUTTON INTERACTIONS ===== */
/* Bouncy Ball Buttons - Optimized for performance */
.bouncy-ball-btn {
    background: radial-gradient(circle at 30% 30%, 
        rgba(255, 255, 255, 0.8) 0%, 
        var(--playground-red) 30%, 
        #c62828 100%);
    box-shadow: 
        0 4px 8px rgba(244, 67, 54, 0.25),
        inset 0 2px 4px rgba(255, 255, 255, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.4);
}

.bouncy-ball-btn:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 
        0 8px 20px rgba(244, 67, 54, 0.3),
        inset 0 3px 6px rgba(255, 255, 255, 0.4);
}

.bouncy-ball-btn:active {
    transform: translateY(-2px) scale(0.98);
    transition-duration: 0.1s;
}

/* Toy Block Buttons - Simplified 3D effect */
.toy-block-btn {
    background: linear-gradient(135deg, 
        var(--sunshine-yellow) 0%, 
        #ffa726 100%);
    border: 3px solid var(--tree-brown);
    border-radius: 8px;
    position: relative;
    box-shadow: 
        0 4px 0 #8d6e63,
        0 6px 12px rgba(0, 0, 0, 0.2);
}

.toy-block-btn::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 6px;
    right: 6px;
    height: 6px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 3px;
}

.toy-block-btn:hover {
    transform: translateY(-3px);
    box-shadow: 
        0 7px 0 #8d6e63,
        0 10px 20px rgba(0, 0, 0, 0.25);
}

.toy-block-btn:active {
    transform: translateY(-1px);
    box-shadow: 
        0 3px 0 #8d6e63,
        0 5px 10px rgba(0, 0, 0, 0.2);
}

/* ===== MICRO-INTERACTIONS ===== */
/* Sound Effect Indicators - Simplified */
.sound-indicator {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    background: radial-gradient(circle, #fff 40%, transparent 70%);
    border-radius: 50%;
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
    transition: all 0.2s ease-out;
}

.sound-indicator::before {
    content: '♪';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    color: var(--playground-red);
    font-weight: bold;
}

.playground-button:hover .sound-indicator {
    opacity: 1;
    transform: scale(1);
    animation: soundPulse 0.4s ease-out;
}

/* ===== FORM ELEMENTS ===== */
/* Sandbox Input Fields */
.sandbox-input {
    background: 
        radial-gradient(circle at 20% 30%, rgba(255,193,7,0.08) 1px, transparent 1px),
        radial-gradient(circle at 80% 70%, rgba(255,235,59,0.08) 1px, transparent 1px),
        linear-gradient(135deg, #fff9c4 0%, #fff59d 100%);
    background-size: 12px 12px, 16px 16px, 100% 100%;
    border: 2px solid var(--tree-brown);
    border-radius: 12px;
    padding: 14px 18px;
    position: relative;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sandbox-input:focus {
    transform: translateY(-1px);
    box-shadow: 
        0 6px 16px rgba(255, 193, 7, 0.2),
        inset 0 1px 4px rgba(255, 235, 59, 0.15);
    border-color: var(--sunshine-yellow);
    outline: none;
}

/* Checkboxes as Playground Balls - Performance optimized */
.playground-ball-checkbox {
    appearance: none;
    width: 28px;
    height: 28px;
    background: radial-gradient(circle at 30% 30%, 
        rgba(255, 255, 255, 0.8) 0%, 
        var(--grass-green) 30%, 
        #2e7d32 100%);
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    cursor: pointer;
    position: relative;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 
        0 2px 6px rgba(76, 175, 80, 0.25),
        inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

.playground-ball-checkbox:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 
        0 4px 12px rgba(76, 175, 80, 0.3),
        inset 0 2px 4px rgba(255, 255, 255, 0.4);
}

.playground-ball-checkbox:checked {
    background: radial-gradient(circle at 30% 30%, 
        rgba(255, 255, 255, 0.9) 0%, 
        var(--sunshine-yellow) 30%, 
        #f57f17 100%);
    transform: scale(1.1);
}

.playground-ball-checkbox:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-weight: bold;
    font-size: 14px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* ===== LOADING STATES ===== */
/* Simplified Merry-go-round Loader */
.merry-go-round-loader {
    width: 48px;
    height: 48px;
    position: relative;
    display: inline-block;
}

.merry-go-round-loader::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 4px solid var(--sunshine-yellow);
    border-radius: 50%;
    border-top-color: var(--playground-red);
    border-right-color: var(--grass-green);
    animation: spin 1.5s linear infinite;
}

.merry-go-round-loader::after {
    content: '🎠';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 18px;
    animation: bob 1s ease-in-out infinite alternate;
}

/* ===== FEEDBACK ANIMATIONS ===== */
/* Success Particles - Reduced count for performance */
.success-particles {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
}

.success-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--sunshine-yellow);
    border-radius: 50%;
    animation: particleFloat 2s ease-out forwards;
}

.success-particle:nth-child(2n) {
    background: var(--playground-red);
    animation-delay: 0.1s;
}

.success-particle:nth-child(3n) {
    background: var(--grass-green);
    animation-delay: 0.2s;
}

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

.confetti {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--playground-red);
    animation: confettiFall 2.5s linear forwards;
}

.confetti:nth-child(2n) { background: var(--sunshine-yellow); }
.confetti:nth-child(3n) { background: var(--grass-green); }
.confetti:nth-child(4n) { background: #9c27b0; }

/* Balloons - Simplified */
.balloon {
    position: fixed;
    bottom: -80px;
    width: 32px;
    height: 48px;
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    animation: balloonFloat 3s ease-out forwards;
}

.balloon::after {
    content: '';
    position: absolute;
    bottom: -16px;
    left: 50%;
    transform: translateX(-50%);
    width: 1px;
    height: 32px;
    background: #666;
}

.balloon-1 { 
    left: 15%; 
    background: var(--playground-red);
    animation-delay: 0s;
}
.balloon-2 { 
    left: 35%; 
    background: var(--sunshine-yellow);
    animation-delay: 0.3s;
}
.balloon-3 { 
    left: 55%; 
    background: var(--grass-green);
    animation-delay: 0.6s;
}
.balloon-4 { 
    left: 75%; 
    background: #9c27b0;
    animation-delay: 0.9s;
}

/* ===== AMBIENT ANIMATIONS ===== */
/* Realistic Butterfly Animations */
.butterfly {
    position: fixed;
    width: 48px;
    height: 36px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.8;
}

/* Butterfly Body */
.butterfly-body {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 28px;
    background: linear-gradient(180deg, #4a2c2a 0%, #6d4c41 50%, #4a2c2a 100%);
    border-radius: 2px;
    z-index: 2;
}

/* Left Wing */
.butterfly::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 6px;
    width: 16px;
    height: 24px;
    background: 
        /* Wing pattern spots */
        radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.8) 3px, transparent 4px),
        radial-gradient(circle at 70% 60%, rgba(255, 255, 255, 0.6) 2px, transparent 3px),
        radial-gradient(circle at 50% 80%, rgba(0, 0, 0, 0.3) 1px, transparent 2px),
        /* Wing base color */
        radial-gradient(ellipse 100% 80%, #ff6b35 0%, #ff8f00 40%, #e65100 100%);
    border-radius: 60% 40% 70% 30%;
    transform-origin: bottom center;
    animation: butterflyWing 0.6s ease-in-out infinite alternate;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 1;
}

/* Right Wing */
.butterfly::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 6px;
    width: 16px;
    height: 24px;
    background: 
        /* Wing pattern spots */
        radial-gradient(circle at 70% 30%, rgba(255, 255, 255, 0.8) 3px, transparent 4px),
        radial-gradient(circle at 30% 60%, rgba(255, 255, 255, 0.6) 2px, transparent 3px),
        radial-gradient(circle at 50% 80%, rgba(0, 0, 0, 0.3) 1px, transparent 2px),
        /* Wing base color */
        radial-gradient(ellipse 100% 80%, #ff6b35 0%, #ff8f00 40%, #e65100 100%);
    border-radius: 40% 60% 30% 70%;
    transform-origin: bottom center;
    animation: butterflyWing 0.6s ease-in-out infinite alternate;
    animation-delay: 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 1;
}

/* Different butterfly species with unique colors and patterns */
.butterfly-1 { 
    top: 20%; 
    animation: butterflyFloat 20s linear infinite;
}

.butterfly-1::before,
.butterfly-1::after {
    background: 
        radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.9) 3px, transparent 4px),
        radial-gradient(circle at 70% 60%, rgba(255, 255, 255, 0.7) 2px, transparent 3px),
        radial-gradient(circle at 50% 80%, #000 1px, transparent 2px),
        radial-gradient(ellipse 100% 80%, #ff6b35 0%, #ff8f00 40%, #e65100 100%);
}

.butterfly-2 { 
    top: 40%; 
    animation: butterflyFloat 25s linear infinite;
    animation-delay: 6s;
}

.butterfly-2::before,
.butterfly-2::after {
    background: 
        radial-gradient(circle at 40% 25%, rgba(255, 255, 255, 0.8) 3px, transparent 4px),
        radial-gradient(circle at 60% 70%, rgba(255, 255, 255, 0.6) 2px, transparent 3px),
        radial-gradient(circle at 30% 50%, #1a237e 2px, transparent 3px),
        radial-gradient(ellipse 100% 80%, #3f51b5 0%, #5c6bc0 40%, #303f9f 100%);
}

.butterfly-3 { 
    top: 60%; 
    animation: butterflyFloat 30s linear infinite;
    animation-delay: 12s;
}

.butterfly-3::before,
.butterfly-3::after {
    background: 
        radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.9) 3px, transparent 4px),
        radial-gradient(circle at 65% 65%, rgba(255, 255, 255, 0.7) 2px, transparent 3px),
        radial-gradient(circle at 50% 20%, #000 1px, transparent 2px),
        radial-gradient(ellipse 100% 80%, #e91e63 0%, #f06292 40%, #c2185b 100%);
}

/* Flying Birds - REMOVED (looked like spiders) */

/* Enhanced Bird Chirp Indicator */
.bird-chirp {
    position: fixed;
    top: 15%;
    right: 20%;
    font-size: 24px;
    opacity: 0;
    transform: scale(0);
    pointer-events: none;
    z-index: 1000;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.3));
}

.bird-chirp.active {
    animation: birdChirp 1.5s ease-out;
}

/* Musical notes that appear with bird chirp */
.bird-chirp::before {
    content: '♪';
    position: absolute;
    top: -10px;
    left: -15px;
    font-size: 14px;
    opacity: 0;
    animation: musicalNote 1.5s ease-out;
    animation-delay: 0.3s;
}

.bird-chirp::after {
    content: '♫';
    position: absolute;
    top: -8px;
    right: -15px;
    font-size: 12px;
    opacity: 0;
    animation: musicalNote 1.5s ease-out;
    animation-delay: 0.6s;
}

/* ===== GENTLE EQUIPMENT MOVEMENTS ===== */
.gentle-sway {
    animation: gentleSway 6s ease-in-out infinite;
}

.gentle-bob {
    animation: gentleBob 4s ease-in-out infinite;
}

.gentle-rock {
    animation: gentleRock 8s ease-in-out infinite;
}

/* ===== ERROR STATES ===== */
.sad-equipment {
    position: relative;
}

.sad-equipment::before {
    content: '😢';
    position: absolute;
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 20px;
    animation: sadBob 1.5s ease-in-out infinite;
}

.sad-shake {
    animation: sadShake 0.4s ease-in-out 2;
}

/* ===== HOVER EFFECTS ===== */
.light-up-hover {
    position: relative;
    transition: all 0.25s ease;
}

.light-up-hover:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 8px 24px rgba(255, 255, 255, 0.15),
        0 0 16px rgba(255, 255, 255, 0.08);
}

/* ===== OPTIMIZED KEYFRAME ANIMATIONS ===== */
@keyframes soundPulse {
    0% { opacity: 0; transform: scale(0); }
    50% { opacity: 1; transform: scale(1.1); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes bob {
    0% { transform: translate(-50%, -50%) translateY(0px); }
    100% { transform: translate(-50%, -50%) translateY(-3px); }
}

@keyframes particleFloat {
    0% {
        opacity: 1;
        transform: translateY(0px) scale(0);
    }
    20% {
        opacity: 1;
        transform: translateY(-16px) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-80px) scale(0);
    }
}

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

@keyframes balloonFloat {
    0% {
        transform: translateY(0px) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(-100vh) rotate(8deg);
        opacity: 0;
    }
}

@keyframes butterflyWing {
    0% { transform: rotateY(0deg); }
    100% { transform: rotateY(-25deg); }
}

@keyframes butterflyFloat {
    0% { left: -40px; }
    100% { left: calc(100% + 40px); }
}

@keyframes birdChirp {
    0% {
        opacity: 0;
        transform: scale(0) translateY(0px);
    }
    25% {
        opacity: 1;
        transform: scale(1) translateY(-8px);
    }
    75% {
        opacity: 1;
        transform: scale(0.9) translateY(-12px);
    }
    100% {
        opacity: 0;
        transform: scale(0) translateY(-16px);
    }
}

@keyframes gentleSway {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(0.8deg); }
}

@keyframes gentleBob {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-2px); }
}

@keyframes gentleRock {
    0%, 100% { transform: rotate(0deg) translateY(0px); }
    25% { transform: rotate(0.4deg) translateY(-1px); }
    75% { transform: rotate(-0.4deg) translateY(-1px); }
}

@keyframes sadBob {
    0%, 100% { transform: translateX(-50%) translateY(0px); }
    50% { transform: translateX(-50%) translateY(3px); }
}

@keyframes sadShake {
    0%, 100% { transform: translateX(0px); }
    25% { transform: translateX(-3px); }
    75% { transform: translateX(3px); }
}

/* Removed bird keyframes - no longer needed */

@keyframes musicalNote {
    0% {
        opacity: 0;
        transform: translateY(0px) scale(0.5);
    }
    30% {
        opacity: 1;
        transform: translateY(-8px) scale(1);
    }
    70% {
        opacity: 1;
        transform: translateY(-16px) scale(0.8);
    }
    100% {
        opacity: 0;
        transform: translateY(-24px) scale(0.3);
    }
}

/* ===== RESPONSIVE ADJUSTMENTS ===== */
@media (max-width: 768px) {
    .butterfly {
        width: 18px;
        height: 12px;
    }
    
    .butterfly::before,
    .butterfly::after {
        width: 7px;
        height: 9px;
    }
    
    .playground-ball-checkbox {
        width: 24px;
        height: 24px;
    }
    
    .merry-go-round-loader {
        width: 36px;
        height: 36px;
    }
    
    .balloon {
        width: 24px;
        height: 36px;
    }
    
    .bird-chirp {
        font-size: 16px;
    }
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    .butterfly,
    .success-particle,
    .confetti,
    .balloon,
    .bird-chirp {
        display: none !important;
    }
    
    .gentle-sway,
    .gentle-bob,
    .gentle-rock {
        animation: none !important;
    }
    
    /* Provide alternative feedback for reduced motion */
    .playground-button:hover {
        outline: 3px solid var(--playground-red);
        outline-offset: 2px;
    }
    
    .sandbox-input:focus {
        outline: 3px solid var(--sunshine-yellow);
        outline-offset: 2px;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .playground-button {
        border: 2px solid currentColor !important;
        background: ButtonFace !important;
        color: ButtonText !important;
    }
    
    .sandbox-input {
        border: 2px solid currentColor !important;
        background: Field !important;
        color: FieldText !important;
    }
    
    .playground-ball-checkbox {
        border: 2px solid currentColor !important;
        background: Field !important;
    }
    
    .playground-ball-checkbox:checked {
        background: Highlight !important;
        color: HighlightText !important;
    }
}

/* Focus Management for Keyboard Navigation */
.playground-button:focus-visible,
.sandbox-input:focus-visible,
.playground-ball-checkbox:focus-visible {
    outline: 3px solid var(--playground-red);
    outline-offset: 2px;
    z-index: 1;
}

/* Ensure animations don't interfere with keyboard navigation */
.playground-button:focus-visible {
    animation: none !important;
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
/* Reduce paint and layout thrashing */
.playground-button,
.sandbox-input,
.playground-ball-checkbox {
    contain: layout style paint;
}

/* Optimize for 60fps animations */
@media (prefers-reduced-motion: no-preference) {
    .playground-button {
        will-change: transform, box-shadow;
    }
    
    .sandbox-input {
        will-change: transform, border-color, box-shadow;
    }
    
    .playground-ball-checkbox {
        will-change: transform, background-color;
    }
}

/* Clean up will-change after animations */
.playground-button:not(:hover):not(:focus):not(:active),
.sandbox-input:not(:focus),
.playground-ball-checkbox:not(:hover):not(:focus):not(:active) {
    will-change: auto;
}
