/* ============================================================================
 * 手机模式补丁（mobile-fix.css）
 * 目标：在真机上打开时，去掉桌面外壳，让内容 1:1 铺满屏幕，像真小程序一样。
 * 触发条件：视口宽度 ≤ 768px（手机），或 URL 带 ?m=1 强制手机模式。
 * ==========================================================================*/

/* ---------------------------------------------------------------- 手机模式 -- */
@media (max-width: 768px) {

  html, body {
    height: 100%;
    overflow: hidden;
    background: #fff;
  }
  body { --ld-mobile: 1; }

  /* 1) 顶栏：只留必要的，压缩高度，横向可滚 */
  .ld-nav {
    height: 46px !important;
    width: 100% !important;
    max-width: 100vw;
    box-sizing: border-box;
    padding: 0 8px !important;
    gap: 6px !important;
    border-bottom: 1px solid var(--ld-line);
    overflow: hidden;
  }
  .ld-brand { gap: 6px; flex: none; }
  .ld-logo { width: 26px; height: 26px; border-radius: 7px; font-size: 13px; }
  .ld-brand-t b { font-size: 12.5px; white-space: nowrap; }
  .ld-brand-t span { display: none; }
  .ld-tabs {
    flex: 1 1 0;
    min-width: 0;
    gap: 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .ld-tabs::-webkit-scrollbar { display: none; }
  .ld-tab {
    padding: 5px 8px; font-size: 12px; flex: none; gap: 4px;
  }
  .ld-tab i { width: 6px; height: 6px; }
  .ld-tab em { display: none; }
  .ld-tab b { font-size: 12px; white-space: nowrap; }
  .ld-acts { gap: 4px; flex: none; }
  .ld-acts .ld-btn {
    font-size: 11px; padding: 4px 8px; border-radius: 7px; white-space: nowrap;
  }
  /* 手机上顶栏只保留最必要的：隐藏作品集、交互核对、视图切换 */
  .ld-acts > a.ld-btn,
  .ld-acts > [data-act="panel"],
  .ld-acts > [data-act="view"] { display: none; }
  /* 但设计墙/单屏切换在手机上仍然有用，做成一个小图标按钮 */
  .ld-mob-viewbtn {
    display: inline-flex !important;
    align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 8px;
    border: 1px solid var(--ld-line); background: #fff;
    font-size: 15px; color: var(--ld-ink);
    flex: none;
  }

  /* 2) 主区域：全屏，取消内边距 */
  .ldsb {
    grid-template-rows: 46px 1fr !important;
    grid-template-columns: 1fr !important;
    grid-template-areas: "nav" "main" !important;
    width: 100vw;
    max-width: 100vw;
    overflow: hidden;
  }
  .ld-main { overflow: hidden; width: 100%; max-width: 100vw; }
  .ld-main::before { display: none; }

  /* 3) 设计墙：手机上一屏一台，横向吸附，不再缩小 */
  .ld-stage {
    padding: 0 !important;
    gap: 0 !important;
    width: 100vw;
    max-width: 100vw;
    height: 100%;
    align-items: flex-start;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
    overflow-y: hidden;
    cursor: default;
  }
  .ld-phone-wrap {
    width: 100vw !important;
    min-width: 100vw;
    max-width: 100vw;
    height: 100%;
    scroll-snap-align: center;
    gap: 0;
    padding: 0;
    justify-content: flex-start;
  }
  /* 手机壳在真机上没有意义，直接去掉外壳，内容铺满 */
  .ld-phone {
    width: 100% !important;
    height: 100% !important;
    border-radius: 0 !important;
    background: transparent !important;
    padding: 0 !important;
    box-shadow: none !important;
    cursor: default !important;
    --ld-scale: 1 !important;
  }
  .ld-phone:hover { transform: none !important; }
  .ld-phone-notch { display: none !important; }

  .ld-viewport {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border-radius: 0 !important;
  }
  .ld-body { width: 100%; height: 100%; }
  /* 内容按屏幕宽度等比缩放，保持 390 布局 */
  .ld-body > * {
    width: 390px !important;
    height: 844px !important;
    transform-origin: 0 0;
    transform: scale(var(--ld-mobile-scale, 1)) !important;
  }
  /* 让内容高度贴合视口：用 JS 计算 scale 后写入 --ld-mobile-scale */

  /* 4) 真实状态栏由内容自己画（手机浏览器已有系统状态栏，隐藏模拟的） */
  .ld-status { display: none !important; }
  .ld-homebar { display: none !important; }

  /* 5) 标题条：手机上会压在 Tabbar 上，移到顶部导航右侧的小字 */
  .ld-caption { display: none !important; }

  /* 顶部显示当前屏名 */
  .ld-mob-screen {
    display: block !important;
    position: fixed; top: 50px; left: 50%; transform: translateX(-50%);
    font-size: 11px; color: #fff; background: rgba(20,22,28,.55);
    padding: 3px 10px; border-radius: 99px; z-index: 55;
    pointer-events: none; backdrop-filter: blur(6px);
    transition: opacity .3s ease;
  }

  /* 6) 交互核对：手机上隐藏 */
  .ld-inspector { display: none !important; }

  /* 7) 单屏模式：直接铺满 */
  .ld-stage-focus { padding: 0 !important; }
  .ld-focus { width: 100%; height: 100%; gap: 0; }
  .ld-rail { display: none !important; }

  /* 8) Toast 位置抬高，避免被浏览器底栏挡住 */
  .ld-toast { bottom: calc(84px * var(--ld-scale, 1)) !important; }

  /* 9) 屏幕切换动画在手机上弱化 */
  .ld-body-in > *, .ld-body-back > * { animation: none !important; }
}

/* 强制手机模式（URL ?m=1）—— 供桌面端做手机预览 */
html.force-mobile .ld-nav { height: 46px !important; padding: 0 8px !important; }
html.force-mobile .ld-brand-t span { display: none; }
html.force-mobile .ld-tabs .ld-tab em { display: none; }
html.force-mobile .ld-inspector { display: none !important; }
html.force-mobile .ldsb {
  grid-template-rows: 46px 1fr !important;
  grid-template-columns: 1fr !important;
  grid-template-areas: "nav" "main" !important;
}
html.force-mobile .ld-stage { padding: 0 !important; gap: 0 !important; }
html.force-mobile .ld-phone-wrap { width: 100vw !important; min-width: 100vw; }
html.force-mobile .ld-phone {
  width: 100% !important; height: 100% !important;
  border-radius: 0 !important; background: transparent !important;
  padding: 0 !important; box-shadow: none !important;
  --ld-scale: 1 !important;
}
html.force-mobile .ld-phone-notch,
html.force-mobile .ld-status,
html.force-mobile .ld-homebar { display: none !important; }
html.force-mobile .ld-viewport {
  position: absolute !important; inset: 0 !important;
  width: 100% !important; height: 100% !important; border-radius: 0 !important;
}
html.force-mobile .ld-body > * {
  transform: scale(var(--ld-mobile-scale, 1)) !important;
  transform-origin: 0 0;
}
html.force-mobile .ld-caption { display: none !important; }
html.force-mobile .ld-rail { display: none !important; }
