/* ---------- CSS Variables — Light Mode (Default) ---------- */
:root {
  --bg-primary: #f4f1ec;            /* Warm Ivory */
  --bg-secondary: #ede9e2;          /* Parchment */
  --bg-card: rgba(255, 255, 255, 0.80);
  --bg-card-hover: rgba(255, 255, 255, 0.97);
  --accent-primary: #2a5f8f;        /* Cinematic Deep Blue */
  --accent-secondary: #c07d2e;      /* Warm Gold */
  --accent-tertiary: #6b7c5e;       /* Sage Green */
  --accent-gold: #e0a736;
  --accent-silver: #8a9aa8;
  --accent-bronze: #b5713a;
  --accent-danger: #c0392b;
  --accent-purple: #5b5ea6;
  --text-primary: #1a1a2e;          /* Deep Ink */
  --text-secondary: #4a5568;        /* Slate */
  --text-muted: #8a96a3;
  --border: rgba(26, 26, 46, 0.10);
  --border-hover: rgba(42, 95, 143, 0.35);
  --shadow: 0 4px 20px rgba(26, 26, 46, 0.10);
  --shadow-glow: 0 0 20px rgba(42, 95, 143, 0.18);
  --shadow-lg: 0 12px 40px rgba(26, 26, 46, 0.16);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --glass: blur(20px);
  --transition: 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ---------- CSS Variables — Dark Mode ---------- */
[data-theme="dark"] {
  --bg-primary: #101612;
  --bg-secondary: #1a241c;
  --bg-card: rgba(26, 36, 28, 0.7);
  --bg-card-hover: rgba(34, 46, 36, 0.9);
  --accent-primary: #8db596;
  --accent-secondary: #dca76a;
  --accent-tertiary: #c4b09b;
  --accent-gold: #ebb15b;
  --accent-silver: #c9cecc;
  --accent-bronze: #cd8a62;
  --accent-danger: #e27676;
  --accent-purple: #9bb0c4;
  --text-primary: #f2f5f3;
  --text-secondary: #a3b3a8;
  --text-muted: #647368;
  --border: rgba(141, 181, 150, 0.15);
  --border-hover: rgba(141, 181, 150, 0.4);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 15px rgba(141, 181, 150, 0.2);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Noto Sans TC', 'Outfit', sans-serif;
  background-color: var(--bg-primary);
  background-image: 
    linear-gradient(160deg, rgba(244, 241, 236, 0.0) 0%, rgba(235, 228, 215, 0.5) 100%);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

[data-theme="dark"] body {
  background-image:
    linear-gradient(to bottom, rgba(16, 22, 18, 0.6), rgba(16, 22, 18, 0.9)),
    url('bg.png');
}

/* ---------- Announcement Bar ---------- */
.announcement-bar {
  background: rgba(255, 255, 255, 0.75);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 16px rgba(26, 26, 46, 0.07);
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: var(--glass);
}

[data-theme="dark"] .announcement-bar {
  background: rgba(18, 19, 28, 0.7);
  border-bottom: 1px solid rgba(255, 0, 85, 0.3);
  box-shadow: 0 2px 20px rgba(255, 0, 85, 0.15);
}

.announcement-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.announcement-icon { font-size: 1.2rem; flex-shrink: 0; }

.announcement-text {
  flex: 1;
  color: var(--text-primary);
  font-size: 0.95rem;
  line-height: 1.5;
  outline: none;
  border-bottom: 1px dashed transparent;
  padding: 2px 4px;
  border-radius: 4px;
  transition: var(--transition);
  cursor: text;
}

.announcement-text:focus {
  border-bottom-color: var(--accent-primary);
  background: rgba(88, 166, 255, 0.05);
}

.announcement-edit-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---------- Hero ---------- */
.hero {
  max-width: 1200px;
  margin: 0 auto;
  padding: 56px 24px 32px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  flex-wrap: wrap;
}

/* =====================================================================
   Envelope Share Card (分享打卡卡片)
   ===================================================================== */
.share-dialog {
  max-width: 400px;
  background: var(--bg-card);
}

.envelope-card-container {
  background: var(--bg-card);
  padding: 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
}

.envelope-card {
  position: relative;
  background-color: #fdfaf3; /* Light cream paper color */
  border-radius: 4px;
  padding: 24px 20px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
  font-family: 'Klee One', 'Noto Sans TC', sans-serif;
  color: #333;
  text-align: center;
  overflow: hidden;
  border-top: 6px dashed #cc4242; /* Soft red ink dashed border for airmail feel */
  /* 強制固定寬度，避免手機版螢幕過窄造成壓縮或排版亂掉 */
  width: 320px;
  box-sizing: border-box;
  margin: 0 auto;
}

.envelope-greeting {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: #cc4242; /* Soft red ink */
  letter-spacing: 0.05em;
}

.envelope-message {
  font-size: 1.15rem;
  line-height: 1.6;
  margin-bottom: 20px;
  text-align: left;
  padding: 0 10px;
}
.envelope-message span {
  font-weight: 600;
}

.envelope-img {
  width: 100%;
  height: 200px; /* 固定高度，讓卡片比例一致 */
  object-fit: cover; /* 改用 cover，避免照片壓縮或產生大面積留白 */
  border-radius: 4px;
  margin-bottom: 16px;
  border: 4px solid #fff;
  /* 移除 box-shadow，以迴避 iOS Safari 的 html-to-image 渲染層消失 Bug */
  background-color: #eee;
}

.envelope-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: #777;
  border-top: 1px dashed #d1c8b4;
  padding-top: 12px;
  margin-top: 8px;
}

/* 預覽圖鎖定高度與寬度，避免手機版撐破版面 */
.share-preview-img {
  width: 100%;
  max-height: 55vh;
  object-fit: contain;
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.share-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.share-btn {
  font-size: 0.9rem;
  padding: 12px;
}
.share-btn.line-btn {
  background: linear-gradient(135deg, #00B900, #009900);
  color: white;
}
.share-btn.line-btn:hover {
  box-shadow: 0 4px 15px rgba(0, 185, 0, 0.3);
}

.hero-badge {
  display: inline-block;
  background: linear-gradient(135deg, rgba(141,181,150,0.2), rgba(220,167,106,0.15));
  border: 1px solid rgba(141, 181, 150, 0.4);
  border-radius: 100px;
  padding: 6px 18px;
  font-size: 0.85rem;
  color: var(--accent-primary);
  font-weight: 700;
  margin-bottom: 14px;
  letter-spacing: 0.05em;
}

.hero-content h1 {
  font-family: 'Outfit', sans-serif;
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.1;
  margin-bottom: 16px;
}

.hero-content p {
  font-size: 1.05rem;
  color: var(--text-secondary);
  max-width: 480px;
}

.hero-stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 28px;
  text-align: center;
  backdrop-filter: var(--glass);
  min-width: 110px;
  transition: var(--transition);
}

.stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-4px);
  box-shadow: var(--shadow-glow);
  background: var(--bg-card-hover);
}

.stat-number {
  display: block;
  font-family: 'Outfit', sans-serif;
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--accent-primary);
  line-height: 1;
  margin-bottom: 6px;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ---------- Main Layout ---------- */
.main-layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 60px;
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
}
.main-layout > .side-panel {
  grid-column: 2;
  grid-row: 1 / -1;
}
.photo-wall-inline {
  margin-top: -8px;
}

@media (max-width: 900px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
  .main-layout > .side-panel {
    grid-column: 1;
    grid-row: auto;
  }
  .side-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
  }
}

@media (max-width: 600px) {
  body { font-size: 14px; }

  .announcement-bar { padding: 8px 12px; }
  .announcement-inner { gap: 8px; }
  .announcement-text { font-size: 0.78rem; }
  .announcement-edit-hint { display: none; }

  .hero {
    padding: 24px 16px 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .hero h1 { font-size: 1.5rem; }
  .hero-stats { gap: 8px; width: 100%; }
  .stat-card { padding: 12px 8px; }
  .stat-number { font-size: 1.6rem; }

  .team-goal-section { padding: 0 12px 12px; }
  .team-goal-header { flex-direction: column; gap: 6px; align-items: flex-start; }

  .main-layout { padding: 0 12px 40px; gap: 12px; }

  .side-panel { grid-template-columns: 1fr; gap: 12px; }

  .card { padding: 16px; border-radius: var(--radius-md); }

  /* Calendar mobile */
  .section-title-group { flex-direction: column; align-items: flex-start; gap: 6px; }
  .cal-day { min-height: 52px; padding: 4px 2px; }
  .day-num { font-size: 0.72rem; }
  .day-name-tag { font-size: 0.55rem; padding: 1px 4px; }

  /* Day detail panel */
  .day-detail-panel { padding: 20px 16px 16px; }
  .day-detail-item { padding: 8px; gap: 8px; }

  /* Random exercise FAB */
  .random-exercise-fab { bottom: 16px; right: 16px; width: 48px; height: 48px; font-size: 1.3rem; }
  .random-exercise-card { padding: 28px 20px; }

  /* Activity feed */
  .activity-item { gap: 8px; }
  .activity-avatar { width: 28px; height: 28px; font-size: 0.65rem; }

  /* Chat */
  .chat-messages { max-height: 200px; }

  /* Leaderboard */
  .leaderboard-item { padding: 8px 10px; }
}

/* ---------- Card ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: var(--glass);
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.section-title-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.section-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.refresh-hint {
  font-size: 0.8rem;
  color: var(--accent-primary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.refresh-hint:hover { background: rgba(88, 166, 255, 0.1); }

/* ---------- Calendar ---------- */
.month-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: var(--transition);
}
.nav-btn:hover { border-color: var(--accent-primary); color: var(--accent-primary); }

.month-label {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  min-width: 90px;
  text-align: center;
}

.calendar-grid-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 8px;
}
.calendar-grid-header span {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 6px 0;
}
.calendar-grid-header span:first-child { color: var(--accent-danger); }
.calendar-grid-header span:last-child  { color: var(--accent-primary); }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal-day {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px;
  cursor: pointer;
  transition: var(--transition);
  min-height: 70px;
  position: relative;
  overflow: hidden;
}

[data-theme="dark"] .cal-day {
  background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.05);
}

.cal-day:hover {
  background: rgba(42, 95, 143, 0.07);
  border-color: rgba(42, 95, 143, 0.35);
  transform: scale(1.04);
  z-index: 2;
  box-shadow: 0 4px 16px rgba(42, 95, 143, 0.12);
}

[data-theme="dark"] .cal-day:hover {
  background: rgba(0, 240, 255, 0.08);
  border-color: rgba(0, 240, 255, 0.4);
}

.cal-day.today {
  border-color: var(--accent-primary) !important;
  background: rgba(42, 95, 143, 0.08);
  box-shadow: inset 0 0 10px rgba(42, 95, 143, 0.1);
}

[data-theme="dark"] .cal-day.today {
  background: rgba(255, 0, 85, 0.1);
  box-shadow: inset 0 0 10px rgba(255, 0, 85, 0.2);
}

.cal-day.sunday .day-num  { color: rgba(248, 81, 73, 0.7); }
.cal-day.saturday .day-num { color: rgba(88, 166, 255, 0.7); }
.cal-day.empty { cursor: default; background: transparent; border-color: transparent; }
.cal-day.empty:hover { transform: none; background: transparent; }

.day-num {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  line-height: 1;
}

.day-avatars {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 3px;
  width: 100%;
}

.day-name-tag {
  width: 100%;
  background: hsla(var(--tag-hue, 210), 72%, 44%, 0.15);
  border: 1.5px solid hsla(var(--tag-hue, 210), 72%, 38%, 0.55);
  color: hsl(var(--tag-hue, 210), 80%, 28%);
  font-size: 0.6rem;
  font-weight: 800;
  border-radius: 3px;
  padding: 1px 3px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

[data-theme="dark"] .day-name-tag {
  background: hsla(var(--tag-hue, 210), 70%, 50%, 0.18);
  border: 1px solid hsla(var(--tag-hue, 210), 70%, 60%, 0.4);
  color: hsl(var(--tag-hue, 210), 80%, 75%);
}

.day-name-more {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border);
  color: var(--text-muted);
}


/* ---------- Leaderboard ---------- */
.leaderboard-section {
  position: relative;
  z-index: 10;
}

.leaderboard-list { list-style: none; }

.leaderboard-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}
.leaderboard-item:last-child { border-bottom: none; }
.leaderboard-item:hover { padding-left: 4px; }

.rank-badge {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
  font-weight: 900;
  flex-shrink: 0;
}
.rank-1 { background: linear-gradient(135deg, #ffcf33, #ffaa00); color: #000; box-shadow: 0 0 10px rgba(255, 207, 51, 0.4); }
.rank-2 { background: linear-gradient(135deg, #d4d4dc, #a0aab4); color: #000; }
.rank-3 { background: linear-gradient(135deg, #e07a5f, #c05c45); color: #fff; }
.rank-n { background: rgba(255,255,255,0.06); color: var(--text-secondary); font-size: 0.75rem; border: 1px solid rgba(255,255,255,0.1); }

.rank-name {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.rank-count {
  font-family: 'Outfit', sans-serif;
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--accent-secondary);
}

.rank-unit { font-size: 0.72rem; color: var(--text-secondary); margin-left: 2px; }

.leaderboard-placeholder,
.activity-placeholder {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---------- Activity Feed ---------- */
.activity-feed { list-style: none; max-height: 360px; overflow-y: auto; }
.activity-feed::-webkit-scrollbar { width: 4px; }
.activity-feed::-webkit-scrollbar-track { background: transparent; }
.activity-feed::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.activity-item {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  animation: slideIn 0.4s ease;
}
.activity-item:last-child { border-bottom: none; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}

.activity-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: grid;
  place-items: center;
  font-size: 0.7rem;
  font-weight: 900;
  color: #101612;
  flex-shrink: 0;
}

.activity-content { flex: 1; }

.activity-text {
  font-size: 0.88rem;
  color: var(--text-primary);
  line-height: 1.4;
}
.activity-text strong { color: var(--accent-secondary); }
.activity-plus { color: var(--accent-secondary); font-weight: 900; }

.activity-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.activity-thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
}
.activity-thumb:hover { border-color: var(--accent-primary); transform: scale(1.05); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: var(--glass);
  z-index: 500;
  display: none;
  place-items: center;
  padding: 20px;
}
.modal-overlay.open { display: grid; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 440px;
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.88) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255,255,255,0.06);
  border: none;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.9rem;
  display: grid;
  place-items: center;
  transition: var(--transition);
}
.modal-close:hover { background: rgba(248, 81, 73, 0.15); color: var(--accent-danger); }

.modal-header { text-align: center; margin-bottom: 24px; }
.modal-icon { font-size: 2.5rem; margin-bottom: 8px; }
.modal-header h3 { font-size: 1.4rem; font-weight: 900; color: var(--text-primary); }
.modal-date { font-size: 0.9rem; color: var(--text-secondary); margin-top: 4px; }

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.form-group input[type="text"] {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
}
.form-group input[type="text"]:focus {
  border-color: var(--accent-primary);
  background: rgba(88, 166, 255, 0.05);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.12);
}

.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  position: relative;
  min-height: 130px;
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
}
.upload-area:hover { border-color: var(--accent-primary); background: rgba(88,166,255,0.04); }
.upload-area input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.upload-icon { font-size: 2rem; }
.upload-placeholder span:last-child { font-size: 0.85rem; color: var(--text-muted); }

.upload-preview {
  display: none;
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}
.upload-preview.visible { display: block; }

.btn-primary {
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  border-radius: var(--radius-md);
  color: #101612;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  box-shadow: 0 4px 15px rgba(141, 181, 150, 0.2);
}
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(141, 181, 150, 0.35); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.modal-footer-note {
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 12px;
  min-height: 20px;
}

/* ---------- Spinner ---------- */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
.hidden { display: none !important; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Lightbox ---------- */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 900;
  place-items: center;
  backdrop-filter: blur(8px);
}
.lightbox.open { display: grid; }
.lightbox-img {
  max-width: 90vw;
  max-height: 88vh;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  object-fit: contain;
}
.lightbox-close {
  position: fixed;
  top: 20px;
  right: 24px;
  background: rgba(255,255,255,0.1);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  display: grid;
  place-items: center;
  transition: var(--transition);
}
.lightbox-close:hover { background: var(--accent-danger); }

/* ---------- Config Notice ---------- */
.config-notice {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  z-index: 800;
  place-items: center;
  backdrop-filter: blur(6px);
}
.config-notice.open { display: grid; }
.config-notice-card {
  background: var(--bg-secondary);
  border: 1px solid rgba(240, 180, 41, 0.4);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.config-notice-card h3 { font-size: 1.2rem; margin-bottom: 12px; }
.config-notice-card p { color: var(--text-secondary); font-size: 0.9rem; line-height: 1.6; margin-bottom: 20px; }
.config-notice-card strong { color: var(--accent-gold); }

/* ---------- Rewards Box ---------- */
.rewards-body {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.8;
  outline: none;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: rgba(240, 180, 41, 0.04);
  border: 1px dashed rgba(240, 180, 41, 0.2);
  transition: var(--transition);
  cursor: text;
  min-height: 60px;
}
.rewards-body:focus {
  background: rgba(240, 180, 41, 0.08);
  border-color: rgba(240, 180, 41, 0.5);
  box-shadow: 0 0 0 3px rgba(240, 180, 41, 0.08);
}

/* ---------- Chat Room ---------- */
.chat-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-secondary);
  box-shadow: 0 0 0 2px rgba(63, 185, 80, 0.3);
  animation: pulse-dot 2s ease infinite;
  flex-shrink: 0;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 2px rgba(63, 185, 80, 0.3); }
  50%       { box-shadow: 0 0 0 6px rgba(63, 185, 80, 0.1); }
}

.chat-messages {
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
  margin-bottom: 14px;
}
.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.chat-msg-item {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: slideIn 0.3s ease;
}

.chat-msg-item.self {
  flex-direction: row-reverse;
}

.chat-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

.chat-msg-item.self .chat-bubble-wrap {
  align-items: flex-end;
}

.chat-msg-name {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-bottom: 3px;
  padding: 0 6px;
}

.chat-bubble {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 2px;
  padding: 8px 12px;
  font-size: 0.88rem;
  color: var(--text-primary);
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg-item.self .chat-bubble {
  background: linear-gradient(135deg, rgba(255, 0, 85, 0.2), rgba(255, 170, 0, 0.15));
  border-color: rgba(255, 0, 85, 0.3);
  border-radius: 12px 12px 2px 12px;
  color: #f0f0f5;
  box-shadow: 0 2px 10px rgba(255, 0, 85, 0.1);
}

.chat-msg-time {
  font-size: 0.64rem;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 6px;
}

.chat-mini-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.65rem;
  font-weight: 900;
  color: #fff;
  flex-shrink: 0;
  margin-bottom: 2px;
}

/* ---------- Music Player ---------- */
.music-section {
  padding-bottom: 24px;
}

/* ---------- Collapsible Panels ---------- */
.collapsible-header {
  cursor: pointer;
  user-select: none;
}
.collapsible-header:hover { opacity: 0.85; }

.collapse-toggle {
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: transform 0.3s ease;
  display: inline-block;
}
.collapsible:not(.collapsed) .collapse-toggle {
  transform: rotate(180deg);
}
.collapsible.collapsed .collapsible-body {
  display: none;
}
.collapsible:not(.collapsed) .collapsible-body {
  display: block;
  animation: collapseOpen 0.3s ease;
}
@keyframes collapseOpen {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 600px; }
}
.music-player-wrap {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 比例 */
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: rgba(0,0,0,0.2);
}
.music-player-wrap iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Chat Input */
.chat-input-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.chat-name-input,
.chat-msg-input {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  transition: var(--transition);
  width: 100%;
}
.chat-name-input { font-size: 0.8rem; }
.chat-name-input:focus,
.chat-msg-input:focus {
  border-color: var(--accent-primary);
  background: rgba(88, 166, 255, 0.05);
}

.chat-msg-row {
  display: flex;
  gap: 8px;
}

.chat-send-btn {
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  border-radius: var(--radius-sm);
  color: #101612;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 0.9rem;
  flex-shrink: 0;
  transition: var(--transition);
  box-shadow: 0 2px 10px rgba(141, 181, 150, 0.2);
}
.chat-send-btn:hover { filter: brightness(1.1); transform: scale(1.06); box-shadow: 0 4px 15px rgba(141, 181, 150, 0.35); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- Toolbar Buttons (Theme + Bell) ---------- */
.toolbar-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.icon-btn {
  background: rgba(141, 181, 150, 0.15);
  border: 1px solid rgba(141, 181, 150, 0.3);
  border-radius: 50%;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 0.9rem;
  transition: var(--transition);
  color: var(--text-primary);
}
.icon-btn:hover { background: rgba(141, 181, 150, 0.3); transform: scale(1.1); }

/* ---------- Team Goal Progress ---------- */
.team-goal-section {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 16px;
}
.team-goal-inner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 24px;
  backdrop-filter: var(--glass);
}
.team-goal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}
.team-goal-label {
  color: var(--accent-secondary);
  font-family: 'Outfit', sans-serif;
}
.team-goal-bar {
  width: 100%;
  height: 12px;
  background: rgba(141, 181, 150, 0.1);
  border-radius: 100px;
  overflow: hidden;
}
.team-goal-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
  border-radius: 100px;
  transition: width 0.8s ease;
}
.team-goal-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}
.goal-adj-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(141, 181, 150, 0.12);
  color: var(--text-primary);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: var(--transition);
  line-height: 1;
}
.goal-adj-btn:hover {
  background: rgba(141, 181, 150, 0.3);
  transform: scale(1.1);
}

/* ---------- Personal Stats ---------- */
.personal-stats-section {
  position: relative;
  z-index: 5;
}

.month-selector-row {
  margin-bottom: 10px;
}
.month-select {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 0.82rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
  appearance: auto;
}
.month-select:focus { border-color: var(--accent-primary); }
.month-select option { background: var(--bg-secondary); color: var(--text-primary); }

.personal-stats-lookup {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.personal-stats-lookup select {
  flex: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
  width: 100%;
  appearance: auto;
}
.personal-stats-lookup select:focus {
  border-color: var(--accent-primary);
  background: rgba(141, 181, 150, 0.05);
}
.personal-stats-lookup select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}
.personal-stats-body { min-height: 50px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.stats-item {
  background: rgba(141, 181, 150, 0.06);
  border: 1px solid rgba(141, 181, 150, 0.15);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}
.stats-value {
  font-family: 'Outfit', sans-serif;
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--accent-primary);
  line-height: 1;
  display: block;
}
.stats-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 4px;
}
.stats-badges {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.badge-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(220, 167, 106, 0.12);
  border: 1px solid rgba(220, 167, 106, 0.35);
  border-radius: 100px;
  padding: 4px 12px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-secondary);
}
.badge-tag.locked {
  background: rgba(100, 115, 104, 0.1);
  border-color: rgba(100, 115, 104, 0.2);
  color: var(--text-muted);
  opacity: 0.5;
}

/* ---------- Photo Wall ---------- */
.photo-wall-section {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 48px;
}
.photo-wall-inner {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  backdrop-filter: var(--glass);
}
.photo-wall-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.photo-wall-item {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1;
  transition: var(--transition);
}
.photo-wall-item:hover { transform: scale(1.04); z-index: 2; box-shadow: var(--shadow-glow); }
.photo-wall-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-wall-item .pw-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  padding: 8px;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0;
  transition: var(--transition);
}
.photo-wall-item:hover .pw-overlay { opacity: 1; }

/* ---------- Day Detail Panel ---------- */
.day-detail-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 500;
  place-items: center;
  backdrop-filter: blur(5px);
}
.day-detail-overlay.open { display: grid; }

.day-detail-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px 20px;
  max-width: 420px;
  width: 92%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.day-detail-title {
  font-size: 1.1rem;
  font-weight: 900;
  color: var(--text-primary);
  margin-bottom: 16px;
  font-family: 'Outfit', sans-serif;
}
.day-detail-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.day-detail-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(141, 181, 150, 0.06);
  border: 1px solid rgba(141, 181, 150, 0.12);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.day-detail-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.88rem;
  color: var(--text-primary);
}
.day-detail-info strong { font-weight: 700; }
.day-detail-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.day-detail-time {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.day-detail-thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition);
}
.day-detail-thumb:hover { transform: scale(1.15); box-shadow: var(--shadow-glow); }
.day-detail-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 20px 0;
}
.day-detail-delete {
  background: rgba(200, 80, 80, 0.1);
  border: 1px solid rgba(200, 80, 80, 0.25);
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  opacity: 0.7;
  transition: var(--transition);
  padding: 6px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.day-detail-delete:hover { opacity: 1; background: rgba(200, 80, 80, 0.25); transform: scale(1.15); }
.day-detail-checkin-btn {
  width: 100%;
  font-size: 0.95rem;
}

/* ---------- Random Exercise FAB ---------- */
.random-exercise-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  display: grid;
  place-items: center;
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 200;
  transition: var(--transition);
  border: none;
  animation: fabPulse 3s ease infinite;
}
.random-exercise-fab:hover { transform: scale(1.12); box-shadow: var(--shadow-glow); }

@keyframes fabPulse {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: 0 0 20px rgba(141, 181, 150, 0.4); }
}

.random-exercise-popup {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 600;
  place-items: center;
  backdrop-filter: blur(6px);
}
.random-exercise-popup.open { display: grid; }

.random-exercise-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  max-width: 360px;
  width: 92%;
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.random-exercise-icon { font-size: 4rem; margin-bottom: 12px; }
.random-exercise-card h3 {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.random-exercise-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

/* ---------- Activity Delete Icon ---------- */
.activity-delete-icon {
  background: none;
  border: none;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0.25;
  transition: var(--transition);
  padding: 4px;
  flex-shrink: 0;
  align-self: flex-start;
  margin-top: 4px;
}
.activity-delete-icon:hover { opacity: 0.8; transform: scale(1.2); }

/* ---------- User Stats Modal (Popover) ---------- */
.user-stats-popover {
  position: absolute;
  top: 50%;
  right: calc(100% + 15px); /* Positioned to the left of the leaderboard item */
  transform: translateY(-50%);
  z-index: 1000;
  max-width: 300px;
  width: max-content;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  animation: slideInPop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  display: none; /* hidden by default */
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  cursor: default;
}
.user-stats-popover.open {
  display: block;
}
@keyframes slideInPop {
  0% { opacity: 0; transform: translateY(-50%) translateX(10px); }
  100% { opacity: 1; transform: translateY(-50%) translateX(0); }
}

/* For mobile devices where left space is insufficient, snap to bottom */
@media (max-width: 600px) {
  .user-stats-popover {
    top: calc(100% + 10px);
    right: 0;
    transform: none;
    width: 280px;
  }
  @keyframes slideInPop {
    0% { opacity: 0; transform: translateY(-10px); }
    100% { opacity: 1; transform: translateY(0); }
  }
}

#userStatsTitle {
  font-size: 1.3rem;
  color: var(--text-primary);
  margin-bottom: 20px;
  text-align: center;
  font-weight: 700;
}
.stats-summary-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 15px;
  text-align: center;
  margin-bottom: 15px;
}
.stats-summary-box p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.stats-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stats-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  padding: 10px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
body.light-mode .stats-item {
  background: rgba(0, 0, 0, 0.02);
}
.stats-item span {
  font-size: 0.95rem;
  color: var(--text-primary);
}
.stats-item strong {
  color: var(--accent-primary);
  font-size: 1.1rem;
}
.stats-comment {
  background: linear-gradient(135deg, rgba(141,181,150,0.1), rgba(220,167,106,0.1));
  border-left: 4px solid var(--accent-primary);
  padding: 15px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-secondary);
  font-style: italic;
}

/* ---------- Light Mode ---------- */
body.light-mode {
  --bg-primary: #f5f7f4;
  --bg-secondary: #eaeee9;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: rgba(255, 255, 255, 0.95);
  --accent-primary: #5a8a63;
  --accent-secondary: #c0883a;
  --accent-tertiary: #a09080;
  --text-primary: #1a2e1f;
  --text-secondary: #5a6b5e;
  --text-muted: #8a9b8e;
  --border: rgba(90, 138, 99, 0.12);
  --border-hover: rgba(90, 138, 99, 0.4);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-glow: 0 0 15px rgba(90, 138, 99, 0.15);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  background-image: none !important;
  background-color: var(--bg-primary) !important;
}
body.light-mode .announcement-bar {
  background: rgba(255, 255, 255, 0.8);
  border-bottom-color: rgba(90, 138, 99, 0.2);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}
body.light-mode .cal-day { background: rgba(90, 138, 99, 0.04); }
body.light-mode .cal-day.today { background: rgba(90, 138, 99, 0.12); }
body.light-mode .chat-bubble { background: rgba(0,0,0,0.04); border-color: rgba(0,0,0,0.08); }
body.light-mode .chat-msg-item.self .chat-bubble { background: rgba(90, 138, 99, 0.12); border-color: rgba(90, 138, 99, 0.3); }
body.light-mode .btn-primary { color: #fff; }
body.light-mode .chat-send-btn { color: #fff; }
body.light-mode .random-exercise-fab { color: #fff; }
body.light-mode .icon-btn { background: rgba(90, 138, 99, 0.1); border-color: rgba(90, 138, 99, 0.2); }

