:root {
  --paper: #f6f3ec;
  --card: #fffdf8;
  --ink: #2a2824;
  --muted: #77716a;
  --line: #ddd6c9;
  --accent: #46664f;
  --accent-soft: #e4ece3;
  --error: #a33b2b;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.5 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { font-family: var(--serif); font-weight: 600; line-height: 1.2; }
h1 { font-size: 1.7rem; margin: 0 0 .3rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .5rem; color: var(--muted); font-family: var(--sans); text-transform: uppercase; letter-spacing: .06em; font-size: .75rem; }
.muted { color: var(--muted); }
.error { color: var(--error); }

/* Sidhuvud */
.top { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.2rem; border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 2; }
.brand { font-family: var(--serif); font-size: 1.25rem; color: var(--ink); font-weight: 600; }
.search { flex: 1; max-width: 360px; }
.search input { width: 100%; padding: .4rem .7rem; border: 1px solid var(--line); border-radius: 999px; background: var(--paper); font: inherit; }
.me { margin-left: auto; display: flex; gap: 1rem; align-items: center; font-size: .9rem; }
.me form { margin: 0; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: .7rem 1.2rem; font: inherit; font-weight: 600; cursor: pointer; }
button.primary:disabled { opacity: .6; cursor: wait; }

main { padding: 1.2rem; }
.narrow { max-width: 560px; margin: 2rem auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1.6rem; }
.narrow.wide { max-width: 900px; }

/* Trädsidan: personen till vänster, anorna åt höger */
.tree-page { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 1.2rem; align-items: start; }
.focus { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1.2rem 1.3rem; position: sticky; top: 4.2rem; max-height: calc(100vh - 5.4rem); overflow: auto; }
.focus-head { display: flex; gap: 1rem; align-items: flex-start; }
.focus-portrait { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: .1rem .8rem; margin: .4rem 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.events { list-style: none; padding: 0; margin: 0; }
.events li { padding: .15rem 0; }
.etype { display: inline-block; min-width: 4.5rem; color: var(--muted); }
.people { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .3rem; }
.family h2 .pcard.inline { display: inline; padding: 0; border: 0; background: none; text-transform: none; letter-spacing: 0; font-size: .95rem; }
.family h2 .pcard.inline .pyears, .family h2 .pcard.inline .portrait { display: none; }
.bio { font-family: var(--serif); font-size: 1rem; }
.bio img { max-width: 100%; height: auto; border-radius: 6px; }
.bio table { border-collapse: collapse; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .6rem; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.gallery figcaption { font-size: .78rem; color: var(--muted); line-height: 1.3; margin-top: .2rem; }

.ancestors { overflow-x: auto; }
.gen-picker { font-size: .85rem; color: var(--muted); margin-bottom: .6rem; display: flex; gap: .4rem; align-items: center; }
.gen-picker a { padding: .1rem .5rem; border-radius: 6px; border: 1px solid transparent; }
.gen-picker a.on { border-color: var(--line); background: var(--card); color: var(--ink); }

.tree { display: flex; min-height: calc(100vh - 8rem); }
.tree.gen5 { min-height: 1000px; }
.tree.gen6 { min-height: 1800px; }
.col { flex: 1 1 0; min-width: 160px; display: flex; flex-direction: column; }
.slot { flex: 1 1 0; display: flex; align-items: center; padding: 2px 0 2px 14px; position: relative; min-height: 26px; }
/* Linjer: varje par (far över mor) binds ihop åt vänster mot barnet */
.slot::before { content: ""; position: absolute; left: 0; width: 14px; border-top: 1px solid var(--line); top: 50%; }
.slot.upper::after, .slot.lower::after { content: ""; position: absolute; left: 0; border-left: 1px solid var(--line); }
.slot.upper::after { top: 50%; bottom: 0; }
.slot.lower::after { top: 0; bottom: 50%; }
.slot.blank::before, .slot.blank::after { display: none; }

.pcard { display: flex; align-items: center; gap: .5rem; width: 100%; padding: .35rem .55rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; color: var(--ink); line-height: 1.25; flex-wrap: wrap; }
a.pcard:hover { border-color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.pcard .portrait { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; }
.pname { font-weight: 500; }
.pyears { color: var(--muted); font-size: .82rem; }
.pcard.empty { color: var(--muted); border-style: dashed; background: transparent; font-size: .85rem; }
.col.depth4 .pcard, .col.depth5 .pcard, .col.depth6 .pcard { padding: .15rem .45rem; font-size: .82rem; }
.col.depth4 .portrait, .col.depth5 .portrait, .col.depth6 .portrait { display: none; }
.col.depth5 .pyears, .col.depth6 .pyears { display: none; }

/* Sök och admin */
.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.invite-form { display: flex; gap: .8rem; flex-wrap: wrap; align-items: flex-end; }
.invite-form label { display: flex; flex-direction: column; font-size: .85rem; color: var(--muted); }
.invite-form input { padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 6px; font: inherit; min-width: 220px; }
.notice { background: var(--accent-soft); border-radius: 8px; padding: .8rem 1rem; margin-bottom: 1rem; }
.notice input.copy { width: 100%; padding: .4rem; font-family: ui-monospace, monospace; font-size: .85rem; }

@media (max-width: 820px) {
  .tree-page { grid-template-columns: 1fr; }
  .focus { position: static; max-height: none; }
  .tree { min-height: 640px; }
  .top { flex-wrap: wrap; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
}
