:root {
  --background: #f7f4ee;
  --foreground: #1d2623;
  --panel: #fffdf8;
  --panel-strong: #f0eadf;
  --line: #d7ccb9;
  --ink-soft: #5d665f;
  --accent: #28666e;
  --accent-strong: #153f46;
  --leaf: #527853;
  --clay: #9a4f35;
  --gold: #b27b26;
  --shadow: 0 22px 60px rgba(49, 42, 31, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--background);
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.92), rgba(247, 244, 238, 0.96)),
    radial-gradient(circle at 16% 8%, rgba(178, 123, 38, 0.14), transparent 28rem);
  color: var(--foreground);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  padding: 24px;
}

.topbar {
  align-items: end;
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 620px);
  margin: 0 auto 18px;
  max-width: 1600px;
}

.eyebrow {
  color: var(--clay);
  font-size: 0.75rem;
  font-weight: 800;
  margin: 0 0 8px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  color: var(--accent-strong);
  font-size: clamp(2.2rem, 5vw, 5.4rem);
  line-height: 0.95;
  margin-bottom: 14px;
}

h2 {
  font-size: 1.25rem;
  line-height: 1.2;
  margin-bottom: 4px;
}

h3 {
  color: var(--accent-strong);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.intro {
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1.6;
  max-width: 760px;
}

.statsGrid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.statsGrid div {
  background: rgba(255, 253, 248, 0.82);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.statsGrid strong {
  color: var(--accent-strong);
  display: block;
  font-size: clamp(1rem, 2vw, 1.45rem);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.statsGrid span,
.panelHeader span,
.personMeta,
.familyUnit small,
.timeline small,
.placeCloud small,
.emptyPerson small {
  color: var(--ink-soft);
  font-size: 0.78rem;
}

.toolbar,
.workspace {
  margin: 0 auto;
  max-width: 1600px;
}

.toolbar {
  align-items: end;
  background: rgba(255, 253, 248, 0.8);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(260px, 1fr) minmax(190px, 260px) auto;
  margin-bottom: 14px;
  padding: 12px;
}

.searchBox,
.branchSelect {
  display: grid;
  gap: 6px;
}

.searchBox span,
.branchSelect span {
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 700;
}

.searchBox input,
.branchSelect select {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--foreground);
  min-height: 44px;
  outline: none;
  padding: 0 12px;
  width: 100%;
}

.searchBox input:focus,
.branchSelect select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(40, 102, 110, 0.16);
}

.segmented {
  align-items: center;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  min-height: 44px;
  padding: 3px;
}

.segmented button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--ink-soft);
  font-weight: 800;
  min-height: 36px;
  padding: 0 12px;
}

.segmented button[aria-selected="true"] {
  background: var(--accent);
  color: #ffffff;
}

.workspace {
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(240px, 310px) minmax(0, 1fr) minmax(300px, 400px);
}

.loadingShell {
  display: grid;
  align-content: center;
}

.loadingPanel {
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 8px;
  margin: 0 auto;
  max-width: 720px;
  padding: 22px;
}

.loadingPanel strong {
  color: var(--accent-strong);
  font-size: 1.2rem;
}

.loadingPanel span {
  color: var(--ink-soft);
  line-height: 1.5;
}

.peoplePanel,
.visualPanel,
.detailsPanel {
  background: rgba(255, 253, 248, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.peoplePanel,
.detailsPanel {
  max-height: calc(100vh - 210px);
  overflow: auto;
  padding: 14px;
  position: sticky;
  top: 14px;
}

.visualPanel {
  min-height: 620px;
  overflow: hidden;
}

.panelHeader,
.selectedHeader {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.panelHeader {
  margin-bottom: 12px;
}

.peopleList {
  display: grid;
  gap: 8px;
}

.personButton,
.emptyPerson {
  align-items: start;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--foreground);
  display: grid;
  gap: 4px;
  min-height: 64px;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.personButton:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.personButton.active {
  background: #e7f1ef;
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
}

.personButton.compact,
.emptyPerson {
  min-height: 74px;
}

.personName {
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.selectedHeader {
  background:
    linear-gradient(135deg, rgba(40, 102, 110, 0.12), rgba(82, 120, 83, 0.1)),
    var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 18px;
}

.selectedHeader h2 {
  color: var(--accent-strong);
  font-size: clamp(1.45rem, 3vw, 2.25rem);
  overflow-wrap: anywhere;
}

.selectedHeader p {
  color: var(--ink-soft);
  margin-bottom: 0;
}

.quickFacts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  max-width: 360px;
}

.quickFacts span,
.referenceGrid span {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  padding: 7px 10px;
}

.treeCanvas,
.descendantCanvas,
.placeCloud {
  padding: 18px;
}

.generationRow {
  display: grid;
  gap: 10px;
  grid-template-columns: 140px minmax(0, 1fr);
  padding: 10px 0;
  position: relative;
}

.generationRow + .generationRow {
  border-top: 1px dashed var(--line);
}

.generationLabel {
  color: var(--clay);
  font-size: 0.78rem;
  font-weight: 900;
  padding-top: 10px;
  text-transform: uppercase;
}

.generationPeople {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
}

.emptyPerson {
  background: rgba(240, 234, 223, 0.5);
  color: var(--ink-soft);
}

.descendantCanvas {
  display: grid;
  gap: 18px;
}

.descendantRow > div {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}

.quietState {
  color: var(--ink-soft);
  line-height: 1.5;
}

.placeCloud {
  align-content: start;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}

.placeCloud button {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--accent-strong);
  display: grid;
  gap: 5px;
  min-height: 86px;
  padding: 12px;
  text-align: left;
}

.placeCloud button span {
  font-size: calc(0.9rem * var(--weight));
  font-weight: 850;
  line-height: 1.1;
}

.detailBlock {
  border-top: 1px solid var(--line);
  padding: 14px 0;
}

.detailBlock:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.familyList {
  display: grid;
  gap: 10px;
  margin: 0;
}

.familyList div {
  display: grid;
  gap: 4px;
}

.familyList dt {
  color: var(--ink-soft);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.familyList dd {
  margin: 0;
}

.familyList button,
.familyUnit button {
  background: transparent;
  border: 0;
  color: var(--accent);
  font-weight: 800;
  padding: 0;
  text-align: left;
}

.familyEvent,
.mediaTitles {
  color: var(--ink-soft);
  font-size: 0.86rem;
  line-height: 1.45;
  margin: 12px 0 0;
}

.familyUnit {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
  padding: 12px;
}

.familyUnit p {
  font-weight: 850;
  margin-bottom: 0;
}

.familyUnit div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.timeline {
  display: grid;
  gap: 10px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.timeline li {
  border-left: 3px solid var(--gold);
  display: grid;
  gap: 4px;
  padding-left: 10px;
}

.timeline strong {
  color: var(--accent-strong);
}

.timeline span {
  color: var(--foreground);
  font-size: 0.9rem;
  line-height: 1.4;
}

.referenceGrid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 1180px) {
  .topbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .peoplePanel,
  .detailsPanel {
    max-height: none;
    position: static;
  }

  .peopleList {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    max-height: 360px;
    overflow: auto;
  }
}

@media (max-width: 760px) {
  .shell {
    padding: 12px;
  }

  .topbar,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .statsGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .segmented {
    overflow-x: auto;
  }

  .segmented button {
    flex: 1 0 auto;
  }

  .selectedHeader,
  .panelHeader {
    display: grid;
  }

  .quickFacts {
    justify-content: flex-start;
  }

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

  .generationPeople {
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  }
}
