/* ==========================================================================
   手机排版 v1（2026-11-20）
   —— 竖屏一套、横屏一套
   竖屏：字号整体收一档，标题不再挤成四行
   横屏：高度很矮，顶栏/分类/横幅全部压扁，把纵向空间还给内容
   ========================================================================== */

/* ---------------- 竖屏手机（窄） ---------------- */
@media (max-width: 640px) and (orientation: portrait) {
  :root {
    --gut: 14px;
    --fs-display: 26px;
    --fs-h1: 22px;
    --fs-h2: 17px;
    --fs-h3: 15px;
    --fs-body: 14.5px;
  }

  /* 顶栏收紧 */
  .mast-inner { padding: 9px var(--gut); gap: 10px; }

  /* 分类条：字号小一点、可横滑 */
  .toolbar { padding: 6px 0; gap: 8px; }
  .sorts { padding: 0 var(--gut); gap: 14px; }
  .sort-btn { font-size: 13px; }
  .tagbar { gap: 6px; padding: 2px var(--gut) 8px; }
  .tagbar .cat { font-size: 12px; padding: 5px 10px; }

  /* 大卡：标题从 26px 降到 19px，图比例从 21:9 放到 16:10 */
  .hero { border-radius: var(--r-lg); }
  .hero-media { aspect-ratio: 16 / 10; }
  .hero-body { padding: 14px 14px 16px; }
  .hero h2 {
    font-size: 19px;
    line-height: 1.36;
    max-width: none;
    -webkit-line-clamp: 3;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .hero p { font-size: 13px; -webkit-line-clamp: 2; margin-top: 6px; }
  .hero-meta { font-size: 12px; }

  /* 研究横幅：压扁，别再占半屏 */
  .research-band { padding: 12px 14px; gap: 9px; margin-top: 12px; border-radius: var(--r-lg); }
  .rb-left { padding: 0 0 8px; }
  .rb-date { font-size: 15px; }
  .rb-main h3 { font-size: 17px; line-height: 1.34; }
  .rb-main p { font-size: 13px; -webkit-line-clamp: 2; margin-top: 4px; }
  .rb-act { gap: 6px; }
  .rb-act .btn { height: 32px; font-size: 12px; padding: 0 12px; }

  /* 底部导航：矮一点，中间按钮小一点 */
  .tabbar { padding: 0 6px calc(4px + var(--sb)); }
  .tabbar button { padding: 8px 0 5px; font-size: 11px; gap: 3px; }
  .tabbar svg { width: 21px; height: 21px; }
  .tabbar .tab-upload { flex: 0 0 62px; }
  .tabbar .tab-upload .fab { width: 46px; height: 46px; margin-top: -16px; }
  .tabbar .tab-upload .fab svg { width: 21px; height: 21px; }

  /* 详情/编辑器里的标题也跟着收 */
  .sheet .title-xl { font-size: 21px !important; line-height: 1.35; }
  .article-head h1 { font-size: 21px; line-height: 1.35; }

  /* 详情页顶栏：分类+编号一行显示，别折两行；图标缩一点给文字让位 */
  .sheet-head { gap: 2px; padding-left: 4px; padding-right: 4px; }
  .sheet-head h2 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 0 1 auto;
    font-size: 13px !important;
  }
  .sheet-head .icon-btn { flex: 0 0 auto; width: 30px; height: 30px; }
  .sheet-head .icon-btn svg { width: 16px; height: 16px; }
}

/* ---------------- 横屏手机（高度很矮，宽可能够） ---------------- */
@media (orientation: landscape) and (max-height: 560px) and (max-width: 1000px) {
  :root {
    --gut: 12px;
    --fs-display: 22px;
    --fs-h1: 19px;
    --fs-h2: 16px;
    --fs-h3: 14px;
    --fs-body: 13.5px;
  }

  /* 顶栏：不吸顶、压到 36px 高 */
  .masthead { position: static; }
  .mast-inner { padding: 5px var(--gut); gap: 8px; }
  .head-search input { height: 30px; font-size: 13px; padding-left: 34px; }
  .head-search svg { width: 14px; height: 14px; left: 11px; }

  /* 分类条压到一行 */
  .toolbar { padding: 3px 0; gap: 6px; }
  .sorts { padding: 0 var(--gut); gap: 12px; }
  .sort-btn { font-size: 12px; padding: 5px 0; }
  .tagbar { padding: 0 var(--gut) 5px; gap: 5px; }
  .tagbar .cat { font-size: 12px; padding: 4px 9px; }

  /* 研究横幅：变成一条横条，高度压到 ~72px */
  .research-band {
    grid-template-columns: 108px 1fr auto;
    gap: 10px;
    padding: 9px 12px;
    margin-top: 8px;
    border-radius: var(--r-md);
    align-items: center;
  }
  .rb-left { flex-direction: row; align-items: baseline; gap: 8px; border-right: 1px solid var(--line); border-bottom: 0; padding: 0 10px 0 0; }
  .rb-left .kicker { font-size: 10px; letter-spacing: .2em; }
  .rb-date { font-size: 13px; max-width: 60px; }
  .rb-main h3 { font-size: 15px; line-height: 1.3; -webkit-line-clamp: 1; }
  .rb-main p { display: none; }
  .rb-main .rb-kw { display: none; }
  .rb-act { gap: 5px; }
  .rb-act .btn { height: 28px; font-size: 12px; padding: 0 10px; }

  /* 大卡：横屏用左图右文，避免一张卡占满整屏 */
  .hero {
    display: grid;
    grid-template-columns: 300px 1fr;
    align-items: stretch;
    background: var(--paper-2);
  }
  .hero-media { aspect-ratio: auto; height: 100%; min-height: 150px; position: relative; }
  .hero-media img { position: absolute; inset: 0; width: 100%; height: 100%; }
  /* 文字挪到右栏以后就不需要压暗层了 */
  .hero-scrim { display: none; }
  .hero-body {
    position: static;            /* 关键：原来 absolute 贴在图底，白字会压在浅色底上看不见 */
    color: var(--ink);
    padding: 12px 18px;
    gap: 6px;
    max-width: none;
    justify-content: center;
  }
  .hero .kicker { color: var(--bronze); }
  .hero h2 {
    color: var(--ink);
    text-shadow: none;
    font-size: 17px;
    line-height: 1.32;
    max-width: none;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .hero p { display: none; }
  .hero-meta { color: var(--ink-3); font-size: 11px; }
  .hero-meta .ava { border-color: var(--line); background: var(--paper-3); color: var(--ink-2); }

  /* 卡片：横屏排两列，图片别太高 */
  .grid.wall { column-gap: 10px; }
  .grid.wall .card-media { min-height: 110px; }
  .grid.wall .card h3 { font-size: 13px; }

  /* 底部导航：矮、图标小 */
  .tabbar { padding: 0 6px calc(2px + var(--sb)); }
  .tabbar button { padding: 5px 0 3px; font-size: 10px; gap: 2px; }
  .tabbar svg { width: 17px; height: 17px; }
  .tabbar .tab-upload { flex: 0 0 54px; }
  .tabbar .tab-upload .fab { width: 38px; height: 38px; margin-top: -12px; }
  .tabbar .tab-upload .fab svg { width: 17px; height: 17px; }

  /* 详情弹层：横屏左右分栏，图片在左文字在右 */
  .sheet-inner { max-width: none; }
  .sheet-body { padding: 12px 16px 20px; }
  .article-head h1 { font-size: 18px; }
  /* 横屏详情顶栏同样不折行 */
  .sheet-head h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .rv-bar { padding: 4px 10px; }
  .rv-title { font-size: 12px; }
}

/* ---------------- 很小的屏（≤ 380 宽）再收一档 ---------------- */
@media (max-width: 380px) and (orientation: portrait) {
  :root { --gut: 12px; }
  .hero h2 { font-size: 17.5px; }
  .rb-main h3 { font-size: 16px; }
  .tabbar button { font-size: 10px; }
}

/* ==========================================================================
   移动端专项修整（只在 ≤900px 生效，桌面端一行不动）
   2026-11-22：按「手机拥挤 / 遮挡」问题清单逐条修
   ========================================================================== */
@media (max-width: 900px) {

  /* ---------- 1. 悬浮水印：手机上直接不显示 ---------- */
  .nb-side,
  .nb-foot { display: none !important; }

  /* ---------- 2. 底部遮挡：给所有页面留出导航栏高度 ---------- */
  #app { padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
  .feed { padding-bottom: calc(28px + env(safe-area-inset-bottom)) !important; }
  .sheet-body { padding-bottom: calc(110px + env(safe-area-inset-bottom)) !important; }

  /* ---------- 3. 返回按钮：移到右下、进内容上方的空档，不再压搜索框 ---------- */
  #nb-page-back {
    top: auto !important;
    bottom: calc(92px + env(safe-area-inset-bottom)) !important;
    left: 12px !important;
    min-height: 36px !important;
    padding: 0 14px !important;
    font-size: 13px !important;
    box-shadow: 0 10px 26px -14px rgba(0, 0, 0, .7) !important;
  }

  /* ---------- 4. 页面左右留白：不再贴屏 ---------- */
  :root { --gut: 14px; }
  .wrap { padding-left: 14px; padding-right: 14px; }
  .feed .grid { gap: 11px; }

  /* ---------- 5. 卡片：内边距 + 层级 ---------- */
  .card-body { padding: 13px 13px 15px; }
  .card h3 {
    font-size: 16px; font-weight: 700; line-height: 1.45;
    margin: 0 0 10px;
  }
  .card-no {
    font-size: 10px; letter-spacing: .12em;
    color: var(--ink-4);
    margin-bottom: 9px;
    opacity: .85;
  }
  .card p.exc { font-size: 13px; line-height: 1.65; margin: 0 0 10px; }
  .ctags { gap: 5px; margin-top: 8px; }
  .ctags span {
    font-size: 10px;
    padding: 2px 7px;
    border-radius: 999px;
    line-height: 1.5;
  }

  /* ---------- 6. 「这样用最快」提示框：两边留空 ---------- */
  .guide {
    margin: 14px 12px 6px !important;
    padding: 16px 16px 12px !important;
    border-radius: 16px;
  }

  /* ---------- 7. 我的：四个数字均匀分布 ---------- */
  .profile .stat-row {
    display: flex !important;
    justify-content: space-between !important;
    gap: 0 !important;
    flex-wrap: nowrap !important;
    margin-top: 18px !important;
  }
  .profile .stat-row > div {
    flex: 1 1 0;
    text-align: center !important;
    display: flex; flex-direction: column;
    gap: 6px;                     /* 数字与文字的间距 */
  }
  .profile .stat-row b {
    font-size: 20px; line-height: 1;
    font-variant-numeric: tabular-nums;
  }
  .profile .stat-row span {
    font-size: 11px; line-height: 1.4;
    color: var(--ink-4);
    letter-spacing: .04em;
  }

  /* ---------- 8. 详情/解析页：文字呼吸感 ---------- */
  .sheet-body { padding: 20px 18px 24px !important; }
  .sheet-body p {
    line-height: 1.78;
    margin: 0 0 14px;
    font-size: 15px;
  }
  .sheet-body p:last-child { margin-bottom: 0; }
  .sheet-body ul, .sheet-body ol { padding-left: 20px; margin: 0 0 16px; }
  .sheet-body li { line-height: 1.78; margin-bottom: 8px; }
  .sheet-body li::marker { color: var(--bronze); }

  /* 小标题更清楚 */
  .sheet-body h3, .sheet-body h4 {
    font-size: 15px; font-weight: 700;
    margin: 22px 0 10px;
    letter-spacing: .01em;
  }
  .sheet-body b, .sheet-body strong { font-weight: 700; }

  /* 暗灰字提亮（依据 / 备注这类） */
  .sheet-body .dim,
  .sheet-body small,
  .sheet-body .muted,
  .sheet-body em { color: var(--ink-3) !important; opacity: 1; }

  /* ---------- 9. 详情页操作按钮：三排 → 一排横滑 ---------- */
  .actrow {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 14px 0 16px !important;
    gap: 8px !important;
    scroll-snap-type: x proximity;
  }
  .actrow::-webkit-scrollbar { display: none; }
  .actrow .btn {
    flex: 0 0 auto !important;
    white-space: nowrap;
    min-height: 38px;
    padding: 0 13px;
    font-size: 13px;
    scroll-snap-align: start;
  }

  /* ---------- 10. 标签与色卡 ---------- */
  .swatch-row { gap: 8px; }
  .sw { padding: 5px 9px 5px 5px; gap: 7px; }
  .sw-chip { width: 20px; height: 20px; }
  .sw em {
    font-size: 12px !important;
    color: var(--ink-2) !important;
    font-weight: 500;
    letter-spacing: .01em;
  }

  /* 分区/类型小胶囊更扁 */
  .pill, .tag-pill, .chip {
    padding: 3px 9px !important;
    font-size: 11px !important;
  }
}

@media (max-width: 900px) {
  /* 详情弹层：禁止横向溢出（正文右侧被裁的原因） */
  #sheet-post .sheet-inner,
  .sheet-inner {
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    border-radius: 18px 18px 0 0 !important;
  }
  .sheet-body {
    overflow-x: hidden;
    min-width: 0;
    max-width: 100%;
  }
  .sheet-body p,
  .sheet-body li,
  .sheet-body h3,
  .sheet-body h4 {
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
  }
  /* 标签行允许换行，不要挤成一条横溢 */
  .sheet-body .ctags,
  .sheet-body [class*="tag"] {
    max-width: 100%;
    flex-wrap: wrap;
  }
  /* 色卡：色名提亮放大 */
  .sw-pan {
    font-size: 11px !important;
    color: var(--ink-3) !important;
    opacity: 1 !important;
  }
  /* 顶部导航行（分类 · 编号）不要顶到边 */
  .sheet-head { padding-left: 16px !important; padding-right: 16px !important; }
}

@media (max-width: 900px) {
  /* AI 解析卡片：手机上从「左图右文」改成上下堆叠，文字拿满宽，不再被裁 */
  .ai-card {
    grid-template-columns: 1fr !important;
    display: block !important;
  }
  .ai-card > *,
  .ai-card-body,
  .ai-concept,
  .ai-list,
  .ai-item {
    width: auto !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }
  .ai-card img,
  .ai-card .ai-pic {
    width: 100% !important;
    height: auto !important;
    max-height: 260px;
    object-fit: cover;
    margin-bottom: 12px;
  }
  .ai-concept,
  .ai-list p,
  .ai-item p {
    font-size: 14px !important;
    line-height: 1.75 !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
    white-space: normal !important;
  }
  .ai-list li, .ai-item {
    margin-bottom: 10px !important;
  }
}

@media (max-width: 900px) {
  /* 最后一刀：详情正文里任何子元素都不许超出容器（根治右侧被裁） */
  .sheet-body {
    overflow-x: hidden !important;
    padding-left: 18px !important;
    padding-right: 18px !important;
    box-sizing: border-box !important;
  }
  .sheet-body * {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  .sheet-body p, .sheet-body li, .sheet-body div, .sheet-body span {
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
  }
  .sheet-body img, .sheet-body video, .sheet-body iframe {
    max-width: 100% !important;
    height: auto !important;
  }
}

@media (max-width: 900px) {
  /* 返回按钮：手机上不再固定悬浮（底部导航已经能回资料墙） */
  #nb-page-back { display: none !important; }

  /* 轮播：手指纵向滚动必须能穿过去；横向滑动由 JS 处理 */
  #nb-feat, .nb-feat, .nb-feat-slide, .nb-feat-img, .nb-feat-txt {
    touch-action: pan-y !important;
  }
  .nb-feat-slide { pointer-events: auto !important; }
  #nb-feat { position: relative; }
  /* 圆点做大，手指好点 */
  .nb-feat-dots { right: 12px !important; bottom: 12px !important; gap: 10px !important; }
  .nb-dot {
    width: 10px !important; height: 10px !important;
    border-width: 1.5px !important;
  }
  .nb-feat-dots::before {
    content: ''; position: absolute; inset: -10px -6px;  /* 扩大点击热区 */
  }

  /* 滚动体验：内层不要抢纵向手势，避免「拉不动 / 弹上弹下」 */
  .actrow {
    scroll-snap-type: none !important;
    overscroll-behavior-x: contain;
    overscroll-behavior-y: auto;
    -webkit-overflow-scrolling: auto;
  }
  .sheet-body {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  /* 全站禁止横向回弹，纵向恢复正常 */
  html, body {
    overscroll-behavior-x: none;
    overscroll-behavior-y: auto;
    -webkit-text-size-adjust: 100%;
  }
  /* 轮播里的文字不要挡住点击 */
  .nb-feat-txt { pointer-events: none; }
}

/* ==========================================================================
   滚动性能（只在 ≤900px）：快速滑动不再半路停住
   原因：固定层毛玻璃 + 每张卡片入场动画，iOS 上每帧都要重算
   ========================================================================== */
@media (max-width: 900px) {

  /* 1. 固定层关掉毛玻璃，改实色 —— 这项通常提升最明显 */
  .masthead,
  .tabbar,
  .install-bar,
  .sheet-head,
  .sheet-foot,
  .subnav-inner,
  .tagbar,
  .view-toggle,
  .sel-bar,
  .toast,
  .mast-inner,
  .head-search,
  .sheet-nav {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }
  .masthead,
  .tabbar {
    background: var(--paper) !important;
  }
  html[data-theme="dark"] .masthead,
  html[data-theme="dark"] .tabbar {
    background: var(--paper) !important;
  }

  /* 2. 卡片不再做入场动画和位移动画 */
  .card,
  .work-card,
  .rel-item,
  .sim-item,
  .grid > *,
  .feed > * {
    animation: none !important;
    transition: transform .12s ease !important;
    will-change: auto !important;
  }
  .card:hover,
  .work-card:hover,
  .rel-item:hover {
    transform: none !important;
  }

  /* 3. 滚动过程中不要跑平滑滚动 */
  html, body, .feed, .grid, .sheet-body {
    scroll-behavior: auto !important;
  }

  /* 4. 让长列表的离屏卡片跳过渲染（瀑布流很长时明显） */
  .grid .card {
    content-visibility: auto;
    contain-intrinsic-size: 320px 420px;
  }

  /* 5. 阴影降级：大范围模糊阴影在滚动时很贵 */
  .card,
  .work-card {
    box-shadow: none !important;
  }
  .card:hover,
  .work-card:hover {
    box-shadow: 0 8px 20px -14px rgba(0, 0, 0, .35) !important;
  }
}
