:root {
  --bg: #f7f8f5;
  --surface: #ffffff;
  --surface-alt: #eef4f2;
  --ink: #1c2430;
  --muted: #5d6776;
  --line: #d6ddd9;
  --line-strong: #a9b5af;
  --accent: #117733;
  --accent-2: #4460fa;
  --attention: #f0b429;
  --danger: #a50f15;
  --shadow: 0 12px 34px rgba(31, 45, 61, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  overflow-x: hidden;
}

button,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

main {
  padding: 20px 28px 28px;
}

.screen {
  display: none;
}

.screen.is-active {
  display: block;
}

.screen-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-alt);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.settings-wrap {
  position: relative;
  display: inline-flex;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.icon-button:hover,
.icon-button[aria-expanded="true"] {
  background: var(--surface-alt);
  border-color: var(--line-strong);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.settings-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: min(300px, calc(100vw - 56px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  z-index: 40;
}

.settings-panel select {
  width: 100%;
  min-width: 0;
}

.tab,
.button-row button {
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 34px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
}

.tab.is-active,
.button-row button:hover,
.check-button[aria-expanded="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(20, 28, 36, 0.08);
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 14px;
  margin-bottom: 16px;
  min-height: 42px;
}

.toolbar-wrap {
  align-items: end;
  flex-wrap: wrap;
}

.control-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.impact-panel-controls {
  box-sizing: border-box;
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 124px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.impact-panel-controls-bars {
  justify-items: start;
}

.impact-rank-control-grid {
  display: grid;
  grid-template-columns: minmax(210px, 260px) minmax(160px, auto);
  grid-template-areas:
    "category actions"
    "switch switch";
  gap: 8px 10px;
}

.impact-category-control {
  grid-area: category;
  display: grid;
  gap: 6px;
}

.impact-rank-actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding-top: 23px;
}

.impact-category-dropdown {
  width: 100%;
  min-width: 0;
  margin-top: 0;
}

.impact-bar-control {
  display: grid;
  gap: 6px;
}

.impact-bar-control select {
  margin-top: 0;
  min-width: 180px;
}

.toolbar-timeseries {
  align-items: stretch;
}

.timeseries-control-stack {
  display: grid;
  gap: 10px;
  flex: 0 0 290px;
}

.timeseries-key-stack {
  display: grid;
  align-content: end;
  gap: 8px;
  flex: 1 1 540px;
  min-width: 0;
}

.timeseries-status-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 30px;
}

label,
fieldset {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  padding: 0;
  margin-bottom: 6px;
}

select {
  display: block;
  min-width: 180px;
  max-width: min(520px, 72vw);
  height: 36px;
  margin-top: 6px;
  padding: 0 34px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
}

.split-layout,
.impact-layout {
  display: grid;
  gap: 16px;
}

.split-layout {
  grid-template-columns: minmax(0, 1fr) 290px;
}

.impact-layout {
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.8fr);
}

.plot-panel,
.stats-panel,
.table-panel,
.mini-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.plot-panel {
  min-width: 0;
  padding: 12px;
  overflow-x: auto;
}

.plot-explainer {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.stats-panel {
  padding: 12px;
}

.distribution-key {
  color: var(--ink);
}

.boxplot-key {
  padding-bottom: 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.distribution-key-timeseries {
  --weighted-color: var(--accent);
  width: 100%;
  max-width: 640px;
  justify-self: end;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.distribution-key-heading {
  display: block;
  margin: 0 0 7px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 850;
}

.distribution-key-items {
  display: grid;
  gap: 7px;
}

.distribution-key-timeseries .distribution-key-items {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 6px 12px;
}

.distribution-key-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 18px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.25;
}

.distribution-sample {
  display: block;
  flex: 0 0 34px;
  width: 34px;
}

.distribution-sample-line {
  height: 0;
  border-top: 2px solid #111820;
}

.distribution-sample-line-unweighted {
  border-top-style: dashed;
}

.distribution-sample-line-weighted {
  border-top-color: var(--weighted-color);
}

.distribution-sample-band,
.distribution-sample-iqr,
.distribution-sample-outer {
  height: 15px;
  border-radius: 3px;
  border: 1px solid transparent;
}

.distribution-sample-median {
  height: 0;
  border-top: 2px solid #111820;
}

.distribution-sample-iqr,
.distribution-sample-unweighted-iqr {
  background: rgba(93, 103, 118, 0.28);
  border-color: rgba(93, 103, 118, 0.22);
}

.distribution-sample-outer,
.distribution-sample-unweighted-outer {
  background: rgba(93, 103, 118, 0.14);
  border-color: rgba(93, 103, 118, 0.18);
}

.distribution-sample-weighted-iqr {
  background: var(--weighted-color);
  opacity: 0.28;
}

.distribution-sample-weighted-outer {
  background: var(--weighted-color);
  opacity: 0.14;
}

.distribution-key-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

svg {
  display: block;
  width: 100%;
  max-width: 100%;
}

.mini-card svg {
  height: auto;
}

#boxplotSvg {
  min-height: 520px;
  min-width: 760px;
}

#rankSvg {
  min-height: 620px;
  min-width: 760px;
}

#barsSvg {
  min-height: 620px;
  min-width: 420px;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 12px;
}

.mini-grid.has-single-card {
  grid-template-columns: minmax(0, 1fr);
}

.mini-card {
  padding: 10px 10px 8px;
  min-width: 0;
}

.mini-grid.has-single-card .mini-card {
  padding: 14px;
}

.mini-grid.has-single-card .mini-head {
  min-height: 44px;
}

.mini-grid.has-single-card .mini-title {
  font-size: 14px;
}

.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
}

.mini-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
  min-height: 38px;
}

.mini-title {
  font-size: 12px;
  line-height: 1.25;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.mini-meta {
  white-space: nowrap;
  color: var(--muted);
  font-size: 11px;
}

.stat-block {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.stat-block:last-child {
  border-bottom: 0;
}

.stat-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
}

.stat-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  margin-top: 7px;
  font-size: 12px;
}

.muted {
  color: var(--muted);
}

.warning-dot {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--attention);
  color: #241a00;
  font-size: 12px;
  font-weight: 900;
}

.attention-banner {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid #e2b13c;
  border-radius: 999px;
  background: #fff7d6;
  color: #5c4300;
  font-size: 12px;
  font-weight: 800;
}

.status-pill {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.check-menu label.is-disabled {
  color: #98a29b;
  background: #f3f5f2;
  cursor: not-allowed;
}

.button-row {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 36px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-alt);
  align-self: end;
}

.button-row button {
  min-height: 28px;
  height: 28px;
  padding: 0 12px;
}

.switch-control {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  padding-top: 18px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.impact-switch {
  grid-area: switch;
  align-self: center;
  max-width: 360px;
  padding-top: 0;
}

.impact-rank-actions .button-row,
.impact-rank-actions .status-pill {
  align-self: center;
}

.switch-control input {
  appearance: none;
  position: relative;
  width: 34px;
  height: 20px;
  margin: 0;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #dfe5e1;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.switch-control input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(20, 28, 36, 0.18);
  transition: transform 0.15s ease;
}

.switch-control input:checked {
  border-color: var(--accent);
  background: var(--accent);
}

.switch-control input:checked::after {
  transform: translateX(14px);
}

.check-dropdown {
  position: relative;
  min-width: 190px;
  margin-top: 6px;
}

.check-dropdown-wide {
  min-width: 270px;
}

.check-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.check-button::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.6px solid var(--muted);
  border-bottom: 1.6px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  flex: 0 0 auto;
}

.check-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  max-width: min(520px, calc(100vw - 56px));
  max-height: 330px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  z-index: 30;
}

.check-dropdown.is-open .check-menu {
  display: block;
}

.check-menu label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 5px 7px;
  border-radius: 6px;
  color: var(--ink);
  font-weight: 650;
  cursor: pointer;
}

.check-menu label:hover {
  background: var(--surface-alt);
}

.check-menu input {
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.table-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.about-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  width: 100%;
}

.about-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.about-panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.about-panel p {
  margin: 0 0 12px;
  max-width: 72ch;
  color: var(--ink);
  line-height: 1.55;
}

.about-references {
  grid-column: 1 / -1;
}

.site-footer {
  margin: 0 28px 28px;
  padding: 16px 0 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.site-footer p {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.5;
}

.site-footer a,
.about-panel a {
  color: var(--accent);
}

.reference-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.reference-list a {
  display: inline-block;
  margin-left: 4px;
  overflow-wrap: anywhere;
}

.paper-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  margin-top: 8px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.paper-link:hover {
  background: var(--surface-alt);
}

.about-points {
  display: grid;
  gap: 14px;
}

.about-points div {
  display: grid;
  gap: 4px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.about-points div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.about-points strong {
  font-size: 13px;
}

.about-points span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.legend-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.legend-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.legend-panel h2 {
  margin: 0 0 10px;
  font-size: 15px;
}

.legend-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 7px 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.legend-swatch {
  width: 16px;
  height: 4px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.table-panel {
  overflow: hidden;
}

.table-panel h2 {
  margin: 0;
  padding: 12px 14px;
  font-size: 15px;
  border-bottom: 1px solid var(--line);
}

.table-scroll {
  overflow: auto;
  max-height: 430px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12px;
}

th,
td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  z-index: 1;
}

td {
  overflow-wrap: anywhere;
}

th:first-child,
td:first-child {
  width: 52px;
}

th:last-child,
td:last-child {
  width: 86px;
  white-space: nowrap;
  text-align: right;
}

.load-error {
  position: fixed;
  inset: 20px;
  display: grid;
  place-items: center;
  padding: 24px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: var(--surface);
  color: var(--danger);
  font-weight: 700;
  z-index: 100;
}

.axis-label,
.tick-label,
.plot-label {
  fill: var(--muted);
  font-size: 12px;
}

.plot-title {
  fill: var(--ink);
  font-size: 15px;
  font-weight: 800;
}

@media (max-width: 980px) {
  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .header-actions {
    align-items: stretch;
    justify-content: space-between;
  }

  .screen-tabs {
    flex: 1 1 auto;
    overflow-x: auto;
  }

  .split-layout,
  .impact-layout,
  .table-layout,
  .legend-layout,
  .about-layout {
    grid-template-columns: 1fr;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-timeseries {
    align-items: stretch;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .impact-switch {
    max-width: none;
  }

  .timeseries-control-stack,
  .timeseries-key-stack {
    flex-basis: 290px;
  }

  .timeseries-key-stack {
    flex: 1 1 520px;
  }

  .timeseries-status-row {
    justify-content: flex-start;
  }

  .distribution-key-timeseries {
    max-width: none;
    justify-self: stretch;
  }

  .distribution-key-timeseries .distribution-key-items {
    grid-template-columns: repeat(3, minmax(135px, 1fr));
  }

  select {
    width: 100%;
    max-width: 100%;
  }
}

@media (max-width: 740px) {
  .toolbar-timeseries {
    flex-direction: column;
  }

  .timeseries-control-stack,
  .timeseries-key-stack {
    flex-basis: auto;
  }

  .distribution-key-timeseries .distribution-key-items {
    grid-template-columns: 1fr;
  }
}
