/* =============================================================
   Dragon Silk Road — 首页 · /trade/ 3D 旅程宿主样式
   -------------------------------------------------------------
   作用域：body.page-home 且 <body class="… has-home-trade-lane">
           且 section.home-trade-lane（运行时再加 is-* 状态类）
   设计依据：docs/SOLUTION-home-trade-lane-insertion.md

   三条不可动摇的几何前提（改这里之前先读 SOLUTION §4.2）：
     1) lane.top 必须 = catalog.top + catalog.scrollRange
        → 靠 margin-top: -100svh（与 #catalog 的 sticky 尾巴重合）
     2) lane 内部 stage 占 100svh，由 ScrollTrigger pin 住
        pin 结束后 stage 仍占 100svh（pinSpacing 的物理结果）
     3) #network.top 必须 = lane.top + pin
        → 靠 #network 自己 margin-top: -100svh（与 stage 尾巴同像素）

   ⚠️ 禁止在本 section 或其祖先上加：transform / filter / backdrop-filter /
      will-change: transform / contain: paint。
      它们会让 fixed 的 pinned stage 变成"相对该元素定位"，pin 立刻失效。
   ============================================================= */

/* --------------------------------------------------------------------------
 * 1) 宿主 section
 * ----------------------------------------------------------------------- */
body.page-home .home-trade-lane {
  position: relative;
  z-index: 6;                 /* < #catalog(7)：抬升才能盖住它；> #network(5)：pin 期间盖住真身 */
  margin-top: -100svh;        /* ← 几何前提 1 */
  background: #fff;
  /* 不能用 clip/hidden：下面 ::before 的补缝条在 lane 盒子上方，
     overflow 会把它裁掉（实测被裁后缝隙会露出 #f7f3ea）。
     stage 自己已有 overflow:hidden，pinned 时是 fixed，不需要父级裁剪。 */
  overflow: visible;
  isolation: isolate;
}

/* trade 的 .tj-page 只在 /trade/ 上加 min-height；首页这里贴地由 stage 决定，
   避免 100vh 的 min-height 把空 section 撑高。 */
body.page-home .home-trade-lane.tj-page {
  min-height: 0;
}

/* 抬升交接的"缝"补齐（2026-11-10 实测，最大 47px @1440×900）：
   homepage-reveal.js 用 smoothStep 抬升 foreground，而下一段是线性滚动，
   两者在 t≈0.86 处差出 680(1−t) − 900(1−s(t)) ≈ 47px 的空白带（原始首页就有，
   只是米色对米色不明显）。这里用一段向上溢出的白色把缝补掉：
   它属于 lane（z 6），永远被 catalog（z 7）盖住，只在"缝"里可见。 */
body.page-home .home-trade-lane::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 8svh;
  min-height: 56px;
  background: #fff;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
 * 2) #network：位移与 stage 尾巴精确重合；中和 catalog 交接的 scale/opacity
 *    （值 -100svh 与 homepage-reveal.css 原规则一致，语义从"被 catalog 揭示"
 *      改成"与 stage 尾巴对齐，作为 swap 的落点"）
 * ----------------------------------------------------------------------- */
body.page-home.has-home-trade-lane .home-network.home-network--catalog-handoff {
  /* ← 几何前提 3：network.top 必须 = pin 结束点（= stage st.end）。
     syncGeometry() 直接按 st.end 反推 --trade-pin-offset，不再假设
     lane.top / lane 高度与 pin 距离一致（catalog 懒加载会让它们漂移）。 */
  margin-top: calc(-100svh + var(--trade-pin-offset, 0px));
  transform: none;
  opacity: 1;
  will-change: auto;
  z-index: 5;
}

body.page-home.has-home-trade-lane .home-network.home-network--catalog-handoff::before {
  background: none;           /* 机翼揭幕已替代顶部白→玉渐变 */
}

/* --------------------------------------------------------------------------
 * 3) swap：pin 结束的同一像素，舞台整块让位给真 #network
 *    （两者内容在 swap 帧像素相同，所以这步不可见）
 * ----------------------------------------------------------------------- */
body.page-home .home-trade-lane.is-handed-off {
  z-index: 0;                 /* 掉到 #network(5) 之下 */
}

body.page-home .home-trade-lane.is-handed-off .tj-stage {
  visibility: hidden;         /* 不再绘制，也不再拦截任何东西 */
}

/* --------------------------------------------------------------------------
 * 4) 头：开场白幕双保险
 *    t0=120 已让 updateIntroWhite 在首帧就 hidden=true；CSS 再兜一层，
 *    防止 3D 未就绪（has3D=false）时的任何瞬时可见。
 * ----------------------------------------------------------------------- */
body.page-home .home-trade-lane .tj-intro-white {
  display: none !important;
}

/* --------------------------------------------------------------------------
 * 5) 尾：wing 层（客机带出 network）
 *    结构：.tj-ocean-white > .home-trade-wing > .home-trade-wing__inner > clone
 *    .tj-ocean-white 由 trade-ocean-reveal.js 每帧写 translate3d(seamPx−vw)
 *    内层由 home-trade-lane.js 每帧写 translate3d(vw−seamPx) —— 合成恒为 0，
 *    于是"面板在扫、内容钉死在视口"。
 * ----------------------------------------------------------------------- */
body.page-home .home-trade-lane .tj-ocean-white {
  overflow: hidden;           /* 把内层裁到正在扫动的面板里 */
}

body.page-home .home-trade-lane.is-wing-ready .tj-ocean-white {
  box-shadow: none;           /* seam=vw 时右边缘会留 ~1px 暗线 */
}

body.page-home .home-trade-lane .home-trade-wing {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  /* Under the white veil; the veil is z1 inside .tj-ocean-white. */
  z-index: 0;
  will-change: transform;
}

body.page-home .home-trade-lane .home-trade-wing__inner {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;                /* 用 100%（不含滚动条），不能用 100vw */
  height: 100%;
  overflow: hidden;
  will-change: transform;
}

/* 克隆本体：尺寸/位置与真 #network 首屏一致；不可交互、不进无障碍树 */
body.page-home .home-trade-lane .home-trade-wing__clone {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  margin: 0 !important;
  transform: none !important;
  opacity: 1 !important;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
 * 6) #network 冻结在"终态"：机翼揭幕取代它自己的入场动画
 *    必须同时覆盖真身与克隆，否则 swap 帧会差一帧动画。
 * ----------------------------------------------------------------------- */
html.home-motion-ready body.page-home.has-home-trade-lane #network [data-motion-item],
html.home-motion-ready body.page-home .home-trade-lane .home-trade-wing__clone [data-motion-item] {
  opacity: 1 !important;
  transform: none !important;
  filter: none !important;
  transition: none !important;
}

/* motion 系统的图片壳用 clip-path 做"自下而上揭开"（初始 inset(100% 0 0 0)）；
   克隆/真身都必须直接给出终态，否则卡片图会被裁成 0 高 → swap 前看起来像空卡。 */
html.home-motion-ready body.page-home.has-home-trade-lane #network .motion-media-shell,
html.home-motion-ready body.page-home .home-trade-lane .home-trade-wing__clone .motion-media-shell,
body.page-home.has-home-trade-lane #network .motion-media-shell,
body.page-home .home-trade-lane .home-trade-wing__clone .motion-media-shell {
  clip-path: inset(0 0 0 0) !important;
  -webkit-clip-path: inset(0 0 0 0) !important;
}

body.page-home.has-home-trade-lane #network .motion-line-inner,
body.page-home .home-trade-lane .home-trade-wing__clone .motion-line-inner {
  transform: none !important;
  will-change: auto !important;
}

/* 品牌装饰（homepage-motion 的 silk-route 形状）由滚动驱动，
   克隆在 boot 时抓到的是 progress≈0 的初始态；swap 前必须把两边都钉在终态，
   否则会看到"斜向浅色带 + 曲线"在 swap 时跳变（实测 diff 集中在顶部 306px）。 */
body.page-home.has-home-trade-lane #network .home-motion-shape,
body.page-home .home-trade-lane .home-trade-wing__clone .home-motion-shape {
  --motion-shape-progress: 1 !important;
  --motion-shape-shift: 0px !important;
}

/* 克隆里的 motion 元素不参与合成层，避免亚像素抗锯齿差异 */
body.page-home .home-trade-lane .home-trade-wing__clone [data-motion-item] {
  will-change: auto !important;
}

/* 克隆里的图片不再触发 lazy 观察者的布局抖动 */
body.page-home .home-trade-lane .home-trade-wing__clone img {
  visibility: visible !important;
}

/* --------------------------------------------------------------------------
 * 7) 沉浸（D8）+ 布局锁定（Q1）
 *    home-trade-focus 由适配层在接近 lane 时加到 body 上。
 *    --dsr-header-height 归零：保证 main.js 在段内重新显示/隐藏 header 时
 *    不会产生 114px 的文档位移（那会让 pin 的 start/end 过期）。
 * ----------------------------------------------------------------------- */
body.page-home.home-trade-focus {
  --dsr-header-height: 0px;
}

body.page-home.home-trade-focus .to-top {
  opacity: 0;
  pointer-events: none;
}

body.page-home.home-trade-focus .site-header {
  opacity: 0;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
 * 8) 断点：<901px 整段不渲染（D5）
 *    与 trade-journey.js 的 staticMode() 严格同一断点（901）。
 * ----------------------------------------------------------------------- */
@media (max-width: 900px) {
  body.page-home .home-trade-lane {
    display: none;
  }

  body.page-home.has-home-trade-lane .home-network.home-network--catalog-handoff {
    margin-top: 0;
    transform: none;
    opacity: 1;
  }
}

/* --------------------------------------------------------------------------
 * 9) 失败兜底（适配层 8s 未就绪 → html.home-trade-failed）
 * ----------------------------------------------------------------------- */
html.home-trade-failed body.page-home .home-trade-lane {
  display: none;
}

html.home-trade-failed body.page-home.has-home-trade-lane .home-network.home-network--catalog-handoff {
  margin-top: 0;
}

/* --------------------------------------------------------------------------
 * 10) 调试开关（?tradelane=debug 时给适配层加的类）：把 lane 描边，
 *     只用于本地视觉校验，不影响任何尺寸。
 * ----------------------------------------------------------------------- */
html.home-trade-debug body.page-home .home-trade-lane {
  outline: 2px dashed rgba(0, 128, 255, 0.45);
  outline-offset: -2px;
}

/* --------------------------------------------------------------------------
 * 11) 视觉门控（2026-11-30 · SOLUTION §8）
 *
 *   问题：trade-journey.js:1294-1304 在 init 后 2 帧就无条件把 3D 层
 *        opacity 0→1（520ms），完全不看贴图是否已到 ⇒ 首帧渲染出只带
 *        基础色的几何体（深藏青集装箱 + 灰色拖板）= 用户看到的"白模"。
 *
 *   本规则是**静态 CSS**，首帧即生效、不依赖任何 JS 时序：
 *       只要 html 上没有 home-trade-visual-ready，整个 pinned 舞台不可见。
 *   适配层在「全部旅程贴图 decode 成功」后才加该类（见 home-trade-lane.js）。
 *
 *   · 用 visibility 而不是 opacity：不参与布局、不影响 pin 测量，
 *     也不会与 trade-journey.js 逐帧写入的 opacity/transform 打架。
 *   · home-trade-skipped / home-trade-failed 时 lane 已 display:none，
 *     本规则自然失效，无需额外覆盖。
 * ----------------------------------------------------------------------- */
html:not(.home-trade-visual-ready) body.page-home.has-home-trade-lane .home-trade-lane [data-tj-stage] {
  visibility: hidden !important;
}

/* --------------------------------------------------------------------------
 * 12) 跳过兜底（2026-11-30 · SOLUTION §7）
 *
 *   判定：用户滚到"旅程第一可见像素"之前（scrollY + 1.2*innerHeight ≥ lane.top）
 *        而旅程贴图仍未全部就绪 ⇒ 直接跳过整段，显示 Factory & partner network。
 *
 *   几何：把 lane 整段 display:none（连同 ScrollTrigger 的 pinSpacing），
 *        并把 #network 交还给 homepage-reveal 的**基线交接**：
 *          · margin-top: -100svh  ——  与 homepage-reveal.css 的基线完全一致
 *          · transform / opacity  ——  交回 --catalog-network-scale / -opacity
 *        于是 catalog 的最后 100svh 抬升会自然揭示 #network，
 *        与"旅程播完 → 机翼带出 network"在视觉上等价，且**滚动位置零跳变**。
 *
 *   为什么不是 margin-top: 0（home-trade-failed 的做法）：
 *        实测会让 #network 落在 laneTop 之后约 966px，判定点上多出一屏空白，
 *        并产生 966px 的 scrollTo 跳变。
 * ----------------------------------------------------------------------- */
html.home-trade-skipped body.page-home .home-trade-lane {
  display: none !important;
}

html.home-trade-skipped body.page-home.has-home-trade-lane #network.home-network--catalog-handoff {
  margin-top: -100svh !important;
  transform: scale(var(--catalog-network-scale, 1)) !important;
  opacity: var(--catalog-network-opacity, 1) !important;
  will-change: auto;
  z-index: 5;
}

/* 跳过时把沉浸态一并撤掉：header / 回顶恢复可交互，
   并把主内容的 header 占位还原（114px 由适配层用滚动补偿抵消）。 */
html.home-trade-skipped body.page-home.home-trade-focus .site-header {
  opacity: 1 !important;
  pointer-events: auto !important;
}

html.home-trade-skipped body.page-home.home-trade-focus .to-top {
  opacity: 1;
  pointer-events: auto;
}
