/* ============================================================
   小涵互联 · 手机端收口层（mobile3.css）
   ------------------------------------------------------------
   定位：mobile.css → mobile2.css 之后最后加载，只做「补缺口 + 收口」，
        不重复 mobile2 已完成的模块重排，避免互相打架。
   解决：
   1) 全站缺全局 box-sizing → width:100% + padding 的元素横向溢出
   2) 触控目标 < 44px（页脚链接、更多、社区行内操作、广告位）
   3) mobile2 未覆盖页面的标题/留白（pay、apps、about、agreement、错误页）
   4) 登录/注册/找回 输入框字号 < 16px（iOS 聚焦自动放大）
   5) 表格横向溢出、图片变形、破图空框
   6) TabBar 安全区与点击反馈、横向滚动标签条的可发现性
   桌面端（>820px）零影响
   ============================================================ */

@media (max-width: 820px) {

    /* ---------- A. 盒模型与横向溢出防线 ---------- */
    /* 全站此前没有全局 border-box，.dl-btn{width:100%;padding:9px 15px}
       在 content-box 下会多出 30~44px，正是 apps.php 溢出 405px 的根因 */
    *,
    *::before,
    *::after {
        box-sizing: border-box;
    }

    html,
    body {
        max-width: 100%;
        overflow-x: hidden;
    }

    img,
    video,
    canvas,
    iframe,
    svg,
    table {
        max-width: 100%;
    }

    img {
        height: auto;
    }

    /* 长英文 / URL 不撑破容器（社区仓库名、下载文件名常见） */
    .cm-title,
    .issue-title,
    .repo-name,
    .lc-title,
    .dl-title,
    .article,
    .doc,
    .content-body,
    .detail-body {
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    /* ---------- B. 触控目标补强（≥44px 或补足 padding） ---------- */
    .section-head .more,
    .m-card > .m-head > a,
    .cm-panel-head .more,
    .v3-sec .v3-sec-more,
    a.more {
        display: inline-flex !important;
        align-items: center;
        min-height: 40px !important;
        padding: 0 4px !important;
        font-size: 13px !important;
    }

    .cm-tabs-mini a,
    .cm-tab,
    .cm-chip,
    .cat-tab,
    .hb-chip,
    .plat-tab,
    .tabs a,
    .chip {
        min-height: 40px !important;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        padding-left: 14px;
        padding-right: 14px;
    }

    /* 社区列表行内操作（关注/收藏/评论数）原本 17px 高，手指点不准 */
    .cm-issue-item a,
    .cm-item a,
    .issue-item a,
    .cm-rank a,
    .cm-issue-item .meta a {
        display: inline-flex;
        align-items: center;
        min-height: 32px;
        padding: 2px 0;
    }

    .cm-issue-item a.t,
    .issue-item a.t {
        display: block;
        min-height: 40px;
        padding: 4px 0;
    }

    /* 页脚链接：原本 10~20px 高，改成两列自适应网格 */
    .xh-foot-links {
        display: grid !important;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 2px 8px;
        margin: 8px 0 4px !important;
    }

    .xh-foot-links a {
        display: flex !important;
        align-items: center;
        justify-content: center;
        min-height: 40px;
        padding: 0 6px !important;
        border-radius: 10px;
        font-size: 13px !important;
        background: rgba(127, 140, 170, .06);
    }

    .xh-foot-links a:active {
        background: rgba(var(--xh-primary-rgb), .14);
    }

    .xh-foot-copy {
        display: flex !important;
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px 10px;
    }

    .xh-foot-copy a,
    .xh-foot-copy span {
        min-height: 32px;
        display: inline-flex;
        align-items: center;
        font-size: 12px !important;
    }

    a.ad-footer,
    .xh-ad-tag {
        min-height: 32px;
        display: inline-flex;
        align-items: center;
    }

    .xh-ad-slot,
    .ad-slot,
    .ad-box {
        border-radius: var(--m-r-md);
        overflow: hidden;
    }

    .xh-ad-slot img,
    .ad-slot img,
    .ad-box img,
    .ad-footer img {
        width: 100%;
        height: auto;
        object-fit: cover;
    }

    /* ---------- C. 标题与留白兜底（mobile2 未覆盖的页面） ---------- */
    main.shell > h1,
    main.hub > h1,
    main > h1:not(.xh-err-title) {
        font-size: 21px !important;
        line-height: 1.3 !important;
        font-weight: 800 !important;
        letter-spacing: -.3px;
        margin: 0 0 8px !important;
    }

    /* about.php：<main> 无 class，原本 0 留白直接贴边 */
    main:not(.shell):not(.shell-narrow):not(.hub):not(.auth-main):not(.hb-page):not(.xh-err-wrap):not(.mg-main) {
        padding: 14px var(--m-pad) 26px !important;
    }

    /* agreement.php：main.shell-narrow 内联 padding:34px 0 60px → 左右 0 贴边 */
    main.shell-narrow {
        padding: 14px var(--m-pad) 26px !important;
    }

    main.shell-narrow > h1 {
        font-size: 19px !important;
        margin: 4px 0 12px !important;
    }

    /* 详情/协议正文：段落间距与字号统一，避免密集文字墙 */
    .article,
    .doc,
    .content-body,
    .detail-body {
        font-size: 14.5px !important;
        line-height: 1.85 !important;
    }

    .article h2,
    .doc h2,
    .content-body h2,
    .detail-body h2 {
        font-size: 17px !important;
        margin: 22px 0 10px !important;
        line-height: 1.45;
    }

    .article h3,
    .doc h3,
    .content-body h3,
    .detail-body h3 {
        font-size: 15.5px !important;
        margin: 18px 0 8px !important;
    }

    .article p,
    .doc p,
    .content-body p,
    .detail-body p {
        margin: 0 0 12px !important;
    }

    .article ul,
    .doc ul,
    .article ol,
    .doc ol {
        padding-left: 20px !important;
        margin: 0 0 14px !important;
    }

    .article li,
    .doc li {
        margin-bottom: 6px;
    }

    /* 旧静态页 iframe 承载（legacy.php）：标题过小、留白偏紧 */
    .legacy-frame,
    iframe.xh-legacy-frame {
        width: 100% !important;
        border-radius: var(--m-r-md);
    }

    /* ---------- D. 表单：字号 ≥16px 防 iOS 聚焦放大 ---------- */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    input[type="url"],
    input[type="search"],
    input:not([type]),
    textarea,
    select {
        font-size: 16px !important;
        min-height: 46px;
        border-radius: 12px;
    }

    textarea {
        min-height: 96px;
        line-height: 1.7;
    }

    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
        min-height: 0;
    }

    label {
        line-height: 1.6;
    }

    /* 认证页（登录/注册/找回/重置） */
    .auth-main {
        padding: 14px var(--m-pad) 30px !important;
    }

    .auth-shell {
        display: block !important;
        gap: 0 !important;
    }

    /* 移动端收起大段品牌文案，只保留品牌行 + 一句话说明，表单优先上屏 */
    .auth-brand {
        padding: 4px 2px 14px !important;
        background: none !important;
        border: 0 !important;
        box-shadow: none !important;
    }

    .auth-brand .brand-mark {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-bottom: 6px;
    }

    .auth-brand .brand-mark img {
        width: 34px;
        height: 34px;
        border-radius: 10px;
    }

    .auth-brand h1 {
        font-size: 19px !important;
        line-height: 1.35 !important;
        margin: 6px 0 6px !important;
    }

    .auth-brand .brand-sub,
    .auth-brand .brand-points,
    .auth-brand .brand-notice {
        display: none !important;
    }

    .auth-card {
        margin: 0 !important;
        padding: 18px 16px 20px !important;
        border-radius: var(--m-r-lg) !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .auth-card .card-head h2 {
        font-size: 18px !important;
        margin: 0 0 4px !important;
    }

    .auth-card .card-head p {
        font-size: 12.5px !important;
        line-height: 1.6 !important;
        margin: 0 0 14px !important;
    }

    .auth-card button[type="submit"],
    .auth-submit {
        min-height: 48px !important;
        font-size: 15.5px !important;
        border-radius: 13px !important;
        width: 100%;
    }

    .auth-tabs {
        display: flex !important;
        gap: 6px;
        margin-bottom: 14px !important;
    }

    .auth-tab {
        flex: 1 1 0;
        min-height: 42px !important;
        font-size: 13.5px !important;
        border-radius: 11px !important;
    }

    .auth-card .form-field,
    .auth-card .field {
        margin-bottom: 12px !important;
    }

    /* 支付页 / 会员页的选项卡与金额按钮 */
    .pay-way {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px !important;
    }

    .pay-way .dl-btn {
        width: 100% !important;
    }

    /* ---------- E. 表格：改为容器内横向滚动，避免整页溢出 ---------- */
    .hist-table,
    .ad-table,
    table.xh-table,
    .tbl {
        display: block !important;
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        border-radius: var(--m-r-md);
    }

    .hist-table table,
    .tbl table {
        min-width: 520px;
    }

    /* ---------- F. 图片：破图兜底 + 防变形 ---------- */
    .lc-icon img,
    .dl-icon img,
    .site-ico img,
    .card-ico img,
    .xh-nav-logo img {
        object-fit: contain;
        background: rgba(127, 140, 170, .08);
        border-radius: 8px;
    }

    img[src*="icon.php"] {
        background: rgba(127, 140, 170, .08);
    }

    .plat-panel-shot img,
    .plat-panel-shot {
        width: 100% !important;
        height: auto !important;
    }

    /* ---------- G. 横向滚动标签条：可发现性 + 惯性滚动 ---------- */
    .cat-tabs,
    .plat-tabs,
    .hb-chips,
    .cm-tabs,
    .chip-row,
    .cm-tabs-mini,
    .hero-chips,
    .tabs {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        scrollbar-width: none;
        padding-bottom: 2px;
    }

    .cat-tabs::-webkit-scrollbar,
    .plat-tabs::-webkit-scrollbar,
    .hb-chips::-webkit-scrollbar,
    .cm-tabs::-webkit-scrollbar,
    .chip-row::-webkit-scrollbar,
    .cm-tabs-mini::-webkit-scrollbar,
    .hero-chips::-webkit-scrollbar {
        display: none;
    }

    .cat-tab,
    .hb-chip,
    .cm-tab,
    .plat-tab {
        scroll-snap-align: start;
        flex: 0 0 auto;
        white-space: nowrap;
    }

    /* ---------- H. TabBar：安全区、毛玻璃、按压反馈 ---------- */
    .xh-tabbar {
        padding-bottom: max(env(safe-area-inset-bottom, 0px), 2px) !important;
        backdrop-filter: saturate(180%) blur(18px);
        -webkit-backdrop-filter: saturate(180%) blur(18px);
    }

    .xh-tab {
        min-width: 0;
        flex: 1 1 0;
        gap: 3px;
    }

    .xh-tab-label {
        font-size: 11px !important;
        line-height: 1.1;
        letter-spacing: .2px;
    }

    .xh-tab:active .xh-tab-label {
        opacity: .72;
    }

    .xh-tab.on .xh-tab-label {
        font-weight: 600;
    }

    /* 有 TabBar 时页脚底部留白不重复叠加 */
    body.xh-has-tabbar .xh-foot {
        padding-bottom: 8px !important;
        margin-bottom: 0 !important;
    }

    /* ---------- I. 按压反馈统一（不再各页各自为政） ---------- */
    .link-card,
    .dl-card,
    .site-card,
    .tool-tile,
    .v3-card,
    .quick-item,
    .cm-item,
    .issue-item {
        transition: transform .16s ease, box-shadow .16s ease;
    }

    .link-card:active,
    .dl-card:active,
    .site-card:active,
    .tool-tile:active,
    .v3-card:active,
    .quick-item:active,
    .cm-item:active {
        transform: scale(.985);
    }

    /* ---------- L. 修正与补漏（实测定位后的精确覆盖） ---------- */

    /* L1 认证页输入框：mobile2 用 body.auth-body input[type] {15.5px !important}，
       特异性高于元素级选择器，须同级覆盖。<16px 会触发 iOS 聚焦自动缩放 */
    body.auth-body input[type=text],
    body.auth-body input[type=password],
    body.auth-body input[type=email],
    body.auth-body input[type=tel],
    body.auth-body input[type=number],
    body.auth-body input[type=search],
    body.auth-body input:not([type]),
    body.auth-body textarea,
    body.auth-body select {
        font-size: 16px !important;
        min-height: 48px !important;
        border-radius: 13px !important;
    }

    body.auth-body .auth-card .link-muted,
    body.auth-body .switch-line a,
    body.auth-body .auth-foot a,
    body.auth-body .check a {
        display: inline-flex;
        align-items: center;
        min-height: 36px;
        padding: 0 2px;
        font-size: 12.5px !important;
    }

    /* L2 about.php：.ab-hero h1 用 clamp(26px,4.6vw,38px)，390 视口取到 26px 下限 */
    .ab-hero {
        padding: 6px 0 4px !important;
    }

    .ab-hero h1 {
        font-size: 21px !important;
        line-height: 1.32 !important;
        margin: 10px 0 8px !important;
        letter-spacing: -.2px !important;
    }

    /* L3 站点分类「查看全部」出口（.v3-sec-more 不在 .v3-sec 内，前序选择器未命中） */
    .v3-sec-more,
    .site-cat-bar .v3-sec-more,
    .site-cat-block .v3-sec-more {
        display: inline-flex !important;
        align-items: center;
        justify-content: flex-end;
        min-height: 40px !important;
        padding: 0 2px !important;
        font-size: 13px !important;
    }

    /* L4 面包屑与社区用户迷你卡 */
    nav.crumb {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0 2px;
        padding: 2px 0 6px !important;
        font-size: 12.5px !important;
    }

    nav.crumb a,
    nav.crumb span,
    .cm-user-mini a {
        display: inline-flex;
        align-items: center;
        min-height: 34px;
        padding: 0 3px;
    }

    /* L5 正文内裸链接（apps.php 的「下载」等）：只补垂直内边距扩大命中区，不改行内流 */
    main p > a:not([class]),
    main li > a:not([class]),
    main td a:not([class]),
    .article a:not([class]),
    .doc a:not([class]) {
        padding-top: 6px;
        padding-bottom: 6px;
    }

    /* L6 残余小触控：仓库顶部标签、提示行内链接、空状态按钮 */
    .cm-repo-top a {
        display: inline-flex;
        align-items: center;
        min-height: 34px;
        padding: 0 4px;
        font-size: 12.5px;
    }

    .dl-hint a,
    .empty a,
    .xh-empty a,
    .cm-empty a {
        display: inline-flex;
        align-items: center;
        min-height: 36px;
        padding: 0 6px;
        font-weight: 600;
    }

    /* L7 issues 列表页主标题改为 h1 后，移动端字号与面板标题对齐 */
    .cm-panel-head h1 {
        font-size: var(--m-fs-h3, 16px) !important;
        line-height: 1.4;
    }

    /* 可点击的整块区域给出统一焦点环，键盘/无障碍可用 */
    a:focus-visible,
    button:focus-visible,
    input:focus-visible,
    select:focus-visible,
    textarea:focus-visible {
        outline: 2px solid rgba(var(--xh-primary-rgb), .65);
        outline-offset: 2px;
        border-radius: 8px;
    }
}

/* ---------- J. 超窄屏（≤360px，iPhone SE / 老安卓） ---------- */
@media (max-width: 360px) {
    :root {
        --m-pad: 12px;
        --m-fs-h1: 18px;
        --m-fs-display: 19px;
    }

    .xh-foot-links {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .xh-tab-label {
        font-size: 10.5px !important;
    }

    .auth-brand h1 {
        font-size: 17.5px !important;
    }

    .pay-way {
        grid-template-columns: 1fr !important;
    }
}

/* ---------- K. 横屏手机 / 小平板（视口高度很小） ---------- */
@media (max-width: 820px) and (orientation: landscape) and (max-height: 480px) {
    .xh-tabbar {
        height: 50px;
    }

    .xh-tab-ico svg {
        width: 20px;
        height: 20px;
    }

    body.xh-has-tabbar {
        padding-bottom: 64px !important;
    }
}


/* ---------- M. 移动端交互基底（点击高亮/锚点遮挡/横向滚动暗示） ---------- */
@media (max-width: 820px) {
    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
        /* 固定导航高度内缩，锚点跳转不被顶部栏盖住 */
        scroll-padding-top: 76px;
    }

    a,
    button,
    [role="button"],
    label,
    summary {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }

    /* 横向滚动条：首尾渐隐，提示“可以左右滑”，滚到端点后自动撤掉对应一侧 */
    .xh-hscroll {
        -webkit-mask-image: linear-gradient(to right, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
        mask-image: linear-gradient(to right, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
    }

    .xh-hscroll.at-start {
        -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 16px), transparent 100%);
        mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 16px), transparent 100%);
    }

    .xh-hscroll.at-end {
        -webkit-mask-image: linear-gradient(to right, transparent 0, #000 16px, #000 100%);
        mask-image: linear-gradient(to right, transparent 0, #000 16px, #000 100%);
    }

    .xh-hscroll.at-start.at-end {
        -webkit-mask-image: none;
        mask-image: none;
    }

    /* 站内跳转顶部进度条：点击后立刻给反馈，避免移动端“点了没反应” */
    .xh-navprog {
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        height: 2px;
        background: var(--xh-primary, #4f8cff);
        box-shadow: 0 0 8px rgba(var(--xh-primary-rgb, 79, 140, 255), .55);
        transform: scaleX(0);
        transform-origin: 0 50%;
        opacity: 0;
        z-index: 1200;
        pointer-events: none;
        transition: transform .9s cubic-bezier(.08, .82, .17, 1), opacity .18s ease;
    }

    .xh-navprog.is-on {
        opacity: 1;
        transform: scaleX(.82);
    }

    /* body 的 overflow-x:hidden 会让 body 成为滚动容器，使页面内 position:sticky 失效；
       clip 同样裁掉横向溢出，但不创建滚动容器，sticky 才能正常工作 */
    body.xh-page {
        overflow-x: clip;
    }

    /* 站点页分类条吸顶：5000px 长列表里随时可切分类（滚过首屏后生效） */
    .cat-tabs {
        position: -webkit-sticky;
        position: sticky;
        top: 0;
        z-index: 30;
        margin-inline: -14px;
        padding: 8px 14px;
        background: var(--xh-bg, #fff);
        /* 半透明 + 背景模糊，避免页面径向渐变色在吸顶处被纯色切断 */
        background: color-mix(in srgb, var(--xh-bg, #fff) 82%, transparent);
        -webkit-backdrop-filter: saturate(180%) blur(14px);
        backdrop-filter: saturate(180%) blur(14px);
        border-bottom: 1px solid color-mix(in srgb, var(--xh-line, #dfe6f2) 60%, transparent);
        box-shadow: 0 10px 18px -18px rgba(0, 0, 0, .5);
    }

    /* 表格内链接触控兜底（如应用列表的“下载”） */
    table td a,
    table th a {
        display: inline-flex;
        align-items: center;
        min-height: 34px;
        padding: 0 3px;
    }

    /* 长文本标题在窄屏最多两行，避免撑爆卡片 */
    .cm-issue-item .body>a.t,
    .cm-item .body>a.t {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
}
