:root {
  --bg: #f4f3ef; --panel: #ffffff; --panel2: #faf9f6; --ink: #17181a; --muted: #62666b; --line: #dcd9d0; --accent: #2457e6;
  --yes: #13894f; --no: #d23c3c; --unsupported: #7d838b; --undetermined: #c27c00; --gt: #2457e6;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1012; --panel: #15181b; --panel2: #1a1e22; --ink: #e7e5e0; --muted: #989ea6; --line: #2a2f35; --accent: #7ea2ff;
    --yes: #3bcf85; --no: #ff6b6b; --unsupported: #9aa1aa; --undetermined: #f2b33d; --gt: #7ea2ff; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1012; --panel: #15181b; --panel2: #1a1e22; --ink: #e7e5e0; --muted: #989ea6; --line: #2a2f35; --accent: #7ea2ff;
  --yes: #3bcf85; --no: #ff6b6b; --unsupported: #9aa1aa; --undetermined: #f2b33d; --gt: #7ea2ff; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif; }
.mono, pre, code { font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace; }
a { color: var(--accent); }
b { font-weight: 600; }
.muted { color: var(--muted); }
.label { font: 500 11px/1.2 "IBM Plex Mono", monospace; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
button, input, select { font: inherit; color: inherit; }
.ghost { background: none; border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }

/* header */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 10px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; color: var(--ink); text-decoration: none; letter-spacing: .01em; }
.mark { width: 16px; height: 16px; border: 2px solid var(--yes); position: relative; }
.mark::after { content: ""; position: absolute; inset: 3px; background: var(--yes); border-radius: 50%; }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
nav::-webkit-scrollbar { display: none; }
nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
nav a.on { color: var(--ink); background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
main { max-width: 1480px; margin: 0 auto; padding: 16px 24px 40px; }
.intro p { max-width: 900px; margin: 4px 0 16px; color: var(--muted); }
.intro b { color: var(--ink); }
.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; max-width: 1480px; margin: 0 auto; padding: 16px 24px 28px; font-size: 13px; border-top: 1px solid var(--line); }

/* detect layout */
.detect { display: grid; grid-template-columns: 220px minmax(0, 1fr) 420px; gap: 20px; align-items: start; }
.left, .trace { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.upload { display: block; border: 1.5px dashed var(--line); border-radius: 8px; padding: 14px; text-align: center; cursor: pointer; background: var(--panel); margin-bottom: 16px; }
.upload:hover, .upload.drag { border-color: var(--accent); }
.upload input { display: none; }
.u1 { display: block; font-weight: 600; }
.u2 { display: block; font-size: 12px; color: var(--muted); }
.gallery { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.gallery button { padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; cursor: pointer; aspect-ratio: 4/3; background: var(--panel2); }
.gallery button.on { border-color: var(--accent); }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }

.controls { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 10px 3px 8px; font-size: 13px; cursor: pointer; user-select: none; }
.chip .dot { width: 9px; height: 9px; border-radius: 2px; }
.chip.off { opacity: .45; }
.chip .n { color: var(--muted); font-family: "IBM Plex Mono", monospace; font-size: 12px; }
.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; cursor: pointer; }
.slider { display: inline-flex; gap: 8px; align-items: center; font-size: 14px; }
.slider b { font-family: "IBM Plex Mono", monospace; font-weight: 500; min-width: 4.5em; display: inline-block; }
.slider input { width: 150px; accent-color: var(--accent); }

.canvas { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; min-height: 320px; display: grid; place-items: center; overflow: hidden; }
.canvas img { display: block; max-width: 100%; max-height: 72vh; }
.canvas img:not([src]), .canvas img[src=""] { display: none; }
.canvas svg { position: absolute; pointer-events: none; }
.canvas svg .hit { pointer-events: all; cursor: pointer; }
.empty { color: var(--muted); padding: 40px; }
.busy { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px; background: color-mix(in srgb, var(--panel) 78%, transparent); font-size: 14px; }
.spin { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: s 0.9s linear infinite; }
@keyframes s { to { transform: rotate(360deg); } }
.meta { font-size: 12px; color: var(--muted); margin: 8px 0; min-height: 1em; }
.err { border: 1px solid var(--no); color: var(--no); background: color-mix(in srgb, var(--no) 8%, transparent); border-radius: 6px; padding: 8px 12px; margin: 8px 0; }

.list { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); overflow: hidden; }
.list:empty { display: none; }
.row { display: grid; grid-template-columns: 34px 1fr auto auto; gap: 10px; align-items: center; padding: 7px 12px; border-top: 1px solid var(--line); cursor: pointer; font-size: 14px; }
.row:first-child { border-top: 0; }
.row:hover { background: var(--panel2); }
.row.on { background: color-mix(in srgb, var(--accent) 10%, var(--panel)); }
.row .k { font-family: "IBM Plex Mono", monospace; color: var(--muted); font-size: 12px; }
.row .s { font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--muted); }
.badge { display: inline-block; font: 500 11px/1 "IBM Plex Mono", monospace; letter-spacing: .04em; text-transform: uppercase; padding: 4px 7px; border-radius: 4px; color: #fff; }
.b-yes { background: var(--yes); } .b-no { background: var(--no); } .b-unsupported { background: var(--unsupported); } .b-undetermined { background: var(--undetermined); }
:root[data-theme="dark"] .badge { color: #0e1012; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge { color: #0e1012; } }

/* trace */
.trace { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; box-shadow: var(--shadow); }
.placeholder p { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.legend { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; margin: 0; font-size: 13px; }
.legend dt { margin: 0; } .legend dd { margin: 0; color: var(--muted); }
.th { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.th h2 { margin: 0; font-size: 20px; font-weight: 600; }
.plain { margin: 6px 0 14px; font-size: 14px; }
.sec { margin-top: 16px; }
.formula { font-family: "IBM Plex Mono", monospace; font-size: 13px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; overflow-x: auto; white-space: nowrap; }
.formula .eq { color: var(--muted); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { text-align: left; font: 500 11px/1.2 "IBM Plex Mono", monospace; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 6px 6px; border-bottom: 1px solid var(--line); }
td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.atom { font-family: "IBM Plex Mono", monospace; font-size: 12px; overflow-wrap: anywhere; }
.tv { font: 500 11px/1 "IBM Plex Mono", monospace; padding: 3px 5px; border-radius: 3px; white-space: nowrap; }
.tv-t { color: var(--yes); background: color-mix(in srgb, var(--yes) 12%, transparent); }
.tv-f { color: var(--no); background: color-mix(in srgb, var(--no) 12%, transparent); }
.tv-u { color: var(--undetermined); background: color-mix(in srgb, var(--undetermined) 14%, transparent); }
.why { color: var(--muted); }
.reading { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--muted); display: block; margin-top: 2px; word-break: break-word; }
.rules { list-style: none; padding: 0; margin: 0; font-family: "IBM Plex Mono", monospace; font-size: 12px; }
.rules li { padding: 4px 8px; border-left: 3px solid var(--line); margin: 4px 0; word-break: break-all; }
.rules li.dec { border-left-color: var(--accent); background: var(--panel2); }
details { margin-top: 14px; }
summary { cursor: pointer; font: 500 12px/1.2 "IBM Plex Mono", monospace; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.steps { font-family: "IBM Plex Mono", monospace; font-size: 11.5px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; max-height: 360px; overflow: auto; white-space: pre; margin-top: 8px; }
.close { float: right; }

/* pipeline */
.nodes { display: grid; gap: 0; counter-reset: n; margin-bottom: 20px; }
.node { display: grid; grid-template-columns: 54px 1fr; gap: 14px; position: relative; padding: 0 0 14px; }
.node::before { counter-increment: n; content: counter(n, decimal-leading-zero); font: 500 13px/32px "IBM Plex Mono", monospace; color: var(--muted); text-align: center; border: 1px solid var(--line); border-radius: 6px; height: 32px; background: var(--panel); }
.node::after { content: ""; position: absolute; left: 27px; top: 34px; bottom: 2px; border-left: 1px dashed var(--line); }
.node:last-child::after { display: none; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; box-shadow: var(--shadow); }
.nh { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nh h3 { margin: 0; font-size: 16px; font-family: "IBM Plex Mono", monospace; font-weight: 500; }
.tag { font: 500 11px/1 "IBM Plex Mono", monospace; padding: 4px 7px; border-radius: 4px; border: 1px solid var(--line); color: var(--muted); }
.tag.learned { border-color: var(--undetermined); color: var(--undetermined); }
.tag.fixed { border-color: var(--yes); color: var(--yes); }
.tag.stage { }
.io { font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--muted); margin-top: 6px; }
.io span { color: var(--ink); }
.node p { margin: 6px 0 0; font-size: 14px; }
.rulebox pre { margin: 0; font-size: 12.5px; overflow-x: auto; }

/* knowledge */
.know { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; align-items: start; }
.clist { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; }
.clist button { text-align: left; background: none; border: 0; padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.clist button.on { background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); font-weight: 600; }
.centry h2 { margin: 0 0 4px; font-size: 24px; }
.kgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 14px; }
.sw { display: inline-flex; align-items: center; gap: 6px; margin: 3px 10px 3px 0; font-size: 13px; }
.sw i { width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line); display: inline-block; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.protos { display: flex; flex-wrap: wrap; gap: 8px; }
.protos svg { width: 64px; height: 64px; background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; }
.protos path { fill: color-mix(in srgb, var(--accent) 18%, transparent); stroke: var(--accent); stroke-width: 1.2; }
.words { display: flex; flex-wrap: wrap; gap: 4px; }
.words span { font-size: 12px; border: 1px solid var(--line); border-radius: 4px; padding: 2px 6px; }

/* results */
.rhead h1 { font-size: 26px; margin: 4px 0 6px; }
.rhead p { color: var(--muted); max-width: 900px; margin: 0 0 18px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 22px; }
.kpi .v { font: 500 28px/1.1 "IBM Plex Mono", monospace; }
.kpi .d { font-size: 13px; color: var(--muted); margin-top: 4px; }
.rsec { margin: 26px 0 0; }
.rsec h2 { font-size: 18px; margin: 0 0 4px; }
.rsec > p { color: var(--muted); margin: 0 0 12px; max-width: 900px; font-size: 14px; }
.bars { display: grid; grid-template-columns: minmax(140px, 330px) 1fr; gap: 6px 12px; align-items: center; font-size: 13px; }
.bar { position: relative; height: 20px; background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--unsupported); opacity: .55; }
.bar i.p { background: var(--accent); opacity: .85; }
.bar i.ap { background: var(--ink); opacity: .85; height: 6px; top: auto; }
.bar span { position: absolute; right: 6px; top: 1px; font: 500 12px/18px "IBM Plex Mono", monospace; }
.tbl { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.tbl table td, .tbl table th { padding: 7px 10px; }
.tbl td.n { font-family: "IBM Plex Mono", monospace; text-align: right; }
.tbl th.n { text-align: right; }
.tbl tr.pc td { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.pcls { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 4px 24px; }
.pcl { display: grid; grid-template-columns: 110px 1fr; gap: 8px; align-items: center; font-size: 13px; }
.two { position: relative; height: 14px; }
.two i { position: absolute; left: 0; height: 6px; border-radius: 2px; }
.two i.a { top: 0; background: var(--accent); } .two i.b { top: 8px; background: var(--unsupported); }
.leg { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.leg i { display: inline-block; width: 12px; height: 6px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
ul.plainlist { margin: 0; padding-left: 18px; font-size: 14px; }

/* responsive */
@media (max-width: 1180px) {
  .detect { grid-template-columns: 200px minmax(0, 1fr); }
  .trace { grid-column: 1 / -1; position: static; max-height: none; }
}
@media (max-width: 760px) {
  .top { padding: 8px 16px; gap: 10px; }
  main { padding: 12px 16px 32px; }
  .foot { padding: 14px 16px 24px; }
  .detect, .know { grid-template-columns: minmax(0, 1fr); }
  .left, .clist { position: static; max-height: none; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); max-height: 200px; overflow: auto; }
  .clist { flex-direction: row; flex-wrap: wrap; }
  .slider input { width: 120px; }
  .canvas img { max-height: 60vh; }
  .canvas { min-height: 200px; }
  .formula { white-space: normal; }
  .trace td:first-child { max-width: 96px; }
  .trace td { padding: 5px 4px; }
  .bars { grid-template-columns: 1fr; }
  .row { grid-template-columns: 28px 1fr auto; } .row .s { display: none; }
}
