*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #5C4A1E;
  --primary-light: #D4A574;
  --primary-dark: #3E2F12;
  --accent: #405A72;
  --accent-light: #A9BFD2;
  --bg: #f4f6f8;
  --bg-card: #FFFFFF;
  --text: #17212b;
  --text-light: #77828e;
  --border: #cbd3db;
  --soft: #eef2f5;
  --shadow: 0 2px 12px rgba(24, 36, 48, 0.08);
  --shadow-lg: 0 8px 32px rgba(24, 36, 48, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.25s ease;
  --transition-slow: 0.4s ease;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: 8px;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-size: 0.85rem;
  z-index: 300;
  text-decoration: none;
  transition: top 0.2s;
}

.skip-link:focus {
  top: 0;
}

[data-theme="dark"] {
  --bg: #0e141a;
  --bg-card: #171f27;
  --text: #f4f6f8;
  --text-light: #98a4af;
  --border: #394550;
  --soft: #222c35;
  --accent: #a9bfd2;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
}

html {
  overflow-x: hidden;
}

body {
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  width: 100%;
  transition: background var(--transition), color var(--transition);
}

.header {
  background: linear-gradient(135deg, #172536, #536f8b);
  color: #fff;
  padding: 16px 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  width: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.logo svg {
  color: var(--primary-light);
}

.logo h1 {
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.nav {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.1);
  padding: 4px;
  border-radius: var(--radius-sm);
}

.nav-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-btn:hover { background: rgba(255, 255, 255, 0.15); }
.nav-btn.active { background: rgba(255, 255, 255, 0.25); font-weight: 600; color: #fff; }

.nav-icon { font-size: 1rem; }

.search-bar {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

.search-bar input {
  padding: 8px 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 0.85rem;
  width: 200px;
  transition: var(--transition);
}

.search-bar input::placeholder { color: rgba(255, 255, 255, 0.5); }
.search-bar input:focus {
  outline: none;
  border-color: var(--primary-light);
  background: rgba(255, 255, 255, 0.25);
}

.search-btn {
  padding: 8px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  font-size: 0.85rem;
  transition: var(--transition);
  white-space: nowrap;
}

.search-btn:hover { background: rgba(255, 255, 255, 0.3); }

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px;
  width: 100%;
}

.view {
  display: none;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--transition-slow), transform var(--transition-slow);
}

.view.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

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

/* Stats Bar */
.stats-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-icon {
  font-size: 1.3rem;
  margin-bottom: 4px;
}

.stat-card b {
  display: block;
  font-size: 1.5rem;
  color: var(--accent);
}

.stat-card span {
  font-size: 0.7rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

/* Loading Skeleton */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(90deg, var(--soft) 25%, var(--bg-card) 50%, var(--soft) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

.skeleton-card {
  width: 170px;
  height: 100px;
  margin: 10px;
  display: inline-block;
}

/* Tree Controls */
.tree-controls {
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.gen-nav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.gen-nav::-webkit-scrollbar { display: none; }

.gen-nav button {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-light);
  border-radius: 99px;
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.gen-nav button:hover { border-color: var(--accent); color: var(--text); }
.gen-nav button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.compact-toggle {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-light);
  border-radius: 99px;
  padding: 5px 14px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.compact-toggle:hover { border-color: var(--accent); color: var(--text); }

.tree-container.compact .tree-generation { padding: 16px 12px; }
.tree-container.compact .tree-person { width: 120px; padding: 8px; }
.tree-container.compact .tree-person-avatar { font-size: 1.4rem; margin-bottom: 3px; }
.tree-container.compact .tree-person-name { font-size: 0.7rem; }
.tree-container.compact .tree-person-role { font-size: 0.6rem; }
.tree-container.compact .tree-kid-card { width: 88px; padding: 6px 4px; }
.tree-container.compact .tree-kid-card .tree-person-name { font-size: 0.65rem; }
.tree-container.compact .tree-clusters { gap: 24px 10px; }
.tree-container.compact .tree-kids-row { gap: 8px; }
.tree-container.compact .tree-spouse-line { font-size: 0.9rem; }
.tree-container.compact .tree-gen-title { margin-bottom: 12px; }
.tree-container.compact .tree-gen-title span { font-size: 0.65rem; padding: 3px 10px; }

.gen-nav-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(255,255,255,0.2);
}

.gen-nav button.active .gen-nav-count {
  background: rgba(255,255,255,0.25);
}

.tree-legend {
  display: flex;
  gap: 16px;
  background: var(--bg-card);
  padding: 8px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-light);
}

.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.male { background: #5B8DEF; }
.legend-dot.female { background: #E8739A; }
.legend-dot.other { background: #9C8EF0; }

/* Tree Container */
.tree-container {
  overflow-x: auto;
  padding: 10px 0;
  -webkit-overflow-scrolling: touch;
}

.tree-generation {
  margin-bottom: 0;
  padding: 30px 20px;
  border-radius: var(--radius);
  scroll-margin-top: 80px;
}

.tree-generation:nth-child(even) {
  background: var(--soft);
}

.tree-generation:last-child { margin-bottom: 10px; }

.tree-gen-title {
  text-align: center;
  margin-bottom: 20px;
}

.tree-gen-title span {
  display: inline-block;
  font-size: 0.75rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-light);
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--soft);
  transition: var(--transition);
}

.tree-clusters {
  display: flex;
  flex-wrap: wrap;
  gap: 40px 24px;
  justify-content: center;
  align-items: flex-start;
}

.tree-cluster {
  transition: opacity 0.3s, filter 0.3s;
}

.tree-cluster.dim,
.timeline-item.dim {
  opacity: 0.15;
  filter: grayscale(0.6);
  pointer-events: none;
  transition: opacity 0.4s, filter 0.4s;
}

.tree-couple {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tree-spouse-line {
  color: var(--accent);
  font-size: 1.2rem;
  flex-shrink: 0;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.tree-cluster {
  animation: cardIn 0.35s ease both;
}

.tree-cluster:nth-child(1) { animation-delay: 0s; }
.tree-cluster:nth-child(2) { animation-delay: 0.05s; }
.tree-cluster:nth-child(3) { animation-delay: 0.1s; }
.tree-cluster:nth-child(4) { animation-delay: 0.15s; }
.tree-cluster:nth-child(5) { animation-delay: 0.2s; }
.tree-cluster:nth-child(6) { animation-delay: 0.25s; }
.tree-cluster:nth-child(7) { animation-delay: 0.3s; }
.tree-cluster:nth-child(8) { animation-delay: 0.35s; }

.tree-person {
  width: 170px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  box-shadow: var(--shadow);
}

.tree-person:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
}

.tree-person.highlight {
  outline: 3px solid var(--accent);
}

.tree-person-avatar {
  font-size: 2rem;
  margin-bottom: 6px;
}

.tree-person-avatar.small {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.tree-person-name {
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
}

.tree-person-role {
  font-size: 0.65rem;
  color: var(--text-light);
  margin-top: 3px;
}

/* Kids */
.tree-kids-wrap {
  position: relative;
  padding-top: 22px;
  margin-top: 8px;
}

.tree-kids-wrap::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  height: 22px;
  border-left: 2px solid var(--border);
}

.tree-kids-row {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 14px;
  position: relative;
  flex-wrap: wrap;
}

.tree-kids-row.multi::before {
  content: '';
  position: absolute;
  top: 0;
  left: 6%;
  right: 6%;
  border-top: 2px solid var(--border);
}

.tree-kid-branch {
  position: relative;
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tree-kid-branch::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  height: 16px;
  border-left: 2px solid var(--border);
}

.tree-kid-card {
  width: 124px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 6px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}

.tree-kid-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.tree-kid-card.highlight {
  outline: 2px solid var(--accent);
}

.tree-continue {
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--accent);
  background: var(--soft);
  border-radius: 99px;
  padding: 3px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

.tree-continue:hover { opacity: 0.8; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  justify-content: center;
  align-items: center;
  padding: 24px;
  backdrop-filter: blur(4px);
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  max-width: 520px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
  animation: modalIn 0.25s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: var(--soft);
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text);
  transition: var(--transition);
  line-height: 1;
  display: grid;
  place-items: center;
  z-index: 1;
}

.modal-close:hover { background: var(--border); }

.profile-content { padding: 32px 28px; }

.profile-header {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.profile-avatar {
  font-size: 2.8rem;
  width: 70px;
  height: 70px;
  border-radius: 20px;
  background: var(--soft);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.profile-name {
  font-size: 1.3rem;
  font-weight: 700;
}

.profile-occupation {
  color: var(--accent);
  font-weight: 500;
  font-size: 0.85rem;
  margin-top: 2px;
}

.profile-dates {
  color: var(--text-light);
  font-size: 0.8rem;
  margin-top: 2px;
}

.profile-bio {
  margin-bottom: 20px;
  line-height: 1.7;
  font-size: 0.9rem;
}

.profile-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-light);
  margin-bottom: 8px;
}

.profile-rel-section {
  margin-top: 16px;
}

.profile-relatives {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.relative-chip {
  background: var(--soft);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
}

.relative-chip:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.profile-tree-btn {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--accent);
  background: var(--bg-card);
  color: var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
}

.profile-tree-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* Search Results */
.search-results {
  display: none;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px 24px;
}

.search-results.active { display: block; animation: fadeIn 0.3s ease; }

.search-results-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.search-results-header h3 { font-size: 1rem; }

.search-count {
  background: var(--accent);
  color: #fff;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
}

.search-results-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.search-result-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 14px;
}

.search-result-item:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.search-result-avatar {
  font-size: 1.8rem;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  background: var(--soft);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.search-result-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.search-result-meta {
  font-size: 0.75rem;
  color: var(--text-light);
}

/* Timeline View */
.timeline-header {
  text-align: center;
  margin-bottom: 36px;
}

.timeline-header h2 {
  font-size: 1.5rem;
}

.timeline-header p {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-top: 4px;
}

.timeline-container {
  position: relative;
  padding: 20px 0;
}

.timeline-container::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 3px;
  background: linear-gradient(to bottom, var(--primary-light), var(--accent), var(--primary-light));
  transform: translateX(-50%);
}

.timeline-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 28px;
  position: relative;
}

.timeline-item:nth-child(odd) {
  flex-direction: row;
  padding-right: calc(50% + 30px);
  text-align: right;
}

.timeline-item:nth-child(even) {
  flex-direction: row-reverse;
  padding-left: calc(50% + 30px);
  text-align: left;
}

.timeline-dot {
  position: absolute;
  left: 50%;
  top: 8px;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: 3px solid var(--bg);
  border-radius: 50%;
  transform: translateX(-50%);
  z-index: 1;
  box-shadow: 0 0 0 2px var(--accent);
}

.timeline-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  transition: var(--transition);
  cursor: pointer;
  width: 100%;
}

.timeline-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.timeline-year {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: 3px 12px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.timeline-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.timeline-person {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 6px;
}

.timeline-desc {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 10px;
}

.timeline-members {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.timeline-tag {
  font-size: 0.7rem;
  background: var(--soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
  transition: var(--transition);
}

.timeline-tag:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.timeline-tag.highlight {
  outline: 2px solid var(--accent);
  background: var(--accent);
  color: #fff;
}

/* Gallery View */
.gallery-header {
  text-align: center;
  margin-bottom: 24px;
}

.gallery-header h2 {
  font-size: 1.5rem;
}

.gallery-header p {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-top: 4px;
}

.gallery-filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.gallery-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1;
}

.gallery-filter-btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-light);
  border-radius: 99px;
  padding: 5px 14px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: var(--transition);
}

.gallery-filter-btn:hover { border-color: var(--accent); color: var(--text); }
.gallery-filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.gallery-sort {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 0.78rem;
  cursor: pointer;
}

.gallery-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.gallery-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: var(--transition);
  cursor: pointer;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-item:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.gallery-item.dim {
  opacity: 0.15;
  filter: grayscale(0.6);
  pointer-events: none;
  transition: opacity 0.4s, filter 0.4s;
}

.gallery-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: var(--transition);
}

/* Scroll to Top */
.scroll-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: var(--transition);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  display: grid;
  place-items: center;
}

.scroll-top.visible {
  opacity: 1;
  pointer-events: auto;
}

.scroll-top:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  color: var(--accent);
}

/* Footer */
.footer {
  text-align: center;
  padding: 24px;
  color: var(--text-light);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* Responsive */
@media (max-width: 900px) {
  .header { padding: 10px 14px; }
  .header-content { flex-direction: column; align-items: stretch; gap: 8px; }
  .logo { justify-content: center; }
  .logo h1 { font-size: 1.1rem; }
  .nav { justify-content: center; }
  .nav-btn { padding: 6px 10px; font-size: 0.8rem; }
  .search-bar { margin-left: 0; }
  .search-bar input { flex: 1; width: auto; font-size: 0.8rem; }
  .search-btn { padding: 6px 10px; font-size: 0.8rem; }
  .stats-bar { gap: 6px; }
  .stat-card { padding: 10px 6px; }
  .stat-card b { font-size: 1.2rem; }
  .stat-icon { font-size: 1rem; }
}

@media (max-width: 768px) {
  .main { padding: 10px 8px; }
  .tree-generation { padding: 20px 8px; }
  .tree-person { width: 130px; padding: 10px; }
  .tree-kid-card { width: 96px; }
  .tree-clusters { gap: 30px 12px; }
  .tree-controls { flex-direction: column; align-items: stretch; }
  .tree-legend { justify-content: center; }
  .gen-nav { justify-content: flex-start; flex-wrap: nowrap; }
  .timeline-container::before { left: 16px; }
  .timeline-item:nth-child(odd),
  .timeline-item:nth-child(even) {
    padding-left: 40px; padding-right: 0;
    text-align: left; flex-direction: row;
  }
  .timeline-dot { left: 16px; width: 12px; height: 12px; }
  .timeline-card { padding: 12px; }
  .gallery-container { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
  .modal { max-height: 90vh; margin: 8px; }
  .profile-header { flex-direction: column; text-align: center; }
  .profile-content { padding: 24px 16px; }
  .scroll-top { bottom: 16px; right: 16px; width: 38px; height: 38px; font-size: 1rem; }
  .search-results-list { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .main { padding: 8px 4px; }
  .header { padding: 8px 8px; }
  .logo h1 { font-size: 0.95rem; }
  .logo svg { width: 24px; height: 24px; }
  .nav-btn { padding: 5px 8px; font-size: 0.75rem; gap: 3px; }
  .nav-icon { font-size: 0.85rem; }
  .search-bar input { font-size: 0.75rem; padding: 6px 8px; }
  .search-btn { padding: 5px 8px; font-size: 0.75rem; }
  .stats-bar { gap: 4px; }
  .stat-card { padding: 8px 4px; }
  .stat-card b { font-size: 1rem; }
  .stat-card span { font-size: 0.6rem; }
  .stat-icon { font-size: 0.85rem; margin-bottom: 2px; }
  .gen-nav { gap: 4px; }
  .gen-nav button { font-size: 0.7rem; padding: 4px 10px; }
  .tree-generation { padding: 16px 4px; }
  .tree-person { width: 110px; padding: 8px; }
  .tree-person-name { font-size: 0.7rem; }
  .tree-person-role { font-size: 0.6rem; }
  .tree-person-avatar { font-size: 1.5rem; margin-bottom: 4px; }
  .tree-kid-card { width: 80px; padding: 6px 4px; }
  .tree-kid-card .tree-person-name { font-size: 0.65rem; }
  .tree-clusters { gap: 24px 8px; }
  .tree-kids-row { gap: 8px; }
  .tree-kids-row.multi::before { left: 4%; right: 4%; }
  .timeline-title { font-size: 0.9rem; }
  .timeline-desc { font-size: 0.75rem; }
  .timeline-tag { font-size: 0.65rem; padding: 2px 6px; }
  .gallery-container { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .gallery-placeholder-text { font-size: 0.75rem; }
  .modal { margin: 4px; max-height: 95vh; }
  .profile-content { padding: 20px 12px; }
  .profile-name { font-size: 1.1rem; }
  .profile-avatar { width: 56px; height: 56px; font-size: 2.2rem; }
  .search-result-item { padding: 10px; }
  .search-result-name { font-size: 0.8rem; }
}

@media (max-width: 360px) {
  .tree-person { width: 90px; padding: 6px; }
  .tree-kid-card { width: 68px; padding: 4px 3px; }
  .tree-clusters { gap: 20px 6px; }
  .gallery-container { grid-template-columns: repeat(2, 1fr); gap: 4px; }
  .header-content { gap: 4px; }
  .nav { gap: 2px; padding: 3px; }
  .nav-btn { padding: 4px 6px; font-size: 0.7rem; }
  .timeline-item:nth-child(odd),
  .timeline-item:nth-child(even) { padding-left: 32px; }
  .timeline-dot { left: 12px; width: 10px; height: 10px; }
  .timeline-container::before { left: 12px; }
}
