:root {
  --bg: #f2efe8;
  --bg-strong: #ece6da;
  --panel: rgba(255, 252, 247, 0.88);
  --panel-strong: rgba(255, 255, 255, 0.95);
  --ink: #241f19;
  --muted: #6f665b;
  --line: #2f2552;
  --line-soft: rgba(47, 37, 82, 0.16);
  --highlight: #2f7d6b;
  --highlight-soft: rgba(47, 125, 107, 0.14);
  --border: rgba(51, 38, 24, 0.12);
  --shadow: 0 24px 48px rgba(56, 42, 30, 0.1);
  --radius-xl: 30px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.85), transparent 36%),
    radial-gradient(circle at 80% 0%, rgba(47, 125, 107, 0.12), transparent 28%),
    linear-gradient(180deg, #faf7f2 0%, var(--bg) 42%, #ebe5da 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a {
  color: inherit;
}

button {
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

.hidden {
  display: none !important;
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: #6f4a25;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: "Instrument Serif", serif;
  font-weight: 400;
  line-height: 0.94;
}

h1 {
  font-size: clamp(2.6rem, 5vw, 4rem);
}

h2 {
  font-size: clamp(2.1rem, 4vw, 3rem);
}

h3 {
  font-size: 1.95rem;
}

h4 {
  font-size: 1.05rem;
  font-family: "Manrope", sans-serif;
  font-weight: 700;
}

p {
  margin: 0;
}

.panel-copy,
.detail-status,
.detail-meta,
.detail-bio,
.dialog-note,
.login-helper {
  color: var(--muted);
}

.primary-button,
.secondary-button,
.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  border: 1px solid transparent;
  text-decoration: none;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.primary-button {
  background: linear-gradient(135deg, #263e3f, #2f7d6b);
  color: #f7fbf9;
  box-shadow: 0 16px 26px rgba(47, 125, 107, 0.2);
}

.secondary-button,
.link-button {
  background: rgba(255, 255, 255, 0.9);
  border-color: var(--border);
}

.primary-button:hover,
.secondary-button:hover,
.link-button:hover {
  transform: translateY(-1px);
}

.primary-button:disabled,
.secondary-button:disabled {
  opacity: 0.46;
  transform: none;
  cursor: not-allowed;
  box-shadow: none;
}

.compact-button {
  min-height: 38px;
  padding-inline: 0.85rem;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.4rem;
  background: linear-gradient(180deg, rgba(255, 251, 246, 0.82), rgba(245, 239, 230, 0.9));
  border-right: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.panel,
.member-form,
.login-card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel::after,
.member-form::after,
.login-card::after {
  content: "";
  position: absolute;
  inset: auto -42px -48px auto;
  width: 148px;
  height: 148px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(47, 125, 107, 0.18), transparent 70%);
  pointer-events: none;
}

.panel {
  padding: 1.35rem;
}

.intro-panel {
  display: grid;
  gap: 0.85rem;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.stat-label {
  margin-bottom: 0.4rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.stat-value {
  font-size: 2rem;
  font-weight: 800;
}

.detail-panel {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1rem;
}

.detail-head {
  display: grid;
  gap: 0.35rem;
}

.person-detail-card {
  display: grid;
  gap: 1rem;
  min-height: 280px;
  padding: 1rem;
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(36, 31, 25, 0.08);
}

.person-detail-card.empty {
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.detail-hero {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 1rem;
  align-items: center;
}

.detail-avatar,
.person-avatar {
  position: relative;
  display: grid;
  place-items: center;
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(135deg, #dfd4c2, #bda88e);
}

.detail-avatar {
  width: 78px;
  height: 78px;
}

.detail-avatar img,
.person-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-avatar img.is-broken,
.person-avatar img.is-broken {
  display: none;
}

.avatar-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: "Instrument Serif", serif;
  font-size: 1.4rem;
  color: rgba(36, 31, 25, 0.82);
}

.detail-bio {
  line-height: 1.55;
}

.detail-relations {
  display: grid;
  gap: 0.9rem;
}

.relation-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.45rem;
}

.relation-chip,
.empty-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(47, 37, 82, 0.1);
  background: rgba(47, 37, 82, 0.06);
  color: #342a58;
}

.relation-chip {
  cursor: pointer;
}

.empty-chip {
  color: var(--muted);
  background: rgba(36, 31, 25, 0.04);
}

.action-stack {
  display: grid;
  gap: 0.65rem;
  margin-top: auto;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.4rem;
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  gap: 1.2rem;
  align-items: flex-end;
}

.workspace-tools {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.8rem;
}

.legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.legend-swatch {
  width: 30px;
  height: 10px;
  border-radius: 999px;
}

.legend-swatch-line {
  background: var(--line);
}

.legend-swatch-highlight {
  background: var(--highlight);
}

.zoom-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
}

.zoom-button {
  min-width: 46px;
}

.zoom-readout {
  min-width: 58px;
  text-align: right;
  font-weight: 800;
}

.tree-scroller {
  position: relative;
  overflow: auto;
  flex: 1;
  min-height: calc(100vh - 168px);
  border-radius: 36px;
  border: 1px solid var(--border);
  background:
    radial-gradient(circle at top, rgba(47, 125, 107, 0.09), transparent 28%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(239, 233, 223, 0.92));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.64), var(--shadow);
}

.tree-scroller.is-dragging {
  cursor: grabbing;
}

.tree-canvas {
  position: relative;
  min-width: 100%;
  min-height: 100%;
}

.tree-surface {
  position: relative;
  padding: 60px 60px 90px;
  transform-origin: top left;
}

#connectorLayer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 0;
}

.connector-path {
  stroke: var(--line);
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.88;
  filter: drop-shadow(0 6px 8px rgba(47, 37, 82, 0.12));
}

.connector-path.is-secondary {
  stroke-width: 3.5;
  opacity: 0.72;
}

.connector-path.is-highlighted {
  stroke: var(--highlight);
  opacity: 1;
}

.forest {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 3rem;
  align-items: center;
  width: max-content;
  min-width: 100%;
}

.family-tree,
.child-branch,
.solo-root {
  position: relative;
  z-index: 1;
}

.family-tree {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.35rem;
}

.family-tree.family-already-shown {
  display: none;
}

.multi-family-cluster {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.7rem;
}

.multi-family-spouses {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  gap: 2.25rem;
  width: 100%;
}

.multi-family-children-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 2rem;
  width: 100%;
}

.multi-family-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-start;
  justify-content: center;
  gap: 2.25rem;
  width: 100%;
}

.multi-family-row > .shared-anchor-family {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.family-parents,
.branch-head,
.children-row,
.descendant-families {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 1.55rem;
}

.branch-head {
  flex-wrap: wrap;
}

.shared-anchor-family {
  gap: 1.55rem;
}

.shared-anchor-family > .branch-head {
  min-height: 176px;
  align-items: center;
}

.children-row {
  gap: 2rem;
}

.descendant-families {
  margin-top: 1.6rem;
  gap: 2.25rem;
}

.child-branch {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.person-card {
  position: relative;
  width: 164px;
  min-height: 176px;
  padding: 0.9rem 0.9rem 1rem;
  border-radius: 24px;
  border: 1px solid rgba(47, 37, 82, 0.18);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 16px 30px rgba(51, 38, 24, 0.1);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease, opacity 180ms ease;
}

.person-card:hover {
  transform: translateY(-2px);
}

.person-card.is-selected {
  border-color: rgba(47, 37, 82, 0.42);
  box-shadow: 0 20px 34px rgba(47, 37, 82, 0.18);
}

.person-card.is-highlighted {
  border-color: rgba(47, 125, 107, 0.4);
  box-shadow: 0 20px 34px rgba(47, 125, 107, 0.18);
}

.person-card.is-dimmed {
  opacity: 0.42;
}

.person-card-select {
  display: grid;
  place-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: center;
  color: inherit;
}

.person-avatar {
  width: 72px;
  height: 72px;
  border: 2px solid rgba(47, 37, 82, 0.24);
}

.person-name {
  font-weight: 800;
  font-size: 0.98rem;
  line-height: 1.2;
}

.person-meta {
  display: block;
  color: var(--muted);
  font-size: 0.83rem;
}

.person-meta.subtle {
  opacity: 0.9;
}

.branch-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid rgba(47, 37, 82, 0.14);
  background: rgba(245, 242, 237, 0.96);
  color: #342a58;
  font-size: 1rem;
  line-height: 1;
}

.branch-toggle.is-collapsed {
  background: rgba(47, 125, 107, 0.08);
}

.solo-root {
  display: flex;
  justify-content: center;
}

.empty-state {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  gap: 0.85rem;
  min-height: 560px;
  padding: 2rem;
  border-radius: 32px;
  border: 1px dashed rgba(47, 37, 82, 0.22);
  background: rgba(255, 255, 255, 0.62);
  text-align: center;
}

.empty-orbit {
  position: absolute;
  width: 240px;
  height: 240px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(47, 125, 107, 0.18), transparent 68%);
}

.member-dialog {
  width: min(620px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  background: transparent;
}

.member-dialog::backdrop {
  background: rgba(23, 18, 14, 0.38);
  backdrop-filter: blur(10px);
}

.member-form {
  display: grid;
  gap: 1rem;
  padding: 1.4rem;
  background: rgba(255, 252, 247, 0.97);
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.dialog-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.dialog-grid label,
.login-form label {
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.94rem;
}

.full-width {
  grid-column: 1 / -1;
}

input,
select,
textarea {
  width: 100%;
  border-radius: 16px;
  border: 1px solid rgba(36, 31, 25, 0.12);
  background: rgba(255, 255, 255, 0.92);
  padding: 0.8rem 0.9rem;
  color: var(--ink);
}

textarea {
  resize: vertical;
  min-height: 120px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(47, 125, 107, 0.24);
  border-color: rgba(47, 125, 107, 0.36);
}

.login-page {
  display: grid;
  place-items: center;
  padding: 1.6rem;
}

.login-shell {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 420px);
  gap: 1.2rem;
}

.login-card {
  padding: 1.6rem;
}

.login-hero {
  display: grid;
  align-content: center;
  gap: 1rem;
  min-height: 420px;
  background:
    radial-gradient(circle at top left, rgba(47, 125, 107, 0.12), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.86), rgba(246, 239, 229, 0.95));
}

.login-panel {
  display: grid;
  gap: 1rem;
  align-content: center;
}

.login-form {
  display: grid;
  gap: 1rem;
}

.login-actions {
  display: flex;
}

.error-banner {
  padding: 0.9rem 1rem;
  border-radius: 16px;
  background: rgba(137, 40, 16, 0.08);
  color: #892810;
  border: 1px solid rgba(137, 40, 16, 0.18);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .workspace {
    padding-top: 0;
  }
}

@media (max-width: 840px) {
  .sidebar,
  .workspace {
    padding: 1rem;
  }

  .workspace-header,
  .dialog-header,
  .dialog-actions,
  .login-shell {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .workspace-tools {
    align-items: stretch;
  }

  .legend {
    gap: 0.65rem;
  }

  .dialog-grid {
    grid-template-columns: 1fr;
  }

  .stats-panel {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .person-card {
    width: 150px;
  }

  .family-parents,
  .children-row,
  .descendant-families {
    gap: 1rem;
  }
}

@media (max-width: 620px) {
  .stats-panel {
    grid-template-columns: 1fr;
  }

  .tree-surface {
    padding: 42px 28px 64px;
  }

  .tree-scroller {
    min-height: 72vh;
  }

  .person-card {
    width: 138px;
    min-height: 166px;
    padding-inline: 0.75rem;
  }

  .person-avatar {
    width: 64px;
    height: 64px;
  }
}
