/* ==========================================================================
   educfa.com.cn 移动端体验增强层
   规则：仅追加样式，不改动 DOM 结构与正文内容（不影响 SEO）
   断点：≤900px 视为移动/平板触屏端
   JS（assets/site-mobile.js）负责打上的标记类：
     .ym-topbar  页面顶部首个导航容器（header / nav）
     .ym-hide    可自动收起的吸顶条（下滑收起、上滑回显）
     .ym-after   紧随顶栏的吸顶条（顶栏收起时上移补位）
     .ym-drawer  由 ☰ 按钮控制的折叠菜单
   ========================================================================== */

/* ---------- 1. 基础兼容 ---------- */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    overflow-wrap: break-word;
}
img, video, iframe, embed, canvas { max-width: 100%; }
img, video { height: auto; }
input, select, textarea { max-width: 100%; }
a, button, [role="button"] { touch-action: manipulation; }

/* 横向滚动容器：顺滑 + 隐藏滚动条 */
.ym-topbar .nav-inner, .ym-after .nav-inner, .ym-topbar ul,
.hero-search, .cat-tabs { -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.ym-topbar .nav-inner::-webkit-scrollbar, .ym-after .nav-inner::-webkit-scrollbar,
.ym-topbar ul::-webkit-scrollbar, .hero-search::-webkit-scrollbar,
.cat-tabs::-webkit-scrollbar { width: 0; height: 0; }

/* ---------- 2. 吸顶导航：下滑收起 / 上滑回显 ---------- */
@media (max-width: 900px) {
    html, body { overflow-x: clip; }        /* clip 不产生滚动容器，不会破坏 sticky */
    html { scroll-padding-top: 76px; }      /* 锚点跳转不被吸顶导航遮挡 */
    :target { scroll-margin-top: 76px; }

    .ym-hide {
        transition: transform .3s cubic-bezier(.22, .61, .36, 1);
    }
    html.ym-nav-hidden .ym-hide {
        transform: translateY(-100%);
    }

    /* 紧随顶栏的吸顶条（如分类横条）：顶栏收起时上移补位，避免留白 */
    .ym-after {
        top: var(--ym-top-offset, 56px) !important;
        transition: top .3s cubic-bezier(.22, .61, .36, 1);
    }
    html.ym-nav-hidden .ym-after { top: 0 !important; }

    /* 顶栏瘦身 */
    .ym-topbar.site-header { height: auto !important; min-height: 52px; }
    .ym-topbar.site-header .header-inner {
        flex-wrap: nowrap !important;
        padding: 7px 12px !important;
        gap: 8px !important;
    }
    .ym-topbar.site-header .logo-wrap { flex: 0 0 auto; }
    .ym-topbar.site-header .logo-text .site-tagline { display: none !important; }
    .ym-topbar.site-header .logo-text .site-name { font-size: 1rem !important; }
    .ym-topbar.site-header .logo-icon { width: 34px !important; height: 34px !important; font-size: 1.05rem !important; }

    /* 顶部导航横条：不分行、不竖排，横向滚动即可看到全部入口 */
    .ym-topbar .nav-inner, .ym-after .nav-inner {
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        gap: 6px !important;
        padding: 0 10px !important;
        overflow-x: auto !important;
    }
    .ym-topbar .nav-inner > a, .ym-after .nav-inner > a { flex: 0 0 auto; }

    .ym-topbar ul:not(.ym-drawer) {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        align-items: center !important;
        gap: 6px !important;
        margin: 0 !important;
        padding: 0 !important;
        list-style: none !important;
        overflow-x: auto !important;
    }
    .ym-topbar ul:not(.ym-drawer) > li { flex: 0 0 auto; }
    .ym-topbar ul:not(.ym-drawer) a {
        display: block !important;
        white-space: nowrap !important;
        padding: 8px 12px !important;
        font-size: 14px !important;
    }
}

/* ---------- 3. 移动端导航抽屉 + 遮罩 ---------- */
.ym-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 995;                                  /* 低于 header(1000)，菜单在上层 */
    background: rgba(8, 10, 18, .42);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .24s ease, visibility .24s ease;
}
.ym-menu-backdrop.is-show { opacity: 1; visibility: visible; }

@keyframes ymDropIn {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
    .nav-toggle {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        min-width: 42px;
        min-height: 42px;
        padding: 0 8px;
        border-radius: 10px;
        line-height: 1;
        font-size: 20px;
        -webkit-user-select: none;
        user-select: none;
    }
    .nav-toggle:active { transform: scale(.96); }

    /* 统一抽屉形态（各页面原桌面横排导航在此断点收起） */
    .ym-drawer {
        display: none !important;
        position: absolute !important;
        top: 100% !important;
        left: 0 !important;
        right: 0 !important;
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: flex-start !important;
        gap: 2px !important;
        margin: 0 !important;
        padding: 8px !important;
        max-height: min(68vh, 440px) !important;
        overflow-y: auto !important;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        border-radius: 0 0 14px 14px;
        background: var(--bg-card, var(--dark-card, #fff)) !important;
        -webkit-backdrop-filter: blur(12px) saturate(1.2);
        backdrop-filter: blur(12px) saturate(1.2);
        box-shadow: 0 18px 36px rgba(0, 0, 0, .22);
        z-index: 1001;
    }
    .ym-drawer.show, .ym-drawer.is-open, .ym-drawer.open {
        display: flex !important;
        animation: ymDropIn .22s cubic-bezier(.22, .61, .36, 1) both;
    }
    .ym-drawer a {
        display: flex !important;
        align-items: center;
        min-height: 44px;
        padding: 11px 14px !important;
        font-size: 15px !important;
        border-radius: 9px;
        white-space: nowrap !important;
    }
    .ym-drawer a:active { opacity: .72; }

    /* 抽屉展开时页面不跟着滚动穿帮 */
    html.ym-menu-open { overscroll-behavior-y: contain; }
}

/* ---------- 4. 首页 / 深色模板 ---------- */
@media (max-width: 640px) {
    .topbar { height: 30px; font-size: 12px; }
    .hero { padding: 30px 0 26px !important; }
    .hero h1 { font-size: 1.5rem !important; margin-bottom: 10px; }
    .hero p { font-size: .95rem !important; margin-bottom: 18px; }

    /* 搜索框保持单行，避免竖向堆叠占屏 */
    .hero-search {
        flex-direction: row !important;
        border-radius: 40px !important;
    }
    .hero-search input {
        font-size: 16px !important;
        padding: 11px 16px !important;
        border-radius: 40px 0 0 40px !important;
        border-right: none !important;
    }
    .hero-search button {
        padding: 0 18px !important;
        border-radius: 0 40px 40px 0 !important;
    }

    /* iOS 聚焦不放大 */
    input[type="text"], input[type="search"], input[type="email"],
    input[type="tel"], input[type="url"], input:not([type]),
    textarea, select { font-size: 16px !important; }
}

/* ---------- 5. 分类列表页 ---------- */
@media (max-width: 900px) {
    .brand-bar { padding: 6px 0 !important; font-size: .78rem !important; }
    .brand-bar .social-mini { display: none !important; }
    .brand-bar .hot-tag {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .brand-bar .hot-tag strong { overflow: hidden; text-overflow: ellipsis; }
    .brand-bar-inner { flex-wrap: nowrap !important; }

    .logo-text .site-tagline { display: none !important; }
    .header-search { flex: 1 1 auto !important; min-width: 0 !important; max-width: none !important; }
    .header-search input { font-size: 16px !important; padding: 8px 40px 8px 12px !important; }
    .header-search button { width: 32px; height: 32px; }

    .nav-inner a { padding: 11px 12px !important; font-size: .85rem !important; }
    .main-wrapper { padding: 12px 12px 0 !important; gap: 18px !important; }
}
@media (max-width: 480px) {
    .header-actions { display: none !important; }   /* 站点地图入口在页脚仍可访问 */
}

/* ---------- 6. 文章详情页（正文为整页 HTML，结构多样） ---------- */
@media (max-width: 900px) {
    body > header:not(.site-header) { padding: 8px 0 !important; }

    /* 正文长表格 / 代码块横向滚动 */
    .table-wrap, .code-wrap, pre { max-width: 100%; }
    a { overflow-wrap: anywhere; }
}

@media (max-width: 640px) {
    main.container { padding-left: 14px !important; padding-right: 14px !important; }
    .container { padding-left: 14px !important; padding-right: 14px !important; }
    .table-wrap { border-radius: 6px; }
}

/* ---------- 7. 回顶按钮 / 安全区 ---------- */
.back-to-top {
    right: max(16px, env(safe-area-inset-right)) !important;
    bottom: calc(16px + env(safe-area-inset-bottom)) !important;
    width: 46px !important;
    height: 46px !important;
    touch-action: manipulation;
}

/* ---------- 8. 无障碍：尊重减少动效偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto !important; }
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
