/* 响应式设计 */

/* 大屏幕 (1200px+) */
@media (min-width: 1200px) {
    .container {
        max-width: 1400px;
    }

    .tools-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .search-title {
        font-size: 3.5rem;
    }
}

/* 中等屏幕 (992px - 1199px) */
@media (max-width: 1199px) {
    .tools-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .nav-menu {
        gap: 24px;
    }

    .search-title {
        font-size: 2.5rem;
    }
}

/* 小屏幕 (768px - 991px) */
@media (max-width: 991px) {
    :root {
        --container-padding: 16px;
        --section-gap: 16px;
        --card-gap: 12px;
    }

    .desktop-nav {
        display: none;
    }

    .mobile-menu-toggle {
        display: flex;
    }

    .mobile-menu {
        display: block;
    }

    .header-content {
        height: 60px;
    }

    .tools-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .tool-card {
        min-height: 200px;
    }

    .search-section {
        padding: 40px 20px;
        margin: 0 16px 32px;
    }

    .search-title {
        font-size: 2rem;
    }

    .search-subtitle {
        font-size: var(--font-size-base);
    }

    .category-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .category-tabs::-webkit-scrollbar {
        display: none;
    }

    .tab-button {
        padding: 10px 16px;
        font-size: var(--font-size-sm);
    }

    .filter-tags {
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 8px;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .filter-tags::-webkit-scrollbar {
        display: none;
    }

    .filter-tag {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* 移动端子分类横向滑动 */
    .sub-categories {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding-bottom: 8px;
    }

    .sub-categories::-webkit-scrollbar {
        display: none;
    }

    .sub-tab-button {
        white-space: nowrap;
        flex-shrink: 0;
    }

    .footer-content {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    .footer-bottom {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }

    .modal-content {
        padding: 24px;
        width: 95%;
    }

    .scroll-buttons {
        right: 16px;
        bottom: 16px;
    }

    .scroll-btn {
        width: 44px;
        height: 44px;
        font-size: 18px;
    }
}

/* 手机屏幕 (576px - 767px) */
@media (max-width: 767px) {
    .tools-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .tool-card {
        min-height: 180px;
    }

    .search-container {
        max-width: 100%;
    }

    .search-box {
        padding: 14px 20px 14px 45px;
        font-size: var(--font-size-sm);
    }

    .search-container {
        width: 100%;
    }
    
    .search-clear-btn {
        right: 8px;
        width: 32px;
        height: 32px;
        padding: 8px;
        z-index: 10;
        pointer-events: auto;
        touch-action: manipulation;
    }
    
    .search-clear-btn svg {
        width: 16px;
        height: 16px;
    }

    .tool-card {
        padding: 16px;
    }

    .tool-card-header {
        gap: 10px;
    }

    .tool-logo {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .tool-name {
        font-size: var(--font-size-base);
    }

    .mobile-only {
        display: initial !important;
    }

    .header-buttons {
        gap: 8px;
        display: flex !important;
        align-items: center;
    }

    .header-buttons button {
        padding: 6px;
        display: flex !important;
        align-items: center;
        justify-content: center;
        min-width: 36px;
        min-height: 36px;
        position: relative;
    }

    /* 移动端子分类横向滑动 */
    .sub-categories {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding-bottom: 8px;
    }

    .sub-categories::-webkit-scrollbar {
        display: none;
    }

    .sub-tab-button {
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* 移动端显示收藏按钮 */
    .bookmark-btn {
        display: flex !important;
    }

    .logo-section {
        gap: 8px;
    }

    .site-title {
        font-size: var(--font-size-lg);
    }

    .footer-links {
        justify-content: center;
    }

    .footer-section {
        text-align: center;
    }
}

/* 超小屏幕 (480px以下) */
@media (max-width: 479px) {
    :root {
        --container-padding: 12px;
        --border-radius: 8px;
        --border-radius-lg: 12px;
    }

    .header-content {
        height: 56px;
        gap: 12px;
    }

    .header-buttons {
        gap: 6px;
    }

    .header-buttons button {
        padding: 8px;
        min-width: 34px;
        min-height: 34px;
        position: relative;
    }

    .site-title {
        font-size: var(--font-size-base);
    }

    .search-section {
        padding: 32px 16px;
        margin: 0 12px 24px;
    }

    .search-title {
        font-size: 1.75rem;
        margin-bottom: 12px;
    }

    .search-subtitle {
        font-size: var(--font-size-sm);
        margin-bottom: 24px;
    }

    .search-box {
        padding: 12px 40px 12px 40px;
    }

    .search-icon {
        left: 14px;
    }
    
    .search-clear-btn {
        right: 12px;
        width: 28px;
        height: 28px;
        padding: 6px;
        z-index: 10;
        pointer-events: auto;
        touch-action: manipulation;
    }
    
    .search-clear-btn svg {
        width: 14px;
        height: 14px;
    }

    .tool-card {
        padding: 12px;
    }

    .tool-logo {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .tab-button {
        padding: 8px 12px;
        font-size: 12px;
    }

    .filter-tag {
        padding: 4px 12px;
        font-size: 11px;
    }

    /* 超小屏幕子分类横向滑动 */
    .sub-categories {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding-bottom: 8px;
    }

    .sub-categories::-webkit-scrollbar {
        display: none;
    }

    .sub-tab-button {
        white-space: nowrap;
        flex-shrink: 0;
        padding: 6px 10px;
        font-size: 11px;
    }

    .modal-content {
        padding: 20px;
        width: 98%;
        max-height: 85vh;
    }

    .scroll-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .scroll-buttons {
        right: 12px;
        bottom: 12px;
    }

    /* 超小屏幕移动端菜单优化 */
    .mobile-nav-menu {
        padding: 12px 16px;
        margin: 0 12px;
        min-width: 180px;
    }

    .mobile-nav-menu a {
        padding: 8px 12px;
        font-size: var(--font-size-sm);
    }
}

/* 横屏手机和小平板 */
@media (max-width: 1023px) and (orientation: landscape) {
    .search-section {
        padding: 32px 20px;
    }

    .search-title {
        font-size: 2rem;
    }

    .main-content {
        padding: 24px 0;
    }
}

/* 打印样式 */
@media print {
    .header,
    .footer,
    .search-section,
    .filter-section,
    .category-tabs,
    .scroll-buttons,
    .tool-modal {
        display: none !important;
    }

    .tool-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }

    .tools-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    body {
        font-size: 12px;
        line-height: 1.4;
    }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000000;
        --shadow-color: rgba(0, 0, 0, 0.5);
    }

    .tool-card {
        border-width: 2px;
    }

    .tool-card:hover {
        border-width: 3px;
    }
}

/* 减少动画模式 */
@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;
    }

    .tool-card:hover {
        transform: none;
    }

    .scroll-btn:hover {
        transform: none;
    }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
    .tool-card:hover {
        transform: none;
        box-shadow: 0 4px 20px var(--shadow-color);
    }

    .nav-menu a:hover,
    .header-buttons button:hover {
        background: transparent;
    }

    .visit-button:hover {
        transform: none;
    }

    /* 增加触摸目标大小 */
    .header-buttons button {
        padding: 10px;
        min-width: 42px;
        min-height: 42px;
        display: flex !important;
        align-items: center;
        justify-content: center;
        position: relative;
    }

    /* 确保收藏按钮在触摸设备上也显示 */
    .bookmark-btn {
        display: flex !important;
    }

    .like-button {
        padding: 8px;
        min-width: 32px;
        min-height: 32px;
    }

    .tab-button {
        min-height: 44px;
    }

    .filter-tag {
        min-height: 32px;
        padding: 8px 16px;
    }
}

/* 暗色模式通过JavaScript控制，移除自动媒体查询以避免冲突 */

/* Safari特定样式 */
@supports (-webkit-appearance: none) {
    .search-box {
        -webkit-appearance: none;
    }
}

/* Firefox特定样式 */
@-moz-document url-prefix() {
    .mobile-menu {
        background: transparent;
    }

    .search-box {
        -moz-appearance: none;
    }
}

/* 可访问性增强 */
@media (prefers-reduced-transparency: reduce) {
    .mobile-menu {
        background: transparent;
        backdrop-filter: none;
    }

    .search-box {
        background: var(--card-background);
        backdrop-filter: none;
    }
}