:root {
  color-scheme: light;
  --ground: #f5f5f7;
  --surface: #fff;
  --raised: #f0f0f3;
  --ink: #1d1d1f;
  --muted: #62626b;
  --rule: #e7e7eb;
  --control: #dadade;
  --accent: #0066cc;
  --positive: #126d4a;
  --negative: #a32c44;
  --chart-1: #0066cc;
  --chart-2: #747481;
  --grid: #ebebef;
  --axis-ink: #62626b;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--ground); font-variant-numeric: tabular-nums; }
h1, h2, p { margin: 0; }
h1, h2, .wordmark { font-weight: 650; letter-spacing: -.045em; }
h1 { font-size: 25px; }
h2 { font-size: 22px; line-height: 1.15; }
button, input, select { font: inherit; }
button, input, select, a { -webkit-tap-highlight-color: transparent; }
button, input, select {
  min-height: 42px;
  border: 1px solid var(--control);
  border-radius: 10px;
  padding: 8px 13px;
  background: var(--surface);
  color: var(--ink);
}
button { cursor: pointer; font-weight: 550; }
button:hover { background: var(--raised); }
button:disabled { cursor: wait; opacity: .6; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.positive { color: var(--positive); }
.negative { color: var(--negative); }
.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.primary:hover { background: #0057b1; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(245,245,247,.94);
  border-bottom: 1px solid var(--rule);
  backdrop-filter: blur(18px);
}
.topbar-inner, main { width: min(1280px, 100%); margin: auto; padding-inline: 36px; }
.topbar-inner { display: flex; gap: 40px; align-items: center; min-height: 66px; }
.topbar nav { display: flex; gap: 25px; align-items: center; color: var(--muted); }
.topbar nav a { display: grid; align-items: center; min-height: 44px; }
.icon-button { display: inline-grid; place-items: center; min-width: 42px; padding: 0; border-color: transparent; background: transparent; }
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; }
#logout { margin-left: auto; }
main { padding-top: 25px; padding-bottom: 48px; }
#overview, #strategies, #ledger { scroll-margin-top: 86px; }
.toolbar { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 22px; }
.field { display: grid; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); }
.field input { width: 150px; }
.field select { width: 132px; }
#run-button { margin-left: auto; min-width: 146px; }
.job { margin: -10px 0 18px; color: var(--muted); }
.job.error, #login-error { color: var(--negative); }
.comparison { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr); gap: 16px; }
.panel, .market {
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background: var(--surface);
}
.panel-heading, .section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}
.panel-heading { margin-bottom: 15px; }
.panel-heading p, .ledger-heading p { margin-top: 6px; font-size: 12px; }
.legend { display: flex; gap: 12px; color: var(--muted); font-size: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-swatch { width: 13px; height: 2px; background: var(--chart-1); }
.legend-swatch.baseline { background: var(--chart-2); }
.chart { width: 100%; position: relative; }
.chart svg, .market-plot svg { display: block; width: 100%; }
.chart.equity { height: 215px; }
.chart.drawdown { height: 146px; }
.replay { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.replay input { flex: 1; min-width: 42px; padding: 0; accent-color: var(--accent); border: 0; }
.replay time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.replay #end { border: 0; padding-inline: 6px; font-size: 12px; }
.compare-head, .score-row { display: grid; grid-template-columns: 1.15fr 1fr 1fr; align-items: baseline; gap: 8px; }
.compare-head { padding: 7px 0 10px; font-size: 12px; color: var(--muted); }
.compare-head > :not(:first-child), .score-row > :not(:first-child) { text-align: right; }
.score-panel { display: flex; flex-direction: column; }
.score-row { flex: 1; align-content: center; border-top: 1px solid var(--rule); padding: 13px 0; }
.score-row > span { color: var(--muted); font-size: 13px; }
.score-row b { font-weight: 550; }
.score-row strong { font-size: clamp(18px, 2vw, 27px); font-weight: 650; letter-spacing: -.045em; }
.section-heading { margin: 27px 0 12px; }
.tabs { display: flex; gap: 3px; padding: 3px; border-radius: 11px; background: #e9e9ed; }
.tabs button { min-height: 36px; border: 0; background: transparent; border-radius: 8px; font-size: 13px; }
.tabs button.active { background: var(--surface);  }
.markets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.market { text-align: left; font-weight: 400; }
.market:hover { background: var(--surface); border-color: var(--control); }
.market.active { border-color: var(--accent); }
.market-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.market-title { font-weight: 700; font-size: 16px; }
.market-price { font-size: 19px; font-weight: 650; letter-spacing: -.035em; }
.market-change { margin-top: 3px; color: var(--muted); font-size: 12px; }
.market-plot { margin-top: 8px; }
.drawdown-panel { margin-top: 16px; }
.ledger-controls { display: flex; gap: 8px; }
.table-wrap { overflow-x: auto; padding-block: 8px; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { text-align: right; padding: 12px 8px; border-bottom: 1px solid var(--rule); }
th { font-size: 12px; color: var(--muted); font-weight: 500; }
td { font-size: 13px; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
tbody tr:last-child td { border-bottom: 0; }
td small { color: var(--muted); display: block; font-size: 11px; }
#ledger-table :is(th, td):nth-child(2) { text-align: left; }
.empty, .empty-row { padding: 20px 0; color: var(--muted); }
#more { margin-top: 12px; }
.rejections { margin-top: 14px; padding: 6px 0; }
.rejections summary { cursor: pointer; padding: 12px 0; font-size: 13px; }
.rejected-row { display: flex; justify-content: space-between; gap: 8px; padding: 10px 0; border-top: 1px solid var(--rule); }
.login-wrap { min-height: 100svh; display: grid; place-items: center; padding: 22px; }
.login-panel { display: grid; gap: 10px; width: min(100%, 360px); padding: 30px; border-radius: 20px; background: var(--surface); border: 1px solid var(--rule); }
.wordmark { font-size: 30px; margin-bottom: 10px; }
.login-panel input, .login-panel button { width: 100%; min-height: 46px; }
#login-error { font-size: 13px; }
#login-error:empty { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 850px) {
  .topbar-inner, main { padding-inline: 22px; }
  .panel, .market { padding-inline: 15px; }
  .comparison { grid-template-columns: minmax(0, 1.2fr) minmax(250px, 1fr); }
  .market-price { font-size: 16px; }
}
@media (max-width: 640px) {
  .topbar-inner, main { padding-inline: 16px; }
  .topbar-inner { gap: 10px; min-height: 57px; }
  h1 { font-size: 22px; }
  h2 { font-size: 20px; }
  .topbar nav { gap: 11px; font-size: 12px; }
  #logout { min-width: 34px; }
  main { padding-top: 16px; }
  .toolbar { display: grid; grid-template-columns: 1fr 1.1fr auto; gap: 9px; margin-bottom: 14px; }
  .field { min-width: 0; }
  .field input, .field select { width: 100%; font-size: 16px; }
  #run-button { margin-left: 0; grid-column: 1 / -1; }
  button, input, select { min-height: 44px; }
  .comparison, .markets { grid-template-columns: 1fr; gap: 10px; }
  .panel, .market { border-radius: 15px; padding: 15px; }
  .panel-heading { margin-bottom: 12px; }
  .chart.equity { height: 177px; }
  .chart.drawdown { height: 126px; }
  .legend { font-size: 11px; gap: 8px; }
  .replay { flex-wrap: wrap; gap: 6px; }
  .replay input { flex-basis: 70%; }
  .replay time { margin-left: 5px; }
  .replay #end { margin-left: auto; }
  .score-row { flex: initial; }
  .score-row strong { font-size: 23px; }
  .score-row:last-child { padding-bottom: 4px; }
  .section-heading { margin-top: 22px; }
  .tabs button { min-height: 38px; padding-inline: 9px; font-size: 12px; }
  .market-price { font-size: 20px; }
  #ledger-table :is(th, td):nth-child(n+3):not(:nth-child(8)) { display: none; }
  th, td { padding-inline: 5px; }
  #strategies-table th, #strategies-table td { font-size: 12px; }
  #strategies-period { font-size: 12px; }
  .login-panel input { font-size: 16px; }
}
.market-title small { margin-left: 6px; color: var(--muted); font-size: 11px; font-weight: 400; }
