* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Serif SC", serif;
  background: #14100d;
  color: #f7f3ea;
  -webkit-font-smoothing: antialiased;
}
:root {
  --c-sheng: #5b8db8;
  --c-dan:   #c97ba6;
  --c-jing:  #b03a2e;
  --c-chou:  #d9a441;
}

/* ---- topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  background: rgba(20,16,13,.7);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(247,243,234,.1);
}
.topbar__back { display: inline-flex; align-items: center; gap: 6px;
  color: rgba(247,243,234,.75); text-decoration: none; font-size: 14px; }
.topbar__back span { font-size: 18px; }
.topbar__back:hover { color: #e9c46a; }
.topbar__title { font-size: 13px; letter-spacing: .3em; color: rgba(247,243,234,.55); }
.topbar__logo {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: #b03a2e; color: #fff; font-size: 18px; border-radius: 5px;
  text-decoration: none; box-shadow: 0 3px 10px rgba(140,42,32,.4);
}

/* ---- head ---- */
.head {
  padding: 48px 20px 12px;
  text-align: center;
  background: radial-gradient(120% 80% at 50% 0%, rgba(180,60,50,.18), transparent 60%);
}
.head__title {
  font-size: clamp(30px, 6vw, 52px);
  font-weight: 700; letter-spacing: .3em;
  color: #f7f3ea; text-shadow: 0 2px 12px rgba(0,0,0,.5);
}
.head__sub {
  margin: 14px auto 0; max-width: 640px;
  font-size: 14px; letter-spacing: .1em;
  color: rgba(247,243,234,.6); line-height: 1.8;
}

/* ---- filter ---- */
.filter {
  display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center; padding: 22px 20px 6px;
}
.filter__btn {
  padding: 7px 16px; font-size: 13px; letter-spacing: .12em; font-family: inherit;
  color: rgba(247,243,234,.75);
  background: rgba(247,243,234,.05);
  border: 1px solid rgba(247,243,234,.18);
  border-radius: 999px; cursor: pointer;
  transition: all .18s ease;
}
.filter__btn:hover { color: #f7f3ea; border-color: rgba(247,243,234,.45); }
.filter__btn.active {
  color: #14100d; background: #e9c46a; border-color: #e9c46a; font-weight: 600;
}

/* ---- legend ---- */
.legend {
  max-width: 960px; margin: 10px auto 0; padding: 4px 20px 6px;
  font-size: 12px; color: rgba(247,243,234,.5); text-align: center; line-height: 1.9;
}
.legend b { color: rgba(233,196,106,.85); font-weight: 600; }

/* ---- tree container ---- */
.tree-container {
  max-width: 960px; margin: 0 auto; padding: 24px 20px 10px;
  display: grid; gap: 34px;
}

/* single tree */
.tree {
  border: 1px solid rgba(247,243,234,.1);
  border-radius: 14px; overflow: hidden;
  background: rgba(247,243,234,.02);
  opacity: 0; transform: translateY(24px);
  transition: opacity .6s ease, transform .6s ease;
}
.tree.in { opacity: 1; transform: translateY(0); }
.tree[data-hidden="true"] { display: none; }

.tree[data-role="sheng"] { --tint: rgba(91,141,184,.14); }
.tree[data-role="dan"]   { --tint: rgba(201,123,166,.14); }
.tree[data-role="jing"]  { --tint: rgba(176,58,46,.16); }
.tree[data-role="chou"]  { --tint: rgba(217,164,65,.14); }

.tree__header {
  position: relative;
  padding: 18px 64px 16px 20px;
  border-bottom: 1px solid rgba(247,243,234,.08);
  background: linear-gradient(90deg, var(--tint, rgba(233,196,106,.1)), transparent 70%);
}
.tree__badge {
  position: absolute; top: 18px; right: 20px;
  width: 40px; height: 40px; display: grid; place-items: center;
  font-size: 20px; font-weight: 700; border-radius: 9px;
}
.tree__badge--sheng { background: var(--c-sheng); color: #fff; }
.tree__badge--dan   { background: var(--c-dan); color: #14100d; }
.tree__badge--jing  { background: var(--c-jing); color: #fff; }
.tree__badge--chou  { background: var(--c-chou); color: #14100d; }
.tree__title {
  font-size: 21px; font-weight: 700; letter-spacing: .1em; color: #f7f3ea;
}
.tree__sub {
  margin-top: 4px; font-size: 12.5px; letter-spacing: .06em;
  color: rgba(247,243,234,.55);
}

/* tree body: vertical generations */
.tree__body {
  padding: 22px 20px 26px;
  display: flex; flex-direction: column;
}

/* one generation row */
.tree__row {
  display: flex; flex-wrap: wrap; gap: 10px 14px;
  position: relative;
}
.tree__row-label {
  flex-basis: 100%;
  font-size: 11px; letter-spacing: .2em;
  color: rgba(247,243,234,.4);
  margin-bottom: 2px;
}

/* node */
.tree__node {
  position: relative;
  padding: 8px 14px; font-size: 14px; letter-spacing: .04em;
  color: rgba(247,243,234,.9);
  background: rgba(247,243,234,.05);
  border: 1px solid rgba(247,243,234,.18);
  border-radius: 8px;
  display: inline-flex; align-items: baseline; gap: 7px;
  transition: border-color .18s, background .18s, transform .18s;
}
.tree__node:hover {
  transform: translateY(-2px);
  border-color: rgba(233,196,106,.55);
  background: rgba(233,196,106,.08);
}
.tree__years { font-size: 11px; color: rgba(247,243,234,.4); letter-spacing: .02em; }

/* founder node: gold emphasis */
.tree__row--master .tree__node--master {
  color: #1a1512;
  background: linear-gradient(135deg, #e9c46a, #d4a94e);
  border-color: transparent; font-weight: 700; font-size: 15px;
  box-shadow: 0 4px 16px rgba(212,169,78,.3);
}
.tree__row--master .tree__node--master .tree__years { color: rgba(20,16,13,.55); }

/* leaf (last gen / living) node: dashed, implying continuation */
.tree__node--leaf { border-style: dashed; color: rgba(247,243,234,.7); }

/* generation connector */
.tree__branch {
  position: relative; align-self: flex-start;
  margin: 6px 0; padding-left: 14px; height: 34px;
  display: flex; align-items: center;
  color: rgba(233,196,106,.5); font-size: 11px; letter-spacing: .18em;
}
.tree__branch::before {
  content: ''; position: absolute; left: 7px; top: -8px; bottom: -8px;
  width: 1px;
  background: linear-gradient(to bottom, rgba(233,196,106,.45), rgba(233,196,106,.15));
}
.tree__branch .gen__tag { position: relative; z-index: 1; padding: 1px 8px; background: #14100d; }

/* ---- foot ---- */
.foot {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 30px 20px 40px;
}
.foot__back {
  color: rgba(247,243,234,.7); text-decoration: none;
  font-size: 14px; letter-spacing: .1em;
}
.foot__back:hover { color: #e9c46a; }
.foot__note {
  font-size: 11px; color: rgba(247,243,234,.4);
  max-width: 520px; text-align: center; line-height: 1.7;
}

/* ---- responsive ---- */
@media (max-width: 640px) {
  .tree__badge { width: 32px; height: 32px; font-size: 17px; }
  .tree__header { padding: 16px 54px 14px 16px; }
  .tree__title { font-size: 19px; }
  .tree__node { padding: 7px 12px; font-size: 13px; }
}
