:root {
  --bg: #faf8f4;
  --ink: #2b2620;
  --muted: #766f63;
  --line: #d8d0c2;
  --accent: #7a5c3e;
  --accent-soft: #efe6d8;
  --panel-bg: #fffdf9;
  --shadow: rgba(43, 38, 32, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Iowan Old Style", "Georgia", "Times New Roman", serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

header {
  position: relative;
  padding: 2rem 1.5rem 1rem;
  text-align: center;
  border-bottom: 1px solid var(--line);
}

.lang-switch {
  position: absolute;
  top: 1rem;
  right: 1.25rem;
  display: flex;
  gap: 0.3rem;
}

.lang-switch button {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  cursor: pointer;
}

.lang-switch button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.lang-switch button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.4rem, 3vw, 2rem);
  letter-spacing: 0.03em;
}

header .subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  font-style: italic;
}

.search-wrap {
  position: relative;
  max-width: 320px;
  margin: 1.25rem auto 0;
}

#search-input {
  width: 100%;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-bg);
  color: var(--ink);
}

#search-input:focus {
  outline: none;
  border-color: var(--accent);
}

#search-results {
  display: none;
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 20px var(--shadow);
  z-index: 20;
  text-align: left;
}

#search-results.visible {
  display: block;
}

.search-result {
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}

.search-result:last-child {
  border-bottom: none;
}

.search-result:hover,
.search-result:focus {
  background: var(--accent-soft);
  outline: none;
}

@keyframes search-flash {
  0%, 100% { background: transparent; }
  25%, 75% { background: var(--accent-soft); }
}

.search-hit {
  animation: search-flash 2.2s ease;
  border-radius: 8px;
}

.toolbar {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.toolbar button {
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  color: var(--accent);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
}

.toolbar button:hover {
  background: var(--accent);
  color: #fff;
}

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

ul.tree {
  list-style: none;
  margin: 0;
  padding-left: 1.4rem;
}

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

ul.tree ul.tree {
  border-left: 1px solid var(--line);
  margin-top: 0.3rem;
}

ul.tree li {
  position: relative;
  padding: 0.15rem 0 0.15rem 1rem;
}

ul.tree ul.tree li::before {
  content: "";
  position: absolute;
  top: 1rem;
  left: -1px;
  width: 1rem;
  height: 1px;
  background: var(--line);
}

details.person {
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
}

details.person > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
}

details.person > summary::-webkit-details-marker {
  display: none;
}

details.person > summary::before {
  content: "▸";
  color: var(--muted);
  display: inline-block;
  transition: transform 0.15s ease;
  width: 0.8em;
}

details.person[open] > summary::before {
  transform: rotate(90deg);
}

.person-name {
  font-weight: 600;
  cursor: pointer;
  border-bottom: 1px dotted transparent;
}

.person-name:hover,
.person-name:focus {
  color: var(--accent);
  border-bottom-color: var(--accent);
  outline: none;
}

.spouse-name {
  font-weight: 500;
}

.dates {
  color: var(--muted);
  font-size: 0.88rem;
}

.marriage {
  margin: 0.15rem 0 0.15rem 1.3rem;
  color: var(--ink);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.3rem;
  font-size: 0.95rem;
}

.marriage .sep {
  color: var(--muted);
}

.marriage-info {
  color: var(--muted);
  font-size: 0.88rem;
}

.siblings-wrap {
  margin: 0.3rem 0 0.2rem 1.3rem;
}

.siblings-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

ul.siblings-tree {
  border-left: 1px dashed var(--line);
}

.meta,
.note {
  margin: 0.1rem 0 0.1rem 1.3rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}

.source-badge,
.history-badge,
.video-badge {
  margin: 0.2rem 0.4rem 0.2rem 1.3rem;
  display: inline-block;
  font-size: 0.78rem;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
}

/* Detail panel */
#detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 32, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 10;
}

#detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(380px, 90vw);
  background: var(--panel-bg);
  box-shadow: -8px 0 24px var(--shadow);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 11;
  overflow-y: auto;
  padding: 1.5rem;
}

#detail-panel.visible {
  transform: translateX(0);
}

#detail-panel.visible ~ #detail-overlay {
  opacity: 1;
  pointer-events: auto;
}

#detail-close {
  float: right;
  background: none;
  border: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

#detail-body h2 {
  margin: 0 0 1rem;
  font-size: 1.3rem;
  clear: both;
}

#detail-body p {
  margin: 0.4rem 0;
  font-size: 0.95rem;
}

#detail-body .note {
  margin-left: 0;
  font-size: 0.88rem;
}

.history-heading {
  margin-top: 1rem !important;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}

.history-text {
  font-size: 0.9rem;
  line-height: 1.6;
}

.videos-heading {
  margin-top: 1rem !important;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}

.detail-video {
  width: 100%;
  border-radius: 6px;
  background: #000;
  margin-top: 0.4rem;
}

.video-caption {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0.2rem 0 0.8rem;
}

.sources-heading {
  margin-top: 1rem !important;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
}

.sources-list {
  padding-left: 1.2rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.sources-list li {
  margin-bottom: 0.4rem;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 1.5rem;
}
