:root{
  --bg: #F3EFE4;
  --bg-raised: #FFFDF7;
  --ink: #1E2A22;
  --ink-soft: #445347;
  --muted: #7C8F80;
  --line: #CFDAD0;
  --verified: #1F7A5C;
  --family: #B08344;
  --disputed: #B23B2E;
  --gap: #A7B3AC;

  --serif: "Spectral", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
}

*{ box-sizing: border-box; }

body{
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
}

/* header + legend stay fully responsive — only the tree itself doesn't reflow */
.site-head{
  max-width: 640px;
  margin: 0 auto;
  padding: 4rem 1.5rem 2rem;
  text-align: center;
}
.site-head__eyebrow{
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.75rem;
}
.site-head__title{
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  margin: 0 0 0.6rem;
  line-height: 1.15;
}
.site-head__sub{
  font-family: var(--serif);
  font-style: italic;
  color: var(--ink-soft);
  margin: 0;
  font-size: 1.05rem;
}

/* ---- tree: fixed-width canvas, pans/zooms instead of reflowing ---- */
.tree-outer{
  position: relative;
}

.tree-scroll{
  position: relative;
  overflow: auto;
  padding: 1rem 0 6rem;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

.tree-canvas{
  position: relative;
  width: max-content;
  min-width: 100%;
  margin: 0 auto;
  transform-origin: top center;
  padding: 0 1.5rem;
}

.connectors{
  position: absolute;
  top: 0; left: 0;
  pointer-events: none;
  z-index: 0;
}
.connectors path{
  fill: none;
  stroke: var(--line);
  stroke-width: 1.5;
}
.connectors path.to-family{ stroke: #DCCBA8; }
.connectors path.to-disputed{ stroke: #E3B8AE; }
.connectors path.to-gap{ stroke: var(--gap); stroke-dasharray: 3 4; }

.levels{
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.6rem;
  width: max-content;
  margin: 0 auto;
}

.level{
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  gap: 1.5rem 1.25rem;
}

.zoom-controls{
  position: fixed;
  right: 1.25rem;
  bottom: 4.5rem;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(30,42,34,0.12);
}
.zoom-controls button{
  width: 2.4rem;
  height: 2.4rem;
  border: none;
  background: transparent;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 1.1rem;
  cursor: pointer;
}
.zoom-controls button:last-child{ border-bottom: none; }
.zoom-controls button:hover{ background: var(--bg); color: var(--verified); }
#zoom-reset{ font-size: 0.68rem; }

.card{
  width: 190px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease, opacity 0.2s ease;
  position: relative;
}
.card:hover{
  border-color: var(--verified);
  box-shadow: 0 4px 14px rgba(31,122,92,0.12);
  transform: translateY(-1px);
}
.card:focus-visible{ outline: 2px solid var(--verified); outline-offset: 2px; }

.card--gap{
  background: transparent;
  border-style: dashed;
  cursor: default;
  box-shadow: none !important;
  transform: none !important;
}
.card--gap:hover{ border-color: var(--gap); }

/* selection state: the open card stands out, the rest recede */
.card.is-selected{
  border-color: var(--verified);
  border-width: 2px;
  background: #EAF5EF;
  box-shadow: 0 4px 16px rgba(31,122,92,0.22);
}
.card.is-dimmed{ opacity: 0.45; }
.card.is-dimmed:hover{ opacity: 0.7; }

.card__marker{
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  display: inline-block;
  margin-bottom: 0.4rem;
}
.card--verified .card__marker{ background: var(--verified); }
.card--family .card__marker{ background: var(--family); }
.card--disputed .card__marker{ background: var(--disputed); }
.card--gap .card__marker{ background: transparent; border: 1px dashed var(--gap); }
.card--known .card__marker{ background: var(--ink); }

.card__spouse-flag{
  position: absolute;
  top: 0.6rem;
  right: 0.7rem;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid var(--family);
}

.card__era{
  font-size: 0.72rem;
  color: var(--muted);
}
.card__name{
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1rem;
  margin: 0.15rem 0 0.1rem;
  line-height: 1.25;
}
.card__role{
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0;
}
.card__mother{
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0.3rem 0 0;
  font-style: italic;
}

/* ---- detail panel + flip card for spouse ---- */
.detail{
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: min(400px, 92vw);
  background: var(--bg-raised);
  border-left: 1px solid var(--line);
  padding: 3rem 1.75rem 2rem;
  overflow-y: auto;
  box-shadow: -8px 0 24px rgba(30,42,34,0.1);
  z-index: 30;
}
.detail__close{
  position: absolute;
  top: 1.25rem; right: 1.25rem;
  width: 2rem; height: 2rem;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.detail__close:hover{ color: var(--ink); }

.detail__tabs{
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
}
.detail__tab{
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-soft);
  border-radius: 999px;
  font-size: 0.82rem;
  cursor: pointer;
  font-family: var(--sans);
}
.detail__tab.is-active{
  background: var(--verified);
  border-color: var(--verified);
  color: #fff;
}

.detail__scene{ perspective: 1400px; }
.detail__flip{
  position: relative;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
}
.detail__flip.no-transition{ transition: none !important; }
.detail__flip.is-flipped{ transform: rotateY(180deg); }
.detail__face{ backface-visibility: hidden; }
.detail__face--back{
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  transform: rotateY(180deg);
}

#detail-body .card__name, #detail-body-spouse .card__name{ font-size: 1.4rem; }
#detail-body .bio, #detail-body-spouse .bio{ margin-top: 1rem; font-size: 0.95rem; color: var(--ink-soft); }
#detail-body .status, #detail-body-spouse .status{
  display: inline-block;
  margin-top: 0.9rem;
  font-size: 0.78rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.status--verified{ color: var(--verified); }
.status--family{ color: var(--family); }
.status--disputed{ color: var(--disputed); }
.status--gap{ color: var(--gap); }

.legend{
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  justify-content: center;
  padding: 0.9rem 1rem;
  background: var(--bg);
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.legend__item{ display: inline-flex; align-items: center; gap: 0.4rem; }
.dot{ width: 0.6rem; height: 0.6rem; border-radius: 50%; display: inline-block; }
.dot--verified{ background: var(--verified); }
.dot--family{ background: var(--family); }
.dot--disputed{ background: var(--disputed); }
.dot--gap{ background: transparent; border: 1px dashed var(--gap); }

@media (max-width: 560px){
  .detail{ width: 100vw; }
}
