:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #17202a; --muted: #5b6672; --line: #e2e6ea;
  --accent: #0e9f6e; --cand: #f59e0b; --anchor: #2f6fde; --view: #8b5cf6; --chip: #eef1f4; --code: #f2f4f6;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1419; --panel: #161c23; --text: #e6eaee; --muted: #93a0ad; --line: #26303a;
          --chip: #1f2830; --code: #11171d; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.app { display: grid; grid-template-columns: minmax(0, 1fr) 400px; height: 100vh; }
.viewport { position: relative; min-height: 320px; }
#canvas { width: 100%; height: 100%; display: block; }
.legend { position: absolute; left: 12px; bottom: 10px; display: flex; gap: 12px; flex-wrap: wrap;
  font-size: 12px; color: var(--muted); background: color-mix(in srgb, var(--panel) 85%, transparent);
  padding: 6px 10px; border-radius: 8px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.sw.best { background: var(--accent); } .sw.cand { background: var(--cand); }
.sw.anchor { background: var(--anchor); } .sw.view { background: var(--view); }
.panel { background: var(--panel); border-left: 1px solid var(--line); padding: 18px 18px 12px; overflow-y: auto; }
h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
h1 span { color: var(--accent); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 18px 0 6px; }
h2 small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.tag { margin: 4px 0 14px; color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; color: var(--muted); }
select, input, button { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; }
select { flex: 1; }
.query { display: flex; gap: 8px; margin-top: 12px; }
.query input { flex: 1; min-width: 0; }
button { background: var(--accent); color: #fff; border: 0; font-weight: 600; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chips button { background: var(--chip); color: var(--text); font-weight: 400; font-size: 12px; padding: 4px 9px; border-radius: 999px; }
.status { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--chip); min-height: 20px; }
.status b { color: var(--accent); }
.status .warn { color: var(--cand); display: block; margin-top: 4px; font-size: 13px; }
.status .err { color: #e5484d; }
.cands { width: 100%; border-collapse: collapse; }
.cands td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.cands tr { cursor: pointer; }
.cands tr.sel td { background: var(--chip); }
.cands .rank { color: var(--muted); width: 28px; }
.cands .score { width: 46%; }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; display: inline-block; width: calc(100% - 48px); vertical-align: middle; }
.bar i { display: block; height: 100%; background: var(--cand); }
tr:first-child .bar i { background: var(--accent); }
.num { font-variant-numeric: tabular-nums; display: inline-block; width: 42px; text-align: right; color: var(--muted); }
.trace .c { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.trace .c .h { display: flex; justify-content: space-between; font-weight: 600; }
.trace .c .h span:last-child { font-variant-numeric: tabular-nums; }
.trace .note { color: var(--cand); font-size: 12px; }
.trace dl { display: grid; grid-template-columns: 1fr auto; gap: 1px 12px; margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.trace dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; color: var(--text); }
details { margin-top: 12px; }
summary { cursor: pointer; color: var(--muted); }
pre { background: var(--code); border-radius: 8px; padding: 10px; font-size: 12px; overflow-x: auto; white-space: pre-wrap; }
footer { margin-top: 18px; font-size: 12px; color: var(--muted); }
footer a { color: var(--anchor); }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 55vh auto; height: auto; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
}
