:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

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

  --critical: #d03b3b;
  --row-highlight: rgba(42, 120, 214, 0.12);
  --row-highlight-soft: rgba(42, 120, 214, 0.06);
}

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

    --series-1: #3987e5;
    --series-2: #199e70;
    --series-3: #c98500;
    --series-4: #008300;
    --series-5: #9085e9;
    --series-6: #e66767;
    --series-7: #d55181;
    --series-8: #d95926;
    --row-highlight: rgba(57, 135, 229, 0.18);
    --row-highlight-soft: rgba(57, 135, 229, 0.09);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page-plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);

  --series-1: #3987e5;
  --series-2: #199e70;
  --series-3: #c98500;
  --series-4: #008300;
  --series-5: #9085e9;
  --series-6: #e66767;
  --series-7: #d55181;
  --series-8: #d95926;
  --row-highlight: rgba(57, 135, 229, 0.18);
  --row-highlight-soft: rgba(57, 135, 229, 0.09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.page {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.page-header h1 {
  font-size: 26px;
  margin: 0 0 4px;
}
.subtitle {
  color: var(--text-secondary);
  margin: 0 0 24px;
  font-size: 14px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  min-width: 130px;
}
.field-grow { flex: 1; }
.field em { color: var(--text-muted); font-style: normal; }
.field input {
  font: inherit;
  font-size: 14px;
  padding: 7px 9px;
  border: 1px solid var(--axis);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
}
.field input:focus {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}

.submit-btn {
  background: var(--text-primary);
  color: var(--surface-1);
  border: none;
  border-radius: 6px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.submit-btn:hover { opacity: 0.9; }

.status {
  min-height: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  margin: 12px 2px;
}
.status.is-error { color: var(--critical); }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-top: 8px;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}
.card-head h2 {
  font-size: 16px;
  margin: 0;
}
.link-btn {
  background: none;
  border: none;
  color: var(--series-1);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.chart-controls {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.chart-mode {
  display: flex;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.chart-mode button {
  border: none;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
}
.chart-mode button.is-active {
  background: var(--series-1);
  color: #fff;
}
.chart-mode button:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: -2px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 8px;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.legend-item:hover { border-color: var(--border); }
.legend-item:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }
.legend-item.is-off { opacity: 0.35; }
.legend-item.is-off span:last-child { text-decoration: line-through; }
.legend-item svg { display: block; }

.chart-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 60px 0;
}

#map {
  height: 380px;
  border-radius: 8px;
  margin-top: 12px;
  z-index: 0;
}
.map-note {
  font-size: 12px;
  color: var(--text-muted);
  margin: 6px 2px 0;
}
.map-popup { font-size: 12px; line-height: 1.5; }
.map-popup-type { color: #52514e; margin-bottom: 2px; }

.chart-wrap {
  position: relative;
  overflow-x: auto;
}
#chart-mount svg { display: block; touch-action: none; }

.chart-zoom {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface-1);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.chart-zoom button {
  width: 28px;
  height: 26px;
  border: none;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.chart-zoom button + button {
  border-top: 1px solid var(--gridline);
}
.chart-zoom button:hover {
  background: var(--row-highlight-soft);
  color: var(--text-primary);
}
.chart-zoom button:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: -2px;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface-1);
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  line-height: 1.5;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  z-index: 5;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.tooltip .t-value { font-weight: 700; }
.tooltip .t-row { display: flex; align-items: center; gap: 6px; }
.tooltip .t-key {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}

.table-wrap {
  margin-top: 16px;
  max-height: 360px;
  overflow: auto;
  border-top: 1px solid var(--gridline);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
  white-space: nowrap;
}
th {
  color: var(--text-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--surface-1);
  z-index: 1;
}
td.num { font-variant-numeric: tabular-nums; }
tbody tr.is-hover td {
  background: var(--row-highlight);
}
tbody tr.is-related td {
  background: var(--row-highlight-soft);
}
tbody tr.is-outlier td {
  color: var(--text-muted);
  opacity: 0.75;
}

.footnote {
  font-size: 12px;
  color: var(--text-muted);
  margin: 8px 2px 0;
}

@media (max-width: 640px) {
  .filter-row { flex-direction: column; align-items: stretch; }
  .submit-btn { width: 100%; }
}

.partners {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.partners-lede {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-secondary);
}
.partners-note {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: 6px;
}
.partners-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.partner-btn {
  display: block;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-primary);
  background: var(--surface-1);
  transition: border-color 120ms ease, transform 120ms ease;
}
.partner-btn:hover {
  border-color: var(--series-1);
  transform: translateY(-1px);
}
.partner-title {
  display: block;
  font-weight: 600;
  font-size: 14px;
}
.partner-sub {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.site-footer {
  margin-top: 48px;
  padding: 20px 2px 32px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.55;
}
.site-footer .support { color: var(--text-secondary); font-size: 13px; }
.bmac-btn {
  display: inline-block;
  margin-left: 6px;
  padding: 4px 10px;
  background: #ffdd00;
  color: #0b0b0b !important;
  text-decoration: none;
  border-radius: 6px;
  font-weight: 600;
}
.bmac-btn:hover { background: #ffe633; }

.terms h2 { font-size: 15px; margin: 20px 0 6px; }
.terms h2:first-of-type { margin-top: 0; }
.terms p, .terms ul { color: var(--text-secondary); font-size: 14px; line-height: 1.55; }
.terms ul { padding-left: 20px; }
.terms a { color: var(--series-1); }
.site-footer p { margin: 0 0 10px; }
.site-footer a { color: var(--text-secondary); }
.site-footer .disclaimer { font-style: italic; }
.site-footer .privacy summary {
  cursor: pointer;
  color: var(--text-secondary);
  margin-top: 4px;
}
.site-footer .privacy p { margin-top: 8px; }
