/**
 * 🧪 Chemistry Platform Preloader Styles
 * Unified & Ultra-Smooth Loading System for Dr. Tarek Yousif Platform
 */

:root {
    --preloader-bg: #060a12;
    --preloader-accent: #38bdf8;
    --preloader-primary: #0284c7;
    --preloader-glow: rgba(56, 189, 248, 0.28);
}

/* Base Preloader Overlay */
#chemistryPreloader {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--preloader-bg);
    background-image: 
        radial-gradient(circle at 50% 38%, rgba(14, 165, 233, 0.16) 0%, transparent 60%),
        radial-gradient(circle at 80% 20%, rgba(99, 102, 241, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 20% 80%, rgba(2, 132, 199, 0.1) 0%, transparent 50%);
    z-index: 9999999;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    opacity: 1;
    visibility: visible;
    transition: opacity 0.42s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.42s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.42s ease;
    font-family: 'Cairo', 'Alexandria', sans-serif;
    direction: rtl;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
    overflow: hidden;
}

/* Hidden state for smooth reveal */
#chemistryPreloader.preloader-hidden {
    opacity: 0 !important;
    visibility: hidden !important;
    transform: scale(1.03) !important;
    pointer-events: none !important;
}

/* Content Container Card */
.preloader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    z-index: 2;
    padding: 1.5rem;
    max-width: 440px;
    width: 90%;
    animation: preloaderCardPop 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Ambient Radial Glow behind Scientist */
.preloader-halo {
    position: absolute;
    width: 270px;
    height: 270px;
    background: radial-gradient(circle, var(--preloader-glow) 0%, rgba(56, 189, 248, 0) 70%);
    border-radius: 50%;
    filter: blur(30px);
    pointer-events: none;
    z-index: -1;
    animation: preloaderHaloPulse 2.8s ease-in-out infinite alternate;
}

/* Lottie Player Container */
.preloader-lottie-wrap {
    width: 175px;
    height: 175px;
    margin-bottom: 0.85rem;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    filter: drop-shadow(0 10px 25px rgba(56, 189, 248, 0.22));
}

.preloader-lottie-wrap dotlottie-player,
.preloader-lottie-wrap lottie-player {
    width: 100%;
    height: 100%;
}

/* Student Welcome Pill */
.preloader-student-greeting {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.88rem;
    font-weight: 700;
    color: #38bdf8;
    background: linear-gradient(135deg, rgba(14, 165, 233, 0.18), rgba(99, 102, 241, 0.18));
    border: 1px solid rgba(56, 189, 248, 0.35);
    padding: 0.3rem 0.95rem;
    border-radius: 9999px;
    margin-bottom: 0.6rem;
    box-shadow: 0 4px 15px rgba(14, 165, 233, 0.15);
    backdrop-filter: blur(8px);
    animation: preloaderBadgeGlow 2s ease-in-out infinite alternate;
}

/* Brand Title & Badge */
.preloader-brand-title {
    font-size: 1.45rem;
    font-weight: 800;
    color: #ffffff;
    margin: 0 0 0.35rem 0;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: linear-gradient(135deg, #ffffff 35%, #38bdf8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.preloader-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: #93c5fd;
    background: rgba(14, 165, 233, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.2);
    padding: 0.2rem 0.8rem;
    border-radius: 9999px;
    margin-bottom: 1.15rem;
    backdrop-filter: blur(6px);
}

/* Progress Area (Bar + Percentage) */
.preloader-progress-area {
    width: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.preloader-progress-track {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 9999px;
    overflow: hidden;
    position: relative;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}

.preloader-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #0284c7, #38bdf8, #818cf8, #38bdf8);
    background-size: 200% 100%;
    border-radius: 9999px;
    box-shadow: 0 0 14px #38bdf8;
    animation: preloaderProgressShine 1.8s linear infinite;
}

.preloader-percent-text {
    font-size: 0.72rem;
    font-weight: 700;
    color: #38bdf8;
    letter-spacing: 0.05em;
    font-family: monospace, 'Cairo', sans-serif;
}

/* Dynamic Chem Micro-Copy */
.preloader-status-text {
    font-size: 0.83rem;
    color: #94a3b8;
    margin: 0;
    min-height: 1.4em;
    transition: opacity 0.25s ease;
    font-weight: 500;
    line-height: 1.5;
}

/* Keyframe Animations */
@keyframes preloaderCardPop {
    0% {
        opacity: 0;
        transform: translateY(12px) scale(0.97);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes preloaderHaloPulse {
    0% {
        transform: scale(0.9);
        opacity: 0.45;
    }
    100% {
        transform: scale(1.15);
        opacity: 0.85;
    }
}

@keyframes preloaderBadgeGlow {
    0% {
        box-shadow: 0 0 10px rgba(56, 189, 248, 0.15);
        border-color: rgba(56, 189, 248, 0.25);
    }
    100% {
        box-shadow: 0 0 20px rgba(56, 189, 248, 0.35);
        border-color: rgba(56, 189, 248, 0.55);
    }
}

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

/* Mobile Responsiveness */
@media (max-width: 480px) {
    .preloader-lottie-wrap {
        width: 140px;
        height: 140px;
        margin-bottom: 0.75rem;
    }
    .preloader-brand-title {
        font-size: 1.25rem;
    }
    .preloader-student-greeting {
        font-size: 0.8rem;
        padding: 0.25rem 0.8rem;
    }
    .preloader-progress-area {
        width: 170px;
    }
    .preloader-status-text {
        font-size: 0.76rem;
    }
}

/* Accessibility: Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    #chemistryPreloader {
        transition: opacity 0.15s ease !important;
    }
    .preloader-halo,
    .preloader-content,
    .preloader-student-greeting {
        animation: none !important;
    }
}
