:root {
  --bg: #0a0b10;
  --surface: #11131a;
  --surface-2: #171a23;
  --line: #222632;
  --line-soft: #1a1d27;
  --text: #eceef4;
  --muted: #8b91a3;
  --faint: #5d6375;
  --accent: #c6f36b;
  --accent-ink: #11160a;
  --danger: #ff7a7a;
  --gold: #f4c95d;
  --silver: #c3cad6;
  --bronze: #dc9a68;
  --radius: 14px;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background:
    radial-gradient(900px 420px at 85% -10%, rgba(198, 243, 107, .07), transparent 70%),
    radial-gradient(700px 380px at -10% 0%, rgba(120, 140, 255, .06), transparent 70%),
    var(--bg);
  background-repeat: no-repeat;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.page { width: min(1200px, calc(100% - 40px)); margin: 0 auto; padding: 40px 0 64px; }

/* 顶部 */
.top { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { display: flex; align-items: flex-end; gap: 4px; width: 44px; height: 44px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.logo i { flex: 1; border-radius: 2px; background: var(--accent); }
.logo i:nth-child(1) { height: 55%; opacity: .55; }
.logo i:nth-child(2) { height: 100%; }
.logo i:nth-child(3) { height: 35%; opacity: .35; }
.eyebrow { margin: 0; color: var(--muted); font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(1.6rem, 3vw, 2.2rem); line-height: 1.15; letter-spacing: -.02em; }

.live { display: inline-flex; align-items: center; gap: 9px; margin: 0; padding: 7px 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.pulse { position: relative; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.live[data-state="ok"] .pulse { background: var(--accent); }
.live[data-state="ok"] .pulse::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; animation: ping 2.4s ease-out infinite; }
.live[data-state="error"] { color: var(--danger); border-color: rgba(255, 122, 122, .35); }
.live[data-state="error"] .pulse { background: var(--danger); }
@keyframes ping { 0% { transform: scale(.6); opacity: .8; } 80%, 100% { transform: scale(1.6); opacity: 0; } }

/* 时间范围 */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 22px; }
.ranges { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.ranges button { padding: 7px 14px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: .86rem; white-space: nowrap; transition: background .15s, color .15s; }
.ranges button:hover { color: var(--text); background: var(--surface-2); }
.ranges button[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); font-weight: 650; }
.custom { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.custom label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .82rem; }
.custom input { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color-scheme: dark; }
.custom-sep { color: var(--faint); }
.custom button { padding: 7px 16px; border: 1px solid var(--accent); border-radius: 8px; background: transparent; color: var(--accent); font-weight: 600; }
.custom button:hover { background: rgba(198, 243, 107, .1); }
.range-label { margin: 0 0 0 auto; color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }

.alert { margin: 0 0 18px; padding: 11px 14px; border: 1px solid rgba(255, 122, 122, .35); border-radius: 10px; background: rgba(255, 122, 122, .08); color: var(--danger); font-size: .86rem; }

/* 汇总 */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin-bottom: 26px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--line); }
.stat { padding: 18px 20px; background: var(--surface); }
.stat p { margin: 0 0 8px; color: var(--muted); font-size: .8rem; }
.stat em { margin-left: 4px; color: var(--faint); font-size: .7rem; font-style: normal; letter-spacing: .06em; }
.stat strong { display: block; font-family: var(--mono); font-size: clamp(1.35rem, 2.4vw, 1.85rem); font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-accent strong { color: var(--accent); }

/* 前三名 */
.podium { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: end; gap: 14px; margin-bottom: 26px; }
.podium:empty { display: none; }
.medal { --tone: var(--silver); position: relative; display: grid; gap: 14px; padding: 20px 22px 22px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(180deg, var(--surface-2), var(--surface)); }
.medal::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: var(--tone); }
.medal-1 { --tone: var(--gold); order: 2; padding-top: 30px; padding-bottom: 30px; box-shadow: 0 18px 50px -24px rgba(244, 201, 93, .35); }
.medal-2 { --tone: var(--silver); order: 1; }
.medal-3 { --tone: var(--bronze); order: 3; }
.medal-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.medal-rank { font-family: var(--mono); color: var(--tone); font-size: .78rem; font-weight: 700; letter-spacing: .12em; }
.medal-name { overflow: hidden; margin: 0; font-size: 1.08rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.medal-cost { font-family: var(--mono); font-size: clamp(1.5rem, 2.8vw, 2.1rem); font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.medal-1 .medal-cost { color: var(--gold); }
.medal-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.medal-meta b { color: var(--text); font-family: var(--mono); font-weight: 550; }

/* 完整排行 */
.board { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.board-head, .row-main { display: grid; grid-template-columns: 64px minmax(0, 1fr) 120px 150px 140px 128px; align-items: center; gap: 12px; padding: 0 20px; }
.board-head { height: 44px; border-bottom: 1px solid var(--line); color: var(--faint); font-size: .74rem; letter-spacing: .04em; }
.num { text-align: right; }

.row { position: relative; border-bottom: 1px solid var(--line-soft); }
.row:last-child { border-bottom: 0; }
.row-main { min-height: 60px; }
.row:hover .row-main, .row.open .row-main { background: rgba(255, 255, 255, .018); }
.row-bar { position: absolute; left: 0; bottom: -1px; height: 1px; background: var(--accent); opacity: .55; pointer-events: none; }

.c-rank { font-family: var(--mono); color: var(--faint); font-weight: 600; font-variant-numeric: tabular-nums; }
.row.top-1 .c-rank { color: var(--gold); }
.row.top-2 .c-rank { color: var(--silver); }
.row.top-3 .c-rank { color: var(--bronze); }
.c-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.c-name .name { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.tag { flex: 0 0 auto; padding: 1px 7px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); font-size: .7rem; }
.cell-num { font-family: var(--mono); font-size: .9rem; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.c-cost { color: var(--accent); font-weight: 600; }

.toggle { justify-self: end; display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--muted); font-size: .8rem; white-space: nowrap; }
.toggle:hover { color: var(--text); border-color: var(--faint); }
.toggle::after { content: ""; width: 6px; height: 6px; margin-top: -3px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); transition: transform .18s; }
.row.open .toggle { color: var(--accent); border-color: rgba(198, 243, 107, .4); }
.row.open .toggle::after { margin-top: 3px; transform: rotate(-135deg); }

/* 模型明细 */
.models { padding: 4px 20px 16px 96px; background: rgba(0, 0, 0, .18); }
.model-head, .model { display: grid; grid-template-columns: minmax(0, 1fr) 100px 130px 120px 150px; align-items: center; gap: 12px; }
.model-head { padding: 10px 0 6px; color: var(--faint); font-size: .72rem; }
.model { padding: 8px 0; border-top: 1px dashed var(--line-soft); font-size: .86rem; }
.model-name { overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }
.share { display: flex; align-items: center; gap: 10px; }
.share-track { flex: 1; height: 5px; overflow: hidden; border-radius: 99px; background: var(--line); }
.share-fill { display: block; height: 100%; border-radius: inherit; background: var(--accent); opacity: .8; }
.share span { width: 44px; color: var(--muted); font-family: var(--mono); font-size: .76rem; text-align: right; }

.empty { margin: 0; padding: 56px 20px; color: var(--muted); text-align: center; }
.board.loading #rows { opacity: .45; transition: opacity .2s; }

.foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 20px; margin-top: 18px; color: var(--faint); font-size: .74rem; }
.foot p { margin: 0; }

/* 响应式：窄屏下每行变成卡片 */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .podium { grid-template-columns: 1fr; }
  .medal-1, .medal-2, .medal-3 { order: 0; padding: 18px 20px; }
  .range-label { margin-left: 0; width: 100%; }
  .board-head { display: none; }
  .row-main { grid-template-columns: 40px minmax(0, 1fr) auto; grid-template-areas: "rank name toggle" ". req req" ". tok tok" ". cost cost"; row-gap: 6px; padding: 14px 16px; }
  .c-rank { grid-area: rank; }
  .c-name { grid-area: name; }
  .toggle { grid-area: toggle; }
  .c-req { grid-area: req; }
  .c-tok { grid-area: tok; }
  .c-cost { grid-area: cost; }
  .cell-num { display: flex; justify-content: space-between; }
  .cell-num::before { content: attr(data-label); color: var(--faint); font-family: Inter, ui-sans-serif, system-ui, sans-serif; font-size: .78rem; font-weight: 400; }
  .models { padding: 2px 16px 14px 56px; }
  .model-head { display: none; }
  .model { grid-template-columns: minmax(0, 1fr) auto; row-gap: 4px; }
  .model .cell-num::before { font-size: .74rem; }
  .model-name { grid-column: 1 / -1; font-weight: 600; }
  .model .cell-num, .model .share { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .page { width: calc(100% - 24px); padding-top: 24px; }
  .top { align-items: flex-start; flex-direction: column; }
  .ranges { width: 100%; }
  .ranges button { flex: 1 0 auto; padding: 7px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
