/* H5 移动端整站适配 */
:root {
    --h5-tabbar-h: 56px;
    --h5-header-h: 50px;
    --h5-safe-bottom: env(safe-area-inset-bottom, 0px);
    --h5-safe-top: env(safe-area-inset-top, 0px);
}

/* 桌面端：隐藏 H5 专属组件 */
.h5-icon-btn,
.h5-search-bar,
.h5-tabbar,
.h5-drawer,
.h5-drawer-mask,
.h5-toast {
    display: none;
}

.nav-desktop,
.header-search-desktop {
    display: flex;
}

@media (max-width: 768px) {
    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    body.h5-app {
        padding-bottom: calc(var(--h5-tabbar-h) + var(--h5-safe-bottom));
        -webkit-tap-highlight-color: transparent;
        overscroll-behavior-y: none;
    }

    .container {
        padding: 0 14px;
    }

    /* 顶栏 */
    .h5-header.site-header {
        padding-top: var(--h5-safe-top);
        background: linear-gradient(180deg, #1e293b 0%, #2b2b2b 100%);
    }

    .h5-header .header-inner {
        height: var(--h5-header-h);
        gap: 10px;
        position: relative;
    }

    .h5-header .logo-icon {
        width: 28px;
        height: 28px;
        font-size: 0.95rem;
        border-radius: 8px;
    }

    .h5-icon-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border: none;
        background: rgba(255,255,255,0.1);
        color: #fff;
        border-radius: 8px;
        font-size: 1.15rem;
        cursor: pointer;
        flex-shrink: 0;
    }

    .h5-header .logo {
        flex: 1;
        justify-content: center;
        font-size: 1.05rem;
    }

    .h5-header .logo-text {
        max-width: 140px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .nav-desktop,
    .header-search-desktop {
        display: none !important;
    }

    .h5-search-bar {
        display: block;
        padding: 0 14px 12px;
        background: linear-gradient(180deg, #2b2b2b 0%, #1f2937 100%);
    }

    .h5-search-bar[hidden] {
        display: none !important;
    }

    .h5-search-form {
        display: flex;
        gap: 8px;
    }

    .h5-search-form input {
        flex: 1;
        min-width: 0;
        padding: 10px 14px;
        border: none;
        border-radius: 8px;
        font-size: 16px;
        outline: none;
    }

    .h5-search-form button {
        padding: 0 18px;
        border: none;
        border-radius: 8px;
        background: #f97316;
        color: #fff;
        font-weight: 600;
        font-size: 0.9rem;
        flex-shrink: 0;
    }

    /* 侧滑菜单 */
    .h5-drawer-mask {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 200;
        background: rgba(0,0,0,0.45);
        opacity: 0;
        transition: opacity 0.25s;
        pointer-events: none;
    }

    .h5-drawer-mask:not([hidden]) {
        opacity: 1;
        pointer-events: auto;
    }

    .h5-drawer {
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(280px, 82vw);
        z-index: 201;
        background: #fff;
        box-shadow: 4px 0 24px rgb(0 0 0 / 0.15);
        transform: translateX(-100%);
        transition: transform 0.28s ease;
        padding-top: var(--h5-safe-top);
    }

    .h5-drawer.open {
        transform: translateX(0);
    }

    .h5-drawer-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px;
        background: #2b2b2b;
        color: #fff;
    }

    .h5-drawer-logo {
        font-weight: 700;
        font-size: 0.95rem;
    }

    .h5-drawer-close {
        width: 32px;
        height: 32px;
        border: none;
        background: rgba(255,255,255,0.12);
        color: #fff;
        border-radius: 6px;
        font-size: 1.3rem;
        line-height: 1;
        cursor: pointer;
    }

    .h5-drawer-nav {
        flex: 1;
        overflow-y: auto;
        padding: 8px 0;
    }

    .h5-drawer-nav a {
        display: block;
        padding: 14px 20px;
        color: var(--text);
        font-size: 0.95rem;
        border-bottom: 1px solid #f1f5f9;
    }

    .h5-drawer-nav a.active {
        color: var(--primary);
        background: #eff6ff;
        font-weight: 600;
    }

    .h5-drawer-divider {
        padding: 12px 20px 6px;
        font-size: 0.78rem;
        color: var(--text-muted);
        font-weight: 600;
    }

    body.h5-drawer-open {
        overflow: hidden;
    }

    /* 底部 Tab */
    .h5-tabbar {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 150;
        height: calc(var(--h5-tabbar-h) + var(--h5-safe-bottom));
        padding-bottom: var(--h5-safe-bottom);
        background: #fff;
        border-top: 1px solid #e8e8e8;
        box-shadow: 0 -2px 12px rgb(0 0 0 / 0.06);
    }

    .h5-tabbar-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        color: #94a3b8;
        font-size: 0.68rem;
        padding: 4px 0;
        transition: color 0.2s;
    }

    .h5-tabbar-item.active {
        color: #16a34a;
    }

    .h5-tabbar-icon {
        font-size: 1.25rem;
        line-height: 1;
    }

    .h5-tabbar-label {
        font-weight: 500;
    }

    /* Toast */
    .h5-toast {
        display: block;
        position: fixed;
        left: 50%;
        bottom: calc(var(--h5-tabbar-h) + var(--h5-safe-bottom) + 16px);
        transform: translateX(-50%) translateY(20px);
        z-index: 300;
        max-width: 80vw;
        padding: 10px 18px;
        background: rgba(0,0,0,0.78);
        color: #fff;
        font-size: 0.88rem;
        border-radius: 8px;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s, transform 0.25s;
    }

    .h5-toast.show {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }

    /* 首页幻灯片：保持 1920×400 比例，避免 100vw 撑出横向滚动 */
    .page-home .home-carousel-main .carousel-track {
        min-height: 112px;
        max-height: min(260px, 38vw);
        height: auto;
    }

    .page-home .carousel-btn {
        display: none;
    }

    .home-hot-tags {
        padding: 10px 0;
    }

    .hot-tags-grid {
        gap: 6px 10px;
    }

    .hot-tag-item {
        font-size: 0.78rem;
    }

    .home-release-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .home-release-tabs {
        width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .release-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }

    .release-card-title {
        font-size: 0.82rem;
    }

    .release-card-desc {
        display: none;
    }

    .release-card-body {
        padding: 10px;
    }

    /* 软件列表 */
    .software-list-page .detail-col-side {
        display: none;
    }

    .list-page-head {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .list-search-form,
    .list-search-box {
        max-width: none;
        width: 100%;
    }

    .category-pills {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .category-pills .pill {
        flex-shrink: 0;
    }

    .software-list-grid {
        grid-template-columns: 1fr !important;
    }

    .software-list-item {
        padding: 12px;
    }

    /* 软件详情 */
    .detail-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .detail-col-side {
        display: none;
    }

    .detail-layout {
        flex-direction: column !important;
    }

    .software-spec-grid {
        grid-template-columns: 1fr !important;
    }

    .software-showcase-inner {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .software-metric-row {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .software-detail-page .detail-hero-media,
    .software-detail-page .detail-cover-wrap {
        width: 100% !important;
    }

    .software-detail-page .btn-detail-report {
        flex: 1;
        text-align: center;
    }

    .detail-download .download-panel-list {
        grid-template-columns: 1fr !important;
    }

    .download-panel-item {
        grid-template-columns: 1fr !important;
    }

    .download-item {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .btn-download {
        width: 100%;
        text-align: center;
        padding: 12px;
        font-size: 1rem;
    }

    /* 新闻 */
    .news-hero-card {
        grid-template-columns: 1fr !important;
    }

    .news-featured-grid {
        grid-template-columns: 1fr !important;
    }

    .news-hub-layout {
        grid-template-columns: 1fr !important;
    }

    .news-hub-side {
        display: none;
    }

    .news-detail-layout {
        grid-template-columns: 1fr !important;
    }

    .news-detail-side {
        display: none;
    }

    .news-feed-item {
        flex-direction: column;
    }

    .news-feed-cover {
        width: 100%;
        height: 160px;
    }

    /* 投诉 */
    .complaint-layout {
        grid-template-columns: 1fr !important;
    }

    .complaint-tabs {
        overflow-x: auto;
    }

    .complaint-tab {
        flex-shrink: 0;
    }

    /* 赞助 */
    .sponsor-layout {
        grid-template-columns: 1fr !important;
    }

    .sponsor-aside {
        position: static;
    }

    .sponsor-grid {
        grid-template-columns: 1fr !important;
    }

    /* 单页 */
    .single-page-layout {
        grid-template-columns: 1fr !important;
    }

    .single-page-side {
        display: none;
    }

    .single-page-main {
        padding: 16px !important;
    }

    /* 页脚 */
    .footer-main {
        grid-template-columns: 1fr 1fr !important;
        gap: 20px;
    }

    .footer-about {
        grid-column: 1 / -1;
    }

    .site-links-section .friend-links-label,
    .site-links-section .single-pages-label {
        min-width: 64px;
        font-size: 0.82rem;
    }

    .site-footer {
        padding-bottom: 16px;
    }

    /* 通用 */
    .section {
        padding: 16px 0 20px;
    }

    .breadcrumb {
        font-size: 0.78rem;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 12px;
    }

    .section-title {
        font-size: 1.15rem;
    }

    .pagination {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .pagination a,
    .pagination span {
        min-width: 36px;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .search-box input {
        font-size: 16px;
    }

    .form-field input,
    .form-field select,
    .form-field textarea {
        font-size: 16px;
    }

    .btn-copy-sm {
        min-height: 36px;
        padding: 8px 14px;
    }

    .cs-widget {
        right: 12px;
        bottom: calc(var(--h5-tabbar-h) + var(--h5-safe-bottom) + 12px);
    }

    .cs-widget-panel {
        width: min(280px, calc(100vw - 24px));
    }
}

@media (max-width: 380px) {
    .release-grid {
        grid-template-columns: 1fr !important;
    }

    .h5-tabbar-label {
        font-size: 0.62rem;
    }

    .footer-main {
        grid-template-columns: 1fr !important;
    }
}
