:root {
  --bg: #0a0a18;
  --card-bg: rgba(255, 255, 255, 0.06);
  --card-border: rgba(160, 180, 255, 0.25);
  --card-glow: rgba(120, 150, 255, 0.35);
  --text: #e8eaf6;
  --text-dim: #9aa0c0;
  --accent: #7c9cff;
  --conflict: #ff5a3c;
  --conflict-glow: rgba(255, 90, 60, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(1200px 800px at 20% 10%, #141432 0%, transparent 60%),
    radial-gradient(1000px 700px at 85% 80%, #1a1030 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

#scene {
  position: fixed;
  inset: 0;
  cursor: grab;
}

#scene.panning { cursor: grabbing; }

#world {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

/* ---------- Плашка ---------- */

.node {
  position: absolute;
  top: 0;
  left: 0;
  width: 240px;
  pointer-events: auto;
  cursor: grab;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 14px;
  padding: 14px 16px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45), 0 0 18px var(--card-glow);
  transform-origin: top left;
  animation: node-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  transition: border-color 0.2s, box-shadow 0.2s;
}

@keyframes node-in {
  from { opacity: 0; scale: 0.6; }
  to   { opacity: 1; scale: 1; }
}

.node:hover {
  border-color: rgba(180, 200, 255, 0.55);
}

.node.selected {
  border-color: var(--accent);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45), 0 0 26px rgba(124, 156, 255, 0.55);
}

.node.in-conflict {
  border-color: var(--side-color, #ff5a3c);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45), 0 0 22px var(--side-color, #ff5a3c);
  animation: node-in 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2),
             conflict-pulse 2.2s ease-in-out infinite;
}

@keyframes conflict-pulse {
  0%, 100% { box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45), 0 0 14px var(--side-color, #ff5a3c); }
  50%      { box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45), 0 0 32px var(--side-color, #ff5a3c); }
}

.node.in-conflict.has-details .title::after {
  background: var(--side-color, #ff5a3c);
}

.node .title {
  font-size: 15px;
  line-height: 1.35;
  font-weight: 600;
  outline: none;
  word-break: break-word;
}

.node.has-details .title::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 8px;
  vertical-align: middle;
  opacity: 0.8;
}

.node.in-conflict.has-details .title::after {
  background: var(--conflict);
}

/* ---------- Ручка для связей ---------- */

#edge-handle {
  position: fixed;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 0 12px var(--accent);
  cursor: crosshair;
  z-index: 20;
  pointer-events: auto;
  animation: handle-in 0.15s ease-out;
}

@keyframes handle-in {
  from { scale: 0; }
  to   { scale: 1; }
}

/* ---------- Подсказка ---------- */

#tooltip {
  position: fixed;
  max-width: 280px;
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(16, 16, 34, 0.92);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(8px);
  font-size: 13px;
  line-height: 1.45;
  z-index: 30;
  pointer-events: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

#tooltip .tt-title {
  font-weight: 700;
  margin-bottom: 4px;
}

#tooltip .tt-desc {
  color: var(--text-dim);
}

#tooltip .tt-rel {
  margin-top: 6px;
  font-size: 12px;
}

#tooltip .tt-rel.conflict { color: #ff9a80; }
#tooltip .tt-rel.link { color: #9db4ff; }

/* ---------- Мини-меню связи ---------- */

#edge-menu {
  position: fixed;
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(16, 16, 34, 0.95);
  border: 1px solid var(--card-border);
  backdrop-filter: blur(8px);
  z-index: 40;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}

#edge-menu button {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--card-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

#edge-menu button:hover { background: rgba(255, 255, 255, 0.12); }
#edge-menu button[data-kind="conflict"]:hover {
  border-color: var(--conflict);
  background: rgba(255, 90, 60, 0.15);
}
#edge-menu button[data-kind="link"]:hover {
  border-color: var(--accent);
  background: rgba(124, 156, 255, 0.15);
}

/* ---------- Боковая панель ---------- */

#panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  height: 100%;
  padding: 24px 22px;
  background: rgba(12, 12, 26, 0.92);
  border-left: 1px solid rgba(160, 180, 255, 0.18);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  z-index: 25;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.4);
  animation: panel-in 0.25s ease-out;
  scrollbar-width: thin;
  scrollbar-color: rgba(160, 180, 255, 0.25) transparent;
}

#panel::-webkit-scrollbar { width: 8px; }
#panel::-webkit-scrollbar-thumb {
  background: rgba(160, 180, 255, 0.2);
  border-radius: 4px;
}
#panel::-webkit-scrollbar-track { background: transparent; }

@keyframes panel-in {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

.panel-head {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

#p-title {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(160, 180, 255, 0.2);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

#p-title:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(124, 156, 255, 0.07);
  box-shadow: 0 0 0 3px rgba(124, 156, 255, 0.15);
}

#p-close {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 12px;
  border: 1px solid rgba(160, 180, 255, 0.2);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#p-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.1); }

#panel label,
#panel .list-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(160, 180, 255, 0.1);
}

#panel label > span,
#panel .list-field > span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(154, 160, 192, 0.85);
}

#panel textarea {
  resize: vertical;
  min-height: 64px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(160, 180, 255, 0.16);
  background: rgba(255, 255, 255, 0.04);
  color: #eef0ff;
  font-size: 14px;
  line-height: 1.6;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

#panel textarea::placeholder,
#panel input::placeholder {
  color: rgba(154, 160, 192, 0.45);
}

#panel textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(124, 156, 255, 0.06);
  box-shadow: 0 0 0 3px rgba(124, 156, 255, 0.13);
}

/* Список «как уменьшить влияние» */

.reduce-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reduce-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.reduce-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(160, 180, 255, 0.16);
  background: rgba(255, 255, 255, 0.04);
  color: #eef0ff;
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.reduce-row input:focus {
  outline: none;
  border-color: #2dd4bf;
  background: rgba(45, 212, 191, 0.06);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.12);
}

.row-del {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: rgba(154, 160, 192, 0.6);
  font-size: 16px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.row-del:hover {
  background: rgba(255, 90, 60, 0.15);
  color: #ff9a80;
}

.add-btn {
  align-self: flex-start;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px dashed rgba(45, 212, 191, 0.4);
  background: rgba(45, 212, 191, 0.05);
  color: #6ee7d4;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.add-btn:hover {
  background: rgba(45, 212, 191, 0.12);
  border-color: rgba(45, 212, 191, 0.7);
}

#p-delete {
  margin-top: auto;
  padding: 11px;
  border-radius: 12px;
  border: 1px solid rgba(255, 90, 60, 0.35);
  background: rgba(255, 90, 60, 0.06);
  color: #ff9a80;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

#p-delete:hover { background: rgba(255, 90, 60, 0.16); }

/* ---------- Подсказка снизу ---------- */

#hint {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-dim);
  background: linear-gradient(transparent, rgba(5, 5, 15, 0.8));
  pointer-events: none;
  z-index: 15;
}

#save-status.saving { color: var(--accent); }
#save-status.saved { color: #6fd08c; }

.hidden { display: none !important; }
