/* Crypto wins boards. Tokens match 術語表 / 停損計算器. */
:root, [data-theme="light"] {
  --bg: #f4f3ef;
  --surface: #f9f8f5;
  --s2: #edeae4;
  --text: #28251d;
  --muted: #7a7974;
  --border: oklch(0.2 0.01 80 / 0.12);
  --bull: #2d6a0a;
  --bear: #a13544;
  --neutral: #7a6800;
  --primary: #01696f;
  --shadow: 0 4px 16px oklch(0.2 0.01 80 / 0.07);
}

[data-theme="dark"] {
  --bg: #111214;
  --surface: #17191d;
  --s2: #1d2026;
  --text: #e2e6ee;
  --muted: #95a0b3;
  --border: rgba(255,255,255,.08);
  --bull: #58d26a;
  --bear: #ff5a6b;
  --neutral: #f0c24b;
  --primary: #4ea1ff;
  --shadow: 0 8px 24px rgba(0,0,0,.34);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: "Satoshi", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  line-height: 1.45;
  background:
    radial-gradient(1100px 480px at 8% -12%, color-mix(in oklab, var(--primary) 16%, transparent), transparent 56%),
    radial-gradient(900px 420px at 92% -8%, color-mix(in oklab, var(--bull) 9%, transparent), transparent 52%),
    var(--bg);
}

main { flex: 1; }
.topbar { position: sticky; top: 0; }

.btn {
  background: var(--s2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
}
.top-actions .btn { min-height: 34px; padding: 7px 10px; font-size: 12px; }
.btn:hover { border-color: color-mix(in oklab, var(--primary) 35%, var(--border)); }

a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

.page {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 20px 16px 56px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.page-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}
.page-links a {
  color: var(--primary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 650;
}
.page-links a:hover { text-decoration: underline; text-underline-offset: 3px; }

.hero { display: flex; flex-direction: column; gap: 8px; }
.hero h1 {
  font-size: clamp(1.35rem, 3.6vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.25;
}
.lede {
  color: var(--muted);
  font-size: 14px;
  max-width: 68ch;
  line-height: 1.6;
}
.lede strong { color: var(--text); font-weight: 700; }

.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.bar label { color: var(--muted); font-size: 14px; }
input[type="date"] {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  min-height: 34px;
}

.sort-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.sort-filter .sf-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  margin-right: 2px;
}
.sort-filter button {
  background: var(--s2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  min-height: 30px;
}
.sort-filter button[data-letter] { min-width: 1.8rem; padding: 4px 5px; }
.sort-filter button.on {
  color: var(--primary);
  background: color-mix(in oklab, var(--primary) 12%, transparent);
  border-color: color-mix(in oklab, var(--primary) 26%, transparent);
}
.sort-filter button:hover { color: var(--text); }

.status {
  color: var(--muted);
  min-height: 1.2em;
  font-size: 14px;
}
.status.err { color: var(--bear); }

.panel {
  background: color-mix(in oklab, var(--surface) 94%, transparent);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.45;
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
th {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--s2);
}
th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
th[data-sort]:hover { color: var(--text); }
th[data-sort].on { color: var(--primary); }
th[data-sort].on::after {
  content: attr(data-arrow);
  margin-left: 4px;
  font-size: 0.7em;
}
tr:last-child td { border-bottom: 0; }
td.rank {
  width: 40px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
td.num { font-weight: 700; font-variant-numeric: tabular-nums; }
td.up { color: var(--bull); }
td.down { color: var(--bear); }
td.cls { color: var(--neutral); }
td.coin { font-weight: 700; }
.name { color: var(--muted); font-size: 12px; font-weight: 500; }
.coin .day { margin-top: 2px; }
.coin .day.up { color: var(--bull); }
.coin .day.down { color: var(--bear); }

.site-footer {
  padding: 18px 22px 26px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.gate:not([hidden]) {
  padding: 18px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.gate h2 { font-size: 18px; letter-spacing: -0.02em; }
.gate p { color: var(--muted); font-size: 14px; max-width: 62ch; }
.gate-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
}
.btn-primary:hover { filter: brightness(1.05); }
.winner-line { font-size: 14px; font-weight: 700; }

@media (max-width: 720px) {
  .page { padding: 16px 12px 40px; }
  th, td { padding: 8px 10px; }
}

/* US race board. Scoped so the crypto wins tables stay as they are. */
#usRace.page { width: min(100%, 1240px); }
#usRace .hero-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}
#usRace .pill {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
}
#usRace .pill.live { color: var(--bull); border-color: color-mix(in oklab, var(--bull) 45%, var(--border)); }
#usRace .pill.closed { color: var(--muted); }
#usRace .pill.racing { color: var(--neutral); border-color: color-mix(in oklab, var(--neutral) 45%, var(--border)); }
#usRace .bar input[type="search"],
#usRace .bar select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  min-height: 34px;
}
#usRace .bar input[type="search"] { min-width: min(100%, 220px); flex: 1; }
#usRace .bar select { max-width: min(280px, 70vw); }
#usRace .meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
#usRace .stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}
#usRace .stat b {
  display: block;
  font-size: 1.05rem;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
#usRace .stat span { color: var(--muted); font-size: 12px; }
#usRace .winners { display: flex; flex-wrap: wrap; gap: 8px; }
#usRace .win-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  min-width: 120px;
}
#usRace .win-chip b { display: block; color: var(--primary); }
#usRace .win-chip .pct { font-weight: 750; font-variant-numeric: tabular-nums; }
#usRace .win-chip .pct.up { color: var(--bull); }
#usRace .win-chip .pct.down { color: var(--bear); }
#usRace .win-chip .slot { color: var(--muted); font-size: 12px; }
#usRace .table-wrap { max-height: min(70vh, 720px); }
#usRace table { min-width: 1080px; }
#usRace th[data-sort] {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--s2);
}
#usRace td.sym { font-weight: 700; }
#usRace tr.top3 { background: color-mix(in oklab, var(--neutral) 10%, transparent); }
#usRace tr.top1 td.rank { color: var(--neutral); font-weight: 800; }
#usRace .hint { color: var(--muted); font-size: 13px; line-height: 1.55; }
#usRace .hint b { color: var(--text); }

#usRace .scatter-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
}
#usRace .scatter-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
}
#usRace .scatter-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 750;
  color: var(--text);
}
#usRace .scatter-legend {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
#usRace .scatter-wrap {
  position: relative;
  min-height: 420px;
  background: var(--s2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
  overflow-y: hidden;
}
#usRace .scatter-plot {
  width: 100%;
  min-height: 280px;
}
#usRace .scatter-plot svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 420px;
  max-height: 720px;
}
#usRace .scatter-empty {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  margin: 0;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  z-index: 1;
  background: color-mix(in oklab, var(--surface) 55%, transparent);
}
#usRace .scatter-empty:not([hidden]) {
  display: grid;
}
#usRace .scatter-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}
#usRace .scatter-axis-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: inherit;
}
#usRace .scatter-tick {
  fill: var(--muted);
  font-size: 10px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}
#usRace .scatter-grid {
  stroke: rgba(226,230,238,0.18);
  stroke-width: 1;
  stroke-dasharray: 3 4;
}
html[data-theme="light"] #usRace .scatter-grid {
  stroke: rgba(40,37,29,0.12);
}
#usRace .scatter-bg {
  fill: #243044;
}
html[data-theme="light"] #usRace .scatter-bg {
  fill: #f3f1ea;
}
#usRace .scatter-frame {
  fill: none !important;
  stroke: var(--border, rgba(255,255,255,.08));
  stroke-width: 1.25;
}
#usRace .scatter-dot {
  cursor: pointer;
  stroke-width: 1.5;
  transition: stroke-width 0.12s ease, opacity 0.12s ease;
  opacity: 1;
}
#usRace .scatter-mark {
  opacity: 1;
}
#usRace .scatter-dot.rank-1 {
  fill: #f0c24b;
  stroke: #ffe08a;
}
#usRace .scatter-dot.rank-2 {
  fill: #58d26a;
  stroke: #9af0a6;
}
#usRace .scatter-dot.rank-3 {
  fill: #4ea1ff;
  stroke: #9cc7ff;
}
#usRace .scatter-dot.rank-rest {
  fill: #8b95a8;
  stroke: #c0c8d8;
  opacity: 0.95;
}
#usRace .scatter-dot:hover,
#usRace .scatter-dot.is-selected {
  stroke-width: 2.5;
  opacity: 1;
}
#usRace .scatter-dot.is-selected {
  stroke: #d7e8ff;
  fill: #4ea1ff;
}
#usRace .scatter-label {
  fill: var(--text, #e2e6ee);
  font-size: 10px;
  font-weight: 700;
  font-family: inherit;
  pointer-events: none;
  paint-order: stroke;
  stroke: #111214;
  stroke: color-mix(in oklab, var(--bg) 80%, transparent);
  stroke-width: 3px;
}
#usRace .scatter-label.muted {
  fill: var(--muted);
  font-weight: 600;
}
#usRace tr.scatter-selected {
  outline: 2px solid color-mix(in oklab, var(--primary) 55%, transparent);
  outline-offset: -2px;
  background: color-mix(in oklab, var(--primary) 12%, transparent);
}
#usRace tr[data-symbol] { cursor: pointer; }

