:root {
  --bg: #f6f4ef; --fg: #1f2328; --muted: #6b7280; --line: #d9d4ca; --card: #ffffff; --card2: #efece5;
  --accent: #2f5aa0; --hl: #fff3c4;
  --c-special: #d9822b; --c-geo: #2a9d8f; --c-chron: #7b61c9; --c-constr: #3b6fb6; --c-subgen: #2f5aa0;
  --c-names: #5b86c9; --c-ff: #3a9b4f; --c-pattern: #7ab23c; --c-appx: #a0569a; --c-proc: #8a94a0; --c-gen: #6c7680;
  --ok: #2e8b57; --bad: #c0392b; --warn: #b8860b;
  --sx: #3b6fb6; --sv: #d9822b; --sy: #7b61c9; --sz: #2a9d8f;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #15171b; --fg: #e6e3dc; --muted: #9aa1ab; --line: #333842; --card: #1e2127; --card2: #262a31; --hl: #3b3520;
  --c-proc: #9aa3ad; --c-gen: #8e969f;
} }
:root[data-theme="dark"] { --bg: #15171b; --fg: #e6e3dc; --muted: #9aa1ab; --line: #333842; --card: #1e2127; --card2: #262a31; --hl: #3b3520; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; display: flex; flex-direction: column; }
a { color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: 12px; }
.bar { display: flex; align-items: center; gap: 14px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--card); flex-wrap: wrap; }
.brand { white-space: nowrap; } .brand a { text-decoration: none; margin-right: 4px; }
.tabs { display: flex; gap: 2px; background: var(--card2); border-radius: 8px; padding: 2px; }
.tabs button { border: 0; background: transparent; color: var(--fg); padding: 6px 14px; border-radius: 6px; cursor: pointer; font: inherit; }
.tabs button.on { background: var(--card); box-shadow: 0 1px 2px rgba(0,0,0,.15); font-weight: 600; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 520px; }
.search input, #sub-q { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); font: inherit; }
#q-results { position: absolute; top: 100%; left: 0; right: 0; margin: 4px 0 0; padding: 4px; list-style: none; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.18); z-index: 20; max-height: 60vh; overflow: auto; }
#q-results li { padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
#q-results li:hover, #q-results li.sel { background: var(--card2); }
#q-results .k { font-size: 11px; color: var(--muted); min-width: 64px; }
.stats { font-size: 12px; color: var(--muted); white-space: nowrap; }
main { flex: 1; display: flex; min-height: 0; }
.stage { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.view { position: absolute; inset: 0; }
.view svg { width: 100%; height: 100%; display: block; cursor: grab; }
.view svg:active { cursor: grabbing; }
.caption { position: absolute; left: 12px; right: 12px; bottom: 8px; margin: 0; font-size: 12px; color: var(--muted); pointer-events: none; text-shadow: 0 0 4px var(--bg); }
.zoomctl { position: absolute; left: 12px; top: 12px; display: flex; flex-direction: column; gap: 4px; }
.zoomctl button { width: 32px; height: 28px; border: 1px solid var(--line); background: var(--card); color: var(--fg); border-radius: 6px; cursor: pointer; font: inherit; }
.legend { position: absolute; right: 12px; top: 12px; background: color-mix(in srgb, var(--card) 88%, transparent); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; display: grid; grid-template-columns: auto auto; gap: 3px 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }
.toolbar { position: absolute; left: 56px; top: 12px; display: flex; gap: 6px; flex-wrap: wrap; max-width: calc(100% - 70px); }
.toolbar button { font: inherit; font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--fg); cursor: pointer; }
.toolbar button.off { opacity: .4; text-decoration: line-through; }
.tip { position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; font-size: 12px; max-width: 320px; box-shadow: 0 4px 16px rgba(0,0,0,.18); z-index: 10; }
.tip b { display: block; }
.panel { width: 400px; border-left: 1px solid var(--line); background: var(--card); overflow: auto; }
.panel-inner { padding: 16px 18px 40px; }
.panel h2 { margin: 0 0 6px; font-size: 18px; line-height: 1.25; }
.panel h3 { margin: 18px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0; }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--card2); border: 1px solid var(--line); cursor: default; }
.chip.link { cursor: pointer; } .chip.link:hover { background: var(--hl); }
.chip.cat { color: #fff; border-color: transparent; }
.rule { padding: 7px 0 7px 10px; border-left: 3px solid var(--line); margin: 6px 0; font-size: 13px; }
.rule.p { border-color: var(--bad); } .rule.lc { border-color: var(--warn); } .rule.c:not(.p):not(.lc) { border-color: var(--c-constr); }
.rule .n { color: var(--muted); font-size: 11px; margin-right: 4px; }
.rule .tag { font-size: 10px; padding: 1px 5px; border-radius: 4px; margin-left: 4px; vertical-align: 1px; color: #fff; }
.tag.p { background: var(--bad); } .tag.c { background: var(--c-constr); } .tag.lc { background: var(--warn); }
.rule code { font-size: 12px; background: var(--card2); padding: 0 3px; border-radius: 3px; }
.ref { color: var(--accent); cursor: pointer; text-decoration: underline dotted; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 12px; margin: 6px 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.sheetrow { display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; align-items: baseline; }
.sheetrow:hover { background: var(--card2); }
.sheetrow .id { font-weight: 600; min-width: 70px; max-width: 150px; } .sheetrow .t { flex: 1; } .sheetrow .m { color: var(--muted); font-size: 11px; white-space: nowrap; }
/* flow */
.fnode { cursor: pointer; }
.fnode rect { fill: var(--card); stroke: var(--line); stroke-width: 1.2; }
.fnode.decision rect { stroke: var(--c-constr); stroke-width: 1.6; }
.fnode.result rect { stroke-width: 0; }
.fnode.result.ok rect { fill: color-mix(in srgb, var(--ok) 16%, var(--card)); }
.fnode.result.bad rect { fill: color-mix(in srgb, var(--bad) 14%, var(--card)); }
.fnode.result.warn rect { fill: color-mix(in srgb, var(--warn) 16%, var(--card)); }
.fnode.result .bar { stroke-width: 0; }
.fnode.result.ok .bar { fill: var(--ok); } .fnode.result.bad .bar { fill: var(--bad); } .fnode.result.warn .bar { fill: var(--warn); }
.fnode.list rect { fill: color-mix(in srgb, var(--c-ff) 12%, var(--card)); stroke: var(--c-ff); }
.fnode.start rect { fill: var(--fg); stroke: var(--fg); } .fnode.start text { fill: var(--bg); }
.fnode text { fill: var(--fg); font-size: 13px; pointer-events: none; }
.fnode text.sub { fill: var(--muted); font-size: 11px; }
.fnode text.sheets { fill: var(--accent); font-size: 10.5px; }
.fnode:hover rect { stroke: var(--fg); stroke-width: 2; } .fnode.sel rect { stroke: var(--fg); stroke-width: 2.4; filter: drop-shadow(0 0 6px rgba(0,0,0,.25)); }
.fedge { fill: none; stroke: var(--muted); stroke-width: 1.4; }
.fedge.yes { stroke: var(--ok); } .fedge.no { stroke: var(--bad); } .fedge.faint { stroke-dasharray: 4 4; opacity: .7; }
.flabel { font-size: 11px; fill: var(--muted); paint-order: stroke; stroke: var(--bg); stroke-width: 3px; }
.flabel.yes { fill: var(--ok); } .flabel.no { fill: var(--bad); }
.ring circle { cursor: pointer; fill: var(--c-special); opacity: .85; } .ring circle:hover { opacity: 1; stroke: var(--fg); stroke-width: 1.5; }
.ring text { fill: var(--muted); font-size: 11px; }
.ring text.cap { font-size: 12px; fill: var(--fg); }
.lane { fill: none; stroke: var(--line); stroke-dasharray: 3 5; }
.lanelab { font-size: 12px; fill: var(--muted); font-weight: 600; letter-spacing: .04em; }
/* network */
.nlink { stroke: var(--muted); stroke-opacity: .18; fill: none; }
.nnode { cursor: pointer; stroke: var(--bg); stroke-width: 1; }
.nlab { font-size: 11px; fill: var(--fg); pointer-events: none; paint-order: stroke; stroke: var(--bg); stroke-width: 3px; }
.dim { opacity: .08; }
.lit { stroke: var(--fg) !important; stroke-width: 2px !important; }
.nlink.lit { stroke-opacity: .7 !important; stroke-width: 1.5px; }
/* lists */
.lists-wrap { position: absolute; inset: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0; overflow: hidden; }
.lists-left, .lists-right { overflow: auto; padding: 16px 18px 40px; }
.lists-left { border-right: 1px solid var(--line); }
.lists-wrap h2 { font-size: 16px; margin: 0 0 4px; } .lists-wrap h3 { font-size: 13px; margin: 20px 0 4px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin: 0 2px 0 8px; }
.sw.x { background: var(--sx); } .sw.v { background: var(--sv); } .sw.y { background: var(--sy); } .sw.z { background: var(--sz); }
.lgroup { margin-top: 14px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.lrow { display: grid; grid-template-columns: 220px 1fr 48px; gap: 8px; align-items: center; padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.lrow:hover, .lrow.sel { background: var(--card2); }
.lrow .n { text-align: right; font-size: 12px; color: var(--muted); }
.lrow .lab { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .lrow .lab b { font-weight: 600; margin-right: 6px; }
.bar2 { height: 14px; display: flex; border-radius: 3px; overflow: hidden; background: var(--card2); }
.bar2 i { display: block; height: 100%; } .bar2 .x { background: var(--sx); } .bar2 .v { background: var(--sv); } .bar2 .y { background: var(--sy); } .bar2 .z { background: var(--sz); }
.hit { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin: 6px 0; font-size: 13px; }
.hit .h { display: flex; gap: 8px; align-items: baseline; } .hit .h b { cursor: pointer; color: var(--accent); }
.hit .use { color: var(--muted); font-size: 12px; margin-top: 3px; }
.sf { font-family: ui-monospace, Menlo, monospace; font-size: 11px; padding: 0 5px; border-radius: 4px; color: #fff; }
.sf.x { background: var(--sx); } .sf.v { background: var(--sv); } .sf.y { background: var(--sy); } .sf.z { background: var(--sz); }
.msg { font-size: 11px; color: var(--ok); } 
.multi { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 13px; }
.multi span { cursor: pointer; } .multi span:hover { text-decoration: underline; } .multi em { color: var(--muted); font-style: normal; font-size: 12px; }
#sub-q-wrap { position: relative; }
.sublist { max-height: 50vh; overflow: auto; margin-top: 8px; }
.sublist div { padding: 3px 4px; font-size: 13px; cursor: pointer; border-radius: 4px; display: flex; justify-content: space-between; } .sublist div:hover { background: var(--card2); }
/* rules treemap */
.crumbs { position: absolute; left: 56px; top: 12px; z-index: 2; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.crumbs span { cursor: pointer; padding: 3px 9px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); } .crumbs span:last-child { font-weight: 600; cursor: default; }
.cell { cursor: pointer; } .cell rect { stroke: var(--bg); stroke-width: 1.5; }
.cell:hover rect { stroke: var(--fg); }
.cell text { pointer-events: none; fill: #fff; font-size: 12px; paint-order: stroke; stroke: rgba(0,0,0,.35); stroke-width: 2px; }
.cell text.n { font-size: 10px; opacity: .85; }
@media (max-width: 900px) {
  main { flex-direction: column; }
  .panel { width: auto; max-height: 45vh; border-left: 0; border-top: 1px solid var(--line); }
  .lists-wrap { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; } .lists-left { border-right: 0; border-bottom: 1px solid var(--line); }
  .legend { display: none; } .lrow { grid-template-columns: 1fr 1fr 40px; }
  .stats { display: none; }
}

/* embed button + popover */
.embed { position: relative; }
.embed > button, #embed-copy { font: inherit; font-size: 12px; padding: 5px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--card2); color: var(--fg); cursor: pointer; }
.embed-pop { position: absolute; right: 0; top: 100%; margin-top: 6px; width: 420px; max-width: 90vw; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.2); z-index: 30; }
.embed-pop p { margin: 0 0 6px; } .embed-pop code { font-size: 11px; }
.embed-pop textarea { width: 100%; font: 11px/1.4 ui-monospace, Menlo, monospace; background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 6px; resize: vertical; margin-bottom: 6px; }
/* embed mode: no header, stage full width, panel as a drawer */
.embed-bar { display: none; }
.panel-close { display: none; }
body.embed .bar { display: none; }
body.embed .embed-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 12px; font-size: 13px; border-bottom: 1px solid var(--line); background: var(--card); }
body.embed .embed-bar a { font-size: 12px; text-decoration: none; }
body.embed main { position: relative; }
body.embed .panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(400px, 100%); transform: translateX(102%); transition: transform .25s ease; box-shadow: -8px 0 24px rgba(0,0,0,.18); z-index: 6; border-left: 1px solid var(--line); }
body.embed .panel.open { transform: none; }
body.embed .panel-close { display: block; position: sticky; top: 8px; float: right; margin: 8px 8px 0 0; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--line); background: var(--card2); color: var(--fg); font-size: 18px; line-height: 1; cursor: pointer; z-index: 2; }
body.embed .legend { top: auto; bottom: 36px; }
@media (max-width: 900px) { body.embed main { flex-direction: row; } body.embed .panel { max-height: none; border-top: 0; } }
