:root {
  --ink: #1A1A2E;
  --ground: #F4F6FB;
  --card: #FFFFFF;
  --muted: #5B5E73;
  --line: #E4E6F0;
  --accent: #FF6B35;
  --accent-soft: #FFE1D4;
  --teal: #0E7C7B;
  --danger: #C81E3A;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ground); color: var(--ink); font-family: var(--font); font-size: 16px; }
body { overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
a { color: var(--teal); }
a.btn, a.tab, a.family-card, a.chat-row { text-decoration: none; }
svg { display: block; }
.hidden { display: none !important; }

#app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.splash { margin: auto; font: 800 40px/1 var(--display); letter-spacing: -0.02em; }

/* ---------- shared pieces ---------- */
.screen { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(var(--safe-top) + 20px) 18px 24px; display: flex; flex-direction: column; gap: 16px; }
.screen.with-tabs { padding-bottom: calc(var(--safe-bottom) + 100px); }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.h1 { margin: 0; font: 800 34px/1.05 var(--display); letter-spacing: -0.02em; }
.h2 { margin: 0; font: 700 20px/1.2 var(--display); }
.label { font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.icon-btn { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--card); color: var(--ink); flex: none; }
.icon-btn.dark { background: var(--ink); color: #fff; }

.btn { min-height: 52px; border-radius: 18px; padding: 0 20px; font-weight: 700; font-size: 17px; display: flex; align-items: center; justify-content: center; gap: 10px; background: var(--ink); color: #fff; width: 100%; }
.btn.accent { background: var(--accent); color: var(--ink); }
.btn.light { background: var(--card); color: var(--ink); }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid #F3C4CC; }
.btn.small-btn { min-height: 40px; border-radius: 14px; font-size: 15px; width: auto; padding: 0 14px; }
.btn:disabled { opacity: 0.55; }

.card { background: var(--card); border-radius: 24px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
.input { height: 50px; border-radius: 16px; border: 1.5px solid var(--line); background: var(--card); padding: 0 16px; font-size: 17px; color: var(--ink); width: 100%; }
.input:focus { outline: none; border-color: var(--ink); }

.avatar { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; color: var(--ink); }
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.avatar.on-dark { color: #fff; }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--safe-bottom) + 100px); background: var(--ink); color: #fff; border-radius: 16px; padding: 14px 16px; font-size: 15px; z-index: 50; }

/* ---------- welcome / join ---------- */
.hero { position: relative; overflow: hidden; background: var(--ink); color: #fff; border-radius: 32px; padding: 32px 24px 28px; display: flex; flex-direction: column; gap: 14px; }
.hero .blob { position: absolute; border-radius: 50%; }
.hero .b1 { width: 200px; height: 200px; right: -60px; top: -70px; background: var(--accent); }
.hero .b2 { width: 90px; height: 90px; right: 70px; top: 100px; background: #8B7CFF; }
.hero .b3 { width: 56px; height: 56px; right: 20px; top: 150px; background: #F2B705; }
.hero h1 { position: relative; margin: 0; font: 800 46px/0.95 var(--display); letter-spacing: -0.03em; max-width: 230px; }
.hero p { position: relative; margin: 0; font-size: 17px; line-height: 1.45; color: #D9DAEA; }
.pill { position: relative; align-self: flex-start; background: var(--accent); color: var(--ink); font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; padding: 7px 12px; border-radius: 999px; }
.steps { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 8px; line-height: 1.4; }

.swatches { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; }
.swatch { aspect-ratio: 1; border-radius: 50%; border: 3px solid transparent; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--ground), 0 0 0 5px var(--ink); }

/* ---------- chats list ---------- */
.people { display: flex; gap: 14px; overflow-x: auto; padding: 4px 2px 2px; scrollbar-width: none; }
.people::-webkit-scrollbar { display: none; }
.person { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; min-width: 56px; }
.person .avatar { width: 54px; height: 54px; font-size: 18px; }

.family-card { position: relative; overflow: hidden; text-align: left; background: var(--accent); color: var(--ink); border-radius: 28px; padding: 20px; display: flex; flex-direction: column; gap: 10px; width: 100%; }
.family-card::after { content: ""; position: absolute; right: -40px; top: -40px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255, 255, 255, 0.22); }
.family-card > * { position: relative; z-index: 1; }
.family-card .name { font: 800 26px/1.1 var(--display); }
.family-card .preview { font-size: 16px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.family-card .foot { display: flex; align-items: center; justify-content: space-between; }
.stack { display: flex; }
.stack .avatar { border: 2px solid var(--accent); margin-left: -8px; }
.stack .avatar:first-child { margin-left: 0; }

.badge { min-width: 24px; height: 24px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; padding: 0 7px; }

.chat-list { display: flex; flex-direction: column; gap: 2px; }
.chat-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; width: 100%; text-align: left; border-radius: 18px; }
.chat-row:active { background: rgba(26, 26, 46, 0.05); }
.chat-row .mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-row .who { font-weight: 700; font-size: 16px; }
.chat-row .what { font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row .what.unread { color: var(--ink); font-weight: 600; }
.chat-row .side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: 13px; color: var(--muted); }
.group-icon { background: var(--ink); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; line-height: 1.5; }

/* ---------- tab bar ---------- */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(255, 255, 255, 0.96); border-top: 1px solid var(--line); display: flex; justify-content: space-around; padding: 8px 8px calc(var(--safe-bottom) + 8px); z-index: 10; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; font-weight: 500; color: var(--muted); min-width: 64px; }
.tab .ic { padding: 4px 16px; border-radius: 999px; display: flex; }
.tab.active { color: var(--ink); font-weight: 700; }
.tab.active .ic { background: var(--accent-soft); }

/* ---------- conversation ---------- */
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-head { background: var(--card); padding: calc(var(--safe-top) + 8px) 10px 10px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.chat-head .back { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; color: var(--ink); }
.chat-head .t { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-head .t b { font: 800 19px/1.2 var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .t span { font-size: 13px; color: var(--muted); }
.head-icon { width: 44px; height: 44px; border-radius: 16px; display: flex; align-items: center; justify-content: center; flex: none; }

.msgs { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; background: var(--line); color: #3E4157; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 5px 12px; border-radius: 999px; margin: 10px 0 6px; }
.sys { align-self: center; font-size: 13px; color: var(--muted); padding: 4px 0; text-align: center; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 82%; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg .spacer { width: 30px; flex: none; }
.msg .col { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.msg.me .col { align-items: flex-end; }
.bubble { background: var(--card); border-radius: 20px 20px 20px 6px; padding: 9px 14px; font-size: 16px; line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--accent); border-radius: 20px 20px 6px 20px; }
.bubble .from { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.bubble .from i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.bubble.photo { padding: 4px; background: var(--card); }
.msg.me .bubble.photo { background: var(--accent); }
.bubble.photo img { display: block; max-width: 230px; max-height: 300px; border-radius: 16px; object-fit: cover; }
.meta { font-size: 12px; color: var(--muted); padding: 0 4px; display: flex; align-items: center; gap: 4px; }
.msg.pending .bubble { opacity: 0.6; }

.composer { background: var(--card); border-top: 1px solid var(--line); padding: 8px 10px calc(var(--safe-bottom) + 8px); display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; min-width: 0; min-height: 44px; max-height: 140px; resize: none; border: none; border-radius: 22px; background: var(--ground); padding: 11px 16px; font-size: 16px; line-height: 22px; }
.composer textarea:focus { outline: none; }
.composer .icon-btn { background: var(--ground); }
.composer .send { background: var(--ink); color: #fff; }

/* ---------- sheets ---------- */
.overlay { position: fixed; inset: 0; background: rgba(26, 26, 46, 0.4); z-index: 30; display: flex; align-items: flex-end; }
.sheet { width: 100%; max-height: 88dvh; overflow-y: auto; background: var(--ground); border-radius: 28px 28px 0 0; padding: 12px 18px calc(var(--safe-bottom) + 20px); display: flex; flex-direction: column; gap: 14px; }
.grabber { align-self: center; width: 40px; height: 5px; border-radius: 3px; background: #C9CBD8; }
.check-row { display: flex; align-items: center; gap: 12px; padding: 8px 4px; font-size: 16px; }
.check-row input { width: 22px; height: 22px; accent-color: var(--ink); }

/* ---------- settings ---------- */
.list-row { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.list-row .grow { flex: 1; min-width: 0; }
.link-box { background: var(--ground); border-radius: 14px; padding: 12px; font-size: 14px; word-break: break-all; user-select: all; -webkit-user-select: all; }
.row-gap { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- install.php ---------- */
.setup { display: flex; min-height: 100%; padding: 24px 16px; }
.setup-card { margin: auto; width: 100%; max-width: 480px; background: var(--card); border-radius: 28px; padding: 28px 24px; display: flex; flex-direction: column; gap: 14px; line-height: 1.5; }
.setup-card h1 { margin: 0; font: 800 30px/1.1 var(--display); }
.setup-card form { display: flex; flex-direction: column; gap: 14px; }
.setup-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.setup-card input { height: 48px; border-radius: 14px; border: 1.5px solid var(--line); padding: 0 14px; font-size: 16px; }
.setup-card button { height: 50px; border-radius: 16px; background: var(--ink); color: #fff; font-weight: 700; font-size: 16px; }
.setup-link { background: var(--ground); border-radius: 14px; padding: 12px; word-break: break-all; font-weight: 600; }
