/**
 * Performance Optimization Styles
 * CSS optimizations for lazy loading, mobile performance, and memory efficiency
 */

/* Lazy Loading Styles */
.lazy-section {
    min-height: 400px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.lazy-section::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: shimmer 2s infinite;
}

.lazy-section.loading {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
}

.lazy-section.loading::after {
    content: '콘텐츠 로딩 중...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2rem;
    color: #1976d2;
    font-weight: 500;
}

.lazy-section.loaded {
    min-height: auto;
    background: transparent;
    animation: fadeInUp 0.6s ease-out;
}

.lazy-section.error {
    background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
}

.lazy-section.error::after {
    content: '콘텐츠 로딩 실패';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2rem;
    color: #c62828;
    font-weight: 500;
}

/* Shimmer animation for loading states */
@keyframes shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Fade in animation for loaded content */
@keyframes fadeInUp {
    0% {
        opacity: 0;
        transform: translateY(30px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Lazy image loading */
img[data-src] {
    opacity: 0;
    transition: opacity 0.3s ease;
    background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
}

img[data-src].loaded {
    opacity: 1;
}

/* Performance optimizations for mobile */
.mobile-optimized * {
    /* Reduce animation complexity on mobile */
    animation-duration: 0.2s !important;
    transition-duration: 0.2s !important;
}

.mobile-optimized .content-card {
    /* Optimize for GPU acceleration */
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
}

.mobile-optimized .floating-emoji {
    /* Disable resource-intensive animations on mobile */
    display: none !important;
}

/* Touch optimizations */
.touch-optimized {
    min-width: 44px;
    min-height: 44px;
    touch-action: manipulation;
}

.touch-active {
    transform: scale(0.95) !important;
    opacity: 0.8 !important;
    transition: all 0.1s ease !important;
}

/* Low memory mode optimizations */
.low-memory-mode * {
    animation-duration: 0.1s !important;
    transition-duration: 0.1s !important;
}

.low-memory-mode .floating-emoji,
.low-memory-mode .background-animation {
    display: none !important;
}

.low-memory-mode .content-card {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
}

/* Paused state for performance */
.paused * {
    animation-play-state: paused !important;
}

/* Scroll performance optimizations */
.scroll-optimized {
    will-change: scroll-position;
    -webkit-overflow-scrolling: touch;
}

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

/* Reduce motion for accessibility and performance */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .floating-emoji,
    .background-animation {
        display: none !important;
    }
}

/* High contrast mode optimizations */
@media (prefers-contrast: high) {
    .lazy-section {
        background: #ffffff;
        border: 2px solid #000000;
    }
    
    .lazy-section.loading {
        background: #f0f0f0;
    }
    
    .lazy-section.error {
        background: #ffe0e0;
    }
}

/* Print optimizations */
@media print {
    .lazy-section,
    .floating-emoji,
    .background-animation,
    .loading-spinner {
        display: none !important;
    }
    
    .content-card {
        break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #ccc;
    }
}

/* Dark mode optimizations */
@media (prefers-color-scheme: dark) {
    .lazy-section {
        background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
    }
    
    .lazy-section.loading {
        background: linear-gradient(135deg, #1a202c 0%, #2d3748 100%);
    }
    
    .lazy-section.loading::after {
        color: #90cdf4;
    }
    
    .lazy-section.error {
        background: linear-gradient(135deg, #742a2a 0%, #9b2c2c 100%);
    }
    
    .lazy-section.error::after {
        color: #feb2b2;
    }
}

/* Container queries for responsive performance */
@container (max-width: 480px) {
    .content-card {
        contain-intrinsic-size: 250px;
    }
    
    .lazy-section {
        min-height: 300px;
    }
}

/* GPU acceleration hints */
.gpu-accelerated {
    transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
}

/* Memory efficient gradients */
.efficient-gradient {
    background-image: linear-gradient(135deg, var(--gradient-start, #667eea) 0%, var(--gradient-end, #764ba2) 100%);
}

/* Optimized focus states */
.focus-optimized:focus {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
}

/* Performance monitoring indicators */
.performance-indicator {
    position: fixed;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
    z-index: 9999;
    pointer-events: none;
}

.performance-indicator.good {
    background: rgba(76, 175, 80, 0.8);
}

.performance-indicator.warning {
    background: rgba(255, 152, 0, 0.8);
}

.performance-indicator.critical {
    background: rgba(244, 67, 54, 0.8);
}

/* Intersection observer root margin optimization */
.intersection-root {
    overflow: hidden;
    position: relative;
}

/* Lazy loading placeholder improvements */
.lazy-placeholder {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading-shimmer 2s infinite;
}

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

/* Content loading states */
.content-loading {
    opacity: 0.6;
    pointer-events: none;
    position: relative;
}

.content-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
}

.content-loaded {
    opacity: 1;
    pointer-events: auto;
    animation: contentFadeIn 0.3s ease-out;
}

@keyframes contentFadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scroll performance improvements */
.scroll-container {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Virtual keyboard optimizations */
.virtual-keyboard-open {
    height: 100vh;
    overflow: hidden;
}

.virtual-keyboard-open .fixed-bottom {
    position: static;
}

/* Battery saving mode */
.battery-saver * {
    animation: none !important;
    transition: none !important;
    transform: none !important;
    filter: none !important;
    backdrop-filter: none !important;
}

.battery-saver .gradient-bg {
    background: #f5f5f5 !important;
}

/* Network-aware optimizations */
.slow-connection .high-quality-image {
    display: none;
}

.slow-connection .low-quality-image {
    display: block;
}

/* Preload hints */
.preload-hint {
    content-visibility: auto;
    contain-intrinsic-size: 200px 100px;
}

/* Critical resource prioritization */
.critical-resource {
    font-display: swap;
    loading: eager;
}

.non-critical-resource {
    loading: lazy;
}

/* Memory leak prevention */
.cleanup-target {
    /* Mark elements for cleanup */
    --cleanup: true;
}

/* Performance debugging */
.debug-performance * {
    outline: 1px solid rgba(255, 0, 0, 0.3);
}

.debug-performance .lazy-section {
    outline: 2px solid rgba(0, 255, 0, 0.5);
}

.debug-performance .loaded {
    outline: 2px solid rgba(0, 0, 255, 0.5);
}