/* ========================================
   LOADING SCREEN STYLES - GUARANTEED FADE
   ======================================== */

.loading-screen {
    /* Guaranteed fullscreen positioning */
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    margin: 0 !important;
    padding: 0 !important;
    padding-bottom: 10vh !important;
    /* Visually lift content to appear centered on mobile */
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    z-index: 999999 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    overflow: hidden !important;
    overscroll-behavior: none !important;
    transition: opacity 0.4s ease-out;
}

/* Safari-specific fix: Use pseudo-element to fill gap instead of changing container height */
@media not all and (min-resolution:.001dpcm) {
    @supports (-webkit-appearance:none) and (not (overflow:-webkit-marquee)) and (not (-ms-ime-align:auto)) and (not (-moz-appearance:none)) {
        .loading-screen {
            overflow: visible !important;
            /* Allow pseudo-element to extend outside */
        }

        .loading-screen::after {
            content: '';
            position: absolute;
            left: 0;
            right: 0;
            top: 100%;
            height: 50vh;
            background: linear-gradient(135deg, #e2e8f0 0%, #e2e8f0 100%);
            /* Match the bottom color of the gradient */
            z-index: 999999;
        }
    }
}

.loading-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1000"><defs><pattern id="loading-grid" width="40" height="40" patternUnits="userSpaceOnUse"><path d="M 40 0 L 0 0 0 40" fill="none" stroke="rgba(59,130,246,0.05)" stroke-width="1"/></pattern></defs><rect width="100%" height="100%" fill="url(%23loading-grid)" /></svg>');
    opacity: 0.5;
    animation: gridPulse 6s ease-in-out infinite;
}

/* When hidden, ONLY change opacity - this ensures smooth transition */
.loading-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

/* Loading Logo */
.loading-logo {
    margin-bottom: 40px;
    animation: logoEntrance 1s ease-out;
}

.loading-logo-svg {
    width: 200px;
    height: auto;
    filter: drop-shadow(0 8px 25px rgba(59, 130, 246, 0.2));
    animation: pulse 2s ease-in-out infinite;
}

/* Logo SVG Styles */
.loading-logo-e {
    fill: url(#loading-logo-d);
}

.loading-logo-f {
    fill: url(#loading-logo-c);
}

.loading-logo-g {
    fill: url(#loading-logo-b);
}

.loading-logo-h {
    fill: #302d96;
}

.loading-logo-i {
    fill: #1e00ff;
}

/* Loading Content */
.loading-content {
    text-align: center;
    max-width: 500px;
    position: relative;
    z-index: 10;
}

.loading-title {
    font-size: 24px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 12px;
    animation: fadeInUp 0.8s ease-out 0.3s both;
}

.loading-subtitle {
    font-size: 16px;
    color: #6b7280;
    margin-bottom: 40px;
    animation: fadeInUp 0.8s ease-out 0.4s both;
}

/* Progress Bar */
.loading-progress {
    width: 300px;
    height: 4px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin: 0 auto 20px;
    animation: fadeInUp 0.8s ease-out 0.5s both;
}

.loading-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #1d4ed8);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease-out;
}

/* Loading Status Text */
.loading-status {
    font-size: 14px;
    color: #3b82f6;
    font-weight: 500;
    min-height: 20px;
    animation: fadeInUp 0.8s ease-out 0.6s both;
    transition: opacity 0.3s ease;
}

/* Loading Particles */
.loading-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.3;
}

.loading-particle {
    position: absolute;
    width: 3px;
    height: 3px;
    background: rgba(59, 130, 246, 0.4);
    border-radius: 50%;
    animation: floatParticle 4s ease-in-out infinite;
}

/* ========================================
   KEYFRAME ANIMATIONS
   ======================================== */

@keyframes gridPulse {

    0%,
    100% {
        opacity: 0.3;
    }

    50% {
        opacity: 0.6;
    }
}

@keyframes logoEntrance {
    0% {
        opacity: 0;
        transform: translateY(-30px) scale(0.8);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

@keyframes fadeInUp {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes progressFill {
    0% {
        width: 0%;
    }

    15% {
        width: 12%;
    }

    30% {
        width: 28%;
    }

    45% {
        width: 48%;
    }

    60% {
        width: 68%;
    }

    75% {
        width: 85%;
    }

    90% {
        width: 95%;
    }

    100% {
        width: 100%;
    }
}

@keyframes floatParticle {

    0%,
    100% {
        transform: translateY(0px) translateX(0px);
        opacity: 0.4;
    }

    25% {
        transform: translateY(-20px) translateX(10px);
        opacity: 0.8;
    }

    50% {
        transform: translateY(-10px) translateX(-15px);
        opacity: 0.6;
    }

    75% {
        transform: translateY(-25px) translateX(5px);
        opacity: 0.8;
    }
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
    .loading-logo-svg {
        width: 150px;
    }

    .loading-title {
        font-size: 20px;
    }

    .loading-subtitle {
        font-size: 14px;
        margin-bottom: 30px;
    }

    .loading-progress {
        width: 250px;
    }

    .loading-status {
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .loading-logo-svg {
        width: 120px;
    }

    .loading-logo {
        margin-bottom: 30px;
    }

    .loading-title {
        font-size: 18px;
    }

    .loading-subtitle {
        font-size: 13px;
    }

    .loading-progress {
        width: 200px;
    }
}

/* Mobile Landscape Optimization */
@media (max-height: 500px) and (orientation: landscape) {
    .loading-logo {
        margin-bottom: 15px;
    }

    .loading-logo-svg {
        width: 80px;
    }

    .loading-title {
        font-size: 16px;
        margin-bottom: 8px;
    }

    .loading-subtitle {
        font-size: 12px;
        margin-bottom: 15px;
    }

    .loading-progress {
        width: 180px;
        margin-bottom: 10px;
    }

    .loading-status {
        font-size: 12px;
    }
}

/* Ensure fullscreen on all iOS devices including iPhone SE, iPhone 13 mini, etc */
@supports (-webkit-touch-callout: none) {
    .loading-screen {
        /* iOS-specific fullscreen hack */
        min-height: -webkit-fill-available !important;
        height: -webkit-fill-available !important;
        /* Force taller height to fill gap */
        min-height: 110vh !important;
        height: 110vh !important;
    }
}