:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --border: #dddcd5;
  --text: #1d1d1b;
  --muted: #5e5e58;
  --accent: #3b4fc4;
  --accent-soft: #e6e9fb;
  --code-bg: #f3f3ef;
  --code-text: #23231f;
  --link: #2f45b8;
  --err: #b42318;
  --err-soft: #fdecea;
  --ok: #1f7a3d;
  --chip-user: #6b4fbf;
  --chip-system: #6a6a63;
  --chip-thinking: #9a6a00;
  --chip-assistant: #1f6fb2;
  --chip-tool_call: #1f7a3d;
  --chip-tool_result: #3f5f5a;
  --chip-note: #7a5a48;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1c1c1a;
    --surface-2: #252522;
    --border: #3a3a35;
    --text: #e9e8e2;
    --muted: #a3a29a;
    --accent: #8d9cf5;
    --accent-soft: #272c4a;
    --code-bg: #20201d;
    --code-text: #e4e3dc;
    --link: #9aa8ff;
    --err: #ff8a7a;
    --err-soft: #3a1f1c;
    --ok: #6fd08f;
    --chip-user: #a993f0;
    --chip-system: #a3a29a;
    --chip-thinking: #e2b13c;
    --chip-assistant: #6db3f0;
    --chip-tool_call: #6fd08f;
    --chip-tool_result: #8fc0b8;
    --chip-note: #d0a68e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--link); }

.wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header and tabs */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 24px;
  padding-top: 12px;
}
.brand h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.brand .sub { margin: 2px 0 10px; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  appearance: none;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius) var(--radius) 0 0;
  cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] {
  color: var(--accent);
  background: var(--bg);
  border-color: var(--border);
  box-shadow: inset 0 -2px 0 var(--bg);
  margin-bottom: -1px;
}
.tab .count { font-weight: 400; color: var(--muted); margin-left: 4px; font-size: 12px; }

main.wrap { padding-top: 16px; padding-bottom: 32px; min-height: 60vh; }

.status { padding: 24px 0; color: var(--muted); }
.status.error {
  color: var(--err);
  background: var(--err-soft);
  border: 1px solid var(--err);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.pipeline-desc { margin: 0 0 16px; color: var(--muted); max-width: 900px; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 290px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.sidebar { position: sticky; top: 104px; max-height: calc(100vh - 120px); overflow-y: auto; }
.problem-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.problem-card {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.problem-card:hover { border-color: var(--accent); }
.problem-card[aria-current="true"] { border-color: var(--accent); background: var(--accent-soft); }
.problem-card .pc-title { font-weight: 600; font-size: 14px; line-height: 1.35; display: block; }
.problem-card .pc-field { color: var(--accent); font-size: 12px; font-weight: 600; display: block; margin-top: 2px; }
.problem-card .pc-tagline { color: var(--muted); font-size: 13px; display: block; margin-top: 4px; line-height: 1.4; }
.problem-card .badges { margin-top: 6px; }

.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11.5px;
  line-height: 1.6;
  overflow: hidden;
  background: var(--surface);
}
.badge .bl { padding: 0 6px; color: var(--muted); background: var(--surface-2); }
.badge .bv { padding: 0 7px; font-weight: 600; }

/* Problem */
.problem { min-width: 0; }
.problem-empty { color: var(--muted); padding: 24px 0; }
.problem-head {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.problem-head h2 { margin: 0 0 4px; font-size: 22px; line-height: 1.3; letter-spacing: -0.01em; }
.problem-head .ph-field { color: var(--accent); font-weight: 600; font-size: 13px; }
.problem-head .ph-id { color: var(--muted); font-family: var(--mono); font-size: 12.5px; margin-top: 2px; word-break: break-all; }
.problem-head .ph-tagline { margin: 8px 0 0; color: var(--muted); }
.problem-head .badges { margin-top: 10px; }

details.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
details.section > summary {
  cursor: pointer;
  padding: 12px 18px;
  font-weight: 650;
  font-size: 16px;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before,
details.sub > summary::before {
  content: "▸";
  display: inline-block;
  color: var(--muted);
  transition: transform 0.12s ease;
  font-size: 0.9em;
}
details[open].section > summary::before,
details[open].sub > summary::before { transform: rotate(90deg); }
details.section > .section-body { padding: 0 18px 16px; border-top: 1px solid var(--border); }
.section-body > .block:first-child { margin-top: 14px; }

details.sub {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
details.sub > summary {
  cursor: pointer;
  padding: 8px 12px;
  font-weight: 600;
  list-style: none;
  display: flex;
  gap: 8px;
  align-items: center;
}
details.sub > summary::-webkit-details-marker { display: none; }
details.sub > .sub-body { padding: 0 12px 12px; }

.block { margin: 12px 0; min-width: 0; }
.block-title { font-weight: 600; font-size: 13.5px; margin: 0 0 6px; color: var(--muted); }

/* Markdown */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { line-height: 1.3; margin: 1.1em 0 0.4em; }
.md h1 { font-size: 1.35em; }
.md h2 { font-size: 1.2em; }
.md h3 { font-size: 1.07em; }
.md h4, .md h5, .md h6 { font-size: 1em; }
.md p { margin: 0.6em 0; }
.md ul, .md ol { margin: 0.5em 0; padding-left: 1.5em; }
.md li { margin: 0.2em 0; }
.md blockquote { margin: 0.6em 0; padding: 0.2em 0.9em; border-left: 3px solid var(--border); color: var(--muted); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.md code, .kv code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.08em 0.35em;
  border-radius: 4px;
}
.md pre code { background: none; padding: 0; font-size: inherit; }

/* Code */
.code-wrap { position: relative; border: 1px solid var(--border); border-radius: var(--radius); background: var(--code-bg); }
.code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--muted);
}
.code-head .ct { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.code-head .lang { opacity: 0.8; margin-left: 6px; }
pre {
  margin: 0;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--code-text);
  background: var(--code-bg);
  overflow: auto;
  white-space: pre;
  tab-size: 4;
}
.code-wrap pre { max-height: 520px; border-radius: 0 0 var(--radius) var(--radius); }
.md pre { border: 1px solid var(--border); border-radius: var(--radius); max-height: 520px; }
pre.wrap-lines { white-space: pre-wrap; overflow-wrap: anywhere; }

.btn {
  appearance: none;
  font: inherit;
  font-size: 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:focus-visible, .tab:focus-visible, .problem-card:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Tables */
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
td.num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.md .table-scroll { margin: 0.6em 0; }

/* Links, kv, files */
.links { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.links li { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px; background: var(--bg); overflow-wrap: anywhere; }
.links .lt { font-weight: 600; }
.links .lmeta { color: var(--muted); font-size: 13px; }
.links .lurl { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.links .lnote { font-size: 13.5px; margin-top: 2px; }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.files td.path { font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; }

/* Trajectory */
.traj { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); }
.traj-head { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.traj-title { font-weight: 650; font-size: 15px; }
.traj-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); margin-top: 4px; }
.traj-meta b { color: var(--text); font-weight: 600; }
.traj-summary { margin-top: 6px; font-size: 14px; }
.traj-controls { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-top: 8px; font-size: 13px; color: var(--muted); }
.traj-controls label { display: inline-flex; gap: 5px; align-items: center; cursor: pointer; }
.steps { list-style: none; margin: 0; padding: 6px; max-height: 70vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.step { border: 1px solid var(--border); border-left: 4px solid var(--chip-note); border-radius: 6px; background: var(--surface); padding: 6px 10px 8px; min-width: 0; }
.step-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; margin-bottom: 4px; }
.step-no { color: var(--muted); font-family: var(--mono); min-width: 2.5em; }
.chip { display: inline-block; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 700; color: var(--surface); background: var(--chip-note); line-height: 1.7; text-transform: lowercase; }
.step-label { font-family: var(--mono); font-weight: 600; overflow-wrap: anywhere; }
.step-time { color: var(--muted); margin-left: auto; font-family: var(--mono); font-size: 11.5px; }
.step pre { background: transparent; padding: 0; font-size: 12.5px; white-space: pre-wrap; overflow-wrap: anywhere; overflow: visible; }
.step pre.collapsed { max-height: 15.5em; overflow: hidden; -webkit-mask-image: linear-gradient(to bottom, #000 70%, transparent); mask-image: linear-gradient(to bottom, #000 70%, transparent); }
.step .expand { margin-top: 4px; }
.step-text-md { font-size: 14px; }
.step.r-user { border-left-color: var(--chip-user); }
.step.r-system { border-left-color: var(--chip-system); }
.step.r-thinking { border-left-color: var(--chip-thinking); }
.step.r-thinking pre { color: var(--muted); font-style: italic; }
.step.r-assistant { border-left-color: var(--chip-assistant); }
.step.r-tool_call { border-left-color: var(--chip-tool_call); }
.step.r-tool_result { border-left-color: var(--chip-tool_result); }
.step.is-error { border-left-color: var(--err); background: var(--err-soft); }
.chip.r-user { background: var(--chip-user); }
.chip.r-system { background: var(--chip-system); }
.chip.r-thinking { background: var(--chip-thinking); }
.chip.r-assistant { background: var(--chip-assistant); }
.chip.r-tool_call { background: var(--chip-tool_call); }
.chip.r-tool_result { background: var(--chip-tool_result); }
.chip.r-note { background: var(--chip-note); }
.chip.err { background: var(--err); }
.steps.hide-thinking .step.r-thinking { display: none; }
.no-steps { padding: 12px; color: var(--muted); }

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 24px;
  color: var(--muted);
  font-size: 12.5px;
  padding-top: 16px;
  padding-bottom: 24px;
  border-top: 1px solid var(--border);
}

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; max-height: none; overflow: visible; }
  .problem-list { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .problem-list li { flex: 0 0 240px; }
  .site-header { position: static; }
}

@media (max-width: 520px) {
  body { font-size: 14.5px; }
  .brand h1 { font-size: 18px; }
  .tab { padding: 7px 12px; }
  details.section > summary { padding: 10px 12px; }
  details.section > .section-body { padding: 0 12px 12px; }
  .problem-head { padding: 12px; }
  .kv { grid-template-columns: minmax(0, 1fr); }
  .kv dd { margin-bottom: 6px; }
}
