/**
 * 高级性能优化CSS
 * @author Huameitang
 * 这个CSS文件包含了各种性能优化技术
 * 包括GPU加速、渲染优化、内存优化等
 * 针对不同设备和性能级别提供差异化优化
 */

/* ===== 基础性能优化 ===== */

/* 启用硬件加速 */
.gpu-accelerated,
.gpu-accelerated * {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
    will-change: transform, opacity;
}

/* 优化渲染性能 */
.render-optimized {
    contain: layout style paint;
    content-visibility: auto;
}

/* 内存优化 */
.memory-optimized {
    image-rendering: optimizeSpeed;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: optimize-contrast;
}

/* 滚动优化 */
.scroll-optimized {
    scroll-behavior: smooth;
    overflow-anchor: auto;
    overscroll-behavior: contain;
}

/* ===== 性能级别特定优化 ===== */

/* 高性能设备优化 */
.high-performance {
    animation-fill-mode: both;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

.high-performance .hero {
    transform: translate3d(0, 0, 0);
    filter: blur(0);
    transition: all 0.3s ease-out;
}

.high-performance .card {
    transform: translateZ(0);
    transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
}

.high-performance .card:hover {
    transform: translateY(-5px) translateZ(0);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* 中等性能设备优化 */
.medium-performance {
    animation-duration: 0.4s;
    transition-duration: 0.3s;
}

.medium-performance .hero {
    transition: opacity 0.3s ease;
}

.medium-performance .card:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

/* 低性能设备优化 */
.low-performance {
    animation: none !important;
    transition: none !important;
    transform: none !important;
    filter: none !important;
    box-shadow: none !important;
}

.low-performance * {
    animation: none !important;
    transition: none !important;
    transform: none !important;
    filter: none !important;
}

.low-performance .hero {
    background-attachment: scroll;
}

.low-performance .card {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.low-performance .card:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* ===== 移动设备优化 ===== */

.mobile-optimized {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.mobile-optimized img {
    max-width: 100%;
    height: auto;
    image-rendering: optimizeSpeed;
}

.mobile-optimized .hero {
    background-attachment: scroll;
    min-height: 70vh;
}

/* 超小屏幕优化 */
.ultra-mobile-optimized {
    font-size: 14px;
    line-height: 1.4;
}

.ultra-mobile-optimized .hero {
    min-height: 60vh;
    padding: 1rem;
}

.ultra-mobile-optimized .card {
    margin: 0.5rem 0;
    padding: 1rem;
}

/* ===== 高刷新率显示器优化 ===== */

.high-refresh-optimized {
    animation-timing-function: linear;
}

.high-refresh-optimized .smooth-animation {
    animation-duration: 0.1s;
    animation-iteration-count: infinite;
}

/* ===== 减少动画偏好优化 ===== */

.motion-reduced,
.motion-reduced * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

/* ===== 数据节省模式优化 ===== */

.data-saver {
    background-image: none !important;
    box-shadow: none !important;
    text-shadow: none !important;
}

.data-saver img {
    display: none;
}

.data-saver .hero {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    min-height: 50vh;
}

/* ===== 懒加载优化 ===== */

.lazy {
    opacity: 0;
    transition: opacity 0.3s;
}

.lazy.loaded {
    opacity: 1;
}

/* 图片懒加载占位符 */
.lazy-placeholder {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

/* ===== 关键渲染路径优化 ===== */

/* 首屏内容优先显示 */
.above-fold {
    contain: layout;
    will-change: auto;
}

/* 非首屏内容延迟渲染 */
.below-fold {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}

/* ===== 字体优化 ===== */

/* 字体显示优化 */
@font-face {
    font-family: 'Optimized';
    font-display: swap;
    font-weight: 400;
    src: local('Arial'), local('sans-serif');
}

.font-optimized {
    font-family: 'Optimized', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    text-rendering: optimizeSpeed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== 布局稳定性优化 ===== */

/* 防止布局偏移 */
.layout-stable img,
.layout-stable video {
    width: 100%;
    height: auto;
    aspect-ratio: attr(width) / attr(height);
}

/* 为动态内容预留空间 */
.content-placeholder {
    min-height: 200px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

/* ===== 交互优化 ===== */

/* 快速点击响应 */
.fast-click {
    touch-action: manipulation;
    cursor: pointer;
}

/* 悬停效果优化 */
.hover-optimized {
    transition: transform 0.2s ease-out;
}

.hover-optimized:hover {
    transform: scale(1.02);
}

/* ===== 内存管理优化 ===== */

/* 限制复杂选择器 */
.memory-efficient * {
    box-sizing: border-box;
}

/* 避免昂贵的CSS属性 */
.performance-critical {
    filter: none;
    backdrop-filter: none;
    mix-blend-mode: normal;
}

/* ===== 响应式优化 ===== */

/* 小屏幕优化 */
@media (max-width: 768px) {
    .mobile-first {
        font-size: 16px;
        line-height: 1.5;
    }
    
    .mobile-first .hero {
        min-height: 60vh;
        padding: 1rem;
    }
    
    .mobile-first .card {
        margin: 1rem 0;
    }
}

/* 大屏幕优化 */
@media (min-width: 1920px) {
    .desktop-optimized {
        max-width: 1800px;
        margin: 0 auto;
    }
}

/* 高分辨率屏幕优化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .retina-optimized img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: optimize-contrast;
    }
}

/* ===== 打印优化 ===== */

@media print {
    .print-optimized {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    .print-optimized .hero {
        background: none !important;
        min-height: auto !important;
    }
}

/* ===== 可访问性优化 ===== */

/* 高对比度模式 */
@media (prefers-contrast: high) {
    .high-contrast {
        background: white;
        color: black;
        border: 2px solid black;
    }
}

/* 深色模式优化 */
@media (prefers-color-scheme: dark) {
    .dark-mode-optimized {
        background: #1a1a1a;
        color: #ffffff;
    }
}

/* ===== 调试和监控 ===== */

/* 性能监控标记 */
.perf-monitor::before {
    content: '⚡';
    position: absolute;
    top: 0;
    right: 0;
    background: #00ff00;
    color: #000;
    padding: 2px 4px;
    font-size: 10px;
    z-index: 9999;
}

/* 低性能警告 */
.perf-warning::after {
    content: '⚠️ 性能警告';
    position: fixed;
    bottom: 10px;
    right: 10px;
    background: #ff6b6b;
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12px;
    z-index: 10000;
}