/* 緣投回家記：開場、任務景點、回家三段動畫（static/js/story.js） */
#story {
  position: fixed; inset: 0; z-index: 400; display: none; overflow: hidden;
  background: #0b1020; color: #fff; font-family: 'Noto Sans TC', sans-serif;
  -webkit-tap-highlight-color: transparent; cursor: pointer;
}
#story.show { display: block; animation: st-fade .4s ease; }
#story .st-layer { position: absolute; inset: 0; opacity: 0; transition: opacity 1s ease; pointer-events: none; }
#story .st-layer.on { opacity: 1; }
#story .st-layer svg { width: 100%; height: 100%; display: block; }

/* 文字底下的漸層陰影，讓亮色景點上的字看得清楚 */
.st-shade { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(rgba(0,0,0,.38), rgba(0,0,0,0) 32%, rgba(0,0,0,0) 58%, rgba(0,0,0,.5)); }

/* 星空 */
.st-stars { background: radial-gradient(ellipse at 30% 20%, #26306b 0%, #0b1020 60%), #0b1020; }
.st-stars i { position: absolute; width: 2px; height: 2px; border-radius: 50%; background: #fff; animation: st-twinkle 2.4s ease-in-out infinite; }

/* 緣投星 */
.st-planet { position: absolute; left: 50%; bottom: -34vmin; width: 80vmin; height: 80vmin; margin-left: -40vmin; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #b7f0c7 0%, #5fbf86 35%, #2d6b4c 75%, #183a2b 100%);
  box-shadow: 0 0 60px 10px rgba(140, 240, 180, .35), inset -30px -40px 80px rgba(0,0,0,.45); transition: filter 1.6s ease, box-shadow 1.6s ease; }
.st-planet::before, .st-planet::after { content: ''; position: absolute; border-radius: 50%; background: rgba(255,255,255,.12); }
.st-planet::before { width: 14%; height: 9%; left: 22%; top: 22%; }
.st-planet::after { width: 9%; height: 6%; left: 58%; top: 14%; }
.st-planet.glow { filter: brightness(1.25) saturate(1.2); box-shadow: 0 0 120px 40px rgba(245, 213, 142, .55), inset -30px -40px 80px rgba(0,0,0,.35); }

/* 蟲洞 */
.st-hole { position: absolute; left: 50%; top: 30%; width: 46vmin; height: 46vmin; margin: -23vmin 0 0 -23vmin; border-radius: 50%;
  transform: scale(0); transition: transform 1.1s cubic-bezier(.2,1.4,.4,1); pointer-events: none; }
.st-hole.open { transform: scale(1); }
.st-hole.close { transform: scale(0); transition: transform .5s ease-in; }
.st-hole::before { content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: repeating-conic-gradient(from 0deg, #7b5cff 0 12deg, #2bd4ff 12deg 24deg, #1a0f4a 24deg 36deg);
  -webkit-mask: radial-gradient(circle, transparent 0 20%, #000 34%, transparent 70%);
          mask: radial-gradient(circle, transparent 0 20%, #000 34%, transparent 70%);
  animation: st-spin 2.2s linear infinite; }
.st-hole::after { content: ''; position: absolute; inset: 22%; border-radius: 50%;
  background: radial-gradient(circle, #000 0 40%, rgba(60,30,140,.9) 58%, transparent 72%);
  box-shadow: 0 0 60px 20px rgba(120, 90, 255, .55); animation: st-pulse 1.4s ease-in-out infinite; }

/* 穿越隧道 */
.st-tunnel { background: radial-gradient(circle, #000 0 8%, #2a1670 30%, #0b1020 70%); }
.st-tunnel i { position: absolute; left: 50%; top: 50%; width: 2px; height: 22vmin; background: linear-gradient(rgba(255,255,255,0), #9fe6ff, rgba(255,255,255,0));
  transform-origin: 50% 0; animation: st-warp .7s linear infinite; }

/* 緣投 */
.st-mascot { position: absolute; left: 50%; top: 50%; width: 30vmin; height: 30vmin; margin: -15vmin 0 0 -15vmin; object-fit: contain;
  filter: drop-shadow(0 8px 18px rgba(0,0,0,.35)); opacity: 0; transition: opacity .6s ease; pointer-events: none; }
.st-mascot.on { opacity: 1; }
.st-mascot.mv-bob { animation: st-bob 2.2s ease-in-out infinite; }
.st-mascot.mv-wave { animation: st-wave 1s ease-in-out infinite; }
.st-mascot.mv-suck { animation: st-suck 1.8s cubic-bezier(.6,0,.9,.6) forwards; }
.st-mascot.mv-drop { animation: st-drop 1.6s cubic-bezier(.3,0,.4,1) forwards; }
.st-mascot.mv-land { animation: st-land 1.6s cubic-bezier(.3,0,.4,1) forwards; }
.st-mascot.mv-rise { animation: st-rise 2s cubic-bezier(.6,0,.9,.5) forwards; }
.st-mascot.mv-run { animation: st-run 1.4s cubic-bezier(.3,.8,.4,1) forwards, st-hop .45s ease-in-out 1.4s 4; }
.st-mascot.mv-stay { transform: translateY(8vh); }

/* 字幕與對話 */
.st-cap { position: absolute; left: 50%; bottom: 12vh; width: min(560px, calc(100% - 40px)); transform: translate(-50%, 16px); opacity: 0;
  text-align: center; font-family: 'LXGW WenKai TC', 'Noto Serif TC', serif; font-size: clamp(18px, 4.4vw, 26px); line-height: 1.7;
  text-shadow: 0 2px 12px rgba(0,0,0,.7); transition: opacity .7s ease, transform .7s ease; pointer-events: none; }
.st-cap.on { opacity: 1; transform: translate(-50%, 0); }
.st-cap.top { bottom: auto; top: 9vh; }
.st-cap small { display: block; font-family: 'Noto Sans TC', sans-serif; font-size: 14px; opacity: .85; margin-top: 6px; }
.st-bubble { position: absolute; left: 50%; top: calc(58% - 15vmin - 64px); transform: translateX(-50%) scale(.6); opacity: 0; background: #fff; color: #2d4a35;
  border-radius: 18px; padding: 10px 16px; font-family: 'LXGW WenKai TC', serif; font-size: clamp(16px, 4vw, 20px); white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); transition: opacity .4s ease, transform .4s cubic-bezier(.2,1.5,.4,1); pointer-events: none; }
.st-bubble.on { opacity: 1; transform: translateX(-50%) scale(1); }
.st-bubble::after { content: ''; position: absolute; left: 50%; bottom: -7px; width: 14px; height: 14px; background: #fff; transform: translateX(-50%) rotate(45deg); }

/* 任務景點卡 */
.st-place { position: absolute; left: 50%; top: 7vh; width: calc(100% - 32px); transform: translate(-50%, -12px); opacity: 0; text-align: center; transition: opacity .6s ease, transform .6s ease; pointer-events: none; }
.st-place.on { opacity: 1; transform: translate(-50%, 0); }
.st-place .tag { display: inline-block; font-size: 12px; letter-spacing: 3px; padding: 3px 12px; border-radius: 20px; background: rgba(0,0,0,.35); color: #f5d58e; }
.st-place h2 { font-family: 'Noto Serif TC', serif; font-size: clamp(30px, 8vw, 48px); letter-spacing: 6px; margin-top: 8px; text-shadow: 0 3px 16px rgba(0,0,0,.5); }
.st-place .town { font-size: 14px; opacity: .95; text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.st-energy { width: min(320px, 70vw); margin: 12px auto 0; font-size: 12px; letter-spacing: 1px; text-shadow: 0 1px 6px rgba(0,0,0,.6); }
.st-energy b { display: block; height: 10px; border-radius: 6px; background: rgba(255,255,255,.3); margin-top: 4px; overflow: hidden; }
.st-energy b i { display: block; height: 100%; width: 0; border-radius: 6px; background: linear-gradient(90deg, #7b5cff, #2bd4ff); transition: width 1.4s ease .3s; }

/* 按鈕 */
.st-actions { position: absolute; left: 0; right: 0; bottom: 4vh; display: flex; gap: 10px; justify-content: center; opacity: 0; transition: opacity .6s ease; pointer-events: none; }
.st-actions.on { opacity: 1; pointer-events: auto; }
.st-btn { border: 0; border-radius: 999px; padding: 12px 24px; font-size: 15px; font-weight: 700; cursor: pointer; font-family: inherit;
  background: linear-gradient(90deg, #e8c27a, #f5d58e); color: #3a2e12; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.st-skip { position: absolute; right: 16px; top: 16px; z-index: 2; border: 1px solid rgba(255,255,255,.4); background: rgba(0,0,0,.25); color: #fff;
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer; font-family: inherit; }
.st-hint { position: absolute; left: 0; right: 0; bottom: 3vh; text-align: center; font-size: 12px; opacity: .7; pointer-events: none; text-shadow: 0 1px 4px rgba(0,0,0,.6); }
.st-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s ease; }
.st-flash.on { opacity: 1; }

@keyframes st-fade { from { opacity: 0; } }
@keyframes st-twinkle { 0%,100% { opacity: .25; } 50% { opacity: 1; } }
@keyframes st-spin { to { transform: rotate(360deg); } }
@keyframes st-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.08); } }
@keyframes st-warp { from { transform: rotate(var(--r)) translateY(4vmin) scaleY(.2); opacity: 0; } 30% { opacity: 1; } to { transform: rotate(var(--r)) translateY(70vmin) scaleY(1.4); opacity: 0; } }
@keyframes st-bob { 0%,100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-2vmin) rotate(3deg); } }
@keyframes st-wave { 0%,100% { transform: translateY(8vh) rotate(-8deg); } 50% { transform: translateY(7vh) rotate(8deg); } }
@keyframes st-suck { 0% { transform: translate(0, 0) rotate(0) scale(1); } 100% { transform: translate(0, -20vh) rotate(900deg) scale(0); opacity: .2; } }
@keyframes st-drop { 0% { transform: translateY(-40vh) rotate(-540deg) scale(.2); } 70% { transform: translateY(8vh) rotate(0) scale(1); } 85% { transform: translateY(9vh) scale(1.08, .92); } 100% { transform: translateY(8vh) scale(1); } }
@keyframes st-land { 0% { transform: translateY(-50vh) scale(.3) rotate(360deg); } 75% { transform: translateY(calc(50vh - 46vmin - 9vmin)) scale(.62); } 88% { transform: translateY(calc(50vh - 46vmin - 8vmin)) scale(.68, .56); } 100% { transform: translateY(calc(50vh - 46vmin - 9vmin)) scale(.62); } }
@keyframes st-rise { 0% { transform: translateY(8vh) rotate(0) scale(1); } 25% { transform: translateY(10vh) scale(1.1, .9); } 100% { transform: translateY(-20vh) rotate(1080deg) scale(0); opacity: .2; } }
@keyframes st-run { from { transform: translate(-70vw, 2vh); } to { transform: translate(0, 2vh); } }
@keyframes st-hop { 0%,100% { transform: translate(0, 2vh); } 50% { transform: translate(0, -3vh); } }
.st-mission .st-mascot { width: 24vmin; height: 24vmin; margin: -12vmin 0 0 -12vmin; }
.st-mission .st-cap { bottom: 9vh; }

@media (prefers-reduced-motion: reduce) {
  #story *, #story *::before, #story *::after { animation-duration: .01s !important; animation-iteration-count: 1 !important; transition-duration: .2s !important; }
}
