/* =============================================================================
   Lumibao Family — "heirloom album" theme
   Heritage serif type (EB Garamond / Crimson Text), warm walnut + antique gold.
   ========================================================================== */
:root {
  /* surfaces */
  --bg: #1f1811;
  --bg-2: #271f17;
  --panel: #2b2219;
  --panel-2: #35291e;
  --line: #4a3a29;
  --line-soft: #3b2e21;

  /* ink */
  --ink: #f3ead9;
  --ink-dim: #d9cbb4;
  --muted: #ac9c85;

  /* brand */
  --accent: #c9a24b;       /* antique gold */
  --accent-deep: #a7822f;
  --accent-ink: #241a0e;
  --sage: #8fa383;         /* heritage green */
  --danger: #cf7a68;

  /* tree card tones (antique, not neon) */
  --card-male: #33505f;
  --card-female: #6f4750;
  --card-border: #c9a24b;

  /* type */
  --font-head: "EB Garamond", Georgia, "Times New Roman", serif;
  --font-body: "Crimson Text", Georgia, serif;

  /* motion */
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --dur: 240ms;

  --z-panel: 35;
  --z-modal: 50;
  --z-banner: 60;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  font-size: 17px;
  color: var(--ink);
  background:
    radial-gradient(1100px 700px at 78% -10%, #2c2318 0%, transparent 60%),
    radial-gradient(900px 600px at 10% 110%, #2a2117 0%, transparent 55%),
    var(--bg);
}
body { display: flex; flex-direction: column; }

.hidden { display: none !important; }

h1, h2, .brand-name { font-family: var(--font-head); font-weight: 600; letter-spacing: .2px; }

.ic { width: 18px; height: 18px; flex: none; }

/* ---------- Banner ---------- */
.banner {
  position: sticky; top: 0; flex: none; z-index: var(--z-banner);
  background: linear-gradient(#3f3113, #372a10);
  color: #f4e4bd;
  font-size: 14px;
  text-align: center;
  padding: 9px 16px;
  border-bottom: 1px solid var(--accent-deep);
  letter-spacing: .2px;
}

/* ---------- Login ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 22px; padding: 24px;
  background:
    radial-gradient(1000px 520px at 50% -8%, #34291b 0%, transparent 62%),
    var(--bg);
  animation: fade var(--dur) var(--ease);
}
.login-card {
  width: 100%; max-width: 400px;
  background: linear-gradient(180deg, #2f2519, #281f16);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 34px 30px 30px;
  display: flex; flex-direction: column; gap: 13px;
  box-shadow: 0 30px 70px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.04);
  text-align: center;
  animation: rise 420ms var(--ease) both;
}
.crest {
  width: 62px; height: 62px; margin: 0 auto 4px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--accent);
  background: radial-gradient(circle at 50% 35%, #3a2d1c, #2a2016);
  border: 1px solid var(--accent-deep);
  box-shadow: inset 0 0 18px rgba(201,162,75,.15);
}
.crest-icon { width: 32px; height: 32px; }
.login-card h1 { margin: 2px 0 0; font-size: 30px; }
.rule { display: flex; align-items: center; justify-content: center; margin: 2px 0 4px; }
.rule span {
  display: block; width: 120px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent-deep), transparent);
  position: relative;
}
.rule span::after {
  content: "";
  position: absolute; left: 50%; top: 50%; width: 5px; height: 5px;
  transform: translate(-50%, -50%) rotate(45deg);
  background: var(--accent); border-radius: 1px;
}
.login-sub { margin: 0 0 8px; color: var(--muted); font-size: 16px; }
.login-card input {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 13px 15px;
  border-radius: 11px;
  font-family: var(--font-body);
  font-size: 16px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.login-card input::placeholder { color: #8f8069; }
.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201,162,75,.2);
}
#login-btn {
  margin-top: 4px;
  width: 100%;
  justify-content: center;
  display: inline-flex; align-items: center;
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: var(--accent-ink);
  border: 1px solid var(--accent-deep);
  padding: 13px 18px;
  border-radius: 11px;
  font-family: var(--font-body);
  font-size: 17px; font-weight: 600; letter-spacing: .3px;
  cursor: pointer;
  transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease);
}
#login-btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
#login-btn:active { transform: translateY(0); }
#login-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(201,162,75,.35); }
#login-btn:disabled { opacity: .6; cursor: default; transform: none; }

.login-error { color: #f0a493; font-size: 15px; margin: 2px 0 0; }
.login-foot { color: #7e6f58; font-size: 15px; font-style: italic; margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: linear-gradient(180deg, var(--accent), var(--accent-deep));
  color: var(--accent-ink);
  border: 1px solid var(--accent-deep);
  padding: 10px 18px;
  border-radius: 11px;
  font-family: var(--font-body);
  font-size: 16px; font-weight: 600; letter-spacing: .2px;
  cursor: pointer;
  transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease), background var(--dur) var(--ease);
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(201,162,75,.35); }
.btn.ghost {
  background: transparent; color: var(--ink-dim);
  border: 1px solid var(--line);
  font-weight: 500;
}
.btn.ghost:hover { background: var(--panel-2); color: var(--ink); border-color: var(--accent-deep); }

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px;
  background: transparent; border: none; color: var(--muted);
  border-radius: 10px; cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { color: var(--ink); background: var(--panel-2); }
.icon-btn .ic { width: 20px; height: 20px; }

/* ---------- App shell ---------- */
.app { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; animation: fade var(--dur) var(--ease); }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 20px;
  background: linear-gradient(180deg, #2c2318, #251d14);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 26px; height: 26px; color: var(--accent);
  flex: none;
}
.brand-name { font-size: 22px; color: var(--ink); }
.topbar-actions { display: flex; gap: 9px; }

.main { position: relative; flex: 1; min-height: 0; }
.tree {
  width: 100%; height: 100%;
  background:
    radial-gradient(1200px 800px at 50% 40%, #2a2118 0%, #1d1610 78%);
  color: var(--ink);
}

/* loading / error overlay over the tree */
.loading {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
  background: radial-gradient(900px 600px at 50% 40%, #241d17 0%, #1b1510 80%);
  color: var(--ink-dim);
  animation: fade 200ms var(--ease);
}
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 900ms linear infinite;
}
#loading-text { font-family: var(--font-head); font-size: 19px; margin: 0; letter-spacing: .3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* hover "add" buttons around each card (child below, partner right, parent up) */
.card_cont { overflow: visible !important; }
/* family-chart translates the visible card -50%,-50% onto card_cont's origin, so
   this layer carries the same transform to sit exactly over the visible box. */
.lf-add-layer {
  position: absolute; inset: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.lf-add {
  position: absolute; z-index: 6;
  /* explicit auto: the layer sets pointer-events:none and it's inherited */
  pointer-events: auto;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  border: 2px solid #1f1811;
  display: grid; place-items: center;
  cursor: pointer; padding: 0;
  opacity: 0; visibility: hidden; transform: scale(.85);
  /* hide after a 300ms grace period so the cursor can travel to the button */
  transition: opacity 150ms var(--ease), transform 150ms var(--ease),
    visibility 0s linear 300ms;
  box-shadow: 0 3px 10px rgba(0,0,0,.5);
}
/* invisible bridge so moving from the card to the button never crosses a dead zone */
.lf-add::before { content: ""; position: absolute; inset: -16px; border-radius: 50%; }
.card_cont:hover .lf-add, .lf-add:focus-visible {
  opacity: 1; visibility: visible; transform: scale(1);
  transition: opacity 150ms var(--ease), transform 150ms var(--ease), visibility 0s;
}
.lf-add:hover { transform: scale(1.18); }
.lf-add svg { width: 16px; height: 16px; position: relative; }
.lf-add-child  { bottom: -15px; left: 50%; margin-left: -15px; }
.lf-add-partner{ right: -15px;  top: 50%;  margin-top: -15px; }
.lf-add-parent { top: -15px;    left: 50%; margin-left: -15px; }

/* partner toggle (upper-left): reveal/hide a person's married-in partners */
.lf-partner-toggle {
  position: absolute; z-index: 6; pointer-events: auto;
  top: -12px; left: -12px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--panel-2); color: var(--accent);
  border: 2px solid #1f1811;
  display: grid; place-items: center; padding: 0; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.45);
  opacity: .55;
  transition: transform 120ms var(--ease), opacity 150ms, background 150ms;
}
.card_cont:hover .lf-partner-toggle { opacity: 1; }
.lf-partner-toggle:hover { transform: scale(1.15); opacity: 1; }
.lf-partner-toggle.on { background: var(--accent); color: var(--accent-ink); opacity: 1; }
.lf-partner-toggle svg { width: 15px; height: 15px; }

/* branch toggle (lower-left): fold/unfold a person's descendants */
.lf-collapse {
  position: absolute; z-index: 6; pointer-events: auto;
  bottom: -12px; left: -12px;
  min-width: 26px; height: 26px; border-radius: 13px;
  background: var(--panel-2); color: var(--accent);
  border: 2px solid #1f1811;
  display: grid; place-items: center; padding: 0 4px; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.45);
  opacity: .55;
  transition: transform 120ms var(--ease), opacity 150ms, background 150ms;
}
.card_cont:hover .lf-collapse { opacity: 1; }
.lf-collapse:hover { transform: scale(1.12); opacity: 1; }
/* collapsed: always visible badge with the hidden-people count */
.lf-collapse.on { background: var(--accent); color: var(--accent-ink); opacity: 1; }
.lf-collapse svg { width: 15px; height: 15px; }
.lf-collapse span { font-size: 12px; font-weight: 700; letter-spacing: .2px; line-height: 1; }

/* empty placeholder boxes: dashed outline + "tap to add" hint */
.card_cont.lf-empty .card-inner { outline: 2px dashed var(--accent); outline-offset: -3px; }
.lf-del {
  position: absolute; z-index: 7; pointer-events: auto;
  top: -11px; right: -11px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--danger); color: #2a0f0a;
  border: 2px solid #1f1811;
  display: grid; place-items: center; padding: 0; cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.5);
  transition: transform 120ms var(--ease), filter 120ms var(--ease);
}
.lf-del svg { width: 13px; height: 13px; }
.lf-del:hover { transform: scale(1.15); filter: brightness(1.08); }
.lf-empty-hint {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  pointer-events: none;
}
.lf-empty-hint span {
  background: rgba(20, 14, 8, .6);
  color: #f3ead9;
  font-size: 12px; letter-spacing: .3px;
  padding: 3px 9px; border-radius: 7px;
}

/* our replacement parent->child link: a child of a married-in partner hangs
   straight under that partner (drawn in attachPartnerLinks) */
.lf-partner-link {
  fill: none;
  stroke: #fff;
  stroke-width: 1;
  pointer-events: none;
}
/* the library midpoint link we replace */
.links_view .link.lf-link-hidden { display: none; }

/* couple-status marker between spouses (click to cycle none/married/dating) */
.lf-couple { position: absolute; left: 0; top: 0; z-index: 5; }
.lf-couple-btn {
  pointer-events: auto;
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; padding: 0; cursor: pointer;
  border: 2px solid #1f1811;
  background: rgba(20,14,8,.6);
  box-shadow: 0 2px 8px rgba(0,0,0,.45);
  transition: transform 120ms var(--ease), background 150ms, border-color 150ms;
}
.lf-couple-none .lf-couple-btn { border-color: var(--accent-deep); }
.lf-couple-married .lf-couple-btn, .lf-couple-dating .lf-couple-btn,
.lf-couple-deceased .lf-couple-btn { background: #251d14; border-color: var(--accent); }
.lf-couple-married .lf-couple-btn { color: var(--accent); }
.lf-couple-dating .lf-couple-btn { color: #e58aa0; }
.lf-couple-deceased .lf-couple-btn { color: #b9b2a6; border-color: #6d6355; }
.lf-couple-btn:hover { transform: scale(1.15); border-color: var(--accent); }
.lf-couple-btn:focus-visible { outline: none; border-color: var(--ink); }
.lf-couple-btn svg { width: 16px; height: 16px; }

/* family-chart card theming (colors only — no layout changes) */
.f3 .card-inner { border-radius: 10px !important; box-shadow: 0 6px 16px rgba(0,0,0,.35) !important; }
.f3 .card-male .card-inner { background: var(--card-male) !important; }
.f3 .card-female .card-inner { background: var(--card-female) !important; }
.f3 .card-main .card-inner { outline: 2px solid var(--accent); outline-offset: 1px; }
.f3 .card-label { font-family: var(--font-body) !important; }

/* ---------- Members panel ---------- */
.members-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 340px; max-width: 86vw;
  background: linear-gradient(180deg, #2b2219, #241c14);
  border-left: 1px solid var(--line);
  z-index: var(--z-panel);
  display: flex; flex-direction: column; padding: 18px;
  box-shadow: -18px 0 50px rgba(0,0,0,.4);
  animation: slideIn 320ms var(--ease);
}
.members-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.members-head h2 { margin: 0; font-size: 22px; }
.search-wrap { position: relative; margin-bottom: 14px; }
.search-ic {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; color: var(--muted); pointer-events: none;
}
#members-search {
  width: 100%;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  padding: 11px 12px 11px 36px; border-radius: 10px;
  font-family: var(--font-body); font-size: 16px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
#members-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201,162,75,.18); }
.members-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.member-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 10px; border-radius: 12px; cursor: pointer;
  transition: background var(--dur) var(--ease);
}
.member-row:hover { background: var(--panel-2); }
.member-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  object-fit: cover; background: var(--panel-2);
  border: 1px solid var(--accent-deep); flex: none;
}
.member-name { font-size: 17px; line-height: 1.2; }
.member-sub { font-size: 14px; color: var(--muted); font-style: italic; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: rgba(20, 14, 8, .62);
  display: grid; place-items: center; padding: 22px;
  animation: fade 200ms var(--ease);
}
.modal-card {
  width: 100%; max-width: 500px;
  background: linear-gradient(180deg, #2d2419, #271e15);
  border: 1px solid var(--line);
  border-radius: 18px; padding: 24px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,.55);
  animation: rise 300ms var(--ease) both;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { margin: 0; font-size: 24px; }

.photos-row { display: flex; gap: 18px; margin-bottom: 20px; }
.photo-slot { flex: 1; text-align: center; }
.photo-label {
  font-family: var(--font-head); font-size: 15px; color: var(--accent);
  letter-spacing: .8px; text-transform: uppercase; margin-bottom: 8px;
}
.photo-frame {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  border-radius: 12px; overflow: hidden;
  background: var(--panel-2);
  border: 1px solid var(--accent-deep);
  box-shadow: inset 0 0 0 4px rgba(31,24,16,.9), 0 6px 18px rgba(0,0,0,.35);
  display: grid; place-items: center; margin-bottom: 10px;
}
.photo-frame img { width: 100%; height: 100%; object-fit: cover; display: none; }
.photo-frame img.show { display: block; }
.photo-empty { color: var(--muted); font-size: 15px; font-style: italic; }
.photo-frame img.show + .photo-empty { display: none; }

.upload-btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: 8px 15px; border-radius: 9px; font-size: 15px; cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.upload-btn:hover { background: var(--line-soft); border-color: var(--accent-deep); }
.upload-btn .ic { width: 16px; height: 16px; color: var(--accent); }
.upload-status { font-size: 14px; color: var(--muted); min-height: 18px; margin-top: 5px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.field span { color: var(--accent); font-family: var(--font-head); font-size: 15px; letter-spacing: .4px; }
.field span em { color: var(--muted); font-style: italic; font-size: 13px; }
.field input, .field textarea, .field select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--ink);
  padding: 11px 13px; border-radius: 9px;
  font-family: var(--font-body); font-size: 16px; resize: vertical;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.field select { appearance: none; cursor: pointer; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(201,162,75,.18); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.person-context {
  margin: -4px 0 16px; text-align: center;
  font-family: var(--font-head); font-size: 16px; color: var(--sage);
  font-style: italic;
}

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.danger-btn { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.danger-btn:hover { background: rgba(207,122,104,.12); filter: none; transform: none; }
.modal-hint { color: var(--muted); font-size: 14px; font-style: italic; margin: 14px 0 0; text-align: center; }

/* ---------- Motion ---------- */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }

@media (prefers-reduced-motion: reduce) {
  *, .btn:hover { animation: none !important; transition: none !important; transform: none !important; }
}

/* Touch screens have no hover: keep the add buttons visible (dimmed) so the
   tree can still be built from a phone. */
@media (hover: none), (pointer: coarse) {
  .lf-add { opacity: .6; visibility: visible; transform: scale(1); }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .members-panel { width: 100%; }
  .brand-name { font-size: 19px; }
  .lbl-lg { display: none; }        /* icon-only refresh/logout on small screens */
  .btn { padding: 9px 13px; }
  .topbar-actions { gap: 6px; }
}
