/* ==================== 性能优化配置 ==================== */

/* 为需要动画的元素启用硬件加速 */
.tech-bg,
.tech-navbar,
.tech-dropdown-menu,
.tech-challenge-card,
.tech-sidebar {
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* 动态背景优化 - 简化或禁用动画 */
.tech-bg::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(0, 255, 255, 0.02) 2px, rgba(0, 255, 255, 0.02) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(0, 255, 255, 0.02) 2px, rgba(0, 255, 255, 0.02) 4px);
    /* Edge 浏览器禁用动画 */
    animation: none;
}

/* 仅在非 Edge 浏览器启用动画 */
@supports not (-ms-ime-align: auto) {
    .tech-bg::before {
        animation: gridMove 30s linear infinite;
    }
}

/* 减少 backdrop-filter 模糊值 */
.tech-navbar {
    backdrop-filter: blur(6px); /* 从 12px 降低到 6px */
    -webkit-backdrop-filter: blur(6px);
}

.tech-dropdown-menu,
.tech-sidebar-card,
.tech-challenge-card {
    backdrop-filter: blur(5px); /* 从 10px 降低到 5px */
    -webkit-backdrop-filter: blur(5px);
}

/* 优化文字阴影 - 减少模糊半径 */
.tech-competition-title {
    text-shadow: 0 0 5px rgba(0, 255, 255, 0.5); /* 从 10px 降低到 5px */
}

.tech-challenge-title {
    text-shadow: 0 0 5px rgba(0, 255, 255, 0.3); /* 从 10px 降低到 5px */
}

.tech-ranking-title,
.tech-stat-value {
    text-shadow: 0 0 5px rgba(0, 255, 255, 0.3); /* 从 10px 降低到 5px */
}

/* 优化盒子阴影 */
.tech-navbar {
    box-shadow: 0 2px 10px rgba(0, 255, 255, 0.15); /* 简化阴影 */
}

.tech-challenge-card:hover {
    box-shadow: 0 4px 15px rgba(0, 255, 255, 0.25); /* 减少阴影复杂度 */
}

/* 禁用某些非关键动画 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Edge 专用优化 */
@supports (-ms-ime-align: auto) {
    /* 移除 backdrop-filter */
    .tech-navbar,
    .tech-dropdown-menu,
    .tech-sidebar-card,
    .tech-challenge-card,
    .tech-filter-panel,
    .tech-dynamic-card,
    .tech-ranking-card {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: rgba(0, 30, 60, 0.9); /* 增加不透明度补偿 */
    }
    
    /* 简化阴影效果 */
    .tech-competition-title,
    .tech-challenge-title,
    .tech-ranking-title,
    .tech-stat-value {
        text-shadow: none;
    }
    
    /* 禁用复杂的box-shadow */
    .tech-navbar,
    .tech-challenge-card:hover,
    .tech-sidebar-card {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    }
}

/* Edge 浏览器专用样式 (通过 JavaScript 添加的 class) */
body.edge-browser .tech-bg::before {
    animation: none !important; /* 禁用背景动画 */
}

body.edge-browser .tech-navbar,
body.edge-browser .tech-dropdown-menu,
body.edge-browser .tech-sidebar-card,
body.edge-browser .tech-challenge-card,
body.edge-browser .tech-filter-panel,
body.edge-browser .tech-dynamic-card,
body.edge-browser .tech-ranking-card {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: rgba(0, 30, 60, 0.92) !important;
}

body.edge-browser .tech-container-info-card,
body.edge-browser .tech-info-card,
body.edge-browser .flag-submit-enhanced {
    backdrop-filter: none !important;
    background: rgba(0, 20, 40, 0.9) !important;
}

/* 简化 Edge 浏览器中的阴影 */
body.edge-browser [class*="text-shadow"] {
    text-shadow: none !important;
}

body.edge-browser .tech-navbar {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

body.edge-browser .tech-challenge-card:hover {
    box-shadow: 0 4px 12px rgba(0, 255, 255, 0.2) !important;
}

/* 优化 transition 性能 - 只变换 transform 和 opacity */
.tech-nav-link,
.tech-btn,
.tech-challenge-card,
.tech-quick-link,
.tech-filter-option {
    transition: transform 0.2s ease, opacity 0.2s ease;
}

/* 减少 hover 时的 transform 幅度 */
.tech-nav-link:hover,
.tech-btn:hover {
    transform: translateY(-1px); /* 从 -2px 减少到 -1px */
}

.tech-challenge-card:hover {
    transform: translateY(-3px); /* 从 -5px 减少到 -3px */
}

/* 优化动画性能 */
@keyframes gridMove {
    0% { 
        transform: translate3d(0, 0, 0); /* 使用 3D transform */
    }
    100% { 
        transform: translate3d(0, 40px, 0); /* 使用 3D transform */
    }
}

/* 优化滚动性能 */
.tech-solve-records,
.tech-ranking-list,
.tech-dynamic-body {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    contain: paint; /* CSS containment 优化 */
}

/* 减少重绘区域 */
.tech-sidebar {
    contain: layout style paint;
}

.tech-challenge-card {
    contain: layout paint;
}

/* 优化图片和头像渲染 */
.tech-user-avatar,
.tech-avatar,
img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* 防止布局抖动 */
.tech-navbar {
    contain: layout;
}

/* 优化表格渲染 */
.tech-ranking-table,
.tech-dynamic-table {
    table-layout: fixed;
    contain: layout;
}

/* 降低复杂动画的帧率要求 */
.tech-blood-first,
.tech-blood-second,
.tech-blood-third {
    animation-timing-function: steps(30); /* 使用 steps 代替 ease */
}

/* 禁用标题闪烁时的性能密集型操作 */
@keyframes techFadeIn {
    from {
        opacity: 0;
        transform: translate3d(0, -10px, 0);
    }
    to {
        opacity: 1;
        transform: translate3d(0, 0, 0);
    }
}

/* 性能监控提示 */
/* 如果仍然卡顿，可以添加以下 class 到 body 标签来启用极简模式 */
body.performance-mode .tech-bg::before {
    animation: none !important;
    background-image: none !important;
}

body.performance-mode [class*="backdrop-filter"] {
    backdrop-filter: none !important;
}

body.performance-mode [class*="text-shadow"] {
    text-shadow: none !important;
}

body.performance-mode [class*="box-shadow"] {
    box-shadow: none !important;
}

