* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: #0f1115;
  color: #e6e8ee;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: #161922;
  border-bottom: 1px solid #232735;
  z-index: 2;
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  letter-spacing: 1px;
}

.actions {
  display: flex;
  gap: 10px;
}

.btn {
  border: 0;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  transition: transform 0.1s, background 0.2s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: #4f7cff;
  color: white;
}

.btn.primary:hover {
  background: #6b91ff;
}

.btn.ghost {
  background: transparent;
  color: #c2c8d6;
  border: 1px solid #2e3346;
}

.btn.ghost:hover {
  background: #1d2130;
}

.btn.small {
  padding: 4px 10px;
  font-size: 12px;
}

.btn.danger {
  background: #c64040;
  color: white;
}

.stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #0a0c12;
}

#starfield {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  z-index: 0;
}

#graph {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
  cursor: grab;
  touch-action: none;
  z-index: 1;
}

#graph.panning {
  cursor: grabbing;
}

.node-group {
  cursor: pointer;
}

.node-circle {
  fill: #1f2638;
  stroke: #4f7cff;
  stroke-width: 2;
  transition: stroke 0.2s, stroke-width 0.2s;
}

.node-group:hover .node-circle {
  stroke: #ffd166;
  stroke-width: 3;
}

.node-center .node-circle {
  stroke: #ffd166;
  stroke-width: 3;
  fill: #2a2233;
}

.node-label {
  fill: #e6e8ee;
  font-size: 13px;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}

.node-initial {
  fill: #9aa3bd;
  font-size: 22px;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
  font-weight: 600;
}

.edge {
  stroke: #4f7cff;
  stroke-opacity: 0.45;
  stroke-width: 1.5;
  fill: none;
  pointer-events: stroke;
  cursor: pointer;
  transition: stroke-opacity 0.2s, stroke-width 0.2s;
}

.edge:hover {
  stroke-opacity: 1;
  stroke-width: 2.5;
}

.edge.peer-edge {
  stroke: #6cd4a8;
  stroke-opacity: 0.85;
  stroke-width: 1.8;
}

.edge-label-group {
  pointer-events: none;
  user-select: none;
}

.edge-label-bg {
  fill: rgba(15, 17, 21, 0.92);
  stroke: rgba(108, 212, 168, 0.45);
  stroke-width: 1;
  rx: 4;
  ry: 4;
}

.edge-label {
  fill: #d8f3e6;
  font-size: 12px;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  user-select: none;
}

.node-group.selected .node-circle {
  stroke: #ffd166;
  stroke-width: 4;
  filter: drop-shadow(0 0 8px rgba(255, 209, 102, 0.55));
}

.delete-btn {
  fill: #c64040;
  cursor: pointer;
}

.edit-btn {
  fill: #4f7cff;
  cursor: pointer;
}

.action-btn-group {
  opacity: 0;
  transition: opacity 0.2s;
  cursor: pointer;
}

.node-group:hover .action-btn-group {
  opacity: 1;
}

.action-btn-text {
  fill: white;
  font-size: 13px;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  font-weight: bold;
}

.tooltip {
  position: absolute;
  background: rgba(20, 24, 36, 0.96);
  border: 1px solid #2e3346;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  max-width: 260px;
  pointer-events: none;
  z-index: 5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.tooltip strong {
  color: #ffd166;
  display: block;
  margin-bottom: 4px;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: #161922;
  border: 1px solid #232735;
  border-radius: 12px;
  padding: 24px;
  width: 90%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-box h2 {
  margin: 0 0 16px 0;
  font-size: 18px;
}

#person-form label {
  display: block;
  font-size: 13px;
  color: #9aa3bd;
  margin-bottom: 12px;
}

#person-form input[type="text"],
#person-form input[type="number"],
#person-form input[type="file"],
#person-form textarea {
  width: 100%;
  padding: 8px 10px;
  background: #0f1115;
  border: 1px solid #2e3346;
  border-radius: 6px;
  color: #e6e8ee;
  font-size: 14px;
  margin-top: 4px;
  font-family: inherit;
}

#person-form textarea {
  resize: vertical;
  min-height: 50px;
}

fieldset {
  border: 1px solid #2e3346;
  border-radius: 8px;
  padding: 12px;
  margin: 0 0 12px 0;
}

legend {
  font-size: 13px;
  color: #9aa3bd;
  padding: 0 6px;
}

.relation-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 0.8fr auto;
  gap: 8px;
  margin-bottom: 12px;
  align-items: center;
}

.relation-row .r-comment-field {
  grid-column: 1 / -1;
}

#person-form .relation-row .relation-field {
  margin-bottom: 0;
}

.relation-row .relation-field input,
.relation-row .relation-field textarea {
  margin-top: 4px !important;
}

.relation-row .remove {
  background: transparent;
  border: 1px solid #2e3346;
  color: #c64040;
  border-radius: 6px;
  cursor: pointer;
  padding: 6px 10px;
  height: fit-content;
}

.visibility-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: start;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid #252a3a;
  border-radius: 8px;
  background: rgba(15, 17, 21, 0.45);
}

.visibility-row select {
  width: 100%;
  padding: 8px 10px;
  background: #0f1115;
  border: 1px solid #2e3346;
  border-radius: 6px;
  color: #e6e8ee;
  font-size: 14px;
  margin-top: 4px;
  font-family: inherit;
}

.visibility-fields {
  grid-column: 1 / -2;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
}

#person-form .visibility-fields label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 0;
  color: #c2c8d6;
}

.visibility-fields input[type="checkbox"] {
  accent-color: #ffd166;
}

.visibility-row .remove {
  background: transparent;
  border: 1px solid #2e3346;
  color: #c64040;
  border-radius: 6px;
  cursor: pointer;
  padding: 6px 10px;
  height: fit-content;
  margin-top: 20px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.modal-subtitle {
  margin: -8px 0 14px 0;
  font-size: 12px;
  color: #9aa3bd;
}

.edge-chips-row {
  cursor: pointer;
}

.edge-chip {
  cursor: pointer;
}

.edge-chip-bg {
  fill: rgba(20, 24, 36, 0.92);
  stroke: rgba(108, 212, 168, 0.55);
  stroke-width: 1;
  transition: fill 0.15s, stroke 0.15s;
}

.edge-chip.event .edge-chip-bg {
  fill: rgba(31, 56, 47, 0.92);
  stroke: rgba(108, 212, 168, 0.7);
}

.edge-chip.event.private .edge-chip-bg {
  fill: rgba(56, 40, 70, 0.92);
  stroke: rgba(180, 140, 240, 0.75);
  stroke-dasharray: 4 2;
}

#event-form label.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  color: #c2c8d6;
  margin-bottom: 16px;
}

#event-form label.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
  accent-color: #b48cf0;
}

.edge-chip.add .edge-chip-bg {
  fill: rgba(31, 38, 56, 0.92);
  stroke: rgba(79, 124, 255, 0.6);
  stroke-dasharray: 3 3;
}

.edge-chip:hover .edge-chip-bg {
  fill: rgba(40, 50, 70, 0.95);
  stroke: #ffd166;
}

.edge-chip-text {
  fill: #d8f3e6;
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
  user-select: none;
}

.edge-chip.add .edge-chip-text {
  fill: #aab8e0;
}

.password-modal-box {
  max-width: 640px;
}

.password-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.password-grid label {
  display: block;
  font-size: 13px;
  color: #9aa3bd;
  margin-bottom: 0;
}

.password-grid input {
  width: 100%;
  padding: 8px 10px;
  background: #0f1115;
  border: 1px solid #2e3346;
  border-radius: 6px;
  color: #e6e8ee;
  font-size: 14px;
  margin-top: 4px;
  font-family: inherit;
}

.affinity-badge {
  pointer-events: none;
  user-select: none;
}

.affinity-mode-bg {
  fill: rgba(20, 24, 36, 0.95);
  stroke: rgba(154, 163, 189, 0.5);
  stroke-width: 1;
}

.affinity-mode-text {
  fill: #e6e8ee;
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: middle;
  font-weight: 600;
}

.affinity-score-bg {
  fill: rgba(40, 44, 60, 0.95);
  stroke: rgba(154, 163, 189, 0.4);
  stroke-width: 1;
}

.affinity-score-text {
  fill: #c2c8d6;
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: middle;
  font-weight: 700;
}

.affinity-score-bg.high {
  fill: rgba(31, 80, 50, 0.95);
  stroke: rgba(108, 212, 168, 0.7);
}
.affinity-score-bg.mid {
  fill: rgba(80, 70, 30, 0.95);
  stroke: rgba(255, 209, 102, 0.7);
}
.affinity-score-bg.low {
  fill: rgba(80, 50, 40, 0.95);
  stroke: rgba(220, 140, 100, 0.7);
}
.affinity-score-bg.neg {
  fill: rgba(90, 35, 45, 0.95);
  stroke: rgba(220, 90, 110, 0.8);
}

#event-form label {
  display: block;
  font-size: 13px;
  color: #9aa3bd;
  margin-bottom: 12px;
}

#event-form input[type="text"],
#event-form textarea {
  width: 100%;
  padding: 8px 10px;
  background: #0f1115;
  border: 1px solid #2e3346;
  border-radius: 6px;
  color: #e6e8ee;
  font-size: 14px;
  margin-top: 4px;
  font-family: inherit;
}

#event-form textarea {
  resize: vertical;
  min-height: 80px;
}

.user-info {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 8px;
  background: #1d2130;
  color: #ffd166;
  font-size: 13px;
  font-weight: 600;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid #2e3346;
}

.auth-tab {
  flex: 1;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  color: #9aa3bd;
  font-size: 14px;
  padding: 10px 0;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.auth-tab:hover {
  color: #c2c8d6;
}

.auth-tab.active {
  color: #ffd166;
  border-bottom-color: #ffd166;
}

#auth-form label {
  display: block;
  font-size: 13px;
  color: #9aa3bd;
  margin-bottom: 12px;
}

#auth-form input {
  width: 100%;
  padding: 8px 10px;
  background: #0f1115;
  border: 1px solid #2e3346;
  border-radius: 6px;
  color: #e6e8ee;
  font-size: 14px;
  margin-top: 4px;
  font-family: inherit;
}

.auth-error {
  color: #ff8a8a;
  background: rgba(198, 64, 64, 0.12);
  border: 1px solid rgba(198, 64, 64, 0.4);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  margin: 8px 0;
}

