/* =================================================================
   QUIZSEO PERFORMANCE OPTIMIZATION CSS
   Core Web Vitals & Speed Optimization Styles
   Version: 3.2.0
   Author: MiniMax Agent
   ================================================================= */

/* ===============================================
   CRITICAL CSS - LOADED INLINE FOR FASTEST LCP
   =============================================== */

/* Core container optimizations */
.quizSEO-container-optimized {
    contain: layout style paint;
    will-change: transform;
    position: relative;
    max-width: 100%;
    margin: 0 auto;
}

/* Question progressive loading optimizations */
.quizSEO-question-optimized {
    contain: layout style;
    margin-bottom: 1.5em;
    transition: opacity 0.3s ease;
}

.quizSEO-question-optimized:not(.loaded) {
    opacity: 0.7;
}

.quizSEO-question-optimized.loaded {
    opacity: 1;
}

/* ===============================================
   LAZY LOADING OPTIMIZATIONS
   =============================================== */

/* Image lazy loading styles */
.quizSEO-img-container {
    position: relative;
    overflow: hidden;
    background: #f5f5f5;
    border-radius: 4px;
}

.quizSEO-img-container[data-lazy-container="true"] {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.quizSEO-img-container img[data-lazy="true"]:not(.quizSEO-img-loaded) {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.quizSEO-img-container img.quizSEO-img-loaded {
    opacity: 1;
}

/* Skeleton loader for images */
.quizSEO-img-container[data-lazy-container="true"]::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: quizSEO-skeleton-loading 1.5s infinite;
    z-index: 1;
}

.quizSEO-img-container img.quizSEO-img-loaded + ::before {
    display: none;
}

@keyframes quizSEO-skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===============================================
   PROGRESSIVE LOADING STYLES
   =============================================== */

/* Question placeholder */
.quizSEO-question-placeholder {
    min-height: 200px;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1.5em;
    margin-bottom: 1.5em;
    position: relative;
    overflow: hidden;
}

.quizSEO-question-skeleton {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: quizSEO-skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

/* Loading indicator */
.quizSEO-loading-indicator {
    text-align: center;
    padding: 2em;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    margin-bottom: 1em;
}

.quizSEO-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007cba;
    border-radius: 50%;
    animation: quizSEO-spin 1s linear infinite;
    margin: 0 auto 1em;
}

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

/* ===============================================
   CORE WEB VITALS OPTIMIZATIONS
   =============================================== */

/* Prevent Cumulative Layout Shift (CLS) */
.quizSEO-question-title {
    line-height: 1.4;
    margin-bottom: 0.8em;
    font-weight: 600;
    min-height: 1.4em; /* Reserve space to prevent shift */
}

.quizSEO-answers {
    list-style: none;
    padding: 0;
    margin: 0;
    min-height: 120px; /* Reserve space for answers */
}

.quizSEO-answer {
    margin-bottom: 0.5em;
    padding: 0.75em;
    border: 2px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #f9f9f9;
    min-height: 44px; /* Touch target size */
    display: flex;
    align-items: center;
}

.quizSEO-answer:hover {
    background: #f0f8ff;
    border-color: #007cba;
    transform: translateY(-1px);
}

.quizSEO-answer.selected {
    background: #e3f2fd;
    border-color: #1976d2;
}

/* Optimize button performance */
.quizSEO-button {
    background: #007cba;
    color: #fff;
    border: none;
    padding: 0.75em 1.5em;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 600;
    transition: background-color 0.2s ease, transform 0.1s ease;
    min-height: 44px;
    min-width: 120px;
    position: relative;
    overflow: hidden;
}

.quizSEO-button:hover {
    background: #005a87;
    transform: translateY(-1px);
}

.quizSEO-button:active {
    transform: translateY(0);
}

.quizSEO-button:focus {
    outline: 2px solid #4285f4;
    outline-offset: 2px;
}

/* Progress bar optimization */
.quizSEO-progress {
    width: 100%;
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    margin-bottom: 1.5em;
    overflow: hidden;
    position: relative;
}

.quizSEO-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #007cba, #4fc3f7);
    border-radius: 4px;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.quizSEO-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: quizSEO-progress-shine 2s infinite;
}

@keyframes quizSEO-progress-shine {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* ===============================================
   MOBILE OPTIMIZATION
   =============================================== */

@media (max-width: 768px) {
    .quizSEO-container-optimized {
        padding: 0.5em;
    }
    
    .quizSEO-question-optimized {
        margin-bottom: 1em;
    }
    
    .quizSEO-answer {
        padding: 1em;
        margin-bottom: 0.75em;
        min-height: 48px; /* Larger touch targets on mobile */
    }
    
    .quizSEO-button {
        width: 100%;
        margin-bottom: 0.5em;
        min-height: 48px;
    }
    
    .quizSEO-question-title {
        font-size: 1.1em;
        line-height: 1.3;
    }
}

/* ===============================================
   SECONDARY CONTENT (LOADED AFTER CRITICAL)
   =============================================== */

.quizSEO-secondary-content {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.quizSEO-secondary-content.loaded {
    opacity: 1;
}

/* Quiz statistics and charts */
.quizSEO-chart-container {
    contain: layout style paint;
    min-height: 300px;
    background: #fafafa;
    border-radius: 8px;
    padding: 1em;
    margin: 1em 0;
}

.quizSEO-statistics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1em;
    margin: 1em 0;
}

.quizSEO-stat-item {
    background: #fff;
    padding: 1.5em;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    text-align: center;
    transition: transform 0.2s ease;
}

.quizSEO-stat-item:hover {
    transform: translateY(-2px);
}

/* ===============================================
   PRINT STYLES
   =============================================== */

@media print {
    .quizSEO-loading-indicator,
    .quizSEO-spinner,
    .quizSEO-question-placeholder {
        display: none !important;
    }
    
    .quizSEO-question-content {
        display: block !important;
    }
    
    .quizSEO-container-optimized {
        max-width: none;
    }
}

/* ===============================================
   REDUCED MOTION SUPPORT
   =============================================== */

@media (prefers-reduced-motion: reduce) {
    .quizSEO-answer,
    .quizSEO-button,
    .quizSEO-progress-bar,
    .quizSEO-question-optimized,
    .quizSEO-img-container img {
        transition: none;
    }
    
    .quizSEO-spinner,
    .quizSEO-skeleton-loading,
    .quizSEO-progress-shine {
        animation: none;
    }
}

/* ===============================================
   HIGH CONTRAST SUPPORT
   =============================================== */

@media (prefers-contrast: high) {
    .quizSEO-answer {
        border-color: #333;
        background: #fff;
    }
    
    .quizSEO-answer:hover {
        background: #e0e0e0;
        border-color: #000;
    }
    
    .quizSEO-button {
        background: #000;
        color: #fff;
        border: 2px solid #000;
    }
    
    .quizSEO-button:hover {
        background: #333;
    }
}

/* ===============================================
   DARK MODE SUPPORT
   =============================================== */

@media (prefers-color-scheme: dark) {
    .quizSEO-container-optimized {
        color: #e0e0e0;
    }
    
    .quizSEO-question-placeholder {
        background: #2a2a2a;
        border-color: #404040;
    }
    
    .quizSEO-answer {
        background: #3a3a3a;
        color: #e0e0e0;
        border-color: #555;
    }
    
    .quizSEO-answer:hover {
        background: #4a4a4a;
        border-color: #007cba;
    }
    
    .quizSEO-answer.selected {
        background: #1a3a5a;
        border-color: #4fc3f7;
    }
    
    .quizSEO-chart-container {
        background: #2a2a2a;
    }
    
    .quizSEO-stat-item {
        background: #3a3a3a;
        color: #e0e0e0;
    }
}

/* ===============================================
   PERFORMANCE UTILITIES
   =============================================== */

/* GPU acceleration for smooth animations */
.quizSEO-gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
}

/* Content visibility optimization */
.quizSEO-content-visibility {
    content-visibility: auto;
    contain-intrinsic-size: 300px;
}

/* Font display optimization */
@font-face {
    font-family: 'QuizSEO-Icons';
    font-display: swap;
    /* Prevents invisible text during font load */
}

/* ===============================================
   LEGACY BROWSER FALLBACKS
   =============================================== */

/* Fallback for browsers without CSS Grid */
.no-cssgrid .quizSEO-statistics {
    display: flex;
    flex-wrap: wrap;
}

.no-cssgrid .quizSEO-stat-item {
    flex: 1 1 200px;
    margin: 0.5em;
}

/* Fallback for browsers without CSS contain */
.no-csscontain .quizSEO-container-optimized,
.no-csscontain .quizSEO-question-optimized {
    contain: none;
}