/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Noto Serif TC', 'Georgia', serif;
  background: #000;
  color: #f5e6c8;
}

/* ── 橫屏提示（手機直屏時顯示）── */
#rotate-prompt {
  display: none;
  position: fixed; inset: 0; z-index: 9999;
  background: #111;
  flex-direction: column;
  align-items: center; justify-content: center;
  font-size: 1.2rem; gap: 1.5rem;
  text-align: center;
}
.rotate-icon { font-size: 3rem; animation: spin 2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 僅觸控小螢幕直向時提示橫置，避免桌面窄視窗被整頁遮住 */
@media (orientation: portrait) and (max-width: 900px) and (hover: none) and (pointer: coarse) {
  #rotate-prompt { display: flex; }
}

/* ══════════════════════════════
   標題畫面
══════════════════════════════ */
body.title-screen {
  background-image: url('/public/out.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  margin: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 標題面板 */
#title-panel {
  position: relative;
  width: min(80vh, 80vw);
  height: min(90vh, 1000vw);
}
.title-panel-bg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#title-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;  /* logo 靠上，按鈕靠下 */
  padding: 30% 4% 8%;
}

#title-logo {
  width: 100%;
  max-width: none;
  filter: drop-shadow(0 4px 16px rgba(235, 219, 136, 0.7));
}

/* 按鈕並排靠下 */
#title-buttons {
  display: flex;
  flex-direction: row;
  gap: 0.75rem;
  align-items: center;
  justify-content: center;
  width: 100%;
}

#title-buttons .menu-btn img {
  width: min(200px, 65vw);
}

.menu-btn {
  position: relative;
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  width: 72%;
}
.menu-btn img {
  width: 100%;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5));
  transition: filter 0.2s;
}
.menu-btn span {
  position: absolute;
  font-size: clamp(0.7rem, 2.2vh, 1.2rem);
  font-weight: bold;
  color: #3b1f0a; letter-spacing: 0.1em;
  text-shadow: 0 1px 2px rgba(255,220,150,0.4);
  pointer-events: none;
}
.menu-btn:hover img { filter: brightness(1.15) drop-shadow(0 2px 8px rgba(200,150,50,0.6)); }

#volume-btn {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: none; border: none; cursor: pointer;
  z-index: 10;
}
#volume-btn img { width: 48px; }

/* 封面音量面板：fixed，浮在音量鍵正上方 */
body.title-screen #volume-panel {
  position: fixed;
  bottom: calc(1.5rem + 48px + 0.5rem);
  right: 1.5rem;
  top: auto;
}

/* ══════════════════════════════
   遊戲畫面
══════════════════════════════ */
body.game-screen {
  display: block;
  position: relative;
  width: 100vw; height: 100vh;
}

/* 場景背景 */
#scene-bg {
  position: absolute; inset: 0;
  background: #1a0e05 center/cover no-repeat;
  transition: background-image 0.6s ease;
  z-index: 1;
}

#scene-props {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
}

.scene-prop {
  position: absolute;
  height: auto;
  object-fit: contain;
  background: transparent;
}

/* 角色立繪：bottom 由 JS syncCharacterToDialog() 動態設定，讀取對話框實際高度 */
#character-wrap {
  position: absolute;
  right: 10%;
  bottom: min(42vh, 100vw * 416 / 2536); /* JS 接管前的 fallback */
  top: 0;
  display: flex;
  align-items: flex-end;
  z-index: 10;
  pointer-events: none;
}
#character-sprite {
  /* 高度填滿可用空間，寬度隨畫面寬縮放，同時設上限避免過大 */
  max-height: 100%;
  max-width: min(40vw, 600px);
  width: auto;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(4px 0 12px rgba(0,0,0,0.6));
  transition: opacity 0.4s;
}

/* ── 對話橫條（底部，比例對應 dialog.png 2536×416）── */
#dialog-card {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  width: 100%;
  aspect-ratio: 2536 / 416;
  max-height: 42vh;
  min-height: 100px;
  z-index: 20;
  background: url('../public/dialog.png') center bottom / 100% 100% no-repeat;
  /* 初始隱藏，避免導向結局頁前閃現預設對話框；engine.js 確認不導向後才顯示 */
  visibility: hidden;
}

#dialog-content {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
}

/* 說話者名稱：固定在名牌標籤區域內 */
#speaker-bar {
  position: absolute;
  top: 4%;
  left: 14.3%;
  width: 13%;
  height: 22%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
}
#speaker-name {
  font-size: clamp(0.6rem, 1.3vw, 0.9rem);
  font-weight: bold;
  color: #f5e6c8;
  letter-spacing: 0.12em;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  white-space: nowrap;
}

/* 旁白（不使用） */
#narration-box {
  display: none !important;
}

/* 對話文字：固定在對話框文字區域左上，隨視窗縮放 */
#dialog-text {
  position: absolute;
  top: 33%;
  left: 10%;
  right: 5%;
  bottom: 12%;
  font-size: clamp(0.9rem, 1.5vw, 1.3rem);
  line-height: 1.8;
  color: #2d271a;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* 選項：覆蓋同一文字區域 */
#choices {
  position: absolute;
  top: 32%;        /* 從 26% 改成 32% */
  left: 8%;
  right: 5%;
  bottom: 12%;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow-y: auto;
}

.choice-btn {
  background: rgba(180, 130, 60, 0.15);
  border: 1px solid rgba(180, 130, 60, 0.5);
  border-radius: 4px;
  color: #2d1a08;
  font-size: clamp(0.85rem, 1.7vw, 1.1rem);  /* 再大一點 */
  font-family: inherit;
  padding: 0.45rem 1.2rem;
  cursor: pointer;
  text-align: center;
  transition: background 0.2s;
  width: 70%;
  align-self: center;
}
.choice-btn:hover { background: rgba(180, 130, 60, 0.35); }

/* 繼續提示：固定在右下角 ▼ 圖案位置 */
#next-hint {
  position: absolute;
  bottom: 4%;
  right: 3.5%;
  color: #8b5e3c;
  font-size: clamp(0.55rem, 1vw, 0.8rem);
}
.blink { animation: blink 1.2s ease-in-out infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.2} }

/* ── HUD ── */
#hud {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  z-index: 30;
  display: flex;
  gap: 0.5rem;
}
#hud button {
  background: none; border: none; cursor: pointer;
  opacity: 0.85; transition: opacity 0.2s;
}
#hud button:hover { opacity: 1; }
#hud img { width: 36px; height: 36px; object-fit: contain; }

/* ── 選單覆蓋層 ── */
#menu-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: stretch; justify-content: flex-end;
}
#menu-panel {
  position: relative;
  height: 100%;
  width: auto;
  aspect-ratio: 747 / 1424;
}
#menu-panel > img {
  display: block;
  height: 100%;
  width: 100%;
  object-fit: fill;
}
#menu-items {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1rem;
}

/* ── 結局畫面 ── */
body.ending-page {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  overflow: auto;
}
.ending-scrim {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}
.ending-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  max-width: 520px;
}
.ending-img {
  max-width: 80vw;
  max-height: 40vh;
  object-fit: contain;
  border-radius: 4px;
}
.ending-title { font-size: 2rem; letter-spacing: 0.2em; }
.ending-desc {
  font-size: 1rem;
  opacity: 0.9;
  line-height: 2;
}
.btn-back {
  padding: 0.6rem 2rem;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: inherit;
}
.btn-back:hover { background: rgba(255, 255, 255, 0.16); }

body.ending-bad {
  color: #c8a0a0;
  background: #0d0505 url('../public/out_night.png') center / cover no-repeat;
}
body.ending-bad .ending-scrim { background: rgba(13, 5, 5, 0.72); }
body.ending-bad .btn-back {
  border-color: rgba(150, 60, 60, 0.5);
  background: rgba(150, 60, 60, 0.2);
}
body.ending-bad .btn-back:hover { background: rgba(150, 60, 60, 0.4); }

body.ending-good {
  color: #f5e6c8;
  background: #1a0e05 url('../public/out.png') center / cover no-repeat;
}
body.ending-good .ending-scrim { background: rgba(26, 14, 5, 0.65); }
body.ending-good .btn-back {
  border-color: rgba(180, 130, 60, 0.5);
  background: rgba(180, 130, 60, 0.2);
}
body.ending-good .btn-back:hover { background: rgba(180, 130, 60, 0.4); }

body.ending-love {
  color: #c8dff5;
  background: #05101a url('../public/bar.png') center / cover no-repeat;
}
body.ending-love .ending-scrim { background: rgba(5, 16, 26, 0.68); }
body.ending-love .btn-back {
  border-color: rgba(60, 120, 180, 0.5);
  background: rgba(60, 120, 180, 0.2);
}
body.ending-love .btn-back:hover { background: rgba(60, 120, 180, 0.4); }

/* ── 音量面板 ── */
#volume-panel {
  position: absolute;
  top: calc(0.8rem + 36px + 0.5rem);
  right: 0.8rem;
  z-index: 35;
  background: rgba(15, 8, 3, 0.92);
  border: 1px solid rgba(180, 130, 60, 0.5);
  border-radius: 8px;
  padding: 0.6rem 0.6rem 0.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}
#volume-panel .vol-label {
  font-size: 0.6rem;
  color: #c8a870;
  letter-spacing: 0.05em;
}
#volume-slider {
  -webkit-appearance: none;
  appearance: none;
  writing-mode: vertical-lr;
  direction: rtl;
  width: 28px;
  height: 90px;
  background: rgba(180, 130, 60, 0.25);
  border-radius: 4px;
  outline: none;
  cursor: pointer;
}
#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 28px;
  background: url('../public/volume_slide.png') center/contain no-repeat;
  cursor: pointer;
}
#volume-slider::-moz-range-thumb {
  width: 28px;
  height: 28px;
  background: url('../public/volume_slide.png') center/contain no-repeat;
  cursor: pointer;
  border: none;
}

/* ── RWD：小螢幕調整 ── */
@media (max-height: 500px) {
  #dialog-card { max-height: 48vh; min-height: 88px; }
  #dialog-content { padding: 2% 4% 1.5% 10%; }
  #speaker-name { font-size: 0.75rem; }
  #dialog-text { font-size: 0.78rem; }
  /* #character-wrap bottom 由 JS 動態設定，不在此覆寫 */
  #hud img { width: 28px; height: 28px; }
}
