/* ═══════════════════════════════════════════
   手机端设计 — iPhone 比例基准 (≤500px)
   信息密度：图网格 2 列 · 文本/表单 1 列 · 触摸≥44px
   交互：底部 TabBar · 模态→底部弹出(bottom sheet)
   详细页(#page-create-detail)专属规则在 canvas.css（最后加载，权威），勿写在此
   ═══════════════════════════════════════════ */

/* 桌面/平板默认隐藏底部 TabBar（仅 ≤500px 显示） */
.mob-tabbar { display: none; }

@media (max-width: 500px) {

  /* ═══════ 1. 排版基准 ═══════ */
  html { -webkit-text-size-adjust: 100%; }
  body { font-size: var(--text-base); line-height: var(--lh-body); }

  h1 { font-size: clamp(1.9rem, 9vw, 2.6rem); line-height: 1.15; }
  h2 { font-size: clamp(1.4rem, 7vw, 1.9rem); }
  h3 { font-size: 1rem; }
  .section-head h2 { font-size: 1.4rem; font-weight: 500; }

  /* 防 iOS 输入聚焦自动放大：触控输入 ≥16px */
  input, textarea, select { font-size: 16px; }
  input::placeholder, textarea::placeholder { font-size: 0.9rem; }

  /* ═══════ 2. 布局容器 + tabbar 间距 ═══════ */
  body { padding-bottom: var(--tabbar-h); }
  .page { padding-bottom: calc(var(--tabbar-h) + 16px); }
  #page-home { padding-bottom: calc(var(--tabbar-h) + 8px); }
  .container { padding: 0 var(--gutter); }
  /* 内联 padding 钉子户的类化钩子（index.html 已改用此类） */
  .page-shell { padding: var(--sp-4) var(--gutter) calc(var(--tabbar-h) + 16px); }
  .page-shell--tighter { padding-top: var(--sp-6); }

  /* ═══════ 3. 顶栏/导航 ═══════ */
  /* 顶1黑条整栏隐藏；顶栏两行：上行居中 LOGO（信息展示，贴刘海下方），下行功能区工具条（绝不贴摄像头） */
  .nav__tier1 { display: none; }
  .nav__ad { display: none; }
  .nav__tier2 {
    height: auto;
    display: block;
  }
  /* 顶栏永不上白色实底：滚动后 logo/图标仅换色，背景保持透明露出下方页面（用户：上面得是正常背景） */
  .nav--solid .nav__tier2 {
    background: transparent;
    box-shadow: none;
  }

  /* 帮助/更多设置下拉 → 全宽顶部下拉 sheet（右缘不再溢出） */
  .nav__help-panel, .nav__menu-panel {
    position: fixed; top: var(--nav-h); left: 0; right: 0;
    width: 100%; min-width: 0;
    max-height: calc(100vh - var(--nav-h) - var(--tabbar-h));
    max-height: calc(100dvh - var(--nav-h) - var(--tabbar-h));
    overflow-y: auto;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border-left: none; border-right: none;
    padding: var(--sp-2) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom));
    box-shadow: var(--shadow-lg);
  }
  .nav__menu-item { min-height: var(--touch); }

  /* 隐藏桌面顶栏导航，改用底部 tabbar */
  .nav__links, .nav__toggle { display: none !important; }
  .nav__t2-inner {
    position: relative;
    display: flex; flex-direction: column; align-items: stretch;
    height: auto; padding: 0; gap: 0;
  }
  /* 上行：LOGO 信息展示（水平居中，垂直贴刘海下方） */
  .nav__weblogo {
    flex: none; width: 100%;
    height: calc(var(--nav2-h) + var(--nav-safe-top));
    padding-top: var(--nav-safe-top);
    justify-content: center;
  }
  .nav__weblogo img { height: 30px; }
  /* 下行：功能区工具条 —— 搜索靠左，更多设置/通知/头像贴右（移动端顶栏规范） */
  .nav__right {
    position: static; justify-self: auto;
    width: 100%; height: var(--mob-tools-h);
    justify-content: flex-end; align-items: center; gap: 2px;
    padding: 0 10px;
  }
  .nav__right .nav__iconbtn { padding: 0 8px; min-height: var(--mob-tools-h); }
  .nav__right .nav__iconbtn .icon-svg { width: 18px; height: 18px; }
  /* 搜索推到最左，其余功能区/头像贴右 */
  .nav__right .nav__iconbtn[onclick="openSearch()"] { margin-right: auto; }
  /* 商城按钮收进「更多设置」抽屉（soojump 注入菜单项），不再占工具条 */
  .nav__right .nav__iconbtn[title="商城"] { display: none; }

  /* ═══════ 4. 底部 TabBar + 触摸目标 ═══════ */
  .mob-tabbar {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 110;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 4px 8px max(4px, env(safe-area-inset-bottom));
    justify-content: space-around;
    align-items: flex-start;
  }
  .mob-tabbar__item {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 4px 8px; min-width: 48px; min-height: 50px;
    justify-content: center;
    font-size: 0.62rem; color: var(--fg-muted);
    cursor: pointer; border: none; background: none; position: relative;
    transition: color 0.15s; -webkit-tap-highlight-color: transparent;
  }
  .mob-tabbar__item.active { color: var(--pop); font-weight: 500; }
  .mob-tabbar__item .icon-svg { width: 22px; height: 22px; color: inherit; }
  .mob-tabbar__item .badge-dot {
    position: absolute; top: 2px; right: calc(50% - 16px);
    width: 7px; height: 7px; border-radius: 50%; background: var(--red);
  }

  .btn { min-height: var(--touch); padding: 12px 20px; font-size: 0.88rem; }
  .btn-sm { min-height: var(--touch-sm); padding: 8px 14px; font-size: 0.8rem; }
  .chip, .filter-bar .chip { min-height: var(--touch-sm); padding: 8px 14px; font-size: 0.78rem; }
  .nav__iconbtn { min-width: var(--touch); min-height: var(--touch); }
  .pager-row button { min-width: 38px; min-height: 38px; }
  .g-icon-btn { min-height: 42px; padding: 10px 16px; }
  a, button { -webkit-tap-highlight-color: transparent; }

  /* ═══════ 5. 模态 → 底部弹出 ═══════ */
  .modal-overlay { align-items: flex-end; }
  .modal {
    max-width: 100vw; max-height: 85vh;
    border-radius: 20px 20px 0 0 !important;
    padding: 24px 18px;
    animation: mobSlideUp 0.28s var(--ease-out);
  }
  @keyframes mobSlideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
  .modal__box { max-width: 100vw !important; max-height: 90vh !important; border-radius: 20px 20px 0 0 !important; }
  .modal__close { top: 18px; right: 18px; font-size: 1.4rem; }
  /* 纹样库/文化库详情弹窗：移动端垂直居中（其余模态保持底部弹出） */
  #detailModal { align-items: center; }
  #detailModal .modal { border-radius: 20px !important; animation: none; max-height: 88vh; }

  .gdetail { padding: 0 !important; align-items: flex-end !important; }
  .gdetail__inner { max-width: 100vw !important; max-height: 92vh !important; border-radius: 20px 20px 0 0 !important; padding: 20px 16px !important; }
  .gdetail__img { max-height: 40vh; border-radius: 12px !important; }

  /* ═══════ 6. 网格/卡片（图网格 2 列，文本/表单 1 列）═══════ */
  .grid--3, .grid--4 { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .card__body { padding: 10px 12px; }
  .card__title { font-size: 0.82rem; }
  .works-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .cr-recent__row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .cr-recent__card { border-radius: 10px; }
  .lady-grid { grid-template-columns: 1fr; gap: 14px; }
  .lady-card { flex-basis: 78vw; }

  /* ═══════ 7. 首页 Hero ═══════ */
  /* display:block 根治 static 化后的 flex 溢出（.hero__right 成为第二 in-flow 子项会挤窄 inner） */
  .hero { display: block; min-height: 100svh; min-height: 100vh; }
  .hero__inner {
    flex-direction: column; align-items: stretch; gap: var(--sp-6);
    padding: calc(var(--nav-h) + var(--sp-3)) var(--gutter) calc(var(--tabbar-h) + 24px);
  }
  .hero__left { flex: none; max-width: 100%; }
  .hero__title { font-size: clamp(2rem, 11vw, 2.8rem); line-height: 1.2; }
  .hero__sub { font-size: 0.92rem; margin-bottom: var(--sp-6); }
  /* 输入 + 胶囊 → 两行（输入全宽、胶囊全宽），消除横向挤压；圆角收窄为 16px，避免全宽行文字顶到圆弧 */
  .hero__gen { flex-wrap: wrap; padding: 12px; gap: 10px; max-width: 100%; border-radius: 16px; }
  .hero__input { flex-basis: 100%; font-size: 0.85rem; padding-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .hero__capsule { width: 100%; justify-content: center; min-height: var(--touch); padding: 12px 20px; font-size: 0.84rem; }
  .hero__switch { left: var(--gutter); bottom: calc(var(--tabbar-h) + 16px); gap: 8px; }
  .hero__arrow { width: 40px; height: 40px; }
  .hero__arrow svg { width: 18px; height: 18px; }
  /* 右区块：移动端整体隐藏（订阅卡移入页底 #heroPlanBottom，图片展示区删除） */
  .hero__right { display: none; }
  .hero__showcase { display: none; }
  .hero__plan-bottom {
    padding: var(--sp-6) var(--gutter) calc(var(--tabbar-h) + 20px);
    border-top: 1px solid var(--border);
    background: var(--bg-soft);
  }
  .hero__plan-bottom .hero__plan-card { padding: var(--sp-4); background: var(--bg-card); box-shadow: var(--shadow-sm); transform: none; }
  .hero__plan-title { font-size: 1.2rem; }
  .hero__plan-desc { font-size: 0.8rem; margin-bottom: 14px; }
  .hero__plan-body { height: 64px; font-size: 0.75rem; }
  /* 统计横杠：移动端整体删除（用户确认不要竖栏保留，直接去掉这组数据） */
  .statbar { display: none; }
  /* lady 横向滑动条：桌面边缘出血用的 margin-right 在 393 下反向溢出 8px */
  .lady-slider { margin-right: 0; }

  /* ═══════ 8. 创作页 ═══════ */
  .cr-home { padding: calc(var(--nav-h) + var(--sp-6)) var(--gutter) calc(var(--tabbar-h) + 16px); }
  .cr-home__hero { max-width: 100%; }
  .cr-input { padding: 12px 12px 8px; border-radius: 12px; }
  .cr-input__field { font-size: 0.88rem; }
  .mode-chip { min-width: 70px; padding: 10px 6px; }
  .mode-chip__name { font-size: 0.74rem; }
  /* 智能生成 → QQ 式对话：消息区滚动在上，输入框固定在底部 */
  #page-create-smart { padding-bottom: 0; }
  .cr-smart {
    display: flex; flex-direction: column; gap: 0; padding: 0;
    height: calc(100vh - var(--nav-h) - var(--tabbar-h));
    height: calc(100svh - var(--nav-h) - var(--tabbar-h));
    height: calc(100dvh - var(--nav-h) - var(--tabbar-h));
  }
  .cr-chat { flex: 1; min-height: 0; height: auto; border-radius: 0; border: none; }
  .cr-canvas { display: none; }               /* 作品改由 JS 直接进入消息流 */
  .cr-chat__inputwrap { padding: 8px; flex-shrink: 0; border-top: 1px solid var(--border); }
  .cr-iconbtn { font-size: 0.74rem; padding: 0 10px; }
  .cr-iconbtn span { display: none; }
  #page-create-smart .cr-points { top: calc(var(--nav-h) + 12px); right: 12px; font-size: 0.72rem; padding: 6px 10px; }

  /* ═══════ 9. 纹样库/文化库 ═══════ */
  .styles-layout { grid-template-columns: 1fr; gap: var(--sp-4); padding: var(--sp-4) var(--gutter) calc(var(--tabbar-h) + 16px); }
  .styles-side { position: static; border-right: none; border-bottom: 1px solid var(--border); padding: 0 0 12px; max-height: none; }
  .styles-side__subs { display: flex; flex-wrap: wrap; gap: 6px; }
  .styles-side__sub { padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-pill); font-size: 0.76rem; }
  .styles-side__sub.active { background: var(--fg); color: var(--bg); border-color: var(--fg); }
  .styles-head { flex-direction: column; gap: var(--sp-3); }
  .styles-title { font-size: clamp(1.8rem, 9vw, 2.4rem); }
  .styles-desc { font-size: 0.8rem; line-height: 1.75; }

  /* 透视浮卡 → 3×2 纹样马赛克（--x/--y 被 left/top:auto 屏蔽，零 JS 坐标改动；
     tilt 已在 styles.js bindFloatTilt 用 matchMedia 守卫禁用） */
  .styles-float {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
    width: 100%; height: auto; padding: 4px; overflow: hidden;
    perspective: none;
  }
  .styles-float__card {
    position: relative; left: auto; top: auto;
    width: 100%; height: 88px; transform: none;
  }
  .styles-float__card .styles-float__bob { animation: none; transform: none; }
  .styles-float__inner { border-radius: 8px; will-change: auto; }

  .culture-cloud { width: 100%; height: 160px; }
  .yz-tabs { padding: 12px 12px 0; gap: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* ═══════ 9.1 纹样库/文化库：标签收起 + 侧边可拖拽抽屉 ═══════ */
  /* 原标签区在移动端整体隐藏，由 JS 移入 #mobTagDrawer */
  .styles-side, .styles-classify, #cultureSide { display: none; }

  .mob-tagdrawer {
    position: fixed; top: var(--nav-h); bottom: var(--tabbar-h); right: 0;
    width: min(320px, 84vw); z-index: 120;
    display: flex; flex-direction: column;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    transform: translateX(102%);
    transition: transform 0.28s var(--ease);
    visibility: hidden;
  }
  .mob-tagdrawer.open { transform: translateX(0); visibility: visible; }
  .mob-tagdrawer.from-left { right: auto; left: 0; border-left: none; border-right: 1px solid var(--border); transform: translateX(-102%); }
  .mob-tagdrawer.from-left.open { transform: translateX(0); }
  .mob-tagdrawer__head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px; border-bottom: 1px solid var(--border); flex-shrink: 0;
  }
  .mob-tagdrawer__title { font-size: 0.95rem; font-weight: 500; }
  .mob-tagdrawer__close { font-size: 1.5rem; line-height: 1; color: var(--fg-dim); background: none; border: none; padding: 4px 10px; min-width: var(--touch); min-height: var(--touch); }
  .mob-tagdrawer__body {
    flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  }
  .mob-tagdrawer .styles-side,
  .mob-tagdrawer #cultureSide { display: block; padding: 0; border: none; max-height: none; }
  .mob-tagdrawer .styles-side__subs { display: flex; flex-wrap: wrap; gap: 8px; }
  .mob-tagdrawer .styles-classify { display: block; margin: 14px 0 0; padding: 14px 0 0; border: none; border-top: 1px solid var(--border); }
  .mob-tagdrawer .styles-classify__search-wrap { width: 100%; margin-top: 6px; }
  .mob-tagdrawer .styles-classify__search { width: 100%; }

  /* 可拖拽标签按钮：贴左右边缘，可拖到任意高度 */
  .mob-tagbtn {
    position: fixed; z-index: 125;
    display: inline-flex; align-items: center; gap: 5px;
    right: 0; top: 40%;
    padding: 12px 9px 12px 13px;
    background: var(--bg-card); color: var(--fg);
    border: 1px solid var(--border); border-radius: 999px 0 0 999px;
    box-shadow: var(--shadow);
    font-size: 0.78rem; min-height: var(--touch);
    touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
    white-space: nowrap;
  }
  .mob-tagbtn.on-left { right: auto; left: 0; border-radius: 0 999px 999px 0; padding: 12px 13px 12px 9px; }
  .mob-tagbtn .icon-svg { width: 16px; height: 16px; color: var(--fg); }
  .mob-tagbtn.dragging { cursor: grabbing; }

  /* ═══════ 10. 个人中心 / 用户主页 / 我的作品 ═══════ */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 0; }
  .tabs button { flex-shrink: 0; padding: 10px 14px; font-size: 0.82rem; white-space: nowrap; min-height: var(--touch); }
  /* 用户主页：头部换行 + 作品网格 2 列（JS 注入 minmax 已类化移除） */
  .pub-head { flex-wrap: wrap; gap: var(--sp-4); }
  .pub-works-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .works-wrap { padding: var(--sp-6) var(--gutter) calc(var(--tabbar-h) + 16px); }

  /* ═══════ 11. 工具类/杂项 ═══════ */
  .toast-ctr { top: calc(var(--nav-h) + 8px); right: 12px; left: 12px; }
  .toast { max-width: none; font-size: 0.8rem; padding: 12px 16px; }
  .cr-notif-panel { width: calc(100vw - 32px); left: 16px !important; right: 16px !important; }
  .notif-item { padding: 14px 12px; }
  .search-overlay { padding: 60px 12px 12px; }
  .search-input-row { padding: 12px 14px; }
  .search-input-row input { font-size: 0.92rem; }
  .help-cards { grid-template-columns: 1fr; gap: 10px; }
  .help-box { padding: 20px 14px; max-width: 100vw; }
  .help-card { padding: 20px 14px; }
  .section-head { margin-bottom: 24px; }
  /* 提醒（toast）水平居中 */
  .toast-ctr { align-items: center; }
  .comment-form { flex-direction: column; gap: 8px; }
  .comment-form input { width: 100%; min-height: 40px; }
  .comment-reply { margin-left: 12px; padding-left: 8px; }
  .empty { padding: 60px 20px; }
  /* 浮动右键菜单防溢出（create-shared.js 注入 min-width:170px 的 .cr-floatmenu） */
  .cr-floatmenu { max-width: calc(100vw - 12px); }
  .cr-floatmenu .cr-switch__opt span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* ═══════ 12. 屏蔽桌面专属元素 ═══════
     注意：.cr-side 详细页会被 canvas.css 反压为 flex!important，此处必须保留 */
  .cr-side { display: none !important; }
}

/* ── 平板 (501-768px) ── */
@media (min-width: 501px) and (max-width: 768px) {
  .mob-tabbar { display: none; }
  .grid--4 { grid-template-columns: repeat(2, 1fr); }
  .grid--3 { grid-template-columns: repeat(2, 1fr); }
  .container { padding: 0 20px; }
  .styles-layout { padding: 32px 20px 60px; }
  .cr-recent__row { grid-template-columns: repeat(3, 1fr); }
}
