:root {
  color-scheme: light;
  --bg: #eef0ea;
  --paper: #fdfdfb;
  --paper-soft: #f6f7f2;
  --ink: #203129;
  --muted: #66756e;
  --line: #d8ded7;
  --line-strong: #bdc4b8;
  --violet: #75638f;
  --violet-soft: #f0ecf5;
  --teal: #2f6b4f;
  --teal-soft: #e7f0ea;
  --rose: #a45569;
  --rose-soft: #f6ebef;
  --blue: #496e87;
  --orange: #b16f35;
  --green: #2f7b67;
  --clutter: #8b929c;
  --shadow: 0 16px 42px rgba(27, 35, 32, .12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at 86% -8%, rgba(109, 79, 194, .13), transparent 30rem),
    radial-gradient(circle at 3% 110%, rgba(15, 118, 110, .12), transparent 34rem),
    var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button,
input,
a {
  font: inherit;
}

button,
a,
input[type="range"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(36, 86, 200, .34);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 1440px);
  min-height: 100vh;
  min-height: 100dvh;
  margin-inline: auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.app-header {
  min-height: 55px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 16px 6px;
  border-bottom: 1px solid rgba(189, 196, 184, .86);
  background: rgba(253, 253, 251, .8);
  backdrop-filter: blur(15px);
}

.title-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--teal);
  font-size: 9px;
  font-weight: 850;
  letter-spacing: .16em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
  letter-spacing: -.018em;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(21px, 2.2vw, 31px);
  line-height: 1.04;
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
  line-height: 1.1;
}

h3 {
  margin-bottom: 0;
  font-size: 10px;
  line-height: 1.2;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.scope-chip,
.back-button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 830;
}

.scope-chip {
  padding: 0 12px;
  border: 1px solid #d9cdef;
  background: var(--violet-soft);
  color: #4b358d;
}

.back-button {
  gap: 6px;
  padding: 0 13px;
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 5px 15px rgba(27, 35, 32, .17);
}

.back-button:hover {
  background: var(--teal);
}

.back-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.view-nav {
  min-height: 33px;
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 4px;
  padding: 3px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 242, .84);
}

.view-nav a {
  min-width: 150px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 11px;
  border-radius: 7px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 850;
  text-decoration: none;
}

.view-nav a:hover {
  color: var(--ink);
  background: #fff;
}

body[data-view="partition"] [data-view-link="partition"],
body[data-view="hypotheses"] [data-view-link="hypotheses"],
body[data-view="inference"] [data-view-link="inference"] {
  background: #fff;
  box-shadow: 0 2px 8px rgba(27, 35, 32, .1);
  color: var(--teal);
}

.view-stage {
  min-height: 0;
  padding: 9px 12px;
}

.view-panel {
  height: 100%;
  min-height: 0;
  display: none;
}

body[data-view="partition"] [data-view-panel="partition"],
body[data-view="hypotheses"] [data-view-panel="hypotheses"],
body[data-view="inference"] [data-view-panel="inference"] {
  display: grid;
}

.partition-panel {
  grid-template-columns: minmax(0, 1.72fr) minmax(300px, .82fr);
  gap: 10px;
}

.scene-card,
.control-card,
.hypothesis-workbench,
.marginal-card,
.inference-card {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(253, 253, 251, .95);
  box-shadow: var(--shadow);
}

.scene-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px 6px;
}

.card-heading p,
.inference-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.35;
}

.family-badge,
.accuracy-pill {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .04em;
}

.family-a {
  background: var(--violet-soft);
  color: var(--violet);
}

.family-b {
  background: var(--teal-soft);
  color: var(--teal);
}

.measurement-scene,
.mini-scene {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: block;
}

.scene-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 14px;
  padding: 5px 13px 8px;
  color: var(--muted);
  font-size: 8px;
  font-weight: 760;
}

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

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

.object-one { background: var(--blue); }
.object-two { background: var(--orange); }
.ambiguous { background: linear-gradient(90deg, var(--blue) 50%, var(--orange) 50%); }
.clutter { border: 1.5px solid var(--clutter); background: #fff; }

.control-card {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px;
  scrollbar-width: thin;
}

.control-section + .control-section {
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.section-title,
.slider-label,
.method-heading,
.inference-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section-title output,
.method-heading output,
.hypothesis-flow output {
  color: var(--teal);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.slider-label {
  margin-top: 6px;
  color: var(--muted);
  font-size: 8px;
  font-weight: 780;
}

input[type="range"] {
  width: 100%;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--violet);
  cursor: pointer;
}

input[type="range"]:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.hint,
.fine-print,
.model-note {
  color: var(--muted);
  font-size: 8px;
  line-height: 1.35;
}

.hint {
  margin: 2px 0 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 5px;
}

.metric-grid div {
  padding: 5px 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  text-align: center;
}

.metric-grid span {
  min-height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 6.5px;
  font-weight: 760;
  line-height: 1.15;
}

.metric-grid strong {
  display: block;
  margin-top: 2px;
  color: var(--violet);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
}

button {
  min-height: 29px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 8px;
  font-weight: 840;
}

button:not(:disabled):hover {
  border-color: var(--teal);
  color: var(--teal);
}

button:disabled {
  cursor: not-allowed;
  opacity: .46;
}

.primary-button,
.reveal-button {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.primary-button:not(:disabled):hover,
.reveal-button:not(:disabled):hover {
  background: #095f59;
  color: #fff;
}

.reveal-button {
  width: 100%;
  margin-top: 8px;
}

.reveal-button[aria-pressed="true"] {
  border-color: var(--violet);
  background: var(--violet);
}

.boundary-note,
.projection-callout {
  margin-top: 7px;
  padding: 7px 8px;
  border-left: 3px solid var(--violet);
  border-radius: 7px;
  background: var(--violet-soft);
  color: #453577;
  font-size: 8px;
  font-weight: 690;
  line-height: 1.35;
}

.model-note {
  margin: 7px 0 0;
  padding: 6px 7px;
  border: 1px solid #ead0da;
  border-radius: 7px;
  background: #fff8fa;
  color: #735261;
}

.hypotheses-panel {
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, .72fr);
  gap: 10px;
}

.hypothesis-workbench {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
}

.hypothesis-flow {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 7px;
  border-bottom: 1px solid var(--line);
}

.flow-arrow {
  color: var(--muted);
  font-size: 12px;
}

.hypothesis-flow output {
  margin-left: auto;
}

.hypothesis-cards {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  overflow-y: auto;
  padding: 8px 10px 10px;
}

.hypothesis-card {
  min-width: 0;
  align-self: start;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.hypothesis-card.is-muted {
  opacity: .58;
}

.hypothesis-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 7px;
  font-weight: 850;
}

.hypothesis-card header strong {
  color: var(--teal);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
}

.hypothesis-card .weight-track,
.marginal-row .bar,
.visit-row .bar,
.bp-row .bar {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #e9ece6;
}

.hypothesis-card .weight-track {
  margin: 6px 0 5px;
}

.hypothesis-card .weight-track span,
.marginal-row .bar span,
.visit-row .bar span,
.bp-row .bar span {
  height: 100%;
  display: block;
  border-radius: inherit;
}

.hypothesis-card .weight-track span {
  background: var(--teal);
}

.hypothesis-card p {
  margin: 0;
  color: var(--muted);
  font-size: 7.5px;
  line-height: 1.3;
}

.marginal-card {
  overflow-y: auto;
  padding: 12px;
}

.marginal-card h2 {
  font-size: 20px;
}

.ambiguous-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin: 13px auto 10px;
  border: 7px solid transparent;
  border-radius: 50%;
  background:
    linear-gradient(#fff, #fff) padding-box,
    conic-gradient(var(--orange) 0 46%, var(--blue) 46% 77%, var(--green) 77% 91%, var(--clutter) 91%) border-box;
  box-shadow: 0 7px 20px rgba(27, 35, 32, .12);
}

.ambiguous-mark span {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  font-weight: 800;
}

.marginal-bars {
  display: grid;
  gap: 5px;
}

.marginal-row,
.visit-row,
.bp-row {
  display: grid;
  grid-template-columns: minmax(90px, 1fr) minmax(80px, 1.1fr) 34px;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 7.5px;
  font-weight: 730;
}

.marginal-row strong,
.visit-row strong,
.bp-row strong {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 8px;
  text-align: right;
}

.marginal-card .model-note {
  margin-top: 9px;
}

.inference-panel {
  grid-template-rows: auto minmax(0, 1fr);
  gap: 7px;
}

.inference-heading {
  align-items: flex-end;
  padding: 1px 4px;
}

.accuracy-pill {
  background: var(--ink);
  color: #fff;
}

.inference-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.inference-card {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(120px, 1fr) auto auto auto;
  overflow-y: auto;
  padding: 9px;
}

.gibbs-card {
  border-top: 4px solid var(--teal);
}

.bp-card {
  border-top: 4px solid var(--rose);
}

.method-heading > div {
  display: flex;
  align-items: center;
  gap: 6px;
}

.method-number {
  padding: 3px 5px;
  border-radius: 5px;
  background: var(--paper-soft);
  color: var(--muted);
  font-size: 7px;
  font-weight: 900;
}

.method-thesis {
  margin: 4px 0 5px;
  color: var(--muted);
  font-size: 8px;
  line-height: 1.3;
}

.method-thesis strong {
  color: var(--ink);
}

.mini-scene {
  min-height: 120px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.visit-list,
.bp-readout {
  min-height: 32px;
  display: grid;
  gap: 3px;
  margin-top: 5px;
}

.visit-row,
.bp-row {
  grid-template-columns: minmax(115px, 1.4fr) minmax(80px, 1fr) 33px;
  font-size: 7px;
}

.visit-row .bar span {
  background: var(--teal);
}

.bp-row .bar span {
  background: var(--rose);
}

.fine-print {
  margin: 5px 0 0;
}

.app-footer {
  min-height: 25px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 4px 15px 5px;
  color: var(--muted);
  font-size: 7.5px;
  font-weight: 720;
}

kbd {
  min-width: 18px;
  display: inline-block;
  padding: 1px 4px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font: 750 7px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
}

.noscript-note {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 30;
  max-width: 430px;
  padding: 10px 12px;
  border: 1px solid #d9cdef;
  border-radius: 9px;
  background: #faf8ff;
  box-shadow: var(--shadow);
  color: #4b3b78;
  font-size: 10px;
}

body.is-paused .measurement-scene,
body.is-paused .mini-scene {
  animation-play-state: paused !important;
}

@media (min-width: 801px) {
  .app-shell {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .view-stage {
    overflow: hidden;
  }
}

@media (max-width: 800px) {
  .app-shell {
    display: block;
  }

  .app-header,
  .app-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .view-nav {
    justify-content: flex-start;
    overflow-x: auto;
  }

  .view-nav a {
    flex: 0 0 auto;
  }

  .partition-panel,
  .hypotheses-panel,
  .inference-grid {
    grid-template-columns: 1fr;
  }

  .view-panel,
  body[data-view] [data-view-panel] {
    height: auto;
  }

  .scene-card,
  .hypothesis-workbench,
  .inference-card {
    min-height: 420px;
  }

  .control-card,
  .marginal-card,
  .inference-card {
    overflow: visible;
  }

  .inference-heading {
    align-items: flex-start;
    flex-direction: column;
  }

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

@media (max-width: 480px) {
  .app-header {
    padding: 10px 11px;
  }

  .scope-chip {
    display: none;
  }

  .view-stage {
    padding: 7px;
  }

  .card-heading,
  .hypothesis-flow {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .hypothesis-flow output {
    width: 100%;
    margin-left: 0;
  }

  .hypothesis-cards {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .app-footer {
    gap: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
