/* ========== Theme variables ========== */
:root {
  --bg: #ffffff;
  --bg-elevated: #f8f9fa;
  --text: #1a1a1a;
  --text-muted: #555;
  --border: #e1e1e1;
  --accent: #5b2c87;
  --accent-bg: #f5edfa;
  --infobox-bg: #f8f9fa;
  --infobox-border: #a2a9b1;
  --link: #0645ad;
  --link-visited: #6a3a8b;
}
[data-theme="dark"] {
  --bg: #1a1a1a;
  --bg-elevated: #242424;
  --text: #e5e5e5;
  --text-muted: #999;
  --border: #3a3a3a;
  --accent: #b083d4;
  --accent-bg: #2d1f3a;
  --infobox-bg: #242424;
  --infobox-border: #3a3a3a;
  --link: #6ab0f3;
  --link-visited: #b083d4;
}

/* ========== Reset ========== */
* { box-sizing: border-box; }
body, h1, h2, h3, h4, p, ul, ol, dl { margin: 0; padding: 0; }

/* ========== Layout ========== */
body {
  display: grid;
  grid-template-columns: 250px 1fr;
  grid-template-rows: 56px 1fr auto;
  grid-template-areas:
    "header header"
    "sidebar content"
    "footer footer";
  min-height: 100vh;
  font-family: 'Lora', Georgia, 'Times New Roman', serif;
  line-height: 1.7;
  background: var(--bg);
  color: var(--text);
}
.site-header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.site-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  text-decoration: none;
}
.search-box { flex: 1; position: relative; max-width: 500px; }
.search-box input {
  width: 100%;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font: inherit;
  background: var(--bg);
  color: var(--text);
}
.search-box ul {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  list-style: none;
  max-height: 400px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.search-box li { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.search-box li:hover, .search-box li[aria-selected="true"] { background: var(--accent-bg); }
.search-box li a { color: var(--text); text-decoration: none; display: block; }

.theme-toggle, .nav-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text);
}
.nav-toggle { display: none; }

.sidebar {
  grid-area: sidebar;
  padding: 1rem;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.section-list { list-style: none; }
.section-list li { padding: 0.4rem 0; }
.section-list a {
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
}
.section-list a:hover { color: var(--accent); }
.section-list a[aria-current="page"] {
  color: var(--accent);
  font-weight: 700;
}

.content {
  grid-area: content;
  padding: 1.5rem 2rem;
  max-width: 1100px;
}

.breadcrumbs ol {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.breadcrumbs li:not(:last-child)::after { content: "›"; margin-left: 0.5rem; color: var(--text-muted); }
.breadcrumbs a { color: var(--link); text-decoration: none; }
.breadcrumbs a:hover { text-decoration: underline; }

.site-footer {
  grid-area: footer;
  padding: 1rem 2rem;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ========== Typography ========== */
h1, h2, h3, h4 { font-family: 'Lora', Georgia, serif; line-height: 1.3; margin-bottom: 0.5em; }
h1 { font-size: 2rem; color: var(--accent); border-bottom: 2px solid var(--accent); padding-bottom: 0.3em; margin-bottom: 1em; }
h2 { font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.2em; margin-top: 1.5em; margin-bottom: 0.6em; }
h3 { font-size: 1.2rem; margin-top: 1.3em; margin-bottom: 0.4em; }
p { margin-bottom: 1em; }
a { color: var(--link); }
a:visited { color: var(--link-visited); }

/* Body lists (Places Lived, Vehicles Owned, etc.) */
.article-body ul, .article-body ol { margin: 0 0 1em 1.5em; padding: 0; }
.article-body li { margin-bottom: 0.4em; }
.article-body li > p:only-child { margin-bottom: 0; }  /* tighten single-paragraph items */
.article-body li > p { margin-bottom: 0.4em; }

/* ========== Article + infobox layout ========== */
.article {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 2rem;
  align-items: start;
}
.article-body { min-width: 0; }
.infobox {
  background: var(--infobox-bg);
  border: 1px solid var(--infobox-border);
  padding: 0.75rem;
  font-size: 0.875rem;
}
.infobox h3 {
  margin: -0.75rem -0.75rem 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  text-align: center;
}
.infobox-portrait {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 0 0.25rem;
  border-radius: 4px;
}
.infobox-caption {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.35;
  margin-bottom: 0.5rem;
  font-style: italic;
}
.infobox-caption div { margin: 0; }
.infobox-nav {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: center;
  font-size: 0.85rem;
}
.infobox-nav li { display: block; padding: 0.15rem 0; }
.infobox-nav a { color: var(--link); text-decoration: none; }
.infobox-nav a:hover { text-decoration: underline; }
.page-portrait {
  margin: 0 0 1em;
  text-align: center;
}
.page-portrait img {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.page-portrait figcaption {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 0.4em;
  line-height: 1.4;
}
.infobox dl { margin: 0; }
.infobox dt {
  font-weight: 700;
  margin-top: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.infobox dd { margin: 0; }

.family-tree-image { max-width: 100%; height: auto; margin: 1em 0; border: 1px solid var(--border); }

/* ========== Cards ========== */
.section-grid, .family-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin: 1.5em 0;
}
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  display: block;
  transition: transform 0.1s, box-shadow 0.1s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.card-image { aspect-ratio: 4/3; background: var(--accent-bg); }
.card-image img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 0.75rem; }
.card-title { font-weight: 700; font-size: 1rem; margin-bottom: 0.25rem; }
.card-meta { font-size: 0.85rem; color: var(--text-muted); }

/* ========== Photo gallery ========== */
.photo-gallery {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 1em 0;
}
.photo-gallery .thumb {
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
  background: var(--accent-bg);
}
.photo-gallery .thumb img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 0.2s;
}
.photo-gallery .thumb:hover img { transform: scale(1.05); }

/* ========== Audio item ========== */
.audio-item {
  margin: 1em 0;
  padding: 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.audio-item audio {
  width: 100%;
  margin-top: 0.5rem;
}

/* ========== Mobile ========== */
@media (max-width: 768px) {
  body { grid-template-columns: 1fr; grid-template-areas: "header" "content" "footer"; }
  .sidebar {
    position: fixed; top: 56px; left: -100%; bottom: 0;
    width: 280px; transition: left 0.2s; z-index: 200;
  }
  .sidebar[data-open="true"] { left: 0; }
  .nav-toggle { display: inline-block; }
  .article { grid-template-columns: 1fr; }
  .infobox { order: -1; }
  .photo-gallery { grid-template-columns: repeat(2, 1fr); }
}
