:root {
  --bg: #000;
  --grid: #1a1814;
  --surface: #000;
  --surface2: #000;
  --line: #2c2822;
  --line2: #3a342b;
  --ink: #ece6da;
  --muted: #8c8576;
  --faint: #5f594d;
  --amber: #f2a93b;
  --amber-d: #412402;
  --cyan: #5ec8c8;
  --green: #9cc46a;
  --red: #e2705a;
  --mono:
    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --r: 0px;
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
  display: grid;
  grid-template-columns: 212px 1fr 380px;
  grid-template-rows: 46px 1fr;
  grid-template-areas: "top top top" "palette canvas out";
}
/* ---- top bar ---- */
.top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand {
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink);
}
.brand b {
  color: var(--amber);
}
.top .hint {
  color: var(--muted);
  font-size: 11.5px;
}
.top .spacer {
  flex: 1;
}
.tbtn {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  cursor: pointer;
  background: var(--surface2);
  border: 1px solid var(--line2);
  border-radius: var(--r);
  padding: 6px 11px;
}
.tbtn:hover {
  border-color: var(--amber);
  color: var(--amber);
}
.tbtn.danger:hover {
  border-color: var(--red);
  color: var(--red);
}
/* ---- palette ---- */
.palette {
  grid-area: palette;
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
  padding: 10px 10px 40px;
}
.pgroup {
  margin: 4px 0 14px;
}
.ptitle {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 4px 7px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.ptitle::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.pitem {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  margin: 4px 0;
  background: var(--surface2);
  border: 1px solid var(--line);
  border-left: 2px solid var(--dot, var(--line2));
  border-radius: var(--r);
  cursor: grab;
  user-select: none;
  font-size: 12px;
  color: var(--ink);
}
.pitem:hover {
  border-color: var(--line2);
  border-left-color: var(--dot, var(--amber));
  transform: translateX(1px);
}
.pitem:active {
  cursor: grabbing;
}
.pitem .pk {
  margin-left: auto;
  color: var(--faint);
  font-size: 10px;
}
/* ---- canvas ---- */
.canvaswrap {
  grid-area: canvas;
  position: relative;
  overflow: auto;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0/26px 26px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0/26px 26px,
    var(--bg);
}
.canvas {
  position: relative;
  width: 2600px;
  height: 1800px;
}
.empty {
  position: absolute;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  color: var(--faint);
  pointer-events: none;
  max-width: 420px;
}
.empty b {
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}
.node {
  position: absolute;
  width: 262px;
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--r);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.node.dragging {
  outline: 1px solid var(--amber);
  z-index: 50;
}
.nhead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  cursor: grab;
  background: var(--surface2);
  border-bottom: 1px solid #917142;
  border-top: 2px solid var(--dot, var(--amber));
}
.nhead:active {
  cursor: grabbing;
}
.nhead .nt {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}
.nhead .nf {
  font-size: 9.5px;
  letter-spacing: 0.08em;
  color: var(--faint);
  text-transform: uppercase;
}
.nhead .x {
  margin-left: auto;
  color: var(--faint);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
}
.nhead .x:hover {
  color: var(--red);
}
.nbody {
  padding: 9px 10px 11px;
}
.f {
  margin: 0 0 8px;
}
.f:last-child {
  margin-bottom: 0;
}
.f > label {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
  margin: 0 0 3px;
  letter-spacing: 0.02em;
}
.f input[type="text"],
.f input[type="number"],
.f select,
.f textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line2);
  border-radius: var(--r);
  padding: 5px 7px;
}
.f textarea {
  resize: vertical;
  min-height: 48px;
  line-height: 1.4;
}
.f input:focus,
.f select:focus,
.f textarea:focus {
  outline: none;
  border-color: var(--amber);
}
.row {
  display: flex;
  gap: 6px;
}
.row > * {
  flex: 1;
}
.togg {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 3px 0;
}
.togg input {
  accent-color: var(--amber);
  width: 14px;
  height: 14px;
}
.togg span {
  font-size: 12px;
  color: var(--ink);
}
.dynrow {
  display: flex;
  gap: 5px;
  align-items: center;
  margin-bottom: 5px;
}
.dynrow input {
  flex: 1;
}
.dynrow .del {
  color: var(--faint);
  cursor: pointer;
  padding: 2px 5px;
  border: 1px solid var(--line2);
  border-radius: var(--r);
  font-size: 11px;
}
.dynrow .del:hover {
  color: var(--red);
  border-color: var(--red);
}
.addbtn {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--cyan);
  cursor: pointer;
  background: transparent;
  border: 1px dashed var(--line2);
  border-radius: var(--r);
  padding: 5px 8px;
  width: 100%;
  margin-top: 2px;
}
.addbtn:hover {
  border-color: var(--cyan);
}
/* ---- output ---- */
.out {
  grid-area: out;
  border-left: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
}
.otabs {
  display: flex;
  border-bottom: 1px solid var(--line);
}
.otab {
  flex: 1;
  text-align: center;
  padding: 10px 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.otab.active {
  color: var(--amber);
  border-bottom-color: var(--amber);
  background: var(--surface2);
}
.otab .cnt {
  color: var(--faint);
  font-size: 10px;
}
.obar {
  display: flex;
  gap: 7px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
}
.obar .path {
  flex: 1;
  align-self: center;
  color: var(--faint);
  font-size: 10.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
pre.code {
  margin: 0;
  flex: 1;
  overflow: auto;
  padding: 13px 14px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink);
  white-space: pre;
  tab-size: 2;
}
.code .k {
  color: var(--amber);
}
.code .s {
  color: var(--green);
}
.code .n {
  color: var(--cyan);
}
.code .b {
  color: #c89bf0;
}
.code .p {
  color: var(--muted);
}
::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}
::-webkit-scrollbar-thumb {
  background: var(--line2);
  border-radius: var(--r);
  border: 3px solid var(--surface);
}
.canvaswrap::-webkit-scrollbar-thumb {
  border-color: var(--bg);
}
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--amber);
  color: var(--amber-d);
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--r);
  opacity: 0;
  transition: 0.2s;
  font-size: 12px;
  pointer-events: none;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* minimize button (sits in header next to ✕) */
.nhead .m {
  margin-left: auto;
  color: var(--faint);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
}
.nhead .m:hover {
  color: var(--amber);
}
.nhead .m ~ .x {
  margin-left: 0; /* keep ✕ snug against – */
}

/* collapsed brick */
.ini {
  display: none;
}
.node.min {
  width: 60px;
  min-width: 60px;
  height: 60px;
  min-height: 60px;
  justify-content: center;
  display: flex;
}
.node.min .nbody {
  display: none;
}
.node.min .nhead {
  padding: 0;
  gap: 0;
}
.node.min .nt,
.node.min .nf,
.node.min .m,
.node.min .x {
  display: none;
}
.node.min .ini {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 16px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

/* help button (sits between – and the label cluster) */
.nhead .q {
  margin-left: auto;
  color: var(--faint);
  cursor: help;
  font-size: 12px;
  line-height: 1;
  padding: 2px 4px;
}
.nhead .q:hover {
  color: var(--cyan);
}
.nhead .q ~ .m {
  margin-left: 0; /* q now owns the auto-margin that pushes the cluster right */
}
.node.min .q {
  display: none;
}

/* help tooltip */
#tip {
  position: fixed;
  z-index: 200;
  max-width: 240px;
  background: var(--bg);
  border: 1px solid var(--cyan);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  padding: 8px 10px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
}
#tip b {
  display: block;
  color: var(--cyan);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}
