/* Árvore e cartas da família. */
.family-page {
  min-height: calc(100svh - 110px);
  padding: 55px clamp(20px, 5vw, 72px) 70px;
  background: #fff1e6;
  color: #314e49;
  text-align: center;
}
.family-heading .eyebrow { color: #437a77; margin: 0 0 10px; }
.family-heading h1 {
  margin: 0;
  font: 400 clamp(42px, 5vw, 64px) / 1.1 Garamond, Georgia, serif;
  font-variant: small-caps;
  letter-spacing: .035em;
}
.family-heading .ornament { margin: 18px auto; }
.family-subtitle { color: #55776b; font: italic 21px Garamond, Georgia, serif; margin: 0; }
.family-tree-viewport { overflow: auto; max-width: 100%; margin: 36px auto 0; border: 1px solid #d6bd9555; background: #fff9f1; }
.family-tree { min-width: max-content; position: relative; padding: 58px 48px; }
.family-generations { position: relative; z-index: 1; display: grid; gap: 100px; }
.family-row { display: flex; justify-content: center; gap: clamp(42px, 6vw, 100px); }
.family-connections { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.family-connections path { fill: none; stroke: #ba9655; stroke-width: 1.5; }
.family-letter {
  width: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  border: 0;
  background: transparent;
  padding: 0 8px 14px;
  color: #314e49;
  cursor: pointer;
  transition: transform .25s ease, filter .25s ease;
}
.family-letter:hover { transform: translateY(-6px); filter: drop-shadow(0 9px 10px #835c3130); }
.family-letter img { display: block; width: 145px; height: 145px; object-fit: contain; image-rendering: pixelated; }
.family-name { color: #245c58; font: 400 25px Garamond, Georgia, serif; font-variant: small-caps; }
.family-role { margin-top: 5px; color: #8e744e; font: 9px Cinzel, serif; letter-spacing: .14em; }
.family-note { margin: 24px 0 0; color: #698277; font: italic 17px Garamond, Georgia, serif; }
.letter-dialog { width: min(500px, calc(100% - 40px)); padding: 0; border: 1px solid #c5a779; background: #fff8eb; color: #314e49; }
.letter-dialog::backdrop { background: #091e1cbb; }
.letter-paper { position: relative; text-align: center; margin: 10px; padding: 55px 32px; border: 1px solid #e1cfad; }
.letter-paper .eyebrow { color: #a18353; }
.letter-paper h2 { margin: 12px 0; color: #245c58; font: 400 42px Garamond, Georgia, serif; font-variant: small-caps; }
.letter-role { color: #8e744e; font: 11px Cinzel, serif; letter-spacing: .12em; }
.letter-description { font: 20px / 1.5 Garamond, Georgia, serif; }
.letter-close { position: absolute; top: 10px; right: 12px; border: 0; background: transparent; color: #245c58; font: 30px Garamond, serif; cursor: pointer; }
@media (max-width: 680px) {
  .family-page { padding: 95px 15px 50px; }
  .family-tree { padding: 38px 20px; }
  .family-row { gap: 14px; }
  .family-letter { width: 145px; }
  .family-letter img { width: 120px; height: 120px; }
}
@media (prefers-reduced-motion: reduce) { .family-letter { transition: none; } .family-letter:hover { transform: none; } }

/* Grupos e controles da árvore completa. */
.family-controls { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 28px; }
.family-controls button { width: 36px; height: 36px; border: 1px solid #b99d72; background: transparent; color: #286e6b; font: 23px Garamond, serif; cursor: pointer; }
.family-controls button:disabled { opacity: .35; cursor: default; }
.family-controls span { min-width: 45px; font: 15px Garamond, serif; color: #526a61; }
.family-tree-viewport { margin-top: 16px; max-height: 75vh; }
.family-row { gap: 48px; }
.family-group { display: flex; align-items: start; gap: 20px; }
.family-name { max-width: 180px; line-height: 1.05; overflow-wrap: anywhere; }
.letter-description { white-space: pre-line; }
@media (max-width: 680px) { .family-row { gap: 30px; } .family-group { gap: 10px; } }

/* A árvore funciona como uma área de arraste e zoom. */
.family-tree-viewport {
  margin-top: 36px;
  height: min(75vh, 700px);
  overflow: auto;
  scrollbar-width: none;
  cursor: grab;
  touch-action: none;
  overscroll-behavior: contain;
}
.family-tree-viewport::-webkit-scrollbar { display: none; }
.family-tree-viewport.dragging { cursor: grabbing; user-select: none; }
.family-letter { touch-action: manipulation; }

/* Pessoas sem vínculo confirmado ficam separadas das gerações. */
.family-row:has(.family-unconfirmed) { position: relative; padding-top: 45px; }
.family-unconfirmed { position: absolute; top: 0; left: 0; right: 0; margin: 0; color: #698277; font: italic 17px Garamond, Georgia, serif; }

/* O título e a árvore ocupam a altura disponível da tela. */
.family-page {
  height: 100svh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 24px clamp(16px, 2vw, 30px) 20px;
}
.family-heading { flex: none; }
.family-tree-viewport {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  height: auto;
  width: 100%;
  margin: 18px auto 0;
}
@media (max-width: 680px) {
  .family-page { padding: 68px 12px 12px; }
  .family-tree-viewport { margin-top: 12px; }
}

/* Mais espaço entre gerações e entre ramos independentes. */
.family-generations { gap: 220px; }
.family-row { gap: 90px; }
.family-group { gap: 28px; }
@media (max-width: 680px) {
  .family-generations { gap: 190px; }
  .family-row { gap: 65px; }
  .family-group { gap: 18px; }
}

/* A legenda diferencia o parentesco mantendo o estilo das linhas. */
.family-connections .indirect-label { fill: #a88144; font: 15px Garamond, Georgia, serif; text-anchor: middle; paint-order: stroke; stroke: #fff9f1; stroke-width: 5px; stroke-linejoin: round; }


/* Teste da JMH Typewriter nos textos. */
html body :is(p, a, button, label, input, select, .family-name, .family-role, .council-coin-face) { font-family: "JMH Typewriter", Garamond, serif; }

/* Fonte dos títulos. */
.family-heading h1 { font-family: "The Inquisition", Garamond, serif; font-variant: normal; }

/* Movimento suave dos retratos dos membros. */
.family-portrait { transition: transform .35s ease; }
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .family-letter:hover .family-portrait { transform: translateY(-4px) rotate(3deg); }
}
@media (prefers-reduced-motion: reduce) { .family-portrait { transition: none; } }
