/* ═══════════════════════════════════════════════════════════════════
   tree.css — the family tree

   The tree is drawn in three stacked layers inside one canvas:

     1. <svg class="tree__lines">   the connector lines
     2. <div class="tree__nodes">   the person cards, absolutely placed
     3. the canvas itself carries a single CSS transform for pan + zoom

   Laying the cards out in JavaScript and drawing the lines as SVG keeps
   the two perfectly in step — a card never drifts away from its line,
   because both are positioned from the same numbers.
   ═══════════════════════════════════════════════════════════════════ */

/* ═══ VIEW SWITCH ═══════════════════════════════════════════════════ */
.view-switch {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--divider);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-sm);
}
.view-switch button {
  border: 0;
  background: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: .86rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-soft);
  padding: 9px 18px;
  border-radius: var(--r-pill);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: color var(--t-fast), background var(--t-fast);
}
.view-switch button[aria-pressed="true"] {
  background: var(--grad-gold);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
@media (hover: hover) and (pointer: fine) {
  .view-switch button:not([aria-pressed="true"]):hover { color: var(--brown); }
}

/* ═══ THE FRAME ═════════════════════════════════════════════════════
   A fixed-height window the canvas is dragged around inside. Height is
   capped against the viewport so the controls never leave the screen. */
.tree {
  position: relative;
  height: min(74vh, 760px);
  min-height: 420px;
  border: 1px solid var(--divider);
  border-radius: var(--r-lg);
  background:
    radial-gradient(90% 70% at 50% 0%, rgba(232, 190, 106, .13), transparent 70%),
    var(--cream);
  overflow: hidden;
  /* Stops the browser from claiming the drag as a page scroll or a
     pinch-to-zoom of the whole page. Without this the tree barely
     moves on a phone.                                               */
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.tree.is-dragging { cursor: grabbing; }

.tree__canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}
/* Only animate when the view is being reset, never while dragging —
   a transition during a drag feels like the tree is lagging behind
   your finger.                                                      */
.tree__canvas.is-easing { transition: transform .42s var(--ease); }

.tree__lines {
  position: absolute;
  top: 0;
  left: 0;
  overflow: visible;
  pointer-events: none;
}
.tree__nodes { position: relative; }

/* ═══ CONNECTOR LINES ═══════════════════════════════════════════════ */
.tree__lines path {
  fill: none;
  stroke: var(--divider);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke var(--t-fast), stroke-width var(--t-fast);
}
/* The horizontal bar joining a husband and wife sits slightly heavier
   and in gold — it is the one line that means "married", not
   "descended from".                                                 */
.tree__lines path.bond {
  stroke: var(--gold);
  stroke-width: 2.5;
}
.tree__lines path.is-lit {
  stroke: var(--gold);
  stroke-width: 3.5;
}
.tree__lines path.bond.is-lit { stroke: var(--gold-bright); }

/* ═══ PERSON CARD ═══════════════════════════════════════════════════ */
.tnode {
  position: absolute;
  width: 168px;
  box-sizing: border-box;
  padding: 16px 12px 14px;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--divider);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast),
              border-color var(--t-fast);
}
@media (hover: hover) and (pointer: fine) {
  .tnode:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-card);
    border-color: var(--gold-bright);
  }
}
.tnode:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* The lit state belongs to everyone on the hovered person's direct
   line of ancestry, so it has to read clearly without shouting.     */
.tnode.is-lit {
  border-color: var(--gold);
  box-shadow: var(--shadow-gold);
}
/* Everyone NOT on that line recedes, which is what actually makes the
   lineage legible — the glow alone is not enough on a crowded tree. */
.tree.is-tracing .tnode:not(.is-lit) { opacity: .38; }
.tree.is-tracing .tree__lines path:not(.is-lit) { opacity: .3; }

.tnode__photo {
  width: 68px;
  height: 68px;
  margin: 0 auto 10px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--grad-gold);
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 3px var(--card), 0 0 0 4px var(--divider);
  transition: box-shadow var(--t-fast);
}
.tnode.is-lit .tnode__photo { box-shadow: 0 0 0 3px var(--card), 0 0 0 4px var(--gold); }
.tnode__photo img { width: 100%; height: 100%; object-fit: cover; }
.tnode__photo .initials {
  font-family: var(--font-heading);
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
}

.tnode__name {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--dark-brown);
  margin-bottom: 2px;
  overflow-wrap: anywhere;
}
.tnode__gu {
  font-family: var(--font-gu);
  font-size: .8rem;
  color: var(--gold-deep);
  line-height: 1.4;
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}
.tnode__relation {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--warm-gray);
}
.tnode__years {
  font-size: .74rem;
  color: var(--text-soft);
  margin-top: 5px;
  font-style: italic;
}

/* ═══ IN LOVING MEMORY ══════════════════════════════════════════════
   Deliberately gentle: a softer card, a small diya, and years instead
   of a birthday countdown. No black, no heavy borders.              */
.tnode--remembered {
  background: linear-gradient(170deg, #FFFDF9 0%, #FBF3E6 100%);
  border-style: dashed;
  border-color: #DCC9A6;
}
.tnode--remembered .tnode__photo {
  background: linear-gradient(135deg, #D9C7A4 0%, #BFA880 100%);
  filter: saturate(.72);
}
.tnode__memorial {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--gold-deep);
}
.tnode__memorial i { font-size: .8rem; }

/* ═══ THE MEMORIAL TICKBOX ON THE FORM ══════════════════════════════ */
.memorial-check {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 16px;
  border: 1px dashed var(--divider);
  border-radius: var(--r-md);
  background: var(--cream);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--text-soft);
  transition: border-color var(--t-fast), background var(--t-fast);
}
.memorial-check input { width: 18px; height: 18px; accent-color: var(--gold-deep); flex: 0 0 auto; }
.memorial-check i { color: var(--gold-deep); margin-right: 3px; }
.memorial-check:has(input:checked) {
  border-color: var(--gold);
  background: #FBF3E6;
  color: var(--brown);
}

/* ═══ CONTROLS ══════════════════════════════════════════════════════ */
.tree__controls {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 3;
}
.tree__controls button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--divider);
  border-radius: var(--r-sm);
  background: var(--card);
  color: var(--brown);
  cursor: pointer;
  font-size: .95rem;
  box-shadow: var(--shadow-sm);
  transition: background var(--t-fast), color var(--t-fast);
}
@media (hover: hover) and (pointer: fine) {
  .tree__controls button:hover { background: var(--grad-gold); color: #fff; }
}

.tree__hint {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--r-pill);
  background: rgba(255, 251, 244, .92);
  border: 1px solid var(--divider);
  font-size: .78rem;
  color: var(--text-soft);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  transition: opacity var(--t);
}
.tree__hint.is-gone { opacity: 0; }

/* ═══ GENERATION BANDS ══════════════════════════════════════════════
   Faint labels down the left of the canvas so a deep tree still tells
   you which layer you are looking at.                                */
.tband {
  position: absolute;
  left: 0;
  font-family: var(--font-heading);
  font-size: .8rem;
  font-style: italic;
  color: var(--warm-gray);
  white-space: nowrap;
  pointer-events: none;
  opacity: .75;
}
.tband span {
  font-family: var(--font-gu);
  font-style: normal;
  color: var(--gold-deep);
  margin-left: 6px;
}

/* ═══ PHONES ════════════════════════════════════════════════════════
   The cards shrink a little so more of the tree fits before you need
   to drag. The layout numbers in tree.js read these same values.     */
@media (max-width: 640px) {
  .tree { height: min(68vh, 560px); }
  .tnode { width: 136px; padding: 12px 9px 11px; }
  .tnode__photo { width: 54px; height: 54px; margin-bottom: 8px; }
  .tnode__name { font-size: .88rem; }
  .tnode__gu { font-size: .72rem; }
  .tnode__relation { font-size: .64rem; }
  .tree__hint { display: none; }
}

/* ═══ PRINTING ══════════════════════════════════════════════════════
   A dragged-and-zoomed canvas prints as whatever happened to be on
   screen, so printing the tree is not offered. The card list prints
   properly instead.                                                  */
@media print {
  .tree, .view-switch { display: none !important; }
}
