:root {
  --bg: #000;
  --fg: #fff;
  --dim: #a8a8a8;
  --mid: #767676;
  --faint: #3f3f3f;
  --line: #262626;
  --panel: #0a0a0a;
  --cell: #060606;
  --card: 370px;
  --gap: 16px;
  --pad: 8px;
  --tall: 15px;
  --add: 22px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 1px solid var(--line);
  cursor: pointer;
  padding: 0;
}

button:hover { border-color: var(--fg); }

.icon {
  width: 24px;
  height: 24px;
  line-height: 1;
  display: grid;
  place-items: center;
  flex: none;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
  display: block;
}

.dot[data-empty="1"] { border: 1px solid var(--faint); }
.dot[data-on="1"] { outline: 1px solid var(--fg); outline-offset: 2px; }

#bar {
  flex: none;
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  z-index: 40;
}

#brand { color: var(--dim); }

#bundles {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: auto;
  max-width: 55vw;
}

.bundle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px 3px 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.bundle[data-active="1"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.bundle[data-active="1"] .kill { color: var(--bg); }
.bundle .name { outline: none; cursor: text; }
.bundle .name:empty::before { content: "·"; color: var(--faint); }
.bundle .kill { visibility: hidden; }
.bundle:hover .kill { visibility: visible; }

#share[data-ok="1"], #refresh[data-ok="1"] { background: var(--fg); color: var(--bg); }

#isolate {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  cursor: pointer;
  flex: none;
}

#isolate .dot { width: 12px; height: 12px; }
#isolate:hover { border-color: var(--fg); }
.spacer { flex: 1; }
#who { color: var(--mid); }

#connection-button { padding: 3px 7px; white-space: nowrap; }
#connection {
  width: min(440px, calc(100vw - 32px));
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--mid);
  padding: 24px;
}
#connection::backdrop { background: rgb(0 0 0 / 75%); }
#connection h1 { font-size: 16px; margin: 0 0 16px; }
#connection p { line-height: 1.6; }
#connection label { display: block; margin: 16px 0 8px; }
#connection input {
  width: 100%;
  padding: 9px;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--mid);
}
#connection details { margin-top: 16px; }
#connection summary { cursor: pointer; color: var(--dim); }
#connection .hint { color: var(--dim); font-size: 12px; }
#connection a { color: inherit; }
#connection-error { color: #ff5f56; }
#connection .actions { display: flex; gap: 8px; margin-top: 20px; }
#connection button { padding: 7px 10px; }
#connection button:disabled { opacity: .5; cursor: wait; }
#connect { background: var(--fg); color: var(--bg); }
#disconnect { margin-left: auto; }

body.privacy { overflow: auto; height: auto; display: block; }
.privacy article { max-width: 720px; margin: 48px auto; padding: 0 24px; line-height: 1.7; }
.privacy h1 { font-size: 20px; }
.privacy a { color: inherit; }
.privacy li { margin: 12px 0; }

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

#wires {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
  overflow: visible;
  color: var(--fg);
}

#wires path.wire {
  fill: none;
  stroke: var(--fg);
  stroke-width: 1.5;
  marker-end: url(#arrow);
  marker-start: url(#dot);
}

#wires path.wire[data-kind="stack"] {
  stroke: var(--dim);
  stroke-width: 1;
  stroke-dasharray: 3 2;
}

#wires path.hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  pointer-events: stroke;
  cursor: pointer;
}

#wires path.hit:hover + path.wire { stroke: var(--fg); stroke-width: 2.5; }
#wires path.wire.live { stroke: var(--fg); stroke-dasharray: 4 3; }

#grid {
  display: grid;
  gap: 1px;
  background: var(--line);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  width: max-content;
  position: relative;
  z-index: 10;
}

.colhead, .rowhead, .cell, .corner, .addcol, .addrow, .filler {
  background: var(--bg);
  min-width: 0;
}

.corner, .rowhead, .addrow {
  width: 36px;
  position: sticky;
  left: 0;
  z-index: 12;
}

.colhead, .corner, .addcol {
  position: sticky;
  top: 0;
  z-index: 14;
}

.corner { z-index: 16; }

.colhead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 36px;
  background: var(--panel);
  cursor: grab;
}

.colhead .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.colhead .count { color: var(--mid); }
.colhead .kill, .rowhead .kill { visibility: hidden; }
.colhead:hover .kill, .rowhead:hover .kill { visibility: visible; }

.kill {
  border: none;
  color: var(--dim);
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  flex: none;
}

.kill:hover { color: var(--fg); }

.corner, .addcol, .addrow {
  display: grid;
  place-items: center;
  background: var(--panel);
  color: var(--dim);
  height: 36px;
}

.addcol { width: 36px; cursor: pointer; }
.addrow { cursor: pointer; height: auto; min-height: 36px; }
.addcol:hover, .addrow:hover { color: var(--fg); background: #111; }

.rowhead {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  color: var(--dim);
  background: var(--panel);
  padding: 8px 0;
  cursor: grab;
}

.rowhead .ord { font-size: 15px; }

.cell {
  background: var(--cell);
  padding: var(--tall) var(--pad);
  display: flex;
  flex-direction: row;
  gap: var(--gap);
  min-height: 84px;
  min-width: 0;
}

.cell.bucket {
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 6px;
  padding: 8px;
  background: #040404;
  min-height: 42px;
}

.rowhead.bucket { cursor: default; color: var(--faint); }
.rowhead.bucket .ord { font-size: 12px; }

.card.chip {
  width: auto;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  grid-template-columns: none;
}

.card.chip .title {
  display: block;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--dim);
  font-size: 12px;
}

.card.chip .kill {
  position: static;
  visibility: hidden;
  background: none;
}

.card.chip:hover .kill { visibility: visible; }

.cell[data-over="1"] { background: #141414; outline: 1px solid var(--fg); outline-offset: -1px; }

.cell .add {
  width: var(--add);
  flex: none;
  color: var(--faint);
  border: 1px dashed var(--line);
  display: grid;
  place-items: center;
  opacity: 0;
  cursor: pointer;
}

.cell:hover .add { opacity: 1; }
.cell .add:hover { color: var(--fg); border-color: var(--fg); }

.card {
  width: var(--card);
  flex: none;
  border: 1px solid var(--line);
  border-left: 3px solid var(--faint);
  background: #0d0d0d;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  cursor: grab;
  position: relative;
  user-select: none;
}

.card .body {
  display: grid;
  align-content: start;
  gap: 5px;
  min-width: 0;
}

.card .rail {
  display: grid;
  align-content: start;
  gap: 3px;
  padding-left: 9px;
  border-left: 1px solid var(--line);
  text-align: right;
  font-size: 10px;
  line-height: 1.2;
}

.st { color: var(--faint); }
.st[data-on="1"][data-key="draft"] { color: #b6b6b6; }
.st[data-on="1"][data-key="ready"] { color: #5f9fff; }
.st[data-on="1"][data-key="review"] { color: #ffd93f; }
.st[data-on="1"][data-key="conflict"] { color: #ff5f56; }
.st[data-on="1"][data-key="approved"] { color: #5fd75f; }
.st[data-on="1"][data-key="merged"] { color: #b57fff; }

.dot.checks {
  border: 1px solid var(--faint);
  margin-left: auto;
}

.dot.checks[data-state="SUCCESS"] { background: #5fd75f; border-color: transparent; }
.dot.checks[data-state="FAILURE"], .dot.checks[data-state="ERROR"] { background: #ff5f56; border-color: transparent; }
.dot.checks[data-state="PENDING"], .dot.checks[data-state="EXPECTED"] { background: #ffd93f; border-color: transparent; }

.hole {
  width: var(--card);
  flex: none;
  display: grid;
  place-items: center;
  color: transparent;
  border: 1px dashed transparent;
  cursor: pointer;
}

.cell:hover .hole { border-color: var(--line); }
.hole:hover { color: var(--fg); border-color: var(--fg); }
#stage[data-dragging="1"] .hole { border-color: var(--line); }

.card:hover { border-color: var(--dim); }
.card[data-draft="1"] { border-top-style: dashed; border-right-style: dashed; border-bottom-style: dashed; }
.card[data-state="MERGED"] .num { text-decoration: line-through; }
.card[data-selected="1"] { border-color: var(--fg); }
.card[data-drag="1"] { opacity: 0.25; }
.card[data-dim="1"] { opacity: 0.32; }
.card[data-target="1"] { outline: 1px dashed var(--fg); outline-offset: 2px; }

.card .top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card .chips {
  display: flex;
  gap: 3px;
  padding: 3px;
  margin: -3px;
  cursor: pointer;
  flex: none;
}

.card .num { color: var(--fg); flex: none; }
.card .num:hover { text-decoration: underline; }

.card .who {
  color: var(--mid);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


.card .title {
  color: var(--fg);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}

.card .refs {
  display: grid;
  gap: 1px;
  font-size: 12px;
  color: #d4d4d4;
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.card .refs .base { color: var(--mid); }

.card .grow {
  border: none;
  color: var(--mid);
  padding: 0 3px;
  margin-left: 6px;
  line-height: 1.2;
  white-space: nowrap;
}

.card .grow:hover { color: var(--fg); background: #1c1c1c; }

.card .kill {
  position: absolute;
  bottom: 3px;
  right: 3px;
  visibility: hidden;
  background: #0d0d0d;
}

.card:hover .kill { visibility: visible; }

.card .plug {
  position: absolute;
  right: -6px;
  top: 50%;
  translate: 0 -50%;
  width: 11px;
  height: 11px;
  border: 1px solid var(--dim);
  background: var(--bg);
  border-radius: 50%;
  cursor: crosshair;
  visibility: hidden;
  z-index: 3;
}

.card:hover .plug, .card[data-wiring="1"] .plug { visibility: visible; }
.card .plug:hover { background: var(--fg); }

#tags {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  max-height: 25vh;
  overflow: auto;
  z-index: 30;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 4px 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  cursor: grab;
  user-select: none;
}

.tag[data-active="1"] { background: var(--fg); color: var(--bg); }
.tag[data-active="1"] .kill { color: var(--bg); }

.tag .name {
  min-width: 5ch;
  outline: none;
  cursor: text;
  white-space: pre;
  user-select: text;
}

.tag .name:empty::before {
  content: "·";
  color: var(--faint);
}

.addtag {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  color: var(--dim);
  flex: none;
}

#ghost {
  position: fixed;
  z-index: 60;
  width: var(--card);
  pointer-events: none;
  opacity: 0.9;
  rotate: -1deg;
}

#tagghost {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  opacity: 0.9;
}

#guide {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  z-index: 85;
  display: grid;
  justify-items: center;
  align-content: start;
  padding: 12vh 16px 16px;
  overflow: auto;
}

#guide article {
  width: min(680px, 100%);
  border: 1px solid var(--fg);
  background: var(--panel);
  padding: 22px 26px;
}

#guide p {
  margin: 0 0 16px;
  line-height: 1.7;
  color: var(--dim);
}

#guide p:first-child { color: var(--fg); }
#guide p:last-child { margin-bottom: 0; color: var(--faint); }

#modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: 80;
  display: grid;
  justify-items: center;
  align-content: start;
  padding-top: 12vh;
}

#picker {
  width: min(720px, 92vw);
  border: 1px solid var(--fg);
  background: var(--panel);
  display: grid;
}

#query {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: none;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  outline: none;
}

#results {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 52vh;
  overflow: auto;
}

#results li {
  padding: 7px 10px;
  display: flex;
  gap: 10px;
  align-items: center;
  cursor: pointer;
  border-bottom: 1px solid #141414;
}

#results li[data-active="1"] { background: var(--fg); color: var(--bg); }
#results li[data-active="1"] .sub { color: var(--bg); }
#results li[data-active="1"] .st { color: var(--bg); }
#results li .sub { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#results li .main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#results li .flags { margin-left: auto; flex: none; display: inline-flex; align-items: center; gap: 8px; }
#results li .lead { flex: none; }
#results li[data-used="1"] { opacity: 0.35; }

#menu {
  position: fixed;
  z-index: 90;
  background: var(--panel);
  border: 1px solid var(--fg);
  padding: 4px;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  max-height: 60vh;
  overflow: auto;
}

#menu .row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border: none;
  text-align: left;
  width: 100%;
}

#menu .row:hover { background: #161616; }
#menu .row[data-on="1"]::after { content: "✓"; margin-left: auto; }
#menu .row.add { justify-content: center; color: var(--dim); }
#menu .row .name:empty::before { content: "·"; color: var(--faint); }

#menu .strip {
  display: flex;
  gap: 10px;
  padding: 6px;
}

#menu .strip .dot { cursor: pointer; width: 13px; height: 13px; }

#toast {
  position: fixed;
  bottom: 12px;
  left: 12px;
  z-index: 95;
  border: 1px solid var(--fg);
  background: var(--panel);
  padding: 6px 10px;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#stage[data-wiring="1"] .card { cursor: crosshair; }
#stage[data-busy="1"] #brand { opacity: 0.4; }
