/* 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 */
  --series-2: #eb6834;   /* orange */
  --context: #52514e;    /* HSI context line */
  --up: #006300;
  --down: #c62f2f;
}
@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;
    --context: #c3c2b7;
    --up: #0ca30c;
    --down: #e66767;
  }
}
: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;
  --context: #c3c2b7;
  --up: #0ca30c;
  --down: #e66767;
}

* { 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 { 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: 22px; }
h1 { font-size: 26px; line-height: 1.25; margin: 0; font-weight: 650; letter-spacing: 0.01em; }
.subtitle { margin: 2px 0 0; color: var(--ink-2); }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.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: 28px; font-weight: 600; line-height: 1.25; margin-top: 4px; white-space: nowrap; overflow-wrap: normal; }
.tile-pair { font-size: 22px; line-height: 1.6; }
.tile-pair .sep { color: var(--muted); font-weight: 400; margin: 0 6px; }
.tile-pair small { font-size: 12px; color: var(--ink-2); font-weight: 400; margin-right: 4px; }
.tile-note { font-size: 13px; color: var(--muted); margin-top: 2px; }
.delta-up { color: var(--up); }
.delta-down { color: var(--down); }

/* Range selector: one row, scopes every chart below */
.ranges { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; max-width: 100%; overflow-x: auto; }
.segmented button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; cursor: pointer;
  color: var(--ink-2); font-size: 14px; white-space: nowrap;
}
.segmented button:hover { background: var(--hover); }
.segmented button[aria-checked="true"] { background: var(--ink); color: var(--surface); font-weight: 600; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }

/* Chart cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 18px 10px; margin-bottom: 18px; }
.card-head h2 { font-size: 18px; line-height: 1.35; margin: 0; font-weight: 620; }
.card-head h2 span { font-weight: 450; color: var(--ink-2); font-size: 15px; margin-left: 6px; }
.card-desc { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 18px; margin: 12px 0 8px; font-size: 13px; min-height: 22px; }
.legend .date { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.legend .item { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.legend .key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; transform: translateY(-4px); }
.legend .value { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.legend .name { color: var(--ink-2); }
.chart { height: 460px; position: relative; }


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

.error { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; color: var(--ink-2); }

@media (max-width: 860px) {
  .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: 22px; }
  .tile-pair { font-size: 17px; }
  .card { padding: 14px 12px 6px; border-radius: 12px; }
  .card-head h2 span { display: block; margin-left: 0; }
  .chart { height: 380px; }
  .hint { display: none; }
}
