/* ===== Family Tree — styles ===== */
:root {
  --bg: #f6f1e8;
  --surface: #fffdf8;
  --surface-2: #f1eadf;
  --ink: #2b221b;
  --muted: #76695c;
  --line: #e2d7c7;
  --accent: #9a3412;
  --accent-hover: #7c2d12;
  --accent-ink: #fff;
  --accent-soft: #fbe8dc;
  --male: #2f5d73;
  --male-soft: #e3eef2;
  --female: #9b3a5a;
  --female-soft: #f6e4ea;
  --other: #6b5b95;
  --ok: #2f6f3e;
  --ok-soft: #e1f0e3;
  --warn: #9a6a06;
  --warn-soft: #fbf0d6;
  --danger: #b42318;
  --danger-soft: #fde7e4;
  --info: #2c5d8a;
  --info-soft: #e3edf7;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --radius: 12px;
  --font: "Noto Sans", "Noto Sans Devanagari", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Noto Serif", "Noto Serif Devanagari", Georgia, serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191512;
    --surface: #221d19;
    --surface-2: #2b2520;
    --ink: #efe6da;
    --muted: #a8998a;
    --line: #3b332c;
    --accent: #ef8a5c;
    --accent-hover: #f6a27c;
    --accent-ink: #1d120c;
    --accent-soft: #3b241a;
    --male: #82b4cb;
    --male-soft: #1f2e35;
    --female: #e295b0;
    --female-soft: #3a2029;
    --other: #b3a5dc;
    --ok: #7fc18f;
    --ok-soft: #1f3324;
    --warn: #e6b94f;
    --warn-soft: #3a2f14;
    --danger: #f2877b;
    --danger-soft: #3d1f1b;
    --info: #8db9e2;
    --info-soft: #1d2b39;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    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);
  min-height: 100vh;
}
img { max-width: 100%; display: block; }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { font-family: var(--serif); line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2.1rem); }
h2 { font-size: 1.3rem; margin-top: 1.6em; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
code { font-size: .85em; word-break: break-all; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.lead { font-size: 1.08rem; }
.spaced { margin-top: 2rem; }
.warn-text { color: var(--warn); }
.danger-text { color: var(--danger) !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: var(--serif); font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.brand svg { width: 28px; height: 28px; fill: var(--accent); color: var(--accent); }
.topsearch { position: relative; flex: 1; max-width: 360px; }
.topsearch input { width: 100%; padding: 8px 12px 8px 34px; border-radius: 999px; background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2376695c' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='6'/%3E%3Cpath d='M16 16l4 4'/%3E%3C/svg%3E") no-repeat 10px 50% / 16px; border-color: transparent; }
.mainnav { display: flex; gap: 4px; }
.mainnav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; font-size: .95rem; white-space: nowrap; }
.mainnav a:hover { background: var(--surface-2); color: var(--ink); }
.mainnav a.is-active { color: var(--accent); background: var(--accent-soft); }
.topactions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.lang-toggle { display: inline-grid; place-items: center; min-width: 36px; height: 34px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 600; font-size: .9rem; }
.lang-toggle:hover { border-color: var(--accent); color: var(--accent); }
.iconbtn { position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; color: var(--muted); }
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn:hover, .iconbtn.is-active { color: var(--accent); background: var(--accent-soft); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .72rem; font-weight: 700; }
.dot { position: absolute; top: 2px; right: 0; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: .65rem; font-weight: 700; display: grid; place-items: center; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 8px); width: 240px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; display: grid; }
.menu-pop a, .menu-pop button { display: block; padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; background: none; border: 0; text-align: left; font: inherit; cursor: pointer; width: 100%; }
.menu-pop a:hover, .menu-pop button:hover { background: var(--surface-2); }
.menu-who { padding: 8px 12px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-who small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

.search-results { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 50; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: 60vh; overflow: auto; padding: 4px; min-width: 260px; }
.sr-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border: 0; background: none; border-radius: 8px; color: var(--ink); text-align: left; cursor: pointer; font: inherit; }
.sr-item:hover, .sr-item.is-active { background: var(--surface-2); }
.sr-item strong { display: block; font-weight: 600; font-size: .95rem; }
.sr-item small { color: var(--muted); }
.sr-empty { padding: 12px; color: var(--muted); font-size: .9rem; }

.bottomnav { display: none; }

/* ---------- page ---------- */
.page { padding: 24px 20px 64px; max-width: 1200px; margin: 0 auto; }
.narrow { max-width: 760px; margin: 0 auto; }
.narrow.wide { max-width: 1000px; }
.crumbs { margin-bottom: .5rem; font-size: .9rem; }
.crumbs a { text-decoration: none; }
.heading-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.flashes { max-width: 760px; margin: 0 auto 16px; display: grid; gap: 8px; }
.flash { padding: 10px 14px; border-radius: 10px; border: 1px solid transparent; font-size: .95rem; }
.flash-success { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.flash-info { background: var(--info-soft); color: var(--info); }
.callout { padding: 12px 16px; border-radius: 10px; background: var(--accent-soft); border-left: 3px solid var(--accent); margin: 12px 0 16px; }
.callout-success { background: var(--ok-soft); border-left-color: var(--ok); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin: 20px 0; }
.panel h2:first-child, .panel h3:first-child { margin-top: 0; }
.panel-danger { border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }
.empty { text-align: center; padding: 64px 16px; }
.empty-code { font-family: var(--serif); font-size: 4rem; color: var(--accent); line-height: 1; margin-bottom: 12px; }
.empty-inline { padding: 28px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* ---------- forms ---------- */
label { display: grid; gap: 4px; font-size: .9rem; font-weight: 500; color: var(--ink); }
.label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: 4px; }
input, select, textarea {
  font: inherit; font-size: 1rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; width: 100%; min-height: 42px;
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; border-color: var(--accent); }
input[disabled] { opacity: .65; }
input[type=checkbox] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px 18px; margin: 0; background: var(--surface); display: grid; gap: 14px; }
legend { font-family: var(--serif); font-weight: 700; padding: 0 6px; }
.hint { margin: -4px 0 0; font-size: .82rem; color: var(--muted); }
.stack { display: grid; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.form-row > label { flex: 0 1 auto; }
.form-row.tight { gap: 6px; flex-wrap: nowrap; }
.form-row.tight select { min-height: 34px; padding: 4px 8px; font-size: .88rem; width: auto; }
.grow { flex: 1 1 200px; }
form.inline { display: inline; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; min-height: 40px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--ink); }
.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: 5px 11px; min-height: 32px; font-size: .86rem; border-radius: 8px; }
.btn-icon { width: 32px; padding: 0; font-size: 1.1rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.linklike { background: none; border: 0; padding: 0 2px; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); text-decoration: none; white-space: nowrap; }
.tag-info, .tag-pending { background: var(--info-soft); color: var(--info); }
.tag-warn, .tag-disputed { background: var(--warn-soft); color: var(--warn); }
.tag-accent, .tag-join, .tag-claim { background: var(--accent-soft); color: var(--accent); }
.tag-active, .tag-used, .tag-approved, .tag-photo { background: var(--ok-soft); color: var(--ok); }
.tag-revoked, .tag-expired, .tag-disabled, .tag-quiet { background: var(--surface-2); color: var(--muted); }
.tag-story, .tag-memory { background: var(--female-soft); color: var(--female); }
.tag-biography, .tag-achievement, .tag-suggestion { background: var(--male-soft); color: var(--male); }
.tag-recipe, .tag-entry { background: var(--warn-soft); color: var(--warn); }

/* ---------- auth ---------- */
.is-guest .page { padding-top: 0; }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 0; }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 28px; }
.auth-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.auth-head h1 { font-size: 1.25rem; margin: 0; flex: 1; }
.auth-head .lang-toggle { font-size: .8rem; }
.auth-mark { width: 40px; height: 40px; color: var(--accent); fill: var(--accent); flex: none; }
.auth-card h2 { margin-top: 0; font-size: 1.35rem; }
.auth-foot { text-align: center; margin: 16px 0 6px; font-size: .92rem; }

/* ---------- tree ---------- */
.is-tree .page { max-width: none; padding: 0; }
.is-tree .flashes { padding: 12px 20px 0; }
.tree-shell { display: flex; flex-direction: column; height: calc(100vh - 57px); height: calc(100dvh - 57px); }
.tree-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--surface); }
.tree-title { display: flex; flex-direction: column; line-height: 1.2; }
.tree-focus-name { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; color: var(--ink); text-decoration: none; }
.tree-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
label.mini { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); font-weight: 500; }
label.mini select { width: auto; min-height: 32px; padding: 3px 8px; font-size: .88rem; }
.tree-viewport {
  position: relative; flex: 1; overflow: hidden; touch-action: none; cursor: grab;
  background-color: var(--bg);
  background-image: radial-gradient(color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 1px);
  background-size: 22px 22px;
}
.tree-viewport:active { cursor: grabbing; }
.tree-viewport:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tree-canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.tree-lines { position: absolute; left: 0; top: 0; overflow: visible; }
.tree-lines line { stroke: color-mix(in srgb, var(--muted) 70%, transparent); stroke-width: 1.5; fill: none; }
.tree-lines line.ln-marriage { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 0; }
.tree-cards { position: absolute; inset: 0; }
.tree-status { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--line); padding: 6px 14px; border-radius: 999px; font-size: .85rem; box-shadow: var(--shadow); }
.tree-hint { padding: 6px 20px 8px; margin: 0; background: var(--surface); border-top: 1px solid var(--line); }

.tcard {
  position: absolute; width: 184px; height: 76px;
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--male);
  border-radius: 12px; box-shadow: var(--shadow); cursor: pointer; user-select: none;
  transition: box-shadow .15s, transform .15s;
}
.tcard:hover { box-shadow: 0 2px 4px rgba(60,40,20,.08), 0 8px 24px rgba(60,40,20,.12); transform: translateY(-1px); }
.tcard.g-female { border-left-color: var(--female); }
.tcard.g-other { border-left-color: var(--other); }
.tcard.is-focus { outline: 2.5px solid var(--accent); outline-offset: 2px; }
.tcard.is-me .tcard-photo { box-shadow: 0 0 0 2px var(--accent); }
.tcard.is-deceased { background: var(--surface-2); }
.tcard.is-deceased .tcard-photo img { filter: grayscale(.6); }
.tcard.is-hidden { opacity: .7; border-style: dashed; }
.tcard-photo { flex: none; width: 46px; height: 46px; border-radius: 50%; overflow: hidden; background: var(--male-soft); color: var(--male); display: grid; place-items: center; }
.g-female .tcard-photo { background: var(--female-soft); color: var(--female); }
.tcard-photo img { width: 100%; height: 100%; object-fit: cover; }
.tcard-photo i { font-style: normal; font-weight: 700; font-size: 1rem; }
.tcard-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.tcard-text strong { font-size: .86rem; font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tcard-text em { font-style: normal; font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcard-text small { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.tcard-text small b { color: var(--ok); font-size: .6rem; vertical-align: 1px; }
.tcard-open { position: absolute; top: 4px; right: 6px; font-size: .8rem; color: var(--muted); text-decoration: none; padding: 2px 4px; border-radius: 6px; opacity: 0; }
.tcard:hover .tcard-open, .tcard.is-focus .tcard-open { opacity: 1; }
.tcard-open:hover { background: var(--accent-soft); color: var(--accent); }

/* ---------- profile ---------- */
.profile { max-width: 980px; margin: 0 auto; }
.profile-hero { display: grid; grid-template-columns: 200px 1fr; gap: 28px; align-items: start; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); border-top: 4px solid var(--male); }
.profile-hero.g-female { border-top-color: var(--female); }
.hero-photo { width: 200px; height: 200px; border-radius: 14px; overflow: hidden; background: var(--male-soft); display: grid; place-items: center; }
.g-female .hero-photo { background: var(--female-soft); }
.hero-photo img { width: 100%; height: 100%; object-fit: cover; }
.hero-initial { font-family: var(--serif); font-size: 5rem; color: var(--male); }
.g-female .hero-initial { color: var(--female); }
.hero-text h1 { margin-bottom: 2px; }
.hero-alt { font-size: 1.15rem; color: var(--muted); margin: 0 0 6px; font-family: var(--serif); }
.hero-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-bottom: 8px; color: var(--muted); }
.hero-relation { margin: 4px 0 6px; padding: 8px 12px; background: var(--accent-soft); border-radius: 10px; display: inline-flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.hero-relation strong { color: var(--accent); font-size: 1.1rem; }
.hero-owner { margin: 4px 0 12px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.tabs { position: sticky; top: 57px; z-index: 10; display: flex; gap: 4px; margin: 20px 0 0; padding: 6px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 8px 14px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap; }
.tabs a:hover { color: var(--ink); background: var(--surface-2); }
.tabs a.is-active { color: var(--accent); background: var(--accent-soft); }
.tabs .count { font-size: .75rem; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-left: 2px; }
.tabpanel { padding: 22px 4px; }
.tabpanel.is-hidden { display: none; }

.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.facts > div { padding: 14px 16px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); margin: -1px -1px 0 0; }
.facts dt { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.facts dd { margin: 2px 0 0; font-weight: 500; }

.family-group { margin-bottom: 22px; }
.family-group h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-family: var(--font); font-weight: 700; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; }
.chip-wrap { position: relative; }
.chip { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 8px 14px 8px 8px; background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--male); border-radius: 12px; text-decoration: none; color: var(--ink); }
.chip.g-female { border-left-color: var(--female); }
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip.is-deceased { background: var(--surface-2); }
.chip-photo { flex: none; width: 40px; height: 40px; border-radius: 50%; overflow: hidden; background: var(--male-soft); color: var(--male); display: grid; place-items: center; font-weight: 700; }
.g-female .chip-photo { background: var(--female-soft); color: var(--female); }
.chip-photo img { width: 100%; height: 100%; object-fit: cover; }
.chip-photo i { font-style: normal; }
.chip-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.chip-text strong { font-weight: 600; font-size: .95rem; }
.chip-text small { color: var(--muted); font-size: .8rem; }
.chip-x { position: absolute; top: -7px; right: -7px; }
.chip-x button { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--muted); cursor: pointer; font-size: .9rem; line-height: 1; opacity: 0; transition: opacity .15s; }
.chip-wrap:hover .chip-x button, .chip-x button:focus { opacity: 1; }
.chip-x button:hover { color: var(--danger); border-color: var(--danger); }
@media (hover: none) { .chip-x button { opacity: .8; } }
.add-relative { margin-top: 28px; padding: 18px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.add-relative h3 { margin-top: 0; }
.link-existing { margin-top: 14px; }
.link-existing summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: .92rem; margin-bottom: 10px; }

.picker { position: relative; }
.picker.is-picked input[data-picker-q] { border-color: var(--ok); background: var(--ok-soft); }
.picked { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tag-picker { display: grid; gap: 6px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-list .tag { background: var(--accent-soft); color: var(--accent); }

.uploader, .entry-new { margin-bottom: 18px; }
.uploader > summary, .entry-new > summary { list-style: none; display: inline-flex; margin-bottom: 14px; }
.uploader > summary::-webkit-details-marker, .entry-new > summary::-webkit-details-marker { display: none; }
.uploader form, .entry-new form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.dropzone { position: relative; display: grid; place-items: center; min-height: 110px; border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface-2); text-align: center; padding: 16px; cursor: pointer; color: var(--muted); }
.dropzone:hover { border-color: var(--accent); color: var(--accent); }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; }
.upload-preview { display: flex; flex-wrap: wrap; gap: 8px; }
.upload-preview figure { margin: 0; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; font-size: .75rem; color: var(--muted); }
.upload-preview img { width: 100%; height: 100%; object-fit: cover; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.thumb { position: relative; padding: 0; border: 0; border-radius: 10px; overflow: hidden; aspect-ratio: 1; cursor: zoom-in; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .25s; }
.thumb:hover img { transform: scale(1.04); }
.thumb.is-pending img { opacity: .6; }
.thumb .tag { position: absolute; left: 6px; top: 6px; }
.thumb .tag-accent { left: auto; right: 6px; }
.lightbox { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--ink); width: min(1000px, 94vw); max-height: 92vh; overflow: auto; }
.lightbox::backdrop { background: rgba(10, 8, 6, .82); }
.lightbox > img { width: 100%; max-height: 72vh; object-fit: contain; background: #000; }
.lb-close { position: sticky; top: 0; height: 0; z-index: 2; text-align: right; }
.lb-close button { margin: 8px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 1.3rem; cursor: pointer; }
.lb-info { padding: 14px 18px 18px; display: grid; gap: 10px; }
.lb-caption { font-size: 1.05rem; margin: 0; }
.small-chips .tag { font-size: .8rem; }
.small-form { margin-top: 10px; max-width: 420px; }

.entry { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; }
.entry.is-pending { border-style: dashed; }
.entry header { margin-bottom: 8px; }
.entry h3 { margin: 6px 0 2px; font-size: 1.15rem; }
.entry-body { line-height: 1.7; white-space: normal; overflow-wrap: anywhere; }
.entry-body.clamp { max-height: 9.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.entry .btn-row { margin-top: 10px; }

/* ---------- lists, tables ---------- */
.list { display: grid; gap: 10px; }
.list .chip { min-width: 0; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.plain-list { padding-left: 1.2em; }
.plain-list li { margin: 4px 0; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.copyrow { display: flex; gap: 6px; flex-wrap: wrap; }
.copyrow input { flex: 1 1 240px; font-size: .85rem; }

.approval { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; }
.approval header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.approval h3 { margin: 0 0 4px; font-family: var(--font); font-size: 1.05rem; font-weight: 600; }
.approval-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.approval-actions input { min-height: 40px; }
.approval-photo { display: flex; gap: 14px; align-items: flex-start; }
.approval-photo img { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; }
.diff { width: 100%; border-collapse: collapse; font-size: .9rem; margin: 8px 0; }
.diff th, .diff td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.diff th { font-size: .75rem; color: var(--muted); text-transform: uppercase; }
.diff .old { color: var(--danger); text-decoration: line-through; text-decoration-thickness: 1px; }
.diff .new { color: var(--ok); font-weight: 600; }

.notif-list, .history { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.notif-list li, .history li { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.notif-list li:last-child, .history li:last-child { border-bottom: 0; }
.notif-list li.is-unread { background: var(--accent-soft); }
.notif-list a { color: var(--ink); text-decoration: none; }
.notif-list small { color: var(--muted); white-space: nowrap; }
.history li.is-undone { opacity: .55; }

.relation-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 14px; align-items: end; background: var(--surface); padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); }
.picker-slot { min-width: 0; }
.relation-answer { text-align: center; padding: 28px 16px 20px; margin: 22px 0 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; }
.relation-answer .big { font-family: var(--serif); font-size: 2.2rem; color: var(--accent); margin: 4px 0 0; line-height: 1.2; }
.relation-answer .alt { font-size: 1.15rem; color: var(--muted); margin-bottom: 8px; }
.relation-answer .reverse { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.relation-path { list-style: none; padding: 0; display: grid; gap: 6px; justify-items: center; }
.relation-path li { display: grid; justify-items: center; gap: 4px; }
.relation-path .step { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.relation-path .step::before { content: "↓ "; }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .mainnav { display: none; }
  .topsearch { max-width: none; }
}
@media (max-width: 640px) {
  body.has-nav { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .topbar { padding: 8px 12px; gap: 10px; }
  .brand span { display: none; }
  .page { padding: 16px 14px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
  .profile-hero { grid-template-columns: 1fr; padding: 16px; gap: 16px; text-align: left; }
  .hero-photo { width: 120px; height: 120px; }
  .hero-initial { font-size: 3.2rem; }
  .tabs { top: 53px; }
  .chip { min-width: 0; width: 100%; }
  .chips .chip-wrap { flex: 1 1 100%; }
  .gallery { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .relation-form { grid-template-columns: 1fr; }
  .tree-shell { height: calc(100dvh - 53px - 64px - env(safe-area-inset-bottom)); }
  .tree-toolbar { padding: 8px 12px; }
  .tree-hint { display: none; }
  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottomnav a { position: relative; flex: 1; display: grid; justify-items: center; gap: 2px; padding: 4px 0; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600; }
  .bottomnav svg { width: 22px; height: 22px; fill: currentColor; }
  .bottomnav a.is-active { color: var(--accent); }
  .bottomnav .dot { top: 0; right: calc(50% - 20px); }
  .auth-card { border-radius: 14px; padding: 22px; }
  .form-row.tight { flex-wrap: wrap; }
}
