:root {
  --paper: #f8fafc;
  --white: #ffffff;
  --ink: #17212b;
  --muted: #657684;
  --line: #dce3e8;
  --mean: #265dff;
  --seed: #9aabb7;
  --positive: #128477;
  --negative: #c94b57;
  --waiting: #7656b5;
  --sans: "Avenir Next", "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --width: 1180px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  overflow-x: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.45;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }

button,
select,
input { font: inherit; }

:focus-visible {
  outline: 3px solid #f0b429;
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 20;
  padding: 8px 12px;
  background: var(--ink);
  color: white;
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }

.topbar {
  display: flex;
  min-height: 68px;
  padding: 12px max(20px, calc((100% - var(--width)) / 2));
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgb(248 250 252 / 94%);
}

.project-name {
  font-size: 17px;
  font-weight: 720;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.project-name span { color: var(--mean); }

.intervals {
  display: flex;
  min-width: 0;
  margin: 0;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--white);
}

.intervals legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.interval-option { position: relative; }

.interval-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.interval-option label {
  display: block;
  min-width: 46px;
  padding: 6px 9px;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.interval-option label:hover { color: var(--ink); }

.interval-option input:checked + label {
  background: var(--ink);
  color: white;
}

.interval-option input:focus-visible + label {
  outline: 3px solid #f0b429;
  outline-offset: 2px;
}

[hidden] { display: none !important; }

main {
  width: min(calc(100% - 40px), var(--width));
  margin: 0 auto;
}

.plot-section {
  padding: 70px 0 76px;
  border-bottom: 1px solid var(--line);
}

.plot-section-primary {
  display: flex;
  min-height: 0;
  padding-top: 42px;
  flex-direction: column;
}

.plot-head {
  display: flex;
  min-height: 58px;
  gap: 28px;
  align-items: flex-start;
  justify-content: space-between;
}

h1,
h2 {
  margin: 0;
  font-size: clamp(25px, 3vw, 35px);
  font-weight: 660;
  letter-spacing: -0.035em;
  line-height: 1.15;
}

h2 { font-size: clamp(23px, 2.6vw, 31px); }

#twap-title {
  max-width: 980px;
  font-size: clamp(21px, 2.2vw, 28px);
}

.plot-head p {
  margin: 7px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  white-space: pre-line;
}

.plot-head .rho-definition {
  display: flex;
  max-width: 780px;
  margin-top: 10px;
  gap: 7px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 10px;
}

.rho-definition math { font-size: 15px; }
.rho-definition .rho-scale { color: var(--muted); }

.plot-tools {
  display: flex;
  gap: 24px;
  align-items: flex-end;
}

.legend {
  display: flex;
  gap: 16px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

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

.legend i {
  display: inline-block;
  width: 24px;
  border-top: 3px solid var(--mean);
}

.legend .legend-seed {
  border-top: 1px dashed var(--seed);
}

.legend .diamond {
  width: 9px;
  height: 9px;
  border: 1px solid var(--ink);
  background: var(--mean);
  transform: rotate(45deg);
}

.legend .dot {
  width: 8px;
  height: 8px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--white);
}

.legend .range {
  width: 20px;
  border-top: 1px solid var(--seed);
}

.chart {
  position: relative;
  display: grid;
  min-height: 410px;
  margin-top: 30px;
  flex: 1;
  place-items: stretch;
}

.chart-main {
  flex: 0 0 auto;
  min-height: 0;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.chart-twap { min-height: 390px; }

.signal-panel {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  padding: 14px 12px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.signal-panel-head {
  display: flex;
  min-width: 0;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
}

.signal-panel h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.signal-panel-value {
  color: var(--mean);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 700;
  white-space: nowrap;
}

.rule-definition {
  display: grid;
  margin-top: 24px;
  padding: 14px 16px;
  grid-template-columns: 170px minmax(360px, 1.35fr) minmax(300px, 1fr);
  gap: 18px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}

.rule-definition-heading strong {
  display: block;
  font-size: 14px;
}

.rule-definition math {
  width: 100%;
  color: var(--ink);
  font-size: 13px;
}

.formula-key {
  display: grid;
  margin: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 14px;
}

.formula-key div {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px;
  align-items: baseline;
}

.formula-key dt,
.formula-key dd { margin: 0; }

.formula-key dt {
  color: var(--ink);
  font-size: 11px;
}

.formula-key dd {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  line-height: 1.35;
}

.signal-panel .chart-svg {
  height: auto;
  min-height: 0;
  margin-top: 8px;
}

.chart svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
  overflow: visible;
}

.chart-svg text {
  fill: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.chart-svg .axis-label {
  fill: var(--ink);
  font-size: 10px;
  font-weight: 700;
}

.chart-svg .gridline {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-svg .zero-line {
  stroke: var(--ink);
  stroke-dasharray: 4 5;
  stroke-width: 1.2;
}

.animated-path {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  transition: stroke-dashoffset 2200ms cubic-bezier(.16, .65, .3, 1);
}

.mean-line {
  fill: none;
  stroke: var(--mean);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
  transition-duration: 2800ms;
}

.seed-line {
  fill: none;
  stroke: var(--seed);
  stroke-dasharray: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.chart-point {
  opacity: 0;
  transform: scale(.35);
  transform-box: fill-box;
  transform-origin: center;
  transition:
    opacity 260ms ease calc(1900ms + var(--point-order, 0) * 180ms),
    transform 320ms ease calc(1900ms + var(--point-order, 0) * 180ms);
}

.chart.is-visible .animated-path { stroke-dashoffset: 0; }

.chart.is-visible .chart-point {
  opacity: 1;
  transform: scale(1);
}

.mean-point {
  fill: var(--mean);
  stroke: var(--white);
  stroke-width: 3;
}

.seed-point {
  fill: var(--white);
  stroke: var(--seed);
  stroke-width: 1.5;
}

.range-line {
  stroke: var(--seed);
  stroke-width: 1.4;
  stroke-linecap: round;
}

.mean-diamond {
  fill: var(--mean);
  stroke: var(--ink);
  stroke-width: 1.4;
}

.twap-seed {
  fill: var(--white);
  stroke: var(--ink);
  stroke-width: 1.5;
}

.empty-state {
  display: grid;
  min-height: inherit;
  place-items: center;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
}

.conclusion {
  color: var(--negative);
  font: inherit;
  font-weight: 780;
}

.conclusion:empty { display: none; }

.load-error {
  margin: 20px;
  padding: 12px;
  border: 1px solid var(--negative);
}

@media (max-width: 720px) {
  .topbar {
    min-height: 0;
    padding: 14px 16px 10px;
    gap: 12px;
    align-items: flex-start;
    flex-direction: column;
  }

  .intervals {
    width: 100%;
    min-inline-size: 0;
  }

  .interval-option { flex: 1; }

  .interval-option label {
    min-width: 0;
    padding-right: 4px;
    padding-left: 4px;
  }

  main { width: min(calc(100% - 28px), var(--width)); }

  .plot-section,
  .plot-section-primary {
    min-height: 0;
    padding: 38px 0 46px;
  }

  .plot-head {
    gap: 22px;
    flex-direction: column;
  }

  .plot-tools {
    width: 100%;
    gap: 16px;
    align-items: flex-end;
    justify-content: space-between;
  }

  .chart,
  .chart-twap {
    min-height: 330px;
    margin-top: 24px;
  }

  .chart-main {
    grid-template-columns: 1fr;
    margin-top: 24px;
  }

  .rule-definition { grid-template-columns: 1fr; }
  .rule-definition .formula-key { grid-column: auto; }

  .signal-panel-head { flex-wrap: wrap; }

}

@media (min-width: 721px) and (max-width: 1080px) {
  .chart-main { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .rule-definition { grid-template-columns: 150px 1fr; }
  .rule-definition .formula-key { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
  }

  .animated-path { stroke-dashoffset: 0; }

  .chart-point {
    opacity: 1;
    transform: none;
  }
}
