:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --text: #171c23;
  --muted: #697684;
  --line: #dde3ea;
  --grid: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #fafbfc;
  --input: #ffffff;
  --button-bg: #161b22;
  --button-text: #ffffff;
  --tooltip-bg: #111827;
  --tooltip-text: #ffffff;
  --blue: #3267d6;
  --red: #c94343;
  --excluded-point: #8a94a3;
  --green: #14745e;
  --shadow: 0 10px 28px rgba(27, 36, 48, 0.06);
  --over-bg: #fff0f0;
  --over-text: #a52929;
  --under-bg: #eaf7f2;
  --under-text: #0f684f;
}

body.dark {
  color-scheme: dark;
  --bg: #0f1318;
  --text: #eef2f7;
  --muted: #95a2af;
  --line: #28323e;
  --grid: #202a35;
  --panel: #151a21;
  --panel-soft: #111720;
  --input: #10161d;
  --button-bg: #eef3f8;
  --button-text: #10161d;
  --tooltip-bg: #f8fafc;
  --tooltip-text: #111827;
  --blue: #6d96ff;
  --red: #ff6565;
  --excluded-point: #7c8794;
  --green: #4cc7a6;
  --shadow: 0 12px 34px rgba(0, 0, 0, 0.18);
  --over-bg: rgba(255, 101, 101, 0.14);
  --over-text: #ff9a9a;
  --under-bg: rgba(76, 199, 166, 0.14);
  --under-text: #77dfc3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: background 180ms ease, color 180ms ease;
  font-variant-numeric: tabular-nums;
}

.shell {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 16px;
}

.toolbar > div:first-child {
  padding-top: 14px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.eyebrow a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--green) 38%, transparent);
}

.eyebrow a:hover {
  border-bottom-color: var(--green);
}

.chart-source {
  margin-bottom: 9px;
  font-size: 11px;
}

h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 760;
  line-height: 1.1;
}

h1 span {
  color: var(--muted);
  font-size: 0.78em;
  font-weight: 640;
}

.version-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  margin-left: 8px;
  padding: 0 8px;
  transform: translateY(-4px);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0;
  vertical-align: middle;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  width: auto;
  padding-top: 18px;
  flex: 0 0 auto;
}

.social-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 120ms ease, border-color 120ms ease, background 120ms ease;
}

.social-link:hover {
  border-color: color-mix(in srgb, var(--blue) 42%, var(--line));
  background: color-mix(in srgb, var(--blue) 8%, var(--panel));
  opacity: 0.9;
}

.x-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  color: var(--panel);
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.api-key,
.control-button {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.api-key {
  width: 220px;
}

.control-button {
  flex: 0 0 auto;
}

.control-button > span {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

input,
button {
  appearance: none;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  font: inherit;
  font-size: 13px;
  line-height: 1;
}

input {
  width: 100%;
  padding: 0 12px;
  background: var(--input);
  color: var(--text);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.controls input,
.controls button {
  height: 38px;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 16%, transparent);
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border-color: var(--button-bg);
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  font-weight: 700;
  transition: opacity 120ms ease, border-color 120ms ease, background 120ms ease;
}

button:hover {
  opacity: 0.88;
}

.theme-toggle,
.metric-toggle {
  width: 104px;
  gap: 8px;
  padding: 0 10px;
  border-color: var(--line);
  background: var(--panel);
  color: var(--text);
}

.metric-toggle {
  width: 126px;
}

.legend-toggle {
  width: auto;
  height: 26px;
  min-width: 116px;
  padding: 0 9px;
  border-color: var(--line);
  background: var(--input);
}

.theme-toggle b,
.metric-toggle b {
  font-size: 12px;
  line-height: 1;
}

.toggle-track {
  position: relative;
  width: 28px;
  height: 16px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 28%, transparent);
}

.toggle-track span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 140ms ease;
}

body.dark .toggle-track span {
  transform: translateX(12px);
}

body.metric-fdv .metric-toggle .toggle-track span {
  transform: translateX(12px);
}

.model-toggle.is-excluded .toggle-track span {
  transform: translateX(12px);
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

.chart-panel,
.table-wrap,
.interpretation,
.metrics > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.chart-panel {
  padding: 14px 16px 16px;
}

.chart-wrap {
  position: relative;
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  font-weight: 760;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.blue {
  background: var(--blue);
}

.red {
  background: var(--red);
}

canvas {
  width: 100%;
  height: clamp(440px, 58vh, 680px);
  display: block;
  cursor: crosshair;
}

.tooltip {
  position: absolute;
  z-index: 2;
  min-width: 210px;
  max-width: 280px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.18);
  font-size: 12px;
  pointer-events: none;
}

.tooltip strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}

.tooltip span {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  line-height: 1.6;
}

.coordinate-readout {
  position: absolute;
  z-index: 3;
  min-width: 190px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--tooltip-bg) 92%, transparent);
  color: var(--tooltip-text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.16);
  font-size: 11px;
  font-weight: 760;
  pointer-events: none;
}

.coordinate-readout span {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  line-height: 1.6;
}

.coordinate-readout em {
  color: color-mix(in srgb, var(--tooltip-text) 62%, transparent);
  font-style: normal;
}

.coordinate-readout b {
  font-weight: 850;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.metrics > div {
  padding: 13px 14px;
  display: grid;
  gap: 6px;
}

.metrics span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.metrics strong {
  font-size: 22px;
  line-height: 1;
}

.metrics small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.metric-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.metric-refresh {
  height: 26px;
  padding: 0 10px;
  border-color: var(--line);
  background: var(--input);
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
}

.last-update-metric strong {
  font-size: 17px;
  line-height: 1.2;
}

.valuation-metric {
  align-content: start;
}

.valuation-metric strong {
  overflow: hidden;
  font-size: 18px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.valuation-metric:first-child strong {
  color: var(--over-text);
}

.valuation-metric:nth-child(2) strong {
  color: var(--under-text);
}

.r2-gauge {
  position: relative;
  height: 8px;
  margin-top: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, #d64b4b 0%, #f3f4f6 50%, #1b9b72 100%);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--line) 70%, transparent);
}

.r2-gauge i {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 12px;
  height: 12px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
  transform: translate(-50%, -50%);
}

.r2-scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
  font-weight: 760;
  line-height: 1;
}

.table-wrap {
  overflow: auto;
  max-height: 520px;
}

.interpretation {
  margin-top: 12px;
  padding: 18px 20px 20px;
}

.interpretation h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 800;
}

.interpretation-grid {
  display: grid;
  gap: 14px;
  max-width: 860px;
}

.interpretation article {
  display: grid;
  gap: 5px;
}

.interpretation h3 {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 820;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.interpretation p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1120px;
  font-size: 13px;
}

th,
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
  font-weight: 760;
}

.project-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 220px;
}

.project-name {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
}

.project-name b {
  overflow: hidden;
  text-overflow: ellipsis;
}

.token-logo {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--panel-soft);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--line) 86%, transparent);
  object-fit: cover;
}

.token-logo-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--muted);
  background: var(--panel);
  color: var(--muted);
  font-size: 9px;
  font-style: normal;
  font-weight: 850;
  line-height: 1;
}

.table-head-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 220px;
}

.include-all-table {
  height: 26px;
  min-width: 84px;
  padding: 0 10px;
  border-color: var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
}

.model-toggle {
  height: 30px;
  min-width: 88px;
  gap: 7px;
  padding: 0 9px;
  border-color: var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
}

.model-toggle.is-excluded {
  border-color: color-mix(in srgb, var(--red) 44%, var(--line));
  background: color-mix(in srgb, var(--red) 11%, var(--panel));
  color: var(--red);
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

tbody tr {
  background: var(--panel);
}

tbody tr:nth-child(even) {
  background: var(--panel-soft);
}

tbody tr:hover {
  background: color-mix(in srgb, var(--blue) 8%, var(--panel));
}

tbody tr.is-excluded-row {
  color: color-mix(in srgb, var(--text) 72%, var(--muted));
}

tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 94px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.badge-over {
  background: var(--over-bg);
  color: var(--over-text);
}

.badge-under {
  background: var(--under-bg);
  color: var(--under-text);
}

.delta {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 72px;
  font-weight: 850;
}

.delta-over {
  color: var(--over-text);
}

.delta-under {
  color: var(--under-text);
}

@media (max-width: 820px) {
  .toolbar,
  .chart-head {
    align-items: stretch;
    flex-direction: column;
  }

  .controls {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) 104px minmax(220px, 1fr);
    width: 100%;
    padding-top: 0;
  }

  .toolbar > div:first-child {
    padding-top: 0;
  }

  .api-key {
    width: auto;
  }

  .control-button > span {
    display: none;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-panel {
    padding: 12px 10px 14px;
  }

  .chart-head {
    gap: 12px;
  }

  canvas {
    height: min(620px, 72vh);
  }

}

@media (max-width: 560px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .social-link,
  .theme-toggle,
  .controls button {
    width: 100%;
  }

  .legend-toggle {
    width: auto;
  }

  .shell {
    width: min(100vw - 16px, 1440px);
    padding-top: 12px;
  }

  .chart-panel {
    padding-inline: 6px;
  }

  .chart-wrap {
    margin-inline: -2px;
  }

  canvas {
    height: 620px;
  }
}
