:root {
  --accent: #6d5efc; --accent-2: #8f84ff; --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --bg: #f2f2f7; --bg-2: #ffffff; --bg-3: #e9e9ee; --text: #000000; --muted: #86868b; --line: rgba(60,60,67,.14);
  --good: #34c759; --warn: #ff9500; --bad: #ff3b30; --shadow: 0 1px 1px rgba(0,0,0,.02), 0 4px 18px rgba(0,0,0,.05);
  --radius: 16px; --nav-h: 64px; --head-h: 56px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Inter", "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #000000; --bg-2: #1c1c1e; --bg-3: #2c2c2e; --text: #ffffff; --muted: #8e8e93; --line: rgba(84,84,88,.5);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35); color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); overflow-x: clip; }
body { font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h1 { font-size: 26px; } h2 { font-size: 19px; } h3 { font-size: 16px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 11.5px; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; } .col { display: flex; flex-direction: column; gap: 10px; }
.wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; } .between { justify-content: space-between; } .center { justify-content: center; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gap-s { gap: 6px; } .mt { margin-top: 14px; } .mb { margin-bottom: 14px; }

.splash { position: fixed; inset: 0; display: grid; place-items: center; }
.splash-logo { font-size: 64px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.12); } }

/* ---------- Layout ---------- */
.shell { min-height: 100%; }
.topbar { position: sticky; top: 0; z-index: 30; height: calc(var(--head-h) + var(--safe-t)); padding: var(--safe-t) 12px 0;
  display: flex; align-items: center; gap: 8px; background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(18px); -webkit-backdrop-filter: saturate(180%) blur(18px); border-bottom: 1px solid transparent; }
.topbar.scrolled { border-bottom-color: var(--line); }
.topbar .title { font-weight: 700; font-size: 18px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: -.02em; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.iconbtn { position: relative; width: 40px; height: 40px; border-radius: 12px; border: 0; background: transparent; display: grid; place-items: center; cursor: pointer; font-size: 20px; color: var(--text); flex: none; }
.iconbtn:hover { background: var(--bg-3); }
.iconbtn svg { width: 22px; height: 22px; }
.badge { position: absolute; top: 3px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.page { padding: 12px 16px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 860px; margin: 0 auto; animation: pagein .22s ease-out; }
.page.wide { max-width: none; padding: 0; }
.page.wide { animation: none; }
@keyframes pagein { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
.page.back-anim { animation: pageback .22s ease-out; }
@keyframes pageback { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }

.bottomnav { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: color-mix(in srgb, var(--bg-2) 88%, transparent); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); border-top: 1px solid var(--line); }
.bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 10.5px; font-weight: 600; position: relative; }
.bottomnav a svg { width: 25px; height: 25px; }
.bottomnav a.active { color: var(--text); }
.bottomnav a.active svg { stroke-width: 2.4; }
.bottomnav .badge { top: 6px; right: calc(50% - 22px); }
.sidenav { display: none; }
@media (min-width: 960px) {
  .bottomnav { display: none; }
  .sidenav { display: flex; flex-direction: column; gap: 2px; position: fixed; top: 0; bottom: 0; left: 0; width: 240px; padding: 18px 12px; border-right: 1px solid var(--line); background: var(--bg-2); z-index: 35; overflow-y: auto; }
  .sidenav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; color: var(--text); font-weight: 550; position: relative; }
  .sidenav a svg { width: 22px; height: 22px; }
  .sidenav a.active { background: var(--accent-soft); color: var(--accent); }
  .sidenav a:hover:not(.active) { background: var(--bg-3); }
  .sidenav .badge { position: static; margin-left: auto; }
  .sidenav .brand { padding: 4px 12px 18px; }
  .with-side { margin-left: 240px; }
  .page { padding-bottom: 40px; }
}

/* ---------- Cards & lists ---------- */
.card { background: var(--bg-2); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card, .section + .section { margin-top: 14px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 22px 2px 10px; }
.section-title h2 { font-size: 17px; }
.section-title a { font-size: 14px; font-weight: 600; }
.list { background: var(--bg-2); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; position: relative; color: var(--text); }
.item + .item::before { content: ""; position: absolute; top: 0; left: 64px; right: 0; border-top: 1px solid var(--line); }
.item:active { background: var(--bg-3); }
.item .sub { color: var(--muted); font-size: 13px; }
.item .chev { color: var(--muted); }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty .big { font-size: 42px; margin-bottom: 8px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.kpi { background: var(--bg-2); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.kpi b { display: block; font-size: 22px; }

/* ---------- Buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 18px; border-radius: 12px; border: 0; cursor: pointer; font-weight: 650; background: var(--accent); color: #fff; white-space: nowrap; }
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--bg-3); color: var(--text); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }
.btn.small { height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; min-height: 46px; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font-size: 16px; font-weight: 400; outline: none; transition: border .15s, box-shadow .15s; }
textarea.input { resize: vertical; min-height: 90px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--text); white-space: nowrap; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.seg { display: inline-flex; background: var(--bg-3); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; font-weight: 600; font-size: 13px; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--bg-2); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--bg-3); border-radius: 15px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: .2s; }
.switch input:checked + span { background: var(--good); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ---------- Avatars ---------- */
.avatar { --s: 44px; width: var(--s); height: var(--s); border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: calc(var(--s) * .38); background: var(--c, var(--accent)); overflow: hidden; position: relative; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.ring { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.avatar .dot { position: absolute; right: 0; bottom: 0; width: 28%; height: 28%; border-radius: 50%; background: var(--good); border: 2px solid var(--bg-2); }
.avatar.deceased { filter: grayscale(1); }
.status-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text); font-size: 12.5px; font-weight: 600; }
.stories { display: flex; gap: 14px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: none; }
.stories::-webkit-scrollbar { display: none; }
.story { flex: none; width: 68px; text-align: center; font-size: 11.5px; cursor: pointer; }
.story .avatar { --s: 60px; margin: 0 auto 5px; box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }
.story .em { position: absolute; right: -2px; bottom: -2px; font-size: 18px; }

/* ---------- Dashboard ---------- */
.hero { border-radius: 22px; padding: 20px; color: #fff; background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #000)); box-shadow: var(--shadow); }
.hero .muted { color: rgba(255,255,255,.8); }
.progress { height: 8px; border-radius: 4px; background: rgba(255,255,255,.25); overflow: hidden; }
.progress > i { display: block; height: 100%; background: #fff; border-radius: 4px; }
.card .progress { background: var(--bg-3); } .card .progress > i { background: var(--accent); }
.step { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.step .tick { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; flex: none; font-size: 14px; }
.step.done .tick { background: var(--good); border-color: var(--good); color: #fff; }
.step.done .t { text-decoration: line-through; color: var(--muted); }
.modules { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (min-width: 600px) { .modules { grid-template-columns: repeat(6, 1fr); } }
.module { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; border-radius: 16px; background: var(--bg-2); box-shadow: var(--shadow); cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text); text-align: center; }
.module .ic { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-size: 22px; background: var(--accent-soft); }
.today { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; }
.today .date { width: 64px; height: 68px; border-radius: 14px; background: var(--bg-2); color: var(--text); display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: var(--shadow); }
.today .date b { font-size: 26px; line-height: 1; } .today .date span { font-size: 11px; font-weight: 700; color: var(--bad); text-transform: uppercase; }

/* ---------- Feed ---------- */
.post { background: var(--bg-2); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 14px; overflow: hidden; }
.post .ph { display: flex; gap: 10px; align-items: center; padding: 12px 14px; }
.post .body { padding: 0 14px 12px; white-space: pre-wrap; word-wrap: break-word; }
.post .media img { width: 100%; max-height: 520px; object-fit: cover; }
.post .actions { display: flex; gap: 4px; padding: 6px 8px; border-top: 1px solid var(--line); }
.post .actions button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 10px; cursor: pointer; font-weight: 600; color: var(--muted); }
.post .actions button.on { color: var(--bad); }
.post .comments { padding: 0 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.comment { background: var(--bg-3); padding: 8px 12px; border-radius: 14px; font-size: 14px; }
.kind-tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 3px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }
.minimap { height: 200px; border-radius: 12px; overflow: hidden; margin: 0 14px 12px; }
.poll-opt { position: relative; display: flex; justify-content: space-between; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 8px; cursor: pointer; overflow: hidden; }
.poll-opt i { position: absolute; inset: 0 auto 0 0; background: var(--accent-soft); z-index: 0; transition: width .4s; }
.poll-opt span { position: relative; z-index: 1; }
.poll-opt.mine { border-color: var(--accent); font-weight: 650; }
.composer { display: flex; gap: 10px; align-items: center; padding: 12px; }
.composer .fake { flex: 1; padding: 11px 14px; border-radius: 22px; background: var(--bg-3); color: var(--muted); cursor: pointer; }

/* ---------- Sheets / modals / toasts ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.38); z-index: 80; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; z-index: 90; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; background: var(--bg-2); border-radius: 22px 22px 0 0; padding: 8px 18px calc(18px + var(--safe-b)); animation: up .26s cubic-bezier(.2,.9,.3,1); box-shadow: 0 -10px 40px rgba(0,0,0,.2); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin-bottom: 14px; }
@media (min-width: 700px) { .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 560px; transform: translate(-50%, -50%); border-radius: 22px; max-height: 86vh; animation: pop .2s; } }
@keyframes up { from { transform: translateY(100%); } }
@keyframes pop { from { opacity: 0; transform: translate(-50%, -46%); } }
#toasts { position: fixed; z-index: 120; left: 50%; top: calc(10px + var(--safe-t)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; width: min(94vw, 420px); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-radius: 16px; background: color-mix(in srgb, var(--bg-2) 92%, transparent); backdrop-filter: blur(18px); box-shadow: 0 10px 30px rgba(0,0,0,.18); animation: drop .3s cubic-bezier(.2,.9,.3,1); cursor: pointer; border: 1px solid var(--line); }
.toast.err { border-color: var(--bad); }
@keyframes drop { from { opacity: 0; transform: translateY(-20px); } }
.menu { position: fixed; z-index: 100; min-width: 220px; background: var(--bg-2); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.25); padding: 6px; animation: fade .12s; }
.menu button { display: flex; width: 100%; gap: 10px; align-items: center; padding: 10px 12px; border: 0; background: transparent; border-radius: 9px; cursor: pointer; text-align: left; font-size: 14.5px; }
.menu button:hover { background: var(--bg-3); }
.offline-bar { position: sticky; top: calc(var(--head-h) + var(--safe-t)); z-index: 29; background: #2b2b30; color: #fff; font-size: 12.5px; text-align: center; padding: 5px 10px; }

/* ---------- Tree ---------- */
.tree-wrap { position: fixed; inset: calc(var(--head-h) + var(--safe-t)) 0 calc(var(--nav-h) + var(--safe-b)) 0; overflow: hidden; background:
  radial-gradient(circle, color-mix(in srgb, var(--muted) 22%, transparent) 1px, transparent 1.2px) 0 0 / 22px 22px, var(--bg); touch-action: none; }
@media (min-width: 960px) { .tree-wrap { left: 240px; bottom: 0; } }
.tree-wrap svg { width: 100%; height: 100%; cursor: grab; user-select: none; }
.tree-wrap svg.dragging { cursor: grabbing; }
.tnode { cursor: pointer; }
.tnode rect.card-bg { fill: var(--bg-2); stroke: var(--line); stroke-width: 1; filter: drop-shadow(0 2px 6px rgba(0,0,0,.08)); }
.tnode.me rect.card-bg { stroke: var(--accent); stroke-width: 2.5; }
.tnode.hl rect.card-bg { stroke: var(--warn); stroke-width: 3; }
.tnode.linked rect.card-bg { stroke-dasharray: 5 4; }
.tnode text { fill: var(--text); font-size: 13px; }
.tnode text.sub { fill: var(--muted); font-size: 11px; }
.tnode text.rel { fill: var(--accent); font-size: 11px; font-weight: 700; }
.tedge { fill: none; stroke: color-mix(in srgb, var(--muted) 60%, transparent); stroke-width: 1.6; }
.tedge.spouse { stroke: var(--bad); stroke-width: 2; opacity: .6; }
.tedge.sib { stroke-dasharray: 4 4; }
.tree-tools { position: absolute; z-index: 5; left: 10px; right: 10px; top: 10px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; pointer-events: none; }
.tree-tools > * { pointer-events: auto; }
.tree-zoom { position: absolute; z-index: 5; right: 12px; bottom: 14px; display: flex; flex-direction: column; gap: 8px; }
.tree-zoom button { width: 44px; height: 44px; border-radius: 14px; border: 0; background: var(--bg-2); box-shadow: var(--shadow); font-size: 20px; cursor: pointer; color: var(--text); }
.tree-legend { position: absolute; z-index: 5; left: 12px; bottom: 14px; display: flex; flex-direction: column; gap: 4px; background: var(--bg-2); padding: 8px 10px; border-radius: 12px; box-shadow: var(--shadow); font-size: 12px; max-width: 60vw; }
.tree-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.minimap-box { position: absolute; z-index: 5; right: 68px; bottom: 14px; width: 130px; height: 90px; background: var(--bg-2); border-radius: 10px; box-shadow: var(--shadow); overflow: hidden; }
.minimap-box svg { cursor: pointer; }
.floating-search { background: var(--bg-2); box-shadow: var(--shadow); border-radius: 12px; border: 0; height: 40px; padding: 0 12px; min-width: 0; flex: 1; max-width: 260px; font-size: 15px; }

/* ---------- Person ---------- */
.profile-head { text-align: center; padding: 10px 0 4px; }
.profile-head .avatar { --s: 108px; margin: 0 auto 12px; font-size: 40px; }
.quick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 16px 0; }
.quick a, .quick button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 2px; border-radius: 14px; background: var(--bg-2); box-shadow: var(--shadow); border: 0; cursor: pointer; font-size: 11.5px; font-weight: 600; color: var(--text); }
.quick .ic { font-size: 20px; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 10px 12px; font-size: 14.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.rel-chips { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.rel-chip { flex: none; width: 82px; text-align: center; font-size: 12px; cursor: pointer; }
.rel-chip .avatar { --s: 56px; margin: 0 auto 4px; }
.timeline { border-left: 2px solid var(--line); margin-left: 8px; padding-left: 16px; }
.timeline .ev { position: relative; padding: 6px 0 12px; }
.timeline .ev::before { content: ""; position: absolute; left: -23px; top: 11px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
.map { height: 260px; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.map.full { position: fixed; inset: calc(var(--head-h) + var(--safe-t)) 0 calc(var(--nav-h) + var(--safe-b)) 0; height: auto; border-radius: 0; }
@media (min-width: 960px) { .map.full { left: 240px; bottom: 0; } }
.leaflet-container { background: var(--bg-3); font: inherit; }
.map-pin { width: 38px; height: 38px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35); overflow: hidden; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; }
.map-pin.live { animation: livepulse 1.6s infinite; }
@keyframes livepulse { 0% { box-shadow: 0 0 0 0 rgba(30,158,90,.6); } 100% { box-shadow: 0 0 0 16px rgba(30,158,90,0); } }

/* ---------- Search ---------- */
.searchbar { position: sticky; top: calc(var(--head-h) + var(--safe-t)); z-index: 20; background: var(--bg); padding: 4px 0 10px; }
.searchbar .input { padding-left: 42px; border-radius: 14px; background: var(--bg-2); }
.searchbar .ico { position: absolute; left: 14px; top: 17px; color: var(--muted); }
mark { background: color-mix(in srgb, var(--warn) 30%, transparent); color: inherit; border-radius: 3px; }

/* ---------- Chat ---------- */
.chat-page { display: flex; flex-direction: column; height: calc(100dvh - var(--head-h) - var(--safe-t)); max-width: 860px; margin: 0 auto; }
.msgs { flex: 1; overflow-y: auto; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 3px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 18px; background: var(--bg-2); box-shadow: 0 1px 1px rgba(0,0,0,.05); align-self: flex-start; word-wrap: break-word; white-space: pre-wrap; }
.msg.me { align-self: flex-end; background: var(--accent); color: #fff; }
.msg .meta { font-size: 10.5px; opacity: .7; text-align: right; margin-top: 2px; }
.msg .who { font-size: 12px; font-weight: 700; color: var(--accent); }
.msg.pending { opacity: .6; }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); background: var(--bg-3); padding: 3px 10px; border-radius: 10px; margin: 10px 0; }
.chat-input { display: flex; gap: 8px; padding: 8px 10px calc(8px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line); }
.chat-input textarea { flex: 1; min-height: 44px; max-height: 140px; resize: none; border-radius: 22px; padding: 11px 16px; }
.typing { font-size: 12px; color: var(--accent); padding: 0 16px 4px; min-height: 18px; }
@media (max-width: 959px) { .chat-mode .bottomnav { display: none; } }

/* ---------- Photos ---------- */
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; border-radius: 12px; overflow: hidden; }
@media (min-width: 700px) { .gallery { grid-template-columns: repeat(5, 1fr); } }
.gallery .g { aspect-ratio: 1; background: var(--bg-3); cursor: pointer; position: relative; overflow: hidden; }
.gallery .g img { width: 100%; height: 100%; object-fit: cover; }
.gallery .g .t { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 6px; }
.lightbox { position: fixed; inset: 0; z-index: 110; background: rgba(0,0,0,.94); display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; }
.lightbox img { max-width: 100%; max-height: 82vh; object-fit: contain; }

/* ---------- Auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 18px; background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent), var(--bg); }
.auth .box { width: min(420px, 100%); }
.auth .logo { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto 16px; box-shadow: var(--shadow); }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.swipe-indicator { position: fixed; left: 0; top: 50%; z-index: 200; width: 36px; height: 36px; margin-top: -18px; border-radius: 50%; background: var(--bg-2); box-shadow: var(--shadow); display: grid; place-items: center; transform: translateX(-40px); pointer-events: none; transition: opacity .2s; }
.color-dots { display: flex; gap: 10px; flex-wrap: wrap; }
.color-dots button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.color-dots button.active { border-color: var(--text); }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple td, table.simple th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }

.is-offline .tree-wrap, .is-offline .map.full { top: calc(var(--head-h) + var(--safe-t) + 27px); }

.reacts { display: flex; gap: 4px; margin: -2px 6px 4px; align-self: flex-start; }
.reacts.me { align-self: flex-end; }
.reacts button { border: 1px solid var(--line); background: var(--bg-2); border-radius: 12px; padding: 1px 7px; font-size: 13px; cursor: pointer; }
.reacts button.on { border-color: var(--accent); background: var(--accent-soft); }
.chat-input .rec { flex: 1; display: flex; align-items: center; gap: 8px; padding: 0 12px; color: var(--bad); font-weight: 600; font-size: 14px; }
.chat-input .rec i { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); animation: pulse 1s infinite; }
.iconbtn.recording { color: var(--bad); }
.msg { user-select: text; -webkit-user-select: text; }


/* ================= Apple-style refresh ================= */
body { letter-spacing: -.011em; }
h1, h2, .large-title { letter-spacing: -.022em; }
.card, .list, .post, .kpi, .module, .quick a, .quick button { box-shadow: none; }
[data-theme="light"] .card, [data-theme="light"] .list, [data-theme="light"] .post { box-shadow: 0 0 0 .5px rgba(0,0,0,.04); }
.list { border-radius: 14px; }
.item { min-height: 52px; }
.item + .item::before { border-top-width: .5px; }
.section-title h2 { font-size: 20px; font-weight: 700; }
.section-title a, .section-title .btn.ghost { font-weight: 500; }
.btn { border-radius: 14px; font-weight: 600; letter-spacing: -.01em; transition: transform .12s, filter .12s; }
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: var(--bg-3); }
.chip { border: 0; background: var(--bg-3); font-weight: 500; }
.chip.active { background: var(--text); color: var(--bg-2); }
.seg { border-radius: 10px; padding: 2px; background: color-mix(in srgb, var(--muted) 18%, transparent); }
.seg button { border-radius: 8px; padding: 6px 12px; font-weight: 500; color: var(--text); }
.seg button.active { background: var(--bg-2); font-weight: 600; box-shadow: 0 3px 8px rgba(0,0,0,.12), 0 3px 1px rgba(0,0,0,.04); }
[data-theme="dark"] .seg button.active { background: #636366; }
.input, select.input, textarea.input { border: 0; background: var(--bg-3); border-radius: 12px; }
[data-theme="light"] .card .input, [data-theme="light"] .sheet .input { background: #f2f2f7; }
.input:focus { box-shadow: 0 0 0 3px var(--accent-soft); background: var(--bg-2); }
.sheet { border-radius: 14px 14px 0 0; background: var(--bg-2); }
@media (min-width: 700px) { .sheet { border-radius: 18px; } }
.topbar { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; transition: background .2s; }
.topbar.scrolled { background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: .5px solid var(--line); }
.topbar .title { font-size: 17px; font-weight: 600; text-align: center; transition: opacity .18s; }
.topbar.has-large .title { opacity: 0; }
.topbar.has-large.collapsed .title { opacity: 1; }
.large-title { font-size: 34px; font-weight: 700; padding: 0 16px; max-width: 860px; margin: 2px auto 4px; line-height: 1.15; }
.large-title.hidden { display: none; }
.bottomnav { background: color-mix(in srgb, var(--bg-2) 80%, transparent); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-top: .5px solid var(--line); }
.bottomnav a { font-weight: 500; font-size: 10px; }
.bottomnav a.active { color: var(--accent); }
.sidenav { background: color-mix(in srgb, var(--bg-2) 70%, var(--bg)); border-right: .5px solid var(--line); }
.hero { border-radius: 24px; background:
  radial-gradient(120% 140% at 0% 0%, color-mix(in srgb, var(--accent) 70%, #fff) 0%, transparent 55%),
  radial-gradient(120% 120% at 100% 100%, color-mix(in srgb, var(--accent) 60%, #000) 0%, transparent 60%), var(--accent); }
.module { background: transparent; padding: 6px 2px; }
.module .ic { width: 58px; height: 58px; border-radius: 16px; background: var(--bg-2); box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 16px rgba(0,0,0,.05); }
[data-theme="dark"] .module .ic { background: var(--bg-3); }
.post { border-radius: 18px; }
.msg { border-radius: 20px; }
.msg.me { background: var(--accent); }
.story .avatar { box-shadow: 0 0 0 2.5px var(--bg), 0 0 0 4.5px var(--accent); }

/* ---------- Photos (Apple Photos style) ---------- */
.memory { position: relative; display: block; width: 100%; aspect-ratio: 4 / 3; max-height: 460px; border: 0; padding: 0; border-radius: 22px; overflow: hidden; cursor: pointer; background: #111; margin-bottom: 8px; }
.memory img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transform: scale(1.04); transition: opacity 1.4s ease, transform 6s linear; }
.memory img.on { opacity: 1; transform: scale(1.14); }
.memory-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0) 45%, rgba(0,0,0,.65)); }
.memory-text { position: absolute; left: 18px; right: 70px; bottom: 16px; color: #fff; text-align: left; display: flex; flex-direction: column; gap: 2px; }
.memory-text span { font-size: 11px; font-weight: 700; letter-spacing: .12em; opacity: .85; }
.memory-text b { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.memory-text small { font-size: 13px; opacity: .85; }
.memory-play { position: absolute; right: 16px; bottom: 18px; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: rgba(255,255,255,.22); backdrop-filter: blur(10px); }
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 2px 10px; flex-wrap: wrap; }
.lib-head h2 { font-size: 22px; font-weight: 700; }
.pgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; margin: 0 -16px; }
@media (min-width: 640px) { .pgrid { grid-template-columns: repeat(5, 1fr); margin: 0; border-radius: 14px; overflow: hidden; } }
.pgrid-head { grid-column: 1 / -1; padding: 14px 16px 6px; font-weight: 700; font-size: 17px; background: var(--bg); position: sticky; top: calc(var(--head-h) + var(--safe-t)); z-index: 2; }
.pcell { position: relative; aspect-ratio: 1; border: 0; padding: 0; background: var(--bg-3); cursor: pointer; overflow: hidden; }
.pcell img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s, filter .2s; }
.pcell:active img { filter: brightness(.85); }
.pbadge { position: absolute; right: 5px; bottom: 5px; color: #fff; background: rgba(0,0,0,.45); border-radius: 8px; padding: 2px 4px; display: grid; place-items: center; }
.library.months, .library.years { display: flex; flex-direction: column; gap: 14px; }
.period-card { position: relative; border: 0; padding: 0; border-radius: 20px; overflow: hidden; cursor: pointer; background: var(--bg-3); aspect-ratio: 16 / 10; text-align: left; transition: transform .2s; }
.period-card.years { aspect-ratio: 4 / 3; }
.period-card:active { transform: scale(.985); }
.collage { position: absolute; inset: 0; display: grid; grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; gap: 2px; }
.collage img { width: 100%; height: 100%; object-fit: cover; }
.collage .c-full { grid-column: 1 / -1; grid-row: 1 / -1; }
.collage .c-main { grid-row: 1 / -1; }
.period-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,.45) 0%, rgba(0,0,0,0) 38%); }
.period-label { position: absolute; left: 16px; top: 14px; color: #fff; display: flex; flex-direction: column; }
.period-label b { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.period-card.years .period-label b { font-size: 38px; }
.period-label span { font-size: 13px; opacity: .9; }
.stack-row { display: flex; gap: 18px; overflow-x: auto; padding: 14px 4px 10px; scrollbar-width: none; scroll-snap-type: x mandatory; }
.stack-row::-webkit-scrollbar { display: none; }
.stack-card { flex: none; width: 150px; border: 0; background: none; padding: 0; text-align: left; cursor: pointer; scroll-snap-align: start; color: var(--text); }
.stack { position: relative; width: 150px; height: 150px; margin-bottom: 10px; }
.stack img, .stack .empty { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.18); background: var(--bg-3); transition: transform .35s cubic-bezier(.2,.9,.3,1); }
.stack .s3 { transform: rotate(-7deg) translate(-6px, 4px) scale(.94); filter: brightness(.85); }
.stack .s2 { transform: rotate(5deg) translate(6px, 2px) scale(.97); filter: brightness(.92); }
.stack-card:hover .s3 { transform: rotate(-11deg) translate(-14px, 4px) scale(.94); }
.stack-card:hover .s2 { transform: rotate(9deg) translate(14px, 0) scale(.97); }
.stack-card:hover .s1 { transform: translateY(-4px); }
.stack-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stack-count { color: var(--muted); font-size: 13px; }
.people-row { display: flex; gap: 16px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: none; }
.person-bubble { flex: none; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; color: var(--text); font-size: 13px; font-weight: 500; }
.upload-preview img { width: 100%; max-height: 340px; object-fit: cover; border-radius: 16px; }
.empty-hero { text-align: center; padding: 50px 20px; }
.empty-stack { position: relative; width: 120px; height: 120px; margin: 0 auto 24px; }
.empty-stack span { position: absolute; inset: 0; border-radius: 20px; background: var(--bg-2); box-shadow: 0 6px 20px rgba(0,0,0,.1); display: grid; place-items: center; color: var(--accent); }
.empty-stack span:nth-child(1) { transform: rotate(-10deg) translateX(-14px); opacity: .6; }
.empty-stack span:nth-child(2) { transform: rotate(8deg) translateX(14px); opacity: .8; }

/* ---------- Full-screen viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 150; color: #fff; touch-action: none; opacity: 0; transition: opacity .22s; }
.viewer.open { opacity: 1; }
.viewer.closing { opacity: 0; }
.viewer-bg { position: absolute; inset: 0; background: #000; }
.viewer-track { position: absolute; inset: 0; display: flex; transform: translateX(-100%); }
.vslide { flex: none; width: 100%; height: 100%; display: grid; place-items: center; overflow: hidden; }
.vslide img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-drag: none; will-change: transform; }
.viewer-top, .viewer-bottom { position: absolute; left: 0; right: 0; z-index: 2; transition: opacity .2s; background: color-mix(in srgb, #000 55%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.viewer-top { top: 0; padding: calc(8px + var(--safe-t)) 10px 8px; display: flex; align-items: center; gap: 10px; }
.viewer-meta { flex: 1; text-align: center; display: flex; flex-direction: column; min-width: 0; }
.viewer-meta b { font-size: 15px; } .viewer-meta span { font-size: 12px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-bottom { bottom: 0; padding: 8px 10px calc(10px + var(--safe-b)); }
.viewer-strip { display: flex; gap: 2px; overflow-x: auto; justify-content: safe center; padding-bottom: 8px; scrollbar-width: none; }
.viewer-strip img { width: 34px; height: 46px; object-fit: cover; border-radius: 4px; opacity: .55; cursor: pointer; flex: none; transition: all .2s; }
.viewer-strip img.on { opacity: 1; width: 52px; margin: 0 4px; }
.viewer-tools { display: flex; align-items: center; justify-content: space-between; }
.viewer-count { font-size: 13px; opacity: .8; }
.vbtn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: #fff; display: grid; place-items: center; cursor: pointer; }
.vbtn:hover { background: rgba(255,255,255,.12); }
.viewer.bare .viewer-top, .viewer.bare .viewer-bottom, .viewer.playing .viewer-bottom { opacity: 0; pointer-events: none; }
.viewer.playing .vslide img { animation: kenburns 3.5s ease-out both; }
@keyframes kenburns { from { transform: scale(1); } to { transform: scale(1.08); } }
.large-title:not(.hidden) + .page { padding-top: 6px; }

/* mentions, audience, chat extras */
.mention-box { position: relative; z-index: 5; margin-top: 4px; background: var(--bg-2); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.18); overflow: hidden; }
.mention-box button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 12px; border: 0; background: transparent; cursor: pointer; text-align: left; font-size: 15px; }
.mention-box button:hover { background: var(--bg-3); }
a.mention { color: var(--accent); font-weight: 600; }
.aud-pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; color: var(--muted); }
.msg .quote { border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--text) 6%, transparent); border-radius: 8px; padding: 4px 8px; margin: 2px 0 4px; font-size: 13px; cursor: pointer; }
.msg.me .quote { border-left-color: #fff; background: rgba(255,255,255,.18); }
.msg .quote b { display: block; font-size: 12px; }
.msg .quote span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; opacity: .85; }
.msg.deleted { font-style: italic; opacity: .65; }
.msg .doc { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: color-mix(in srgb, var(--text) 6%, transparent); color: inherit; margin-bottom: 4px; min-width: 200px; }
.msg.me .doc { background: rgba(255,255,255,.18); }
.msg .doc b { display: block; font-size: 14px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .doc small { opacity: .75; }
.msg.flash { animation: flash 1.2s; }
@keyframes flash { 30% { box-shadow: 0 0 0 3px var(--accent); } }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg-2); border-top: .5px solid var(--line); }
.reply-bar .grow { border-left: 3px solid var(--accent); padding-left: 8px; min-width: 0; }
.reply-bar b { font-size: 13px; color: var(--accent); } .reply-bar span { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.emoji-row { display: flex; justify-content: space-between; background: var(--bg-3); border-radius: 30px; padding: 6px 10px; margin-bottom: 12px; }
.emoji-row button { border: 0; background: none; font-size: 28px; cursor: pointer; transition: transform .12s; }
.emoji-row button:active { transform: scale(1.3); }
.thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chips .chip.active { background: var(--accent); color: #fff; }
.upload-progress { height: 6px; border-radius: 3px; background: var(--bg-3); overflow: hidden; } .upload-progress i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

body.viewer-open .backdrop { z-index: 160; }
body.viewer-open .sheet { z-index: 170; }
body.viewer-open .menu, body.viewer-open #toasts { z-index: 180; }
