:root {
  color-scheme: dark;
  --bg: #211032;
  --panel: #2c1746;
  --panel-alt: #381B5D;
  --border: #644174;
  --accent: #8E3F90;
  --secondary: #c78dca;
  --brand-dark: #381B5D;
  --chart-primary: #ff80c8;
  --chart-secondary: #55e0ef;
  --text: #faf2fc;
  --muted: #c4afcf;
  --grid: #c4afcf1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(ellipse at 80% 0%, #8E3F9026, transparent 55%), var(--bg);
  color: var(--text);
}

button, select {
  font: inherit;
}

button, select, .range-handle {
  outline-offset: 4px;
}

:focus-visible {
  outline: 2px solid var(--secondary);
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 36px 28px;
}

.header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.brand {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--brand-dark));
  box-shadow: 0 6px 28px #8E3F9033;
  font-size: 17px;
  font-weight: 850;
  letter-spacing: -1px;
  color: white;
}

h1 {
  font-size: clamp(24px, 3vw, 32px);
  letter-spacing: -1px;
  margin: 0;
  font-weight: 750;
}

h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -.4px;
}

#datasetLabel {
  color: var(--secondary);
  margin: 10px 0 0;
}

.view-switch {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 5px;
  border: 1px solid var(--border);
  background: #381B5D66;
  border-radius: 13px;
  margin-bottom: 24px;
}

.view-tab {
  border: 0;
  border-radius: 9px;
  padding: 10px 20px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 650;
  transition: background .15s, color .15s;
}

.view-tab:hover {
  color: var(--text);
  background: var(--panel-alt);
}

.view-tab.active {
  background: linear-gradient(115deg, var(--accent), var(--brand-dark));
  color: white;
  box-shadow: 0 3px 10px #21103240;
}

.scope-row, .filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
}

.scope-row label, .filters label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
}

select {
  width: 100%;
  min-width: 0;
  padding: 11px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  cursor: pointer;
}

select:hover {
  border-color: var(--accent);
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin: 20px 0;
}

.card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(125deg, var(--brand-dark), var(--panel));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 22px;
  width: 32px;
  height: 3px;
  background: var(--accent);
  border-radius: 0 0 4px 4px;
}

.card:nth-child(2)::before {
  background: var(--secondary);
}

.card small {
  display: block;
  color: var(--muted);
  margin-bottom: 12px;
  font-size: 12px;
}

.card .value {
  font-size: clamp(23px, 2.7vw, 34px);
  font-weight: 750;
  letter-spacing: -.8px;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.card:first-child .value {
  color: var(--chart-primary);
}

.card:nth-child(2) .value {
  color: var(--chart-secondary);
}

.chart-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
}

.comparison-chart {
  margin-top: 20px;
}

.plot {
  position: relative;
  height: clamp(300px, 32vw, 390px);
}

.detail-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  margin-top: 20px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 18px;
  font-size: 14px;
}

th, td {
  text-align: left;
  padding: 14px 12px;
  border-bottom: 1px solid #64417480;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

td {
  line-height: 1.5;
  overflow-wrap: anywhere;
}

td:nth-child(3), td:nth-child(4) {
  white-space: nowrap;
}

tbody tr:hover {
  background: #8E3F9012;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
}

.pagination button, .range-caption button {
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 12px;
  cursor: pointer;
}

.pagination button:hover:not(:disabled), .range-caption button:hover {
  border-color: var(--accent);
  background: var(--brand-dark);
}

.pagination button:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.hover-readout {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
  min-height: 24px;
  margin: 18px 0 0;
  font-size: 13px;
  line-height: 1.7;
  font-variant-numeric: tabular-nums;
}

.navigator {
  position: relative;
  height: 18px;
  margin: 18px 8px 8px;
  background: var(--panel-alt);
  border-radius: 4px;
  touch-action: none;
}

.range-selection {
  position: absolute;
  top: 0;
  bottom: 0;
  border: 1px solid #c78dca99;
  background: linear-gradient(90deg, #8E3F9040, #381B5D66);
  cursor: grab;
}

.range-selection:active {
  cursor: grabbing;
}

.range-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 10px;
  margin-left: -5px;
  border: 2px solid var(--panel);
  border-radius: 3px;
  background: var(--accent);
  cursor: ew-resize;
  touch-action: none;
}

.range-handle:last-child {
  background: var(--secondary);
}

.range-caption {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.range-caption button {
  font-size: 11px;
  padding: 3px 8px;
}

@media (max-width: 700px) {
  .container {
    padding: 22px 14px;
  }
  .header {
    gap: 12px;
    margin-bottom: 22px;
  }
  .brand {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    font-size: 15px;
  }
  .scope-row, .filters {
    gap: 12px;
    padding: 14px;
  }
  .cards {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .card {
    padding: 18px;
  }
  .card small {
    margin-bottom: 8px;
  }
  .chart-wrap, .detail-panel {
    padding: 14px;
  }
  .view-tab {
    padding: 10px 14px;
    font-size: 13px;
  }
  .pagination {
    gap: 8px;
    font-size: 12px;
  }
  .pagination button {
    padding: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

[hidden] {
  display: none !important;
}
