*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1c1922;
  --bg-panel: #241f2b;
  --bg-panel-2: #2b2533;
  --bg-node: #322a3d;
  --bg-node-head: #3d3350;
  --line: #423a52;
  --text: #ece7f2;
  --text-dim: #a89fb8;
  --accent: #ff9ac1;
  --accent-2: #ffd59e;
  --good: #6ee7a8;
  --bad: #ff8a8a;
  --wire: #ff9ac1;
  --wire-bad: #ff8a8a;
}

html, body {
  height: 100%;
  width: 100%;
}
body {
  font-family: 'Fredoka', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Top bar ── */
#topbar {
  flex-shrink: 0;
  height: 3.4rem;
  background: linear-gradient(90deg, #2a2333, #241f2b);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.1rem;
  gap: 1rem;
}
#topbar h1 {
  font-size: clamp(1rem, 2.4vw, 1.35rem);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.01em;
  white-space: nowrap;
}
#topbar h1 span {
  font-size: 0.62em;
  font-weight: 400;
  color: var(--text-dim);
  margin-left: 0.4rem;
}
#topbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}
#level-select {
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--bg-node);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  cursor: pointer;
}
#btn-clear {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  background: #4a2b3a;
  color: #ffc9dc;
  border: 1px solid #6a3a4e;
  border-radius: 6px;
  padding: 0.38rem 0.85rem;
  cursor: pointer;
}
#btn-clear:hover { background: #5c3547; }

/* ── Workspace ── */
#workspace {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ── Palette ── */
#palette {
  width: clamp(150px, 15vw, 200px);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  padding: 0.8rem 0.7rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
#palette h2 {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
  margin: 0.5rem 0 0.15rem;
}
.palette-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.pal-btn {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  text-align: left;
  background: var(--bg-node);
  color: var(--text);
  border: 1px solid var(--line);
  border-left: 3px solid var(--pal-c, var(--accent));
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: background 0.12s, transform 0.08s;
}
.pal-btn:hover { background: var(--bg-node-head); transform: translateX(2px); }
.pal-btn .pal-ico { font-size: 1rem; }
.palette-hint {
  font-size: 0.7rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 0.6rem;
  border-top: 1px solid var(--line);
  padding-top: 0.6rem;
}
.palette-hint b { color: var(--accent-2); }

/* ── Canvas ── */
#canvas {
  flex: 1;
  position: relative;
  overflow: auto;
  background:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,0.045) 1px, transparent 0);
  background-size: 22px 22px;
  outline: none;
}
#wire-layer {
  position: absolute;
  top: 0; left: 0;
  width: 2400px;
  height: 1600px;
  pointer-events: none;
  z-index: 1;
}
#nodes-layer {
  position: absolute;
  top: 0; left: 0;
  width: 2400px;
  height: 1600px;
  z-index: 2;
}
#canvas-empty {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-dim);
  font-size: 0.95rem;
  max-width: 22rem;
  text-align: center;
  line-height: 1.6;
  pointer-events: none;
  z-index: 0;
}

/* ── Node ── */
.node {
  position: absolute;
  width: 158px;
  background: var(--bg-node);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  user-select: none;
  transition: box-shadow 0.12s, border-color 0.12s;
}
.node.err { border-color: var(--bad); }
.node.selected { border-color: var(--accent-2); box-shadow: 0 0 0 2px var(--accent-2), 0 6px 18px rgba(0,0,0,0.4); }
.node-head {
  background: var(--bg-node-head);
  border-bottom: 1px solid var(--line);
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  padding: 0.35rem 0.5rem;
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: grab;
  border-left: 3px solid var(--node-c, var(--accent));
}
.node-head .n-ico { font-size: 0.95rem; }
.node-head .n-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-del {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0 0.1rem;
}
.node-del:hover { color: var(--bad); }
.node-body {
  padding: 0.4rem 0.1rem 0.5rem;
  position: relative;
}
.port-row {
  display: flex;
  align-items: center;
  height: 22px;
  font-size: 0.72rem;
  color: var(--text-dim);
  position: relative;
}
.port-row.in { justify-content: flex-start; padding-left: 0.55rem; }
.port-row.out { justify-content: flex-end; padding-right: 0.55rem; }
.port {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 2px solid var(--accent);
  position: absolute;
  cursor: crosshair;
  transition: transform 0.1s, background 0.1s;
}
.port:hover { transform: scale(1.3); background: var(--accent); }
.port.in { left: -7px; }
.port.out { right: -7px; border-color: var(--accent-2); }
.port.out:hover { background: var(--accent-2); }
.port.filled { background: var(--accent); }
.node-param {
  margin: 0.25rem 0.5rem 0.15rem;
}
.node-param select {
  width: 100%;
  font-family: inherit;
  font-size: 0.74rem;
  background: var(--bg-panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.25rem 0.35rem;
  cursor: pointer;
}
.node-status {
  margin: 0.3rem 0.5rem 0;
  font-size: 0.68rem;
  color: var(--text-dim);
  line-height: 1.35;
  border-top: 1px dashed var(--line);
  padding-top: 0.3rem;
  min-height: 1.1em;
}
.node-status.ok { color: var(--good); }
.node-status.bad { color: var(--bad); }
.node-mini { display: flex; justify-content: center; padding: 0.2rem 0 0.1rem; }
.node-mini svg { width: 62px; height: 52px; }

/* ── Goal panel ── */
#goal {
  width: clamp(200px, 21vw, 280px);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-left: 1px solid var(--line);
  padding: 0.9rem 0.9rem 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
#goal h2 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-dim);
}
#goal-card, #result-card {
  background: var(--bg-panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
#goal-cake svg, #result-cake svg { width: 120px; height: 100px; }
#goal-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-2);
  text-align: center;
}
#goal-desc {
  font-size: 0.78rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}
#goal-specs, #result-notes {
  list-style: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
#goal-specs li {
  font-size: 0.76rem;
  color: var(--text);
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
#goal-specs li::before { content: '\25CF'; color: var(--accent); font-size: 0.6em; }
#result-status {
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
}
#result-status.pending { color: var(--text-dim); }
#result-status.win { color: var(--good); }
#result-status.fail { color: var(--bad); }
#result-notes li {
  font-size: 0.74rem;
  line-height: 1.4;
  display: flex;
  gap: 0.35rem;
}
#result-notes li.ok { color: var(--good); }
#result-notes li.bad { color: var(--bad); }
#result-notes li .rn-ico { flex-shrink: 0; }

/* scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #453b57; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #574a6d; }

@media (max-width: 780px) {
  #palette { width: 120px; }
  #goal { width: 160px; }
}
