/* 全域樣式 */

/* CSS 變數定義 */
:root {
  /* 主色調 */
  --primary-color: #7f00ff;
  --primary-dark: #6600cc;
  --primary-light: #9933ff;

  /* 輔助色調 */
  --secondary-color: #00d4ff;
  --accent-color: #ff6b35;
  --success-color: #00c851;
  --warning-color: #ffbb33;
  --error-color: #ff4444;

  /* 背景色 */
  --bg-primary: #0f0a19;
  --bg-secondary: #1a0f2e;
  --bg-tertiary: #2d1b47;
  --bg-card: rgba(255, 255, 255, 0.05);
  --bg-overlay: rgba(0, 0, 0, 0.8);

  /* 文字色 */
  --text-primary: #ffffff;
  --text-secondary: #b8b8b8;
  --text-muted: #888888;

  /* 邊框色 */
  --border-color: rgba(255, 255, 255, 0.1);
  --border-active: rgba(127, 0, 255, 0.5);

  /* 陰影 */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 20px rgba(127, 0, 255, 0.3);

  /* 間距 */
  --spacing-xs: 0.25rem;
  --spacing-sm: 0.5rem;
  --spacing-md: 1rem;
  --spacing-lg: 1.5rem;
  --spacing-xl: 2rem;
  --spacing-2xl: 3rem;

  /* 圓角 */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* 轉場動畫 */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.3s ease;
  --transition-slow: 0.5s ease;

  /* 字體族 */
  --font-main: "Orbitron", "Rajdhani", "Microsoft JhengHei", sans-serif;
  --font-mono: "JetBrains Mono", "Courier New", "Microsoft JhengHei", monospace;
  --font-display: "Orbitron", "Rajdhani", "Microsoft JhengHei", sans-serif;

  /* Z-index */
  --z-dropdown: 1000;
  --z-modal: 2000;
  --z-tooltip: 3000;
  --z-loading: 9999;
}

/* 基礎重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  /* 防止所有元素產生橫向滾動 */
  max-width: 100%;
}

/* 排除 TIDIO 客服系統元素，不受全域重置影響 */
*[id*="tidio"],
*[class*="tidio"],
*[id*="tidio"] *,
*[class*="tidio"] *,
#tidio-chat,
#tidio-chat *,
.tidio-chat-container,
.tidio-chat-container *,
.tidiochat,
.tidiochat *,
iframe[src*="tidio"],
iframe[src*="tidio"] * {
  margin: initial;
  padding: initial;
  box-sizing: border-box;
  max-width: none;
}

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

/* 全域防止橫向滾動設定 */
html,
body,
#root,
#app,
.main-container,
.container {
  overflow-x: hidden !important;
  max-width: 100% !important;
  width: 100% !important;
}

/* 確保所有容器元素不會超出視窗寬度 */
div,
section,
article,
main,
aside,
header,
footer,
nav {
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* 防止圖片和媒體元素造成橫向滾動 */
img,
video,
iframe,
embed,
object {
  max-width: 100%;
  height: auto;
}

/* 防止表格造成橫向滾動 */
table {
  max-width: 100%;
  table-layout: fixed;
  overflow-x: auto;
  display: block;
  white-space: nowrap;
}

/* 防止預格式化文字造成橫向滾動 */
pre,
code {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* HTML 和 Body */
html {
  font-size: 16px;
  scroll-behavior: smooth;
  /* 防止橫向滾動 */
  overflow-x: hidden !important;
  max-width: 100% !important;
  width: 100% !important;
}

body {
  font-family:
    "Orbitron", "Rajdhani", "Microsoft JhengHei", "Arial", sans-serif !important;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: linear-gradient(
    135deg,
    var(--bg-primary) 0%,
    var(--bg-secondary) 100%
  );
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* 防止橫向滾動 */
  overflow-x: hidden !important;
  max-width: 100% !important;
  width: 100% !important;
  position: relative;
  /* 確保footer緊貼底部，沒有額外空白 */
  display: flex;
  flex-direction: column;
}

/* 🔧 修復動態生成文字的字體問題 */
body * {
  font-family: inherit;
}

/* 🔧 排除 TIDIO 客服系統元素，不受字體繼承影響 */
*[id*="tidio"],
*[class*="tidio"],
*[id*="tidio"] *,
*[class*="tidio"] *,
#tidio-chat,
#tidio-chat *,
.tidio-chat-container,
.tidio-chat-container *,
.tidiochat,
.tidiochat *,
iframe[src*="tidio"],
iframe[src*="tidio"] * {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif !important;
}

/* 全域字體統一設定已整合到上方 body 規則中 */

/* 等寬字體元素 */
code,
pre,
.mono-font,
input[type="text"],
input[type="password"],
input[type="email"],
textarea,
select {
  font-family:
    "JetBrains Mono", "Courier New", "Microsoft JhengHei", monospace !important;
}

/* 容器 */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--spacing-md);
}

.main-container {
  flex: 1;
  padding-top: 80px; /* 為固定導航欄留出空間 */
}

/* 文字樣式 */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: var(--spacing-md);
  color: var(--text-primary);
}

h1 {
  font-size: 2.5rem;
}
h2 {
  font-size: 2rem;
}
h3 {
  font-size: 1.5rem;
}
h4 {
  font-size: 1.25rem;
}
h5 {
  font-size: 1.125rem;
}
h6 {
  font-size: 1rem;
}

p {
  margin-bottom: var(--spacing-md);
  color: var(--text-secondary);
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: color var(--transition-fast);
}

/* 按鈕樣式 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-sm) var(--spacing-lg);
  font-size: 1rem;
  font-weight: 500;
  text-decoration: none;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  min-height: 44px; /* 符合觸控標準 */
  gap: var(--spacing-sm);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--primary-dark)
  );
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(
    135deg,
    var(--primary-light),
    var(--primary-color)
  );
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  transform: translateY(-2px);
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 2px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--primary-color);
  background: rgba(127, 0, 255, 0.1);
}

.btn-success {
  background: linear-gradient(135deg, var(--success-color), #00a041);
  color: white;
}

.btn-warning {
  background: linear-gradient(135deg, var(--warning-color), #e6a000);
  color: white;
}

.btn-error {
  background: linear-gradient(135deg, var(--error-color), #cc0000);
  color: white;
}

.btn-sm {
  padding: var(--spacing-xs) var(--spacing-md);
  font-size: 0.875rem;
  min-height: 36px;
}

.btn-lg {
  padding: var(--spacing-md) var(--spacing-xl);
  font-size: 1.125rem;
  min-height: 52px;
}

/* 表單元素 */
.form-group {
  margin-bottom: var(--spacing-lg);
}

.form-label {
  display: block;
  margin-bottom: var(--spacing-sm);
  font-weight: 500;
  color: var(--text-primary);
}

.form-control {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 1rem;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(127, 0, 255, 0.1);
}

.form-control::placeholder {
  color: var(--text-muted);
}

/* 卡片樣式 */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--spacing-lg);
  backdrop-filter: blur(10px);
  transition: all var(--transition-normal);
}

.card:hover {
  border-color: var(--border-active);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card-header {
  margin-bottom: var(--spacing-lg);
  padding-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  margin-bottom: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.card-body {
  padding: var(--spacing-lg);
}

.card-footer {
  margin-top: var(--spacing-lg);
  padding-top: var(--spacing-md);
  border-top: 1px solid var(--border-color);
}

/* 網格系統 */
.grid {
  display: grid;
  gap: var(--spacing-lg);
}

.grid-2 {
  grid-template-columns: repeat(2, 1fr);
}
.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}
.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 768px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
}

/* Flex 工具類 */
.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.flex-center {
  align-items: center;
  justify-content: center;
}

.flex-between {
  justify-content: space-between;
}

.flex-around {
  justify-content: space-around;
}

.flex-wrap {
  flex-wrap: wrap;
}

.flex-1 {
  flex: 1;
}

/* 間距工具類 */
.m-0 {
  margin: 0;
}
.m-1 {
  margin: var(--spacing-xs);
}
.m-2 {
  margin: var(--spacing-sm);
}
.m-3 {
  margin: var(--spacing-md);
}
.m-4 {
  margin: var(--spacing-lg);
}
.m-5 {
  margin: var(--spacing-xl);
}

.p-0 {
  padding: 0;
}
.p-1 {
  padding: var(--spacing-xs);
}
.p-2 {
  padding: var(--spacing-sm);
}
.p-3 {
  padding: var(--spacing-md);
}
.p-4 {
  padding: var(--spacing-lg);
}
.p-5 {
  padding: var(--spacing-xl);
}

/* 文字對齊 */
.text-left {
  text-align: left;
}
.text-center {
  text-align: center;
}
.text-right {
  text-align: right;
}

/* 文字顏色 */
.text-primary {
  color: var(--text-primary);
}
.text-secondary {
  color: var(--text-secondary);
}
.text-muted {
  color: var(--text-muted);
}
.text-success {
  color: var(--success-color);
}
.text-warning {
  color: var(--warning-color);
}
.text-error {
  color: var(--error-color);
}

/* 背景顏色 */
.bg-primary {
  background-color: var(--bg-primary);
}
.bg-secondary {
  background-color: var(--bg-secondary);
}
.bg-card {
  background-color: var(--bg-card);
}

/* 邊框 */
.border {
  border: 1px solid var(--border-color);
}
.border-0 {
  border: none;
}
.border-primary {
  border-color: var(--primary-color);
}

/* 圓角 */
.rounded {
  border-radius: var(--radius-md);
}
.rounded-sm {
  border-radius: var(--radius-sm);
}
.rounded-lg {
  border-radius: var(--radius-lg);
}
.rounded-xl {
  border-radius: var(--radius-xl);
}
.rounded-full {
  border-radius: 50%;
}

/* 陰影 */
.shadow {
  box-shadow: var(--shadow-md);
}
.shadow-sm {
  box-shadow: var(--shadow-sm);
}
.shadow-lg {
  box-shadow: var(--shadow-lg);
}
.shadow-none {
  box-shadow: none;
}

/* 顯示/隱藏 */
.hidden {
  display: none !important;
}
.visible {
  visibility: visible;
}
.invisible {
  visibility: hidden;
}

/* 響應式工具類 */
@media (max-width: 768px) {
  .mobile-hidden {
    display: none !important;
  }
  .mobile-only {
    display: block !important;
  }
}

@media (min-width: 769px) {
  .desktop-hidden {
    display: none !important;
  }
  .desktop-only {
    display: block !important;
  }
  .mobile-only {
    display: none !important;
  }
}

/* 載入動畫 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* .fade-in { */
/* animation: fadeIn var(--transition-normal) ease; */
/* } */
.fade-in {
  opacity: 1 !important;
  visibility: visible !important;
}

.slide-in-up {
  animation: slideInUp var(--transition-normal) ease;
}

.pulse {
  animation: pulse 2s infinite;
}

/* 頁面載入動畫 - 移除閃爍效果 */
.page-loaded {
  opacity: 1 !important;
  visibility: visible !important;
  /* animation: fadeIn 0.5s ease; */
}

/* 載入遮罩 */
#initial-loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-loading);
  transition: opacity 0.5s ease;
}

#initial-loading.fade-out {
  opacity: 0;
}

/* SPA 內容容器 */
#spa-content {
  flex: 1;
  /* 防止SPA內容產生橫向滾動 */
  max-width: 100%;
  width: 100%;
  position: relative;
}

/* 額外的防止橫向滾動保護 */
.spa-container,
.page-container,
.content-wrapper {
  overflow-x: hidden;
  max-width: 100%;
  width: 100%;
}

/* 🔧 修復頁面容器高度問題，防止footer下方空白 */
.cyber-main-container,
.main-container,
.upgrade-main,
.profile-main,
.exchange-main,
.lottery-main,
.lottery-room-main,
.lottery-detail-main,
.battle-main,
.battlepass-main,
.fairness-main,
.home-cyber-main {
  /* 使用flex而不是min-height: 100vh 來避免footer下方空白 */
  flex: 1 !important;
  min-height: auto !important;
}

/* 確保頁面內容至少填滿可用空間 */
.page-content,
.main-content {
  min-height: 100%;
}

/* 確保所有文字內容不會造成橫向滾動 */
p,
h1,
h2,
h3,
h4,
h5,
h6,
span,
div {
  overflow-wrap: break-word;
  word-wrap: break-word;
  hyphens: auto;
}

/* 滾動條樣式 */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* 選擇文字樣式 */
::selection {
  background: var(--primary-color);
  color: white;
}

/* 焦點樣式 */
:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* 防止常見造成橫向滾動的元素 */
.grid,
.flex,
.row,
.col {
  max-width: 100%;
  overflow-x: hidden;
}

/* 防止固定寬度元素造成橫向滾動 */
.fixed-width {
  max-width: 100% !important;
  width: auto !important;
}

/* 防止負邊距造成橫向滾動 */
.no-negative-margin {
  margin-left: 0 !important;
  margin-right: 0 !important;
}

/* 響應式容器最大寬度限制 */
@media (max-width: 768px) {
  * {
    max-width: 100% !important;
  }

  /* 排除 TIDIO 客服系統元素，不受移動設備寬度限制影響 */
  *[id*="tidio"],
  *[class*="tidio"],
  *[id*="tidio"] *,
  *[class*="tidio"] *,
  #tidio-chat,
  #tidio-chat *,
  .tidio-chat-container,
  .tidio-chat-container *,
  .tidiochat,
  .tidiochat *,
  iframe[src*="tidio"],
  iframe[src*="tidio"] * {
    max-width: none !important;
    width: auto !important;
  }

  .container,
  .main-container,
  #spa-content {
    padding-left: 15px !important;
    padding-right: 15px !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
}

/* 防止特定元素類型造成橫向滾動 */
canvas,
svg {
  max-width: 100%;
  height: auto;
}

/* 輔助功能 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 打印樣式 */
@media print {
  * {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
  }

  .no-print {
    display: none !important;
  }
}

/* 🚀 戰鬥房間即時推送動畫效果 */
.player-join {
  animation: playerJoinPulse 0.5s ease-out;
  transform: scale(1);
}

.player-leave {
  animation: playerLeaveFade 0.5s ease-out;
}

.player-change {
  animation: playerChangeGlow 0.5s ease-out;
}

@keyframes playerJoinPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(0, 255, 0, 0.7);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 10px rgba(0, 255, 0, 0.3);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(0, 255, 0, 0);
  }
}

@keyframes playerLeaveFade {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(0.95);
    box-shadow: 0 0 0 5px rgba(255, 0, 0, 0.3);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes playerChangeGlow {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 165, 0, 0.7);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(255, 165, 0, 0.4);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 165, 0, 0);
  }
}

/* 即時更新指示器樣式優化 */
.realtime-indicator {
  position: fixed !important;
  top: 20px !important;
  right: 20px !important;
  background: linear-gradient(45deg, #00ff88, #00cc66) !important;
  color: white !important;
  padding: 8px 12px !important;
  border-radius: 20px !important;
  font-size: 12px !important;
  font-weight: bold !important;
  z-index: 10000 !important;
  transition: all 0.3s ease !important;
  box-shadow: 0 2px 10px rgba(0, 255, 136, 0.3) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
}

.realtime-indicator:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 4px 15px rgba(0, 255, 136, 0.5) !important;
}

/* 戰鬥房間玩家區域基本樣式增強 */
.gacha_area {
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.gacha_area::before {
  content: "";
  position: absolute;
  top: -2px;
  left: -2px;
  right: -2px;
  bottom: -2px;
  background: transparent;
  border-radius: inherit;
  z-index: -1;
  transition: all 0.3s ease;
  opacity: 0;
}

/* 玩家狀態指示 */
.player-online .gacha_area::before {
  background: linear-gradient(45deg, #00ff88, #00cc66);
  opacity: 0.3;
}

.player-waiting .gacha_area::before {
  background: linear-gradient(45deg, #ffa500, #ff8c00);
  opacity: 0.3;
}

/* 響應式設計 */
@media (max-width: 768px) {
  .realtime-indicator {
    top: 10px !important;
    right: 10px !important;
    font-size: 11px !important;
    padding: 6px 10px !important;
  }
}

/* 減少動畫對性能的影響 */
@media (prefers-reduced-motion: reduce) {
  .player-join,
  .player-leave,
  .player-change {
    animation: none;
  }

  .gacha_area {
    transition: none;
  }

  .realtime-indicator {
    transition: opacity 0.1s ease !important;
  }
}
