/* ==========================================================
   story.css — Story UI v0.8.1
   跟 battle.css 同一個遊戲的視覺語言（深色底 / 白字 / 少量淡藍線條），
   但刻意不要太科技化 —— Dialogue Box 用銀灰細邊 + 少量淡藍線條，
   不是battle-hud那種戰鬥儀表板風格。
   Base 1280x720 / 16:9，Desktop + Mobile Landscape 為主要支援目標。
   ========================================================== */

#story-root {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh; /* fallback */
  height: 100dvh;
  overflow: hidden;
  background: #000;
  color: #fff;
  font-family: "Segoe UI", "Noto Sans TC", -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

/* ---------- Background ---------- */

#story-background {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-color: #14141c; /* Missing Asset fallback：深色 neutral 背景，不是白屏/破圖 */
  transition: opacity 0.15s ease;
  z-index: 1;
}

/* fade 轉場：opacity 1->0（換圖）->1，兩段各 ~150ms，總長落在 250~400ms 區間 */
#story-background.story-bg-fading {
  opacity: 0;
}

/* ---------- Portrait ---------- */

.story-portrait {
  position: absolute;
  bottom: 0;
  height: 78%; /* 70~85% Story Stage */
  z-index: 2;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.08s ease; /* 換 expression 用短 fade，不是整個閃爍，見 storyUI.js */
}

.story-portrait.story-portrait-fading {
  opacity: 0;
}

.story-portrait-img {
  display: block;
  height: 100%;
  width: auto;
  object-fit: contain; /* Asset Wiring：真實 portrait 素材比例不一定跟舊 placeholder 假設一致，
                           height:100%+width:auto 本身就不會拉伸/裁切，這裡明確加上 object-fit:contain
                           只是讓意圖清楚，不改變任何現有版面行為 */
  -webkit-user-drag: none;
  user-drag: none;
}

.story-portrait-left {
  left: 4%;
}

.story-portrait-right {
  right: 4%;
}

/* ---------- Dialogue Box (~25~30% 高度) ---------- */

#story-dialogue-layer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: clamp(150px, 27%, 240px);
  z-index: 5;
  padding: clamp(14px, 2.4vh, 22px) clamp(20px, 4vw, 40px);
  background: linear-gradient(180deg, #0d0d16dd 0%, #06060bf5 100%);
  border-top: 1px solid #c7d5e2aa; /* 銀灰細邊 */
  box-shadow: 0 -1px 0 #7ecbff33 inset, 0 0 24px #0008;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

#story-speaker-name {
  flex: 0 0 auto;
  align-self: flex-start;
  margin-bottom: 6px;
  padding: 3px 14px;
  border-radius: 4px;
  border: 1px solid #7ecbff88;
  background: #101828cc;
  font-size: clamp(13px, 1.9vh, 17px);
  font-weight: 800;
  letter-spacing: 1px;
  color: #bfe3ff;
}

#story-dialogue-text {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: clamp(16px, 2.6vh, 26px);
  line-height: 1.55;
  white-space: pre-wrap;
}

#story-next-indicator {
  position: absolute;
  right: clamp(16px, 3vw, 30px);
  bottom: clamp(10px, 1.6vh, 16px);
  font-size: clamp(14px, 2vh, 20px);
  color: #bfe3ff;
  animation: storyNextBobAnim 1s ease-in-out infinite;
  pointer-events: none;
}

@keyframes storyNextBobAnim {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(5px); }
}

/* ---------- Choice ---------- */

#story-choice-layer {
  position: absolute;
  right: clamp(16px, 4vw, 60px);
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: clamp(200px, 32vw, 340px);
}

.story-choice-btn {
  min-height: 44px; /* 手機觸控最小高度 */
  padding: 12px 18px;
  border-radius: 8px;
  border: 2px solid #ffffff55;
  background: #12121ecc;
  color: #fff;
  font-size: clamp(14px, 2vh, 17px);
  font-weight: 700;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
}

.story-choice-btn:active {
  background: #262646;
}

/* ---------- Mobile Landscape 極短高度：Dialogue 文字優先，Portrait 可縮小但不裁臉 ---------- */

@media (orientation: landscape) and (max-height: 500px) {
  #story-dialogue-layer {
    height: clamp(110px, 34%, 170px);
    padding: 10px clamp(14px, 3vw, 26px);
  }

  #story-speaker-name {
    font-size: clamp(11px, 1.6dvh, 14px);
    padding: 2px 10px;
    margin-bottom: 3px;
  }

  #story-dialogue-text {
    font-size: clamp(13px, 2.2dvh, 18px);
  }

  .story-portrait {
    height: 62%;
  }

  #story-choice-layer {
    width: clamp(160px, 40vw, 260px);
    gap: 8px;
  }

  .story-choice-btn {
    min-height: 40px;
    font-size: clamp(12px, 1.8dvh, 14px);
    padding: 8px 14px;
  }
}
