/* ML metric visualizer — figures that sit inside the prose.
   All colours derive from the site tokens, so the panels follow the
   light/dark toggle rather than the OS setting alone. */

:root {
  --mlv-point: #24405c;
  --mlv-error: #b03a2e;
  --mlv-good: #2f6b45;
  --mlv-tie: #8b8579;
  --mlv-diag: #a49d8e;
  --mlv-axis: #c6bfae;
  --mlv-ring: #fbfaf7;
  --mlv-square-opacity: 0.16;
  --mlv-pair-opacity: 0.32;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --mlv-point: #9dc0e0;
    --mlv-error: #e88a7d;
    --mlv-good: #8fcfa8;
    --mlv-tie: #7d786e;
    --mlv-diag: #6a6f7a;
    --mlv-axis: #464b55;
    --mlv-ring: #15171b;
    --mlv-square-opacity: 0.2;
    --mlv-pair-opacity: 0.38;
  }
}

:root[data-theme="dark"] {
  --mlv-point: #9dc0e0;
  --mlv-error: #e88a7d;
  --mlv-good: #8fcfa8;
  --mlv-tie: #7d786e;
  --mlv-diag: #6a6f7a;
  --mlv-axis: #464b55;
  --mlv-ring: #15171b;
  --mlv-square-opacity: 0.2;
  --mlv-pair-opacity: 0.38;
}

/* ---------- Figure shell ---------- */
.prose .mlv-figure {
  margin: 1.8rem 0 2rem;
}

.mlv-figure figcaption {
  font-family: var(--font-sans);
  font-size: 0.76rem;
  line-height: 1.5;
  color: var(--ink-muted);
  margin-top: 0.6rem;
  max-width: 32rem;
}

.mlv-figure figcaption b,
.mlv-figure figcaption strong {
  color: var(--ink);
  font-weight: 600;
}

.mlv-readout {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.3rem;
  margin-bottom: 0.6rem;
}

.mlv-readout__label {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.mlv-readout__value {
  font-family: var(--font-mono);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.mlv-plot {
  width: 100%;
}

.mlv-svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  overflow: visible;
  touch-action: none;
}

/* A single panel stays close to the text measure; a trio spans the column.
   Both are centred: auto margins go equal-and-negative when the box is wider
   than the column, which is exactly what the trio wants. */
.prose > .mlv-figure,
.prose > article > .mlv-figure {
  max-width: 22rem;
  margin-inline: auto;
}

.mlv-trio,
.mlv-controls--wide,
.mlv-caption--wide {
  width: max(100%, min(44rem, 100vw - 3rem));
  margin-inline: auto;
}

.mlv-trio {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.2rem;
  margin-block: 1.8rem 0.6rem;
}

.mlv-trio .mlv-figure {
  margin: 0;
  min-width: 0;
}

.mlv-trio .mlv-readout {
  display: block;
  padding-bottom: 0.25rem;
  margin-bottom: 0.4rem;
}

.mlv-trio .mlv-readout__label {
  display: block;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
}

.mlv-trio .mlv-readout__value {
  font-size: 0.82rem;
}

@media (max-width: 34em) {
  .mlv-trio {
    grid-template-columns: 1fr;
    gap: 1.6rem;
  }
}

/* ---------- Controls ---------- */
.mlv-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  margin: 1.4rem 0;
  padding: 0.7rem 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
}

.mlv-button {
  font-family: var(--font-sans);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink);
  background: none;
  border: 1px solid var(--rule-strong);
  border-radius: 2px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.mlv-button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* The group-move toggle stays lit while it is on. */
.mlv-button.is-active {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.mlv-controls--wide .mlv-hint {
  flex: 1 1 16rem;
}

.mlv-hint {
  font-family: var(--font-sans);
  font-size: 0.76rem;
  color: var(--ink-muted);
}

/* ---------- Prompts ---------- */
.mlv-prompts {
  margin: 1.6rem 0 2rem;
  padding: 0.9rem 1.1rem 1rem;
  border: 1px solid var(--rule);
  border-left: 3px solid var(--rule-strong);
  border-radius: 2px;
}

.prose .mlv-prompts h4 {
  font-family: var(--font-sans);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 0.7rem;
}

.prose .mlv-prompts ol {
  margin: 0;
}

.prose .mlv-prompts li {
  font-size: 0.92rem;
}

.mlv-answer {
  margin-top: 0.9rem;
  font-size: 0.9rem;
}

.mlv-answer summary {
  font-family: var(--font-sans);
  font-size: 0.76rem;
  color: var(--ink-muted);
  cursor: pointer;
}

.mlv-answer summary:hover {
  color: var(--accent);
}

.prose .mlv-answer p {
  margin: 0.6rem 0 0;
  font-size: 0.9rem;
  color: var(--ink-muted);
}

/* ---------- Plot marks ---------- */
.mlv-svg text {
  font-family: var(--font-sans);
  font-size: 9px;
  fill: var(--ink-faint);
}

.mlv-trio .mlv-svg text {
  font-size: 8px;
}

.mlv-axis-label {
  font-size: 8.5px;
  letter-spacing: 0.03em;
  fill: var(--ink-muted);
}

.mlv-trio .mlv-axis-label {
  font-size: 7.5px;
}

.mlv-axis line,
.mlv-axis path {
  stroke: var(--mlv-axis);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.mlv-diag {
  stroke: var(--mlv-diag);
  stroke-dasharray: 4 4;
  stroke-width: 1.2;
}

.mlv-rule {
  stroke: var(--mlv-diag);
  stroke-width: 1;
  opacity: 0.7;
}

.mlv-threshold {
  stroke: var(--mlv-diag);
  stroke-dasharray: 2 4;
  stroke-width: 1;
  opacity: 0.8;
}

.mlv-resid {
  stroke: var(--mlv-error);
  stroke-width: 2.5;
  opacity: 0.55;
  stroke-linecap: round;
}

.mlv-square {
  fill: var(--mlv-error);
  opacity: var(--mlv-square-opacity);
}

.mlv-pair {
  stroke-width: 1.2;
  opacity: var(--mlv-pair-opacity);
}

.mlv-pair--conc {
  stroke: var(--mlv-good);
}

.mlv-pair--disc {
  stroke: var(--mlv-error);
}

.mlv-pair--tie {
  stroke: var(--mlv-tie);
}

/* AUC draws every positive/negative pair, so it needs a lighter hand. */
[data-mlv="auc"] .mlv-pair {
  opacity: 0.14;
}

.mlv-bin {
  fill: var(--mlv-error);
  stroke: var(--mlv-ring);
  stroke-width: 1;
}

.mlv-point {
  fill: var(--mlv-point);
  stroke: var(--mlv-ring);
  stroke-width: 1;
  cursor: grab;
}

.mlv-point.is-dragging,
.mlv-point:active {
  cursor: grabbing;
}

[data-mlv="mae"] .mlv-point,
[data-mlv="mse"] .mlv-point,
[data-mlv="cindex"] .mlv-point {
  cursor: ns-resize;
}

[data-mlv="brier"] .mlv-point,
[data-mlv="mce"] .mlv-point,
[data-mlv="auc"] .mlv-point {
  cursor: ew-resize;
}

/* ---------- Legend ---------- */
ul.mlv-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
  list-style: none;
  margin: 0.8rem 0 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.prose ul.mlv-legend li + li {
  margin-top: 0;
}

.mlv-legend li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.mlv-swatch {
  width: 1.1rem;
  height: 0;
  border-top: 3px solid currentColor;
  display: inline-block;
}

.mlv-swatch--conc {
  color: var(--mlv-good);
}

.mlv-swatch--disc {
  color: var(--mlv-error);
}

.mlv-swatch--point {
  color: var(--mlv-point);
  height: 0.55rem;
  width: 0.55rem;
  border: 0;
  border-radius: 50%;
  background: currentColor;
}

@media print {
  .mlv-controls {
    display: none;
  }
}
