/**
 * Fast Loading Optimizations
 * Lazy loading, skeleton screens, page transitions, and performance enhancements
 */

/* ===== Page Loading Bar ===== */
#pageLoadingBar {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, #fbbf24, #f59e0b, #fbbf24);
    background-size: 200% 100%;
    z-index: 99999;
    transition: width 0.3s ease, opacity 0.3s ease;
    pointer-events: none;
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.5);
    animation: loadingGlow 1s ease infinite;
}

@keyframes loadingGlow {

    0%,
    100% {
        box-shadow: 0 0 5px rgba(251, 191, 36, 0.3);
    }

    50% {
        box-shadow: 0 0 15px rgba(251, 191, 36, 0.6);
    }
}

/* ===== Skeleton Loading Animations ===== */
@keyframes shimmer {
    0% {
        background-position: -200px 0;
    }

    100% {
        background-position: calc(200px + 100%) 0;
    }
}

.skeleton {
    background: linear-gradient(90deg, #1e293b 0px, #334155 50px, #1e293b 100px);
    background-size: 200px 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: 8px;
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}

.skeleton-title {
    height: 24px;
    width: 60%;
}

.skeleton-card {
    background: #1e293b;
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 16px;
}

/* ===== Lazy Loading Images ===== */
img[data-src] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

img.loaded {
    opacity: 1;
}

/* Low-res placeholder blur effect */
.lazy-img-wrapper {
    position: relative;
    overflow: hidden;
    background: #1e293b;
}

.lazy-img-wrapper::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.1), rgba(139, 92, 246, 0.1));
    animation: pulse 2s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }
}

/* ===== Loading States ===== */
.content-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    min-height: 200px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(251, 191, 36, 0.2);
    border-top-color: #fbbf24;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    margin-top: 16px;
    color: #94a3b8;
    font-size: 14px;
}

/* ===== Fade In Animation ===== */
.fade-in {
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== Instant Tab Switching ===== */
.tab-content {
    will-change: opacity, display;
}

.tab-content.active {
    animation: fadeIn 0.2s ease;
}

/* ===== Optimize Media Loading ===== */
video,
audio {
    will-change: contents;
}

/* Hide video controls during loading */
video:not([data-loaded]) {
    background: #0f172a;
}

/* ===== Reduce Layout Shift ===== */
.audio-player-skeleton {
    height: 160px;
    background: #1e293b;
    border-radius: 20px;
}

.video-player-skeleton {
    aspect-ratio: 16/9;
    background: #0f172a;
    border-radius: 16px;
}

/* ===== Preload States ===== */
[data-preload="false"] {
    visibility: hidden;
    height: 0;
    overflow: hidden;
}

[data-preload="true"] {
    visibility: visible;
    height: auto;
}

/* ===== Instant Click Feedback ===== */
.app-tab:active,
.btn:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
}

/* ===== Hardware Acceleration ===== */
.app-tabs,
.tab-content,
.premium-audio-player,
.premium-video-player {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* ===== Smooth Scrolling ===== */
.audio-playlist,
.video-playlist-items {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* ===== Reduce Animation for Low Power ===== */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}