/* Layout: a header with the title and view tabs, one full-width view at a time,
   and a person panel that slides over from the right (a bottom sheet on phones).
   Two family halves get their own quiet tints; flags carry the color. */

@font-face { font-family: "Cormorant Garamond"; font-weight: 600; font-display: swap; src: url("vendor/fonts/cormorant-garamond-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Sans 3"; font-weight: 400; font-display: swap; src: url("vendor/fonts/source-sans-3-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Sans 3"; font-weight: 600; font-display: swap; src: url("vendor/fonts/source-sans-3-latin-600-normal.woff2") format("woff2"); }

:root {
  --bg: #eef1ef;
  --surface: #ffffff;
  --ink: #1d2826;
  --muted: #5b6965;
  --line: #a5b3ae;
  --accent: #2f6b55;
  --accent-ink: #ffffff;
  --danger: #a3322a;
  --waiting: #9a6a00;
  --backdrop-filter: none;
  --flag-fade: .1;
  /* Tree cards are black in both themes, so their text has its own light colours. */
  --card-bg: #000000;
  --card-ink: #f2f5f3;
  --card-muted: #a7b3ae;
  --card-accent: #79c2a3;
  --font-display: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --font-body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131a18; --surface: #1b2421; --ink: #e3ebe7; --muted: #9eaea8; --line: #5d6f69;
    --accent: #79c2a3; --accent-ink: #0f1a16;
    --danger: #ef8a7f; --waiting: #e3b44d;
    --backdrop-filter: brightness(.55) saturate(.85); --flag-fade: .09;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--font-body); }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(1.9rem, 4.5vw, 2.7rem); }
h2 { font-size: 1.6rem; }
h3 { font-size: 1.25rem; display: flex; align-items: center; gap: 10px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.flag-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 600; color: var(--accent); margin: 0 0 4px; }
.lede { color: var(--muted); max-width: 62ch; margin: 6px 0 16px; }
.fine { color: var(--muted); font-size: .875rem; }

/* ----- header ----- */
.masthead { background: var(--surface); padding: 20px 16px 0; box-shadow: 0 1px 0 rgb(0 0 0 / .04), 0 6px 18px rgb(0 0 0 / .04); }
.masthead-inner { max-width: 1280px; margin: 0 auto; display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; }
.admin-link { color: var(--accent); font-weight: 600; text-decoration: none; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; }
.tabs { max-width: 1280px; margin: 14px auto 0; display: flex; gap: 4px; overflow-x: auto; }
.tab { background: none; border: 0; padding: 10px 14px; border-radius: 8px 8px 0 0; color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap; }
.tab[aria-pressed="true"] { background: var(--bg); color: var(--ink); }
.tab .count:not(:empty) { display: inline-block; min-width: 1.5em; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .75rem; }

.page { max-width: 1280px; margin: 0 auto; padding: 20px 16px 64px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.page > * { min-width: 0; }
.notice { margin: 0; padding: 10px 14px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); }
.notice[data-tone="error"] { color: var(--danger); }
.origins-banner { margin: 0; height: clamp(110px, 17vw, 220px); border-radius: 12px; overflow: hidden; background: var(--surface); }
.origins-banner img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center 62%; filter: var(--backdrop-filter); }
.welcome { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; }
.welcome p { margin: 0 0 6px; max-width: 75ch; }

/* ----- buttons and chips ----- */
.button { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 14px; font-weight: 600; cursor: pointer; }
.button.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.button.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.button:disabled { opacity: .6; cursor: wait; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px 12px; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

/* ----- chart ----- */
.focus-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px 24px; }
.focus-bar .fine { margin: 4px 0 0; }
.focus-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.focus-controls label { font-weight: 600; font-size: .9rem; }
.search { position: relative; }
.search input { width: min(280px, 70vw); padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.matches { position: absolute; top: calc(100% + 4px); left: 0; right: 0; min-width: 260px; margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / .18); z-index: 5; }
.match { padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.match:hover, .match[aria-selected="true"] { background: var(--bg); color: var(--accent); }
.match.empty { color: var(--muted); cursor: default; }
.chart-scroller { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.related-panel { display: grid; gap: 12px; }
.related-panel h2 { font-size: 1.3rem; }
.related { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.related-group { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: grid; gap: 8px; align-content: start; }
.related-group .eyebrow { margin: 0; }
.painting { margin: 0; display: grid; gap: 12px; }
.painting img { display: block; width: 100%; height: auto; border-radius: 12px; border: 1px solid var(--line); }
.painting figcaption { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px 20px; color: var(--muted); font-size: .9rem; }
.chart { display: block; width: 100%; height: auto; margin: 0 auto; }
.connector { fill: none; stroke: var(--line); stroke-width: 1.6; }
.card { cursor: pointer; }
.leaving { pointer-events: none; }
.card-box { fill: var(--card-bg); stroke: var(--line); stroke-width: 1; }
.card-flag { opacity: var(--flag-fade); pointer-events: none; }
.avatar { pointer-events: none; }
.avatar-ground { fill: #1d2523; }
.avatar-figure { fill: #4d5c57; }
.avatar-ring { fill: none; stroke: var(--card-muted); stroke-width: 1.5; opacity: .6; }
.card-edge { fill: none; stroke: var(--line); stroke-width: 1; pointer-events: none; }
.card:hover .card-edge, .card:focus-visible .card-edge { stroke: var(--accent); stroke-width: 2; }
.card.focus .card-edge { stroke: var(--accent); stroke-width: 3; }
.card.focus .card-box { stroke: var(--accent); stroke-width: 3; }
.card.unnamed .card-box { stroke-dasharray: 5 4; }
.card.placeholder .card-box { fill: none; stroke-dasharray: 5 4; }
.card-add { font: 600 13px var(--font-body); fill: var(--accent); }
.card-more { font: 600 15px var(--font-body); fill: var(--card-accent); }
.card-info { cursor: pointer; }
.card-info-tab { fill: var(--line); opacity: .45; transition: opacity .15s, fill .15s; }
.card-info-icon { fill: var(--card-ink); pointer-events: none; }
.card-info:hover .card-info-tab, .card-info:focus-visible .card-info-tab { fill: var(--accent); opacity: 1; }
.card-info:hover .card-info-icon, .card-info:focus-visible .card-info-icon { fill: var(--accent-ink); }
.card-info:focus-visible { outline: none; }
.card:hover .card-box, .card:focus-visible .card-box { stroke: var(--accent); stroke-width: 2; }
.card:focus-visible { outline: none; }
.card-name { font: 600 13.5px var(--font-body); fill: var(--card-ink); }
.card.sibling .card-name { font-size: 12px; }
.group-caption { font: italic 11.5px var(--font-body); fill: var(--muted); }
.card-detail { font: 12px var(--font-body); fill: var(--card-muted); }
.card.placeholder .card-detail { fill: var(--muted); }
.unplaced { display: grid; gap: 8px; }



/* ----- questions ----- */
.questions-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 32px; }
.questions { margin: 0; padding-left: 22px; display: grid; gap: 6px; }
.question { background: none; border: 0; padding: 4px 0; text-align: left; cursor: pointer; color: var(--ink); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; }
.question:hover { text-decoration-color: var(--accent); }
.mine { list-style: none; margin: 10px 0 16px; padding: 0; display: grid; gap: 8px; }
.status { display: inline-block; font-size: .75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; border: 1px solid currentColor; }
.status-pending { color: var(--waiting); }
.status-approved { color: var(--accent); }
.status-rejected { color: var(--muted); }

/* ----- person panel ----- */
.person-panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(420px, 100%); background: var(--surface); box-shadow: -8px 0 30px rgb(0 0 0 / .18); padding: calc(20px + env(safe-area-inset-top, 0px)) 22px calc(28px + env(safe-area-inset-bottom, 0px)); overflow-y: auto; z-index: 10; }
.person-panel h2 { margin-bottom: 6px; }
.close { position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); right: 12px; background: none; border: 0; font-size: 1.8rem; line-height: 1; cursor: pointer; color: var(--muted); }
.nickname { margin: 0 0 4px; font-style: italic; }
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 14px; margin: 14px 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.note { white-space: pre-line; }
.relation { margin: 14px 0; }
.stories blockquote { margin: 10px 0; padding: 10px 14px; background: var(--bg); border-radius: 8px; }
.stories blockquote p { margin: 0 0 4px; white-space: pre-line; }
.stories footer { color: var(--muted); font-size: .85rem; }
.panel-photo { display: block; width: 112px; height: 112px; object-fit: cover; border-radius: 50%; margin: 0 0 12px; border: 2px solid var(--line); }
.story-photo { margin: 0; display: grid; gap: 4px; justify-items: start; font-size: .8rem; }
.story-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; margin: 6px 0; }
.story-photos img, .photo-thumbs img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
.photo-thumbs { list-style: none; margin: 4px 0 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 96px)); gap: 6px; }
.photo-thumbs:empty { display: none; }
.pending-note { color: var(--waiting); font-size: .9rem; }
.panel-actions { display: grid; gap: 8px; margin-top: 18px; }
.panel-actions .button { width: 100%; }

/* ----- form dialog ----- */
.form-dialog { width: min(680px, calc(100% - 24px)); max-height: calc(100% - 24px); border: 1px solid var(--line); border-radius: 12px; padding: 22px; background: var(--surface); color: var(--ink); }
.form-dialog::backdrop { background: rgb(0 0 0 / .45); }
.form-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field.check { display: flex; align-items: center; gap: 8px; align-self: end; }
.field label { font-weight: 600; font-size: .9rem; }
.field input[type="text"], .field select, .field textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.hint { color: var(--muted); font-size: .8rem; }
.form-error { color: var(--danger); margin: 12px 0 0; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

@media (max-width: 720px) {
  .questions-layout, .form-fields { grid-template-columns: minmax(0, 1fr); }
  .person-panel { top: auto; max-height: 82vh; border-radius: 14px 14px 0 0; width: 100%; box-shadow: 0 -8px 30px rgb(0 0 0 / .18); }
}
