:root {
  --wood-dark: #3e1b05;
  --wood-mid: #8b4513;
  --wood-light: #f5cd79;
  --primary-gold: #f1c40f;
  --accent-orange: #ff793f;
  --fever-color: #ff3838;
  --text-main: #2f3542;
  --font-game: 'Fredoka', 'Zen Maru Gothic', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  --font-num: 'Outfit', 'Fredoka', sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1e272e;
  font-family: var(--font-game);
  color: var(--text-main);
}

#gameCanvasContainer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  overflow: hidden;
}

#threeCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* 🌟 大畫面半透明淡雅背景分數浮水印 (3D 天空背景完美融合) */
#bgBigScoreOverlay {
  position: absolute;
  top: 14%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  pointer-events: none;
  font-family: var(--font-num);
  font-size: clamp(80px, 12vw, 150px);
  font-weight: 900;
  color: rgba(255, 255, 255, 0.18);
  letter-spacing: 4px;
  text-shadow: 0 4px 18px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  white-space: nowrap;
}

#bgBigScoreOverlay.fever {
  color: rgba(255, 215, 0, 0.38);
  text-shadow: 0 0 30px rgba(255, 215, 0, 0.6);
  transform: translateX(-50%) scale(1.05);
}

/* 頂部懸浮工具列 */
.top-floating-bar {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 5;
  background: rgba(30, 15, 5, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 8px 18px;
  border-radius: 30px;
  border: 2px solid rgba(255, 215, 0, 0.4);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.top-title {
  font-size: 16px;
  font-weight: 900;
  color: #ffd32a;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 8px;
  border-right: 1.5px solid rgba(255, 255, 255, 0.2);
}

.header-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 800;
  font-family: var(--font-game);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s ease;
}

.header-btn:hover {
  background: rgba(255, 215, 0, 0.3);
  border-color: #ffd32a;
  transform: translateY(-2px);
}

/* 左上角精緻木紋 HUD 儀表板 */
.hud-container {
  position: absolute;
  top: 18px;
  left: 20px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.hud-badge {
  background: linear-gradient(180deg, #f5cd79 0%, #e67e22 100%);
  border: 3px solid var(--wood-dark);
  border-radius: 16px;
  padding: 6px 14px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35), inset 0 2px 4px #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 175px;
}

.hud-label {
  font-size: 11px;
  font-weight: 900;
  color: var(--wood-dark);
  letter-spacing: 0.5px;
}

.hud-value {
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

.hud-stage-pill {
  background: linear-gradient(135deg, #0984e3 0%, #6c5ce7 100%);
  border: 2px solid #fff;
  border-radius: 14px;
  padding: 4px 10px;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}

/* 右側即時連擊 (Combo) 浮動徽章 */
.combo-badge-container {
  position: absolute;
  top: 18px;
  right: 20px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
}

.combo-card {
  background: linear-gradient(135deg, #ff7675 0%, #d63031 100%);
  border: 3px solid #fff;
  border-radius: 18px;
  padding: 6px 16px;
  color: #fff;
  text-align: center;
  box-shadow: 0 6px 18px rgba(214, 48, 49, 0.45);
  transform-origin: right center;
  transition: transform 0.1s ease;
  display: none;
}

.combo-card.active {
  display: block;
  animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.combo-num {
  font-family: var(--font-num);
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.combo-text {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 1px;
  opacity: 0.9;
}

/* Fever 雙倍狂熱進度條 */
.fever-bar-container {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: min(420px, 80vw);
  height: 16px;
  background: rgba(0, 0, 0, 0.55);
  border: 2.5px solid #fff;
  border-radius: 12px;
  overflow: hidden;
  z-index: 5;
  pointer-events: none;
  display: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

.fever-bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #f1c40f 0%, #ff7675 50%, #e84393 100%);
  box-shadow: 0 0 12px #f1c40f;
  transition: width 0.05s linear;
}

/* 操作提示浮動欄 (右上角側邊欄) */
.controls-hint {
  position: absolute;
  top: 90px;
  right: 20px;
  background: rgba(30, 15, 5, 0.88);
  border: 2px solid rgba(255, 209, 59, 0.45);
  border-radius: 16px;
  padding: 10px 14px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 4;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}

.controls-hint-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  white-space: nowrap;
}

.key-badge {
  background: linear-gradient(180deg, #ffffff 0%, #dfe6e9 100%);
  color: #2d3436;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 900;
  font-family: var(--font-num);
  font-size: 12px;
  border: 1.5px solid #b2bec3;
  box-shadow: 0 2px 0 #636e72;
}

/* 遊戲彈窗與選單 (Overlay) */
.game-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(10, 5, 2, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
  padding: 20px;
  text-align: center;
  transition: opacity 0.3s ease;
}

.game-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: linear-gradient(180deg, #fffdf7 0%, #fff3d6 60%, #ffeaa7 100%);
  border: 8px solid var(--wood-dark);
  border-radius: 32px;
  padding: 26px 36px;
  max-width: 760px;
  width: 94%;
  color: var(--text-main);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.9), inset 0 4px 8px #ffffff, inset 0 -4px 8px rgba(93, 64, 55, 0.2);
  animation: popIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  position: relative;
}

/* 🌟 大螢幕旗艦雙欄開始選單 (Widescreen Grand Start Menu) */
.modal-card-large {
  max-width: 1240px;
  width: 92vw;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 42px;
  border-radius: 36px;
  border-width: 10px;
}

.modal-card-large::-webkit-scrollbar {
  width: 8px;
}
.modal-card-large::-webkit-scrollbar-thumb {
  background: #deb887;
  border-radius: 4px;
}

.start-dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 22px;
  margin: 14px 0 18px;
  text-align: left;
}

.dashboard-panel {
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 3px solid #deb887;
  border-radius: 22px;
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.05);
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 900;
  color: #873600;
  border-bottom: 2px dashed #deb887;
  padding-bottom: 6px;
}

.stage-roadmap-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stage-roadmap-card {
  background: #ffffff;
  border: 2px solid #e0c9a6;
  border-radius: 14px;
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: all 0.15s ease;
}

.stage-roadmap-card:hover {
  border-color: #e67e22;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(230, 126, 34, 0.2);
}

.stage-card-title {
  font-size: 13.5px;
  font-weight: 900;
  color: #d35400;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stage-card-desc {
  font-size: 11px;
  font-weight: 600;
  color: #7f8c8d;
}

.controls-card-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.controls-card-item {
  background: #ffffff;
  border: 2px solid #e0c9a6;
  border-radius: 12px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 800;
  color: #5d4037;
}

.item-guide-grid-large {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.guide-item-large {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 248, 235, 0.95) 100%);
  border: 3px solid #deb887;
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 5px 14px rgba(0,0,0,0.06), inset 0 1px 2px #fff;
  transition: transform 0.15s ease;
}

.guide-item-large:hover {
  transform: translateY(-2px);
  border-color: #e67e22;
  box-shadow: 0 8px 20px rgba(230, 126, 34, 0.2);
}

.guide-icon-large {
  font-size: 34px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  filter: drop-shadow(0 3px 6px rgba(0,0,0,0.18));
}

.modal-title {
  font-size: 36px;
  font-weight: 900;
  color: #d35400;
  text-shadow: 3px 3px 0 #ffffff, 4px 4px 0 #bdc3c7;
  margin-bottom: 4px;
  letter-spacing: 1px;
}

.modal-subtitle {
  font-size: 14.5px;
  font-weight: 700;
  color: #6d4c2d;
  margin-bottom: 12px;
  line-height: 1.5;
}

.gameover-score-box {
  background: #ffffff;
  border: 4px dashed #e67e22;
  border-radius: 20px;
  padding: 16px 24px;
  margin: 14px 0;
  box-shadow: inset 0 3px 8px rgba(0,0,0,0.06);
}

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  margin-bottom: 6px;
  font-weight: 700;
  color: #5d4037;
}

.score-row span:last-child {
  font-family: var(--font-num);
}

.score-row.final {
  font-size: 32px;
  color: #e74c3c;
  font-weight: 900;
  border-top: 3px solid #f1f2f6;
  padding-top: 8px;
  margin-top: 8px;
  text-shadow: 1px 1px 0 #fff;
}

/* 🎖️ 銅牌、銀牌、金牌、白金、鑽石、鴨神全套段位稱號勳章樣式 */
.rank-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 34px;
  border-radius: 28px;
  margin: 10px 0;
  border: 4px solid #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  animation: rankPulse 2.2s infinite ease-in-out;
}

.rank-badge-medal {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 1px;
  text-transform: uppercase;
  opacity: 0.95;
}

.rank-badge-title {
  font-size: 21px;
  font-weight: 900;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.35);
}

.rank-badge-desc {
  font-size: 12px;
  font-weight: 700;
  opacity: 0.92;
}

/* 🌱 新手小幼鴨 */
.rank-rookie {
  background: linear-gradient(135deg, #a8e063 0%, #56ab2f 100%);
  color: #ffffff;
  border-color: #d4fc79;
  box-shadow: 0 6px 20px rgba(86, 171, 47, 0.4);
}

/* 🥉 銅牌 (Bronze) */
.rank-bronze {
  background: linear-gradient(135deg, #f39c12 0%, #d35400 50%, #8b4513 100%);
  color: #ffffff;
  border-color: #f5cd79;
  box-shadow: 0 6px 22px rgba(211, 84, 0, 0.45);
  text-shadow: 0 2px 4px rgba(93, 33, 0, 0.5);
}

/* 🥈 銀牌 (Silver) */
.rank-silver {
  background: linear-gradient(135deg, #f5f6fa 0%, #718093 50%, #2f3640 100%);
  color: #ffffff;
  border-color: #ffffff;
  box-shadow: 0 6px 22px rgba(113, 128, 147, 0.5);
  text-shadow: 0 2px 4px rgba(0,0,0,0.45);
}

/* 🥇 金牌 (Gold) */
.rank-gold {
  background: linear-gradient(135deg, #fff9d2 0%, #f1c40f 35%, #e67e22 100%);
  color: #ffffff;
  border-color: #ffffff;
  box-shadow: 0 8px 26px rgba(241, 196, 15, 0.55);
  text-shadow: 0 2px 4px rgba(160, 82, 45, 0.6);
}

/* 💎 白金 (Platinum) */
.rank-platinum {
  background: linear-gradient(135deg, #e0f7fa 0%, #00cec9 45%, #0984e3 100%);
  color: #ffffff;
  border-color: #81ecec;
  box-shadow: 0 8px 28px rgba(0, 206, 201, 0.55);
  text-shadow: 0 2px 4px rgba(9, 132, 227, 0.6);
}

/* 👑 鑽石 (Diamond) */
.rank-diamond {
  background: linear-gradient(135deg, #f8a5c2 0%, #e056fd 45%, #686de0 100%);
  color: #ffffff;
  border-color: #ffcccc;
  box-shadow: 0 10px 32px rgba(224, 86, 253, 0.6);
  text-shadow: 0 2px 5px rgba(104, 109, 224, 0.7);
}

/* 🌌 鴨神・傳說級 (Godlike) */
.rank-god {
  background: linear-gradient(135deg, #ff9ff3 0%, #feca57 25%, #ff6b6b 50%, #48dbfb 75%, #1dd1a1 100%);
  background-size: 300% 300%;
  animation: rankRainbow 3s ease infinite, rankPulse 1.8s infinite ease-in-out;
  color: #ffffff;
  border-color: #ffffff;
  box-shadow: 0 12px 36px rgba(255, 107, 107, 0.65), inset 0 2px 8px rgba(255,255,255,0.6);
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}

@keyframes rankRainbow {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes rankPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

.action-btn {
  background: linear-gradient(180deg, #ff793f 0%, #e65100 100%);
  color: white;
  border: 4px solid #3e1b05;
  border-radius: 20px;
  padding: 12px 40px;
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  margin-top: 8px;
  box-shadow: 0 8px 0 #3e1b05, 0 16px 30px rgba(0,0,0,0.5), inset 0 2px 4px rgba(255,255,255,0.3);
  transition: all 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.8px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.4);
}

.action-btn:hover {
  background: linear-gradient(180deg, #ff8b57 0%, #ef6c00 100%);
  transform: translateY(-3px);
  box-shadow: 0 11px 0 #3e1b05, 0 20px 35px rgba(0,0,0,0.55), inset 0 2px 4px rgba(255,255,255,0.4);
}

.action-btn:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 #3e1b05, 0 6px 12px rgba(0,0,0,0.4);
}

.action-btn-large {
  font-size: 24px;
  padding: 16px 64px;
  border-radius: 24px;
  box-shadow: 0 10px 0 #3e1b05, 0 20px 40px rgba(0,0,0,0.5), inset 0 2px 4px rgba(255,255,255,0.4);
}

/* 📱 手機專屬人體工學雙手手把 (Dual-Thumb Cluster Touch Controls) */
.touch-controls {
  display: none;
  position: absolute;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  left: 0;
  width: 100%;
  padding: 0 calc(16px + env(safe-area-inset-right, 0px)) 0 calc(16px + env(safe-area-inset-left, 0px));
  justify-content: space-between;
  align-items: flex-end;
  z-index: 20;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-cluster {
  display: flex;
  gap: 12px;
  pointer-events: auto;
}

.touch-cluster-left {
  align-items: center;
}

.touch-cluster-right {
  align-items: center;
}

.touch-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(30, 15, 5, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 3px solid rgba(255, 255, 255, 0.7);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45), inset 0 2px 4px rgba(255, 255, 255, 0.35);
  transition: all 0.08s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.touch-icon {
  font-size: 24px;
  line-height: 1;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}

.touch-label {
  font-size: 11px;
  font-weight: 900;
  font-family: var(--font-main);
  color: rgba(255, 255, 255, 0.9);
  margin-top: 2px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.touch-btn-move {
  background: linear-gradient(135deg, rgba(84, 160, 255, 0.75) 0%, rgba(46, 134, 222, 0.85) 100%);
  border-color: #74b9ff;
}

.touch-btn-dash {
  background: linear-gradient(135deg, rgba(255, 159, 67, 0.85) 0%, rgba(238, 82, 83, 0.9) 100%);
  border-color: #ff9f43;
  width: 76px;
  height: 76px;
}

.touch-btn-jump {
  background: linear-gradient(135deg, rgba(29, 209, 161, 0.85) 0%, rgba(16, 172, 132, 0.9) 100%);
  border-color: #1dd1a1;
  width: 76px;
  height: 76px;
}

.touch-btn:active,
.touch-btn.active {
  transform: scale(0.90);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6), inset 0 3px 6px rgba(0, 0, 0, 0.4);
  filter: brightness(1.25);
}

@keyframes popIn {
  0% { transform: scale(0.8); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 960px) {
  .start-dashboard-grid { grid-template-columns: 1fr; gap: 14px; }
  .modal-card-large { width: 95vw; padding: 20px 22px; max-height: 94vh; }
  .item-guide-grid-large { grid-template-columns: 1fr; }
  .stage-roadmap-grid { grid-template-columns: repeat(2, 1fr); }
  .controls-card-list { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .touch-controls { display: flex; }
  .controls-hint { display: none; }
  .top-floating-bar {
    top: calc(10px + env(safe-area-inset-top, 0px));
    left: 10px;
    right: 10px;
    transform: none;
    padding: 6px 10px;
    gap: 6px;
    justify-content: space-between;
    width: calc(100% - 20px);
    max-width: 100%;
  }
  .top-title { font-size: 13px; }
  .header-btn { font-size: 11px; padding: 5px 8px; border-radius: 10px; }
  .hud-badge { min-width: 110px; padding: 4px 8px; }
  .hud-value { font-size: 15px; }
  .modal-card { width: 92vw; padding: 18px 16px; border-radius: 24px; border-width: 6px; }
  .modal-title { font-size: 26px !important; }
  .modal-subtitle { font-size: 13px !important; }
  .stage-roadmap-grid { grid-template-columns: 1fr; }
  .action-btn { padding: 12px 28px; font-size: 18px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .top-floating-bar { padding: 4px 10px; }
  .touch-btn { width: 62px; height: 62px; }
  .touch-icon { font-size: 20px; }
  .touch-label { font-size: 9.5px; }
  .modal-card { max-height: 96vh; overflow-y: auto; padding: 12px 18px; }
  .modal-title { font-size: 22px !important; }
}
