:root {
  --border: #888;
  --line: #444;
  --plus: #e00000;
  --text: #000;
  --muted: #555;
  --bg: #fff;
  --ui: #f3f3f3;
  --accent: #2f5d8a;
  --block-w: 300px;
  --block-h: 90px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;                /* telefony: bez chowania pod paskiem przeglądarki */
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}

body { display: flex; flex-direction: column; }

/* ---------- Pasek narzędzi ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  border-bottom: 1px solid #ddd;
  background: var(--ui);
  flex-wrap: wrap;
}
.toolbar h1 { font-size: 18px; margin: 0; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; }
.toolbar label.select { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.toolbar select { font: inherit; font-size: 14px; padding: 4px 6px; border: 1px solid #bbb; border-radius: 4px; background: #fff; }

/* pasek drzewa: [‹] nazwa [znaczek] … komunikat … [tryb] [warstwy] [użytkownik] */
.tree-bar { flex-wrap: nowrap; }
.tree-bar h1 { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-bar .vis-badge, .tree-bar #backBtn { flex: none; }
/* kilka drzew konta: nazwa drzewa jako lista rozwijana */
#treeTitle[hidden], .tree-select[hidden] { display: none; }
.toolbar .tree-select {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  font: inherit;
  font-size: 18px;
  font-weight: bold;
  color: inherit;
  padding: 4px 30px 4px 6px;
  margin-left: -6px;              /* tekst w tym samym miejscu co zwykła nazwa */
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23555' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") right 8px center / 16px no-repeat;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  text-overflow: ellipsis;
}
.toolbar .tree-select:hover, .toolbar .tree-select:focus-visible { border-color: #bbb; background-color: #fff; }
.tree-select option { font-weight: normal; }
.bar-right { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex: 1 1 auto; }
.bar-right .vis-badge { margin-right: auto; }   /* znaczek przy nazwie, przyciski do prawej */
.tb-btn, .icon-btn { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.icon-btn { padding: 5px 8px; }
.tb-btn[hidden], .icon-btn[hidden] { display: none; }
.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tb-btn[aria-pressed="true"], .tb-btn[aria-expanded="true"] { background: #dde7f1; border-color: var(--accent); }
#modeBtn[aria-pressed="true"] { background: #fff4e0; border-color: #d9a441; }   /* tryb edycji wyróżniony */
.mode-view .edit-only { display: none; }
.mode-view .person { cursor: pointer; }

button, .btn {
  font: inherit;
  font-size: 14px;
  padding: 5px 12px;
  border: 1px solid #bbb;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  display: inline-block;
}
button:hover, .btn:hover { background: #eaeaea; }
button:focus-visible, .btn:focus-within, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #244a6f; }
button[aria-pressed="true"] { background: #dde7f1; border-color: var(--accent); }
button.danger { color: #b00; border-color: #d99; }

/* ---------- Obszar drzewa ---------- */
#viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
#viewport.dragging { cursor: grabbing; }
/* przesuwanie drzewa myszą nie może zaznaczać tekstu w blokach */
#viewport { user-select: none; -webkit-user-select: none; }
#viewport #layers, #viewport #settingsPanel { user-select: text; -webkit-user-select: text; }

#canvas {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}
#canvas svg.lines {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}
#canvas svg.lines path {
  fill: none;
  stroke-width: 2;
}
/* --layer-op: krycie z panelu warstw (1 = włączona, 0–1 = wyłączona) */
#canvas svg.lines g { opacity: var(--layer-op, 1); transition: opacity 0.15s; }
#canvas svg.lines.focus g { opacity: calc(var(--layer-op, 1) * 0.12); }
#canvas svg.lines.focus g.active { opacity: 1; }
#canvas svg.lines g.active path { stroke-width: 3.5; }
#canvas .person { opacity: var(--layer-op, 1); transition: opacity 0.15s; }
#canvas .plus { opacity: var(--layer-op, 1); }
#canvas.focusing .person.dim { opacity: calc(var(--layer-op, 1) * 0.3); }
#canvas.focusing .person:not(.dim) { opacity: 1; }
#canvas.focusing .plus { opacity: calc(var(--layer-op, 1) * 0.25); }
#canvas .ghost { pointer-events: none; }

#empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  cursor: default;
}
#empty[hidden] { display: none; }

/* ---------- Blok osoby ---------- */
.person {
  position: absolute;
  width: var(--block-w);
  height: var(--block-h);
  display: flex;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}
.person:hover { box-shadow: 0 0 0 2px #bcd; }
.person .photo {
  /* kwadrat na całą wysokość bloku: (wysokość − 2 px ramki) + 1 px kreski z prawej */
  width: calc(var(--block-h) - 1px);
  height: calc(var(--block-h) - 2px);
  flex: none;
  object-fit: cover;
  border-right: 1px solid var(--border);
  display: block;
}
.person .info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.person .name {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 0 8px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
/* szerokość bloku jest dobierana w app.js (updateBlockSize) tak, by nazwisko mieściło się w linii */
.person .name .full {
  font-size: 20px;
  font-weight: bold;
  line-height: 1.2;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.person .name .maiden {
  font-size: 16px;
  line-height: 1.2;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.person .name .maiden, .details .maiden { font-weight: normal; color: #333; }
.person .meta { display: flex; height: 30px; font-size: 15px; line-height: 29px; }
.person .date {
  flex: 1;
  min-width: 0;
  text-align: right;
  padding: 0 8px;
  border-right: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.person .age { width: 80px; flex: none; padding: 0 6px; white-space: nowrap; text-align: center; }
.person.deceased .photo { filter: grayscale(0.6); }

/* ---------- Przeciąganie ---------- */
.person { touch-action: none; }
.person.dragging {
  z-index: 10;
  cursor: grabbing;
  opacity: 0.85 !important;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}
.person.no-drop { outline: 2px solid #c00; outline-offset: 2px; }
.person.drop-swap { outline: 3px dashed var(--accent); outline-offset: 3px; }
.drop-indicator {
  position: absolute;
  width: 4px;
  height: calc(var(--block-h) + 20px);
  background: var(--accent);
  border-radius: 2px;
  z-index: 9;
  pointer-events: none;
}
#canvas.drag-active .plus { visibility: hidden; }

/* ---------- Czerwone plusy ---------- */
.plus {
  position: absolute;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--plus);
  font-size: 26px;
  font-weight: bold;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  z-index: 2;
}
.plus:hover { background: transparent; transform: scale(1.35); }

/* ---------- Panel warstw ---------- */
#layers, #settingsPanel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(340px, 90vw);
  background: #fff;
  border-left: 1px solid #ccc;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.08);
  z-index: 5;
  display: flex;
  flex-direction: column;
  cursor: default;
}
#layers[hidden], #settingsPanel[hidden] { display: none; }
.layers-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 4px; }
.layers-head h2 { margin: 0; font-size: 17px; }
/* [x] zamykający panele (warstwy, ustawienia): czerwony krzyżyk i obwódka, bez wypełnienia */
button.icon {
  font-size: 20px; line-height: 1; padding: 2px 9px;
  background: #fff; border: 1px solid #d93025; color: #d93025; border-radius: 6px;
}
button.icon:hover { background: #fdecea; color: #b3261e; border-color: #b3261e; }
.layers-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 10px; border-bottom: 1px solid #e3e3e3; }
.layers-actions button { font-size: 13px; padding: 4px 9px; }
#layersList { list-style: none; margin: 0; padding: 6px 0; overflow-y: auto; flex: 0 1 auto; min-height: 0; }   /* [Ustawienia domyślne] zaraz pod rodzinami */
#layersList li {
  padding: 6px 14px 8px;
  border-left: 3px solid transparent;
}
.layer-row { display: flex; align-items: center; gap: 8px; }
/* główna linia: zamiast wyboru koloru – próbka koloru ramki motywu */
.main-swatch { flex: none; width: 30px; height: 24px; border-radius: 3px; border: 1px solid rgba(0, 0, 0, 0.25); }
.layer-op {
  display: grid;
  grid-template-columns: 1fr 42px;
  align-items: center;
  column-gap: 8px;
  margin: 4px 0 0 24px;
  font-size: 12px;
  color: var(--muted);
}
.layer-op span { grid-column: 1 / -1; }
.layer-op input[type="range"] { width: 100%; margin: 0; accent-color: var(--accent); }
.layer-op output { text-align: right; font-variant-numeric: tabular-nums; }
#layersList li.off .layer-op { display: none; }   /* ukryta warstwa – bez suwaka krycia */
#layersList li:hover, #layersList li.active { background: #f2f6fa; border-left-color: var(--accent); }
#layersList li.off .layer-name span { color: var(--muted); }
#layersList li.empty { color: var(--muted); font-size: 14px; }
#layersList input[type="checkbox"] { width: 16px; height: 16px; margin: 0; flex: none; }
#layersList input[type="color"] {
  width: 30px;
  height: 24px;
  padding: 1px;
  border: 1px solid #bbb;
  border-radius: 3px;
  background: #fff;
  flex: none;
  cursor: pointer;
}
.layer-name {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 2px 0;
  display: flex;
  flex-direction: column;
}
.layer-name:hover { background: transparent; }
.layer-name span { font-size: 14px; font-weight: bold; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer-name small { font-size: 12px; color: var(--muted); }

/* ---------- Okno formularza ---------- */
dialog {
  overflow: auto;
  border: 1px solid #aaa;
  border-radius: 6px;
  padding: 20px;
  width: min(640px, 94vw);
  max-height: 92vh;
  max-height: 92dvh;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
.sections { display: flex; flex-direction: column; gap: 14px; }
fieldset {
  border: 1px solid #ccc;
  border-radius: 4px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  padding: 10px 14px 14px;
}
legend { font-weight: bold; padding: 0 4px; }
fieldset label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
fieldset label.wide { grid-column: 1 / -1; }
fieldset label.check { flex-direction: row; align-items: center; gap: 6px; }
fieldset label[hidden] { display: none; }

/* pole zdjęcia w formularzu */
.photo-field {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px;
  border: 1px dashed transparent;
  border-radius: 4px;
}
.photo-field.drop { border-color: var(--accent); background: #f2f6fa; }
.photo-preview { width: 84px; height: 84px; object-fit: cover; border: 1px solid var(--border); flex: none; }
.photo-field.changed .photo-preview { outline: 2px solid var(--accent); outline-offset: 2px; }
.photo-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.photo-actions small { font-size: 12px; color: var(--muted); line-height: 1.4; }
.photo-actions .check { font-size: 13px; color: var(--text); }
fieldset input, fieldset select, fieldset textarea {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  padding: 5px 7px;
  border: 1px solid #bbb;
  border-radius: 3px;
}
fieldset textarea { min-height: 60px; resize: vertical; }
.buttons { display: flex; gap: 8px; margin-top: 16px; }
.buttons .spacer { flex: 1; }

@media (max-width: 560px) {
  fieldset { grid-template-columns: 1fr; }
  .toolbar h1 { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  #canvas svg.lines g, #canvas .person { transition: none; }
}

/* ---------- Logowanie i karta osoby ---------- */
.auth-form { width: min(380px, 100%); }
dialog:has(.auth-form) { width: min(420px, 94vw); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.stack input { font: inherit; font-size: 15px; color: var(--text); padding: 6px 8px; border: 1px solid #bbb; border-radius: 3px; }
.form-hint { margin: 0 0 14px; font-size: 14px; color: var(--muted); line-height: 1.45; }
.form-error { margin: 12px 0 0; color: #b00; font-size: 14px; }
.form-error[hidden] { display: none; }

/* karta postaci – wygląd bloku i tła bierze z motywu; panel szczegółów motyw może ostylować (.card-details) */
dialog.person-card { width: min(640px, 94vw); padding: 34px 28px 28px; border-color: rgba(0, 0, 0, 0.25); }
.card-block { position: relative; margin: 14px auto 26px; }
.card-block .person {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  cursor: default;
}
/* w karcie blok nie jest klikalny – bez efektów po najechaniu (także tych z motywów) */
.card-block .person { pointer-events: none; }
/* [x] w prawym górnym rogu karty – kolory i kształt ustawia motyw zmiennymi --card-x-* */
.card-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  background: var(--card-x-bg, #fff);
  color: var(--card-x-fg, #333);
  border: var(--card-x-border-w, 1px) solid var(--card-x-border, rgba(0, 0, 0, 0.3));
  border-radius: var(--card-x-radius, 50%);
  box-shadow: var(--card-x-shadow, 0 1px 3px rgba(0, 0, 0, 0.2));
  cursor: pointer;
  transition: transform 0.15s, filter 0.15s;
}
.card-close svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }
.card-close:hover { transform: scale(1.08); filter: brightness(1.12); }
.card-close:focus-visible { outline: 2px solid var(--card-x-border, #4a6fa5); outline-offset: 2px; }
.card-details {
  background: rgba(255, 255, 255, 0.94);
  color: #222;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 6px;
  padding: 16px 20px;
}
.card-details dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; margin: 0; font-size: 15px; line-height: 1.4; }
.card-details dt { color: #666; }
.card-details dd { margin: 0; }
.card-details .details-notes { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid rgba(0, 0, 0, 0.12); white-space: pre-wrap; line-height: 1.5; }
.card-details .card-empty { margin: 0; color: #666; }
dialog.person-card .buttons { margin-top: 16px; }
}

/* ---------- Kadrowanie zdjęcia ---------- */
.crop-dialog { width: min(400px, 94vw); }
.crop-stage {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  border-radius: 4px;
  cursor: grab;
  touch-action: none;
}
.crop-stage.grabbing { cursor: grabbing; }
.crop-stage:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.crop-zoom { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.crop-zoom input { flex: 1; accent-color: var(--accent); }

/* ---------- Ekrany ---------- */
#treeScreen { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#treeScreen[hidden], #home[hidden] { display: none; }
#home { flex: 1; overflow-y: auto; }

.vis-badge { font-size: 12px; padding: 2px 8px; border-radius: 10px; border: 1px solid; }
.vis-badge[hidden] { display: none; }
.vis-badge.public { color: #2a6a35; border-color: #9cc9a4; background: #eef7f0; }
.vis-badge.private { color: #7a4a00; border-color: #e0bf86; background: #fbf4e6; }

/* ---------- Lista drzew ---------- */
.home-bar { justify-content: space-between; }
.home-body { max-width: 860px; margin: 0 auto; padding: 28px 20px 60px; }
.home-intro { margin: 0 0 18px; color: var(--muted); line-height: 1.5; }
.tree-empty { color: var(--muted); }
.tree-empty p { margin: 0 0 12px; }
.table-wrap { overflow-x: auto; }
.tree-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.tree-table th {
  text-align: left;
  font-size: 13px;
  font-weight: normal;
  color: var(--muted);
  padding: 8px 12px;
  border-bottom: 2px solid #ccc;
}
.tree-table td { padding: 10px 12px; border-bottom: 1px solid #e3e3e3; vertical-align: middle; }
.tree-table tbody tr:hover { background: #f6f8fa; }
.tree-table .t-name a { color: var(--text); font-weight: bold; text-decoration: none; }
.tree-table .t-name a:hover { color: var(--accent); text-decoration: underline; }
.tree-table .t-count { text-align: right; font-variant-numeric: tabular-nums; width: 80px; }
.tree-table .t-login { width: 150px; white-space: nowrap; }
.tree-table .t-login button { font-size: 13px; padding: 3px 10px; }
.tree-table .who::before { content: "✓ "; color: #2a6a35; }
.tree-table .muted { color: var(--muted); }

/* wybór widoczności w formularzach */
.vis-choice { display: flex; flex-direction: column; gap: 8px; border: 0; padding: 0; margin: 0; }
.vis-choice legend { font-size: 13px; color: var(--muted); font-weight: normal; padding: 0; margin-bottom: 6px; }
.vis-choice .radio {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text);
}
.vis-choice .radio:has(input:checked) { border-color: var(--accent); background: #f2f6fa; }
.vis-choice .radio input { margin-top: 3px; }
.vis-choice .radio span { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.vis-choice .radio small { color: var(--muted); font-size: 12.5px; }
.form-hint code { font-size: 13px; background: #f1f1f1; padding: 1px 4px; border-radius: 3px; }
.stack .form-hint { margin: 0; }

/* główna linia w panelu warstw */
.main-toggle {
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: #aaa;
}
.main-toggle:hover { color: #c98a00; background: #fbf4e6; }
.main-toggle[aria-pressed="true"] { color: #c98a00; }
#layersList li.main { background: #fdf8ec; border-left-color: #c98a00; }
#layersList li.main:hover, #layersList li.main.active { background: #faf1dc; }
.main-toggle:disabled { cursor: default; background: transparent; }
.main-toggle:disabled:not([aria-pressed="true"]) { color: #d4d4d4; }
.main-toggle:disabled:hover { background: transparent; }
.main-line-hint { margin: 10px 14px 0; font-size: 12.5px; color: #7a4a00; background: #fbf4e6; border: 1px solid #e0bf86; border-radius: 4px; padding: 6px 8px; line-height: 1.4; }
.main-line-hint[hidden] { display: none; }
#layersList input[type="color"]:disabled { cursor: not-allowed; opacity: 1; }
.photo-field.busy { opacity: 0.6; pointer-events: none; }
.photo-field.busy .photo-actions::after { content: "Konwertowanie…"; font-size: 12px; color: var(--accent); }

/* wybór motywu w ustawieniach drzewa */
.theme-select { font: inherit; font-size: 15px; color: var(--text); padding: 6px 8px; border: 1px solid #bbb; border-radius: 3px; background: #fff; }
/* w trybie Ręcznie blok można chwycić i przeciągnąć */
body.order-manual.mode-edit .person { cursor: grab; }

/* ================= Responsywność ================= */

/* komputer: menu narzędzi rozłożone w pasku (kontener „znika” z układu) */

/* dotyk: większy obszar trafienia dla plusów i przycisków */
@media (pointer: coarse) {
  .plus::before { content: ""; position: absolute; inset: -10px; }
  button, .btn, .toolbar select { min-height: 38px; }
  .main-toggle { min-height: 0; }
  #layersList input[type="checkbox"] { width: 20px; height: 20px; }
}

/* tablet */
@media (max-width: 1100px) {
  .toolbar { gap: 10px; padding: 8px 12px; }
  .toolbar h1 { font-size: 17px; }
}

/* telefon */
@media (max-width: 760px) {
  .toolbar { gap: 8px; padding: 6px 10px; }
  .toolbar h1 { font-size: 16px; }
  .home-bar h1 { font-size: 17px; }
  /* na telefonie same ikony */
  .tb-btn .btn-text { display: none; }
  .tb-btn, .icon-btn { padding: 0; width: 40px; height: 40px; justify-content: center; }
  .ico { width: 20px; height: 20px; }


  /* panel warstw na całą szerokość */
  #layers, #settingsPanel { width: 100%; }

  /* okna dialogowe */
  dialog { padding: 16px; width: 96vw; }
  dialog.person-card { padding: 40px 12px 14px; width: 96vw; }
  .card-details { padding: 12px 14px; }
  .card-details dl { grid-template-columns: 1fr; gap: 2px; }
  .card-details dt { margin-top: 8px; font-size: 13px; }

  /* lista drzew */
  .home-body { padding: 18px 12px 40px; }
  .tree-table { font-size: 14px; }
  .tree-table th, .tree-table td { padding: 8px 6px; }
  .tree-table .t-count { width: auto; }
  .tree-table .t-login { width: auto; }
}

/* bardzo wąskie telefony */
@media (max-width: 400px) {
  .tree-table th:nth-child(2), .tree-table td:nth-child(2) { display: none; }  /* liczba osób – widać ją po wejściu */
}
#layersList .layer-op input[type="range"]:disabled { opacity: 0.5; cursor: not-allowed; }

/* związki w oknie edycji osoby */
fieldset.unions { grid-template-columns: 1fr; gap: 8px; }
fieldset.unions label.check { color: var(--text); font-size: 14px; }
.unions-hint { font-size: 12px; color: var(--muted); line-height: 1.4; }
.card-details .divorced { opacity: 0.7; font-size: 0.9em; }

/* panel konta i ustawień drzewa */
#settingsPanel { overflow-y: auto; }
#settingsPanel .layers-head h2 { display: flex; align-items: center; gap: 8px; }
.sp-account { display: flex; gap: 8px; padding: 4px 14px 14px; border-bottom: 1px solid #e3e3e3; }
.sp-account button { flex: 1; }
.sp-form { display: flex; flex-direction: column; gap: 14px; padding: 14px; }
.sp-form h3 { margin: 0; font-size: 15px; }
.sp-form > label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.sp-form input:not([type]), .sp-form input[type="text"], .sp-form select {
  font: inherit; font-size: 15px; color: var(--text); padding: 6px 8px; border: 1px solid #bbb; border-radius: 3px; background: #fff;
}
.sp-io { display: flex; gap: 8px; }
.sp-io > * { flex: 1; text-align: center; }
.sp-form .buttons { margin-top: 4px; }
.sp-form .form-error { margin: 0; }

/* wybór języka na stronie głównej */
.home-actions { display: flex; align-items: center; gap: 10px; }
.lang-select { font: inherit; font-size: 14px; font-weight: bold; padding: 5px 6px; border: 1px solid #bbb; border-radius: 4px; background: #fff; color: var(--text); }
@media (pointer: coarse) { .lang-select { min-height: 38px; } }

/* panel ustawień: etykieta i lista w jednej linii, nazwa pogrubiona */
.sp-form > label.sp-row {
  display: grid;
  grid-template-columns: 64px 1fr;     /* stała szerokość etykiety – listy równo i na całą resztę */
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text);
}
.sp-form > label.sp-row select { width: 100%; min-width: 0; }
.sp-form > label.sp-name b { font-size: 14px; color: var(--text); }
/* panel warstw: „Ustawienia domyślne” na dole */
.layers-foot { flex: none; padding: 10px 14px 14px; border-top: 1px solid #e3e3e3; }
.layers-foot button { width: 100%; }

/* usuwanie drzewa */
.sp-danger { padding: 14px; margin-top: 4px; border-top: 1px solid #e3e3e3; }
.sp-danger button { width: 100%; }
button.danger-solid { background: #b3261e; border-color: #b3261e; color: #fff; }
button.danger-solid:hover { background: #8f1d17; }
.danger-hint { color: #8f1d17; }
.tree-table .t-login button[data-logout] { margin-left: 6px; }

/* logo na stronie głównej */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 32px; height: 32px; flex: none; }
@media (max-width: 760px) { .brand-logo { width: 28px; height: 28px; } }

/* „Nie pamiętasz hasła?” */
.forgot { margin: 10px 0 0; }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: 14px; min-height: 0; }
.link-btn:hover { background: none; color: #244a6f; }
.sp-account { flex-wrap: wrap; }
.sp-account button { flex: 1 1 40%; white-space: nowrap; }
#settingsPanel .layers-head h2 { min-width: 0; }
#settingsPanel .layers-head h2 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.date-hint { grid-column: 1 / -1; font-size: 12px; color: var(--muted); margin-top: -4px; }

/* pole daty: oddzielne pola dd . mm . rrrr w jednej ramce + ikona kalendarza (jak w przeglądarce);
   wypełniony sam rok oznacza datę „tylko rok” */
.date-field { position: relative; display: block; }
.date-seg {
  display: flex;
  align-items: center;
  padding: 5px 36px 5px 7px;
  border: 1px solid #bbb;
  border-radius: 3px;
  background: #fff;
  cursor: text;
}
.date-seg:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.date-seg.invalid { border-color: #c0392b; background: #fff6f5; }
fieldset .date-seg .seg {
  border: 0;
  padding: 0;
  border-radius: 2px;
  background: transparent;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  text-align: center;
  font-variant-numeric: tabular-nums;
  outline: none;
}
fieldset .date-seg .seg { width: 1.5em; text-align: left; }   /* szerokość ustawia app.js wg treści */
fieldset .date-seg .seg:focus { background: #cfe1f7; }
fieldset .date-seg .seg::placeholder { color: #888; }
.date-seg .dot { color: #555; padding: 0; }
.date-pick {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  min-height: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: #444;
}
.date-pick:hover { background: #eee; }
.date-pick .ico { width: 16px; height: 16px; }
.date-native { position: absolute; right: 0; bottom: 0; width: 36px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }

/* daty urodzenia i śmierci w jednym wierszu formularza */
fieldset .date-row { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
fieldset .date-row > label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
@media (max-width: 380px) { fieldset .date-row { grid-template-columns: 1fr; } }

/* związki: wiersz „Związek z: … [lista]” */
fieldset.unions .union-row { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; color: var(--text); font-size: 14px; }
fieldset.unions .union-row select { flex: 0 0 auto; min-width: 150px; }
@media (max-width: 480px) { fieldset.unions .union-row { flex-direction: column; align-items: stretch; } }

/* owdowienie: przerywana linia między małżonkami */
#canvas svg.lines path.dashed { stroke-dasharray: 7 5; stroke-linecap: butt; }

/* ================= Strona główna (jak „w przygotowaniu”) ================= */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#home {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  place-items: center;
  gap: 20px;
  padding: 24px 16px 14px;
  background: radial-gradient(ellipse at 50% 40%, #f7f5ef 0%, #e9efe2 100%);
  font-family: Georgia, "Times New Roman", serif;
  color: #3b3224;
}
#home[hidden] { display: none; }
.home-footer { font-size: 13px; color: #7a6f5c; text-align: center; }
.home-footer a { color: inherit; text-decoration: none; border-bottom: 1px dotted currentColor; }
.home-footer a:hover { color: #4e8f2f; }
.home-top { position: absolute; top: 14px; right: 16px; display: flex; align-items: center; gap: 12px; max-width: calc(100% - 32px); }
.home-account { font-size: 15px; color: #3b3224; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-account[hidden] { display: none; }
.ha-login { overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 760px) {
  /* telefon: liczba drzew w nawiasie pod loginem */
  .home-account { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; font-size: 14px; }
  .ha-login { max-width: 100%; }
  .ha-count { font-size: 13px; color: #6b604e; }
}
.home-center { display: flex; flex-direction: column; align-items: center; gap: 26px; width: min(460px, 100%); }
.home-logo {
  width: min(192px, 48vw);
  height: auto;
  transform-origin: 50% 92%;
  animation: home-grow 1.4s cubic-bezier(.2, .8, .2, 1) both, home-sway 6s ease-in-out 1.4s infinite;
  filter: drop-shadow(0 6px 10px rgba(60, 45, 20, 0.15));
}
@keyframes home-grow { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: scale(1); } }
@keyframes home-sway { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(1.6deg); } }
.home-buttons { display: flex; gap: 12px; }
.home-btn {
  min-width: 130px;
  padding: 9px 22px;
  border-radius: 22px;
  font-family: inherit;
  font-size: 16px;
  border: 1px solid #c9bfa8;
  background: #fffdf8;
  color: #3b3224;
}
.home-btn:hover { background: #f3eee2; }
.home-btn.primary { background: #4e8f2f; border-color: #4e8f2f; color: #fff; }
.home-btn.primary:hover { background: #3f7726; }
.home-btn[hidden] { display: none; }
.tree-empty { color: #7a6d58; font-style: italic; text-align: center; }

/* koło z drzewami: 3 wiersze, środkowy duży, skrajne mniejsze i zanikające */
.tree-wheel-wrap { width: 100%; }
.tree-wheel {
  position: relative;              /* offsetTop wierszy liczony względem listy */
  --row: 56px;
  height: calc(var(--row) * 3);
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  padding: var(--row) 0;
  outline: none;
  -webkit-mask-image: linear-gradient(rgba(0,0,0,.15) 0%, #000 38%, #000 62%, rgba(0,0,0,.15) 100%);
  mask-image: linear-gradient(rgba(0,0,0,.15) 0%, #000 38%, #000 62%, rgba(0,0,0,.15) 100%);
}
.tree-wheel::-webkit-scrollbar { display: none; }
.tree-wheel:focus-visible { box-shadow: 0 0 0 2px rgba(78, 143, 47, 0.35); border-radius: 8px; }
.wheel-item {
  height: var(--row);
  scroll-snap-align: center;
  scroll-snap-stop: always;       /* przeciągnięcie palcem też nie przeskakuje drzew */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: #3b3224;
  transition: transform 0.12s linear, opacity 0.12s linear;
  will-change: transform, opacity;
}
.wi-name { font-size: 24px; line-height: 1.15; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.wi-meta { font-size: 13px; color: #7a6d58; font-style: italic; }
.wi-lock { font-size: 0.7em; margin-right: 6px; }
.wheel-item.current .wi-name { color: #2f5a1c; }
.wheel-item.current:hover .wi-name { text-decoration: underline; text-underline-offset: 4px; }
@media (prefers-reduced-motion: reduce) { .home-logo { animation: none; } .wheel-item { transition: none; } }
@media (max-width: 480px) { .wi-name { font-size: 20px; } .home-btn { min-width: 110px; } }

@media (max-width: 760px) { .toolbar .tree-select { font-size: 16px; } }

/* telefon: pasek drzewa w jednej linii – ‹ nazwa (lista drzew) … przyciski; bez znaczka „Publiczne” */
@media (max-width: 760px) {
  .tree-bar .vis-badge { display: none; }
  .tree-bar .bar-right { flex: 0 0 auto; margin-left: auto; }
  .toolbar .tree-select { flex: 0 1 auto; padding-right: 26px; background-position: right 6px center; }
}
/* średnie ekrany: [+] bez napisu, żeby zmieściła się nazwa drzewa */
@media (max-width: 1100px) { #treeNewBtn .btn-text { display: none; } }

/* „Utwórz drzewo”: e-mail już ma konto – ramka z hasłem i [Anuluj] [Zaloguj i dodaj] */
.new-account[hidden], .exists-box[hidden], .auth-form > .buttons[hidden] { display: none; }
.new-account { display: contents; }
.exists-box {
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid #e0bf86;
  border-left: 4px solid #d08a1e;
  border-radius: 6px;
  background: #fbf4e6;
}
.exists-box p { margin: 0; line-height: 1.45; color: #5a3d0a; }
.exists-buttons { display: flex; justify-content: flex-end; gap: 8px; }

/* panel ustawień: link do podglądu (nad eksportem / importem JSON) */
.sp-share { display: grid; gap: 6px; padding: 10px 0 2px; border-top: 1px solid #e3e3e3; }
.sp-share small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.sp-share-body { display: grid; gap: 6px; }
.sp-share .share-url { width: 100%; font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid #bbb; border-radius: 4px; background: #f7f7f7; color: var(--text); }
.sp-share-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.sp-share-btns button { flex: 1; }

.sp-autoalign[hidden] { display: none; }
.sp-autoalign { width: 100%; }

/* przytrzymanie bloku (ekran dotykowy) – tryb zamiany stron z małżonkiem */
.person.swap-hold { outline: 3px dashed var(--accent, #2a6fb0); outline-offset: 3px; }
.person { -webkit-touch-callout: none; }
