/* ===========================
   Design System & Variables
   =========================== */
:root {
  /* Colors - Default Dark Theme */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);

  --text-primary: #f0f0f5;
  --text-secondary: #a0a0b8;
  --text-muted: #5a5a70;

  --accent-primary: #6366f1;
  --accent-secondary: #8b5cf6;
  --accent-gradient: linear-gradient(
    135deg,
    #6366f1 0%,
    #8b5cf6 50%,
    #a855f7 100%
  );

  /* Taiwan Stock Market Convention: Red for Gains, Green for Losses */
  --gain-color: #f87171;
  --gain-bg: rgba(248, 113, 113, 0.12);
  --loss-color: #34d399;
  --loss-bg: rgba(52, 211, 153, 0.12);
  --warning: #fbbf24;

  /* General UI colors */
  --success: #34d399;
  --success-bg: rgba(52, 211, 153, 0.12);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);

  /* Medals */
  --gold: linear-gradient(135deg, #ffd700 0%, #ffed4a 50%, #f59e0b 100%);
  --silver: linear-gradient(135deg, #c0c0c0 0%, #e8e8e8 50%, #a0a0a0 100%);
  --bronze: linear-gradient(135deg, #cd7f32 0%, #e8a860 50%, #b87333 100%);

  /* Card quality */
  --card-border: rgba(255, 255, 255, 0.08);
  --card-border-hover: rgba(255, 255, 255, 0.15);
  --card-shine: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0) 60%
  );

  /* Spacing - Fluid */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: clamp(0.75rem, 0.5rem + 0.5vw, 1rem);
  --space-lg: clamp(1rem, 0.75rem + 0.5vw, 1.5rem);
  --space-xl: clamp(1.25rem, 1rem + 0.5vw, 2rem);
  --space-2xl: clamp(2rem, 1.5rem + 1vw, 3rem);

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.3);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ===========================
   CNY Theme Override (限時新春主題)
   =========================== */
body.cny-theme {
  --bg-secondary: #8b0000;
  --bg-card: rgba(139, 0, 0, 0.8);
  --bg-card-hover: rgba(139, 0, 0, 0.9);
  --text-primary: #ffd700;
  --text-secondary: #ffc125;
  --text-muted: #cd853f;
  --accent-primary: #ffd700;
  --accent-secondary: #ffa500;
  --accent-gradient: linear-gradient(
    135deg,
    #ffd700 0%,
    #ffa500 50%,
    #ff8c00 100%
  );
  --gain-color: #ffd700;
  --gain-bg: rgba(255, 215, 0, 0.2);
  --loss-color: #90ee90;
  --loss-bg: rgba(144, 238, 144, 0.2);
  --shadow-glow: 0 0 40px rgba(255, 215, 0, 0.4);
}

/* Hide horse icon by default, show only in CNY theme */
.horse-icon {
  display: none;
}

body.cny-theme .horse-icon {
  display: block;
  font-size: 2rem;
  margin-top: var(--space-xs);
  animation: bounce 2s infinite;
}

/* ===========================
   Base Styles
   =========================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: clamp(14px, 0.875rem + 0.25vw, 16px);
  scroll-behavior: smooth;
}

body {
  font-family:
    "Inter",
    "Noto Sans TC",
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

/* Animated Background */
body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(
      ellipse at 20% 20%,
      rgba(99, 102, 241, 0.15) 0%,
      transparent 50%
    ),
    radial-gradient(
      ellipse at 80% 80%,
      rgba(139, 92, 246, 0.1) 0%,
      transparent 50%
    ),
    radial-gradient(
      ellipse at 50% 50%,
      rgba(168, 85, 247, 0.05) 0%,
      transparent 70%
    );
  pointer-events: none;
  z-index: -1;
}

/* ===========================
   Layout
   =========================== */
.app-container {
  max-width: 900px;
  margin: 0 auto;
  padding: var(--space-lg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  transition:
    transform 0.3s ease,
    opacity 0.3s ease;
}

/* 月份切換滑動動畫 */
.app-container.slide-left {
  transform: translateX(-100px);
  opacity: 0;
}

.app-container.slide-right {
  transform: translateX(100px);
  opacity: 0;
}

.app-container.slide-left-enter {
  transform: translateX(100px);
  opacity: 0;
  animation: slideInFromRight 0.3s ease forwards;
}

.app-container.slide-right-enter {
  transform: translateX(-100px);
  opacity: 0;
  animation: slideInFromLeft 0.3s ease forwards;
}

@keyframes slideInFromRight {
  from {
    transform: translateX(100px);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideInFromLeft {
  from {
    transform: translateX(-100px);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ===========================
   Header
   =========================== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-md);
  animation: fadeInDown 0.6s ease;
  gap: var(--space-md);
  position: relative;
}

.header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 5%;
  right: 5%;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(99, 102, 241, 0.3),
    transparent
  );
}

.header-content {
  flex: 1;
  text-align: center;
}

/* 左右兩側容器 - 手機版（預設置中） */
.header-left,
.header-right {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  flex: 0 0 auto;
  width: 80px;
}

/* Role Indicator 手機版 */
.role-indicator {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  white-space: nowrap;
  margin-top: var(--space-sm);
}

.role-indicator .btn-logout {
  font-size: 0.7rem;
  padding: 2px 6px;
}

/* 桌面版 header 佈局 - 月份按鈕水平對齊，融資/來賓水平對齊 */
@media (min-width: 700px) {
  .header-left,
  .header-right {
    width: auto;
    gap: var(--space-sm);
  }

  .header-left {
    align-items: flex-start !important;
  }

  .header-right {
    align-items: flex-end !important;
  }

  .role-indicator {
    font-size: 0.875rem;
  }

  .role-indicator .btn-logout {
    font-size: 0.875rem;
    padding: 4px 12px;
  }

  .margin-link {
    font-size: 0.875rem;
  }
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  margin-bottom: var(--space-sm);
}

.logo-icon {
  font-size: 2.5rem;
  animation: bounce 2s infinite;
}

.logo h1 {
  font-size: clamp(1.5rem, 1rem + 2.5vw, 2.5rem);
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-secondary);
  font-size: clamp(0.75rem, 0.65rem + 0.4vw, 1rem);
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.horse-icon {
  font-size: 2rem;
  margin-top: var(--space-xs);
  animation: bounce 2s infinite;
  cursor: pointer;
  transition:
    transform 0.3s ease,
    filter 0.3s ease;
}

.horse-icon:hover {
  transform: scale(1.2);
  filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.8));
}

/* 當不在當月時，馬下方顯示文字提示 */
.horse-icon.not-current-month {
  position: relative;
}

.horse-icon.not-current-month::after {
  content: "回當月";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 2px;
  font-size: 0.55rem;
  color: var(--gold);
  white-space: nowrap;
  animation: textBlink 1.5s ease-in-out infinite;
  font-weight: 600;
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
  background: rgba(0, 0, 0, 0.6);
  padding: 2px 6px;
  border-radius: 4px;
}

@keyframes textBlink {
  0%,
  100% {
    opacity: 0.6;
  }

  50% {
    opacity: 1;
  }
}

/* 桌面版放大馬的圖示 */
@media (min-width: 700px) {
  .horse-icon,
  body.cny-theme .horse-icon {
    font-size: 4rem;
  }

  .horse-icon.not-current-month::after {
    font-size: 1rem;
    margin-top: 0;
  }
}

/* 月份導航按鈕 */
.month-nav-btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.3s ease;
  min-width: 80px;
}

.month-nav-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 215, 0, 0.3);
  color: var(--text-primary);
  transform: scale(1.05);
}

.month-nav-btn:active {
  transform: scale(0.98);
}

.nav-arrow {
  font-size: 1.2rem;
  line-height: 1;
}

.nav-month {
  font-size: 0.9rem;
  font-weight: 600;
}

/* 新春主題下的導航按鈕 */
body.cny-theme .month-nav-btn:hover {
  border-color: rgba(255, 215, 0, 0.5);
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.2);
}

/* 桌面版放大月份導航按鈕 */
@media (min-width: 700px) {
  .month-nav-btn {
    padding: var(--space-lg) var(--space-xl);
    min-width: 110px;
  }

  .nav-arrow {
    font-size: 2rem;
  }

  .nav-month {
    font-size: 1.35rem;
  }
}

/* 月份導航按鈕鎖定狀態（16號前） */
.month-nav-btn.frozen {
  opacity: 0.4;
  cursor: not-allowed;
}

.month-nav-btn.frozen::after {
  content: " 🔒";
  font-size: 0.8rem;
}

.month-nav-btn.frozen:hover {
  transform: none;
  background: rgba(255, 255, 255, 0.05);
}

/* ===========================
   Cards
   =========================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  transition: var(--transition-normal);
  animation: fadeInUp 0.5s ease backwards;
  overflow: hidden;
  position: relative;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
}

/* Staggered card entrance */
.card:nth-child(1) {
  animation-delay: 0s;
}

.card:nth-child(2) {
  animation-delay: 0.08s;
}

.card:nth-child(3) {
  animation-delay: 0.16s;
}

.card:nth-child(4) {
  animation-delay: 0.24s;
}

.card:nth-child(5) {
  animation-delay: 0.32s;
}

.card:hover {
  background: var(--bg-card-hover);
  border-color: var(--card-border-hover);
  box-shadow:
    var(--shadow-md),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transform: translateY(-1px);
}

.card-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: clamp(1rem, 0.85rem + 0.5vw, 1.25rem);
  font-weight: 700;
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-md);
  color: var(--text-primary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  position: relative;
}

.card-title::before {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 40px;
  height: 2px;
  background: var(--accent-gradient);
  border-radius: 2px;
}

.leaderboard-title {
  justify-content: space-between;
}

.title-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.card-icon {
  font-size: 1.5rem;
}

/* ===========================
   Settings Card
   =========================== */
.date-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-lg);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.input-group label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.date-input {
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  color: var(--text-primary);
  font-size: 1rem;
  font-family: inherit;
  transition: var(--transition-fast);
  cursor: pointer;
}

.date-input:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.date-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(255, 215, 0, 0.3);
}

.date-note {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===========================
   Participants Grid
   =========================== */
.participants-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.participant-row {
  display: grid;
  grid-template-columns: 40px 120px 100px minmax(0, 1fr) 120px 120px 20px;
  gap: var(--space-md);
  align-items: center;
  padding: var(--space-md);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: var(--transition-fast);
  box-sizing: border-box;
  width: 100%;
  position: relative;
  /* 讓子元素可以絕對定位 */
}

.participant-row:hover {
  border-color: rgba(255, 255, 255, 0.1);
  transform: translateX(4px);
}

.participant-number {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-gradient);
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.8rem;
  margin: 0 auto;
}

.participant-input {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  color: #ffd700;
  font-size: 0.95rem;
  font-weight: 500;
  font-family: inherit;
  transition: var(--transition-fast);
}

.participant-input::placeholder {
  color: var(--text-muted);
}

.participant-input:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.participant-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.1);
}

.participant-input.stock-code {
  font-family: "SF Mono", "Fira Code", monospace;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1.5px dashed rgba(255, 215, 0, 0.5);
  background: rgba(255, 215, 0, 0.08);
  text-align: center;
}

.participant-input.stock-code:focus {
  border-color: var(--accent-primary);
  border-style: solid;
  background: rgba(255, 215, 0, 0.15);
}

.participant-input.stock-code::placeholder {
  color: rgba(255, 215, 0, 0.45);
  font-size: 0.8rem;
  letter-spacing: 0;
  font-family: inherit;
  text-transform: none;
}

.participant-input.stock-name-display {
  font-size: 0.85rem;
  color: rgba(255, 215, 0, 0.6);
  background: rgba(0, 0, 0, 0.25);
  border-color: transparent;
  cursor: default;
  font-style: italic;
}

.participant-input.stock-name-display::placeholder {
  color: rgba(255, 255, 255, 0.15);
  font-style: italic;
}

.participant-input.price-input {
  text-align: right;
}

/* Stock Code Group with Reload Button */
.stock-code-group {
  display: flex;
  gap: var(--space-xs);
  align-items: center;
}

.stock-code-group .stock-code {
  flex: 1;
}

.btn-reload {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: var(--transition-fast);
  flex-shrink: 0;
}

.btn-reload:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.5);
  transform: scale(1.1);
}

.btn-reload:active {
  transform: scale(0.95);
}

/* Remove Button */
.btn-remove {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: 50%;
  color: #ef4444;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-remove:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
  transform: scale(1.1);
}

.btn-remove:active {
  transform: scale(0.95);
}

/* Add Participant Button */
.btn-add-participant {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  width: 100%;
  box-sizing: border-box;
  padding: var(--space-md);
  margin-top: var(--space-md);
  background: rgba(99, 102, 241, 0.1);
  border: 2px dashed rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-md);
  color: var(--accent-primary);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-normal);
}

.btn-add-participant:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: rgba(99, 102, 241, 0.5);
  transform: translateY(-2px);
}

.btn-add-participant:active {
  transform: translateY(0);
}

/* ===========================
   Buttons
   =========================== */
.action-buttons {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
  flex-wrap: wrap;
}

/* 桌面版：按鈕同一行 */
@media (min-width: 768px) {
  .action-buttons {
    flex-wrap: nowrap;
  }

  .action-buttons .btn {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.9rem;
  }
}

.action-buttons-secondary {
  display: flex;
  justify-content: center;
  width: 100%;
  margin-top: var(--space-md);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.btn::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: var(--transition-slow);
}

.btn:hover::before {
  left: 100%;
}

.btn-icon {
  font-size: 1.25rem;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
  box-shadow:
    var(--shadow-sm),
    0 0 20px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow:
    var(--shadow-md),
    0 0 30px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-start {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
  box-shadow:
    var(--shadow-sm),
    0 0 20px rgba(245, 158, 11, 0.3);
}

.btn-start:hover {
  transform: translateY(-2px);
  box-shadow:
    var(--shadow-md),
    0 0 30px rgba(245, 158, 11, 0.4);
}

.btn-start:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-fetch {
  background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
  color: white;
  box-shadow:
    var(--shadow-sm),
    0 0 20px rgba(6, 182, 212, 0.3);
}

.btn-fetch:hover {
  transform: translateY(-2px);
  box-shadow:
    var(--shadow-md),
    0 0 30px rgba(6, 182, 212, 0.4);
}

.btn-fetch:disabled,
.btn-start:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Danger Button (Clear Data) */
.btn-danger {
  background: linear-gradient(135deg, #dc2626 0%, #ef4444 100%);
  color: white;
  box-shadow:
    var(--shadow-sm),
    0 0 20px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow:
    var(--shadow-md),
    0 0 30px rgba(239, 68, 68, 0.4);
}

/* Warning Button (Clear Current Price) */
.btn-warning {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
  box-shadow:
    var(--shadow-sm),
    0 0 20px rgba(245, 158, 11, 0.3);
}

.btn-warning:hover {
  transform: translateY(-2px);
  box-shadow:
    var(--shadow-md),
    0 0 30px rgba(245, 158, 11, 0.4);
}


/* ===========================
   Participants Header
   =========================== */
.participants-header {
  display: grid;
  grid-template-columns: 40px 120px 100px minmax(0, 1fr) 120px 120px 20px;
  gap: var(--space-md);
  align-items: center;
  /* 垂直置中對齊 */
  padding: var(--space-sm) var(--space-md);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: var(--space-sm);
  width: 100%;
  box-sizing: border-box;
}

/* Desktop header - align each column to match text inside inputs */
/* 第1欄：空（#編號位置） */
.participants-header span:nth-child(1) {
  text-align: center;
}

/* 第2欄：參賽者 - 配合下拉選單 padding */
.participants-header span:nth-child(2) {
  text-align: left;
  padding-left: var(--space-md);
}

/* 第3欄：代碼 - 配合輸入框置中 */
.participants-header span:nth-child(3) {
  text-align: center;
}

/* 第4欄：股票名稱 - 配合輸入框 padding */
.participants-header span:nth-child(4) {
  text-align: left;
  padding-left: var(--space-md);
}

/* 第5欄：起始價 - 配合輸入框置中 */
.participants-header span:nth-child(5) {
  text-align: center;
}

/* 第6欄：最新價 - 配合輸入框置中 */
.participants-header span:nth-child(6) {
  text-align: center;
}

/* 第7欄：空（刪除按鈕位置） */

/* Mobile header - hidden by default on desktop */
.participants-header-mobile {
  display: none;
}

/* ===========================
   Tablet Grid Override (iPad mini / small tablets)
   Must be AFTER base .participants-header / .participant-row
   definitions so it wins via cascade.
   =========================== */
@media (min-width: 700px) and (max-width: 899px) {
  .participant-row {
    grid-template-columns: 32px 90px 75px minmax(60px, 1fr) 85px 85px 16px;
    gap: 8px;
    padding: 10px;
  }

  .participants-header {
    grid-template-columns: 32px 90px 75px minmax(60px, 1fr) 85px 85px 16px;
    gap: 8px;
    padding: var(--space-xs) 10px;
    font-size: 0.65rem;
    white-space: nowrap;
  }

  .participants-header span:nth-child(2),
  .participants-header span:nth-child(4) {
    padding-left: 8px;
  }

  .participant-input {
    padding: 6px 8px;
    font-size: 0.85rem;
  }

  .participant-number {
    width: 22px;
    height: 22px;
    font-size: 0.7rem;
  }
}

/* ===========================
   Member Toggle (積分會員/友誼參賽)
   =========================== */
/* 非會員：暗色數字圓圈 */
.participant-number.guest {
  background: rgba(255, 255, 255, 0.15);
  opacity: 0.6;
}

/* Guest/Non-member badge in leaderboard */
.guest-badge {
  margin-left: 4px;
  font-size: 0.9rem;
}

.guest-participant {
  opacity: 0.85;
  border-style: dashed !important;
}

.guest-participant .participant-name {
  color: var(--text-secondary);
}

/* ===========================
   Last Updated
   =========================== */
.last-updated {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: var(--space-sm);
  transition: color 0.3s ease;
}

.last-updated.fresh {
  color: #4ade80;
}

.last-updated.stale {
  color: #fbbf24;
}

/* ===========================
   Contest Status
   =========================== */
.contest-status {
  text-align: center;
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

.status-live {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  font-weight: 600;
  animation: pulse 2s infinite;
}

.status-final {
  background: rgba(255, 215, 0, 0.2);
  color: #ffd700;
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-md);
  font-weight: 600;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

/* ===========================
   Leaderboard
   =========================== */
.leaderboard-card {
  animation: fadeInUp 0.6s ease;
}

.leaderboard {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.leaderboard-item {
  display: grid;
  grid-template-columns: 60px 1fr auto;
  gap: var(--space-lg);
  align-items: center;
  padding: var(--space-lg);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: slideIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) backwards;
  position: relative;
  overflow: hidden;
}

/* 排行榜項目頂部光線 */
.leaderboard-item::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.08),
    transparent
  );
}

.leaderboard-item:nth-child(1) {
  animation-delay: 0.05s;
}

.leaderboard-item:nth-child(2) {
  animation-delay: 0.12s;
}

.leaderboard-item:nth-child(3) {
  animation-delay: 0.19s;
}

.leaderboard-item:nth-child(4) {
  animation-delay: 0.26s;
}

.leaderboard-item:nth-child(5) {
  animation-delay: 0.33s;
}

.leaderboard-item:nth-child(6) {
  animation-delay: 0.4s;
}

.leaderboard-item:nth-child(7) {
  animation-delay: 0.47s;
}

.leaderboard-item:nth-child(8) {
  animation-delay: 0.54s;
}

.leaderboard-item:nth-child(9) {
  animation-delay: 0.61s;
}

.leaderboard-item:nth-child(10) {
  animation-delay: 0.68s;
}

.leaderboard-item:hover {
  transform: translateX(6px);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.leaderboard-item.rank-1 {
  background: linear-gradient(
    135deg,
    rgba(255, 215, 0, 0.1) 0%,
    rgba(255, 215, 0, 0.02) 100%
  );
  border-color: rgba(255, 215, 0, 0.3);
  animation: goldGlow 2s ease-in-out 3 forwards;
  /* 6秒後停止，保留最終狀態 */
}

/* 第一名金光閃爍動畫 */
@keyframes goldGlow {
  0%,
  100% {
    box-shadow:
      0 4px 20px rgba(255, 215, 0, 0.2),
      0 0 40px rgba(255, 215, 0, 0.1),
      inset 0 0 20px rgba(255, 215, 0, 0.05);
    border-color: rgba(255, 215, 0, 0.3);
  }

  50% {
    box-shadow:
      0 4px 30px rgba(255, 215, 0, 0.4),
      0 0 60px rgba(255, 215, 0, 0.2),
      inset 0 0 30px rgba(255, 215, 0, 0.1);
    border-color: rgba(255, 215, 0, 0.6);
  }
}

.leaderboard-item.rank-2 {
  background: linear-gradient(
    135deg,
    rgba(192, 192, 192, 0.1) 0%,
    rgba(192, 192, 192, 0.02) 100%
  );
  border-color: rgba(192, 192, 192, 0.3);
}

.leaderboard-item.rank-3 {
  background: linear-gradient(
    135deg,
    rgba(205, 127, 50, 0.1) 0%,
    rgba(205, 127, 50, 0.02) 100%
  );
  border-color: rgba(205, 127, 50, 0.3);
}

.rank-badge {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 1.5rem;
  font-weight: 800;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.rank-1 .rank-badge {
  background: var(--gold);
  color: #1a1a1a;
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
  animation: crownBounce 1.5s ease-in-out 4;
  /* 6秒後停止 */
}

/* 第一名皇冠彈跳動畫 */
@keyframes crownBounce {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }

  25% {
    transform: translateY(-4px) scale(1.05);
  }

  50% {
    transform: translateY(0) scale(1);
  }

  75% {
    transform: translateY(-2px) scale(1.02);
  }
}

.rank-2 .rank-badge {
  background: var(--silver);
  color: #1a1a1a;
  box-shadow: 0 0 15px rgba(192, 192, 192, 0.3);
}

.rank-3 .rank-badge {
  background: var(--bronze);
  color: #1a1a1a;
  box-shadow: 0 0 15px rgba(205, 127, 50, 0.3);
}

.rank-other .rank-badge {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 2px solid rgba(255, 255, 255, 0.1);
}

.participant-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-width: 0;
}

/* ===========================
   Leaderboard Avatar
   =========================== */
.leaderboard-avatar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.avatar-circle {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent-gradient);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
  letter-spacing: 0;
}

.rank-1 .avatar-circle {
  background: var(--gold);
  color: #1a1a1a;
  box-shadow: 0 2px 12px rgba(255, 215, 0, 0.4);
}

.rank-2 .avatar-circle {
  background: var(--silver);
  color: #1a1a1a;
  box-shadow: 0 2px 10px rgba(192, 192, 192, 0.3);
}

.rank-3 .avatar-circle {
  background: var(--bronze);
  color: #1a1a1a;
  box-shadow: 0 2px 10px rgba(205, 127, 50, 0.3);
}

/* ===========================
   Gain Progress Bar
   =========================== */
.gain-bar-container {
  margin-top: var(--space-xs);
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
  max-width: 200px;
}

.gain-bar {
  height: 100%;
  border-radius: 2px;
  transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
  min-width: 2px;
}

.gain-bar.positive {
  background: linear-gradient(90deg, var(--gain-color), #fca5a5);
}

.gain-bar.negative {
  background: linear-gradient(90deg, var(--loss-color), #6ee7b7);
}

.participant-header {
  display: grid;
  grid-template-columns: 80px auto auto;
  align-items: center;
  gap: var(--space-md);
}

.participant-name {
  font-size: clamp(1rem, 0.85rem + 0.5vw, 1.35rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.stock-info {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  font-size: 1rem;
  color: var(--text-secondary);
}

.stock-code-badge {
  background: rgba(99, 102, 241, 0.25);
  color: var(--accent-primary);
  padding: 4px 10px;
  border-radius: 6px;
  font-family: "SF Mono", monospace;
  font-weight: 600;
  font-size: 0.95rem;
}

.gain-display {
  text-align: right;
  min-width: 100px;
}

.gain-percent {
  font-size: clamp(1.25rem, 1rem + 1vw, 1.75rem);
  font-weight: 700;
}

.gain-percent.positive {
  color: var(--gain-color);
  /* Red for gains (Taiwan style) */
}

.gain-percent.negative {
  color: var(--loss-color);
  /* Green for losses (Taiwan style) */
}

.price-change {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.stock-name-label {
  color: var(--text-primary);
  font-weight: 500;
  margin-left: var(--space-sm);
}

.price-range {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ===========================
   Status Message
   =========================== */
.status-message {
  position: fixed;
  bottom: var(--space-xl);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-xl);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: var(--transition-normal);
  opacity: 0;
  pointer-events: none;
  z-index: 1000;
}

.status-message.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.status-message.success {
  border-color: var(--success);
  background: var(--success-bg);
}

.status-message.error {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.status-message.info {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.15);
}

.status-message.warning {
  border-color: var(--warning);
  background: rgba(245, 158, 11, 0.15);
}

/* ===========================
   Login Modal
   =========================== */
.login-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.3s ease;
}

.login-content {
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  width: 90%;
  max-width: 400px;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  text-align: center;
}

.login-title {
  font-size: 2rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-sm);
}

.login-subtitle {
  color: var(--text-secondary);
  margin-bottom: var(--space-xl);
}

.login-options {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.login-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-lg);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-normal);
}

.login-btn:hover {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.1);
  transform: translateY(-2px);
}

.login-btn-icon {
  font-size: 2rem;
}

.login-btn-text {
  font-size: 1.1rem;
  font-weight: 600;
}

.login-btn-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.guest-btn {
  border-color: rgba(16, 185, 129, 0.3);
}

.guest-btn:hover {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.1);
}

.login-divider {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  color: var(--text-muted);
  font-size: 0.875rem;
}

.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
}

.admin-login {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.admin-login-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.admin-btn-small {
  background: var(--bg-card);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
}

.admin-btn-small:hover {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.1);
  color: var(--text-primary);
}

.admin-password-input {
  flex: 1;
  background: var(--bg-primary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}

.admin-password-input:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.login-error {
  color: #ef4444;
  font-size: 0.875rem;
  padding: var(--space-sm);
  background: rgba(239, 68, 68, 0.1);
  border-radius: var(--radius-sm);
}

/* ===========================
   Countdown Modal (16號限制提示)
   =========================== */
.countdown-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.3s ease;
}

.countdown-content {
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  width: 90%;
  max-width: 320px;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  text-align: center;
  animation: fadeInUp 0.3s ease;
}

.countdown-icon {
  font-size: 3.5rem;
  margin-bottom: var(--space-md);
  animation: pulse 2s infinite;
}

.countdown-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.countdown-message {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: var(--space-lg);
}

.countdown-days {
  font-size: 4rem;
  font-weight: 800;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1;
}

.countdown-label {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: var(--space-xl);
}

.countdown-close-btn {
  background: linear-gradient(
    135deg,
    var(--accent-primary),
    var(--accent-secondary)
  );
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-xl);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-fast);
}

.countdown-close-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

/* ===========================
   Role Indicator Colors
   =========================== */
.role-indicator.admin {
  color: var(--accent-primary);
}

.role-indicator.guest {
  color: var(--text-secondary);
}

.btn-logout {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 0.75rem;
  padding: 2px 8px;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-logout:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

/* Desktop Leaderboard - Larger fonts */
@media (min-width: 768px) {
  .leaderboard-item {
    grid-template-columns: 70px 1fr auto;
    gap: var(--space-xl);
    padding: var(--space-lg) var(--space-xl);
  }

  .leaderboard-item .rank-badge {
    width: 56px;
    height: 56px;
    font-size: 1.6rem;
  }

  .participant-header {
    grid-template-columns: 100px 70px auto;
    gap: var(--space-lg);
  }

  .participant-name {
    font-size: 1.5rem;
    font-weight: 700;
  }

  .stock-code-badge {
    padding: 5px 12px;
    font-size: 1rem;
    border-radius: 6px;
  }

  .stock-name-label {
    font-size: 1.1rem;
    color: var(--text-secondary);
  }

  .price-range {
    font-size: 1rem;
  }

  .gain-percent {
    font-size: 2rem;
  }

  .gain-amount {
    font-size: 1rem;
  }
}

/* Disabled input style */
.input-disabled {
  opacity: 1 !important;
  cursor: not-allowed !important;
  background: rgba(0, 0, 0, 0.3) !important;
}

/* ===========================
   Footer
   =========================== */
.footer {
  text-align: center;
  padding: var(--space-xl) 0;
  color: var(--text-muted);
  font-size: 0.875rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  margin-top: auto;
}

/* ===========================
   Progress Modal
   =========================== */
.progress-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease;
}

.progress-content {
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl);
  width: 90%;
  max-width: 500px;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.progress-title {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-lg);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.progress-bar-container {
  height: 24px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: var(--space-md);
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6366f1 0%, #8b5cf6 50%, #a855f7 100%);
  border-radius: 12px;
  transition: width 0.3s ease;
  position: relative;
}

.progress-bar::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(100%);
  }
}

.progress-text {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-md);
}

.progress-details {
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  max-height: 200px;
  overflow-y: auto;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.8;
}

.progress-details .success {
  color: #10b981;
}

.progress-details .error {
  color: #ef4444;
}

.progress-details .skip {
  color: #f59e0b;
}

/* 取消按鈕 */
.btn-cancel-fetch {
  display: block;
  width: 100%;
  margin-top: var(--space-lg);
  padding: var(--space-md) var(--space-lg);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  backdrop-filter: blur(4px);
}

.btn-cancel-fetch:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
  transform: translateY(-1px);
}

.btn-cancel-fetch:active:not(:disabled) {
  transform: translateY(0);
  background: rgba(239, 68, 68, 0.25);
}

.btn-cancel-fetch:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* ===========================
   Animations
   =========================== */
@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes bounce {
  0%,
  100% {
    transform: rotate(-5deg);
  }

  50% {
    transform: rotate(5deg);
  }
}

/* ===========================
   Responsive Design - Mobile Optimized
   =========================== */

/* Tablet and smaller */
@media (max-width: 699px) {
  .app-container {
    padding: var(--space-sm);
    gap: var(--space-md);
  }

  .logo h1 {
    font-size: 1.5rem;
  }

  /* Participants Header - Hide on mobile */
  .participants-header {
    display: none;
  }

  /* Participant rows - stack vertically on mobile */
  .participant-row {
    grid-template-columns: 28px 1fr 28px;
    grid-template-rows: auto auto auto auto auto;
    gap: 4px;
    padding: var(--space-sm);
  }

  .participant-row .participant-number {
    grid-row: 1 / 6;
    grid-column: 1;
    align-self: start;
    margin-top: 2px;
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
  }

  .participant-row .name-input,
  .participant-row .name-select {
    grid-row: 1;
    grid-column: 2;
    width: 100%;
    min-width: 0;
  }

  .participant-row .stock-code-group {
    grid-row: 2;
    grid-column: 2;
  }

  .participant-row .stock-name-display {
    grid-row: 3;
    grid-column: 2;
  }

  .participant-row .price-input:nth-of-type(4) {
    grid-row: 4;
    grid-column: 2;
  }

  .participant-row .price-input:nth-of-type(5) {
    grid-row: 5;
    grid-column: 2;
  }

  .participant-row .btn-remove {
    grid-row: 1;
    grid-column: 3;
    align-self: start;
    margin-top: 2px;
    width: 24px;
    height: 24px;
    font-size: 0.8rem;
  }

  /* Hide member checkbox on tablet/mobile */
  .participant-row .member-checkbox {
    display: none;
  }

  .card {
    padding: var(--space-md);
  }

  /* Leaderboard adjustments */
  .leaderboard-item {
    grid-template-columns: 40px 1fr;
    grid-template-rows: auto auto;
    gap: var(--space-sm);
    padding: var(--space-sm);
  }

  .leaderboard-item .rank-badge {
    grid-row: 1 / 3;
    align-self: start;
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  .leaderboard-item .participant-info {
    grid-row: 1;
    grid-column: 2;
  }

  .gain-display {
    grid-row: 2;
    grid-column: 2;
    text-align: left;
  }

  /* Action buttons */
  .action-buttons {
    gap: var(--space-xs);
  }

  .btn {
    font-size: 0.85rem;
    padding: 6px 12px;
  }

  /* 參賽者 Header Mobile - 對齊欄位內文字 */
  .participants-header-mobile span:nth-child(2) {
    text-align: left;
    padding-left: 8px;
  }

  .participants-header-mobile span:nth-child(3) {
    text-align: left;
    padding-left: 4px;
  }

  .participants-header-mobile span:nth-child(4) {
    text-align: left;
    padding-left: 4px;
  }

  .participants-header-mobile span:nth-child(5) {
    text-align: right;
    padding-right: 4px;
  }

  .participants-header-mobile span:nth-child(6) {
    text-align: right;
    padding-right: 4px;
  }
}

/* ===========================
   Ultra Compact Mobile (Single Screen)
   =========================== */
@media (max-width: 480px) {
  /* Root spacing overrides for ultra-compact */
  :root {
    --space-xs: 0.15rem;
    --space-sm: 0.3rem;
    --space-md: 0.5rem;
    --space-lg: 0.75rem;
    --space-xl: 1rem;
    --space-2xl: 1.25rem;
  }

  body {
    font-size: 14px;
    line-height: 1.4;
  }

  .app-container {
    padding: 8px;
    gap: 8px;
    min-height: auto;
  }

  /* Ultra compact header */
  .header {
    padding: 8px 0;
  }

  .logo {
    gap: 6px;
    margin-bottom: 2px;
  }

  .logo-icon {
    font-size: 1.25rem;
    animation: none;
  }

  .logo h1 {
    font-size: 1.1rem;
  }

  .subtitle {
    font-size: 0.7rem;
    letter-spacing: 0.05em;
  }

  .last-updated {
    font-size: 0.65rem;
    margin-top: 2px;
  }

  /* Ultra compact cards */
  .card {
    padding: 10px;
    border-radius: 10px;
  }

  .card-title {
    font-size: 0.9rem;
    margin-bottom: 8px;
    gap: 4px;
  }

  .card-icon {
    font-size: 1rem;
  }

  /* Settings card - inline dates */
  .date-inputs {
    display: flex;
    gap: 8px;
  }

  .input-group {
    flex: 1;
    gap: 2px;
  }

  .input-group label {
    font-size: 0.7rem;
  }

  .date-input {
    padding: 6px 8px;
    font-size: 0.8rem;
    border-radius: 6px;
  }

  .date-note {
    display: none;
  }

  /* Hide desktop header, show mobile header */
  .participants-header {
    display: none !important;
  }

  .participants-header-mobile {
    display: grid;
    grid-template-columns: 24px minmax(85px, 1.4fr) 44px minmax(
        40px,
        0.9fr
      ) minmax(48px, 1fr) minmax(48px, 1fr);
    gap: 4px;
    padding: 4px 8px;
    color: var(--text-muted);
    font-size: 0.55rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 3px;
  }

  /* Align each header column to match text inside inputs */
  /* nth-child(1) = 空白 */
  .participants-header-mobile span:nth-child(1) {
    text-align: center;
  }

  /* nth-child(2) = 參賽者 - 對齊下拉選單內文字 */
  .participants-header-mobile span:nth-child(2) {
    text-align: left;
    padding-left: 8px;
  }

  /* nth-child(3) = 選股 - 對齊輸入框內文字 */
  .participants-header-mobile span:nth-child(3) {
    text-align: left;
    padding-left: 4px;
  }

  /* nth-child(4) = 名稱 - 對齊輸入框內文字 */
  .participants-header-mobile span:nth-child(4) {
    text-align: left;
    padding-left: 4px;
  }

  /* nth-child(5) = 起始價 - 對齊輸入框內數字結尾 */
  .participants-header-mobile span:nth-child(5) {
    text-align: right;
    padding-right: 4px;
  }

  /* nth-child(6) = 最新價 - 對齊輸入框內數字結尾 */
  .participants-header-mobile span:nth-child(6) {
    text-align: right;
    padding-right: 4px;
  }

  /* nth-child(7) = 空白（隱藏） */
  .participants-header-mobile span:nth-child(7) {
    display: none;
  }

  /* Ultra compact participant rows - SINGLE ROW layout */
  .participants-grid {
    gap: 6px;
  }

  .participant-row {
    /* Single row without X button: [#] [Name] [Code] [StockName] [StartPrice] [CurrentPrice] */
    display: grid;
    grid-template-columns: 24px minmax(60px, 1fr) 44px minmax(
        40px,
        0.9fr
      ) minmax(48px, 1fr) minmax(48px, 1fr);
    grid-template-rows: auto;
    gap: 4px;
    padding: 8px;
    border-radius: 6px;
    align-items: center;
  }

  .participant-row .participant-number {
    grid-row: 1;
    grid-column: 1;
    width: 16px;
    height: 16px;
    font-size: 0.55rem;
    justify-self: center;
  }

  .participant-row .name-input {
    grid-row: 1;
    grid-column: 2;
    font-size: 0.6rem;
    padding: 3px 2px;
  }

  .participant-row .stock-code-group {
    grid-row: 1;
    grid-column: 3;
    justify-self: center;
  }

  .participant-row .stock-code-group .stock-code {
    width: 36px;
    font-size: 0.75rem;
    padding: 3px 2px;
    text-align: center;
  }

  /* Hide reload button on mobile to save space */
  .participant-row .btn-reload {
    display: none;
  }

  .participant-row .stock-name-display {
    grid-row: 1;
    grid-column: 4;
    font-size: 0.75rem;
    padding: 3px 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .participant-row .price-input:nth-of-type(4) {
    grid-row: 1;
    grid-column: 5;
    font-size: 0.75rem;
    padding: 3px 2px;
    text-align: right;
  }

  .participant-row .price-input:nth-of-type(5) {
    grid-row: 1;
    grid-column: 6;
    font-size: 0.75rem;
    padding: 3px 2px;
    text-align: right;
  }

  /* Hide remove button on mobile */
  .participant-row .btn-remove {
    display: none;
  }

  /* Hide member checkbox on mobile */
  .participant-row .member-checkbox {
    display: none;
  }

  .participant-number {
    width: 16px;
    height: 16px;
    font-size: 0.55rem;
    margin: 0 auto;
  }

  .participant-input {
    padding: 3px 2px;
    font-size: 0.6rem;
    border-radius: 3px;
  }

  .participant-input.stock-name-display {
    font-size: 0.6rem;
    padding: 3px 2px;
  }

  /* Stock code group */
  .stock-code-group {
    gap: 0;
  }

  /* Add participant button */
  .btn-add-participant {
    padding: 4px;
    font-size: 0.65rem;
    margin-top: 3px;
    width: 100%;
  }

  /* Ultra compact buttons */
  .action-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
  }

  /* Hide clear data button on mobile */
  .btn-danger {
    display: none;
  }

  .btn {
    flex: 1;
    min-width: 90px;
    max-width: 120px;
    padding: 8px 10px;
    font-size: 0.75rem;
    border-radius: 8px;
    text-align: center;
    justify-content: center;
  }

  .btn-icon {
    font-size: 0.9rem;
  }

  /* Ultra compact leaderboard */
  .leaderboard-card {
    margin-top: 0;
  }

  .leaderboard {
    gap: 6px;
  }

  .leaderboard-item {
    grid-template-columns: 32px 1fr auto;
    grid-template-rows: auto;
    gap: 8px;
    padding: 8px;
    border-radius: 8px;
  }

  .leaderboard-item .rank-badge {
    grid-row: 1;
    width: 28px;
    height: 28px;
    font-size: 0.85rem;
  }

  .leaderboard-item .participant-info {
    grid-row: 1;
    grid-column: 2;
  }

  .participant-header {
    grid-template-columns: 55px 50px auto;
    justify-content: start;
    gap: 6px;
  }

  .stock-name-label {
    justify-self: start;
  }

  .participant-name {
    font-size: 0.85rem;
  }

  .stock-info {
    font-size: 0.7rem;
    gap: 4px;
  }

  .stock-code-badge {
    padding: 1px 4px;
    font-size: 0.65rem;
  }

  .stock-name-label {
    margin-left: 2px;
  }

  .gain-display {
    grid-row: 1;
    grid-column: 3;
    text-align: right;
  }

  .gain-percent {
    font-size: 1rem;
  }

  .price-change,
  .price-range {
    font-size: 0.65rem;
  }

  /* Footer */
  .footer {
    padding: 8px;
    margin-top: 0;
  }

  .footer p {
    font-size: 0.65rem;
  }

  /* Progress modal */
  .progress-modal .progress-content {
    padding: 16px;
    margin: 10px;
  }

  .progress-title {
    font-size: 0.9rem;
  }

  .progress-text {
    font-size: 0.8rem;
  }

  .progress-details {
    font-size: 0.7rem;
    max-height: 100px;
  }

  /* 取消按鈕手機版：置中對齊 + 放大10% */
  .btn-cancel-fetch {
    display: block !important;
    width: auto !important;
    margin-left: auto !important;
    margin-right: auto !important;
    margin-top: var(--space-lg);
    text-align: center;
    font-size: calc(0.95rem * 1.1);
    padding: calc(var(--space-md) * 1.1) calc(var(--space-lg) * 1.1);
    min-width: 130px;
  }

  /* Status message */
  .status-message {
    font-size: 0.8rem;
    padding: 8px 16px;
    bottom: 10px;
  }
}

/* Extra small phones (iPhone SE, etc.) */
@media (max-width: 375px) {
  .app-container {
    padding: 6px;
    gap: 6px;
  }

  .logo h1 {
    font-size: 1rem;
  }

  .logo-icon {
    font-size: 1.1rem;
  }

  .card {
    padding: 8px;
  }

  .card-title {
    font-size: 0.85rem;
  }

  .btn {
    font-size: 0.7rem;
    padding: 6px 8px;
    min-width: 80px;
  }

  .participant-row {
    padding: 5px;
  }

  .participant-input {
    font-size: 0.75rem;
    padding: 4px 6px;
  }
}

/* ===========================
   歷史月份凍結樣式
   =========================== */
.historical-view {
  position: relative;
}

.historical-view::before {
  content: "📦 歷史資料 - 僅供檢視";
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 165, 0, 0.9);
  color: #1a1a2e;
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 1000;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* 凍結按鈕樣式 */
.btn.frozen,
button.frozen {
  opacity: 0.5;
  cursor: not-allowed !important;
  pointer-events: none;
}

.btn.frozen::after,
button.frozen::after {
  content: " 🔒";
}

/* 凍結輸入欄樣式 */
.historical-view input:disabled {
  background: rgba(100, 100, 100, 0.3) !important;
  color: var(--text-secondary) !important;
  cursor: not-allowed;
}

.historical-view .date-input:disabled {
  opacity: 0.6;
}

/* ===========================
   來賓順序輸入樣式
   =========================== */
.row-status-icon {
  display: block;
  font-size: 0.8rem;
  margin-top: 4px;
}

.row-status-icon.editable {
  animation: pulse 1s infinite;
}

.row-status-icon.waiting {
  opacity: 0.5;
}

/* 來賓列狀態 */
.guest-row-locked {
  /* 已鎖定列正常顯示，不變暗 */
}

.guest-row-editable {
  border: 2px solid rgba(255, 215, 0, 0.5) !important;
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.2);
  animation: glowPulse 2s infinite;
}

/* 可編輯列的圓圈樣式：保持金色漸層 */
.guest-row-editable .participant-number {
  background: var(--accent-gradient);
  font-size: 0.55rem;
  width: 16px;
  height: 16px;
  min-width: 16px;
  max-width: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.guest-row-waiting .participant-input,
.guest-row-waiting .name-select {
  opacity: 0.4;
}

.guest-row-waiting .participant-number {
  opacity: 1;
  background: var(--accent-gradient);
  width: 16px;
  height: 16px;
  font-size: 0.55rem;
}

@keyframes glowPulse {
  0%,
  100% {
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.2);
  }

  50% {
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
  }
}

/* 確認按鈕 */
.btn-confirm-entry {
  display: block;
  margin-top: 8px;
  padding: 4px 12px;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-confirm-entry:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 10px rgba(16, 185, 129, 0.4);
}

/* 來賓模式參賽者欄 - 已移除重複設定 */

/* ===========================
   來賓確認 Popup
   =========================== */
.confirm-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(5px);
}

.confirm-content {
  background: linear-gradient(145deg, #1a1a2e 0%, #16213e 100%);
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  max-width: 400px;
  width: 90%;
  text-align: center;
  animation: popIn 0.3s ease-out;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.confirm-title {
  font-size: 1.5rem;
  color: var(--text-primary);
  margin-bottom: var(--space-lg);
}

.confirm-info {
  background: rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-lg);
}

.confirm-row {
  display: flex;
  justify-content: space-between;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.confirm-row:last-child {
  border-bottom: none;
}

.confirm-label {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.confirm-value {
  color: var(--accent-gold);
  font-weight: 600;
  font-size: 1rem;
}

.confirm-warning {
  color: #fbbf24;
  font-size: 0.9rem;
  margin-bottom: var(--space-lg);
}

.confirm-buttons {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
}

.confirm-buttons .btn {
  min-width: 100px;
}

/* ===========================
   揪咪風格警告 Popup
   =========================== */
.cute-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  animation: fadeIn 0.3s ease;
}

.cute-popup-content {
  background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 50%, #ffecd2 100%);
  border-radius: 24px;
  padding: var(--space-xl);
  text-align: center;
  max-width: 320px;
  box-shadow:
    0 20px 60px rgba(255, 105, 180, 0.4),
    0 0 40px rgba(255, 182, 193, 0.3);
  animation: bounceIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes bounceIn {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }

  50% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.cute-emoji {
  font-size: 64px;
  margin-bottom: var(--space-sm);
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%,
  100% {
    transform: rotate(0deg);
  }

  25% {
    transform: rotate(-10deg);
  }

  75% {
    transform: rotate(10deg);
  }
}

.cute-title {
  color: #d63384;
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: var(--space-sm);
  text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.8);
}

.cute-message {
  color: #6f42c1;
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: var(--space-lg);
  font-weight: 500;
}

.cute-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 12px 32px;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  transition: all 0.3s ease;
}

.cute-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

/* ===========================
   參賽者下拉選單樣式
   =========================== */
.name-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: rgba(0, 0, 0, 0.2);
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffd700' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
  padding-right: 32px;
  cursor: pointer;
  color: #ffd700;
  font-weight: 500;
}

.name-select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.3);
}

.name-select option {
  background-color: #1a1a2e;
  color: #fff;
  padding: 8px;
}

.name-input-new {
  margin-top: 4px;
}

@media (max-width: 768px) {
  .name-select {
    font-size: 0.75rem;
    padding: 5px 22px 5px 6px;
    background-size: 12px;
    background-position: right 4px center;
  }
}

@media (max-width: 480px) {
  .name-select {
    font-size: 0.6rem;
    padding: 4px 16px 4px 3px;
    background-size: 8px;
    background-position: right 2px center;
  }
}

/* ===========================
   名人堂樣式
   =========================== */
.hall-of-fame-card {
  background: linear-gradient(
    135deg,
    rgba(30, 20, 50, 0.95),
    rgba(50, 30, 70, 0.95)
  );
  border: 2px solid rgba(255, 215, 0, 0.3);
}

.title-badge {
  font-size: 0.65rem;
  background: linear-gradient(
    135deg,
    rgba(255, 215, 0, 0.15),
    rgba(255, 200, 0, 0.1)
  );
  color: var(--gold);
  padding: 4px 10px;
  border-radius: 12px;
  margin-left: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  border: 1px solid rgba(255, 215, 0, 0.3);
  text-transform: uppercase;
}

.scoring-rules {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin-bottom: var(--space-md);
  opacity: 0.8;
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.rule-rank,
.rule-roi {
  white-space: nowrap;
}

.rule-divider {
  opacity: 0.5;
}

/* Mobile: hide divider and stack rules */
@media (max-width: 580px) {
  .scoring-rules {
    flex-direction: column;
    gap: 4px;
  }

  .rule-divider {
    display: none;
  }
}

.hall-of-fame {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  max-width: 600px;
  margin: 0 auto;
}

.hall-card {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: var(--space-md);
  transition:
    transform 0.3s,
    box-shadow 0.3s;
}

.hall-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.hall-card.champion {
  background: linear-gradient(
    135deg,
    rgba(255, 215, 0, 0.2),
    rgba(255, 180, 0, 0.1)
  );
  border: 2px solid rgba(255, 215, 0, 0.5);
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.2);
}

.hall-card.runner-up {
  background: linear-gradient(
    135deg,
    rgba(192, 192, 192, 0.15),
    rgba(150, 150, 150, 0.1)
  );
  border: 1px solid rgba(192, 192, 192, 0.4);
}

.hall-card.third {
  background: linear-gradient(
    135deg,
    rgba(205, 127, 50, 0.15),
    rgba(180, 100, 30, 0.1)
  );
  border: 1px solid rgba(205, 127, 50, 0.4);
}

.hall-rank {
  font-size: 2rem;
  min-width: 50px;
  text-align: center;
}

.hall-info {
  flex: 1;
}

.hall-name {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--gold);
  margin-bottom: 4px;
}

.streak-badge {
  font-size: 0.75rem;
  background: linear-gradient(135deg, #ff6b6b, #ff8e53);
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

.hall-medals {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: 4px;
}

.medal {
  font-size: 0.85rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
}

.hall-stats {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
}

.hall-stats .positive {
  color: var(--price-up);
  font-weight: bold;
}

.hall-stats .negative {
  color: var(--price-down);
  font-weight: bold;
}

.hall-points {
  text-align: center;
  min-width: 70px;
}

.points-value {
  font-size: 2rem;
  font-weight: bold;
  background: linear-gradient(135deg, var(--gold), #ffcc00);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.points-label {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
  text-transform: uppercase;
}

/* 本月預測區塊 */
.projection-divider {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin: var(--space-lg) 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.projection-divider::before,
.projection-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
}

.hall-card.projection {
  opacity: 0.7;
  border: 1px dashed rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.03);
}

.hall-card.projection:hover {
  opacity: 0.9;
}

.projection-points .points-value {
  color: var(--accent);
  background: none;
  -webkit-text-fill-color: var(--accent);
  font-size: 1.5rem;
}

.empty-hall {
  text-align: center;
  padding: var(--space-xl);
  color: rgba(255, 255, 255, 0.6);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
}

.empty-hint {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.4);
}

@media (max-width: 768px) {
  .hall-card {
    flex-wrap: wrap;
  }

  .hall-rank {
    font-size: 1.5rem;
    min-width: 40px;
  }

  .hall-name {
    font-size: 1rem;
  }

  .hall-points {
    min-width: 60px;
  }

  .points-value {
    font-size: 1.5rem;
  }
}

/* ===========================
   名人堂按鈕特效
   =========================== */
.btn-hall-of-fame {
  background: linear-gradient(135deg, #9c27b0, #673ab7, #3f51b5);
  background-size: 200% 200%;
  animation: gradientShift 3s ease infinite;
  border: 2px solid rgba(255, 215, 0, 0.5);
  color: white;
  position: relative;
  overflow: hidden;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.btn-hall-of-fame::before {
  content: "";
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: linear-gradient(
    45deg,
    transparent 30%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 70%
  );
  transform: rotate(45deg);
  animation: shine 2s infinite;
}

@keyframes gradientShift {
  0% {
    background-position: 0% 50%;
  }

  50% {
    background-position: 100% 50%;
  }

  100% {
    background-position: 0% 50%;
  }
}

@keyframes shine {
  0% {
    transform: translateX(-100%) rotate(45deg);
  }

  100% {
    transform: translateX(100%) rotate(45deg);
  }
}

.btn-hall-of-fame:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow:
    0 10px 30px rgba(156, 39, 176, 0.5),
    0 0 20px rgba(255, 215, 0, 0.3);
}

.btn-hall-of-fame:active {
  transform: translateY(-1px) scale(1.02);
}

/* ===========================
   Margin Maintenance Ratio System
   =========================== */

/* Margin Link Button */
.margin-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  margin-top: var(--space-sm);
  color: var(--accent-primary);
  font-size: 0.7rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: var(--transition-normal);
}

.margin-link:hover {
  opacity: 0.8;
}

.margin-link-icon {
  font-size: 1rem;
}

.margin-link-text {
  display: inline;
}

@media (min-width: 700px) {
  .margin-link {
    font-size: 0.875rem;
  }
}

/* Responsive text for role indicator */
.role-text-short {
  display: inline;
}

.role-text-full {
  display: none;
}

@media (min-width: 700px) {
  .role-text-short {
    display: none;
  }

  .role-text-full {
    display: inline;
  }
}

/* Margin Warning Banner (頁面頂部警告橫幅) */
.margin-warning-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: var(--space-md) var(--space-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  font-weight: 600;
  z-index: 1000;
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.margin-warning-banner.level-warning {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  color: #1a1a1a;
}

.margin-warning-banner.level-margin_call {
  background: linear-gradient(135deg, #fb923c 0%, #f97316 100%);
  color: white;
}

.margin-warning-banner.level-danger {
  background: linear-gradient(135deg, #f87171 0%, #ef4444 100%);
  color: white;
  animation:
    slideDown 0.3s ease,
    pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.8;
  }
}

.margin-warning-icon {
  font-size: 1.25rem;
}

.margin-warning-text {
  font-size: 0.95rem;
}

.margin-warning-close {
  position: absolute;
  right: var(--space-md);
  background: none;
  border: none;
  color: inherit;
  font-size: 1.5rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.margin-warning-close:hover {
  opacity: 1;
}

/* Margin Modal (詳細資料彈窗) */
.margin-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  padding: var(--space-lg);
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.margin-modal-content {
  background: linear-gradient(
    180deg,
    var(--bg-secondary) 0%,
    var(--bg-primary) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
  from {
    transform: scale(0.9);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

.margin-modal-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.margin-modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
}

.margin-modal-title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-xl);
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.margin-modal-icon {
  font-size: 1.75rem;
  -webkit-text-fill-color: initial;
}

/* Current Value Display */
.margin-current {
  text-align: center;
  padding: var(--space-xl);
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-xl);
}

.margin-current-value {
  font-size: 3.5rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-sm);
}

.margin-current-status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  background: rgba(34, 197, 94, 0.15);
  border-radius: var(--radius-xl);
  font-weight: 600;
  color: #22c55e;
}

.margin-current-status.status-warning {
  background: rgba(234, 179, 8, 0.15);
  color: #eab308;
}

.margin-current-status.status-margin_call {
  background: rgba(249, 115, 22, 0.15);
  color: #f97316;
}

.margin-current-status.status-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.margin-current-date {
  margin-top: var(--space-md);
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Thresholds Display */
.margin-thresholds {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-xl);
}

.threshold-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-md);
  border-left: 3px solid transparent;
}

.threshold-safe {
  border-left-color: #22c55e;
}

.threshold-warning {
  border-left-color: #eab308;
}

.threshold-danger {
  border-left-color: #f97316;
}

.threshold-critical {
  border-left-color: #ef4444;
}

.threshold-icon {
  font-size: 1rem;
}

.threshold-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

.threshold-value {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Refresh Button */
.margin-refresh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: 6px 18px;
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: var(--radius-lg);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  background: rgba(245, 158, 11, 0.12);
  color: #f59e0b;
  -webkit-text-fill-color: #f59e0b;
  white-space: nowrap;
}

.margin-refresh-btn:hover {
  background: rgba(245, 158, 11, 0.25);
  border-color: rgba(245, 158, 11, 0.6);
  transform: translateY(-1px);
}

.margin-refresh-primary {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #1a1a2e;
  width: 100%;
  margin-top: var(--space-md);
}

.margin-refresh-primary:hover {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(245, 158, 11, 0.3);
}

.margin-refresh-primary:active {
  transform: translateY(0);
}

.margin-refresh-link {
  text-align: center;
  margin-top: var(--space-lg);
  margin-bottom: var(--space-xs);
}

.margin-refresh-link a {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-decoration: none;
  opacity: 0.7;
  transition: all 0.3s ease;
}

.margin-refresh-link a:hover {
  color: #f59e0b;
  opacity: 1;
}

/* History Section */
.margin-history-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
}

.margin-history {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  margin-bottom: var(--space-lg);
}

.margin-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-sm);
}

.margin-history-item.latest {
  background: rgba(255, 255, 255, 0.06);
  border-left: 3px solid var(--accent-primary);
}

.margin-history-date {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 90px;
}

.margin-history-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 80px;
  text-align: right;
}

.margin-history-change {
  font-size: 0.8rem;
  font-weight: 500;
  min-width: 80px;
  text-align: right;
}

.change-up {
  color: var(--price-up, #ef4444);
}

.change-down {
  color: var(--price-down, #22c55e);
}

/* Sub Data Section */
.margin-sub-data {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xl);
}

.margin-sub-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sub-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.sub-value {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.status-detail {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-left: var(--space-xs);
}

/* Margin Fetch Progress */
.margin-fetch-progress {
  margin-bottom: var(--space-lg);
  padding: var(--space-md);
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.margin-progress-bar-container {
  height: 18px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 9px;
  overflow: hidden;
  margin-bottom: var(--space-sm);
}

.margin-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f59e0b 0%, #f97316 50%, #ef4444 100%);
  border-radius: 9px;
  transition: width 0.4s ease;
  position: relative;
}

.margin-progress-bar::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  animation: shimmer 1.5s infinite;
}

.margin-progress-text {
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
}

.margin-progress-details {
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  max-height: 140px;
  overflow-y: auto;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.margin-progress-details .success {
  color: #10b981;
}

.margin-progress-details .error {
  color: #ef4444;
}

.margin-progress-details .skip {
  color: #f59e0b;
}

.margin-cancel-btn {
  margin-top: var(--space-md);
  font-size: 0.85rem;
  padding: var(--space-sm) var(--space-md);
}

.margin-refresh-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Note */
.margin-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.6;
  text-align: center;
}

/* Adjust body padding when warning banner is shown */
body.margin-warning-active {
  padding-top: 52px;
}

/* 選股參考連結 (比賽設定卡片右側) */
.stock-ref-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-primary, #a78bfa);
  text-decoration: none;
  padding: 5px 14px;
  border-radius: 20px;
  background: rgba(167, 139, 250, 0.1);
  border: 1px solid rgba(167, 139, 250, 0.25);
  transition: all 0.3s ease;
  white-space: nowrap;
}

.stock-ref-link:hover {
  background: rgba(167, 139, 250, 0.2);
  border-color: rgba(167, 139, 250, 0.5);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(167, 139, 250, 0.2);
}

@media (max-width: 480px) {
  .stock-ref-link {
    font-size: 0.7rem;
    padding: 4px 10px;
  }
}

/* ===========================
   卡珊卓預警模組
   ========================= */

/* 背離警告區塊 */
.cassandra-alert {
  margin: 16px 0;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid rgba(168, 85, 247, 0.3);
  background: linear-gradient(
    135deg,
    rgba(168, 85, 247, 0.08),
    rgba(236, 72, 153, 0.06)
  );
  animation: cassandraPulse 3s ease-in-out infinite;
}

.cassandra-alert.cassandra-critical {
  border-color: rgba(239, 68, 68, 0.5);
  background: linear-gradient(
    135deg,
    rgba(239, 68, 68, 0.12),
    rgba(168, 85, 247, 0.08)
  );
  animation: cassandraPulse 1.5s ease-in-out infinite;
}

.cassandra-alert.cassandra-high {
  border-color: rgba(249, 115, 22, 0.4);
  background: linear-gradient(
    135deg,
    rgba(249, 115, 22, 0.1),
    rgba(168, 85, 247, 0.06)
  );
}

@keyframes cassandraPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(168, 85, 247, 0);
  }

  50% {
    box-shadow: 0 0 16px 2px rgba(168, 85, 247, 0.15);
  }
}

.cassandra-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.cassandra-icon {
  font-size: 1.3rem;
}

.cassandra-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #c084fc;
}

.cassandra-badge {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 12px;
  background: rgba(168, 85, 247, 0.15);
  color: #d8b4fe;
}

.cassandra-critical .cassandra-badge {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.cassandra-desc {
  font-size: 0.82rem;
  color: #a1a1aa;
  line-height: 1.5;
}

.cassandra-desc strong {
  color: #e2e8f0;
}

/* 斷頭價計算器 */
.margin-call-calc {
  margin: 14px 0;
  padding: 12px 16px;
  border-radius: 10px;
  background: rgba(30, 30, 40, 0.6);
  border: 1px solid rgba(63, 63, 70, 0.5);
}

.calc-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.calc-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: #a1a1aa;
  min-width: 36px;
}

.calc-input {
  flex: 1;
  max-width: 120px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(63, 63, 70, 0.7);
  background: rgba(24, 24, 30, 0.8);
  color: #e2e8f0;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.calc-input:focus {
  border-color: rgba(168, 85, 247, 0.6);
}

.calc-input::placeholder {
  color: #52525b;
}

.calc-arrow {
  font-size: 1rem;
  color: #71717a;
}

.calc-result {
  font-size: 1rem;
  font-weight: 700;
  color: #71717a;
  min-width: 80px;
  text-align: right;
}

.calc-result-active {
  color: #f97316;
}

.calc-hint {
  margin-top: 6px;
  font-size: 0.7rem;
  color: #52525b;
}

/* 10 天追蹤表格 */
.cassandra-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
  border: 1px solid rgba(63, 63, 70, 0.4);
}

.cassandra-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.cassandra-table thead th {
  padding: 8px 10px;
  text-align: center;
  font-weight: 600;
  font-size: 0.75rem;
  color: #a1a1aa;
  background: rgba(24, 24, 30, 0.8);
  border-bottom: 1px solid rgba(63, 63, 70, 0.5);
  white-space: nowrap;
}

.cassandra-table tbody td {
  padding: 8px 10px;
  text-align: center;
  border-bottom: 1px solid rgba(63, 63, 70, 0.25);
  white-space: nowrap;
}

.cassandra-table tbody tr:last-child td {
  border-bottom: none;
}

.cassandra-table .row-latest td {
  background: rgba(168, 85, 247, 0.06);
  font-weight: 600;
}

.cassandra-table .row-divergence td {
  background: rgba(239, 68, 68, 0.06);
}

/* K 線色彩（台灣：紅漲綠跌） */
.candle-red {
  color: #ef4444;
  font-weight: 700;
}

.candle-green {
  color: #22c55e;
  font-weight: 700;
}

.candle-neutral {
  color: #71717a;
}

/* 通用文字色彩 */
.text-muted {
  color: #52525b;
}

/* 背離標記（閃爍） */
.divergence-flag {
  animation: divergenceBlink 1.5s ease-in-out infinite;
}

@keyframes divergenceBlink {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

/* 手機響應式 */
@media (max-width: 480px) {
  .cassandra-table {
    font-size: 0.75rem;
  }

  .cassandra-table thead th,
  .cassandra-table tbody td {
    padding: 6px 6px;
  }

  .cassandra-alert {
    padding: 10px 12px;
  }

  .calc-row {
    gap: 6px;
  }

  .calc-input {
    max-width: 90px;
    font-size: 0.82rem;
  }
}
