:root {
  --bg: #000;
  --panel: rgba(6, 8, 10, 0.82);
  --panel-strong: rgba(12, 15, 18, 0.94);
  --line: rgba(255, 255, 255, 0.11);
  --text: #f4f7fb;
  --muted: #89939f;
  --soft: #c6ccd5;
  --glow: #ffffff;
  --glow-soft: #dce3ec;
  --danger: #dce3ec;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.055), transparent 27rem),
    radial-gradient(circle at 80% 72%, rgba(255, 255, 255, 0.045), transparent 32rem),
    #000;
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px),
    radial-gradient(circle, rgba(255, 255, 255, 0.13) 1px, transparent 1.4px);
  background-position: 0 0, 0 0, 0 0;
  background-size: 48px 48px, 48px 48px, 16px 16px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), rgba(0, 0, 0, 0.35));
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.72);
  outline-offset: 2px;
}

.app-shell {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

.tree-board {
  position: relative;
  overflow: hidden;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  cursor: grab;
  touch-action: none;
}

.tree-board.panning {
  cursor: grabbing;
}

.wire-layer,
.people-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.wire-layer {
  z-index: 1;
  pointer-events: none;
}

.people-layer {
  z-index: 2;
  transform-origin: 0 0;
}

.toolbar {
  position: absolute;
  z-index: 5;
  top: 24px;
  left: 24px;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(18px);
  -webkit-user-select: none;
  user-select: none;
}

body.is-panning,
body.is-panning * {
  -webkit-user-select: none !important;
  user-select: none !important;
}

body:not(.owner-mode) .toolbar {
  display: none;
}

body.admin-locked .toolbar {
  opacity: 0.58;
}

.icon-button,
.tool-button {
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  -webkit-user-select: none;
  user-select: none;
}

.icon-button {
  display: grid;
  width: 38px;
  place-items: center;
  padding: 0;
  font-size: 24px;
  font-weight: 600;
}

.icon-button.primary {
  border-color: rgba(255, 255, 255, 0.42);
  background: rgba(255, 255, 255, 0.15);
  box-shadow: 0 0 24px rgba(255, 255, 255, 0.14);
}

.icon-button.danger {
  color: var(--danger);
}

.tool-button {
  min-width: 84px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.tool-button[aria-pressed="true"] {
  border-color: rgba(255, 255, 255, 0.68);
  color: #050608;
  background: var(--glow);
  box-shadow: 0 0 26px rgba(255, 255, 255, 0.22);
}

.tool-button.subtle {
  min-width: 62px;
  color: var(--muted);
}

.save-button {
  min-width: 118px;
}

.save-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.connection-hint {
  position: absolute;
  z-index: 5;
  top: 84px;
  left: 24px;
  max-width: 320px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: var(--soft);
  background: rgba(0, 0, 0, 0.68);
  font-size: 13px;
  line-height: 1.4;
  backdrop-filter: blur(16px);
}

.person-card {
  position: absolute;
  display: grid;
  width: 138px;
  height: 174px;
  grid-template-rows: 104px 1fr;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.025)),
    rgba(0, 0, 0, 0.64);
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
  -webkit-user-select: none;
  user-select: none;
  backdrop-filter: blur(18px);
  cursor: pointer;
  touch-action: none;
}

.person-card.draggable {
  cursor: grab;
}

.person-card.draggable:active {
  cursor: grabbing;
}

.person-card::before {
  position: absolute;
  inset: -1px;
  z-index: -1;
  content: "";
  opacity: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.75), transparent 42%, rgba(255, 255, 255, 0.38));
  filter: blur(12px);
  transition: opacity 180ms ease;
}

.person-card:hover::before,
.person-card.selected::before,
.person-card.connecting::before {
  opacity: 0.55;
}

.person-card.selected {
  border-color: rgba(255, 255, 255, 0.72);
}

.person-card.connecting {
  outline: 2px solid rgba(255, 255, 255, 0.82);
  outline-offset: 4px;
}

.person-card img {
  width: 100%;
  height: 104px;
  object-fit: cover;
  background: #0b0f13;
  filter: grayscale(1) contrast(1.08) brightness(1.06);
}

.person-meta {
  display: grid;
  min-width: 0;
  align-content: center;
  gap: 2px;
  text-align: left;
}

.person-first-name,
.person-last-name,
.person-birth {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-first-name {
  font-size: 14px;
  line-height: 1.05;
  font-weight: 800;
}

.person-last-name {
  font-size: 13px;
  line-height: 1.05;
  font-weight: 800;
}

.person-birth {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
  font-weight: 600;
}

.wire-base {
  fill: none;
  stroke: rgba(255, 255, 255, 0.13);
  stroke-linecap: square;
  stroke-linejoin: miter;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.wire-flow {
  fill: none;
  stroke: rgba(255, 255, 255, 0.72);
  stroke-dasharray: 14 26;
  stroke-linecap: square;
  stroke-linejoin: miter;
  stroke-width: 2.3;
  filter: url("#wireGlow");
  opacity: 0.7;
  animation: dataFlow 2s linear infinite;
  vector-effect: non-scaling-stroke;
}

.data-pulse {
  fill: var(--glow);
  filter: url("#wireGlow");
  opacity: 0.95;
}

@keyframes dataFlow {
  to {
    stroke-dashoffset: -72;
  }
}

.info-card {
  position: absolute;
  right: 24px;
  bottom: 24px;
  z-index: 5;
  display: grid;
  width: min(420px, calc(100vw - 48px));
  grid-template-columns: 112px 1fr;
  gap: 16px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.72);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(20px);
}

.info-card img {
  width: 112px;
  height: 112px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.12);
  filter: grayscale(1) contrast(1.08) brightness(1.06);
}

.info-copy {
  min-width: 0;
  padding-right: 34px;
}

.info-card h2 {
  margin: 0 0 4px;
  font-size: 22px;
  line-height: 1.08;
}

.info-birth,
.info-bio {
  margin: 0;
  color: var(--soft);
  font-size: 13px;
  line-height: 1.45;
}

.info-birth {
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 700;
}

.info-bio {
  white-space: pre-wrap;
}

.info-instagram {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  overflow: hidden;
  margin-top: 14px;
  padding: 8px 10px;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 22px rgba(255, 255, 255, 0.12);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.info-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  font-size: 18px;
  line-height: 1;
}

.admin-login {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.56);
  backdrop-filter: blur(10px);
}

.admin-login form {
  width: min(360px, 100%);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.82);
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.52);
}

.admin-login h2 {
  margin: 0 0 20px;
  font-size: 24px;
}

.admin-login label {
  display: grid;
  gap: 8px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 700;
}

.admin-login input {
  width: 100%;
  margin-bottom: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  outline: none;
}

.login-error {
  min-height: 20px;
  margin: 0 0 14px;
  color: var(--glow-soft);
  font-size: 13px;
  line-height: 1.4;
}

.profile-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 6;
  width: min(380px, 100vw);
  height: 100vh;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(24px);
}

.empty-state,
.editor {
  padding: 26px;
}

.empty-state {
  display: grid;
  height: 100%;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.panel-header h1 {
  margin: 0;
  font-size: 25px;
  line-height: 1.05;
}

.photo-picker {
  position: relative;
  display: block;
  width: 100%;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.photo-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.photo-picker img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  filter: grayscale(1) contrast(1.08) brightness(1.06);
}

.photo-picker span {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 8px 10px;
  color: #050608;
  background: var(--glow);
  font-size: 12px;
  font-weight: 800;
}

.editor label {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 700;
}

.editor input,
.editor textarea,
.instagram-input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text);
  background: rgba(255, 255, 255, 0.055);
  outline: none;
}

.editor input,
.editor textarea {
  padding: 12px;
}

.editor input:focus,
.editor textarea:focus,
.instagram-input:focus-within {
  border-color: rgba(255, 255, 255, 0.52);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.editor textarea {
  resize: vertical;
  line-height: 1.45;
}

.instagram-input {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
}

.instagram-input span {
  display: grid;
  height: 100%;
  place-items: center;
  color: var(--glow-soft);
  font-weight: 900;
}

.instagram-input input {
  border: 0;
  background: transparent;
}

.info-preview {
  display: grid;
  gap: 14px;
  margin: 22px 0;
  padding: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.045);
}

.info-preview p {
  min-height: 36px;
  margin: 0;
  color: var(--soft);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.info-preview a {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  padding: 9px 11px;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 22px rgba(255, 255, 255, 0.12);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.connection-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  color: var(--soft);
  font-size: 13px;
}

.connection-row button {
  border: 0;
  color: var(--danger);
  background: transparent;
  font-weight: 800;
}

@media (max-width: 880px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .tree-board {
    height: 100vh;
    height: 100dvh;
  }

  .profile-panel {
    border-left: 0;
  }

  .toolbar {
    top: 14px;
    right: 14px;
    left: 14px;
    flex-wrap: wrap;
    max-width: calc(100vw - 28px);
  }

  .tool-button {
    min-width: auto;
    padding: 0 10px;
  }

  .save-button {
    min-width: 106px;
  }

  .connection-hint {
    top: 112px;
    left: 14px;
    max-width: calc(100vw - 28px);
  }

  .info-card {
    right: 14px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 84px);
    max-height: min(44vh, 340px);
    max-height: min(44dvh, 340px);
    overflow-y: auto;
    width: calc(100vw - 28px);
    grid-template-columns: 88px 1fr;
    -webkit-overflow-scrolling: touch;
  }

  .info-card img {
    width: 88px;
    height: 88px;
  }
}
