/* Page « Nos ancêtres ». Complète css/style.css (polices, variables, thème vert).
   CSP : aucun style en ligne. */

.ancestors {
  width: min(100%, 960px);
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-right, 0px)) 56px max(16px, env(safe-area-inset-left, 0px));
}

.ancestors-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  padding-bottom: 16px;
}

.ancestors-back,
.ancestors-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--card-edge);
  border-radius: 12px;
  background: #ffffff;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.ancestors-back:hover,
.ancestors-button:hover {
  background: var(--accent-soft);
}

.ancestors a:focus-visible,
.ancestors button:focus-visible,
.ancestors summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.ancestors-back .icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Présentation */
.ancestors-intro {
  margin-bottom: 28px;
  padding: 22px 24px;
  border: 1px solid var(--glass-edge);
  border-radius: 16px;
  background: var(--glass-strong);
  box-shadow: var(--shadow-s);
}

.ancestors-lead {
  max-width: 62ch;
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  line-height: 1.45;
}

.ancestors-names {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 16px 0 0;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.ancestors-names span:not(.ancestors-arrow) {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.85rem;
}

.ancestors-arrow {
  color: var(--muted);
}

.ancestors-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin: 18px 0 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.85rem;
  list-style: none;
}

.ancestors-legend li {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.legend-direct,
.legend-sibling,
.legend-male,
.legend-female {
  width: 18px;
  height: 18px;
  border: 1px solid var(--card-edge);
  border-radius: 5px;
  background: var(--card);
}

.legend-direct {
  box-shadow: 0 0 0 2px var(--accent);
}

/* Code couleur homme / femme, comme dans le logiciel de généalogie. */
.legend-male,
.anc-person.is-male {
  border-color: #b8cde3;
  background: #edf3fa;
}

.legend-female,
.anc-person.is-female {
  border-color: #e6c3cf;
  background: #fbeff3;
}

.legend-couple {
  width: 22px;
  height: 2px;
  border-radius: 2px;
  background: var(--line);
}

.ancestors-legend .legend-uncertain {
  position: static;
}

.ancestors-hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.badge-uncertain {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid #e3b64a;
  border-radius: 999px;
  background: #fff6dd;
  color: #7a5a00;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}

/* --- Arbre : même vignettes et traits que l'arbre de la famille --- */
.ancestors-main {
  width: 100vw;
  margin-left: calc(50% - 50vw);
}

.anc-tree-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 0 24px;
  scrollbar-width: none;
  cursor: grab;
}

.anc-tree-wrapper::-webkit-scrollbar {
  display: none;
}

.anc-tree-wrapper.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.anc-tree {
  position: relative;
  margin: 0 auto;
}

.anc-tree .connections {
  z-index: 0;
}

.anc-tree .connection.is-direct {
  stroke: #8db596;
  stroke-width: 2.5;
}

.anc-tree .connection.is-hi {
  stroke: var(--accent);
  stroke-width: 2.75;
}

/* Vignette plus compacte que dans l'arbre : dix générations à faire tenir. */
.anc-person {
  position: absolute;
  z-index: 1;
  display: block;
  width: 116px;
  padding: 10px 6px;
  color: var(--text);
  font: inherit;
}

/* Médaillon : seulement pour les ancêtres qui ont un portrait, posé sur le coin de la vignette. */
.anc-avatar {
  position: absolute;
  top: -36px;
  left: calc(50% - 22px);
  display: block;
  width: 44px;
  height: 44px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--card-edge), 0 4px 10px -4px rgba(30, 70, 48, 0.55);
}

.anc-avatar-photo {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 28%;
}

.anc-person .person-name {
  font-size: 0.86rem;
}

.anc-person.is-direct {
  border-color: rgba(44, 90, 65, 0.35);
  box-shadow: 0 0 0 2px var(--accent), var(--shadow-s);
}

.anc-person.is-lineage {
  box-shadow: 0 0 0 3px var(--sage), var(--shadow-m);
}

.anc-person:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.anc-last {
  display: block;
  margin-top: 2px;
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.2;
  overflow-wrap: anywhere;
  text-transform: uppercase;
}

.anc-years {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.anc-uncertain {
  position: absolute;
  top: -8px;
  right: -8px;
  display: inline-grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 1px solid #e3b64a;
  border-radius: 50%;
  background: #fff6dd;
  color: #7a5a00;
  font-size: 0.75rem;
  font-weight: 800;
}

.anc-couple-line {
  position: absolute;
  z-index: 0;
}

.anc-marriage {
  position: absolute;
  z-index: 2;
  padding: 1px 6px;
  border: 1px solid var(--card-edge);
  border-radius: 999px;
  background: var(--panel);
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 700;
  white-space: nowrap;
  transform: translateX(-50%);
}

/* --- Colonne des générations, fixe à gauche, et bandes de fond --- */
.ancestors-main {
  position: relative;
}

.anc-tree-wrapper {
  position: relative;
  z-index: 1;
}

.anc-bands,
.anc-gen-column {
  position: absolute;
  left: 0;
  pointer-events: none;
}

.anc-bands {
  right: 0;
  z-index: 0;
}

.anc-band {
  position: absolute;
  left: 0;
  right: 0;
}

/* Différence volontairement très légère : on devine les étages sans être dérangé. */
.anc-band.is-tinted {
  background: rgba(44, 90, 65, 0.04);
}

.anc-gen-column {
  z-index: 2;
  width: 224px;
  border-right: 1px solid var(--border);
  background: rgba(247, 251, 248, 0.9);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.anc-band-column.is-tinted {
  background: rgba(44, 90, 65, 0.06);
}

.anc-gen-label {
  position: absolute;
  left: 16px;
  right: 12px;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  column-gap: 10px;
  color: var(--text);
  transform: translateY(-50%);
  pointer-events: auto;
}

.anc-gen-label.has-thumb {
  grid-template-columns: 84px minmax(0, 1fr);
}

.anc-gen-label .anc-history {
  grid-column: 1 / -1;
}

.anc-gen-head {
  display: grid;
  gap: 2px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: default;
}

/* Vignette de l'image historique : un clic l'agrandit. */
.anc-gen-thumb {
  display: block;
  padding: 0;
  border: 1px solid var(--card-edge);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow-s, 0 1px 3px rgba(0, 0, 0, 0.12));
  cursor: zoom-in;
}

.anc-gen-thumb img {
  display: block;
  width: 84px;
  height: 63px;
  object-fit: cover;
  transition: transform 0.2s ease;
}

.anc-gen-thumb:hover img {
  transform: scale(1.06);
}

.ancestors .anc-gen-head:focus-visible,
.ancestors .anc-gen-thumb:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

.anc-gen-number {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 500;
}

.anc-gen-short {
  display: none;
}

.anc-gen-period {
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-style: italic;
}

/* Repères historiques sous le libellé de génération. */
.anc-history {
  display: grid;
  gap: 3px;
  margin: 6px 0 0;
  padding: 6px 0 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.3;
  list-style: none;
}

.anc-history b {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.anc-world {
  display: inline-block;
  margin-left: 5px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: 1px;
}

/* Téléphone : colonne étroite (« Gén. 10 », année) ; un toucher déplie les repères. */
@media (max-width: 700px) {
  .anc-gen-column {
    width: 68px;
  }

  .anc-gen-label,
  .anc-gen-label.has-thumb {
    left: 8px;
    right: 6px;
    grid-template-columns: minmax(0, 1fr);
  }

  .anc-gen-head {
    cursor: pointer;
  }

  .anc-gen-thumb {
    display: none;
  }

  .anc-gen-word {
    display: none;
  }

  .anc-gen-short {
    display: inline;
  }

  .anc-gen-number {
    font-size: 0.85rem;
  }

  .anc-gen-period {
    font-size: 0.72rem;
  }

  .anc-history {
    display: none;
  }

  .anc-gen-label.is-open {
    right: auto;
    width: min(260px, calc(100vw - 32px));
    padding: 10px 12px;
    border: 1px solid var(--card-edge);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: var(--shadow-m);
  }

  .anc-gen-label.is-open .anc-gen-word {
    display: inline;
  }

  .anc-gen-label.is-open .anc-gen-short {
    display: none;
  }

  .anc-gen-label.is-open .anc-history {
    display: grid;
  }

  .anc-gen-label.is-open.has-thumb {
    grid-template-columns: 84px minmax(0, 1fr);
  }

  .anc-gen-label.is-open .anc-gen-thumb {
    display: block;
  }
}

/* --- Photos dans la fiche : portrait + bande de miniatures --- */
.anc-dialog-media {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  margin: 0 0 14px;
}

.anc-dialog-photo-button,
.anc-gallery-thumb {
  display: block;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--card-edge), var(--shadow-s);
  cursor: zoom-in;
}

.anc-dialog-photo {
  display: block;
  width: 150px;
  height: auto;
}

.anc-gallery {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 28px;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.anc-gallery-track {
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 4px 2px;
  overflow-x: auto;
  list-style: none;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.anc-gallery-track::-webkit-scrollbar {
  display: none;
}

.anc-gallery-track li {
  flex: none;
  scroll-snap-align: start;
}

.anc-gallery-thumb {
  border-radius: 8px;
}

.anc-gallery-thumb img {
  display: block;
  width: 84px;
  height: 112px;
  object-fit: cover;
  transition: transform 0.2s ease;
}

.anc-gallery-thumb:hover img,
.anc-dialog-photo-button:hover img {
  transform: scale(1.04);
}

.anc-dialog-photo-button img {
  transition: transform 0.2s ease;
}

.anc-gallery-nav,
.photo-dialog-nav {
  display: grid;
  place-items: center;
  padding: 0;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  background: var(--panel);
  color: var(--accent);
  cursor: pointer;
}

.anc-gallery-nav {
  width: 28px;
  height: 28px;
}

.anc-gallery-nav:disabled {
  opacity: 0.3;
  cursor: default;
}

.anc-gallery-nav .icon,
.photo-dialog-nav .icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ancestors .anc-dialog-photo-button:focus-visible,
.ancestors .anc-gallery-thumb:focus-visible,
.ancestors .anc-gallery-nav:focus-visible,
.ancestors .photo-dialog-nav:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Badge « +n » sur le médaillon quand l'ancêtre a d'autres photos. */
.anc-photo-count {
  position: absolute;
  right: -16px;
  bottom: -2px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(21, 34, 27, 0.72);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.5;
}

/* --- Visionneuse --- */
.photo-dialog {
  width: min(920px, calc(100vw - 24px));
  padding: 0;
  overflow: hidden;
  background: #15221b;
  color: #fff;
}

.photo-dialog-figure {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 240px;
  margin: 0;
  touch-action: pan-y;
  user-select: none;
}

.photo-dialog-image {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 140px);
  width: auto;
  height: auto;
}

.photo-dialog-nav {
  position: absolute;
  top: 50%;
  width: 42px;
  height: 42px;
  transform: translateY(-50%);
  box-shadow: var(--shadow-m);
}

.photo-dialog-nav.is-prev {
  left: 12px;
}

.photo-dialog-nav.is-next {
  right: 12px;
}

.photo-dialog-nav[hidden] {
  display: none;
}

.photo-dialog-nav .icon {
  width: 20px;
  height: 20px;
}

.photo-dialog-caption {
  display: flex;
  gap: 12px;
  align-items: baseline;
  margin: 0;
  padding: 12px 18px 14px;
  font-size: 0.9rem;
}

.photo-dialog-count {
  color: rgba(255, 255, 255, 0.65);
  font-variant-numeric: tabular-nums;
}

.photo-dialog-count:empty {
  display: none;
}

.photo-dialog .person-dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  margin: 0;
}

@media (max-width: 560px) {
  .anc-dialog-media {
    flex-direction: column;
    align-items: stretch;
  }

  .anc-dialog-photo-button {
    align-self: flex-start;
  }
}

/* --- Image historique agrandie --- */
.history-dialog {
  width: min(720px, calc(100vw - 24px));
  padding: 0;
  overflow: hidden;
}

.history-dialog-figure {
  margin: 0;
}

.history-dialog-image {
  display: block;
  width: 100%;
  height: auto;
  background: var(--border);
}

.history-dialog figcaption {
  display: grid;
  gap: 4px;
  padding: 14px 18px 18px;
}

.history-dialog-caption {
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.history-dialog-credit {
  color: var(--muted);
  font-size: 0.78rem;
}

.history-dialog-credit a {
  color: var(--accent);
}

.history-dialog .person-dialog-close {
  position: absolute;
  top: 10px;
  right: 10px;
  margin: 0;
  box-shadow: var(--shadow-m);
}

/* --- Fiche d'un ancêtre --- */
.anc-dialog {
  overflow: auto;
  max-height: calc(100vh - 48px);
}

.anc-dialog-body {
  padding: 28px 28px 24px;
}

.anc-dialog-body h2 {
  margin: 0 90px 0 0;
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 500;
  line-height: 1.15;
}

.anc-dialog-dates {
  margin: 10px 0 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: pre-wrap;
}

.anc-dialog-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 0;
}

.anc-tag,
.anc-tag-direct {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
}

.anc-tag-direct {
  background: var(--accent);
  color: #ffffff;
}

.anc-dialog-note {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.anc-relations {
  margin-top: 18px;
}

.anc-relations h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.anc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.anc-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--card-edge);
  border-radius: 10px;
  background: var(--background);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.anc-chip span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 400;
}

.anc-chip.is-direct {
  border-color: rgba(44, 90, 65, 0.4);
  background: var(--accent-soft);
  color: var(--accent);
}

.anc-chip:hover {
  border-color: var(--accent);
}

.anc-chip:focus-visible,
.anc-dialog .person-dialog-close:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.anc-dialog .person-dialog-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--panel);
  cursor: pointer;
}

.anc-dialog-tree {
  margin-top: 22px;
}

.ancestors-message {
  padding: 28px;
  border: 1px solid var(--card-edge);
  border-radius: 14px;
  background: var(--card);
  text-align: center;
}

.ancestors-message h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 500;
}

.ancestors-message p {
  margin: 0 0 16px;
  color: var(--muted);
}

.ancestors-main:has(.ancestors-message) {
  width: auto;
  margin-left: 0;
}

.ancestors-source {
  margin-top: 36px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

@media (max-width: 560px) {
  .ancestors-intro {
    padding: 18px;
  }

  .ancestors-lead {
    font-size: 1.05rem;
  }

  .anc-dialog-body {
    padding: 22px 18px 18px;
  }
}

/* L'arbre occupe toute la largeur de la fenêtre (100vw inclut la barre de défilement). */
.ancestors-body {
  overflow-x: clip;
}

html:has(.ancestors-body) {
  overflow-x: clip;
}

/* Survol : la vignette passe en vert comme dans l'arbre, ses textes restent lisibles. */
@media (hover: hover) and (pointer: fine) {
  .anc-person.is-male:hover,
  .anc-person.is-female:hover {
    border-color: var(--accent);
    background: var(--accent);
  }

  .anc-person:hover .anc-last,
  .anc-person:hover .anc-years {
    color: rgba(255, 255, 255, 0.86);
  }
}

