/* ==========================================================================
   全域與重置樣式
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  /* 禁止文字選取，避免遊戲過程中誤觸選取文字 */
  user-select: none;
  -webkit-user-select: none;
  /* 移除移動端點擊時的高光效果 */
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  /* 隱藏捲軸，確保遊戲佔滿全螢幕且不會滾動 */
  overflow: hidden;
  color: #333;
}

/* ==========================================================================
   主遊戲容器
   ========================================================================== */
/* 9:16 直向設計，適合手機版面 */
#gameWrapper {
  position: relative;
  width: 100%;
  max-width: 440px;
  height: 100vh;
  max-height: 780px;
  background-color: #000;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  /* 針對觸控優化，僅允許特定操作 (避免雙擊縮放等) */
  touch-action: manipulation;
}

/* ==========================================================================
   HUD 頂部狀態列
   ========================================================================== */
#hudContainer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* 讓滑鼠/觸控事件穿透容器，不影響後方畫布操作 */
  pointer-events: none;
  z-index: 10;
}

.hud-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hud-badges {
  display: flex;
  gap: 8px;
}

.badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.9);
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: bold;
  font-size: 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  border: 1.5px solid #fff;
}

.hp-badge {
  background: rgba(255, 255, 255, 0.95);
  letter-spacing: -2px;
  font-size: 13px;
  padding: 4px 8px;
  border-color: #FFCDD2;
}

.hud-actions {
  display: flex;
  gap: 6px;
  /* 恢復點擊事件，讓按鈕可以被點擊 */
  pointer-events: auto;
}

.hud-btn {
  background: rgba(255, 255, 255, 0.9);
  border: 1.5px solid #fff;
  border-radius: 50%;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: transform 0.1s;
}

.hud-btn:active {
  transform: scale(0.92);
}

/* ==========================================================================
   HUD 階梯進度條
   ========================================================================== */
.hud-progress-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  padding: 4px 10px;
  border-radius: 12px;
}

.step-label {
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  white-space: nowrap;
}

.progress-track {
  flex: 1;
  height: 10px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 5px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 2%;
  background: linear-gradient(90deg, #4CAF50, #8BC34A, #FFEB3B);
  border-radius: 5px;
  transition: width 0.2s ease-out;
}

/* ==========================================================================
   HUD 護盾倒數浮標
   ========================================================================== */
.shield-badge {
  background: linear-gradient(135deg, #FFD700, #FF9800);
  color: #fff;
  animation: pulse 1s infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

/* ==========================================================================
   手機底部虛擬控制鍵
   ========================================================================== */
#touchControls {
  position: absolute;
  bottom: 12px;
  left: 0;
  width: 100%;
  padding: 0 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  /* 事件穿透，避免遮擋背景畫布 */
  pointer-events: none;
  z-index: 10;
}

.touch-dpad {
  display: flex;
  gap: 12px;
  /* 恢復按鍵的點擊事件 */
  pointer-events: auto;
}

.touch-btn {
  width: 58px;
  height: 58px;
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  font-size: 22px;
  font-weight: bold;
  color: #1976D2;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  /* 禁用預設的觸控行為 (如滑動)，由 JS 處理 */
  touch-action: none;
}

.touch-btn:active {
  background: #BBDEFB;
  transform: scale(0.92);
}

.touch-jump-btn {
  width: 76px;
  height: 76px;
  background: linear-gradient(135deg, #FF9800, #F57C00);
  border: 3px solid #FFF3E0;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 900;
  color: #fff;
  box-shadow: 0 6px 14px rgba(245, 124, 0, 0.4);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  /* 恢復點擊事件 */
  pointer-events: auto;
}

.touch-jump-btn:active {
  transform: scale(0.92);
  background: #E65100;
}

/* ==========================================================================
   浮層 Modal 通用設計
   ========================================================================== */
.screen-modal {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 18px;
  z-index: 50;
  transition: opacity 0.3s;
}

.modal-content {
  background: #ffffff;
  border-radius: 20px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  animation: popIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   首頁與選單介面 (Start Screen / Menu)
   ========================================================================== */
.title-banner {
  background: linear-gradient(135deg, #FF9800, #FF5722);
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  margin-bottom: 14px;
  box-shadow: 0 4px 10px rgba(255, 87, 34, 0.3);
}

.title-sub {
  font-size: 13px;
  letter-spacing: 2px;
  opacity: 0.95;
}

.title-main {
  font-size: 22px;
  font-weight: 900;
  margin-top: 2px;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}

.story-card {
  background: #FFF8E1;
  border: 1.5px dashed #FFB300;
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: #5D4037;
  text-align: left;
  margin-bottom: 14px;
}

.character-intro-box {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.char-card {
  flex: 1;
  background: #F5F5F5;
  border-radius: 10px;
  padding: 8px;
  font-size: 12px;
  text-align: left;
  border-left: 4px solid #1E88E5;
}

.char-card.char-anze {
  border-left-color: #43A047;
}

.char-name {
  font-weight: bold;
  font-size: 13px;
  margin-bottom: 2px;
}

/* ==========================================================================
   通用按鈕樣式
   ========================================================================== */
.btn-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.primary-btn {
  background: linear-gradient(135deg, #4CAF50, #2E7D32);
  color: #fff;
  font-size: 18px;
  font-weight: bold;
  padding: 14px 20px;
  border: none;
  border-radius: 28px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(46, 125, 50, 0.35);
  transition: transform 0.1s;
}

.primary-btn:active {
  transform: scale(0.96);
}

.secondary-btn {
  background: #ECEFF1;
  color: #37474F;
  font-size: 14px;
  font-weight: bold;
  padding: 10px 16px;
  border: none;
  border-radius: 20px;
  cursor: pointer;
}

.lottery-btn {
  background: linear-gradient(135deg, #00C300, #009900);
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  padding: 14px 18px;
  border: none;
  border-radius: 26px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 195, 0, 0.35);
}

.rumor-btn {
  background: linear-gradient(135deg, #FF7043, #D84315);
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  padding: 14px 18px;
  border: none;
  border-radius: 26px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(216, 67, 21, 0.35);
}

/* ==========================================================================
   快問快答 Modal (Quiz System)
   ========================================================================== */
.quiz-header {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.category-tag {
  font-size: 12px;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 12px;
  color: #fff;
}

.tag-food { background: #E65100; }
.tag-medicine { background: #0288D1; }
.tag-medical { background: #00897B; }
.tag-cosmetics { background: #D81B60; }

.quiz-topic {
  font-size: 13px;
  font-weight: bold;
  color: #555;
}

.quiz-question-box {
  background: #E3F2FD;
  border-radius: 12px;
  padding: 14px 12px;
  font-size: 15px;
  font-weight: bold;
  color: #0D47A1;
  line-height: 1.45;
  margin-bottom: 14px;
  text-align: left;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.quiz-option-btn {
  background: #FFFFFF;
  border: 2px solid #90CAF9;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: bold;
  color: #1565C0;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s;
}

.quiz-option-btn:hover {
  background: #E3F2FD;
}

.quiz-option-btn.correct {
  background: #E8F5E9;
  border-color: #2E7D32;
  color: #1B5E20;
}

.quiz-option-btn.wrong {
  background: #FFEBEE;
  border-color: #C62828;
  color: #B71C1C;
}

/* 問答解答區塊 */
.explanation-box {
  background: #FFFDE7;
  border: 1.5px solid #FBC02D;
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.5;
  color: #37474F;
  text-align: left;
  margin-bottom: 14px;
}

.explanation-box.correct-box {
  background: #E8F5E9;
  border-color: #4CAF50;
  color: #1B5E20;
}

.explanation-box.wrong-box {
  background: #FFF3E0;
  border-color: #FF9800;
  color: #E65100;
}

/* ==========================================================================
   結算畫面 (Result Modal)
   ========================================================================== */
.win-icon {
  font-size: 48px;
  margin-bottom: 6px;
}

.result-title {
  font-size: 24px;
  font-weight: 900;
  color: #2E7D32;
  margin-bottom: 6px;
}

.fail-title {
  color: #C62828;
}

.result-desc {
  font-size: 14px;
  color: #555;
  line-height: 1.5;
  margin-bottom: 14px;
}

.stats-card {
  background: #F1F8E9;
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  color: #33691E;
  margin-bottom: 16px;
  font-weight: bold;
}

/* ==========================================================================
   規則說明 Modal
   ========================================================================== */
.rules-list {
  text-align: left;
  font-size: 13px;
  line-height: 1.6;
  color: #424242;
  margin-bottom: 16px;
}

.rules-list li {
  margin-bottom: 8px;
}

/* ==========================================================================
   工具類別 (Utility Classes)
   ========================================================================== */
.hidden {
  display: none !important;
}
