:root {
  --bg: #f6f1ea;
  --surface: #fffaf3;
  --surface-strong: #fffdf9;
  --surface-2: #efe4d7;
  --text: #2d261f;
  --muted: #73675c;
  --line: #b8a792;
  --accent: #6d5a44;
  --accent-soft: #e7d9c7;
  --shadow: 0 18px 45px rgba(45, 38, 31, 0.12);
  --radius: 22px;
  --ancestor-branch-w: 380px;
  --child-branch-w: 280px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #fff7eb 0, var(--bg) 42%, #ece0d2 100%);
  color: var(--text);
}

button {
  font: inherit;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 2rem clamp(1rem, 4vw, 3rem) 1rem;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4rem);
  letter-spacing: -0.05em;
}

.eyebrow {
  margin: 0 0 0.4rem;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(310px, 380px);
  gap: 1.5rem;
  padding: 1rem clamp(1rem, 4vw, 3rem) 3rem;
}

.tree-section,
.detail-panel {
  border: 1px solid rgba(184, 167, 146, 0.35);
  border-radius: var(--radius);
  background: rgba(255, 250, 243, 0.78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.tree-section {
  min-height: 620px;
  overflow: hidden;
  padding: 1.25rem;
}

.detail-panel {
  position: sticky;
  top: 1rem;
  height: fit-content;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
  padding: 1.25rem;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: end;
  margin-bottom: 1rem;
}

.section-heading h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 1.8rem);
}

.focus-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: right;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-bottom: 1rem;
}

.toolbar button,
.app-header button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.68rem 1rem;
  background: var(--accent-soft);
  color: var(--text);
  cursor: pointer;
  font-weight: 650;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.toolbar button:hover,
.app-header button:hover {
  transform: translateY(-1px);
}

.toolbar button:focus-visible,
.app-header button:focus-visible,
.person-card:focus-visible {
  outline: 3px solid rgba(109, 90, 68, 0.35);
  outline-offset: 3px;
}

.toolbar button.is-active {
  background: var(--accent);
  color: white;
}

.toolbar button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}

.toolbar button.secondary,
.app-header button.secondary {
  border-color: rgba(184, 167, 146, 0.45);
  background: var(--surface-2);
  color: var(--text);
}

.tree {
  min-height: 480px;
  overflow-x: auto;
  padding: 1.5rem 0.5rem 2.5rem;
}

.tree-map {
  position: relative;
  display: flex;
  min-width: 820px;
  flex-direction: column;
  align-items: center;
}

.tree-connections {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}

.tree-conn {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* faint second-parent (partner) hint — dashed, low opacity */
.tree-conn-soft {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.25;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 3 5;
  opacity: 0.4;
}

.tree-map:not(.simple-tree) .family-connector {
  visibility: hidden;
}

/* SVG layer owns every connector in the full tree — silence the CSS line stubs */
.tree-map:not(.simple-tree) .sibling-family-group::before,
.tree-map:not(.simple-tree) .linked-family-level .parent-child-bracket,
.tree-map:not(.simple-tree) .tree-level + .tree-level::before,
.tree-map:not(.simple-tree) .level-control + .tree-level::before,
.tree-map:not(.simple-tree) .grandparents + .level-control::before,
.tree-map:not(.simple-tree) .generation-centered:has(.person-card + .person-card)::before,
.tree-map:not(.simple-tree) .partner-set::before,
.tree-map:not(.simple-tree) .focus-side-right:not(:empty)::before,
.tree-map:not(.simple-tree) .child-branches:has(.child-branch + .child-branch)::before {
  display: none;
}

.simple-tree {
  min-width: 620px;
}

.tree-level {
  position: relative;
  width: 100%;
  padding: 0.75rem 0;
}

.tree-level + .tree-level {
  margin-top: 2.25rem;
}

.tree-level + .tree-level::before {
  position: absolute;
  top: -2.25rem;
  left: 50%;
  width: 1px;
  height: 2.65rem;
  background: var(--line);
  content: "";
}

.level-control {
  display: grid;
  position: relative;
  z-index: 3;
  width: 100%;
  margin: 1.1rem 0 0.65rem;
  place-items: center;
}

.level-control + .tree-level {
  margin-top: 1.2rem;
}

.level-control + .tree-level::before {
  position: absolute;
  top: -1.85rem;
  left: 50%;
  width: 1px;
  height: 2.25rem;
  background: var(--line);
  content: "";
}

.grandparents + .level-control::before {
  position: absolute;
  top: -1.85rem;
  left: 50%;
  width: 1px;
  height: 1.85rem;
  background: var(--line);
  content: "";
}

.level-button {
  border: 1px solid rgba(184, 167, 146, 0.5);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  background: var(--surface-strong);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 700;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.level-button:hover {
  background: var(--accent);
  color: white;
  transform: translateY(-1px);
}

.level-button:focus-visible {
  outline: 3px solid rgba(109, 90, 68, 0.35);
  outline-offset: 3px;
}

.generation {
  display: flex;
  position: relative;
  align-items: stretch;
  justify-content: center;
  gap: 1.1rem;
}

.generation-centered {
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
}

.generation-centered:has(.person-card + .person-card)::before {
  position: absolute;
  top: 50%;
  right: 90px;
  left: 90px;
  z-index: 0;
  height: 1px;
  background: var(--line);
  content: "";
}

.family-units {
  display: flex;
  justify-content: center;
  gap: 2rem;
  width: fit-content;
  max-width: 100%;
  margin-inline: auto;
}

.family-unit {
  position: relative;
  width: fit-content;
  max-width: 100%;
}

.family-unit .parent-pair {
  padding-inline: 0.4rem;
}

.family-unit .parent-pair::before,
.sibling-set::before,
.child-set::before {
  display: none;
}

.family-connector {
  position: relative;
  width: calc(100% - 90px);
  min-width: 74px;
  max-width: 320px;
  height: 38px;
  margin: 0.7rem auto 0;
  border-right: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  border-left: 2px solid var(--line);
  border-radius: 0 0 20px 20px;
}

.family-connector::after {
  position: absolute;
  bottom: -2.1rem;
  left: 50%;
  width: 2px;
  height: 2.1rem;
  background: var(--line);
  content: "";
  transform: translateX(-50%);
}

.family-unit:has(.person-card:only-child) .family-connector {
  width: 2px;
  min-width: 2px;
  border-right: 0;
  border-bottom: 0;
  border-left: 2px solid var(--line);
  border-radius: 0;
}

.ancestor-family-level,
.parent-family-level {
  padding-bottom: 0;
}

.ancestor-family-level + .ancestor-family-level,
.ancestor-family-level + .level-control,
.parent-family-level + .focus-level,
.family-descendants + .tree-level {
  margin-top: 2.9rem;
}

.ancestor-family-level + .ancestor-family-level::before,
.parent-family-level + .focus-level::before,
.family-descendants + .tree-level::before {
  display: none;
}

.parent-family-level .family-units {
  min-width: min(100%, 420px);
}

.focus-generation {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 180px minmax(220px, 1fr);
  gap: 1.1rem;
  align-items: center;
  width: 100%;
}

.focus-family-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, auto);
  gap: 1.6rem;
  align-items: end;
  width: min(100%, 820px);
  margin-inline: auto;
}

.sibling-family-group {
  position: relative;
  min-width: 0;
}

.linked-family-level::before {
  display: none;
}

.sibling-family-group::before {
  position: absolute;
  top: -2.25rem;
  left: 50%;
  width: 1px;
  height: 2.25rem;
  background: var(--line);
  content: "";
}

.parent-child-bracket {
  position: relative;
  width: min(72%, 380px);
  height: 34px;
  margin: -0.2rem auto 0.75rem;
  border-right: 2px solid var(--line);
  border-bottom: 2px solid var(--line);
  border-left: 2px solid var(--line);
  border-radius: 0 0 18px 18px;
}

.parent-child-bracket::before {
  position: absolute;
  top: -0.7rem;
  left: 50%;
  width: 2px;
  height: 0.7rem;
  background: var(--line);
  content: "";
  transform: translateX(-50%);
}

.parent-child-bracket::after {
  position: absolute;
  bottom: -0.75rem;
  left: 50%;
  width: 2px;
  height: 0.75rem;
  background: var(--line);
  content: "";
  transform: translateX(-50%);
}

.sibling-set {
  padding: 0 0.75rem;
}

.partner-group {
  display: grid;
  position: relative;
  align-self: end;
  gap: 0.75rem;
}

.partner-set {
  display: flex;
  position: relative;
  gap: 1.1rem;
  align-items: stretch;
}

.partner-set::before {
  position: absolute;
  top: 50%;
  left: -1.35rem;
  width: 1.35rem;
  height: 1px;
  background: var(--line);
  content: "";
}

.ancestors .generation-centered:has(.person-card + .person-card)::before {
  display: none;
}

.focus-person {
  grid-column: 2;
}

.focus-side {
  display: flex;
  gap: 1.1rem;
  align-items: center;
  min-width: 0;
}

.focus-side-left {
  grid-column: 1;
  justify-content: flex-end;
}

.focus-side-right {
  grid-column: 3;
  justify-content: flex-start;
}

.focus-side-left:not(:empty)::after,
.focus-side-right:not(:empty)::before {
  width: 1.1rem;
  height: 1px;
  background: var(--line);
  content: "";
}

.focus-side-left:not(:empty)::after {
  margin-right: -1.1rem;
}

.focus-side-right:not(:empty)::before {
  margin-left: -1.1rem;
}

.connection-label {
  position: relative;
  z-index: 2;
  width: fit-content;
  margin: 0 auto 0.65rem;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.focus-level::before {
  z-index: 0;
}

.ancestor-branches {
  display: flex;
  position: relative;
  justify-content: center;
  gap: 2rem;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding-bottom: 1.25rem;
}

.ancestor-branches:has(.ancestor-branch + .ancestor-branch)::after {
  position: absolute;
  right: calc(var(--ancestor-branch-w) / 2);
  bottom: 0;
  left: calc(var(--ancestor-branch-w) / 2);
  height: 1px;
  background: var(--line);
  content: "";
}

.ancestor-branch {
  position: relative;
  flex: 0 0 var(--ancestor-branch-w);
  width: var(--ancestor-branch-w);
  padding-bottom: 1rem;
}

.ancestor-branch::after {
  position: absolute;
  bottom: -1.25rem;
  left: 50%;
  width: 1px;
  height: 2.25rem;
  background: var(--line);
  content: "";
}

.branch-label {
  position: relative;
  z-index: 2;
  width: fit-content;
  margin: 0 auto 0.65rem;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.child-branches {
  display: flex;
  position: relative;
  justify-content: center;
  gap: 2rem;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding-top: 1.25rem;
}

.child-branches:has(.child-branch + .child-branch)::before {
  position: absolute;
  top: 0;
  right: calc(var(--child-branch-w) / 2);
  left: calc(var(--child-branch-w) / 2);
  height: 1px;
  background: var(--line);
  content: "";
}

.child-branch {
  position: relative;
  flex: 0 0 var(--child-branch-w);
  width: var(--child-branch-w);
  padding-top: 1rem;
}

.child-branch::before {
  position: absolute;
  top: -1.25rem;
  left: 50%;
  width: 1px;
  height: 2.25rem;
  background: var(--line);
  content: "";
}

.family-child-branches {
  align-items: flex-start;
  padding-top: 0;
}

.family-child-branches::before,
.family-child-branch::before {
  display: none !important;
}

.family-child-branch {
  flex: 0 0 auto;
  width: auto;
  min-width: var(--child-branch-w);
  padding-top: 0;
}

.child-branch-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3.5rem;
}

.coparent-ghost {
  display: flex;
  align-items: center;
}

.coparent-ghost-card {
  display: grid;
  justify-items: center;
  gap: 0.3rem;
  width: 138px;
  border: 1.5px dashed rgba(184, 167, 146, 0.7);
  border-radius: 18px;
  padding: 0.75rem 0.6rem;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.18s ease, background 0.18s ease;
}

.coparent-ghost-card:hover {
  opacity: 1;
  background: var(--surface-2);
}

.coparent-ghost-avatar {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  object-fit: cover;
  font-size: 0.85rem;
  font-weight: 700;
}

.coparent-ghost-name {
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: center;
}

.coparent-ghost-role {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.child-set {
  margin-top: 2.35rem;
}

.family-child-branch .child-set {
  margin-top: 1.75rem;
}

.co-parent-label {
  display: flex;
  position: relative;
  z-index: 2;
  width: fit-content;
  min-height: 32px;
  margin: 0 auto 0.75rem;
  border: 1px solid rgba(184, 167, 146, 0.45);
  border-radius: 999px;
  padding: 0.32rem 0.45rem 0.32rem 0.75rem;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.78rem;
  align-items: center;
  gap: 0.45rem;
}

.person-link {
  border: 0;
  border-radius: 999px;
  padding: 0.28rem 0.55rem;
  background: var(--accent-soft);
  color: var(--text);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
}

.person-link:hover {
  background: var(--accent);
  color: white;
}

.person-link:focus-visible {
  outline: 3px solid rgba(109, 90, 68, 0.35);
  outline-offset: 2px;
}

.person-card {
  display: block;
  position: relative;
  z-index: 1;
  width: 180px;
  min-height: 218px;
  border: 1px solid rgba(184, 167, 146, 0.45);
  border-radius: 24px;
  padding: 0.85rem;
  background: var(--surface-strong);
  box-shadow: 0 10px 24px rgba(45, 38, 31, 0.08);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.person-card:hover,
.person-card.active {
  border-color: var(--accent);
  box-shadow: 0 18px 34px rgba(45, 38, 31, 0.14);
  transform: translateY(-3px);
}

.person-card.active {
  background: #fff8ee;
}

.relation-badge {
  display: inline-block;
  margin-bottom: 0.55rem;
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.avatar,
.detail-photo {
  object-fit: cover;
  background: linear-gradient(145deg, #eadbc7, #cfb99f);
  color: var(--accent);
  font-weight: 750;
}

.avatar {
  display: grid;
  width: 82px;
  height: 82px;
  margin: 0 auto 0.7rem;
  border-radius: 50%;
  place-items: center;
  font-size: 1.35rem;
}

.person-name {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 1rem;
  font-weight: 750;
}

.person-card p {
  margin: 0.2rem 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.simple-tree .tree-level {
  padding: 0.35rem 0;
}

.simple-tree .tree-level + .tree-level {
  margin-top: 1.55rem;
}

.simple-tree .tree-level + .tree-level::before {
  top: -1.55rem;
  height: 1.9rem;
}

.simple-tree .connection-label,
.simple-tree .branch-label,
.simple-tree .co-parent-label,
.simple-tree .relation-badge,
.simple-tree .person-name,
.simple-tree .person-card p {
  display: none;
}

.simple-tree .generation,
.simple-tree .focus-side {
  gap: 0.75rem;
}

.simple-tree .family-units {
  gap: 1rem;
}

.simple-tree .family-unit .parent-pair {
  padding-inline: 0;
}

.simple-tree .family-connector {
  width: calc(100% - 38px);
  min-width: 34px;
  height: 22px;
  margin-top: 0.4rem;
  border-width: 1px;
  border-radius: 0 0 12px 12px;
}

.simple-tree .family-connector::after {
  bottom: -1.25rem;
  width: 1px;
  height: 1.25rem;
}

.simple-tree .ancestor-family-level + .ancestor-family-level,
.simple-tree .ancestor-family-level + .level-control,
.simple-tree .parent-family-level + .focus-level,
.simple-tree .family-descendants + .tree-level {
  margin-top: 1.65rem;
}

.simple-tree .child-set {
  margin-top: 1.35rem;
}

.simple-tree .generation-centered:has(.person-card + .person-card)::before {
  right: 38px;
  left: 38px;
}

.simple-tree .focus-generation {
  grid-template-columns: minmax(130px, 1fr) 76px minmax(130px, 1fr);
  gap: 0.75rem;
}

.simple-tree .focus-family-row {
  grid-template-columns: minmax(0, 1fr) minmax(76px, auto);
  gap: 0.85rem;
  width: min(100%, 360px);
}

.simple-tree .parent-child-bracket {
  width: min(72%, 150px);
  height: 22px;
  margin: -0.1rem auto 0.45rem;
  border-width: 1px;
}

.simple-tree .parent-child-bracket::before,
.simple-tree .parent-child-bracket::after {
  width: 1px;
}

.simple-tree .sibling-set {
  padding: 0;
}

.simple-tree .partner-set::before {
  left: -0.85rem;
  width: 0.85rem;
}

.simple-tree .focus-side-left:not(:empty)::after,
.simple-tree .focus-side-right:not(:empty)::before {
  width: 0.75rem;
}

.simple-tree .focus-side-left:not(:empty)::after {
  margin-right: -0.75rem;
}

.simple-tree .focus-side-right:not(:empty)::before {
  margin-left: -0.75rem;
}

.simple-tree {
  --ancestor-branch-w: 160px;
  --child-branch-w: 130px;
}

.simple-tree .ancestor-branches,
.simple-tree .child-branches {
  gap: 1rem;
}

.simple-tree .ancestor-branches {
  padding-bottom: 0.8rem;
}

.simple-tree .ancestor-branch {
  padding-bottom: 0.8rem;
}

.simple-tree .ancestor-branch::after {
  bottom: -0.8rem;
  height: 1.45rem;
}

.simple-tree .child-branches {
  padding-top: 0.8rem;
}

.simple-tree .child-branch {
  padding-top: 0.8rem;
}

.simple-tree .child-branch::before {
  top: -0.8rem;
  height: 1.45rem;
}

.simple-tree .person-card {
  display: grid;
  width: 76px;
  min-height: 76px;
  height: 76px;
  border-radius: 50%;
  padding: 0.35rem;
  place-items: center;
}

.simple-tree .person-card:hover,
.simple-tree .person-card.active {
  transform: translateY(-2px);
}

.simple-tree .avatar {
  width: 64px;
  height: 64px;
  margin: 0;
  font-size: 1rem;
}

.detail-header {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.detail-photo {
  display: grid;
  flex: 0 0 auto;
  width: 104px;
  height: 104px;
  border-radius: 28px;
  place-items: center;
  font-size: 1.7rem;
}

.detail-panel h2 {
  margin: 0;
}

.detail-subtitle,
.bio {
  color: var(--muted);
}

.detail-subtitle {
  margin: 0.25rem 0 0;
}

.bio {
  margin: 1.25rem 0;
  line-height: 1.55;
}

.bio p {
  margin: 0;
}

.bio p + p {
  margin-top: 0.6rem;
}

.detail-panel dl {
  display: grid;
  grid-template-columns: 106px minmax(0, 1fr);
  gap: 0.55rem 0.8rem;
  margin: 0;
}

.detail-panel dt {
  color: var(--muted);
}

.detail-panel dd {
  margin: 0;
}

.detail-gallery {
  margin-top: 1.5rem;
}

.detail-gallery h3 {
  margin-bottom: 0.65rem;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.gallery-item {
  display: flex;
  min-width: 0;
  min-height: 118px;
  margin: 0;
  border-radius: 16px;
  background: var(--surface-2);
  color: var(--muted);
  overflow: hidden;
  flex-direction: column;
}

.gallery-image,
.gallery-placeholder {
  width: 100%;
  aspect-ratio: 4 / 3;
}

.gallery-image {
  display: block;
  object-fit: cover;
}

.gallery-placeholder {
  display: grid;
  background: linear-gradient(145deg, #eadbc7, #cfb99f);
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: 750;
  place-items: center;
}

.gallery-item figcaption {
  display: grid;
  min-height: 54px;
  padding: 0.5rem;
  font-size: 0.72rem;
  gap: 0.15rem;
  align-content: center;
}

.gallery-item strong {
  color: var(--text);
}

.gallery-item small {
  display: block;
}

.gallery-item.image-error::before {
  display: grid;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: linear-gradient(145deg, #eadbc7, #cfb99f);
  color: var(--muted);
  content: "Bild nicht gefunden";
  font-size: 0.7rem;
  place-items: center;
}

.gallery-item.has-image {
  cursor: zoom-in;
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}

.gallery-item.has-image:hover {
  box-shadow: 0 8px 18px rgba(45, 38, 31, 0.18);
  transform: translateY(-2px);
}

.gallery-item.has-image:focus-visible {
  outline: 3px solid rgba(109, 90, 68, 0.35);
  outline-offset: 3px;
}

body.lightbox-open {
  overflow: hidden;
}

.image-lightbox {
  width: min(1100px, calc(100vw - 2rem));
  max-width: none;
  max-height: calc(100vh - 2rem);
  margin: auto;
  border: 0;
  border-radius: 24px;
  padding: 0;
  background: transparent;
  color: white;
  overflow: visible;
}

.image-lightbox::backdrop {
  background: rgba(28, 23, 18, 0.86);
  backdrop-filter: blur(8px);
}

.lightbox-content {
  display: grid;
  position: relative;
  max-height: calc(100vh - 2rem);
  border-radius: 24px;
  background: #1f1a16;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.lightbox-image {
  display: block;
  width: 100%;
  max-height: calc(100vh - 9rem);
  object-fit: contain;
}

.lightbox-caption {
  padding: 1rem 1.25rem 1.15rem;
}

.lightbox-caption h2,
.lightbox-caption p {
  margin: 0;
}

.lightbox-caption p {
  margin-top: 0.25rem;
  color: rgba(255, 255, 255, 0.68);
}

.lightbox-close {
  display: grid;
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  padding: 0;
  background: rgba(28, 23, 18, 0.72);
  color: white;
  cursor: pointer;
  font-size: 1.75rem;
  line-height: 1;
  place-items: center;
}

.lightbox-close:hover {
  background: rgba(28, 23, 18, 0.95);
}

.lightbox-close:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.55);
  outline-offset: 3px;
}

.loading-state,
.empty-state,
.error-state {
  color: var(--muted);
}

.loading-state,
.tree-empty,
.error-state {
  margin: 4rem auto;
  text-align: center;
}

.error-state strong {
  color: var(--text);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.search-wrapper {
  position: relative;
  flex-shrink: 0;
}

.search-input {
  width: 220px;
  border: 1px solid rgba(184, 167, 146, 0.45);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  background: var(--surface-strong);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.search-input::placeholder {
  color: var(--muted);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 90, 68, 0.15);
}

.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 100;
  width: max(100%, 260px);
  max-height: 280px;
  margin: 0;
  border: 1px solid rgba(184, 167, 146, 0.45);
  border-radius: 16px;
  padding: 0.4rem;
  background: var(--surface-strong);
  box-shadow: 0 12px 32px rgba(45, 38, 31, 0.15);
  list-style: none;
  overflow-y: auto;
}

.search-result-item button {
  display: flex;
  width: 100%;
  border: 0;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  gap: 0.6rem;
  align-items: baseline;
  text-align: left;
  transition: background 0.14s ease;
}

.search-result-item button:hover,
.search-result-item button:focus-visible {
  background: var(--accent-soft);
  outline: none;
}

.search-result-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 700;
}

.search-result-meta {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
    max-height: none;
    scroll-margin-top: 1rem;
  }

  .app-header,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .search-wrapper {
    width: 100%;
  }

  .search-input {
    width: 100%;
  }

  .search-results {
    right: auto;
    left: 0;
  }
}

@media (max-width: 600px) {
  .app-header {
    padding-top: 1.25rem;
  }

  .app-header button {
    width: 100%;
  }

  .layout {
    gap: 1rem;
  }

  .tree-section,
  .detail-panel {
    border-radius: 18px;
    padding: 1rem;
  }

  .toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .toolbar button {
    padding-inline: 0.65rem;
  }

  .tree-map {
    min-width: 680px;
  }

  .simple-tree {
    min-width: 520px;
  }

  .focus-generation {
    grid-template-columns: minmax(180px, 1fr) 158px minmax(180px, 1fr);
  }

  .focus-family-row {
    grid-template-columns: minmax(0, 1fr) minmax(158px, auto);
    gap: 1rem;
    width: min(100%, 660px);
  }

  .simple-tree .focus-generation {
    grid-template-columns: minmax(110px, 1fr) 76px minmax(110px, 1fr);
  }

  .simple-tree .focus-family-row {
    grid-template-columns: minmax(0, 1fr) minmax(76px, auto);
    width: min(100%, 340px);
  }

  .child-branches {
    gap: 1rem;
  }

  .ancestor-branches {
    gap: 1rem;
  }

  :root {
    --ancestor-branch-w: 330px;
    --child-branch-w: 250px;
  }

  .person-card {
    width: 158px;
  }

  .detail-header {
    align-items: flex-start;
  }

  .detail-photo {
    width: 82px;
    height: 82px;
    border-radius: 22px;
  }

  .detail-panel dl {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .detail-panel dd {
    margin-bottom: 0.55rem;
  }

  .image-lightbox {
    width: calc(100vw - 1rem);
    max-height: calc(100vh - 1rem);
  }

  .lightbox-content {
    max-height: calc(100vh - 1rem);
    border-radius: 18px;
  }

  .lightbox-image {
    max-height: calc(100vh - 8rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
