:root {
  --bg: #f4f4f5;
  --panel: #ffffff;
  --ink: #18181b;
  --ink2: #3f3f46;
  --muted: #71717a;
  --faint: #a1a1aa;
  --line: #e4e4e7;
  --grid: #f0f0f2;
  --hover: #f4f4f5;
  --fault: #e0442a;
  --fault-soft: #fde7e2;
  --onfault: #ffffff;
  --radius: 10px;
  --sans: "Geist Sans", ui-sans-serif, system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0d;
    --panel: #131316;
    --ink: #ededf0;
    --ink2: #c4c4cb;
    --muted: #8d8d96;
    --faint: #5c5c66;
    --line: #26262c;
    --grid: #1a1a1f;
    --hover: #1c1c21;
    --fault: #ff5a3c;
    --fault-soft: #3a1710;
    --onfault: #140805;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0b0d;
  --panel: #131316;
  --ink: #ededf0;
  --ink2: #c4c4cb;
  --muted: #8d8d96;
  --faint: #5c5c66;
  --line: #26262c;
  --grid: #1a1a1f;
  --hover: #1c1c21;
  --fault: #ff5a3c;
  --fault-soft: #3a1710;
  --onfault: #140805;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
  font-feature-settings: "ss01", "tnum";
}
a { color: inherit; text-underline-offset: 3px; text-decoration-color: var(--faint); }
a:hover { text-decoration-color: var(--ink); }
.mono, code { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }

/* Header */
.bar {
  display: flex; align-items: center; gap: 20px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.mark { display: flex; align-items: center; gap: 9px; text-decoration: none; font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.mark svg { width: 30px; height: 20px; fill: none; stroke: var(--fault); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.tag { margin: 0; color: var(--muted); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.links { display: flex; align-items: center; gap: 16px; }
.links a { text-decoration: none; color: var(--ink2); }
.links a:hover { color: var(--ink); }

/* Buttons and inputs */
button, select, input {
  font: inherit; color: inherit;
}
button {
  cursor: pointer; border-radius: 7px; padding: 7px 12px; border: 1px solid var(--line);
  background: var(--panel); transition: background .12s, border-color .12s, transform .06s;
  white-space: nowrap;
}
button:hover { background: var(--hover); border-color: var(--faint); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; transform: none; }
button.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 500; }
button.primary:hover { background: var(--ink2); }
button.ghost { background: transparent; }
button.small { padding: 4px 9px; font-size: 12.5px; }
button.icon { padding: 6px; display: inline-grid; place-items: center; }
button.icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
button.primary.icon svg .ip { fill: currentColor; stroke: none; }
button.danger { color: var(--fault); border-color: color-mix(in srgb, var(--fault) 40%, var(--line)); }
button.danger:hover { background: var(--fault-soft); }
:focus-visible { outline: 2px solid var(--fault); outline-offset: 2px; }
select, input {
  width: 100%; padding: 7px 9px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--panel);
}
input[type="number"] { font-family: var(--mono); }

/* Layout */
.lab {
  display: grid; gap: 12px; padding: 12px;
  grid-template-columns: 250px minmax(0, 1fr) 330px;
  grid-template-areas:
    "controls stage side"
    "history history history";
  max-width: 1680px; margin: 0 auto;
}
.controls { grid-area: controls; }
.stage { grid-area: stage; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; min-width: 0; }
.side { grid-area: side; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-content: start; min-width: 0; }
.history { grid-area: history; min-width: 0; }
.stage > *, .side > * { min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.label {
  margin: 0 0 8px; font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  display: flex; align-items: baseline; gap: 8px;
}
.label .mono { text-transform: none; letter-spacing: 0; color: var(--ink); font-size: 12px; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }
.controls .label { margin-top: 18px; }
.controls .label:first-child { margin-top: 0; }
.field { margin-bottom: 10px; }
.field > label { display: block; font-size: 12.5px; color: var(--ink2); margin-bottom: 4px; }
.seedrow { display: flex; gap: 6px; }
.row2 { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.row2 .primary { flex: 1; }
.count { color: var(--ink); font-family: var(--mono); letter-spacing: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { font-size: 12px; padding: 4px 8px; font-family: var(--mono); }
.chips button[aria-pressed="true"] { border-color: var(--fault); color: var(--fault); }

.faults { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; border-top: 1px solid var(--line); }
.faults li { display: grid; grid-template-columns: 54px 1fr auto; gap: 6px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.faults li.past { color: var(--muted); }
.faults li .t { font-family: var(--mono); font-size: 11.5px; color: var(--muted); cursor: pointer; }
.faults li .t:hover { color: var(--fault); }
.faults li button { padding: 0 6px; border: 0; font-size: 15px; line-height: 1; color: var(--faint); background: none; }
.faults li button:hover { color: var(--fault); }
.faults .empty { display: block; color: var(--muted); padding: 8px 0; }

/* Scope */
.scopehead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.scopehead .label { margin: 0; }
.scopehead .hint { margin: 0; }
#cluster { width: 100%; height: auto; display: block; max-height: 470px; user-select: none; touch-action: manipulation; }
#cluster .link { stroke: var(--line); stroke-width: 1.5; }
#cluster .link.cut { stroke: var(--fault); stroke-dasharray: 5 5; }
#cluster .cutx { stroke: var(--fault); stroke-width: 2; }
#cluster .node { cursor: pointer; }
#cluster .node .body { fill: var(--panel); stroke: var(--ink); stroke-width: 1.5; transition: fill .15s; }
#cluster .node.leader .body { fill: var(--ink); }
#cluster .node.candidate .body { stroke-dasharray: 4 3; stroke-width: 2; }
#cluster .node.down .body { fill: var(--grid); stroke: var(--faint); stroke-dasharray: 2 3; }
#cluster .node.sel .halo { stroke: var(--fault); }
#cluster .node .halo { fill: none; stroke: transparent; stroke-width: 2; }
#cluster .node:hover .halo { stroke: var(--faint); }
#cluster .node.sel:hover .halo { stroke: var(--fault); }
#cluster .nlabel { font: 600 16px var(--sans); fill: var(--ink); text-anchor: middle; dominant-baseline: central; pointer-events: none; }
#cluster .leader .nlabel { fill: var(--panel); }
#cluster .down .nlabel { fill: var(--faint); }
#cluster .nsub { font: 11px var(--mono); fill: var(--muted); text-anchor: middle; pointer-events: none; }
#cluster .meter { fill: var(--grid); }
#cluster .meter-last { fill: var(--faint); }
#cluster .meter-commit { fill: var(--ink); }
#cluster .drift { font: 10px var(--mono); fill: var(--fault); text-anchor: middle; }
#cluster .client rect { fill: var(--panel); stroke: var(--faint); }
#cluster .client text { font: 10.5px var(--mono); fill: var(--muted); text-anchor: middle; dominant-baseline: central; }
#cluster .msg { fill: var(--ink); }
#cluster .msg.vote { fill: var(--panel); stroke: var(--ink); stroke-width: 1.3; }
#cluster .msg.client { fill: var(--muted); }
#cluster .msg.lost { fill: var(--fault); }
#cluster .msg.snap { fill: var(--ink); stroke: var(--fault); stroke-width: 1.3; }
#cluster .legend text { font: 10.5px var(--sans); fill: var(--muted); dominant-baseline: central; }
#cluster .banner { font: 500 12px var(--mono); fill: var(--fault); text-anchor: middle; }

.netbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
.netbar .label { margin: 0 4px 0 0; }

/* Seismograph */
.transport { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.transport select { width: auto; padding: 5px 6px; font-size: 12.5px; }
.steptext { color: var(--ink2); margin-left: 6px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 1; }
#seis { width: 100%; max-width: 100%; display: block; cursor: ew-resize; touch-action: none; }

/* Verdict */
.vhead { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.vlabel { font-size: 30px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.verdict.fail .vlabel { color: var(--fault); }
.verdict.fail { border-color: color-mix(in srgb, var(--fault) 45%, var(--line)); }
.vsub { color: var(--muted); }
.vdetail { margin: 8px 0 0; font-size: 13px; }
.vdetail:empty { display: none; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 10px; margin: 12px 0; }
.stats div { min-width: 0; }
.stats dt { font-size: 11px; color: var(--muted); }
.stats dd { margin: 0; font-family: var(--mono); font-size: 13px; }
.fp { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.fp .label { margin: 0; }
.fp code { flex: 1; }
.shrinkout { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 13px; }
.shrinkout table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12.5px; }
.shrinkout td, .shrinkout th { text-align: right; padding: 3px 0; }
.shrinkout th { font-family: var(--sans); font-weight: 400; color: var(--muted); font-size: 11.5px; }
.shrinkout td:first-child, .shrinkout th:first-child { text-align: left; font-family: var(--sans); }
.shrinkout .row2 { margin-top: 10px; }

/* Inspector */
.kvs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; margin: 0 0 10px; }
.kvs dt { font-size: 11px; color: var(--muted); }
.kvs dd { margin: 0; font-family: var(--mono); font-size: 13px; }
.loglist { font-family: var(--mono); font-size: 11.5px; max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: 7px; }
.loglist div { display: grid; grid-template-columns: 34px 28px 1fr; gap: 6px; padding: 2px 8px; white-space: nowrap; }
.loglist div.uncommitted { color: var(--muted); }
.loglist div.volatile { color: var(--fault); }
.loglist div.commitline { border-top: 1px solid var(--ink); }
.loglist .i { color: var(--faint); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.kvtable { font-family: var(--mono); font-size: 12px; margin-top: 8px; }
.kvtable div { display: flex; gap: 8px; }
.kvtable span:first-child { color: var(--muted); width: 26px; flex: none; }

/* Event log */
.events { list-style: none; margin: 0; padding: 0; font-size: 11.5px; max-height: 230px; overflow: auto; }
.events li { display: grid; grid-template-columns: 62px 1fr; gap: 8px; padding: 2px 4px; border-radius: 4px; cursor: pointer; }
.events li:hover { background: var(--hover); }
.events li .t { color: var(--faint); }
.events li.now { background: var(--hover); color: var(--ink); box-shadow: inset 2px 0 var(--ink); }
.events li.fault { color: var(--fault); }
.events li.lost { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--fault); }

/* History */
.histhead { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.histhead .label { margin: 0; }
.histhead .label .hint { text-transform: none; letter-spacing: 0; margin: 0; }
.keys { display: flex; gap: 4px; }
.keys button { font-family: var(--mono); font-size: 12px; padding: 3px 9px; }
.keys button[aria-selected="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.keys button.bad { border-color: var(--fault); }
.keys button.bad[aria-selected="true"] { background: var(--fault); border-color: var(--fault); color: var(--onfault); }
.zoom { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.zoom .mono { color: var(--muted); min-width: 64px; text-align: center; }
#hist { width: 100%; display: block; }
#hist .lane { fill: var(--grid); }
#hist .lanelabel { font: 11px var(--mono); fill: var(--muted); dominant-baseline: central; }
#hist .op rect { fill: var(--panel); stroke: var(--ink2); stroke-width: 1; }
#hist .op.read rect { fill: var(--grid); }
#hist .op.pending rect { stroke-dasharray: 3 3; }
#hist .op.lin rect { stroke: var(--ink); stroke-width: 1.5; }
#hist .op.stuck rect { stroke: var(--fault); stroke-width: 2; fill: var(--fault-soft); }
#hist .op text { font: 10.5px var(--mono); fill: var(--ink); dominant-baseline: central; pointer-events: none; }
#hist .op .ord { fill: var(--muted); font-size: 9.5px; }
#hist .op.stuck .ord { fill: var(--fault); }
#hist .axis { stroke: var(--line); }
#hist .tick { font: 10px var(--mono); fill: var(--faint); text-anchor: middle; }
#hist .ph { stroke: var(--ink); stroke-width: 1; }
#hist .lp { stroke: var(--faint); stroke-width: 1; stroke-dasharray: 2 3; }
#hist .op { cursor: pointer; }
.trace { font-size: 13px; margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.trace:empty { display: none; }
.trace h3 { margin: 0 0 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
.trace ol { margin: 0; padding: 0; list-style: none; font-family: var(--mono); font-size: 11.5px; max-height: 190px; overflow: auto; border: 1px solid var(--line); border-radius: 7px; }
.trace li { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; padding: 2px 8px; }
.trace li .n { color: var(--faint); }
.trace li .s { color: var(--muted); max-width: 18ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trace li.stuck { color: var(--fault); }
.trace p { margin: 0 0 6px; }
.trace strong { font-weight: 600; }

/* About */
.about { max-width: 1680px; margin: 0 auto; padding: 28px 24px 48px; }
.aboutgrid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px; }
.about h2 { font-size: 20px; letter-spacing: -0.01em; margin: 0 0 10px; font-weight: 600; }
.about p { max-width: 68ch; color: var(--ink2); }
.trace .cycle li { grid-template-columns: 48px 1fr auto; }
.trace .cycle li.edge { color: var(--muted); font-size: 11.5px; border: 0; }
.trace .cycle li.edge .n { font-family: var(--mono); text-transform: lowercase; }
.story { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.story ol { margin: 6px 0 0; padding-left: 1.6em; font-size: 12.5px; line-height: 1.5; }
.story li { cursor: pointer; padding: 2px 0; color: var(--ink2); }
.story li:hover { color: var(--ink); }
.story li .bt { color: var(--muted); font-size: 11px; margin-right: 6px; }
.story li.fault { color: var(--ink); }
.story li.violation { color: var(--fault); font-weight: 500; }
.gallerywrap { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--line); }
.gallerywrap h2 { margin-bottom: 4px; }
.gallery { list-style: none; margin: 14px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.gallery button { width: 100%; height: 100%; text-align: left; white-space: normal; display: grid; gap: 6px; align-content: start; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: none; font: inherit; color: inherit; cursor: pointer; }
.gallery button:hover { border-color: var(--ink2); }
.gallery .gt { font-weight: 600; color: var(--ink); }
.gallery .gs { color: var(--ink2); font-size: 13px; }
.gallery .gm { color: var(--muted); font-size: 11.5px; }
.gallery .gv { color: var(--ink2); }
.gallery .gv.bad { color: var(--fault); }
.aboutgrid.one { grid-template-columns: minmax(0, 1fr); }
.aboutgrid.one p { max-width: 78ch; }
.resultswrap { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--line); }
.resultswrap .hint { max-width: 78ch; }
.aboutgrid.second { margin-top: 36px; padding-top: 28px; border-top: 1px solid var(--line); }
.mcbtns { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 8px; }
.mcbtns button[aria-pressed="true"] { border-color: var(--ink); color: var(--ink); }
.mctrace { margin: 10px 0 0; padding-left: 2.6em; font-size: 12px; line-height: 1.7; color: var(--ink2); max-width: 68ch; }
.mctrace li::marker { color: var(--muted); }
.rates b { font-weight: 600; color: var(--ink); }
.rates { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 10px; }
.rates th { text-align: left; font-weight: 400; color: var(--muted); font-size: 11.5px; border-bottom: 1px solid var(--line); padding: 4px 0; }
.rates td { padding: 6px 10px 6px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.rates th { padding-right: 10px; }
.ratescroll { overflow-x: auto; }
#recovery { margin-top: 28px; }
#recovery h3 { font-size: 14px; font-weight: 600; margin: 0 0 4px; }
.recgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px 28px; margin-top: 14px; }
.recrow { margin: 0; }
.recrow figcaption { font-family: var(--mono); font-size: 12px; color: var(--ink); margin-bottom: 8px; display: flex; flex-direction: column; gap: 2px; }
.recrow figcaption span { color: var(--muted); font-size: 11px; }
.recunit { font-size: 10px; color: var(--faint); text-align: right; margin-top: 2px; }
.recbars { display: grid; grid-template-columns: repeat(9, 1fr); align-items: end; gap: 3px; height: 64px; border-bottom: 1px solid var(--line); }
.recbars span { display: block; background: var(--ink2); border-radius: 2px 2px 0 0; min-height: 1px; }
.recaxis { display: grid; grid-template-columns: repeat(9, 1fr); gap: 3px; font-family: var(--mono); font-size: 10px; color: var(--muted); margin-top: 4px; }
.recaxis span { transform: translateX(-50%); white-space: nowrap; }
.ratescroll .rates td:nth-child(4), .ratescroll .rates td:nth-child(5) { font-family: var(--mono); white-space: nowrap; }
.rates td:first-child { font-family: var(--mono); font-size: 12px; }
.rates td:nth-child(2) { font-family: var(--mono); }
.rates button { padding: 0; border: 0; background: none; font: inherit; text-decoration: underline; text-decoration-color: var(--faint); text-underline-offset: 3px; }
.rates tr.correct td { color: var(--ink); font-weight: 500; }
.foot { margin-top: 28px; color: var(--muted); font-size: 13px; }

/* Busy state */
.busy { position: relative; }
.busy::after { content: ""; position: absolute; inset: 0; background: color-mix(in srgb, var(--panel) 50%, transparent); border-radius: inherit; pointer-events: none; }

@media (max-width: 1240px) {
  .lab { grid-template-columns: 240px minmax(0, 1fr); grid-template-areas: "controls stage" "side side" "history history"; }
  .side { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
}
@media (max-width: 820px) {
  .bar { padding: 12px 16px; gap: 12px; }
  .tag { display: none; }
  .links { margin-left: auto; gap: 12px; }
  .lab { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "side" "controls" "history"; padding: 10px; gap: 10px; }
  .panel { padding: 12px; }
  .side { grid-template-columns: minmax(0, 1fr); }
  .aboutgrid { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .about { padding: 20px 16px 40px; }
  .trace { grid-template-columns: minmax(0, 1fr); }
  .zoom { margin-left: 0; }
  .vlabel { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
