/* Stammbaum: Gestaltung "Dämmerung"
   Abendviolett für Bedienung und Links, Altrosa als Übergang, Pfirsich wie der
   erste Morgenhimmel markiert die Person im Mittelpunkt.
   Schrift: Raleway, selbst gehostet in assets/fonts (siehe LIESMICH.txt dort).
   Medium für Überschriften und Namen, Regular für Text, Light für Untertitel. */

@font-face { font-family: "Raleway"; src: url("fonts/Raleway-VariableFont_wght.ttf") format("truetype"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Raleway"; src: url("fonts/Raleway-Italic-VariableFont_wght.ttf") format("truetype"); font-weight: 100 900; font-style: italic; font-display: swap; }

:root {
  --stone: #F6F0F1;
  --paper: #FFFFFF;
  --sheet: #FBF7F8;
  --ink: #262040;
  --muted: #6E6483;
  --line: #E2D6DC;
  --line-strong: #BFB1C6;
  --dusk: #4A3D78;
  --dusk-dark: #3A2F63;
  --dusk-soft: #ECE8F4;
  --rose: #B76E8E;
  --apricot: #E0907E;
  --apricot-soft: #FDEEE8;
  --danger: #A8322A;
  --serif: "Raleway", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --sans: "Raleway", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--stone); color: var(--ink); font: 400 15px/1.55 var(--sans); font-variant-numeric: lining-nums; font-feature-settings: "lnum" 1; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--dusk); outline-offset: 2px; }
[hidden] { display: none !important; }

#app { display: flex; flex-direction: column; min-height: 100vh; }
#app.full { height: 100vh; height: 100dvh; }

/* Kopfzeile */
.bar {
  position: relative; display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap;
  padding: 12px 22px 15px; background: var(--paper);
}
/* Dämmerungsstreifen: Abendviolett, Altrosa, Pfirsich als feine Linie unter dem Kopf */
.bar::after, .print-tools::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px;
  background: linear-gradient(90deg, var(--dusk) 0 45%, var(--rose) 45% 75%, var(--apricot) 75% 100%);
}
.bar h1 { font: 500 26px/1.15 var(--serif); margin: 0 auto 0 0; letter-spacing: -.01em; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }

/* Schaltflächen */
.btn {
  font-weight: 500; border: 1px solid var(--line-strong); background: var(--paper); border-radius: 6px;
  padding: 7px 12px; cursor: pointer; line-height: 1.2; text-decoration: none; display: inline-block;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--dusk); border-color: var(--dusk); color: #fff; }
.btn.primary:hover { background: var(--dusk-dark); border-color: var(--dusk-dark); }
.btn.danger { color: var(--danger); border-color: #E6BFBB; }
.btn.danger:hover { border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); border-color: var(--line-strong); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.nav .btn[aria-current="true"] { background: var(--dusk-soft); border-color: var(--dusk); color: var(--dusk-dark); font-weight: 600; }
.btn:disabled { opacity: .55; cursor: default; }

/* Suche */
.search { position: relative; }
.search input {
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 10px; width: 230px; background: #fff;
}
.results {
  position: absolute; top: 100%; left: 0; min-width: 100%; width: 300px; margin: 4px 0 0; padding: 4px;
  list-style: none; background: #fff; border: 1px solid var(--line-strong); border-radius: 6px;
  z-index: 30; max-height: 340px; overflow: auto; box-shadow: 0 6px 18px rgba(38, 32, 64, .12);
}
.results button { width: 100%; text-align: left; background: none; border: 0; padding: 6px 8px; border-radius: 4px; cursor: pointer; }
.results button:hover, .results button:focus { background: var(--dusk-soft); }
.results .none { padding: 6px 8px; }

/* Hauptbereich: Baum links, Seitenleiste rechts */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 410px; }
.canvas {
  position: relative; overflow: hidden; min-height: 320px;
  background-color: var(--sheet);
  background-image: radial-gradient(#E4D8DE 1px, transparent 1px);
  background-size: 22px 22px;
}
.stage { position: absolute; inset: 0; }
.stage svg { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.stage svg:active { cursor: grabbing; }
.tools {
  position: absolute; left: 14px; bottom: 14px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px;
}
.tools label { font-size: 13px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.tools select { border: 1px solid var(--line-strong); border-radius: 4px; background: #fff; padding: 1px 2px; }
.hint {
  position: absolute; right: 14px; top: 12px; margin: 0; font-size: 12.5px; color: var(--muted);
  background: rgba(255, 255, 255, .88); padding: 4px 8px; border-radius: 6px;
}
.empty { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; text-align: center; padding: 24px; gap: 14px; }
.empty p { max-width: 34ch; margin: 0; font: 300 19px/1.5 var(--serif); }

.panel { background: var(--paper); border-left: 1px solid var(--line); overflow-y: auto; padding: 24px 26px 48px; }
.panel h2 { font: 500 24px/1.2 var(--serif); margin: 0 0 12px; }
.panel h2.pname { font-size: 32px; line-height: 1.12; margin-bottom: 4px; letter-spacing: -.01em; }
.sub { color: var(--muted); margin: 0 0 12px; font: 300 16px var(--serif); }
.meta { color: var(--muted); font-size: 13px; }
.lead { color: var(--muted); margin: 0 0 16px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; margin: 14px 0; }
.facts dt { color: var(--muted); font-weight: 300; }
.facts dd { margin: 0; }
.note { white-space: pre-wrap; font: 400 15.5px/1.65 var(--serif); margin: 14px 0; }
.rel { margin-top: 22px; }
.rel h3 { font: 600 13px var(--sans); color: var(--muted); letter-spacing: .02em; margin: 0 0 6px; padding-bottom: 5px; border-bottom: 1px solid var(--line); }
.rel ul { list-style: none; margin: 0; padding: 0; }
.rel li { display: flex; align-items: flex-start; gap: 6px; padding: 4px 0; }
.rel li > span:first-child { margin-right: auto; }
.link {
  background: none; border: 0; padding: 0; color: var(--dusk); cursor: pointer; text-align: left;
  text-decoration: underline; text-decoration-color: #B9AFD3; text-underline-offset: 3px;
}
.link:hover { text-decoration-color: currentColor; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 18px 0 0; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 22px 0; }

/* Formulare */
form.f { display: grid; gap: 12px; }
.f label { display: grid; gap: 4px; font-size: 13.5px; color: var(--muted); }
.f input[type=text], .f input[type=password], .f select, .f textarea {
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 8px 10px; background: #fff; color: var(--ink); font-size: 15px; width: 100%;
}
.f textarea { min-height: 120px; font: 400 15.5px/1.65 var(--serif); resize: vertical; }
.f textarea.long { min-height: 300px; }
.f .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.f .check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 15px; }
.f .help { font-size: 12.5px; color: var(--muted); margin: -6px 0 0; }
.f .buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.box { border: 1px solid var(--line); border-radius: 8px; padding: 16px; background: var(--sheet); margin-top: 18px; }
.box h3 { font: 500 17px var(--serif); margin: 0 0 12px; }
.seg { display: flex; gap: 16px; border: 0; padding: 0; margin: 0; }
.seg legend { padding: 0; margin-bottom: 4px; font-size: 13.5px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 2px; background: var(--dusk-soft); color: var(--dusk-dark); border-radius: 999px; padding: 3px 4px 3px 11px; font-size: 13.5px; color: var(--ink); }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 6px; font-size: 15px; line-height: 1; }

/* Geschichten */
.story-list { list-style: none; padding: 0; margin: 0; }
.story-list li { padding: 12px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.story-list .link { font: 500 17px/1.3 var(--serif); }
.story-body { font: 400 16.5px/1.75 var(--serif); max-width: 65ch; }
.story-body p { margin: 0 0 1em; }
.story-people { margin: 4px 0 18px; color: var(--muted); }

dialog.reader {
  border: 0; border-radius: 10px; max-width: 720px; width: calc(100% - 28px); max-height: 88vh;
  padding: 34px 40px 30px; color: var(--ink); box-shadow: 0 20px 60px rgba(38, 32, 64, .28);
}
dialog.reader::backdrop { background: rgba(38, 32, 64, .45); }
dialog.reader h2 { font: 500 32px/1.15 var(--serif); margin: 0 0 6px; }
dialog.reader .close { position: absolute; right: 14px; top: 12px; }

/* Import */
.import-preview { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.import-preview p { margin: 0 0 8px; }
.warn { margin: 10px 0 14px; padding-left: 18px; font-size: 13.5px; color: var(--ink); }
.warn li { margin-bottom: 4px; }
label.btn input[type=file] { display: none; }

/* Freigaben */
.share { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.share strong { font-family: var(--serif); font-size: 17px; }
.share-url { font-size: 12.5px; word-break: break-all; color: var(--muted); background: var(--stone); padding: 6px 8px; border-radius: 4px; margin: 8px 0; }

/* Anmeldung */
.center { max-width: 430px; width: calc(100% - 32px); margin: 12vh auto; padding: 32px; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.center h1 { font: 500 30px/1.15 var(--serif); margin: 0 0 8px; }
.notice { max-width: 520px; margin: 14vh auto; padding: 0 20px; text-align: center; font: 300 19px/1.5 var(--serif); }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; max-width: 90vw;
}
.toast.err { background: var(--danger); }

@media (max-width: 900px) {
  #app.full { height: auto; }
  .layout { grid-template-columns: 1fr; }
  .canvas { height: 64vh; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .search input { width: 100%; }
  .search { flex: 1 1 200px; }
  .hint { display: none; }
}

/* Familienbuch (Druck / PDF) */
.print-tools {
  position: sticky; top: 0; z-index: 10; display: flex; gap: 12px 16px; flex-wrap: wrap; align-items: center;
  padding: 10px 20px 14px; background: var(--paper);
}
.print-tools label { font-size: 13.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.print-tools select { border: 1px solid var(--line-strong); border-radius: 4px; padding: 3px 4px; background: #fff; }
.print-tools .meta { margin-left: auto; }
.doc { width: calc(100% - 32px); max-width: 920px; margin: 24px auto 60px; background: #fff; padding: 56px 64px; border: 1px solid var(--line); }
.doc h1 { font: 500 46px/1.05 var(--serif); margin: 0 0 6px; }
.doc h2 { font: 500 28px/1.2 var(--serif); margin: 0 0 18px; padding-bottom: 8px; border-bottom: 2px solid var(--dusk); }
.doc .treebox { margin-top: 28px; }
.doc .treebox svg { width: 100%; height: auto; max-height: 215mm; display: block; }
.reg { columns: 2; column-gap: 34px; }
.reg-item { break-inside: avoid; margin: 0 0 14px; font-size: 13px; line-height: 1.45; }
.reg-item strong { font: 500 15px var(--serif); }
.reg-item .rl { color: var(--muted); }
.doc-story { margin: 0 0 30px; }
.doc-story h3 { font: 500 22px/1.2 var(--serif); margin: 0 0 2px; break-after: avoid; }
.doc-story .story-body { font-size: 15px; max-width: none; }
.page { margin-bottom: 56px; }

/* Personenblätter (A4) */
.sheets { padding: 24px 0 60px; }
.sheet {
  width: 210mm; max-width: calc(100% - 32px); min-height: 297mm; margin: 0 auto 24px; padding: 16mm 15mm 12mm;
  background: #fff; border: 1px solid var(--line); display: flex; flex-direction: column;
}
.sheet .meta { font-size: 8.5pt; margin: 0 0 2mm; }
.sheet-head h1 { font: 500 28pt/1.05 var(--serif); margin: 0; }
.sheet-head .sub { font-size: 12pt; font-weight: 300; margin: 1.5mm 0 0; }
.sheet-facts { display: flex; flex-wrap: wrap; gap: 3mm 10mm; margin: 5mm 0 0; font-size: 10.5pt; }
.sheet-facts dt { color: var(--muted); font-size: 8.5pt; }
.sheet-facts dd { margin: 0; }
.sheet-tree { margin: 8mm 0 7mm; }
.sheet-tree svg { width: 100%; height: auto; display: block; }
.sheet-fam { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7mm; font-size: 9.5pt; line-height: 1.3; }
.sheet-fam h2 { font: 500 11.5pt var(--serif); margin: 0 0 2.5mm; padding-bottom: 1.5mm; border-bottom: .5mm solid var(--dusk); color: var(--dusk-dark); }
.sheet-fam ul { list-style: none; margin: 0; padding: 0; }
.sheet-fam li { margin: 0 0 2mm; break-inside: avoid; }
.sheet .rl { color: var(--muted); font-size: 8.5pt; }
.sheet-foot { margin-top: auto; padding-top: 6mm; display: flex; justify-content: space-between; font-size: 8pt; color: var(--muted); }
.sheet-extra { min-height: 0; display: block; }
.extra-title { font: 500 18pt/1.2 var(--serif); margin: 0 0 7mm; padding-bottom: 2mm; border-bottom: .5mm solid var(--dusk); }
.sheet-extra .story-body { font-size: 11pt; max-width: none; }
.sheet-extra .doc-story h3 { font-size: 14pt; }

@media print {
  @page { size: A4; margin: 16mm 15mm; }
  .sheets { padding: 0; }
  .sheet { width: auto; max-width: none; min-height: 263mm; margin: 0; padding: 0; border: 0; break-after: page; }
  .sheet:last-child { break-after: auto; }
  .sheet-extra { min-height: 0; }
  body { background: #fff; }
  .print-tools { display: none; }
  .doc { margin: 0; padding: 0; border: 0; max-width: none; width: auto; }
  .page { break-after: page; margin: 0; }
  .page:last-child { break-after: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
