:root {
  color-scheme: light;
  --bg: #faf7f1;
  --ink: #202124;
  --muted: #64605d;
  --line: #d9d2c4;
  --panel: #fffdf8;
  --blue: #2f5f91;
  --blue-dark: #234a73;
  --red: #b4473f;
  --gold: #b7832f;
  --sage: #587366;
  --violet: #72558b;
  --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;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.skip-link {
  position: absolute;
  left: 1rem;
  top: .5rem;
  z-index: 30;
  transform: translateY(-150%);
  background: var(--ink);
  color: #fff;
  padding: .5rem .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: .85rem clamp(1rem, 4vw, 3rem);
  border-bottom: 1px solid rgba(32, 33, 36, .12);
  background: rgba(250, 247, 241, .92);
  backdrop-filter: blur(16px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .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: .62rem;
}
.nav-links { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .35rem; }
.nav-links a {
  min-height: 2.25rem;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .48rem .75rem;
  background: rgba(255,253,248,.72);
  color: var(--ink);
  text-decoration: none;
  font-weight: 680;
  font-size: .88rem;
}
.nav-links a:hover, .nav-links a[aria-current="page"] { border-color: var(--ink); background: #fff; }

.app-shell { width: min(1440px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 40px; }
.topbar { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding: 6px 2px 22px; }
.eyebrow { margin: 0 0 6px; color: var(--red); font-size: .74rem; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1, h2, h3 { margin: 0; }
h1 { font-size: clamp(2.4rem, 5.5vw, 4.9rem); line-height: .95; }
h2 { font-size: clamp(1.15rem, 2vw, 1.75rem); }
.project-note { max-width: 760px; margin: 12px 0 0; color: var(--muted); line-height: 1.5; }
.status-pill {
  min-width: 126px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 13px;
  background: rgba(255,255,255,.72);
  color: var(--muted);
  font-size: .82rem;
  font-weight: 720;
  text-align: center;
}
.status-pill.ok { color: var(--blue-dark); border-color: rgba(47,95,145,.35); }
.status-pill.updating { color: var(--gold); border-color: rgba(183,131,47,.4); }
.status-pill.error { color: var(--red); border-color: rgba(180,71,63,.35); }

.public-info { display: grid; grid-template-columns: 1.35fr .82fr .82fr; gap: 12px; margin-bottom: 18px; }
.info-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,253,248,.88);
  box-shadow: 0 10px 26px rgba(26,24,20,.05);
  padding: 14px;
}
.info-card h2 { max-width: 22ch; line-height: 1.05; }
.info-card p { margin: 8px 0 0; color: var(--muted); font-size: .89rem; line-height: 1.45; }
.info-card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.info-kicker { color: var(--red); font-size: .71rem; font-weight: 820; text-transform: uppercase; }
.version-badge { border: 1px solid rgba(47,95,145,.25); border-radius: 999px; background: #eef5fb; color: var(--blue-dark); padding: .2rem .5rem; font-size: .71rem; font-weight: 820; }

.workspace { display: grid; grid-template-columns: minmax(350px, 390px) minmax(0,1fr); gap: 18px; align-items: start; }
.control-panel, .visual-panel { border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,253,248,.94); box-shadow: var(--shadow); }
.control-panel { position: sticky; top: 76px; max-height: calc(100vh - 94px); overflow: auto; padding: 18px; }
.visual-panel { min-width: 0; padding: 20px; }
.control-heading, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.quiet-button, button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
  font-weight: 700;
}
button:hover { border-color: var(--ink); }
.scenario-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 16px; }
.scenario-grid label { display: grid; gap: 5px; color: var(--muted); font-size: .76rem; font-weight: 720; }
.scenario-grid input {
  width: 100%;
  min-height: 37px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 0 9px;
  color: var(--ink);
}
.scenario-grid button { align-self: end; }
.fixed-model-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 12px; }
.fixed-model-row span { display: flex; justify-content: space-between; align-items: baseline; border: 1px solid var(--line); border-radius: 7px; background: #f8f5ee; padding: 8px 10px; }
.fixed-model-row small { color: var(--muted); font-weight: 700; }
.drag-hint { margin: 17px 0 10px; color: var(--muted); font-size: .79rem; }
.trajectory-controls { display: grid; gap: 10px; }
.trajectory-card { border: 1px solid var(--line); border-radius: 7px; background: #fff; padding: 9px; }
.trajectory-top { display: flex; align-items: center; justify-content: space-between; gap: 9px; margin-bottom: 5px; }
.trajectory-name { display: flex; align-items: baseline; gap: 7px; }
.trajectory-name strong { font-size: .87rem; }
.trajectory-name span { color: var(--muted); font-size: .7rem; }
.trajectory-card select { min-height: 28px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--muted); padding: 0 6px; font-size: .72rem; }
.trajectory-svg { display: block; width: 100%; height: 86px; touch-action: none; overflow: visible; }
.trajectory-grid { stroke: #e7e1d7; stroke-width: 1; }
.trajectory-line { fill: none; stroke-width: 2.4; stroke-linejoin: round; stroke-linecap: round; }
.trajectory-point { stroke: #fff; stroke-width: 2.2; cursor: ns-resize; }
.trajectory-point:focus { stroke: var(--ink); stroke-width: 3; outline: none; }
.trajectory-label { fill: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; }
.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 14px; }

.panel-heading { align-items: end; margin-bottom: 14px; }
.plot-tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff; }
.plot-tabs button { min-height: 35px; border: 0; border-right: 1px solid var(--line); border-radius: 0; color: var(--muted); }
.plot-tabs button:last-child { border-right: 0; }
.plot-tabs button.active { background: var(--blue); color: #fff; }
.plot-wrap { position: relative; min-height: 520px; border: 1px solid var(--line); border-radius: 8px; background: #fffefa; overflow: hidden; }
.plot-wrap.scrollable { overflow-x: auto; overflow-y: hidden; scrollbar-color: #bbb3a7 transparent; scrollbar-width: thin; }
.plot-wrap.scrollable #main-plot { max-width: none; }
#main-plot { display: block; width: 100%; min-height: 520px; }
.plot-message { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(255,253,248,.84); color: var(--red); text-align: center; }
.plot-message[hidden] { display: none; }
.axis-line, .tick-line { stroke: #bbb3a7; stroke-width: 1; }
.grid-line { stroke: #ebe5da; stroke-width: 1; }
.axis-text { fill: var(--muted); font-size: 11px; }
.axis-label { fill: var(--muted); font-size: 12px; font-weight: 700; }
.subject-path { fill: none; stroke: var(--blue); stroke-width: 1; opacity: .11; }
.subject-density { fill: rgba(88,115,102,.06); stroke: rgba(88,115,102,.25); stroke-width: .8; }
.band-outer { fill: rgba(47,95,145,.10); }
.band-inner { fill: rgba(47,95,145,.19); }
.median-path { fill: none; stroke: var(--blue-dark); stroke-width: 3; }
.density-path { fill: none; stroke-width: 2.2; }
.facet-density-fill { fill: rgba(47,95,145,.08); }
.histogram-bar { fill: rgba(180,71,63,.27); stroke: rgba(180,71,63,.48); stroke-width: .45; }
.histogram-baseline { stroke: #d9d2c4; stroke-width: 1; stroke-dasharray: 3 3; }
.facet-grid { stroke: #eee8de; stroke-width: 1; }
.facet-axis, .facet-frame { stroke: #c8c0b4; stroke-width: 1; }
.facet-frame { fill: #fff; }
.facet-title { fill: var(--ink); font-size: 11px; font-weight: 780; }
.facet-meta { fill: var(--muted); font-size: 9px; font-weight: 650; }
.facet-axis-text { fill: var(--muted); font-size: 8.5px; }
.normal-score-point { fill: var(--blue); opacity: .34; }
.fitted-contour { fill: none; stroke: var(--red); stroke-width: 1.45; }
.fitted-contour.contour-0 { opacity: .55; }
.fitted-contour.contour-1 { opacity: .72; }
.fitted-contour.contour-2 { opacity: .9; stroke-width: 1.8; }
.combined-link { fill: none; stroke: rgba(183,131,47,.42); stroke-width: 1.4; stroke-dasharray: 4 4; }
.combined-row-label { fill: var(--muted); font-size: 10px; font-weight: 760; letter-spacing: .04em; text-transform: uppercase; }
.dependence-path { fill: none; stroke: var(--blue); stroke-width: 3; }
.dependence-point { fill: #fff; stroke: var(--red); stroke-width: 2.5; }
.dependence-truth { fill: var(--blue); }
.scatter-point { fill: var(--blue); opacity: .38; }
.plot-note { fill: var(--ink); font-size: 13px; font-weight: 720; }
.legend-text { fill: var(--muted); font-size: 11px; }

.readout-grid { display: grid; grid-template-columns: repeat(3, minmax(110px, .55fr)) minmax(230px, 1.7fr); gap: 10px; margin-top: 12px; }
.readout-card { border: 1px solid var(--line); border-radius: 7px; background: #fff; padding: 10px 12px; }
.readout-card span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .7rem; font-weight: 760; text-transform: uppercase; }
.readout-card strong { font-size: 1rem; line-height: 1.3; }
.readout-card.wide strong { font-size: .85rem; font-weight: 650; }
.trace-line { margin-top: 12px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .72rem; line-height: 1.45; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 330px minmax(0,1fr); }
  .public-info { grid-template-columns: 1fr 1fr; }
  .about-card { grid-column: 1 / -1; }
  .readout-grid { grid-template-columns: repeat(3,1fr); }
  .readout-card.wide { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .site-header, .topbar, .panel-heading { align-items: flex-start; flex-direction: column; }
  .nav-links { justify-content: flex-start; }
  .workspace { grid-template-columns: 1fr; }
  .control-panel { position: static; max-height: none; }
  .public-info { grid-template-columns: 1fr; }
  .about-card { grid-column: auto; }
  .plot-tabs { width: 100%; }
  .plot-tabs button { flex: 1; }
}
@media (max-width: 560px) {
  .app-shell { width: min(100% - 20px, 1440px); padding-top: 14px; }
  .scenario-grid, .button-grid, .readout-grid { grid-template-columns: 1fr 1fr; }
  .readout-card.wide { grid-column: 1 / -1; }
  .visual-panel { padding: 11px; }
  .plot-wrap, #main-plot { min-height: 430px; }
}
