/* performance-optimize.css - 网站性能优化样式 */

/* 关键CSS：首屏渲染必需的样式 */

/* 基础重置和性能优化 */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    line-height: 1.5;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    background-color: #0f172a;
    color: #e2e8f0;
    overflow-x: hidden;
}

/* 图片优化 */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* 懒加载图片样式 */
img.lazy {
    opacity: 0;
    transition: opacity 0.3s ease-in;
}

img.lazy.loaded {
    opacity: 1;
}

/* 图片占位符 */
img[data-src] {
    background-color: #1e293b;
    background-image: linear-gradient(45deg, #1e293b 25%, transparent 25%), 
                      linear-gradient(-45deg, #1e293b 25%, transparent 25%), 
                      linear-gradient(45deg, transparent 75%, #1e293b 75%), 
                      linear-gradient(-45deg, transparent 75%, #1e293b 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    min-height: 50px;
}

/* 性能优化：内容可见性 */
.content-visibility-auto {
    content-visibility: auto;
}

.content-visibility-hidden {
    content-visibility: hidden;
}

.content-visibility-visible {
    content-visibility: visible;
}

/* 减少布局偏移 */
.header-placeholder {
    height: 80px;
    width: 100%;
}

/* 轻量级动画 */
.fade-in-fast {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* 避免大布局偏移 */
.stable-layout {
    contain: layout style paint;
}

/* 高效的文本渲染 */
.optimized-text {
    font-size: clamp(1rem, 2vw, 1.25rem);
    line-height: 1.6;
    letter-spacing: -0.01em;
}

/* 减少不必要的阴影和模糊效果 */
.low-end-device .shadow-lg,
.low-end-device .shadow-xl {
    box-shadow: none;
}

.low-end-device .glass-effect,
.low-end-device [backdrop-filter] {
    backdrop-filter: none;
    background-color: rgba(15, 23, 42, 0.9);
}

/* 高效的渐变 */
.optimized-gradient {
    background-image: linear-gradient(90deg, #0891b2 0%, #06b6d4 100%);
    background-size: 100% 1px;
    background-repeat: no-repeat;
    background-position: 0 0;
}

/* 优化滚动条 */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #0891b2;
    border-radius: 3px;
}

/* 响应式图片容器 */
.img-container {
    position: relative;
    overflow: hidden;
    aspect-ratio: 16/9;
}

.img-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

/* 减少动画复杂度 */
.reduce-motion * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

/* 避免大型计算 */
.no-blur {
    filter: none !important;
}

/* 减少重绘和回流 */
.will-change-transform {
    will-change: transform;
}

.will-change-opacity {
    will-change: opacity;
}

/* 关键渲染路径优化 */
.critical-path {
    contain: layout style paint;
}

/* 预加载关键字体 */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('https://fonts.gstatic.com/s/inter/v12/UcCO3FwrK3iLTeHuS_fvQtMwCp50KnMw2boKoduKmMEVuLyfAZ9hjp-Ek-_EeA.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* 高效的颜色变量 */
:root {
    --primary: #0891b2;
    --secondary: #06b6d4;
    --dark: #0f172a;
    --darker: #020617;
}

/* 减少动画帧 */
.fewer-frames {
    animation-timing-function: steps(10);
}

/* 延迟加载内容的容器 */
.lazy-container {
    min-height: 1px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lazy-container.loaded {
    opacity: 1;
}

/* 优化表格性能 */
.performant-table {
    table-layout: fixed;
    width: 100%;
}

/* 避免复杂的CSS选择器 */
.simple-selector {
    /* 使用简单的类选择器而不是复杂的嵌套选择器 */
}

/* 减少伪元素使用 */
.minimize-pseudo ::before,
.minimize-pseudo ::after {
    content: none !important;
}

/* 高效的背景处理 */
.optimized-bg {
    background-attachment: local;
    background-size: 100% auto;
    background-position: center top;
}

/* 打印样式优化 */
@media print {
    * {
        animation: none !important;
        transition: none !important;
        box-shadow: none !important;
        text-shadow: none !important;
        background: transparent !important;
        color: black !important;
    }
}

/* 低带宽模式 */
.low-bandwidth .heavy-resource {
    display: none !important;
}

/* 首屏内容优先级 */
.above-the-fold {
    contain: layout style paint;
    z-index: 1;
}

/* 代码高亮优化 */
code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.875rem;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    background-color: rgba(14, 165, 233, 0.1);
    color: #22d3ee;
}
