:root {
  --bg: #0e1013;
  --panel: #13161a;
  --panel-2: #181c21;
  --line: #252a31;
  --line-2: #323840;
  --ink: #ece7dc;
  --muted: #8f979f;
  --dim: #7d858d;
  --plan: #e8b04a;
  --tool_call: #5ec2e3;
  --tool_result: #7dce9d;
  --answer: #cbb4ff;
  --judge: #ff8ea2;
  --warn: #f0b35a;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--answer); outline-offset: 2px; }
.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; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(14, 16, 19, .85);
}
.who { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.name { font-family: var(--serif); font-size: 21px; letter-spacing: .01em; }
.role { font: 12px var(--mono); color: var(--muted); }
.links { display: flex; gap: 8px; }
.links a {
  font: 12.5px var(--mono); text-decoration: none;
  display: inline-flex; align-items: center; min-height: 36px;
  padding: 6px 13px; border: 1px solid var(--line-2); border-radius: 999px;
  transition: border-color .15s, background .15s;
}
.links a:hover { border-color: var(--ink); background: var(--panel-2); }

/* ---------- panes ---------- */
.panes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
  min-height: 0;
}
.pane { display: flex; flex-direction: column; min-height: 0; }
.chat { border-right: 1px solid var(--line); }
.trace { background: rgba(10, 12, 14, .55); }
.pane-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 24px;
  font: 11px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px dashed var(--line);
}
.pane-head h2 { margin: 0; font: inherit; letter-spacing: inherit; }
.live { display: inline-flex; align-items: center; gap: 7px; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--plan); }

.messages, .runs { flex: 1; overflow-y: auto; }
.messages { padding: 28px 24px 12px; }
.runs { padding: 20px 24px 40px; }

/* ---------- intro ---------- */
.intro { max-width: 34rem; margin-bottom: 28px; }
.intro h1 {
  font-family: var(--serif); font-weight: 400;
  font-size: clamp(26px, 3.1vw, 38px); line-height: 1.12; letter-spacing: -.01em;
  margin: 0 0 14px;
}
.intro h1 em { color: var(--muted); }
.intro p { color: var(--muted); margin: 0; max-width: 31rem; }

/* ---------- chat messages ---------- */
.msg {
  position: relative; max-width: 36rem; margin: 0 0 14px;
  padding: 12px 14px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer; overflow-wrap: anywhere;
  transition: border-color .2s, background .2s;
}
.msg.user p { margin: 0; }
.msg .typing { white-space: pre-wrap; }
.msg.user {
  margin-left: auto; width: fit-content; max-width: 80%;
  background: var(--panel-2); border-color: var(--line);
  font-family: var(--serif); font-size: 17px;
}
.msg.agent { background: transparent; border-color: var(--line); }
.msg.is-selected { border-color: var(--answer); background: rgba(203, 180, 255, .05); }
.msg.user.is-selected { background: rgba(203, 180, 255, .08); }
.msg .who-tag { display: block; font: 10.5px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--dim); margin-bottom: 6px; }
.msg.agent p { margin: 0 0 8px; }
.msg.agent ul { margin: 0 0 8px; padding-left: 18px; }
.msg.agent li { margin-bottom: 5px; }
.msg.agent strong { color: #fff; font-weight: 600; }
.msg .thinking { color: var(--muted); font: 13px var(--mono); }
.msg .thinking::after { content: "▍"; animation: blink 1s steps(1) infinite; margin-left: 2px; }
.msg-foot {
  display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center;
  margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line);
  font: 11.5px var(--mono); color: var(--muted);
}
.msg-foot button { font: inherit; cursor: pointer; background: none; }
.msg-foot .cite { padding: 2px 7px; border: 1px solid var(--line-2); border-radius: 4px; color: var(--ink); }
.msg-foot .cite:hover { border-color: var(--tool_result); color: var(--tool_result); }
.msg-foot .to-trace { border: 0; padding: 2px 0; color: var(--answer); text-decoration: underline; text-underline-offset: 3px; }
.msg-foot .score { color: var(--tool_result); }
.msg-foot .score.flag { color: var(--warn); }

/* ---------- composer ---------- */
.composer { padding: 14px 24px 16px; border-top: 1px solid var(--line); background: rgba(14, 16, 19, .9); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 999px;
  padding: 7px 13px; font-size: 13.5px; cursor: pointer; text-align: left;
  transition: border-color .15s, background .15s, opacity .15s;
}
.chip:hover { border-color: var(--plan); background: var(--panel-2); }
.chip.used { color: var(--muted); }
.chip.used::before { content: "↻ "; color: var(--dim); }
.is-busy .chip, .is-busy .ask button { opacity: .45; cursor: progress; }
.ask { display: flex; gap: 8px; }
.ask input {
  flex: 1; min-width: 0; padding: 10px 12px;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px;
}
.ask input:focus { border-color: var(--answer); }
.ask button {
  padding: 10px 16px; border-radius: 8px; border: 1px solid var(--ink);
  background: var(--ink); color: var(--bg); font-weight: 600; cursor: pointer;
}
.fine { margin: 10px 0 0; font: 11.5px var(--mono); color: var(--dim); }

/* ---------- trace: empty ---------- */
.empty { color: var(--muted); max-width: 30rem; padding-top: 12px; }
.legend { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 14px; font: 12px var(--mono); }
.legend li::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--c); }

.k-plan { --c: var(--plan); }
.k-tool_call { --c: var(--tool_call); }
.k-tool_result { --c: var(--tool_result); }
.k-answer { --c: var(--answer); }
.k-judge { --c: var(--judge); }

/* ---------- trace: run card ---------- */
.run {
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  margin-bottom: 18px; overflow: hidden;
  transition: border-color .2s, box-shadow .2s;
  scroll-margin-top: 12px;
}
.run.is-selected { border-color: var(--answer); box-shadow: 0 0 0 3px rgba(203, 180, 255, .09); }
.run-head {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.run-id { font: 11.5px var(--mono); color: var(--muted); }
.badge {
  font: 10.5px var(--mono); letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 4px; border: 1px solid var(--line-2); color: var(--muted); margin-left: 6px;
}
.badge { display: inline-block; white-space: nowrap; }
.badge.live { color: var(--tool_result); border-color: rgba(125, 206, 157, .45); }
.badge.recorded { color: var(--muted); }
.run-status { font: 11.5px var(--mono); color: var(--muted); }
.run-status.done { color: var(--tool_result); }
.run-q { grid-column: 1 / -1; margin: 0; font: 400 17px/1.35 var(--serif); overflow-wrap: anywhere; }
.run-link { all: unset; cursor: pointer; }
.run-link:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--dim); }
.run-link:focus-visible { outline: 2px solid var(--answer); outline-offset: 2px; }
.run.done:not(.is-selected) .steps, .run.done:not(.is-selected) .mode-note { display: none; }
.run.done:not(.is-selected) .run-status::after { content: " · show steps"; color: var(--dim); }
.mode-note {
  margin: 10px 16px 0; padding: 7px 10px; border-radius: 6px;
  font: 11.5px var(--mono); color: var(--muted); border: 1px dashed var(--line-2);
}
.guard { margin: 6px 0 0; font: 12px var(--mono); color: var(--warn); }
details.unsupported { margin-top: 8px; font: 12px var(--mono); color: var(--warn); }
details.unsupported summary { cursor: pointer; padding: 3px 0; }
details.unsupported ul { margin: 4px 0 0; padding-left: 18px; color: #d6d1c7; font-family: var(--sans); }
.skind { font-style: normal; font-size: 10px; color: var(--dim); margin-left: 4px; }
.k-wait { --c: var(--dim); }
.msg.notice { border-color: rgba(240, 179, 90, .45); }
.msg.notice .body p { margin: 0; }
.chips.nudge .chip:not(.used) { border-color: var(--plan); }
.composer-label { margin: 0 0 6px; font: 11px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.msg.notice .who-tag, .msg.withheld .who-tag { color: var(--warn); }
.msg.withheld { border-color: rgba(240, 179, 90, .45); }
.draft-note { margin: 0 0 6px; font: 11px var(--mono); color: var(--muted); }
.gate { margin: 10px 0 0; font: 12px var(--mono); }
.gate.pass { color: var(--tool_result); }
.gate.fail { color: var(--warn); }
.removed { margin: 4px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--muted); }
details.withheld-draft summary { cursor: pointer; padding: 3px 0; font: 12px var(--mono); color: var(--warn); }
.redacted-note { margin: 6px 0 0; font: 12px var(--mono); color: var(--warn); }
.run.stopped .run-status { color: var(--warn); }
.mname { min-width: 0; overflow-wrap: anywhere; }
.msg-foot .cite, .msg-foot .to-trace { min-height: 24px; }

/* ---------- trace: steps ---------- */
.steps { list-style: none; margin: 0; padding: 12px 16px 4px; }
.step { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 10px; padding-bottom: 12px; }
.step .rail { position: relative; }
.step .rail::before {
  content: ""; position: absolute; left: 7px; top: 14px; bottom: -14px; width: 1px; background: var(--line-2);
}
.step:last-child .rail::before { display: none; }
.step .dot {
  position: absolute; left: 3px; top: 5px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 18%, transparent);
}
.step.pending .dot { background: transparent; border: 1.5px solid var(--c); animation: pulse 1s ease-in-out infinite; }
.meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font: 12px var(--mono); }
.kind { color: var(--c); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; font-size: 11px; }
.meta .nm { color: var(--ink); }
.meta .lat, .meta .tok { color: var(--muted); }
.meta .lat { margin-left: auto; }
.step.pending .meta .lat { color: var(--c); }
.content { margin-top: 5px; font-size: 13.5px; color: #d6d1c7; }
.step.pending .content { color: var(--dim); font: 12.5px var(--mono); }
.content code, .content pre { font-family: var(--mono); font-size: 12.5px; }
.call { font: 12.5px var(--mono); color: var(--ink); overflow-wrap: anywhere; }
.call .fn { color: var(--tool_call); }
.call .arg { color: var(--muted); }
details.result summary { display: block; padding: 3px 0; cursor: pointer; font: 12.5px var(--mono); color: #cfe9d8; list-style: none; }
details.result summary::-webkit-details-marker { display: none; }
details.result summary::before { content: "▸ "; color: var(--dim); }
details.result[open] summary::before { content: "▾ "; }
details.result pre {
  margin: 8px 0 0; padding: 10px 12px; max-height: 260px; overflow: auto;
  background: #0b0d10; border: 1px solid var(--line); border-radius: 8px; color: #b9c2ba; white-space: pre-wrap; word-break: break-word;
}
.answer-text { padding: 8px 10px; border-radius: 6px; background: rgba(203, 180, 255, .05); }
.answer-text p { margin: 0 0 6px; }
.answer-text ul { margin: 0 0 6px; padding-left: 18px; }

/* ---------- judge ---------- */
.scores { display: grid; gap: 8px; }
.score-row { display: grid; grid-template-columns: 136px minmax(60px, 1fr) 40px 46px; gap: 10px; align-items: center; font: 12px var(--mono); }
.score-row .bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; position: relative; }
.score-row .bar i { position: absolute; inset: 0 auto 0 0; background: var(--judge); border-radius: 3px; }
.score-row .bar b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); }
.score-row .v { text-align: right; color: var(--ink); }
.verdict { font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; text-align: center; padding: 1px 0; border-radius: 4px; }
.verdict.pass { color: var(--tool_result); border: 1px solid rgba(125, 206, 157, .4); }
.verdict.fail { color: var(--warn); border: 1px solid rgba(240, 179, 90, .45); }
.rationale { grid-column: 1 / -1; margin: -3px 0 2px; color: var(--muted); font: 12px var(--sans); }

/* ---------- run summary ---------- */
.summary { border-top: 1px solid var(--line); padding: 12px 16px 14px; background: var(--panel-2); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat span { display: block; font: 10.5px var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--dim); }
.stat strong { font: 600 14px var(--mono); }
.wf { display: grid; gap: 4px; }
.wf-row { display: grid; grid-template-columns: 112px 1fr; gap: 10px; align-items: center; font: 11px var(--mono); color: var(--muted); }
.wf-row .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wf-track { position: relative; height: 8px; background: rgba(255, 255, 255, .03); border-radius: 2px; }
.wf-bar { position: absolute; top: 0; bottom: 0; border-radius: 2px; background: var(--c); min-width: 2px; }

.step .body { border-radius: 6px; }
.step.flash .body { animation: flash 1.8s ease-out; }
@keyframes flash { from { background: rgba(125, 206, 157, .22); box-shadow: 0 0 0 6px rgba(125, 206, 157, .22); } to { background: transparent; box-shadow: 0 0 0 6px transparent; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.step, .msg, .run { animation: rise .25s ease-out; }

/* ---------- after the first run: keep the composer compact on desktop ---------- */
@media (min-width: 900px) {
  .has-runs .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
  .has-runs .chip { flex: none; }
  .has-runs .chips { -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent); mask-image: linear-gradient(90deg, #000 88%, transparent); }
}

/* ---------- mobile: stack panes ---------- */
@media (max-width: 899px) {
  body { height: auto; min-height: 100vh; }
  .top { flex-wrap: wrap; padding: 12px 16px; }
  .who { gap: 2px 12px; }
  .panes { display: block; }
  .chat { border-right: 0; border-bottom: 1px solid var(--line); }
  .trace { min-height: 100vh; min-height: 100svh; }
  .messages, .runs { overflow: visible; }
  .messages { padding: 22px 16px 8px; }
  .composer { padding: 12px 16px 16px; }
  .runs { padding: 16px 12px 40px; }
  .pane-head { padding: 9px 16px; }
  .msg.user { max-width: 92%; }
  .score-row { grid-template-columns: minmax(40px, 1fr) 40px 44px; gap: 4px 8px; }
  .score-row > .mname { grid-column: 1 / -1; }
  .ask input { font-size: 16px; }
  .wf-row { grid-template-columns: 90px 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
