:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --text: #1c1c1a;
  --muted: #64645f;
  --line: #e2e2dc;
  --accent: #2f5bd3;
  --cheat: #c0392b;
  --cheat-bg: #fbe9e7;
  --clean: #1e7f4f;
  --clean-bg: #e4f4ea;
  --gap: #9a6a00;
  --gap-bg: #fdf3d8;
  --conflict: #7b3fb5;
  --conflict-bg: #f1e8fb;
  --disputed: #b8560f;
  --disputed-bg: #fdeee2;
  --unspec: #7a6a4f;
  --unspec-bg: #f1ece2;
  --other: #5b6470;
  --other-bg: #eceef1;
  --excl: #8a8a85;
  --excl-bg: #f0f0ee;
  --miss: #c0392b;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413;
    --surface: #1d1d1b;
    --surface-2: #262623;
    --text: #ecebe6;
    --muted: #a3a29b;
    --line: #34332f;
    --accent: #7ea2ff;
    --cheat: #ff8a7a;
    --cheat-bg: #3a1f1b;
    --clean: #6fd6a0;
    --clean-bg: #17301f;
    --gap: #f0c457;
    --gap-bg: #362b12;
    --conflict: #c9a2f2;
    --conflict-bg: #2c2138;
    --disputed: #ffab6b;
    --disputed-bg: #3a2616;
    --unspec: #d2c19f;
    --unspec-bg: #2f2a20;
    --other: #b4bcc8;
    --other-bg: #262a30;
    --excl: #8f8e88;
    --excl-bg: #24241f;
    --miss: #ff8a7a;
  }
}
:root[data-theme="dark"] {
  --bg: #141413; --surface: #1d1d1b; --surface-2: #262623; --text: #ecebe6; --muted: #a3a29b; --line: #34332f;
  --accent: #7ea2ff; --cheat: #ff8a7a; --cheat-bg: #3a1f1b; --clean: #6fd6a0; --clean-bg: #17301f; --gap: #f0c457;
  --gap-bg: #362b12; --conflict: #c9a2f2; --conflict-bg: #2c2138; --disputed: #ffab6b; --disputed-bg: #3a2616;
  --unspec: #d2c19f; --unspec-bg: #2f2a20; --other: #b4bcc8; --other-bg: #262a30; --excl: #8f8e88; --excl-bg: #24241f; --miss: #ff8a7a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; }
h3 { font-size: 14px; margin: 18px 0 6px; }
button { font: inherit; color: inherit; }

.top {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap;
  padding: 20px 24px 12px;
}
.sub { margin: 4px 0 0; color: var(--muted); }
.meta { color: var(--muted); font-size: 12.5px; text-align: right; }
.meta a { margin-left: 10px; }

.tabs { display: flex; gap: 4px; padding: 0 24px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
  background: none; border: 0; padding: 10px 12px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 18px 24px 60px; max-width: 1900px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin-bottom: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
  cursor: pointer; text-align: left; border-left: 4px solid var(--line);
}
.card:hover { border-color: var(--accent); }
.card .n { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.card .t { font-weight: 600; }
.card .d { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card.l-cheat { border-left-color: var(--cheat); }
.card.l-clean { border-left-color: var(--clean); }
.card.l-amb { border-left-color: var(--conflict); }
.card.l-other { border-left-color: var(--other); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--surface); border: 0; padding: 5px 10px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); font-weight: 600; }

#gate-matrix { overflow-x: auto; }
.matrix { border-collapse: collapse; font-variant-numeric: tabular-nums; width: 100%; max-width: 760px; min-width: 560px; }
.matrix th, .matrix td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: right; }
.matrix th:first-child, .matrix td:first-child { text-align: left; }
.matrix td.cell { cursor: pointer; }
.matrix td.cell:hover { background: var(--surface-2); }
.matrix td.miss { color: var(--miss); font-weight: 650; }
.matrix .pct { color: var(--muted); font-size: 12px; margin-left: 4px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 12px 0; }
.fgroup { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.fgroup > span { color: var(--muted); font-size: 12px; margin-right: 2px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 9px; cursor: pointer;
  font-size: 12.5px; color: var(--muted);
}
.chip[aria-pressed="true"] { color: var(--text); border-color: var(--text); background: var(--surface-2); }
input[type="search"], select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px;
}
input[type="search"] { min-width: 240px; }
.check { color: var(--muted); font-size: 12.5px; display: inline-flex; gap: 5px; align-items: center; cursor: pointer; }

.results-head { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 6px; color: var(--muted); }
.sort select { margin-left: 6px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.grid { border-collapse: collapse; width: 100%; min-width: 1050px; }
.grid th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface);
}
.grid td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid td.nowrap { white-space: nowrap; }
.grid tr.row { cursor: pointer; }
.grid tr.row:hover td { background: var(--surface-2); }
.grid tr.row.open td { background: var(--surface-2); }
.repo { font-weight: 550; }
.small { font-size: 12px; color: var(--muted); }
.warn { color: var(--gap); }
.more { color: var(--muted); }

.pill { display: inline-block; border-radius: 6px; padding: 1px 7px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.l-CHEATABLE { color: var(--cheat); background: var(--cheat-bg); }
.l-CLEAN, .l-NOT_CHEATABLE { color: var(--clean); background: var(--clean-bg); }
.l-CLEAN_KNOWN_GAP { color: var(--gap); background: var(--gap-bg); }
.l-CONFLICT { color: var(--conflict); background: var(--conflict-bg); }
.l-DISPUTED, .l-DISPUTES_R1 { color: var(--disputed); background: var(--disputed-bg); }
.l-BAD_UNSPECIFIED { color: var(--unspec); background: var(--unspec-bg); }
.l-BAD_OTHER { color: var(--other); background: var(--other-bg); }
.l-EXCLUDED, .l-NEUTRAL { color: var(--excl); background: var(--excl-bg); }
.route { font-family: var(--mono); font-size: 12px; }
.route.miss { color: var(--miss); font-weight: 650; }
.tag { display: inline-block; font-size: 11.5px; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; margin: 1px 2px 1px 0; white-space: nowrap; }

.detail td { background: var(--bg); padding: 12px 14px 16px; }
.dgrid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .dgrid { grid-template-columns: 1fr; } }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
.box h4 { margin: 0 0 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.caveat { margin: 0 0 4px; padding-left: 14px; text-indent: -10px; }
.caveat::before { content: "⚠ "; color: var(--gap); }
.kv { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 3px 8px; font-size: 12.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.ev { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.ev.tier-audit { border-left: 3px solid var(--accent); }
.ev-head { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.ev-head .dec { font-weight: 600; }
.ev-body { padding: 8px 12px 10px; }
.ev .method { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0; }
.text.clamp { max-height: 9.5em; overflow: hidden; position: relative; }
.text.clamp::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2.5em; background: linear-gradient(transparent, var(--surface)); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 12.5px; }
.sub-ev { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 6px; }
.sub-ev .lbl { color: var(--muted); font-size: 12px; font-weight: 600; }

.legend {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 6px 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px;
  font-size: 13px; color: var(--muted);
}
.legend b { color: var(--text); }
.grid.compact { table-layout: fixed; min-width: 1150px; }
.grid.compact tr.row td {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 6px 10px; vertical-align: middle;
}
.grid.compact tr.row { cursor: pointer; }
.grid.compact tr.row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.grid.compact tr.row.open td { background: var(--surface-2); border-bottom-color: transparent; }
.grid.compact tr.detail > td { white-space: normal; background: var(--bg); padding: 14px 16px 18px; border-bottom: 2px solid var(--line); }
.approx { color: var(--gap); font-weight: 700; margin-left: 2px; }
.detail-head { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; margin-bottom: 12px; font-size: 13px; }
.detail-head .repo { font-size: 15px; }
.dgrid h4 { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.hr + .hr, .mr + .mr { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 8px; }
.hr-head, .mr-head { font-size: 12.5px; }
.who { font-weight: 650; }
.who.audit { color: var(--accent); }
.dec { font-weight: 600; }
.reader { color: var(--muted); }
.why { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.grid .text { margin: 4px 0 0; font-size: 13px; }
.sublbl { color: var(--muted); font-size: 12px; font-weight: 600; margin-top: 6px; }
.backed { font-weight: 600; white-space: nowrap; }
.backed.b-audit { color: var(--accent); }
.backed.b-implicit { color: var(--muted); }
.caveats { margin-top: 6px; font-size: 12px; color: var(--gap); }
.caveats div { margin-top: 3px; }
.verified { margin-top: 4px; font-size: 12px; color: var(--clean); }
.task-list { display: grid; gap: 6px; }
.task { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.task .name { min-width: 280px; font-weight: 550; }
.task .chips { display: flex; gap: 4px; flex-wrap: wrap; }
.task .chips button { border: 0; cursor: pointer; }

.prose { max-width: 860px; }
.prose p, .prose li { color: var(--text); }
.prose { overflow-wrap: anywhere; }
.prose .scroll { overflow-x: auto; }
.prose table { border-collapse: collapse; margin: 8px 0 14px; width: 100%; min-width: 520px; }
.prose th, .prose td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; font-size: 13px; }
.prose th { color: var(--muted); font-weight: 600; }
.prose .num { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .top, main { padding-left: 16px; padding-right: 16px; }
  .tabs { padding: 0 16px; }
  .meta { text-align: left; }
  input[type="search"] { min-width: 0; width: 100%; }
}
