/* The macro page. Dark is its own idiom and what it uses when opened directly;
   the dashboard links here with ?theme=, and the light palette borrows that
   dashboard's warm tokens so the two read as one site. */

:root {
  --bg: #0a0a0b;
  --panel: #101013;
  --ink: #ffffff;
  --body: #b4b4b8;
  --muted: #6e6e76;
  --line: #232326;
  --line-soft: #17171a;
  --chip: #141417;
  --accent: #4a8bf0;
  --up: #3fbf7f;
  --down: #e0574f;

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #efe6d3;
  --panel: #f6efe0;
  --ink: #24211c;
  --body: #4a453b;
  --muted: #726b5c;
  --line: #dccdac;
  --line-soft: #e5d9bc;
  --chip: #e5d9bc;
  --accent: #2f6ecb;
  --up: #1d7a4c;
  --down: #a33229;

  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ---------- top bar ---------- */

.top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}

.back {
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  color: var(--body);
}
.back:hover { color: var(--ink); }

.brand { font-weight: 700; letter-spacing: -0.01em; }

.stamp {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
}

/* Shown when the feed turns out to have been rebuilt while the page was open.
   Brief and quiet: it is there so a number that changed under you reads as new
   data rather than as something you misremembered. */
.stamp.fresh { animation: stamp-fresh 2.4s ease-out 1; }

@keyframes stamp-fresh {
  0%, 60% { color: var(--accent); }
  100% { color: var(--muted); }
}

@media (prefers-reduced-motion: reduce) {
  .stamp.fresh { animation: none; color: var(--accent); }
}

/* ---------- page ---------- */

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 22px 60px;
}

.head h1 {
  margin: 4px 0 6px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.note {
  margin: 0 0 18px;
  max-width: 72ch;
  color: var(--body);
  font-size: 13.5px;
}

/* ---------- controls ---------- */

.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  padding-bottom: 14px;
}

.pick {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.pick select {
  appearance: none;
  background: var(--chip);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 28px 7px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  /* The caret is drawn rather than left to the platform, which would otherwise
     paint a light-mode arrow onto a dark control. */
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 13px center, right 8px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.pick select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.ranges { display: flex; gap: 2px; background: var(--chip); border-radius: 7px; padding: 2px; }

.zoom { display: flex; gap: 2px; background: var(--chip); border-radius: 7px; padding: 2px; }

.zoom button {
  appearance: none;
  background: none;
  border: 0;
  border-radius: 5px;
  width: 28px;
  height: 26px;
  font: inherit;
  font-size: 15px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}
.zoom button:hover { background: var(--line); color: var(--ink); }
.zoom button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.range {
  appearance: none;
  background: none;
  border: 0;
  border-radius: 5px;
  padding: 5px 11px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}
.range:hover:not(:disabled) { color: var(--ink); }
.range.on { background: var(--line); color: var(--ink); }
.range:disabled { opacity: 0.32; cursor: default; }

/* ---------- readout ---------- */

.readout {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.value {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.delta { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--muted); }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }

.over { font-size: 12px; color: var(--muted); }

.when { font-size: 12.5px; color: var(--muted); }

/* ---------- chart ---------- */

.chart-wrap { margin: 0; }

.chart {
  position: relative;   /* the tooltip is positioned against this box */
  height: 460px;
  cursor: grab;
  touch-action: pan-y;
  /* Stops a drag from selecting the axis labels under the cursor. */
  user-select: none;
  -webkit-user-select: none;
}
.chart.grabbing { cursor: grabbing; }

.chart svg { display: block; }

.chart .grid { stroke: var(--line-soft); stroke-width: 1; }
.chart .grid-v { stroke-dasharray: 2 4; }
.chart .zero { stroke: var(--line); stroke-width: 1.5; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { fill: var(--accent); stroke: var(--bg); stroke-width: 1.5; }
/* A pinned point is larger, so it stays findable once the cursor has moved on. */
.chart .marker.is-pinned .dot { r: 5; }
.chart .marker.is-pinned .crosshair { stroke: var(--accent); stroke-dasharray: none; opacity: 0.55; }

/* ---------- the point tooltip ---------- */

.tip {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 6px 9px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: 0 3px 12px rgb(0 0 0 / 0.22);
  /* It follows the cursor, so it must never be what the cursor is over. */
  pointer-events: none;
  white-space: nowrap;
}
.tip.pinned { border-color: var(--accent); }

.tip-value { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tip-when { font-size: 11px; color: var(--muted); }

.chart .axis-y,
.chart .axis-x {
  fill: var(--muted);
  font-family: var(--sans);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.chart .axis-x { text-anchor: middle; }

.chart-foot {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 6px;
  font-size: 11.5px;
  color: var(--muted);
}

.status {
  margin: 14px 0 0;
  padding: 12px 14px;
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--body);
  font-size: 13px;
}

/* ---------- the board of current readings ---------- */

.latest { margin-top: 38px; }

.latest h2 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.latest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

/* A full reset: this is a button so it can be clicked and focused like one,
   but it must not carry any of a button's default chrome. */
.latest-card {
  appearance: none;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: var(--panel);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 13px;
}
.latest-card:hover { background: var(--chip); }
.latest-card:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.latest-label { font-size: 11.5px; color: var(--muted); }
.latest-value { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.latest-when { font-size: 11px; color: var(--muted); }

/* ---------- footer ---------- */

.foot {
  margin-top: 38px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  max-width: 80ch;
}
.foot p { margin: 0 0 8px; }
.foot .thin { color: var(--muted); opacity: 0.85; }

/* ---------- narrow screens ---------- */

@media (max-width: 720px) {
  .page { padding: 18px 14px 44px; }
  .head h1 { font-size: 24px; }
  .controls { gap: 10px; }
  .readout { margin-left: 0; width: 100%; }
  .value { font-size: 26px; }
  .chart { height: 320px; }
}
