:root {
  color-scheme: light;
  --bg: #faf7f1;
  --ink: #202124;
  --muted: #64605d;
  --line: #d9d2c4;
  --panel: #fffdf8;
  --teal: #2f5f91;
  --teal-dark: #234a73;
  --berry: #b4473f;
  --gold: #b7832f;
  --sage: #587366;
  --violet: #64558a;
  --shadow: 0 18px 45px rgba(26, 24, 20, 0.09);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: 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;
}

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

.skip-link {
  position: absolute;
  left: 1rem;
  top: 0.5rem;
  z-index: 20;
  transform: translateY(-150%);
  background: var(--ink);
  color: #fff;
  padding: 0.5rem 0.75rem;
}

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

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid rgba(32, 33, 36, 0.12);
  background: rgba(250, 247, 241, 0.92);
  backdrop-filter: blur(16px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 760;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #f2c14e;
  font-size: 0.62rem;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem;
}

.nav-links a {
  max-width: 100%;
  min-height: 2.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.48rem 0.75rem;
  background: rgba(255, 253, 248, 0.72);
  color: var(--ink);
  text-decoration: none;
  font-weight: 680;
  font-size: 0.9rem;
  text-align: center;
}

.nav-links a:hover,
.nav-links a[aria-current="page"] {
  border-color: var(--ink);
  background: #fff;
}

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

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

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

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

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

h1 {
  max-width: 12ch;
  font-size: clamp(2.25rem, 5vw, 4.8rem);
  line-height: 0.95;
}

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

h3 {
  font-size: 0.98rem;
}

.status-pill,
.version-badge {
  border: 1px solid rgba(100, 85, 138, 0.25);
  border-radius: 999px;
  background: #f2eff9;
  color: var(--violet);
  padding: 0.35rem 0.62rem;
  font-size: 0.78rem;
  font-weight: 820;
  white-space: nowrap;
}

.public-info {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(230px, 0.82fr) minmax(230px, 0.82fr);
  gap: 12px;
  margin-bottom: 18px;
}

.info-card,
.control-panel,
.visual-panel,
.plot-card,
.readout-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.info-card {
  padding: 14px;
  box-shadow: 0 10px 26px rgba(26, 24, 20, 0.05);
}

.info-card h2 {
  max-width: 20ch;
  font-size: clamp(1.2rem, 2.1vw, 1.8rem);
  line-height: 1.02;
}

.info-card p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.info-card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.info-kicker {
  color: var(--berry);
  font-size: 0.72rem;
  font-weight: 820;
  text-transform: uppercase;
}

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

.control-panel {
  position: sticky;
  top: 80px;
  display: grid;
  gap: 14px;
  padding: 18px;
  max-height: calc(100svh - 96px);
  overflow: auto;
}

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

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

select,
button {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fffefa;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 720;
}

button {
  cursor: pointer;
}

button:hover,
select:hover {
  border-color: rgba(100, 85, 138, 0.42);
}

.control-group,
.margin-card {
  display: grid;
  gap: 9px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.subsection-title {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 820;
  text-transform: uppercase;
}

.margin-controls {
  display: grid;
  gap: 12px;
}

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

.mini-slider span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 760;
}

.mini-slider strong {
  color: var(--violet);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.mini-slider input {
  grid-column: 1 / -1;
}

.mini-slider.is-disabled {
  opacity: 0.5;
}

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

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

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

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

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

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

.range-limits {
  display: flex;
  justify-content: space-between;
}

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

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  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.rank {
  background: var(--violet);
}

.swatch.margin {
  background: var(--gold);
}

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

.swatch.tracked {
  background: var(--gold);
}

.swatch.tail {
  background: var(--berry);
}

.annotation {
  border-left: 4px solid var(--violet);
  margin-bottom: 16px;
  padding: 9px 12px;
  background: #f4f1fb;
  color: #3e3854;
  font-weight: 720;
}

.plot-grid,
.joint-plot-grid {
  display: grid;
  gap: 14px;
}

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

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

.plot-card {
  min-width: 0;
  padding: 14px;
  box-shadow: 0 10px 26px rgba(26, 24, 20, 0.05);
}

.plot-card h3 {
  margin-bottom: 10px;
}

svg {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  min-height: 330px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
}

.joint-plot {
  aspect-ratio: 1.09 / 1;
  min-height: 420px;
}

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

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

.tail-zone {
  fill: rgba(180, 71, 63, 0.08);
  stroke: rgba(180, 71, 63, 0.42);
  stroke-width: 1.2;
}

.point {
  fill: rgba(100, 85, 138, 0.5);
}

.point.observed {
  fill: rgba(47, 95, 145, 0.48);
}

.point.highlight {
  fill: var(--gold);
  stroke: var(--ink);
  stroke-width: 1.3;
}

.rug {
  stroke: var(--gold);
  stroke-width: 2;
  stroke-linecap: round;
}

.margin-path {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.margin-path.y1 {
  stroke: var(--gold);
}

.margin-path.y2 {
  stroke: var(--teal);
  stroke-dasharray: 8 7;
}

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

.readout-card {
  padding: 12px;
  box-shadow: 0 10px 26px rgba(26, 24, 20, 0.04);
}

.readout-card span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 760;
  text-transform: uppercase;
}

.readout-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

:focus-visible {
  outline: 3px solid var(--violet);
  outline-offset: 3px;
}

@media (max-width: 980px) {
  .site-header,
  .topbar,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav-links,
  .legend {
    justify-content: flex-start;
  }

  .public-info,
  .workspace,
  .plot-grid,
  .joint-plot-grid,
  .readout-grid {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
    max-height: none;
  }
}

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

  h1 {
    font-size: 2.7rem;
  }

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

  svg {
    min-height: 260px;
  }
}
