/* ==========================================================================
   糖果雨消消樂：九九乘法大冒險 (Candy Multiplier Drop)
   專為國小低年級設計 - 可愛、刺激、粉嫩夢幻糖果風格 CSS
   ========================================================================== */

:root {
  --primary-pink: #ff6b9d;
  --secondary-pink: #ff8ebb;
  --bubblegum: #ff4b8b;
  --candy-yellow: #ffd154;
  --mint-green: #48e5c2;
  --sky-blue: #4db5ff;
  --grape-purple: #9d65ff;
  --sugar-white: #ffffff;
  --bg-cream: #fff8f0;
  --text-dark: #44284b;
  --shadow-soft: 0 8px 24px rgba(255, 107, 157, 0.2);
  --shadow-card: 0 10px 30px rgba(78, 38, 86, 0.12);
  --jelly-btn-shadow: 0 6px 0 #d94073, 0 8px 16px rgba(0, 0, 0, 0.15);
  --jelly-btn-active: 0 2px 0 #d94073, 0 3px 6px rgba(0, 0, 0, 0.2);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

body {
  font-family: 'Nunito', 'Quicksand', 'PingFang TC', 'Microsoft JhengHei UI', '微軟正黑體', sans-serif;
  background: radial-gradient(circle at 50% 20%, #ffeaf1 0%, #ffd6e6 50%, #fbd5ed 100%);
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-x: hidden;
  position: relative;
}

/* 背景漂浮糖果裝飾 */
body::before, body::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  filter: blur(40px);
  opacity: 0.45;
}
body::before {
  width: 320px;
  height: 320px;
  background: #ffc2dc;
  top: -50px;
  left: -50px;
  animation: floatBg 12s infinite ease-in-out;
}
body::after {
  width: 400px;
  height: 400px;
  background: #c7ebff;
  bottom: -80px;
  right: -80px;
  animation: floatBg 15s infinite ease-in-out reverse;
}

@keyframes floatBg {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(30px) scale(1.08); }
}

/* 主遊戲容器 */
.app-container {
  width: 100%;
  max-width: 520px;
  min-height: 100vh;
  padding: 8px 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 1;
}

/* 頂部導航列 */
.top-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  padding: 4px 6px;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  font-size: 1.15rem;
  color: #ff3377;
  text-shadow: 1px 2px 0 rgba(255, 255, 255, 0.9);
}
.brand-badge .icon-spin {
  display: inline-block;
  animation: candyRoll 6s linear infinite;
}
@keyframes candyRoll {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.header-controls {
  display: flex;
  gap: 8px;
}

.circle-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #ffffff;
  color: #553366;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
  transition: transform 0.12s, background 0.2s;
}
.circle-btn:active {
  transform: scale(0.92);
}
.circle-btn:hover {
  background: #fff0f6;
}

/* 狀態儀表板 */
.stats-panel {
  width: 100%;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(8px);
  border-radius: 18px;
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-card);
  border: 2px solid rgba(255, 255, 255, 0.95);
  margin-bottom: 8px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.stat-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #8c7194;
  letter-spacing: 0.5px;
}
.stat-value {
  font-size: 1.25rem;
  font-weight: 900;
  color: #3b1d44;
}
.stat-score {
  color: #e0246a;
}
.stat-level {
  color: #7b32d9;
}

/* 狂熱條 (Fever Bar) */
.fever-container {
  width: 100%;
  margin-bottom: 8px;
}
.fever-bar-wrap {
  width: 100%;
  height: 14px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid #ffffff;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.08);
  position: relative;
}
.fever-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ff719a, #ffd43f, #3ee2b7, #3bb2ff, #a855f7);
  background-size: 300% 100%;
  border-radius: 8px;
  transition: width 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: feverGradient 3s infinite linear;
}
@keyframes feverGradient {
  0% { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}
.fever-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 800;
  color: #754b85;
  margin-top: 2px;
  padding: 0 4px;
}
.fever-active-text {
  animation: pulseFever 0.8s infinite alternate;
  color: #d81159;
}
@keyframes pulseFever {
  from { transform: scale(1); filter: drop-shadow(0 0 2px #ff69b4); }
  to { transform: scale(1.08); filter: drop-shadow(0 0 6px #ff1493); }
}

/* 核心題目卡片 (位於落糖欄位正下方、超大鍵盤正上方，眼手合一最舒適視線) */
.question-card {
  width: 100%;
  background: linear-gradient(135deg, #ffffff 0%, #fff2f8 100%);
  border-top: 3px dashed #ffccd9;
  border-bottom: 3px dashed #ffccd9;
  box-shadow: inset 0 2px 6px rgba(255, 107, 157, 0.08);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
  z-index: 2;
}

.question-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 50%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
  transform: skewX(-20deg);
  animation: shine 4s infinite;
}
@keyframes shine {
  0% { left: -100%; }
  25%, 100% { left: 200%; }
}

.mascot-box {
  width: 58px;
  height: 58px;
  background: #ffe3ee;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  box-shadow: 0 4px 10px rgba(255, 75, 139, 0.2);
  flex-shrink: 0;
  animation: mascotWiggle 3s infinite ease-in-out;
}
@keyframes mascotWiggle {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(-5deg) scale(1.05); }
  75% { transform: rotate(5deg) scale(1.05); }
}

.question-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.question-hint-title {
  font-size: 0.78rem;
  font-weight: 800;
  color: #ff508c;
  display: flex;
  align-items: center;
  gap: 4px;
}

.question-equation {
  font-size: 1.85rem;
  font-weight: 900;
  color: #2e1738;
  letter-spacing: 1px;
  line-height: 1.2;
}
.question-equation .target-unknown {
  color: #e61f67;
  display: inline-block;
  animation: bounceUnknown 1.2s infinite ease-in-out;
}
@keyframes bounceUnknown {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.combo-badge {
  background: linear-gradient(135deg, #ff9f1c, #ff3864);
  color: #fff;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 900;
  box-shadow: 0 3px 8px rgba(255, 56, 100, 0.35);
  display: none;
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes popIn {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* 糖果雨核心機台 (結合落糖畫布與底部果凍大鍵盤) */
.arcade-cabinet {
  width: 100%;
  background: #ffffff;
  border-radius: 26px;
  border: 4px solid #ffbed6;
  box-shadow: 0 12px 35px rgba(255, 107, 157, 0.22);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 遊戲畫布與危機警戒線容器 (機台上半部螢幕) */
.canvas-wrapper {
  width: 100%;
  position: relative;
  background: rgba(255, 255, 255, 0.95);
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: pointer;
}

/* 警戒線光效 */
.danger-warning-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 50px;
  background: linear-gradient(180deg, rgba(255, 51, 85, 0.25) 0%, transparent 100%);
  pointer-events: none;
  display: none;
  animation: dangerPulse 0.8s infinite alternate;
}
@keyframes dangerPulse {
  from { opacity: 0.3; }
  to { opacity: 0.85; }
}

/* 糖果雨倒數進度條 */
.rain-timer-bar {
  position: absolute;
  top: 0;
  left: 0;
  height: 5px;
  background: #3bb2ff;
  width: 100%;
  transition: width 0.1s linear;
  z-index: 5;
}

/* 落下欄位最下方的超大 Q 萌果凍鍵盤 */
.virtual-keypad-panel {
  width: 100%;
  background: linear-gradient(180deg, #fff4f8 0%, #ffe9f2 100%);
  border-top: none;
  padding: 10px 10px 14px;
  transition: all 0.25s ease-in-out;
}

.virtual-keypad-panel.hidden {
  display: none;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

/* 超大防誤觸果凍糖果按鈕 */
.key-btn {
  height: 64px;
  min-height: 64px;
  border-radius: 18px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  font-family: inherit;
  font-size: 2.1rem;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* 頂部高光果凍弧光 */
.key-btn::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 12%;
  width: 76%;
  height: 36%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.65) 0%, rgba(255, 255, 255, 0.08) 100%);
  border-radius: 12px;
  pointer-events: none;
}

.key-btn:active, .key-btn.pressed {
  transform: translateY(6px) scale(0.97);
  filter: brightness(0.95);
}

/* 繽紛糖果色彩配置 */
.key-btn.candy-1 {
  background: linear-gradient(180deg, #ff6b8b 0%, #ee3a64 100%);
  color: #ffffff;
  box-shadow: 0 6px 0 #b8173d, 0 8px 14px rgba(238, 58, 100, 0.3);
}
.key-btn.candy-1:active, .key-btn.candy-1.pressed {
  box-shadow: 0 1px 0 #b8173d;
}

.key-btn.candy-2 {
  background: linear-gradient(180deg, #ff9f43 0%, #ee7d11 100%);
  color: #ffffff;
  box-shadow: 0 6px 0 #ba5b06, 0 8px 14px rgba(238, 125, 17, 0.3);
}
.key-btn.candy-2:active, .key-btn.candy-2.pressed {
  box-shadow: 0 1px 0 #ba5b06;
}

.key-btn.candy-3 {
  background: linear-gradient(180deg, #ffd32a 0%, #f5ba00 100%);
  color: #4a3400;
  box-shadow: 0 6px 0 #bf9000, 0 8px 14px rgba(245, 186, 0, 0.3);
}
.key-btn.candy-3:active, .key-btn.candy-3.pressed {
  box-shadow: 0 1px 0 #bf9000;
}

.key-btn.candy-4 {
  background: linear-gradient(180deg, #2ed573 0%, #17b357 100%);
  color: #ffffff;
  box-shadow: 0 6px 0 #0f8f43, 0 8px 14px rgba(23, 179, 87, 0.3);
}
.key-btn.candy-4:active, .key-btn.candy-4.pressed {
  box-shadow: 0 1px 0 #0f8f43;
}

.key-btn.candy-5 {
  background: linear-gradient(180deg, #38b6ff 0%, #1e90ff 100%);
  color: #ffffff;
  box-shadow: 0 6px 0 #0b6ecc, 0 8px 14px rgba(30, 144, 255, 0.3);
}
.key-btn.candy-5:active, .key-btn.candy-5.pressed {
  box-shadow: 0 1px 0 #0b6ecc;
}

.key-btn.candy-6 {
  background: linear-gradient(180deg, #a55eea 0%, #8833e2 100%);
  color: #ffffff;
  box-shadow: 0 6px 0 #681fbf, 0 8px 14px rgba(136, 51, 226, 0.3);
}
.key-btn.candy-6:active, .key-btn.candy-6.pressed {
  box-shadow: 0 1px 0 #681fbf;
}

.key-btn.candy-7 {
  background: linear-gradient(180deg, #ff4785 0%, #db1b5f 100%);
  color: #ffffff;
  box-shadow: 0 6px 0 #a80f44, 0 8px 14px rgba(219, 27, 95, 0.3);
}
.key-btn.candy-7:active, .key-btn.candy-7.pressed {
  box-shadow: 0 1px 0 #a80f44;
}

.key-btn.candy-8 {
  background: linear-gradient(180deg, #ffa801 0%, #e88600 100%);
  color: #ffffff;
  box-shadow: 0 6px 0 #b36300, 0 8px 14px rgba(232, 134, 0, 0.3);
}
.key-btn.candy-8:active, .key-btn.candy-8.pressed {
  box-shadow: 0 1px 0 #b36300;
}

.key-btn.candy-9 {
  background: linear-gradient(180deg, #00d2d3 0%, #01a3a4 100%);
  color: #ffffff;
  box-shadow: 0 6px 0 #007778, 0 8px 14px rgba(1, 163, 164, 0.3);
}
.key-btn.candy-9:active, .key-btn.candy-9.pressed {
  box-shadow: 0 1px 0 #007778;
}

.key-btn.candy-0 {
  background: linear-gradient(180deg, #ffffff 0%, #f0f3fa 100%);
  color: #3b1d44;
  box-shadow: 0 6px 0 #cbcfdb, 0 8px 14px rgba(0, 0, 0, 0.1);
}
.key-btn.candy-0:active, .key-btn.candy-0.pressed {
  box-shadow: 0 1px 0 #cbcfdb;
}

/* 清空與退格鍵特殊樣式 (雙行大字體清晰易懂) */
.key-btn.clear-key {
  background: linear-gradient(180deg, #fff0da 0%, #fedbb4 100%);
  border-color: #ffd494;
  color: #b35600;
  box-shadow: 0 6px 0 #d9994c, 0 8px 14px rgba(217, 153, 76, 0.25);
}
.key-btn.clear-key:active, .key-btn.clear-key.pressed {
  box-shadow: 0 1px 0 #d9994c;
}

.key-btn.back-key {
  background: linear-gradient(180deg, #eef2ff 0%, #dbe4ff 100%);
  border-color: #bfd2ff;
  color: #2f52ba;
  box-shadow: 0 6px 0 #8fa8e8, 0 8px 14px rgba(143, 168, 232, 0.25);
}
.key-btn.back-key:active, .key-btn.back-key.pressed {
  box-shadow: 0 1px 0 #8fa8e8;
}

.key-label-sub {
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1;
  opacity: 0.9;
  margin-bottom: 2px;
}
.key-label-main {
  font-size: 1.6rem;
  font-weight: 900;
  line-height: 1;
}

/* 鍵盤按鍵開關按鈕啟動狀態樣式 */
.circle-btn.active {
  background: #ff4b8b;
  color: #ffffff;
  border-color: #ffffff;
}

/* 題目輸入框狀態樣式 */
.target-unknown.typing {
  background: #ffe8f2;
  border: 2px dashed #ff3377;
  border-radius: 10px;
  padding: 0 8px;
  min-width: 44px;
  display: inline-block;
  text-align: center;
  color: #ff1f6d;
}

.target-unknown.correct-flash {
  background: #d4fcd6;
  border: 2px solid #2ec4b6;
  color: #1b8a5a;
  animation: popSuccess 0.4s ease-out;
}

.target-unknown.wrong-shake {
  background: #ffe0e6;
  border: 2px solid #ff3366;
  color: #d81159;
  animation: shakeWrong 0.4s ease-in-out;
}

@keyframes popSuccess {
  0% { transform: scale(0.9); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

@keyframes shakeWrong {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* 底部操作與道具工具列 */
.bottom-toolbar {
  width: 100%;
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.item-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  background: #ffffff;
  border: 2px solid #ffccd9;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  transition: all 0.15s;
  position: relative;
}
.item-btn:hover {
  background: #fff4f7;
  transform: translateY(-2px);
}
.item-btn:active {
  transform: translateY(1px);
}
.item-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.item-icon {
  font-size: 1.4rem;
  line-height: 1.1;
}
.item-name {
  font-size: 0.7rem;
  font-weight: 800;
  color: #6d4b7c;
  margin-top: 2px;
}
.item-count {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ff3377;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 900;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}

/* 彈出視窗 (Modal 系統) */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(45, 18, 55, 0.65);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.hidden {
  display: none !important;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  border-radius: 28px;
  border: 4px solid #ffbed6;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  padding: 22px 18px;
  text-align: center;
  position: relative;
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;
  box-sizing: border-box;
}

.modal-card::-webkit-scrollbar {
  width: 6px;
}
.modal-card::-webkit-scrollbar-track {
  background: #fff0f5;
  border-radius: 6px;
}
.modal-card::-webkit-scrollbar-thumb {
  background: #ffb3c6;
  border-radius: 6px;
}
.modal-card::-webkit-scrollbar-thumb:hover {
  background: #ff4b8b;
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-mascot {
  font-size: 3.5rem;
  margin-bottom: 6px;
  animation: bounceMascot 2s infinite ease-in-out;
}
@keyframes bounceMascot {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.modal-title {
  font-size: 1.6rem;
  font-weight: 900;
  color: #ff3377;
  margin-bottom: 6px;
}
.modal-subtitle {
  font-size: 0.9rem;
  color: #72507e;
  margin-bottom: 18px;
  line-height: 1.4;
}

/* 遊戲模式卡片選擇區 */
.mode-selection-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}

.mode-card {
  background: linear-gradient(135deg, #fff7fb 0%, #fff0f5 100%);
  border: 2px solid #ffd4e5;
  border-radius: 18px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
  box-shadow: 0 4px 10px rgba(255, 107, 157, 0.08);
}
.mode-card:hover {
  border-color: #ff508c;
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(255, 80, 140, 0.2);
}
.mode-card.selected {
  background: linear-gradient(135deg, #ffe0ed 0%, #ffd0e3 100%);
  border-color: #ff2a74;
  box-shadow: 0 6px 16px rgba(255, 42, 116, 0.28);
}
.mode-card-icon {
  font-size: 2.2rem;
  flex-shrink: 0;
}
.mode-card-info h4 {
  font-size: 1.05rem;
  font-weight: 900;
  color: #3b1747;
}
.mode-card-info p {
  font-size: 0.78rem;
  color: #785885;
  margin-top: 2px;
}

/* 果凍大按鈕 */
.jelly-btn {
  width: 100%;
  background: linear-gradient(180deg, #ff6596 0%, #e82e6c 100%);
  color: #ffffff;
  border: none;
  border-radius: 20px;
  padding: 14px 20px;
  font-size: 1.2rem;
  font-weight: 900;
  letter-spacing: 1px;
  cursor: pointer;
  box-shadow: var(--jelly-btn-shadow);
  transition: all 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.jelly-btn:active {
  transform: translateY(4px);
  box-shadow: var(--jelly-btn-active);
}
.jelly-btn.btn-secondary {
  background: linear-gradient(180deg, #6c8aff 0%, #4662d9 100%);
  box-shadow: 0 6px 0 #324bb3, 0 8px 16px rgba(0, 0, 0, 0.15);
}
.jelly-btn.btn-secondary:active {
  box-shadow: 0 2px 0 #324bb3, 0 3px 6px rgba(0, 0, 0, 0.2);
}
.jelly-btn.btn-outline {
  background: #ffffff;
  color: #553366;
  border: 2px solid #eed6e5;
  box-shadow: 0 4px 10px rgba(0,0,0,0.06);
}
.jelly-btn.btn-return-hub {
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  color: #92400e;
  border: 2px solid #f59e0b;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.25);
  font-weight: 900;
  margin-top: 10px;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}
.jelly-btn.btn-return-hub:hover {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.4);
}

/* 結算分析成績報告卡片 */
.result-stats-card {
  background: #fdf5f9;
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 16px;
  border: 2px dashed #ffb4cf;
}
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #f2e2eb;
  font-size: 0.88rem;
  font-weight: 700;
  color: #593563;
}
.result-row:last-child {
  border-bottom: none;
}
.result-highlight {
  font-size: 1.15rem;
  font-weight: 900;
  color: #e61f67;
}

.weakness-box {
  text-align: left;
  background: #fff;
  border-radius: 14px;
  padding: 10px 12px;
  margin-top: 10px;
  border: 1px solid #fed2e2;
}
.weakness-title {
  font-size: 0.8rem;
  font-weight: 800;
  color: #e0246a;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
}
.weakness-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.weak-tag {
  background: #ffe3ed;
  color: #b51750;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 900;
}

/* 點子陣列視覺提示 Modal (幫助低年級具象化乘法) */
.dot-matrix-container {
  background: #ffffff;
  border-radius: 16px;
  padding: 16px;
  margin: 12px 0;
  border: 2px solid #ffd6e7;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.dot-grid {
  display: grid;
  gap: 6px;
  padding: 8px;
  background: #fff6fa;
  border-radius: 12px;
}
.candy-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ff508c;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.2);
}

/* 自訂模式複選框樣式 */
.number-filter-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0;
}
.num-btn {
  padding: 8px 4px;
  background: #ffffff;
  border: 2px solid #ffd2e2;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 900;
  color: #553366;
  cursor: pointer;
  transition: all 0.15s;
}
.num-btn.active {
  background: #ff4785;
  color: #ffffff;
  border-color: #d81159;
}

/* RWD 響應式優化 */
@media (max-height: 700px) {
  .app-container {
    padding: 4px 8px 10px;
  }
  .mascot-box {
    width: 46px;
    height: 46px;
    font-size: 1.8rem;
  }
  .question-equation {
    font-size: 1.55rem;
  }
  .stats-panel {
    padding: 6px 12px;
  }
  .bottom-toolbar {
    margin-top: 6px;
  }
}

/* 平板與橫/直向觸控螢幕優化 (超大果凍按鍵防誤觸) */
@media (min-width: 500px) {
  .app-container {
    max-width: 580px;
  }
  .key-btn {
    height: 74px;
    min-height: 74px;
    font-size: 2.35rem;
    border-radius: 20px;
  }
  .keypad-grid {
    gap: 12px;
  }
  .key-label-sub {
    font-size: 0.85rem;
  }
  .key-label-main {
    font-size: 1.85rem;
  }
  .question-equation {
    font-size: 2.15rem;
  }
}

/* ==================== 學生身分登錄卡片 (登錄全班英雄榜) ==================== */
.player-profile-card {
  background: linear-gradient(135deg, #fff7fa 0%, #fff0f5 100%);
  border: 2px dashed #ff99bb;
  border-radius: 18px;
  padding: 10px 12px;
  margin: 8px 0 12px;
  text-align: left;
  box-shadow: 0 4px 10px rgba(255, 75, 139, 0.08);
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.profile-card-header {
  font-size: 0.86rem;
  font-weight: 800;
  color: #d81159;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.profile-input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  width: 100%;
  box-sizing: border-box;
}

.profile-field {
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.profile-field.field-full {
  grid-column: 1 / -1;
}

.profile-field label {
  font-size: 0.76rem;
  font-weight: 800;
  color: #773355;
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 3px;
}

.label-optional {
  font-size: 0.72rem;
  color: #995577;
  font-weight: 600;
  margin-left: 2px;
}

.profile-field input {
  width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
  background: #ffffff;
  border: 2px solid #ffccd9;
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 0.95rem;
  font-weight: 800;
  text-align: center;
  color: #331122;
  outline: none;
  height: 38px;
  transition: all 0.2s ease;
  user-select: text;
  -webkit-user-select: text;
}

.profile-field input[type="number"]::-webkit-outer-spin-button,
.profile-field input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.profile-field input[type="number"] {
  -moz-appearance: textfield;
}

.profile-field input:focus {
  border-color: #ff3377;
  background: #fffdfd;
  box-shadow: 0 0 0 3px rgba(255, 51, 119, 0.2);
}

.profile-field input::placeholder {
  color: #c9a4b0;
  font-weight: 600;
  font-size: 0.85rem;
}

.profile-error-msg {
  font-size: 0.78rem;
  color: #d81159;
  font-weight: 800;
  margin-top: 6px;
  background: #ffe8ee;
  border: 1px solid #ffccd9;
  border-radius: 8px;
  padding: 4px 8px;
  text-align: center;
}

/* ==================== 結算頁面雲端排名徽章 ==================== */
.cloud-rank-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #fff5f8, #f0f7ff);
  border: 2px solid #ffd4e0;
  border-radius: 14px;
  padding: 8px 12px;
  margin-top: 10px;
  box-shadow: 0 4px 10px rgba(255, 110, 160, 0.12);
}

.cloud-rank-badge .cr-icon {
  font-size: 1.8rem;
  line-height: 1;
}

.cloud-rank-badge .cr-info {
  text-align: left;
  flex: 1;
}

.cloud-rank-badge .cr-title {
  font-size: 0.74rem;
  color: #884466;
  font-weight: 800;
}

.cloud-rank-badge .cr-rank {
  font-size: 0.95rem;
  color: #d81159;
  font-weight: 900;
  margin-top: 2px;
}

/* ==================== 彈出視窗：全班英雄榜 ==================== */
.modal-leaderboard-card {
  max-width: 540px !important;
  width: 95% !important;
  padding: 18px 16px !important;
}

.lb-cloud-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff5f8;
  border: 1.5px solid #ffd4e0;
  border-radius: 12px;
  padding: 6px 10px;
  margin-bottom: 10px;
  font-size: 0.8rem;
  gap: 6px;
  flex-wrap: wrap;
}

.lb-cloud-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  color: #663344;
}

.cloud-indicator {
  font-size: 0.72rem;
  line-height: 1;
}

.cloud-indicator.online {
  color: #2ec4b6;
}

.cloud-indicator.offline {
  color: #a0aec0;
}

.cloud-indicator.syncing {
  color: #ffb703;
  animation: pulseSync 1s infinite alternate;
}

@keyframes pulseSync {
  from { opacity: 0.4; }
  to { opacity: 1; }
}

.lb-cloud-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lb-mini-btn {
  background: #ffffff;
  border: 1.5px solid #ffccd9;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.76rem;
  font-weight: 800;
  color: #d81159;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transition: all 0.2s ease;
}

.lb-mini-btn:hover {
  background: #ff4b8b;
  color: #ffffff;
  border-color: #ff4b8b;
}

.lb-mini-btn.btn-sheet {
  background: #eef8f2;
  border-color: #bbf0d0;
  color: #1a7f4b;
}

.lb-mini-btn.btn-sheet:hover {
  background: #1a7f4b;
  color: #ffffff;
  border-color: #1a7f4b;
}

.leaderboard-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.lb-tab-btn {
  flex: 1;
  padding: 8px 10px;
  border-radius: 12px;
  border: 2px solid #ffd4e0;
  background: #ffffff;
  font-size: 0.88rem;
  font-weight: 900;
  color: #774466;
  cursor: pointer;
  transition: all 0.2s ease;
}

.lb-tab-btn.active {
  background: linear-gradient(135deg, #ff4b8b 0%, #ff7aa2 100%);
  color: #ffffff;
  border-color: #ff4b8b;
  box-shadow: 0 4px 10px rgba(255, 75, 139, 0.3);
}

.leaderboard-table-container {
  max-height: 46vh;
  overflow-y: auto;
  border: 2px solid #ffdce6;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.04);
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.leaderboard-table th {
  position: sticky;
  top: 0;
  background: #ffeaf1;
  color: #b51750;
  font-weight: 900;
  padding: 8px 6px;
  border-bottom: 2px solid #ffd0de;
  z-index: 2;
  font-size: 0.8rem;
}

.leaderboard-table td {
  padding: 8px 6px;
  text-align: center;
  border-bottom: 1px solid #fff0f5;
  color: #4a223a;
  font-weight: 700;
}

.leaderboard-table tr:hover {
  background: #fff9fb;
}

.leaderboard-table tr.my-rank {
  background: #fff2d6 !important;
  font-weight: 900;
}

.rank-badge {
  display: inline-block;
  min-width: 24px;
  font-weight: 900;
}

.rank-badge.rank-1 {
  color: #e67e00;
  font-size: 1.15rem;
}

.rank-badge.rank-2 {
  color: #718096;
  font-size: 1.1rem;
}

.rank-badge.rank-3 {
  color: #a16207;
  font-size: 1.05rem;
}

.lb-loading {
  padding: 24px !important;
  color: #884466;
  font-weight: 800;
}

/* ==================== 彈出視窗：雲端試算表設定 ==================== */
.modal-setup-card {
  max-width: 480px !important;
  width: 95% !important;
  text-align: left;
}

.cloud-setup-content {
  margin: 10px 0;
}

.setup-field {
  margin-bottom: 12px;
}

.setup-field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 800;
  color: #552244;
  margin-bottom: 4px;
}

.setup-field input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 2px solid #ffccd9;
  border-radius: 10px;
  font-size: 0.85rem;
  font-family: Consolas, Monaco, monospace;
  color: #331122;
  outline: none;
  transition: all 0.2s ease;
}

.setup-field input:focus {
  border-color: #ff3377;
  box-shadow: 0 0 0 3px rgba(255, 51, 119, 0.2);
}

.field-tip {
  font-size: 0.72rem;
  color: #885577;
  margin-top: 3px;
  display: block;
}

.setup-test-box {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  padding: 8px 12px;
  background: #fff7fa;
  border-radius: 12px;
  border: 1px dashed #ff99bb;
}

.setup-test-box .jelly-btn {
  padding: 6px 14px;
  font-size: 0.82rem;
  min-height: auto;
  box-shadow: 0 4px 0 #cc1144;
}

.setup-test-result {
  font-size: 0.82rem;
  font-weight: 800;
  color: #774466;
  flex: 1;
}

.setup-test-result.success {
  color: #1a7f4b;
}

.setup-test-result.error {
  color: #d81159;
}

.setup-help-guide {
  background: #f8f9ff;
  border: 1.5px solid #dce4ff;
  border-radius: 12px;
  padding: 10px 14px;
  margin-top: 10px;
  font-size: 0.78rem;
  color: #334466;
}

.setup-help-guide h4 {
  margin: 0 0 6px 0;
  color: #2b3a67;
  font-size: 0.84rem;
}

.setup-help-guide ol {
  padding-left: 18px;
  margin: 0;
  line-height: 1.5;
}
