/* 四人の刃 — 兩集動畫 Demo。分鏡、字幕、章節卡全部以現有遊戲畫作演出。 */
:root {
  --ink: #e9dfc4;
  --muted: #9aa79b;
  --gold: #caa96a;
  --paper: #0c1213;
  --ease-film: cubic-bezier(0.2, 0.7, 0.2, 1);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(circle at 50% -10%, #17242a, #080d0e 60%);
  color: var(--ink);
  font: 15px/1.7 Georgia, "Noto Serif CJK TC", serif;
  min-height: 100vh;
}
header {
  display: flex; align-items: center; gap: 22px;
  padding: 14px clamp(16px, 4vw, 46px);
  border-bottom: 1px solid #22343630;
}
.wordmark { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.wordmark .seal {
  display: grid; place-items: center; width: 38px; height: 38px;
  background: #35150f; color: #f2e3c0; font-weight: 700; font-size: 19px;
  border: 1px solid #caa96a66;
}
.wordmark span:last-child { display: flex; flex-direction: column; line-height: 1.2; letter-spacing: 0.18em; font-size: 13px; }
.wordmark small { color: var(--muted); font-size: 10px; letter-spacing: 0.3em; }
.episode-tabs { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.episode-tab {
  background: none; border: 1px solid #3a4a44; color: var(--muted);
  padding: 8px 14px; cursor: pointer; letter-spacing: 0.08em; font: 13px Georgia, serif;
  transition: color 0.3s, border-color 0.3s;
}
.episode-tab:hover { color: var(--ink); }
.episode-tab.current { color: #f4e9cd; border-color: var(--gold); background: #caa96a14; }
#back { color: var(--muted); text-decoration: none; letter-spacing: 0.12em; font-size: 12px; }
#back:hover { color: var(--ink); }

main { max-width: 1180px; margin: 0 auto; padding: 22px clamp(14px, 3vw, 36px) 60px; }
.editorial { display: flex; align-items: baseline; gap: 18px; flex-wrap: wrap; margin-bottom: 14px; }
.editorial #episode-label { margin: 0; color: var(--gold); letter-spacing: 0.24em; font-size: 12px; }
.editorial .synopsis { margin: 0; color: var(--muted); font-size: 12px; letter-spacing: 0.06em; }

/* ── 分鏡舞台 ─────────────────────────────── */
.stage {
  position: relative; aspect-ratio: 16/9; overflow: hidden;
  background: #060a0b; border: 1px solid #2c3d3a; border-radius: 10px;
  container-type: size; cursor: pointer;
}
.camera { position: absolute; inset: 0; }
.backdrop {
  position: absolute; inset: -6%; width: 112%; height: 112%; object-fit: cover;
  filter: saturate(0.92) contrast(1.05) brightness(0.9);
}
.camera[data-camera="pan-in"] .backdrop, .camera[data-camera="in"] .backdrop { animation: ken-in 100s var(--ease-film) both; }
.camera[data-camera="pan-in-slow"] .backdrop, .camera[data-camera="in-slow"] .backdrop { animation: ken-slow 120s var(--ease-film) both; }
.camera[data-camera="pan-left"] .backdrop, .camera[data-camera="left"] .backdrop { animation: ken-left 100s var(--ease-film) both; }
.camera[data-camera="pan-right"] .backdrop, .camera[data-camera="right"] .backdrop { animation: ken-right 100s var(--ease-film) both; }
.camera[data-camera="pan-out"] .backdrop, .camera[data-camera="out"] .backdrop { animation: ken-out 100s var(--ease-film) both; }
.camera[data-camera="push"] .backdrop { animation: ken-in 70s var(--ease-film) both; }
@keyframes ken-in { from { transform: scale(1.02); } to { transform: scale(1.16); } }
@keyframes ken-slow { from { transform: scale(1.14) translateX(1.5%); } to { transform: scale(1.16) translateX(-1.5%); } }
@keyframes ken-left { from { transform: scale(1.12) translateX(3%); } to { transform: scale(1.12) translateX(-3%); } }
@keyframes ken-right { from { transform: scale(1.12) translateX(-3%); } to { transform: scale(1.12) translateX(3%); } }
@keyframes ken-out { from { transform: scale(1.18); } to { transform: scale(1.03); } }

.mist {
  position: absolute; inset: 0; pointer-events: none; opacity: 0.5;
  background:
    radial-gradient(ellipse at 20% 80%, #cfe3d810, transparent 55%),
    radial-gradient(ellipse at 80% 30%, #caa96a0a, transparent 50%);
}
.vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 52%, #000a 100%);
}
.letterbox { position: absolute; left: 0; right: 0; height: 7%; background: #040707; z-index: 5; }
.letterbox.top { top: 0; } .letterbox.bottom { bottom: 0; }

/* 演員進場 */
.cast { position: absolute; inset: 0; z-index: 2; }
.stage[data-shot="closeup"] .cast, .stage[data-shot="duel"] .cast,
.stage[data-shot="fight"] .cast, .stage[data-shot="frame"] .cast { visibility: hidden; }

/* 圖像包 keyframe：手繪整幀直接做鏡頭（2560×1440 = 舞台比例），
 * 基礎幀切換時輕微推近（drift），講嘢/眨眼變體只換 src 唔重啟。 */
.keyframe {
  position: absolute; inset: 0; z-index: 3;
  width: 100%; height: 100%; object-fit: cover;
  filter: saturate(1.02) contrast(1.03);
}
.keyframe.drift { animation: kf-drift 13s ease-out both; }
@keyframes kf-drift { from { scale: 1.001; } to { scale: 1.045; } }
.actor {
  position: absolute; bottom: 10%; height: 58%;
  filter: drop-shadow(0 14px 12px #000b);
  transform: scale(var(--scale, 1));
  animation: actor-in 2.4s var(--ease-film) both;
}
@keyframes actor-in {
  from { opacity: 0; translate: 0 4cqh; filter: drop-shadow(0 14px 12px #000b) blur(3px); }
  to { opacity: 1; translate: 0 0; filter: drop-shadow(0 14px 12px #000b) blur(0); }
}
.side-far-left { left: 6%; }
.side-left { left: 16%; }
.side-center { left: 42%; }
.side-right { right: 16%; }
.side-far-right { right: 6%; }

/* 大頭鏡：動作 asset 裁切（唔一定要成個人） */
.closeup {
  position: absolute; inset: 0; z-index: 4; margin: 0;
  background: radial-gradient(ellipse at 50% 38%, #101c1cd8, #05090af2 82%);
  overflow: hidden;
  --face-y: 13%; --head-x: 50%;   /* JS 用 canvas 實測錨點覆寫 */
}
/* 研究結論：講嘢鏡頭塊面填滿畫面、眼喺上面三分一。
 * 做法：張圖絕對定位，用 translate(-var(--head-x), -var(--face-y)) 將「眼線」
 * 呢一點釘死喺 top 34% / left 50%（上三分一線）——唔靠置中，所以無論邊種
 * 畫種、放幾大，個頭一定喺畫面入面。height 百分比只負責 zoom。 */
.closeup img {
  position: absolute; top: 34%; left: 50%;
  max-width: none; object-fit: cover;
  filter: drop-shadow(0 0 42px #000c) contrast(1.06);
  translate: calc(-1 * var(--head-x)) calc(-1 * var(--face-y));
}
/* 裁切級別 × 畫種：height 由驅動按 CROP_ZOOM 指定（head 420% ≈ 面部填滿）。 */
.closeup[data-crop="head"] img { height: 420%; }
.closeup[data-crop="face"] img { height: 300%; }
.closeup[data-crop="bust"] img { height: 190%; }
.closeup[data-kind="wide"][data-crop="head"] img { height: 360%; }
.closeup[data-kind="wide"][data-crop="face"] img { height: 260%; }
.closeup[data-kind="wide"][data-crop="bust"] img { height: 170%; }
.closeup[data-crop="head"] img.duel-pose { height: 440%; }
.closeup[data-crop="face"] img.duel-pose { height: 310%; }

/* 180 度軸線：left 機位個頭靠左望右（右邊留白），right 機位相反。 */
.closeup[data-side="left"] img { translate: calc(-1 * var(--head-x) - 11cqw) calc(-1 * var(--face-y)); }
.closeup[data-side="right"] img { translate: calc(-1 * var(--head-x) + 11cqw) calc(-1 * var(--face-y)); }
.closeup[data-side="right"] .plate { left: auto; right: 7%; border-right: 0; border-left: 3px solid var(--gold); padding: 0 0 0 12px; }

/* 對白大頭要「生」：微微呼吸同視線漂移。 */
.closeup img { animation: closeup-breath 4.2s ease-in-out infinite alternate; }
@keyframes closeup-breath { from { margin-top: 0; } to { margin-top: 0.7cqh; } }
.closeup .shade {
  position: absolute; inset: 0;
  background: linear-gradient(100deg, #05090ae6 0 30%, transparent 62%),
              radial-gradient(circle at 78% 34%, transparent 30%, #05090ab0 72%);
}
.closeup .plate {
  position: absolute; left: 7%; top: 18%;
  writing-mode: vertical-rl; letter-spacing: 0.4em;
  font: 700 clamp(15px, 3cqw, 30px) Georgia, "Noto Serif CJK TC", serif;
  color: #f4e9cd; text-shadow: 0 3px 18px #000;
  border-right: 3px solid var(--gold); padding-right: 12px;
}
.closeup.cut { animation: cut-dip 0.32s steps(2) both; }

/* 對峙機位：雙人 + 速度線 + 出招特效 */
.duel-stage { position: absolute; inset: 0; z-index: 4; }
.duel-stage img {
  position: absolute; bottom: 9%; height: 74%; max-width: none;
  object-fit: contain; filter: drop-shadow(0 16px 14px #000c);
}
.duel-stage img.hero { left: 10%; }
.duel-stage img.rival { right: 10%; transform: scaleX(-1); }
.duel-stage img { transition: translate 0.65s var(--ease-film), filter 0.4s ease; }

/* ── 決戰七拍 ─────────────────────────────── */
/* 1 對峙：定格企位，輕輕呼吸；落花飄下做觸發。 */
.duel-stage[data-phase="standoff"] img { animation: idle-bob 3.2s ease-in-out infinite alternate; }
.duel-stage[data-phase="standoff"] .petal { display: block; }
.petal {
  display: none; position: absolute; left: 49%; top: -3%;
  width: 7px; height: 5px; border-radius: 60% 40% 55% 45%;
  background: #e8b4c4; box-shadow: 0 0 6px #e8b4c488;
  animation: petal-fall 4.6s ease-in both;
}
@keyframes petal-fall {
  0% { translate: 0 0; rotate: 0deg; opacity: 0; }
  12% { opacity: 0.9; }
  100% { translate: 4cqw 62cqh; rotate: 220deg; opacity: 0; }
}
@keyframes idle-bob { from { margin-top: 0; } to { margin-top: 0.8cqh; } }

/* 2 蓄勢：鏡頭推近，雙方下蹲蓄力（windup 招式由驅動換上）。 */
.duel-stage[data-phase="windup"] { animation: fight-zoom-in 2s ease-out both; }
.duel-stage[data-phase="windup"] img { translate: 0 2cqh; filter: brightness(1.06); }

/* 3 突進：衝向中線，動感模糊＋速度線全開，荷蘭角。 */
.duel-stage[data-phase="charge"] { rotate: -1.6deg; }
.duel-stage[data-phase="charge"] img.hero { translate: 24cqw 0; filter: blur(2.5px); transition-duration: 0.55s; transition-timing-function: cubic-bezier(0.6, 0, 0.9, 0.4); }
.duel-stage[data-phase="charge"] img.rival { translate: -24cqw 0; filter: blur(2.5px); transition-duration: 0.55s; transition-timing-function: cubic-bezier(0.6, 0, 0.9, 0.4); }
.duel-stage[data-phase="charge"] .speed-lines { opacity: 0.95; }

/* 4 交鋒：衝擊格（黑幕白刃）＋定格＋震屏。 */
.duel-stage[data-phase="impact"] img { filter: brightness(2.2) contrast(1.4); }
.duel-stage.quake { animation: cam-quake 0.42s linear both; }
@keyframes cam-quake {
  0%, 100% { translate: 0 0; }
  20% { translate: -0.9cqw 0.5cqh; } 40% { translate: 0.8cqw -0.4cqh; }
  60% { translate: -0.5cqw 0.3cqh; } 80% { translate: 0.3cqw -0.2cqh; }
}
.impact-frame {
  position: absolute; inset: 0; opacity: 0; pointer-events: none; z-index: 6;
  background: #040707;
}
.impact-frame::before {
  content: ""; position: absolute; left: -12%; right: -12%; top: 48%; height: 5px;
  background: linear-gradient(90deg, transparent, #fff 20%, var(--gold) 50%, #fff 80%, transparent);
  rotate: -11deg; scale: 0 1;
}
.impact-frame::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-conic-gradient(from 100deg at 50% 50%, #fff0 0 8deg, #ffffffcc 8deg 9.2deg, #fff0 9.2deg 16deg);
  -webkit-mask: radial-gradient(circle, transparent 34%, #000 80%);
  mask: radial-gradient(circle, transparent 34%, #000 80%);
  opacity: 0;
}
.impact-frame.boom { animation: impact-boom 0.42s steps(1) both; }
@keyframes impact-boom {
  0% { opacity: 1; } 22% { opacity: 0; } 38% { opacity: 1; } 100% { opacity: 0; }
}
.impact-frame.boom::before { animation: impact-streak 0.42s ease-out both; }
@keyframes impact-streak { 0% { scale: 0 1; } 30% { scale: 1 1; } 100% { scale: 1 0.4; opacity: 0; } }

/* 5 擦身：換位衝過（motion blur 拖影）。 */
.duel-stage[data-phase="pass"] img.hero { translate: 82cqw 0; filter: blur(7px); transition-duration: 0.9s; transition-timing-function: cubic-bezier(0.7, 0, 0.2, 1); }
.duel-stage[data-phase="pass"] img.rival { translate: -82cqw 0; filter: blur(7px); transition-duration: 0.9s; transition-timing-function: cubic-bezier(0.7, 0, 0.2, 1); }

/* 6 靜止：背對背定格（換位完成），塵埃落定，慢推近。 */
.duel-stage[data-phase="hold"] img.hero { translate: 58cqw 0; filter: blur(0); }
.duel-stage[data-phase="hold"] img.rival { translate: -58cqw 0; filter: blur(0); }
.duel-stage[data-phase="hold"] { animation: fight-zoom-in 3.4s ease-out both; }
.duel-stage[data-phase="hold"] .speed-lines { opacity: 0; }

/* 7 分勝：敗者傷口浮現（刀痕亮線）——踉蹌、傾側、倒下；勝者持式而立。 */
.duel-stage[data-phase="aftermath"] img { filter: blur(0); }
.duel-stage[data-phase="aftermath"] .plate { opacity: 1; }
.duel-stage[data-phase="aftermath"][data-winner="hero"] img.rival { animation: loser-fall-rival 2.6s ease-in both; }
.duel-stage[data-phase="aftermath"][data-winner="rival"] img.hero { animation: loser-fall 2.6s ease-in both; }
.duel-stage[data-phase="aftermath"][data-winner="hero"] img.hero,
.duel-stage[data-phase="aftermath"][data-winner="rival"] img.rival {
  animation: winner-settle 2.2s ease-out both;
}
@keyframes loser-fall {
  0% { translate: 58cqw 0; rotate: 0deg; opacity: 1; }
  30% { rotate: -4deg; }
  60% { translate: 54cqw 6cqh; rotate: 9deg; opacity: 0.85; }
  100% { translate: 52cqw 14cqh; rotate: 24deg; opacity: 0.12; }
}
@keyframes loser-fall-rival {
  0% { translate: -58cqw 0; rotate: 0deg; opacity: 1; }
  100% { translate: -52cqw 14cqh; rotate: -24deg; opacity: 0.12; }
}
@keyframes winner-settle { 0% { filter: brightness(1.5); } 100% { filter: brightness(1); } }
.duel-stage[data-phase="aftermath"] img.wound::after { content: ""; }
@keyframes fight-zoom-in { from { scale: 1; } to { scale: 1.1; } }

/* After pass and hold, fighters have swapped sides:
   Hero crossed to screen-right (+58cqw), Rival crossed to screen-left (-58cqw).
   In aftermath, winner holds their crossed position; loser plays their fall animation. */
.duel-stage[data-phase="aftermath"] img.hero { translate: 58cqw 0; }
.duel-stage[data-phase="aftermath"] img.rival { translate: -58cqw 0; }
.duel-stage .plate {
  position: absolute; top: 11%; font: 700 clamp(12px, 2cqw, 20px) Georgia, "Noto Serif CJK TC", serif;
  letter-spacing: 0.3em; color: #f2e6c8; text-shadow: 0 2px 10px #000; z-index: 6;
  border-bottom: 2px solid var(--gold); padding: 2px 8px;
}
.duel-stage .plate.hero { left: 8%; }
.duel-stage .plate.rival { right: 8%; }
.duel-stage .speed-lines {
  position: absolute; inset: 0; opacity: 0.5; pointer-events: none;
  background: repeating-conic-gradient(from 0deg at 50% 62%, #fff0 0 3.4deg, #ffffff26 3.4deg 3.8deg);
  -webkit-mask: radial-gradient(circle at 50% 62%, transparent 26%, #000 68%);
  mask: radial-gradient(circle at 50% 62%, transparent 26%, #000 68%);
}
.duel-stage .fx { position: absolute; inset: 0; pointer-events: none; }
.duel-stage .fx.slash {
  left: -10%; right: -10%; top: 46%; height: 4px; opacity: 0;
  background: linear-gradient(90deg, transparent, #fff 18%, var(--gold) 50%, #fff 82%, transparent);
  animation: fx-slash 0.6s ease-out 0.35s both;
}
.duel-stage .fx.flash { inset: 0; opacity: 0; background: radial-gradient(circle at 50% 55%, #fffbe8, #caa96a55 34%, transparent 72%); animation: fx-flash 0.7s ease-out 0.35s both; }
@keyframes duel-lunge-hero { 0%, 20% { translate: 0 0; } 55% { translate: 26% 0; } 100% { translate: 20% 0; } }
@keyframes duel-lunge-rival { 0%, 20% { translate: 0 0; } 55% { translate: -14% 0; } 100% { translate: -8% 0; } }
@keyframes fx-slash { 0% { opacity: 0; transform: rotate(-9deg) scaleX(0); } 35% { opacity: 1; } 100% { opacity: 0; transform: rotate(-9deg) scaleX(1); } }
@keyframes fx-flash { 0% { opacity: 0; } 30% { opacity: 0.95; } 100% { opacity: 0; } }
@keyframes cut-dip { 0% { opacity: 0; } 55% { opacity: 1; } 100% { opacity: 1; } }

/* 章節卡 */
.chapter-card {
  position: absolute; z-index: 6; inset: 0; margin: 0; padding: 0 8%;
  display: grid; place-content: center; text-align: center;
  background: #05090ab8; color: #f2e6c8;
  font-size: clamp(18px, 4.6cqw, 44px); letter-spacing: 0.5em; text-indent: 0.5em;
  opacity: 0; pointer-events: none; transition: opacity 0.9s ease;
  text-shadow: 0 4px 26px #000;
}
.chapter-card.shown { opacity: 1; }

/* 旁白/對白字幕（底部定點平滑淡入淡出） */
.beats {
  position: absolute; z-index: 7; left: 8%; right: 8%; bottom: 9%;
  height: 3.5em; pointer-events: none;
}
.beat {
  position: absolute; left: 0; right: 0; bottom: 0;
  margin: 0; opacity: 0; translate: 0 8px; pointer-events: none;
  transition: opacity 0.6s ease, translate 0.6s var(--ease-film);
  font-size: clamp(12px, 2.3cqw, 22px);
  text-shadow: 0 2px 8px #000, 0 0 22px #0008;
  color: #f3ecd8;
}
.beat.shown { opacity: 1; translate: 0 0; }
.beat .who { color: var(--gold); letter-spacing: 0.08em; }
.film-meta {
  position: absolute; z-index: 8; top: 8.4%; left: 3%; right: 3%;
  display: flex; justify-content: space-between; color: #d8caa899;
  font-size: 10px; letter-spacing: 0.3em;
}

/* ── 控制列 ─────────────────────────────── */
.transport {
  display: flex; align-items: center; gap: 14px; margin-top: 14px; flex-wrap: wrap;
}
button { font: 13px Georgia, serif; letter-spacing: 0.1em; }
.transport .primary, #speed {
  background: #1c2a28; color: var(--ink); border: 1px solid #3c4f47;
  padding: 10px 18px; cursor: pointer; transition: background 0.3s;
}
.transport .primary:hover, #speed:hover { background: #24352f; }
#speed.fast { color: #ffd98c; border-color: #caa96a; }
.track {
  flex: 1; min-width: 200px; height: 8px; background: #17221f; border: 1px solid #2c3a34;
  cursor: pointer; position: relative;
}
#progress {
  position: absolute; inset: 0 auto 0 0; width: 0;
  background: linear-gradient(90deg, #8a6f3c, var(--gold));
}
#timer { color: var(--muted); font-size: 12px; letter-spacing: 0.14em; }

/* ── 章節表 + 腳本 ───────────────────────── */
.below { margin-top: 26px; }
.below h2 { color: #f0e5c8; letter-spacing: 0.3em; font-size: 17px; margin: 0 0 12px; }
.chapters { display: flex; flex-wrap: wrap; gap: 8px; }
.chapters button {
  background: none; border: 1px solid #2f3f39; color: var(--muted);
  padding: 7px 11px; cursor: pointer; font-size: 12px; letter-spacing: 0.06em;
  transition: color 0.25s, border-color 0.25s;
}
.chapters button:hover { color: var(--ink); }
.chapters button.current { color: #ffe6ad; border-color: var(--gold); background: #caa96a12; }
details { margin-top: 18px; }
summary { cursor: pointer; color: var(--gold); letter-spacing: 0.2em; font-size: 12px; }
.transcript { color: #c9c2ac; font-size: 13px; white-space: pre-wrap; }
footer {
  display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  padding: 16px clamp(16px, 4vw, 46px); border-top: 1px solid #22343630;
  color: #7d8d84; font-size: 11px; letter-spacing: 0.24em;
}
@media (max-width: 720px) {
  .episode-tabs { order: 3; width: 100%; }
  .beat { font-size: 14px; }
  .actor { height: 46%; }
}

@media (prefers-reduced-motion: reduce) {
  .backdrop, .actor, .closeup img, .duel-stage, .duel-stage img, .impact-frame, .fx, .speed-lines, .petal, .beat {
    animation: none !important;
    transition: none !important;
  }
}
