/* Standalone case-trace viewer. Native theme, shares the write-up palette.
   Modeled on experiment #23's trace viewer: clear model inputs, readable loop. */
:root{
  --ink:#1a1a1a; --muted:#5c5c5c; --faint:#8a8a8a;
  --bg:#ffffff; --panel:#f7f7f5; --rule:#e2e2dd; --rule2:#eceae4;
  --harness:#2f6f7d; --retrieval:#8a6d3b; --imaging:#8a3f57;
  --accent:#c0561a; --good:#2e6e4e; --mid:#8a5a12; --bad:#9c2f2a;
  --sys:#7a7a86; --user:#2f6f7d; --tool:#8a6d3b; --rag:#5a7d3b; --answer:#c0561a; --reason:#6a5a8a;
}
*{box-sizing:border-box}
html{scroll-behavior:smooth}
body{margin:0; background:var(--bg); color:var(--ink);
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
  font-size:15px; line-height:1.55; -webkit-font-smoothing:antialiased}
h1,h2,h3,h4,.serif{font-family:Georgia,"Times New Roman",serif}
a{color:var(--accent)}
code,pre{font-family:ui-monospace,Menlo,Consolas,monospace}

/* top bar */
#topbar{display:flex; flex-wrap:wrap; align-items:flex-end; gap:12px 24px;
  padding:18px 26px; border-bottom:1px solid var(--rule); background:#fff; position:sticky; top:0; z-index:20}
#topbar h1{font-size:1.4rem; margin:0 0 .15em; letter-spacing:-.01em}
#topbar .sub{margin:0; color:var(--muted); font-size:.9rem; max-width:720px}
#topbar .sub a{white-space:nowrap}
.backlink{font-size:.85rem; text-decoration:none; padding:6px 13px; border:1px solid var(--rule);
  border-radius:20px; color:var(--muted); white-space:nowrap}
.backlink:hover{border-color:var(--accent); color:var(--accent)}

#layout{display:grid; grid-template-columns:288px 1fr; gap:0; align-items:start}
@media(max-width:900px){#layout{grid-template-columns:1fr}}

/* controls */
#controls{padding:18px 18px 40px; border-right:1px solid var(--rule); position:sticky; top:74px;
  max-height:calc(100vh - 74px); overflow:auto; background:var(--panel)}
@media(max-width:900px){#controls{position:static; max-height:none; border-right:0; border-bottom:1px solid var(--rule)}}
.ctl-group{margin-bottom:18px}
.ctl-label{display:block; font-family:Georgia,serif; font-size:.82rem; font-weight:700;
  text-transform:uppercase; letter-spacing:.05em; color:var(--muted); margin-bottom:6px}
.ctl-label .hint{font-weight:400; text-transform:none; letter-spacing:0; color:var(--faint)}
#controls select{width:100%; font-size:.9rem; padding:7px 8px; border:1px solid var(--rule);
  border-radius:6px; background:#fff; font-family:inherit}
.case-meta{margin-top:6px; font-size:.8rem; color:var(--muted); line-height:1.4}
.vfamily{margin-bottom:12px}
.vfamily-label{font-size:.78rem; font-weight:700; color:var(--ink); margin:8px 0 4px}
.vfamily-label .vfamily-sub{display:block; font-weight:400; color:var(--faint); font-size:.72rem}
.chips{display:flex; flex-wrap:wrap; gap:5px}
.chip{font-size:.78rem; padding:4px 10px; border:1px solid var(--rule); border-radius:16px;
  background:#fff; color:var(--ink); cursor:pointer; font-family:inherit; line-height:1.3}
.chip:hover{border-color:var(--accent)}
.chip.on{color:#fff; border-color:transparent}
.chip.on.harness{background:var(--harness)} .chip.on.retrieval{background:var(--retrieval)} .chip.on.imaging{background:var(--imaging)}
.chips.runs .chip.on{background:var(--accent)}
.legend .legendlist{list-style:none; padding:0; margin:0; font-size:.78rem; color:var(--muted)}
.legend .legendlist li{display:flex; align-items:center; gap:7px; padding:2px 0}
.swatch{width:11px; height:11px; border-radius:3px; flex:0 0 auto}
.swatch.sys{background:var(--sys)} .swatch.user{background:var(--user)} .swatch.tool{background:var(--tool)}
.swatch.rag{background:var(--rag)} .swatch.reason{background:var(--reason)} .swatch.answer{background:var(--answer)}
.legend-note{font-size:.72rem; color:var(--faint); margin:8px 0 0; line-height:1.4}

/* stage */
#stage{padding:22px 30px 80px; min-width:0; max-width:960px}
.placeholder{color:var(--faint); padding:40px 0}
.errbar{background:#fbeceb; border:1px solid #e6c4c0; color:#8a2b25; padding:12px 14px; border-radius:8px; font-size:.9rem}

.cellhead{display:flex; flex-wrap:wrap; align-items:flex-start; gap:14px 22px;
  border-bottom:1px solid var(--rule); padding-bottom:14px; margin-bottom:6px}
.cellhead .vlabel{font-family:Georgia,serif; font-size:1.35rem; line-height:1.2}
.cellhead .runid{color:var(--muted); font-size:.86rem; margin-top:3px}
.subtag{display:inline-block; font-size:.7rem; font-weight:700; letter-spacing:.05em; text-transform:uppercase;
  color:#fff; padding:2px 9px; border-radius:14px; margin-bottom:6px}
.subtag.harness{background:var(--harness)} .subtag.retrieval{background:var(--retrieval)} .subtag.imaging{background:var(--imaging)}
.scorebadge{margin-left:auto; text-align:right}
.scorebadge .big{font-family:Georgia,serif; font-size:1.9rem; font-variant-numeric:tabular-nums}
.scorebadge .den{display:block; font-size:.74rem; color:var(--muted)}
.variant-note{color:var(--muted); font-size:.9rem; font-style:italic; margin:8px 0 4px}

.sectionlabel{font-family:Georgia,serif; font-weight:700; font-size:.82rem; text-transform:uppercase;
  letter-spacing:.06em; color:var(--muted); margin:22px 0 8px; padding-bottom:3px; border-bottom:1px solid var(--rule2)}
.sectionlabel:first-of-type{margin-top:14px}

/* collapsible blocks */
.block{border:1px solid var(--rule); border-radius:8px; margin:7px 0; overflow:hidden; background:#fff}
.block>summary{list-style:none; cursor:pointer; display:flex; align-items:center; gap:9px;
  padding:9px 12px; font-size:.9rem; user-select:none}
.block>summary::-webkit-details-marker{display:none}
.block .caret{color:var(--faint); font-size:.8rem; transition:transform .12s}
.block[open] .caret{transform:rotate(90deg)}
.block .bdot{width:9px; height:9px; border-radius:50%; flex:0 0 auto; background:var(--faint)}
.block.sys .bdot{background:var(--sys)} .block.user .bdot{background:var(--user)} .block.tool .bdot{background:var(--tool)}
.block.rag .bdot{background:var(--rag)} .block.reason .bdot{background:var(--reason)} .block.answer .bdot{background:var(--answer)}
.block .btitle{font-weight:700}
.block .bmeta{margin-left:auto; color:var(--faint); font-size:.78rem; font-family:ui-monospace,monospace}
.block .body{padding:0 13px 12px; border-top:1px solid var(--rule2)}
.block .body:empty{display:none}
pre.txt{white-space:pre-wrap; word-break:break-word; font-size:.82rem; line-height:1.5; margin:10px 0 0;
  color:#333; font-family:ui-monospace,Menlo,monospace; max-height:300px; overflow:auto}
/* long fields scroll inside a bounded panel instead of truncating or running off the page */
.scrollpanel{max-height:260px; overflow:auto}
.kv{font-size:.82rem; margin:8px 0 0}
.kv b{color:#222}

/* inputs: imaging */
.imaging{display:flex; flex-wrap:wrap; gap:12px; margin:4px 0}
.imgcard{width:168px; border:1px solid var(--rule); border-radius:8px; overflow:hidden; background:#fff}
.imgcard img{width:100%; height:140px; object-fit:cover; display:block; background:#111}
.imgcard .cap{padding:6px 8px; font-size:.74rem; color:var(--muted)}
.imgcard .cap .ref{font-weight:700; color:#333}
.noimg{color:var(--faint); font-style:italic; font-size:.85rem}

/* tool / retrieval detail */
.args{background:var(--panel); border:1px solid var(--rule2); border-radius:6px; padding:8px 10px;
  font-size:.78rem; white-space:pre-wrap; word-break:break-word; margin:8px 0 0; color:#444; font-family:ui-monospace,monospace; max-height:220px; overflow:auto}
.sublabel{font-size:.74rem; font-weight:700; text-transform:uppercase; letter-spacing:.04em; color:var(--faint); margin:10px 0 3px}
.retr-summary{font-size:.83rem; margin:8px 0 4px}
.retr-item{padding:6px 0; border-bottom:1px dotted var(--rule)}
.retr-meta{display:flex; flex-wrap:wrap; gap:7px; align-items:baseline; font-size:.78rem}
.retr-num{color:var(--faint)} .retr-tag{font-family:ui-monospace,monospace; color:var(--retrieval); font-weight:700}
.retr-title{color:#333} .retr-score{color:var(--faint); font-family:ui-monospace,monospace}
.retr-text{font-size:.78rem; color:#666; margin-top:2px}
.subq{margin:4px 0 0 1.1em; padding:0; font-size:.8rem; color:#444}
.subq li{margin:2px 0}
.gapnote{background:#fbf3e8; border:1px solid #e6d8bf; color:#7a5a1e; font-size:.78rem; padding:7px 10px; border-radius:6px; margin:8px 0 0}

/* answer — rendered Markdown in a bounded, scrollable panel so scores stay near the top */
.answerbox{max-height:320px; overflow:auto; overflow-wrap:break-word; background:#fff; border:1px solid var(--rule);
  border-left:3px solid var(--answer); border-radius:6px; padding:6px 15px 12px; font-size:.86rem; line-height:1.55; color:#222}
.answerbox>*:first-child{margin-top:0}
.answerbox p{margin:.5em 0}
.answerbox h4,.answerbox h5,.answerbox h6{font-family:Georgia,serif; margin:.85em 0 .3em; line-height:1.25}
.answerbox h4{font-size:1rem} .answerbox h5{font-size:.92rem} .answerbox h6{font-size:.86rem; color:var(--muted)}
.answerbox ul,.answerbox ol{margin:.4em 0; padding-left:1.4em}
.answerbox li{margin:.15em 0}
.answerbox code{background:var(--panel); padding:0 4px; border-radius:4px; font-size:.9em}
.answerbox strong{font-weight:700} .answerbox em{font-style:italic}
.answerbox hr{border:0; border-top:1px solid var(--rule); margin:.7em 0}
.cite{background:#f0ece3; border-radius:4px; padding:0 4px; font-size:.85em; color:var(--retrieval); font-family:ui-monospace,monospace}
.unavail{color:var(--faint); font-style:italic; font-size:.86rem; background:var(--panel); border:1px dashed var(--rule);
  border-radius:6px; padding:11px 13px}

/* scores */
.scoregrid{display:flex; flex-wrap:wrap; gap:8px; margin:4px 0 10px}
.scard{flex:1 1 130px; background:var(--panel); border:1px solid var(--rule); border-radius:8px; padding:8px 11px}
.scard .lab{font-size:.72rem; color:var(--muted)}
.scard .v{font-family:Georgia,serif; font-size:1.15rem; font-variant-numeric:tabular-nums}
.scard.sc-hi .v{color:var(--good)} .scard.sc-mid .v{color:var(--mid)} .scard.sc-lo .v{color:var(--bad)} .scard.sc-na .v{color:var(--faint)}
.ot{display:inline-block; padding:1px 8px; border-radius:14px; font-size:.72rem; font-weight:700; background:#f3d6d3; color:#8a2b25}
.rat{font-size:.85rem; color:#444; margin:6px 0 10px; padding-left:11px; border-left:2px solid var(--rule); max-height:240px; overflow:auto}
.rat b{color:#222}
.critlist{list-style:none; padding:0; margin:6px 0}
.critlist li{padding:3px 0 3px 24px; position:relative; font-size:.86rem; line-height:1.4}
.critlist li::before{position:absolute; left:0; top:2px; font-weight:700}
.critlist li.sat::before{content:"\2713"; color:var(--good)}
.critlist li.unsat::before{content:"\2717"; color:var(--bad)}
