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

body {
  font-family: Arial, sans-serif;
  background: #1c1b2b;
  color: #fff1f6;
  overflow: hidden;
}

.page {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  gap: 0;
}

/* EDITOR PANEL */
.editor-panel {
  background: rgba(24, 20, 40, 0.95);
  border-right: 2px solid #fdc0cb;
  padding: 20px;
  overflow-y: auto;
  box-shadow: 4px 0 12px rgba(253, 192, 203, 0.15);
}

.editor-panel h1 {
  font-size: 24px;
  color: #fdc0cb;
  margin-bottom: 20px;
  text-shadow: 0 0 8px rgba(253, 192, 203, 0.4);
}

.editor-panel label {
  display: block;
  margin-top: 16px;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: bold;
  color: #fdc0cb;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

.editor-panel input,
.editor-panel select {
  width: 100%;
  padding: 10px;
  background: rgba(255, 241, 246, 0.9);
  border: 2px solid #fdc0cb;
  border-radius: 6px;
  font-size: 14px;
  color: black;
  transition: 0.2s ease;
}

.editor-panel input:focus,
.editor-panel select:focus {
  outline: none;
  background: rgba(255, 241, 246, 1);
  box-shadow: 0 0 8px rgba(253, 192, 203, 0.4);
}

.button-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.editor-panel button {
  padding: 12px;
  background: rgba(253, 192, 203, 0.2);
  border: 2px solid #fdc0cb;
  border-radius: 6px;
  color: #fdc0cb;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.2s ease;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

.editor-panel button:hover {
  background: rgba(253, 192, 203, 0.35);
  box-shadow: 0 0 10px rgba(253, 192, 203, 0.3);
  transform: translateY(-1px);
}

.editor-panel button:active {
  transform: translateY(0);
}

.editor-panel hr {
  margin: 20px 0;
  border: none;
  border-top: 2px solid #fdc0cb;
  opacity: 0.3;
}

/* LEGEND */
.legend-block {
  margin-top: 12px;
}

.legend-title {
  font-size: 16px;
  font-weight: bold;
  color: #fdc0cb;
  margin-bottom: 10px;
  text-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
  color: #fff1f6;
}

.legend-swatch {
  width: 32px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

.rel-child {
  background: #fdc0cb;
}

.rel-romantic {
  background: #c14dff;
}

.rel-friend {
  background: #2a8cff;
}

.rel-coworker {
  background: #4dffb8;
}

.rel-reference {
  background: #ff8c2a;
}

.hint-text {
  margin-top: 16px;
  padding: 12px;
  background: rgba(253, 192, 203, 0.1);
  border: 1px solid rgba(253, 192, 203, 0.3);
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.6;
  color: #fff1f6;
}

/* TREE AREA */
.tree-area {
  display: flex;
  flex-direction: column;
  background: #1c1b2b;
  overflow: hidden;
}

.tree-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(24, 20, 40, 0.95);
  border-bottom: 2px solid #fdc0cb;
  box-shadow: 0 2px 8px rgba(253, 192, 203, 0.12);
}

.tree-toolbar button {
  padding: 8px 16px;
  background: rgba(253, 192, 203, 0.15);
  border: 2px solid #fdc0cb;
  border-radius: 6px;
  color: #fdc0cb;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.2s ease;
}

.tree-toolbar button:hover {
  background: rgba(253, 192, 203, 0.25);
  box-shadow: 0 0 8px rgba(253, 192, 203, 0.25);
}

#zoomLabel {
  min-width: 50px;
  text-align: center;
  font-weight: bold;
  color: #fdc0cb;
}

.connect-mode-btn.active {
  background: rgba(193, 77, 255, 0.3);
  border-color: #c14dff;
  color: #c14dff;
  box-shadow: 0 0 12px rgba(193, 77, 255, 0.4);
}

.zoom-hint {
  margin-left: auto;
  font-size: 13px;
  color: rgba(253, 192, 203, 0.6);
  font-style: italic;
}

/* VIEWPORT */
.tree-viewport {
  flex: 1;
  overflow: auto;
  position: relative;
  background: radial-gradient(circle at 50% 50%, rgba(253, 192, 203, 0.03) 0%, transparent 50%);
}

.tree-wrapper {
  position: relative;
  transform-origin: top left;
  transition: transform 0.15s ease-out;
  min-width: 100%;
  min-height: 100%;
  padding: 40px;
}

.tree-lines {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}

.tree-lines .edge-hitbox {
  pointer-events: stroke;
  cursor: pointer;
}

.edge-label-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

.edge-label-layer > * {
  pointer-events: auto;
}

/* TREE STRUCTURE */
.tree {
  display: inline-block;
  position: relative;
  z-index: 1;
}

.tree ul {
  list-style: none;
  display: flex;
  gap: 40px;
  padding: 0;
  margin: 0;
  padding-top: 60px;
  position: relative;
}

.tree > ul {
  padding-top: 0;
}

.tree li {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

/* NODE CARDS */
.node-card {
  width: 180px;
  background: rgba(24, 20, 40, 0.9);
  border: 3px solid #fdc0cb;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 0 12px rgba(253, 192, 203, 0.2);
  overflow: hidden;
}

.node-card:hover {
  border-color: #c14dff;
  box-shadow: 0 0 18px rgba(193, 77, 255, 0.4);
  transform: translateY(-2px);
}

.node-card.selected {
  border-color: #c14dff;
  background: rgba(40, 30, 60, 0.95);
  box-shadow: 0 0 20px rgba(193, 77, 255, 0.5);
}

.node-card.dragging {
  opacity: 0.5;
}

.node-card.drop-target {
  border-color: #4dffb8;
  box-shadow: 0 0 20px rgba(77, 255, 184, 0.5);
}

.node-card.invalid-drop {
  border-color: #ff4d4d;
  box-shadow: 0 0 20px rgba(255, 77, 77, 0.5);
}

.node-card.connect-start {
  border-color: #2a8cff;
  box-shadow: 0 0 20px rgba(42, 140, 255, 0.6);
}

.node-image {
  width: 100%;
  height: 140px;
  background: rgba(253, 192, 203, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 2px solid #fdc0cb;
  overflow: hidden;
}

.node-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.node-image.placeholder {
  font-size: 16px;
  color: rgba(253, 192, 203, 0.4);
  font-weight: bold;
}

.node-name {
  padding: 12px;
  text-align: center;
  font-size: 15px;
  font-weight: bold;
  color: #fdc0cb;
  background: rgba(253, 192, 203, 0.05);
  word-wrap: break-word;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.4);
}

.node-name.editing {
  padding: 8px;
}

.node-name input {
  width: 100%;
  padding: 4px;
  background: rgba(255, 241, 246, 0.95);
  border: 2px solid #c14dff;
  border-radius: 4px;
  font-size: 15px;
  font-weight: bold;
  color: black;
  text-align: center;
}

/* EDGE LABELS */
.edge-label {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(24, 20, 40, 0.95);
  border: 2px solid #fdc0cb;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: bold;
  color: #fdc0cb;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 0 10px rgba(253, 192, 203, 0.3);
  transition: 0.2s ease;
  z-index: 10;
}

.edge-label:hover {
  background: rgba(40, 30, 60, 0.98);
  box-shadow: 0 0 14px rgba(253, 192, 203, 0.5);
  transform: translate(-50%, -50%) scale(1.05);
}

.edge-label.editing {
  padding: 4px;
}

.edge-label input {
  width: 120px;
  padding: 4px 8px;
  background: rgba(255, 241, 246, 0.95);
  border: 2px solid #c14dff;
  border-radius: 4px;
  font-size: 13px;
  color: black;
}

/* EDGE ACTION MENU */
.edge-action-menu {
  position: absolute;
  transform: translate(-50%, -50%);
  background: rgba(24, 20, 40, 0.98);
  border: 2px solid #fdc0cb;
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 0 20px rgba(253, 192, 203, 0.4);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}

.edge-action-menu select,
.edge-action-menu button {
  padding: 8px;
  background: rgba(253, 192, 203, 0.15);
  border: 2px solid #fdc0cb;
  border-radius: 6px;
  color: #fdc0cb;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.2s ease;
}

.edge-action-menu select:hover,
.edge-action-menu button:hover {
  background: rgba(253, 192, 203, 0.25);
}

.edge-action-menu button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* RELATIONSHIP POPUP */
.relationship-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(24, 20, 40, 0.98);
  border: 3px solid #fdc0cb;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 0 40px rgba(253, 192, 203, 0.6);
  z-index: 1000;
  display: none;
}

.relationship-popup.visible {
  display: block;
}

.relationship-popup-title {
  font-size: 20px;
  font-weight: bold;
  color: #fdc0cb;
  margin-bottom: 16px;
  text-align: center;
  text-shadow: 0 0 8px rgba(253, 192, 203, 0.4);
}

.relationship-popup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.relationship-popup-grid button {
  padding: 14px;
  background: rgba(253, 192, 203, 0.15);
  border: 2px solid #fdc0cb;
  border-radius: 8px;
  color: #fdc0cb;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.2s ease;
}

.relationship-popup-grid button:hover {
  background: rgba(253, 192, 203, 0.3);
  box-shadow: 0 0 12px rgba(253, 192, 203, 0.4);
  transform: translateY(-2px);
}

.relationship-popup-cancel {
  width: 100%;
  padding: 12px;
  background: rgba(255, 77, 77, 0.2);
  border: 2px solid #ff4d4d;
  border-radius: 8px;
  color: #ff4d4d;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.2s ease;
}

.relationship-popup-cancel:hover {
  background: rgba(255, 77, 77, 0.3);
  box-shadow: 0 0 12px rgba(255, 77, 77, 0.4);
}

/* CONTEXT MENU */
.context-menu {
  position: fixed;
  background: rgba(24, 20, 40, 0.98);
  border: 2px solid #fdc0cb;
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 0 20px rgba(253, 192, 203, 0.4);
  z-index: 1000;
  display: none;
}

.context-menu.visible {
  display: block;
}

.context-menu button {
  width: 100%;
  padding: 10px 16px;
  background: rgba(255, 77, 77, 0.15);
  border: 2px solid #ff4d4d;
  border-radius: 6px;
  color: #ff4d4d;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: 0.2s ease;
  text-align: left;
}

.context-menu button:hover {
  background: rgba(255, 77, 77, 0.3);
  box-shadow: 0 0 10px rgba(255, 77, 77, 0.3);
}

/* CONNECT MODE */
.tree-viewport.connect-mode {
  cursor: crosshair;
}

.tree-viewport.connect-mode .node-card {
  cursor: crosshair;
}

/* SCROLLBAR STYLING */
.editor-panel::-webkit-scrollbar,
.tree-viewport::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.editor-panel::-webkit-scrollbar-track,
.tree-viewport::-webkit-scrollbar-track {
  background: rgba(24, 20, 40, 0.5);
}

.editor-panel::-webkit-scrollbar-thumb,
.tree-viewport::-webkit-scrollbar-thumb {
  background: rgba(253, 192, 203, 0.3);
  border-radius: 6px;
  border: 2px solid rgba(24, 20, 40, 0.5);
}

.editor-panel::-webkit-scrollbar-thumb:hover,
.tree-viewport::-webkit-scrollbar-thumb:hover {
  background: rgba(253, 192, 203, 0.5);
}
