/* ==========================================================
   РОД — стили Mini App.
   Тёплая, «семейная» палитра. Светлая и тёмная темы Telegram.
   ========================================================== */

:root {
  --bg:        #F7F3ED;
  --bg-soft:   #EFE7DC;
  --surface:   #FFFFFF;
  --surface-2: #FBF7F1;
  --text:      #2C2521;
  --muted:     #8B7F73;
  --line:      #E5DACD;
  --accent:    #B0703A;   /* тёплое дерево */
  --accent-ink:#FFFFFF;
  --leaf:      #6E8B5B;
  --danger:    #B5503F;
  --shadow:    0 6px 20px rgba(60, 42, 26, .10);
  --radius:    18px;
  --card-w:    124px;
  --card-h:    148px;
}

body.theme-dark {
  --bg:        #17130F;
  --bg-soft:   #1F1A15;
  --surface:   #241E18;
  --surface-2: #2B241D;
  --text:      #F3ECE3;
  --muted:     #A69688;
  --line:      #382E25;
  --accent:    #D89A5D;
  --accent-ink:#231A11;
  --leaf:      #93B07C;
  --danger:    #D9705C;
  --shadow:    0 8px 24px rgba(0, 0, 0, .38);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Атрибут hidden должен побеждать любой display ниже по файлу. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button, input, select { font: inherit; color: inherit; }

/* ---------- экраны ---------- */
.screen { display: none; position: absolute; inset: 0; }
.screen.is-active { display: flex; flex-direction: column; }

/* ---------- загрузка / ошибка ---------- */
.boot {
  margin: auto;
  text-align: center;
  padding: 32px 24px;
}
.boot__mark { font-size: 56px; line-height: 1; }
.boot__name {
  margin-top: 14px;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: .14em;
}
.boot__tagline { margin-top: 6px; color: var(--muted); font-size: 14px; }
.spinner {
  width: 26px; height: 26px; margin: 26px auto 0;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px;
  border: 0; border-radius: 14px;
  font-size: 16px; font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, opacity .12s ease;
}
.btn:active { transform: scale(.975); }
.btn--primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }
.btn--ghost   { background: transparent; color: var(--muted); }
.btn--dashed {
  width: 100%; background: transparent; color: var(--accent);
  border: 1.5px dashed var(--line);
}
.btn[disabled] { opacity: .5; pointer-events: none; }

/* ---------- приглашение ---------- */
.invite { margin: auto; padding: 28px 24px; text-align: center; max-width: 420px; width: 100%; }
.invite__heart { font-size: 44px; }
.invite__title { margin: 12px 0 6px; font-size: 22px; font-weight: 700; }
.invite__sub { margin: 0; color: var(--muted); }
.invite__card {
  margin: 24px auto; padding: 22px 18px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.invite__name { margin-top: 12px; font-size: 19px; font-weight: 700; }
.invite__meta { color: var(--muted); font-size: 14px; }
.invite__question { font-weight: 600; }
.invite__actions { display: flex; flex-direction: column; gap: 8px; }

/* ---------- аватар ---------- */
.avatar {
  width: 56px; height: 56px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 19px; color: #fff;
  background: var(--leaf);
  overflow: hidden;
}
.avatar--lg { width: 88px; height: 88px; font-size: 30px; margin: 0 auto; }
.avatar--f { background: #B57C93; }
.avatar--m { background: #5F86A8; }
.avatar--u { background: #948A7E; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- мастер ---------- */
.wizard__head { padding: 18px 20px 0; }
.wizard__steps { display: flex; gap: 6px; }
.wizard__steps span {
  flex: 1; height: 4px; border-radius: 2px; background: var(--line);
  transition: background .2s ease;
}
.wizard__steps span.is-done { background: var(--accent); }
.wizard__body { flex: 1; overflow-y: auto; padding: 20px 20px 8px; -webkit-overflow-scrolling: touch; }
.wizard__foot {
  display: flex; gap: 10px; padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg);
}
.wizard__foot .btn--primary { flex: 1; }

.step { display: none; }
.step.is-active { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.step__title { margin: 0 0 6px; font-size: 24px; font-weight: 700; letter-spacing: -.01em; }
.step__sub { margin: 0 0 20px; color: var(--muted); }

/* ---------- формы ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form-group { margin-bottom: 22px; }
.form-group__label { font-weight: 600; margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: 13px; color: var(--muted); }
.field input, .field select {
  width: 100%; min-height: 48px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field--row { flex-direction: row; gap: 10px; }
.field--row > * { flex: 1; }
.seg { display: flex; gap: 8px; }
.seg button {
  flex: 1; min-height: 44px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  font-weight: 600; cursor: pointer;
}
.seg button.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.mini-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.mini-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px;
}
.mini-item__name { flex: 1; font-weight: 600; }
.mini-item__meta { color: var(--muted); font-size: 13px; }
.mini-item[data-family] { cursor: pointer; }
.mini-item.is-on { border-color: var(--accent); }
.mini-item__del { border: 0; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; }

/* ---------- верхняя панель ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
  position: relative; z-index: 5;
}
/* Шапка не должна переноситься на вторую строку из-за кнопок справа. */
.topbar__title {
  font-weight: 700; font-size: 17px;
  flex: 0 1 auto; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__meta {
  flex: 1 1 auto; min-width: 0; color: var(--muted); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__btn {
  border: 0; background: transparent; font-size: 20px; cursor: pointer;
  width: 36px; height: 36px; border-radius: 10px;
}

/* ---------- холст дерева ---------- */
.canvas {
  flex: 1; position: relative; overflow: hidden;
  background:
    radial-gradient(circle at 20% 0%, var(--bg-soft), transparent 55%),
    var(--bg);
  touch-action: none;
  cursor: grab;
}
.canvas:active { cursor: grabbing; }
.canvas__stage { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
.canvas__links { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
.canvas__cards { position: absolute; top: 0; left: 0; }

.link { fill: none; stroke-width: 2; stroke-linecap: round; }
.link--parent { stroke: var(--line); }
.link--spouse { stroke: var(--accent); stroke-dasharray: 1 6; }

.pcard {
  position: absolute;
  width: var(--card-w); height: var(--card-h);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 8px 10px;
  cursor: pointer;
  transition: transform .14s ease, border-color .14s ease;
}
.pcard:active { transform: scale(.97); }
.pcard--me { border-color: var(--accent); border-width: 2px; }
.pcard--gone { background: var(--surface-2); }
.pcard__name {
  margin-top: 10px; font-weight: 700; font-size: 13px; text-align: center;
  line-height: 1.25; max-height: 2.5em; overflow: hidden;
}
.pcard__years { margin-top: 3px; font-size: 12px; color: var(--muted); }
.pcard__badge {
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  padding: 2px 10px; border-radius: 20px; font-size: 11px; font-weight: 700;
  background: var(--accent); color: var(--accent-ink); white-space: nowrap;
}
.pcard__flag { position: absolute; top: 8px; right: 10px; font-size: 13px; }

/* ---------- баннер-подсказка ---------- */
.nudge {
  position: absolute; left: 12px; right: 12px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  z-index: 6;
}
.nudge__text { flex: 1; font-size: 14px; }
.nudge__btn {
  border: 0; background: var(--accent); color: var(--accent-ink);
  border-radius: 12px; padding: 9px 14px; font-weight: 600; cursor: pointer;
}
.nudge__close { border: 0; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; }

/* ---------- зум ---------- */
.zoom {
  position: absolute; right: 12px; bottom: calc(92px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; z-index: 6;
}
.zoom__btn {
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 18px; cursor: pointer; box-shadow: var(--shadow);
}

/* ---------- шторка ---------- */
.sheet { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(20, 14, 8, .45); }
.sheet__panel {
  position: relative; width: 100%; max-height: 88vh; overflow-y: auto;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom));
  animation: rise .22s ease;
  -webkit-overflow-scrolling: touch;
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet__grip {
  display: block; width: 56px; height: 20px; padding: 8px 0 0; margin: 0 auto 10px;
  border: 0; background: transparent; cursor: pointer;
}
.sheet__grip::before {
  content: ''; display: block; width: 40px; height: 4px; margin: 0 auto;
  border-radius: 2px; background: var(--line);
}
.sheet__title { margin: 0 0 16px; font-size: 20px; font-weight: 700; }
.sheet__actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet__actions .btn { flex: 1; }

.person-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.person-name { font-size: 20px; font-weight: 700; }
.person-sub { color: var(--muted); font-size: 14px; }
.person-facts { margin: 14px 0; display: flex; flex-direction: column; gap: 8px; }
.fact { display: flex; gap: 8px; font-size: 14px; }
.fact__k { color: var(--muted); min-width: 92px; }
.memorial {
  margin: 14px 0; padding: 12px 14px; border-radius: 14px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 14px; text-align: center;
}
.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.action {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 8px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.action span:first-child { font-size: 20px; }
.action--wide { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: 13px; margin-top: 14px; }

/* ---------- тост ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 11px 18px; border-radius: 14px; font-size: 14px;
  z-index: 60; max-width: 86%; text-align: center;
}

/* ---------- фото и истории (Этап 4) ---------- */
.section { margin-top: 22px; }
.section__head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 10px;
}
.section__title { font-weight: 700; font-size: 16px; flex: 1; }
.section__add {
  border: 0; background: transparent; color: var(--accent);
  font-weight: 600; font-size: 14px; cursor: pointer; padding: 4px 0;
}
.section__empty { color: var(--muted); font-size: 14px; }

.story {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px; margin-bottom: 10px;
}
.story__title { font-weight: 700; margin-bottom: 4px; }
.story__text { white-space: pre-wrap; word-break: break-word; }
.story__foot {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px; color: var(--muted); font-size: 13px;
}
.story__del { margin-left: auto; border: 0; background: transparent; color: var(--muted); cursor: pointer; }

.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo-cell {
  position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--line); cursor: pointer;
}
.photo-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-cell__year {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px 6px 4px; font-size: 11px; font-weight: 600; color: #fff;
  background: linear-gradient(to top, rgba(0,0,0,.55), transparent);
}

/* аватар с возможностью сменить фото */
.avatar--edit { position: relative; cursor: pointer; }
.avatar--edit::after {
  content: '📷'; position: absolute; right: -2px; bottom: -2px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 12px;
}

/* просмотр фото на весь экран */
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(10, 7, 4, .92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px;
}
.lightbox img { max-width: 100%; max-height: 78vh; border-radius: 12px; }
.lightbox__cap { color: #fff; margin-top: 14px; text-align: center; font-size: 14px; }
.lightbox__close {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 14px;
  width: 40px; height: 40px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.15); color: #fff; font-size: 22px; cursor: pointer;
}
.lightbox__del {
  margin-top: 16px; border: 0; background: rgba(255,255,255,.14); color: #fff;
  border-radius: 12px; padding: 10px 18px; font-weight: 600; cursor: pointer;
}

textarea {
  width: 100%; min-height: 140px; padding: 12px 14px; resize: vertical;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; outline: none; font: inherit; color: inherit;
}
textarea:focus { border-color: var(--accent); }

/* ---------- связи (Этап 4б) ---------- */
.rel-group { margin-bottom: 14px; }
.rel-group__label {
  font-size: 13px; color: var(--muted); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: .04em;
}
.rel {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin-bottom: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
.rel__name { flex: 1; font-weight: 600; min-width: 0; }
.rel__years { color: var(--muted); font-weight: 400; font-size: 13px; }
.rel__cut {
  border: 0; background: transparent; color: var(--danger);
  font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px 0;
}
.avatar--xs { width: 34px; height: 34px; font-size: 13px; }

.opt {
  margin-top: 16px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
}
.opt__label { font-weight: 600; margin-bottom: 8px; }
.opt__hint { color: var(--muted); font-size: 13px; margin-top: 8px; }
.opt__row { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }
.opt__row input { width: 20px; height: 20px; accent-color: var(--accent); }
.opt select {
  width: 100%; min-height: 44px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}

/* ---------- подсветка выбранного человека ---------- */
.pcard, .link { transition: opacity .18s ease, stroke .18s ease; }
.pcard.is-dim { opacity: .28; }
.pcard.is-focus { border-color: var(--accent); border-width: 2px; }
.link--on { stroke: var(--accent); stroke-width: 3; }
.link--off { opacity: .18; }
.link__head { fill: var(--line); }
.link__head--on { fill: var(--accent); }
