:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --ink: #151719;
  --muted: #667085;
  --line: #d9d4ca;
  --panel: #fffdf8;
  --panel-strong: #ffffff;
  --teal: #0f766e;
  --teal-dark: #0a4f4b;
  --berry: #9f1239;
  --gold: #b7791f;
  --slate: #64748b;
  --shadow: 0 18px 45px rgba(26, 24, 20, 0.09);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 0)),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  width: min(1380px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 6px 2px 22px;
}

.project-note {
  max-width: 720px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.project-note code {
  color: var(--ink);
  font-size: 0.9em;
}

a {
  color: var(--teal-dark);
  font-weight: 760;
  text-decoration-color: rgba(15, 118, 110, 0.28);
  text-underline-offset: 3px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--berry);
  font-size: 0.76rem;
  font-weight: 760;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2.1rem, 5vw, 4.8rem);
  line-height: 0.95;
}

h2 {
  font-size: clamp(1.35rem, 2.3vw, 2.2rem);
}

h3 {
  font-size: 0.98rem;
  margin-bottom: 12px;
}

.status-pill {
  min-width: 116px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 680;
  text-align: center;
}

.status-pill.ok {
  color: var(--teal-dark);
  border-color: rgba(15, 118, 110, 0.28);
}

.status-pill.error {
  color: var(--berry);
  border-color: rgba(159, 18, 57, 0.24);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.control-panel,
.visual-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.control-panel {
  position: sticky;
  top: 18px;
  padding: 18px;
}

.visual-panel {
  min-width: 0;
  padding: 20px;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 720;
}

.family-select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-strong);
  color: var(--ink);
  padding: 0 12px;
  font-weight: 720;
}

.family-search {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-strong);
  color: var(--ink);
  margin-bottom: 8px;
  padding: 0 12px;
}

.compact-select {
  min-height: 38px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.84rem;
}

.family-tools {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

.family-tools button {
  min-height: 34px;
  font-size: 0.78rem;
}

.family-tools button.active {
  color: white;
  background: var(--teal);
  border-color: var(--teal);
}

.family-meta {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: capitalize;
}

.recent-families {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.recent-families button {
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 0.74rem;
}

.slider-list {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

.slider-block {
  display: grid;
  gap: 8px;
}

.slider-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px 34px;
  gap: 8px;
  align-items: center;
}

.slider-number,
.range-inputs input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-strong);
  color: var(--ink);
  padding: 0 8px;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.icon-button {
  min-height: 34px;
  padding: 0;
}

.slider-topline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.slider-name {
  font-weight: 780;
}

.slider-role {
  color: var(--muted);
  font-size: 0.82rem;
}

.slider-value {
  color: var(--teal-dark);
  font-variant-numeric: tabular-nums;
  font-weight: 780;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.range-limits {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 24px;
}

.range-panel {
  display: grid;
  gap: 10px;
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.section-title {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 780;
  text-transform: uppercase;
}

.range-mode {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.range-mode label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.range-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.range-inputs label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
  text-transform: uppercase;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-strong);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 720;
}

button:hover {
  border-color: rgba(15, 118, 110, 0.42);
  color: var(--teal-dark);
}

button:active {
  transform: translateY(1px);
}

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

.panel-actions {
  display: grid;
  gap: 12px;
  justify-items: end;
}

.plot-tabs {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-strong);
}

.plot-tabs button {
  min-height: 34px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 0 10px;
  color: var(--muted);
  background: transparent;
}

.plot-tabs button:last-child {
  border-right: 0;
}

.plot-tabs button.active {
  color: white;
  background: var(--teal);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

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

.swatch {
  display: inline-block;
  width: 16px;
  height: 3px;
  border-radius: 999px;
}

.swatch.current {
  background: var(--teal);
}

.swatch.baseline {
  background: var(--slate);
}

#baseline-legend {
  opacity: 0.25;
}

#baseline-legend.active {
  opacity: 1;
}

.plot-wrap {
  width: 100%;
  aspect-ratio: 16 / 8.7;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  overflow: hidden;
}

#density-plot {
  display: block;
  width: 100%;
  height: 100%;
}

.axis text {
  fill: var(--muted);
  font-size: 12px;
}

.axis line,
.axis path,
.grid-line {
  stroke: #ded9ce;
  stroke-width: 1;
}

.density-path {
  fill: none;
  stroke: var(--teal);
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.mass-bar {
  fill: rgba(15, 118, 110, 0.72);
  stroke: var(--teal-dark);
  stroke-width: 1;
}

.baseline-bar {
  fill: rgba(100, 116, 139, 0.24);
  stroke: rgba(100, 116, 139, 0.72);
  stroke-width: 1;
}

.point-mass-line {
  stroke: var(--berry);
  stroke-width: 3;
}

.point-mass-dot {
  fill: var(--berry);
}

.point-mass-label {
  fill: var(--berry);
  font-size: 12px;
  font-weight: 760;
}

.baseline-path {
  fill: none;
  stroke: var(--slate);
  stroke-width: 2;
  stroke-dasharray: 7 7;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.quantile-line {
  stroke: rgba(183, 121, 31, 0.48);
  stroke-width: 1;
}

.cdf-path,
.quantile-path {
  fill: none;
  stroke: var(--teal);
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.median-line {
  stroke: var(--gold);
  stroke-width: 2;
}

.readout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(280px, 0.95fr);
  gap: 16px;
  margin-top: 18px;
  align-items: start;
}

.quantile-table {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.quantile-cell {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.64);
  padding: 9px 10px;
}

.quantile-cell span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 760;
}

.quantile-cell strong {
  display: block;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.technical-panel {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.64);
  padding: 12px 14px;
}

summary {
  cursor: pointer;
  font-weight: 780;
}

dl {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
}

dt {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 760;
  text-transform: uppercase;
}

dd {
  margin: 2px 0 0;
  line-height: 1.45;
}

.formula-block {
  margin: 4px 0 0;
  overflow-x: auto;
  white-space: pre-wrap;
  color: #263238;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.5;
}

.trace-line {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 680;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  border-radius: 7px;
  background: var(--ink);
  color: white;
  padding: 10px 12px;
  font-size: 0.86rem;
  box-shadow: var(--shadow);
}

.error-message {
  color: var(--berry);
  font-weight: 760;
}

@media (max-width: 940px) {
  .app-shell {
    width: min(100% - 20px, 760px);
    padding-top: 18px;
  }

  .topbar,
  .panel-heading {
    align-items: start;
    flex-direction: column;
  }

  .panel-actions {
    justify-items: start;
    width: 100%;
  }

  .workspace,
  .readout-grid {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

  .plot-wrap {
    aspect-ratio: 4 / 3;
    min-height: 300px;
  }

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

@media (max-width: 520px) {
  .button-grid,
  .slider-controls,
  .range-inputs,
  .quantile-table {
    grid-template-columns: 1fr;
  }

  .plot-tabs {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .plot-tabs button {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .plot-tabs button:last-child {
    border-bottom: 0;
  }

  .visual-panel,
  .control-panel {
    padding: 14px;
  }
}
