/**
 * Unified Storm Loader CSS - SINGLE SOURCE OF TRUTH
 * Optimized for performance and bug-free operation
 */

/* Base Loading Overlay */
.storm-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: linear-gradient(135deg, #1a202c 0%, #2d3748 25%, #4a5568 50%, #2b6cb0 75%, #3182ce 100%);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.6s ease-out, visibility 0.6s ease-out;
    backdrop-filter: blur(4px);
    will-change: opacity, visibility;
}

.storm-loading-overlay.show {
    opacity: 1;
    visibility: visible;
}

.storm-loading-overlay.fade-out {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.storm-loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    display: none;
}

/* Loading Content Container */
.storm-loading-content {
    text-align: center;
    color: white;
    z-index: 100001;
    max-width: 400px;
    padding: 0 20px;
}

.storm-loading-title {
    font-size: 2.5rem;
    font-weight: bold;
    margin-bottom: 15px;
    text-shadow: 0 3px 6px rgba(0,0,0,0.4);
    letter-spacing: 1px;
}

.storm-loading-message {
    font-size: 1.2rem;
    margin-bottom: 40px;
    opacity: 0.9;
    transition: opacity 0.3s ease;
    line-height: 1.5;
}

/* Storm Animation Container */
.storm-animation {
    width: 140px;
    height: 140px;
    margin: 0 auto 30px;
    position: relative;
    transition: opacity 0.3s ease, transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

/* Animated Elements for Themed Loaders */
.animated-element {
    font-size: 2.5rem;
    animation: elementBounce 1.2s ease-in-out infinite;
    transform-origin: center;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

@keyframes elementBounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0) scale(1);
    }
    40% {
        transform: translateY(-10px) scale(1.1);
    }
    60% {
        transform: translateY(-5px) scale(1.05);
    }
}

/* Theme-specific animation containers */
.storm-lightning .animated-element {
    color: #fbbf24;
    filter: drop-shadow(0 0 8px #fbbf24);
    animation: lightningFlash 1.5s ease-in-out infinite;
}

.storm-bubbles .animated-element {
    color: #60a5fa;
    filter: drop-shadow(0 0 6px #60a5fa);
    animation: bubbleFloat 2s ease-in-out infinite;
}

.storm-shingles .animated-element {
    color: #d97706;
    filter: drop-shadow(0 0 6px #d97706);
    animation: shingleSlide 1.8s ease-in-out infinite;
}

.storm-metallic .animated-element {
    color: #9ca3af;
    filter: drop-shadow(0 0 6px #9ca3af);
    animation: metallicShine 1.6s ease-in-out infinite;
}

.storm-money .animated-element {
    color: #10b981;
    filter: drop-shadow(0 0 6px #10b981);
    animation: moneyFlow 1.4s ease-in-out infinite;
}

.storm-construction .animated-element {
    color: #f59e0b;
    filter: drop-shadow(0 0 6px #f59e0b);
    animation: constructionBuild 1.7s ease-in-out infinite;
}

.storm-justice .animated-element {
    color: #3b82f6;
    filter: drop-shadow(0 0 6px #3b82f6);
    animation: justiceScale 1.5s ease-in-out infinite;
}

/* Default spinner for pages without specific animations */
.default-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid #3182ce;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Theme-specific keyframes */
@keyframes lightningFlash {
    0%, 50%, 100% { opacity: 1; transform: scale(1); }
    25% { opacity: 0.7; transform: scale(1.2); }
    75% { opacity: 0.9; transform: scale(0.9); }
}

@keyframes bubbleFloat {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-15px) scale(1.1); }
}

@keyframes shingleSlide {
    0%, 100% { transform: translateX(0) rotate(0deg); }
    50% { transform: translateX(5px) rotate(5deg); }
}

@keyframes metallicShine {
    0%, 100% { filter: drop-shadow(0 0 6px #9ca3af) brightness(1); }
    50% { filter: drop-shadow(0 0 12px #9ca3af) brightness(1.3); }
}

@keyframes moneyFlow {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    33% { transform: translateY(-8px) rotate(10deg); }
    66% { transform: translateY(-4px) rotate(-5deg); }
}

@keyframes constructionBuild {
    0%, 100% { transform: translateY(0) scale(1); }
    25% { transform: translateY(-5px) scale(1.05); }
    50% { transform: translateY(-10px) scale(1.1); }
    75% { transform: translateY(-5px) scale(1.05); }
}

@keyframes justiceScale {
    0%, 100% { transform: scale(1) rotate(0deg); }
    50% { transform: scale(1.15) rotate(5deg); }
}

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

/* Loading Dots Animation */
.storm-loading-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 20px;
}

.storm-loading-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.7);
    animation: dot-pulse 1.4s ease-in-out infinite;
}

.storm-loading-dots span:nth-child(1) { animation-delay: 0s; }
.storm-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.storm-loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
    0%, 60%, 100% { 
        opacity: 0.4; 
        transform: scale(1); 
    }
    30% { 
        opacity: 1; 
        transform: scale(1.2); 
    }
}

/* Storm Progress Bar */
.storm-progress {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    overflow: hidden;
    margin: 20px auto 10px;
}

.storm-progress-bar {
    height: 100%;
    background: #3182ce;
    border-radius: 2px;
    animation: progress-flow 2s ease-in-out infinite;
}

@keyframes progress-flow {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

/* Lightning Storm Animation */
.lightning-storm {
    position: relative;
    width: 140px;
    height: 140px;
}

.lightning-cloud {
    width: 100px;
    height: 50px;
    background: linear-gradient(135deg, #4a5568, #2d3748);
    border-radius: 50px;
    position: absolute;
    top: 25px;
    left: 20px;
    box-shadow: 0 6px 12px rgba(0,0,0,0.4);
}

.lightning-cloud::before {
    content: '';
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #4a5568, #2d3748);
    border-radius: 50%;
    position: absolute;
    top: -30px;
    left: 15px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.lightning-cloud::after {
    content: '';
    width: 70px;
    height: 50px;
    background: linear-gradient(135deg, #4a5568, #2d3748);
    border-radius: 50px;
    position: absolute;
    top: -20px;
    right: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.lightning-bolt {
    position: absolute;
    top: 65px;
    left: 55px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 35px solid #ffd700;
    animation: lightning-flash 1.2s infinite;
    filter: drop-shadow(0 0 8px #ffd700);
}

.lightning-bolt::after {
    content: '';
    position: absolute;
    top: 35px;
    left: -8px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 25px solid #ffd700;
}

@keyframes lightning-flash {
    0%, 15%, 35%, 55%, 75%, 95%, 100% { opacity: 0; }
    5%, 25%, 45%, 65%, 85% { opacity: 1; }
}

/* Rain Animation */
.rain-animation {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    opacity: 0.7;
}

.raindrop {
    position: absolute;
    width: 2px;
    height: 20px;
    background: linear-gradient(to bottom, transparent, rgba(135, 206, 235, 0.8));
    border-radius: 0 0 2px 2px;
    animation: falling-rain 1.2s linear infinite;
}

.raindrop:nth-child(1) { left: 10%; animation-delay: 0s; }
.raindrop:nth-child(2) { left: 15%; animation-delay: 0.1s; }
.raindrop:nth-child(3) { left: 25%; animation-delay: 0.2s; }
.raindrop:nth-child(4) { left: 35%; animation-delay: 0.3s; }
.raindrop:nth-child(5) { left: 45%; animation-delay: 0.4s; }
.raindrop:nth-child(6) { left: 55%; animation-delay: 0.5s; }
.raindrop:nth-child(7) { left: 65%; animation-delay: 0.6s; }
.raindrop:nth-child(8) { left: 75%; animation-delay: 0.7s; }
.raindrop:nth-child(9) { left: 85%; animation-delay: 0.8s; }
.raindrop:nth-child(10) { left: 95%; animation-delay: 0.9s; }

@keyframes falling-rain {
    0% { top: -30px; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { top: 100vh; opacity: 0; }
}

/* Hurricane Spiral Animation */
.hurricane-spiral {
    position: relative;
    width: 140px;
    height: 140px;
}

.spiral-center {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 25px;
    height: 25px;
    background: radial-gradient(circle, #1a202c, #2d3748);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
}

.spiral-arm {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 70px;
    height: 5px;
    background: linear-gradient(to right, transparent, rgba(226, 232, 240, 0.8), transparent);
    border-radius: 3px;
    transform-origin: 0 50%;
    animation: hurricane-spin 2.5s linear infinite;
}

.spiral-arm:nth-child(2) {
    transform: rotate(45deg);
    animation-delay: -0.3s;
}

.spiral-arm:nth-child(3) {
    transform: rotate(90deg);
    animation-delay: -0.6s;
}

.spiral-arm:nth-child(4) {
    transform: rotate(135deg);
    animation-delay: -0.9s;
}

@keyframes hurricane-spin {
    0% { transform: rotate(0deg) scale(1); opacity: 1; }
    50% { transform: rotate(180deg) scale(1.3); opacity: 0.6; }
    100% { transform: rotate(360deg) scale(1); opacity: 1; }
}

/* Tornado Animation */
.tornado-animation {
    position: relative;
    width: 140px;
    height: 140px;
}

.tornado-funnel {
    position: absolute;
    bottom: 10px;
    left: 50%;
    width: 0;
    height: 0;
    border-left: 35px solid transparent;
    border-right: 35px solid transparent;
    border-bottom: 110px solid #718096;
    transform: translateX(-50%);
    animation: tornado-sway 3.5s ease-in-out infinite;
    filter: drop-shadow(0 0 10px rgba(0,0,0,0.3));
}

.tornado-debris {
    position: absolute;
    width: 5px;
    height: 5px;
    background: #a0aec0;
    border-radius: 50%;
    animation: debris-swirl 2.2s linear infinite;
    box-shadow: 0 0 3px rgba(160, 174, 192, 0.5);
}

.tornado-debris:nth-child(2) { 
    top: 90px; left: 45px; 
    animation-delay: -0.5s; 
    animation-duration: 2s;
}

.tornado-debris:nth-child(3) { 
    top: 70px; left: 75px; 
    animation-delay: -1s; 
    animation-duration: 2.4s;
}

.tornado-debris:nth-child(4) { 
    top: 50px; left: 55px; 
    animation-delay: -1.5s; 
    animation-duration: 2.1s;
}

.tornado-debris:nth-child(5) { 
    top: 30px; left: 65px; 
    animation-delay: -0.8s; 
    animation-duration: 2.3s;
}

@keyframes tornado-sway {
    0%, 100% { transform: translateX(-50%) rotate(0deg); }
    25% { transform: translateX(-45%) rotate(2deg); }
    75% { transform: translateX(-55%) rotate(-2deg); }
}

@keyframes debris-swirl {
    0% { transform: rotate(0deg) translateX(35px) rotate(0deg); opacity: 0.8; }
    50% { opacity: 1; }
    100% { transform: rotate(360deg) translateX(35px) rotate(-360deg); opacity: 0.8; }
}

/* Progress Bar */
.storm-progress {
    width: 250px;
    height: 8px;
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
    overflow: hidden;
    margin: 25px auto;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.storm-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4fd1c7, #63b3ed, #9f7aea, #f093fb);
    border-radius: 4px;
    width: 0%;
    animation: progress-fill 2s ease-out forwards;
    box-shadow: 0 0 10px rgba(79, 209, 199, 0.5);
}

@keyframes progress-fill {
    0% { width: 0%; }
    100% { width: 100%; }
}

/* Floating Particles */
.floating-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
}

.particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(255,255,255,0.7);
    border-radius: 50%;
    animation: float-particle 5s linear infinite;
    box-shadow: 0 0 6px rgba(255,255,255,0.3);
}

.particle:nth-child(odd) {
    animation-duration: 6s;
    background: rgba(255,255,255,0.5);
    width: 3px;
    height: 3px;
}

@keyframes float-particle {
    0% { 
        transform: translateY(100vh) translateX(0px) rotate(0deg);
        opacity: 0;
    }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { 
        transform: translateY(-50px) translateX(150px) rotate(360deg);
        opacity: 0;
    }
}

/* Rain Storm Specific Animation */
.rain-storm {
    position: relative;
    width: 140px;
    height: 140px;
}

.rain-cloud {
    position: relative;
    width: 120px;
    height: 60px;
    background: linear-gradient(135deg, #4a5568, #2d3748);
    border-radius: 60px;
    margin: 40px auto;
    box-shadow: 0 8px 16px rgba(0,0,0,0.4);
}

.rain-cloud .cloud-part {
    position: absolute;
    background: linear-gradient(135deg, #4a5568, #2d3748);
    border-radius: 50%;
}

.rain-cloud .cloud-part:nth-child(1) {
    width: 50px;
    height: 50px;
    top: -25px;
    left: 20px;
}

.rain-cloud .cloud-part:nth-child(2) {
    width: 60px;
    height: 45px;
    top: -20px;
    right: 15px;
    border-radius: 45px;
}

.rain-cloud .cloud-part:nth-child(3) {
    width: 40px;
    height: 40px;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
}

/* Desktop Specific Styles */
@media (min-width: 768px) {
    .storm-loading-title {
        font-size: 3rem;
        margin-bottom: 20px;
    }
    
    .storm-loading-message {
        font-size: 1.3rem;
        margin-bottom: 50px;
    }
    
    .storm-animation {
        width: 160px;
        height: 160px;
        margin-bottom: 40px;
    }
    
    .lightning-storm,
    .hurricane-spiral,
    .tornado-animation,
    .rain-storm {
        width: 160px;
        height: 160px;
    }
    
    .storm-progress {
        width: 300px;
        height: 10px;
    }
    
    .floating-particles .particle {
        width: 5px;
        height: 5px;
    }
}

/* Mobile Specific Styles */
@media (max-width: 767px) {
    .storm-loading-title {
        font-size: 2rem;
    }
    
    .storm-loading-message {
        font-size: 1rem;
        padding: 0 15px;
        margin-bottom: 30px;
    }
    
    .storm-animation {
        width: 120px;
        height: 120px;
        margin-bottom: 25px;
    }
    
    .lightning-storm,
    .hurricane-spiral,
    .tornado-animation,
    .rain-storm {
        width: 120px;
        height: 120px;
    }
    
    .storm-progress {
        width: 200px;
        height: 6px;
    }
}

/* Transition Effects */
.page-transition-enter {
    opacity: 0;
    transform: translateY(30px) scale(0.9);
}

.page-transition-enter-active {
    opacity: 1;
    transform: translateY(0) scale(1);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.page-transition-exit {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.page-transition-exit-active {
    opacity: 0;
    transform: translateY(-30px) scale(1.1);
    transition: opacity 0.4s ease-in, transform 0.4s ease-in;
}

/* Theme Variations */
.storm-loading-overlay.theme-emergency {
    background: linear-gradient(135deg, #742a2a 0%, #c53030 50%, #e53e3e 100%);
}

.storm-loading-overlay.theme-success {
    background: linear-gradient(135deg, #22543d 0%, #38a169 50%, #48bb78 100%);
}

.storm-loading-overlay.theme-info {
    background: linear-gradient(135deg, #2a4365 0%, #3182ce 50%, #4299e1 100%);
}

/* High Performance Optimizations */
.storm-loading-overlay * {
    will-change: transform, opacity;
    backface-visibility: hidden;
    perspective: 1000px;
}

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