/* =========================================================================
 * loading.css —— SonicLink 声波传讯 · 高级加载动效
 * 启动页（Splash + 真实进度）/ 顶部进度条 / 发送乐观 UI 反馈
 * 沿用项目既有的项目既有蓝色强调色 + 液态玻璃配色；无外部资源。
 * ========================================================================= */

:root {
  --lp-ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --lp-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --lp-dur-micro: 120ms;
  --lp-dur-ui: 200ms;
  --lp-dur-page: 280ms;
}

/* ---------- 启动页 Splash ---------- */
#lpSplash {
  --p: 0;
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  background:
    radial-gradient(90% 70% at 50% 12%, rgba(46,123,184,.12) 0%, transparent 62%),
    var(--page, #F5F9FD);
  opacity: 1;
  will-change: transform, opacity;
  /* 退出 240ms，快于入场 280ms */
  transition: opacity 240ms var(--lp-ease-out), transform 240ms var(--lp-ease-out);
}
#lpSplash.lp-gone { opacity: 0; transform: scale(0.96); pointer-events: none; }

/* 品牌标记：声波同心圆 */
.lp-mark { position: relative; width: 76px; height: 76px; display: grid; place-items: center; }
.lp-mark > svg { width: 30px; height: 30px; color: var(--accent, #2E7BB8); position: relative; z-index: 2; }
.lp-mark::before, .lp-mark::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 1.5px solid color-mix(in srgb, var(--accent, #2E7BB8) 50%, transparent);
  animation: lpMarkPulse 2.1s cubic-bezier(.4,0,.2,1) infinite;
}
.lp-mark::after { animation-delay: -1.05s; }
@keyframes lpMarkPulse {
  0%   { transform: scale(.55); opacity: 0; }
  30%  { opacity: .75; }
  100% { transform: scale(1.18); opacity: 0; }
}

.lp-word {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  animation: lpEnter 280ms var(--lp-ease-out) both;
}
@keyframes lpEnter {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}
.lp-title {
  font-size: 17px; font-weight: 800; letter-spacing: .06em;
  color: var(--ink-1, #14263B);
}
.lp-sub { font-size: 11px; letter-spacing: .16em; color: var(--ink-3, #5C6E83); }

.lp-bar {
  --p: 0;
  position: relative; width: min(230px, 60vw); height: 3px; border-radius: 3px;
  background: color-mix(in srgb, var(--accent, #2E7BB8) 14%, transparent);
  overflow: hidden;
}
.lp-bar > i {
  position: absolute; inset: 0; border-radius: 3px;
  transform: scaleX(var(--p)); transform-origin: left center;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--accent, #2E7BB8) 60%, #fff),
    var(--accent, #2E7BB8));
  transition: transform 200ms var(--lp-ease-out);
  will-change: transform;
}
.lp-bar::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 42px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.85), transparent);
  will-change: transform;
  animation: lpShimmer 1.5s linear infinite;
}
@keyframes lpShimmer {
  from { transform: translate3d(-52px, 0, 0); }
  to   { transform: translate3d(250px, 0, 0); }
}

.lp-pct { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--ink-3, #5C6E83); letter-spacing: .1em; }
.lp-stage { font-size: 12px; color: var(--ink-2, #31435A); min-height: 16px; }

/* ---------- 顶部进度条 ---------- */
#lpTop {
  --p: 0;
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 9998;
  pointer-events: none;
  background: color-mix(in srgb, var(--accent, #2E7BB8) 8%, transparent);
  opacity: 0;
  transition: opacity var(--lp-dur-ui) var(--lp-ease-out);
  will-change: opacity;
}
#lpTop.lp-on { opacity: 1; }
#lpTop > i {
  position: absolute; inset: 0; display: block;
  transform: scaleX(var(--p)); transform-origin: left center;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--accent, #2E7BB8) 55%, #fff),
    var(--accent, #2E7BB8));
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transition: transform 180ms var(--lp-ease-out), opacity 180ms var(--lp-ease-out);
  will-change: transform;
}
/* 头部亮点：与进度条同 duration / 同 easing */
#lpTop > b {
  position: absolute; top: 0; left: 0; width: 32px; height: 3px;
  background: linear-gradient(90deg, transparent, #fff);
  border-radius: 0 3px 3px 0;
  transform: translate3d(calc(var(--p) * (100vw - 32px)), 0, 0);
  transform-origin: left center;
  opacity: 0.9;
  transition: transform 180ms var(--lp-ease-out), opacity 180ms var(--lp-ease-out);
  will-change: transform;
}
/* 收尾：冲到 100% 后淡出 */
#lpTop.lp-done > i,
#lpTop.lp-done > b { opacity: 0; }
#lpTop.lp-done { background: transparent; }

/* ---------- 发送乐观 UI：秒发回执气泡 ---------- */
#lpOptimistic {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top, 0px));
  transform: translate(-50%, -14px); z-index: 9997;
  display: flex; align-items: center; gap: 9px;
  max-width: min(440px, 90vw);
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--glass-w4, rgba(255,255,255,.9));
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border, rgba(20,52,92,.10));
  box-shadow: 0 8px 24px var(--ink-shadow);
  font-size: 12.5px; color: var(--ink-1, #14263B);
  opacity: 0; pointer-events: none;
  transition: opacity .24s ease, transform .28s cubic-bezier(.16,1,.3,1);
}
#lpOptimistic.lp-on { opacity: 1; transform: translate(-50%, 0); }
/* 状态图标：pending(旋转) → ok(对勾) → fail(叹号) */
#lpOptimistic .lp-ico {
  width: 15px; height: 15px; flex: none;
  color: var(--accent, #2E7BB8);
  transform-origin: 50% 50%;
  will-change: transform;
  transition: transform 200ms var(--lp-ease-out);
}
#lpOptimistic.lp-pending .lp-ico { animation: lpSpin 850ms linear infinite; }
@keyframes lpSpin { to { transform: rotate(360deg); } }
#lpOptimistic.lp-ok .lp-ico { color: var(--ok-ink, #0A6B3C); animation: lpPop 200ms var(--lp-ease-out); }
#lpOptimistic.lp-fail .lp-ico { color: var(--bad-ink, #9B1C20); }
@keyframes lpPop { from { transform: scale(0.6); } to { transform: scale(1); } }
#lpOptimistic .lp-txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#lpOptimistic .lp-act {
  margin-left: 2px; padding: 3px 10px; border-radius: 999px;
  border: 1px solid var(--border, rgba(20,52,92,.16));
  background: transparent; color: var(--accent, #2E7BB8);
  font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer;
}
#lpOptimistic .lp-act:active { transform: scale(0.96); }

/* ---------- Hover（仅精确指针设备） ---------- */
@media (hover: hover) and (pointer: fine) {
  #lpOptimistic:hover { transform: translate3d(-50%, -2px, 0) scale(1); }
}

/* ---------- 减弱动态 ----------
   去 transform / 位移 / 缩放；循环动画负 delay 暂停在好看的帧；保留 opacity。 */
@media (prefers-reduced-motion: reduce) {
  #lpSplash.lp-gone { transform: none; }
  .lp-word { animation: none; opacity: 1; transform: none; }
  #lpOptimistic,
  #lpOptimistic.lp-on { transform: translate3d(-50%, 0, 0) scale(1); }
  #lpOptimistic:hover { transform: translate3d(-50%, 0, 0) scale(1); }
  #lpOptimistic.lp-ok .lp-ico { animation: none; transform: none; }
  .lp-mark::before,
  .lp-mark::after { animation: none; opacity: .5; }
  .lp-bar::after { animation: none; opacity: 0; }
  #lpOptimistic.lp-pending .lp-ico { animation: none; opacity: .7; }
  .lp-bar > i, #lpTop > i, #lpTop > b { transition-duration: 1ms !important; }
  #lpSplash, #lpTop, #lpOptimistic { transition-duration: 120ms !important; }
}