/* Colour tokens. Dark values are declared twice: once for the OS setting, once for the toggle. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --hover: rgba(11, 11, 11, 0.05);
  --series-1: #2a78d6;   /* blue: calls, bulls, single series */
  --series-2: #eb6834;   /* orange: puts, bears */
  --up: #2a78d6;         /* diverging: price up */
  --down: #e34948;       /* diverging: price down */
  --mid: #f0efec;        /* diverging midpoint */
  --up-text: #1c5cab;
  --down-text: #b42f2f;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --hover: rgba(255, 255, 255, 0.06);
    --series-1: #3987e5;
    --series-2: #d95926;
    --up: #3987e5;
    --down: #e66767;
    --mid: #383835;
    --up-text: #86b6ef;
    --down-text: #f09a9a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --hover: rgba(255, 255, 255, 0.06);
  --series-1: #3987e5;
  --series-2: #d95926;
  --up: #3987e5;
  --down: #e66767;
  --mid: #383835;
  --up-text: #86b6ef;
  --down-text: #f09a9a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang HK", "Microsoft JhengHei", sans-serif;
}
a { color: inherit; text-underline-offset: 2px; }
button, input { font: inherit; color: inherit; }

.page { max-width: 1240px; margin: 0 auto; padding: 28px 16px 40px; }

/* Header */
.masthead { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
h1 { font-size: 26px; line-height: 1.25; margin: 0; font-weight: 650; }
.subtitle { margin: 2px 0 0; color: var(--ink-2); }

/* Date bar: the one control that scopes everything below */
.datebar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  position: sticky; top: 0; z-index: 5; padding: 10px 0; margin-bottom: 8px;
  background: var(--page);
}
.datebar input[type="date"] {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 15px; font-variant-numeric: tabular-nums; min-height: 38px;
}
.icon-btn, .text-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  min-height: 38px; cursor: pointer; color: var(--ink);
}
.icon-btn { width: 38px; font-size: 20px; line-height: 1; }
.text-btn { padding: 0 12px; font-size: 14px; color: var(--ink-2); }
.icon-btn:hover, .text-btn:hover { background: var(--hover); }
.icon-btn:disabled { opacity: 0.4; cursor: default; }
.note { font-size: 13px; color: var(--muted); }

#content { transition: opacity 0.15s; }
#content[aria-busy="true"] { opacity: 0.45; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 8px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.tile-label { font-size: 13px; color: var(--ink-2); }
.tile-value { font-size: 24px; font-weight: 600; line-height: 1.3; margin-top: 4px; white-space: nowrap; }
.tile-note { font-size: 13px; color: var(--muted); margin-top: 2px; }
.delta-up { color: var(--up-text); }
.delta-down { color: var(--down-text); }

.section-title { font-size: 19px; font-weight: 650; margin: 26px 0 12px; }
.section-title span { font-size: 14px; font-weight: 450; color: var(--muted); margin-left: 8px; }
.missing { background: var(--surface); border: 1px dashed var(--baseline); border-radius: 12px; padding: 18px; color: var(--ink-2); margin-bottom: 16px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 18px 10px; margin-bottom: 16px; min-width: 0; }
.card-head h3 { font-size: 17px; line-height: 1.35; margin: 0; font-weight: 620; }
.card-head h3 span { font-weight: 450; color: var(--ink-2); font-size: 15px; margin-left: 6px; }
.card-desc { margin: 4px 0 10px; font-size: 13px; color: var(--muted); }
h4 { font-size: 14px; margin: 4px 0 6px; font-weight: 600; color: var(--ink-2); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-2 > .card { margin-bottom: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; margin-bottom: 8px; }

.chart { height: 340px; width: 100%; }
.chart-tall { height: 460px; }
.chart-map { height: 560px; }

.scale { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin: -2px 0 8px; font-variant-numeric: tabular-nums; }
.scale-bar { display: inline-block; width: 160px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, var(--down), var(--mid), var(--up)); }

.legend-row { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); margin: -2px 0 6px; }
.legend-row .key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* Tables */
.table-view { margin-top: 8px; border-top: 1px solid var(--grid); }
.table-view summary { cursor: pointer; padding: 10px 0; font-size: 13px; color: var(--ink-2); }
.table-view summary:hover { color: var(--ink); }
.table-wrap { max-height: 320px; overflow: auto; margin-bottom: 10px; }
.table-wrap.plain { max-height: none; }
.table-wrap.scroll { max-height: 520px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 5px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
td.name { white-space: normal; min-width: 90px; }
th { position: sticky; top: 0; background: var(--surface); color: var(--ink-2); font-weight: 500; }
.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

.footer { color: var(--muted); font-size: 13px; margin-top: 26px; }
.footer p { margin: 4px 0; }

@media (max-width: 1000px) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .page { padding-top: 20px; }
  h1 { font-size: 22px; }
  .tile-value { font-size: 20px; }
  .card { padding: 14px 12px 6px; }
  .chart-map { height: 460px; }
  .chart-tall { height: 420px; }
  .card-head h3 span { display: block; margin-left: 0; }
}
