body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #e9e9e9;
  color: #111;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

.page {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.editor-panel {
  background: #f8f8f8;
  border-right: 2px solid #ccc;
  padding: 20px;
}

.editor-panel h1 {
  margin-top: 0;
  font-size: 24px;
}

.editor-panel label {
  display: block;
  margin-top: 15px;
  margin-bottom: 6px;
  font-weight: bold;
}

.editor-panel input,
.editor-panel select,
.editor-panel button {
  width: 100%;
  padding: 10px;
  margin-bottom: 10px;
  font-size: 14px;
}

.button-group {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.legend-block {
  margin: 14px 0 18px 0;
  padding-top: 8px;
}

.legend-title {
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin-bottom: 6px;
}

.legend-swatch {
  width: 18px;
  height: 10px;
  display: inline-block;
  border: 2px solid #000;
  flex-shrink: 0;
}

.rel-child {
  background: #000000;
}

.rel-married {
  background: #c14dff;
}

.rel-friend {
  background: #2a8cff;
}

.rel-reference {
  background: #ff8c2a;
}

.tree-area {
  overflow: hidden;
  padding: 20px;
}

.tree-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: #e9e9e9;
  padding-bottom: 10px;
}

.tree-toolbar button {
  width: auto;
  min-width: 44px;
  margin-bottom: 0;
  cursor: pointer;
}

#zoomLabel {
  min-width: 60px;
  text-align: center;
  font-weight: bold;
}

.zoom-hint {
  margin-left: 10px;
  font-size: 13px;
  color: #555;
  font-style: italic;
  user-select: none;
}

.connect-mode-btn.active {
  background: #2d74ff;
  color: #fff;
  border-color: #1f56c5;
}

.tree-viewport {
  width: 100%;
  height: calc(100vh - 90px);
  overflow: auto;
  border: 1px solid #cfcfcf;
  background: #ececec;
  padding: 30px;
  position: relative;
}

.tree-viewport.drag-root-target {
  background: #e3e3e3;
}

.tree-viewport.connect-mode {
  background: #e9f1ff;
}

.tree-wrapper {
  position: relative;
  display: inline-block;
  min-width: max-content;
  transform-origin: top left;
}

.tree-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  overflow: visible;
  z-index: 0;
}

.edge-label-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.tree {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  min-width: max-content;
  pointer-events: none;
}

.tree ul {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 88px;
  margin: 0;
  padding: 52px 0 0 0;
}

.tree li {
  list-style: none;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
  padding: 0;
}

.node-card {
  width: 170px;
  border: 4px solid #000;
  background: #fff;
  overflow: hidden;
  margin: 0 auto;
  cursor: grab;
  position: relative;
  z-index: 2;
  user-select: none;
  pointer-events: auto;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease, outline-color 0.12s ease;
}

.tree-viewport.connect-mode .node-card {
  cursor: pointer;
}

.node-card:active {
  cursor: grabbing;
}

.node-card:hover {
  filter: brightness(0.98);
}

.node-card.selected {
  outline: 5px solid #4d8dff;
  outline-offset: 0;
}

.node-card.dragging {
  opacity: 0.65;
  transform: scale(0.97);
}

.node-card.drop-target {
  outline: 5px dashed #28a745;
  outline-offset: 2px;
}

.node-card.invalid-drop {
  outline: 5px dashed #dc3545;
  outline-offset: 2px;
}

.node-card.connect-start {
  outline: 5px solid #c14dff;
  outline-offset: 2px;
}

.node-image {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 4px solid #000;
  background: #f0f0f0;
}

.node-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.node-image.placeholder {
  font-size: 22px;
  font-weight: bold;
}

.node-name {
  padding: 8px;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
}

.edge-label {
  position: absolute;
  transform: translate(-50%, -50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 3px 7px;
  background: #fff;
  border: 3px solid #000;
  font-size: 11px;
  font-weight: bold;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  max-width: 180px;
  pointer-events: auto;
  cursor: pointer;
}

.edge-label.editing {
  min-width: 120px;
  max-width: 220px;
}

.edge-label input {
  width: 100%;
  min-width: 50px;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  text-align: center;
  padding: 0;
  margin: 0;
}

.edge-hitbox {
  cursor: pointer;
}

.overlay-edge {
  opacity: 0.72;
}

.edge-action-menu {
  position: absolute;
  transform: translate(-50%, -50%);
  background: #fff;
  border: 3px solid #000;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 30;
  pointer-events: auto;
  min-width: 150px;
}

.edge-action-menu button,
.edge-action-menu select {
  width: 100%;
  margin: 0;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  border: 2px solid #000;
  background: #f8f8f8;
}

.edge-action-menu button:hover,
.edge-action-menu select:hover {
  background: #ececec;
}

.relationship-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 200;
  min-width: 240px;
  background: #ffffff;
  border: 3px solid #000;
  padding: 12px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  display: none;
  transform: translate(-50%, -50%);
}

.relationship-popup.visible {
  display: block;
}

.relationship-popup-title {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 10px;
}

.relationship-popup-grid {
  display: grid;
  gap: 8px;
}

.relationship-popup-grid button {
  width: 100%;
  padding: 8px 10px;
  border: 2px solid #000;
  background: #f6f6f6;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
}

.relationship-popup-grid button:hover {
  background: #ececec;
}

.relationship-popup-cancel {
  margin-top: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 2px solid #000;
  background: #fff5f5;
  cursor: pointer;
}

.relationship-popup-cancel:hover {
  background: #ffeaea;
}
.secondary-parent-edge {
  opacity: 0.9;
}

.shared-child-drop-glow {
  opacity: 1;
}