/* style.css - Factor Dragon (貪吃因數龍) UI & Game Styling */
:root {
  --bg-dark: #0a0e1a;
  --bg-card: rgba(16, 24, 48, 0.92);
  --primary-emerald: #10b981;
  --emerald-glow: rgba(16, 185, 129, 0.45);
  --gold: #f59e0b;
  --gold-glow: rgba(245, 158, 11, 0.45);
  --cyan: #06b6d4;
  --pink: #ec4899;
  --danger: #ef4444;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-glass: rgba(255, 255, 255, 0.12);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

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

html, body {
  height: 100%;
  max-height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  background: radial-gradient(circle at 50% 15%, #152747 0%, var(--bg-dark) 85%);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  padding: 4px 8px 8px;
  touch-action: manipulation;
  box-sizing: border-box;
}

/* Return to Hub Bar (固定頂部，高度精緻緊湊，永遠不被捲動遮擋) */
.hub-topbar {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 4px;
  margin-bottom: 4px;
  z-index: 100;
  height: 42px;
  box-sizing: border-box;
}

.hub-brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-hub-return {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
  border: 1.5px solid rgba(245, 158, 11, 0.45);
  padding: 5px 12px;
  border-radius: 20px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
  transition: all 0.25s;
  backdrop-filter: blur(8px);
  white-space: nowrap;
}

.btn-hub-return:hover {
  background: rgba(245, 158, 11, 0.32);
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.35);
}

.dragon-title-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid rgba(16, 185, 129, 0.35);
  padding: 3px 10px;
  border-radius: 20px;
}

.dragon-avatar {
  font-size: 20px;
  filter: drop-shadow(0 0 8px var(--emerald-glow));
}

.dragon-pill-title {
  font-size: 14px;
  font-weight: 900;
  background: linear-gradient(135deg, #a7f3d0 0%, #10b981 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.top-actions {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.05);
}

.icon-btn.active-guide {
  background: rgba(6, 182, 212, 0.25);
  border-color: var(--cyan);
  color: var(--cyan);
}

/* Main Container (滿版自適應，零滾動條) */
.game-container {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  overflow: hidden;
  box-sizing: border-box;
}

/* Canvas Area (主遊戲畫面大幅放大) */
.canvas-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  box-sizing: border-box;
}

canvas#gameCanvas {
  display: block;
  border-radius: var(--radius-lg);
  border: 2px solid rgba(16, 185, 129, 0.45);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.65), inset 0 0 50px rgba(16, 185, 129, 0.08);
  background: #09101d;
  touch-action: none;
}

/* Auxiliary Info Wing (所有輔助資訊卡片集合，充實填滿搖桿旁的空白區域) */
.aux-info-wing {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
  user-select: none;
  box-sizing: border-box;
}

.aux-card {
  background: rgba(13, 22, 45, 0.85);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 6px 10px;
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  box-sizing: border-box;
}

/* Target & Stats Card */
.aux-stats-card {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.aux-target-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(217, 119, 6, 0.35) 100%);
  border: 2px solid #fbbf24;
  border-radius: 10px;
  padding: 3px 10px;
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.3);
  min-width: 68px;
  flex-shrink: 0;
}

.aux-label {
  font-size: 10.5px;
  font-weight: 800;
  color: var(--gold);
  line-height: 1.2;
}

.aux-target-badge .target-val {
  font-size: 24px;
  font-weight: 900;
  color: #ffffff;
  line-height: 1.1;
  text-shadow: 0 0 10px rgba(255, 230, 0, 0.6);
}

.aux-stats-details {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1 1 auto;
  min-width: 0;
}

.aux-stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stat-hearts {
  color: var(--pink);
  letter-spacing: 2px;
  font-size: 14px;
}

.stat-mode-badge {
  background: rgba(6, 182, 212, 0.2);
  color: var(--cyan);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid rgba(6, 182, 212, 0.4);
  font-size: 11px;
  font-weight: 800;
}

.powerup-pill {
  align-items: center;
  gap: 4px;
  background: rgba(236, 72, 153, 0.2);
  color: #f472b6;
  border: 1px solid #ec4899;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 800;
}

.aux-sub-scores {
  font-size: 12.5px;
  color: #cbd5e1;
}

.aux-sub-scores strong {
  color: #fbbf24;
  font-weight: 800;
}

.aux-high-score {
  opacity: 0.8;
  font-size: 11.5px;
}

/* Factor Shelf Card */
.aux-shelf-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.aux-shelf-card .shelf-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--text-muted);
}

.aux-shelf-card .shelf-title {
  color: var(--gold);
  display: flex;
  align-items: center;
  gap: 4px;
}

.aux-shelf-card .shelf-progress-text {
  color: var(--primary-emerald);
  font-size: 11px;
}

.aux-shelf-card .factor-slots-container {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
  overflow-y: auto;
  max-height: 82px;
  padding-right: 2px;
}

.factor-slot {
  min-width: 34px;
  height: 34px;
  padding: 0 5px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 14px;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: #64748b;
  box-sizing: border-box;
}

.factor-slot.uncollected {
  background: rgba(15, 23, 42, 0.6);
  color: #64748b;
  border: 1px dashed rgba(255, 255, 255, 0.2);
}

.factor-slot.collected {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  border: 1px solid #34d399;
  box-shadow: 0 0 12px var(--emerald-glow);
  transform: scale(1.05);
}

.factor-slot.is-prime {
  border-color: #fbbf24;
}

.factor-slot.is-prime.collected {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  box-shadow: 0 0 14px var(--gold-glow);
}

.factor-slot.newly-added {
  animation: slotPop 0.5s ease-out;
}

@keyframes slotPop {
  0% { transform: scale(0.6); filter: brightness(2); }
  60% { transform: scale(1.25); filter: brightness(1.5); }
  100% { transform: scale(1.06); filter: brightness(1); }
}

/* Bottom Toolbar (Speed & Hint) */
.aux-bottom-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
  flex: 0 0 auto;
}

.speed-selector {
  display: flex;
  align-items: center;
  gap: 4px;
}

.speed-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
}

.speed-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-glass);
  color: var(--text-muted);
  padding: 3px 8px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  transition: all 0.2s;
}

.speed-btn.active {
  background: rgba(16, 185, 129, 0.25);
  border-color: var(--primary-emerald);
  color: #34d399;
}

.aux-hint-text {
  font-size: 11px;
  color: var(--text-muted);
}

/* Educational Instant Feedback Bubble on Screen */
.feedback-overlay {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  opacity: 0;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.95);
  border-radius: 30px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 10;
  white-space: nowrap;
}

.feedback-overlay.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.feedback-overlay.success {
  border: 1px solid var(--primary-emerald);
  color: #34d399;
}

.feedback-overlay.error {
  border: 1px solid var(--danger);
  color: #f87171;
}

/* Controller Wing (Left or Right) */
.controller-wing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 0 0 auto;
  user-select: none;
  transition: all 0.25s ease;
  box-sizing: border-box;
  padding: 0 6px;
}

/* Control Toolbar */
.controller-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  box-sizing: border-box;
}

/* Hand Position Switcher (Left vs Right) */
.hand-pos-switch {
  display: flex;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 2px;
  gap: 2px;
}

.hand-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  padding: 3px 6px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.hand-btn.active {
  background: rgba(245, 158, 11, 0.28);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.6);
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.35);
}

/* Control Mode Switcher Tabs */
.control-type-switch {
  display: flex;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 2px;
  gap: 2px;
}

.ctrl-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 800;
  padding: 3px 6px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.ctrl-tab-btn.active {
  background: rgba(16, 185, 129, 0.28);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.5);
  box-shadow: 0 0 10px var(--emerald-glow);
}

/* Virtual Analog Joystick (加大直徑與好觸控設計) */
.joystick-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.joystick-base {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(16, 24, 52, 0.96) 0%, rgba(6, 11, 26, 0.98) 100%);
  border: 2.5px solid rgba(16, 185, 129, 0.55);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.65), inset 0 0 32px rgba(16, 185, 129, 0.18);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: grab;
}

.joystick-base:active {
  cursor: grabbing;
}

/* Direction Arrow Indicators on Joystick Base */
.joy-dir-indicator {
  position: absolute;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.3);
  pointer-events: none;
  transition: all 0.15s;
  font-weight: 900;
}

.joy-up { top: 9px; left: 50%; transform: translateX(-50%); }
.joy-down { bottom: 9px; left: 50%; transform: translateX(-50%); }
.joy-left { left: 9px; top: 50%; transform: translateY(-50%); }
.joy-right { right: 9px; top: 50%; transform: translateY(-50%); }

.joy-dir-indicator.active {
  color: #34d399;
  text-shadow: 0 0 10px #10b981, 0 0 18px #34d399;
  transform-origin: center;
  scale: 1.4;
}

/* Draggable Joystick Stick (加大觸控球體面積) */
.joystick-stick {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #a7f3d0 0%, #10b981 55%, #064e3b 100%);
  border: 2.5px solid #ffffff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6), 0 0 20px var(--emerald-glow);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  will-change: transform;
}

.stick-center-orb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fcd34d;
  box-shadow: 0 0 10px #fbbf24;
}

.joystick-hint {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* Digital D-Pad (加大按鍵與間距，好按防誤觸) */
.dpad-container {
  display: grid;
  grid-template-columns: repeat(3, 62px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
  background: rgba(16, 24, 48, 0.75);
  border: 1px solid var(--border-glass);
  padding: 8px;
  border-radius: 20px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
}

.dpad-btn {
  background: rgba(255, 255, 255, 0.09);
  border: 1.5px solid var(--border-glass);
  color: var(--text-main);
  border-radius: 14px;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.dpad-btn:active {
  background: rgba(16, 185, 129, 0.5);
  border-color: var(--primary-emerald);
  transform: scale(0.93);
  box-shadow: 0 0 16px var(--emerald-glow);
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-center {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--gold);
  pointer-events: none;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }

/* ==================== 1. 直式螢幕 (PORTRAIT) ==================== */
@media (orientation: portrait), (max-aspect-ratio: 1.15/1) {
  .game-container {
    display: grid !important;
    grid-template-rows: 1fr 215px !important;
    gap: 8px !important;
    height: calc(100vh - 46px) !important;
    width: 100% !important;
    padding: 0 4px !important;
    box-sizing: border-box !important;
  }

  .canvas-wrapper {
    grid-row: 1 !important;
    grid-column: 1 / span 2 !important;
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    min-width: 0 !important;
  }

  /* 直式：左手模式 (左下方：搖桿 205px，右下方：輔助資訊充實填補空白 1fr) */
  body.hand-pos-left .game-container,
  .game-container.hand-pos-left {
    grid-template-columns: 205px 1fr !important;
  }
  body.hand-pos-left .controller-wing,
  .game-container.hand-pos-left .controller-wing {
    grid-row: 2 !important;
    grid-column: 1 !important;
    width: 100% !important;
  }
  body.hand-pos-left .aux-info-wing,
  .game-container.hand-pos-left .aux-info-wing {
    grid-row: 2 !important;
    grid-column: 2 !important;
    width: 100% !important;
  }

  /* 直式：右手模式 (左下方：輔助資訊充實填補空白 1fr，右下方：搖桿 205px) */
  body.hand-pos-right .game-container,
  .game-container.hand-pos-right {
    grid-template-columns: 1fr 205px !important;
  }
  body.hand-pos-right .aux-info-wing,
  .game-container.hand-pos-right .aux-info-wing {
    grid-row: 2 !important;
    grid-column: 1 !important;
    width: 100% !important;
  }
  body.hand-pos-right .controller-wing,
  .game-container.hand-pos-right .controller-wing {
    grid-row: 2 !important;
    grid-column: 2 !important;
    width: 100% !important;
  }
}

/* ==================== 2. 橫式螢幕 (LANDSCAPE) ==================== */
@media (orientation: landscape) and (min-aspect-ratio: 1.15/1) {
  .game-container {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 10px !important;
    height: calc(100vh - 46px) !important;
    padding: 0 8px !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
  }

  .canvas-wrapper {
    flex: 0 1 auto !important;
    width: min(72vh, calc(100vw - 470px)) !important;
    height: min(72vh, calc(100vw - 470px)) !important;
    max-width: min(72vh, calc(100vw - 470px)) !important;
    max-height: min(72vh, calc(100vw - 470px)) !important;
    order: 2 !important;
    grid-column: unset !important;
    grid-row: unset !important;
    margin: 0 auto !important;
  }

  /* 橫式：左手習慣 (左側搖桿 1，中央超大畫布 2，右側輔助資訊 3) */
  body.hand-pos-left .controller-wing,
  .game-container.hand-pos-left .controller-wing {
    order: 1 !important;
    width: 200px !important;
    flex: 0 0 200px !important;
    height: 100% !important;
    justify-content: center !important;
    grid-column: unset !important;
    grid-row: unset !important;
  }
  body.hand-pos-left .aux-info-wing,
  .game-container.hand-pos-left .aux-info-wing {
    order: 3 !important;
    width: 235px !important;
    flex: 0 0 235px !important;
    height: 100% !important;
    justify-content: center !important;
    grid-column: unset !important;
    grid-row: unset !important;
  }

  /* 橫式：右手習慣 (左側輔助資訊 1，中央超大畫布 2，右側搖桿 3) */
  body.hand-pos-right .aux-info-wing,
  .game-container.hand-pos-right .aux-info-wing {
    order: 1 !important;
    width: 235px !important;
    flex: 0 0 235px !important;
    height: 100% !important;
    justify-content: center !important;
    grid-column: unset !important;
    grid-row: unset !important;
  }
  body.hand-pos-right .controller-wing,
  .game-container.hand-pos-right .controller-wing {
    order: 3 !important;
    width: 200px !important;
    flex: 0 0 200px !important;
    height: 100% !important;
    justify-content: center !important;
    grid-column: unset !important;
    grid-row: unset !important;
  }
}

.speed-selector {
  display: flex;
  align-items: center;
  gap: 6px;
}

.speed-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-glass);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  transition: all 0.2s;
}

.speed-btn.active {
  background: rgba(16, 185, 129, 0.25);
  border-color: var(--primary-emerald);
  color: #34d399;
}

/* Modals */
.skin-selector-container {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 16px;
  text-align: left;
}

.skin-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.skin-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.skin-card {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: all 0.25s;
  position: relative;
}

.skin-card:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.skin-card.active {
  border-color: #34d399;
  background: rgba(16, 185, 129, 0.2);
  box-shadow: 0 0 16px var(--emerald-glow);
}

.skin-card.skin-cool.active {
  border-color: #06b6d4;
  background: rgba(6, 182, 212, 0.2);
  box-shadow: 0 0 16px rgba(6, 182, 212, 0.45);
}

.skin-avatar {
  font-size: 32px;
  margin-bottom: 4px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4));
}

.skin-info h4 {
  font-size: 13.5px;
  font-weight: 900;
  color: #ffffff;
  margin-bottom: 2px;
}

.skin-info p {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
}

.skin-badge-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  background: #10b981;
  color: #ffffff;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 900;
  display: none;
  align-items: center;
  justify-content: center;
}

.skin-card.active .skin-badge-check {
  display: flex;
}

/* Hand Position Selector in Start Menu */
.hand-selector-box {
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  padding: 10px 14px;
  margin-bottom: 16px;
  text-align: left;
}

.hand-title {
  font-size: 13px;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hand-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.hand-card-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 9px 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.hand-card-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.hand-card-btn.active {
  border-color: #fbbf24;
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.3);
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(4, 7, 16, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-backdrop.active {
  display: flex;
}

.modal-content {
  background: #111a30;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  max-width: 520px;
  width: 100%;
  padding: 26px 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 24px;
  font-weight: 900;
  margin-bottom: 8px;
  color: #ffffff;
}

.modal-subtitle {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}

.mode-cards-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.mode-card-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  cursor: pointer;
  transition: all 0.25s;
  color: var(--text-main);
  width: 100%;
}

.mode-card-btn:hover {
  background: rgba(16, 185, 129, 0.12);
  border-color: var(--primary-emerald);
  transform: translateY(-2px);
}

.mode-icon {
  font-size: 28px;
  flex-shrink: 0;
}

.mode-details h3 {
  font-size: 15px;
  font-weight: 800;
  margin-bottom: 4px;
  color: #ffffff;
}

.mode-details p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

.btn-primary {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  width: 100%;
  box-shadow: 0 4px 16px var(--emerald-glow);
  transition: all 0.2s;
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-2px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  border-radius: 12px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 10px;
  width: 100%;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Return to Lobby in Modals (回到遊戲大廳按鈕) */
.start-modal-nav-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 10px;
}

.btn-return-lobby-portal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: linear-gradient(135deg, rgba(255, 230, 0, 0.16) 0%, rgba(245, 158, 11, 0.28) 100%);
  border: 1.5px solid rgba(255, 230, 0, 0.55);
  color: #ffe600;
  text-decoration: none;
  font-size: 15px;
  font-weight: 900;
  padding: 13px 18px;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(255, 230, 0, 0.2);
  transition: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  letter-spacing: 0.5px;
  width: 100%;
}

.btn-return-lobby-portal:hover {
  background: linear-gradient(135deg, rgba(255, 230, 0, 0.32) 0%, rgba(245, 158, 11, 0.48) 100%);
  border-color: #ffe600;
  color: #ffffff;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(255, 230, 0, 0.4);
}

.portal-crown {
  font-size: 20px;
  filter: drop-shadow(0 0 8px rgba(255, 230, 0, 0.6));
}

.portal-text {
  letter-spacing: 0.5px;
}

.btn-return-lobby-link {
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #ffe600 !important;
  border-color: rgba(255, 230, 0, 0.45) !important;
  background: rgba(255, 230, 0, 0.08) !important;
}

.btn-return-lobby-link:hover {
  background: rgba(255, 230, 0, 0.22) !important;
  border-color: #ffe600 !important;
  color: #ffffff !important;
}

/* Custom Free Practice Input */
.custom-input-box {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 20px;
  justify-content: center;
}

.custom-input-box input {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--primary-emerald);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 18px;
  color: #ffffff;
  width: 100px;
  text-align: center;
  font-weight: 900;
}

/* Learning Review Card Table */
.review-table-container {
  max-height: 240px;
  overflow-y: auto;
  margin: 16px 0;
  border: 1px solid var(--border-glass);
  border-radius: 12px;
}

.review-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.review-table th, .review-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
}

.review-table th {
  background: rgba(255, 255, 255, 0.05);
  color: var(--gold);
}

/* Guide Modal Styling */
.guide-section {
  text-align: left;
  margin-bottom: 14px;
  background: rgba(0, 0, 0, 0.2);
  padding: 12px;
  border-radius: 10px;
  border-left: 3px solid var(--primary-emerald);
}

.guide-section h4 {
  font-size: 14px;
  color: #34d399;
  margin-bottom: 6px;
}

.guide-section p, .guide-section li {
  font-size: 12.5px;
  color: #cbd5e1;
  line-height: 1.5;
}

.guide-section ul {
  padding-left: 18px;
  margin-top: 4px;
}

/* Responsive adjustments */
@media (max-width: 600px) {
  body {
    padding: 4px 6px 6px;
  }
  .stage-dock-row {
    flex: 0 0 200px;
    height: 200px;
    gap: 6px;
  }
  .hand-pos-left .controller-wing,
  .hand-pos-right .controller-wing {
    width: 165px;
    flex: 0 0 165px;
  }
  .joystick-base {
    width: 144px;
    height: 144px;
  }
  .joystick-stick {
    width: 60px;
    height: 60px;
  }
  .target-val {
    font-size: 20px;
  }
  .factor-slot {
    min-width: 30px;
    height: 30px;
    font-size: 13px;
  }
  .dpad-container {
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 44px);
    gap: 4px;
    padding: 5px;
  }
  .dpad-btn {
    font-size: 18px;
  }
}
