/* ============================================================
   一帛入梦 · 二级页「单屏四拍」入场 focus-intro.css
   纯 HTML/CSS：一个独立 sticky 场景 + view-timeline，无 JS。
   完整 T 形帛画轻微开幕 → 推近本境、周围压暗而该部位保持明亮
   并停留可读 → 帛画淡出，接原故事首段。
   滚动距离约一个屏高；四拍 20 / 30 / 25 / 25。
   焦点坐标复用 story.html 已核对的 1080×1681 像素，转成百分比。
   ============================================================ */

.focus-intro {
  position: relative;
  height: 240svh;
  view-timeline-name: --fi;
  view-timeline-axis: block;
  background-color: #061c23;
  /* 聚焦时焦点在视口的纵向位置（无单位比例，默认 .5 屏幕中心）；本境标示位置 */
  --ty: .5;
  --label-top: 80%;
}

.paper-story {
  --static-scenery: url("../assets/backgrounds/encounter-lakeshore.webp");
}

.fi-sticky {
  position: sticky;
  top: 0;
  height: 100svh;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(rgb(6 21 24 / 24%), rgb(6 21 24 / 38%)),
    var(--static-scenery) center / cover no-repeat;
}

/* 极淡的底纹，让深色场景不发闷 */
.fi-sticky::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 42%, rgba(97, 120, 115, .12), transparent 62%);
}

/* 原点固定在屏幕中心，frame 在此基础上做居中与聚焦变换 */
.fi-anchor {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
}

.fi-frame {
  position: relative;
  width: min(90vw, 50svh, 380px);
  aspect-ratio: 1080 / 1681;
  will-change: transform, opacity;
  /* 以 frame 左上角（即屏幕中心 anchor 点）为变换原点，数学最稳 */
  transform-origin: 0 0;
  /* 焦点在 frame 内的位置（百分比）与推近倍数，由各境覆盖 */

}

.fi-map {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

/* 坐标相对于完整 WebP（含透明边），亮区随画面缩放。 */
.focus-intro[data-realm="encounter"] { --fx: 49%; --fy: 53%; --rx: 15%; --ry: 6%; --S: 2.35; }
.focus-intro[data-realm="human"] { --fx: 50%; --fy: 80.8%; --rx: 14%; --ry: 3.8%; --S: 2.5; }
.focus-intro[data-realm="underworld"] { --fx: 50%; --fy: 88%; --rx: 13%; --ry: 5%; --S: 2.35; }
.focus-intro[data-realm="gate"] { --fx: 50%; --fy: 30%; --rx: 19%; --ry: 5.5%; --S: 2; }
.focus-intro[data-realm="heaven"] { --fx: 50%; --fy: 7.2%; --rx: 34%; --ry: 8%; --S: 1.24; }
.fi-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse var(--rx) var(--ry) at var(--fx) var(--fy),
    transparent 70%, rgb(2 13 17 / 74%) 135%);
  /* T 形轮廓裁切，直接打开本地 HTML 时也可显示。 */
  clip-path: polygon(13.7% 0, 87.7% 0, 87.7% 34%, 69.45% 34%,
    69.45% 99.5%, 30.4% 99.5%, 30.4% 34%, 13.7% 34%);
  opacity: .86;
}
/* ---------- 本境标示：聚焦停留时显示，位于焦点下方 ---------- */
.fi-label {
  position: absolute;
  left: 50%;
  top: var(--label-top);
  z-index: 4;
  width: 88%;
  margin: 0;
  text-align: center;
  opacity: 0;
  will-change: opacity, transform;
}
.fi-kicker {
  display: block;
  margin-bottom: 8px;
  font-family: Arial, "PingFang SC", sans-serif;
  font-size: 11px;
  letter-spacing: .34em;
  color: #c3a978;
}
.fi-name {
  margin: 0;
  font-family: Painting, "Songti SC", serif;
  font-weight: 400;
  font-size: clamp(34px, 9vw, 46px);
  letter-spacing: .22em;
  color: #ecd9b2;
  text-shadow: 0 2px 16px rgba(2, 12, 16, .9);
}

/* ============================================================
   滚动驱动：四拍 20 / 30 / 25 / 25
   0–20 完整开幕；20–50 推近压暗；50–75 聚焦停留；75–100 淡出
   ============================================================ */
@supports (animation-timeline: view()) {
  .fi-frame {
    animation: fi-frame linear both;
    animation-timeline: --fi;
    animation-range: contain 0% contain 100%;
  }
  .fi-frame::after {
    animation: fi-veil linear both;
    animation-timeline: --fi;
    animation-range: contain 0% contain 100%;
  }
  .fi-label {
    animation: fi-label linear both;
    animation-timeline: --fi;
    animation-range: contain 0% contain 100%;
  }
}

@keyframes fi-frame {
  /* 完整态：frame 居中（参考点 50%/50% 对齐屏幕中心） */
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(.9);
  }
  28%, 43% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  /* 聚焦态：frame 内焦点 (fx,fy) 对齐屏幕 (50%, --ty) */
  69%, 87% {
    opacity: 1;
    transform:
      translate(
        calc(-1 * var(--S) * var(--fx)),
        calc(-1 * var(--S) * var(--fy) + (var(--ty) - .5) * 100vh)
      )
      scale(var(--S));
  }
  100% {
    opacity: 0;
    transform:
      translate(
        calc(-1 * var(--S) * var(--fx)),
        calc(-1 * var(--S) * var(--fy) + (var(--ty) - .5) * 100vh)
      )
      scale(var(--S));
  }
}

@keyframes fi-veil {
  0%, 43% { opacity: 0; }
  69%, 87% { opacity: 1; }
  100% { opacity: 0; }
}

@keyframes fi-label {
  0%, 61% { opacity: 0; transform: translate(-50%, 14px); }
  69%, 86% { opacity: 1; transform: translate(-50%, 0); }
  98%, 100% { opacity: 0; transform: translate(-50%, -10px); }
}

/* ============================================================
   平板 / 桌面：帛画更大，标示更稳
   ============================================================ */
@media (min-width: 700px) {
  .fi-frame { width: min(52vw, 50svh, 460px); }
  .focus-intro { --label-top: 82%; }
  .fi-name { font-size: clamp(40px, 5vw, 58px); }
}
@media (min-width: 1024px) {
  .fi-frame { width: min(34vw, 50svh, 480px); }
  .focus-intro { --label-top: 84%; }
}

/* ============================================================
   reduced-motion / 不支持 view-timeline：
   静态完整帛画 + 本境标示，正常接下文
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .focus-intro { height: auto; view-timeline-name: none; }
  .fi-sticky {
    position: static;
    height: auto;
    min-height: 0;
    padding: 72px 0 56px;
  }
  .fi-anchor {
    position: static;
    left: auto; top: auto;
  }
  .fi-frame {
    width: min(78vw, 420px);
    margin: 0 auto;
    opacity: 1;
    animation: none;
    transform: none;
  }
  .fi-veil {
    opacity: .18;
    animation: none;
  }
  .fi-label {
    position: static;
    left: auto; top: auto;
    width: auto;
    margin-top: 26px;
    opacity: 1;
    animation: none;
    transform: none;
  }
}

@supports not (animation-timeline: view()) {
  .focus-intro { height: auto; }
  .fi-sticky {
    position: static;
    height: auto;
    min-height: 0;
    padding: 72px 0 56px;
  }
  .fi-anchor { position: static; left: auto; top: auto; }
  .fi-frame {
    width: min(78vw, 420px);
    margin: 0 auto;
    opacity: 1;
    transform: none;
  }
  .fi-veil { opacity: .18; }
  .fi-label {
    position: static;
    left: auto; top: auto;
    width: auto;
    margin-top: 26px;
    opacity: 1;
    transform: none;
  }
}

/* 两层项目内的透明云纹以不同速度散开，中间留出全画停留段。 */
@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    .fi-clouds { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
    .fi-clouds::before, .fi-clouds::after {
      content: ""; position: absolute; inset: -15%;
      background: url("../assets/mobile/cloud-back.webp") center / contain no-repeat;
      animation: fi-cloud-drift linear both;
      animation-timeline: --fi;
      animation-range: contain 0% contain 30%;
      --start: -16%; --end: -49%; --strength: .57;
    }
    .fi-clouds::after {
      background-image: url("../assets/fh_part8_yun02-BQu_L6bM.webp");
      --start: 19%; --end: 56%; --strength: .38;
      animation-range: contain 0% contain 24%;
    }
  }
}
@keyframes fi-cloud-drift {
  from { transform: translate(var(--start), 3%) scale(1.09); opacity: var(--strength); }
  to { transform: translate(var(--end), -9%) scale(1.17); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .fi-frame::after { animation: none; opacity: .86; }
}
