/* The canvas of Fernwire, a made-up workflow builder: two nodes and the cable between them. script.js places the
   nodes (x, y on .node) and draws the cable, the plugs and the ports in the SVG above them; the CSS owns the card
   inside each node (lift on hover, press). One element for GSAP, its child for the CSS. */
:root {
  --canvas: #f3f2ef;        /* the canvas, a soft warm grey */
  --canvas-deep: #e9e7e2;   /* the canvas at the edges */
  --dot: rgba(28, 27, 34, 0.10); /* the dots of the grid */
  --card: #ffffff;          /* the nodes */
  --ink: #1c1b22;           /* the words and the bare cable */
  --muted: #8d8a93;         /* the small words */
  --line: rgba(28, 27, 34, 0.08); /* hairlines */
  --accent: #5146e5;        /* the one colour: an indigo for the live cable */
  --accent-2: #8f86ff;      /* the same indigo, lighter, at the far end of the cable */
  --accent-soft: rgba(81, 70, 229, 0.10); /* the indigo as a tint */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Geist Variable', system-ui, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

.stage {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background:
    radial-gradient(circle at 50% 46%, transparent 40%, var(--canvas-deep) 120%),
    radial-gradient(var(--dot) 1px, transparent 1.2px) 0 0 / 22px 22px,
    var(--canvas);
}

/* the top bar */
.bar {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: clamp(12px, 2.4vh, 20px) clamp(14px, 3vw, 28px);
  font-size: 13px;
  z-index: 3;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.brand__mark {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
}

.crumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-left: 14px;
  border-left: 1px solid var(--line);
  font-weight: 500;
  white-space: nowrap;
}

.crumb__muted { color: var(--muted); }

.crumb svg {
  width: 6px;
  height: 9px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.saved {
  margin-left: auto;
  display: inline-block;
  overflow: hidden;
  height: 26px;
  padding: 0 11px;
  line-height: 26px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 520;
}

.saved__in { display: inline-block; }

/* the nodes */
.node {
  position: absolute;
  left: 0;
  top: 0;
  width: clamp(168px, 19vw, 240px);
  z-index: 1;
  cursor: grab;
}

.node.is-held { cursor: grabbing; z-index: 2; }

.node__card {
  position: relative;
  padding: 12px 13px 11px;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #fcfcfd 100%);
  box-shadow:
    0 0 0 1px rgba(28, 27, 34, 0.07),
    0 1px 1px rgba(28, 27, 34, 0.04),
    0 4px 10px -2px rgba(28, 27, 34, 0.06),
    0 16px 32px -14px rgba(28, 27, 34, 0.18);
  transition: transform 0.45s cubic-bezier(0.22, 1.2, 0.36, 1), box-shadow 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

/* a hairline of light along the top edge */
.node__card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 1), rgba(255, 255, 255, 0) 40%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.node.is-lift .node__card,
.node.is-held .node__card {
  transform: translateY(-2px);
  box-shadow:
    0 0 0 1px rgba(28, 27, 34, 0.08),
    0 2px 2px rgba(28, 27, 34, 0.04),
    0 10px 18px -4px rgba(28, 27, 34, 0.08),
    0 28px 44px -18px rgba(28, 27, 34, 0.26);
}

.node.is-held .node__card { transform: translateY(-3px) scale(1.012); }

@media (hover: hover) {
  .node:hover .node__card {
    transform: translateY(-2px);
    box-shadow:
      0 0 0 1px rgba(28, 27, 34, 0.08),
      0 2px 2px rgba(28, 27, 34, 0.04),
      0 10px 18px -4px rgba(28, 27, 34, 0.08),
      0 28px 44px -18px rgba(28, 27, 34, 0.26);
  }
}

.node__head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.node__icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(180deg, #f7f6f4, #eceae6);
  box-shadow: inset 0 0 0 1px rgba(28, 27, 34, 0.06), inset 0 1px 0 #fff;
}

.node__icon svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.node__icon--ai {
  background: linear-gradient(160deg, #6a60f0, var(--accent) 60%, #3f35c9);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 4px 10px -4px rgba(81, 70, 229, 0.6);
}

.node__icon--ai svg { fill: #fff; stroke: none; }

.node__words { display: grid; gap: 1px; min-width: 0; }

.node__kind {
  font-size: 11px;
  font-weight: 520;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.node__title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.012em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node__meta {
  margin: 10px 0 0;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  font-family: 'Geist Mono Variable', ui-monospace, monospace;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.node__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
}

.state {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px 0 7px;
  border-radius: 999px;
  background: rgba(28, 27, 34, 0.045);
  color: var(--muted);
  font-weight: 540;
  white-space: nowrap;
  overflow: hidden;
  transition: background-color 0.4s ease, color 0.4s ease;
}

.state.is-live { background: var(--accent-soft); color: var(--accent); }

.state__tick {
  width: 0;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.state.is-done .state__tick { width: 12px; }

.state__in { display: inline-block; }

.runs {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  color: var(--muted);
}

.runs__num {
  position: relative;
  display: inline-block;
  overflow: hidden;
  height: 15px;
  line-height: 15px;
  font-family: 'Geist Mono Variable', ui-monospace, monospace;
  font-size: 11.5px;
  font-weight: 560;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.runs__in { display: block; }

/* the cable, the plugs and the ports */
.wires {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 2;
}

.wires path { fill: none; stroke-linecap: round; stroke-linejoin: round; }

.wire__shadow { stroke: rgba(28, 27, 34, 0.16); stroke-width: 4.5; }
.wire__ink { stroke: var(--ink); stroke-width: 3; }
.wire__live { stroke-width: 3; opacity: 0; }
.wire__shine { stroke: rgba(255, 255, 255, 0.55); stroke-width: 0.8; }
.wire__pulse { stroke: #ffffff; stroke-width: 1.6; stroke-dasharray: 0 1000; opacity: 0; }
.wire__pulse-glow { stroke: var(--accent-2); stroke-width: 7; stroke-dasharray: 0 1000; opacity: 0; }

.plug rect { fill: var(--ink); }
.plug path { stroke: rgba(255, 255, 255, 0.4); stroke-width: 1; stroke-linecap: round; }
.plug .plug__band { stroke: rgba(255, 255, 255, 0.14); stroke-width: 1.4; }

.port__ring {
  fill: #fff;
  stroke: rgba(28, 27, 34, 0.28);
  stroke-width: 1.3;
  transition: stroke 0.3s ease;
}

.port.is-near .port__ring { stroke: var(--accent); }
.port__core { fill: var(--accent); }

/* the hint at the bottom */
.hint {
  position: absolute;
  left: 50%;
  bottom: clamp(14px, 4vh, 30px);
  margin: 0;
  transform: translateX(-50%);
  overflow: hidden;
  height: 18px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  z-index: 3;
}

.hint__in { display: block; line-height: 18px; }

/* the drawn cursor of the autopilot */
.ghost {
  position: absolute;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  margin: -3px 0 0 -5px;
  fill: var(--ink);
  stroke: #fff;
  stroke-width: 1.4;
  stroke-linejoin: round;
  filter: drop-shadow(0 3px 5px rgba(28, 27, 34, 0.25));
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

@media (max-width: 560px) {
  .crumb { display: none; }
  .node { width: min(176px, 50vw); }
  .node__card { padding: 10px 11px 9px; }
  .node__title { font-size: 13px; }
  .node__icon { width: 27px; height: 27px; }
  .runs__label { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .node__card, .state, .state__tick, .port__ring { transition: opacity 0.3s ease; }
}
