/* 凇语工坊 · 转场遮罩（veil）
   四种：slide 横向刷 / diag 斜切 / arrow 箭头 / blinds 百叶
   用法：Veil.play('slide', () => { /* 遮罩盖满时执行：换页/换内容 */ })
   规则：prefers-reduced-motion 下直接回调，不放动画。 */

.veil {
  position: fixed;
  inset: 0;
  z-index: 9998;
  pointer-events: none;
  overflow: hidden;
}

.veil-layer,
.veil-bar {
  position: absolute;
  inset: 0;
  will-change: transform, clip-path;
}

/* 第一层用蛋黄、第二层用深棕：浅色先出，深色后出、先撤，露出浅色再撤 */
.veil-layer.v1 { background: var(--blue, #f5b301); }
.veil-layer.v2 { background: var(--text, #3a3226); }

/* ---------- 横向刷 ---------- */
@keyframes veilSlideIn  { from { transform: translateX(-101%); } to { transform: translateX(0); } }
@keyframes veilSlideOut { from { transform: translateX(0); }     to { transform: translateX(101%); } }

.veil-slide .v1 {
  animation: veilSlideIn .52s cubic-bezier(.87,.05,.02,.97) both,
             veilSlideOut .52s cubic-bezier(.87,.05,.02,.97) forwards;
  animation-delay: 0s, .72s;
}
.veil-slide .v2 {
  animation: veilSlideIn .52s cubic-bezier(.87,.05,.02,.97) both,
             veilSlideOut .52s cubic-bezier(.87,.05,.02,.97) forwards;
  animation-delay: .09s, .63s;
}

/* ---------- 斜切揭幕 ---------- */
@keyframes veilDiagIn {
  from { clip-path: polygon(0 0, 0 0, 0 100%, -14% 100%); }
  to   { clip-path: polygon(0 0, 114% 0, 100% 100%, -14% 100%); }
}
@keyframes veilDiagOut {
  from { clip-path: polygon(0 0, 114% 0, 100% 100%, -14% 100%); }
  to   { clip-path: polygon(114% 0, 114% 0, 114% 100%, 114% 100%); }
}

.veil-diag .v1 {
  animation: veilDiagIn .52s cubic-bezier(.87,.05,.02,.97) both,
             veilDiagOut .52s cubic-bezier(.87,.05,.02,.97) forwards;
  animation-delay: 0s, .72s;
}
.veil-diag .v2 {
  animation: veilDiagIn .52s cubic-bezier(.87,.05,.02,.97) both,
             veilDiagOut .52s cubic-bezier(.87,.05,.02,.97) forwards;
  animation-delay: .09s, .63s;
}

/* ---------- 箭头形 ---------- */
@keyframes veilArrowIn {
  from { clip-path: polygon(-20% 0, -20% 0, -9% 50%, -20% 100%, -20% 100%, -9% 50%); }
  to   { clip-path: polygon(-20% 0, 100% 0, 111% 50%, 100% 100%, -20% 100%, -9% 50%); }
}
@keyframes veilArrowOut {
  from { clip-path: polygon(-20% 0, 100% 0, 111% 50%, 100% 100%, -20% 100%, -9% 50%); }
  to   { clip-path: polygon(100% 0, 100% 0, 111% 50%, 100% 100%, 100% 100%, 111% 50%); }
}

.veil-arrow .v1 {
  animation: veilArrowIn .52s cubic-bezier(.87,.05,.02,.97) both,
             veilArrowOut .52s cubic-bezier(.87,.05,.02,.97) forwards;
  animation-delay: 0s, .72s;
}
.veil-arrow .v2 {
  animation: veilArrowIn .52s cubic-bezier(.87,.05,.02,.97) both,
             veilArrowOut .52s cubic-bezier(.87,.05,.02,.97) forwards;
  animation-delay: .09s, .63s;
}

/* ---------- 光圈：从点击的位置扩散 ---------- */
@keyframes veilCircleIn {
  from { clip-path: circle(0% at var(--vx, 50%) var(--vy, 50%)); }
  to   { clip-path: circle(150% at var(--vx, 50%) var(--vy, 50%)); }
}

.veil-circle .v1 { animation: veilCircleIn .56s cubic-bezier(.4, 0, .2, 1) both; }
.veil-circle .v2 { animation: veilCircleIn .56s cubic-bezier(.4, 0, .2, 1) .08s both; }

/* ---------- 百叶：五条纵向，错开落 ---------- */
@keyframes veilBarIn  { from { transform: translateY(-101%); } to { transform: translateY(0); } }
@keyframes veilBarOut { from { transform: translateY(0); }     to { transform: translateY(101%); } }

.veil-blinds .veil-bar {
  inset: auto 0 auto 0;
  height: 20%;
  top: calc((var(--i) - 1) * 20%);
  background: var(--blue, #f5b301);
  animation: veilBarIn .46s cubic-bezier(.87,.05,.02,.97) both,
             veilBarOut .46s cubic-bezier(.87,.05,.02,.97) forwards;
  animation-delay: calc((var(--i) - 1) * .05s),
                   calc(.56s + (var(--i) - 1) * .05s);
}
.veil-blinds .veil-bar:nth-child(even) { background: var(--text, #3a3226); }

@media (prefers-reduced-motion: reduce) {
  .veil { display: none !important; }
}
