/* ============================================================
   Stammbaum — design system
   Vintage beige · dark blue ink · bright sand · Instrument Serif + Lexend
   ============================================================ */

@font-face {
  font-family: 'Instrument Serif';
  font-style: normal;
  font-weight: 400;
  src: url('/fonts/instrument-serif-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Instrument Serif';
  font-style: normal;
  font-weight: 400;
  src: url('/fonts/instrument-serif-latin-ext-400-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Instrument Serif';
  font-style: italic;
  font-weight: 400;
  src: url('/fonts/instrument-serif-latin-400-italic.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Instrument Serif';
  font-style: italic;
  font-weight: 400;
  src: url('/fonts/instrument-serif-latin-ext-400-italic.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Lexend';
  font-style: normal;
  font-weight: 300 600;
  src: url('/fonts/lexend-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Lexend';
  font-style: normal;
  font-weight: 300 600;
  src: url('/fonts/lexend-latin-ext-400-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --ink: #1b2a4a;
  --ink-deep: #101b33;
  --ink-soft: #3d4d73;
  --sand: #d9b36c;
  --sand-bright: #e9cf9c;
  --sand-faint: #f2e3c4;
  --paper: #f4edda;
  --paper-light: #faf6ea;
  --paper-deep: #e9dfc4;
  --sepia: #4d4232;
  --sepia-faint: #8a7c66;
  --brick: #9c4a3c;
  --forest: #4a6b52;
  --olive: #8a7a3c;
  --serif: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  --sans: 'Lexend', system-ui, -apple-system, sans-serif;
  --radius: 10px;
  --shadow: 0 10px 30px -12px rgba(16, 27, 51, .25);
  --shadow-sm: 0 3px 10px -4px rgba(16, 27, 51, .18);
  --hairline: 1px solid var(--paper-deep);
  --topbar-h: 60px;
  /* device safe areas, resolved once so every fixed-position surface can
     reference them without repeating the env() fallback dance */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  /* viewport-fit=cover lets the page run under the status bar, and the
     web-app manifest means it really does in installed mode — so the bar's
     own height is 60px of content *plus* whatever the notch takes. Anything
     that sits below the topbar has to offset by the total, not by 60px. */
  --topbar-total: calc(var(--topbar-h) + var(--safe-t));
  /* the minimum comfortable touch target; see the coarse-pointer block below */
  --tap: 44px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; overflow-x: hidden; }
/* iOS/Android hide and show the URL bar as you scroll, which changes what
   100vh means mid-gesture; 100dvh tracks the box that is actually visible. */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}
/* a double-tap must never be read as "zoom the page" — the tree handles its
   own zoom, and elsewhere it just makes taps feel unreliable */
body { touch-action: manipulation; }

body {
  background: var(--paper);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(217, 179, 108, .14), transparent 60%),
    repeating-linear-gradient(0deg, rgba(74, 66, 50, .022) 0 1px, transparent 1px 3px);
  color: var(--sepia);
  font-family: var(--sans);
  font-weight: 300;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--sand-bright); color: var(--ink-deep); }

a { color: var(--ink); }

h1, h2, h3, h4 { font-family: var(--serif); font-weight: 400; color: var(--ink); margin: 0 0 .5em; line-height: 1.15; }
h1 { font-size: 30px; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }

.muted { color: var(--sepia-faint); }
.small { font-size: 13px; }
.micro {
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--sepia-faint);
}

/* ---------------- buttons ---------------- */
.btn {
  font-family: var(--sans);
  font-weight: 500;
  font-size: 13.5px;
  letter-spacing: .02em;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 18px;
  cursor: pointer;
  transition: all .15s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  background: none;
  line-height: 1.2;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--ink); color: var(--paper-light); box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--ink-deep); transform: translateY(-1px); }

.btn-sand { background: var(--sand); color: var(--ink-deep); }
.btn-sand:hover:not(:disabled) { background: var(--sand-bright); }

.btn-ghost { border-color: var(--paper-deep); color: var(--ink); background: transparent; }
.btn-ghost:hover:not(:disabled) { border-color: var(--sand); background: var(--paper-light); }

.btn-danger-ghost { border-color: transparent; color: var(--brick); }
.btn-danger-ghost:hover:not(:disabled) { background: rgba(156, 74, 60, .08); border-color: rgba(156, 74, 60, .3); }

.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 7px; }

/* ---------------- inputs ---------------- */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 500;
  color: var(--sepia-faint);
  margin-bottom: 5px;
}
.input, select.input, textarea.input {
  width: 100%;
  font-family: var(--sans);
  font-weight: 300;
  font-size: 14.5px;
  color: var(--sepia);
  background: var(--paper-light);
  border: 1px solid var(--paper-deep);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--sand); box-shadow: 0 0 0 3px rgba(217, 179, 108, .25); }
textarea.input { resize: vertical; min-height: 80px; }
select.input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a7c66' fill='none' stroke-width='1.5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

/* ---------------- top bar ---------------- */
.topbar {
  background: var(--ink);
  color: var(--paper-light);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 clamp(12px, 2vw, 26px);
  padding-left: max(clamp(12px, 2vw, 26px), var(--safe-l));
  padding-right: max(clamp(12px, 2vw, 26px), var(--safe-r));
  padding-top: var(--safe-t);
  height: var(--topbar-total);
  min-width: 0;
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 2px solid var(--sand);
  box-shadow: 0 2px 12px rgba(16, 27, 51, .25);
}
.wordmark {
  font-family: var(--serif);
  font-style: italic;
  font-size: 24px;
  color: var(--paper-light);
  text-decoration: none;
  letter-spacing: .02em;
  white-space: nowrap;
}
.wordmark em { color: var(--sand); font-style: italic; }
/* the everyday links and the admin dropdown share one row; only the links scroll */
.topnav-wrap { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.topnav { display: flex; gap: 4px; flex: 0 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.topnav::-webkit-scrollbar { display: none; }
.topnav a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: rgba(250, 246, 234, .78);
  text-decoration: none;
  font-size: 12.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 7px;
  white-space: nowrap;
  transition: all .15s;
}
.topnav a .ph { font-size: 16px; opacity: .85; }
.topnav a:hover { color: var(--paper-light); background: rgba(217, 179, 108, .14); }
.topnav a.active { color: var(--ink-deep); background: var(--sand); }

/* Admin sections, folded into one dropdown. Eight role-gated links next to the
   five everyday ones forced the whole bar into icon-only mode; behind a single
   trigger they stay one click away and the bar keeps its labels. */
.navmenu { position: relative; flex-shrink: 0; }
.navmenu > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: rgba(250, 246, 234, .78);
  font-size: 12.5px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 7px;
  white-space: nowrap;
  user-select: none;
  transition: all .15s;
}
.navmenu > summary::-webkit-details-marker { display: none; }
.navmenu > summary .ph { font-size: 16px; opacity: .85; }
.navmenu > summary .nm-caret { font-size: 12px; transition: transform .15s ease; }
.navmenu[open] > summary .nm-caret { transform: rotate(180deg); }
.navmenu > summary:hover,
.navmenu[open] > summary { color: var(--paper-light); background: rgba(217, 179, 108, .14); }
/* collapsed, the trigger is the only trace of the admin section you are in */
.navmenu.active > summary { color: var(--ink-deep); background: var(--sand); }
.navmenu.active > summary .ph { opacity: 1; }
.navmenu-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 5;
  min-width: 250px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px;
  background: var(--paper-light);
  border: 1px solid var(--paper-deep);
  border-top: 2px solid var(--sand);
  border-radius: 12px;
  box-shadow: 0 18px 40px -18px rgba(16, 27, 51, .45);
}
.navmenu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--sepia);
  text-decoration: none;
  font-size: 13.5px;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.navmenu-item .ph { font-size: 17px; color: var(--ink); flex-shrink: 0; }
.navmenu-item:hover { background: var(--sand-faint); color: var(--ink); }
.navmenu-item.active { background: var(--sand); color: var(--ink-deep); }
.navmenu-item.active .ph { color: var(--ink-deep); }
.topbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; min-width: 0; }
.topbar-out { border-color: rgba(250, 246, 234, .3); color: var(--paper-light); }
.topbar-out:hover { border-color: var(--sand); }
.role-badge {
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink-deep);
  background: var(--sand);
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.user-chip { display: flex; align-items: center; gap: 8px; color: rgba(250, 246, 234, .85); font-size: 13px; white-space: nowrap; }

/* ---------------- cards / panels ---------------- */
.panel {
  background: var(--paper-light);
  border: 1px solid var(--paper-deep);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.panel-pad { padding: 22px 26px; }

.ledger { position: relative; }
.ledger::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  background-image: repeating-linear-gradient(0deg, rgba(74, 66, 50, .015) 0 1px, transparent 1px 3px);
}

/* ---------------- modals ---------------- */
.veil {
  position: fixed;
  inset: 0;
  background: rgba(16, 27, 51, .55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 20px 20px;
  z-index: 100;
  overflow-y: auto;
  animation: veil-in .18s ease;
}
@keyframes veil-in { from { opacity: 0; } }
.modal {
  background: var(--paper-light);
  border-radius: 14px;
  box-shadow: 0 24px 60px -12px rgba(16, 27, 51, .45);
  border: 1px solid var(--paper-deep);
  width: 100%;
  max-width: 640px;
  animation: modal-in .22s cubic-bezier(.2, .8, .3, 1);
}
@keyframes modal-in { from { transform: translateY(14px) scale(.985); opacity: 0; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px 14px;
  border-bottom: var(--hairline);
}
.modal-head h2 { margin: 0; font-size: 24px; }
.modal-body { padding: 20px 24px 6px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px 20px;
  border-top: var(--hairline);
  margin-top: 14px;
  flex-wrap: wrap;
}

/* Secondary actions fold away by default. A person modal had eight buttons
   competing for the same row; now it offers the one or two that matter and
   keeps the rest one tap away, on every screen size. */
.act-more { margin: 0; }
.act-more > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--sans);
  font-weight: 500;
  font-size: 13.5px;
  color: var(--ink);
  border: 1px solid var(--paper-deep);
  border-radius: 8px;
  padding: 9px 16px;
  min-height: var(--tap);
  box-sizing: border-box;
  user-select: none;
}
.act-more > summary::-webkit-details-marker { display: none; }
.act-more > summary:hover { border-color: var(--sand); background: var(--paper-light); }
.act-more > summary .ph { transition: transform .15s ease; }
.act-more[open] > summary .ph.act-caret { transform: rotate(180deg); }
.act-more-body { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; width: 100%; }

/* ---- mobile: modals become bottom sheets ----------------------------
   A centred card that scrolls the whole veil puts its buttons wherever the
   content happens to end. As a sheet the title stays put, the body scrolls,
   and the actions sit within thumb reach at the bottom of the screen. */
@media (max-width: 720px) {
  .veil {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    max-width: none !important;
    width: 100%;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    border-radius: 18px 18px 0 0;
    animation: sheet-in .24s cubic-bezier(.2, .8, .3, 1);
  }
  .modal-head {
    position: sticky;
    top: 0;
    background: var(--paper-light);
    border-radius: 18px 18px 0 0;
    padding: 14px 16px 12px;
    z-index: 2;
  }
  .modal-head h2 { font-size: 20px; line-height: 1.2; overflow-wrap: anywhere; }
  .modal-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px 16px 6px; -webkit-overflow-scrolling: touch; }
  .modal-foot {
    padding: 12px 16px calc(14px + var(--safe-b));
    background: var(--paper-light);
    flex-wrap: wrap;
    justify-content: stretch;
    gap: 8px;
    margin-top: 0;
  }
  .modal-foot .btn { flex: 1 1 auto; justify-content: center; min-height: var(--tap); }
  /* the sticky header keeps an X in view the whole time, so a second close
     button down here only costs a row of the sheet */
  .modal-foot > .btn[data-close] { display: none; }
  .modal-foot .act-more { flex: 1 1 100%; }
  .modal-foot .act-more > summary { width: 100%; justify-content: center; }
  .modal-foot .act-more-body .btn { flex: 1 1 45%; }
}
@keyframes sheet-in { from { transform: translateY(24px); opacity: .4; } }

/* ---------------- onboarding wizard ---------------- */
.wizard-modal { max-width: 560px; }
.wizard-dots { display: flex; gap: 6px; justify-content: center; margin-bottom: 18px; }
.wz-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--paper-deep); transition: background .15s, transform .15s; }
.wz-dot.active { background: var(--sand); transform: scale(1.35); }
.wz-dot.done { background: var(--ink-soft); }
.wizard-step-count { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--sepia-faint); margin-bottom: 10px; }
#wz-body p { margin: 0 0 12px; line-height: 1.55; }
#wz-body p:last-child { margin-bottom: 0; }
.wizard-link-widget { margin-top: 18px; padding-top: 16px; border-top: var(--hairline); }
/* Phosphor inline icons */
.ph { width: 1em; height: 1em; fill: currentColor; flex-shrink: 0; vertical-align: -0.16em; display: inline-block; }
.btn .ph, .filter-pill .ph { font-size: 1.15em; }
.btn > .ph + span, .btn > .ph + * { margin-left: 7px; }
.btn:has(.ph) { display: inline-flex; align-items: center; }
.icon-btn .ph { font-size: 20px; }
.rel-x .ph { font-size: 12px; }
.icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--sepia-faint);
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--paper-deep); color: var(--ink); }

/* ---------------- toasts ---------------- */
.toasts {
  position: fixed;
  bottom: calc(22px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  background: var(--paper-light);
  border: 1px solid var(--paper-deep);
  border-left: 4px solid var(--sand);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 11px 18px;
  font-size: 14px;
  max-width: 480px;
  animation: toast-in .25s ease;
}
.toast.ok { border-left-color: var(--forest); }
.toast.err { border-left-color: var(--brick); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

/* ---------------- medallions ---------------- */
.medallion {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--sand-faint);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid rgba(217, 179, 108, .55);
  overflow: hidden;
}
.medallion img { width: 100%; height: 100%; object-fit: cover; }
.medallion.lg { width: 72px; height: 72px; font-size: 30px; }
.medallion.sm { width: 32px; height: 32px; font-size: 14px; }

/* ---------------- tables ---------------- */
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th {
  text-align: left;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--sepia-faint);
  padding: 10px 12px;
  border-bottom: 2px solid var(--paper-deep);
}
table.list td { padding: 11px 12px; border-bottom: var(--hairline); vertical-align: middle; }
table.list tr:hover td { background: rgba(217, 179, 108, .08); }
table.list tr.clickable { cursor: pointer; }

/* ---------------- badges ---------------- */
.badge {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge.pending { background: rgba(138, 122, 60, .15); color: var(--olive); }
.badge.approved { background: rgba(74, 107, 82, .14); color: var(--forest); }
.badge.rejected { background: rgba(156, 74, 60, .12); color: var(--brick); }
.badge.spam { background: var(--paper-deep); color: var(--sepia-faint); }
.badge.neutral { background: var(--paper-deep); color: var(--sepia-faint); }

/* ---------------- auth screens ---------------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px 16px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--paper-light);
  border: 1px solid var(--paper-deep);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 38px 36px 30px;
  position: relative;
}
.auth-card::before {
  content: '';
  position: absolute;
  top: -8px;
  left: 10%;
  right: 10%;
  height: 3px;
  background: var(--sand);
  border-radius: 3px;
}
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand .wordmark { color: var(--ink); font-size: 34px; display: block; }
.auth-brand .wordmark em { color: var(--sand); }
.auth-brand .tagline { font-size: 12.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--sepia-faint); margin-top: 6px; }
.auth-alt { text-align: center; margin-top: 18px; font-size: 13.5px; }
.auth-alt a { color: var(--ink); font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }

/* ---------------- layout ---------------- */
.page {
  padding: 28px 30px 60px;
  padding-left: max(30px, var(--safe-l));
  padding-right: max(30px, var(--safe-r));
  padding-bottom: calc(60px + var(--safe-b));
  max-width: 1200px;
  margin: 0 auto;
}
@media (max-width: 720px) {
  .page { padding: 18px max(14px, var(--safe-l)) calc(48px + var(--safe-b)) max(14px, var(--safe-r)); }
  .page-head { gap: 10px; }
  .page-head h1 { font-size: 26px; }
  /* page actions stack into full-width buttons instead of squeezing */
  .page-head .print-hidden { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
  .page-head .print-hidden .btn { flex: 1 1 auto; justify-content: center; }
  .panel-pad { padding: 16px 14px; }
}
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 32px; }
.page-head .sub { color: var(--sepia-faint); font-size: 14px; margin-top: 2px; }

/* ---------------- tree ---------------- */
.tree-stage {
  position: fixed;
  inset: var(--topbar-total) 0 0 0;
  background:
    radial-gradient(ellipse 70% 45% at 50% -8%, rgba(217, 179, 108, .12), transparent 60%),
    var(--paper);
  overflow: hidden;
}
.tree-viewport {
  position: absolute;
  inset: 0;
  overflow: hidden;
  user-select: none;
}
.tree-canvas-el {
  position: absolute;
  inset: 0;
  cursor: grab;
  touch-action: none;
}
.tree-canvas-el:active { cursor: grabbing; }
.tree-hitlayer {
  position: absolute;
  inset: 0;
  cursor: grab;
  touch-action: none;
  overflow: hidden;
}
.tree-hitlayer:active { cursor: grabbing; }
/* Hit regions are laid out once in world coordinates inside this wrapper;
   panning and zooming move the wrapper, not the boxes. `--inv-s` carries the
   inverse of the current zoom down to anything that must keep a constant
   on-screen size (the collapse buttons). */
.tree-hitworld {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  will-change: transform;
}
.tree-hit {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  border-radius: 10px;
  transform-origin: center;
}
.tree-hit.micro { border-radius: 50%; }
/* expand / collapse toggle: sits on the rim of a branch; quiet unless hovered */
.tree-collapse {
  position: absolute;
  pointer-events: auto;
  /* sized in screen pixels, then un-zoomed so it stays legible and tappable
     at every scale without a per-button style write on each zoom step */
  transform: translate(-50%, -50%) scale(var(--inv-s, 1));
  border: 1px solid var(--sand);
  border-radius: 11px;
  background: var(--paper-light);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-shadow: 0 1px 3px rgba(16, 27, 51, .18);
  transition: background .15s, transform .15s;
  white-space: nowrap;
}
.tree-collapse.open { color: var(--sepia-faint); border-color: var(--paper-deep); }
.tree-collapse:hover { background: var(--sand); color: var(--ink-deep); border-color: var(--sand); transform: translate(-50%, -50%) scale(calc(var(--inv-s, 1) * 1.12)); }
.tree-collapse .ph { pointer-events: none; }
.tree-collapse span { pointer-events: none; }

/* focus chip under the toolbar */
.tree-focus {
  position: absolute;
  right: 18px;
  bottom: 16px;
  z-index: 7;
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  background: rgba(250, 246, 234, .9);
  backdrop-filter: blur(6px);
  border: 1px solid var(--paper-deep);
  border-radius: 20px;
  padding: 4px 14px;
  cursor: pointer;
  font-family: var(--sans);
}
.tree-focus[hidden] { display: none; }
.tree-focus:hover { border-color: var(--sand); }
.tree-focus .tf-k { font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--sepia-faint); }
.tree-focus .tf-n { font-family: var(--serif); font-size: 15px; color: var(--ink); }
.tt-depth { display: inline-flex; align-items: center; gap: 2px; }
.tt-depth[hidden], #tt-scope[hidden], #tt-dir[hidden] { display: none; }
.tt-d-label { min-width: 48px; text-align: center; font-size: 12px; letter-spacing: .04em; color: var(--sepia); font-variant-numeric: tabular-nums; }
.tt-zoom { display: inline-flex; align-items: center; gap: 2px; }

/* toolbar */
.tree-toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  width: fit-content;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  align-items: center;
  background: rgba(250, 246, 234, .92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--paper-deep);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 6px 8px;
  /* above .topbar (z-index: 40): its own stacking context must outrank the
     topbar's, or a tooltip popping up from a button near the toolbar's top
     edge gets painted over by the topbar and shows cropped */
  z-index: 45;
  max-width: calc(100vw - 32px);
}
.tt-sep { width: 1px; height: 20px; background: var(--paper-deep); margin: 0 4px; flex-shrink: 0; }
.tree-toolbar .btn-sm { min-width: 34px; justify-content: center; }
#tt-z-label { min-width: 52px; font-variant-numeric: tabular-nums; }
.btn-ghost.active { background: var(--sand-faint); border-color: var(--sand); color: var(--ink); }

/* toolbar with an overflow row: a wrapper that stacks the primary bar and
   the "more" bar (revealed by the kebab button) vertically, centred as one
   unit — each bar keeps the .tree-toolbar chrome (background/border/blur),
   it just stops positioning itself once nested here. */
.tree-toolbar-stack {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  width: fit-content;
  max-width: calc(100vw - 32px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 45;
}
.tree-toolbar-stack .tree-toolbar { position: static; width: auto; max-width: 100%; margin: 0; z-index: auto; }
.tree-toolbar-more[hidden] { display: none; }

/* ---- view options: inline on desktop, a bottom sheet on a phone ----
   Same markup either way. On a wide screen the group labels collapse away
   and the controls read as an icon toolbar under the main bar; on a phone
   they turn into a labelled sheet, because an unlabelled icon has no
   tooltip to fall back on when there is no cursor to hover with. */
.tt-group { display: inline-flex; align-items: center; gap: 6px; }
.tt-group[hidden] { display: none; }
.tt-group-h, .tt-label, .tt-sheet-head { display: none; }
.tt-scrim { display: none; }

/* person peek: the tapped person plus what can be done with them. Replaces
   "one tap silently re-roots the whole tree", which was impossible to undo
   by accident on a touch screen. */
.tree-peek {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
  background: rgba(250, 246, 234, .96);
  backdrop-filter: blur(10px);
  border: 1px solid var(--paper-deep);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 8px 10px 8px 12px;
}
.tree-peek[hidden] { display: none; }
.tree-peek .tp-body { display: flex; flex-direction: column; min-width: 0; }
.tree-peek .tp-name { font-family: var(--serif); font-size: 17px; color: var(--ink); line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-peek .tp-years { font-size: 12px; color: var(--sepia-faint); }
.tree-peek .tp-actions { display: flex; gap: 6px; flex-shrink: 0; }
.tree-peek .tp-close { flex-shrink: 0; }

/* toolbar (mobile): the primary bar keeps search, fit and the options
   button; everything else moves into the sheet below, so the canvas is not
   covered by a scrolling strip of unreadable icons. */

/* person search dropdown */
.tt-search { position: relative; }
.tt-q {
  width: 200px;
  background: var(--paper-light);
  border: 1px solid var(--paper-deep);
  border-radius: 8px;
  padding: 7px 12px;
  font-family: var(--sans);
  font-weight: 300;
  font-size: 13.5px;
  color: var(--sepia);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.tt-q:focus { border-color: var(--sand); box-shadow: 0 0 0 3px rgba(217, 179, 108, .22); }
.tt-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 280px;
  max-height: 340px;
  overflow-y: auto;
  background: var(--paper-light);
  border: 1px solid var(--paper-deep);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 4px;
}
.tt-result {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 7px;
  padding: 8px 10px;
  font-family: var(--sans);
  cursor: pointer;
}
.tt-result:hover { background: var(--paper-deep); }
.tt-r-name { font-family: var(--serif); font-size: 15px; color: var(--ink); }
.tt-r-years { font-size: 11.5px; color: var(--sepia-faint); white-space: nowrap; }
.tt-empty { padding: 12px; font-size: 13px; color: var(--sepia-faint); text-align: center; }

/* icon-only toolbar pills (layout mode, scope, direction) */
.icon-pill { min-width: 32px; height: 30px; padding: 6px; display: inline-flex; align-items: center; justify-content: center; }
.icon-pill .ph { font-size: 16px; }

/* tooltips: hover/focus label above any [data-tip] control. Native `title`
   is intentionally not used alongside it, so only one tooltip ever shows. */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 9px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--ink-deep);
  color: var(--paper-light);
  font-family: var(--sans);
  font-weight: 400;
  font-size: 12px;
  line-height: 1.35;
  letter-spacing: 0;
  text-transform: none;
  white-space: normal;
  width: max-content;
  max-width: 220px;
  text-align: center;
  padding: 6px 10px;
  border-radius: 7px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
  z-index: 60;
}
[data-tip]::before {
  content: '';
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--ink-deep);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
  z-index: 60;
}
[data-tip]:hover::after, [data-tip]:hover::before,
[data-tip]:focus-visible::after, [data-tip]:focus-visible::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
/* touch has no hover to dismiss it with — rely on aria-label there instead */
@media (hover: none) { [data-tip]::after, [data-tip]::before { display: none !important; } }

/* gap (card spacing) dropdown */
.tt-rot90 { transform: rotate(90deg); }
.tt-gap { position: relative; display: inline-flex; }
.tt-gap-pop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 230px;
  background: var(--paper-light);
  border: 1px solid var(--paper-deep);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 12px 14px 14px;
  z-index: 20;
}
.tt-gap-pop[hidden] { display: none; }
.tt-gap-row { display: flex; align-items: center; gap: 10px; }
.tt-gap-val { min-width: 42px; text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--sepia); }
.tt-gap-pop input[type="range"] {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--paper-deep);
  outline: none;
}
.tt-gap-pop input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--sand);
  border: 2px solid var(--ink);
  cursor: pointer;
}
.tt-gap-pop input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--sand);
  border: 2px solid var(--ink);
  cursor: pointer;
}
.tt-gap-pop .btn { width: 100%; justify-content: center; margin-top: 12px; }

/* fixed-root filter chip: sits centred below the toolbar when a super admin
   has narrowed the archive down to one line */
.tree-filter-chip {
  position: absolute;
  right: 18px;
  bottom: 58px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(250, 246, 234, .92);
  backdrop-filter: blur(6px);
  border: 1px solid var(--paper-deep);
  border-radius: 20px;
  padding: 5px 8px 5px 14px;
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--sepia);
  max-width: calc(100vw - 32px);
}
.tree-filter-chip[hidden] { display: none; }
.tree-filter-chip .ph { font-size: 15px; color: var(--sepia-faint); flex-shrink: 0; }
.tree-filter-chip strong { color: var(--ink); font-weight: 500; }
.tree-filter-chip.off { border-color: var(--sand); background: var(--sand-faint); }

/* legend (bottom-left) */
.tree-legend {
  position: absolute;
  left: 18px;
  bottom: 16px;
  display: flex;
  gap: 14px;
  z-index: 7;
  background: rgba(250, 246, 234, .88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--paper-deep);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 11.5px;
  letter-spacing: .04em;
  color: var(--sepia-faint);
}
.tl-item { display: inline-flex; align-items: center; gap: 6px; }
.tl-swatch { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--sand); }
.tl-swatch.living { background: var(--sand-faint); }
.tl-swatch.dead { background: var(--paper-deep); border-color: var(--paper-deep); }
.tl-line { display: inline-block; width: 16px; height: 2px; border-radius: 2px; }
.tl-line.spouse { height: 3px; background: var(--sand-bright); }
.tl-line.child { background: var(--sand); opacity: .8; }

/* connected view: draggable graph cards (styled like .tree-hit, but a grab
   cursor since every card can be picked up and moved) */
.graph-hit {
  position: absolute;
  pointer-events: auto;
  cursor: grab;
  border-radius: 10px;
}
.graph-hit:active { cursor: grabbing; }

.tree-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--sepia-faint);
  background: rgba(250, 246, 234, .88);
  backdrop-filter: blur(6px);
  border: 1px solid var(--paper-deep);
  border-radius: 20px;
  padding: 5px 14px;
  z-index: 7;
  pointer-events: none;
  white-space: nowrap;
  max-width: calc(100vw - 240px);
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 720px) {
  /* the stack creates the stacking context the sheet lives in, so it has to
     outrank the scrim itself — a z-index inside it cannot escape it */
  .tree-toolbar-stack { top: calc(8px + var(--safe-t)); left: 8px; right: 8px; max-width: calc(100vw - 16px); gap: 6px; width: auto; z-index: 47; }
  .tree-toolbar {
    top: 10px;
    left: 8px;
    right: 8px;
    max-width: calc(100vw - 16px);
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding: 6px 8px;
  }
  .tree-toolbar-stack > .tree-toolbar:first-child { width: 100%; }
  .tt-search { flex: 1; min-width: 0; }
  .tt-q { width: 100%; min-width: 0; font-size: 16px; padding: 9px 12px; }
  .tt-results { width: auto; left: 0; right: 0; max-height: 50vh; }
  .tt-desk { display: none !important; }
  .tree-toolbar .btn-sm { min-width: 42px; min-height: 40px; }

  /* the options bar becomes a modal bottom sheet */
  .tt-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(16, 27, 51, .35);
    z-index: 46;
  }
  .tt-scrim[hidden] { display: none; }
  .tree-toolbar-more {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0;
    top: auto !important;
    max-width: none !important;
    max-height: 76vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    border-radius: 18px 18px 0 0;
    border-bottom: none;
    padding: 6px 16px calc(18px + var(--safe-b));
    z-index: 1;
    background: var(--paper-light);
    box-shadow: 0 -18px 40px -18px rgba(16, 27, 51, .45);
  }
  .tree-toolbar-more .tt-sep { display: none; }
  .tt-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--paper-light);
    padding: 8px 0 6px;
    margin-bottom: 2px;
    border-bottom: var(--hairline);
    z-index: 1;
  }
  .tt-sheet-title { font-family: var(--serif); font-size: 19px; color: var(--ink); }
  .tt-group {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px 0;
    border-bottom: var(--hairline);
  }
  .tt-group:last-child { border-bottom: none; }
  .tt-group-h {
    display: block;
    font-size: 11px;
    letter-spacing: .14em;
    text-transform: uppercase;
    font-weight: 500;
    color: var(--sepia-faint);
  }
  .tt-group .pill-group { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
  .tt-group .filter-pill,
  .tt-group .btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    width: auto;
    border-radius: 12px;
    font-size: 13px;
    letter-spacing: .02em;
    text-transform: none;
    padding: 8px 12px;
  }
  .tt-label { display: inline; }
  .tt-group .icon-pill { min-width: 0; height: auto; }
  #tt-depth { justify-content: space-between; gap: 10px; }
  #tt-depth .btn-sm { flex: 1; }
  .tt-d-label { font-size: 15px; min-width: 70px; }
  /* the spacing slider is worth more than the popover it hid behind */
  #tt-gap-btn { display: none; }
  .tt-gap-pop, .tt-gap-pop[hidden] {
    display: block;
    position: static;
    width: auto;
    border: none;
    box-shadow: none;
    background: none;
    padding: 0;
  }
  .tt-gap-pop .tt-gap-row { gap: 12px; }
  .tt-gap-pop input[type="range"] { height: 22px; }
  .tt-gap-pop .btn { width: auto; margin-top: 0; min-height: 42px; min-width: 42px; }

  /* the pointer-only hint is swapped for a touch one and removed on first use */
  .tree-hint { bottom: calc(100px + var(--safe-b)); white-space: normal; max-width: calc(100vw - 32px); text-align: center; line-height: 1.4; }
  /* the living/deceased swatches repeat what every card's years already say,
     and they were the only thing left fighting for the bottom-left corner */
  .tree-legend { display: none; }
  /* the topbar search and the tree's own search box did the same job twice,
     one above the other; the in-canvas one wins here because it centres the
     person instead of reloading the whole view */
  body:has(.tree-stage) .searchbox.topsearch { display: none; }
  /* stack the focus chip above the legend instead of beside it, and cap
     its width — a long person name would otherwise overflow the screen */
  .tree-focus {
    left: 8px;
    right: 8px;
    bottom: calc(12px + var(--safe-b));
    width: fit-content;
    max-width: calc(100vw - 16px);
    margin: 0 auto;
  }
  .tree-focus .tf-k { display: none; }
  .tree-focus .tf-n { max-width: 55vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* stack above the focus chip instead of near the top — both pieces of
     "why does the tree look like this" info now live in one bottom-right
     column, right of the legend */
  .tree-filter-chip {
    left: 8px;
    right: 8px;
    bottom: calc(56px + var(--safe-b));
    width: fit-content;
    margin: 0 auto;
    max-width: calc(100vw - 16px);
    font-size: 11.5px;
  }
  .tree-filter-chip .tf-k { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* the peek card spans the width and sits above everything else down there */
  .tree-peek {
    left: 8px;
    right: 8px;
    bottom: calc(8px + var(--safe-b));
    transform: none;
    max-width: none;
    flex-wrap: wrap;
    z-index: 30;
  }
  .tree-peek .tp-body { flex: 1; }
  .tree-peek .tp-actions { width: 100%; order: 3; }
  .tree-peek .tp-actions .btn { flex: 1; justify-content: center; min-height: 44px; }
  /* with the peek card open the legend and chips would collide with it */
  .tree-stage:has(.tree-peek:not([hidden])) .tree-legend,
  .tree-stage:has(.tree-peek:not([hidden])) .tree-focus,
  .tree-stage:has(.tree-peek:not([hidden])) .tree-filter-chip { display: none; }
}


/* ---------------- person modal ---------------- */
.person-hero { display: flex; gap: 18px; align-items: center; margin-bottom: 18px; }
.person-hero h2 { margin: 0; font-size: 27px; }
.person-hero .vitals { font-size: 13.5px; color: var(--sepia-faint); letter-spacing: .06em; }
.person-section { margin: 18px 0; }
.person-section > .micro { display: block; margin-bottom: 8px; border-bottom: var(--hairline); padding-bottom: 6px; }
.kinship-term {
  font-family: var(--serif);
  font-style: italic;
  font-size: 19px;
  line-height: 1.25;
  color: var(--ink);
}
.kinship-detail { margin-top: 5px; line-height: 1.5; }
.kinship-detail a { color: var(--ink-soft); text-decoration: underline dotted; }
.kinship-detail a:hover { color: var(--ink); }

/* ---------------- relationship calculator ---------------- */
.relate-pickers {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: start;
}
.relate-slot > .micro { display: block; margin-bottom: 8px; }
.relate-swap { align-self: center; margin-top: 22px; }
.relate-search { position: relative; }
.relate-hits {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 320px;
  overflow-y: auto;
  background: var(--paper-light);
  border: 1px solid var(--paper-deep);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 20;
  padding: 6px;
}
.relate-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: var(--hairline);
  border-radius: 9px;
  background: var(--paper);
}
.relate-card .relate-name { font-family: var(--serif); font-size: 17px; color: var(--ink); }
.relate-card .icon-btn { margin-left: auto; }
.relate-result { margin-top: 22px; padding-top: 18px; border-top: var(--hairline); }
.relate-sentence { font-size: 15px; line-height: 1.6; color: var(--sepia); }
.relate-sentence.reverse { margin-top: 6px; color: var(--sepia-faint); }
.relate-term { font-family: var(--serif); font-size: 19px; color: var(--ink); }
@media (max-width: 700px) {
  .relate-pickers { grid-template-columns: 1fr; }
  .relate-swap { margin-top: 0; justify-self: start; }
}
.family-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: var(--hairline);
  border-radius: 9px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--paper);
  transition: border-color .15s;
}
.family-row:hover { border-color: var(--sand); }
.family-row .role-tag { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--sepia-faint); font-weight: 500; }
.family-row .kids { font-size: 12.5px; color: var(--sepia-faint); margin-left: auto; white-space: nowrap; }
.spouse-link { text-decoration: none; color: var(--ink); font-weight: 500; }
.kid-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--paper);
  border: var(--hairline);
  border-radius: 20px;
  padding: 3px 10px 3px 4px;
  margin: 0 6px 6px 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--ink);
  text-decoration: none;
  transition: border-color .15s;
}
.kid-chip:hover { border-color: var(--sand); }

/* ---------------- diff / review ---------------- */
.diff-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.diff-col { border: var(--hairline); border-radius: 9px; padding: 12px 14px; background: var(--paper); }
.diff-col h4 { margin: 0 0 8px; font-size: 16px; }
.diff-col .micro { display: block; margin-bottom: 10px; }
.diff-row { display: flex; gap: 8px; padding: 3px 0; font-size: 13.5px; }
.diff-row .k { color: var(--sepia-faint); width: 92px; flex-shrink: 0; font-size: 12px; padding-top: 1px; }
.diff-row .v { flex: 1; word-break: break-word; }
.diff-row .v.empty { color: var(--sepia-faint); font-style: italic; }
.diff-row.changed .v { background: rgba(217, 179, 108, .22); border-radius: 4px; padding: 0 4px; }

/* ---------------- stats ---------------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat {
  background: var(--paper-light);
  border: var(--hairline);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat .num { font-family: var(--serif); font-size: 30px; color: var(--ink); line-height: 1; }
.stat .lbl { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--sepia-faint); margin-top: 6px; font-weight: 500; }

/* ---------------- search ---------------- */
.searchbox { position: relative; }
.searchbox input {
  width: 260px;
  background: rgba(250, 246, 234, .12);
  border: 1px solid rgba(250, 246, 234, .25);
  color: var(--paper-light);
  border-radius: 8px;
  padding: 7px 12px 7px 32px;
  font-family: var(--sans);
  font-weight: 300;
  font-size: 13.5px;
  outline: none;
  transition: all .15s;
}
.searchbox input::placeholder { color: rgba(250, 246, 234, .5); }
.searchbox input:focus { background: var(--paper-light); color: var(--sepia); border-color: var(--sand); }
.searchbox .s-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: rgba(250, 246, 234, .55); font-size: 15px; pointer-events: none; display: inline-flex; }
.searchbox input:focus + .s-icon { color: var(--sepia-faint); }
.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 320px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--paper-light);
  border: 1px solid var(--paper-deep);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 50;
  padding: 6px;
}
.search-result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  color: var(--sepia);
}
.search-result:hover { background: var(--paper-deep); }
.search-result .sr-name { font-family: var(--serif); font-size: 15px; color: var(--ink); }
.search-result .sr-years { font-size: 12px; color: var(--sepia-faint); }

/* ---------------- empty states ---------------- */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--sepia-faint);
}
.empty .big { font-family: var(--serif); font-style: italic; font-size: 26px; color: var(--ink); margin-bottom: 8px; }

/* ---------------- Familienblatt ---------------- */
.sheet { max-width: 720px; margin: 0 auto; padding: 22px clamp(14px, 3vw, 24px) 64px; }
.sh-hero { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 8px; }
.sh-hero .medallion.lg { flex-shrink: 0; }
.sh-hero-body { min-width: 0; flex: 1; }
.sh-hero h1 { margin: 2px 0 6px; font-size: clamp(24px, 5vw, 30px); line-height: 1.15; overflow-wrap: anywhere; }
.sh-crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 4px; font-size: 12px; color: var(--sepia-faint); }
.sh-crumbs a { color: var(--sepia); text-decoration: none; }
.sh-crumbs a:hover, .sh-crumbs a:focus-visible { color: var(--ink); text-decoration: underline; }
.sh-crumbs .ph { font-size: 11px; opacity: .6; }
.sh-vitals { margin: 0; font-size: 14px; color: var(--sepia); }
.sh-vitals strong { font-weight: 500; color: var(--ink); }
.sh-stats { margin: 6px 0 10px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--sepia-faint); }
.sh-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sh-actions .btn { text-decoration: none; }
.sh-section { margin-top: 20px; }
.sh-h, .sh-sub {
  display: flex; align-items: center; gap: 8px; margin: 0 0 8px;
  font-family: var(--sans); font-weight: 500; font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--sepia-faint);
}
.sh-sub { margin-top: 10px; }
.sh-h .ph, .sh-sub .ph { font-size: 15px; }
.sh-count { margin-left: auto; font-size: 11px; letter-spacing: 0; background: var(--paper-deep); color: var(--sepia); border-radius: 10px; padding: 1px 8px; font-variant-numeric: tabular-nums; }
.sh-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.sh-person {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 7px 10px;
  background: var(--paper-light); border: 1px solid var(--paper-deep); border-radius: 12px;
  color: var(--ink); text-decoration: none; transition: border-color .15s, box-shadow .15s;
}
.sh-person:hover, .sh-person:focus-visible { border-color: var(--sand); box-shadow: var(--shadow-sm); outline: none; }
.sh-person:focus-visible { box-shadow: 0 0 0 3px rgba(217, 179, 108, .35); }
.sh-person[aria-current="page"] { background: var(--sand-faint); border-color: var(--sand); }
.sh-person .medallion { flex-shrink: 0; }
.sh-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sh-name { font-family: var(--serif); font-size: 17px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sh-years { font-size: 12.5px; color: var(--sepia-faint); }
.sh-go { color: var(--sepia-faint); font-size: 16px; flex-shrink: 0; }
.sh-fam { border: 1px solid var(--paper-deep); border-radius: 14px; padding: 10px; background: var(--paper); margin-bottom: 10px; }
.sh-fam .sh-person { background: var(--paper-light); }
.sh-empty { margin: 0; font-size: 13.5px; color: var(--sepia-faint); font-style: italic; }
.sh-hint { margin-top: 26px; font-size: 12.5px; color: var(--sepia-faint); text-align: center; }
@media (max-width: 720px) {
  .sheet { padding: 16px max(14px, var(--safe-l)) calc(72px + var(--safe-b)) max(14px, var(--safe-r)); }
  /* the two things you always want from a Familienblatt — jump into the tree,
     open the details — stay reachable however far down the lists you are */
  .sh-actions {
    position: fixed;
    left: 0; right: 0;
    bottom: 0;
    z-index: 30;
    gap: 8px;
    padding: 10px max(12px, var(--safe-l)) calc(10px + var(--safe-b)) max(12px, var(--safe-r));
    background: rgba(250, 246, 234, .96);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--paper-deep);
    flex-wrap: nowrap;
  }
  .sh-actions .btn { flex: 1; justify-content: center; min-height: var(--tap); }
  .sh-hint { margin-bottom: 8px; }
}
@media (max-width: 480px) {
  .sh-hero { gap: 14px; }
  .sh-hero .medallion.lg { width: 56px; height: 56px; font-size: 22px; }
}

/* wide tables (members, import mapping) scroll inside their panel rather
   than pushing the whole page sideways or silently clipping their last
   column. The directory is the exception: it drops columns instead. */
@media (max-width: 720px) {
  .panel:has(> table.list), .panel:has(> .ck-fields) { overflow-x: auto; }
  table.list:not(.dir-table) { min-width: 560px; }
  table.list:not(.dir-table) td, table.list:not(.dir-table) th { padding: 12px 10px; }
}

/* ---------------- directory ---------------- */
/* the A–Z filter, folded on phones (see renderList) */
.dir-filter { border-bottom: var(--hairline); }
.dir-filter > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  min-height: var(--tap);
  box-sizing: border-box;
  font-size: 13.5px;
  color: var(--sepia);
  user-select: none;
}
.dir-filter > summary::-webkit-details-marker { display: none; }
.dir-filter > summary strong { color: var(--ink); font-weight: 500; }
.dir-filter > summary .act-caret { margin-left: auto; transition: transform .15s ease; }
.dir-filter[open] > summary .act-caret { transform: rotate(180deg); }
.dir-filter > .pill-group { padding: 0 18px 14px; }
.dir-sub { display: none; }
@media (max-width: 720px) {
  /* a six-column table cannot be read on a phone: keep the name, move the
     dates and the trade under it, drop the rest (they are in the details) */
  .dir-table .col-opt { display: none; }
  /* with only the portrait and the name left, the header row says nothing */
  .dir-table thead { display: none; }
  .dir-sub { display: block; font-size: 12.5px; line-height: 1.35; margin-top: 2px; }
  .dir-table td { padding: 12px 10px; }
  .dir-filter > .pill-group { padding: 0 14px 14px; }
}

/* ---------------- Mein Konto ---------------- */
.me-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 16px; }
.me-card { padding: 18px 20px 20px; }
.me-card h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 20px; }
details.me-card { padding-top: 0; }
details.me-card > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 0 0;
  min-height: var(--tap);
  box-sizing: border-box;
  user-select: none;
}
details.me-card > summary::-webkit-details-marker { display: none; }
details.me-card > summary h3 { margin: 0; }
details.me-card > summary .act-caret { margin-left: auto; color: var(--sepia-faint); transition: transform .15s ease; }
details.me-card[open] > summary .act-caret { transform: rotate(180deg); }
details.me-card > summary + * { margin-top: 12px; }
.me-card h3 .ph { font-size: 18px; color: var(--sepia-faint); }
.me-card form .btn { margin-top: 4px; }
.me-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.me-actions .btn { text-decoration: none; }
.user-chip { text-decoration: none; border-radius: 20px; padding: 2px 8px 2px 2px; transition: background .15s; }
.user-chip:hover { background: rgba(217, 179, 108, .14); }

/* ---------------- toggle switch (settings) ---------------- */
.switch-row { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch-track { position: absolute; inset: 0; background: var(--paper-deep); border-radius: 20px; transition: background .15s ease; }
.switch-track::before {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--paper-light);
  box-shadow: 0 1px 3px rgba(16, 27, 51, .3);
  transition: transform .15s ease;
}
.switch input:checked + .switch-track { background: var(--ink); }
.switch input:checked + .switch-track::before { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(217, 179, 108, .35); }

/* ---------------- import status log ---------------- */
.import-log {
  margin-top: 14px; max-height: 260px; overflow-y: auto;
  background: var(--paper-light); border: 1px solid var(--paper-deep); border-radius: 10px;
  padding: 8px 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.5;
}
.il-line { display: flex; gap: 10px; color: var(--sepia); }
.il-line .il-t { color: var(--sepia-faint); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.il-line.ok { color: var(--forest); }
.il-line.warn { color: var(--olive); }
.il-line.err { color: var(--brick); }
.il-line.muted { color: var(--sepia-faint); }
.il-line.running .il-m::after { content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 8px; border-radius: 50%; background: var(--sand); animation: il-pulse 1s infinite alternate; }
@keyframes il-pulse { from { opacity: .3 } to { opacity: 1 } }

/* ---------------- print: never render background colors/shadows, whatever the browser's "print backgrounds" setting ---------------- */
@media print {
  * {
    background: transparent !important;
    box-shadow: none !important;
    -webkit-print-color-adjust: economy !important;
    print-color-adjust: economy !important;
  }
}

/* ---------------- tree image export / print ---------------- */
.tt-export { display: inline-flex; align-items: center; gap: 2px; }
.tree-print { display: none; }
@media print {
  body.tree-printing > :not(.tree-print) { display: none !important; }
  body.tree-printing .tree-print { display: block; width: 100%; max-height: 96vh; object-fit: contain; margin: 0 auto; }
  body.tree-printing { background: #fff; }
}

/* ---------------- print ---------------- */
.print-block { display: none; }
@media print {
  body { background: #fff; }
  .topbar, .tree-toolbar, .toasts, .veil, .print-hidden, .sh-actions, .sh-go, .sh-hint { display: none !important; }
  .print-block { display: block; }
  .page { max-width: none; padding: 0; }
  .panel { box-shadow: none; border-color: #ccc; }
  .print-cover { text-align: center; padding: 40px 0 10px; border-bottom: 3px double #1b2a4a; margin-bottom: 24px; }
  .print-cover h1 { font-size: 40px; margin: 0; }
  .print-cover .tagline { font-size: 12px; letter-spacing: .2em; text-transform: uppercase; color: #666; margin-top: 8px; }
  .print-avoid-break { break-inside: avoid; page-break-inside: avoid; }
}

/* ============================================================
   Touch: nothing interactive smaller than a fingertip
   ------------------------------------------------------------
   Keyed on the pointer, not the width — a small laptop window keeps the
   dense desktop chrome, a large tablet gets the roomy targets it needs.
   ============================================================ */
@media (pointer: coarse) {
  .btn { min-height: var(--tap); }
  .btn-sm { min-height: 40px; padding: 8px 14px; font-size: 13px; }
  .icon-btn { width: var(--tap); height: var(--tap); }
  .filter-pill { min-height: 38px; padding: 8px 14px; }
  .rel-x { min-width: 32px; min-height: 32px; }
  .sh-person, .search-result, .tt-result, .family-row { min-height: var(--tap); }
  table.list td { padding: 14px 12px; }
  input[type="range"] { height: 26px; }
}

/* ------------------------------------------------------------
   iOS Safari zooms the whole page in whenever a field it focuses renders
   under 16px, and never zooms back out — the page just stays wrong until
   you pinch it back. Every text-entry control therefore has to clear that
   bar.

   Gated on `any-pointer` rather than `pointer`: `pointer` describes the
   *primary* pointing device, so an iPad with a trackpad attached reports
   `pointer: fine` while still being a touchscreen that does the zoom.
   `any-pointer: coarse` is true whenever a touchscreen exists at all.
   (Tap sizing above stays on `pointer` — target size should follow the
   device you are actually pointing with.)

   Matched on the element rather than a class so a field added later is
   covered by default, and !important because several dense views set a
   smaller size from a more specific selector (.ck-fields .input and
   friends) that no ordering here could beat. Controls that never trigger
   the zoom — checkbox, radio, range, file, color — are left alone.
   ------------------------------------------------------------ */
@media (any-pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]),
  select,
  textarea { font-size: 16px !important; }
}

/* ---------------- misc ---------------- */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--paper-deep);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.center-load { display: flex; align-items: center; justify-content: center; min-height: 50vh; gap: 10px; color: var(--sepia-faint); }

.divider { border: none; border-top: var(--hairline); margin: 18px 0; }

.pill-group { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-pill {
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--paper-deep);
  background: transparent;
  color: var(--sepia-faint);
  cursor: pointer;
  transition: all .15s;
}
.filter-pill:hover { border-color: var(--sand); color: var(--ink); }
.filter-pill.active { background: var(--ink); border-color: var(--ink); color: var(--paper-light); }

.msg-banner {
  border-radius: 9px;
  padding: 12px 16px;
  font-size: 13.5px;
  margin-bottom: 16px;
  border: 1px solid;
}
.msg-banner.info { background: rgba(217, 179, 108, .12); border-color: rgba(217, 179, 108, .5); color: var(--olive); }
.msg-banner.err { background: rgba(156, 74, 60, .08); border-color: rgba(156, 74, 60, .35); color: var(--brick); }

/* ============================================================
   Hamburger + megamenu (small screens)
   ============================================================ */
.hamburger {
  display: none;
  background: none;
  border: 1px solid rgba(250, 246, 234, .3);
  border-radius: 8px;
  width: 42px;
  height: 38px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--paper-light);
  font-size: 22px;
  flex-shrink: 0;
  transition: border-color .15s;
}
.hamburger:hover { border-color: var(--sand); }
.hamburger .hb-close { display: none; }
.topbar.menu-open .hamburger .hb-open { display: none; }
.topbar.menu-open .hamburger .hb-close { display: inline-block; }

/* megamenu panel — hidden by default, slides down from the topbar */
.megamenu {
  position: fixed;
  top: var(--topbar-total);
  left: 0;
  right: 0;
  z-index: 39;
  background: var(--paper-light);
  border-bottom: 2px solid var(--sand);
  box-shadow: 0 18px 40px -18px rgba(16, 27, 51, .35);
  padding: 18px 26px 20px;
  max-height: calc(100dvh - var(--topbar-total));
  overflow-y: auto;
  padding-bottom: calc(20px + var(--safe-b));
  transform: translateY(-12px);
  opacity: 0;
  pointer-events: none;
  transition: transform .25s ease, opacity .2s ease;
}
.megamenu[aria-hidden="false"] {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.megamenu-inner {
  max-width: 760px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
  gap: 10px;
}
.mm-tile {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 14px 16px;
  border: 1px solid var(--paper-deep);
  border-radius: 12px;
  background: var(--paper);
  text-decoration: none;
  color: var(--sepia);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.mm-tile:hover { border-color: var(--sand); background: var(--paper-light); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.mm-tile.active { border-color: var(--sand); background: var(--sand-faint); }
.mm-icon {
  font-size: 24px;
  color: var(--ink);
  line-height: 1;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--sand-faint);
  border: 1px solid rgba(217, 179, 108, .5);
  border-radius: 10px;
  flex-shrink: 0;
}
.mm-body { display: flex; flex-direction: column; gap: 3px; }
.mm-title { font-family: var(--serif); font-size: 18px; color: var(--ink); line-height: 1.2; }
.mm-desc { font-size: 12.5px; color: var(--sepia-faint); line-height: 1.45; }
/* the admin tiles are a group of their own, not more of the same list */
.mm-section {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}
.mm-section::after { content: ""; flex: 1; height: 1px; background: var(--paper-deep); }
.mm-foot {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding-top: 14px;
  border-top: var(--hairline);
  font-size: 13px;
  color: var(--sepia-faint);
}
.mm-foot .role-badge { margin-right: auto; }
.mm-foot { flex-wrap: wrap; }
.mm-user { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* responsive menu bar
   ≥ 1801   wordmark · nav (icon + label) · role · user · search · sign out
   901–1800 nav labels only, no role badge, user shows medallion only, narrower
            search — the right-hand trimmings cost the nav its labels first
   ≤ 900    wordmark · search (fills) · hamburger — everything else lives in the megamenu */
@media (max-width: 1800px) {
  .topbar .role-badge { display: none; }
  .user-chip-name { display: none; }
  .searchbox.topsearch input { width: 190px; }
  .topbar-out span { display: none; }
  .topbar .topbar-out { min-width: 38px; justify-content: center; padding-left: 0; padding-right: 0; }
  .topbar { gap: 12px; }
}
/* nav-compact is set by JS whenever the inline nav would overflow: icons only, labels in title */
.topbar.nav-compact .topnav a span { display: none; }
.topbar.nav-compact .topnav a { padding: 8px 10px; }
.topbar.nav-compact .topnav a .ph { font-size: 20px; opacity: 1; }
.topbar.nav-compact .navmenu > summary span { display: none; }
.topbar.nav-compact .navmenu > summary { padding: 8px 10px; gap: 4px; }
.topbar.nav-compact .navmenu > summary .ph { font-size: 20px; opacity: 1; }
.topbar.nav-compact .navmenu > summary .nm-caret { font-size: 12px; }
/* …except the nudge: without the label there is no "after the label", so it
   becomes a corner badge on the icon. A dot nobody can see is not a nudge. */
.topbar.nav-compact .topnav a { position: relative; }
.topbar.nav-compact .topnav a span.nav-dot:not([hidden]),
.topbar.nav-compact .navmenu > summary span.nav-dot:not([hidden]) {
  display: inline-block;
  position: absolute; top: 5px; right: 5px; margin: 0;
}
.topbar.nav-compact .navmenu > summary { position: relative; }
/* the menu is twelve tiles deep; at three lines of description each, finding
   anything on a phone means scrolling past the whole app */
@media (max-width: 720px) {
  .megamenu-inner { gap: 6px; }
  .mm-tile { padding: 10px 12px; gap: 10px; }
  .mm-icon { width: 34px; height: 34px; font-size: 19px; border-radius: 9px; }
  .mm-title { font-size: 17px; }
  .mm-desc {
    font-size: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .mm-foot .btn { flex: 1 1 auto; justify-content: center; }
}
@media (max-width: 900px) {
  .hamburger { display: inline-flex; }
  .topnav-wrap { display: none; }
  .user-chip { display: none; }
  .topbar .topbar-out { display: none; }
  .topbar { gap: 12px; }
  .topbar-right { flex: 1; gap: 10px; }
  .searchbox.topsearch { flex: 1; min-width: 0; }
  .searchbox.topsearch input { width: 100%; min-width: 0; }
  .search-results { left: 0; right: 0; width: auto; }
  .megamenu { padding: 14px clamp(12px, 3vw, 26px) 18px; }
}
@media (max-width: 420px) {
  .wordmark { font-size: 21px; }
}
@media (min-width: 901px) {
  .megamenu { display: none; }
}

/* ---------------- import checks (review queue) ---------------- */
.check-card {
  border: var(--hairline);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 14px;
  background: var(--paper);
  transition: border-color .15s;
}
.check-card:hover { border-color: var(--sand); }
.check-card input[type="radio"], .check-card input[type="checkbox"] { accent-color: var(--ink); margin-right: 4px; }
.ck-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; }
.ck-name { font-family: var(--serif); font-size: 19px; color: var(--ink); }
.ck-section { margin-top: 12px; padding-top: 10px; border-top: var(--hairline); }
.ck-section > .micro { display: block; margin-bottom: 6px; }
.ck-warn { display: flex; gap: 6px; align-items: flex-start; color: var(--olive); font-size: 13px; margin: 4px 0; }
.ck-warn .ph { flex-shrink: 0; margin-top: 2px; }
.ck-fields { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.ck-fields th { text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--sepia-faint); font-weight: 500; padding: 4px 6px; }
.ck-fields td { padding: 3px 6px; vertical-align: middle; border-top: 1px solid rgba(233, 223, 196, .6); }
.ck-fields td.k { color: var(--sepia-faint); font-size: 12.5px; width: 92px; white-space: nowrap; }
.ck-fields td.cur { color: var(--sepia); max-width: 220px; word-break: break-word; }
.ck-fields td.cur.empty { color: var(--sepia-faint); font-style: italic; }
.ck-fields .input { padding: 5px 8px; font-size: 13px; }
.ck-kind { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 10px; white-space: nowrap; }
.ck-kind.set, .ck-kind.fill { background: rgba(74, 107, 82, .14); color: var(--forest); }
.ck-kind.same { background: var(--paper-deep); color: var(--sepia-faint); }
.ck-kind.keep { background: rgba(138, 122, 60, .15); color: var(--olive); }
.ck-kind.overwrite { background: rgba(156, 74, 60, .12); color: var(--brick); }
.ck-rel { border: var(--hairline); border-radius: 8px; padding: 10px 12px; margin: 8px 0; background: var(--paper-light); }
.ck-rel-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.ck-rel-head em { color: var(--sepia-faint); }
.ck-rel-fields { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; align-items: center; }
.ck-rel-fields .input { padding: 5px 8px; font-size: 13px; width: 150px; }
.ck-rel-fields .input.yr { width: 80px; }
.ck-plan { margin-top: 12px; border: 1px solid rgba(217, 179, 108, .5); background: rgba(217, 179, 108, .08); border-radius: 8px; padding: 10px 14px; font-size: 13.5px; }
.ck-plan .micro { display: block; margin-bottom: 6px; }
.ck-plan.stale { opacity: .6; }
.ck-plan-line { display: flex; gap: 8px; align-items: flex-start; padding: 2px 0; }
.ck-plan-line .ph { flex-shrink: 0; margin-top: 3px; }
.ck-plan-line.blocked { color: var(--brick); }
.ck-plan-line.warn { color: var(--olive); }
.ck-plan-sum { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; color: var(--sepia-faint); font-size: 12.5px; }
.ck-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.ck-actions .input { flex: 1; min-width: 160px; padding: 6px 10px; font-size: 13px; }
.ck-decided { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: var(--hairline); flex-wrap: wrap; }
.ck-decided .ck-name { font-size: 16px; }
.ck-batches { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
@media (max-width: 720px) {
  .ck-fields td.k { width: auto; }
  .ck-fields .cur-col { display: none; }
}

/* ---------------- import proposals ---------------- */
.proposal-card {
  border: var(--hairline);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--paper);
  transition: border-color .15s;
}
.proposal-card:hover { border-color: var(--sand); }
.proposal-card input[type="radio"] { accent-color: var(--ink); margin-right: 4px; }
.proposal-card pre {
  background: var(--paper-light);
  border: var(--hairline);
  border-radius: 8px;
  padding: 8px 10px;
  max-height: 160px;
  overflow: auto;
}

/* ---------------- parentless triage (verwaiste Personen) ----------------
   One row per record, and every decision inside it — a suggested duplicate,
   a suggested parent, a two-person record to split — is its own bordered
   card. Suggestions used to be flat rows separated by whitespace only, which
   left it unclear where one ended and the next began. */
.orphan-item { padding: 14px 18px; border-bottom: var(--hairline); }
.orphan-item:last-child { border-bottom: 0; }
.orphan-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.orphan-who { flex: 1; min-width: 220px; }
.orphan-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.orphan-origin { margin-top: 9px; }
.orphan-section { margin-top: 13px; }
.orphan-section > .micro { display: block; margin-bottom: 3px; }
.orphan-section-hint { display: block; margin-bottom: 9px; }

.orphan-card {
  border: var(--hairline);
  border-radius: 10px;
  padding: 11px 14px;
  background: var(--paper-light);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  transition: border-color .15s;
}
.orphan-card + .orphan-card { margin-top: 8px; }
.orphan-card:hover { border-color: var(--sand); }
.orphan-card-body { flex: 1; min-width: 200px; }
.orphan-card .btn { flex-shrink: 0; }

/* A two-person record is one decision about two halves, so the halves stay
   inside a single card, divided rather than separated. */
.orphan-card.is-couple { display: block; }
.orphan-part { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 0; }
.orphan-part:first-child { padding-top: 0; }
.orphan-part + .orphan-part { border-top: var(--hairline); }
.orphan-card.is-couple .btn { margin-top: 11px; }

@media (max-width: 720px) {
  .orphan-item { padding: 13px 14px; }
  .orphan-actions { width: 100%; }
  .orphan-actions .btn { flex: 1; justify-content: center; }
  .orphan-card .btn { width: 100%; justify-content: center; }
}

/* ---------------- portraits ---------------- */
.medallion img { width: 100%; height: 100%; object-fit: cover; display: block; }
.portrait-upload {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper-light);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  border: 2px solid var(--paper-light);
  transition: transform .15s;
}
.portrait-upload:hover { transform: scale(1.1); background: var(--ink-deep); }


/* ---------------- relationship editor + audit ---------------- */
.rel-row { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin: 4px 0 8px; }
.rel-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--paper); border: var(--hairline);
  border-radius: 20px; padding: 2px 10px 2px 3px;
}
.rel-chip .rel-name { font-size: 13px; color: var(--ink); }
.rel-x {
  background: none; border: none; cursor: pointer;
  color: var(--sepia-faint); font-size: 11px; padding: 2px 3px;
  border-radius: 50%; display: inline-flex; align-items: center;
}
.rel-x:hover { color: var(--brick); background: rgba(156, 74, 60, .1); }
.rel-fam { border: var(--hairline); border-radius: 9px; padding: 10px 12px; margin-bottom: 10px; background: var(--paper); }
.rel-slot { display: inline-flex; align-items: center; gap: 8px; margin-right: 18px; }
.audit-row {
  display: flex; gap: 8px; align-items: baseline;
  padding: 6px 0; border-bottom: var(--hairline);
  flex-wrap: wrap;
}
.audit-row .small:first-child { flex-shrink: 0; }


/* ============================================================
   Knowledge base — Wissen (Geschichten + Lexikon)
   ============================================================ */
.kb-tabs { margin-bottom: 18px; }
.kb-tabs .filter-pill { padding: 7px 16px; font-size: 14px; }
.kb-tabs .filter-pill .ph { width: 15px; height: 15px; flex-shrink: 0; }

.kb-filters { margin-bottom: 18px; display: flex; flex-direction: column; gap: 14px; }

/* .searchbox is styled for the dark topbar; on paper it needs the ink palette */
.kb-search { position: relative; max-width: 520px; width: 100%; }
.kb-search input {
  width: 100%;
  background: var(--paper-light);
  border: 1px solid var(--paper-deep);
  color: var(--sepia);
  font-size: 14px;
  padding: 9px 14px 9px 36px;
}
.kb-search input::placeholder { color: var(--sepia-faint); }
.kb-search input:focus { border-color: var(--sand); background: var(--paper-light); }
.kb-search .s-icon { color: var(--sepia-faint); left: 12px; }
.kb-search input:focus + .s-icon { color: var(--ink); }

/* pills that carry an icon need room between glyph and label */
.kb-filters .filter-pill, .kb-tabs .filter-pill { display: inline-flex; align-items: center; gap: 6px; }
.kb-filters .filter-pill .ph { width: 13px; height: 13px; flex-shrink: 0; }

/* ---- story cards ---- */
.kb-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}
.kb-card {
  background: var(--paper-light);
  border: var(--hairline);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  display: flex; flex-direction: column;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.kb-card:hover, .kb-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--sand);
  box-shadow: 0 6px 18px rgba(27, 42, 74, .09);
  outline: none;
}
.kb-card-photo { aspect-ratio: 4 / 3; background: var(--paper-deep); overflow: hidden; }
.kb-card-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kb-card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 7px; flex: 1; }
.kb-card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.kb-card-meta .badge .ph { width: 12px; height: 12px; margin-right: 4px; vertical-align: -1px; }
.kb-card-title { font-family: var(--serif); font-size: 20px; margin: 0; color: var(--ink); line-height: 1.2; }
.kb-card-text { margin: 0; font-size: 13.5px; color: var(--sepia); line-height: 1.5; }
.kb-card-people { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-top: auto; padding-top: 6px; }
.kb-card-people .rel-chip { padding: 2px 9px 2px 3px; }
.kb-card-people .rel-name { font-size: 12px; }

/* ---- glossary list ---- */
.kb-terms { margin: 0; }
.kb-term {
  padding: 14px 20px;
  border-bottom: var(--hairline);
  cursor: pointer;
}
.kb-term:last-child { border-bottom: none; }
.kb-term:hover, .kb-term:focus-visible { background: var(--paper-deep); outline: none; }
.kb-term dt {
  font-family: var(--serif); font-size: 19px; color: var(--ink);
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
}
.kb-term dd { margin: 4px 0 0; font-size: 14px; color: var(--sepia); line-height: 1.5; }
.kb-term dd.kb-aliases { margin-top: 5px; font-size: 13px; color: var(--sepia-faint); }
.kb-term dd.kb-aliases .micro { margin-right: 4px; }

/* ---- story / term detail ---- */
.modal.modal-wide { max-width: 860px; }
.kb-story-meta { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-bottom: 14px; }
.kb-story-meta .micro { display: inline-flex; align-items: center; gap: 5px; }
.kb-story-meta .micro .ph, .kb-story-meta .badge .ph { width: 13px; height: 13px; }
.kb-lead {
  font-family: var(--serif); font-size: 19px; line-height: 1.45;
  color: var(--ink-soft); margin: 0 0 16px;
}
.kb-example {
  font-family: var(--serif); font-style: italic; font-size: 15px;
  color: var(--ink-soft);
  border-left: 3px solid var(--sand); padding: 4px 0 4px 14px;
}
.kb-tag {
  display: inline-block; padding: 3px 11px; border-radius: 20px;
  background: var(--paper); border: var(--hairline);
  font-size: 12.5px; color: var(--ink); text-decoration: none; cursor: pointer;
}
.kb-tag:hover { background: var(--sand-bright); border-color: var(--sand); }

.kb-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.kb-shot { margin: 0; cursor: zoom-in; }
.kb-shot img {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block;
  border: var(--hairline); border-radius: 8px; background: var(--paper-deep);
}
.kb-shot:hover img { border-color: var(--sand); }
.kb-shot figcaption { font-size: 12px; color: var(--sepia-faint); margin-top: 5px; line-height: 1.35; }

/* ---- lightbox ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 200;
  /* solid, not translucent: even 3% of paper-on-ink leaves the sheet behind
     legibly ghosted across a flat dark field, and a photo deserves the
     whole screen — on a phone this *is* the screen */
  background: var(--ink-deep);
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 40px 16px;
}
.lightbox figure { margin: 0; max-width: 92vw; max-height: 88vh; text-align: center; }
.lightbox img { max-width: 100%; max-height: 80vh; object-fit: contain; border-radius: 6px; }
.lightbox figcaption {
  color: var(--paper); font-family: var(--serif); font-style: italic;
  font-size: 15px; margin-top: 12px;
}
.lightbox .icon-btn { color: var(--paper); background: rgba(244, 237, 218, .12); flex-shrink: 0; }
.lightbox .icon-btn:hover { background: rgba(244, 237, 218, .25); }
.lightbox .lb-close { position: absolute; top: 16px; right: 16px; }
.lb-count {
  position: absolute; top: 22px; left: 20px;
  color: rgba(244, 237, 218, .7); font-size: 12px; letter-spacing: .1em;
  font-variant-numeric: tabular-nums;
}

/* ---- story form: photo rows, related picker ---- */
.kb-photo-edit { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
/* thumbnail | actions on the first line, caption spanning underneath — the
   caption is the long field, and it must not be squeezed on a phone */
.kb-photo-row {
  display: grid;
  grid-template-columns: 74px 1fr;
  grid-template-areas: "thumb actions" "caption caption";
  gap: 8px 10px;
  align-items: center;
}
.kb-photo-row img, .kb-photo-row .kb-photo-new {
  grid-area: thumb;
  width: 74px; height: 56px; object-fit: cover;
  border: var(--hairline); border-radius: 6px; background: var(--paper-deep);
  display: inline-flex; align-items: center; justify-content: center; color: var(--sepia-faint);
}
.kb-photo-actions { grid-area: actions; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.kb-photo-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-photo-caption { grid-area: caption; width: 100%; }
.kb-photo-row.dropped { opacity: .45; }
/* a hairline between rows: stacked thumbnail/caption pairs otherwise read as
   one run-on block, especially on a phone where each row is two lines tall */
.kb-photo-row + .kb-photo-row { border-top: var(--hairline); padding-top: 12px; }

/* paired fields — one column as soon as two would be cramped */
.form-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-pair.wide-first { grid-template-columns: 2fr 1fr; }

/* the flexible gap that pushes primary actions right; it collapses on a
   phone, where the footer buttons share the width instead */
.foot-gap { flex: 1; }
.kb-related-picker {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  max-height: 190px; overflow-y: auto;
  border: var(--hairline); border-radius: 9px; padding: 12px 14px; background: var(--paper);
}
.kb-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }

/* ---- person modal: linked stories ---- */
.kb-mini { display: flex; flex-direction: column; }
.kb-mini-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0; border-bottom: var(--hairline);
  text-decoration: none; color: inherit;
}
.kb-mini-row:last-child { border-bottom: none; }
.kb-mini-row:hover .kb-mini-title { color: var(--ink); text-decoration: underline; }
.kb-mini-thumb {
  width: 46px; height: 36px; object-fit: cover; flex-shrink: 0;
  border: var(--hairline); border-radius: 5px; background: var(--paper-deep);
  display: inline-flex; align-items: center; justify-content: center; color: var(--sepia-faint);
}
.kb-mini-body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kb-mini-title {
  font-family: var(--serif); font-size: 15px; color: var(--ink-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ============================================================
   Markdown editor + rendered prose
   ============================================================ */
.md-editor { border: var(--hairline); border-radius: 10px; overflow: hidden; background: var(--paper-light); }
.md-toolbar {
  display: flex; align-items: center; gap: 3px; flex-wrap: wrap;
  padding: 6px 8px; background: var(--paper); border-bottom: var(--hairline);
}
.md-spacer { flex: 1; }
.md-tool {
  min-width: 30px; height: 28px; padding: 0 7px;
  background: none; border: 1px solid transparent; border-radius: 6px;
  color: var(--ink); font-size: 14px; cursor: pointer; line-height: 1;
}
.md-tool:hover { background: var(--sand-bright); border-color: var(--sand); }
.md-tool .ph { width: 15px; height: 15px; vertical-align: -3px; }
.md-modes { display: inline-flex; gap: 2px; }
.md-mode {
  padding: 4px 10px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  background: none; border: 1px solid transparent; border-radius: 6px;
  color: var(--sepia-faint); cursor: pointer;
}
.md-mode.active { background: var(--ink); color: var(--paper-light); border-color: var(--ink); }
.md-panes { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.md-editor[data-mode="write"] .md-panes { grid-template-columns: 1fr; }
.md-editor[data-mode="write"] .md-preview { display: none; }
.md-editor[data-mode="preview"] .md-panes { grid-template-columns: 1fr; }
.md-editor[data-mode="preview"] .md-src { display: none; }
.md-src {
  border: none !important; border-radius: 0 !important; resize: vertical;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px; line-height: 1.6; min-height: 200px;
  background: var(--paper-light);
}
.md-src:focus { outline: none; box-shadow: none; }
.md-preview {
  border-left: var(--hairline); padding: 12px 16px;
  overflow-y: auto; max-height: 420px; background: var(--paper);
}
.md-editor[data-mode="preview"] .md-preview { border-left: none; }
.md-hint { padding: 6px 10px; border-top: var(--hairline); background: var(--paper); font-size: 11.5px; }

.prose { font-size: 15px; line-height: 1.65; color: var(--sepia); }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p { margin: 0 0 12px; }
.prose .md-h { font-family: var(--serif); color: var(--ink); margin: 20px 0 8px; line-height: 1.25; font-weight: 400; }
.prose h3.md-h { font-size: 21px; }
.prose h4.md-h { font-size: 18px; }
.prose h5.md-h, .prose h6.md-h {
  font-size: 12px; letter-spacing: .09em; text-transform: uppercase;
  font-family: var(--sans); color: var(--sepia-faint);
}
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin-bottom: 4px; }
.prose strong { color: var(--ink); font-weight: 600; }
.prose a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--sand); }
.prose .md-quote {
  margin: 0 0 14px; padding: 6px 0 6px 16px;
  border-left: 3px solid var(--sand);
  font-family: var(--serif); font-style: italic; font-size: 16px; color: var(--ink-soft);
}
.prose .md-hr { border: none; border-top: var(--hairline); margin: 20px 0; }
.prose code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .88em; background: var(--paper-deep); padding: 1px 5px; border-radius: 4px;
}
.prose .md-pre {
  background: var(--paper-deep); border-radius: 8px; padding: 12px 14px;
  overflow-x: auto; margin: 0 0 14px;
}
.prose .md-pre code { background: none; padding: 0; }
.prose .md-img {
  max-width: 100%; height: auto; display: block; margin: 6px 0 14px;
  border: var(--hairline); border-radius: 8px;
}


/* ==================================================================
   Event galleries
   ==================================================================
   A gallery is looked at, not read: square thumbs in an even grid,
   one tap to full screen, and nothing else competing for attention.
   Square rather than masonry on purpose — a phone grid that reflows
   as every image decodes is the thing that makes an album feel cheap.
   ------------------------------------------------------------------ */
.gal-back {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--sepia-faint); text-decoration: none;
  margin-bottom: 10px;
}
.gal-back:hover { color: var(--ink); }
.gal-head { align-items: flex-start; }
.gal-meta {
  display: flex; flex-wrap: wrap; gap: 6px 16px;
  font-size: 13px; color: var(--sepia-faint); margin-top: 2px;
}
.gal-meta span { display: inline-flex; align-items: center; gap: 5px; }
.gal-lead {
  margin: 10px 0 0; max-width: 62ch;
  font-family: var(--serif); font-size: 17px; color: var(--ink-soft);
}
.gal-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.gal-affects { margin: 4px 0 18px; }
.gal-affects .micro { display: block; margin-bottom: 6px; }

/* Masonry: thin rows, each tile spanning as many as its picture needs, so
   a portrait stays a portrait. The spans are set in JS from the stored
   pixel size (gallery.js, layoutMasonry) — CSS columns would do this in one
   line and would run the photos top to bottom, which is the wrong order for
   pictures in time order. */
.gal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  grid-auto-rows: 8px;
  gap: 10px;
  /* no align-items: start here — an item aligned to the start of its area
     is sized by its content, and then the row span it was given decides
     nothing at all */
}
.gal-tile {
  position: relative; padding: 0; margin: 0; cursor: zoom-in;
  border: var(--hairline); border-radius: 10px; overflow: hidden;
  background: var(--paper-deep);
  /* the height comes from the row span; before the spans are applied a
     tile is one row tall rather than zero */
  min-height: 8px;
  -webkit-tap-highlight-color: transparent;
}
.gal-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gal-tile:hover { border-color: var(--sand); }
.gal-tile:hover img { transform: scale(1.03); }
.gal-tile img { transition: transform .25s ease; }
.gal-tile:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }
.gal-cover-mark {
  position: absolute; top: 6px; right: 6px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--sand); color: var(--ink-deep);
  display: grid; place-items: center; font-size: 12px;
}
.gal-card-blank {
  display: grid; place-items: center; width: 100%; height: 100%;
  color: var(--sepia-faint); font-size: 30px; background: var(--paper-deep);
}
.kb-card-photo { position: relative; }
.gal-new {
  position: absolute; top: 8px; left: 8px;
  background: var(--brick); color: var(--paper-light);
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 20px;
}
.gal-page.gal-dragging { outline: 2px dashed var(--sand); outline-offset: -8px; }
.gal-progress { display: flex; align-items: center; gap: 12px; margin: 0 0 14px; }
.gal-progress-bar {
  flex: 1; height: 6px; border-radius: 6px; background: var(--paper-deep); overflow: hidden;
}
.gal-progress-bar span {
  display: block; height: 100%; background: var(--sand); transition: width .2s ease;
}

/* ---- the photo viewer (galleries and story photos alike) ---- */
.gal-viewer { flex-direction: row; }
.lb-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: calc(10px + var(--safe-t)) 14px 10px;
  background: linear-gradient(rgba(16, 27, 51, .75), rgba(16, 27, 51, 0));
}
.lb-bar-actions { display: flex; align-items: center; gap: 4px; }
.gal-viewer .lb-count { position: static; }
.lb-stage {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  max-width: 100%; will-change: transform;
}
.lb-stage figure { margin: 0; max-width: 92vw; max-height: 86vh; text-align: center; }
.lb-stage img {
  max-width: 92vw; max-height: 78vh; width: auto; height: auto;
  /* the box is reserved from the stored pixel size before the file arrives;
     contain keeps a stale w/h from stretching the picture */
  object-fit: contain; border-radius: 6px; background: rgba(244, 237, 218, .06);
}
/* the close button belongs in the bar with the other actions — the story
   lightbox pins it to the corner, which would drop it on top of them */
.gal-viewer .lb-close { position: static; top: auto; right: auto; }
/* .icon-btn sets a display, which outranks the hidden attribute: without
   this the owner-only actions would show to everyone (they would simply do
   nothing, the server refuses them, but the offer alone is a lie) */
.gal-viewer .icon-btn[hidden], .gal-viewer .lb-count[hidden] { display: none; }
/* the arrows sit over the picture, and the stage is painted after them */
.gal-viewer .lb-prev, .gal-viewer .lb-next { z-index: 2; }
.lb-caption-edit {
  display: flex; gap: 6px; align-items: center;
  margin-top: 12px; width: min(92vw, 520px);
}
.lb-caption-edit .input { flex: 1; }

/* ---- the nudge: a red dot on the section that grew ---- */
.nav-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--brick); box-shadow: 0 0 0 2px rgba(16, 27, 51, .25);
  margin-left: 5px; vertical-align: 2px; flex-shrink: 0;
}
/* the display above outranks the hidden attribute, and a dot on every
   section is worse than no dot at all */
.nav-dot[hidden] { display: none; }
.mm-icon { position: relative; }
.mm-icon .nav-dot { position: absolute; top: -2px; right: -4px; margin: 0; }
.filter-pill .nav-dot { box-shadow: none; }

/* ---- footer + viewer mode ---- */
/* The footer belongs at the bottom of the screen, not halfway up it after a
   short page. The body is exactly one viewport tall and the document
   scrolls, so a min-height on the content is all it takes — no flex layout,
   and nothing the sticky topbar or the fixed tree stage can notice. */
#main { min-height: calc(100vh - var(--topbar-total) - 74px); }
@supports (height: 100dvh) {
  #main { min-height: calc(100dvh - var(--topbar-total) - 74px); }
}
.app-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 14px max(18px, var(--safe-l)) calc(16px + var(--safe-b)) max(18px, var(--safe-r));
  border-top: var(--hairline);
  font-size: 12px; color: var(--sepia-faint);
}
.af-name { font-family: var(--serif); font-size: 13px; color: var(--ink-soft); }
.af-viewer {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--sand-faint); border: 1px solid var(--sand);
  color: var(--ink); border-radius: 20px; padding: 6px 14px;
  font-family: var(--sans); font-size: 12.5px; cursor: pointer;
}
.af-viewer:hover { background: var(--sand-bright); }
/* The tree covers the whole viewport (.tree-stage is fixed), so the footer
   has to float above it rather than sit after it. */
body:has(.tree-stage) .app-foot {
  position: fixed; left: 0; bottom: 0; z-index: 41;
  border-top: none; background: none; pointer-events: none;
  padding-bottom: calc(10px + var(--safe-b));
}
body:has(.tree-stage) .af-name { display: none; }
body:has(.tree-stage) .af-viewer {
  pointer-events: auto;
  background: rgba(250, 246, 234, .92);
  backdrop-filter: blur(8px);
}
.viewer-hint {
  display: inline-flex; align-items: flex-start; gap: 8px; text-align: left;
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--sepia-faint); font-family: var(--sans); font-size: 13px;
}
.viewer-hint:hover { color: var(--ink); }
.viewer-note {
  display: flex; gap: 9px; align-items: flex-start;
  background: var(--sand-faint); border: 1px solid var(--paper-deep);
  border-radius: 8px; padding: 10px 12px; margin: 16px 0 0;
  color: var(--sepia); line-height: 1.5;
}
.viewer-note .ph { color: var(--ink-soft); margin-top: 2px; }

/* ---- settings: the viewer share link ---- */
.vl-link {
  margin-top: 12px; padding: 10px 12px;
  background: var(--paper-deep); border-radius: 8px;
  font-size: 12.5px; word-break: break-all;
}
.vl-link code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* ------------------------------------------------------------------
   Mobile. The knowledge base is the part of the archive most likely to
   be read on a phone at a family gathering, so it is laid out for that
   width first and widened afterwards, not the other way round.
   ------------------------------------------------------------------ */
@media (max-width: 720px) {
  .md-panes { grid-template-columns: 1fr !important; }
  .md-preview { border-left: none; border-top: var(--hairline); }
  .lightbox { padding: 0; }
  .form-pair, .form-pair.wide-first { grid-template-columns: 1fr; }
  /* the panes are stacked from here down, so "Geteilt" has nothing to offer */
  .md-mode[data-mode="split"] { display: none; }
  /* our own spacer: the sheet's footer buttons share the row from here down
     (see "mobile: modals become bottom sheets"), so it must not push them */
  .foot-gap { display: none; }
}

@media (max-width: 640px) {
  /* Filter pills: a scrollable strip rather than four stacked rows that
     bury the content. Same pattern as the tree toolbar. */
  .kb-filters .pill-group {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* room so the last pill's border is not clipped mid-scroll */
    padding: 2px 2px 4px;
    margin: -2px -2px -4px;
  }
  .kb-filters .pill-group::-webkit-scrollbar { display: none; }
  .kb-filters { padding: 14px 16px; gap: 12px; }
  /* comfortable thumb targets: the desktop chips are ~26px tall */
  .kb-filters .filter-pill, .kb-tabs .filter-pill {
    flex-shrink: 0; white-space: nowrap; min-height: 38px; padding: 6px 14px;
  }
  .kb-tag { padding: 7px 14px; font-size: 13.5px; }
  .kb-shot { -webkit-tap-highlight-color: transparent; }

  /* Story cards become rows: the cover shrinks to a square thumbnail so
     several entries fit on screen instead of one hero image. */
  .kb-cards { grid-template-columns: 1fr; gap: 10px; }
  .kb-card { flex-direction: row; align-items: stretch; }
  .kb-card-photo { width: 104px; aspect-ratio: auto; flex-shrink: 0; }
  .kb-card-body { padding: 11px 13px; gap: 5px; min-width: 0; }
  .kb-card-title { font-size: 17px; }
  .kb-card-text {
    font-size: 13px;
    /* two lines is enough of a taste on a phone */
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .kb-card-meta { gap: 6px; }
  .kb-card-meta .micro { font-size: 10px; }
  /* medallions in a 104px-narrower card only add noise */
  .kb-card-people { display: none; }

  /* Glossary rows */
  .kb-term { padding: 12px 16px; }
  .kb-term dt { font-size: 17px; gap: 7px; }
  .kb-term dd { font-size: 13.5px; }

  /* Markdown editor */
  .md-toolbar { gap: 2px; padding: 5px 6px; }
  .md-tool { min-width: 34px; height: 32px; padding: 0 8px; }
  .md-src { min-height: 190px; }
  .md-hint { display: none; }


  /* Gallery + lightbox */
  .kb-gallery { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kb-shot figcaption { font-size: 11.5px; }
  .lightbox figure { max-width: 100vw; max-height: 100vh; }
  .lightbox img { max-height: 72vh; }
  /* controls float over the image edges instead of stealing width from it */
  .lightbox .lb-prev, .lightbox .lb-next {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 44px; height: 44px; justify-content: center;
    background: rgba(16, 27, 51, .55);
  }
  .lightbox .lb-prev { left: 8px; }
  .lightbox .lb-next { right: 8px; }
  .lightbox .lb-close, .lightbox .lb-prev, .lightbox .lb-next { min-width: 44px; min-height: 44px; }
  .lb-count { top: 26px; left: 16px; }
}

@media (max-width: 420px) {
  /* Anything narrower than an iPhone SE: give the text more of the card and
     shrink the thumbnail, and stop stacking photo editors two-up. */
  .kb-card-photo { width: 88px; }
  .kb-photo-row { grid-template-columns: 60px 1fr; }
  .kb-photo-row img, .kb-photo-row .kb-photo-new { width: 60px; height: 46px; }
}

@media print {
  .kb-tabs, .kb-filters, .md-editor, .lightbox { display: none !important; }
}


/* ---- galleries and the photo viewer on a phone ---- */
@media (max-width: 640px) {
  /* two columns rather than three: with the pictures at their own
     proportions, bigger tiles read better than more of them */
  .gal-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; grid-auto-rows: 6px; }
  .gal-tile { border-radius: 7px; min-height: 6px; }
  .gal-actions { width: 100%; }
  .gal-actions .btn { flex: 1; justify-content: center; }
  .gal-head h1 { font-size: 26px; }
  .gal-lead { font-size: 15px; }
  /* the picture gets the screen: controls float over its edges */
  .gal-viewer .lb-prev, .gal-viewer .lb-next {
    position: absolute; top: 50%; transform: translateY(-50%);
    background: rgba(16, 27, 51, .5);
  }
  .lb-stage figure { max-width: 100vw; max-height: 100vh; }
  .lb-stage img { max-width: 100vw; max-height: 74vh; border-radius: 0; }
  .app-foot { padding-top: 12px; font-size: 11.5px; }
  /* the Familienblatt keeps a fixed action bar at the bottom edge */
  body:has(.sh-actions) .app-foot { padding-bottom: calc(76px + var(--safe-b)); }
}

@media print {
  .app-foot, .gal-actions, .gal-back { display: none !important; }
}

/* ---------------- start page ---------------- */
/* Four blocks, each its own panel, each filled by its own request: what is
   new, what changed, the member's own entry, and the way on to everything
   else (see start.js). */
.start-page .start-block { margin-bottom: 18px; }
.start-h {
  display: flex; align-items: center; gap: 10px;
  font-size: 19px; margin: 0 0 14px;
}
.start-h .ph { font-size: 20px; color: var(--ink); flex-shrink: 0; }

/* Zuletzt bearbeitet and Mein Eintrag sit side by side where there is room.
   Below that they stack, and the feed comes first: it changes every day, the
   member's own entry rarely does. */
.start-cols {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 18px;
  align-items: start;
}
.start-cols .start-block { margin-bottom: 0; }

/* --- Was ist neu --- */
.start-news-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.start-news-card {
  display: flex; gap: 12px; align-items: center;
  padding: 10px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--paper-deep); border-radius: 12px;
  background: var(--paper);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.start-news-card:hover { border-color: var(--sand); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.start-news-shot {
  width: 56px; height: 56px; flex-shrink: 0;
  border-radius: 9px; overflow: hidden;
  background: var(--sand-faint);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 22px; color: var(--ink);
}
.start-news-shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.start-news-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.start-news-text .badge { align-self: flex-start; }
.start-news-text strong {
  font-family: var(--serif); font-weight: 400; font-size: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- Zuletzt bearbeitet --- */
.start-feed { list-style: none; margin: 0; padding: 0; }
.start-feed-item + .start-feed-item { border-top: var(--hairline); }
.start-feed-item > a, .start-feed-gone {
  display: flex; flex-direction: column; gap: 2px;
  padding: 9px 4px; text-decoration: none; color: var(--ink);
  border-radius: 8px;
}
.start-feed-item > a:hover { background: var(--sand-faint); }
.start-feed-gone { color: var(--sepia-faint); }
.start-feed-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.start-feed-line strong {
  font-family: var(--serif); font-weight: 400; font-size: 15.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- Mein Eintrag --- */
.start-me-card {
  display: flex; gap: 14px; align-items: center;
  text-decoration: none; color: var(--ink);
  padding: 4px 0 14px;
}
.start-me-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.start-me-text strong { font-family: var(--serif); font-weight: 400; font-size: 18px; }

.start-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.start-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px; border-radius: 20px;
  border: 1px solid var(--paper-deep); background: var(--paper);
  text-decoration: none; color: var(--ink); font-size: 13.5px;
}
.start-chip:hover { border-color: var(--sand); background: var(--paper-light); }
.start-chip .ph { font-size: 16px; }

/* --- Werkzeuge --- */
.start-tools {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.start-tool {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; text-decoration: none; color: var(--sepia);
  border: 1px solid var(--paper-deep); border-radius: 12px;
  background: var(--paper);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.start-tool:hover { border-color: var(--sand); background: var(--paper-light); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.start-tool-icon {
  position: relative;
  width: 36px; height: 36px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; font-size: 20px; color: var(--ink);
  background: var(--sand-faint); border: 1px solid rgba(217, 179, 108, .5);
}
.start-tool-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.start-tool-body strong { font-family: var(--serif); font-weight: 400; font-size: 16px; color: var(--ink); }
/* a sentence, not a label: .micro would set it in spaced capitals, which is
   fine for "HEUTE" and punishing for three lines of description */
.start-tool-desc { font-size: 12.5px; color: var(--sepia-faint); line-height: 1.45; }

@media (max-width: 860px) {
  /* one column: two panels side by side stop being two panels and start
     being two narrow strips */
  .start-cols { grid-template-columns: 1fr; }
  .start-cols .start-block { margin-bottom: 18px; }
}
@media (max-width: 640px) {
  .start-page .panel-pad { padding: 16px 16px; }
  .start-h { font-size: 17px; margin-bottom: 11px; }
  .start-news-grid { grid-template-columns: 1fr; }
  .start-tools { grid-template-columns: 1fr; }
}
