/* ============================================================
   WhereRelay — 首屏动效（从 base.css 抽离，可独立预览 / 复用）
   ------------------------------------------------------------
   本文件只负责首屏的动画：
   1. 「直连 vs 中继」拓扑对比卡（.topo*）及其全部循环动效
   2. 首屏入场编排（hero-copy 逐项淡入、hero-visual 延迟入场）

   配套文件：
   - 结构：partials/02-hero.html
   - 脚本：assets/js/hero-anim.js（终端打字 + 重播 / 暂停 / 调速）
   - 预览：animation/index.html（由 node tools/build.mjs 生成）
   - 依赖：base.css 的设计 token（--brand / --line / --soft …）
     与 .dot / .i 等基础类；单独嵌入其他页面时先引 base.css。

   ------------------------------------------------------------
   动效时间轴（DESIGN.md §5.5）
   ------------------------------------------------------------
   直连失败 · 2.4s 循环
     0–50%    红点沿虚线出发（8% 淡入），停在丢包点前 44%
     52–56%   红点在 46.5% 处消失
     52–94%   × 爆点弹出 + 扩散环 + 结果条闪红
   中继流光 · 2.2s 循环（第二颗数据包负延迟 1.1s）
     0–100%   绿点从左 2% 流到右 96%，带 9px 拖尾
     20–62%   WhereRelay 入口 chip 描边呼吸
     64–100%  目标节点到达波纹 + 状态点脉冲
   终端打字 · 每行约 4s（脚本 assets/js/hero-anim.js）
     初始停留 2.6s → 删除 15ms/字 → 换行 30ms
     → 打字 32–64ms/字 → 停留 2s → 下一行
   入场 · 只播一次
     文案 hero-in .62s（每项 +60ms 递延），卡片 .78s（延迟 .18s），
     缓动 cubic-bezier(.2,.6,.2,1)
   ============================================================ */

/* ------------------------------------------------------------
   1 · 拓扑对比卡：结构 + 静态样式
   ------------------------------------------------------------ */
/* 首屏右侧：拓扑对比图 */
.topo{position:relative;background:#fff;border:1px solid var(--line);border-radius:20px;box-shadow:var(--shadow);overflow:hidden}
.topo-hd{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:14px 20px;background:var(--soft-2);border-bottom:1px solid var(--line)}
.topo-hd-l{display:flex;align-items:center;gap:8px;min-width:0;font-family:var(--f-mono);font-size:11px;letter-spacing:.08em;text-transform:uppercase;color:var(--ink-3);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.topo-hd-l .dot{width:6px;height:6px}
.topo-body{padding:24px 20px 20px}
.topo-row{position:relative;display:flex;flex-direction:column;gap:12px;padding:16px;border:1px solid var(--line);border-radius:12px;background:#fff}
.topo-row+.topo-row{margin-top:12px}
.topo-row{transition:border-color .45s ease,box-shadow .45s ease}
.topo-row.probe-focus{box-shadow:0 0 0 3px rgba(0,136,79,.07)}
.topo-row.bad.probe-focus{border-color:#F2C2BC;box-shadow:0 0 0 3px rgba(217,45,32,.06)}
.topo-row.hl.probe-focus{border-color:var(--brand-line);box-shadow:0 0 0 3px rgba(0,136,79,.09)}
.topo-row.hl{background:var(--tint);border-color:var(--brand-line)}
.topo-row-hd{display:flex;align-items:center;justify-content:space-between;gap:8px}
.topo-name{display:inline-flex;align-items:center;gap:8px;font-size:14px;line-height:24px;font-weight:600;color:var(--ink)}
.topo-name .i{width:16px;height:16px}
.topo-row.bad .topo-name .i{color:var(--off)}
.topo-row.hl .topo-name .i{color:var(--brand)}
.topo-state{display:inline-flex;align-items:center;gap:6px;font-family:var(--f-mono);font-size:11px;letter-spacing:.04em;color:var(--ink-3)}
.topo-path{display:flex;align-items:center;gap:0;min-height:64px}
.topo-node{display:flex;flex-direction:column;align-items:center;gap:6px;width:64px;flex:none}
.topo-node .box{display:flex;align-items:center;justify-content:center;width:40px;height:40px;border:1px solid var(--line-2);border-radius:10px;background:#fff;color:var(--ink-2)}
.topo-node .box.on{background:var(--brand);border-color:var(--brand);color:#fff}
.topo-node small{font-size:10px;line-height:14px;color:var(--ink-3);white-space:nowrap;font-family:var(--f-mono)}
.topo-wire{position:relative;flex:1;height:40px;display:flex;align-items:center;justify-content:center;min-width:0}
.topo-wire::before{content:"";position:absolute;left:0;right:0;top:50%;border-top:1px solid var(--line-2)}
.topo-wire.dash::before{border-top-style:dashed;border-top-color:#D9A6A0}
.topo-wire.ok::before{border-top:2px solid var(--brand-line);top:calc(50% - .5px)}
.topo-wire-tag{position:relative;padding:4px 8px;border:1px solid var(--line);border-radius:6px;background:#fff;font-family:var(--f-mono);font-size:10px;line-height:14px;color:var(--ink-3);white-space:nowrap;max-width:100%;overflow:hidden;text-overflow:ellipsis}
.topo-row.hl .topo-wire-tag{border-color:var(--brand-line);color:var(--brand);background:#fff}
.topo-mid{flex:none;display:flex;flex-direction:column;align-items:center;gap:6px;padding:0 4px}
.topo-mid .chip{display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 10px;border-radius:8px;background:var(--brand);color:#fff;font-family:var(--f-mono);font-size:11px;line-height:1;font-weight:500}
.topo-mid small{font-family:var(--f-mono);font-size:9px;line-height:12px;color:var(--brand);letter-spacing:.02em;white-space:nowrap}
.topo-result{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:8px 10px;border-radius:8px;background:#FEF3F2;border:1px solid #FDDCD9;font-size:12px;line-height:20px}
.topo-result .r-l{display:inline-flex;align-items:center;gap:6px;font-weight:600;color:#B42318}
.topo-result .r-m{font-family:var(--f-mono);font-size:11px;color:#B42318;opacity:.8;white-space:nowrap}
.topo-result.good{background:#fff;border-color:var(--brand-line)}
.topo-result.good .r-l{color:var(--brand)}
.topo-result.good .r-m{color:var(--ink-3);opacity:1}
.topo-foot{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-top:16px;padding-top:16px;border-top:1px solid var(--line)}
.topo-foot .mono{font-size:10px;letter-spacing:.06em;color:var(--ink-4);text-transform:uppercase}
.topo-foot .stat{display:flex;align-items:baseline;gap:6px;flex:none;margin-left:12px;font-family:var(--f-mono);font-size:12px;color:var(--ink-2);white-space:nowrap}
.topo-foot .stat b{font-size:16px;font-weight:600;color:var(--ink)}
.topo-foot .stat.good b{color:var(--brand)}
/* ------------------------------------------------------------
   2 · 数据包流动：中继双包 2.2s（错开 1.1s）+ 直连丢包 2.4s
   ------------------------------------------------------------ */
/* live packets: 2.2s cycle, continuous flow on the relay path */
.packet{position:absolute;top:calc(50% - 3px);left:2%;width:6px;height:6px;border-radius:50%;background:var(--brand);box-shadow:0 0 0 3px rgba(0,136,79,.10);animation:packet-move 2.2s linear infinite}
.packet::after{content:"";position:absolute;right:6px;top:2px;width:9px;height:2px;border-radius:1px;background:var(--brand);opacity:.28}
.packet.p2{animation-delay:-1.1s}
@keyframes packet-move{0%{left:2%;opacity:0}10%{opacity:1}92%{opacity:1}100%{left:96%;opacity:0}}

/* failing packet: tries, dies at the loss point */
.pkt-fail{background:var(--off);box-shadow:0 0 0 3px rgba(217,45,32,.10);animation:pkt-fail 2.4s cubic-bezier(.55,.05,.85,.5) infinite}
.pkt-fail::after{background:var(--off);opacity:.22}
@keyframes pkt-fail{0%{left:4%;opacity:0}8%{opacity:1}50%{left:44%;opacity:1}56%{left:46.5%;opacity:0}100%{left:46.5%;opacity:0}}

/* ------------------------------------------------------------
   3 · 失败反馈：× 爆点 + 扩散环 + 结果条闪红（2.4s）
   ------------------------------------------------------------ */
/* failure burst at the loss point */
.topo-fail{position:absolute;left:46.5%;top:calc(50% - 10px);width:20px;height:20px;display:inline-flex;align-items:center;justify-content:center;border-radius:50%;background:#FEF3F2;border:1px solid #FDDCD9;color:#D92D20;opacity:0;transform:scale(.62);animation:fail-pop 2.4s cubic-bezier(.2,.6,.2,1) infinite;z-index:3}
.topo-fail .i{width:12px;height:12px}
.topo-fail::after{content:"";position:absolute;inset:-2px;border-radius:50%;border:1px solid #F5C6C1;opacity:0;animation:fail-ring 2.4s ease-out infinite}
@keyframes fail-ring{0%,54%{opacity:0;transform:scale(1)}62%{opacity:.9}88%,100%{opacity:0;transform:scale(2.1)}}
@keyframes fail-pop{0%,52%{opacity:0;transform:scale(.62)}58%{opacity:1;transform:scale(1.14)}65%{transform:scale(1)}84%{opacity:1;transform:scale(1)}94%,100%{opacity:0;transform:scale(1)}}

/* the failed row breathes red on each failure */
.topo-row.bad .topo-result{animation:fail-flash 2.4s ease-out infinite}
@keyframes fail-flash{0%,54%{background:#FEF3F2;border-color:#FDDCD9}60%{background:#FCE7E4;border-color:#F8C9C3}72%,100%{background:#FEF3F2;border-color:#FDDCD9}}

/* ------------------------------------------------------------
   4 · 到达反馈：节点波纹 + 入口 chip 呼吸 + 状态点脉冲
   ------------------------------------------------------------ */
/* arrival ripple on the target node */
.topo-node .box{position:relative}
.topo-node.arrive .box::after{content:"";position:absolute;inset:-2px;border-radius:13px;border:2px solid rgba(0,136,79,.45);opacity:0;animation:arrive-ring 2.2s ease-out infinite}
@keyframes arrive-ring{0%,64%{opacity:0;transform:scale(.86)}72%{opacity:1}100%{opacity:0;transform:scale(1.52)}}

/* relay entry chip breathes as packets cross */
.topo-mid{position:relative}
.topo-mid .chip{position:relative;z-index:1}
.topo-mid .chip::after{content:"";position:absolute;inset:-4px;border-radius:12px;border:1.5px solid rgba(0,136,79,.38);opacity:0;animation:chip-pulse 2.2s ease-out infinite;z-index:-1}
@keyframes chip-pulse{0%,20%{opacity:0;transform:scale(.95)}32%{opacity:1}62%,100%{opacity:0;transform:scale(1.22)}}

/* live result dot pulses when a packet arrives */
.topo-result.good .dot{animation:dot-live-pulse 2.2s ease-out infinite}
@keyframes dot-live-pulse{0%,70%{box-shadow:0 0 0 0 rgba(0,136,79,.28)}82%{box-shadow:0 0 0 6px rgba(0,136,79,0)}100%{box-shadow:0 0 0 0 rgba(0,136,79,0)}}

/* mono wire label sits above the dashed line so packets stay visible */
.topo-row.bad .topo-wire-tag{transform:translateY(-15px);background:#fff}

/* ------------------------------------------------------------
   5 · 卡底终端日志与光标（文案由 assets/js/hero-anim.js 驱动）
   ------------------------------------------------------------ */
/* live terminal log in the card footer */
.topo-log{display:inline-flex;align-items:center;gap:7px;flex:1 1 auto;min-width:0;max-width:100%;font-size:10px;letter-spacing:.02em;color:var(--ink-3);white-space:nowrap;overflow:hidden}
.topo-log .dot{width:6px;height:6px;flex:none}
.topo-log-tx{display:inline-block;min-width:0;overflow:hidden;text-overflow:ellipsis;max-width:100%}
.topo-caret{display:inline-block;width:5px;height:10px;flex:none;background:var(--brand);opacity:.75;animation:caret-blink 1.1s steps(1) infinite}
@keyframes caret-blink{0%,50%{opacity:.75}51%,100%{opacity:0}}

/* ------------------------------------------------------------
   6 · 首屏入场（只播一次）
   ------------------------------------------------------------ */
/* hero entrance */
@keyframes hero-in{from{opacity:0;transform:translateY(14px)}to{opacity:1;transform:none}}
.hero-copy > *{animation:hero-in .62s cubic-bezier(.2,.6,.2,1) both}
.hero-copy > h1{animation-delay:.04s}
.hero-copy > .hero-sub{animation-delay:.10s}
.hero-copy > .hero-cta{animation-delay:.16s}
.hero-copy > .hero-note{animation-delay:.22s}
.hero-copy > .hero-meta{animation-delay:.28s}
.hero-visual{animation:hero-in .78s cubic-bezier(.2,.6,.2,1) .18s both}

/* ------------------------------------------------------------
   7 · 响应式
   ------------------------------------------------------------ */
@media (max-width:1024px){
  .topo{max-width:640px}
}
@media (max-width:760px){
  .topo-hd{padding:12px 14px}
  .topo-hd-l{font-size:10px;letter-spacing:.04em}
  .topo-body{padding:16px 12px 14px}
  .topo-row{padding:12px}
  .topo-node{width:52px}
  .topo-node .box{width:36px;height:36px}
  .topo-node small{font-size:9px}
  .topo-wire-tag{font-size:9px;padding:3px 6px}
  .topo-mid .chip{font-size:10px;padding:0 8px;height:26px}
  .topo-mid small{font-size:8px}
  .topo-result{font-size:11px;padding:6px 8px;flex-wrap:wrap}
  .topo-foot{gap:8px}
  .topo-foot .mono{font-size:9px;letter-spacing:.02em}
  .topo-log{font-size:9px;gap:6px}
  .topo-caret{width:4px;height:9px}
  .topo-foot .stat{margin-left:8px;font-size:11px}
  .topo-foot .stat b{font-size:14px}
}

/* ------------------------------------------------------------
   8 · 降级
   prefers-reduced-motion：所有循环动画停止，数据包 / 爆点 / 波纹隐藏，
   终端由 assets/js/hero-anim.js 固定为 probe relay · 38 ms。
   html.anim-static 是同一套静态规则的显式开关（预览页「静态」按钮，
   或嵌入方需要手动关闭动效时使用）。
   ------------------------------------------------------------ */
@media (prefers-reduced-motion:reduce){
  .hero-copy > *,.hero-visual{animation:none}
  .packet,.topo-fail,.topo-node.arrive .box::after,.topo-mid .chip::after{display:none}
  .topo-row.bad .topo-result,.topo-result.good .dot,.topo .dot-live::after,.topo-caret{animation:none}
}
html.anim-static .hero-copy > *,html.anim-static .hero-visual{animation:none}
html.anim-static .packet,html.anim-static .topo-fail,html.anim-static .topo-node.arrive .box::after,html.anim-static .topo-mid .chip::after{display:none}
html.anim-static .topo-row.bad .topo-result,html.anim-static .topo-result.good .dot,html.anim-static .topo .dot-live::after,html.anim-static .topo-caret{animation:none}
