:root {
    --primary-purple: #79499c;
    --deep-purple: #5a3378;
    --light-purple: #9d6bc9;
    --accent-gold: #e6b325;
    --loader-gradient: linear-gradient(135deg, #1a1033, #2d1b4e, #4a2a7a, #6b3fa0);
}

.loader {
    position: fixed;
    inset: 0;
    background: var(--loader-gradient);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.6s ease;
}

.loader-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2.5rem;
    direction: rtl;
    padding: 20px;
    width: 100%;
    max-width: 500px;
}

/* Enhanced Book Stack with realistic paper movement */
.book-stack {
    position: relative;
    width: 80px;
    height: 100px;
    perspective: 600px;
}

.book {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, var(--primary-purple), var(--light-purple));
    border-radius: 4px 8px 8px 4px;
    transform-origin: left center;
    animation: bookOpen 3s ease-in-out infinite;
    box-shadow: 
        -3px 0 10px rgba(0, 0, 0, 0.2),
        inset -2px 0 3px rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

/* Enhanced paper layers inside books */
.book::before {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    bottom: 2px;
    left: 15px;
    background: linear-gradient(to right,
        transparent 0%,
        rgba(255, 255, 255, 0.15) 1px,
        transparent 2px,
        rgba(255, 255, 255, 0.08) 3px,
        transparent 4px,
        rgba(255, 255, 255, 0.05) 5px,
        transparent 10px);
    border-radius: 3px 6px 6px 1px;
    z-index: 1;
}

.book::after {
    content: '';
    position: absolute;
    top: 1px;
    right: 1px;
    bottom: 1px;
    left: 10px;
    background: repeating-linear-gradient(
        to right,
        transparent 0%,
        rgba(255, 255, 255, 0.03) 1px,
        transparent 2px,
        rgba(255, 255, 255, 0.02) 3px,
        transparent 5px
    );
    border-radius: 3px 7px 7px 2px;
    animation: paperShift 4s ease-in-out infinite;
}

/* Individual paper movement layers */
.book .paper-layer-1,
.book .paper-layer-2,
.book .paper-layer-3 {
    position: absolute;
    top: 3px;
    right: 3px;
    bottom: 3px;
    left: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 2px 5px 5px 1px;
    transform-origin: left center;
}

.book .paper-layer-1 {
    animation: paperTurn 3.5s ease-in-out infinite;
    background: linear-gradient(to right,
        rgba(255, 255, 255, 0.1) 0%,
        rgba(255, 255, 255, 0.03) 30%,
        transparent 100%);
}

.book .paper-layer-2 {
    animation: paperTurn 4s ease-in-out infinite;
    background: linear-gradient(to right,
        rgba(255, 255, 255, 0.07) 0%,
        rgba(255, 255, 255, 0.02) 40%,
        transparent 100%);
    animation-delay: 0.3s;
}

.book .paper-layer-3 {
    animation: paperTurn 4.5s ease-in-out infinite;
    background: linear-gradient(to right,
        rgba(255, 255, 255, 0.04) 0%,
        rgba(255, 255, 255, 0.01) 50%,
        transparent 100%);
    animation-delay: 0.6s;
}

.book:nth-child(1) { 
    animation-delay: 0s; 
    z-index: 3; 
    background: linear-gradient(45deg, var(--primary-purple), var(--light-purple));
}

.book:nth-child(2) { 
    animation-delay: 0.8s; 
    z-index: 2; 
    background: linear-gradient(45deg, var(--deep-purple), var(--primary-purple));
    transform: translateX(10px) scale(0.95);
}

.book:nth-child(3) { 
    animation-delay: 1.6s; 
    z-index: 1; 
    background: linear-gradient(45deg, #2d1b4e, var(--deep-purple));
    transform: translateX(20px) scale(0.9);
}

@keyframes bookOpen {
    0%, 100% { 
        transform: perspective(600px) rotateY(0deg) scale(1);
        box-shadow: 
            -3px 0 10px rgba(0, 0, 0, 0.2),
            inset -2px 0 3px rgba(255, 255, 255, 0.1);
    }
    25% { 
        transform: perspective(600px) rotateY(-10deg) scale(1.02);
        box-shadow: 
            -5px 0 15px rgba(0, 0, 0, 0.25),
            inset -1px 0 5px rgba(255, 255, 255, 0.15);
    }
    50% { 
        transform: perspective(600px) rotateY(-25deg) scale(1.05);
        box-shadow: 
            -8px 0 20px rgba(0, 0, 0, 0.3),
            inset 0 0 6px rgba(255, 255, 255, 0.2);
    }
    75% { 
        transform: perspective(600px) rotateY(-10deg) scale(1.02);
        box-shadow: 
            -5px 0 15px rgba(0, 0, 0, 0.25),
            inset -1px 0 5px rgba(255, 255, 255, 0.15);
    }
}

/* Realistic paper movement animations */
@keyframes paperTurn {
    0%, 100% { 
        transform: rotateY(0deg) translateX(0);
        opacity: 0.6;
    }
    25% { 
        transform: rotateY(-2deg) translateX(1px);
        opacity: 0.8;
    }
    50% { 
        transform: rotateY(-5deg) translateX(2px);
        opacity: 1;
    }
    75% { 
        transform: rotateY(-2deg) translateX(1px);
        opacity: 0.8;
    }
}

@keyframes paperShift {
    0%, 100% { 
        transform: translateX(0) skewY(0deg);
        background-position: 0 0;
    }
    33% { 
        transform: translateX(-1px) skewY(0.5deg);
        background-position: 2px 0;
    }
    66% { 
        transform: translateX(1px) skewY(-0.5deg);
        background-position: -2px 0;
    }
}

/* Paper edge effect */
.book .paper-edge {
    position: absolute;
    left: 10px;
    top: 0;
    width: 3px;
    height: 100%;
    background: linear-gradient(to bottom,
        transparent,
        rgba(255, 255, 255, 0.1),
        transparent);
    z-index: 2;
    animation: edgeGlow 3s ease-in-out infinite;
}

@keyframes edgeGlow {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
}

/* Arabic Word - No change */
.text-loader {
    font-family: 'Almarai', sans-serif;
    font-weight: 800;
    font-size: 3rem;
    color: white;
    position: relative;
    text-align: center;
    text-shadow: 
        0 2px 8px rgba(0, 0, 0, 0.5),
        0 4px 16px rgba(0, 0, 0, 0.3);
    margin: 0;
}

.arabic-word {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px);
    animation: wordAppear 1s ease forwards;
    animation-delay: 0.3s;
}

@keyframes wordAppear {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Progress Bar - No change */
.progress-container {
    width: 100%;
    max-width: 320px;
    margin-top: 1rem;
}

.progress-bar {
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, 
        var(--accent-gold), 
        #ffd166);
    border-radius: 2px;
    position: relative;
    transition: width 0.4s ease;
    box-shadow: 0 0 10px rgba(230, 179, 37, 0.4);
}

.progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(255, 255, 255, 0.3), 
        transparent);
    animation: shimmer 2s infinite ease-in-out;
    will-change: transform;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.progress-text {
    color: rgba(255, 255, 255, 0.85);
    font-family: 'Almarai', sans-serif;
    font-size: 0.85rem;
    margin-top: 0.75rem;
    text-align: center;
    direction: rtl;
    font-weight: 400;
    min-height: 1.2em;
}

/* Floating particles - No change */
.floating-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.3;
}

.particle {
    position: absolute;
    width: 2px;
    height: 2px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    animation: float 20s infinite linear;
    will-change: transform;
}

@keyframes float {
    0% {
        transform: translateY(100vh);
        opacity: 0;
    }
    10%, 90% {
        opacity: 0.6;
    }
    100% {
        transform: translateY(-100px);
        opacity: 0;
    }
}

/* Mobile Optimizations - Updated */
@media (max-width: 768px) {
    .loader-content {
        gap: 2rem;
        padding: 15px;
    }
    
    .book-stack {
        width: 60px;
        height: 75px;
    }
    
    .text-loader {
        font-size: 2.2rem;
    }
    
    .progress-container {
        max-width: 280px;
    }
    
    .book {
        animation: bookOpenMobile 4s ease-in-out infinite;
    }
    
    @keyframes bookOpenMobile {
        0%, 100% { transform: perspective(400px) rotateY(0deg); }
        50% { transform: perspective(400px) rotateY(-15deg); }
    }
}

@media (max-width: 480px) {
    .loader-content {
        gap: 1.5rem;
    }
    
    .book-stack {
        width: 50px;
        height: 65px;
    }
    
    .text-loader {
        font-size: 1.8rem;
    }
    
    .progress-container {
        max-width: 250px;
    }
    
    .progress-text {
        font-size: 0.8rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .book,
    .arabic-word,
    .progress-fill::after,
    .particle,
    .book::after,
    .book .paper-layer-1,
    .book .paper-layer-2,
    .book .paper-layer-3,
    .book .paper-edge {
        animation: none !important;
    }
    
    .arabic-word {
        opacity: 1;
        transform: none;
    }
}