/* ════════════════════════════════════════════
   style.css — KK音標生存遊戲
   ════════════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.hidden {
  display: none !important;
}

body {
  overflow: hidden;
  background: #0a0a1a;            /* 深藍黑：電腦letterbox區域填色，與海洋主題呼應 */
  font-family: 'Segoe UI', 'Noto Sans TC', sans-serif;
  touch-action: none;
  /* iOS safe area：確保全螢幕不被缺口/工具列遮住 */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  width: 100vw;
  height: 100vh;
}

#game-canvas {
  position: fixed;
  /* width/height/top/left 由 JS resizeCanvas() 動態設定，填滿 viewport */
  display: block;
  touch-action: none;             /* 防止 iOS 雙擊放大 */
  -webkit-touch-callout: none;    /* 防止 iOS 長按選單 */
  -webkit-user-select: none;
  user-select: none;
  pointer-events: none;           /* 讓 touch 事件穿透到 joyZone */
  image-rendering: auto;          /* 縮放後保持清晰（不用 pixelated 避免鋸齒）*/
}

/* ── Overlay base（對齊畫布區域，由 JS --gx/--gy/--gw/--gh 控制）── */
.overlay {
  position: fixed;
  left:   var(--gx, 0px);
  top:    var(--gy, 0px);
  width:  var(--gw, 100vw);
  height: var(--gh, 100vh);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.overlay.hidden {
  display: none;
}

.overlay.active {
  display: flex;
}

/* ── HUD（頂部覆蓋層，支援多排自適應）─────── */
#hud {
  position: fixed;
  left:   var(--gx, 0px);   /* 對齊 canvas 左緣 */
  top:    var(--gy, 0px);   /* 對齊 canvas 頂緣 */
  width:  var(--gw, 100vw); /* 與 canvas 同寬 */
  height: auto;
  pointer-events: none;
  z-index: 7;
  display: flex;
  flex-direction: column;
}

#hud.hidden {
  display: none;
}

/* ── 第一排：HP / XP / 操控按鈕 ── */
#hud-row1 {
  display: flex;
  align-items: center;
  padding: clamp(5px, 1.1vh, 10px) clamp(8px, 2vw, 18px);
  gap: clamp(5px, 1.4vw, 12px);
  background: rgba(0, 0, 15, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  pointer-events: auto;
}

#hp-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

#xp-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.hud-label {
  font-size: clamp(0.9rem, 2.2vw, 1.2rem);
  line-height: 1;
  flex-shrink: 0;
}

#hp-bar-bg {
  flex: 1;
  min-width: 44px;
  height: clamp(9px, 1.5vh, 16px);
  background: rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  overflow: hidden;
}

#hp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #e74c3c, #ff6b6b);
  border-radius: 8px;
  transition: width 0.2s;
  width: 100%;
}

#hp-text {
  color: white;
  font-size: clamp(0.7rem, 1.6vw, 0.88rem);
  font-weight: bold;
  flex-shrink: 0;
  min-width: 28px;
}

#xp-bar-bg {
  flex: 1;
  min-width: 44px;
  height: clamp(9px, 1.5vh, 16px);
  background: rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  overflow: hidden;
}

#xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #6c5ce7, #a29bfe);
  border-radius: 8px;
  transition: width 0.3s;
  width: 0%;
}

#lv-display {
  color: #a29bfe;
  font-size: clamp(0.7rem, 1.6vw, 0.88rem);
  font-weight: bold;
  flex-shrink: 0;
  min-width: 36px;
}

/* 🔊 ⏸ 按鈕組 — 永遠靠右、不壓縮 */
#hud-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 4px;
}

.btn-pause {
  width: clamp(30px, 5vw, 38px);
  height: clamp(30px, 5vw, 38px);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.15);
  color: white;
  font-size: clamp(0.85rem, 2vw, 1rem);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: background 0.15s;
  flex-shrink: 0;
}

.btn-pause:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ── 第二排：計時 / 擊殺 ── */
#hud-row2 {
  display: flex;
  align-items: center;
  gap: clamp(10px, 3vw, 22px);
  padding: 3px clamp(8px, 2vw, 18px) 4px;
  background: rgba(0, 0, 10, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  pointer-events: none;
}

#timer-display {
  color: white;
  font-size: clamp(0.82rem, 1.9vw, 1rem);
  font-weight: 900;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.4);
}

#kill-count {
  color: #ffd32a;
  font-size: clamp(0.78rem, 1.8vw, 0.95rem);
  font-weight: bold;
}

/* ── Menu Screen ────────────────────────────── */
#screen-menu {
  background: linear-gradient(160deg, #0a1a3a, #0d3b6e, #155e8a);
  left: 0 !important;
  top: 0 !important;
  width: 100vw !important;
  height: calc(var(--svh, 1vh) * 100) !important; /* JS 動態量測的真實可視高度 */
  overflow-y: auto;
  justify-content: center !important;
  box-sizing: border-box;
}

.menu-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, calc(var(--svh, 1vh) * 2), 14px);
  width: 100%;
  max-width: 500px;
  padding: clamp(12px, calc(var(--svh, 1vh) * 3), 22px) clamp(16px, 4vw, 32px);
  box-sizing: border-box;
  background: rgba(10, 20, 50, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 24px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

/* Logo + 標題並排 */
.menu-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
}

.menu-title-wrap {
  text-align: left;
}

.logo {
  width: clamp(40px, calc(var(--svh, 1vh) * 7), 62px);
  height: clamp(40px, calc(var(--svh, 1vh) * 7), 62px);
  font-size: clamp(48px, calc(var(--svh, 1vh) * 8.5), 72px);
  line-height: 1;
  object-fit: contain;
  animation: float 3s ease-in-out infinite;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.title {
  font-size: clamp(1.1rem, calc(var(--svh, 1vh) * 3.5), 1.7rem);
  color: white;
  font-weight: 900;
  text-shadow: 0 0 20px rgba(162, 155, 254, 0.8);
  line-height: 1.1;
}

.menu-subtitle {
  font-size: clamp(0.65rem, calc(var(--svh, 1vh) * 1.8), 0.82rem);
  color: rgba(162, 210, 255, 0.7);
  margin-top: 3px;
}

/* 難度區塊 */
.menu-section {
  width: 100%;
}

.menu-section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: clamp(0.62rem, calc(var(--svh, 1vh) * 1.5), 0.75rem);
  color: rgba(255, 255, 255, 0.35);
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}
.menu-section-label::before,
.menu-section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.15);
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-14px); }
}

.diff-btns {
  display: flex;
  flex-direction: column;
  gap: 7px;
  justify-content: center;
  width: 100%;
}

.diff-btn {
  padding: clamp(4px, calc(var(--svh, 1vh) * 1), 7px) 12px;
  border-radius: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: clamp(0.68rem, calc(var(--svh, 1vh) * 2), 0.86rem);
  font-weight: bold;
  cursor: pointer;
  transition: 0.15s;
  touch-action: manipulation;
}

.diff-btn.active {
  background: #a29bfe;
  border-color: #a29bfe;
  color: #1a1a2e;
}

.diff-btn:hover:not(.active) {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
}

.btn-main {
  min-width: 180px;
  min-height: clamp(32px, calc(var(--svh, 1vh) * 6), 46px);
  padding: clamp(6px, calc(var(--svh, 1vh) * 1.8), 11px) 32px;
  font-size: clamp(0.85rem, calc(var(--svh, 1vh) * 2.8), 1.1rem);
  font-weight: 900;
  border: none;
  border-radius: 30px;
  background: linear-gradient(135deg, #fd79a8, #e84393);
  color: white;
  cursor: pointer;
  box-shadow: 0 6px 0 #a52d6e, 0 10px 25px rgba(232, 67, 147, 0.4);
  transition: transform 0.1s, box-shadow 0.1s;
  touch-action: manipulation;
}

.btn-main:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #a52d6e;
}

.btn-sub {
  min-width: 140px;
  min-height: clamp(28px, calc(var(--svh, 1vh) * 5.5), 40px);
  padding: clamp(5px, calc(var(--svh, 1vh) * 1.4), 9px) 22px;
  font-size: clamp(0.74rem, calc(var(--svh, 1vh) * 2.2), 0.92rem);
  font-weight: bold;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s;
}

.btn-sub:hover {
  background: rgba(255, 255, 255, 0.2);
}

.hs-text {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.9rem;
}

/* ── Quiz Overlay ───────────────────────────── */
#quiz-overlay {
  background: rgba(10, 10, 30, 0.92);
  backdrop-filter: blur(4px);
}

.quiz-card {
  background: white;
  border-radius: 24px;
  padding: 28px 32px;
  max-width: 420px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.quiz-badge {
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  color: white;
  padding: 6px 18px;
  border-radius: 20px;
  font-size: 1rem;
  font-weight: bold;
}

.quiz-hint {
  font-size: 0.9rem;
  color: #888;
}

.quiz-word {
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 900;
  color: #2d3436;
  letter-spacing: 3px;
}

.quiz-sound-btn {
  background: #dfe6e9;
  border: none;
  border-radius: 20px;
  padding: 8px 18px;
  font-size: 0.9rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s;
}

.quiz-sound-btn:hover {
  background: #b2bec3;
}

.quiz-opts {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.quiz-opt-btn {
  width: 100%;
  min-height: 56px;
  font-size: 1.1rem;
  font-weight: bold;
  border: 3px solid #dfe6e9;
  border-radius: 14px;
  background: white;
  color: #2d3436;
  cursor: pointer;
  transition: 0.15s;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.quiz-opt-btn .opt-cn {
  font-size: 1.3rem;
  color: #2d3436;
}

.quiz-opt-btn:hover {
  border-color: #6c5ce7;
  background: #f0eeff;
}

.quiz-opt-btn.correct {
  background: #00b894;
  border-color: #00b894;
  color: white;
}

.quiz-opt-btn.correct .opt-cn {
  color: white;
}

.quiz-opt-btn.wrong {
  background: #d63031;
  border-color: #d63031;
  color: white;
  animation: shake 0.4s;
}

.quiz-opt-btn.wrong .opt-cn {
  color: white;
}

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

.quiz-feedback {
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: bold;
}

.quiz-feedback.correct-fb {
  background: #d4edda;
  color: #155724;
}

.quiz-feedback.wrong-fb {
  background: #f8d7da;
  color: #721c24;
}

.quiz-feedback.hidden {
  display: none;
}

/* ── Upgrade Overlay ────────────────────────── */
#upgrade-overlay {
  background: rgba(10, 10, 30, 0.92);
  backdrop-filter: blur(4px);
  flex-direction: column;
  gap: 24px;
}

.upgrade-header {
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 900;
  color: white;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
}

.upgrade-cards {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0 16px;
}

.upgrade-card {
  width: clamp(130px, 28vw, 170px);
  padding: 18px 14px;
  border-radius: 20px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  touch-action: manipulation;
  border: 3px solid rgba(255, 255, 255, 0.2);
}

.upgrade-card:hover {
  transform: translateY(-6px) scale(1.04);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  border-color: white;
}

.uc-emoji {
  font-size: 2.5rem;
}

.uc-name {
  font-size: 1rem;
  font-weight: 900;
  color: white;
}

.uc-level {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 2px;
}

.uc-desc {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.4;
}

.uc-tier {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  align-self: center;
}

.tier-1 { background: rgba(255,255,255,0.22); color: rgba(255,255,255,0.9); }
.tier-2 { background: rgba(46,213,115,0.35); color: #7bed9f; border: 1px solid #7bed9f; }
.tier-3 { background: rgba(255,193,7,0.35); color: #ffd32a; border: 1px solid #ffd32a; }

/* ── Tier-2 / Tier-3 card glow animations ───── */
@keyframes tier2Pulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(0,0,0,0.4), 0 0 0px rgba(46,213,115,0); }
  50%       { box-shadow: 0 8px 24px rgba(0,0,0,0.4), 0 0 22px rgba(46,213,115,0.7); }
}
@keyframes tier3Pulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(0,0,0,0.4), 0 0 0px rgba(255,211,42,0); }
  50%       { box-shadow: 0 8px 24px rgba(0,0,0,0.4), 0 0 32px rgba(255,211,42,0.9); }
}
@keyframes tier3BorderSpin {
  0%   { border-color: rgba(255,211,42,0.7); }
  33%  { border-color: rgba(255,120,60,0.8); }
  66%  { border-color: rgba(255,80,200,0.8); }
  100% { border-color: rgba(255,211,42,0.7); }
}

.tier-card-2 {
  animation: tier2Pulse 1.8s ease-in-out infinite;
  border: 3px solid rgba(46,213,115,0.55) !important;
}
.tier-card-3 {
  animation: tier3Pulse 1.2s ease-in-out infinite, tier3BorderSpin 2.5s linear infinite;
  border: 3px solid rgba(255,211,42,0.7) !important;
}

.uc-req {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.65);
  background: rgba(0,0,0,0.25);
  border-radius: 8px;
  padding: 3px 8px;
  line-height: 1.4;
}

/* ── Custom Word Panel ──────────────────────── */
#custom-word-panel {
  background: rgba(5, 15, 40, 0.92);
  backdrop-filter: blur(6px);
}

.cw-card {
  background: #0d2a5e;
  border-radius: 24px;
  padding: 28px 24px 24px;
  max-width: 420px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  border: 2px solid rgba(100,180,255,0.3);
}

.cw-title {
  font-size: 1.3rem;
  font-weight: 900;
  color: white;
  text-align: center;
}

.cw-subtitle {
  font-size: 0.8rem;
  color: rgba(180,210,255,0.85);
  text-align: center;
  line-height: 1.5;
}

.cw-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.cw-empty {
  color: rgba(180,210,255,0.5);
  text-align: center;
  font-size: 0.85rem;
  padding: 16px 0;
}

.cw-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.08);
  border-radius: 12px;
  padding: 8px 12px;
}

.cw-speak {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0;
  opacity: 0.75;
  transition: opacity 0.15s;
}
.cw-speak:hover { opacity: 1; }

.cw-word {
  font-weight: 700;
  color: #7ecfff;
  font-size: 0.95rem;
  flex: 1;
}

.cw-cn {
  color: rgba(255,255,255,0.85);
  font-size: 0.9rem;
  flex: 1;
}

.cw-del {
  background: rgba(255,80,80,0.25);
  border: 1px solid rgba(255,80,80,0.4);
  color: #ff7675;
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: background 0.15s;
}
.cw-del:hover { background: rgba(255,80,80,0.45); }

.cw-add-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cw-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.cw-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 2px solid rgba(100,180,255,0.3);
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
.cw-input:focus { border-color: rgba(100,180,255,0.7); }
.cw-input::placeholder { color: rgba(255,255,255,0.4); }

.btn-small {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: none;
  background: #2ecc71;
  color: white;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-small:hover { background: #27ae60; }

/* ── 預設詞包區塊 ──────────────────────────── */


/* ── 匯入 / 匯出 ────────────────────────────── */
.cw-io-row {
  display: flex;
  gap: 8px;
}
.btn-io {
  flex: 1;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1.5px solid rgba(100,180,255,0.4);
  background: rgba(40,80,160,0.5);
  color: rgba(180,220,255,0.95);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-io:hover {
  background: rgba(60,110,200,0.7);
  border-color: rgba(100,180,255,0.7);
}
.btn-io-import {
  background: rgba(40,120,80,0.5);
  border-color: rgba(80,200,120,0.4);
  color: rgba(160,240,190,0.95);
}
.btn-io-import:hover {
  background: rgba(40,160,80,0.65);
  border-color: rgba(80,220,140,0.7);
}
.hidden-input { display: none; }

/* ── 批次匯入區 ───────────────────────────── */
.cw-import-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(0,0,0,0.25);
  border: 1.5px solid rgba(80,200,120,0.35);
  border-radius: 14px;
  padding: 14px;
}
.cw-import-hint {
  font-size: 0.8rem;
  color: rgba(180,240,200,0.85);
  font-weight: 600;
}
.cw-import-example {
  font-size: 0.78rem;
  color: rgba(140,210,170,0.7);
  font-family: monospace;
  line-height: 1.7;
  padding-left: 6px;
  border-left: 2px solid rgba(80,200,120,0.4);
}
.cw-import-text {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid rgba(80,200,120,0.4);
  background: rgba(255,255,255,0.08);
  color: white;
  font-size: 0.9rem;
  font-family: monospace;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.6;
}
.cw-import-text:focus { border-color: rgba(80,220,140,0.75); }
.cw-import-text::placeholder { color: rgba(255,255,255,0.3); }
.cw-import-actions {
  display: flex;
  gap: 8px;
}

/* ── 複習錯題面板 ────────────────────────── */
.rv-card {
  background: #0d2a5e;
  border-radius: 24px;
  padding: 28px 24px 24px;
  max-width: 420px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  border: 2px solid rgba(255,150,100,0.35);
}
.rv-title {
  font-size: 1.3rem;
  font-weight: 900;
  color: white;
  text-align: center;
}
.rv-subtitle {
  font-size: 0.8rem;
  color: rgba(255,200,180,0.8);
  text-align: center;
  line-height: 1.5;
}
.rv-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
}
.rv-empty {
  color: rgba(180,210,255,0.5);
  text-align: center;
  font-size: 0.9rem;
  padding: 20px 0;
}
.rv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,100,80,0.1);
  border: 1px solid rgba(255,120,80,0.2);
  border-radius: 12px;
  padding: 8px 12px;
}
.rv-badge {
  background: #c0392b;
  color: white;
  font-size: 0.72rem;
  font-weight: 800;
  border-radius: 8px;
  padding: 3px 7px;
  white-space: nowrap;
  min-width: 32px;
  text-align: center;
}
.rv-speak {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  padding: 0;
  opacity: 0.75;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.rv-speak:hover { opacity: 1; }
.rv-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.rv-word {
  font-weight: 700;
  color: #ffb07c;
  font-size: 0.95rem;
}
.rv-phon {
  font-size: 0.78rem;
  color: rgba(255,200,150,0.65);
}
.rv-cn {
  color: rgba(255,255,255,0.85);
  font-size: 0.9rem;
  flex-shrink: 0;
}
.rv-actions {
  display: flex;
  gap: 10px;
}
.btn-danger {
  flex: 1;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1.5px solid rgba(255,80,60,0.5);
  background: rgba(180,30,20,0.5);
  color: rgba(255,180,160,0.95);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger:hover { background: rgba(200,40,30,0.7); }

/* 選單上的錯題數徽章 */
.btn-review-menu {
  position: relative;
}
.rv-menu-badge {
  display: inline-block;
  background: #e74c3c;
  color: white;
  font-size: 0.75rem;
  font-weight: 800;
  border-radius: 10px;
  padding: 1px 7px;
  margin-left: 4px;
  vertical-align: middle;
}

/* Custom word quiz option style */
.opt-cn {
  font-size: 1.3rem;
  font-weight: 800;
  padding: 4px 0;
}

/* ── Game Over ───────────────────────────────── */
#screen-gameover {
  background: rgba(10, 10, 30, 0.95);
}

.go-card {
  background: white;
  border-radius: 24px;
  padding: 32px 36px;
  max-width: 380px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.go-title {
  font-size: 2rem;
  font-weight: 900;
  color: #d63031;
}

.go-stat {
  font-size: 1rem;
  color: #555;
  font-weight: bold;
}

.go-record {
  font-size: 1.3rem;
  font-weight: 900;
  color: #f39c12;
  animation: pulse 0.8s ease-in-out infinite;
}

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

.go-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

/* ── Game Clear ─────────────────────────────── */
.gc-card {
  background: linear-gradient(135deg, #fff9e6 0%, #fff3cc 100%);
  border-radius: 24px;
  padding: 32px 36px;
  max-width: 380px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  border: 3px solid #f1c40f;
}

.gc-crown {
  font-size: 3.5rem;
  animation: pulse 1s ease-in-out infinite;
}

.gc-title {
  font-size: 2rem;
  font-weight: 900;
  color: #e67e22;
}

.gc-subtitle {
  font-size: 1rem;
  color: #7f8c8d;
  font-weight: bold;
}

.gc-stat {
  font-size: 1rem;
  color: #555;
  font-weight: bold;
}

.gc-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
}

/* ── Touch Joystick ──────────────────────────── */
.joystick-zone {
  position: fixed;
  left:   0;
  top:    0;
  width:  100%;
  height: 100%;
  z-index: 100;
  touch-action: none; /* 阻止瀏覽器雙擊放大等預設行為 */
}

.joystick-zone.hidden {
  display: none;
}

.joystick-base {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.35);
  position: fixed;              /* 動態定位：由 JS 設定 left/top（相對螢幕） */
  transform: translate(-50%, -50%); /* 以圓心為基準 */
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;                   /* 預設隱藏，按下時才顯示 */
  transition: opacity 0.08s;
  pointer-events: none;         /* 讓觸控事件穿透到 zone */
}

.joystick-base.active {
  opacity: 1;
}

.joystick-knob {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  position: absolute;
  pointer-events: none;
  transition: none;
}

/* ── Word Reveal Overlay ─────────────────────── */
#word-reveal {
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(6px);
  animation: fadeInOverlay 0.3s ease;
}

@keyframes fadeInOverlay {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.wr-card {
  background: linear-gradient(135deg, rgba(13,59,110,0.95), rgba(21,94,138,0.95));
  border: 2px solid rgba(100, 200, 255, 0.4);
  border-radius: 28px;
  padding: 36px 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  box-shadow: 0 0 60px rgba(0, 150, 255, 0.3), 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.wr-correct {
  font-size: 1.4rem;
  font-weight: 900;
  color: #55efc4;
  text-shadow: 0 0 12px rgba(85, 239, 196, 0.5);
}

.wr-word {
  font-size: clamp(2.4rem, 8vw, 3.5rem);
  font-weight: 900;
  color: white;
  text-shadow: 0 0 24px rgba(255, 255, 255, 0.4);
  letter-spacing: 4px;
}

.wr-phonetic {
  font-size: clamp(1.1rem, 3.5vw, 1.5rem);
  color: rgba(180, 220, 255, 0.9);
  font-style: italic;
  letter-spacing: 2px;
}

.wr-chinese {
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 900;
  color: #74b9ff;
  text-shadow: 0 0 12px rgba(116, 185, 255, 0.4);
}

.wr-close-btn {
  margin-top: 10px;
  padding: 14px 42px;
  border-radius: 28px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  background: linear-gradient(135deg, #00b894, #00cec9);
  color: white;
  font-size: clamp(1rem, 3vw, 1.2rem);
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 4px 0 rgba(0, 100, 90, 0.6), 0 8px 20px rgba(0, 184, 148, 0.3);
  letter-spacing: 1px;
}

.wr-close-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 100, 90, 0.6);
}

.wr-close-btn:hover {
  background: linear-gradient(135deg, #00cec9, #00b894);
}

.wr-close-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ── Pause Overlay ────────────────────────────── */
#pause-overlay {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.pause-card {
  background: rgba(10, 26, 58, 0.96);
  border: 2px solid rgba(100, 200, 255, 0.4);
  border-radius: 24px;
  padding: clamp(24px, 4vh, 40px) clamp(28px, 5vw, 56px);
  text-align: center;
  color: white;
  box-shadow: 0 0 40px rgba(0, 100, 200, 0.3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  min-width: clamp(240px, 50vw, 340px);
}

.pause-title {
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  font-weight: 900;
  line-height: 1;
}

.pause-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.pause-btns .btn-main,
.pause-btns .btn-sub {
  width: 100%;
}

.pause-hint {
  font-size: clamp(0.75rem, 2vw, 0.88rem);
  color: rgba(180, 220, 255, 0.6);
}

/* ── 第三排：技能圖示（無技能時不佔空間）──── */
.upgrades-display {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 3px 10px 5px;
  background: rgba(0, 0, 0, 0.4);
  min-height: 0;
}

.hud-upg {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  padding: 2px 7px;
  font-size: 1rem;
  line-height: 1;
  color: white;
}

.hud-upg sub {
  font-size: 0.6rem;
  font-weight: 900;
  color: #ffeaa7;
  vertical-align: middle;
  margin-left: 1px;
}

/* ── 大魔王血條 ─────────────────────────────── */
.boss-hpbar {
  position: fixed;
  top: calc(var(--gy, 0px) + 94px); /* HUD 頂部三排之下 */
  left: calc(var(--gx, 0px) + var(--gw, 50vw) / 2);
  transform: translateX(-50%);
  background: rgba(0, 0, 20, 0.88);
  border: 2px solid rgba(255, 60, 60, 0.75);
  border-radius: 14px;
  padding: 8px 18px;
  min-width: 280px;
  max-width: 480px;
  z-index: 6;
  backdrop-filter: blur(6px);
  box-shadow: 0 0 24px rgba(255, 40, 40, 0.45), 0 2px 8px rgba(0,0,0,0.6);
  animation: boss-hpbar-appear 0.4s ease;
}

@keyframes boss-hpbar-appear {
  from { opacity: 0; transform: translateX(-50%) scale(0.85); }
  to   { opacity: 1; transform: translateX(-50%) scale(1); }
}

.boss-hpbar.hidden { display: none; }

.boss-hpbar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
}

.boss-hpbar-face {
  font-size: 30px;
  flex-shrink: 0;
  filter: drop-shadow(0 0 6px rgba(255,100,100,0.6));
}

.boss-hpbar-info {
  flex: 1;
  min-width: 0;
}

.boss-hpbar-name {
  color: #ff9090;
  font-weight: bold;
  font-size: 13px;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 0 8px rgba(255,60,60,0.7);
}

.boss-hpbar-track {
  height: 14px;
  background: rgba(60, 0, 0, 0.7);
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid rgba(255, 60, 60, 0.4);
}

.boss-hpbar-fill {
  height: 100%;
  background: linear-gradient(90deg, #cc2200, #ff5500, #ff8800);
  border-radius: 7px;
  transition: width 0.25s ease;
  box-shadow: 0 0 6px rgba(255,80,0,0.6);
  width: 100%;
}

/* ── 主選單大按鈕 ── */
.btn-play-main {
  width: 100%;
  font-size: clamp(1rem, 2.8vh, 1.2rem);
  min-height: clamp(44px, 7vh, 58px);
  letter-spacing: 0.04em;
}

/* ── 次要功能列（圖示＋文字縱向，三格並排）── */
.menu-secondary-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.btn-icon-action {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: clamp(8px, 1.6vh, 12px) 6px;
  border: 1.5px solid rgba(255,255,255,0.22);
  border-radius: 14px;
  background: rgba(255,255,255,0.08);
  color: white;
  cursor: pointer;
  transition: background 0.15s;
  touch-action: manipulation;
  min-width: 0;
}

.btn-icon-action:hover {
  background: rgba(255,255,255,0.18);
}

.bia-icon {
  font-size: clamp(1.2rem, 3vh, 1.6rem);
  line-height: 1;
}

.bia-label {
  font-size: clamp(0.68rem, 1.6vh, 0.82rem);
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ── 選單底欄 ── */
.menu-footer {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.menu-footer-row {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: center;
}

.menu-author {
  font-size: clamp(0.68rem, 1.6vh, 0.78rem);
  color: rgba(255, 255, 255, 0.4);
}

.menu-footer-sep {
  font-size: clamp(0.68rem, 1.6vh, 0.78rem);
  color: rgba(255, 255, 255, 0.2);
}

.menu-contact {
  font-size: clamp(0.68rem, 1.6vh, 0.78rem);
  color: rgba(162, 210, 255, 0.55);
  text-decoration: none;
  transition: color 0.15s;
}

.menu-contact:hover {
  color: rgba(162, 210, 255, 0.9);
}

/* ── Diff rows ── */
.diff-row {
  display: flex;
  gap: 7px;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}

/* ── Leaderboard overlay ── */
.lb-card {
  background: linear-gradient(160deg,#0a1a3a,#0d2d5a);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 20px;
  padding: 24px 20px 20px;
  max-width: 400px;
  width: 92%;
  max-height: 80vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.lb-title {
  font-size: 1.4rem;
  font-weight: 900;
  color: #FFD700;
  text-align: center;
  text-shadow: 0 0 12px rgba(255,215,0,0.6);
}
.lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lb-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.07);
  border-radius: 10px;
  color: white;
  font-size: 0.9rem;
}
.lb-rank {
  font-size: 1.1rem;
  font-weight: bold;
  min-width: 28px;
  text-align: center;
}
.lb-name { flex: 1; font-weight: bold; }
.lb-score { color: #FFD700; font-weight: bold; min-width: 50px; text-align: right; }
.lb-level { color: #aaddff; font-size: 0.8rem; min-width: 44px; text-align: right; }
.lb-empty { color: rgba(180,210,255,0.5); text-align: center; padding: 20px 0; }

/* ── Game Over name entry ── */
.go-name-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.go-name-label {
  color: rgba(255,255,255,0.8);
  font-size: 0.88rem;
  text-align: center;
}
.go-name-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.go-name-input {
  flex: 1;
  max-width: 180px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.9);
  color: #222;
  font-size: 0.95rem;
  outline: none;
  touch-action: manipulation;
  -webkit-user-select: text;
  user-select: text;
}
.go-name-input:focus { border-color: #a29bfe; }
.go-name-save-btn {
  padding: 8px 16px;
  border-radius: 12px;
  border: none;
  background: #a29bfe;
  color: #1a1a2e;
  font-weight: bold;
  font-size: 0.9rem;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}
.go-name-saved {
  color: #00FF88;
  font-size: 0.85rem;
  text-align: center;
}

/* ── UI Icons ── */
.hud-icon {
  width: clamp(1.2rem, 3vw, 1.5rem);
  height: clamp(1.2rem, 3vw, 1.5rem);
  font-size: clamp(1.2rem, 3vw, 1.5rem);
  vertical-align: middle;
}
.hud-icon-small {
  width: clamp(1rem, 2.5vw, 1.2rem);
  height: clamp(1rem, 2.5vw, 1.2rem);
  vertical-align: -2px;
}
.btn-icon {
  width: 1.4em;
  height: 1.4em;
  vertical-align: -6px;
  margin-right: 6px;
  display: inline-block;
}
.go-icon {
  width: 1.2em;
  height: 1.2em;
  vertical-align: -4px;
}
.go-icon-small {
  width: 1em;
  height: 1em;
  vertical-align: -2px;
}

/* ── 手機橫向：quiz card 縮緊，確保不超出畫面 ── */
@media (max-height: 500px) and (orientation: landscape) {
  .quiz-card {
    padding: 12px 20px;
    gap: 6px;
    max-height: 90dvh;
    overflow-y: auto;
  }
  .quiz-word {
    font-size: clamp(1.2rem, 5vw, 2rem);
    letter-spacing: 1px;
  }
  .quiz-badge { padding: 3px 12px; font-size: 0.8rem; }
  .quiz-hint  { font-size: 0.75rem; }
  .quiz-opt-btn { min-height: 40px; font-size: 0.9rem; }
  .quiz-opts { gap: 6px; }
  .quiz-sound-btn { padding: 5px 12px; font-size: 0.8rem; }

  /* ── 升級技能卡橫向縮放 ── */
  #upgrade-overlay {
    gap: 8px;
    overflow-y: auto;
    padding: 8px 0;
  }
  .upgrade-header {
    font-size: 1rem;
    margin: 0;
  }
  .upgrade-cards {
    gap: 8px;
    padding: 0 8px;
    flex-wrap: nowrap;
  }
  .upgrade-card {
    width: clamp(100px, 22vw, 140px);
    padding: 8px 10px;
    gap: 4px;
    border-radius: 14px;
  }
  .uc-emoji { font-size: 1.6rem; }
  .uc-name  { font-size: 0.8rem; }
  .uc-level { font-size: 0.7rem; }
  .uc-desc  { font-size: 0.68rem; line-height: 1.3; }

  /* ── 答對單字卡橫向縮放 ── */
  .wr-card {
    padding: 12px 24px;
    gap: 6px;
    border-radius: 18px;
  }
  .wr-correct  { font-size: 1rem; }
  .wr-word     { font-size: clamp(1.4rem, 5vw, 2rem); letter-spacing: 2px; }
  .wr-phonetic { font-size: clamp(0.8rem, 2.5vw, 1rem); }
  .wr-chinese  { font-size: clamp(1rem, 3.5vw, 1.4rem); }
  .wr-close-btn { padding: 8px 28px; font-size: 0.9rem; margin-top: 4px; }

  /* ── 遊戲結束橫向縮放 ── */
  .go-card {
    padding: 12px 20px;
    gap: 6px;
    max-height: 92dvh;
    overflow-y: auto;
    border-radius: 16px;
  }
  .go-title  { font-size: 1.3rem; }
  .go-stat   { font-size: 0.8rem; }
  .go-record { font-size: 1rem; }
  .go-name-label { font-size: 0.75rem; }
  .go-name-input { padding: 6px 10px; font-size: 0.85rem; }
  .go-name-save-btn { padding: 6px 12px; font-size: 0.8rem; }

  /* ── 遊戲通關橫向縮放 ── */
  .gc-card {
    padding: 12px 20px;
    gap: 6px;
    max-height: 92dvh;
    overflow-y: auto;
    border-radius: 16px;
  }
  .gc-crown    { font-size: 2rem; }
  .gc-title    { font-size: 1.3rem; }
  .gc-subtitle { font-size: 0.8rem; }
  .gc-stat     { font-size: 0.8rem; }

  /* ── 排行榜橫向縮放 ── */
  .lb-card {
    max-height: 88dvh;
    padding: 12px 14px;
    gap: 8px;
  }
  .lb-title { font-size: 1.1rem; }
  .lb-entry { padding: 5px 10px; font-size: 0.78rem; }

  /* ── 暫停橫向縮放 ── */
  .pause-card {
    padding: 12px 24px;
    gap: 8px;
  }

  /* ── 自訂單字橫向縮放 ── */
  .cw-card {
    padding: 12px 16px;
    gap: 8px;
    max-height: 92dvh;
    border-radius: 16px;
  }
  .cw-title    { font-size: 1rem; }
  .cw-subtitle { font-size: 0.7rem; }
  .cw-list     { max-height: 30dvh; }
  .cw-input    { padding: 6px 10px; font-size: 0.82rem; }
  .cw-add-btn, .btn-io { padding: 6px 12px; font-size: 0.8rem; }

  /* ── 錯題複習橫向縮放 ── */
  .rv-card {
    padding: 12px 16px;
    gap: 8px;
    max-height: 92dvh;
    border-radius: 16px;
  }
  .rv-title    { font-size: 1rem; }
  .rv-subtitle { font-size: 0.7rem; }
  .rv-list     { max-height: 35dvh; }
  .rv-item     { padding: 5px 8px; font-size: 0.8rem; }
}
