/* gift-earnings-v1 — 打賞收益：排行榜 + 記錄明細. Self-contained per prototype principle. */

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-sans); -webkit-font-smoothing: antialiased; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* ============ APP SHELL ============ */
.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 720px);
  gap: 24px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

/* ============ SIDEBAR ============ */
.sidebar { position: sticky; top: 24px; height: calc(100vh - 48px); display: flex; flex-direction: column; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 14px; font-size: 32px; font-weight: 800; margin-bottom: 36px; color: var(--text); }
.brand img { width: 42px; height: 42px; object-fit: contain; }
.sidebar nav { display: flex; flex-direction: column; gap: 8px; }
.sidebar nav a {
  padding: 14px 18px;
  color: var(--text-soft);
  border-radius: 999px;
  font-weight: 600;
  font-size: 16px;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.sidebar nav a.active,
.sidebar nav a:hover {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-card);
}
.new-post {
  border-radius: 999px;
  background: var(--cta-bg);
  color: var(--cta-text);
  font-weight: 700;
  padding: 14px 22px;
  font-size: 16px;
}

/* ============ MAIN ============ */
.main { min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  min-height: 44px;
  gap: 12px;
}
.topbar .back {
  display: none;
  width: 36px; height: 36px;
  align-items: center; justify-content: center;
  font-size: 22px;
  color: var(--text);
}
.topbar h1 { font-size: 26px; margin: 0; font-weight: 700; letter-spacing: -0.01em; flex: 1; }
.topbar-brand { display: none; align-items: center; gap: 8px; color: var(--text); font-weight: 800; font-size: 22px; letter-spacing: -0.01em; }
.topbar-brand img { width: 24px; height: 24px; object-fit: contain; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

/* ============ OWNER CARD ============ */
.owner-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-card);
}
.owner-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.owner-row .avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
  font-size: 16px;
  flex-shrink: 0;
}
.owner-who { flex: 1; min-width: 0; }
.owner-who b { display: block; font-size: 15px; font-weight: 700; }
.owner-who small { display: block; font-size: 12px; color: var(--text-soft); margin-top: 1px; }

/* ============ STATS ============ */
.stats-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow-card);
}
.stat-card.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border-color: transparent;
}
.stat-card small {
  display: block;
  font-size: 11px;
  color: var(--text-soft);
  font-weight: 600;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  text-transform: uppercase;
}
.stat-card.primary small { color: rgba(255,255,255,0.78); }
.stat-card b {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.stat-card.primary b { color: white; font-size: 26px; }
.stat-card .unit {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-soft);
}
.stat-card.primary .unit { color: rgba(255,255,255,0.82); }
.stat-card.primary b.alt { font-size: 17px; margin-top: 2px; opacity: 0.95; }
.stat-card b[hidden] { display: none !important; }
.stat-card .usd-hint {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255,255,255,0.82);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

/* ============ LIST SECTIONS ============ */
.list-section { padding: 0; overflow: hidden; margin-bottom: 14px; }
.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.list-head h2 { font-size: 15px; margin: 0; font-weight: 700; }
.sort-note { font-size: 11px; color: var(--text-soft); font-weight: 600; }

/* 排序切換 pills */
.sort-toggle {
  display: flex;
  gap: 3px;
  background: var(--surface-soft);
  border-radius: 999px;
  padding: 3px;
}
.sort-toggle button {
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.sort-toggle button.on {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-card);
}

.rank-list,
.tips-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: min(440px, 58vh);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.rank-list li,
.tips-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  transition: background 0.15s;
}
.rank-list li:last-child,
.tips-list li:last-child { border-bottom: 0; }
.rank-list li:hover,
.tips-list li:hover { background: var(--surface-soft); }

.rank-list .avatar,
.tips-list .avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: white;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}
.rank-list .info,
.tips-list .info { flex: 1; min-width: 0; }
.rank-list .info b,
.tips-list .info b { display: block; font-size: 14px; font-weight: 700; }
.rank-list .info small,
.tips-list .info small {
  display: block;
  font-size: 11px;
  color: var(--text-soft);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.info small .meta-dot { margin: 0 4px; color: var(--text-muted); }

.rank-list .earned,
.tips-list .earned { text-align: right; flex-shrink: 0; }
.rank-list .earned b,
.tips-list .earned b {
  display: block;
  font-size: 15px;
  font-weight: 800;
  color: var(--success);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.rank-list .earned small,
.tips-list .earned small {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}
.tips-list .earned.usdc b { color: #2775ca; }

/* 雙代幣堆疊金額行（rank / posts） */
.earned .amt {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 4px;
}
.earned .amt small { margin-top: 0; }
.earned .amt.usdc b { color: #2775ca; font-size: 13px; }

.info-note {
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.6;
  text-align: center;
}
.info-note a { color: var(--primary-dark); font-weight: 600; }

/* ============ Avatar gradients ============ */
.avatar.g1 { background: linear-gradient(135deg, #6366f1, #4f46e5); }
.avatar.g2 { background: linear-gradient(135deg, #ec4899, #f97316); }
.avatar.g3 { background: linear-gradient(135deg, #06b6d4, #3b82f6); }
.avatar.g4 { background: linear-gradient(135deg, #10b981, #059669); }
.avatar.g5 { background: linear-gradient(135deg, #f59e0b, #ef4444); }

/* ============ BACK TO TOP ============ */
.to-top {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 50;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--text);
  color: white;
  display: grid;
  place-items: center;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.32);
  opacity: 0;
  transform: translateY(8px) scale(0.9);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s, background 0.15s;
}
.to-top.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
@media (hover: hover) {
  .to-top:hover { background: var(--primary-dark); }
}
.to-top:active { transform: translateY(0) scale(0.94); }

/* ============ MOBILE NAV ============ */
.mobile-nav { display: none; }

/* ============ RESPONSIVE ============ */
@media (max-width: 1024px) {
  .app-shell { grid-template-columns: 220px minmax(0, 1fr); padding: 16px; gap: 18px; }
}

@media (max-width: 720px) {
  .app-shell { grid-template-columns: 1fr; padding: 0; gap: 0; }
  .sidebar { display: none; }
  .main { padding: 14px 16px 90px; }
  .topbar { padding: 4px 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
  .topbar .back { display: inline-flex; }
  .topbar h1 { font-size: 18px; text-align: center; }
  .topbar-brand { display: none; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .stats-row .stat-card.primary { grid-column: 1 / -1; }

  .to-top {
    bottom: 88px; right: 16px; width: 42px; height: 42px;
    transition: opacity 0.2s, transform 0.2s, background 0.15s,
                bottom 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  }
  body.nav-hidden .to-top { bottom: 28px; }

  .mobile-nav {
    position: fixed;
    left: 12px; right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow-card);
    padding: 10px;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 20;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s;
  }
  .mobile-nav.nav-hidden {
    transform: translateY(calc(100% + 24px));
    opacity: 0;
    pointer-events: none;
  }
  .mobile-nav a { text-align: center; font-size: 12px; color: var(--text-soft); padding: 8px 4px; }
  .mobile-nav a.active { color: var(--text); font-weight: 600; }
  .mobile-nav .compose-btn {
    width: 46px; height: 46px;
    margin: auto; padding: 0;
    border-radius: 50%;
    background: var(--cta-bg); color: var(--cta-text);
    display: grid; place-items: center; line-height: 1;
  }
}

/* ============ PANE NAV ============ */
.pane-nav {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow-card);
  padding: 4px;
  margin-bottom: 14px;
}
.pane-nav button {
  padding: 9px 0;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-soft);
  transition: background 0.15s, color 0.15s;
}
.pane-nav button.on {
  background: var(--cta-bg);
  color: var(--cta-text);
}
.list-section[hidden] { display: none !important; }

/* ============ POSTS PANE ============ */
.posts-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: min(440px, 58vh);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.posts-list li { border-bottom: 1px solid var(--line); }
.posts-list li:last-child { border-bottom: 0; }
.post-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  transition: background 0.15s;
}
.post-row:hover { background: var(--surface-soft); }
.post-row .picon {
  width: 38px; height: 38px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--primary-soft);
  color: var(--primary-dark);
  flex-shrink: 0;
}
.post-row .info { flex: 1; min-width: 0; }
.post-row .info b { display: block; font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.post-row .info small { display: block; font-size: 11px; color: var(--text-soft); margin-top: 2px; }
.post-row .earned { text-align: right; flex-shrink: 0; }
.post-row .earned b {
  display: block;
  font-size: 15px;
  font-weight: 800;
  color: var(--success);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.post-row .earned small {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}

/* 邀請排行榜入口 */
.rank-btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  margin-top: 14px; padding: 12px;
  border: 1px solid var(--line); border-radius: var(--radius, 16px);
  background: var(--surface); color: var(--primary);
  font-size: 14px; font-weight: 700; text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.rank-btn:hover { border-color: var(--primary); background: var(--primary-soft, #eef2ff); }
