/* ================= Kinfolk — heritage oak design language ================= */

:root {
  --bg: #0c0a05;
  --bg-2: #171207;
  --ink: #f0e6cf;
  --ink-dim: #b3a382;
  --ink-faint: #7d6f52;
  --glass: rgba(255, 240, 200, 0.045);
  --glass-2: rgba(255, 240, 200, 0.08);
  --stroke: rgba(230, 200, 140, 0.14);
  --stroke-bright: rgba(230, 200, 140, 0.3);
  --accent: #d4af6a;
  --accent-2: #8fae5a;
  --danger: #c96f5a;
  --ok: #8fae5a;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;
  --font-display: 'Cinzel', 'Times New Roman', serif;
  --font-serif: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'Inter', system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: radial-gradient(ellipse 120% 60% at 50% -5%, #2b2310 0%, transparent 55%), var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(212, 175, 106, 0.3); }

/* ---------- ambient background: golden light through the canopy ---------- */

.aurora { position: fixed; inset: 0; z-index: 0; overflow: hidden; filter: blur(90px) saturate(115%); }
.blob { position: absolute; border-radius: 50%; opacity: 0.55; will-change: transform; }
.blob-1 { width: 55vw; height: 55vw; left: -12vw; top: -18vw; background: radial-gradient(circle, #4a3a14 0%, transparent 65%); animation: drift1 30s ease-in-out infinite alternate; }
.blob-2 { width: 45vw; height: 45vw; right: -10vw; top: 6vh; background: radial-gradient(circle, #2e4418 0%, transparent 65%); animation: drift2 36s ease-in-out infinite alternate; }
.blob-3 { width: 42vw; height: 42vw; left: 26vw; bottom: -22vw; background: radial-gradient(circle, #3a2c16 0%, transparent 65%); animation: drift3 42s ease-in-out infinite alternate; }
@keyframes drift1 { to { transform: translate(8vw, 6vh) scale(1.1); } }
@keyframes drift2 { to { transform: translate(-6vw, 9vh) scale(0.95); } }
@keyframes drift3 { to { transform: translate(-5vw, -7vh) scale(1.07); } }

.grid-overlay {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 55% 35% at 50% 0%, rgba(232, 200, 126, 0.09) 0%, transparent 70%),
    radial-gradient(ellipse 120% 55% at 50% 115%, rgba(0, 0, 0, 0.55) 0%, transparent 65%);
}

#app { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- typography ---------- */

h1, h2, h3, .display { font-family: var(--font-display); letter-spacing: 0.015em; font-weight: 600; }

.gradient-text {
  background: linear-gradient(100deg, #f4dfae 0%, #d4af6a 55%, #c08a4a 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- shared components ---------- */

.glass {
  background: linear-gradient(160deg, rgba(46, 36, 18, 0.5), rgba(20, 16, 8, 0.55));
  border: 1px solid var(--stroke);
  border-radius: var(--r-lg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-display); font-weight: 600; font-size: 12.5px;
  letter-spacing: 0.06em;
  color: var(--ink); background: var(--glass-2);
  border: 1px solid var(--stroke-bright); border-radius: 999px;
  padding: 10px 22px; cursor: pointer; text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
  user-select: none; white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); background: rgba(255, 240, 200, 0.12); border-color: rgba(232, 200, 126, 0.45); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: linear-gradient(100deg, rgba(212, 175, 106, 0.22), rgba(160, 120, 60, 0.22));
  border-color: rgba(222, 185, 116, 0.55);
  box-shadow: 0 0 22px rgba(212, 175, 106, 0.14), inset 0 0 16px rgba(232, 200, 126, 0.07);
  color: #f4e6c2;
}
.btn.primary:hover { box-shadow: 0 0 32px rgba(212, 175, 106, 0.28), inset 0 0 20px rgba(232, 200, 126, 0.12); }
.btn.danger { border-color: rgba(201, 111, 90, 0.45); color: #e8b5a5; }
.btn.danger:hover { background: rgba(201, 111, 90, 0.14); }
.btn.small { padding: 6px 14px; font-size: 11px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-dim); }
.btn.ghost:hover { color: var(--ink); background: var(--glass); }
.btn:disabled { opacity: 0.45; pointer-events: none; }

input, select, textarea {
  width: 100%; font-family: var(--font-body); font-size: 14.5px; color: var(--ink);
  background: rgba(10, 8, 3, 0.5); border: 1px solid var(--stroke); border-radius: var(--r-sm);
  padding: 11px 14px; outline: none; transition: border-color 0.18s, box-shadow 0.18s;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(212, 175, 106, 0.6);
  box-shadow: 0 0 0 3px rgba(212, 175, 106, 0.14);
}
textarea { resize: vertical; min-height: 80px; }
select option { background: #221b0e; }
label.field { display: block; margin-bottom: 14px; }
label.field > span {
  display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--ink-dim); margin-bottom: 6px; font-family: var(--font-display); font-weight: 600;
}

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10.5px; font-family: var(--font-display); font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  padding: 4px 12px; border-radius: 999px;
  background: var(--glass); border: 1px solid var(--stroke); color: var(--ink-dim);
}
.chip.on { color: #c6d69a; border-color: rgba(143, 174, 90, 0.45); background: rgba(143, 174, 90, 0.1); }

/* ---------- topbar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 18px;
  padding: 14px 28px; margin: 14px 18px 0;
  border-radius: 999px;
  background: rgba(22, 17, 8, 0.65);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px);
}
.topbar .brand {
  font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: 0.06em;
  display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none;
  color: #ecd9a8;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(212, 175, 106, 0.25), rgba(90, 110, 50, 0.3));
  border: 1px solid rgba(222, 185, 116, 0.45);
  box-shadow: 0 0 18px rgba(212, 175, 106, 0.22);
  font-size: 15px;
}
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--ink-dim); font-size: 13px; }
.topbar .who b { color: var(--ink); font-weight: 500; }

/* ---------- login ---------- */

.login-wrap { flex: 1; display: grid; place-items: center; padding: 40px 20px; }
.login-card {
  width: min(420px, 100%); padding: 44px 40px 36px; text-align: center;
  animation: rise 0.6s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55), 0 0 60px rgba(212, 175, 106, 0.06);
}
.login-card .brand-mark { width: 58px; height: 58px; border-radius: 18px; font-size: 30px; margin: 0 auto 20px; }
.login-card h1 { font-size: 30px; font-weight: 700; margin-bottom: 6px; letter-spacing: 0.08em; }
.login-card .sub { color: var(--ink-dim); font-size: 15px; margin-bottom: 30px; font-family: var(--font-serif); font-style: italic; }
.login-card form { text-align: left; }
.login-card .btn { width: 100%; margin-top: 8px; padding: 13px; font-size: 14px; }

@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- home: the family grove ---------- */

.home { flex: 1; padding: 44px clamp(18px, 4vw, 60px) 70px; }
.home-head { text-align: center; margin-bottom: 46px; animation: rise 0.5s cubic-bezier(0.2,0.8,0.2,1); }
.home-head h1 { font-size: clamp(28px, 4.2vw, 44px); font-weight: 700; letter-spacing: 0.05em; }
.home-head p { color: var(--ink-dim); margin-top: 10px; font-size: 17px; font-family: var(--font-serif); font-style: italic; }

.family-grid {
  display: grid; gap: 22px;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  max-width: 1500px; margin: 0 auto;
}
.family-card {
  position: relative; padding: 26px 24px 22px; cursor: pointer; overflow: hidden;
  transition: transform 0.25s cubic-bezier(0.2,0.8,0.2,1), box-shadow 0.25s, border-color 0.25s;
  animation: rise 0.55s cubic-bezier(0.2,0.8,0.2,1) both;
}
.family-card:hover {
  transform: translateY(-5px);
  border-color: color-mix(in srgb, var(--fam-accent, #d4af6a) 55%, transparent);
  box-shadow: 0 24px 60px rgba(0,0,0,0.5), 0 0 44px color-mix(in srgb, var(--fam-accent, #d4af6a) 16%, transparent);
}
.family-card .halo {
  position: absolute; top: -46px; right: -46px; width: 150px; height: 150px; border-radius: 50%;
  background: radial-gradient(circle, var(--fam-accent, #d4af6a) 0%, transparent 70%);
  opacity: 0.12; transition: opacity 0.25s; pointer-events: none;
}
.family-card:hover .halo { opacity: 0.28; }
.family-card .fam-glyph {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 19px;
  color: var(--fam-accent, var(--accent));
  background: color-mix(in srgb, var(--fam-accent, #d4af6a) 10%, rgba(10, 8, 3, 0.4));
  border: 2px solid color-mix(in srgb, var(--fam-accent, #d4af6a) 45%, transparent);
  box-shadow: 0 0 20px color-mix(in srgb, var(--fam-accent, #d4af6a) 18%, transparent);
  margin-bottom: 16px;
}
.family-card h3 { font-size: 19px; font-weight: 600; margin-bottom: 3px; letter-spacing: 0.03em; }
.family-card .tagline { color: var(--ink-dim); font-size: 14px; min-height: 20px; font-family: var(--font-serif); font-style: italic; }
.family-card .meta { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.family-card .count { font-size: 12.5px; color: var(--ink-dim); }
.family-card .count b { color: var(--ink); font-family: var(--font-display); }
.family-card .go {
  margin-left: auto; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-size: 15px;
  border: 1px solid var(--stroke); color: var(--ink-dim);
  transition: all 0.2s;
}
.family-card:hover .go {
  color: var(--bg); background: var(--fam-accent, var(--accent));
  border-color: transparent; box-shadow: 0 0 18px color-mix(in srgb, var(--fam-accent, #d4af6a) 55%, transparent);
}

/* ---------- tree view ---------- */

.tree-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.tree-head {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 22px clamp(18px, 4vw, 60px) 10px;
}
.tree-head h1 { font-size: clamp(22px, 3vw, 30px); font-weight: 700; letter-spacing: 0.05em; }
.tree-head .tagline { color: var(--ink-dim); font-size: 14.5px; font-family: var(--font-serif); font-style: italic; }
.tree-head .spacer { flex: 1; }

.tree-stage {
  position: relative; flex: 1; min-height: 66vh; margin: 8px 18px 18px;
  border-radius: var(--r-lg); border: 1px solid var(--stroke);
  background:
    radial-gradient(ellipse 70% 45% at 50% 0%, rgba(212, 175, 106, 0.07) 0%, transparent 65%),
    linear-gradient(180deg, rgba(24, 22, 10, 0.35) 0%, rgba(12, 10, 4, 0.55) 70%, rgba(8, 6, 2, 0.75) 100%);
  overflow: hidden;
  cursor: grab;
}
.tree-stage.dragging { cursor: grabbing; }
.tree-stage svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.tree-empty {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  color: var(--ink-dim); pointer-events: none;
}
.tree-empty .btn { pointer-events: auto; margin-top: 16px; }

.zoom-hud {
  position: absolute; right: 16px; bottom: 16px; display: flex; gap: 8px; z-index: 5;
}
.zoom-hud .btn { width: 38px; height: 38px; padding: 0; font-size: 17px; }

/* SVG tree nodes */
.tnode { cursor: pointer; }
.tnode .tin {
  transform-box: fill-box; transform-origin: center;
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tnode:hover .tin { transform: scale(1.07); }
.tnode .ring-glow { opacity: 0.35; transition: opacity 0.2s; }
.tnode:hover .ring-glow { opacity: 0.85; }
.tnode text { user-select: none; -webkit-user-select: none; }

.branch-under { fill: none; stroke: #241811; stroke-linecap: round; }
.branch { fill: none; stroke: #573f2a; stroke-linecap: round; }
.branch-hi { fill: none; stroke: rgba(212, 175, 106, 0.16); stroke-linecap: round; }

/* ---------- drawer (person detail) ---------- */

.drawer-veil {
  position: fixed; inset: 0; z-index: 60; background: rgba(6, 4, 1, 0.6);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  animation: fade 0.25s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 61;
  width: min(430px, 94vw); display: flex; flex-direction: column;
  background: linear-gradient(170deg, rgba(34, 27, 13, 0.95), rgba(16, 12, 5, 0.96));
  border-left: 1px solid var(--stroke-bright);
  backdrop-filter: blur(26px); -webkit-backdrop-filter: blur(26px);
  animation: slide-in 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
  overflow-y: auto;
}
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.drawer-hero { position: relative; padding: 40px 30px 24px; text-align: center; }
.drawer-hero .halo {
  position: absolute; top: -70px; left: 50%; transform: translateX(-50%);
  width: 300px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle, #d4af6a 0%, transparent 70%);
  opacity: 0.13; pointer-events: none;
}
.drawer-avatar {
  width: 116px; height: 116px; border-radius: 50%; margin: 0 auto 16px;
  display: grid; place-items: center; overflow: hidden; position: relative;
  font-family: var(--font-display); font-weight: 700; font-size: 40px;
  color: #e8c87e;
  background: radial-gradient(circle, #26301a 0%, #171d0f 80%);
  border: 3px solid #c9a35c;
  box-shadow: 0 0 0 2px rgba(20, 14, 5, 0.9), 0 0 0 3.5px rgba(138, 116, 64, 0.5), 0 0 44px rgba(212, 175, 106, 0.28);
}
.drawer-avatar img { width: 100%; height: 100%; object-fit: cover; }
.drawer-hero h2 { font-size: 24px; font-weight: 700; position: relative; letter-spacing: 0.04em; color: #f0dfae; }
.drawer-hero .rel { color: var(--ink-dim); font-size: 14.5px; margin-top: 4px; position: relative; font-family: var(--font-serif); font-style: italic; }
.drawer-close {
  position: absolute; top: 16px; right: 16px; width: 36px; height: 36px;
  border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  background: var(--glass); border: 1px solid var(--stroke); color: var(--ink-dim);
  font-size: 16px; transition: all 0.15s; z-index: 2;
}
.drawer-close:hover { color: var(--ink); border-color: var(--stroke-bright); }

.contact-list { padding: 6px 26px 20px; display: flex; flex-direction: column; gap: 10px; }
.contact-row {
  display: flex; align-items: center; gap: 14px; padding: 13px 16px;
  border-radius: var(--r-md); text-decoration: none; color: var(--ink);
  background: var(--glass); border: 1px solid var(--stroke);
  transition: border-color 0.18s, background 0.18s, transform 0.18s;
}
a.contact-row:hover { border-color: rgba(212, 175, 106, 0.5); background: var(--glass-2); transform: translateX(3px); }
.contact-icon {
  width: 38px; height: 38px; flex: none; border-radius: 12px; display: grid; place-items: center; font-size: 16px;
  background: rgba(212, 175, 106, 0.1);
  border: 1px solid rgba(212, 175, 106, 0.3);
}
.contact-row .cval { font-size: 14.5px; word-break: break-word; }
.contact-row .clabel {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.11em;
  color: var(--ink-faint); font-family: var(--font-display); font-weight: 600;
}

.drawer-actions {
  margin-top: auto; padding: 18px 26px 26px; display: flex; gap: 10px; flex-wrap: wrap;
  border-top: 1px solid var(--stroke);
}

/* ---------- modal ---------- */

.modal-veil {
  position: fixed; inset: 0; z-index: 70; display: grid; place-items: center;
  background: rgba(6, 4, 1, 0.65); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  animation: fade 0.2s ease; padding: 20px; overflow-y: auto;
}
.modal {
  width: min(520px, 100%); max-height: 90vh; overflow-y: auto;
  padding: 30px 30px 26px; position: relative;
  background: linear-gradient(165deg, rgba(38, 30, 14, 0.97), rgba(18, 14, 6, 0.97));
  animation: rise 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 40px 100px rgba(0,0,0,0.65);
}
.modal h2 { font-size: 20px; font-weight: 700; margin-bottom: 22px; letter-spacing: 0.04em; }
.modal .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.modal-foot .left { margin-right: auto; }

.photo-drop {
  display: flex; align-items: center; gap: 14px; padding: 12px;
  border: 1px dashed var(--stroke-bright); border-radius: var(--r-md);
  cursor: pointer; margin-bottom: 14px; transition: border-color 0.18s;
}
.photo-drop:hover { border-color: rgba(212, 175, 106, 0.55); }
.photo-drop .preview {
  width: 54px; height: 54px; border-radius: 50%; overflow: hidden; flex: none;
  background: rgba(10, 8, 3, 0.45); display: grid; place-items: center; font-size: 21px;
  border: 1px solid var(--stroke);
}
.photo-drop .preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-drop .hint { font-size: 13px; color: var(--ink-dim); }

/* ---------- admin ---------- */

.admin { flex: 1; padding: 40px clamp(18px, 4vw, 60px) 70px; max-width: 1150px; margin: 0 auto; width: 100%; }
.admin h1 { font-size: clamp(26px, 3.4vw, 34px); font-weight: 700; margin-bottom: 6px; letter-spacing: 0.05em; }
.admin .sub { color: var(--ink-dim); margin-bottom: 30px; font-family: var(--font-serif); font-style: italic; font-size: 16px; }
.admin-toolbar { display: flex; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }

.user-card { padding: 20px 22px; margin-bottom: 14px; animation: rise 0.4s cubic-bezier(0.2,0.8,0.2,1) both; }
.user-card .u-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.user-card .u-avatar {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 17px;
  color: #e8c87e;
  background: linear-gradient(135deg, rgba(212, 175, 106, 0.16), rgba(90, 110, 50, 0.18));
  border: 1px solid var(--stroke-bright);
}
.user-card .u-name { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.user-card .u-sub { color: var(--ink-dim); font-size: 12.5px; }
.user-card .u-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.access-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; margin-top: 16px; }
.access-cell {
  display: flex; align-items: center; gap: 9px; padding: 9px 12px;
  border-radius: var(--r-sm); border: 1px solid var(--stroke); background: rgba(10, 8, 3, 0.3);
  font-size: 13px; cursor: pointer; user-select: none; transition: border-color 0.15s, background 0.15s;
}
.access-cell:hover { border-color: var(--stroke-bright); }
.access-cell .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.access-cell .mode { margin-left: auto; font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; font-family: var(--font-display); font-weight: 600; color: var(--ink-faint); }
.access-cell[data-mode="view"] { border-color: rgba(212, 175, 106, 0.4); }
.access-cell[data-mode="view"] .mode { color: #e0c27e; }
.access-cell[data-mode="edit"] { border-color: rgba(143, 174, 90, 0.5); background: rgba(143, 174, 90, 0.07); }
.access-cell[data-mode="edit"] .mode { color: #b0c883; }

/* ---------- toast ---------- */

#toast-root { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast {
  padding: 12px 24px; border-radius: 999px; font-size: 13px; font-family: var(--font-display); font-weight: 600; letter-spacing: 0.04em;
  background: rgba(30, 24, 11, 0.95); border: 1px solid var(--stroke-bright);
  backdrop-filter: blur(16px); box-shadow: 0 12px 40px rgba(0,0,0,0.55);
}
.toast.err { border-color: rgba(201, 111, 90, 0.55); color: #e8b5a5; }
.toast.ok { border-color: rgba(143, 174, 90, 0.5); color: #c6d69a; }

/* ---------- misc ---------- */

.spin {
  width: 26px; height: 26px; margin: 60px auto; border-radius: 50%;
  border: 2px solid var(--stroke-bright); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .topbar { padding: 10px 18px; margin: 10px 10px 0; gap: 10px; }
  .topbar .who { display: none; }
  .tree-stage { margin: 6px 10px 12px; }
  .modal .row2 { grid-template-columns: 1fr; }
}
