:root {
  --accent: #2F5D4A;
  --ground: #F6F4EF;
  --surface: #FFFFFF;
  --surface-2: #FBFAF7;
  --ink: #1F2A24;
  --ink-2: #2E3832;
  --muted: #4A544E;
  --muted-2: #5C665F;
  --line: #DDD8CC;
  --line-2: #ECE8DE;
  --line-strong: #CFC9BB;
  --connector: #A9A293;
  --ochre: #8A5A14;
  --chip: #F1EEE6;
  --sel-bg: #EEF4F0;
  --serif: 'Lora', Georgia, serif;
  --sans: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.5; }
a { color: var(--accent); }
a:hover { filter: brightness(.8); }
button { font: inherit; cursor: pointer; color: inherit; }
img { max-width: 100%; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.wrap { max-width: 1360px; margin: 0 auto; padding-left: 24px; padding-right: 24px; }
@media (max-width: 600px) { .wrap { padding-left: 16px; padding-right: 16px; } }

/* ---------- nagłówek ---------- */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.header-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 32px; padding-top: 14px; padding-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand svg { color: var(--accent); }
.brand span { font-family: var(--serif); font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
.main-nav { display: flex; flex-wrap: wrap; gap: 4px 24px; flex: 1 1 auto; }
.main-nav button { background: none; border: 0; padding: 10px 0; min-height: 44px; color: var(--muted); border-bottom: 2px solid transparent; }
.main-nav button.is-active { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line-strong); border-radius: 8px; padding: 0 12px; background: var(--surface-2); min-width: 220px; color: var(--muted-2); }
.search input { border: 0; background: transparent; height: 44px; font: inherit; color: var(--ink); outline: none; flex: 1; min-width: 0; }
.search:focus-within { outline: 3px solid var(--accent); outline-offset: 1px; }
@media (max-width: 700px) { .search { flex: 1 1 100%; } }

/* ---------- hero ---------- */
.hero { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 24px; padding-top: 40px; padding-bottom: 24px; }
.hero-text { display: flex; flex-direction: column; gap: 8px; }
.eyebrow { font-size: 14px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ochre); }
.hero h1 { margin: 0; font-family: var(--serif); font-size: clamp(32px, 5vw, 44px); line-height: 1.1; font-weight: 600; letter-spacing: -0.01em; }
.hero p { margin: 0; color: var(--muted); max-width: 640px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; }

.btn { height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 600; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn:hover { filter: brightness(.96); }
.icon-btn { width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); display: inline-flex; align-items: center; justify-content: center; color: var(--ink); }

/* ---------- układ ---------- */
.layout { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; padding-bottom: 48px; }
.board { flex: 999 1 640px; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.board-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line-2); font-size: 14px; color: var(--muted); }
.zoom { display: flex; gap: 4px; }

/* ---------- drzewo ---------- */
.tree-scroll { overflow: auto; max-height: min(78vh, 900px); background-color: var(--surface-2); background-image: radial-gradient(#E4DFD3 1px, transparent 1px); background-size: 20px 20px; cursor: grab; }
.tree-scroll.dragging { cursor: grabbing; user-select: none; }
.tree-sizer { position: relative; margin: 0 auto; }
.tree-stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.tree-stage svg { position: absolute; left: 0; top: 0; overflow: visible; }
.tree-stage path { fill: none; stroke: var(--connector); stroke-width: 2; }

.card { position: absolute; width: 212px; height: 96px; display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px; text-align: left; background: var(--surface); border: 1px solid var(--line-strong); box-shadow: 0 1px 2px rgba(31,42,36,.06); transition: box-shadow .15s, border-color .15s; }
.card:hover { border-color: var(--accent); }
.card.is-selected { background: var(--sel-bg); border: 2px solid var(--accent); padding: 11px 13px; box-shadow: 0 6px 18px rgba(31,42,36,.14); }
.card.is-match { box-shadow: 0 0 0 4px #F2C46D; }
.card.is-dup { border-style: dashed; background: var(--surface-2); }
.av { flex: none; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-family: var(--serif); font-weight: 600; font-size: 15px; background: var(--chip); color: var(--ink-2); overflow: hidden; }
.av img { width: 100%; height: 100%; object-fit: cover; }
.card.is-selected .av { background: var(--accent); color: #fff; }
.c-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.c-name { font-family: var(--serif); font-weight: 600; font-size: 16px; line-height: 1.25; color: var(--ink); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.c-years { font-size: 14px; color: var(--muted); }
.c-sub { font-size: 13px; color: var(--muted-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gen-label { position: absolute; font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ochre); white-space: nowrap; }

/* ---------- panel ---------- */
.panel { flex: 1 1 320px; min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.p-head { display: flex; align-items: center; gap: 16px; }
.p-av { width: 72px; height: 72px; border-radius: 50%; background: #E7EFEA; color: #1E3F31; display: flex; align-items: center; justify-content: center; font-family: var(--serif); font-size: 26px; font-weight: 600; flex: none; overflow: hidden; }
.p-av img { width: 100%; height: 100%; object-fit: cover; }
.p-head h2 { margin: 0; font-family: var(--serif); font-size: 24px; line-height: 1.2; font-weight: 600; }
.p-head .p-years { color: var(--muted); }
.p-facts { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.p-facts dt { font-size: 13px; color: var(--muted-2); }
.p-facts dd { margin: 0; font-weight: 600; }
.p-sec { display: flex; flex-direction: column; gap: 8px; }
.p-sec h3 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ochre); }
.p-bio { margin: 0; color: var(--ink-2); white-space: pre-line; }
.p-note { margin: 0; padding: 12px 14px; border-radius: 8px; background: var(--chip); color: var(--ink-2); font-size: 15px; }
.rel { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 8px 0; border: 0; border-top: 1px solid var(--line-2); background: none; text-align: left; }
.rel:hover .rel-name { color: var(--accent); text-decoration: underline; }
.rel-role { color: var(--muted-2); font-size: 14px; }
.p-photos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.p-photos button { padding: 0; border: 0; border-radius: 6px; overflow: hidden; aspect-ratio: 1; background: var(--line-2); }
.p-photos img { width: 100%; height: 100%; object-fit: cover; }
.p-empty { color: var(--muted-2); font-size: 14px; margin: 0; }

/* ---------- oś czasu ---------- */
#view-timeline, #view-list { padding: 24px; }
.tl-decade { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 16px; padding: 16px 0; border-top: 1px solid var(--line-2); }
.tl-decade:first-child { border-top: 0; }
.tl-decade h3 { margin: 0; font-family: var(--serif); font-size: 22px; font-weight: 600; }
.tl-decade ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.tl-ev { display: flex; gap: 12px; align-items: baseline; }
.tl-year { flex: none; width: 44px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.tl-kind { flex: none; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; padding: 1px 8px; border-radius: 99px; background: var(--chip); color: var(--ink-2); }
.tl-kind.k-birth { background: #E3EEE8; color: #1E3F31; }
.tl-kind.k-union { background: #F6EBD7; color: #6B4510; }
.tl-kind.k-death { background: #E9E6EF; color: #3E3550; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-align: left; }
@media (max-width: 600px) { .tl-decade { grid-template-columns: 1fr; gap: 8px; } }

/* ---------- lista ---------- */
.table-box { overflow-x: auto; }
.ptable { width: 100%; border-collapse: collapse; font-size: 15px; }
.ptable th { text-align: left; font-size: 13px; font-weight: 600; color: var(--muted-2); padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ptable th button { background: none; border: 0; padding: 0; font-weight: 600; color: inherit; }
.ptable td { padding: 6px 12px; border-bottom: 1px solid var(--line-2); }
.ptable tr.is-selected td { background: var(--sel-bg); }
.empty-state { padding: 48px 24px; text-align: center; color: var(--muted); }

/* ---------- stopka ---------- */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); }
.footer-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; padding-top: 24px; padding-bottom: 24px; font-size: 14px; color: var(--muted); }

/* ---------- lightbox ---------- */
.lightbox { border: 0; border-radius: 12px; padding: 16px; max-width: min(92vw, 1100px); background: var(--surface); }
.lightbox::backdrop { background: rgba(20, 24, 22, .8); }
.lightbox form { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.lightbox img { max-height: 78vh; margin: 0 auto; border-radius: 6px; }
.lightbox p { margin: 10px 0 0; color: var(--muted); text-align: center; }

/* ---------- druk ---------- */
@media print {
  @page { size: landscape; margin: 10mm; }
  body { background: #fff; }
  .site-header, .hero-actions, .board-bar, .panel, .site-footer, .main-nav { display: none !important; }
  .board { border: 0; }
  .tree-scroll { max-height: none; overflow: visible; background: none; }
  .card { box-shadow: none !important; }
  .card.is-selected { background: #fff; border-width: 1px; padding: 12px 14px; }
}
