:root {
  --bg: #FAF7F0;
  --card-bg: #FFFFFF;
  --text: #211E19;
  --muted: #6B6558;
  --border: #E8E2D4;
  --accent: #16532E;
  --accent-dark: #0E3A20;
  --red: #B3272B;
  --line: #CFC7B2;
}

[data-theme="dark"] {
  --bg: #141310;
  --card-bg: #1D1A14;
  --text: #F3EFE6;
  --muted: #B8B0A0;
  --border: #3A362C;
  --line: #4A4636;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Work Sans', sans-serif;
  transition: background 0.2s ease, color 0.2s ease;
}

a { color: var(--accent); }
a:hover { color: var(--accent-dark); }

/* Header */
.site-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 40px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FAF7F0;
  font-family: 'Fraunces', serif;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}

.brand-name {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 1.5px;
  color: var(--text);
}

.toggle-btn {
  font-family: 'Work Sans', sans-serif;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}
.toggle-btn:hover { border-color: var(--accent); }

/* Hero */
.hero {
  width: 100%;
  padding: 64px 24px 48px;
  text-align: center;
}

.eyebrow {
  font-size: 13px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--red);
  margin-bottom: 16px;
}

.hero h1 {
  margin: 0 0 20px;
  font-family: 'Fraunces', serif;
  font-size: clamp(32px, 6vw, 52px);
  font-weight: 600;
  color: var(--text);
  text-wrap: balance;
}

.hero p {
  max-width: 620px;
  margin: 0 auto;
  font-size: 16.5px;
  line-height: 1.6;
  color: var(--muted);
}

.hero-divider {
  width: 110px;
  height: 3px;
  background: var(--accent);
  margin: 32px auto 0;
  position: relative;
}
.hero-divider span {
  position: absolute;
  top: -3px;
  left: 50%;
  transform: translateX(-50%);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red);
}

/* Toolbar */
.toolbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 0 24px 32px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill-btn {
  font-family: 'Work Sans', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  white-space: nowrap;
}
.pill-btn:hover { border-color: var(--accent); color: var(--accent); }
.pill-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.pill-btn:disabled:hover { border-color: var(--border); color: var(--text); }

.icon-btn {
  padding: 9px 14px;
  font-size: 16px;
  line-height: 1;
}

/* Tree wrapper: scrollable in both directions so long/wide trees stay reachable */
.tree-wrapper {
  width: 100%;
  overflow: auto;
  padding: 0 24px 100px;
  -webkit-overflow-scrolling: touch;
  cursor: grab;
}
.tree-wrapper.dragging { cursor: grabbing; user-select: none; }

.tree {
  position: relative;
  display: inline-flex;
  justify-content: center;
  min-width: 100%;
  transform-origin: top center;
}

/* Generation guide lines: purely visual grouping, no labels */
.generation-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.gen-line {
  position: absolute;
  height: 2px;
  background: var(--line);
  opacity: 0.6;
  border-radius: 2px;
}

.tree > ul {
  position: relative;
  z-index: 1;
}

.couple {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 20px;
  white-space: nowrap;
}
.couple:hover { border-color: var(--accent); }

.couple-sm { padding: 10px 16px; }
.couple-md { padding: 10px 16px; }

.amp {
  font-family: 'Fraunces', serif;
  font-size: 14px;
  color: var(--red);
}
.amp-with {
  font-family: 'Work Sans', sans-serif;
  font-size: 11px;
  font-style: italic;
  color: var(--muted);
}

.person-name {
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
}

.solo-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  white-space: nowrap;
}
.solo-card:hover { border-color: var(--accent); }

.root-card { padding: 16px 26px; }

.solo-card-md { padding: 10px 16px; }

.solo-card-sm { padding: 9px 14px; }

.card-meta {
  font-family: 'Work Sans', sans-serif;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 3px;
}

/* Node = card + collapse toggle button */
.node {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.toggle {
  position: absolute;
  right: -10px;
  top: -10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--accent);
  color: #FAF7F0;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 2;
}
.toggle:hover { background: var(--accent-dark); }

/* Tree connector lines */
.tree ul {
  padding-top: 28px;
  position: relative;
  display: flex;
  justify-content: center;
  margin: 0;
}
.tree li {
  list-style-type: none;
  position: relative;
  padding: 28px 14px 0 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tree li::before, .tree li::after {
  content: '';
  position: absolute;
  top: 0;
  right: 50%;
  border-top: 2px solid var(--line);
  width: 50%;
  height: 28px;
}
.tree li::after {
  right: auto;
  left: 50%;
  border-left: 2px solid var(--line);
}
.tree li:only-child::after, .tree li:only-child::before { display: none; }
.tree li:only-child { padding-top: 0; }
.tree li:first-child::before, .tree li:last-child::after { border: 0 none; }
.tree li:last-child::before { border-right: 2px solid var(--line); border-radius: 0 6px 0 0; }
.tree li:first-child::after { border-radius: 6px 0 0 0; }
.tree > ul > li { padding-top: 0; }
.tree > ul > li::before, .tree > ul > li::after { display: none; }
.tree ul ul::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  border-left: 2px solid var(--line);
  width: 0;
  height: 28px;
}

/* Collapsed branches: hide descendants, keep the node visible */
.tree li.collapsed > ul { display: none; }
.tree li.collapsed > .node .toggle { background: var(--red); }

/* Footer */
.site-footer {
  width: 100%;
  padding: 32px 24px;
  border-top: 1px solid var(--border);
}

/* Responsive tweaks */
@media (max-width: 720px) {
  .site-header { padding: 16px 20px; }
  .brand-name { font-size: 15px; letter-spacing: 1px; }
  .hero { padding: 48px 16px 36px; }
  .hero p { font-size: 15px; }
  .toolbar { gap: 12px; padding: 0 16px 24px; }
  .tree-wrapper { padding: 0 12px 72px; }
  .person-name { font-size: 14px; }
  .root-card .person-name { font-size: 16px; }
  .couple, .solo-card { padding: 10px 14px; }
}

@media (max-width: 420px) {
  .toolbar { justify-content: flex-start; }
  .toolbar-group { justify-content: center; width: 100%; }
}
