/* =====================================================================
   AGENT DESIGN CANVAS — Celestial Light-Weave
   ===================================================================== */

:root {
  --void-1: #0F0524;
  --void-2: #1A103C;
  --void-3: #060116;
  --weave-1: #8F00FF;
  --weave-2: #B026FF;
  --weave-3: #5A0099;
  --energy-1: #00F0FF;
  --energy-2: #FFFFFF;
  --coral-1: #FF4040;
  --coral-2: #FF6B35;
  --pulse-1: #00FF9F;
  --pulse-2: #00FFCC;
  --frost: #E0E6FF;

  --font-display: 'Michroma', 'Arial Black', sans-serif;
  --font-ui: 'Chakra Petch', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --bar-w: 78px;
  --top-h: 64px;
  --hud-h: 44px;
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--void-3);
  color: var(--frost);
  font-family: var(--font-ui);
  font-weight: 400;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
}

body {
  position: relative;
  display: grid;
  grid-template-columns: var(--bar-w) 1fr;
  grid-template-rows: var(--top-h) 1fr var(--hud-h);
  grid-template-areas:
    "top top"
    "bar stage"
    "hud hud";
}

button { font: inherit; color: inherit; }

button:focus-visible,
.canvas-title:focus-visible {
  outline: 2px solid var(--energy-1);
  outline-offset: 3px;
}

/* ---------- Small-screen notice ---------- */
.mobile-gate {
  display: none;
}

/* ---------- Background atmosphere ---------- */
.void-backdrop {
  position: fixed; inset: 0; z-index: -3;
  background:
    radial-gradient(ellipse 80% 60% at 75% 15%, rgba(176,38,255,0.20), transparent 60%),
    radial-gradient(ellipse 60% 80% at 18% 92%, rgba(0,240,255,0.13), transparent 60%),
    radial-gradient(ellipse 100% 100% at 50% 50%, var(--void-2) 0%, var(--void-1) 50%, var(--void-3) 100%);
}
.weave-mesh {
  position: fixed; inset: 0; z-index: -2;
  width: 100%; height: 100%;
  pointer-events: none;
  opacity: 0.6;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 90%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 90%);
}
.drift-particles { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.drift-particles span {
  position: absolute;
  width: 2px; height: 2px;
  background: var(--energy-1);
  box-shadow: 0 0 8px var(--energy-1), 0 0 16px rgba(0,240,255,0.4);
  border-radius: 50%;
  opacity: 0;
  animation: drift linear infinite;
}
.drift-particles span:nth-child(1)  { left:  4%; top: 18%; animation-duration: 22s; animation-delay:  -1s; }
.drift-particles span:nth-child(2)  { left: 13%; top: 72%; animation-duration: 30s; animation-delay:  -5s; }
.drift-particles span:nth-child(3)  { left: 22%; top: 38%; animation-duration: 26s; animation-delay:  -9s; background: var(--weave-2); box-shadow: 0 0 10px var(--weave-2); }
.drift-particles span:nth-child(4)  { left: 31%; top: 88%; animation-duration: 34s; animation-delay: -12s; }
.drift-particles span:nth-child(5)  { left: 39%; top: 24%; animation-duration: 28s; animation-delay:  -3s; background: var(--pulse-1); box-shadow: 0 0 8px var(--pulse-1); }
.drift-particles span:nth-child(6)  { left: 47%; top: 56%; animation-duration: 24s; animation-delay: -15s; }
.drift-particles span:nth-child(7)  { left: 55%; top: 12%; animation-duration: 32s; animation-delay:  -7s; background: var(--weave-2); box-shadow: 0 0 10px var(--weave-2); }
.drift-particles span:nth-child(8)  { left: 61%; top: 64%; animation-duration: 26s; animation-delay: -11s; }
.drift-particles span:nth-child(9)  { left: 68%; top: 30%; animation-duration: 36s; animation-delay:  -2s; }
.drift-particles span:nth-child(10) { left: 74%; top: 80%; animation-duration: 28s; animation-delay: -18s; background: var(--pulse-2); box-shadow: 0 0 8px var(--pulse-2); }
.drift-particles span:nth-child(11) { left: 80%; top: 22%; animation-duration: 30s; animation-delay:  -6s; }
.drift-particles span:nth-child(12) { left: 86%; top: 54%; animation-duration: 34s; animation-delay: -13s; background: var(--weave-2); box-shadow: 0 0 10px var(--weave-2); }
.drift-particles span:nth-child(13) { left: 91%; top: 70%; animation-duration: 22s; animation-delay:  -8s; }
.drift-particles span:nth-child(14) { left: 96%; top: 36%; animation-duration: 38s; animation-delay:  -4s; }
.drift-particles span:nth-child(15) { left: 50%; top: 92%; animation-duration: 26s; animation-delay: -16s; }
.drift-particles span:nth-child(16) { left:  9%; top: 50%; animation-duration: 33s; animation-delay: -20s; background: var(--weave-2); box-shadow: 0 0 10px var(--weave-2); }
.drift-particles span:nth-child(17) { left: 65%; top: 86%; animation-duration: 29s; animation-delay: -10s; }
.drift-particles span:nth-child(18) { left: 35%; top:  4%; animation-duration: 31s; animation-delay: -14s; }

@keyframes drift {
  0%   { transform: translate(0,0); opacity: 0; }
  10%  { opacity: 0.85; }
  90%  { opacity: 0.6; }
  100% { transform: translate(40px, -140px); opacity: 0; }
}

/* ---------- Topbar ---------- */
.topbar {
  grid-area: top;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px;
  background: linear-gradient(180deg, rgba(15,5,36,0.88), rgba(15,5,36,0.55));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(143,0,255,0.25);
  position: relative; z-index: 5;
}
.topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--energy-1) 20%, var(--weave-2) 50%, var(--energy-1) 80%, transparent);
  opacity: 0.55;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-size: 30px; line-height: 1;
  color: var(--energy-1);
  text-shadow: 0 0 14px var(--energy-1), 0 0 28px rgba(0,240,255,0.5);
  animation: rotateGlyph 12s linear infinite;
}
@keyframes rotateGlyph { to { transform: rotate(360deg); } }
.brand-title {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.24em;
  color: var(--frost);
  text-shadow: 0 0 14px rgba(0,240,255,0.4);
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: rgba(224,230,255,0.5);
  letter-spacing: 0.14em;
  margin-top: 4px;
}

.topbar-meta { display: flex; align-items: center; gap: 12px; }
.meta-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.18em;
  color: var(--frost);
  background: rgba(143,0,255,0.10);
  border: 1px solid rgba(143,0,255,0.35);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
.meta-pill.mono { color: var(--energy-1); border-color: rgba(0,240,255,0.3); min-width: 90px; justify-content: center; }
.meta-pill .pulse {
  width: 8px; height: 8px;
  background: var(--pulse-1);
  box-shadow: 0 0 10px var(--pulse-1);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  animation: heartbeat 1.6s ease-in-out infinite;
}
@keyframes heartbeat { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.4; transform: scale(0.6); } }

.btn {
  font-family: var(--font-ui);
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--frost);
  background: linear-gradient(135deg, rgba(176,38,255,0.20), rgba(0,240,255,0.10));
  border: 1px solid rgba(0,240,255,0.4);
  padding: 9px 18px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 10px;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  transition: all .25s ease;
  position: relative;
}
.btn:hover {
  background: linear-gradient(135deg, rgba(176,38,255,0.38), rgba(0,240,255,0.28));
  color: var(--energy-2);
  box-shadow: 0 0 18px rgba(0,240,255,0.45), inset 0 0 12px rgba(0,240,255,0.15);
}
.btn:active { transform: translateY(1px); }
.btn-icon {
  font-size: 14px;
  color: var(--energy-1);
  text-shadow: 0 0 8px var(--energy-1);
}
.btn-clear:hover .btn-icon { animation: rotateGlyph 1.6s linear infinite; }
.btn-compact {
  padding: 8px 12px;
  font-size: 10px;
}
.file-import {
  display: none;
}

/* ---------- Widget bar ---------- */
.widget-bar {
  grid-area: bar;
  background: linear-gradient(180deg, rgba(15,5,36,0.92), rgba(6,1,22,0.96));
  border-right: 1px solid rgba(143,0,255,0.25);
  padding: 14px 0;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,240,255,0.12) rgba(15,5,36,0.06);
  position: relative; z-index: 4;
  box-shadow: inset -10px 0 22px rgba(0,240,255,0.035);
}
.widget-bar:hover,
.widget-bar:focus-within {
  scrollbar-color: rgba(0,240,255,0.34) rgba(15,5,36,0.14);
}
.widget-bar::after {
  content: ''; position: absolute; right: -1px; top: 0; bottom: 0; width: 1px;
  background: linear-gradient(180deg, transparent, var(--weave-2) 30%, var(--energy-1) 60%, transparent);
  opacity: 0.45;
}
.widget-bar::-webkit-scrollbar {
  width: 8px;
}
.widget-bar::-webkit-scrollbar-track {
  background:
    linear-gradient(180deg, rgba(15,5,36,0.02), rgba(26,16,60,0.08)),
    linear-gradient(90deg, transparent 0 3px, rgba(0,240,255,0.025) 3px 4px, transparent 4px);
  border-left: 1px solid rgba(143,0,255,0.03);
}
.widget-bar::-webkit-scrollbar-thumb {
  min-height: 36px;
  background:
    linear-gradient(180deg, rgba(0,240,255,0.11), rgba(176,38,255,0.09)),
    linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
  border: 2px solid rgba(15,5,36,0.88);
  border-radius: 2px;
  box-shadow:
    0 0 5px rgba(0,240,255,0.06),
    inset 0 0 4px rgba(255,255,255,0.04);
}
.widget-bar:hover::-webkit-scrollbar-track,
.widget-bar:focus-within::-webkit-scrollbar-track {
  background:
    linear-gradient(180deg, rgba(15,5,36,0.08), rgba(26,16,60,0.22)),
    linear-gradient(90deg, transparent 0 3px, rgba(0,240,255,0.07) 3px 4px, transparent 4px);
  border-left-color: rgba(143,0,255,0.08);
}
.widget-bar:hover::-webkit-scrollbar-thumb,
.widget-bar:focus-within::-webkit-scrollbar-thumb {
  background:
    linear-gradient(180deg, rgba(0,240,255,0.28), rgba(176,38,255,0.22) 70%, rgba(0,255,204,0.20)),
    linear-gradient(90deg, transparent, rgba(255,255,255,0.18), transparent);
  box-shadow:
    0 0 8px rgba(0,240,255,0.18),
    0 0 12px rgba(176,38,255,0.08),
    inset 0 0 5px rgba(255,255,255,0.12);
}
.widget-bar::-webkit-scrollbar-thumb:hover,
.widget-bar::-webkit-scrollbar-thumb:active {
  background:
    linear-gradient(180deg, rgba(201,248,255,0.42), rgba(0,240,255,0.36) 35%, rgba(176,38,255,0.28) 70%, rgba(0,255,204,0.30)),
    linear-gradient(90deg, transparent, rgba(255,255,255,0.24), transparent);
  box-shadow:
    0 0 10px rgba(0,240,255,0.24),
    0 0 14px rgba(176,38,255,0.12),
    inset 0 0 5px rgba(255,255,255,0.16);
}

.tool-divider {
  width: 30px; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(143,0,255,0.55), transparent);
  margin: 4px 0;
  flex: 0 0 auto;
}

.tool {
  width: 54px; height: 60px;
  position: relative;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: 0;
  padding: 0;
  flex: 0 0 auto;
}
.tool-shape {
  position: absolute; inset: 4px;
  background: linear-gradient(135deg, var(--weave-3), var(--weave-1));
  clip-path: polygon(50% 2%, 100% 27%, 100% 73%, 50% 98%, 0 73%, 0 27%);
  transition: all .25s ease;
}
.tool-shape::before {
  content: ''; position: absolute; inset: 1.5px;
  background: linear-gradient(180deg, rgba(15,5,36,0.96), rgba(26,16,60,0.96));
  clip-path: polygon(50% 2%, 100% 27%, 100% 73%, 50% 98%, 0 73%, 0 27%);
}
.tool-glyph {
  position: relative; z-index: 1;
  font-size: 18px;
  color: var(--frost);
  text-shadow: 0 0 8px rgba(0,240,255,0.5);
  transition: all .25s ease;
  font-family: var(--font-mono);
  line-height: 1;
}
.glyph-svg {
  display: block;
  width: 1em;
  height: 1em;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: square;
  stroke-linejoin: bevel;
  filter: drop-shadow(0 0 6px currentColor);
}
.tool-glyph .glyph-svg {
  width: 24px;
  height: 24px;
}
.tool:hover .tool-shape {
  background: linear-gradient(135deg, var(--weave-2), var(--energy-1));
  filter: drop-shadow(0 0 8px rgba(0,240,255,0.55));
}
.tool:hover .tool-glyph { color: var(--energy-2); text-shadow: 0 0 12px var(--energy-1); }
.tool.active .tool-shape {
  background: linear-gradient(135deg, var(--energy-1), var(--energy-2));
  filter: drop-shadow(0 0 14px var(--energy-1)) drop-shadow(0 0 24px rgba(0,240,255,0.5));
}
.tool.active .tool-shape::before { background: linear-gradient(135deg, rgba(0,90,140,0.85), rgba(15,5,36,0.95)); }
.tool.active .tool-glyph { color: var(--energy-2); text-shadow: 0 0 14px var(--energy-1); }

.tool-label {
  position: fixed;
  left: calc(var(--bar-w) - 6px); top: 50%;
  transform: translate(-6px, -50%);
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.18em;
  background: rgba(15,5,36,0.96);
  border: 1px solid rgba(0,240,255,0.4);
  padding: 6px 12px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: all .2s ease;
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
  z-index: 50;
  color: var(--energy-2);
  box-shadow: 0 0 14px rgba(0,240,255,0.25);
}
.tool:hover .tool-label,
.tool:focus-visible .tool-label { opacity: 1; transform: translate(8px, -50%); }
.tool-group.open > .tool .tool-label { opacity: 0; }

/* group flyout */
.tool-group { position: relative; }
.tool-flyout {
  position: fixed;
  left: calc(var(--bar-w) + 12px); top: 0;
  display: none; flex-direction: column;
  padding: 12px 10px 10px;
  background: linear-gradient(180deg, rgba(15,5,36,0.97), rgba(26,16,60,0.97));
  border: 1px solid rgba(143,0,255,0.5);
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  z-index: 60;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), 0 0 28px rgba(143,0,255,0.30);
  animation: flyoutIn .18s ease;
}
@keyframes flyoutIn {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}
.tool-group.open .tool-flyout { display: flex; }
.tool-flyout-title {
  font-family: var(--font-display); font-size: 9px;
  letter-spacing: 0.28em;
  color: var(--energy-1);
  padding: 0 4px 8px;
  border-bottom: 1px solid rgba(143,0,255,0.3);
  margin-bottom: 6px;
  text-shadow: 0 0 10px rgba(0,240,255,0.4);
}
.subtool {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px;
  cursor: pointer;
  background: transparent;
  border: 0;
  border-left: 2px solid transparent;
  color: var(--frost);
  font-family: var(--font-ui); font-size: 12px;
  letter-spacing: 0.12em;
  transition: all .2s ease;
  min-width: 220px;
  text-align: left;
}
.subtool:hover {
  background: rgba(0,240,255,0.08);
  border-left-color: var(--energy-1);
  color: var(--energy-2);
}
.subtool.active {
  background: rgba(0,240,255,0.14);
  border-left-color: var(--energy-1);
  color: var(--energy-2);
  box-shadow: inset 0 0 16px rgba(0,240,255,0.10);
}
.subtool-glyph {
  font-family: var(--font-mono); font-size: 14px;
  color: var(--energy-1);
  text-shadow: 0 0 8px var(--energy-1);
  width: 22px; text-align: center; flex: 0 0 22px;
}
.subtool-glyph .glyph-svg {
  width: 22px;
  height: 22px;
}
.subtool-label { flex: 1; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; font-size: 11px; }
.subtool-desc {
  font-family: var(--font-mono); font-size: 9.5px;
  color: rgba(224,230,255,0.45);
  letter-spacing: 0.06em;
}

/* ---------- Canvas stage ---------- */
.canvas-stage {
  grid-area: stage;
  position: relative;
  overflow: hidden;
}
.canvas-stage[data-placing="1"] { cursor: crosshair; }
.canvas-stage.panning { cursor: grabbing; }

.viewport {
  position: absolute; inset: 0;
  transform-origin: 0 0;
  will-change: transform;
  overflow: visible;
}

.canvas-title-wrap {
  position: absolute;
  left: 50%; top: 18px;
  transform: translateX(-50%);
  z-index: 4;
  text-align: center;
  pointer-events: none;
  user-select: none;
}
.canvas-title-eyebrow {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.5em;
  color: rgba(0,240,255,0.55);
  margin-bottom: 6px;
  text-shadow: 0 0 10px rgba(0,240,255,0.3);
}
.canvas-title {
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.32em;
  color: var(--frost);
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(0,240,255,0.45), 0 0 36px rgba(176,38,255,0.3);
  padding: 4px 14px;
  outline: none;
  border: 1px solid transparent;
  pointer-events: auto;
  cursor: text;
  min-width: 200px;
  display: inline-block;
  white-space: nowrap;
  transition: all .25s ease;
  caret-color: var(--energy-1);
}
.canvas-title:empty::before {
  content: attr(data-placeholder);
  color: rgba(224,230,255,0.35);
}
.canvas-title:hover {
  border-color: rgba(0,240,255,0.25);
  background: rgba(0,240,255,0.04);
}
.canvas-title:focus {
  border-color: rgba(0,240,255,0.55);
  background: rgba(0,240,255,0.08);
  box-shadow: 0 0 22px rgba(0,240,255,0.25), inset 0 0 14px rgba(0,240,255,0.10);
  color: var(--energy-2);
}
.canvas-title-rule {
  width: 180px; height: 1px;
  margin: 8px auto 0;
  background: linear-gradient(90deg, transparent, var(--energy-1) 30%, var(--weave-2) 70%, transparent);
  opacity: 0.55;
}

.wires {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 1;
}
.wire-group { pointer-events: auto; }
.wire-path {
  fill: none;
  stroke: url(#thread-grad);
  stroke-width: 2;
  stroke-linecap: round;
  filter: url(#glow);
  stroke-dasharray: 6 8;
  animation: weaveDrift 3s linear infinite;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}
.wire-group:hover .wire-path { stroke-width: 3; }
@keyframes weaveDrift { to { stroke-dashoffset: -28; } }
.wire-temp {
  fill: none;
  stroke: rgba(0,240,255,0.8);
  stroke-width: 2;
  stroke-dasharray: 4 5;
  pointer-events: none;
  filter: url(#glow);
  vector-effect: non-scaling-stroke;
}
.wire-hit {
  fill: none; stroke: transparent; stroke-width: 14;
  pointer-events: stroke;
  cursor: pointer;
}
.wire-cap {
  fill: var(--energy-1);
  filter: url(#glow);
  pointer-events: none;
}

.nodes { position: absolute; inset: 0; z-index: 2; pointer-events: none; }

/* ---------- Empty hint ---------- */
.empty-hint {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%,-50%);
  text-align: center;
  pointer-events: none;
  z-index: 0;
  opacity: 0.7;
  transition: opacity .3s ease;
}
body.has-nodes .empty-hint { opacity: 0; }
.empty-glyph {
  font-size: 64px;
  color: var(--weave-2);
  text-shadow: 0 0 24px rgba(176,38,255,0.6), 0 0 48px rgba(0,240,255,0.25);
  margin-bottom: 18px;
  animation: floatGlyph 6s ease-in-out infinite;
  display: inline-block;
}
@keyframes floatGlyph {
  0%,100% { transform: translateY(0) rotate(0); }
  50%     { transform: translateY(-10px) rotate(180deg); }
}
.empty-title {
  font-family: var(--font-display); font-size: 12px;
  letter-spacing: 0.42em;
  color: var(--frost);
  margin-bottom: 12px;
  text-shadow: 0 0 14px rgba(0,240,255,0.35);
}
.empty-text {
  font-family: var(--font-ui); font-size: 13px;
  color: rgba(224,230,255,0.55);
  max-width: 460px;
  letter-spacing: 0.05em;
  line-height: 1.7;
  margin: 0 auto;
}

/* ---------- Node ---------- */
.node {
  position: absolute;
  width: max-content;
  min-width: 200px;
  max-width: 460px;
  height: 110px;
  pointer-events: auto;
  user-select: none;
  --tint-1: var(--weave-2);
  --tint-2: var(--weave-1);
  --accent: var(--energy-1);
  animation: nodeIn .35s cubic-bezier(.2,.8,.2,1);
  cursor: move;
}
@keyframes nodeIn {
  from { opacity: 0; transform: scale(0.6); filter: blur(8px); }
  to   { opacity: 1; transform: scale(1);   filter: blur(0); }
}
.node-shell {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--accent), var(--tint-1) 50%, var(--tint-2));
  filter: drop-shadow(0 0 14px color-mix(in srgb, var(--accent) 45%, transparent));
  transition: filter .25s ease;
  clip-path: var(--node-shape);
}
.node-shell::before {
  content: ''; position: absolute; inset: 1.5px;
  background:
    linear-gradient(135deg, rgba(15,5,36,0.94), rgba(26,16,60,0.97) 60%, rgba(15,5,36,0.96));
  clip-path: var(--node-shape);
}
.node-shell::after {
  content: ''; position: absolute; inset: 1.5px;
  background:
    radial-gradient(ellipse at 30% 0%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%),
    radial-gradient(ellipse at 100% 100%, color-mix(in srgb, var(--tint-1) 22%, transparent), transparent 65%);
  clip-path: var(--node-shape);
  opacity: 0.9;
  pointer-events: none;
}
.node:hover .node-shell { filter: drop-shadow(0 0 22px color-mix(in srgb, var(--accent) 75%, transparent)); }
.node.selected .node-shell {
  filter: drop-shadow(0 0 26px var(--accent)) drop-shadow(0 0 48px color-mix(in srgb, var(--accent) 60%, transparent));
}
.node.selected .node-shell::before {
  background: linear-gradient(135deg, rgba(15,5,36,0.96), rgba(26,16,60,0.99) 55%, color-mix(in srgb, var(--accent) 14%, rgba(15,5,36,0.96)));
}

.node-content {
  position: relative; z-index: 2;
  height: 100%;
  display: flex; flex-direction: column;
  padding: 12px 34px;
  pointer-events: none;
}
.node-header {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--font-mono); font-size: 9px;
  letter-spacing: 0.24em;
  color: var(--accent);
  text-shadow: 0 0 6px color-mix(in srgb, var(--accent) 60%, transparent);
}
.node-id { color: rgba(224,230,255,0.45); }

.node-body {
  display: flex; align-items: center; gap: 12px;
  flex: 1;
}
.node-glyph {
  font-family: var(--font-mono);
  font-size: 24px;
  color: var(--accent);
  text-shadow: 0 0 14px var(--accent);
  width: 36px; text-align: center; flex: 0 0 36px;
  line-height: 1;
}
.node-glyph .glyph-svg {
  width: 34px;
  height: 34px;
}
.node-titles { flex: 1; min-width: 0; }
.node-title {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--frost);
  text-shadow: 0 0 10px rgba(0,240,255,0.30);
  white-space: nowrap;
}
.node-title-input {
  width: 100%;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--energy-2);
  background: rgba(0,240,255,0.08);
  border: 1px solid rgba(0,240,255,0.5);
  padding: 2px 6px;
  outline: none;
  text-transform: uppercase;
  box-shadow: 0 0 12px rgba(0,240,255,0.30), inset 0 0 8px rgba(0,240,255,0.10);
  pointer-events: auto;
}
.node-title-input:focus { border-color: var(--energy-1); }
.node-title { pointer-events: auto; }

.node-sub {
  font-family: var(--font-ui); font-size: 9.5px;
  letter-spacing: 0.18em;
  color: rgba(224,230,255,0.55);
  margin-top: 4px;
  text-transform: uppercase;
}

.node-foot {
  display: flex; justify-content: space-between; align-items: center;
  font-family: var(--font-mono); font-size: 8px;
  color: rgba(224,230,255,0.4);
  letter-spacing: 0.16em;
}
/* Diamond shapes: hide the noisy foot bar so it doesn't clip the slants */
.node[data-type="router"] .node-foot,
.node[data-type="aggregator"] .node-foot { display: none; }
.node[data-type="router"] .node-content,
.node[data-type="aggregator"] .node-content { padding: 18px 44px; }
/* Trigger has a left notch at center — push glyph inward */
.node[data-type="trigger"] .node-content { padding-left: 38px; }
/* Output has a left notch at center too */
.node[data-type="output"] .node-content { padding-left: 38px; }
/* Workflow's parallelogram slants in toward the bottom-left/top-right */
.node[data-type="workflow"] .node-content { padding: 12px 40px; }
/* Eval octagon clips top/bottom corners */
.node[data-type="eval"] .node-content { padding: 18px 38px; }
/* Container chamfered rect — give breathing room from the corner ports */
.node[data-type="container"] .node-content { padding: 22px 36px; }
.foot-bar {
  flex: 1; height: 1px; margin: 0 8px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.55;
}

/* ports */
.port {
  position: absolute;
  width: 30px; height: 30px;
  top: 50%; transform: translate(-50%,-50%);
  pointer-events: auto;
  cursor: crosshair;
  z-index: 3;
}
.port::before {
  content: ''; position: absolute; inset: 10px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent), 0 0 18px color-mix(in srgb, var(--accent) 60%, transparent);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  transition: all .2s ease;
}
.port::after {
  content: ''; position: absolute; inset: 0;
  border: 1px solid color-mix(in srgb, var(--accent) 70%, transparent);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  opacity: 0; transition: opacity .2s ease;
}
.port:hover::before { transform: scale(1.4); }
.port:hover::after { opacity: 1; }
.port-in  { left: 0; }
.port-out { left: 100%; }
.port-any { left: 50%; }

/* Container: 8 omnidirectional ports on the chamfered-rect perimeter */
.node[data-type="container"] .port-any { top: auto; left: auto; transform: translate(-50%,-50%); }
.node[data-type="container"] .port-any[data-port-idx="0"] { left: 35%;  top: 0%; }
.node[data-type="container"] .port-any[data-port-idx="1"] { left: 65%;  top: 0%; }
.node[data-type="container"] .port-any[data-port-idx="2"] { left: 100%; top: 35%; }
.node[data-type="container"] .port-any[data-port-idx="3"] { left: 100%; top: 65%; }
.node[data-type="container"] .port-any[data-port-idx="4"] { left: 65%;  top: 100%; }
.node[data-type="container"] .port-any[data-port-idx="5"] { left: 35%;  top: 100%; }
.node[data-type="container"] .port-any[data-port-idx="6"] { left: 0%;   top: 65%; }
.node[data-type="container"] .port-any[data-port-idx="7"] { left: 0%;   top: 35%; }

/* Docking: hide host ports when a harness is docked, plus dock candidate glow */
.node[data-type="host"][data-docked="1"] .port { display: none; }
.node[data-dock-candidate="1"] .node-shell {
  filter: drop-shadow(0 0 28px var(--accent)) drop-shadow(0 0 56px color-mix(in srgb, var(--accent) 70%, transparent)) !important;
}
.node[data-dock-candidate="1"] .node-shell::before {
  background: linear-gradient(135deg, rgba(15,5,36,0.94), rgba(26,16,60,0.99) 55%, color-mix(in srgb, var(--accent) 22%, rgba(15,5,36,0.96)));
}
.node[data-docked="1"][data-type="harness"] .node-shell {
  filter: drop-shadow(0 0 18px color-mix(in srgb, var(--accent) 70%, transparent)) drop-shadow(0 6px 22px rgba(201,184,255,0.55));
}

/* Router fan-out: 6 distinct output ports along the right diamond edges */
.node[data-type="router"] .port-out { top: auto; left: auto; transform: translate(-50%,-50%); }
.node[data-type="router"] .port-out[data-port-idx="0"] { left: 62.5%; top: 12.5%; }
.node[data-type="router"] .port-out[data-port-idx="1"] { left: 80%;   top: 30%;   }
.node[data-type="router"] .port-out[data-port-idx="2"] { left: 95%;   top: 45%;   }
.node[data-type="router"] .port-out[data-port-idx="3"] { left: 95%;   top: 55%;   }
.node[data-type="router"] .port-out[data-port-idx="4"] { left: 80%;   top: 70%;   }
.node[data-type="router"] .port-out[data-port-idx="5"] { left: 62.5%; top: 87.5%; }

/* Aggregator: 6 inputs along the left diamond edges, single output at right tip */
.node[data-type="aggregator"] .port-in { top: auto; left: auto; transform: translate(-50%,-50%); }
.node[data-type="aggregator"] .port-in[data-port-idx="0"] { left: 37.5%; top: 12.5%; }
.node[data-type="aggregator"] .port-in[data-port-idx="1"] { left: 20%;   top: 30%;   }
.node[data-type="aggregator"] .port-in[data-port-idx="2"] { left:  5%;   top: 45%;   }
.node[data-type="aggregator"] .port-in[data-port-idx="3"] { left:  5%;   top: 55%;   }
.node[data-type="aggregator"] .port-in[data-port-idx="4"] { left: 20%;   top: 70%;   }
.node[data-type="aggregator"] .port-in[data-port-idx="5"] { left: 37.5%; top: 87.5%; }

/* Gate has two outputs: success (top), failure (bottom) */
.node[data-type="gate"] .port-out { top: auto; left: auto; transform: translate(-50%,-50%); }
.node[data-type="gate"] .port-out[data-port-idx="0"] { left: 94%; top: 26%; }
.node[data-type="gate"] .port-out[data-port-idx="1"] { left: 94%; top: 74%; }
.node[data-type="gate"] .port-out[data-port-idx="0"]::before {
  background: var(--pulse-1);
  box-shadow: 0 0 10px var(--pulse-1), 0 0 18px rgba(0,255,159,0.55);
}
.node[data-type="gate"] .port-out[data-port-idx="0"]::after {
  border-color: rgba(0,255,159,0.7);
}
.node[data-type="gate"] .port-out[data-port-idx="1"]::before {
  background: var(--coral-2);
  box-shadow: 0 0 10px var(--coral-2), 0 0 18px rgba(255,107,53,0.55);
}
.node[data-type="gate"] .port-out[data-port-idx="1"]::after {
  border-color: rgba(255,107,53,0.7);
}

/* shape + tint per type */
.node[data-type="harness"] {
  --node-shape: polygon(8% 0, 92% 0, 100% 50%, 92% 100%, 8% 100%, 0 50%);
  --tint-1: var(--weave-1); --tint-2: var(--weave-3);
  --accent: var(--weave-2);
}
.node[data-type="trigger"] {
  --node-shape: polygon(0 0, 88% 0, 100% 50%, 88% 100%, 0 100%, 12% 50%);
  --tint-1: #006e8c; --tint-2: #003a4a;
  --accent: var(--energy-1);
}
.node[data-type="host"] {
  --node-shape: polygon(0 0, 100% 0, 100% 78%, 92% 100%, 8% 100%, 0 78%);
  --tint-1: #2a1a5c; --tint-2: #100632;
  --accent: #C9B8FF;
}
.node[data-type="human-person"] {
  --node-shape: polygon(50% 0, 92% 18%, 100% 64%, 72% 100%, 28% 100%, 0 64%, 8% 18%);
  --tint-1: #8a5a18; --tint-2: #3a2208;
  --accent: #FFD27A;
}
.node[data-type="human-group"] {
  --node-shape: polygon(10% 0, 90% 0, 100% 24%, 92% 100%, 8% 100%, 0 24%);
  --tint-1: #8a5a18; --tint-2: #3a2208;
  --accent: #FFD27A;
}
.node[data-type="router"] {
  --node-shape: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  --tint-1: #008f5a; --tint-2: #004a30;
  --accent: var(--pulse-1);
}
.node[data-type="gate"] {
  --node-shape: polygon(0 0, 88% 0, 100% 50%, 88% 100%, 0 100%);
  --tint-1: #8a2a14; --tint-2: #4a1408;
  --accent: var(--coral-2);
}
.node[data-type="connector"] {
  --node-shape: polygon(15% 0, 85% 0, 100% 50%, 85% 100%, 15% 100%, 0 50%);
  --tint-1: #4a4f7a; --tint-2: #1a1e3a;
  --accent: var(--frost);
}
.node[data-type="input"] {
  --node-shape: polygon(0 0, 88% 0, 100% 50%, 88% 100%, 0 100%);
  --tint-1: #008f5a; --tint-2: #004a30;
  --accent: var(--pulse-2);
}
.node[data-type="output"] {
  --node-shape: polygon(12% 0, 100% 0, 100% 100%, 12% 100%, 0 50%);
  --tint-1: #008f5a; --tint-2: #004a30;
  --accent: var(--pulse-2);
}
.node[data-type="aggregator"] {
  --node-shape: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  --tint-1: #1a5a8c; --tint-2: #0a2a4a;
  --accent: #6FE6FF;
}
.node[data-type="container"] {
  --node-shape: polygon(0 8%, 8% 0, 92% 0, 100% 8%, 100% 92%, 92% 100%, 8% 100%, 0 92%);
  --tint-1: #3a4a8a; --tint-2: #14203e;
  --accent: #B8C8FF;
}
.node[data-type="code"] {
  --node-shape: polygon(0 14%, 14% 0, 100% 0, 100% 86%, 86% 100%, 0 100%);
  --tint-1: #0d6e62; --tint-2: #053730;
  --accent: var(--pulse-2);
}
.node[data-type="workflow"] {
  --node-shape: polygon(12% 0, 100% 0, 88% 100%, 0 100%);
  --tint-1: #6e3a9a; --tint-2: #2a1454;
  --accent: #C9A4FF;
}
/* Free-floating text — no shell, no ports, no chrome */
.node[data-type="text"] {
  width: max-content;
  min-width: 0;
  max-width: none;
  height: auto;
}
.node[data-type="text"] .node-shell { display: none; }
.text-node {
  font-family: var(--font-display);
  color: var(--frost);
  letter-spacing: 0.18em;
  white-space: nowrap;
  padding: 6px 10px;
  pointer-events: auto;
  user-select: none;
  outline: none;
  border: 1px solid transparent;
  text-shadow: 0 0 16px rgba(0,240,255,0.45), 0 0 32px rgba(176,38,255,0.30);
  transition: text-shadow .25s ease, border-color .2s ease;
}
.node[data-type="text"][data-subtype="header"] .text-node {
  font-size: 56px;
  letter-spacing: 0.10em;
  font-weight: 700;
  text-transform: uppercase;
  text-shadow: 0 0 22px rgba(0,240,255,0.55), 0 0 48px rgba(176,38,255,0.40), 0 2px 0 rgba(0,0,0,0.2);
}
.node[data-type="text"][data-subtype="label"] .text-node {
  font-size: 16px;
  letter-spacing: 0.18em;
  font-family: var(--font-ui);
  font-weight: 500;
}
.node[data-type="text"]:hover .text-node {
  text-shadow: 0 0 28px var(--energy-1), 0 0 56px rgba(176,38,255,0.5);
}
.node[data-type="text"].selected .text-node {
  border-color: rgba(0,240,255,0.4);
  background: rgba(0,240,255,0.04);
}
.text-node[contenteditable="true"] {
  border-color: rgba(0,240,255,0.6);
  background: rgba(0,240,255,0.06);
  cursor: text;
  caret-color: var(--energy-1);
}

.node[data-type="eval"] {
  --node-shape: polygon(20% 0, 80% 0, 100% 30%, 100% 70%, 80% 100%, 20% 100%, 0 70%, 0 30%);
  --tint-1: #8a2a14; --tint-2: #4a1408;
  --accent: var(--coral-1);
}

/* ---------- HUD ---------- */
.hud {
  grid-area: hud;
  display: flex; align-items: center;
  padding: 0 22px;
  background: linear-gradient(180deg, rgba(15,5,36,0.85), rgba(6,1,22,0.95));
  border-top: 1px solid rgba(143,0,255,0.25);
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.18em;
  color: rgba(224,230,255,0.7);
  position: relative; z-index: 5;
  gap: 22px;
}
.hud::before {
  content: ''; position: absolute; left: 0; right: 0; top: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--energy-1) 30%, var(--weave-2) 70%, transparent);
  opacity: 0.4;
}
.hud-cell { display: flex; align-items: center; gap: 10px; }
.hud-label { color: rgba(0,240,255,0.7); }
.hud-value { color: var(--energy-2); text-shadow: 0 0 6px rgba(0,240,255,0.5); font-weight: 500; min-width: 36px; }
.hud-hint { margin-left: auto; color: rgba(224,230,255,0.5); letter-spacing: 0.10em; font-size: 10px; }
.hud-hint .sep { color: rgba(143,0,255,0.6); margin: 0 4px; }
.kbd {
  display: inline-block;
  padding: 2px 7px;
  border: 1px solid rgba(0,240,255,0.3);
  color: var(--energy-2);
  background: rgba(0,240,255,0.06);
  margin: 0 3px;
  font-size: 9.5px;
  letter-spacing: 0.14em;
}

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: rgba(15,5,36,0.5); }
::-webkit-scrollbar-thumb { background: rgba(143,0,255,0.4); }
::-webkit-scrollbar-thumb:hover { background: rgba(176,38,255,0.7); }

/* ---------- Utility ---------- */
.is-leaving { animation: nodeOut .25s ease forwards !important; }
@keyframes nodeOut {
  to { opacity: 0; transform: scale(0.55); filter: blur(8px); }
}

@media (max-width: 960px) {
  body > header,
  body > aside,
  body > main,
  body > footer {
    display: none !important;
  }
  .mobile-gate {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 28px;
    text-align: center;
    background:
      radial-gradient(ellipse 80% 55% at 50% 24%, rgba(0,240,255,0.16), transparent 64%),
      radial-gradient(ellipse 75% 80% at 50% 92%, rgba(176,38,255,0.24), transparent 68%),
      linear-gradient(180deg, var(--void-1), var(--void-3));
  }
  .mobile-gate::before {
    content: '';
    position: absolute;
    inset: 22px;
    border: 1px solid rgba(0,240,255,0.25);
    clip-path: polygon(18px 0, 100% 0, 100% calc(100% - 18px), calc(100% - 18px) 100%, 0 100%, 0 18px);
    box-shadow: inset 0 0 36px rgba(0,240,255,0.08), 0 0 40px rgba(143,0,255,0.18);
    pointer-events: none;
  }
  .mobile-gate > * {
    max-width: 330px;
  }
  .mobile-gate-mark {
    font-size: 54px;
    color: var(--energy-1);
    text-shadow: 0 0 18px var(--energy-1), 0 0 44px rgba(176,38,255,0.55);
    margin: 0 auto 24px;
  }
  .mobile-gate h1 {
    font-family: var(--font-display);
    font-size: 21px;
    line-height: 1.55;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: var(--energy-2);
    text-shadow: 0 0 18px rgba(0,240,255,0.45);
    margin-bottom: 18px;
  }
  .mobile-gate p {
    font-size: 15px;
    line-height: 1.65;
    color: rgba(224,230,255,0.72);
    letter-spacing: 0.04em;
  }
  .mobile-gate-note {
    margin-top: 16px;
    color: var(--energy-1) !important;
    font-family: var(--font-mono);
    font-size: 12px !important;
    letter-spacing: 0.12em !important;
    text-transform: uppercase;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
