:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --warning: #fab219;
  --critical: #d03b3b;
  --wash: rgba(11, 11, 11, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --wash: rgba(255, 255, 255, 0.05);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --wash: rgba(255, 255, 255, 0.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* the page colour fills the whole window, edge to edge */
html { background: var(--page); }
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--page); min-height: 100vh; }

.viz-root {
  color: var(--text-primary);
  padding: 20px clamp(12px, 3vw, 32px) 32px;
  max-width: 1180px;
  margin: 0 auto;
  font-size: 14px;
  line-height: 1.4;
}

.top { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; margin-bottom: 14px; }
h1 { font-size: 20px; font-weight: 600; margin: 0; }
h2 { font-size: 14px; font-weight: 600; margin: 0 0 10px; }
.asof { margin: 0; color: var(--text-secondary); font-size: 13px; }
.asof .flag { color: var(--text-primary); font-weight: 600; }
.asof .flag::before { content: "▲ "; color: var(--warning); }

.banner {
  border: 1px solid var(--border);
  border-left: 4px solid var(--warning);
  background: var(--surface-1);
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 14px;
  color: var(--text-primary);
}
.banner.critical { border-left-color: var(--critical); }
.banner strong { font-weight: 600; }

.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
@media (max-width: 640px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.tile-label { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-value { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.tile-sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.key { display: inline-flex; align-items: center; gap: 6px; }
.k-fut { stroke: var(--series-1); stroke-width: 2; }
.k-fut-dot { fill: var(--series-1); }
.k-prev { stroke: var(--series-2); stroke-width: 2; stroke-dasharray: 4 3; }
.k-prev-dot { fill: var(--series-2); }
.k-idx { stroke: var(--series-3); stroke-width: 2; stroke-dasharray: 1 3; stroke-linecap: round; }
.k-idx-dot { fill: var(--series-3); }

.chart-wrap { position: relative; }
#chart { display: block; width: 100%; height: 400px; touch-action: pan-y; }
@media (max-width: 600px) { #chart { height: 320px; } }

#chart .grid { stroke: var(--grid); stroke-width: 1; }
#chart .baseline { stroke: var(--axis); stroke-width: 1; }
#chart .tick { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
#chart .tick-strong { fill: var(--text-secondary); font-size: 11px; }
#chart .axis-title { fill: var(--text-muted); font-size: 11px; }
#chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
#chart .s1 { stroke: var(--series-1); }
#chart .s2 { stroke: var(--series-2); stroke-dasharray: 5 4; }
#chart .s3 { stroke: var(--series-3); stroke-dasharray: 1 4; }
#chart .dot { stroke: var(--surface-1); stroke-width: 2; }
#chart .d1 { fill: var(--series-1); }
#chart .d2 { fill: var(--series-2); }
#chart .d3 { fill: var(--series-3); }
#chart .end-label { fill: var(--text-secondary); font-size: 12px; }
#chart .end-value { fill: var(--text-primary); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
#chart .crosshair { stroke: var(--text-muted); stroke-width: 1; }
#chart .focus { stroke: var(--surface-1); stroke-width: 2; }
#chart .hit { fill: transparent; cursor: crosshair; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 8px 10px;
  font-size: 12px;
  min-width: 170px;
  z-index: 2;
}
.tooltip .tt-head { font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.tooltip .tt-sub { color: var(--text-muted); margin-bottom: 6px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.tooltip .tt-row b { margin-left: auto; color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.sw { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.sw1 { background: var(--series-1); }
.sw2 { background: var(--series-2); }
.sw3 { background: var(--series-3); }

.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th { font-weight: 600; color: var(--text-secondary); font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.muted { color: var(--text-muted); }
tbody tr:hover { background: var(--wash); }
tbody tr:last-child td { border-bottom: none; }
td .pill { font-size: 11px; color: var(--text-primary); }
td .pill::before { content: "▲ "; color: var(--warning); }

.foot { color: var(--text-muted); font-size: 12px; margin-top: 6px; }
.foot p { margin: 0 0 4px; }
.key[hidden] { display: none; }

.contango { margin-top: 10px; border-top: 1px solid var(--grid); padding-top: 4px; }
#contango-table th, #contango-table td { padding: 6px 10px; }
#contango-table thead th { vertical-align: bottom; }
#contango-table .sub { display: block; font-weight: 400; color: var(--text-muted); font-size: 11px; }
#contango-table th[scope="row"] { color: var(--text-secondary); font-weight: 600; font-size: 12px; position: sticky; left: 0; background: var(--surface-1); }
#contango-table tbody tr:hover { background: transparent; }
#contango-table tbody tr:last-child th { border-bottom: none; }

.k-spot { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 6 4; }
#chart .spot { stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 8 5; }
#chart .spot-label { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums;
  paint-order: stroke; stroke: var(--surface-1); stroke-width: 3px; stroke-linejoin: round; }
#chart .pt-label { fill: var(--text-secondary); font-size: 10.5px; font-weight: 600; font-variant-numeric: tabular-nums;
  paint-order: stroke; stroke: var(--surface-1); stroke-width: 3px; stroke-linejoin: round; }

.history-ctl { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); }
.history-ctl input[type="date"], .history-ctl button {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px;
}
.history-ctl button { cursor: pointer; }
.history-ctl button:hover { background: var(--wash); }
.asof strong { color: var(--text-primary); font-weight: 600; }
@media (max-width: 600px) { .history-ctl { margin-left: 0; width: 100%; } }

.theme-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.theme-toggle button { font: inherit; font-size: 13px; color: var(--text-secondary); background: var(--surface-1); border: 0; padding: 5px 10px; cursor: pointer; }
.theme-toggle button + button { border-left: 1px solid var(--border); }
.theme-toggle button:hover { background: var(--wash); }
.theme-toggle button[aria-pressed="true"] { color: var(--text-primary); font-weight: 600; background: var(--wash); }
