/* Palette roles. Light and dark are both selected sets, not an auto-flip.
   Dark values are declared under the media query (OS setting) and under
   [data-theme] (explicit toggle), so the toggle wins in both directions. */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;      /* trend line -- the one hue that carries meaning */
  --deemphasis: #898781;  /* raw weigh-ins -- deliberately neutral */
  --hover-wash: rgba(11, 11, 11, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --deemphasis: #898781;
    --hover-wash: rgba(255, 255, 255, 0.06);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --deemphasis: #898781;
  --hover-wash: rgba(255, 255, 255, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 24px 20px 64px;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1000px; margin: 0 auto; }

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 28px;
}

h1 { font-size: 19px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.updated { font-size: 13px; color: var(--text-muted); }

/* --- Hero figure: exactly one per view --- */
.hero { margin-bottom: 28px; }
.hero-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.hero-value {
  font-size: 56px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.025em;
  /* Proportional figures: tabular-nums looks loose at display sizes. */
}
.hero-value .unit {
  font-size: 24px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: 4px;
}
.hero-sub { font-size: 13px; color: var(--text-muted); margin-top: 6px; }

/* --- Stat tiles --- */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.tile-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.tile-value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.tile-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* --- Chart card --- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 18px 12px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.card-title { font-size: 15px; font-weight: 600; }

.head-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Icon button (fullscreen toggle). */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { background: var(--hover-wash); color: var(--text-primary); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn .ic-compress { display: none; }
.icon-btn.is-on .ic-expand { display: none; }
.icon-btn.is-on .ic-compress { display: inline; }

/* Fullscreen overlay: a fixed layer filling the viewport. Works everywhere;
   native fullscreen + landscape are requested on top where supported. */
body.fs-lock { overflow: hidden; }
.card.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  margin: 0;
  border: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--surface-1);
}
.card.is-fullscreen .chart-box { flex: 1 1 auto; height: auto; min-height: 0; }
.card.is-fullscreen .table-toggle { display: none; } /* keep the fullscreen view to the chart */

/* Filters in one row above the chart. */
.filters { display: flex; gap: 2px; flex-wrap: wrap; }
.filters button {
  font: inherit;
  font-size: 13px;
  padding: 5px 11px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
}
.filters button:hover { background: var(--hover-wash); }
.filters button[aria-pressed="true"] {
  background: var(--hover-wash);
  border-color: var(--border);
  color: var(--text-primary);
  font-weight: 600;
}
.filters button:focus-visible,
.linkish:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Legend: always present for two or more series --- */
.legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin: 10px 0 14px;
  font-size: 13px;
  color: var(--text-secondary); /* text never wears the series color */
}
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.key-line {
  width: 18px;
  height: 2px;
  border-radius: 1px;
  background: var(--accent);
}
.key-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--deemphasis);
}

.chart-box { position: relative; height: 380px; }

/* One finger scrolls the page; two-finger pinch is delivered to our zoom
   handler (which preventDefaults only on the two-pointer gesture). Without
   this, dragging on the tall mobile chart would trap the page scroll. */
#chart { touch-action: pan-y; }

/* --- Chart controls row (zoom hint + reset) --- */
.chart-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  min-height: 22px;
}
.zoom-hint { font-size: 12px; color: var(--text-muted); }
#zoomReset { margin-left: auto; }

@media (max-width: 560px) {
  /* The gesture varies by device; keep the hint short on narrow screens. */
  .zoom-hint { font-size: 11px; }
}

/* --- Table view: the non-visual path to the same numbers --- */
.table-toggle { margin-top: 14px; }
.linkish {
  font: inherit;
  font-size: 13px;
  background: none;
  border: 0;
  padding: 4px 0;
  color: var(--text-secondary);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.table-scroll { max-height: 340px; overflow: auto; margin-top: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
th {
  position: sticky;
  top: 0;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-weight: 600;
}
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.msg {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  color: var(--text-secondary);
}
.msg code {
  font-size: 13px;
  background: var(--hover-wash);
  padding: 1px 5px;
  border-radius: 4px;
}
[hidden] { display: none !important; }

@media (max-width: 560px) {
  .hero-value { font-size: 44px; }
  .chart-box { height: 300px; }
}
