:root {
  --bg: #ffffff; --bar: rgba(246,246,246,.86); --bar-border: rgba(0,0,0,.12);
  --in: #e9e9eb; --in-text: #000; --out: #0b84fe; --out-text: #fff;
  --muted: #8e8e93; --field: #ffffff; --field-border: #c7c7cc; --accent: #0b84fe;
  --sheet: rgba(255,255,255,.96); --em: #3a3a3c;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --bar: rgba(22,22,24,.86); --bar-border: rgba(255,255,255,.12);
    --in: #26252a; --in-text: #fff; --out: #0a84ff; --muted: #8d8d93; --field: #000; --field-border: #3a3a3c;
    --sheet: rgba(36,36,38,.97); --em: #d1d1d6; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--in-text); }
body { overscroll-behavior: none; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* header */
.top { flex: none; background: var(--bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--bar-border); padding-top: env(safe-area-inset-top); z-index: 5; }
.top-inner { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px 6px; }
.icon-btn { color: var(--accent); width: 40px; height: 40px; display: grid; place-items: center; }
.right-spacer { width: 40px; }
.contact { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: #c7c7cc; display: block; }
.avatar.big { width: 84px; height: 84px; }
.name { font-size: 11.5px; display: flex; align-items: center; gap: 2px; color: var(--in-text); }
.name svg { color: var(--muted); }

/* messages */
main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 0 10px; }
#messages { display: flex; flex-direction: column; }
.stamp { text-align: center; color: var(--muted); font-size: 11.5px; margin: 14px 0 6px; }
.stamp b { font-weight: 600; }
.row { display: flex; padding: 0 14px; margin-top: 2px; }
.row.user { justify-content: flex-end; }
.row.gap { margin-top: 10px; }
.bubble { max-width: 76%; padding: 7px 12px 8px; border-radius: 18px; font-size: 16.5px; line-height: 1.32; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; position: relative; }
.row.char .bubble { background: var(--in); color: var(--in-text); }
.row.user .bubble { background: var(--out); color: var(--out-text); }
.row.char.tail .bubble { border-bottom-left-radius: 18px; }
.row.tail .bubble::before, .row.tail .bubble::after { content: ""; position: absolute; bottom: 0; height: 20px; }
.row.user.tail .bubble::before { right: -7px; width: 20px; background: var(--out); border-bottom-left-radius: 16px 14px; }
.row.user.tail .bubble::after { right: -26px; width: 26px; background: var(--bg); border-bottom-left-radius: 10px; }
.row.char.tail .bubble::before { left: -7px; width: 20px; background: var(--in); border-bottom-right-radius: 16px 14px; }
.row.char.tail .bubble::after { left: -26px; width: 26px; background: var(--bg); border-bottom-right-radius: 10px; }
.bubble em { font-style: italic; color: var(--em); opacity: .92; }
.row.user .bubble em { color: rgba(255,255,255,.88); }
.bubble.img { padding: 0; background: none !important; overflow: hidden; border-radius: 18px; }
.bubble.img::before, .bubble.img::after { display: none; }
.bubble.img img { display: block; max-width: 100%; width: 240px; border-radius: 18px; }
.delivered { text-align: right; color: var(--muted); font-size: 11px; padding: 2px 16px 0; }
.status-line { text-align: center; color: var(--muted); font-size: 12px; min-height: 0; padding: 4px 20px; }
.status-line.err { color: #ff3b30; }
.load-more { text-align: center; padding: 6px; }
.load-more button { color: var(--accent); font-size: 14px; }

/* typing */
.bubble.typing { display: inline-flex; gap: 4px; padding: 12px 14px; }
.bubble.typing span { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .4; animation: blink 1.3s infinite; }
.bubble.typing span:nth-child(2) { animation-delay: .18s; } .bubble.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .35; transform: translateY(0); } 30% { opacity: .9; transform: translateY(-2px); } }
.row.char.typingrow .bubble::before, .row.char.typingrow .bubble::after { display: none; }

/* composer */
.composer { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 6px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); }
.round-btn { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); background: var(--in); flex: none; margin-bottom: 1px; }
.round-btn:disabled { opacity: .5; }
.field { flex: 1; display: flex; align-items: flex-end; border: 1px solid var(--field-border); border-radius: 19px; background: var(--field); padding: 3px 3px 3px 12px; min-height: 38px; }
.field textarea { flex: 1; border: 0; outline: 0; resize: none; background: transparent; color: var(--in-text); font: inherit; font-size: 16.5px; line-height: 1.3; padding: 5px 0; max-height: 140px; }
.field textarea::placeholder { color: var(--muted); }
.send { width: 30px; height: 30px; border-radius: 50%; background: var(--out); display: grid; place-items: center; flex: none; transition: opacity .15s; }
.send:disabled { opacity: 0; pointer-events: none; }

/* sheet */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; z-index: 20; }
.sheet[hidden] { display: none; }
.sheet-card { width: 100%; background: var(--sheet); border-radius: 16px 16px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
.sheet-card .avatar { align-self: center; }
.sheet-name { text-align: center; font-weight: 600; font-size: 20px; margin-bottom: 8px; }
.sheet-card button { padding: 13px; border-radius: 12px; background: var(--in); color: var(--accent); font-size: 17px; }
.sheet-card .danger { color: #ff3b30; } .sheet-card .cancel { font-weight: 600; }
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); display: grid; place-items: center; z-index: 30; }
.viewer[hidden] { display: none; }
.viewer img { max-width: 100vw; max-height: 100vh; object-fit: contain; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100%; padding: 24px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.login-card h1 { margin: 4px 0 0; font-size: 26px; }
.muted { color: var(--muted); margin: 0; text-align: center; }
.login-card input { width: 100%; font-size: 17px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--field-border); background: var(--field); color: var(--in-text); outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card button { width: 100%; padding: 12px; border-radius: 12px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 600; }
.login-card button:disabled { opacity: .6; }
.err { color: #ff3b30; min-height: 1.2em; margin: 0; font-size: 14px; }

/* lock screen */
.lock { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: grid; place-items: center; padding: 24px; padding-top: calc(24px + env(safe-area-inset-top)); }
.lock[hidden] { display: none; }
.login-card .faceid { display: flex; align-items: center; justify-content: center; gap: 8px; }
.login-card .faceid[hidden] { display: none; }
.login-card #pwBtn.secondary { background: var(--in); color: var(--accent); font-weight: 500; }
.sheet-card p.muted { padding: 0 8px 8px; }

.notify-banner { margin: 10px 14px; padding: 10px 12px; border-radius: 14px; background: var(--in); display: flex; align-items: center; gap: 8px; font-size: 14px; }
.notify-banner[hidden] { display: none; }
.notify-banner span { flex: 1; }
.notify-banner button { color: #fff; background: var(--accent); border-radius: 10px; padding: 7px 10px; font-size: 14px; font-weight: 600; }
.notify-banner .x { background: none; color: var(--muted); padding: 4px 6px; }

/* small avatar next to Lili's bubbles (iMessage group style) */
.row.char { align-items: flex-end; gap: 10px; padding-left: 8px; }
.mini-av { width: 28px; height: 28px; border-radius: 50%; flex: none; object-fit: cover; display: block; position: relative; z-index: 2; }
span.mini-av { visibility: hidden; }
.row.char .bubble { max-width: calc(76% - 20px); }

/* memories page */
.mem-page { position: fixed; inset: 0; z-index: 25; background: var(--bg); display: flex; flex-direction: column; }
.mem-page[hidden] { display: none; }
.mem-title { font-weight: 600; font-size: 17px; }
.mem-body { flex: 1; overflow-y: auto; padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); }
.mem-intro { text-align: left; margin: 8px 0 12px; }
.mem-item { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 14px; background: var(--in); margin-bottom: 8px; }
.mem-item .t { flex: 1; font-size: 15px; line-height: 1.35; }
.mem-item .meta { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.mem-item button { color: #ff3b30; font-size: 14px; padding: 2px 4px; }
.mem-h { font-size: 15px; margin: 22px 0 6px; }
.mem-summary { white-space: pre-wrap; font-size: 14px; color: var(--em); line-height: 1.4; }
.bubble.img.pending img { opacity: .6; }
[hidden] { display: none !important; }
