/* ═══════════════════════════════════════════════════════════════════════════
 * 指令排行 — 表格樣式
 * 全部使用 tokens.css 的 v1/v2 變數，不再自訂 :root（讓 dark mode 自動生效）
 * ═══════════════════════════════════════════════════════════════════════════ */

/* body 字體 / 顏色 / 字級由 shared.css 統一設定，這裡不再覆寫 */
body { min-height: 100vh; }

/* Grid texture */
body::before {
  content: '';
  position: fixed; inset: 0; z-index: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 90% 55% at 50% 0%, black 20%, transparent 100%);
  pointer-events: none;
  opacity: .25;
}

/* Top brand line */
body::after {
  content: '';
  position: fixed; top: 0; left: 0; right: 0; height: 1px; z-index: 99;
  background: linear-gradient(90deg, transparent 0%, var(--swag) 35%, var(--swag) 65%, transparent 100%);
  opacity: 0.35;
  pointer-events: none;
}

/* 與百科 .wrap 同版心 */
.page {
  position: relative; z-index: 1;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 28px 80px;
}

/* ── RANKING HERO（與百科 .hero 對齊） ── */
.ranking-hero {
  padding: 28px 0 20px;
}
.ranking-eyebrow {
  font-size: var(--t-xs);
  letter-spacing: var(--ls-widest);
  text-transform: uppercase;
  color: var(--mid);
  font-weight: var(--w-sb);
  margin-bottom: 10px;
}
.ranking-sub {
  font-size: 13px;
  color: var(--mid);
  line-height: var(--lh-normal);
  margin-top: 10px;
  max-width: 480px;
}

/* ── RANKING CONTROLS BAR ── */
.ranking-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

h1 {
  font-size: clamp(1.7rem, 3.5vw, 2.5rem);
  font-weight: var(--w-b);
  letter-spacing: var(--ls-tight);
  line-height: var(--lh-tight);
  color: var(--text);
}
h1 .hl { color: var(--swag-dk); }

/* ── KIND TABS（對齊百科 .k-btn） ── */
.kind-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.kind-tab {
  font-family: inherit;
  min-height: var(--control-h-sm);
  padding: 0 12px;
  border-radius: var(--r-full);
  border: 1px solid var(--line2);
  background: var(--surface);
  color: var(--muted);
  font-size: var(--t-xs);
  font-weight: var(--w-sb);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
}
.kind-tab:hover { border-color: var(--swag); color: var(--swag); }
.kind-tab.active[data-kind="all"] {
  border-color: var(--swag-dk);
  background: var(--swag-bg);
  color: var(--swag-dk);
}
.kind-tab.active[data-kind="green"] {
  background: rgba(34,197,94,0.10);
  color: #1f6638;
  border-color: rgba(45,138,78,0.35);
}
.kind-tab.active[data-kind="yellow"] {
  background: rgba(245,166,35,0.10);
  color: #7a5300;
  border-color: rgba(176,120,0,0.35);
}

.meta-row {
  display: flex; align-items: center; gap: 8px;
}

.live-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--swag);
  box-shadow: 0 0 0 3px var(--swag-bg);
  animation: blink 2.4s ease infinite;
  flex-shrink: 0;
}

@keyframes blink {
  0%,100% { box-shadow: 0 0 0 3px var(--swag-bg); }
  50%      { box-shadow: 0 0 0 6px rgba(43,197,180,.04); }
}

.mono-sm {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
}

/* ── TABLE ── */
.table-card {
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--r-md);
  overflow: hidden;
  animation: fadeUp .45s .13s ease both;
}

.table-scroller {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed; /* 固定欄寬，避免分類切換時欄距跳動 */
}

thead {
  background: var(--bg);
  border-bottom: 1px solid var(--line2);
  border-left: 3px solid var(--swag);
}

th {
  font-family: var(--font-mono);
  font-size: var(--t-sm);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 13px 16px;
  text-align: left;
  white-space: nowrap;
  font-weight: var(--w-m);
}

th.r { text-align: right; }
th.c { text-align: center; }
.th-sort {
  appearance: none; border: none; background: transparent;
  color: inherit; font: inherit;
  letter-spacing: inherit; text-transform: inherit;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0;
}
.th-sort .arr { font-size: 10px; color: var(--muted); opacity: .75; }
.th-sort.active { color: var(--swag); font-weight: var(--w-sb); }
.th-sort.active .arr { color: var(--swag); opacity: 1; }

tbody tr {
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
  transition: background .15s, border-color .15s;
}

tbody tr:last-child { border-bottom: none; }

tbody tr:hover {
  background: var(--swag-bg);
  border-left-color: var(--swag);
}
/* Top3 整列淡漸層底（飽和度收斂：上端 0.20 → 0.14） */
tbody tr.top-row-1 { background: linear-gradient(180deg, rgba(255,215,0,.14) 0%, rgba(255,215,0,.03) 100%); border-left-color: rgba(255,215,0,.7); }
tbody tr.top-row-2 { background: linear-gradient(180deg, rgba(192,200,216,.16) 0%, rgba(192,200,216,.03) 100%); border-left-color: rgba(192,200,216,.7); }
tbody tr.top-row-3 { background: linear-gradient(180deg, rgba(205,127,50,.13) 0%, rgba(205,127,50,.03) 100%); border-left-color: rgba(205,127,50,.7); }
tbody tr.top-row-1:hover { background: linear-gradient(180deg, rgba(255,215,0,.22) 0%, rgba(255,215,0,.06) 100%); }
tbody tr.top-row-2:hover { background: linear-gradient(180deg, rgba(192,200,216,.24) 0%, rgba(192,200,216,.06) 100%); }
tbody tr.top-row-3:hover { background: linear-gradient(180deg, rgba(205,127,50,.20) 0%, rgba(205,127,50,.06) 100%); }

td { padding: 13px 16px; white-space: nowrap; vertical-align: middle; }

/* Rank */
.td-rank { text-align: center; width: 48px; }

.rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--r-xs);
  font-family: var(--font-mono);
  font-size: 14px; font-weight: var(--w-m);
}

.r1 { background: rgba(255,215,0,.13); color: #b8860b; border: 1px solid rgba(255,215,0,.35); }
.r2 { background: rgba(140,148,164,.12); color: #6b7280; border: 1px solid rgba(140,148,164,.30); }
.r3 { background: rgba(205,127,50,.13); color: #cd7f32; border: 1px solid rgba(205,127,50,.30); }
.rn { background: var(--bg); color: var(--muted); border: 1px solid var(--line2); }

/* Name */
.td-name {
  font-weight: var(--w-m);
  color: var(--text);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.td-name.top { color: var(--text); font-weight: var(--w-sb); }
.name-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.top-mark {
  font-size: 10px; font-weight: var(--w-b);
  letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 6px; border-radius: var(--r-full);
  border: 1px solid var(--line2);
  color: var(--swag); background: var(--swag-bg);
  flex-shrink: 0;
}
.name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Buyers */
.td-buyers {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
}
.buyers-inner {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
}
.buyers-val {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
  min-width: 56px;
  text-align: right;
}
.buyers-label-mobile { display: none; }

/* Mono */
.td-mono {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--mid);
  text-align: right;
}

.td-buyers, .td-mono, .td-diamond { font-variant-numeric: tabular-nums; }
.td-diamond { text-align: right; }
.diamond-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 14px;
  color: #7a5300;
}
.diamond-s {
  width: 12px;
  height: auto;
  vertical-align: middle;
  flex-shrink: 0;
}

/* Empty / skeleton */
.empty-row td { text-align: center; padding: 48px; color: var(--muted); font-size: 13px; }

.skel {
  height: 12px; border-radius: 3px;
  background: linear-gradient(90deg, var(--bg) 25%, var(--surface-2, var(--bg)) 50%, var(--bg) 75%);
  background-size: 300% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-row td { padding: 12px 14px; }

/* Footer */
.footer {
  margin-top: 18px;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
  animation: fadeUp .45s .19s ease both;
}

.status-row { display: flex; align-items: center; gap: 8px; }
.status-row.err .live-dot {
  background: #f87171;
  box-shadow: 0 0 0 3px rgba(248,113,113,.15);
  animation: none;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.row-in { animation: fadeUp .3s ease both; }

/* ── Mobile card layout（與百科同斷點 720px） ── */
@media (max-width: 720px) {
  .page { padding: 0 16px 48px; padding-bottom: max(48px, env(safe-area-inset-bottom, 48px)); }

  .ranking-hero { padding: 20px 0 14px; }
  h1 { font-size: 1.32rem; }
  .ranking-sub { font-size: 12px; }

  .ranking-controls {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding-bottom: 12px;
    margin-bottom: 16px;
  }
  .kind-tabs {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .kind-tabs::-webkit-scrollbar { display: none; }
  /* 觸控目標 ≥44px（與百科一致） */
  .kind-tab { min-height: 44px; padding: 0 16px; font-size: 12px; flex-shrink: 0; }
  .mono-sm { font-size: 12px; }

  /* Hide scroll hint on mobile */
  .footer .mono-sm:last-child { display: none; }

  /* Turn table into card list */
  .table-card { background: transparent; border: none; border-radius: 0; box-shadow: none; }
  .table-scroller { overflow-x: visible; }

  table, thead, tbody, th, td, tr { display: block; }

  thead { display: none; }

  tbody tr {
    background: var(--surface);
    border: 1px solid var(--line2) !important;
    border-left: 3px solid transparent !important;
    border-radius: var(--r);
    margin-bottom: 12px;
    padding: 14px 12px;
    display: grid;
    grid-template-columns: 44px 1fr;
    grid-template-rows: auto auto auto auto;
    column-gap: 10px;
    row-gap: 10px;
  }

  tbody tr:hover {
    border-color: var(--swag) !important;
    border-left-color: var(--swag) !important;
  }

  td { padding: 0; border: none; white-space: normal; }

  .td-rank {
    grid-column: 1;
    grid-row: 1 / 4;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .td-name {
    grid-column: 2;
    grid-row: 1;
    font-size: 14px;
    font-weight: var(--w-sb);
    max-width: 100%;
    white-space: normal;
    word-break: break-word;
    line-height: 1.45;
  }
  .name-row { display: block; }
  .top-mark { display: inline-block; margin-bottom: 6px; }

  .td-buyers {
    grid-column: 2;
    grid-row: 2;
    text-align: left;
  }

  .buyers-inner {
    justify-content: flex-start;
    gap: 6px;
  }
  .buyers-label-mobile {
    display: inline-block;
    font-size: 11px;
    color: var(--muted);
    letter-spacing: .04em;
  }
  .buyers-val {
    min-width: 0;
    text-align: left;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: var(--r-full);
    border: 1px solid var(--line2);
    background: var(--bg);
    color: var(--mid);
  }

  .td-mono, .td-diamond {
    grid-column: 2;
    display: inline-flex;
    align-items: center;
    gap: 4px;
  }
  .td-mono { grid-row: 3; text-align: left; font-size: 13px; }
  .td-diamond { grid-row: 4; text-align: left; justify-content: flex-start; font-size: 13px; }
  .td-diamond .diamond-wrap { justify-content: flex-start; color: #7a5300; }

  .td-mono::before,
  .td-diamond::before {
    content: attr(data-label) ' ';
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--muted);
    letter-spacing: .08em;
    text-transform: uppercase;
    margin-right: 4px;
  }
}

/* 觸控裝置：按下回饋 */
@media (hover: none) and (pointer: coarse) {
  .kind-tab:active { transform: scale(0.98); }
}
