:root {
  color-scheme: light;
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-soft: #fbfaf7;
  --ink: #1c2420;
  --muted: #66716b;
  --line: #ded8cc;
  --accent: #2f6f64;
  --accent-dark: #16463f;
  --spouse: #19867a;
  --year: #8a5f22;
  --shadow: 0 18px 48px rgba(48, 39, 27, 0.09);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
summary:focus-visible,
.photo-link:focus-visible,
.notes:focus-visible {
  outline: 3px solid rgba(47, 111, 100, 0.3);
  outline-offset: 3px;
}

.hero {
  position: relative;
  min-height: clamp(280px, 44vh, 440px);
  display: flex;
  align-items: end;
  overflow: hidden;
  border-bottom: 1px solid rgba(28, 36, 32, 0.1);
}

.hero__bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(247, 245, 240, 0.96), rgba(247, 245, 240, 0.78) 46%, rgba(247, 245, 240, 0.52)),
    url("bg.jpg") center / cover;
  opacity: 0.82;
}

.hero__content {
  position: relative;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 72px 0 48px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  max-width: 780px;
  margin-bottom: 16px;
  font-size: clamp(2.7rem, 8vw, 6.2rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.hero__copy {
  max-width: 680px;
  margin-bottom: 0;
  color: #38443d;
  font-size: clamp(1rem, 2vw, 1.2rem);
}

main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.toolbar {
  display: flex;
  gap: 16px;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 16px;
}

.search {
  flex: 1;
  min-width: 0;
}

.search span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.search input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
}

.toolbar__actions {
  display: flex;
  gap: 8px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-bottom: 24px;
  color: var(--muted);
  font-size: 0.92rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.dot--direct {
  background: var(--accent-dark);
}

.dot--spouse {
  background: var(--spouse);
}

.dot--year {
  background: var(--year);
}

.tree-shell,
.notes-section {
  margin-top: 24px;
}

.section-heading {
  margin-bottom: 14px;
}

.section-heading h2 {
  margin-bottom: 0;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
}

.tree {
  padding: 8px 0 0;
}

.tree ul {
  position: relative;
  margin: 0;
  padding: 0 0 0 28px;
  list-style: none;
}

.tree li {
  position: relative;
  margin: 0 0 12px;
}

.tree li::before {
  content: "";
  position: absolute;
  top: 36px;
  left: -19px;
  width: 16px;
  border-top: 1px solid var(--line);
}

.tree li::after {
  content: "";
  position: absolute;
  top: -12px;
  bottom: 50%;
  left: -20px;
  border-left: 1px solid var(--line);
}

.tree > ul {
  padding-left: 0;
}

.tree > ul > li::before,
.tree > ul > li::after {
  display: none;
}

.person {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  max-width: 560px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 10px 12px;
}

.photo-link {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid rgba(28, 36, 32, 0.12);
  background: var(--surface-soft);
}

.photo-link img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.person__body {
  min-width: 0;
  flex: 1;
}

.person__name {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
  margin: 0;
  font-weight: 800;
}

.person--spouse .person__name {
  color: var(--spouse);
  font-style: italic;
}

.death-year {
  color: var(--year);
  font-size: 0.88rem;
  font-weight: 700;
}

.person__place {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

details {
  max-width: 100%;
}

summary {
  display: block;
  cursor: pointer;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

.node-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--accent-dark);
  border: 1px solid var(--line);
  font-size: 0.88rem;
  font-weight: 800;
}

details[open] .node-toggle {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.children {
  margin-top: 12px;
}

.notes {
  min-height: 180px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px 24px;
}

.notes-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.notes[contenteditable="false"] {
  background: var(--surface-soft);
}

.notes li + li {
  margin-top: 8px;
}

.is-hidden {
  display: none;
}

.is-match .person {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(47, 111, 100, 0.12), var(--shadow);
}

@media (max-width: 760px) {
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar__actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .person {
    max-width: none;
  }

  .tree ul {
    padding-left: 20px;
  }

  .tree li::before {
    left: -13px;
    width: 10px;
  }

  .tree li::after {
    left: -14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
