/**
 * 响应式设计增强
 * 额外的移动端优化和触摸友好改进
 */

/* ==================== 触摸优化 ==================== */

/* 确保所有可点击元素有足够的触摸目标 */
button,
a,
input[type="button"],
input[type="submit"],
.clickable {
    min-height: 44px;
    min-width: 44px;
}

/* 触摸反馈 */
button:active,
a:active,
.clickable:active {
    opacity: 0.7;
    transform: scale(0.98);
}

/* 防止双击缩放 */
* {
    touch-action: manipulation;
}

/* 平滑滚动 */
html {
    scroll-behavior: smooth;
}

/* iOS 滚动优化 */
.scrollable,
.main-content {
    -webkit-overflow-scrolling: touch;
}

/* ==================== 输入框优化 ==================== */

/* 移动端输入框样式 */
@media (max-width: 768px) {

    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px;
        /* 防止 iOS 自动缩放 */
        padding: 14px 16px;
    }

    /* 输入框获得焦点时的优化 */
    input:focus,
    textarea:focus {
        font-size: 16px;
    }
}

/* ==================== 图片响应式 ==================== */

/* 确保图片不超出容器 */
img {
    max-width: 100%;
    height: auto;
}

/* 图片加载占位 */
img[loading="lazy"] {
    background-color: #f0f0f0;
}

/* ==================== 文字响应式 ==================== */

/* 防止长文本溢出 */
.text-overflow {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 允许长单词换行 */
.word-break {
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

/* 响应式字体大小 */
@media (max-width: 480px) {
    h1 {
        font-size: 24px;
    }

    h2 {
        font-size: 20px;
    }

    h3 {
        font-size: 18px;
    }

    body {
        font-size: 14px;
    }
}

/* ==================== 横屏优化 ==================== */

@media (max-height: 500px) and (orientation: landscape) {

    /* 横屏时减小导航栏高度 */
    .navbar {
        height: 48px;
    }

    .mobile-nav {
        height: 48px;
    }

    /* 调整主内容区域 */
    .main-content {
        margin-bottom: 48px;
    }

    /* 减小弹窗内边距 */
    .modal-content {
        padding: 16px;
    }
}

/* ==================== 平板优化 ==================== */

@media (min-width: 768px) and (max-width: 1024px) {

    /* 平板专用样式 */
    .container {
        max-width: 720px;
        margin: 0 auto;
    }

    /* 瀑布流 2 列 */
    .waterfall-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ==================== 大屏优化 ==================== */

@media (min-width: 1440px) {
    .container {
        max-width: 1320px;
    }

    /* 瀑布流 4 列 */
    .waterfall-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ==================== 打印样式 ==================== */

@media print {

    /* 隐藏导航和不必要的元素 */
    .navbar,
    .mobile-nav,
    button,
    .no-print {
        display: none !important;
    }

    /* 优化打印布局 */
    .main-content {
        margin: 0;
        padding: 0;
    }

    /* 确保背景色打印 */
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ==================== 可访问性增强 ==================== */

/* 焦点可见性 */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* 跳过导航链接（屏幕阅读器） */
.skip-to-content {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 100;
}

.skip-to-content:focus {
    top: 0;
}

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

/* ==================== 减少动画（用户偏好） ==================== */

@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;
    }
}

/* ==================== 深色模式支持（预留） ==================== */

@media (prefers-color-scheme: dark) {
    /* 深色模式样式（未来实现） */
    /* 
    :root {
        --background-color: #1a1a1a;
        --text-color: #ffffff;
        --border-color: #333333;
    }
    */
}

/* ==================== 移动端特定优化 ==================== */

@media (max-width: 768px) {

    /* 移除悬停效果（避免触摸后残留） */
    *:hover {
        /* 在移动端禁用 hover 效果 */
    }

    /* 优化表单布局 */
    .form-group {
        margin-bottom: 16px;
    }

    /* 全宽按钮 */
    .btn-block {
        width: 100%;
        display: block;
    }

    /* 卡片间距 */
    .card {
        margin-bottom: 12px;
    }

    /* 模态框全屏 */
    .modal {
        padding: 0;
    }

    .modal-content {
        border-radius: 0;
        min-height: 100vh;
    }
}

/* ==================== 超小屏幕优化 ==================== */

@media (max-width: 360px) {

    /* 超小屏幕（如 iPhone SE）的特殊处理 */
    .container {
        padding: 0 8px;
    }

    button,
    .btn {
        padding: 10px 16px;
        font-size: 14px;
    }

    h1 {
        font-size: 20px;
    }

    h2 {
        font-size: 18px;
    }
}

/* ==================== 触摸设备检测 ==================== */

@media (hover: none) and (pointer: coarse) {

    /* 触摸设备专用样式 */
    button,
    a {
        padding: 12px 20px;
    }

    /* 增大可点击区域 */
    .nav-link {
        padding: 16px;
    }
}

/* ==================== 高分辨率屏幕优化 ==================== */

@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    /* Retina 屏幕优化 */
    /* 可以加载高清图片 */
}