/* ============================================================
   Lindstrøm family tree — styles
   ============================================================ */

:root {
  --ink: #2e2418;
  --paper: #f6f1e7;
  --gold: #c9a227;
  --leaf: #6fa15c;
  --leaf-deep: #46753a;
  --bark: #6b4f35;
  --male: #7fb4d9;
  --female: #e8a0b4;
  --nonbinary: #c0a5e8;
  --panel-bg: rgba(250, 247, 240, 0.94);
  --shadow: 0 18px 50px rgba(46, 36, 24, 0.28);
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Nunito Sans", -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--sans);
  color: var(--ink);
  background: #cfc8ba;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Atmosphere ---------- */

#sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(110% 80% at 28% 18%, rgba(238, 232, 221, 0.85) 0%, rgba(238, 232, 221, 0) 55%),
    radial-gradient(95% 75% at 74% 78%, rgba(186, 175, 158, 0.6) 0%, rgba(186, 175, 158, 0) 60%),
    radial-gradient(60% 50% at 60% 35%, rgba(214, 199, 180, 0.5) 0%, rgba(214, 199, 180, 0) 65%),
    linear-gradient(180deg, #d9d3c7 0%, #cfc8ba 50%, #c2b9a8 100%);
  animation: skydrift 60s ease-in-out infinite alternate;
}

@keyframes skydrift {
  from { filter: brightness(1) saturate(1); }
  to   { filter: brightness(1.04) saturate(0.94); }
}

/* Pale patches drifting like impasto strokes on plaster. */
.cloud {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(244, 238, 227, 0.7), rgba(244, 238, 227, 0));
  filter: blur(10px);
  opacity: 0.5;
  animation: clouddrift linear infinite;
}

.cloud.c1 { width: 42vw; height: 14vh; top: 8%;  animation-duration: 95s; }
.cloud.c2 { width: 30vw; height: 10vh; top: 22%; animation-duration: 140s; animation-delay: -60s; opacity: 0.55; }
.cloud.c3 { width: 52vw; height: 16vh; top: 4%;  animation-duration: 180s; animation-delay: -110s; opacity: 0.45; }

@keyframes clouddrift {
  from { transform: translateX(-60vw); }
  to   { transform: translateX(160vw); }
}

#particles {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

/* ---------- Stage ---------- */

#stage {
  position: fixed;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#stage.dragging { cursor: grabbing; }

/* ---------- Tree elements (SVG) ---------- */

.branch { pointer-events: none; }

.node { cursor: pointer; }

/* No browser focus box on click — keyboard focus glows instead. */
.node:focus { outline: none; }
.node:focus-visible .portrait-ring {
  filter: drop-shadow(0 0 10px rgba(201, 162, 39, 0.85));
}

.node .portrait-ring {
  transition: stroke-width 0.35s ease, filter 0.35s ease;
}

.node:hover .portrait-ring,
.node.selected .portrait-ring {
  filter: drop-shadow(0 0 10px rgba(201, 162, 39, 0.85));
}

.node text {
  font-family: var(--serif);
  fill: #3a2e1f;
  paint-order: stroke;
  stroke: rgba(246, 241, 231, 0.85);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

.node .name { font-size: 18px; font-weight: 600; letter-spacing: 0.02em; }
.node .surname { font-size: 15px; font-weight: 500; fill: #55462f; font-family: var(--serif); }
.node .dates { font-size: 12.5px; font-family: var(--sans); font-weight: 400; fill: #6b5c46; }

/* Pets: smaller, warmer nodes with a species badge. */
.node.pet .pet-name { font-size: 14px; }
.node.pet .dates { font-size: 10.5px; }
.pet-badge { font-size: 11px; pointer-events: none; stroke: none; }

/* Relationship years resting on the couple's vine. */
.rel-dates {
  font-family: var(--sans);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  fill: #8a6d4a;
  paint-order: stroke;
  stroke: rgba(246, 241, 231, 0.85);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

.rel-dates.ended { fill: #a2937e; font-weight: 400; }

/* Family-name plaques where a new lineage branches off. */
.lineage-label {
  font-family: var(--serif);
  font-size: 30px;
  font-style: italic;
  font-weight: 500;
  letter-spacing: 0.2em;
  fill: #7a6248;
  opacity: 0;
  transition: opacity 2.2s ease;
  paint-order: stroke;
  stroke: rgba(228, 221, 208, 0.75);
  stroke-width: 4px;
  stroke-linejoin: round;
  pointer-events: none;
}

.lineage-label.visible { opacity: 0.85; }

.tendril { pointer-events: none; }
.bloom-burst { pointer-events: none; }
.ground { pointer-events: none; }

.bud { cursor: pointer; }
.bud circle.pulse {
  animation: budpulse 2.2s ease-in-out infinite;
  transform-origin: center;
  transform-box: fill-box;
}

@keyframes budpulse {
  0%, 100% { transform: scale(1);   opacity: 0.85; }
  50%      { transform: scale(1.45); opacity: 0.35; }
}

.leaf-cluster { pointer-events: none; }

/* ---------- Masthead ---------- */

#masthead {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  left: 0;
  right: 0;
  z-index: 5;
  text-align: center;
  pointer-events: none;
  transition: opacity 1.2s ease, transform 1.2s ease;
}

#masthead h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.2rem, 6vw, 3.6rem);
  letter-spacing: 0.14em;
  color: #3b2f20;
  text-shadow: 0 2px 18px rgba(255, 252, 240, 0.9);
}

#masthead p {
  margin: 0.15em 0 0;
  font-size: clamp(0.8rem, 2.4vw, 1rem);
  font-style: italic;
  font-family: var(--serif);
  color: #6b5c46;
}

#masthead.faded { opacity: 0.35; transform: translateY(-6px); }

/* ---------- Controls ---------- */

#controls {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#controls button {
  width: 46px;
  height: 46px;
  border: 1px solid rgba(107, 79, 53, 0.25);
  border-radius: 50%;
  background: var(--panel-bg);
  color: var(--ink);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(46, 36, 24, 0.18);
  backdrop-filter: blur(6px);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#controls button:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(46, 36, 24, 0.26); }
#controls button:active { transform: scale(0.96); }

/* ---------- Hint ---------- */

#hint {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
  padding: 9px 20px;
  border-radius: 999px;
  background: var(--panel-bg);
  border: 1px solid rgba(107, 79, 53, 0.2);
  box-shadow: 0 4px 16px rgba(46, 36, 24, 0.15);
  font-size: 0.85rem;
  color: #5b4c38;
  pointer-events: none;
  transition: opacity 0.8s ease;
  max-width: min(80vw, 420px);
  text-align: center;
}

#hint.hidden { opacity: 0; }

/* ---------- Detail panel ---------- */

#panel {
  position: fixed;
  z-index: 8;
  top: 0;
  right: 0;
  height: 100%;
  width: min(420px, 100vw);
  background: var(--panel-bg);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-left: 1px solid rgba(107, 79, 53, 0.15);
}

#panel.open { transform: translateX(0); }

/* Fading edge hints that the panel content scrolls. */
#panel::after {
  content: "";
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 44px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(250, 247, 240, 0) 0%, rgba(250, 247, 240, 0.95) 90%);
}

#panel-close {
  position: sticky;
  top: 12px;
  margin: 12px 12px 0 auto;
  display: block;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(107, 79, 53, 0.12);
  color: var(--ink);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: background 0.2s ease, transform 0.2s ease;
}

#panel-close:hover { background: rgba(107, 79, 53, 0.22); transform: rotate(90deg); }

#panel-content { padding: 0 28px 40px; }

.panel-portrait {
  width: 168px;
  height: 168px;
  margin: 4px auto 18px;
  border-radius: 50%;
  overflow: hidden;
  border: 4px solid var(--gold);
  box-shadow: 0 10px 30px rgba(46, 36, 24, 0.3);
  background: #e8e0d0;
}

.panel-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.panel-name {
  margin: 0;
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.1;
}

.panel-dates {
  margin: 6px 0 2px;
  text-align: center;
  color: #6b5c46;
  font-size: 0.95rem;
}

.panel-gender {
  text-align: center;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #8a7a62;
  margin-bottom: 18px;
}

.panel-gender .dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: baseline;
}

.panel-bio {
  line-height: 1.65;
  color: #4a3d2c;
  border-top: 1px solid rgba(107, 79, 53, 0.15);
  padding-top: 16px;
  margin-bottom: 18px;
  font-family: var(--serif);
  font-size: 1.05rem;
}

.panel-section h3 {
  margin: 18px 0 8px;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #8a7a62;
  font-weight: 700;
}

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

.relation-chips button {
  border: 1px solid rgba(107, 79, 53, 0.25);
  background: rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.88rem;
  font-family: var(--sans);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.25;
}

.relation-chips button .chip-dates {
  font-size: 0.72rem;
  color: #8a7a62;
  font-style: italic;
}

.relation-chips button:hover {
  background: rgba(201, 162, 39, 0.18);
  transform: translateY(-1px);
}

.panel-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.panel-gallery img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.2s ease, transform 0.2s ease;
  background: #e8e0d0;
}

.panel-gallery img:hover { transform: scale(1.05); }
.panel-gallery img.active { border-color: var(--gold); }

/* ---------- Loading veil ---------- */

#veil {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: linear-gradient(180deg, #d9d3c7, #c2b9a8);
  transition: opacity 1s ease;
}

#veil.lifted { opacity: 0; pointer-events: none; }

#veil p {
  font-family: var(--serif);
  font-style: italic;
  color: #6b5c46;
  font-size: 1.1rem;
}

.seed {
  width: 16px;
  height: 22px;
  background: var(--bark);
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  animation: seedpulse 1.4s ease-in-out infinite;
}

@keyframes seedpulse {
  0%, 100% { transform: scale(1) translateY(0); }
  50%      { transform: scale(1.18) translateY(-6px); }
}

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
  #panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: min(72vh, 620px);
    border-left: none;
    border-top: 1px solid rgba(107, 79, 53, 0.15);
    border-radius: 22px 22px 0 0;
    transform: translateY(105%);
  }

  #panel.open { transform: translateY(0); }

  #panel::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 44px;
    height: 5px;
    border-radius: 3px;
    background: rgba(107, 79, 53, 0.3);
  }

  #panel-content { padding: 0 20px 40px; }
  .panel-portrait { width: 128px; height: 128px; }
  .panel-name { font-size: 1.6rem; }

  #controls { bottom: max(84px, env(safe-area-inset-bottom)); }
  #controls button { width: 42px; height: 42px; }
  #hint { font-size: 0.78rem; }
}

@media (prefers-reduced-motion: reduce) {
  #sky { animation: none; }
  .cloud { animation: none; }
  .bud circle.pulse { animation: none; }
}
