:root {
  --bg-color: var(--md3e-surface-container);
  --card-bg: var(--md3e-surface);
  --primary: var(--md3e-primary);
  --success: var(--md3e-success);
  --danger: var(--md3e-error);
  --text-main: var(--md3e-on-surface);
  --border-color: var(--md3e-outline);
  --accent: var(--md3e-tertiary);
  --font-family-base: var(--md3e-font-family);
}

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(103, 80, 164, 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(--md3e-surface);
  border: 2px solid var(--md3e-outline);
  color: var(--md3e-on-surface);
  border-radius: var(--md3e-shape-corner-full); /* 使用MD3E的完全圓角 */
  transition: var(--md3e-transition-standard); /* 標準過渡效果 */
  border-radius: 100px; /* 完全圓形 */
  box-shadow: none; /* 移除陰影 */
}

.lang-btn:hover {
  border-color: var(--md3e-primary); /* 懸浮時邊框使用主色 */
  background-color: var(--md3e-surface-container-low); /* 輕微背景變化 */
}

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

/* 激活狀態（當前語言） */
.lang-btn.active {
  background-color: var(--md3e-primary); /* 主色背景 */
  color: var(--md3e-on-primary); /* 主色文字（確保對比度） */
  border-color: var(--md3e-primary); /* 邊框與背景一致 */
}

/* 移除選中狀態額外裝飾 */
.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: 40%;
  height: 12px;
  border-radius: 6px; /* 小圓角 */
  background-color: #e2e8f0;
  overflow: hidden;
  margin: 20px auto;
  border: 1px solid var(--border-color); /* 細邊框 */
}

.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: 20px;
  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;
  margin: 25px auto;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
}

.canvas-container:hover {
  box-shadow: 0 12px 20px rgba(0, 0, 0, 0.12);
}

.btn-report,
.btn-reset {
  margin: 0;
  flex: 1;
  max-width: 200px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.2s ease;
}

.btn-report:hover,
.btn-reset:hover {
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.btn-report:active,
.btn-reset:active {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

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

/* 輸入區樣式 */
.input-group {
  margin-top: 20px 0;
  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; /* 移除默認邊框 */
  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; /* 移除漸變 */
  background-color: var(--primary);
  color: var(--md3e-on-primary);
  border-radius: var(--md3e-shape-corner-medium);
  transition: var(--md3e-transition-standard);
}

/* 移除按鈕點擊動畫效果 */
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: 15px 0;
  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;
  text-align: left;
  gap: 20px;
  margin: 25px 0;
}

.stat-box {
  background: #f8fafc;
  border-radius: 12px; /* 中等圓角 */
  padding: 16px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  border: 1px solid var(--border-color); /* 細邊框 */
}

.stat-box:hover {
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
  transform: translateY(-2px);
  background-color: #f8fafc;
}

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

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

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

.back-btn {
  background: var(--md-sys-color-surface);
  border: 1px solid var(--md-sys-color-outline);
  color: var(--md-sys-color-on-surface);
  padding: 0.5rem 1rem;
  border-radius: var(--md-sys-shape-small); /* 使用系統統一圓角變量 */
  cursor: pointer;
  display: inline-flex; /* 改為inline-flex適應內容寬度 */
  align-items: center;
  gap: 0.5rem;
  transition: all var(--md3e-transition-standard); /* 統一過渡動畫 */
  font-weight: 500; /* 增加字體重量提升可讀性 */
  min-height: 48px; /* 確保觸控區域大小 */
  box-shadow: var(--md-sys-elevation-level1); /* 增加輕微陰影提升層次感 */
}

.back-btn:hover {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  border-color: var(--md-sys-color-primary); /* 懸停時邊框色同步 */
  transform: translateX(-3px);
  box-shadow: var(--md-sys-elevation-level2); /* 懸停增強陰影 */
}

.back-btn:active {
  transform: translateX(-1px); /* 調整點擊反饋位置 */
  box-shadow: var(--md-sys-elevation-level1); /* 點擊時陰影減弱 */
  filter: brightness(0.95); /* 增加亮度變化反饋 */
}

.back-btn:focus {
  outline: 2px solid var(--md-sys-color-primary); /* 焦点狀態優化，提升可訪問性 */
  outline-offset: 2px;
}

.small-screen-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: var(--md3e-surface);
  z-index: 9999;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem;
  text-align: center;
}

.small-screen-overlay i {
  font-size: 3rem;
  color: var(--md3e-primary);
}
