/* Trailmark - ledger paper, ink, hairlines. Red only ever marks a break in the trail;
   green only ever marks a link that holds; amber only ever marks a suggestion. */
:root {
  --paper: #f6f4ef;
  --paper-2: #efece5;
  --card: #fffdf9;
  --ink: #141414;
  --ink-2: #3b3a37;
  --ink-3: #75716a;
  --ink-4: #a6a198;
  --rule: #e2ddd3;
  --rule-2: #cfc9bd;
  --red: #c7341f;
  --red-bg: #fbe9e5;
  --green: #2c7a4b;
  --green-bg: #e6f2ea;
  --amber: #a8650b;
  --amber-bg: #fbf0dc;
  --sans: 'Inter Tight', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 15px; line-height: 1.5;
       -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column; }
code, .mono { font-family: var(--mono); font-size: .88em; }
code, pre, .mono, .chip, .id, .amt, textarea, .q-file, .engine, .elabel, .card .i, .card .k { font-variant-ligatures: none; font-feature-settings: 'liga' 0, 'calt' 0; }
a { color: inherit; }
button { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; gap: 28px; padding: 0 28px; height: 60px; border-bottom: 1px solid var(--ink); background: var(--paper); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.mark { width: 34px; height: 22px; overflow: visible; }
.mark .m-ok { stroke: var(--ink); stroke-width: 2.2; fill: none; }
.mark .m-break { stroke: var(--red); stroke-width: 2.2; fill: none; stroke-dasharray: 3.2 2.6; }
.mark .m-dot { fill: var(--ink); }
.mark .m-ghost { fill: var(--paper); stroke: var(--red); stroke-width: 1.6; }
.tagline { margin: 0; color: var(--ink-2); font-size: 15px; font-weight: 500; white-space: nowrap; }
.engine { margin-left: auto; font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.engine b { color: var(--ink); font-weight: 600; }
.pulse { width: 7px; height: 7px; background: var(--ink-4); display: inline-block; }
.engine.ready .pulse { background: var(--green); }
.engine.fail .pulse { background: var(--red); }
.howbtn { height: 30px; padding: 0 12px; border: 1px solid var(--ink); background: transparent; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.howbtn:hover { background: var(--ink); color: var(--paper); }
dialog.how { max-width: 620px; width: calc(100% - 32px); border: 1px solid var(--ink); background: var(--card); color: var(--ink); padding: 28px 32px 24px; }
dialog.how::backdrop { background: rgba(20, 20, 20, .35); }
dialog.how h2 { margin: 0 0 14px; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
dialog.how ol { margin: 0; padding-left: 20px; display: grid; gap: 12px; font-size: 14.5px; line-height: 1.55; color: var(--ink-2); }
dialog.how ol b { color: var(--ink); }
.how-x { position: absolute; top: 18px; right: 20px; }
.how-x button { border: none; background: none; font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); cursor: pointer; }
.how-try { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--rule); font-size: 14px; }
.how-try a { font-family: var(--mono); font-weight: 600; font-size: 13px; }
.how-foot { margin: 10px 0 0; font-size: 12.5px; color: var(--ink-3); }
.k-brk { color: var(--red); font-weight: 600; } .k-sug { color: var(--amber); font-weight: 600; } .k-ok { color: var(--green); font-weight: 600; }
.sample-tag { font-family: var(--mono); font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--paper); background: var(--ink); padding: 3px 8px; white-space: nowrap; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 312px minmax(0, 1fr); flex: 1; min-height: 0; }
.ledger { border-right: 1px solid var(--rule-2); background: var(--paper); position: sticky; top: 60px; height: calc(100vh - 60px); overflow-y: auto; }
.stage { padding: 24px 30px 40px; min-width: 0; }

/* ---------- ledger / list ---------- */
.books { padding: 20px 22px 16px; border-bottom: 1px solid var(--rule-2); }
.books-co { font-weight: 700; font-size: 14px; }
.books-co em { font-style: normal; font-weight: 500; color: var(--ink-3); }
.books-asof { font-size: 12.5px; color: var(--ink-3); }
.risk { margin-top: 14px; display: flex; flex-direction: column; }
.risk-n { font-size: 34px; font-weight: 800; letter-spacing: -.03em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.risk-l { font-size: 12.5px; color: var(--ink-2); }
.tally { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 14px; border-top: 1px solid var(--ink); }
.tally div { padding: 8px 0 0; }
.tally b { display: block; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tally span { font-size: 11.5px; color: var(--ink-3); line-height: 1.25; display: block; }
.tally .t-exc b { color: var(--red); }
.tally .t-ok b { color: var(--green); }

.group-h { display: flex; justify-content: space-between; padding: 14px 22px 6px; font-family: var(--mono); font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.row { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 10px; align-items: start; width: 100%; text-align: left; padding: 9px 22px; border: none; background: none; cursor: pointer; border-left: 3px solid transparent; }
.row:hover { background: var(--paper-2); }
.row.sel { background: var(--card); border-left-color: var(--ink); box-shadow: inset 0 1px 0 var(--rule), inset 0 -1px 0 var(--rule); }
.row .dot { width: 8px; height: 8px; margin-top: 6px; }
.row .dot.exception { background: var(--red); }
.row .dot.exception.medium { background: transparent; border: 2px solid var(--red); }
.row .dot.matched { background: transparent; border: 1.5px solid var(--green); }
.row .dot.reconciled { background: var(--green); }
.row .dot.overdue { background: var(--amber); }
.row .who { min-width: 0; }
.row .id { font-family: var(--mono); font-size: 12.5px; font-weight: 600; }
.row .v { display: block; font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .why { display: block; font-size: 12.5px; line-height: 1.35; color: var(--ink-3); }
.row .amt { font-family: var(--mono); font-size: 12px; padding-top: 1px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---------- stage ---------- */
.loading { padding: 80px 0; color: var(--ink-3); max-width: 520px; }
.ld-line { height: 2px; background: linear-gradient(90deg, var(--ink) 0 30%, transparent 30%); background-size: 200% 100%; animation: ld 1s linear infinite; margin-bottom: 14px; }
@keyframes ld { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.inv-head { display: block; padding-bottom: 14px; border-bottom: 1px solid var(--ink); }
.inv-kicker { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.inv-title { margin: 4px 0 8px; font-size: 30px; font-weight: 800; letter-spacing: -.025em; line-height: 1.15; }
.inv-title .vn { font-weight: 500; color: var(--ink-2); }
.inv-meta { margin-top: 4px; font-size: 13.5px; color: var(--ink-2); }
.inv-meta .sep { color: var(--ink-4); margin: 0 7px; }
.inv-kicker { display: flex; align-items: center; gap: 12px; }
.status { font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 3px 9px; white-space: nowrap; transition: background .35s, color .35s; }
.status.exception { background: var(--red); color: #fff; }
.status.matched, .status.reconciled { background: var(--green); color: #fff; }
.status.overdue { background: var(--amber); color: #fff; }

/* ---------- trail canvas ---------- */
.trail-wrap { margin-top: 18px; background: var(--card); border: 1px solid var(--rule-2); position: relative; }
.trail-cap { display: flex; justify-content: space-between; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--rule); font-size: 12px; color: var(--ink-3); }
.trail-cap b { color: var(--ink); font-weight: 600; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 18px; height: 0; vertical-align: middle; margin-right: 6px; border-top: 2px solid var(--ink); }
.legend i.brk { border-top: 2px dashed var(--red); }
.legend i.sug { border-top: 2px dotted var(--amber); }
.legend i.ok { border-top-color: var(--green); }
.trail-scroll { overflow-x: auto; }
svg.trail { display: block; width: 100%; min-width: 900px; height: auto; font-family: var(--sans); }
.lane-h { font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; fill: var(--ink-3); }
.lane-rule { stroke: var(--rule); stroke-width: 1; }
.band-h { font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; fill: var(--ink-4); }

.card rect.box { fill: var(--card); stroke: var(--rule-2); stroke-width: 1; }
.card.ev rect.box { stroke: var(--ink); stroke-width: 1.6; }
.card.ev.high rect.box { stroke: var(--red); stroke-width: 2; }
.card.focus rect.box { stroke: var(--ink); stroke-width: 2.4; }
.card.ghost rect.box { fill: #f9ddd7; stroke: var(--red); stroke-width: 2.2; stroke-dasharray: 6 4; }
.card.cand rect.box { fill: var(--amber-bg); stroke: var(--amber); stroke-width: 1.6; stroke-dasharray: 2 3; }
.card.fixed rect.box { fill: var(--green-bg); stroke: var(--green); stroke-width: 2; stroke-dasharray: none; }
.card.dim { opacity: .55; }
.card .k { font-family: var(--mono); font-size: 10px; letter-spacing: .07em; text-transform: uppercase; fill: var(--ink-3); }
.card .i { font-family: var(--mono); font-size: 14.5px; font-weight: 600; fill: var(--ink); }
.card .l1 { font-size: 13px; fill: var(--ink-2); font-weight: 500; }
.card .l2 { font-size: 12px; fill: var(--ink-3); }
.card.ghost .k, .card.ghost .l1, .card.ghost .i { fill: var(--red); }
.card.cand .k { fill: var(--amber); }
.card .flag { fill: var(--red); }
.card { cursor: default; }
.card.appear { animation: cardIn .38s cubic-bezier(.2, .7, .2, 1) backwards; }
@keyframes cardIn { from { opacity: 0; transform: translateY(6px); } }

.edge { fill: none; stroke: var(--ink-4); stroke-width: 1.3; }
.edge.ev { stroke: var(--ink); stroke-width: 1.8; }
.edge.ev.high { stroke: var(--red); stroke-width: 2.2; }
.edge.brk { stroke: var(--red); stroke-width: 3; stroke-dasharray: 7 5; animation: march 0.9s linear infinite !important; }
@keyframes march { to { stroke-dashoffset: -24; } }
.edge.sug { stroke: var(--amber); stroke-width: 2; stroke-dasharray: 1.5 4; stroke-linecap: round; }
.edge.fixed { stroke: var(--green); stroke-width: 2.6; }
.edge.draw { stroke-dasharray: var(--len); stroke-dashoffset: var(--len); animation: draw .5s ease-out forwards; }
.edge.brk.draw, .edge.sug.draw { animation: none; stroke-dasharray: 6 5; stroke-dashoffset: 0; }
.edge.sug.draw { stroke-dasharray: 1.5 4; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.elab rect { fill: var(--card); }
.elabel { font-family: var(--mono); font-size: 10px; fill: var(--ink-3); }
.elabel.ev { fill: var(--ink); }
.elabel.brk { fill: var(--red); font-weight: 600; }
.elabel.sug { fill: var(--amber); font-weight: 600; }
.elabel.fixed { fill: var(--green); font-weight: 600; }

/* ---------- findings ---------- */
.cols { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 28px; margin-top: 26px; }
.sec-h { font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); padding-bottom: 6px; border-bottom: 1px solid var(--ink); margin: 0 0 14px; display: flex; justify-content: space-between; }
.finding { padding: 0 0 20px; margin-bottom: 20px; border-bottom: 1px solid var(--rule); }
.finding:last-child { border-bottom: none; margin-bottom: 0; }
.f-top { display: flex; align-items: baseline; gap: 10px; }
.sev { font-family: var(--mono); font-size: 10.5px; font-weight: 700; letter-spacing: .08em; padding: 2px 6px; }
.sev.high { background: var(--red); color: #fff; }
.sev.medium { background: var(--ink); color: var(--paper); }
.f-title { font-size: 13px; color: var(--ink-3); font-weight: 600; }
.f-amt { margin-left: auto; font-family: var(--mono); font-weight: 600; font-size: 13px; }
.f-head { font-size: 22px; font-weight: 750; letter-spacing: -.02em; line-height: 1.25; margin: 8px 0 8px; }
.f-detail { margin: 0; font-size: 15px; line-height: 1.6; color: var(--ink-2); max-width: 70ch; }
.chip { font-family: var(--mono); font-size: 12px; font-weight: 600; background: var(--paper-2); padding: 1px 3px; color: var(--ink); cursor: default; white-space: nowrap; }
.chip:hover { background: var(--ink); color: var(--paper); }
.f-path { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 12px; font-size: 12px; color: var(--ink-3); }
.f-path .lbl { font-family: var(--mono); font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; margin-right: 4px; }
.f-path .arr { color: var(--ink-4); }
.fix { margin-top: 14px; padding: 12px 14px; border: 1.5px dashed var(--amber); background: var(--amber-bg); display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 14px; align-items: center; }
.fix p { margin: 0; font-size: 13.5px; }
.fix small { display: block; color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.btn { height: 38px; padding: 0 16px; background: var(--ink); color: #fff; border: none; font-weight: 650; font-size: 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #000; }
.btn.ghostbtn { background: transparent; color: var(--ink); border: 1px solid var(--ink); }
.fixed-note { margin-top: 14px; padding: 12px 14px; border-left: 3px solid var(--green); background: var(--green-bg); font-size: 13.5px; }
.fixed-note code { font-size: 12px; }
.ok-note { padding: 16px 18px; background: var(--green-bg); border-left: 3px solid var(--green); }
.ok-note b { display: block; font-size: 18px; margin-bottom: 4px; }

/* ---------- cypher side ---------- */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--ink); margin-bottom: 14px; }
.tab { border: none; background: none; padding: 0 0 6px; margin-right: 22px; font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-4); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.on { color: var(--ink); border-bottom-color: var(--ink); }
.q-why { font-size: 13.5px; color: var(--ink-2); margin: 0 0 10px; }
.q-file { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); margin-bottom: 6px; display: flex; justify-content: space-between; gap: 10px; }
pre.cy { margin: 0; background: var(--ink); color: #e9e6df; font-family: var(--mono); font-size: 11.8px; line-height: 1.6; padding: 14px 16px; overflow: auto; max-height: 520px; white-space: pre; }
pre.cy .kw { color: #f0c674; }
pre.cy .lb { color: #8fd3b6; }
pre.cy .rt { color: #f2a08c; }
pre.cy .cm { color: #8a877f; }
pre.cy .st { color: #b9c8f0; }
.console textarea { width: 100%; min-height: 168px; resize: vertical; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; padding: 10px 12px; border: 1px solid var(--rule-2); background: var(--card); color: var(--ink); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.preset { border: 1px solid var(--rule-2); background: var(--card); font-size: 12.5px; padding: 4px 9px; cursor: pointer; }
.preset:hover { border-color: var(--ink); }
.run-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }
table.res { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 12.5px; }
table.res th { text-align: left; font-family: var(--mono); font-size: 10.5px; font-weight: 600; letter-spacing: .04em; color: var(--ink-3); border-bottom: 1px solid var(--ink); padding: 4px 8px 4px 0; }
table.res td { border-bottom: 1px solid var(--rule); padding: 5px 8px 5px 0; font-family: var(--mono); font-size: 12px; vertical-align: top; word-break: break-word; }
.err { color: var(--red); font-family: var(--mono); font-size: 12px; margin-top: 10px; white-space: pre-wrap; }

/* ---------- footer ---------- */
.foot { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding: 14px 28px; border-top: 1px solid var(--rule-2); font-size: 12px; color: var(--ink-3); }

/* ---------- small screens ---------- */
@media (max-width: 1100px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 820px) {
  .top { gap: 12px; padding: 0 16px; }
  .tagline, .engine { display: none; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .ledger { position: static; height: auto; max-height: 320px; border-right: none; border-bottom: 1px solid var(--rule-2); }
  .stage { padding: 18px 16px 32px; }
  .inv-head { grid-template-columns: minmax(0, 1fr); }
  .inv-title { font-size: 24px; }
  .foot { padding: 14px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .edge.brk { animation: none !important; }
  .card.appear, .edge.draw { animation: none !important; stroke-dashoffset: 0; }
  .edge.draw:not(.brk):not(.sug) { stroke-dasharray: none; }
}

@media (max-width: 1180px) { .engine { display: none; } }
@media (max-width: 960px) { .tagline { display: none; } }
