:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --ink: #1c2421;
  --muted: #65726c;
  --line: #d8ded5;
  --panel: #ffffff;
  --accent: #0b6f77;
  --accent-2: #c84f31;
  --shadow: 0 18px 40px rgba(27, 37, 32, 0.08);
}

* {
  box-sizing: border-box;
}

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,
select,
input {
  font: inherit;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 28px clamp(18px, 4vw, 56px);
  border-bottom: 1px solid var(--line);
  background: #fbfcf8;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 38px);
  letter-spacing: 0;
}

.topbar p,
.chartHeader p {
  margin-top: 6px;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button + button {
  background: #fff;
  color: var(--accent);
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.panelActions,
.panelHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panelActions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panelHeader button,
.panelActions button {
  min-height: 34px;
  padding: 0 12px;
  white-space: nowrap;
}

main {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: 18px;
  padding: 22px clamp(14px, 3vw, 36px) 34px;
}

.controls,
.chartShell,
.dataPanel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.controls {
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 18px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

select,
input[type="range"] {
  width: 100%;
}

select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  padding: 8px;
}

.chartShell {
  min-width: 0;
  padding: 18px;
}

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

#status {
  min-width: 126px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  padding: 6px 10px;
  text-align: center;
  white-space: nowrap;
}

canvas {
  width: 100%;
  aspect-ratio: 16 / 8.5;
  display: block;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  padding-top: 12px;
}

.legendItem {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.dataPanel {
  grid-column: 1 / -1;
  padding: 18px;
}

.bayesPanel {
  grid-column: 2;
}

.probabilityPanel {
  grid-column: 2;
}

.panelMeta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.tableWrap {
  margin-top: 12px;
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #eef3ee;
  z-index: 1;
}

td:nth-child(4),
td:nth-child(5) {
  text-align: right;
}

.compactTable {
  max-height: none;
}

.commentaryPanel {
  grid-column: 1 / -1;
}

.commentaryBody {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  max-width: 1100px;
  line-height: 1.6;
}

.commentaryBody p {
  color: #2d3833;
}

@media (max-width: 900px) {
  .topbar,
  .chartHeader {
    align-items: stretch;
    flex-direction: column;
  }

  main {
    grid-template-columns: 1fr;
  }

  .bayesPanel {
    grid-column: 1;
  }

  .probabilityPanel {
    grid-column: 1;
  }
}
