:root {
  --bg: #0f111e;
  --panel: #262c3b;
  --panel2: #2f3648;
  --line: #3b4357;
  --text: #e7eaf2;
  --muted: #98a1b8;
  --accent: #8557b5;
  --err: #ff5a5a;
  --warn: #ffb020;
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}
button,
select {
  font: inherit;
}

/* top bar */
#topbar {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}
#topbar h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.2px;
}
#topbar h1 span {
  color: var(--accent);
}
.tools {
  display: flex;
  gap: 6px;
  align-items: center;
}
.tools button,
.tools select,
.codehead button {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
.tools button:hover,
.tools select:hover,
.codehead button:hover:not(:disabled) {
  border-color: var(--accent);
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}

/* layout */
main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 290px 1fr 380px;
}
@media (max-width: 1150px) {
  main {
    grid-template-columns: 250px 1fr 300px;
  }
}

/* palette */
#sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
#rail {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}
.rail-btn {
  --c: #888;
  border: 0;
  border-radius: 999px;
  padding: 2px 9px 2px 7px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: var(--c);
  cursor: pointer;
  opacity: 0.9;
}
.rail-btn:hover {
  opacity: 1;
  filter: brightness(1.1);
}
#palette {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 80px;
  user-select: none;
  -webkit-user-select: none;
}
.pal-head {
  --c: #888;
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0;
  padding: 6px 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #fff;
  background: var(--c);
}
.pal-item {
  margin: 7px 10px;
  cursor: grab;
  display: block;
  width: fit-content;
  max-width: 100%;
}
.pal-item .block {
  pointer-events: none;
}
.pal-item .block * {
  pointer-events: none !important;
}
.pal-var {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pal-var .del {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}
.pal-var .del:hover {
  color: var(--err);
}
.make-var {
  margin: 8px 10px 0;
  background: var(--panel2);
  color: var(--text);
  border: 1px dashed var(--muted);
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
}
.make-var:hover {
  border-color: var(--accent);
}

/* workspace */
#scroller {
  position: relative;
  overflow: auto;
  background-color: #20242f;
  background-image: radial-gradient(#323a4d 1px, transparent 1px);
  background-size: 22px 22px;
}
#canvas {
  position: relative;
  min-width: 3200px;
  min-height: 2200px;
}
.stack {
  position: absolute;
}

/* blocks */
.block {
  --c: #888;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.block.statement,
.block.hat {
  background: var(--c);
  border-radius: 6px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.3);
  cursor: grab;
  min-width: 70px;
}
.block.hat {
  border-radius: 18px 18px 6px 6px;
  padding-top: 8px;
}
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  min-height: 32px;
}
.slot {
  margin-left: 16px;
  margin-right: 16px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 6px 6px 6px 6px;
}
.slot > .blocklist {
  padding: 4px 4px 4px 6px;
  min-height: 30px;
}
.foot {
  height: 10px;
}
.blocklist {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-height: 14px;
}
.blocklist > .block + .block {
  margin-top: 1px;
}
.block.value {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  min-height: 26px;
  background: var(--c);
  border-radius: 14px;
  cursor: grab;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.block.value.shape-bool {
  border-radius: 4px;
  padding: 3px 14px;
  clip-path: polygon(
    9px 0,
    calc(100% - 9px) 0,
    100% 50%,
    calc(100% - 9px) 100%,
    9px 100%,
    0 50%
  );
  box-shadow: none;
}
.lbl {
  white-space: nowrap;
}

.socket {
  display: inline-flex;
  align-items: center;
  min-width: 28px;
  min-height: 22px;
  background: #fff;
  border-radius: 12px;
  padding: 0 3px;
}
.socket.empty {
  background: rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.45);
}
.socket.filled {
  background: none;
  padding: 0;
  min-height: 0;
}
.socket.drop-hover {
  outline: 3px solid #fff;
  background: rgba(255, 255, 255, 0.4);
}
input.inline,
input.field {
  border: 0;
  outline: 0;
  background: transparent;
  color: #1c2030;
  font: 600 13px system-ui, sans-serif;
  text-align: center;
  min-width: 2ch;
  padding: 2px 4px;
}
input.field {
  background: #fff;
  border-radius: 10px;
  margin: 0 1px;
}
select.field {
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 2px 4px;
  font: 600 12px system-ui, sans-serif;
  cursor: pointer;
  max-width: 150px;
}
select.field option {
  color: #111;
  background: #fff;
}
.group {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}
.mini {
  background: rgba(0, 0, 0, 0.28);
  color: #fff;
  border: 0;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  line-height: 18px;
  padding: 0;
  cursor: pointer;
  font-weight: 700;
}
.mini:hover {
  background: rgba(0, 0, 0, 0.5);
}

.block.has-error {
  outline: 2px solid var(--err);
  outline-offset: 1px;
}
.block.has-warning {
  outline: 2px dashed var(--warn);
  outline-offset: 1px;
}
.block.value.has-error,
.block.value.has-warning {
  clip-path: none;
}
.block.flash {
  animation: flash 0.9s ease 2;
}
@keyframes flash {
  50% {
    filter: brightness(1.7);
  }
}

/* dragging */
.ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  opacity: 0.93;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.45));
}
.ghost * {
  pointer-events: none !important;
}
.indicator {
  position: fixed;
  z-index: 999;
  height: 5px;
  border-radius: 3px;
  background: #fff;
  box-shadow: 0 0 0 2px var(--accent);
  pointer-events: none;
}
body.dragging {
  cursor: grabbing;
}
body.dragging * {
  cursor: grabbing !important;
}
body.dragging #sidebar.trash {
  outline: 3px dashed var(--err);
  outline-offset: -3px;
}

.ctx {
  position: fixed;
  z-index: 1100;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  padding: 4px;
  min-width: 150px;
}
.ctx button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  color: var(--text);
  padding: 6px 10px;
  border-radius: 5px;
  cursor: pointer;
}
.ctx button:hover {
  background: var(--accent);
  color: #fff;
}

/* code pane */
#codepane {
  background: #151922;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.codehead {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.codehead h2 {
  margin: 0 auto 0 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}
#status {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
}
#status.ok {
  color: #6adf8a;
}
#status.bad {
  color: var(--err);
}
#status.idle {
  color: var(--muted);
}
#code {
  flex: 1;
  min-height: 80px;
  margin: 0;
  padding: 6px 0;
  overflow: auto;
  font: 13px/1.55 ui-monospace, "Cascadia Code", Consolas, Menlo, monospace;
}
.cl {
  display: flex;
  white-space: pre;
  padding-right: 12px;
}
.cl .no {
  flex: none;
  width: 3em;
  text-align: right;
  padding-right: 12px;
  color: #566079;
  user-select: none;
}
.cl .s {
  color: #ce9178;
}
.cl .c {
  color: #6a9955;
}
.cl .k {
  color: #c586c0;
}
.cl .o {
  color: #4ec9b0;
}
.cl .n {
  color: #b5cea8;
}
#diags {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 34%;
  overflow-y: auto;
  border-top: 1px solid var(--line);
}
#diags li {
  padding: 6px 12px 6px 28px;
  position: relative;
  font-size: 12.5px;
  border-bottom: 1px solid #202637;
}
#diags li.clickable {
  cursor: pointer;
}
#diags li.clickable:hover {
  background: #1d2333;
}
#diags li::before {
  position: absolute;
  left: 10px;
  top: 6px;
  font-weight: 700;
}
#diags li.error::before {
  content: "\2715";
  color: var(--err);
}
#diags li.warning::before {
  content: "!";
  color: var(--warn);
  left: 12px;
}
#diags li.info::before {
  content: "i";
  color: var(--accent);
  left: 12px;
}
