:root {
  color-scheme: light;
  --surface-1:      #fffdf8;
  --page-plane:     #f5f0e6;
  --text-primary:   #1b1815;
  --text-secondary: #5c5449;
  --text-muted:     #948c7e;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(27,24,21,0.10);
  --success-text:   #006300;
  --critical-text:  #d03b3b;

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */

  --diverging-pos: #2a78d6; /* blue */
  --diverging-neg: #e34948; /* red */
  --diverging-mid: #f0efec;

  --accent: var(--series-1);
  --accent-contrast: #ffffff;

  --font-display: "Fraunces", Georgia, "Iowan Old Style", serif;
  --font-body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --shadow-card: 0 1px 2px rgba(27,24,21,0.05), 0 10px 28px -14px rgba(27,24,21,0.22);
  --shadow-card-hover: 0 1px 2px rgba(27,24,21,0.06), 0 16px 36px -16px rgba(27,24,21,0.28);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1:      #1f1c18;
    --page-plane:     #131110;
    --text-primary:   #f3eee4;
    --text-secondary: #c4bcae;
    --text-muted:     #8c867d;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(243,238,228,0.10);
    --success-text:   #0ca30c;
    --critical-text:  #e66767;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --diverging-pos: #3987e5;
    --diverging-neg: #e66767;
    --diverging-mid: #383835;

    --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 10px 28px -14px rgba(0,0,0,0.5);
    --shadow-card-hover: 0 1px 2px rgba(0,0,0,0.35), 0 16px 36px -16px rgba(0,0,0,0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1f1c18;
  --page-plane:     #131110;
  --text-primary:   #f3eee4;
  --text-secondary: #c4bcae;
  --text-muted:     #8c867d;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(243,238,228,0.10);
  --success-text:   #0ca30c;
  --critical-text:  #e66767;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --diverging-pos: #3987e5;
  --diverging-neg: #e66767;
  --diverging-mid: #383835;

  --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 10px 28px -14px rgba(0,0,0,0.5);
  --shadow-card-hover: 0 1px 2px rgba(0,0,0,0.35), 0 16px 36px -16px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: var(--font-body);
}

body {
  background-image: radial-gradient(ellipse 900px 500px at 15% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent);
  background-repeat: no-repeat;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
  flex-wrap: wrap;
}

.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: linear-gradient(90deg, var(--series-1), var(--series-3) 35%, var(--series-4) 65%, var(--series-5));
  opacity: 0.85;
}

.topbar h1 {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--text-primary);
}

.home-link {
  color: inherit;
  text-decoration: none;
}

.home-link:hover { opacity: 0.75; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

nav.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

nav.tabs a {
  padding: 8px 16px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

nav.tabs a:hover { background: var(--gridline); }

nav.tabs a.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

nav.tabs a.active:hover { background: var(--accent); }

main#view-root {
  flex: 1;
  padding: 28px 24px 48px;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:hover { background: var(--gridline); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 4px 14px -6px color-mix(in srgb, var(--accent) 60%, transparent);
}

.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px 24px;
  box-shadow: var(--shadow-card);
  animation: fadeInUp 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
}

main#view-root > .card:nth-of-type(1) { animation-delay: 0s; }
main#view-root > .card:nth-of-type(2) { animation-delay: 0.05s; }
main#view-root > .card:nth-of-type(3) { animation-delay: 0.1s; }
main#view-root > .card:nth-of-type(4) { animation-delay: 0.15s; }
main#view-root > .card:nth-of-type(5) { animation-delay: 0.2s; }

.card h2 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 9px;
}

.card h2::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
  flex-shrink: 0;
}

.subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 0 0 14px;
  line-height: 1.5;
}

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--page-plane);
  border-radius: 999px;
  margin-bottom: 14px;
}

.segmented button {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.segmented button:hover { background: var(--gridline); }

.segmented button.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

.segmented button.active:hover { background: var(--accent); }

.hero-figure {
  font-family: var(--font-display);
  font-size: clamp(38px, 6vw, 56px);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  margin: 0;
}

.hero-delta {
  font-size: 13px;
  font-weight: 500;
  margin-top: 6px;
}

.hero-delta.up { color: var(--success-text); }
.hero-delta.down { color: var(--critical-text); }

.chart-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.link-btn {
  font: inherit;
  font-size: 12px;
  color: var(--text-secondary);
  background: none;
  border: none;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  padding: 0;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

.legend-item { display: flex; align-items: center; gap: 6px; }

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data-table th,
table.data-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}

table.data-table th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

table.data-table tbody tr {
  transition: background-color 0.12s ease;
}

table.data-table tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

table.data-table td.num,
table.data-table th.num { text-align: right; }

.table-scroll { overflow-x: auto; }

.empty-state {
  color: var(--text-muted);
  font-size: 14px;
  font-family: var(--font-display);
  font-style: italic;
  padding: 28px 0;
  text-align: center;
}

.signin-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.signin-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 700px 500px at 20% 20%, color-mix(in srgb, var(--series-1) 14%, transparent), transparent),
    radial-gradient(ellipse 600px 500px at 85% 80%, color-mix(in srgb, var(--series-5) 10%, transparent), transparent);
  pointer-events: none;
}

.signin-mark {
  width: 40px;
  height: 40px;
  margin: 0 auto 18px;
}

.signin-card {
  position: relative;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 40px 36px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-card-hover);
  animation: fadeInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.signin-card h1 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}

.signin-card p {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin: 0 0 24px;
  line-height: 1.5;
}

.status-banner {
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.status-banner.error { color: var(--critical-text); }

svg.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
svg.chart-svg text { fill: var(--text-muted); font-size: 11px; font-family: var(--font-body); }
svg.chart-svg .value-label { fill: var(--text-primary); font-weight: 600; }
svg.chart-svg .gridline { stroke: var(--gridline); stroke-width: 1; }
svg.chart-svg .baseline { stroke: var(--baseline); stroke-width: 1; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface-1);
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 8px;
  white-space: nowrap;
  transform: translate(-50%, -100%);
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 10;
}

.chart-wrap { position: relative; }
