/* ==========================================================================
   mobile.css — 手机端 / 窄屏适配层
   在 style.css 与各页组件样式之后加载，专门处理：
     1) 防横向溢出（栅格轨道、宽表格、长串）
     2) 触屏可点区域（≥40px）
     3) iOS 输入框聚焦缩放（16px 字号）
     4) 头部导航、页脚、安全区
   桌面端不受影响：除「防溢出护栏」外全部包在 max-width: 720px 内。
   ========================================================================== */

/* --------------------------------------------------------------- 1. 结构性防溢出
   根因：`display:grid` 容器只有隐式单列时，轨道宽度取子项 min-content；
   宽表格（.rq-table min-width:560px）会把整条轨道撑到 600px+，页面出现横向滚动。
   用 minmax(0,1fr) 把轨道钉在容器宽度内，宽内容改由内部自己滚动。 */
.rq-wrap,
.hub,
.article-layout,
.doc-wrap,
.home,
.footer-wrap,
.section {
  grid-template-columns: minmax(0, 1fr);
}

@media (max-width: 720px) {
  /* 关键护栏：栅格/弹性子项默认 min-width:auto，会被内容 min-content 撑开，
     导致窄屏整页横向滚动（宽表格、长域名、nowrap 文本都会触发）。
     统一归零，让子项服从容器宽度，宽内容由自己内部滚动。 */
  main * { min-width: 0; }
  /* 需求列表的表格本来就靠内部横向滚动，恢复它的最小宽度 */
  .rq-table { min-width: 560px; }

  /* 宽表格：保留表格语义，只把外层变成可横向滚动的块 */
  .prose table,
  .article table,
  .doc table,
  .brief-body table {
    display: block;
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  /* 代码块同样只在自己的框里滚动 */
  .prose pre,
  .article pre,
  .doc pre {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  /* 站内已有的表格滚动容器：触摸惯性与滚动条 */
  .rq-table-scroll,
  .site-nav,
  .skills-marquee,
  .rq-marquee {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .rq-table-scroll::-webkit-scrollbar,
  .site-nav::-webkit-scrollbar,
  .rq-marquee::-webkit-scrollbar { display: none; }

  /* 长串（邮箱、URL、编号、用户输入）不撑破卡片 */
  .rq-msg-body,
  .rq-msg-author,
  .prose,
  .rq-home-notice-link,
  .rq-title-row,
  .case-pitch,
  .brief-title,
  .card-title {
    overflow-wrap: anywhere;
  }

  /* 媒体资源按容器缩放，避免超出屏幕 */
  .prose img,
  .article img,
  .prose iframe,
  .article iframe,
  .prose video,
  .article video {
    max-width: 100%;
    height: auto;
  }
  .prose iframe,
  .article iframe { aspect-ratio: 16 / 9; width: 100%; }
}

/* --------------------------------------------------------------- 2. 表单：防 iOS 缩放 */
@media (max-width: 720px) {
  /* iOS Safari 在输入框字号 <16px 时聚焦会自动放大整页，虚拟键盘收起后也不复原 */
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  textarea,
  select {
    font-size: 16px !important;
    line-height: 1.45;
  }
  /* 搜索框保持圆角但放大内边距，触屏更好点 */
  .rq-search input[type="search"] { padding: 13px 18px; }
  .rq-field input[type="text"],
  .rq-field input[type="email"],
  .rq-field input[type="url"],
  .rq-field input[type="password"],
  .rq-field textarea,
  .rq-select { padding: 12px 14px; }
}

/* --------------------------------------------------------------- 3. 触屏可点区域 */
@media (max-width: 720px) {
  .site-nav-list a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 8px 14px;
    font-size: 14px;
  }
  .site-nav { scroll-snap-type: x proximity; }
  .site-nav-list li { scroll-snap-align: start; }

  .brand { display: inline-flex; align-items: center; min-height: 40px; }

  .rq-bell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }
  .rq-bell svg { width: 20px; height: 20px; }

  .lang-select { min-height: 40px; padding: 9px 10px; font-size: 14px; }

  .rq-user-chip { min-height: 36px; padding: 6px 10px; }

  .chip { min-height: 38px; padding: 8px 14px; font-size: 13.5px; }

  .rq-btn-sm { min-height: 40px; padding: 9px 16px; }

  .btn { min-height: 44px; }

  /* 页脚链接：整行可点，避免 12px 高的细小目标 */
  .footer-legal a,
  .footer-copy a,
  .footer-friend-link,
  .footer-icp {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
  }

  /* 面包屑、分页、更多链接 */
  .breadcrumb a,
  .rq-pager a,
  .link-more,
  .rq-home-notice-all {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  /* 首页需求标签：手指更容易点中 */
  .rq-home-tab { min-height: 38px; padding: 7px 14px; max-width: 46vw; }

  /* 案例卡：外链域名与操作按钮放大到可点尺寸 */
  .case-domain { display: inline-flex; align-items: center; min-height: 36px; }
  .case-actions .btn { min-height: 40px; padding: 10px 18px; }
  .case-live { min-height: 26px; }

  /* 需求列表行内「凭口令查看」 */
  .rq-unlock-btn { min-height: 34px; padding: 7px 12px; font-size: 13px; }

  /* 外链索引：长域名允许换行，避免撑破整行 */
  .more-link { flex-wrap: wrap; }
  .more-domain { white-space: normal; overflow-wrap: anywhere; }

  /* 「更多 / 全部」类链接原本 nowrap，长标题在窄屏会撑出屏幕 */
  .link-more { white-space: normal; overflow-wrap: anywhere; }

  /* 首页紧凑案例卡的操作按钮 32px 偏小 */
  .case--compact .case-actions .btn { min-height: 38px; padding: 9px 14px; }

  /* 需求列表的标题链接只有 24px 高，补足可点区域 */
  .rq-row-link { display: inline-flex; align-items: center; min-height: 32px; }
}

/* --------------------------------------------------------------- 4. 触屏设备：去掉悬停副作用 */
@media (hover: none) {
  .case:hover,
  .pillar:hover,
  .card:hover,
  .tool-card:hover { transform: none; }
  .case:hover .case-media img { transform: none; }
  .btn-primary:hover,
  .btn-ghost:hover { transform: none; }
  .skills-marquee:hover .skills-track,
  .rq-marquee:hover .rq-marquee-track { animation-play-state: running; }
}

/* --------------------------------------------------------------- 5. 安全区（刘海/手势条） */
@supports (padding: max(0px)) {
  .site-header { padding-top: env(safe-area-inset-top); }
  .site-footer { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
  body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
}

/* --------------------------------------------------------------- 6. 小屏（≤380px）微调 */
@media (max-width: 380px) {
  :root { --gutter: 14px; }

  .hero { padding: 22px 16px; }
  .hero-title { font-size: clamp(26px, 8vw, 32px); }
  .hero-actions { gap: 8px; }
  .hero-actions .btn { flex: 1 1 100%; }

  .rq-home-tab { max-width: 60vw; }
  .rq-msg-thread .rq-msg { max-width: 94%; }

  .case-grid { gap: 12px; }
  .section-title { font-size: 19px; }

  .rq-table-card { padding-inline: 12px; }
  .rq-search { gap: 8px; }
}

/* --------------------------------------------------------------- 7. 横屏手机（高度受限） */
@media (max-width: 900px) and (max-height: 460px) and (orientation: landscape) {
  .hero { padding-block: 22px; }
  .rq-msg-thread { max-height: 180px; }
}
