:root {
  color-scheme: light;
  --bg: #f4f6f7;
  --surface: #ffffff;
  --surface-muted: #eef2f3;
  --ink: #172126;
  --muted: #617078;
  --line: #d5dde0;
  --line-strong: #aebbc0;
  --teal: #14756f;
  --teal-soft: #e3f1ef;
  --blue: #3567a8;
  --blue-soft: #e8eff8;
  --coral: #b04b3f;
  --coral-soft: #f8eae8;
  --amber: #966319;
  --amber-soft: #f5eddd;
  --green: #287457;
  --green-soft: #e6f2ec;
  --focus: #086fc1;
  --shadow: 0 1px 2px rgb(24 42 48 / 7%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

button,
input,
select { font: inherit; letter-spacing: 0; }

button,
select { cursor: pointer; }

button:disabled { cursor: not-allowed; opacity: 0.42; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
[tabindex="0"]:focus-visible {
  outline: 3px solid rgb(8 111 193 / 28%);
  outline-offset: 2px;
}

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

h1 { margin-bottom: 1px; font-size: 18px; line-height: 1.3; font-weight: 740; }
h2 { margin-bottom: 0; font-size: 19px; line-height: 1.35; }
h3 { margin-bottom: 0; font-size: 15px; line-height: 1.4; }
h4 { margin: 0; font-size: 12px; line-height: 1.4; text-transform: uppercase; }
code,
pre { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 8px 12px;
  color: #fff;
  background: var(--focus);
  border-radius: 4px;
  transform: translateY(-160%);
}

.skip-link:focus { transform: translateY(0); }
.page-width { width: min(100%, 1600px); margin: 0 auto; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  border-bottom: 1px solid var(--line);
  background: rgb(255 255 255 / 96%);
  backdrop-filter: blur(10px);
}

.header-inner {
  min-height: 66px;
  padding: 9px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand { min-width: 250px; display: flex; align-items: center; gap: 10px; }
.brand > svg,
.brand > i { width: 25px; height: 25px; color: var(--teal); flex: 0 0 auto; }
.brand p { margin-bottom: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

.header-metrics {
  margin: 0;
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  flex-wrap: wrap;
}

.header-metrics div {
  min-width: 88px;
  padding: 5px 9px;
  border-left: 1px solid var(--line);
}

.header-metrics dt { color: var(--muted); font-size: 10px; line-height: 1.2; text-transform: uppercase; }
.header-metrics dd { margin: 1px 0 0; font-size: 14px; line-height: 1.25; font-weight: 720; font-variant-numeric: tabular-nums; }

.primary-nav { border-bottom: 1px solid var(--line); background: var(--surface); }
.nav-inner { height: 44px; padding: 0 22px; display: flex; align-items: stretch; gap: 20px; }
.nav-inner button {
  position: relative;
  padding: 0 2px;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-size: 13px;
  font-weight: 680;
}
.nav-inner button[aria-selected="true"] { color: var(--ink); }
.nav-inner button[aria-selected="true"]::after {
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 3px;
  background: var(--teal);
  content: "";
}

.analysis-toolbar { border-bottom: 1px solid var(--line); background: #f9fafb; }
.toolbar-inner {
  min-height: 57px;
  padding: 7px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  overflow-x: auto;
}

.segmented-control {
  min-width: max-content;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  border: 0;
}
.segmented-control legend {
  float: left;
  margin-right: 7px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 720;
  text-transform: uppercase;
}
.segmented-control button {
  min-height: 30px;
  padding: 4px 10px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-right: 0;
  font-size: 12px;
}
.segmented-control button:first-of-type { border-radius: 5px 0 0 5px; }
.segmented-control button:last-of-type { border-right: 1px solid var(--line-strong); border-radius: 0 5px 5px 0; }
.segmented-control button[aria-pressed="true"] { color: #fff; background: var(--teal); border-color: var(--teal); }
.quantile-control button { min-width: 40px; padding-inline: 8px; }
.cutoff-readout { min-width: max-content; margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.view { padding: 22px 22px 34px; }
.section-heading,
.panel-heading,
.trajectory-title-row,
.list-heading,
.trace-navigation {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.section-heading { margin-bottom: 16px; }
.eyebrow { margin-bottom: 3px; color: var(--muted); font-size: 10px; font-weight: 760; line-height: 1.25; text-transform: uppercase; }
.status-badge,
.metric-badge,
.outcome-badge,
.region-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  background: var(--surface);
  font-size: 11px;
  font-weight: 680;
  white-space: nowrap;
}
.status-badge[data-kind="ready"] { color: var(--green); background: var(--green-soft); border-color: #bdd9ca; }
.status-badge[data-kind="error"] { color: var(--coral); background: var(--coral-soft); border-color: #ecc2bd; }
.metric-badge { color: var(--teal); background: var(--teal-soft); border-color: #b9d9d5; }
.outcome-badge[data-correct="true"] { color: var(--green); background: var(--green-soft); border-color: #bdd9ca; }
.outcome-badge[data-correct="false"] { color: var(--coral); background: var(--coral-soft); border-color: #ecc2bd; }

.summary-grid {
  margin: 0 0 18px;
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.summary-grid div { min-width: 0; padding: 14px 15px; border-right: 1px solid var(--line); }
.summary-grid div:last-child { border-right: 0; }
.summary-grid dt { color: var(--muted); font-size: 11px; }
.summary-grid dd { margin: 3px 0 0; font-size: 23px; line-height: 1.2; font-weight: 730; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.summary-grid small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }

.overview-grid { display: grid; grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr); gap: 16px; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); }
.chart-panel { padding: 15px; }
.panel-heading { margin-bottom: 12px; align-items: flex-start; }
.panel-heading p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.canvas-frame { position: relative; width: 100%; height: 300px; }
.canvas-frame canvas { display: block; width: 100%; height: 100%; }

.alignment-panel { margin-top: 16px; padding: 15px; }
.alignment-summary {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(110px, 1fr));
  border-top: 1px solid var(--line);
}
.alignment-summary div { padding: 13px 12px 4px 0; }
.alignment-summary dt { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.alignment-summary dd { margin: 3px 0 0; font-size: 19px; font-weight: 720; font-variant-numeric: tabular-nums; }
.alignment-summary small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }

.trajectories-view {
  display: grid;
  grid-template-columns: minmax(260px, 315px) minmax(0, 1fr);
  align-items: start;
  gap: 18px;
}
.trajectories-view[hidden] { display: none; }
.trajectory-sidebar {
  position: sticky;
  top: 188px;
  max-height: calc(100vh - 208px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.list-heading { padding: 13px 14px; border-bottom: 1px solid var(--line); align-items: flex-end; }
.list-heading output { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.filters { padding: 12px; border-bottom: 1px solid var(--line); }
.search-control { position: relative; display: block; }
.search-control svg,
.search-control i { position: absolute; top: 9px; left: 9px; width: 15px; height: 15px; color: var(--muted); }
.search-control input { width: 100%; min-height: 34px; padding: 6px 8px 6px 31px; border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); }
.filter-grid { margin-top: 9px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filter-grid label,
.fork-filter,
.chunk-select { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 10px; font-weight: 690; text-transform: uppercase; }
.filter-grid select,
.fork-filter input,
.chunk-select select { min-width: 0; min-height: 32px; padding: 5px 7px; color: var(--ink); border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); font-size: 12px; text-transform: none; }
.fork-filter { margin-top: 9px; }
.secondary-button,
.load-more {
  min-height: 32px;
  padding: 5px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 660;
}
.secondary-button { width: 100%; margin-top: 9px; }
.secondary-button svg { width: 14px; height: 14px; }
.trajectory-list { min-height: 0; overflow-y: auto; }
.trajectory-item {
  width: 100%;
  padding: 10px 12px;
  display: block;
  color: var(--ink);
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.trajectory-item:hover { background: #f8fafb; }
.trajectory-item[aria-selected="true"] { background: var(--teal-soft); box-shadow: inset 3px 0 var(--teal); }
.trajectory-item-top { display: flex; justify-content: space-between; gap: 8px; }
.trajectory-item strong { min-width: 0; display: block; font-size: 12px; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trajectory-item p { height: 32px; margin: 4px 0; color: var(--muted); font-size: 11px; line-height: 16px; display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.trajectory-item-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.item-outcome { color: var(--coral); }
.item-outcome[data-correct="true"] { color: var(--green); }
.load-more { margin: 10px 12px; }

.trajectory-workspace { min-width: 0; }
.workspace-state {
  min-height: 430px;
  padding: 50px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  border: 1px dashed var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
}
.workspace-state h2 { margin-top: 12px; color: var(--ink); }
.workspace-state p { max-width: 420px; margin: 5px 0 0; }
.spinner { width: 24px; height: 24px; border: 3px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: spin 0.8s linear infinite; }
.workspace-state[data-kind="error"] .spinner { display: none; }
.workspace-state[data-kind="ready"] .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.trajectory-title-row { margin-bottom: 14px; align-items: flex-start; }
.trajectory-title-row h2 { overflow-wrap: anywhere; }
.trajectory-title-row p { margin: 3px 0 0; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.title-badges { display: flex; gap: 6px; }
.problem-band { margin-bottom: 16px; padding: 13px 15px; border-left: 3px solid var(--blue); background: var(--blue-soft); }
.problem-text { max-height: 150px; margin-top: 7px; overflow: auto; color: #263642; white-space: pre-wrap; overflow-wrap: anywhere; }
.trace-chart-panel { padding: 15px; }
.trace-heading { margin-bottom: 8px; }
.checkbox-control { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.checkbox-control input { width: 15px; height: 15px; accent-color: var(--teal); }
.chart-legend { margin-bottom: 5px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 10px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend i { width: 17px; height: 0; display: inline-block; border-top: 2px solid var(--teal); }
.chart-legend .legend-threshold { border-top-color: var(--coral); border-top-style: dashed; }
.chart-legend .legend-chunk { width: 0; height: 12px; border-top: 0; border-left: 1px solid var(--line-strong); }
.chart-legend .legend-mc { border-top-color: var(--amber); }
.trace-canvas-frame { height: 330px; }
.chart-tooltip {
  position: absolute;
  z-index: 4;
  max-width: 230px;
  padding: 6px 8px;
  color: #fff;
  background: #172126;
  border-radius: 4px;
  box-shadow: 0 2px 7px rgb(0 0 0 / 18%);
  font-size: 10px;
  line-height: 1.35;
  pointer-events: none;
  overflow-wrap: anywhere;
}
.trace-navigation { min-height: 58px; margin: 12px 0; padding: 8px 12px; border: 1px solid var(--line); background: var(--surface); }
.trace-navigation strong { display: block; max-width: 500px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fork-controls { display: flex; align-items: center; justify-content: flex-end; gap: 6px; color: var(--muted); font-size: 11px; }
.icon-button {
  width: 31px;
  height: 31px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
}
.icon-button svg { width: 16px; height: 16px; }

.trace-detail-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(260px, 0.55fr); gap: 12px; align-items: start; }
.response-panel,
.token-panel { padding: 14px; }
.chunk-select { min-width: 115px; }
.response-window {
  min-height: 280px;
  max-height: 520px;
  padding: 13px;
  overflow: auto;
  color: #263238;
  border: 1px solid var(--line);
  background: #fafbfb;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.response-window .token { border-radius: 2px; cursor: pointer; }
.response-window .token:hover { background: var(--blue-soft); }
.response-window .token.is-fork { color: #6f211a; background: #f7dcd8; box-shadow: inset 0 -2px var(--coral); }
.response-window .token.is-boundary { box-shadow: inset 0 -2px var(--blue); }
.response-window .token.is-selected { color: #fff; background: var(--teal); box-shadow: none; }
.response-omission { display: block; margin: 4px 0; color: var(--muted); font-family: inherit; font-size: 10px; font-style: normal; text-align: center; }
.region-badge { text-transform: capitalize; }
.token-metrics { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; border: 1px solid var(--line); background: var(--line); }
.token-metrics div { min-width: 0; padding: 8px; background: var(--surface); }
.token-metrics dt { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.token-metrics dd { margin: 2px 0 0; font-size: 12px; font-weight: 680; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.boundary-flags { min-height: 28px; margin: 10px 0; display: flex; gap: 5px; flex-wrap: wrap; }
.boundary-flag { padding: 3px 6px; color: var(--blue); border: 1px solid #bacde4; border-radius: 4px; background: var(--blue-soft); font-size: 9px; font-weight: 680; }
.alternatives-heading { margin: 13px 0 6px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.alternatives-heading span { color: var(--muted); font-size: 10px; }
.alternatives-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.alternatives-list li { min-height: 38px; padding: 6px 0; display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 7px; border-bottom: 1px solid var(--line); font-size: 11px; }
.alternative-rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.alternative-token { min-width: 0; font-family: "SFMono-Regular", Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alternative-prob { font-variant-numeric: tabular-nums; }
.empty-list { padding: 12px 0; color: var(--muted); font-size: 11px; }

.method-grid { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); background: var(--surface); }
.method-grid section { min-width: 0; padding: 17px; border-right: 1px solid var(--line); }
.method-grid section:last-child { border-right: 0; }
.method-index { display: block; margin-bottom: 20px; color: var(--teal); font-family: "SFMono-Regular", monospace; font-size: 11px; }
.method-grid p { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.run-details { margin: 16px 0 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.run-details div { padding: 12px 12px 0 0; }
.run-details dt { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.run-details dd { margin: 3px 0 0; font-size: 12px; overflow-wrap: anywhere; }

footer { border-top: 1px solid var(--line); background: var(--surface); }
.footer-inner { min-height: 56px; padding: 12px 22px; display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--muted); font-size: 11px; }
.footer-inner a { color: var(--blue); }

@media (max-width: 1120px) {
  .summary-grid { grid-template-columns: repeat(3, 1fr); }
  .summary-grid div:nth-child(3) { border-right: 0; }
  .summary-grid div:nth-child(n + 4) { border-top: 1px solid var(--line); }
  .method-grid { grid-template-columns: 1fr 1fr; }
  .method-grid section:nth-child(2) { border-right: 0; }
  .method-grid section:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .trace-detail-grid { grid-template-columns: 1fr; }
  .token-panel { position: static; }
}

@media (max-width: 820px) {
  .header-inner { align-items: flex-start; flex-direction: column; gap: 8px; }
  .header-metrics { justify-content: flex-start; }
  .header-metrics div:first-child { border-left: 0; padding-left: 0; }
  .toolbar-inner { padding-inline: 14px; }
  .view { padding: 17px 14px 28px; }
  .overview-grid { grid-template-columns: 1fr; }
  .alignment-summary { grid-template-columns: repeat(3, 1fr); }
  .trajectories-view { grid-template-columns: 1fr; }
  .trajectory-sidebar { position: static; max-height: 560px; }
  .canvas-frame { height: 270px; }
  .trace-canvas-frame { height: 300px; }
  .run-details { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 560px) {
  .header-inner { padding-inline: 14px; }
  .header-metrics div { min-width: 72px; padding: 4px 7px; }
  .nav-inner { padding-inline: 14px; gap: 18px; }
  .toolbar-inner { gap: 12px; }
  .segmented-control legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .cutoff-readout { margin-left: 0; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-grid div,
  .summary-grid div:nth-child(3) { border-right: 1px solid var(--line); border-top: 1px solid var(--line); }
  .summary-grid div:nth-child(1),
  .summary-grid div:nth-child(2) { border-top: 0; }
  .summary-grid div:nth-child(even) { border-right: 0; }
  .summary-grid div:first-child { grid-column: 1 / -1; border-right: 0; }
  .alignment-summary { grid-template-columns: 1fr 1fr; }
  .section-heading,
  .trajectory-title-row { align-items: flex-start; }
  .trajectory-title-row { flex-direction: column; }
  .title-badges { align-self: flex-start; }
  .trace-heading { flex-direction: column; }
  .trace-navigation { align-items: flex-start; flex-direction: column; }
  .fork-controls { width: 100%; justify-content: space-between; }
  .response-panel .panel-heading { align-items: flex-start; flex-direction: column; }
  .chunk-select { width: 100%; }
  .method-grid { grid-template-columns: 1fr; }
  .method-grid section { border-right: 0; border-top: 1px solid var(--line); }
  .method-grid section:first-child { border-top: 0; }
  .run-details { grid-template-columns: 1fr; }
  .footer-inner { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
