/* --- 基礎設定與安全區 --- */
:root {
  --bg-color: #f0f4f8;
  --card-bg: #ffffff;
  --primary: #2b6cb0;
  --success: #48bb78;
  --danger: #f56565;
  --text-main: #2d3748;
  --top-bar-height: calc(55px + env(safe-area-inset-top));
  --bottom-bar-height: calc(65px + env(safe-area-inset-bottom));
}

[hidden] { display: none !important; }

body {
  margin: 0; padding: 0;
  background: var(--bg-color);
  /* 🌟 加入 Noto Sans TC 作為首選字體 */
  font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text-main);
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  width: 100vw;
  height: 100dvh; 
  overflow: hidden; 
}

/* --- 固定頂部導覽列 --- */
#top-navbar {
  position: absolute; top: 0; left: 0; right: 0;
  height: var(--top-bar-height);
  background-color: #34495e; 
  color: white;
  display: flex; align-items: center;
  padding: env(safe-area-inset-top) 15px 0 15px; 
  z-index: 1000;
  box-sizing: border-box;
}
.top-nav-title { font-size: 1.3rem; font-weight: bold; margin: 0; display: flex; align-items: center; gap: 8px;}
.top-nav-subtitle { font-size: 0.75rem; color: #cbd5e0; margin-left: 10px; font-weight: normal; }

/* --- 固定底部功能列 --- */
#bottom-navbar {
  position: absolute; bottom: 0; left: 0; right: 0;
  height: var(--bottom-bar-height);
  background-color: #ffffff;
  border-top: 1px solid #e2e8f0;
  display: flex; justify-content: space-around; align-items: center;
  padding-bottom: env(safe-area-inset-bottom); 
  z-index: 1000;
  box-sizing: border-box;
}
.bottom-nav-btn {
  background: none; border: none; box-shadow: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #718096; font-size: 0.75rem; width: 25%; padding: 5px; margin: 0;
  cursor: pointer;
  transition: color 0.2s ease;
}
.bottom-nav-btn:hover { color: var(--primary); }
.bottom-nav-btn span.icon { font-size: 1.5rem; margin-bottom: 2px; }

/* --- 取消 padding，允許滿版 --- */
#main-container {
  position: absolute;
  top: var(--top-bar-height);
  bottom: var(--bottom-bar-height);
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden; 
}

/* --- 遊戲主體卡片 --- */
.app-main {
  max-width: 600px;
  margin: 0 auto;
  padding: 15px;
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  width: 100%;
  height: 100%; 
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden; 
}

/* --- 🌟 UI 升級：現代感按鈕設計 --- */
button.primary-btn {
  width: 100%; padding: 12px 15px; font-size: 1.05rem; font-weight: bold;
  border: 1px solid #cbd5e0; border-radius: 12px; /* 稍微改成圓角矩形，更具現代感 */
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  color: var(--text-main);
  cursor: pointer; 
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05), 0 1px 3px rgba(0, 0, 0, 0.1);
  transition: all 0.15s ease;
}
button.primary-btn:hover:not(:disabled) {
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.08), 0 2px 4px rgba(0, 0, 0, 0.12);
  transform: translateY(-1px);
}
button.primary-btn:active:not(:disabled) {
  transform: translateY(2px) scale(0.98);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
  background: #edf2f7;
}
button.primary-btn:disabled { opacity: 0.6; cursor: not-allowed; transform: none; box-shadow: none; }

#choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr); 
  gap: 12px; /* 增加按鈕間距 */
  width: 100%; 
  margin: 10px 0;
}
#choices button.primary-btn { white-space: normal; height: auto; min-height: 60px; line-height: 1.3; font-size: 0.95rem; margin: 0; padding: 10px; display: flex; align-items: center; justify-content: center;}

/* --- 狀態列 (HUD) --- */
#hud-container { display: flex; flex-direction: column; margin-bottom: 10px; flex-shrink: 0; }
.badge { color: white; padding: 6px 12px; border-radius: 25px; font-size: 0.9rem; font-weight: bold; }
.badge.level { background: var(--primary); }
.badge.streak { background: #ed8936; }
#hud-hp { width: 100%; text-align: center; font-size: 1.3rem; letter-spacing: 2px; margin-bottom: 6px; }

/* --- 🌟 UI 升級：錯誤震動動畫 --- */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

.feedback-banner { border-radius: 12px; padding: 12px; margin: 10px 0; width: 100%; text-align: center; box-sizing: border-box; animation: popIn 0.2s ease;}
.feedback-banner.correct { background-color: #f0fff4; border: 2px solid #48bb78; }
.feedback-banner.wrong { background-color: #fff5f5; border: 2px solid #f56565; animation: shake 0.4s ease-in-out; }
.feedback-title { margin: 0; font-size: 1.3rem; font-weight: bold; }
.feedback-title.correct { color: #2f855a; }
.feedback-title.wrong { color: #c53030; }

.progress-wrapper { width: 100%; background: #edf2f7; border-radius: 10px; height: 8px; overflow: hidden; box-shadow: inset 0 1px 3px rgba(0,0,0,0.1); }
.progress-fill { height: 100%; background: linear-gradient(90deg, #48bb78, #38a169); width: 0%; transition: width 0.3s ease; }
#hud-progress-text { width: 100%; text-align: center; font-size: 0.75rem; color: #718096; margin-top: 6px; font-weight: 500; }

/* 核心排版：鎖定上下，只捲動中間 */
#question-ui { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
#scroll-area { flex: 1; overflow-y: auto; padding: 0 5px 10px 5px; }
#question-text { font-size: 1.15rem; margin-bottom: 15px; line-height: 1.5; font-weight: bold; text-align: justify; color: #1a202c; }
#action-area { flex-shrink: 0; padding-top: 10px; background: var(--card-bg); border-top: 1px solid #e2e8f0; margin-top: 5px; padding-bottom: 5px; }

/* 特效與版權頁 */
.overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 2000; background: rgba(0,0,0,0.6); backdrop-filter: blur(5px); }
@keyframes popIn { 0% { transform: scale(0.9); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
#streak-overlay { background: rgba(255, 215, 0, 0.95); color: #b7791f; font-size: 1.8rem; font-weight: bold; text-align: center; text-shadow: 0 2px 4px rgba(0,0,0,0.1); }
#levelup-overlay { background: rgba(43, 108, 176, 0.95); color: white; text-align: center; }
#ranking-list { list-style: none; padding: 0; overflow-y: auto; flex:1; }
#ranking-list li { padding: 14px 10px; border-bottom: 1px solid #e2e8f0; font-size: 1.05rem; }
.footer-copyright { text-align: center; padding: 15px 10px; font-size: 0.85rem; color: #718096; line-height: 1.8; margin-top: auto; }
.footer-copyright a { color: var(--primary); font-weight: bold; text-decoration: none; }

/* =========================================
   🚀 階段一 & 階段二：升級特效與動畫區
   ========================================= */

/* 1. 轉場動畫 (Fade-in) */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.fade-in {
  animation: fadeIn 0.4s ease forwards;
}

/* 3. 寶物獨立 UI 卡片 */
.treasure-toast {
  background: linear-gradient(135deg, #fffaf0 0%, #fefcbf 100%);
  border: 2px solid #fbd38d; 
  border-radius: 12px; 
  padding: 12px;
  margin-bottom: 15px; 
  text-align: center; 
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
  animation: popIn 0.3s ease;
}

/* 4. 關卡背景變化 (Level 1 ~ Level 4) */
body { transition: background 0.5s ease; }
body.level-0 { background: #f0f4f8; } /* Lv 1 */
body.level-1 { background: linear-gradient(135deg, #e6f2ff, #f0f4f8); } /* Lv 2 */
body.level-2 { background: linear-gradient(135deg, #e6fffa, #f0f4f8); } /* Lv 3 */
body.level-3 { background: linear-gradient(135deg, #fff5f5, #f0f4f8); } /* Lv 4 */
