:root {
  --paper: #f6f1e6;
  --paper-2: #ece3cf;
  --card: #fffdf8;
  --ink: #1c2230;
  --ink-2: #4b5263;
  --ink-3: #7a7f8c;
  --gold: #9a6b22;
  --gold-2: #c9a45c;
  --line: #b4a383;
  --male: #3f5f86;
  --female: #a04e63;
  --neutral: #6c6a5c;
  --focus: #d9862b;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(28, 34, 48, .08), 0 4px 14px rgba(28, 34, 48, .06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 17px/1.6 var(--sans); }
a { color: var(--male); text-underline-offset: 2px; }
a:hover { color: var(--gold); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); margin: .2em 0 .3em; }
h2 { font-size: clamp(1.35rem, 3.4vw, 1.7rem); margin: 1.6em 0 .5em; }
h3 { font-size: 1.15rem; margin: 1.2em 0 .4em; }
img { max-width: 100%; height: auto; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 760px; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 8px; background: var(--card); padding: 6px 10px; z-index: 50; }

/* Topp og bunn */
.top { border-bottom: 1px solid var(--paper-2); background: rgba(246, 241, 230, .94); position: sticky; top: 0; z-index: 30; backdrop-filter: saturate(1.2) blur(6px); }
.top .wrap { display: flex; align-items: center; gap: 18px; min-height: 58px; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; font-family: var(--serif); font-size: 1.25rem; font-weight: 600; letter-spacing: -.01em; }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand b { color: var(--gold); font-weight: 600; }
.top nav { margin-left: auto; display: flex; gap: 16px; font-size: .95rem; }
.top nav a { color: var(--ink-2); text-decoration: none; }
.top nav a:hover, .top nav a[aria-current] { color: var(--ink); text-decoration: underline; text-decoration-color: var(--gold-2); text-underline-offset: 6px; }
@media (max-width: 560px) { .top nav .hide-s { display: none; } .top nav { gap: 12px; font-size: .9rem; } .brand { font-size: 1.1rem; } }
footer.bottom { margin-top: 64px; border-top: 1px solid var(--paper-2); padding: 28px 0 40px; color: var(--ink-2); font-size: .9rem; }
footer.bottom nav { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 10px; }
footer.bottom a { color: var(--ink-2); }

.crumbs { font-size: .88rem; color: var(--ink-3); margin: 18px 0 0; }
.crumbs a { color: var(--ink-3); }
.lede { font-size: 1.12rem; color: var(--ink-2); max-width: 720px; }
.muted { color: var(--ink-3); }
.small { font-size: .88rem; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink); text-decoration: none; font: 500 .95rem var(--sans); cursor: pointer; }
.btn:hover { border-color: var(--gold); color: var(--ink); }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { background: #2c3446; color: #fff; }

/* Forside */
.hero { padding: 40px 0 10px; display: grid; grid-template-columns: 1.1fr .9fr; gap: 32px; align-items: center; }
.hero h1 { font-size: clamp(2.1rem, 6vw, 3.4rem); }
.hero .art { width: 100%; max-width: 420px; justify-self: center; }
@media (max-width: 760px) { .hero { grid-template-columns: 1fr; padding-top: 24px; } .hero .art { max-width: 300px; order: -1; } }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tcard { display: flex; flex-direction: column; gap: 4px; padding: 16px 16px 14px; background: var(--card); border: 1px solid var(--paper-2); border-radius: var(--radius); text-decoration: none; color: var(--ink); box-shadow: var(--shadow); transition: transform .12s, border-color .12s; }
.tcard:hover { transform: translateY(-2px); border-color: var(--gold-2); color: var(--ink); }
.tcard b { font-family: var(--serif); font-size: 1.12rem; font-weight: 600; }
.tcard small { color: var(--ink-3); font-size: .85rem; }
.faces { display: flex; margin-bottom: 6px; min-height: 34px; }
.faces img, .faces i { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--card); margin-right: -8px; object-fit: cover; background: var(--paper-2); }
.kicker { font: 600 .78rem/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.finder-box { margin: 26px 0; padding: 22px; background: var(--ink); color: var(--paper); border-radius: 14px; }
.finder-box h2 { margin-top: 0; color: #fff; }
.finder-box p { color: #cfd3dc; }

/* Tre-side */
.tree-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; }
.intro { max-width: 760px; }
.intro p { margin: .6em 0; }
.sources { font-size: .86rem; color: var(--ink-3); }
.sources a { color: var(--ink-3); }
.chart { position: relative; height: min(76vh, 760px); min-height: 420px; background: radial-gradient(circle at 1px 1px, rgba(154, 107, 34, .13) 1px, transparent 0) 0 0 / 22px 22px, #faf6ec; border: 1px solid var(--paper-2); border-radius: 14px; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; margin: 18px 0 8px; }
.chart.full { position: fixed; inset: 0; height: auto; z-index: 60; border-radius: 0; margin: 0; }
.chart .canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.chart svg.lines { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
.chart svg.lines path { fill: none; stroke: var(--line); stroke-width: 1.6; }
.chart svg.lines path.unc { stroke-dasharray: 5 4; }
.chart svg.lines path.mar { stroke: var(--gold-2); stroke-width: 2; }
.chart .noscript-msg { padding: 24px; }
.node { position: absolute; display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 6px; background: var(--card); border: 1px solid #e2d8c2; border-left: 4px solid var(--neutral); border-radius: 9px; box-shadow: var(--shadow); cursor: pointer; text-align: left; font: inherit; color: var(--ink); overflow: hidden; }
.node.m { border-left-color: var(--male); }
.node.f { border-left-color: var(--female); }
.node.partner { background: #fbf8f1; }
.node.ref { border-style: dashed; background: transparent; box-shadow: none; }
.node.hit { outline: 3px solid var(--focus); outline-offset: 2px; }
.node img, .node .ph { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none; background: var(--paper-2); }
.node .ph { display: grid; place-items: center; font: 600 15px var(--serif); color: var(--ink-3); }
.node .t { min-width: 0; line-height: 1.2; }
.node .n { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font: 600 13.5px/1.2 var(--sans); }
.node .y { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tog { position: absolute; width: 24px; height: 24px; margin-left: -12px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--ink-2); font: 600 15px/20px var(--sans); cursor: pointer; padding: 0; box-shadow: var(--shadow); }
.tog:hover { border-color: var(--gold); color: var(--ink); }
.glabel { position: absolute; font-size: 11px; color: var(--ink-3); white-space: nowrap; transform: translateX(-50%); background: #faf6ec; padding: 0 4px; border-radius: 4px; pointer-events: none; }
.tools { position: absolute; z-index: 5; right: 10px; top: 10px; display: flex; flex-direction: column; gap: 6px; }
.tools button, .tsearch input { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: 600 18px var(--sans); cursor: pointer; box-shadow: var(--shadow); padding: 0; }
.tools button:hover { border-color: var(--gold); }
.tools svg { width: 18px; height: 18px; vertical-align: middle; }
.tsearch { position: absolute; z-index: 6; left: 10px; top: 10px; width: min(300px, calc(100% - 70px)); }
.tsearch input { width: 100%; padding: 0 12px; font: 400 15px var(--sans); text-align: left; }
.tsearch ul, .ac ul { list-style: none; margin: 4px 0 0; padding: 4px; background: var(--card); border: 1px solid var(--paper-2); border-radius: 10px; box-shadow: var(--shadow); max-height: 260px; overflow: auto; }
.tsearch li button, .ac li button { width: 100%; text-align: left; padding: 7px 9px; border: 0; background: none; font: 14px var(--sans); color: var(--ink); border-radius: 7px; cursor: pointer; }
.tsearch li button:hover, .tsearch li button.on, .ac li button:hover, .ac li button.on { background: var(--paper); }
.hint { position: absolute; left: 10px; bottom: 8px; z-index: 4; font-size: 12px; color: var(--ink-3); background: rgba(250, 246, 236, .85); padding: 2px 8px; border-radius: 6px; pointer-events: none; }
.sheet { position: absolute; z-index: 8; right: 10px; bottom: 10px; width: min(340px, calc(100% - 20px)); background: var(--card); border: 1px solid var(--paper-2); border-radius: 14px; box-shadow: 0 10px 30px rgba(28, 34, 48, .18); padding: 16px; }
.sheet[hidden] { display: none; }
.sheet .x { position: absolute; right: 8px; top: 8px; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--ink-3); width: 34px; height: 34px; }
.sheet .who { display: flex; gap: 12px; align-items: center; padding-right: 26px; }
.sheet img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; }
.sheet h3 { margin: 0; font-size: 1.15rem; }
.sheet p { margin: 8px 0; font-size: .92rem; color: var(--ink-2); }
.sheet .acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.sheet .acts .btn { padding: 7px 12px; font-size: .88rem; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .84rem; color: var(--ink-3); margin-bottom: 8px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }
.legend .dash { width: 22px; height: 0; border-top: 2px dashed var(--line); border-radius: 0; vertical-align: 3px; }

/* Tekstversjon av treet (også utskrift) */
.outline, .outline ul { list-style: none; padding-left: 0; margin: 0; }
.outline ul { padding-left: 18px; border-left: 1px solid var(--paper-2); margin-left: 6px; }
.outline li { margin: 3px 0; }
.outline .p { font-weight: 600; }
.outline .yrs, .outline .sp { color: var(--ink-3); font-size: .9rem; }
.outline .grp { font-size: .82rem; color: var(--gold); margin-top: 4px; font-style: italic; }
details.textv { margin: 26px 0; background: var(--card); border: 1px solid var(--paper-2); border-radius: var(--radius); padding: 4px 18px; }
details.textv summary { cursor: pointer; padding: 12px 0; font-family: var(--serif); font-size: 1.15rem; font-weight: 600; }

/* Personside */
.person-head { display: grid; grid-template-columns: auto 1fr; gap: 22px; align-items: center; margin-top: 10px; }
.portrait { width: 150px; }
.portrait img { width: 150px; height: 180px; object-fit: cover; border-radius: 12px; box-shadow: var(--shadow); display: block; }
.portrait figcaption { font-size: .72rem; color: var(--ink-3); margin-top: 4px; line-height: 1.3; }
.portrait figcaption a { color: var(--ink-3); }
@media (max-width: 560px) { .person-head { grid-template-columns: 1fr; } .portrait { width: 120px; } .portrait img { width: 120px; height: 144px; } }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 10px 0; font-size: .96rem; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; }
.mini { margin: 18px 0; padding: 18px 10px; background: #faf6ec; border: 1px solid var(--paper-2); border-radius: 14px; overflow-x: auto; }
.mini .row { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; position: relative; }
.mini .row + .row { margin-top: 26px; }
.mini .row + .row::before { content: ""; position: absolute; top: -20px; left: 50%; height: 14px; border-left: 1.6px solid var(--line); }
.mini .lab { width: 100%; text-align: center; font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 2px; }
.pc { display: flex; gap: 8px; align-items: center; min-width: 0; max-width: 220px; padding: 6px 10px 6px 6px; background: var(--card); border: 1px solid #e2d8c2; border-left: 4px solid var(--neutral); border-radius: 9px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); font-size: .86rem; line-height: 1.2; }
.pc.m { border-left-color: var(--male); }
.pc.f { border-left-color: var(--female); }
.pc.me { outline: 2px solid var(--gold-2); }
.pc img, .pc .ph { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none; background: var(--paper-2); display: grid; place-items: center; font: 600 13px var(--serif); color: var(--ink-3); }
.pc small { display: block; color: var(--ink-3); font-size: .76rem; }
a.pc:hover { border-color: var(--gold-2); color: var(--ink); }
.rel-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; margin: 8px 0 18px; }
.rel-list .pc { max-width: none; }
.flag { display: inline-block; font-size: .72rem; padding: 1px 6px; border-radius: 6px; background: #f4e3c5; color: #7a5212; margin-left: 4px; vertical-align: 1px; }
.note { padding: 12px 14px; background: #fbf3e2; border-left: 3px solid var(--gold-2); border-radius: 6px; font-size: .92rem; color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips a { padding: 5px 12px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--ink); background: var(--card); font-size: .9rem; }
.chips a:hover { border-color: var(--gold); }

/* Slektskapssøker */
.finder { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: end; margin: 18px 0; }
.finder label { display: block; font-size: .85rem; color: var(--ink-3); margin-bottom: 4px; }
.finder .and { padding-bottom: 10px; font-family: var(--serif); font-style: italic; color: var(--ink-3); }
.ac { position: relative; }
.ac input { width: 100%; height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font: 16px var(--sans); color: var(--ink); }
.ac input:focus, .tsearch input:focus { outline: 2px solid var(--gold-2); outline-offset: 1px; }
.ac ul { position: absolute; left: 0; right: 0; z-index: 20; }
.finder-box .ac input { border-color: #49526a; }
@media (max-width: 640px) { .finder { grid-template-columns: 1fr; } .finder .and { padding: 0; text-align: center; } }
.answer { margin: 22px 0; padding: 22px; background: var(--card); border: 1px solid var(--paper-2); border-radius: 14px; box-shadow: var(--shadow); }
.answer .big { font-family: var(--serif); font-size: clamp(1.25rem, 3.6vw, 1.6rem); line-height: 1.35; margin: 0 0 8px; }
.path { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-direction: column; align-items: flex-start; }
.path li { display: flex; flex-direction: column; align-items: flex-start; }
.path .step { font-size: .82rem; color: var(--gold); padding: 4px 0 4px 18px; border-left: 2px solid var(--gold-2); margin-left: 18px; font-style: italic; }

/* Lister */
.plist { columns: 3 220px; column-gap: 24px; padding: 0; list-style: none; }
.plist li { break-inside: avoid; margin: 2px 0; }

@media print {
  .top, footer.bottom, .chart, .no-print, .crumbs { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  details.textv { border: 0; padding: 0; }
  details.textv > *:not(summary) { display: block; }
  .outline a { color: #000; text-decoration: none; }
  .outline ul { border-left-color: #999; }
}
@media (max-width: 640px) {
  .chart { height: 72vh; min-height: 380px; }
  .tools { top: auto; bottom: 10px; right: 10px; flex-direction: row; }
  .tools button { width: 36px; height: 36px; }
  .tsearch { width: calc(100% - 20px); }
  .hint { display: none; }
  .sheet { right: 8px; left: 8px; width: auto; bottom: 8px; }
  .tree-head .no-print { display: none; }
}
