/* Stammbaum viewer — "Karte und Akte": a dark reading-room stage with paper cards for the whole
 * pedigree, and a paper dossier for each person. System fonts only, phone first. */

:root {
  /* stage (dark, warm) */
  --stage: #1d1915;
  --stage-deep: #15120f;
  --stage-glow: #2d2620;
  --cream: #f3ead9;
  --cream-soft: #d9cdb8;
  --cream-muted: #b4a68f;
  --gold: #e2b96a;
  --gold-soft: rgba(226, 185, 106, .32);
  --line-dark: rgba(226, 203, 160, .28);
  --line-dark-strong: rgba(226, 203, 160, .5);
  /* paper (panel, cards) */
  --paper: #f6efe3;
  --paper-deep: #ebe2d2;
  --paper-edge: #d8ccb6;
  --card: #fbf6ec;
  --ink: #2a2522;
  --ink-soft: #4b443d;
  --muted: #6b625a;
  --line: #ddd3c2;
  --line-strong: #bdb09b;
  --accent: #3c5478;
  --accent-ink: #2b3d5a;
  --focus: #e2b96a;
  --danger: #a3432f;
  /* grandparent lines */
  --q-1: #5b7fb5;
  --q-2: #6f9a62;
  --q-3: #cf9a3e;
  --q-4: #b06d90;
  --q-none: #8d8373;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Charter, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --node-w: 148px;
  --node-h: 62px;
  --node-h-small: 40px;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 12, 4, .25), 0 10px 28px -12px rgba(20, 12, 4, .55);
  --top-h: 60px;
  --demo-h: 0px;   /* height of the "Example" strip; only the demo build (html.demo) shows it */
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  height: 100dvh;   /* phones: follow the browser bar as it shows/hides, no gap behind the toolbar */
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--cream);
  background: var(--stage);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
img { max-width: 100%; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- header ---------- */
.top {
  position: relative; z-index: 20; user-select: none; -webkit-user-select: none;
  height: var(--top-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
  background: linear-gradient(to bottom, #241f1a, var(--stage));
  border-bottom: 1px solid rgba(226, 203, 160, .16);
}
.brand { min-width: 0; flex: 0 1 auto; }
.brand-title {
  font-family: var(--serif); font-weight: 600; font-size: 22px; letter-spacing: .01em; line-height: 1.15;
  margin: 0; white-space: nowrap; color: var(--cream);
}
.brand-sub { font-size: 12.5px; color: var(--cream-muted); white-space: nowrap; letter-spacing: .03em; overflow: hidden; text-overflow: ellipsis; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--cream-soft);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: rgba(255, 255, 255, .08); color: var(--cream); }
.lang { display: inline-flex; border: 1px solid var(--line-dark-strong); border-radius: 999px; padding: 2px; margin: 0 4px; }
.lang-btn {
  border: 0; background: transparent; border-radius: 999px;
  padding: 3px 10px; font-size: 13px; font-weight: 600; letter-spacing: .04em;
  cursor: pointer; color: var(--cream-muted);
}
.lang-btn[aria-pressed="true"] { background: var(--gold); color: var(--stage); }
/* compact control of a site with more than two languages (.lang.many): one gold pill with the current code
   that opens a list of the languages, each in its own name. Phones only (below); desktop keeps the pills. */
.lang { position: relative; }
.lang-cur, .lang-list { display: none; }
.lang-cur {
  align-items: center; gap: 2px; border: 0; border-radius: 999px; min-height: 36px; padding: 3px 6px 3px 12px;
  background: var(--gold); color: var(--stage); font-size: 13px; font-weight: 600; letter-spacing: .04em; cursor: pointer;
}
.lang-cur svg { width: 16px; height: 16px; transition: transform .15s; }
.lang-cur[aria-expanded="true"] svg { transform: rotate(180deg); }
.lang-list {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 180px; padding: 6px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.lang-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 8px 12px 8px 10px;
  border: 0; border-radius: 8px; background: transparent; text-align: left; font-size: 16px; cursor: pointer;
}
.lang-item::before { content: ""; width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--line-strong); flex: none; }
.lang-item[aria-checked="true"] { font-weight: 600; }
.lang-item[aria-checked="true"]::before { background: var(--gold); border-color: var(--gold); }
.lang-item:hover { background: var(--paper-deep); }

/* search */
.search { position: relative; flex: 1 1 auto; max-width: 440px; margin-left: 18px; }
.search-icon { position: absolute; left: 12px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--cream-muted); pointer-events: none; }
.search input {
  width: 100%; height: 40px;
  border: 1px solid var(--line-dark-strong); border-radius: 999px;
  padding: 0 14px 0 38px;
  font: inherit; font-size: 16px; color: var(--cream);
  background: rgba(255, 255, 255, .06);
  -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--cream-muted); }
.search input:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 3px var(--gold-soft); background: rgba(255, 255, 255, .09); }
.search-toggle { display: none; }
/* "Cancel" next to the field, phones only (there is no Escape key) */
.search-cancel { display: none; position: absolute; right: 0; top: 0; height: 40px; padding: 0 10px; border: 0; background: transparent; color: var(--gold); font-size: 15px; font-weight: 600; cursor: pointer; }
.results {
  position: absolute; left: 0; right: 0; top: 46px;
  margin: 0; padding: 6px; list-style: none;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: min(60vh, 420px); overflow: auto;
}
.results li { padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; align-items: baseline; }
.results li[aria-selected="true"], .results li:hover { background: var(--paper-deep); }
.results .r-name { font-family: var(--serif); font-size: 17px; }
.results .r-sub { font-size: 13.5px; color: var(--muted); margin-left: auto; text-align: right; }
.results .r-empty { color: var(--muted); cursor: default; }
.results .r-empty:hover { background: none; }
.qdot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--q); flex: none; position: relative; top: -1px; }

/* ---------- stage ---------- */
/* demo build only (data-demo="1"): calm one-line note linking back to the Andante home page */
html.demo { --demo-h: 32px; }
.demo-banner {
  height: var(--demo-h); display: flex; align-items: center; justify-content: center; gap: .45em;
  padding: 0 14px; font-size: 13.5px; color: var(--cream-soft); background: #2a231d;
  border-bottom: 1px solid rgba(226, 203, 160, .16); white-space: nowrap; overflow: hidden;
}
.demo-banner span { overflow: hidden; text-overflow: ellipsis; }
.demo-banner a { color: var(--gold); flex: none; }

.main { position: relative; height: calc(100% - var(--top-h) - var(--demo-h)); display: flex; }
.stage {
  position: relative; flex: 1 1 auto; min-width: 0;
  overflow: hidden; touch-action: none; cursor: grab; outline: none; user-select: none; -webkit-user-select: none;
  background:
    radial-gradient(ellipse 70% 55% at 50% 108%, rgba(226, 185, 106, .16), transparent 70%),
    linear-gradient(to top, var(--stage) 0%, var(--stage-deep) 100%);
}
.stage.dragging { cursor: grabbing; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.world.moving { will-change: transform; }
.world.glide { transition: transform .5s cubic-bezier(.2, .7, .2, 1); }
.bands { position: absolute; pointer-events: none; }
.bands > div { position: absolute; left: 0; right: 0; background: rgba(255, 255, 255, .025); }
/* connectors: every segment drawn once, solid colour (no overlap artefacts), stroke in screen pixels
   (non-scaling) so lines stay crisp at every zoom */
.links { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#links-all { fill: none; stroke: #5d523f; stroke-width: 1.5px; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
#links-path { fill: none; stroke: var(--gold); stroke-width: 3px; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.world.far #links-all { stroke-width: 1px; stroke: #4a4133; }
.nodes, .knots { position: absolute; left: 0; top: 0; }

.loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--cream-muted); font-family: var(--serif); font-size: 18px; pointer-events: none;
}
.loading:empty { display: none; }
.hint {
  position: absolute; left: 50%; top: 18px; transform: translateX(-50%);
  padding: 8px 16px; border-radius: 999px; font-size: 14px; color: var(--cream-soft);
  background: rgba(29, 25, 21, .85); border: 1px solid var(--line-dark); pointer-events: none;
  opacity: 0; transition: opacity .6s; white-space: nowrap; max-width: calc(100% - 100px); overflow: hidden; text-overflow: ellipsis;
}
.hint.show { opacity: 1; }

/* ---------- nodes (three levels of detail, chosen by zoom) ---------- */
.node {
  position: absolute; left: 0; top: 0;
  width: var(--node-w); height: var(--node-h);
  --q: var(--q-none);
  transition: transform .45s cubic-bezier(.2, .7, .2, 1), opacity .3s;
}
.node.enter { opacity: 0; }
.nodes.reveal .node { animation: rise .7s cubic-bezier(.2, .7, .2, 1) both; animation-delay: calc(var(--gen) * 55ms); }
@keyframes rise { from { opacity: 0; translate: 0 18px; } to { opacity: 1; translate: 0 0; } }
.node-btn {
  position: absolute; inset: 0;
  display: flex; align-items: center; gap: 8px;
  width: 100%; height: 100%;
  padding: 5px 8px 5px 12px;
  border: 1.5px solid var(--paper-edge); border-radius: var(--radius);
  background: var(--card); color: var(--ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, .4) inset, 0 2px 6px rgba(0, 0, 0, .35);
  text-align: left; cursor: pointer;
}
.node-btn::before { border-radius: var(--radius) 0 0 var(--radius); }
.node-btn::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--q); }
/* confidence on the card's border (before hover/selected so their colours win). The hypothesis card is opaque
   and a shade darker: a translucent card let the dash vanish into the dark background. */
.node.inferred .node-btn { border: 2px dotted #a39580; }
.node.hypothesis .node-btn { border: 2px dashed var(--muted); background: #ece4d5; }
.node-btn:hover { border-color: var(--q); box-shadow: 0 0 0 2px color-mix(in srgb, var(--q) 50%, transparent), 0 6px 18px rgba(0, 0, 0, .5); }
.node.selected .node-btn { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft), 0 0 24px rgba(226, 185, 106, .35); }
.node.placeholder .node-btn { background: var(--paper-deep); border-color: var(--paper-deep); }
.node.placeholder .node-btn::before { background: var(--line-strong); }
.node-text { min-width: 0; flex: 1; }
.node-name {
  font-family: var(--serif); font-size: 14.5px; line-height: 1.18; font-weight: 600; color: var(--ink);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.node.placeholder .node-name { font-weight: 500; color: var(--ink-soft); }
.node-years { font-size: 12.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
/* portrait as a medallion pinned to the card's corner, so the name keeps the full width */
.node-avatar {
  position: absolute; right: -9px; top: -11px; width: 36px; height: 36px; border-radius: 50%; object-fit: cover;
  border: 2px solid var(--card); background: var(--paper-deep); box-shadow: 0 2px 6px rgba(0, 0, 0, .5);
}
.node.has-photo .node-text { padding-right: 16px; }
/* mid level: surname big, given name small */
.node-mid { display: none; position: absolute; inset: 0 6px 0 13px; flex-direction: column; justify-content: center; min-width: 0; overflow: hidden; }
.node-mid .sur { font-family: var(--serif); font-weight: 700; font-size: 27px; line-height: 30px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.node-mid .giv { font-size: 14px; line-height: 18px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node-btn:hover, .node.selected .node-btn { z-index: 1; }
.world.mid .node-text, .world.mid .node-avatar { display: none; }
.world.mid .node-mid { display: flex; }
.world.mid .node-btn { gap: 0; padding: 0; }
/* far level: coloured tiles — the shape of the tree */
.world.far .node-btn > * { display: none !important; }
.world.far .node-btn { background: var(--q); border-color: transparent; box-shadow: none; border-radius: 14px; }
.world.far .node-btn::before { display: none; }
.world.far .node.hypothesis .node-btn, .world.far .node.inferred .node-btn { opacity: .45; }
.world.far .node.placeholder .node-btn { background: var(--cream-soft); }
.world.far .node.selected .node-btn { box-shadow: 0 0 0 12px var(--gold); }
.world.far .node.dup .node-btn { opacity: .35; border-radius: 30px; }

/* compact pointer node: the same person already has a full branch elsewhere */
.node.dup { height: var(--node-h-small); }
.node.dup .node-btn { background: rgba(251, 246, 236, .12); border: 1.5px dashed var(--line-dark-strong); color: var(--cream-soft); box-shadow: none; padding: 3px 8px 3px 11px; }
.node.dup .node-btn::before { opacity: .7; width: 4px; }
.node.dup .node-name { font-weight: 500; font-size: 13.5px; -webkit-line-clamp: 1; color: var(--cream); }
.node.dup .node-years { font-size: 11.5px; font-style: italic; color: var(--cream-muted); display: flex; align-items: center; gap: 4px; }
.node.dup .node-years svg { width: 11px; height: 11px; flex: none; }
.node.dup .node-mid .sur { color: var(--cream-soft); font-size: 18px; line-height: 20px; font-weight: 500; }
.node.dup .node-mid .giv { color: var(--cream-muted); font-size: 11px; line-height: 13px; }
.node.unknown .node-mid .sur { font-size: 18px; line-height: 20px; font-weight: 400; font-style: italic; color: var(--cream-muted); }
.node.dup.selected .node-btn { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }

/* unknown stub bridging a gap below a hypothesis line */
.node.unknown { height: var(--node-h-small); }
.node.unknown .node-btn { background: transparent; border: 1.5px dashed var(--line-dark); color: var(--cream-muted); box-shadow: none; cursor: default; }
.node.unknown .node-btn::before { opacity: .35; }
.node.unknown .node-name { font-weight: 400; font-style: italic; color: var(--cream-muted); font-size: 13.5px; }
.world.far .node.unknown .node-btn { background: transparent; border-color: var(--line-dark); }

/* side family: siblings of an ancestor and their descendants, in every generation; lighter and narrower */
.node.side { width: 128px; height: 50px; }
.node.side .node-btn { background: rgba(251, 246, 236, .8); border-color: rgba(216, 204, 182, .7); padding: 4px 6px 4px 11px; box-shadow: 0 1px 4px rgba(0, 0, 0, .3); }
.node.side .node-btn::before { width: 4px; opacity: .75; }
.node.side .node-name { font-size: 13px; font-weight: 500; line-height: 1.15; }
.node.side .node-years { font-size: 11.5px; margin-top: 1px; }
.node.side .node-mid .sur { font-size: 20px; line-height: 22px; font-weight: 600; }
.node.side .node-mid .giv { font-size: 11px; line-height: 13px; }
.node.side.selected .node-btn { background: var(--card); border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft), 0 0 24px rgba(226, 185, 106, .35); }
.world.far .node.side .node-btn { opacity: .55; border-radius: 10px; }
#links-half { fill: none; stroke: #5d523f; stroke-width: 1.5px; vector-effect: non-scaling-stroke; stroke-dasharray: 4 3; }

/* unfold pill above a card whose ancestors are hidden: "+ 5 Gen." */
.fold {
  position: absolute; left: 50%; top: -15px; transform: translateX(-50%); z-index: 2;
  display: inline-flex; align-items: center; gap: 3px; height: 22px; padding: 0 8px 0 5px;
  border-radius: 999px; border: 1px solid var(--gold); background: var(--stage); color: var(--gold);
  font-size: 11px; font-weight: 600; letter-spacing: .02em; white-space: nowrap; cursor: pointer;
}
.fold::after { content: ""; position: absolute; inset: -8px; }
.fold svg { width: 12px; height: 12px; }
.fold:hover { background: var(--gold); color: var(--stage); }
.node.open .fold { display: none; }
.world.mid .fold { height: 26px; padding: 0 6px; top: -18px; }
.world.mid .fold .fold-txt { display: none; }
.world.mid .fold svg { width: 16px; height: 16px; }
.world.far .fold { display: none; }

/* side-family fold pill on the outer side of an ancestor's card (room for it is kept by the layout, SIDE_PILL):
   "+ n" in gold while the siblings are folded, a small ring with a minus (like the knot) while they are open */
.sfold {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  display: inline-flex; align-items: center; justify-content: center; height: 22px; padding: 0 7px 0 4px;
  border-radius: 999px; border: 1px solid var(--gold); background: var(--stage); color: var(--gold);
  font-size: 11px; font-weight: 600; letter-spacing: .02em; font-variant-numeric: tabular-nums; white-space: nowrap; cursor: pointer;
}
.sfold.l { right: calc(100% + 4px); }
.sfold.r { left: calc(100% + 4px); }
.sfold::after { content: ""; position: absolute; inset: -8px; }
.sfold svg { width: 11px; height: 11px; }
.sfold .sf-plus { display: inline-flex; align-items: center; gap: 2px; }
.sfold .sf-minus { display: none; }
.sfold:hover { background: var(--gold); color: var(--stage); }
.node.side-open .sfold { width: 18px; height: 18px; padding: 0; border-color: var(--line-dark-strong); color: var(--cream-soft); }
.node.side-open .sfold.l { right: calc(100% + 6px); }
.node.side-open .sfold.r { left: calc(100% + 6px); }
.node.side-open .sfold .sf-plus { display: none; }
.node.side-open .sfold .sf-minus { display: inline-flex; }
.node.side-open .sfold:hover { background: var(--stage); border-color: var(--gold); color: var(--gold); }
.world.mid .sfold { height: 26px; width: 26px; padding: 0; }
.world.mid .sfold .sf-n { display: none; }
.world.mid .sfold svg { width: 16px; height: 16px; }
.world.mid .node.side-open .sfold, .world.far .sfold { display: none; }

/* junction knot: sits exactly where the child's line meets the parents' bus; shows the marriage year
   and folds the branch when clicked */
.knot {
  position: absolute; transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px 8px 1px 6px; border-radius: 999px; white-space: nowrap; cursor: pointer;
  font: 600 11px/15px var(--sans); letter-spacing: .02em; font-variant-numeric: tabular-nums;
  color: var(--cream-soft); background: var(--stage); border: 1px solid var(--line-dark-strong);
}
.knot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid var(--gold); flex: none; box-sizing: border-box; }
.knot::after { content: ""; position: absolute; inset: -8px; }
.knot.nodate { width: 13px; height: 13px; padding: 0; justify-content: center; }
.knot.nodate::before { width: 5px; height: 5px; }
.knot:hover { border-color: var(--gold); color: var(--gold); }
.knot:hover::before { background: var(--gold); }
.world.mid .knot, .world.far .knot { display: none; }
.tool.on { color: var(--gold); }
.tool .ic-collapse { display: none; }
.tool.on .ic-expand { display: none; }
.tool.on .ic-collapse { display: block; }
.tool-sep { height: 1px; background: var(--line-dark); margin: 2px 6px; }

/* generation ruler (screen space, follows the pan) */
.ruler { position: absolute; left: 0; top: 0; bottom: 0; width: 84px; pointer-events: none; z-index: 4;
  background: linear-gradient(to right, var(--stage-deep) 72px, transparent); }
.ruler button {
  position: absolute; left: 6px; transform: translateY(-50%);
  pointer-events: auto; cursor: pointer; border: 0; background: transparent; text-align: left;
  padding: 4px 8px; border-radius: 8px; color: var(--cream-soft); line-height: 1.1;
}
.ruler button:hover { background: rgba(255, 255, 255, .08); color: var(--cream); }
.ruler .rg { display: block; font-family: var(--serif); font-size: 15px; font-weight: 600; color: var(--cream); }
.ruler .ry { display: block; font-size: 11.5px; color: var(--cream-muted); margin-top: 1px; white-space: nowrap; }
.ruler button.hidden { visibility: hidden; pointer-events: none; }
/* compact form (phones, landscape phones; app.js sets the class): one small pill per generation */
.ruler.compact { width: 60px; background: none; }
.ruler.compact button { left: 4px; height: 24px; min-height: 0; padding: 0 9px; border-radius: 999px; white-space: nowrap; background: rgba(21, 18, 15, .88); border: 1px solid var(--line-dark); }
.ruler.compact button::after { content: ""; position: absolute; inset: -10px; }   /* 44px finger target */
.ruler.compact .rg { font-size: 12px; line-height: 22px; }
.ruler.compact .ry { display: none; }

/* minimap strip */
.minimap {
  position: absolute; left: 96px; bottom: 14px; z-index: 5;
  width: 280px; height: 56px; border-radius: 10px; overflow: hidden; cursor: crosshair;
  background: rgba(21, 18, 15, .9); border: 1px solid var(--line-dark); box-shadow: var(--shadow);
}
.minimap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.mm-view { position: absolute; border: 1.5px solid var(--gold); background: rgba(226, 185, 106, .18); border-radius: 2px; pointer-events: none; min-width: 4px; min-height: 4px; }

/* toolbar + legend */
.toolbar {
  position: absolute; right: 14px; bottom: 14px; z-index: 5;
  display: flex; flex-direction: column; gap: 2px; padding: 4px; border-radius: 14px;
  background: rgba(21, 18, 15, .9); border: 1px solid var(--line-dark); box-shadow: var(--shadow);
}
.tool { width: 42px; height: 42px; border: 0; border-radius: 10px; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--cream-soft); }
.tool svg { width: 22px; height: 22px; }
.tool:hover { background: rgba(255, 255, 255, .08); color: var(--cream); }

.legend {
  position: absolute; left: 390px; bottom: 14px; z-index: 5;
  padding: 8px 14px; border-radius: 10px;
  background: rgba(21, 18, 15, .9); border: 1px solid var(--line-dark);
  font-size: 13px; color: var(--cream-soft);
  display: grid; grid-template-columns: auto auto; gap: 3px 16px;
}
.legend .lg { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.legend-btn {
  position: absolute; left: 390px; bottom: 14px; z-index: 5; display: none;
  height: 34px; padding: 0 14px; border-radius: 999px; cursor: pointer; font-size: 13px;
  background: rgba(21, 18, 15, .9); border: 1px solid var(--line-dark); color: var(--cream-soft);
}
.legend-btn:hover { color: var(--cream); border-color: var(--line-dark-strong); }
/* narrower windows: the legend folds into a button (the about box carries the full legend) */
@media (max-width: 1180px) {
  .legend { display: none; }
  .legend-btn { display: inline-flex; align-items: center; }
}
@media (max-width: 900px) {
  .minimap { width: 220px; }
  .legend-btn { left: 330px; }
}
.lg-line { width: 22px; height: 0; border-top: 2px solid var(--cream-muted); flex: none; }
.lg-line.inferred { border-top-style: dotted; }
.lg-line.hypothesis { border-top-style: dashed; }
.lg-line.primary { border-top-color: var(--cream); border-top-width: 2.5px; }

/* ---------- dossier panel (paper) ---------- */
.panel {
  position: relative; z-index: 10; flex: 0 0 auto;
  width: min(500px, 46vw);
  display: flex; flex-direction: column;
  background: var(--paper); color: var(--ink);
  border-left: 1px solid #0f0c09;
  box-shadow: -14px 0 40px -14px rgba(0, 0, 0, .7);
}
.panel[hidden] { display: none; }
.panel-bar {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); background: var(--paper);
}
.panel-grip { display: none; }   /* sheet handle, phones only */
.panel-bar .icon-btn { color: var(--ink-soft); }
.panel-bar .icon-btn:hover { background: var(--paper-deep); color: var(--ink); }
.panel-tree {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--card); border-radius: 999px;
  padding: 6px 14px 6px 10px; font-size: 14px; cursor: pointer; color: var(--ink-soft);
}
.panel-tree svg { width: 18px; height: 18px; }
.panel-tree:hover { background: var(--paper-deep); color: var(--ink); }
.panel-body { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; padding: 22px 24px 56px; outline: none; -webkit-overflow-scrolling: touch; }
.panel a { color: var(--accent); }
.panel a:hover { color: var(--accent-ink); }

.p-head { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; padding-bottom: 16px; border-bottom: 1px solid var(--line-strong); margin-bottom: 4px; }
.p-head > * { grid-column: 1; }
.p-portrait { grid-column: 2; grid-row: 1 / span 4; width: 92px; height: 92px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line-strong); background: var(--paper-deep); cursor: zoom-in; padding: 0; }
.p-portrait img { width: 100%; height: 100%; object-fit: cover; display: block; }
.p-eyebrow { font-size: 13px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.p-name { font-family: var(--serif); font-size: 30px; line-height: 1.12; font-weight: 600; margin: 0; letter-spacing: -.005em; }
.p-aka { color: var(--muted); font-size: 15px; }
.p-relation { font-family: var(--serif); font-style: italic; font-size: 18px; color: var(--ink-soft); margin-top: 4px; }
.p-life { margin-top: 6px; font-size: 15.5px; color: var(--ink-soft); line-height: 1.45; }
.p-life .age { color: var(--ink); font-weight: 600; }
.p-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 13px;
  border: 1px solid var(--line-strong); color: var(--ink-soft); background: var(--card);
}
.chip .qdot { top: 0; }
.chip.c-primary { border-color: var(--ink-soft); }
.chip.c-inferred { border-style: dotted; }
.chip.c-hypothesis { border-style: dashed; }
.chip.c-step { color: var(--muted); font-style: italic; }
.p-conf { font-size: 14px; color: var(--muted); margin-top: 8px; }
.p-living { font-size: 16px; color: var(--muted); font-style: italic; }

.p-sec { margin: 24px 0 0; }
.p-sec h3 {
  font-family: var(--sans); font-size: 12.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.p-sec h3 .n { font-weight: 500; letter-spacing: 0; margin-left: 6px; }
.p-sec p { margin: 0 0 8px; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; font-size: 15.5px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.facts ul { margin: 0; padding-left: 18px; }
.facts li { margin-bottom: 3px; }
.facts .place { color: var(--ink-soft); }

.plink {
  display: inline-flex; align-items: baseline; gap: 6px;
  color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer;
  text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 3px;
  font-size: inherit; text-align: left; font-family: inherit;
}
.plink:hover { color: var(--accent-ink); text-decoration-color: currentColor; }
.plink .yrs { color: var(--muted); font-size: .9em; text-decoration: none; }

.fam { display: grid; grid-template-columns: max-content 1fr; gap: 8px 14px; margin: 0; font-size: 15.5px; }
.fam dt { color: var(--muted); }
.fam dd { margin: 0; display: flex; flex-direction: column; gap: 6px; }

.cards { display: grid; gap: 8px; margin-top: 8px; }
.fam-head { margin-top: 16px; }
.card {
  display: block; width: 100%; text-align: left;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  padding: 10px 12px; cursor: pointer;
}
.card:hover { border-color: var(--line-strong); background: var(--paper-deep); }
.card .c-name { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.card .c-sub { font-size: 14px; color: var(--muted); }
.card .c-rel { font-size: 14.5px; color: var(--ink-soft); margin-top: 2px; }

.photos { display: flex; flex-wrap: wrap; gap: 8px; }
.photo { border: 1px solid var(--line); padding: 0; background: var(--paper-deep); border-radius: 8px; overflow: hidden; cursor: zoom-in; width: 108px; height: 108px; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* the timeline: events and stories in one chronology, with the person's age in the margin */
.timeline { list-style: none; margin: 0; padding: 0; }
.tl { position: relative; display: grid; grid-template-columns: 78px 1fr; gap: 0 22px; padding-bottom: 18px; }
.tl::before { content: ""; position: absolute; left: 90px; top: 12px; bottom: -4px; width: 2px; background: var(--line); }
.tl:last-child::before { bottom: auto; height: 10px; }
.tl::after { content: ""; position: absolute; left: 85px; top: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--card); border: 2.5px solid var(--line-strong); box-sizing: border-box; }
.tl.hypothesis::after { border-style: dashed; }
.tl.inferred::after { border-style: dotted; }
.tl.primary::after { border-color: var(--ink-soft); background: var(--ink-soft); }
.tl.event::after { border-color: var(--accent); background: var(--accent); border-radius: 2px; transform: rotate(45deg); width: 10px; height: 10px; left: 86px; top: 9px; }
.tl-when { text-align: right; min-width: 0; }
.tl-year { display: block; font-family: var(--serif); font-size: 16.5px; font-weight: 600; line-height: 1.4; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
.tl-year.undated { color: var(--muted); font-size: 14px; font-weight: 500; }
.tl-age { display: block; font-size: 12.5px; color: var(--muted); line-height: 1.3; white-space: nowrap; }
.tl-body { padding-left: 16px; min-width: 0; }
.tl-kind { font-weight: 600; color: var(--ink); }
.tl-event { font-size: 16px; }
.tl-event .place { color: var(--ink-soft); }
.tl-cat { display: inline-block; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 2px; }
.tl-about { font-size: 14px; color: var(--ink-soft); margin-bottom: 4px; font-style: italic; }
.tl-text { margin: 0; font-size: 16px; font-family: var(--serif); line-height: 1.55; }
.tl blockquote {
  margin: 10px 0 6px; padding: 6px 0 6px 14px; border-left: 3px solid var(--gold);
  font-family: var(--serif); font-size: 15.5px; color: var(--ink-soft); font-style: italic;
}
.tl-src { font-size: 13.5px; color: var(--muted); margin-top: 6px; line-height: 1.45; }
.tl-src a { white-space: nowrap; }
.scans { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.scan { border: 1px solid var(--line); padding: 0; background: var(--paper-deep); border-radius: 6px; overflow: hidden; height: 76px; width: 100px; cursor: zoom-in; }
.scan img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.tl-undated { font-size: 12.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 6px 0 12px 100px; }

.notes { margin: 0; padding-left: 20px; font-size: 15.5px; font-family: var(--serif); }
.notes li { margin-bottom: 8px; }
.sources { margin: 0; padding-left: 20px; font-size: 14.5px; color: var(--ink-soft); }
.sources li { margin-bottom: 8px; }
.ext::after { content: " ↗"; font-size: .85em; }
.p-fs { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--line); font-size: 14.5px; }

/* ---------- lightbox / modals / scrim ---------- */
.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(10, 8, 6, .6); }
.scrim[hidden] { display: none; }
.lightbox {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: #0e0b09; color: var(--cream);
}
.lightbox[hidden] { display: none; }
.lightbox-close { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); color: var(--cream); z-index: 2; }
.lightbox-fig { margin: 0; width: 100%; height: 100%; display: flex; flex-direction: column; }
/* the image zooms and pans with two fingers / a drag / a double tap (app.js sets the transform) */
.lightbox-img-wrap { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 52px 12px 8px; overflow: hidden; touch-action: none; }
.lightbox-img-wrap img { max-width: 100%; max-height: min(100%, calc(100vh - 150px)); width: auto; height: auto; object-fit: contain; background: #fff; transform-origin: 0 0; user-select: none; -webkit-user-drag: none; }
.lightbox-img-wrap.zoomed img { cursor: grab; }
.lightbox figcaption { flex: none; padding: 10px 18px 22px; font-size: 14.5px; max-width: 900px; margin: 0 auto; color: var(--cream-soft); text-align: center; }
.lightbox figcaption a { color: var(--gold); }
.lightbox figcaption .cap { font-size: 16px; color: var(--cream); margin-bottom: 4px; }

.modal { position: fixed; inset: 0; z-index: 35; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card {
  position: relative; max-width: 560px; width: 100%; max-height: 90vh; overflow: auto;
  background: var(--paper); color: var(--ink); border-radius: 16px; padding: 26px 28px; box-shadow: var(--shadow);
}
.modal-close { position: absolute; top: 8px; right: 8px; color: var(--ink-soft); }
.modal-close:hover { background: var(--paper-deep); color: var(--ink); }
.modal-card h2 { font-family: var(--serif); font-size: 26px; margin: 0 0 10px; padding-right: 36px; }
.modal-card p { margin: 0 0 12px; }
.modal-card .stats { color: var(--muted); font-size: 14px; }
.modal-card a { color: var(--accent); }
.modal-card .lg-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 6px; }
.modal-card .lg-list li { display: flex; gap: 10px; align-items: baseline; }
.modal-card .lg-list b { font-weight: 600; }
.modal-card .lg-line { display: inline-block; width: 26px; border-top: 2px solid var(--line-strong); vertical-align: middle; flex: none; }
.modal-card .lg-line.primary { border-top-color: var(--ink-soft); border-top-width: 2.5px; }
.modal-card .p-eyebrow { margin-top: 16px; }

.btn {
  height: 44px; padding: 0 18px; border: 0; border-radius: 10px; cursor: pointer; font-weight: 600;
  background: var(--accent); color: #fff;
}
.btn:hover { background: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line-strong); height: 38px; padding: 0 14px; font-weight: 500; }
.btn.ghost:hover { background: var(--paper-deep); }
.about-logout { margin: 22px 0 0 !important; padding-top: 14px; border-top: 1px solid var(--line); }

/* ---------- phone ---------- */
/* Touch first: every control at least 44px to the finger (visible size or a padded hit area),
   the dossier as a bottom sheet with a handle, the timeline stacked so stories get the width. */
@media (max-width: 760px) {
  :root { --top-h: 56px; }
  /* phones: no "Example" strip, the tree needs the room (Andreas, 2026-11-05) */
  html.demo { --demo-h: 0px; }
  .demo-banner { display: none; }
  .top { padding: 0 6px 0 calc(14px + env(safe-area-inset-left)); gap: 6px; }
  .brand { flex: 1 1 auto; overflow: hidden; }
  .brand-title { font-size: 19px; }
  .brand-sub { font-size: 11px; white-space: normal; line-height: 1.25; overflow: hidden;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }   /* wraps so every family line shows */
  .top-actions { gap: 0; flex: none; }
  .icon-btn { width: 44px; height: 44px; }
  .lang { margin: 0 2px; }
  .lang-btn { padding: 7px 9px; min-height: 36px; }
  .lang.many .lang-btn { display: none; }   /* more than two languages: the compact control instead of the pills */
  .lang.many .lang-cur { display: inline-flex; }
  .lang.many .lang-list:not([hidden]) { display: block; }
  .search { position: absolute; left: 8px; right: 8px; top: 8px; max-width: none; margin: 0; display: none; }
  .search.open { display: block; }
  .search.open input { padding-right: 100px; }
  .search input::-webkit-search-cancel-button { display: none; }   /* the Cancel button does this */
  .search-cancel { display: block; }
  .search-toggle { display: inline-flex; }
  .top.searching .brand, .top.searching .top-actions { visibility: hidden; }
  .results { max-height: min(55dvh, 420px); padding: 4px; }
  .results li { display: block; padding: 10px 12px; min-height: 44px; }
  .results .r-sub { display: block; margin-left: 0; text-align: left; font-size: 13px; }
  .results .qdot { margin-right: 6px; }
  .legend, .legend-btn { display: none; }
  .ruler { left: env(safe-area-inset-left); }
  .minimap { left: calc(66px + env(safe-area-inset-left)); bottom: calc(64px + env(safe-area-inset-bottom)); width: 150px; height: 40px; }
  .hint { left: calc(50% + 30px); top: 14px; font-size: 14px; }
  .toolbar { right: calc(8px + env(safe-area-inset-right)); bottom: calc(8px + env(safe-area-inset-bottom)); flex-direction: row; }
  .tool { width: 44px; height: 44px; }
  .tool-sep { width: 1px; height: auto; margin: 8px 2px; }
  .fold { height: 24px; font-size: 12px; top: -16px; }
  .sfold { height: 24px; font-size: 12px; }
  .fold::after, .knot::after, .sfold::after { inset: -12px; }   /* ~44px hit area around the small pills */
  .knot { font-size: 12px; line-height: 17px; }
  .world.mid .fold { height: 30px; top: -20px; }

  /* dossier = bottom sheet: a strip of the tree stays visible above it; drag the handle down to close */
  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: calc(var(--top-h) + var(--demo-h) + 12px);
    width: auto; border-left: 0; border-radius: 18px 18px 0 0; overflow: hidden;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .55);
    touch-action: pan-y;
  }
  .panel.sheet-drag { transition: none; }
  .panel-bar { padding: 16px 8px 6px 12px; position: relative; touch-action: none; }
  .panel-grip { display: block; position: absolute; left: 50%; top: 7px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: var(--line-strong); }
  .panel-tree { padding: 9px 14px 9px 10px; min-height: 40px; }
  .panel-close { width: 44px; height: 44px; }
  .panel-body { padding: 16px 16px calc(56px + env(safe-area-inset-bottom)); }
  .p-name { font-size: 26px; }
  .p-portrait { width: 76px; height: 76px; }
  .card { padding: 12px 14px; }

  /* timeline: date line above the text, a thin rail on the left, so stories get the whole width */
  .tl { display: block; padding: 0 0 18px 22px; }
  .tl::before { left: 5px; top: 10px; }
  .tl::after { left: 0; top: 6px; }
  .tl.event::after { left: 1px; top: 7px; }
  .tl-when { display: flex; align-items: baseline; gap: 8px; text-align: left; margin-bottom: 2px; }
  .tl-year { font-size: 15.5px; line-height: 1.3; }
  .tl-age { font-size: 12.5px; }
  .tl-age:empty { display: none; }
  .tl-body { padding-left: 0; }
  .tl-text { font-size: 16.5px; }
  .tl-undated { margin-left: 22px; }
  .facts, .fam { grid-template-columns: 1fr; gap: 2px 0; }
  .facts dt, .fam dt { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; margin-top: 8px; }
  .facts dt:first-child, .fam dt:first-child { margin-top: 0; }
  .scan { width: 112px; height: 86px; }
  .photo { width: 120px; height: 120px; }
  .lightbox-img-wrap { padding: calc(56px + env(safe-area-inset-top)) 8px 8px; }
  .lightbox-img-wrap img { max-height: 100%; }
  .lightbox figcaption { padding-bottom: calc(14px + env(safe-area-inset-bottom)); font-size: 13.5px; }
  .modal { padding: 0; align-items: end; }
  .modal-card { border-radius: 16px 16px 0 0; max-height: 92dvh; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .modal-close { width: 44px; height: 44px; }
}

/* landscape phone: little height, so the chrome gets flatter and the toolbar goes to the bottom row */
@media (max-height: 520px) and (pointer: coarse) {
  :root { --top-h: 46px; }
  .brand-title { font-size: 18px; }
  .brand-sub { display: none; }
  .search input { height: 36px; }
  .hint { display: none; }
  .legend, .legend-btn { display: none; }
  .toolbar { flex-direction: row; right: calc(8px + env(safe-area-inset-right)); bottom: calc(8px + env(safe-area-inset-bottom)); }
  .tool-sep { width: 1px; height: auto; margin: 8px 2px; }
  .minimap { height: 40px; bottom: calc(8px + env(safe-area-inset-bottom)); }
  .ruler { left: env(safe-area-inset-left); }
  .panel { width: min(460px, 52vw); }
  .panel-body { padding: 14px 16px 24px; }
  .modal-card { max-height: 96dvh; padding: 18px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .world.glide, .node { transition: none; }
  .nodes.reveal .node { animation: none; }
  .hint { transition: none; }
}

/* ---------- next steps: letter package ("Nächste Schritte") ----------
 * The site's second section next to the tree. The section switch (.sections) sits in the header on
 * desktop and becomes a bottom tab bar on phones (see the phone block below). The view itself is a
 * paper file on the reading-room desk: it covers the tree below the header, a paper column holds the
 * overview (letters as numbered cards, places to visit, questions for the family) or one letter
 * (facts, "your details" form, the letter as a sheet, a sticky action bar). Printing a letter prints
 * only the sheet, laid out as a Swiss A4 letter (address in the right-hand window). */
.sections {
  display: inline-flex; align-items: center; gap: 2px; padding: 3px; margin: 0 8px 0 0;
  border: 1px solid var(--gold-soft); border-radius: 999px; background: rgba(226, 185, 106, .07);
}
.sections[hidden] { display: none; }
.sec {
  position: relative; display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 13px 0 10px;
  border: 0; border-radius: 999px; background: transparent; color: var(--cream-soft);
  font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer;
}
.sec svg { width: 18px; height: 18px; flex: none; }
.sec:hover { background: rgba(255, 255, 255, .08); color: var(--cream); }
.sec[aria-current] { background: var(--gold); color: var(--stage); }
.sec-n {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; font-size: 12px; line-height: 20px; text-align: center;
  background: var(--gold); color: var(--stage);
}
.sec[aria-current] .sec-n { background: var(--stage); color: var(--gold); }
.sec-n:empty { display: none; }
/* narrow desktop windows: the switch keeps its full labels but drops the icons, so the search field keeps its room */
@media (min-width: 761px) and (max-width: 1040px) {
  .sec svg { display: none; }
  .sec { padding: 0 12px; }
}

.ns {
  position: fixed; left: 0; right: 0; top: var(--top-h); bottom: 0; z-index: 15;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: radial-gradient(120% 80% at 50% 0, var(--stage-glow), var(--stage) 60%, var(--stage-deep));
}
.ns[hidden] { display: none; }
.ns-page {
  position: relative; max-width: 860px; margin: 22px auto 0; min-height: calc(100% - 22px);
  background: var(--paper); color: var(--ink); border-radius: 14px 14px 0 0;
  box-shadow: 0 -2px 0 rgba(255, 255, 255, .04), 0 20px 60px -20px rgba(0, 0, 0, .8);
  padding: 0 40px 0;
}
.ns-page a { color: var(--accent); }
.ns-bar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 0 -40px; padding: 10px 28px 10px 24px; background: var(--paper); border-bottom: 1px solid var(--line); border-radius: 14px 14px 0 0;
}
.ns-back {
  display: inline-flex; align-items: center; gap: 4px; min-height: 40px; padding: 0 14px 0 8px;
  border: 1px solid var(--line-strong); border-radius: 999px; background: var(--card); color: var(--ink-soft); cursor: pointer; font-size: 15px;
}
.ns-back svg { width: 20px; height: 20px; }
.ns-back:hover { background: var(--paper-deep); color: var(--ink); }
.ns-pos { font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

.ns-head { padding: 30px 0 22px; border-bottom: 1px solid var(--line-strong); }
.ns-title { font-family: var(--serif); font-size: 34px; line-height: 1.12; font-weight: 600; margin: 4px 0 0; letter-spacing: -.01em; outline: none; }
.ns-lead { font-family: var(--serif); font-size: 18px; line-height: 1.55; color: var(--ink-soft); margin: 14px 0 0; max-width: 62ch; }
.ns-stats { margin: 12px 0 0; font-size: 14.5px; color: var(--muted); }
.ns-jump { border: 0; padding: 0; background: none; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); text-underline-offset: 3px; }
.ns-jump:hover { text-decoration-color: currentColor; }
.ns-tip {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-top: 16px; padding: 12px 16px; width: 100%; text-align: left;
  border: 1px solid color-mix(in srgb, var(--gold) 70%, var(--line-strong)); border-left: 4px solid var(--gold); border-radius: 10px;
  background: color-mix(in srgb, var(--gold) 12%, var(--card)); cursor: pointer; font-size: 15px; color: var(--ink);
}
.ns-tip span { color: var(--accent); }
.ns-tip:hover span { text-decoration: underline; }

.ns-page .ns-sec { margin: 30px 0 0; }
.ns-page .ns-sec h3 {
  font-family: var(--sans); font-size: 12.5px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.ns-sec p { margin: 0 0 8px; }
.ns-small { font-size: 14px; color: var(--muted); }

/* overview: letter cards */
.ns-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ns-card {
  display: grid; grid-template-columns: auto 1fr auto; gap: 0 16px; align-items: center; width: 100%; text-align: left;
  padding: 14px 14px 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); cursor: pointer; color: var(--ink);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.ns-card:hover { border-color: var(--line-strong); box-shadow: 0 6px 18px -10px rgba(40, 25, 10, .45); transform: translateY(-1px); }
.ns-num {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; align-self: start;
  border: 2px solid var(--ink-soft); font-family: var(--serif); font-size: 20px; font-weight: 600; color: var(--ink);
}
.ns-num.later { border-style: dashed; border-color: var(--line-strong); color: var(--ink-soft); }   /* waits for another letter */
.ns-card-main { display: block; min-width: 0; }
.ns-card-to { display: block; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.ns-card-title { display: block; font-family: var(--serif); font-size: 19px; line-height: 1.3; font-weight: 600; margin-top: 2px; }
.ns-card-who { display: block; font-size: 14.5px; color: var(--ink-soft); margin-top: 4px; }
.ns-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ns-chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; border: 1px solid var(--line-strong); color: var(--ink-soft); background: var(--paper); }
.ns-chip-after { border-style: dashed; }
.ns-card-go { width: 22px; height: 22px; color: var(--muted); }
.ns-card:hover .ns-card-go { color: var(--accent); }

.ns-visits { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; }
.ns-visit { padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.ns-visit h4, .ns-group h4 { font-family: var(--serif); font-size: 17px; line-height: 1.3; margin: 0 0 6px; }
.ns-visit p { font-size: 15px; }
.ns-where { display: flex; gap: 6px; align-items: flex-start; color: var(--ink-soft); font-size: 14px !important; margin: 8px 0 0 !important; }
.ns-where svg { width: 16px; height: 16px; flex: none; margin-top: 3px; color: var(--muted); }
.ns-intro { font-family: var(--serif); font-size: 16.5px; color: var(--ink-soft); }
.ns-group { margin-top: 18px; }
.ns-questions { margin: 0; padding-left: 22px; font-family: var(--serif); font-size: 16px; }
.ns-questions li { margin-bottom: 7px; padding-left: 2px; }
.ns-questions li::marker { color: var(--muted); font-family: var(--sans); font-size: 13px; }
#ns-talk { scroll-margin-top: 70px; padding-bottom: 36px; }

/* one letter */
.ns-head-chips { margin: 10px 0 0; }
.ns-after { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0 0; padding: 10px 12px; border: 1px dashed var(--line-strong); border-radius: 10px; font-size: 15px; color: var(--ink-soft); }
.ns-after svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.ns-facts { display: grid; grid-template-columns: 1.5fr 1fr; gap: 0 32px; }
.ns-facts .ns-why { grid-row: span 3; }
.ns-why > p { font-family: var(--serif); font-size: 16.5px; line-height: 1.55; }
.ns-who { font-size: 15px; margin-top: 12px !important; }
.ns-k { color: var(--muted); }
.ns-who .plink { display: inline; }
.ns-address { font-style: normal; font-size: 15.5px; line-height: 1.45; }
.ns-contact { font-size: 15px; margin: 6px 0 0 !important; overflow-wrap: anywhere; }
.ns-attach { margin: 0; padding-left: 20px; font-size: 15px; }
.ns-attach li { margin-bottom: 4px; }
.ns-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.ns-field { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--muted); }
.ns-field.wide { grid-row: span 2; }
.ns-field input, .ns-field textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--card); width: 100%;
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; resize: vertical;
}
.ns-field textarea { flex: 1 1 auto; min-height: 64px; }
.ns-field input:focus, .ns-field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.ns-hint { font-size: 12.5px; }
.ns-fill-foot { margin: 10px 0 0 !important; }

/* the letter sheet: white paper, a letter typeface; on screen the blocks simply stack */
.ns-sheet {
  background: #fffdf8; color: #1d1a17; border: 1px solid var(--paper-edge); border-radius: 4px;
  box-shadow: 0 1px 2px rgba(40, 25, 10, .12), 0 14px 34px -18px rgba(40, 25, 10, .5);
  padding: 44px 52px 52px; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 15px; line-height: 1.5;
}
.ns-sheet p { margin: 0 0 .9em; }
.ns-letterhead { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 34px; }
.ns-from { font-size: 13px; line-height: 1.45; color: #4a443e; }
.ns-addr { padding-top: 42px; }
.ns-date { margin-bottom: 1.6em !important; }
.ns-subj { font-weight: 700; margin-bottom: 1.4em !important; }
.ns-closing { margin-top: 1.4em !important; margin-bottom: 0 !important; }
.ns-sign { margin-top: 3.2em !important; }
.ns-ph { background: #fbe38a; color: inherit; border-radius: 3px; padding: 0 2px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.ns-filled { background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 3px; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.ns-hints { margin-top: 10px !important; }

/* action bar: stays at the bottom of the window while the letter scrolls */
.ns-actions {
  position: sticky; bottom: 0; z-index: 2; display: flex; flex-wrap: wrap; gap: 8px;
  margin: 26px -40px 0; padding: 12px 40px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--paper) 92%, transparent); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-top: 1px solid var(--line);
}
.ns-act {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: 10px; background: var(--card); color: var(--ink) !important;
  font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.ns-act svg { width: 19px; height: 19px; flex: none; }
.ns-act:hover { background: var(--paper-deep); }
.ns-act.primary { background: var(--accent); border-color: var(--accent); color: #fff !important; }
.ns-act.primary:hover { background: var(--accent-ink); }
.ns-act .s { display: none; }

@media (max-width: 760px) {
  /* the section switch becomes a tab bar at the bottom; everything that sat at the bottom moves up by --tab-h */
  :root { --tab-h: calc(58px + env(safe-area-inset-bottom)); }
  body:has(.sections:not([hidden])) .main { height: calc(100% - var(--top-h) - var(--tab-h)); }   /* stage, toolbar and minimap end above it */
  body:has(.sections:not([hidden])) .panel { bottom: var(--tab-h); }
  body:has(.sections:not([hidden])) .ns { bottom: var(--tab-h); }
  .sections {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 18; height: var(--tab-h);
    display: flex; margin: 0; padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    border: 0; border-top: 1px solid rgba(226, 203, 160, .16); border-radius: 0;
    background: linear-gradient(to top, #241f1a, var(--stage));
  }
  .sec { flex: 1 1 0; flex-direction: column; justify-content: center; gap: 3px; height: auto; padding: 6px 4px 5px; border-radius: 0; font-size: 12.5px; color: var(--cream-muted); }
  .sec svg { width: 23px; height: 23px; }
  .sec:hover { background: none; }
  .sec[aria-current] { background: none; color: var(--gold); }
  .sec-n { position: absolute; top: 3px; left: calc(50% + 6px); min-width: 18px; height: 18px; line-height: 18px; font-size: 11px; padding: 0 5px; }
  .sec[aria-current] .sec-n { background: var(--gold); color: var(--stage); }
  body.ns-letter .sections { display: none; }   /* a letter page: its own action bar sits at the bottom */
  body.ns-open.ns-letter .ns { bottom: 0; }   /* outweighs the :has() rule above */
  .ns-page { margin-top: 0; border-radius: 0; padding: 0 16px; min-height: 100%; }
  .ns-bar { margin: 0 -16px; padding: 8px 12px; border-radius: 0; }
  .ns-bar-overview { display: none; }   /* the tab bar leads back to the tree */
  .ns-head { padding: 20px 0 18px; }
  .ns-title { font-size: 27px; }
  .ns-lead { font-size: 17px; }
  .ns-card { grid-template-columns: auto 1fr; gap: 0 12px; padding: 14px 12px; }
  .ns-card-go { display: none; }
  .ns-num { width: 34px; height: 34px; font-size: 17px; }
  .ns-card-title { font-size: 17.5px; }
  .ns-visits { grid-template-columns: 1fr; }
  .ns-facts { grid-template-columns: 1fr; }
  .ns-facts .ns-why { grid-row: auto; }
  .ns-fields { grid-template-columns: 1fr; }
  .ns-field.wide { grid-row: auto; }
  .ns-sheet { padding: 22px 18px 26px; font-size: 15px; margin: 0 -6px; }
  .ns-letterhead { grid-template-columns: 1fr; gap: 18px; margin-bottom: 24px; }
  .ns-addr { padding-top: 0; }
  .ns-actions { margin: 22px -16px 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); gap: 6px; flex-wrap: nowrap; }
  .ns-act { flex: 1 1 0; flex-direction: column; gap: 2px; min-height: 54px; padding: 4px 4px; font-size: 12.5px; }
  .ns-act .l { display: none; }
  .ns-act .s { display: inline; }
  #ns-talk { scroll-margin-top: 60px; }
}

/* print: only the letter, as a Swiss A4 letter (sender top left, recipient in the right-hand window,
   place and date, bold subject, text, closing). Without an open letter the tree prints as before. */
@page { size: A4; margin: 16mm 20mm 18mm 25mm; }
@media print {
  body.ns-open { height: auto; overflow: visible; background: #fff; color: #000; }
  body.ns-open > *:not(#ns) { display: none !important; }
  body.ns-open .ns { position: static; overflow: visible; background: none; }
  body.ns-open .ns-page { max-width: none; margin: 0; padding: 0; box-shadow: none; border-radius: 0; background: none; min-height: 0; }
  body.ns-open .ns-noprint { display: none !important; }
  body.ns-open .ns-page .ns-sec { margin: 0; }
  body.ns-open .ns-sheet {
    border: 0; border-radius: 0; box-shadow: none; padding: 0; margin: 0; background: none; color: #000;
    font-family: Arial, Helvetica, sans-serif; font-size: 11pt; line-height: 1.42;
  }
  body.ns-open .ns-letterhead { display: block; position: relative; height: 80mm; margin: 0; }   /* text starts ~96 mm from the top */
  body.ns-open .ns-from { position: absolute; left: 0; top: 0; font-size: 9pt; color: #000; }
  body.ns-open .ns-addr { position: absolute; left: 93mm; top: 34mm; width: 72mm; padding: 0; font-size: 11pt; }   /* window: 118 mm from the left edge, ~50 mm from the top */
  body.ns-open .ns-ph, body.ns-open .ns-filled { background: none; padding: 0; }
  body.ns-open .ns-date { margin-bottom: 10mm !important; }
  body.ns-open .ns-subj { margin-bottom: 7mm !important; }
  body.ns-open .ns-sign { margin-top: 16mm !important; }
  body.ns-open .ns-sheet p { break-inside: avoid; }
}
