/* ============================================================
   首页「注册福利」弹窗 + 缩小后的红包
   配套脚本：js/signup-promo.js（弹窗的 DOM 由脚本生成）
   说明文档：docs/signup-promo.md

   层级约定（和站内其他浮层的关系）：
     联系我们弹窗 100 > 本弹窗 90 > 导航栏 50 > 手机菜单 40 > 红包 38
   红包压在导航栏和手机菜单下面，任何情况下都不会挡住导航。
   ============================================================ */

/* 首页有区块比手机屏幕宽（body 的 overflow-x 拦不住），会把 fixed 元素的参照宽度撑大，
   弹窗因此偏到屏幕外。clip 不会产生滚动容器，不影响页面滚动 */
html {
  overflow-x: clip;
}

.sp-root {
  /* 红包尺寸：电脑端 / 手机端 */
  --sp-packet-size: 64px;
  /* 红包静止时的位置（平板、或开了「减少动态效果」的电脑端；手机端见下面的 bottom）。
     76px ≈ 导航栏高度 64px + 间距，让红包落在导航栏下方，不挡 Logo */
  --sp-packet-top: 76px;
  --sp-packet-left: 12px;
  /* 手机端红包在左下角，距离底部的距离 */
  --sp-packet-bottom: 16px;

  --sp-red: #e8382f;
  --sp-red-deep: #b9161b;
  --sp-gold: #ffd36b;
  --sp-gold-deep: #f2a93b;
}

/* 被 New API 用 iframe 嵌入时，本站导航栏是隐藏的，红包直接贴 iframe 左上角 */
.embedded .sp-root {
  --sp-packet-top: 12px;
}

@media (max-width: 767px) {
  .sp-root {
    --sp-packet-size: 48px;
  }
}

/* 切到非中文语言时整体隐藏（由脚本加类） */
.sp-root.sp-lang-off {
  display: none;
}

/* ---------------- 遮罩 + 弹窗 ---------------- */

.sp-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
}

.sp-overlay.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.35s ease, visibility 0s;
}

.sp-dialog {
  position: relative;
  width: min(100%, calc((100vh - 2rem) * 0.685));
  max-width: 23rem;
  /* 矮屏（横屏手机、小窗口）按高度收窄，整张图都能放下 */
  max-height: calc(100vh - 2rem);
  overflow: hidden;
  border-radius: 1.25rem;
  background: #5c1322;
  color: #fff;
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.45);
  text-align: center;
  font-family: inherit;
  transform: translateY(14px) scale(0.96);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.35s ease;
}

.sp-overlay.is-open .sp-dialog {
  transform: none;
  animation: sp-dialog-glow 2.4s ease-in-out infinite;
}

/* 弹窗边缘发光：一圈金色描边 + 外围金红色光晕，和红包同步「呼吸」。
   弹窗本身 overflow: hidden，伪元素光晕会被裁掉，所以这里用 box-shadow 做 */
@keyframes sp-dialog-glow {
  0%, 100% {
    box-shadow:
      0 0 0 1px rgba(255, 211, 107, 0.55),
      0 0 18px 2px rgba(255, 170, 60, 0.35),
      0 0 44px 6px rgba(232, 56, 47, 0.25),
      0 30px 60px -20px rgba(0, 0, 0, 0.45);
  }
  50% {
    box-shadow:
      0 0 0 1px rgba(255, 211, 107, 0.95),
      0 0 28px 4px rgba(255, 190, 70, 0.6),
      0 0 66px 12px rgba(232, 56, 47, 0.4),
      0 30px 60px -20px rgba(0, 0, 0, 0.45);
  }
}

/* 缩小成红包 / 从红包展开：弹窗飞向（或飞出自）红包所在的位置。
   --sp-dx / --sp-dy / --sp-scale 由脚本根据红包坐标实时计算 */
.sp-overlay.is-shrunk .sp-dialog {
  transform: translate(var(--sp-dx, 0), var(--sp-dy, 0)) scale(var(--sp-scale, 0.2));
  opacity: 0;
}

.sp-overlay.is-shrunk {
  opacity: 0;
}

/* 从红包展开的第一帧：瞬间放到红包位置，不要过渡 */
.sp-overlay.no-anim,
.sp-overlay.no-anim .sp-dialog {
  transition: none !important;
}

/* ---- 弹窗画面：一张设计图 + 底部一行小字 ----
   按钮和关闭键画在图上，真实的可点击元素按百分比盖在图中对应位置，
   弹窗缩放时跟着图一起等比变化。换图后要重新量这几个百分比 */

.sp-poster {
  position: relative;
  /* 按钮字号按弹窗宽度缩放（cqw） */
  container-type: inline-size;
  line-height: 0;
}

.sp-poster-img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1233 / 1712;
  user-select: none;
  -webkit-user-select: none;
}

/* 只给读屏软件看的文字 */
.sp-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.sp-icon-btn {
  position: absolute;
  top: 3.4%;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 0.5rem;
  background: transparent;
  color: #fff;
  cursor: pointer;
  transform: translate(-50%, -50%);
  transition: background 0.2s ease;
}

.sp-close {
  left: 92.8%;
}

.sp-minimize {
  left: 83.4%;
}

.sp-icon-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.sp-icon-btn:focus-visible {
  outline: 2px solid var(--sp-gold);
  outline-offset: 1px;
}

.sp-icon-btn svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* 光效层：圆心对准图上那圈金色细环。
   screen 混合只会把图提亮，暗处不变，所以光像是从图里透出来的 */
.sp-aura {
  position: absolute;
  top: 35.3%;
  left: 49.6%;
  z-index: 2;
  width: 72%;
  aspect-ratio: 1;
  mix-blend-mode: screen;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

/* 红包外圈的光晕：一明一暗地呼吸 */
.sp-aura::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(
    closest-side,
    transparent 34%,
    rgba(255, 190, 90, 0.6) 58%,
    rgba(255, 130, 60, 0.22) 76%,
    transparent 100%
  );
  animation: sp-aura-breathe 2.8s ease-in-out infinite;
}

/* 一道亮光沿着金色细环转圈 */
.sp-aura::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    transparent 0deg,
    transparent 230deg,
    rgba(255, 214, 130, 0.5) 320deg,
    #fff3cf 356deg,
    transparent 360deg
  );
  -webkit-mask-image: radial-gradient(closest-side, transparent 60%, #000 62%, #000 64.5%, transparent 66.5%);
  mask-image: radial-gradient(closest-side, transparent 60%, #000 62%, #000 64.5%, transparent 66.5%);
  animation: sp-aura-spin 5s linear infinite;
}

@keyframes sp-aura-breathe {
  0%, 100% { opacity: 0.35; transform: scale(0.95); }
  50% { opacity: 1; transform: scale(1.05); }
}

@keyframes sp-aura-spin {
  to { transform: rotate(360deg); }
}

/* 「立即领取」：真实按钮，叠在图上。金底深红字，和图上的金字同一套配色 */
.sp-cta {
  position: absolute;
  top: 87.4%;
  left: 28.5%;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 43.2%;
  height: 7.5%;
  overflow: hidden;
  border: 1px solid #fff0c0;
  border-radius: 999px;
  background: linear-gradient(to bottom, #fff3c4 0%, #ffd666 46%, #f3ab2f 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    inset 0 -2px 3px rgba(176, 92, 8, 0.4),
    0 6px 14px rgba(90, 0, 8, 0.45);
  color: #8e0f16;
  font-size: 1.25rem;
  font-size: 5.4cqw;
  font-weight: 800;
  letter-spacing: 0.14em;
  line-height: 1;
  text-decoration: none;
  transition: transform 0.2s ease, filter 0.2s ease;
}

/* 隔几秒扫过一道高光 */
.sp-cta::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -40%;
  width: 30%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.75), transparent);
  transform: skewX(-18deg);
  animation: sp-cta-shine 3.4s ease-in-out infinite;
}

@keyframes sp-cta-shine {
  0%, 55% { left: -40%; }
  100% { left: 120%; }
}

.sp-cta:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.sp-cta:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

/* 光点画布：盖在整个弹窗上，不挡点击 */
.sp-sparks {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* 底部小字：和图的下沿一样是纯白，两者看不出分界 */
.sp-note {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1233 / 88;
  margin: 0;
  background: #fff;
  color: #a0623a;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.12em;
}

@media (max-width: 767px) {
  .sp-dialog {
    max-width: 20rem;
  }

  .sp-note {
    font-size: 0.625rem;
  }
}

/* ---------------- 红包 ---------------- */

.sp-packet {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 38;
  width: var(--sp-packet-size);
  height: calc(var(--sp-packet-size) * 1.25);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  /* 漫游时由脚本写 transform；这里只给淡入淡出 */
  transition: opacity 0.3s ease, visibility 0s linear 0.3s;
  -webkit-tap-highlight-color: transparent;
}

.sp-packet.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition: opacity 0.3s ease, visibility 0s;
}

/* 静止模式：手机端，或电脑端开了「减少动态效果」 */
.sp-packet.is-static {
  top: var(--sp-packet-top);
  left: var(--sp-packet-left);
  transform: none !important;
}

/* 手机端放在左下角；env() 给 iPhone 底部横条留出位置 */
@media (max-width: 767px) {
  .sp-packet.is-static {
    top: auto;
    bottom: calc(var(--sp-packet-bottom) + env(safe-area-inset-bottom, 0px));
  }
}

/* 边缘发光：
   1) 红包本体贴边的一圈金色描光（drop-shadow 跟着红包圆角走，不是方框）
   2) 背后一团金红色光晕，慢慢「呼吸」
   想调亮度改 --sp-glow 的透明度，想调光晕大小改 ::before 的 inset */
.sp-root {
  --sp-glow: rgba(255, 196, 77, 0.9);
  --sp-glow-soft: rgba(255, 120, 60, 0.45);
}

.sp-packet::before {
  content: '';
  position: absolute;
  inset: -35% -45%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(
    closest-side,
    var(--sp-glow) 0%,
    var(--sp-glow-soft) 45%,
    transparent 100%
  );
  filter: blur(6px);
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.sp-packet.is-visible::before {
  animation: sp-breathe 2.4s ease-in-out infinite;
}

.sp-packet:hover::before,
.sp-packet:focus-visible::before {
  animation-play-state: paused;
  opacity: 0.95;
}

@keyframes sp-breathe {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 0.85; transform: scale(1.08); }
}

.sp-packet-inner {
  display: block;
  width: 100%;
  height: 100%;
  filter:
    drop-shadow(0 0 2px var(--sp-glow))
    drop-shadow(0 0 7px var(--sp-glow-soft))
    drop-shadow(0 6px 10px rgba(120, 0, 0, 0.35));
  transform-origin: 50% 90%;
  transition: transform 0.2s ease;
}

.sp-packet-inner svg {
  display: block;
  width: 100%;
  height: 100%;
}

.sp-packet:hover .sp-packet-inner,
.sp-packet:focus-visible .sp-packet-inner {
  transform: scale(1.08);
}

.sp-packet:focus-visible {
  outline: 2px solid var(--sp-gold-deep);
  outline-offset: 4px;
  border-radius: 8px;
}

/* 每隔几秒轻轻晃一下，提示可以点 */
.sp-packet.is-visible .sp-packet-inner {
  animation: sp-wiggle 4s ease-in-out 1s infinite;
}

.sp-packet:hover .sp-packet-inner {
  animation-play-state: paused;
}

@keyframes sp-wiggle {
  0%, 82%, 100% { rotate: 0deg; }
  86% { rotate: -9deg; }
  90% { rotate: 8deg; }
  94% { rotate: -5deg; }
  97% { rotate: 3deg; }
}

/* 刚缩小时红包「弹」出来 */
.sp-packet.is-pop .sp-packet-inner {
  animation: sp-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes sp-pop {
  0% { transform: scale(0.4); }
  100% { transform: scale(1); }
}

/* ---------------- 减少动态效果 ----------------
   系统开启时，只保留淡入淡出，去掉位移、缩放、晃动。
   .sp-reduce 由脚本加在 .sp-root 上（预览页也能用它强制模拟） */

.sp-reduce .sp-dialog,
.sp-reduce .sp-overlay.is-open .sp-dialog,
.sp-reduce .sp-overlay.is-shrunk .sp-dialog {
  transform: none;
}

.sp-reduce .sp-packet .sp-packet-inner,
.sp-reduce .sp-packet.is-visible .sp-packet-inner,
.sp-reduce .sp-packet.is-pop .sp-packet-inner {
  animation: none;
}

/* 光晕保留但不呼吸，固定在中等亮度 */
.sp-reduce .sp-packet.is-visible::before {
  animation: none;
  opacity: 0.6;
}

/* 光晕保留、固定在中等亮度，转圈的亮光去掉 */
.sp-reduce .sp-aura::before {
  animation: none;
  opacity: 0.65;
}

.sp-reduce .sp-aura::after,
.sp-reduce .sp-cta::after {
  display: none;
}

.sp-reduce .sp-overlay.is-open .sp-dialog {
  animation: none;
  box-shadow:
    0 0 0 1px rgba(255, 211, 107, 0.75),
    0 0 22px 3px rgba(255, 180, 65, 0.45),
    0 0 54px 9px rgba(232, 56, 47, 0.32),
    0 30px 60px -20px rgba(0, 0, 0, 0.45);
}

.sp-reduce .sp-packet:hover .sp-packet-inner,
.sp-reduce .sp-cta:hover {
  transform: none;
}
