/* ========================================
   跨平台兼容性修复和增强
   确保在所有设备和浏览器上的一致体验
======================================== */

/* 基础重置和兼容性 */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* 图片响应式处理 */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* 确保所有图片都有合适的加载状态 */
img:not([src]) {
    opacity: 0;
}

img[src] {
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    /* 增大触摸目标 */
    .btn,
    .nav-link,
    .pagination-link,
    .film-nav,
    .film-indicator,
    .control-dot {
        min-height: 44px;
        min-width: 44px;
        padding: 12px;
    }
    
    /* 移除悬停效果，避免触摸设备上的粘滞状态 */
    .card:hover,
    .news-card:hover,
    .activity-card:hover,
    .member-card:hover,
    .link-card:hover {
        transform: none;
    }
    
    /* 简化动画效果 */
    .hover-lift:hover,
    .hover-scale:hover {
        transform: none;
    }
}

/* 小屏幕设备特殊处理 */
@media (max-width: 480px) {
    /* 确保容器不会溢出 */
    .container {
        padding: 0 16px;
        overflow-x: hidden;
    }
    
    /* 修复可能的水平滚动问题 */
    body {
        overflow-x: hidden;
    }
    
    /* 调整字体大小确保可读性 */
    body {
        font-size: 16px; /* 防止iOS缩放 */
    }
    
    /* 表格响应式处理 */
    table {
        width: 100%;
        overflow-x: auto;
        display: block;
        white-space: nowrap;
    }
    
    table thead,
    table tbody,
    table tr {
        display: table;
        width: 100%;
        table-layout: fixed;
    }
    
    /* 长文本处理 */
    .text-truncate {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    /* 确保按钮文字不会换行 */
    .btn {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* iOS Safari 特殊修复 */
@supports (-webkit-touch-callout: none) {
    /* 修复iOS Safari的100vh问题 */
    .hero-section,
    .full-height {
        height: -webkit-fill-available;
    }
    
    /* 修复iOS Safari的滚动问题 */
    .scroll-container {
        -webkit-overflow-scrolling: touch;
    }
}

/* 高分辨率屏幕优化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* 确保图标和小图片在高分辨率屏幕上清晰 */
    .icon,
    .logo img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* 横屏模式优化 */
@media (orientation: landscape) and (max-height: 500px) {
    /* 横屏时减少垂直间距 */
    .hero-section {
        height: 100vh;
        min-height: auto;
    }
    
    .section {
        padding: 40px 0;
    }
    
    /* 导航栏高度调整 */
    .navbar {
        height: 50px;
    }
    
    .nav-container {
        height: 50px;
    }
}

/* 打印样式 */
@media print {
    /* 隐藏不必要的元素 */
    .navbar,
    .footer,
    .btn,
    .back-to-top,
    .loading-overlay {
        display: none !important;
    }
    
    /* 确保内容适合打印 */
    .container {
        max-width: none;
        padding: 0;
    }
    
    /* 移除背景和阴影 */
    * {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }
    
    /* 确保链接可见 */
    a::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}

/* 减少动画偏好支持 */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    
    /* 移除所有变换动画 */
    .card:hover,
    .btn:hover,
    .hover-lift:hover {
        transform: none !important;
    }
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    /* 增强边框对比度 */
    .card,
    .btn,
    .form-control {
        border-width: 2px;
        border-color: currentColor;
    }
    
    /* 确保文字对比度 */
    .text-muted {
        color: inherit;
        opacity: 0.8;
    }
}

/* 暗色模式基础支持 */
@media (prefers-color-scheme: dark) {
    /* 如果用户偏好暗色模式，调整一些基础颜色 */
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #2d2d2d;
        --text-primary: #ffffff;
        --text-secondary: #cccccc;
        --border-color: #404040;
    }
}

/* 网络连接优化 */
@media (prefers-reduced-data: reduce) {
    /* 减少数据使用 */
    .hero-section {
        background-image: none;
        background-color: var(--primary-color);
    }
    
    /* 隐藏装饰性图片 */
    .decorative-image {
        display: none;
    }
}

/* 焦点管理和无障碍 */
.focus-visible:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* 跳转链接 */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--primary-color);
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 1000;
}

.skip-link:focus {
    top: 6px;
}

/* 屏幕阅读器专用内容 */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* 修复常见的布局问题 */
.clearfix::after {
    content: "";
    display: table;
    clear: both;
}

/* 确保flex容器在IE中正常工作 */
.flex-container {
    display: -ms-flexbox;
    display: flex;
}

.flex-item {
    -ms-flex: 1;
    flex: 1;
}

/* 修复Safari中的flex-shrink问题 */
.flex-no-shrink {
    flex-shrink: 0;
    -ms-flex-negative: 0;
}

/* 确保网格在旧浏览器中有回退 */
@supports not (display: grid) {
    .grid-fallback {
        display: flex;
        flex-wrap: wrap;
    }
    
    .grid-fallback > * {
        flex: 1 1 300px;
        margin: 10px;
    }
}

/* 修复粘性定位在Safari中的问题 */
.sticky-element {
    position: -webkit-sticky;
    position: sticky;
}

/* 确保滚动条样式一致 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}
