:root {
  --cream: #faf6ec;
  --cream-2: #f3ecd9;
  --paper: #fffbf1;
  --ink: #2a2418;
  --ink-soft: #5a4f3a;
  --muted: #8a7e62;
  --gold: #b08d3a;
  --gold-soft: #d9b860;
  --rose: #b85d6b;
  --line: #d6cdb3;
  --male: #7d92b8;
  --female: #c08aa3;
  --unknown: #aaa089;
  --focus: #b08d3a;
  --shadow: 0 1px 2px rgba(60, 48, 20, 0.06), 0 8px 24px rgba(60, 48, 20, 0.08);
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--cream);
  background-image:
    radial-gradient(1100px 600px at 20% -10%, #fff7df 0, transparent 60%),
    radial-gradient(900px 700px at 100% 100%, #f1e8c8 0, transparent 60%);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 251, 241, 0.85);
  backdrop-filter: blur(8px);
  position: relative; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 28px; height: 28px; color: var(--gold); flex-shrink: 0; }
.brand-text { min-width: 0; }
.brand-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 22px;
  letter-spacing: 0.01em;
  color: var(--ink);
  line-height: 1;
}
.brand-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Search */
.search-wrap { position: relative; }
#search {
  width: 240px;
  padding: 8px 12px;
  font-family: var(--sans);
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  outline: none;
  transition: border 0.15s, box-shadow 0.15s;
}
#search:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(176, 141, 58, 0.15); }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
  max-height: 320px; overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 100;
}
.search-results .item {
  padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.search-results .item:last-child { border-bottom: none; }
.search-results .item:hover { background: var(--cream-2); }
.search-results .item .meta { color: var(--muted); font-size: 11px; margin-top: 2px; }
.search-results .empty { padding: 12px; color: var(--muted); font-style: italic; }

.btn {
  font-family: var(--sans);
  font-size: 13px; font-weight: 500;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { border-color: var(--gold); color: var(--gold); }
.btn.ghost { background: transparent; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 1fr 360px;
  height: calc(100vh - 61px);
  position: relative;
}

.tree-wrap {
  position: relative;
  overflow: hidden;
  background: var(--cream);
  background-image:
    linear-gradient(to right, rgba(176,141,58,0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(176,141,58,0.05) 1px, transparent 1px);
  background-size: 48px 48px;
}

#tree { width: 100%; height: 100%; cursor: grab; }
#tree:active { cursor: grabbing; }
#tree[hidden] { display: none !important; }

.legend {
  position: absolute; bottom: 16px; left: 16px;
  display: flex; gap: 14px;
  background: rgba(255, 251, 241, 0.92);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px;
  font-size: 11px; color: var(--ink-soft);
  z-index: 10;
  pointer-events: none; /* never block clicks on cards underneath */
}
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.dot.male { background: var(--male); }
.dot.female { background: var(--female); }
.dot.unknown { background: var(--unknown); }
.dot.focus-dot { background: var(--focus); }

.zoom-controls {
  position: absolute; bottom: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 10;
}
.zoom-controls button {
  width: 32px; height: 32px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  color: var(--ink-soft);
  transition: all 0.15s;
}
.zoom-controls button:hover { border-color: var(--gold); color: var(--gold); }

/* Tree nodes - Ancestry-style compact portrait cards */
.node { cursor: pointer; }
.node rect {
  fill: var(--paper);
  stroke: var(--line);
  stroke-width: 1.5;
  transition: stroke 0.15s, stroke-width 0.15s, filter 0.15s;
  filter: drop-shadow(0 1px 2.5px rgba(60, 48, 20, 0.1));
}
.node:hover rect { stroke: var(--gold); stroke-width: 2; filter: drop-shadow(0 2px 5px rgba(60, 48, 20, 0.18)); }
.node .accent { stroke-width: 0; }
.node.male .accent { fill: var(--male); }
.node.female .accent { fill: var(--female); }
.node.unknown .accent { fill: var(--unknown); }
.node.focus rect { stroke: var(--gold); stroke-width: 2.5; fill: #fffaeb; }
.node.focus .accent { fill: var(--gold); }
.node text { font-family: var(--sans); fill: var(--ink); }
.node .name { font-size: 11px; font-weight: 600; letter-spacing: 0.2px; }
.node .dates { font-size: 10px; fill: var(--muted); }

/* Photo + silhouette area */
.node .photo-bg { fill: #e8e1d2; }
.node.male .photo-bg { fill: #d6e4f0; }
.node.female .photo-bg { fill: #f0dce0; }
.node.unknown .photo-bg { fill: #e8e1d2; }
.node .photo-ring { stroke: rgba(60, 48, 20, 0.15); stroke-width: 1; }
.node.focus .photo-ring { stroke: var(--gold); stroke-width: 2; }
.node .silhouette circle { fill: rgba(255, 255, 255, 0.85); }
.node .silhouette path { fill: rgba(255, 255, 255, 0.85); }
.node.male .silhouette circle, .node.male .silhouette path { fill: #6b8aa7; }
.node.female .silhouette circle, .node.female .silhouette path { fill: #a87a85; }
.node.unknown .silhouette circle, .node.unknown .silhouette path { fill: #98917f; }

/* Sibling chip (replaces inline sibling cards) */
.sibling-chip rect {
  fill: #fffaf0;
  stroke: var(--gold-soft);
  stroke-width: 1.2;
}
.sibling-chip text {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  fill: var(--ink);
}
.sibling-chip:hover rect {
  fill: var(--gold-soft);
}

/* Aunt/uncle chips (Pass 5): smaller variant beside parent cards */
.aunt-uncle-chip rect {
  fill: #fffaf0;
  stroke: var(--gold-soft);
  stroke-width: 1.1;
  stroke-dasharray: 3 2;
}
.aunt-uncle-chip text {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  fill: var(--ink-soft);
}
.aunt-uncle-chip:hover rect {
  fill: var(--gold-soft);
  stroke-dasharray: none;
}
.aunt-uncle-chip:hover text {
  fill: var(--ink);
}

/* Expand caret above ancestor cards */
.expand-caret circle {
  fill: #fffaf0;
  stroke: var(--gold);
  stroke-width: 1.5;
}
.expand-caret text {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 700;
  fill: var(--gold);
}
.expand-caret:hover circle {
  fill: var(--gold);
}
.expand-caret:hover text {
  fill: #fffaf0;
}

.link {
  fill: none;
  stroke: var(--line);
  stroke-width: 1.5;
}
.link.spouse {
  stroke: var(--gold-soft);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}
.link.sibling-bar {
  stroke: var(--line);
  stroke-width: 1.25;
}
.link.sibling-drop {
  stroke: var(--line);
  stroke-width: 1.25;
}

/* View tabs (Tree / Map) */
.view-tabs {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0;
  background: rgba(255, 251, 241, 0.94);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  z-index: 12;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.view-tab {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.02em;
}
.view-tab:hover { color: var(--gold); }
.view-tab.active {
  background: var(--gold);
  color: #fff;
}

/* Map view */
.map-view {
  position: absolute;
  inset: 0;
  z-index: 5;
  background: var(--cream);
}
.map-view .leaflet-container {
  background: #f4ecd6;
  font-family: var(--sans);
  width: 100%;
  height: 100%;
}
.map-pin {
  background: var(--gold);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(60, 48, 20, 0.35);
  width: 14px;
  height: 14px;
  cursor: pointer;
}
.map-pin.focus { background: var(--rose); width: 18px; height: 18px; }
.map-popup {
  font-family: var(--sans);
  font-size: 12px;
  min-width: 160px;
}
.map-popup .ev-place {
  font-weight: 600;
  font-size: 13px;
  color: var(--ink);
  margin-bottom: 6px;
  font-family: var(--serif);
}
.map-popup .ev-item {
  font-size: 11.5px;
  padding: 3px 0;
  border-top: 1px solid var(--line);
}
.map-popup .ev-item:first-of-type { border-top: none; }
.map-popup a.person-link {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px dotted var(--gold);
  cursor: pointer;
  font-weight: 500;
}
.map-popup a.person-link:hover { color: var(--gold); }
.map-popup .ev-tag {
  display: inline-block;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-left: 4px;
}

/* Leaf hint badge (Pass 3) */
.leaf-badge { cursor: help; }
.leaf-badge circle { fill: #4f9b46; stroke: #fff; stroke-width: 1.5; }
.leaf-badge path { fill: #fff; }
.leaf-badge:hover circle { fill: #3d7a36; }

/* Smooth focus transitions (Pass 2) — applied via d3 transitions on the nodes/links */
.node { transition: opacity 0.25s; }

/* ====== Pass 4 — Search thumbnails, hints counter, recent rail, photos view ====== */

/* Hints counter button in top bar */
#btn-hints {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
#btn-hints .leaf-icon {
  display: inline-block;
  width: 16px; height: 16px;
  background: #4f9b46;
  color: #fff;
  border-radius: 50%;
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  font-weight: 700;
}
#btn-hints #hints-count { font-weight: 600; color: var(--ink); }
#btn-hints:hover { border-color: #4f9b46; color: #4f9b46; }

/* Search results thumbnails */
.search-results .item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}
.search-results .item .thumb {
  width: 36px; height: 36px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: #e8e1d2;
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
}
.search-results .item .thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.search-results .item .thumb.male { background: #d6e4f0; }
.search-results .item .thumb.female { background: #f0dce0; }
.search-results .item .thumb.unknown { background: #e8e1d2; }
.search-results .item .thumb-icon {
  width: 18px; height: 18px;
  background: rgba(255,255,255,0.7);
  border-radius: 50%;
}
.search-results .item .body { min-width: 0; flex: 1; }
.search-results .item .nm { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-results .item .meta { color: var(--muted); font-size: 11px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-results .item .has-photo-dot {
  flex-shrink: 0;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #d97706;
  margin-left: 6px;
  box-shadow: 0 0 0 2px rgba(217,119,6,0.18);
}

/* Recently viewed people rail (under the view tabs) */
.recent-rail {
  position: absolute;
  top: 50px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 251, 241, 0.94);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px 4px 12px;
  z-index: 11;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 40px);
  backdrop-filter: blur(8px);
}
.recent-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  flex-shrink: 0;
}
.recent-list {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.recent-list::-webkit-scrollbar { display: none; }
.recent-item {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px 3px 3px;
  font-size: 11.5px;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s;
  max-width: 180px;
}
.recent-item:hover { border-color: var(--gold); color: var(--gold); }
.recent-item.active { border-color: var(--gold); background: #fffaeb; color: var(--gold); font-weight: 600; }
.recent-item .thumb {
  width: 22px; height: 22px;
  border-radius: 50%;
  overflow: hidden;
  background: #e8e1d2;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.recent-item .thumb.male { background: #d6e4f0; }
.recent-item .thumb.female { background: #f0dce0; }
.recent-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.recent-item .thumb-icon { width: 10px; height: 10px; background: rgba(255,255,255,0.85); border-radius: 50%; }
.recent-item .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }

/* Photos-only view */
.photos-view {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow-y: auto;
  background: var(--cream);
  padding: 80px 24px 32px;
}
.photos-view-header {
  max-width: 1080px;
  margin: 0 auto 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.photos-view-header h2 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--ink);
}
.photos-view-sub { font-size: 12px; color: var(--muted); }
.photos-grid {
  max-width: 1080px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
}
.photo-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--paper);
  cursor: pointer;
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
  box-shadow: var(--shadow);
}
.photo-tile:hover { transform: translateY(-3px); border-color: var(--gold); box-shadow: 0 6px 18px rgba(60, 48, 20, 0.18); }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile .photo-tile-caption {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: linear-gradient(to top, rgba(42, 36, 24, 0.85), transparent);
  color: #fff;
  padding: 14px 10px 8px;
  font-size: 11.5px;
  font-weight: 500;
  font-family: var(--sans);
  letter-spacing: 0.02em;
}
.photo-tile .photo-tile-caption .yr { color: rgba(255,255,255,0.78); font-size: 10.5px; margin-left: 4px; }

/* Videos-only view */
.videos-view {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow-y: auto;
  background: var(--cream);
  padding: 80px 24px 32px;
}
.videos-view-header {
  max-width: 1080px;
  margin: 0 auto 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.videos-view-header h2 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--ink);
}
.videos-view-sub { font-size: 12px; color: var(--muted); }
.videos-grid {
  max-width: 1080px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.video-tile {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--paper);
  cursor: pointer;
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.video-tile:hover { transform: translateY(-3px); border-color: var(--gold); box-shadow: 0 6px 18px rgba(60, 48, 20, 0.18); }
.video-tile-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #1a140d;
  overflow: hidden;
}
.video-tile-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-tile-thumb.no-img { background: linear-gradient(135deg, #2a2418, #4a3a22); }
.video-play-overlay {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 52px; height: 52px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  padding-left: 4px;
  transition: background 0.18s, transform 0.18s;
  pointer-events: none;
}
.video-tile:hover .video-play-overlay {
  background: var(--gold, #b8893c);
  transform: translate(-50%, -50%) scale(1.08);
}
.video-duration {
  position: absolute;
  right: 8px; bottom: 8px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--sans);
}
.video-tile-caption {
  padding: 10px 12px 12px;
  font-family: var(--sans);
}
.video-tile-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 4px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-tile-meta {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Video playback modal */
.video-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-modal[hidden] { display: none; }
.video-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 14, 6, 0.88);
  backdrop-filter: blur(2px);
}
.video-modal-content {
  position: relative;
  background: var(--paper);
  border-radius: 12px;
  overflow: hidden;
  max-width: min(960px, 94vw);
  width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  border: 1px solid var(--line);
}
.video-modal-close {
  position: absolute;
  top: 8px; right: 12px;
  z-index: 2;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.video-modal-close:hover { background: rgba(0,0,0,0.85); }
.video-modal-player {
  width: 100%;
  max-height: 70vh;
  background: #000;
  display: block;
}
.video-modal-info {
  padding: 16px 20px 18px;
  font-family: var(--sans);
  border-top: 1px solid var(--line);
}
.video-modal-title {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  margin: 0 0 6px;
}
.video-modal-meta {
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 10px;
}
.video-modal-people {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.video-modal-person {
  display: inline-block;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  background: var(--cream);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px 10px;
  cursor: default;
}
button.video-modal-person {
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
button.video-modal-person:hover {
  background: var(--gold, #b8893c);
  border-color: var(--gold, #b8893c);
  color: #fff;
}

/* Side panel */
.panel {
  border-left: 1px solid var(--line);
  background: var(--paper);
  overflow-y: auto;
  padding: 24px;
}
.panel-handle { display: none; }
.panel-empty {
  font-family: var(--serif);
  font-size: 18px; color: var(--muted);
  font-style: italic;
  text-align: center;
  padding-top: 80px;
}

.person-card h2 {
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  line-height: 1.15;
  margin: 0 0 4px;
  color: var(--ink);
}
.person-card .sub {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 18px;
}
.person-card .sub code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 11px;
  background: var(--cream-2);
  padding: 1px 5px;
  border-radius: 3px;
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 4px;
}
.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  background: var(--cream-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
}
.link-btn:hover {
  background: var(--paper);
  border-color: var(--gold);
  color: var(--gold);
}
.link-btn svg { flex-shrink: 0; }
.link-btn.anc { color: var(--ink-soft); }
.link-btn.anc:hover { color: var(--gold); }

.section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.section:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
.section h3 {
  font-family: var(--sans);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 10px;
}

.fact { font-size: 13px; margin-bottom: 6px; }
.fact .label {
  display: inline-block;
  min-width: 64px;
  color: var(--muted);
  font-size: 12px;
}

.person-link {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px dotted var(--gold);
  cursor: pointer;
  transition: color 0.1s;
}
.person-link:hover { color: var(--gold); }
.person-link .yrs { color: var(--muted); font-size: 11px; margin-left: 4px; }

.list { display: flex; flex-direction: column; gap: 6px; }

.gap-badge {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--rose);
  background: #f4e1e2;
  padding: 2px 6px;
  border-radius: 3px;
  margin-left: 6px;
}

/* Help dialog */
dialog#help-dialog {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  background: var(--paper);
  color: var(--ink);
  max-width: 480px;
  box-shadow: var(--shadow);
}
dialog#help-dialog::backdrop { background: rgba(42, 36, 24, 0.4); backdrop-filter: blur(2px); }
dialog#help-dialog h2 {
  font-family: var(--serif); font-size: 24px; font-weight: 600; margin: 0 0 12px;
}
dialog#help-dialog ul { padding-left: 18px; margin: 0 0 16px; }
dialog#help-dialog li { margin-bottom: 6px; }
dialog#help-dialog .hint { color: var(--muted); font-size: 12px; }
dialog#help-dialog code {
  font-family: ui-monospace, monospace; font-size: 11px;
  background: var(--cream-2); padding: 1px 5px; border-radius: 3px;
}

/* Loading + responsive */
.loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 20px; color: var(--muted);
  font-style: italic;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: calc(100vh - 56px);
    position: relative;
  }
  .tree-wrap { grid-row: 1; grid-column: 1; }
  .topbar { padding: 8px 12px; flex-wrap: wrap; row-gap: 8px; }
  .brand-title { font-size: 16px; white-space: nowrap; }
  .brand-sub { font-size: 11px; }
  .controls { flex-wrap: wrap; gap: 6px; }
  #search { width: 100%; }
  .search-wrap { flex: 1 1 100%; order: 3; }
  .btn { padding: 6px 10px; font-size: 12px; }
  /* Hide the legend entirely on mobile — it tends to cover cards when the drawer is peeking. */
  .legend { display: none; }
  .zoom-controls { bottom: 8px; right: 8px; }
  .person-card h2 { font-size: 22px; }

  /* Mobile bottom drawer for the person panel (Pass 2) */
  .panel {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    top: auto;
    height: 70vh;
    max-height: 70vh;
    border-left: none;
    border-top: 1px solid var(--line);
    border-radius: 16px 16px 0 0;
    padding: 0;
    z-index: 40;
    box-shadow: 0 -6px 24px rgba(60, 48, 20, 0.15);
    transform: translateY(calc(70vh - 84px));
    transition: transform 0.28s cubic-bezier(0.22, 0.7, 0.25, 1);
    overflow: hidden;
    touch-action: none;
  }
  .panel.open { transform: translateY(0); }
  .panel.dragging { transition: none; }
  .panel-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 28px;
    background: var(--paper);
    border: none;
    border-bottom: 1px solid var(--line);
    cursor: grab;
    padding: 0;
    touch-action: none;
  }
  .panel-handle:active { cursor: grabbing; }
  .panel-handle span {
    display: block;
    width: 44px;
    height: 4px;
    background: var(--line);
    border-radius: 2px;
  }
  .panel-content {
    padding: 14px 18px 80px;
    overflow-y: auto;
    height: calc(70vh - 28px);
    -webkit-overflow-scrolling: touch;
  }

  /* View tabs sit higher on mobile to clear legend */
  .view-tabs { top: 8px; }
  .recent-rail { top: 44px; max-width: calc(100vw - 16px); padding: 3px 8px 3px 10px; }
  .recent-label { font-size: 9px; }
  .recent-item { font-size: 10.5px; padding: 2px 8px 2px 2px; }
  .recent-item .thumb { width: 18px; height: 18px; }
  .photos-view { padding: 70px 12px 100px; }
  .photos-grid { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 8px; }
  .videos-view { padding: 70px 12px 100px; }
  .videos-grid { grid-template-columns: 1fr; gap: 14px; }
  .video-modal-content { max-width: 100vw; max-height: 100vh; border-radius: 0; }
  .video-modal-player { max-height: 50vh; }
  /* legend hidden on mobile (see above) — no bottom offset needed */
  .zoom-controls { bottom: calc(70vh - 84px + 8px); transition: bottom 0.28s cubic-bezier(0.22, 0.7, 0.25, 1); }
  .panel.open ~ * .legend { /* no-op, placeholder */ }
}

/* Desktop: hide the panel handle entirely */
@media (min-width: 901px) {
  .panel-handle { display: none; }
  .panel-content { padding: 0; overflow: visible; height: auto; }
  .panel { padding: 24px; }
}

/* Ancestry photo gallery in the side panel */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  margin-top: 4px;
}

.photo-thumb {
  display: block;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-bg, #1a1a1a);
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

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

.photo-thumb:hover {
  transform: translateY(-2px);
  border-color: var(--accent, #f0a020);
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

/* Inline YouTube video cards */
.video-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-top: 6px;
}
@media (min-width: 900px) {
  .video-grid { grid-template-columns: 1fr 1fr; }
}
.video-card {
  display: flex;
  flex-direction: column;
  background: var(--paper, #fffbf1);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.video-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #111;
  cursor: pointer;
  overflow: hidden;
}
.video-poster {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 200ms ease, filter 200ms ease;
}
.video-frame:hover .video-poster {
  transform: scale(1.02);
  filter: brightness(0.85);
}
/* Cream/gold placeholder for unlisted YouTube videos with no public thumbnail */
.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 18px;
  background:
    radial-gradient(circle at 30% 20%, rgba(212, 175, 110, 0.18), transparent 55%),
    radial-gradient(circle at 70% 80%, rgba(212, 175, 110, 0.14), transparent 60%),
    linear-gradient(135deg, #2b231b 0%, #3a2f23 100%);
  color: #f5ead0;
  font-family: var(--serif, Georgia, serif);
}
.video-placeholder-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  max-width: 88%;
  color: #f5ead0;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
  margin-bottom: 6px;
}
.video-placeholder-sub {
  font-size: 13px;
  color: rgba(245, 234, 208, 0.78);
  font-style: italic;
}
.video-frame:hover .video-placeholder {
  filter: brightness(0.92);
}
.video-expand {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 5;
  transition: background 150ms ease, transform 150ms ease;
}
.video-expand:hover {
  background: rgba(0, 0, 0, 0.78);
  transform: scale(1.08);
}
.video-frame.playing .video-expand {
  display: none;
}

/* Pop-out video modal — large viewer */
.video-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 4vh 4vw;
}
.video-modal.open { display: flex; }
.video-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(4px);
}
.video-modal-inner {
  position: relative;
  z-index: 1;
  width: min(1280px, 92vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.video-modal-close {
  position: absolute;
  top: -38px;
  right: 0;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.video-modal-title {
  color: #fff;
  font-family: var(--serif, Georgia, serif);
  font-size: 16px;
  font-weight: 600;
  text-align: center;
}
.video-modal-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.video-modal-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
@media (max-width: 720px) {
  .video-modal { padding: 6vh 4vw; }
  .video-modal-inner { width: 100%; }
}
.video-play {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 54px;
  height: 54px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 150ms ease;
}
.video-frame:hover .video-play {
  transform: scale(1.08);
}
.video-frame.playing { cursor: default; }
.video-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.video-meta {
  padding: 8px 12px 10px;
  font-size: 13px;
  line-height: 1.4;
}
.video-title {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 2px;
}
.video-sub {
  font-size: 12px;
  color: var(--muted);
}
.video-people {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 3px;
  font-style: italic;
}

/* Biographical notes & life events from GEDCOM */
.bio-note {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text, #2d2618);
  background: rgba(180, 150, 80, 0.07);
  border-left: 3px solid var(--accent, #b48230);
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 0 6px 6px 0;
  white-space: normal;
  word-wrap: break-word;
}
.bio-note:last-child { margin-bottom: 0; }

.doc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.doc-list li {
  font-size: 13px;
  line-height: 1.45;
  background: rgba(180, 150, 80, 0.07);
  border-left: 3px solid var(--accent, #b48230);
  padding: 8px 12px;
  border-radius: 0 6px 6px 0;
}
.doc-link {
  color: var(--accent, #b48230);
  text-decoration: none;
  font-weight: 600;
}
.doc-link:hover { text-decoration: underline; }
.doc-src {
  color: var(--muted, #7a6a4a);
  font-size: 12px;
  font-style: italic;
}

.events-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.event-item {
  font-size: 13px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.025);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.event-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.event-type {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--accent, #b48230);
}
.event-meta { font-size: 12.5px; color: var(--text, #2d2618); }
.event-detail {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.45;
}
.event-detail .label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-right: 4px;
}

/* ---------- Photo lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 9999;
  align-items: center;
  justify-content: center;
}
.lightbox.open { display: flex; }
.lb-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 12, 8, 0.92);
  cursor: zoom-out;
}
.lb-fig {
  position: relative;
  max-width: 92vw;
  max-height: 92vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.lb-img {
  max-width: 92vw;
  max-height: 80vh;
  width: auto;
  height: auto;
  border-radius: 6px;
  box-shadow: 0 14px 60px rgba(0,0,0,0.6);
  background: #1a1612;
}
.lb-cap {
  color: #f0e6d2;
  font-family: var(--ui, system-ui), sans-serif;
  font-size: 14px;
  text-align: center;
  max-width: 80vw;
  padding: 4px 12px;
  opacity: 0.88;
}
.lb-close, .lb-prev, .lb-next {
  position: absolute;
  background: rgba(0,0,0,0.4);
  color: #f0e6d2;
  border: 1px solid rgba(218,165,32,0.4);
  border-radius: 999px;
  width: 44px;
  height: 44px;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: background 0.15s, border-color 0.15s;
}
.lb-close { top: 24px; right: 24px; }
.lb-prev { left: 24px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 24px; top: 50%; transform: translateY(-50%); }
.lb-close:hover, .lb-prev:hover, .lb-next:hover {
  background: rgba(218,165,32,0.25);
  border-color: var(--gold, #daa520);
}
@media (max-width: 600px) {
  .lb-close, .lb-prev, .lb-next { width: 36px; height: 36px; font-size: 22px; }
  .lb-close { top: 12px; right: 12px; }
  .lb-prev { left: 8px; }
  .lb-next { right: 8px; }
}

/* ===== Albums view ===== */
.albums-view {
  padding: 24px;
  overflow-y: auto;
  height: 100%;
}
.albums-view-header {
  margin-bottom: 16px;
}
.albums-view-header h2 {
  margin: 0 0 4px 0;
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  font-size: 28px;
}
.albums-view-sub {
  color: #6b6358;
  font-size: 13px;
  margin-bottom: 12px;
}
.albums-filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.albums-filters input,
.albums-filters select {
  font-family: inherit;
  font-size: 14px;
  padding: 6px 10px;
  border: 1px solid #cdb98e;
  border-radius: 4px;
  background: #faf6ec;
  color: #2a2520;
}
.albums-filters input { flex: 1; min-width: 200px; }
.albums-filters select { min-width: 120px; }

.album-tile { cursor: zoom-in; }
.album-year {
  display: inline-block;
  padding: 1px 6px;
  background: rgba(176,141,58,0.15);
  color: #8a6f2c;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
}

/* Album modal (lightbox) */
.album-modal {
  position: fixed;
  inset: 0;
  background: rgba(20,16,12,0.92);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.album-modal[hidden] { display: none; }
.album-modal-inner {
  max-width: min(1100px, 96vw);
  max-height: 96vh;
  display: flex;
  flex-direction: column;
  position: relative;
}
.album-modal-img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
}
.album-modal-caption {
  color: #faf6ec;
  font-family: 'Cormorant Garamond', serif;
  font-size: 18px;
  margin-top: 10px;
  text-align: center;
}
.album-modal-close {
  position: absolute;
  top: -36px;
  right: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.album-modal-close:hover {
  background: rgba(218,165,32,0.3);
  border-color: #daa520;
}
