/* --- 基礎設定與安全區 --- */
: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);
  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;
}
/* 🚀 修改：調整為自動分配寬度，適應 5 個按鈕 */
.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.7rem; /* 微調字體大小 */
  flex: 1;           /* 自動平分寬度 */
  padding: 5px 2px;  /* 縮小左右內距 */
  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; 
}

/* --- 按鈕設計 --- */
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; }

/* 錯誤震動動畫 */
@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; }

.fade-in { animation: fadeIn 0.4s ease forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.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;
}

/* 關卡背景色變化 */
body.level-0 { background: #f0f4f8; }
body.level-1 { background: linear-gradient(135deg, #e6f2ff, #f0f4f8); }
body.level-2 { background: linear-gradient(135deg, #e6fffa, #f0f4f8); }
body.level-3 { background: linear-gradient(135deg, #fff5f5, #f0f4f8); }

/* =========================================
   🚀 緊張刺激優化：追加樣式 (NDDP)
   ========================================= */

/* 倒數計時文字心跳特效 */
@keyframes heartPulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.8; color: #c53030; }
  100% { transform: scale(1); opacity: 1; }
}
.danger-pulse { animation: heartPulse 0.5s infinite; font-weight: 900 !important; color: #c53030 !important; text-shadow: 0 2px 4px rgba(197, 48, 48, 0.3); }

/* 畫面邊框紅色閃爍警告 */
@keyframes screenAlert {
  0% { box-shadow: inset 0 0 0px rgba(229, 62, 62, 0); }
  50% { box-shadow: inset 0 0 20px rgba(229, 62, 62, 0.6); }
  100% { box-shadow: inset 0 0 0px rgba(229, 62, 62, 0); }
}
.danger-screen { animation: screenAlert 0.5s infinite; border-radius: 20px; }

/* 分享按鈕樣式 */
.btn-share {
  background: linear-gradient(180deg, #48bb78 0%, #2f855a 100%) !important;
  color: white !important; border-color: #276749 !important; margin-top: 15px !important; box-shadow: 0 4px 10px rgba(72, 187, 120, 0.4) !important; animation: popIn 0.5s ease;
}

/* =========================================
   🚀 底部版權與自訂彈窗樣式
   ========================================= */

.footer-btn-group {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.footer-btn {
  background-color: #822727; /* 深紅色系 */
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: bold;
  transition: opacity 0.2s;
}

.footer-btn:hover { opacity: 0.9; }

.footer-btn.share-btn {
  background-color: #1a202c; /* 深灰色系 */
  display: flex;
  align-items: center;
}

.footer-text {
  font-size: 0.85rem;
  color: #718096;
  line-height: 1.6;
}

.footer-text a {
  color: #822727; 
  font-weight: bold; 
  text-decoration: none;
}

/* --- 自訂 Modal (彈窗) --- */
.custom-modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  padding: 20px;
}

.custom-modal-content {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.2);
  animation: popIn 0.3s ease;
  overflow: hidden;
  text-align: left;
}

.custom-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid #e2e8f0;
}

.custom-modal-header h3 {
  margin: 0;
  font-size: 1.2rem;
  color: #822727;
}

.custom-modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #a0aec0;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.custom-modal-body {
  padding: 20px;
  font-size: 1rem;
  color: #2d3748;
  line-height: 1.6;
}
