@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./fonts/jetbrains-mono-latin-700-normal.woff2") format("woff2");
}

:root {
  --bg: #ffffff;
  --ink: #111111;
  --ink-soft: #2b2b2b;
  --grid: #e7e7e7;
  --ghost: rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(var(--grid) 0.8px, transparent 0.8px);
  background-size: 22px 22px;
  overflow: hidden;
  user-select: none;
}

#ui {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 7;
  padding: 8px;
  border: 2px solid var(--ink);
  background: var(--bg);
  box-shadow: 6px 6px 0 var(--ghost);
  display: flex;
  gap: 10px;
  align-items: center;
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.app-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  height: 32px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.app-mark {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #8a6a3a;
  background: #f0d7a6;
  border-radius: 12px;
}

.app-mark svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: 2px solid var(--ink);
  background: var(--bg);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

#selection-menu {
  position: fixed;
  top: 80px;
  left: 16px;
  z-index: 6;
  min-width: 220px;
  padding: 12px 14px;
  border: 2px solid var(--ink);
  background: var(--bg);
  box-shadow: 6px 6px 0 var(--ghost);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: none;
}

#selection-menu.visible {
  display: block;
}

.menu-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.menu-title {
  font-size: 12px;
  font-weight: 700;
}

.menu-title-input {
  flex: 1;
  min-width: 120px;
  padding: 2px 6px;
  border: 2px solid var(--ink);
  background: var(--bg);
  font-family: inherit;
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0.02em;
  display: none;
}

.menu-title-input::placeholder {
  color: var(--ink-soft);
  opacity: 0.6;
}

.menu-title-input:focus {
  outline: none;
}

.menu-select {
  flex: 1;
  min-width: 140px;
  padding: 4px 6px;
  border: 2px solid var(--ink);
  background: var(--bg);
  font-family: inherit;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0.02em;
  height: 32px;
}

.menu-select:focus {
  outline: none;
}

.menu-input {
  padding: 4px 6px;
  border: 2px solid var(--ink);
  background: var(--bg);
  font-family: inherit;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0.02em;
}

.menu-input:focus {
  outline: none;
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
}

.menu-row.actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.menu-label {
  font-size: 10px;
  color: var(--ink-soft);
}

.swatches {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--bg);
  cursor: pointer;
  padding: 0;
}

.swatch.active {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink);
}

.swatch[data-color="#111111"] { background: #111111; }
.swatch[data-color="#3a3a40"] { background: #3a3a40; }
.swatch[data-color="#c46a6a"] { background: #c46a6a; }
.swatch[data-color="#c2a46b"] { background: #c2a46b; }
.swatch[data-color="#6fa38b"] { background: #6fa38b; }
.swatch[data-color="#6d86b8"] { background: #6d86b8; }

.menu-btn {
  flex: 1;
  padding: 6px 8px;
  border: 2px solid var(--ink);
  background: var(--bg);
  font-family: inherit;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.menu-btn.compact {
  flex: 0 0 auto;
  padding: 4px 8px;
  font-size: 10px;
  height: 32px;
}

.menu-btn.full {
  width: 100%;
  justify-content: center;
}

dialog {
  border: 2px solid var(--ink);
  background: var(--bg);
  color: var(--ink);
  padding: 14px;
  box-shadow: 8px 8px 0 var(--ghost);
  min-width: 280px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.dialog-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dialog-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 12px;
  line-height: 1.4;
}

.dialog-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dialog-row + .dialog-actions {
  margin-top: 6px;
}

.dialog-row .menu-select,
.dialog-row .menu-input {
  flex: 1;
}

.dialog-row .icon-btn {
  flex: 0 0 auto;
}

.dialog-label {
  font-size: 10px;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}


.help-body p {
  margin: 0;
}

.menu-btn.danger {
  background: var(--ink);
  color: var(--bg);
}

.menu-btn .icon {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.menu-btn .icon svg {
  width: 14px;
  height: 14px;
  display: block;
}

.menu-btn .lock-open {
  display: none;
}

.menu-btn.unlocked .lock-open {
  display: inline-flex;
}

.menu-btn.unlocked .lock-closed {
  display: none;
}

.menu-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.title {
  font-size: 14px;
  font-weight: 700;
}

.hint {
  margin-top: 6px;
  font-size: 10px;
  color: var(--ink-soft);
}

#canvas {
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

#editor {
  position: fixed;
  z-index: 20;
  display: none;
  padding: 6px 10px;
  border: 2px solid var(--ink);
  background: var(--bg);
  color: var(--ink);
  font-family: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 14px;
  text-align: center;
  letter-spacing: 0.01em;
  box-shadow: 6px 6px 0 var(--ghost);
  transform: translate(-50%, -50%);
  outline: none;
}

#canvas.linking,
#canvas.linking * {
  cursor: crosshair;
}

.link-path {
  stroke: var(--ink);
  stroke-width: 2.6px;
  stroke-linecap: butt;
  stroke-linejoin: miter;
  fill: none;
  pointer-events: stroke;
  cursor: pointer;
}

.link-path.hovered {
  stroke-width: 3.8px;
}

.link-path.selected {
  stroke-width: 5px;
}

.link-label {
  font-size: 10px;
  fill: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  pointer-events: none;
}

.link-label-bg {
  fill: var(--bg);
}

.link-label-group {
  pointer-events: none;
}

.link-path.preview {
  stroke-width: 2.5px;
  opacity: 0.6;
  pointer-events: none;
}

.node {
  cursor: grab;
}

.node.editing {
  opacity: 0;
  pointer-events: none;
}

.node-lock {
  display: none;
  pointer-events: none;
  opacity: 0.45;
}

.node.locked .node-lock {
  display: block;
}

.node-lock-shackle {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.node-lock-body {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.node.edge-hover {
  cursor: crosshair;
}

.node:active {
  cursor: grabbing;
}

.node.edge-hover:active {
  cursor: crosshair;
}

.node .node-shape {
  fill: var(--bg);
  stroke: var(--ink);
  stroke-width: 2px;
  stroke-linejoin: round;
  transition: stroke-width 80ms ease;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.12));
}

.node.edge-hover > .node-shape {
  stroke-width: 3.5px;
}

.node.selected > .node-shape {
  stroke-width: 4px;
}

.node text {
  font-size: 14px;
  fill: var(--ink);
  dominant-baseline: middle;
  text-anchor: middle;
  pointer-events: none;
}

@media (max-width: 600px) {
  #ui {
    top: 10px;
    left: 10px;
    padding: 6px;
    gap: 6px;
  }

  .app-label {
    font-size: 9px;
    letter-spacing: 0.06em;
  }

  .title {
    font-size: 12px;
  }

  .hint {
    font-size: 9px;
  }

  .node text {
    font-size: 12px;
  }
}
