/* ============================================================
   基礎重置
============================================================ */
html {
  /* 防止手機瀏覽器依「系統字體大小」設定自動放大文字，
     確保遊戲版面在任何裝置字體設定下都維持固定比例 */
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

body {
  background-color: #1a1512;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

#game-container {
  width: 1920px;
  height: 1080px;
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: left top;
  overflow: hidden;
  background-color: #000;
}

.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

.scene-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  transition: opacity 0.4s ease;
}

.dim-overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 12, 8, 0.45);
  z-index: 2;
}

/* ============================================================
   讀取畫面
============================================================ */
#loading-screen {
  position: absolute;
  inset: 0;
  background-color: #000000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  color: #fff;
  transition: opacity 0.5s ease;
}

.loading-circle {
  width: 260px;
  height: 260px;
  background-color: #fff3e2;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 30px;
  overflow: hidden;
  box-shadow: 0 0 0 8px rgba(255, 255, 255, 0.15);
}

#loading-mascot {
  width: 70%;
  animation: mascotRun 0.4s infinite alternate ease-in-out;
}

@keyframes mascotRun {
  0% {
    transform: rotate(-10deg);
  }
  100% {
    transform: rotate(10deg);
  }
}

.loading-text {
  font-size: 60px;
  font-weight: bold;
  margin-bottom: 24px;
  letter-spacing: 2px;
}

.dot {
  opacity: 0;
  animation: blinkDots 1.5s infinite;
}
.dot-1 {
  animation-delay: 0s;
}
.dot-2 {
  animation-delay: 0.3s;
}
.dot-3 {
  animation-delay: 0.6s;
}
@keyframes blinkDots {
  0%,
  100% {
    opacity: 0;
  }
  30%,
  70% {
    opacity: 1;
  }
}

.progress-bar-container {
  width: 700px;
  height: 34px;
  border: 3px solid #fff;
  border-radius: 20px;
  padding: 2px;
  margin-bottom: 12px;
}
#progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #ff9ec2, #ff5c9a);
  width: 0%;
  border-radius: 14px;
  transition: width 0.1s linear;
}
#progress-percent {
  font-size: 60px;
  font-weight: bold;
}

/* ============================================================
   標題畫面
============================================================ */
#title-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.title-logo {
  position: absolute;
  z-index: 5;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  width: 1080px;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.25));
}

.img-btn {
  position: relative;
  z-index: 5;
  width: 340px;
  height: 128px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  cursor: pointer;
  transition: filter 0.12s ease;
}
/* 不使用 transform 位移／縮放：避免手機觸控時按壓瞬間幾何位置改變，
   造成 touchend 判定手指移出元素而讓點擊被取消 */
.img-btn:hover {
  filter: brightness(1.06);
}
.img-btn:active {
  filter: brightness(0.9);
}

#title-screen .img-btn {
  position: absolute;
  top: 870px;
  left: 50%;
  transform: translateX(-50%);
  width: 460px;
  height: 173px;
}

/* ============================================================
   說明外框共用
============================================================ */
.frame-wrap {
  position: relative;
  z-index: 5;
  width: 1920px;
  height: 1080px;
}

.frame-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.frame-content {
  position: absolute;
  left: 260px;
  right: 260px;
  top: 180px;
  bottom: 130px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 6;
  overflow-y: auto;
}

/* ============================================================
   遊戲說明畫面
============================================================ */
#instruction-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  cursor: pointer;
}

#instruction-tap-hint {
  align-self: center;
  margin-top: 20px;
  font-size: 56px;
  font-weight: bold;
  color: #ef7b2f;
  animation: bounceDown 1s infinite ease-in-out;
}

.instruction-content {
  align-items: flex-start;
}

.instr-row {
  display: flex;
  align-items: center;
  gap: 24px;
  font-size: 76px;
  font-weight: 600;
  color: #5a4632;
  text-align: left;
  margin-bottom: 18px;
  flex-shrink: 0;
}

.instr-row span {
  text-align: left;
}

.instr-icon-col {
  width: 150px;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
  font-size: 58px;
}

.instr-char-thumb {
  height: 100px;
  width: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.2));
}

.instr-icon {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  flex-shrink: 0;
  background-repeat: no-repeat;
  background-position: left center;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.instr-icon-happy {
  background-image: url("asseets/08.幸福值_空條.png");
  background-size: auto 76px;
}
.instr-icon-patience {
  background-image: url("asseets/08.耐心值_空條.png");
  background-size: auto 76px;
}

/* ============================================================
   遊戲主畫面 - 視覺小說
============================================================ */
#vn-screen {
  z-index: 10;
}

#top-bar {
  position: absolute;
  top: 26px;
  left: 60px;
  width: 1700px;
  z-index: 30;
  display: flex;
  flex-direction: column;
}

.stat-bar {
  position: relative;
  width: 100%;
  height: 84px;
  margin-bottom: -18px;
}

.stat-track {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.3));
}

.stat-fill-clip {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.stat-fill {
  position: absolute;
  left: 0;
  top: 0;
  width: 1700px;
  height: 100%;
}

/* 章節提示卡 */
#chapter-card {
  position: absolute;
  inset: 0;
  z-index: 60;
  background: rgba(30, 20, 10, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#chapter-card-text {
  font-size: 70px;
  color: #fff;
  font-weight: bold;
  text-align: center;
  letter-spacing: 4px;
  background: rgba(0, 0, 0, 0.28);
  padding: 40px 80px;
  border-radius: 30px;
  border: 3px solid rgba(255, 255, 255, 0.5);
  animation: chapterPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes chapterPop {
  0% {
    transform: scale(0.7);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* 角色立繪 */
.vn-char {
  position: absolute;
  bottom: 190px;
  height: 820px;
  width: auto;
  z-index: 15;
  transition: opacity 0.35s ease, transform 0.35s ease, filter 0.35s ease, left 0.35s ease, right 0.35s ease, bottom 0.35s ease;
  filter: drop-shadow(0 12px 14px rgba(0, 0, 0, 0.25));
}

/* 預設（一般對話 / 過場）：角色置中偏內，身形完整不裁切 */
.char-left {
  left: 380px;
}
.char-right {
  right: 380px;
}

/* 問答模式：角色縮小、退到左右兩側最外緣，圖層蓋在選項前方，
   且雙方都維持正常顯示（不套用說話/靜置的透明與縮放差異） */
#vn-screen.ask-mode .vn-char {
  height: 480px;
  z-index: 47;
}
#vn-screen.ask-mode .char-left {
  left: -20px;
  bottom: -60px;
}
#vn-screen.ask-mode .char-right {
  right: -20px;
  bottom: -60px;
}
#vn-screen.ask-mode .char-dim,
#vn-screen.ask-mode .char-speak {
  opacity: 1;
  filter: drop-shadow(0 12px 14px rgba(0, 0, 0, 0.25));
  transform: scale(1);
}

.char-dim {
  opacity: 0.5;
  filter: grayscale(30%) brightness(0.82) drop-shadow(0 12px 14px rgba(0, 0, 0, 0.25));
  transform: scale(0.94);
}
.char-speak {
  opacity: 1;
  filter: drop-shadow(0 12px 14px rgba(0, 0, 0, 0.25));
  transform: scale(1);
}

.char-react-happy {
  animation: reactHappy 0.5s ease;
}
@keyframes reactHappy {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  30% {
    transform: translateY(-26px) scale(1.03);
  }
  60% {
    transform: translateY(0) scale(1);
  }
}
.char-react-sad {
  animation: reactSad 0.5s ease;
}
@keyframes reactSad {
  0%,
  100% {
    transform: translateX(0) rotate(0);
  }
  20% {
    transform: translateX(-10px) rotate(-2deg);
  }
  40% {
    transform: translateX(10px) rotate(2deg);
  }
  60% {
    transform: translateX(-8px) rotate(-1deg);
  }
  80% {
    transform: translateX(8px) rotate(1deg);
  }
}
/* 對話框：預設為「貼底窄版」（一般對話 / 過場 / 結局皆用此樣式） */
#dialogue-box,
#ending-dialogue-box {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: 0;
  top: auto;
  min-height: 290px;
  background: #ffffff;
  border-radius: 40px 40px 0 0;
  padding: 55px 90px 40px;
  z-index: 40;
  box-shadow: 0 -10px 26px rgba(0, 0, 0, 0.18);
  transition: all 0.3s ease;
}

/* 問答模式：對話框改為偏上方的大框，下方留空間給選項 */
#vn-screen.ask-mode #dialogue-box {
  left: 40px;
  right: 40px;
  bottom: auto;
  top: 205px;
  min-height: 200px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 36px;
  padding: 30px 60px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.22);
}

#speaker-name,
#ending-speaker-name {
  display: inline-block;
  font-size: 60px;
  font-weight: bold;
  color: #7a4a1e;
  background: #fff6e6;
  border: 4px solid #ffcf9e;
  padding: 10px 36px;
  border-radius: 30px;
  position: relative;
  top: -76px;
  margin-bottom: -58px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

#dialogue-text,
#ending-dialogue-text {
  font-size: 70px;
  font-weight: 600;
  line-height: 1.4;
  color: #3f3126;
  min-height: 120px;
}

#continue-indicator,
#ending-continue-indicator {
  position: absolute;
  bottom: 18px;
  right: 34px;
  font-size: 60px;
  color: #ef7b2f;
  animation: bounceDown 1s infinite ease-in-out;
}
@keyframes bounceDown {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(8px);
  }
}

/* 選項 */
#choices-area {
  position: absolute;
  left: 260px;
  right: 260px;
  top: 490px;
  z-index: 45;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overflow-x: hidden;
  /* 保留捲動安全機制（避免真的超出畫面），但隱藏捲軸本身，
     避免捲軸出現/消失時擠壓內容寬度造成版面跳動 */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
#choices-area::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.choice-btn {
  background: #fffdf8;
  border: 5px solid #d9a65c;
  border-radius: 26px;
  padding: 16px 44px;
  font-size: 68px;
  font-weight: 600;
  line-height: 1.25;
  color: #4a3826;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  animation: choiceIn 0.35s ease;
}
@keyframes choiceIn {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}
/* 不使用 transform 位移／縮放做為按壓回饋：
   在部分手機瀏覽器上，按下瞬間若元素幾何位置改變，
   會導致 touchend 判定手指已「移出」元素而讓點擊被取消，
   造成「畫面跳一下、點擊卻沒反應」的問題。改用顏色/陰影回饋。 */
.choice-btn:hover {
  background: #fff3e2;
  border-color: #ef7b2f;
}
.choice-btn:active {
  background: #fff3e2;
  border-color: #ef7b2f;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.18);
}
.choice-btn.correct-flash {
  background: #d9f7de !important;
  border-color: #4caf50 !important;
}
.choice-btn.wrong-flash {
  background: #ffe0e0 !important;
  border-color: #e05656 !important;
}

/* 數值變化浮動提示（答對／答錯時跳出） */
#stat-toast {
  position: absolute;
  top: 190px;
  right: 60px;
  z-index: 50;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 40px;
  padding: 18px 44px;
  font-size: 60px;
  font-weight: bold;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
  pointer-events: none;
}
#stat-toast.toast-up {
  color: #3fa64a;
}
#stat-toast.toast-down {
  color: #e0762c;
}
#stat-toast.toast-show {
  animation: toastPop 1.3s ease forwards;
}
@keyframes toastPop {
  0% {
    opacity: 0;
    transform: translateY(14px) scale(0.85);
  }
  15% {
    opacity: 1;
    transform: translateY(0) scale(1.05);
  }
  25% {
    transform: translateY(0) scale(1);
  }
  80% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-16px) scale(0.95);
  }
}

/* 靜音鈕：移到右上角，與幸福值/耐心值同一列 */
#mute-btn {
  position: absolute;
  top: 45px;
  right: 40px;
  bottom: auto;
  width: 86px;
  height: 86px;
  background-color: rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 60px;
  cursor: pointer;
  z-index: 9999;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
  transition: background-color 0.15s ease;
  user-select: none;
}
#mute-btn:hover {
  background-color: rgba(255, 255, 255, 1);
}
#mute-btn:active {
  background-color: rgba(230, 230, 230, 1);
}

/* ============================================================
   過關瞬間特效（先跳出恭喜過關特效，再進入過關對話）
============================================================ */
#victory-flash {
  position: absolute;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 12, 8, 0.4);
  pointer-events: none;
}
#victory-flash img {
  width: 900px;
  filter: drop-shadow(0 14px 24px rgba(0, 0, 0, 0.4));
  animation: victoryFlashPop 1.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes victoryFlashPop {
  0% {
    transform: scale(0.3) rotate(-8deg);
    opacity: 0;
  }
  18% {
    transform: scale(1.15) rotate(3deg);
    opacity: 1;
  }
  30% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  82% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: scale(1.08) rotate(0deg);
    opacity: 0;
  }
}

/* ============================================================
   結局畫面
============================================================ */
#ending-screen {
  z-index: 20;
}

#ending-result {
  position: absolute;
  inset: 0;
  z-index: 55;
  animation: fadeIn 0.6s ease;
}
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.ending-stamp {
  position: absolute;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  width: 620px;
  z-index: 7;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.35));
}

.ending-content {
  top: 300px;
  gap: 30px;
}

#ending-badge {
  background: rgba(255, 255, 255, 0.95);
  border: 4px solid #ffcf9e;
  border-radius: 40px;
  padding: 24px 56px;
  font-size: 64px;
  white-space: nowrap;
  font-weight: bold;
  color: #a85327;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
  text-align: center;
  max-width: 1500px;
}

#ending-system-text {
  font-size: 82px;
  font-weight: 600;
  color: #6b4a2a;
  text-align: center;
  max-width: 1450px;
  white-space: pre-line;
}

.ending-buttons {
  display: flex;
  gap: 50px;
  margin-top: 10px;
}
.ending-buttons .img-btn {
  width: 420px;
  height: 158px;
}
