/* styles.css - 扁平化風格樣式表 */
:root {
  --bg-color: #f0f7ff; /* 淺藍色背景，扁平化風格常用 */
  --card-bg: #ffffff; /* 卡片背景色，純白色增強扁平化感 */
  --primary: #3498db; /* 主色調：藍色 */
  --success: #2ecc8a; /* 成功色：綠色 */
  --danger: #e74c3c; /* 危險色：紅色 */
  --text-main: #2c3e50; /* 主要文字顏色：深灰色 */
  --border-color: #dce1e8; /* 邊框顏色：淺灰色 */
  --accent: #9b59b6; /* 強調色：紫色 */
  --font-family-base: system-ui, sans-serif; /* 字體設定 */
}

body {
  font-family: var(--font-family-base);
  background-color: var(--bg-color);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  padding: 10px;
  box-sizing: border-box;
  height: 100vh;
  overflow: hidden; /* 關閉所有方向的滾動 */
  position: relative;
  user-select: none; /* 禁止所有文本選擇 */
  -webkit-user-select: none; /* Safari、Chrome等WebKit內核瀏覽器 */
  -moz-user-select: none; /* Firefox */
  -ms-user-select: none; /* IE、Edge */
  touch-action: manipulation; /* 防止移動設備上的雙擊放大 */
}

/* 背景裝飾元素 */
body::before {
  content: "";
  position: fixed;
  top: -50px;
  right: -50px;
  width: 200px;
  height: 200px;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 50%;
  z-index: -1;
}

body::after {
  content: "";
  position: fixed;
  bottom: -80px;
  left: -80px;
  width: 250px;
  height: 250px;
  background: rgba(139, 92, 246, 0.1);
  border-radius: 50%;
  z-index: -1;
}

/* 語言切換按鈕 - 扁平化調整 */
.lang-switch {
  position: absolute;
  top: 20px;
  right: 20px;
}

.lang-btn {
  width: 50px;
  height: 50px;
  font-size: 1.1em;
  background-color: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: 100px; /* 完全圓形 */
  box-shadow: none; /* 移除陰影 */
  transition: all 0.2s ease; /* 簡化過渡效果 */
}

.lang-btn:hover {
  transform: none; /* 移除懸浮動畫 */
  border-color: var(--primary);
}

/* 移除按鈕背景動畫效果 */
.lang-btn::before {
  display: none;
}

.lang-btn.active {
  background-color: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: none; /* 移除陰影 */
}

/* 移除選中狀態額外裝飾 */
.lang-btn.active::after {
  display: none;
}

/* 語言顯示控制 */
.en {
  display: none;
}

body.english .zh {
  display: none;
}

body.english .en {
  display: inline;
}

body.english {
  font-family: var(--font-family-base);
}

h1 {
  margin: 10px 0;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* 狀態欄樣式 - 扁平化調整 */
.status-bar {
  display: flex;
  gap: 30px;
  background: var(--card-bg);
  padding: 15px 30px;
  border-radius: 6px; /* 小圓角 */
  border: 1px solid var(--border-color); /* 細邊框 */
  margin-bottom: 1vh;
  font-weight: bold;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  box-shadow: none; /* 移除陰影 */
}

.status-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 1.2em;
  line-height: 1;
}

.goal-text {
  color: var(--primary);
}

.score-text {
  color: var(--success);
}

/* 進度條樣式 - 扁平化調整 */
.progress-container {
  width: 100%;
  max-width: 600px;
  height: 12px;
  border-radius: 6px; /* 小圓角 */
  background-color: #e2e8f0;
  overflow: hidden;
  margin-bottom: 20px;
  border: none; /* 移除邊框 */
}

.progress-bar {
  height: 100%;
  background: var(--primary); /* 純色背景，移除漸變 */
  width: 0%;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

/* 移除進度條裝飾效果 */
.progress-bar::after {
  display: none;
}

/* 主畫布區域樣式 - 扁平化調整 */
.canvas-container {
  background: var(--card-bg);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 900px;
  position: relative;
  border-radius: 12px; /* 中等圓角 */
  border: 1px solid var(--border-color); /* 細邊框 */
  margin-bottom: 10px;
  box-sizing: border-box;
  overflow: hidden;
}

canvas {
  width: 100%;
  max-width: 850px;
  height: auto;
  max-height: 70%; /* 限制最大高度，防止溢出 */
  touch-action: none;
  background-color: #fff;
}

/* 輸入區樣式 */
.input-group {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

input[type="number"] {
  padding: 12px;
  font-size: 1.3em;
  width: 140px;
  border: 1px solid var(--border-color); /* 細邊框 */
  border-radius: 6px; /* 小圓角 */
  text-align: center;
  transition: all 0.2s ease; /* 簡化過渡 */
  background: #fff;
  box-shadow: none; /* 移除陰影 */
}

input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2); /* 簡化焦點效果 */
  position: relative;
  z-index: 10;
}

/* 按鈕樣式 - 扁平化調整 */
button {
  min-height: 48px;
  min-width: 48px; /* 確保移動端觸摸目標足夠大 */
  padding: 12px 25px;
  font-size: 1.1em;
  font-weight: 600;
  cursor: pointer;
  border: none; /* 移除默認邊框 */
  border-radius: 10px; /* 小圓角 */
  transition: background-color 0.2s ease; /* 簡化過渡效果 */
  font-family: var(--font-family-base);
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px; /* 圖標與文字之間的間距 */
  box-shadow: none; /* 移除陰影 */
  background-image: none; /* 移除漸變 */
}

/* 移除按鈕點擊動畫效果 */
button::after {
  display: none;
}

button:hover {
  transform: none; /* 移除懸浮移動效果 */
  box-shadow: none; /* 移除陰影 */
  filter: brightness(1.1); /* 亮度變化替代陰影 */
}

button:active {
  transform: none; /* 移除點擊縮放效果 */
  box-shadow: none;
  filter: brightness(0.9); /* 亮度變化替代縮放 */
}

.btn-submit {
  background-color: var(--success);
  color: white;
}

.btn-submit:active {
  transform: none;
  box-shadow: none;
}

.btn-report {
  background-color: var(--primary);
  color: white;
  margin-top: 10px;
}

.btn-reset {
  background-color: #fdba74;
  color: #c2410c;
  margin-top: 10px;
  margin-bottom: 10px;
  font-size: 0.9em;
}

/* 反饋資訊樣式 */
.feedback {
  margin-top: 10px;
  min-height: 30px;
  font-size: 1.4em;
  font-weight: bold;
  text-align: center;
  transition: all 0.3s ease;
  transform: translateY(0);
  opacity: 1;
}

.feedback.correct {
  color: #2e7d32;
  animation: correctPulse 0.5s ease;
}

.feedback.wrong {
  color: #c62828;
  animation: shake 0.5s ease;
}

/* 反饋動畫關鍵幀 - 簡化版 */
@keyframes correctPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

/* 成績單彈窗樣式 - 扁平化調整 */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.modal-content {
  background: white;
  padding: 30px;
  border-radius: 6px; /* 小圓角 */
  text-align: center;
  max-width: 450px;
  width: 90%;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); /* 輕微陰影 */
  border: none;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(0);
  animation: modalPop 0.3s ease-out;
}

/* 模態框動畫 */
@keyframes modalPop {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 20px 0;
  text-align: left;
}

.stat-box {
  background: #f8fafc;
  border-radius: 12px; /* 中等圓角 */
  padding: 16px;
  transition: background-color 0.2s ease; /* 簡化過渡 */
  box-shadow: none; /* 移除陰影 */
  border: 1px solid var(--border-color); /* 細邊框 */
}

.stat-box:hover {
  transform: none; /* 移除懸浮效果 */
  background-color: #f0f0f0; /* 背景色變化替代浮動效果 */
}

/* 顯示答案按鈕樣式 - 扁平化調整 */
.btn-show-answer {
  background-color: var(--accent);
  color: white;
}

.btn-show-answer:active {
  transform: none;
  box-shadow: none;
}

html,
body {
  height: 100%;
  overflow: hidden; /* 防止所有方向的滾動 */
}

/* 大屏幕優化 (> 1024px) */
@media (min-width: 1024px) {
  .status-bar {
    margin-bottom: 0.5vh;
    padding: 10px 20px;
  }

  .progress-container {
    margin-bottom: 0.5vh;
  }

  .canvas-container {
    padding: 20px;
    margin-bottom: 10px;
  }

  .input-group {
    margin-top: 0.5vh;
    gap: 15px;
  }

  .btn-report {
    margin-top: 5px;
  }

  .feedback {
    margin-top: 10px;
    min-height: 25px;
  }
}

@media (min-height: 800px) {
  .status-bar {
    margin-bottom: 0.8vh;
  }

  .progress-container {
    margin-bottom: 0.8vh;
  }

  .input-group {
    margin-top: 1vh;
  }

  .btn-report {
    margin-top: 1.2vh;
  }

  .btn-reset {
    margin-top: 0.8vh;
  }
}

/* 移動端適配 (螢幕寬度 ≤ 768px) */
@media (max-width: 768px) {
  body {
    padding: 8px;
    box-sizing: border-box;
  }

  /* 遊戲容器調整 */
  .canvas-container {
    padding: 5px 5px; /* 減少上下內邊距，直接縮短容器高度 */
    width: 100%;
    box-sizing: border-box;
    margin: 0 auto;
    max-width: 500px; /* 防止在平板等設備上變得過寬 */
  }

  /* 畫布自適應 - 核心優化點 */
  #gameCanvas {
    width: 100%;
    height: auto;
    max-height: 100px; /* 降低最大高度，使其在手機螢幕上更緊湊 */
  }

  /* 輸入區域優化 */
  .input-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 15px; /* 適當減少與畫布的間距 */
    padding: 0 5px;
  }

  #userAnswer {
    width: 100%;
    padding: 12px 15px;
    font-size: 1.1em;
    border-radius: 12px;
  }

  /* 按鈕優化 */
  .btn-submit,
  .btn-show-answer {
    padding: 14px 0;
    width: 100%;
    font-size: 1.1em;
  }

  .btn-report,
  .btn-reset {
    width: 100%;
    padding: 12px 0;
    margin-top: 12px;
  }

  /* 反饋區域調整 */
  .feedback {
    font-size: 1.1em; /* 適當調小字體，節省空間 */
    min-height: 24px;
    padding: 8px 0;
  }

  /* 語言按鈕優化 */
  .lang-switch {
    top: 10px;
    right: 10px;
  }

  .lang-btn {
    width: 44px;
    height: 44px;
    font-size: 1em;
  }

  /* 標題優化 */
  h1 {
    font-size: 1.4em;
    text-align: center;
    padding: 10px 0;
    margin: 0 0 10px; /* 減少標題下方的間距 */
  }

  /* 進度條容器 */
  .progress-container {
    margin: 0 5px 10px;
    height: 8px;
  }

  button {
    padding: 10px 20px;
    font-size: 1em;
  }

  .input-group button {
    flex: 1;
  }
}

/* 小屏手機適配 (≤ 375px) */
@media (max-width: 375px) {
  .lang-btn {
    width: 40px;
    height: 40px;
  }

  h1 {
    font-size: 1.2em;
  }

  .feedback {
    font-size: 1em;
  }

  /* 為最小屏手機進一步降低畫布高度 */
  #gameCanvas {
    max-height: 140px;
  }
}

/* 橫屏適配 - 關鍵優化 */
@media (max-height: 500px) and (orientation: landscape) {
  body {
    /* 橫屏時，整體頁面使用彈性佈局，讓遊戲區和操作區上下分布 */
    display: flex;
    flex-direction: column;
    height: 100vh; /* 讓 body 占滿整個視口高度 */
    overflow: hidden; /* 防止頁面整體滾動 */
  }

  .canvas-container {
    /* 橫屏時，容器的高度由 flex 決定，不再依賴內容 */
    flex: 0 1 auto;
    padding: 2px;
    margin-bottom: 5px;
  }

  #gameCanvas {
    /* 使用視口高度的百分比來限制，非常有效 */
    max-height: 45vh;
  }

  .main-content {
    /* 讓主內容區（輸入、按鈕）也參與 flex 佈局 */
    flex: 1;
    overflow-y: auto; /* 如果內容太多，允許內部滾動 */
    padding-bottom: 20px; /* 留出一些底部空間 */
  }

  .input-group {
    margin-top: 10px;
    gap: 8px;
  }

  /* 橫屏時可以讓按鈕橫向排列，節省垂直空間 */
  .action-buttons {
    display: flex;
    gap: 8px;
  }
  .btn-submit,
  .btn-show-answer {
    flex: 1; /* 按鈕平分寬度 */
    padding: 10px 0;
  }
}

/* 橫屏適配 */
@media (max-height: 480px) and (orientation: landscape) {
  .canvas-container {
    margin-bottom: 5px;
  }

  #gameCanvas {
    max-height: 120px;
  }

  .input-group {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  #userAnswer {
    flex: 1;
    padding: 8px;
  }

  .btn-submit,
  .btn-show-answer {
    padding: 8px 12px;
    width: auto;
  }
}

/* 超小屏設備優化 (≤ 375px) */
@media (max-width: 375px) {
  h1 {
    font-size: 1.3em;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  canvas {
    height: 180px;
  }
}

/* 中等寬度手機優化 (≥ 480px) and (max-width: 768px) */
@media (min-width: 480px) and (max-width: 768px) {
  .input-group {
    flex-direction: row;
    align-items: center;
  }

  input[type="number"],
  .btn-submit,
  .btn-show-answer {
    width: auto;
  }

  input[type="number"] {
    width: 120px;
  }
}

@media (max-width: 768px) and (orientation: portrait) {
  .status-bar {
    margin-bottom: 8px;
    padding: 8px 12px;
  }

  .progress-container {
    margin-bottom: 8px;
  }

  .canvas-container {
    padding: 8px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
  }

  canvas {
    height: 180px;
    flex-shrink: 0;
  }

  .input-group {
    margin-top: 8px;
    gap: 6px;
  }

  .btn-report {
    margin-top: 10px;
    padding: 8px 0;
  }

  .btn-reset {
    margin-top: 6px;
    margin-bottom: 0;
    padding: 6px 0;
    font-size: 0.85em;
  }

  .feedback {
    margin-top: 8px;
    min-height: 24px;
    font-size: 1.1em;
  }
}
