/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep:       #070b14;
  --bg-mid:        #0d1321;
  --text:          #e0e6f0;
  --text-dim:      #8899b0;
  --text-faint:    #55667a;
  --text-muted:    #3a4a5e;
  --accent:        #f0b429;
  --accent-dim:    rgba(240, 180, 41, 0.12);
  --panel-bg:      rgba(13, 19, 33, 0.65);
  --panel-border:  rgba(136, 153, 176, 0.10);
  --avatar-bg:     rgba(136, 153, 176, 0.06);
  --avatar-border: rgba(136, 153, 176, 0.12);
  --line-color:    rgba(136, 153, 176, 0.18);
}

html { scroll-behavior: smooth; }

body {
  width: 100%;
  min-height: 100vh;
  background: var(--bg-deep);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========== Starry Background ========== */
.stars-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse at 20% 50%, #141f38 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, #181430 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, #0c1a22 0%, transparent 50%),
    var(--bg-deep);
}
.stars-bg::before,
.stars-bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 30% 70%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1px 1px at 50% 30%, rgba(255,255,255,0.45), transparent),
    radial-gradient(1px 1px at 70% 80%, rgba(255,255,255,0.25), transparent),
    radial-gradient(1px 1px at 90% 40%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1.5px 1.5px at 15% 85%, rgba(255,255,255,0.6), transparent),
    radial-gradient(1.5px 1.5px at 85% 15%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 45% 55%, rgba(255,255,255,0.25), transparent),
    radial-gradient(1px 1px at 65% 25%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1px 1px at 25% 45%, rgba(255,255,255,0.25), transparent);
  background-size: 100% 100%;
  animation: twinkle 8s ease-in-out infinite alternate;
}
.stars-bg::after {
  background-image:
    radial-gradient(1px 1px at 5% 60%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1px 1px at 35% 15%, rgba(255,255,255,0.45), transparent),
    radial-gradient(1px 1px at 55% 75%, rgba(255,255,255,0.25), transparent),
    radial-gradient(1px 1px at 75% 45%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 95% 85%, rgba(255,255,255,0.35), transparent),
    radial-gradient(2px 2px at 50% 10%, rgba(255,255,255,0.7), transparent),
    radial-gradient(1.5px 1.5px at 20% 90%, rgba(255,255,255,0.4), transparent);
  animation-delay: -4s;
}
@keyframes twinkle {
  0%   { opacity: 0.4; }
  100% { opacity: 0.9; }
}

/* ========== Back Link ========== */
.back-link {
  position: fixed;
  top: 1.5rem;
  left: 1.5rem;
  z-index: 100;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  padding: 0.5rem 1rem;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  transition: all 0.25s ease;
}
.back-link:hover {
  color: var(--accent);
  border-color: rgba(240, 180, 41, 0.25);
}

/* ========== Family Tree Layout ========== */
.family-tree {
  max-width: 1000px;
  margin: 0 auto;
  padding: 5rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---- Grand-row: four trees side by side ---- */
.grand-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 0;
  width: 100%;
}

.grand-gap-wide {
  width: 6rem;
  flex-shrink: 0;
}

/* ---- Grand-row: two trees side by side ---- */
.grand-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 0;
  width: 100%;
}

.tree-side {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.grand-gap {
  width: 4rem;
  flex-shrink: 0;
}

/* ---- Generation ---- */
.gen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.gen-label {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 0.75rem;
}

/* ---- Couple (horizontal pair) ---- */
.couple {
  display: flex;
  align-items: center;
  gap: 0;
}

.union-h {
  width: 2rem;
  height: 2px;
  background: var(--line-color);
  flex-shrink: 0;
}

/* ---- Union pair (我 ── 媳妇) ---- */
.union-pair {
  display: flex;
  align-items: center;
  gap: 0;
  justify-content: center;
  margin: 0.5rem 0;
}

/* ---- Children row ---- */
.children-row {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 2.5rem;
  width: 100%;
}

/* ---- Member card ---- */
.member {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.2rem 1.5rem;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  min-width: 100px;
  transition: all 0.25s ease;
  position: relative;
}

.member:hover {
  border-color: rgba(240, 180, 41, 0.2);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

/* ---- Avatar placeholder ---- */
.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}

.avatar.empty {
  background: var(--avatar-bg);
  border: 1.5px dashed var(--avatar-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar.empty::after {
  content: '+';
  font-size: 1.5rem;
  font-weight: 200;
  color: var(--text-muted);
}

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

/* ---- Name & relation ---- */
.name {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
  letter-spacing: 0.02em;
}

.relation {
  font-size: 0.7rem;
  color: var(--text-faint);
  letter-spacing: 0.05em;
}

/* ==================================================================
   CONNECTION LINES
   ================================================================== */

/* T-shaped connector between two columns */
.gen-connector {
  position: relative;
  width: 100%;
  height: 2.5rem;
  display: flex;
  align-items: flex-start;
  flex-shrink: 0;
}

/* Four-column connector (grandparents → parents) */
.gen-connector-four {
  justify-content: center;
}

/* Horizontal bars from each column to center */
.gc-line {
  height: 2px;
  background: var(--line-color);
  align-self: center;
}

.gc-line-left {
  flex: 1;
}

.gc-line-right {
  flex: 1;
}

/* Vertical drops */
.gc-v {
  width: 2px;
  height: 100%;
  background: var(--line-color);
  flex-shrink: 0;
}

/* Gap between the two vertical drops */
.gc-gap {
  width: 4rem;
  flex-shrink: 0;
}

.gc-gap-wide {
  width: 6rem;
  flex-shrink: 0;
}

/* Single vertical connector (centered) */
.gen-connector-single {
  justify-content: center;
}

.gc-v-single {
  height: 100%;
  width: 2px;
  background: var(--line-color);
  flex-shrink: 0;
}

/* ========== Footer ========== */
.site-footer {
  text-align: center;
  padding: 2rem 1rem 3rem;
  color: var(--text-faint);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  width: 100%;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .family-tree {
    padding: 4rem 1rem 2rem;
  }

  .member {
    padding: 0.8rem 1rem;
    min-width: 80px;
  }

  .avatar {
    width: 52px;
    height: 52px;
  }

  .name {
    font-size: 0.85rem;
  }

  .union-h {
    width: 1.2rem;
  }

  .grand-gap {
    width: 1.5rem;
  }

  .grand-gap-wide {
    width: 2rem;
  }

  .gc-gap {
    width: 1.5rem;
  }

  .gc-gap-wide {
    width: 2rem;
  }

  .children-row {
    gap: 1.5rem;
  }

  .gen-connector {
    height: 1.8rem;
  }

  .back-link {
    top: 0.75rem;
    left: 0.75rem;
    font-size: 0.75rem;
    padding: 0.4rem 0.75rem;
  }
}
