/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Microsoft JhengHei", "微軟正黑體", sans-serif;
}

:root {
  --bg-dark: #0a0e1a;
  --bg-panel: rgba(16, 24, 48, 0.88);
  --cyan-glow: #00f3ff;
  --magenta-glow: #ff007f;
  --green-glow: #00ff88;
  --yellow-glow: #ffe600;
  --purple-glow: #bf55ec;
  --orange-glow: #ff9100;
  --text-light: #f0f6fc;
  --text-muted: #8b9bb4;
  --border-neon: rgba(0, 243, 255, 0.3);
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: fixed;
  inset: 0;
  background-color: var(--bg-dark);
  color: var(--text-light);
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

/* Master Game Container */
#game-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #15223e 0%, #080d19 100%);
}

/* Top HUD */
#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--bg-panel);
  border-bottom: 2px solid var(--border-neon);
  box-shadow: 0 4px 20px rgba(0, 243, 255, 0.15);
  z-index: 20;
  flex-wrap: nowrap;
  flex-shrink: 0;
  gap: 8px;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
}

.hud-label {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.hud-value {
  font-size: 20px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 0 10px var(--cyan-glow);
}

#hud-combo {
  color: var(--yellow-glow);
  text-shadow: 0 0 12px var(--yellow-glow);
}

/* Time Attack Timer & Fever HUD */
.hud-timer {
  font-family: 'Chakra Petch', monospace, sans-serif;
  color: #00f3ff;
  font-size: 22px;
  font-weight: 900;
  text-shadow: 0 0 12px #00f3ff;
  letter-spacing: 1px;
}

.hud-timer.timer-warning {
  color: #ff0055 !important;
  text-shadow: 0 0 16px #ff0055 !important;
  animation: timerAlert 0.45s infinite alternate ease-in-out;
}

@keyframes timerAlert {
  from { transform: scale(1); filter: brightness(1); }
  to { transform: scale(1.15); filter: brightness(1.4); }
}

.hud-fever-val {
  color: #ffe600 !important;
  font-size: 18px;
  font-weight: 900;
  text-shadow: 0 0 14px #ffe600;
  animation: feverPulse 0.6s infinite alternate;
}

@keyframes feverPulse {
  from { transform: scale(1); filter: brightness(1); }
  to { transform: scale(1.1); filter: brightness(1.3); }
}

/* Screen Fire Aura during Fever */
#game-container.fever-mode-active {
  box-shadow: inset 0 0 40px rgba(255, 230, 0, 0.7), inset 0 0 80px rgba(255, 80, 0, 0.4);
  border: 2px solid #ffe600 !important;
  animation: feverScreenPulse 0.7s infinite alternate;
}

@keyframes feverScreenPulse {
  0% { box-shadow: inset 0 0 30px rgba(255, 230, 0, 0.5), inset 0 0 60px rgba(255, 80, 0, 0.3); }
  100% { box-shadow: inset 0 0 55px rgba(255, 230, 0, 0.9), inset 0 0 100px rgba(255, 80, 0, 0.6); }
}

/* Shield Bar */
.shield-bar-outer {
  width: 130px;
  height: 14px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid rgba(0, 255, 136, 0.5);
  margin-top: 4px;
}

#shield-bar-inner {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #00ff88, #00f3ff);
  box-shadow: 0 0 10px #00ff88;
  transition: width 0.25s ease-out, background 0.3s;
}

.shield-critical {
  background: linear-gradient(90deg, #ff0055, #ff5500) !important;
  box-shadow: 0 0 12px #ff0055 !important;
  animation: pulse-danger 0.6s infinite alternate;
}

@keyframes pulse-danger {
  from { opacity: 0.7; }
  to { opacity: 1; }
}

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

.hud-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(0, 243, 255, 0.4);
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.hud-btn:hover {
  background: rgba(0, 243, 255, 0.25);
  box-shadow: 0 0 10px var(--cyan-glow);
  transform: translateY(-1px);
}

/* Canvas Area */
#canvas-wrapper {
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Target Details Panel (Floating on top-right of canvas) */
#target-detail-panel {
  position: absolute;
  top: 15px;
  right: 20px;
  background: rgba(10, 20, 42, 0.9);
  border: 2px solid var(--cyan-glow);
  box-shadow: 0 0 15px rgba(0, 243, 255, 0.3);
  border-radius: 12px;
  padding: 10px 16px;
  min-width: 160px;
  text-align: center;
  pointer-events: none;
  animation: fadeIn 0.3s ease;
  z-index: 10;
}

.target-title {
  font-size: 12px;
  color: var(--cyan-glow);
  margin-bottom: 2px;
}

.target-number-display {
  font-size: 32px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 12px var(--cyan-glow);
}

.target-history {
  font-size: 13px;
  color: var(--yellow-glow);
  margin-top: 4px;
  min-height: 18px;
}

/* Floating Banners */
#combo-banner {
  position: absolute;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%) scale(1);
  font-size: 38px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 20px #ff007f, 0 0 40px #ffe600;
  pointer-events: none;
  z-index: 15;
  animation: popScale 0.6s ease-out forwards;
}

#equation-banner {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.85);
  border: 2px solid var(--green-glow);
  box-shadow: 0 0 25px var(--green-glow);
  border-radius: 12px;
  padding: 12px 24px;
  font-size: 24px;
  font-weight: 800;
  color: #00ff88;
  z-index: 16;
  text-align: center;
  pointer-events: none;
  animation: floatUpFade 1.2s ease-out forwards;
}

#warning-bubble {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(220, 20, 60, 0.95);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 18px;
  font-weight: bold;
  box-shadow: 0 0 20px rgba(255, 0, 85, 0.8);
  z-index: 17;
  pointer-events: none;
  animation: shake 0.5s ease-out forwards;
}

@keyframes popScale {
  0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; }
  50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

@keyframes floatUpFade {
  0% { transform: translate(-50%, -30%) scale(0.8); opacity: 0; }
  25% { transform: translate(-50%, -50%) scale(1.1); opacity: 1; }
  80% { transform: translate(-50%, -55%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -70%) scale(0.9); opacity: 0; }
}

@keyframes shake {
  0%, 100% { transform: translate(-50%, -50%); opacity: 1; }
  20%, 60% { transform: translate(-55%, -50%); }
  40%, 80% { transform: translate(-45%, -50%); }
  90% { opacity: 1; }
  100% { opacity: 0; }
}

/* Bottom Console */
#cannon-console {
  background: var(--bg-panel);
  border-top: 2px solid var(--border-neon);
  box-shadow: 0 -4px 20px rgba(0, 243, 255, 0.15);
  padding: 8px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 25;
  flex-shrink: 0; /* CRITICAL: Never allow console to be pushed off-screen */
}

.console-hint {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.console-hint strong {
  color: var(--cyan-glow);
}

.prime-buttons-container {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: clamp(6px, 1.2vw, 12px);
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.prime-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(6px, 1.3vh, 12px) 2px;
  border-radius: 12px;
  background: linear-gradient(180deg, #1e2a48 0%, #111a33 100%);
  border: 2px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  cursor: pointer;
  position: relative;
  transition: all 0.12s ease-in-out;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.prime-btn:hover {
  transform: translateY(-3px);
  filter: brightness(1.2);
}

.prime-btn:active, .prime-btn.active-press {
  transform: scale(0.95);
  filter: brightness(1.5);
}

/* Overheat & Anti-Spam Lockout */
#cannon-console.overheated {
  border-top-color: #ff0055;
  box-shadow: 0 -4px 25px rgba(255, 0, 85, 0.4);
}

.overheat-banner {
  color: #ff3366 !important;
  font-weight: bold;
  animation: pulse-danger 0.5s infinite alternate;
}

.prime-btn.locked {
  opacity: 0.35;
  filter: grayscale(0.85);
  cursor: not-allowed;
  pointer-events: none;
  transform: scale(0.96);
  border-color: rgba(255, 0, 85, 0.3) !important;
  box-shadow: none !important;
}

/* Individual Prime Button Styling */
.prime-btn[data-prime="2"] {
  border-color: #00f3ff;
  box-shadow: 0 4px 12px rgba(0, 243, 255, 0.25);
}
.prime-btn[data-prime="3"] {
  border-color: #00ff88;
  box-shadow: 0 4px 12px rgba(0, 255, 136, 0.25);
}
.prime-btn[data-prime="5"] {
  border-color: #ffe600;
  box-shadow: 0 4px 12px rgba(255, 230, 0, 0.25);
}
.prime-btn[data-prime="7"] {
  border-color: #ff9100;
  box-shadow: 0 4px 12px rgba(255, 145, 0, 0.25);
}
.prime-btn[data-prime="11"] {
  border-color: #ff007f;
  box-shadow: 0 4px 12px rgba(255, 0, 127, 0.25);
}
.prime-btn[data-prime="13"] {
  border-color: #bf55ec;
  box-shadow: 0 4px 12px rgba(191, 85, 236, 0.25);
}

.prime-num {
  font-size: clamp(20px, 3.8vh, 28px);
  font-weight: 900;
  line-height: 1;
}

.prime-btn[data-prime="2"] .prime-num { color: #00f3ff; }
.prime-btn[data-prime="3"] .prime-num { color: #00ff88; }
.prime-btn[data-prime="5"] .prime-num { color: #ffe600; }
.prime-btn[data-prime="7"] .prime-num { color: #ff9100; }
.prime-btn[data-prime="11"] .prime-num { color: #ff007f; }
.prime-btn[data-prime="13"] .prime-num { color: #bf55ec; }

.key-badge {
  font-size: 11px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 1px 5px;
  margin-top: 4px;
  color: #ddd;
}

.prime-tip {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* Modals */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(6, 10, 24, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 20px;
}

.modal-card {
  background: linear-gradient(135deg, #131c38 0%, #0d1326 100%);
  border: 2px solid var(--border-neon);
  box-shadow: 0 0 30px rgba(0, 243, 255, 0.25);
  border-radius: 18px;
  padding: 28px 36px;
  max-width: 650px;
  width: 100%;
  text-align: center;
  max-height: 90vh;
  overflow-y: auto;
}

.hidden {
  display: none !important;
}

/* Start Modal Branding */
.game-logo {
  margin-bottom: 20px;
}

.logo-sub {
  font-size: 14px;
  color: var(--yellow-glow);
  letter-spacing: 2px;
  margin-bottom: 4px;
}

.logo-title {
  font-size: 42px;
  font-weight: 900;
  color: #fff;
  letter-spacing: 3px;
  text-shadow: 0 0 20px var(--cyan-glow), 0 0 40px rgba(0, 243, 255, 0.4);
}

.logo-tag {
  font-size: 12px;
  letter-spacing: 4px;
  color: var(--text-muted);
  margin-top: 4px;
}

.modal-intro {
  font-size: 16px;
  line-height: 1.6;
  color: #e2e8f0;
  margin-bottom: 20px;
}

.rule-quick-guide {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 16px;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.guide-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  line-height: 1.4;
}

.guide-icon {
  font-size: 24px;
}

/* Buttons */
.mode-select-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.btn-play, .primary-btn, .secondary-btn, .tertiary-btn, .btn-close-modal {
  padding: 14px 24px;
  font-size: 18px;
  font-weight: bold;
  border-radius: 10px;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-btn {
  background: linear-gradient(90deg, #00f3ff, #0088ff);
  color: #031024;
  box-shadow: 0 4px 15px rgba(0, 243, 255, 0.4);
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(0, 243, 255, 0.6);
}

.secondary-btn {
  background: linear-gradient(90deg, #ff007f, #b30059);
  color: #fff;
  box-shadow: 0 4px 15px rgba(255, 0, 127, 0.4);
}

.secondary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 25px rgba(255, 0, 127, 0.6);
}

.tertiary-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

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

.btn-close-modal {
  width: 100%;
  margin-top: 20px;
  background: var(--cyan-glow);
  color: #05132b;
}

/* Cheat Sheet Modal */
.cheat-content {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.cheat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px 14px;
  border-radius: 8px;
}

.cheat-badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-weight: bold;
  font-size: 13px;
  min-width: 80px;
  text-align: center;
}

.badge-2 { background: rgba(0, 243, 255, 0.25); color: #00f3ff; border: 1px solid #00f3ff; }
.badge-3 { background: rgba(0, 255, 136, 0.25); color: #00ff88; border: 1px solid #00ff88; }
.badge-5 { background: rgba(255, 230, 0, 0.25); color: #ffe600; border: 1px solid #ffe600; }
.badge-7 { background: rgba(255, 145, 0, 0.25); color: #ff9100; border: 1px solid #ff9100; }
.badge-11 { background: rgba(255, 0, 127, 0.25); color: #ff007f; border: 1px solid #ff007f; }
.badge-13 { background: rgba(191, 85, 236, 0.25); color: #bf55ec; border: 1px solid #bf55ec; }

.cheat-desc {
  font-size: 14px;
  color: #e6edf3;
}

.cheat-note {
  margin-top: 8px;
  padding: 12px;
  background: rgba(255, 230, 0, 0.1);
  border-left: 4px solid var(--yellow-glow);
  font-size: 14px;
  line-height: 1.5;
  color: #fff;
}

/* Summary Modal */
.summary-card {
  max-width: 700px;
}

.result-badge {
  display: inline-block;
  padding: 6px 20px;
  font-size: 26px;
  font-weight: 900;
  border-radius: 30px;
  margin: 12px 0 20px 0;
  background: linear-gradient(90deg, #ffe600, #ff9100);
  color: #1a1000;
  box-shadow: 0 0 20px #ffe600;
}

.summary-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 12px 6px;
}

.stat-lbl {
  font-size: 12px;
  color: var(--text-muted);
}

.stat-val {
  font-size: 22px;
  font-weight: 800;
  color: var(--cyan-glow);
  margin-top: 4px;
}

/* Learning Review List */
.review-section {
  text-align: left;
  margin-top: 14px;
}

.review-section h3 {
  font-size: 16px;
  margin-bottom: 8px;
  color: var(--yellow-glow);
}

.review-list {
  max-height: 160px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.review-item {
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
  padding-bottom: 4px;
}

.review-item:last-child {
  border-bottom: none;
}

.review-eq {
  font-weight: bold;
  color: #00ff88;
}

.review-exponential {
  color: var(--cyan-glow);
  font-size: 13px;
}

.summary-actions {
  display: flex;
  gap: 16px;
  margin-top: 24px;
}

.summary-actions button {
  flex: 1;
}

/* Responsive adjustments for iPad & Mobile */
@media (max-width: 900px), (max-height: 750px) {
  .console-hint {
    display: none;
  }
  .key-badge {
    display: none;
  }
}

@media (max-height: 650px) {
  #hud {
    padding: 4px 10px;
    padding-top: max(4px, env(safe-area-inset-top));
  }
  .hud-item {
    min-width: 60px;
  }
  .hud-value {
    font-size: 16px;
  }
  .hud-label {
    font-size: 10px;
  }
  .shield-bar-outer {
    height: 10px;
    width: 80px;
  }
  #cannon-console {
    padding: 6px 10px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
  .prime-tip {
    display: none;
  }
  .prime-btn {
    padding: 4px 2px;
  }
  .prime-num {
    font-size: 22px;
  }
}

@media (max-width: 768px) {
  #hud {
    padding: 6px 10px;
  }
  .hud-item {
    min-width: 60px;
  }
  .hud-value {
    font-size: 15px;
  }
  .hud-label {
    font-size: 10px;
  }
  .shield-bar-outer {
    width: 80px;
  }
  .prime-buttons-container {
    gap: 6px;
  }
  .prime-btn {
    padding: 6px 2px;
  }
  .prime-num {
    font-size: 20px;
  }
  .key-badge {
    display: none;
  }
  .prime-tip {
    font-size: 10px;
  }
  .summary-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .logo-title {
    font-size: 32px;
  }
}

@media (max-width: 480px) {
  .prime-buttons-container {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .prime-tip {
    display: none;
  }
}

/* Player Profile Input Form */
.player-profile-form {
  background: rgba(0, 243, 255, 0.05);
  border: 1px solid rgba(0, 243, 255, 0.3);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 20px;
  text-align: left;
}

.profile-form-title {
  font-size: 14px;
  font-weight: bold;
  color: var(--cyan-glow);
  margin-bottom: 10px;
  text-align: center;
}

.profile-input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 10px;
}

.input-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.input-field label {
  font-size: 12px;
  color: var(--text-muted);
}

.input-field input {
  background: rgba(10, 20, 42, 0.9);
  border: 1.5px solid rgba(0, 243, 255, 0.4);
  border-radius: 8px;
  color: #fff;
  padding: 8px 10px;
  font-size: 14px;
  font-weight: bold;
  text-align: center;
  outline: none;
  transition: all 0.2s;
}

.input-field input:focus {
  border-color: var(--cyan-glow);
  box-shadow: 0 0 10px rgba(0, 243, 255, 0.5);
}

.profile-error {
  margin-top: 8px;
  color: #ff3366;
  font-size: 12px;
  font-weight: bold;
  text-align: center;
  animation: shake 0.4s ease-out;
}

/* Quaternary Golden Leaderboard Button */
.quaternary-btn {
  background: linear-gradient(90deg, #ffe600, #ff9100);
  color: #1a1000 !important;
  box-shadow: 0 4px 15px rgba(255, 230, 0, 0.35);
  font-weight: 900;
}

.quaternary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 230, 0, 0.5);
}

.btn-return-hub {
  background: rgba(255, 230, 0, 0.12) !important;
  color: #ffe600 !important;
  border: 1px dashed rgba(255, 230, 0, 0.5) !important;
  box-shadow: 0 4px 15px rgba(255, 230, 0, 0.15) !important;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-return-hub:hover {
  background: rgba(255, 230, 0, 0.25) !important;
  border-color: #ffe600 !important;
  box-shadow: 0 6px 20px rgba(255, 230, 0, 0.4) !important;
  transform: translateY(-2px);
}

/* Leaderboard Modal Styles */
.leaderboard-card {
  max-width: 760px;
}

.lb-title {
  color: var(--yellow-glow);
  font-size: 26px;
  text-shadow: 0 0 15px rgba(255, 230, 0, 0.4);
  margin-bottom: 16px;
}

.leaderboard-tabs {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
}

.lb-tab {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-muted);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.lb-tab.active {
  background: var(--cyan-glow);
  color: #05132b;
  border-color: var(--cyan-glow);
  box-shadow: 0 0 12px var(--cyan-glow);
}

.lb-tab-hint {
  font-size: 13px;
  color: #8b9bb4;
  text-align: center;
  margin: -6px 0 14px 0;
  background: rgba(0, 243, 255, 0.05);
  border: 1px dashed rgba(0, 243, 255, 0.25);
  border-radius: 8px;
  padding: 8px 12px;
  line-height: 1.5;
}

.lb-tab-hint strong {
  color: var(--cyan-glow);
}

.leaderboard-table-container {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid rgba(0, 243, 255, 0.2);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.4);
  margin-bottom: 20px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  text-align: center;
  font-size: 14px;
}

.leaderboard-table th {
  background: rgba(0, 243, 255, 0.15);
  color: var(--cyan-glow);
  padding: 10px 8px;
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.leaderboard-table td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.leaderboard-table tr:hover {
  background: rgba(255, 255, 255, 0.04);
}

.rank-badge {
  font-weight: 900;
  font-size: 15px;
}

.rank-1 { color: #ffe600; text-shadow: 0 0 10px #ffe600; font-size: 18px; }
.rank-2 { color: #e0e0e0; text-shadow: 0 0 10px #ffffff; font-size: 17px; }
.rank-3 { color: #ff9100; text-shadow: 0 0 10px #ff9100; font-size: 16px; }

.lb-player-tag {
  font-weight: bold;
  color: #fff;
}

.lb-score-tag {
  font-weight: 800;
  color: var(--green-glow);
}

.leaderboard-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn-danger-action {
  color: #ff4d6d !important;
  border-color: rgba(255, 77, 109, 0.3) !important;
  font-size: 14px;
}

.btn-danger-action:hover {
  background: rgba(255, 77, 109, 0.2) !important;
}

.summary-lb-rank {
  margin: 12px 0;
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(255, 230, 0, 0.15);
  border: 1px solid var(--yellow-glow);
  color: #ffe600;
  font-size: 16px;
  font-weight: 900;
  animation: popScale 0.6s ease-out;
}

.summary-cloud-status {
  margin: 10px 0;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  line-height: 1.4;
}

.summary-cloud-status.syncing {
  background: rgba(0, 243, 255, 0.15);
  border: 1px solid #00f3ff;
  color: #00f3ff;
  animation: pulseSync 1.2s infinite ease-in-out;
}

.summary-cloud-status.success {
  background: rgba(0, 255, 136, 0.15);
  border: 1px solid #00ff88;
  color: #00ff88;
}

.summary-cloud-status.warning {
  background: rgba(255, 145, 0, 0.15);
  border: 1px solid #ff9100;
  color: #ff9100;
}

.btn-retry-sync {
  background: rgba(255, 230, 0, 0.25);
  border: 1px solid #ffe600;
  color: #ffe600;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  margin-left: 6px;
  transition: all 0.2s;
}

.btn-retry-sync:hover {
  background: rgba(255, 230, 0, 0.5);
  transform: scale(1.05);
}

/* Cloud Leaderboard Status Bar */
.lb-cloud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 243, 255, 0.05);
  border: 1px solid rgba(0, 243, 255, 0.2);
  border-radius: 10px;
  padding: 8px 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.lb-cloud-status {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cloud-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.cloud-badge.cloud-local {
  background: rgba(255, 230, 0, 0.15);
  border: 1px solid #ffe600;
  color: #ffe600;
}

.cloud-badge.cloud-online {
  background: rgba(0, 255, 136, 0.15);
  border: 1px solid #00ff88;
  color: #00ff88;
  box-shadow: 0 0 10px rgba(0, 255, 136, 0.3);
}

.cloud-badge.cloud-syncing {
  background: rgba(0, 243, 255, 0.15);
  border: 1px solid #00f3ff;
  color: #00f3ff;
  animation: pulseSync 1.2s infinite ease-in-out;
}

@keyframes pulseSync {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(0.97); }
}

.cloud-hint {
  font-size: 12px;
  color: #8b9bb4;
}

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

.btn-cloud-sm {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e0e8f5;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.btn-cloud-sm:hover {
  background: rgba(0, 243, 255, 0.2);
  border-color: #00f3ff;
  color: #00f3ff;
  transform: translateY(-1px);
}

/* Cloud Setup Modal */
.cloud-setup-card {
  max-width: 680px;
  text-align: left;
}

.cloud-setup-desc {
  color: #b0c0d8;
  font-size: 14px;
  margin-bottom: 16px;
  line-height: 1.5;
}

.cloud-setup-form {
  background: rgba(0, 0, 0, 0.3);
  padding: 16px;
  border-radius: 10px;
  border: 1px solid rgba(0, 243, 255, 0.2);
  margin-bottom: 16px;
}

.cloud-setup-form label {
  display: block;
  font-size: 13px;
  font-weight: bold;
  color: #00f3ff;
  margin-bottom: 8px;
}

.url-input-wrap input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid rgba(0, 243, 255, 0.4);
  background: rgba(10, 24, 45, 0.9);
  color: #fff;
  font-size: 13px;
  font-family: monospace;
  box-sizing: border-box;
}

.url-input-wrap input:focus {
  border-color: #00f3ff;
  box-shadow: 0 0 12px rgba(0, 243, 255, 0.5);
  outline: none;
}

.cloud-setup-msg {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: bold;
  line-height: 1.4;
}

.cloud-setup-msg.success {
  background: rgba(0, 255, 136, 0.15);
  border: 1px solid #00ff88;
  color: #00ff88;
}

.cloud-setup-msg.error {
  background: rgba(255, 77, 109, 0.15);
  border: 1px solid #ff4d6d;
  color: #ff4d6d;
}

.cloud-setup-msg.loading {
  background: rgba(0, 243, 255, 0.15);
  border: 1px solid #00f3ff;
  color: #00f3ff;
}

.cloud-setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.cloud-setup-actions button {
  flex: 1 1 auto;
  padding: 10px 16px;
  font-size: 14px;
}

.cloud-guide-details {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: #c5d4eb;
  line-height: 1.6;
}

.cloud-guide-details summary {
  font-weight: bold;
  color: #ffe600;
  cursor: pointer;
  margin-bottom: 8px;
}

.cloud-steps-list {
  padding-left: 20px;
  margin: 8px 0 0 0;
}

.cloud-steps-list li {
  margin-bottom: 8px;
}

.cloud-steps-list ul {
  padding-left: 20px;
  margin: 6px 0;
}

@media (max-width: 600px) {
  .profile-input-grid {
    grid-template-columns: 1fr;
  }
  .lb-cloud-bar {
    flex-direction: column;
    align-items: flex-start;
  }
}


/* ========================================================
   ⚔️ 1v1 VERSUS MULTIPLAYER MODE STYLES
   ======================================================== */

/* Start Screen Versus Button */
.vs-btn {
  background: linear-gradient(135deg, #7c3aed 0%, #db2777 50%, #dc2626 100%) !important;
  color: #ffffff !important;
  border: 2px solid #f472b6 !important;
  box-shadow: 0 0 20px rgba(219, 39, 119, 0.5), inset 0 0 12px rgba(255, 255, 255, 0.2) !important;
  font-weight: 800 !important;
  letter-spacing: 1px;
  position: relative;
  overflow: hidden;
  animation: vsBtnPulse 2.4s infinite ease-in-out;
}

.vs-btn::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(60deg, transparent, rgba(255, 255, 255, 0.25), transparent);
  transform: rotate(30deg);
  animation: vsShine 3s infinite linear;
}

@keyframes vsBtnPulse {
  0%, 100% {
    box-shadow: 0 0 15px rgba(219, 39, 119, 0.45);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 30px rgba(244, 114, 182, 0.8), 0 0 15px #7c3aed;
    transform: scale(1.02);
  }
}

@keyframes vsShine {
  0% { transform: translateX(-100%) rotate(30deg); }
  25%, 100% { transform: translateX(100%) rotate(30deg); }
}

/* Versus Lobby Modal */
.versus-modal-card {
  max-width: 540px;
  background: radial-gradient(circle at 50% 10%, #1e153b 0%, #0a0b18 100%);
  border: 2px solid #8b5cf6;
  box-shadow: 0 0 35px rgba(139, 92, 246, 0.4), 0 20px 40px rgba(0, 0, 0, 0.85);
}

.vs-modal-badge {
  display: inline-block;
  padding: 4px 12px;
  background: rgba(139, 92, 246, 0.25);
  border: 1px solid #a78bfa;
  border-radius: 20px;
  color: #c4b5fd;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.vs-modal-title {
  color: #f472b6;
  text-shadow: 0 0 15px rgba(244, 114, 182, 0.6);
  font-size: 26px;
  margin: 0 0 8px 0;
}

.vs-modal-desc {
  font-size: 13.5px;
  color: #cbd5e1;
  line-height: 1.5;
  margin-bottom: 16px;
}

/* Tab Switcher */
.vs-tab-container {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.45);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 18px;
}

.vs-tab-btn {
  flex: 1 1 auto;
  background: transparent;
  border: none;
  color: #94a3b8;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: bold;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.vs-tab-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.vs-tab-btn.active {
  background: linear-gradient(135deg, #8b5cf6, #ec4899);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(139, 92, 246, 0.5);
}

/* Panels */
.vs-panel {
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Room Code Card */
.vs-room-card {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1.5px dashed #a78bfa;
  border-radius: 16px;
  padding: 18px 12px;
  box-sizing: border-box;
  text-align: center;
}

.room-label {
  font-size: 13px;
  color: #c4b5fd;
  font-weight: bold;
}

.room-code-display {
  font-family: 'Courier New', Courier, monospace;
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 12px;
  color: #fbbf24;
  text-shadow: 0 0 20px rgba(251, 191, 36, 0.6);
  margin: 10px 0;
  padding-left: 12px; /* balance letter-spacing */
}

.room-status-hint {
  font-size: 13px;
  color: #38bdf8;
  margin-bottom: 8px;
  min-height: 20px;
}

.copy-room-btn {
  background: rgba(139, 92, 246, 0.25);
  border: 1px solid #a78bfa;
  color: #e0e7ff;
  border-radius: 8px;
  padding: 5px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.copy-room-btn:hover {
  background: #8b5cf6;
  color: #fff;
}

.vs-instruction {
  font-size: 12.5px;
  color: #94a3b8;
  margin-top: 10px;
}

/* Join Input */
.join-input-group {
  width: 100%;
  text-align: center;
}

.join-input-group label {
  display: block;
  font-size: 14px;
  font-weight: bold;
  color: #cbd5e1;
  margin-bottom: 12px;
}

.code-input-wrapper {
  display: flex;
  gap: 10px;
  justify-content: center;
  max-width: 360px;
  margin: 0 auto;
}

.code-input-wrapper input {
  flex: 1 1 auto;
  font-family: 'Courier New', Courier, monospace;
  font-size: 26px;
  font-weight: bold;
  letter-spacing: 8px;
  text-align: center;
  padding: 10px;
  background: rgba(0, 0, 0, 0.5);
  border: 2px solid #8b5cf6;
  border-radius: 10px;
  color: #fbbf24;
  outline: none;
  transition: all 0.2s;
}

.code-input-wrapper input:focus {
  border-color: #f472b6;
  box-shadow: 0 0 15px rgba(244, 114, 182, 0.5);
}

.vs-join-submit {
  flex: 0 0 auto;
  padding: 10px 18px;
  font-size: 15px;
}

.join-status-hint {
  margin-top: 10px;
  font-size: 13px;
  color: #f87171;
}

/* AI Practice Card */
.ai-practice-card {
  text-align: center;
  padding: 10px;
}

.ai-avatar {
  font-size: 42px;
  margin-bottom: 6px;
  animation: aiFloat 2s infinite alternate ease-in-out;
}

@keyframes aiFloat {
  0% { transform: translateY(0); }
  100% { transform: translateY(-8px); }
}

.ai-title {
  font-size: 17px;
  font-weight: bold;
  color: #38bdf8;
  margin-bottom: 6px;
}

.ai-desc {
  font-size: 13px;
  color: #94a3b8;
  max-width: 380px;
  margin: 0 auto 16px auto;
  line-height: 1.5;
}

.vs-start-ai {
  padding: 10px 24px;
  font-size: 15px;
}

/* Countdown Overlay */
.vs-connecting-box {
  margin-top: 15px;
  padding: 15px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 12px;
  border: 1px solid #a78bfa;
  text-align: center;
}

.vs-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(139, 92, 246, 0.3);
  border-top-color: #ec4899;
  border-radius: 50%;
  margin: 0 auto 8px auto;
  animation: spin 0.8s infinite linear;
}

.vs-spinner-text {
  font-size: 14px;
  color: #e0e7ff;
  font-weight: bold;
}

.vs-countdown-big {
  font-size: 64px;
  font-weight: 900;
  color: #ffe600;
  text-shadow: 0 0 30px rgba(255, 230, 0, 0.8), 0 0 60px #ff007f;
  animation: countdownPop 0.9s infinite ease-out;
  margin-top: 6px;
}

@keyframes countdownPop {
  0% { transform: scale(0.6); opacity: 0.3; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.vs-modal-actions {
  margin-top: 18px;
  width: 100%;
}

.vs-modal-actions button {
  width: 100%;
}

/* ========================================================
   🛰️ 1v1 OPPONENT MINI RADAR WIDGET (對手即時戰況雷達)
   ======================================================== */
#opponent-radar-panel {
  position: absolute;
  top: 15px;
  right: 20px;
  background: rgba(12, 18, 38, 0.9);
  border: 2px solid #8b5cf6;
  box-shadow: 0 0 20px rgba(139, 92, 246, 0.35);
  border-radius: 12px;
  padding: 8px 12px;
  min-width: 170px;
  pointer-events: none;
  animation: fadeIn 0.3s ease;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.radar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: bold;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 5px;
  margin-bottom: 6px;
}

.radar-tag {
  color: #a78bfa;
}

.radar-name {
  color: #fbbf24;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.radar-shield-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.radar-label {
  font-size: 10.5px;
  color: #94a3b8;
}

.radar-shield-bar {
  flex: 1 1 auto;
  height: 8px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  overflow: hidden;
}

#opp-shield-bar {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #06b6d4);
  transition: width 0.3s ease, background 0.3s ease;
}

.radar-shield-val {
  font-size: 11px;
  font-weight: bold;
  color: #34d399;
  min-width: 32px;
  text-align: right;
}

.radar-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px 6px;
  border-radius: 6px;
}

.radar-stat-item {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
}

.radar-stat-item .stat-k {
  color: #94a3b8;
}

.radar-stat-item .stat-v {
  color: #f1f5f9;
  font-weight: bold;
}

.radar-attack-badge {
  margin-top: 6px;
  background: rgba(239, 68, 68, 0.25);
  border: 1px solid #ef4444;
  color: #fca5a5;
  font-size: 10.5px;
  font-weight: bold;
  text-align: center;
  padding: 2px 4px;
  border-radius: 4px;
  animation: pulse 1s infinite alternate;
}

/* In Versus mode, shift target-detail-panel to left: 20px so they don't overlap! */
.versus-mode-active #target-detail-panel {
  right: auto !important;
  left: 20px !important;
}

/* Incoming Attack Banner (紅光警告飛入) */
#vs-attack-banner {
  position: absolute;
  top: 75px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.95), rgba(185, 28, 28, 0.95));
  border: 2px solid #f87171;
  color: #ffffff;
  padding: 10px 22px;
  border-radius: 30px;
  font-size: 15px;
  font-weight: 800;
  box-shadow: 0 0 25px rgba(239, 68, 68, 0.7);
  z-index: 15;
  white-space: nowrap;
  animation: attackBannerDrop 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes attackBannerDrop {
  0% { transform: translateX(-50%) translateY(-30px); opacity: 0; }
  100% { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* Threat Priority Target Panel (突襲威脅優先鎖定特徵) */
#target-detail-panel {
  pointer-events: auto !important;
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

#target-detail-panel:active {
  transform: scale(0.96);
}

.versus-mode-active #target-detail-panel:active {
  transform: scale(0.96) !important;
}

#target-detail-panel.threat-target-panel {
  border-color: #f43f5e !important;
  background: rgba(30, 8, 30, 0.94) !important;
  box-shadow: 0 0 22px rgba(244, 63, 94, 0.75) !important;
  animation: threatPanelPulse 0.9s infinite alternate ease-in-out;
}

@keyframes threatPanelPulse {
  0% { box-shadow: 0 0 14px rgba(244, 63, 94, 0.5); }
  100% { box-shadow: 0 0 28px rgba(244, 63, 94, 0.95); }
}

.badge-threat {
  display: inline-block;
  background: linear-gradient(135deg, #ef4444, #f59e0b);
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 4px;
  vertical-align: middle;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.6);
  animation: bounceBadge 0.6s infinite alternate ease-in-out;
}

@keyframes bounceBadge {
  0% { transform: scale(0.95); }
  100% { transform: scale(1.08); }
}

.badge-switch-hint {
  font-size: 10px;
  color: var(--cyan-glow);
  opacity: 0.85;
  margin-left: 4px;
  font-weight: normal;
}
