/* Consensus. A simulator for how agreement spreads across a follow graph. */

:root {
  color-scheme: light;
  --ground:#f4f6f4; --surface:#ffffff; --surface-2:#eceeec; --surface-3:#e3e6e3;
  --ink:#16191b; --ink-2:#4b5254; --ink-3:#7d8688;
  --rule:#dfe3e0; --rule-strong:#c4cac6;
  --accent:#1c5cab; --accent-soft:#e8eff9;
  --honest:#1565c0; --adversary:#d32f2f; --novel:#1baf7a;
  /* Honest nodes are blue and adversaries are red, so a node's side reads
     instantly. Within a side the individual behaviour keeps its own shade,
     and the marker shape (circle or square) repeats the side independently
     of colour. */
  --hon-1:#1565c0; --hon-2:#0097a7; --hon-3:#7e57c2; --hon-4:#0b3d91;
  --hon-5:#5c9ce6; --hon-6:#4527a0;
  --adv-1:#d32f2f; --adv-2:#8c1515; --adv-3:#e8635c; --adv-4:#a82a24;
  --adv-5:#bf3b30; --adv-6:#f07a6e;
  --blocked:#c77800; --idle:#b6bcb8;
  --good:#12945f; --warn:#b07400; --bad:#c9302f;
  --shadow: 0 1px 2px rgba(20,25,28,.06), 0 8px 24px rgba(20,25,28,.06);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --ground:#0e1112; --surface:#161a1b; --surface-2:#1e2324; --surface-3:#272d2e;
    --ink:#eaeeeb; --ink-2:#a8b1b0; --ink-3:#798382;
    --rule:#272d2e; --rule-strong:#3a4142;
    --accent:#6da7ec; --accent-soft:#15263b;
    --honest:#5da8f0; --adversary:#f26b6b; --novel:#28b884;
    --hon-1:#5da8f0; --hon-2:#26c6da; --hon-3:#b39ddb; --hon-4:#2979d6;
    --hon-5:#9fd4ff; --hon-6:#7e6ae0;
    --adv-1:#ef5350; --adv-2:#c62828; --adv-3:#ff8a80; --adv-4:#a83232;
    --adv-5:#d94f4f; --adv-6:#f5867a;
    --blocked:#e0a02a; --idle:#49504f;
    --good:#28b884; --warn:#d79b28; --bad:#e66767;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --ground:#0e1112; --surface:#161a1b; --surface-2:#1e2324; --surface-3:#272d2e;
  --ink:#eaeeeb; --ink-2:#a8b1b0; --ink-3:#798382;
  --rule:#272d2e; --rule-strong:#3a4142;
  --accent:#6da7ec; --accent-soft:#15263b;
  --honest:#5da8f0; --adversary:#f26b6b; --novel:#28b884;
  --hon-1:#5da8f0; --hon-2:#26c6da; --hon-3:#b39ddb; --hon-4:#2979d6;
  --hon-5:#9fd4ff; --hon-6:#7e6ae0;
  --adv-1:#ef5350; --adv-2:#c62828; --adv-3:#ff8a80; --adv-4:#a83232;
  --adv-5:#d94f4f; --adv-6:#f5867a;
  --blocked:#e0a02a; --idle:#49504f;
  --good:#28b884; --warn:#d79b28; --bad:#e66767;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: Spectral, Georgia, serif; font-weight: 600; margin: 0; }
.mono, code, kbd { font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace; }

/* ---------- shell ---------- */

.app { display: flex; flex-direction: column; height: 100vh; min-height: 0; }

header.bar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 20px; border-bottom: 1px solid var(--rule);
  background: var(--surface);
}
header.bar h1 { font-size: 17px; letter-spacing: -.01em; white-space: nowrap; }
header.bar .sub { color: var(--ink-3); font-size: 12.5px; }
header.bar .spacer { flex: 1; }

main.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 288px minmax(0,1fr) 286px; gap: 0;
}
@media (max-width: 1180px) {
  main.layout { grid-template-columns: 1fr; overflow: auto; }
  .stage { min-height: 62vh; }
}

aside {
  background: var(--surface); overflow-y: auto; padding: 4px 0 28px;
}
aside.left { border-right: 1px solid var(--rule); }
aside.right { border-left: 1px solid var(--rule); }

.stage { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#net { flex: 1; display: block; width: 100%; min-height: 0; cursor: grab; }
#net.editing { cursor: crosshair; }
#net.dragging { cursor: grabbing; }

/* ---------- control groups ---------- */

.group { border-bottom: 1px solid var(--rule); padding: 14px 18px 16px; }
.group > h3 {
  font-family: "IBM Plex Mono", monospace; font-size: 10.5px; letter-spacing: .13em;
  text-transform: uppercase; color: var(--ink-3); font-weight: 500; margin-bottom: 12px;
}

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.field:last-child { margin-bottom: 0; }
.field .row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.field label { font-size: 12.5px; color: var(--ink-2); }
.field .val {
  font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.field .hint { font-size: 11px; color: var(--ink-3); line-height: 1.4; }

input[type=range] { width: 100%; accent-color: var(--accent); height: 18px; }
select, input[type=number], input[type=text] {
  width: 100%; font: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--rule-strong);
  border-radius: 6px; padding: 6px 8px;
}
select:focus-visible, input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

button {
  font: inherit; font-size: 13px; cursor: pointer; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--rule-strong);
  border-radius: 6px; padding: 7px 12px; transition: background .12s, border-color .12s;
}
button:hover { background: var(--surface-3); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btnrow { display: flex; gap: 7px; flex-wrap: wrap; }
.btnrow.split > button { flex: 1; }

/* ---------- strategy mix ---------- */

.mixrow { display: grid; grid-template-columns: 1fr 76px 26px; gap: 6px; margin-bottom: 7px; align-items: center; }
.mixrow .pctwrap {
  display: flex; align-items: center; gap: 3px;
  background: var(--surface-2); border: 1px solid var(--rule-strong); border-radius: 6px;
  padding: 0 7px 0 0;
}
.mixrow .pctwrap:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.mixrow .pctwrap span { font-size: 12px; color: var(--ink-3); }
.mixrow .pct {
  text-align: right; width: 100%; border: 0; background: transparent; padding: 6px 0 6px 7px;
  -moz-appearance: textfield;
}
.mixrow .pct:focus-visible { outline: none; }
.mixrow .pct::-webkit-outer-spin-button, .mixrow .pct::-webkit-inner-spin-button { margin: 0; }

.mixtotal {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: "IBM Plex Mono", monospace; font-size: 11.5px; color: var(--ink-3);
  margin: 2px 0 9px;
}
.mixtotal .n { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.mixtotal.off .n { color: var(--bad); font-weight: 500; }
.mixtotal button {
  border: 0; background: transparent; padding: 0; font-size: 11.5px; color: var(--accent);
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.mixrow button { padding: 5px 0; line-height: 1; }
.mixbar { display: flex; height: 7px; border-radius: 4px; overflow: hidden; margin: 9px 0 4px; background: var(--surface-3); }
.mixbar span { display: block; }

/* ---------- timeline ---------- */

.timeline {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-top: 1px solid var(--rule); background: var(--surface);
}
.timeline .label {
  font-family: "IBM Plex Mono", monospace; font-size: 12px; color: var(--ink-2);
  min-width: 112px; font-variant-numeric: tabular-nums;
}
.timeline input[type=range] { flex: 1; }

/* ---------- readout ---------- */

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--rule); border-bottom: 1px solid var(--rule); }
.metric { background: var(--surface); padding: 11px 14px; display: flex; flex-direction: column; gap: 2px; }
.metric.wide { grid-column: 1 / -1; }
.metric .n { font-family: Spectral, Georgia, serif; font-size: 23px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.metric .l { font-size: 10.8px; color: var(--ink-3); line-height: 1.35; }

.legend { display: flex; flex-direction: column; gap: 8px; font-size: 12.2px; color: var(--ink-2); }
.legend .row { display: flex; align-items: center; gap: 9px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot.sq { border-radius: 2px; }
.dot.ring { background: transparent; border: 2px dashed var(--ink); }

table.pop { width: 100%; border-collapse: collapse; font-size: 12.2px; }
table.pop th, table.pop td { text-align: right; padding: 5px 4px; border-bottom: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
table.pop th:first-child, table.pop td:first-child { text-align: left; }
table.pop th { font-family: "IBM Plex Mono", monospace; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); font-weight: 500; }
table.pop tr:last-child td { border-bottom: none; }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

.tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: 8px;
  box-shadow: var(--shadow); padding: 9px 12px; font-size: 12.2px; line-height: 1.45;
  opacity: 0; transition: opacity .1s; max-width: 250px;
}
.tip b { font-weight: 600; }
.tip .k { color: var(--ink-3); font-family: "IBM Plex Mono", monospace; font-size: 11px; display: block; margin-top: 2px; }

.banner {
  margin: 12px 18px; padding: 10px 12px; border-radius: 8px; font-size: 12.3px; line-height: 1.45;
  background: var(--accent-soft); border-left: 3px solid var(--accent); color: var(--ink-2);
}
.banner.warn { background: color-mix(in oklab, var(--warn) 14%, var(--surface)); border-left-color: var(--warn); }
.banner.bad { background: color-mix(in oklab, var(--bad) 12%, var(--surface)); border-left-color: var(--bad); }

.busy { position: absolute; inset: 0; display: grid; place-items: center; background: color-mix(in oklab, var(--ground) 68%, transparent); font-size: 13px; color: var(--ink-2); z-index: 4; }
[hidden] { display: none !important; }

/* ---------- code editor ---------- */

textarea#code {
  width: 100%; resize: vertical; min-height: 190px;
  font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  font-size: 11.6px; line-height: 1.55; tab-size: 2;
  color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--rule-strong); border-radius: 6px; padding: 9px 10px;
  white-space: pre; overflow-wrap: normal; overflow-x: auto;
}
textarea#code:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#code-error { font-family: "IBM Plex Mono", monospace; font-size: 11.4px; white-space: pre-wrap; }

/* ---------- information buttons ---------- */

button.info {
  display: inline-grid; place-items: center;
  width: 15px; height: 15px; padding: 0; margin-left: 5px;
  border-radius: 50%; border: 1px solid var(--rule-strong);
  background: transparent; color: var(--ink-3);
  font-family: Spectral, Georgia, serif; font-size: 10.5px; font-style: italic;
  line-height: 1; vertical-align: middle; cursor: help;
}
button.info:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
button.info[aria-expanded="true"] { border-color: var(--accent); color: #fff; background: var(--accent); }

.popover {
  position: fixed; z-index: 20; max-width: 330px;
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--rule-strong); border-radius: 9px;
  box-shadow: var(--shadow); padding: 13px 15px;
  font-size: 12.6px; line-height: 1.5;
}
.popover h4 {
  margin: 0 0 6px; font-family: Spectral, Georgia, serif; font-size: 14px;
  font-weight: 600; color: var(--ink);
}
.popover p { margin: 0 0 8px; }
.popover p:last-child { margin-bottom: 0; }
.popover code { background: var(--surface-2); padding: .1em .35em; border-radius: 3px; font-size: 11.4px; }
.popover em { color: var(--ink); font-style: normal; font-weight: 500; }

/* ---------- theme toggle ---------- */

button.ghost.icon {
  width: 32px; height: 30px; padding: 0; display: grid; place-items: center;
  font-size: 15px; line-height: 1;
}

/* ---------- definition lists inside popovers ---------- */

.popover dl.defs { margin: 4px 0 0; }
.popover dl.defs dt {
  font-family: "IBM Plex Mono", monospace; font-size: 11.4px; color: var(--ink);
  margin-top: 9px; font-weight: 500;
}
.popover dl.defs dt:first-child { margin-top: 0; }
.popover dl.defs dd { margin: 2px 0 0; }

/* ---------- node context menu ---------- */

.menu {
  position: fixed; z-index: 25; min-width: 186px; max-height: 70vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: 9px;
  box-shadow: var(--shadow); padding: 5px;
}
.menu .head {
  font-family: "IBM Plex Mono", monospace; font-size: 10px; letter-spacing: .11em;
  text-transform: uppercase; color: var(--ink-3); padding: 7px 9px 5px;
}
.menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  border: 0; background: transparent; border-radius: 5px; padding: 6px 9px; font-size: 12.8px;
}
.menu button:hover { background: var(--accent-soft); }
.menu button[aria-current="true"] { color: var(--accent); font-weight: 500; }
.menu hr { border: 0; border-top: 1px solid var(--rule); margin: 5px 0; }

/* ---------- who is in the run ---------- */

.roster { display: flex; flex-direction: column; gap: 7px; }
.roster .row { display: flex; align-items: baseline; gap: 9px; font-size: 12.4px; }
.roster .row .nm { color: var(--ink); }
.roster .row .ct { margin-left: auto; font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.roster .dot { margin-top: 4px; }
.roster .side {
  font-family: "IBM Plex Mono", monospace; font-size: 10px; letter-spacing: .11em;
  text-transform: uppercase; color: var(--ink-3); margin-top: 4px;
}
.roster .side:first-child { margin-top: 0; }

/* ---------- reset action ---------- */

/* Regenerate discards a hand-edited graph and draws a new one, so it should not
   look like the neutral actions beside it. */
button.reset {
  background: transparent;
  border-color: var(--warn);
  color: var(--warn);
}
button.reset:hover { background: color-mix(in oklab, var(--warn) 13%, var(--surface)); }
button.reset:focus-visible { outline-color: var(--warn); }
