:root {
  --bg: #eff1df;
  --panel: rgba(255, 250, 240, 0.84);
  --panel-strong: rgba(255, 253, 247, 0.96);
  --ink: #2f281f;
  --muted: #726454;
  --leaf: #6b8f47;
  --leaf-strong: #4f6f35;
  --leaf-soft: #adc88d;
  --branch: #7a4f2b;
  --branch-shadow: rgba(81, 45, 18, 0.18);
  --glow: rgba(202, 219, 154, 0.55);
  --ring: rgba(88, 114, 52, 0.22);
  --danger: #8c4c28;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.8), transparent 34%),
    radial-gradient(circle at top right, rgba(184, 210, 137, 0.38), transparent 26%),
    linear-gradient(180deg, #f8f6eb 0%, #eef0dd 48%, #e7ecd4 100%);
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid rgba(94, 86, 62, 0.12);
  background: linear-gradient(180deg, rgba(251, 248, 240, 0.88), rgba(242, 240, 225, 0.75));
  backdrop-filter: blur(18px);
}

.sidebar-card,
.member-form {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(94, 86, 62, 0.12);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 18px 40px rgba(69, 50, 28, 0.08);
}

.sidebar-card {
  padding: 22px;
}

.sidebar-card::after,
.member-form::after {
  content: "";
  position: absolute;
  inset: auto -30px -40px auto;
  width: 120px;
  height: 120px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(191, 211, 146, 0.32), transparent 70%);
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--leaf-strong);
  font-weight: 700;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Cormorant Garamond", serif;
  line-height: 0.95;
  font-weight: 700;
}

h1 {
  font-size: clamp(2.4rem, 4vw, 3.3rem);
}

h2 {
  font-size: clamp(2rem, 3vw, 2.8rem);
}

h3 {
  font-size: 2rem;
}

.intro-copy,
.stage-note,
.selection-hint,
.person-meta,
.person-notes,
.empty-state p,
label {
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.toolbar.stacked {
  flex-direction: column;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.primary-button {
  background: linear-gradient(135deg, var(--leaf) 0%, var(--leaf-strong) 100%);
  color: #f7f9ec;
  box-shadow: 0 12px 24px rgba(79, 111, 53, 0.22);
}

.secondary-button,
.icon-button {
  background: rgba(255, 252, 245, 0.95);
  color: var(--ink);
  border: 1px solid rgba(94, 86, 62, 0.14);
}

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

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

.stats-card {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.stat-value {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
}

.detail-card {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.detail-header {
  margin-bottom: 16px;
}

.person-details {
  min-height: 150px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 253, 247, 0.9);
  border: 1px solid rgba(94, 86, 62, 0.08);
}

.person-details.empty {
  display: grid;
  place-items: center;
  text-align: center;
}

.person-details h3 {
  font-size: 2.15rem;
  margin-bottom: 8px;
}

.person-meta,
.person-notes {
  margin: 0 0 10px;
}

.relationship-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.relationship-list li {
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(173, 200, 141, 0.2);
  color: var(--leaf-strong);
  font-size: 0.9rem;
}

.tree-stage {
  padding: 28px;
  overflow: hidden;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 22px;
}

.tree-scroller {
  position: relative;
  overflow: auto;
  height: calc(100vh - 128px);
  border-radius: 34px;
  border: 1px solid rgba(94, 86, 62, 0.12);
  background:
    radial-gradient(circle at top, rgba(214, 228, 182, 0.68), transparent 34%),
    linear-gradient(180deg, rgba(246, 246, 236, 0.94), rgba(231, 236, 214, 0.96));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.56), 0 24px 48px rgba(76, 64, 34, 0.12);
}

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

.tree-canvas {
  position: relative;
  min-width: max-content;
  min-height: 100%;
  padding: 56px 56px 90px;
}

.forest,
.empty-state {
  position: relative;
  z-index: 2;
}

.forest {
  display: flex;
  gap: 52px;
  align-items: flex-start;
}

.family-block {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 30px;
}

.family-card {
  position: relative;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 660px;
  padding: 16px 18px;
  border-radius: 999px;
  background:
    linear-gradient(180deg, rgba(255, 253, 246, 0.98), rgba(250, 248, 240, 0.94));
  border: 1px solid rgba(122, 79, 43, 0.16);
  box-shadow: 0 16px 30px rgba(84, 60, 26, 0.1);
}

.partner-connector {
  width: 26px;
  height: 12px;
  border-bottom: 4px solid rgba(122, 79, 43, 0.68);
  border-radius: 999px;
  flex: 0 0 auto;
}

.children-row {
  display: inline-flex;
  align-items: flex-start;
  justify-content: center;
  gap: 34px;
}

.child-branch {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.descendant-families {
  display: inline-flex;
  gap: 36px;
  align-items: flex-start;
}

.person-card {
  position: relative;
  z-index: 2;
  min-width: 150px;
  max-width: 210px;
  padding: 14px 16px;
  border-radius: 22px;
  border: 1px solid rgba(76, 112, 47, 0.22);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.92), rgba(242, 249, 229, 0.98) 42%, rgba(228, 238, 208, 0.98) 100%);
  box-shadow: 0 18px 28px rgba(86, 119, 53, 0.14);
  text-align: left;
  color: inherit;
}

.person-card::before {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 28px;
  background: radial-gradient(circle at top, rgba(176, 206, 133, 0.35), transparent 70%);
  opacity: 0;
  transition: opacity 180ms ease;
  z-index: -1;
}

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

.person-card.selected {
  border-color: rgba(79, 111, 53, 0.56);
  box-shadow: 0 20px 30px rgba(86, 119, 53, 0.26);
}

.person-name {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  font-size: 1rem;
}

.person-caption,
.person-role {
  display: block;
  font-size: 0.84rem;
  color: var(--muted);
}

.empty-state {
  position: relative;
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 560px;
  border-radius: 28px;
  border: 1px dashed rgba(122, 79, 43, 0.22);
  background: rgba(255, 252, 246, 0.64);
  text-align: center;
  overflow: hidden;
}

.empty-glow {
  position: absolute;
  width: 240px;
  height: 240px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(177, 203, 134, 0.44), transparent 72%);
}

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

.member-dialog::backdrop {
  background: rgba(38, 30, 16, 0.38);
  backdrop-filter: blur(8px);
}

.member-form {
  padding: 24px;
}

.dialog-header,
.dialog-actions,
.form-row {
  display: flex;
  gap: 14px;
}

.dialog-header,
.dialog-actions {
  justify-content: space-between;
  align-items: center;
}

.member-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
  font-size: 0.92rem;
  font-weight: 600;
}

.member-form input,
.member-form select,
.member-form textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(94, 86, 62, 0.14);
  background: rgba(255, 253, 247, 0.95);
  color: var(--ink);
}

.member-form textarea {
  resize: vertical;
}

.member-form input:focus,
.member-form select:focus,
.member-form textarea:focus {
  outline: 2px solid var(--ring);
  border-color: rgba(79, 111, 53, 0.36);
}

.form-row > label {
  flex: 1;
}

.dialog-actions {
  margin-top: 22px;
}

.hidden {
  display: none !important;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid rgba(94, 86, 62, 0.12);
  }

  .tree-stage {
    padding-top: 18px;
  }

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

@media (max-width: 720px) {
  .sidebar,
  .tree-stage {
    padding: 16px;
  }

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

  .stage-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .tree-canvas {
    padding: 28px 18px 56px;
  }

  .children-row,
  .descendant-families,
  .forest {
    gap: 18px;
  }

  .person-card {
    min-width: 132px;
  }
}
