:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1a1d21;
  --text-dim: #6b7280;
  --accent: #c0392b;
  --accent-soft: #fdecea;
  --up: #d1402f;
  --down: #178a4c;
  --head-bg: #1a1d21;
  --head-text: #ffffff;
  --row-alt: #fafbfc;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1114;
    --surface: #181b1f;
    --border: #2a2e34;
    --text: #e8eaed;
    --text-dim: #9aa0a8;
    --accent: #e74c3c;
    --accent-soft: #2a1715;
    --up: #ff6b5a;
    --down: #3ecf7c;
    --head-bg: #000000;
    --head-text: #e8eaed;
    --row-alt: #1d2126;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1114; --surface: #181b1f; --border: #2a2e34; --text: #e8eaed;
  --text-dim: #9aa0a8; --accent: #e74c3c; --accent-soft: #2a1715;
  --up: #ff6b5a; --down: #3ecf7c; --head-bg: #000; --head-text: #e8eaed;
  --row-alt: #1d2126; --shadow: none;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
.wrap { width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 16px; }

/* 社群圖版面（?share=1）：內容垂直置中成海報卡，避免上下大片留白 */
body.share { display: flex; flex-direction: column; justify-content: center; min-height: 100vh; }
body.share .site-head { position: static; }
body.share main { padding-top: 8px; padding-bottom: 8px; }
body.share .site-foot { margin-top: 10px; }

/* header */
.site-head { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.head-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; flex-wrap: wrap; }
.brand { text-decoration: none; color: inherit; cursor: pointer; display: block; }
.brand h1 { margin: 0; font-size: 20px; letter-spacing: .5px; }
.tagline { margin: 2px 0 0; font-size: 12.5px; color: var(--text-dim); }
.date-pick { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-dim); }
.date-pick select {
  font-size: 15px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  min-width: 140px;
}

/* tabs */
.tabs { display: flex; gap: 6px; padding-top: 14px; padding-bottom: 2px; flex-wrap: wrap; }
.tab {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 8px 16px; border-radius: 999px; font-size: 14px;
  cursor: pointer; white-space: nowrap; transition: all .12s;
}
.tab:hover { border-color: var(--accent); }
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

/* board */
main { padding-top: 16px; padding-bottom: 40px; }
.status { padding: 32px 0; text-align: center; color: var(--text-dim); font-size: 14px; }
.board-meta { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.board-meta h2 { margin: 0; font-size: 17px; }
.board-note { font-size: 12.5px; color: var(--text-dim); }
.stat-row {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 2px 0 14px;
}
.stat-tile {
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-unit { font-size: 13px; font-weight: 500; color: var(--text-dim); margin-left: 3px; }
@media (max-width: 560px) {
  .stat-row { gap: 7px; }
  .stat-tile { padding: 10px; border-radius: 10px; }
  .stat-value { font-size: 19px; }
  .stat-label { font-size: 10.5px; }
}
.updated-at {
  margin: 0 0 12px; font-size: 12.5px; color: var(--text-dim);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface);
}
.updated-at strong { color: var(--text); font-weight: 600; }

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
thead th {
  background: var(--head-bg); color: var(--head-text); font-weight: 600;
  padding: 10px 12px; white-space: nowrap; position: sticky; top: 0;
}
thead th.th-left { text-align: left; }
thead th.th-right { text-align: right; }
thead th.rank { text-align: right; }
thead th .unit { font-weight: 400; font-size: 11px; opacity: .7; margin-left: 3px; }
thead th.th-sort { cursor: pointer; user-select: none; }
thead th.th-sort:hover { background: var(--accent); }
thead th .arrow { font-size: 11px; margin-left: 2px; }
tbody td { padding: 9px 12px; text-align: right; white-space: nowrap; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody td.col-code { text-align: left; color: var(--text-dim); font-family: ui-monospace, "SF Mono", Menlo, monospace; }
tbody td.col-name { text-align: left; font-weight: 600; }
.pos { color: var(--up); }
.neg { color: var(--down); }
.rank { color: var(--text-dim); width: 1%; text-align: right; padding-right: 4px; }

/* feedback */
.feedback { padding: 24px 16px 8px; }
.feedback h2 { margin: 0 0 6px; font-size: 17px; }
.fb-intro { margin: 0 0 12px; font-size: 13px; color: var(--text-dim); line-height: 1.6; }
#fbForm textarea, #fbForm input[type="email"] {
  width: 100%; box-sizing: border-box; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
#fbForm textarea { resize: vertical; min-height: 84px; }
.fb-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.fb-row input[type="email"] { flex: 1 1 240px; }
#fbSubmit {
  flex: 0 0 auto; appearance: none; border: none; cursor: pointer; font: inherit; font-weight: 600;
  background: var(--accent); color: #fff; border-radius: 10px; padding: 10px 22px;
}
#fbSubmit:disabled { opacity: .55; cursor: default; }
.fb-hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.fb-status { margin: 8px 0 0; font-size: 13px; min-height: 1.2em; }
.fb-status.ok { color: var(--down); }
.fb-status.err { color: var(--accent); }
body.share .feedback { display: none; }

/* footer */
.site-foot { border-top: 1px solid var(--border); background: var(--surface); padding: 20px 0 40px; margin-top: 20px; }
.disclaimer { font-size: 12px; color: var(--text-dim); line-height: 1.7; margin: 0 0 8px; }
.disclaimer strong { color: var(--text); }
.meta { font-size: 11px; color: var(--text-dim); margin: 0; }

@media (max-width: 560px) {
  .brand h1 { font-size: 18px; }
  thead th, tbody td { padding: 8px 9px; font-size: 13px; }
}
