:root {
  --ink: #17212b;
  --muted: #5d6974;
  --line: #d7dde2;
  --line-strong: #bdc7ce;
  --soft: #f5f7f8;
  --soft-strong: #edf1f2;
  --panel: #ffffff;
  --teal: #087f73;
  --teal-dark: #075e57;
  --teal-soft: #e2f3f0;
  --gold: #9c6a06;
  --gold-soft: #fff3d6;
  --red: #a13d3d;
  --page-pad: max(18px, calc((100vw - 1480px) / 2));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--panel);
  letter-spacing: 0;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; font-size: 14px; line-height: 1.5; }
button, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app-header {
  min-height: 92px;
  padding: 20px var(--page-pad);
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  color: white;
  background: #17212b;
  border-bottom: 4px solid var(--teal);
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 27px; line-height: 1.15; font-weight: 690; }
h2 { margin-bottom: 0; font-size: 20px; line-height: 1.25; font-weight: 680; }
h3 { margin: 0; font-size: 17px; line-height: 1.3; }
.eyebrow { margin-bottom: 5px; color: #65737e; font-size: 11px; font-weight: 720; text-transform: uppercase; }
.context-kind { color: var(--teal-dark); }
.app-header .eyebrow { color: #9ed4ce; }
.header-meta { max-width: 60%; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; color: #d6dee4; font-size: 12px; text-align: right; }
.header-meta strong { color: white; font-size: 13px; }

.view-tabs {
  height: 48px;
  padding: 0 var(--page-pad);
  display: flex;
  gap: 26px;
  align-items: stretch;
  background: white;
  border-bottom: 1px solid var(--line);
}
.tab { border: 0; border-bottom: 3px solid transparent; padding: 0 2px; background: transparent; color: var(--muted); font-weight: 650; }
.tab:hover { color: var(--teal-dark); }
.tab.active { color: var(--ink); border-bottom-color: var(--teal); }

main { width: 100%; }
.control-band {
  position: sticky;
  top: 0;
  z-index: 8;
  min-height: 72px;
  padding: 11px var(--page-pad);
  display: grid;
  grid-template-columns: minmax(240px, .9fr) minmax(400px, 1.8fr) auto;
  align-items: end;
  gap: 14px;
  background: #f8fafb;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgb(23 33 43 / 8%);
}

label { min-width: 0; color: var(--muted); font-size: 11px; font-weight: 670; }
select {
  width: 100%;
  height: 38px;
  margin-top: 4px;
  padding: 0 30px 0 10px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
}
button:focus-visible, select:focus-visible { outline: 3px solid #9bd1ca; outline-offset: 1px; }
.select-with-actions { margin-top: 4px; display: grid; grid-template-columns: 38px minmax(0, 1fr) 38px; gap: 6px; }
.select-with-actions select { margin-top: 0; }
.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  color: var(--ink);
  background: white;
  font-size: 17px;
  font-weight: 700;
}
.icon-button:hover:not(:disabled) { border-color: var(--teal); color: var(--teal-dark); }
.icon-button:disabled { color: #aab3ba; background: var(--soft); cursor: default; }
.control-status { min-width: 100px; margin: 0 0 9px; color: var(--muted); font-size: 12px; text-align: right; white-space: nowrap; }

.loading { padding: 64px var(--page-pad); text-align: center; color: var(--muted); }
#example-content > section, #scaling-view { padding: 30px var(--page-pad); border-bottom: 1px solid var(--line); }
.context-section, .judge-section { background: #f8fafb; }
.rubric-section, .candidate-section { background: white; }
.section-heading { margin-bottom: 18px; display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.section-subtitle { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.mono { max-width: 55%; overflow-wrap: anywhere; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }

.context-meta {
  max-width: 980px;
  margin: 0 0 20px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--line);
}
.context-meta div { min-width: 0; padding: 9px 14px 9px 0; border-bottom: 1px solid var(--line); }
.context-meta dt { color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.context-meta dd { margin: 2px 0 0; overflow-wrap: anywhere; font-size: 12px; font-weight: 620; }

.structured-text { max-width: 88ch; color: #26333d; font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; }
.structured-text > :first-child { margin-top: 0; }
.structured-text > :last-child { margin-bottom: 0; }
.structured-text p { margin: 0 0 12px; }
.structured-text h3, .structured-text h4 { margin: 20px 0 8px; color: var(--ink); font-size: 14px; }
.structured-text ol, .structured-text ul { margin: 8px 0 15px; padding-left: 24px; }
.structured-text li { margin: 6px 0; padding-left: 3px; }
.structured-text strong { color: var(--ink); font-weight: 720; }
.clampable { position: relative; overflow: hidden; }
.context-text.is-clamped { max-height: 340px; }
.rubric-text.is-clamped { max-height: 430px; }
.clampable.is-clamped { padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.text-button { margin-top: 10px; padding: 4px 0; border: 0; background: transparent; color: var(--teal-dark); font-size: 12px; font-weight: 700; }
.text-button:hover { text-decoration: underline; }

.local-controls { margin: -10px 0 18px; display: flex; justify-content: flex-end; gap: 10px; }
.local-controls label { width: min(260px, 100%); }
.judge-controls label { width: min(230px, 48%); }

details { margin-top: 13px; background: white; border: 1px solid var(--line); border-radius: 6px; }
summary { padding: 11px 13px; display: flex; justify-content: space-between; gap: 16px; cursor: pointer; color: #34424e; font-size: 13px; font-weight: 650; }
.trace-size { color: var(--muted); font-size: 11px; font-weight: 500; white-space: nowrap; }
details > pre, details > div { margin: 0; padding: 16px; border-top: 1px solid var(--line); }
pre { max-height: 600px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: #27343e; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.55; }
.trace-stack { max-width: 1120px; }
.trace-content { max-width: none; background: #fbfcfc; }
.message { padding: 12px 0; border-top: 1px solid var(--line); }
.message:first-child { border-top: 0; }
.message-role { color: var(--teal); font-size: 11px; font-weight: 720; text-transform: uppercase; }
.message-content { max-width: 100ch; margin-top: 5px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; line-height: 1.55; }

.judge-heading { align-items: start; }
.reward-metrics { max-width: 700px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.metric { min-width: 94px; padding: 8px 10px; background: white; border-left: 3px solid var(--teal); }
.metric.primary { background: var(--teal-soft); border-left-color: var(--teal-dark); }
.metric span { display: block; color: var(--muted); font-size: 10px; }
.metric strong { display: block; margin-top: 1px; font-size: 15px; font-variant-numeric: tabular-nums; }

.candidate-heading { align-items: end; }
.score-key { margin: 8px 0 0; color: var(--muted); font-size: 11px; }
.score-key strong:first-child { color: var(--teal-dark); }
.score-key strong:last-of-type { color: var(--gold); }
.score-key span { margin: 0 5px; color: var(--line-strong); }
.candidate-controls { min-width: min(560px, 55%); display: flex; align-items: end; justify-content: flex-end; gap: 14px; }
.candidate-controls label { width: 150px; }
.segmented { height: 38px; display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line-strong); border-radius: 5px; overflow: hidden; }
.segmented button { min-width: 132px; padding: 0 11px; border: 0; border-right: 1px solid var(--line-strong); background: white; color: var(--muted); font-size: 12px; font-weight: 650; }
.segmented button:last-child { border-right: 0; }
.segmented button.active { color: var(--teal-dark); background: var(--teal-soft); }

.candidate-workspace { display: grid; grid-template-columns: minmax(470px, .9fr) minmax(0, 1.45fr); gap: 28px; align-items: start; }
.candidate-index { max-height: 690px; overflow: auto; border: 1px solid var(--line); }
.candidate-index-head, .candidate-index-row {
  display: grid;
  grid-template-columns: 42px 66px 66px 66px minmax(150px, 1fr);
  align-items: center;
  column-gap: 8px;
}
.candidate-index-head {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 38px;
  padding: 0 10px;
  color: var(--muted);
  background: var(--soft-strong);
  border-bottom: 1px solid var(--line-strong);
  font-size: 10px;
  font-weight: 720;
  text-transform: uppercase;
}
.candidate-index-row {
  width: 100%;
  min-height: 50px;
  padding: 7px 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  background: white;
  text-align: left;
}
.candidate-index-row:last-child { border-bottom: 0; }
.candidate-index-row:hover { background: #f8fbfa; }
.candidate-index-row.active { background: var(--teal-soft); box-shadow: inset 3px 0 0 var(--teal); }
.candidate-index-row.top-proxy:not(.active) { box-shadow: inset 3px 0 0 var(--teal); }
.candidate-index-row.top-gold:not(.active) { box-shadow: inset 3px 0 0 var(--gold); }
.candidate-number { color: var(--muted); font-size: 11px; font-weight: 700; }
.score-number { font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 690; }
.score-number.proxy { color: var(--teal-dark); }
.score-number.gold { color: var(--gold); }
.candidate-preview { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #3c4852; font-size: 11px; }

.candidate-detail { min-width: 0; position: sticky; top: 88px; padding: 4px 0 4px 22px; border-left: 3px solid var(--line-strong); }
.candidate-detail-heading { display: flex; justify-content: space-between; align-items: start; gap: 20px; }
.candidate-detail-heading .mono { max-width: 45%; text-align: right; }
.detail-scores { margin: 16px 0 18px; display: grid; grid-template-columns: repeat(4, minmax(90px, 1fr)); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-score { padding: 10px 12px; border-right: 1px solid var(--line); }
.detail-score:first-child { padding-left: 0; }
.detail-score:last-child { border-right: 0; }
.detail-score span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.detail-score strong { display: block; margin-top: 2px; font-size: 17px; font-variant-numeric: tabular-nums; }
.detail-score small { display: block; margin-top: 1px; color: var(--muted); font-size: 10px; }
.response-comparison { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.response-pane { min-width: 0; padding: 16px 18px 0; }
.response-pane:first-child { padding-left: 0; border-right: 1px solid var(--line); }
.response-pane:last-child { padding-right: 0; }
.response-pane-heading { min-height: 33px; margin-bottom: 13px; display: flex; align-items: start; justify-content: space-between; gap: 10px; }
.response-pane-heading h4 { margin: 0; color: var(--ink); font-size: 12px; font-weight: 720; text-transform: uppercase; }
.candidate-response-pane { border-top: 3px solid var(--teal); }
.reference-response-pane { border-top: 3px solid var(--gold); }
.candidate-response { max-width: none; font-size: 14px; line-height: 1.7; }
.match-badge { flex: 0 0 auto; padding: 2px 6px; color: var(--teal-dark); background: var(--teal-soft); border: 1px solid #a9d8d1; border-radius: 3px; font-size: 9px; font-weight: 740; text-transform: uppercase; }
.match-badge[hidden] { display: none; }

#scaling-view { background: #f8fafb; }
.scaling-heading { margin-bottom: 22px; }
.summary-matrix { margin-bottom: 28px; border: 1px solid var(--line); background: white; }
.summary-row { display: grid; grid-template-columns: minmax(250px, 1.45fr) repeat(3, minmax(150px, .75fr)); border-bottom: 1px solid var(--line); }
.summary-row:last-child { border-bottom: 0; }
.summary-row > div { min-width: 0; padding: 12px 14px; border-right: 1px solid var(--line); }
.summary-row > div:last-child { border-right: 0; }
.summary-row.header { color: var(--muted); background: var(--soft-strong); font-size: 10px; font-weight: 720; text-transform: uppercase; }
.summary-split { font-size: 12px; font-weight: 680; }
.summary-value strong { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.summary-value span { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.plot-grid { display: grid; grid-template-columns: 1fr; gap: 22px; }
.plot-grid figure { margin: 0; }
.plot-grid figcaption { margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.plot-grid img { width: 100%; height: auto; display: block; background: white; border: 1px solid var(--line); }
.scaling-table { margin-top: 26px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); }
.scaling-row { padding: 13px; background: white; }
.scaling-row span { display: block; color: var(--muted); font-size: 11px; }
.scaling-row strong { display: block; margin-top: 4px; font-size: 16px; font-variant-numeric: tabular-nums; }
.scaling-row small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.bestk-section { margin-top: 38px; padding-top: 30px; border-top: 2px solid var(--line-strong); }
.bestk-section[hidden] { display: none; }
.bestk-table-wrap { overflow-x: auto; border: 1px solid var(--line); background: white; }
.bestk-table { width: 100%; min-width: 900px; border-collapse: collapse; text-align: left; }
.bestk-table th, .bestk-table td { padding: 12px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); vertical-align: top; }
.bestk-table tr > :last-child { border-right: 0; }
.bestk-table tbody tr:last-child > * { border-bottom: 0; }
.bestk-table thead th { color: var(--muted); background: var(--soft-strong); font-size: 10px; font-weight: 720; text-transform: uppercase; }
.bestk-table tbody th { width: 27%; color: var(--ink); font-size: 12px; font-weight: 680; }
.bestk-table tbody td { min-width: 145px; }
.bestk-table td strong { display: block; color: var(--teal-dark); font-size: 17px; font-variant-numeric: tabular-nums; }
.bestk-table td span { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bestk-table .bestk-judge { color: #34424e; font-size: 11px; font-weight: 650; }
.bestk-table .bestk-random strong { color: var(--gold); }
.bestk-table .bestk-lift { background: #f3faf8; }
.bestk-table .bestk-lift.negative { background: #fff6f5; }
.bestk-table .bestk-lift.negative strong { color: var(--red); }

@media (max-width: 1050px) {
  .control-band { grid-template-columns: minmax(200px, .8fr) minmax(300px, 1.5fr) auto; }
  .candidate-workspace { grid-template-columns: minmax(420px, 1fr) minmax(0, 1.1fr); gap: 20px; }
  .candidate-index-head, .candidate-index-row { grid-template-columns: 36px 58px 58px 58px minmax(100px, 1fr); column-gap: 5px; }
  .detail-scores { grid-template-columns: repeat(2, minmax(90px, 1fr)); }
  .detail-score:nth-child(2) { border-right: 0; }
  .detail-score:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .response-comparison { grid-template-columns: 1fr; }
  .response-pane { padding: 16px 0 18px; }
  .response-pane:first-child { border-right: 0; }
  .response-pane:last-child { border-top-width: 3px; }
}

@media (max-width: 800px) {
  .app-header { align-items: start; flex-direction: column; gap: 10px; }
  .header-meta { max-width: none; align-items: flex-start; text-align: left; }
  .control-band { position: static; grid-template-columns: 1fr; }
  .control-status { margin: 0; text-align: left; }
  #example-content > section, #scaling-view { padding-top: 24px; padding-bottom: 24px; }
  .section-heading, .candidate-heading { align-items: start; flex-direction: column; }
  .local-controls { justify-content: flex-start; }
  .judge-heading { gap: 16px; }
  .reward-metrics { justify-content: flex-start; }
  .candidate-controls { min-width: 0; width: 100%; justify-content: flex-start; flex-wrap: wrap; }
  .candidate-workspace { grid-template-columns: 1fr; }
  .candidate-index { max-height: 540px; }
  .candidate-detail { position: static; padding: 18px 0 0; border-top: 3px solid var(--line-strong); border-left: 0; }
  .summary-row { grid-template-columns: minmax(170px, 1.2fr) repeat(3, minmax(100px, .75fr)); }
  .scaling-table { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .app-header { padding-top: 17px; padding-bottom: 17px; }
  h1 { font-size: 23px; }
  .context-meta { grid-template-columns: 1fr; }
  .section-heading .mono { max-width: 100%; }
  .judge-controls { width: 100%; flex-direction: column; }
  .judge-controls label, .rubric-controls label { width: 100%; }
  .candidate-controls { display: grid; grid-template-columns: 1fr; }
  .candidate-controls label { width: 100%; }
  .segmented button { min-width: 0; }
  .candidate-index-head, .candidate-index-row { grid-template-columns: 32px 54px 54px 54px minmax(70px, 1fr); padding-left: 7px; padding-right: 7px; }
  .candidate-preview { font-size: 10px; }
  .candidate-detail-heading { flex-direction: column; gap: 8px; }
  .candidate-detail-heading .mono { max-width: 100%; text-align: left; }
  .summary-matrix { overflow-x: auto; }
  .summary-row { min-width: 650px; }
  .scaling-table { grid-template-columns: 1fr; }
  pre { max-height: none; }
}
