@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Fraunces:opsz,wght@9..144,600&display=swap');

:root {
  --ink: #18382d;
  --muted: #6d7d75;
  --paper: #f5f0e6;
  --card: #fffdf8;
  --line: #9eb3a7;
  --leaf: #267456;
  --leaf-light: #dfece4;
  --accent: #c96f46;
  --shadow: 0 12px 35px rgba(39, 66, 54, .11), 0 2px 6px rgba(39, 66, 54, .08);
  font-family: "DM Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body { color: var(--ink); background: var(--paper); }
button, input { font: inherit; }
button { color: inherit; }

.topbar {
  position: fixed; z-index: 20; inset: 0 0 auto 0; height: 86px;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 14px max(22px, env(safe-area-inset-right)) 14px max(22px, env(safe-area-inset-left));
  background: rgba(245, 240, 230, .92); border-bottom: 1px solid rgba(38, 116, 86, .12);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: max-content; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; color: white; background: var(--leaf); font-size: 20px; }
h1 { margin: 0; font: 600 25px/1 "Fraunces", serif; letter-spacing: -.025em; }
.brand p { margin: 5px 0 0; color: var(--muted); font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.search { display: flex; align-items: center; gap: 9px; width: min(280px, 35vw); padding: 10px 14px; border: 1px solid rgba(38, 116, 86, .16); border-radius: 99px; background: rgba(255,255,255,.67); }
.search:focus-within { outline: 2px solid rgba(38, 116, 86, .25); border-color: var(--leaf); }
.search svg { width: 18px; fill: none; stroke: var(--muted); stroke-width: 2; }
.search input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
.search input::placeholder { color: #84928b; }
.branch-switcher { display: flex; flex: 0 1 auto; gap: 2px; max-width: min(440px, 38vw); padding: 3px; overflow-x: auto; border-radius: 11px; background: rgba(38,116,86,.08); scrollbar-width: none; }
.branch-switcher::-webkit-scrollbar { display: none; }
.branch-switcher button { flex: 0 0 auto; height: 32px; padding: 0 10px; border: 0; border-radius: 8px; color: var(--leaf); background: transparent; cursor: pointer; font-size: 10px; font-weight: 600; white-space: nowrap; }
.branch-switcher button:hover, .branch-switcher button:active, .branch-switcher button:focus-visible { background: var(--card); outline: 0; box-shadow: 0 1px 5px rgba(39,66,54,.1); }

#viewport { position: absolute; inset: 86px 0 0; overflow: hidden; cursor: grab; touch-action: none; background-image: radial-gradient(circle at center, rgba(38,116,86,.13) 1px, transparent 1.2px); background-size: 28px 28px; }
#viewport.dragging { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
#lines, #cards { position: absolute; inset: 0; overflow: visible; }
#lines path { fill: none; stroke: var(--line); stroke-width: 2; vector-effect: non-scaling-stroke; }
#lines path.sibling { stroke: var(--accent); stroke-dasharray: 5 5; opacity: .72; }
#lines text { fill: var(--accent); font: 600 11px "DM Sans", sans-serif; text-anchor: middle; text-transform: uppercase; letter-spacing: .1em; paint-order: stroke; stroke: var(--paper); stroke-width: 5px; }

.family-card {
  position: absolute; width: 260px; min-height: 94px; padding: 13px 14px;
  border: 1px solid rgba(38,116,86,.13); border-radius: 18px; background: var(--card); box-shadow: var(--shadow);
  cursor: pointer; user-select: none; text-align: left; transition: box-shadow .18s, border-color .18s, opacity .18s;
}
.family-card:hover, .family-card:focus-visible { border-color: rgba(38,116,86,.55); box-shadow: 0 16px 42px rgba(39,66,54,.17), 0 2px 7px rgba(39,66,54,.1); outline: 0; }
.family-card.match { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(201,111,70,.17), var(--shadow); }
.family-card.dimmed { opacity: .26; }
.family-card[data-deceased="true"] { border-style: dashed; border-color: rgba(80, 88, 83, .36); background: #f2efe8; box-shadow: 0 8px 25px rgba(39, 50, 44, .08); }
.family-card[data-deceased="true"] .avatar { color: #5f6863; background: #dfe1dd; }
.family-card[data-deceased="true"] .relation { color: #6f7772; font-weight: 700; }
.people { display: flex; align-items: center; justify-content: center; gap: 7px; min-height: 48px; }
.member { display: flex; flex: 1 1 0; min-width: 0; align-items: center; gap: 7px; }
.person { flex: 1; min-width: 0; }
.avatar { display: grid; place-items: center; flex: 0 0 35px; width: 35px; height: 35px; border-radius: 50%; background: var(--leaf-light); color: var(--leaf); font: 600 14px "Fraunces", serif; }
.name { display: block; overflow: hidden; color: var(--ink); font: 600 15px/1.2 "Fraunces", serif; text-overflow: ellipsis; white-space: nowrap; }
.relation { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.heart { flex: 0 0 auto; color: var(--accent); font-size: 10px; }
.child-count { display: flex; align-items: center; gap: 5px; margin-top: 8px; padding-top: 8px; border-top: 1px solid rgba(38,116,86,.1); color: var(--muted); font-size: 11px; }
.child-count::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--leaf); opacity: .7; }

.controls { position: fixed; z-index: 20; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); display: flex; overflow: hidden; border: 1px solid rgba(38,116,86,.15); border-radius: 14px; background: rgba(255,253,248,.94); box-shadow: var(--shadow); }
.controls button { min-width: 44px; height: 44px; padding: 0 14px; border: 0; background: transparent; cursor: pointer; font-size: 20px; }
.controls button:hover { background: var(--leaf-light); }
.controls .fit { border-inline: 1px solid rgba(38,116,86,.12); font-size: 13px; font-weight: 600; }
.hint { position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); padding: 7px 12px; border-radius: 99px; color: var(--muted); background: rgba(245,240,230,.85); font-size: 11px; pointer-events: none; transition: opacity .5s; white-space: nowrap; }
#loading { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; color: var(--muted); font-size: 13px; text-align: center; }
#loading span { width: 34px; height: 34px; margin: auto; border: 3px solid var(--leaf-light); border-top-color: var(--leaf); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#error { position: fixed; z-index: 30; left: 50%; bottom: 24px; transform: translateX(-50%); padding: 12px 16px; border-radius: 12px; color: white; background: #9d3b32; }

#details { width: min(420px, calc(100vw - 24px)); padding: 0; border: 0; border-radius: 24px; color: var(--ink); background: var(--card); box-shadow: 0 30px 90px rgba(20,45,36,.3); }
#details::backdrop { background: rgba(20,45,36,.35); backdrop-filter: blur(4px); }
#detailsContent { padding: 30px; }
#details .close { position: absolute; z-index: 1; top: 12px; right: 12px; width: 34px; height: 34px; border: 0; border-radius: 50%; background: var(--leaf-light); cursor: pointer; font-size: 22px; }
.detail-kicker { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.detail-title { margin: 8px 0 18px; font: 600 30px "Fraunces", serif; }
.detail-row { display: flex; justify-content: space-between; gap: 20px; padding: 11px 0; border-top: 1px solid rgba(38,116,86,.1); font-size: 13px; }
.detail-row span:first-child { color: var(--muted); }
.detail-row.memorial strong { color: #5f6863; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 640px) {
  .topbar { height: 168px; align-items: flex-start; flex-wrap: wrap; gap: 9px; padding: max(12px, env(safe-area-inset-top)) 14px 10px; }
  .brand-mark { width: 37px; height: 37px; }
  h1 { font-size: 21px; }
  .brand p { display: none; }
  .search { order: 2; flex-basis: 100%; width: 100%; height: 42px; }
  .branch-switcher { order: 3; display: flex; width: 100%; max-width: none; }
  .branch-switcher button { height: 30px; font-size: 11px; }
  #viewport { inset: 168px 0 0; }
  .controls { right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); }
  .hint { bottom: 68px; }
  .family-card { border-radius: 16px; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; animation-duration: .01ms !important; } }
