:root {
  --bg: #0c0f14;
  --surface: #141a22;
  --surface-2: #1b2330;
  --border: #2a3444;
  --text: #e8edf5;
  --muted: #8b98ab;
  --accent: #6ea8fe;
  --accent-2: #f4a261;
  --good: #57c99a;
  --bad: #e76f6f;
  --mono: "SF Mono", "Fira Code", ui-monospace, monospace;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --content-scale: 1;
  --layout-max: 1760px;
  --table-font: 0.72rem;
}

* { box-sizing: border-box; }
html { font-size: calc(16px * var(--content-scale)); }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); }

.layout { max-width: var(--layout-max); width: 100%; margin: 0 auto; padding: 20px 16px 48px; }

.header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: calc(24px * var(--content-scale)); }
.header-aside { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.dataset-picker { display: flex; flex-direction: column; gap: 4px; min-width: min(280px, 70vw); }
.dataset-picker .dataset-label { color: var(--muted); font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.06em; }
.dataset-picker select {
  appearance: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 36px 10px 12px;
  font: inherit;
  font-size: 0.8125rem;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 2px), calc(100% - 12px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
.dataset-picker select:focus { outline: 2px solid rgba(110, 168, 254, 0.35); outline-offset: 1px; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; }
h1 { margin: 0 0 8px; font-size: 1.75rem; font-weight: 650; }
.subtitle { margin: 0; color: var(--muted); font-size: 0.875rem; }
.header .solver-chip { font-family: var(--mono); font-size: 0.6875rem; background: var(--surface); border: 1px solid var(--border); padding: 10px 12px; border-radius: 10px; max-width: 360px; word-break: break-all; color: var(--accent); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(calc(160px * var(--content-scale)), 1fr)); gap: 12px; margin-bottom: calc(20px * var(--content-scale)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 0.75rem; margin-bottom: 6px; }
.kpi .value { font-size: 1.375rem; font-weight: 650; line-height: 1.25; }
.kpi .value.compact { font-size: 0.95rem; font-weight: 600; }
.kpi .hint { color: var(--muted); font-size: 0.6875rem; margin-top: 4px; }

.totals-card { padding: calc(16px * var(--content-scale)); margin-bottom: calc(20px * var(--content-scale)); }
.totals-card h2 { margin: 0 0 4px; font-size: 1rem; }
.totals-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(calc(200px * var(--content-scale)), 1fr)); gap: 12px; margin-top: 12px; }
.totals-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.totals-item.dao { border-color: rgba(110, 168, 254, 0.35); }
.totals-item.performance { border-color: rgba(87, 201, 154, 0.35); }
.totals-item.consistency { border-color: rgba(244, 162, 97, 0.35); }
.totals-item.budget { border-color: rgba(139, 152, 171, 0.35); }
.totals-item .label { color: var(--muted); font-size: 0.75rem; margin-bottom: 6px; }
.totals-item .eth { font-size: 1.25rem; font-weight: 650; font-family: var(--mono); }
.totals-item .usd { color: var(--muted); font-size: 0.8125rem; margin-top: 4px; }
.totals-item .note { color: var(--muted); font-size: 0.6875rem; margin-top: 8px; line-height: 1.4; }
.totals-bar { display: flex; height: 10px; border-radius: 999px; overflow: hidden; margin-top: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.totals-bar-seg { height: 100%; min-width: 2px; }
.totals-bar-seg.dao { background: var(--accent); }
.totals-bar-seg.performance { background: var(--good); }
.totals-bar-seg.consistency { background: var(--accent-2); }

.charts { display: grid; grid-template-columns: repeat(2, 1fr); gap: calc(16px * var(--content-scale)); margin-bottom: calc(20px * var(--content-scale)); }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: calc(16px * var(--content-scale)); }
.chart-card.wide { grid-column: 1 / -1; }
.chart-card h2 { margin: 0 0 4px; font-size: 1rem; }
.caption { margin: 0 0 12px; color: var(--muted); font-size: 0.75rem; line-height: 1.45; }
.chart-stack { display: flex; flex-direction: column; gap: calc(20px * var(--content-scale)); }
canvas { max-height: calc(280px * var(--content-scale)); }
canvas.chart-tall { max-height: calc(340px * var(--content-scale)); }
.chart-subtitle { margin: 0 0 4px; font-size: 0.875rem; font-weight: 600; color: var(--text); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.table-card { padding: calc(16px * var(--content-scale)); }
.table-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.table-head h2 { margin: 0; font-size: 1rem; }
#search { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 10px 12px; min-width: calc(260px * var(--content-scale)); font-size: 0.875rem; }
.table-wrap { overflow: auto; max-height: 560px; border: 1px solid var(--border); border-radius: 8px; -webkit-overflow-scrolling: touch; }
table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: var(--table-font); }
th, td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 0.68rem; z-index: 1; line-height: 1.25; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
.mono { font-family: var(--mono); font-size: 0.68rem; }
.token-pair { display: inline-block; max-width: 118px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.rank-badge { display: inline-block; min-width: 24px; text-align: center; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.68rem; }
.rank-cell { white-space: nowrap; }
.win-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--good);
  border: 1px solid color-mix(in srgb, var(--good) 55%, transparent);
  background: color-mix(in srgb, var(--good) 12%, transparent);
}
.rank-badge.win { border-color: var(--good); color: var(--good); }
tr.row-win td { background: color-mix(in srgb, var(--good) 6%, transparent); }
.solver-chip { display: inline-flex; align-items: center; gap: 0.35rem; max-width: 108px; }
.solver-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 96px; display: inline-block; vertical-align: bottom; }
.solver-icon { width: 0.95rem; height: 0.95rem; border-radius: 999px; object-fit: cover; flex-shrink: 0; background: var(--surface-2); }
.reward-negative { color: var(--bad); }
.muted-dash { color: var(--muted); }
.reward-cell { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 0.05rem; line-height: 1.15; }
.reward-usd { font-size: 0.62rem; color: var(--muted); font-weight: 500; }
.reward-negative .reward-usd { color: inherit; opacity: 0.85; }
.dune-tag { font-size: 0.58rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 1px 4px; border-radius: 4px; margin-top: 1px; }
.dune-tag.cap { background: rgba(244, 162, 97, 0.2); color: var(--accent-2); }
.dune-tag.floor { background: rgba(231, 111, 111, 0.2); color: var(--bad); }
.dune-tag.ok { background: rgba(87, 201, 154, 0.15); color: var(--good); }
.rank-badge.top { border-color: var(--good); color: var(--good); }
.rank-badge.mid { border-color: var(--accent-2); color: var(--accent-2); }
.rank-badge.low { border-color: var(--bad); color: var(--bad); }
a.tx-link { color: var(--accent); text-decoration: none; }
th.col-hint { cursor: help; border-bottom: 1px dotted var(--muted); }
.metric-hint { cursor: help; border-bottom: 1px dotted var(--muted); }
.surplus-pct { color: var(--good); font-weight: 600; cursor: help; border-bottom: 1px dotted var(--muted); }
.surplus-pct-tight { color: #b8ffe0; }
td.surplus-close {
  background: rgba(87, 201, 154, 0.14);
  box-shadow: inset 0 0 0 1px rgba(87, 201, 154, 0.4);
}
tbody tr:hover td.surplus-close { background: rgba(87, 201, 154, 0.22); }

dialog { border: none; padding: 0; background: transparent; max-width: calc(900px * var(--content-scale)); width: 95vw; }
dialog::backdrop { background: rgba(0,0,0,0.65); }
.dialog-inner { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.close { position: absolute; top: 10px; right: 12px; background: none; border: none; color: var(--muted); font-size: 24px; cursor: pointer; }
#detail-json { margin: 12px 0 0; overflow: auto; max-height: 70vh; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; font-family: var(--mono); font-size: 11px; line-height: 1.45; color: #c9d4e3; }

@media (min-width: 1500px) {
  :root { --layout-max: 1920px; --table-font: 0.75rem; }
  .token-pair { max-width: 140px; }
  .solver-name { max-width: 112px; }
}

@media (max-width: 900px) {
  .charts { grid-template-columns: 1fr; }
  .chart-card.wide { grid-column: auto; }
}
