:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --border: #e4e4e0;
  --text: #1c1c1a;
  --text-muted: #5c5c57;
  --accent: #0f766e;
  --on-accent: #ffffff;
  --accent-soft: #8cc9c3;
  --bar-muted: #b4b4ac;
  --bar-muted-soft: #d9d9d3;
  --goal-line: #b45309;
  --avg-line: #1c1c1a;
  --rolling-line: #1d4ed8;
  --grid-line: #ececea;
  --up: #0f766e;
  --down: #b42318;
  --radius: 12px;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

h1 {
  margin: 0;
  font-size: 1.6rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.status {
  margin: 4px 0 20px;
  color: var(--text-muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}

.message {
  padding: 32px 16px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.message p { margin: 0 0 12px; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

#retry {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 12px;
}

.views {
  display: inline-flex;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.views button {
  min-width: 64px;
  padding: 6px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
}
.views button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.navigator {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.navigator h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.navigator button {
  width: 36px;
  height: 36px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 1.3rem;
  line-height: 1;
}
.navigator button:disabled {
  cursor: default;
  opacity: 0.35;
}

.today-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
.today-link:hover { text-decoration: underline; }
.today-link[hidden] { display: none; }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 4px 0;
}
.chart {
  width: 100%;
  height: 280px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  margin: 16px 0 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
/* Dividers drawn as shadows; the container clips the ones on its outer edges. */
.stats > div {
  padding: 12px 14px;
  box-shadow: 1px 0 0 var(--border), 0 1px 0 var(--border);
}
.stats dt {
  color: var(--text-muted);
  font-size: 0.8rem;
}
.stats dd {
  margin: 2px 0 0;
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stats .note {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 400;
}
.stats .up { color: var(--up); }
.stats .down { color: var(--down); }
.stats .empty {
  grid-column: 1 / -1;
  color: var(--text-muted);
}

footer {
  margin-top: 28px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 480px) {
  h1 { font-size: 1.35rem; }
  .navigator { order: 3; flex-basis: 100%; }
  .chart { height: 240px; }
}

/* ---------- Milestone 3: banner, year legend, secondary chart, records ---------- */

:root {
  --heat-0: #dceee9;
  --heat-1: #9fd2c8;
  --heat-2: #4fa89c;
  --heat-3: #1b7f74;
  --heat-4: #0b4f48;
  --heat-missing: #c9c9c2;
  --heat-progress: #f1e3c4;
  --stale-bg: #fff4e5;
  --stale-border: #f2c98a;
  --stale-text: #7a4100;
}

.stale {
  margin: -8px 0 16px;
  padding: 10px 14px;
  background: var(--stale-bg);
  border: 1px solid var(--stale-border);
  border-radius: 10px;
  color: var(--stale-text);
  font-size: 0.9rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 4px 12px 12px;
  color: var(--text-muted);
  font-size: 0.75rem;
}
.legend span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.legend i {
  width: 11px;
  height: 11px;
  border-radius: 2px;
}

.secondary {
  margin-top: 16px;
  padding-top: 12px;
}
.card-title,
.section-title {
  margin: 0 0 4px;
  font-size: 0.95rem;
  font-weight: 600;
}
.card-title { padding: 0 12px; }
.chart-small { height: 220px; }

.records-section { margin-top: 28px; }
.records { margin-top: 8px; }
.records a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 2px;
}
.records a:hover { text-decoration-color: currentColor; }

/* ---------- Dark theme ---------- */

/* Set on <html> by the inline script in index.html: the visitor's choice, else the system setting. */
:root[data-theme="dark"] {
  --bg: #111413;
  --surface: #1a1e1d;
  --border: #2e3432;
  --text: #eceeed;
  --text-muted: #a4aba8;
  --accent: #3cc2b3;
  --on-accent: #06211e;
  --accent-soft: #24625b;
  --bar-muted: #5d6461;
  --bar-muted-soft: #383e3c;
  --goal-line: #f5a54a;
  --avg-line: #eceeed;
  --rolling-line: #8cb4ff;
  --grid-line: #262b29;
  --up: #4fd6c6;
  --down: #ff8a7d;
  --heat-0: #1e3532;
  --heat-1: #1e5c54;
  --heat-2: #24877b;
  --heat-3: #3db8a9;
  --heat-4: #94efe2;
  --heat-missing: #4b514e;
  --heat-progress: #5e4b22;
  --stale-bg: #33240d;
  --stale-border: #6b4a17;
  --stale-text: #ffd59a;
  color-scheme: dark;
}

/* ---------- Keyboard focus ---------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Theme switch ---------- */

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.theme-toggle {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* Show the theme you'd switch to: a moon in light mode, a sun in dark mode. */
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }

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

.home-link {
  color: inherit;
  text-decoration: none;
}
.status a,
footer a,
.prose a {
  color: var(--accent);
}
.prose {
  max-width: 62ch;
  margin-top: 8px;
}
.prose h2 {
  margin: 28px 0 8px;
  font-size: 1.15rem;
}
.prose h2:first-child { margin-top: 8px; }
.prose p { margin: 0 0 14px; }
