/* ========================================================================
   全站 H5 手机自适应模板
   断点：992 平板 / 768 手机 / 480 小屏
   依赖：style.css → frontend.css → compat.css → h5.css（本文件最后加载）
   ======================================================================== */

:root {
    --h5-header-h: 56px;
    --h5-touch: 44px;
    --h5-radius: 14px;
    --h5-gap: 12px;
}

html.site-h5-root {
    overflow-x: clip;
}

body.site-h5,
.portal-body.site-h5 {
    overflow-x: clip;
    -webkit-overflow-scrolling: touch;
    -webkit-tap-highlight-color: transparent;
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
}

.site-h5 .portal-shell {
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    width: 100%;
}

.site-h5 .portal-main-site {
    flex: 1;
    min-width: 0;
    width: 100%;
}

/* ---------- 顶栏抽屉 ---------- */
.news-site-nav-toggle {
    display: none;
    width: var(--h5-touch);
    height: var(--h5-touch);
    border-radius: 12px;
    border: 1px solid var(--portal-line);
    background: var(--portal-surface);
    color: var(--portal-text);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.site-nav-overlay {
    position: fixed;
    inset: 0;
    z-index: 280;
    background: rgba(7, 16, 24, 0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.28s ease, visibility 0.28s ease;
}

.site-nav-overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

body.site-nav-open {
    overflow: hidden;
    touch-action: none;
}

/* ---------- 侧栏折叠块（手机） ---------- */
.home-side-block {
    margin: 0;
    border: none;
    background: transparent;
}

.home-side-block > summary {
    list-style: none;
    cursor: default;
}

.home-side-block > summary::-webkit-details-marker {
    display: none;
}

.home-side-block .home-side-summary {
    display: none;
}

/* 桌面：details 当作普通面板，始终展开内容 */
@media (min-width: 769px) {
    .home-float-sidebar .home-side-block {
        display: block;
    }

    .home-float-sidebar .home-side-summary {
        display: none !important;
    }

    .home-float-sidebar .home-side-body {
        display: block !important;
    }
}

/* ========================================================================
   ≤992px 平板
   ======================================================================== */
@media (max-width: 992px) {
    .home-index-layout {
        grid-template-columns: minmax(0, 1fr) min(260px, 34%);
        gap: 16px;
    }

    .home-adaptive .home-tool-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .home-float-sidebar {
        top: calc(64px + env(safe-area-inset-top, 0px));
        max-height: calc(100dvh - 76px - env(safe-area-inset-top, 0px));
    }

    .news-detail-layout-wide,
    .tool-detail-layout,
    .sponsor-detail-layout {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

/* ========================================================================
   ≤768px 手机主断点
   ======================================================================== */
@media (max-width: 768px) {
    .news-site-nav-toggle {
        display: inline-flex;
    }

    .news-site-header {
        position: sticky;
        top: 0;
        z-index: 220;
    }

    .news-site-header-inner {
        flex-wrap: nowrap;
        gap: 8px;
        min-height: var(--h5-header-h);
        padding: 8px 12px;
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
        padding-left: max(12px, env(safe-area-inset-left, 0px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
    }

    .news-site-brand {
        flex: 1;
        min-width: 0;
    }

    .news-site-brand-text {
        max-width: 8.5em;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 15px;
    }

    .news-site-nav-toggle {
        margin-left: auto;
    }

    .news-site-header-actions {
        flex-shrink: 0;
        gap: 6px;
    }

    .news-site-action {
        width: 40px;
        height: 40px;
        min-width: 40px;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 12px;
    }

    /* 抽屉导航 */
    .news-site-nav {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 290;
        order: unset;
        width: min(300px, 86vw);
        max-width: 86vw;
        flex: none;
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        overflow-x: hidden;
        overflow-y: auto;
        padding: calc(16px + env(safe-area-inset-top, 0px)) 14px calc(24px + env(safe-area-inset-bottom, 0px));
        background: var(--portal-surface);
        border-left: 1px solid var(--portal-line);
        box-shadow: -12px 0 40px rgba(7, 16, 24, 0.18);
        transform: translateX(105%);
        transition: transform 0.32s var(--portal-ease, ease);
        -webkit-overflow-scrolling: touch;
    }

    .news-site-nav.is-open {
        transform: translateX(0);
    }

    .news-site-nav-link {
        width: 100%;
        min-height: var(--h5-touch);
        text-align: left;
        padding: 12px 14px;
        font-size: 15px;
        border-radius: 12px;
        box-sizing: border-box;
    }

    .news-site-nav-divider {
        width: 100%;
        height: 1px;
        margin: 8px 0;
    }

    /* 页面边距 */
    .site-page-shell,
    .home-fullscreen .home-body-inner,
    .news-detail-page.site-page-shell,
    .tool-detail-page.site-page-shell {
        padding-left: max(12px, env(safe-area-inset-left, 0px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    }

    .site-footer-inner {
        padding-left: max(12px, env(safe-area-inset-left, 0px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
    }

    .site-footer-grid {
        grid-template-columns: 1fr;
        gap: 22px;
        text-align: center;
    }

    .site-footer-brand,
    .site-footer-bottom {
        text-align: center;
    }

    .site-footer-logo {
        justify-content: center;
    }

    .site-footer-desc {
        margin-left: auto;
        margin-right: auto;
    }

    .site-footer-stats {
        justify-content: center;
        flex-wrap: wrap;
    }

    .site-footer-links-grid {
        grid-template-columns: 1fr;
    }

    .site-footer-buy-btn {
        width: 100%;
        max-width: 280px;
    }

    /* —— 首页 —— */
    .home-fullscreen .home-hero-full {
        padding: 24px 14px 20px;
        padding-top: calc(24px + env(safe-area-inset-top, 0px));
        border-radius: 0;
    }

    .home-fullscreen .home-hero-title {
        font-size: clamp(26px, 8vw, 34px);
        line-height: 1.25;
    }

    .home-fullscreen .home-hero-desc {
        font-size: 14px;
        margin-left: 0;
        margin-right: 0;
        max-width: none;
    }

    .home-hero-search,
    .home-hero-search-box {
        max-width: none;
        width: 100%;
    }

    .home-hero-search-box {
        flex-wrap: nowrap;
        gap: 8px;
        padding: 6px 6px 6px 12px;
    }

    .home-hero-search-box input {
        font-size: 16px; /* 防 iOS 缩放 */
        min-width: 0;
        flex: 1;
    }

    .home-hero-search-btn {
        flex-shrink: 0;
        min-height: 40px;
        padding: 0 14px;
    }

    .home-adaptive .home-hero-inner {
        text-align: left;
    }

    .home-quick-nav {
        margin-bottom: 16px;
        overflow: hidden;
    }

    .home-quick-nav-track {
        display: flex;
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 8px;
        overflow-x: auto;
        padding: 2px 2px 8px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        scroll-snap-type: x proximity;
    }

    .home-quick-nav-track::-webkit-scrollbar {
        display: none;
    }

    .home-quick-chip {
        flex: 0 0 auto;
        min-height: 36px;
        padding: 8px 14px;
        font-size: 13px;
        scroll-snap-align: start;
    }

    .home-fullscreen .home-hero-stats,
    .home-hero-stats {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        width: 100%;
    }

    .home-fullscreen .home-hero-stat,
    .home-hero-stat {
        display: block;
        text-align: center;
        min-width: 0;
        max-width: none;
        padding: 12px 8px;
        border-radius: 12px;
    }

    .home-hero-num {
        font-size: 20px;
    }

    .home-index-layout {
        grid-template-columns: 1fr !important;
        gap: 14px;
    }

    .home-main-column {
        order: 1;
    }

    .home-news-sidebar,
    .home-float-sidebar {
        position: static !important;
        order: 2;
        max-height: none !important;
        overflow: visible !important;
        z-index: auto;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    /* 手机侧栏：折叠面板 */
    .home-float-sidebar .home-side-block {
        border: 1px solid var(--portal-line);
        border-radius: var(--h5-radius);
        background: var(--portal-surface);
        box-shadow: var(--portal-shadow-card);
        overflow: hidden;
        padding: 0 !important;
    }

    .home-float-sidebar .home-side-block.news-sidebar-panel {
        border: 1px solid var(--portal-line);
        box-shadow: var(--portal-shadow-card);
    }

    .home-float-sidebar .home-side-summary {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        min-height: var(--h5-touch);
        padding: 12px 14px;
        font-size: 15px;
        font-weight: 700;
        color: var(--portal-text);
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
    }

    .home-float-sidebar .home-side-summary::after {
        content: '';
        width: 8px;
        height: 8px;
        border-right: 2px solid var(--portal-muted, #94a3b8);
        border-bottom: 2px solid var(--portal-muted, #94a3b8);
        transform: rotate(45deg);
        transition: transform 0.2s ease;
        flex-shrink: 0;
        margin-top: -4px;
    }

    .home-float-sidebar .home-side-block[open] > .home-side-summary::after {
        transform: rotate(-135deg);
        margin-top: 4px;
    }

    .home-float-sidebar .home-side-block .news-sidebar-title,
    .home-float-sidebar .home-side-block .news-sidebar-head {
        display: none;
    }

    .home-float-sidebar .home-side-body {
        padding: 0 14px 14px;
    }

    .home-float-sidebar .home-side-block[open] > .home-side-summary {
        border-bottom: 1px solid var(--portal-line);
        margin-bottom: 10px;
    }

    .home-adaptive .home-tool-grid {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    .home-section-card {
        border-radius: var(--h5-radius);
    }

    .portal-section-head {
        flex-wrap: wrap;
        gap: 8px;
    }

    .portal-section-title {
        font-size: 17px;
    }

    .portal-tool-card,
    .home-content .portal-tool-card {
        padding: 14px 40px 14px 14px;
        border-radius: 12px;
        min-height: 64px;
    }

    .portal-tool-name {
        font-size: 15px;
    }

    .portal-tool-desc {
        font-size: 12px;
        -webkit-line-clamp: 2;
    }

    /* —— 新闻 —— */
    .news-breadcrumb {
        font-size: 13px;
        flex-wrap: wrap;
        gap: 4px 0;
    }

    .news-adaptive .news-main-head,
    .news-list-card .news-main-head {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 16px;
    }

    .news-adaptive .news-list-stats {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        width: 100%;
    }

    .news-list-link {
        flex-direction: column;
        gap: 12px;
        padding: 14px 16px;
    }

    .news-list-cover {
        width: 100%;
        height: 168px;
        border-radius: 12px;
    }

    .news-grid {
        grid-template-columns: 1fr;
    }

    .news-adaptive .news-article {
        padding: 18px 14px 22px;
    }

    .news-adaptive .news-article-title {
        font-size: 22px;
        line-height: 1.35;
    }

    .news-adaptive .news-detail-nav {
        grid-template-columns: 1fr;
    }

    .news-adaptive .news-detail-nav-item.is-empty {
        display: none;
    }

    .news-adaptive .news-detail-nav-item.is-next {
        text-align: left;
    }

    .news-detail-sidebar {
        position: static;
        max-height: none;
    }

    .news-pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
    }

    /* —— 工具页 —— */
    .tool-adaptive .portal-tool-header,
    .tool-hero-card {
        flex-direction: row;
        align-items: flex-start;
        gap: 12px;
        padding: 16px;
    }

    .tool-adaptive .tool-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .tool-adaptive .tool-actions .btn {
        width: 100%;
        min-height: var(--h5-touch);
    }

    .tool-adaptive .tool-actions .btn-primary {
        grid-column: 1 / -1;
    }

    .tool-adaptive .form-textarea,
    .tool-adaptive .form-control {
        font-size: 16px;
    }

    .tool-adaptive .form-textarea {
        min-height: 180px;
    }

    .tool-detail-sidebar {
        position: static;
    }

    /* —— 赞助 —— */
    .sponsor-detail-page .portal-hero {
        flex-direction: column;
        align-items: flex-start;
        padding: 18px 14px;
        gap: 14px;
    }

    .sponsor-detail-page .portal-hero-stats {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .sponsor-detail-page .sponsor-layout {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .sponsor-detail-page .sponsor-roll {
        height: 280px;
    }

    .sponsor-amounts,
    .sponsor-pay-tabs {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .sponsor-amount-btn,
    .sponsor-pay-tab {
        flex: 1 1 calc(50% - 8px);
        min-width: 0;
        min-height: 40px;
        text-align: center;
    }

    .sponsor-form .form-control,
    .sponsor-form textarea {
        font-size: 16px;
    }

    .sponsor-form .btn {
        width: 100%;
        min-height: var(--h5-touch);
    }

    /* —— 通用控件 —— */
    .site-h5 .form-control,
    .site-h5 input[type="text"],
    .site-h5 input[type="search"],
    .site-h5 input[type="email"],
    .site-h5 input[type="number"],
    .site-h5 input[type="password"],
    .site-h5 textarea,
    .site-h5 select {
        font-size: 16px;
        max-width: 100%;
    }

    .site-h5 .btn {
        min-height: 40px;
    }

    .portal-body .back-top {
        right: max(12px, env(safe-area-inset-right, 0px));
        bottom: max(16px, env(safe-area-inset-bottom, 0px));
        width: var(--h5-touch);
        height: var(--h5-touch);
    }

    img,
    video,
    iframe,
    svg {
        max-width: 100%;
    }

    .news-article img,
    .news-article table {
        max-width: 100%;
        height: auto;
    }

    .news-article table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================================================
   ≤480px 小屏手机
   ======================================================================== */
@media (max-width: 480px) {
    .news-site-brand-text {
        max-width: 6.5em;
    }

    .home-fullscreen .home-hero-badge {
        font-size: 12px;
    }

    .home-fullscreen .home-hero-title {
        font-size: 24px;
    }

    .home-hero-stats {
        gap: 6px;
    }

    .home-hero-stat {
        padding: 10px 6px;
    }

    .home-hero-num {
        font-size: 18px;
    }

    .home-hero-stat span {
        font-size: 11px;
    }

    .news-list-cover {
        height: 148px;
    }

    .news-adaptive .news-article-title {
        font-size: 20px;
    }

    .tool-adaptive .tool-actions {
        grid-template-columns: 1fr;
    }

    .tool-adaptive .tool-actions .btn-primary {
        grid-column: auto;
    }

    .sponsor-amount-btn,
    .sponsor-pay-tab {
        flex: 1 1 calc(50% - 8px);
        font-size: 13px;
    }
}

/* ---------- 触控反馈 ---------- */
@media (hover: none) and (pointer: coarse) {
    .site-h5 .news-site-nav-link:active,
    .site-h5 .news-site-action:active,
    .site-h5 .home-quick-chip:active,
    .site-h5 .portal-tool-card:active,
    .site-h5 .news-list-link:active,
    .site-h5 .home-tool-cat:active,
    .site-h5 .site-footer-buy-btn:active,
    .site-h5 .btn:active {
        transform: scale(0.98);
        opacity: 0.92;
    }
}

@media (prefers-reduced-motion: reduce) {
    .news-site-nav,
    .site-nav-overlay,
    .home-side-block .home-side-summary::after {
        transition: none;
    }
}
