:root {
  color-scheme: light dark;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --blue: #007aff;
  --bubble: #0b84fe;
  --bg: #ffffff;
  --text: #000000;
  --text2: rgba(60, 60, 67, .6);
  --text3: rgba(60, 60, 67, .3);
  --sep: rgba(60, 60, 67, .29);
  --fill: rgba(118, 118, 128, .12);
  --red: #ff3b30;
  --green: #34c759;
  --bar: rgba(249, 249, 249, .94);
  --field-border: rgba(60, 60, 67, .26);
  --sheet: #f2f2f7;
  --sheet-card: #ffffff;
  --note: #f2f2f7;
  --alert: rgba(242, 242, 242, .96);
  --toast: rgba(255, 255, 255, .98);
}
@media (prefers-color-scheme: dark) {
  :root {
    --blue: #0a84ff;
    --bubble: #0a84ff;
    --bg: #000000;
    --text: #ffffff;
    --text2: rgba(235, 235, 245, .6);
    --text3: rgba(235, 235, 245, .3);
    --sep: rgba(84, 84, 88, .65);
    --fill: rgba(118, 118, 128, .24);
    --red: #ff453a;
    --green: #30d158;
    --bar: rgba(18, 18, 20, .94);
    --field-border: rgba(84, 84, 88, .8);
    --sheet: #1c1c1e;
    --sheet-card: #2c2c2e;
    --note: #1c1c1e;
    --alert: rgba(44, 44, 46, .97);
    --toast: rgba(44, 44, 46, .98);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 17px; -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; }
button:disabled { cursor: default; }
svg { display: block; }

#app { position: fixed; left: 0; right: 0; top: 0; height: var(--app-h, 100dvh); overflow: hidden; }

/* ---------- screens ---------- */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg);
  transition: transform .4s cubic-bezier(.2, .85, .25, 1);
}
.screen.chat { transform: translateX(100%); z-index: 2; box-shadow: -10px 0 30px rgba(0, 0, 0, .1); }
#app.chat-open .screen.chat { transform: none; }
#app.chat-open #list-screen { transform: translateX(-28%); }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }

/* ---------- nav bars ---------- */
.nav { flex: none; position: relative; z-index: 3; padding-top: env(safe-area-inset-top); border-bottom: .5px solid transparent; transition: border-color .2s, background-color .2s; }
.nav.solid, .nav.scrolled { background: var(--bar); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px); }
.nav.scrolled, .nav.solid { border-bottom-color: var(--sep); }
.nav-row { height: 44px; display: flex; align-items: center; justify-content: space-between; padding: 0 6px; }
.nav-title { font-weight: 600; font-size: 17px; opacity: 0; transition: opacity .2s; }
.nav.scrolled .nav-title { opacity: 1; }
.nav-icon { width: 44px; height: 44px; display: grid; place-items: center; color: var(--blue); }
.nav-icon svg { width: 24px; height: 24px; }
.large-title { font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: .37px; margin: 0 16px 10px; }

/* ---------- avatars ---------- */
.avatar { width: var(--s); height: var(--s); border-radius: 50%; object-fit: cover; display: block; flex: none; background: linear-gradient(180deg, #a5abb8, #858994); }
.avatar.initials { display: grid; place-items: center; color: #fff; font-weight: 600; font-size: calc(var(--s) * .4); letter-spacing: .3px; overflow: hidden; }
.avatar.initials svg { width: 70%; height: 70%; margin-top: 30%; color: rgba(255, 255, 255, .95); }

/* ---------- conversation list ---------- */
.convos { list-style: none; margin: 0; padding: 0; }
.convo { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 0 0 0 16px; transition: background-color .15s; }
.convo:active { background: var(--fill); }
.convo .avatar { margin: 10px 0; }
.convo-body { flex: 1; min-width: 0; align-self: stretch; display: flex; flex-direction: column; justify-content: center; padding: 10px 16px 10px 0; border-bottom: .5px solid var(--sep); }
.convos li:last-child .convo-body { border-bottom: 0; }
.convo-top { display: flex; align-items: baseline; gap: 8px; }
.convo-name { flex: 1; font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo-time { flex: none; color: var(--text2); font-size: 15px; display: flex; align-items: center; gap: 6px; }
.convo-time svg { color: var(--text3); }
.convo-preview { color: var(--text2); font-size: 15px; line-height: 20px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; min-height: 40px; overflow-wrap: anywhere; }

.empty { text-align: center; padding: 56px 32px 0; }
.empty .empty-art { width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 22px; overflow: hidden; }
.empty .empty-art img { width: 100%; height: 100%; display: block; }
.empty h2 { font-size: 22px; font-weight: 700; margin: 0 0 8px; }
.empty p { font-size: 16px; line-height: 22px; color: var(--text2); margin: 0 0 24px; }

/* notes on the main screen (backup / install) */
.note { display: flex; gap: 12px; margin: 0 16px 12px; padding: 14px 14px 12px; border-radius: 14px; background: var(--note); position: relative; }
.note-icon { width: 30px; height: 30px; border-radius: 50%; background: var(--blue); color: #fff; display: grid; place-items: center; flex: none; }
.note-icon svg { width: 17px; height: 17px; }
.note-body { flex: 1; min-width: 0; }
.note-title { font-weight: 600; font-size: 15px; line-height: 20px; }
.note-text { font-size: 14px; color: var(--text2); margin-top: 2px; line-height: 19px; }
.note-actions { display: flex; gap: 20px; margin-top: 8px; }
.note-actions button { color: var(--blue); font-size: 15px; font-weight: 600; padding: 4px 0; }
.note-actions button.quiet { font-weight: 400; color: var(--text2); }
.inline-icon { display: inline-block; vertical-align: -3px; width: 16px; height: 16px; color: var(--blue); }

/* ---------- chat ---------- */
.chat-nav .nav-row { height: auto; min-height: 44px; padding: 2px 6px 6px; position: relative; justify-content: center; }
.back { position: absolute; left: 0; top: 4px; height: 44px; display: flex; align-items: center; color: var(--blue); padding: 0 14px 0 10px; }
.chat-who { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 2px 12px; max-width: 70%; }
.chat-name { font-size: 12px; display: flex; align-items: center; gap: 3px; color: var(--text); max-width: 100%; }
.chat-name span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-name svg { color: var(--text3); flex: none; width: 6px; height: 10px; }

.msgs { display: flex; flex-direction: column; padding: 8px 0 6px; }
.msgs > :first-child { margin-top: auto; }
.chat-intro { text-align: center; padding: 24px 40px 16px; display: flex; flex-direction: column; align-items: center; }
.chat-intro .ci-name { font-size: 20px; font-weight: 600; margin-top: 10px; }
.chat-intro .ci-text { font-size: 14px; line-height: 19px; color: var(--text2); margin-top: 6px; }
.stamp { text-align: center; font-size: 11px; color: var(--text2); margin: 16px 0 6px; font-weight: 400; }
.stamp b { font-weight: 600; }
.row { display: flex; flex-direction: column; align-items: flex-end; padding: 0 17px 0 64px; margin-top: 2px; }
.row.gap { margin-top: 9px; }
.bubble {
  background: var(--bubble); color: #fff; padding: 7px 12px 8px; border-radius: 18px; font-size: 17px; line-height: 22px;
  max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; position: relative; z-index: 0;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  transition: transform .15s, filter .15s; transform-origin: bottom right;
}
.bubble.tail::before { content: ""; position: absolute; z-index: -1; bottom: 0; right: -8px; height: 20px; width: 20px; background: var(--bubble); border-bottom-left-radius: 16px 14px; }
.bubble.tail::after { content: ""; position: absolute; z-index: -1; bottom: 0; right: -10px; width: 10px; height: 20px; background: var(--bg); border-bottom-left-radius: 10px; }
.bubble.emoji { background: none; font-size: 44px; line-height: 52px; padding: 0 2px; }
.bubble.emoji::before, .bubble.emoji::after { display: none; }
.bubble-img { display: block; max-width: min(240px, 100%); max-height: 320px; border-radius: 18px; object-fit: cover; margin-bottom: 2px; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; transition: transform .15s, filter .15s; transform-origin: bottom right; background: var(--fill); }
.row.pressed .bubble, .row.pressed .bubble-img { transform: scale(.96); filter: brightness(.9); }
.row.new .bubble, .row.new .bubble-img { animation: pop .38s cubic-bezier(.2, .9, .3, 1.15); }
@keyframes pop { from { transform: translateY(14px) scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }
.receipt { align-self: flex-end; padding: 3px 18px 0; font-size: 11px; line-height: 14px; color: var(--text2); min-height: 17px; }
.receipt b { font-weight: 600; }
.receipt.changed { animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.composer { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 6px 10px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); }
#app.kb .composer { padding-bottom: 8px; }
.comp-plus { width: 34px; height: 34px; border-radius: 50%; background: var(--fill); display: grid; place-items: center; color: var(--text2); flex: none; margin-bottom: 1px; }
.comp-plus svg { width: 18px; height: 18px; }
.comp-field { flex: 1; min-width: 0; border: 1px solid var(--field-border); border-radius: 18px; display: flex; flex-direction: column; position: relative; }
.comp-field textarea {
  font: inherit; font-size: 17px; line-height: 22px; border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  padding: 6px 40px 6px 12px; max-height: 136px; display: block; width: 100%; margin: 0; min-height: 34px;
}
.comp-field textarea::placeholder { color: var(--text3); }
.send { position: absolute; right: 3px; bottom: 3px; width: 28px; height: 28px; border-radius: 50%; background: var(--blue); color: #fff; display: grid; place-items: center; transition: opacity .15s, transform .15s; }
.send svg { width: 16px; height: 16px; }
.send:disabled { opacity: 0; transform: scale(.5); pointer-events: none; }
.comp-attach { padding: 8px 8px 2px; position: relative; align-self: flex-start; }
.comp-attach img { display: block; max-width: 140px; max-height: 140px; border-radius: 14px; }
.comp-attach .remove { position: absolute; top: 2px; right: -6px; width: 24px; height: 24px; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; display: grid; place-items: center; }
.comp-attach .remove svg { width: 10px; height: 10px; }

/* ---------- sheets ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; }
.sheet-back { position: absolute; inset: 0; background: rgba(0, 0, 0, .38); opacity: 0; transition: opacity .3s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: calc(100% - env(safe-area-inset-top) - 10px);
  background: var(--sheet); border-radius: 14px 14px 0 0; transform: translateY(100%); transition: transform .4s cubic-bezier(.2, .85, .25, 1);
  display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom);
}
.sheet.tall { height: calc(100% - env(safe-area-inset-top) - 10px); }
.sheet-wrap.open .sheet-back { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--text3); margin: 6px auto 0; flex: none; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 4px 6px 8px; flex: none; }
.sheet-head h2 { font-size: 17px; font-weight: 600; margin: 0; text-align: center; }
.sheet-head > :first-child { justify-self: start; }
.sheet-head > :last-child { justify-self: end; }
.link { color: var(--blue); font-size: 17px; padding: 10px; }
.link.bold { font-weight: 600; }
.link:disabled { color: var(--text3); }
.link.small { font-size: 15px; padding: 4px 8px; }
.sheet-body { overflow-y: auto; padding: 6px 0 24px; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-body.compact { padding-top: 12px; padding-bottom: 8px; }

.group { background: var(--sheet-card); border-radius: 10px; margin: 0 16px; overflow: hidden; }
.group + .group { margin-top: 10px; }
.cell { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 11px 16px; text-align: left; position: relative; font-size: 17px; line-height: 22px; color: var(--text); }
.cell + .cell::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--sep); }
.group.icons .cell + .cell::before { left: 56px; }
button.cell:active { background: var(--fill); }
button.cell:disabled { opacity: .5; }
.cell.blue { color: var(--blue); }
.cell.red { color: var(--red); }
.cell.center { justify-content: center; }
.cell.bold { font-weight: 600; }
.cell .val { margin-left: auto; color: var(--text2); text-align: right; }
.cell .check { margin-left: auto; color: var(--blue); }
.cell .check svg { width: 18px; height: 18px; }
.cell .chev { margin-left: auto; color: var(--text3); }
.cell-icon { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; color: #fff; flex: none; background: var(--blue); }
.cell-icon svg { width: 17px; height: 17px; }
.cell-icon.green { background: var(--green); }
.cell-icon.gray { background: #8e8e93; }
.cell-icon.indigo { background: #5856d6; }
.cell-input { display: block; width: 100%; border: 0; outline: 0; background: transparent; font: inherit; font-size: 17px; color: var(--text); padding: 11px 16px; min-height: 44px; }
.section-label { font-size: 13px; text-transform: uppercase; color: var(--text2); margin: 24px 32px 7px; letter-spacing: -.08px; }
.section-label:first-child { margin-top: 8px; }
.footnote { font-size: 13px; color: var(--text2); margin: 7px 32px 0; line-height: 18px; }
.footnote b { color: var(--text); font-weight: 600; }
.who-edit { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 6px 0 22px; }
.who-edit .photo-pick { border-radius: 50%; }
.prose { margin: 0 32px; font-size: 15px; line-height: 21px; color: var(--text2); }
.prose p { margin: 0 0 10px; }

.btn { display: block; width: calc(100% - 32px); margin: 0 16px; height: 50px; border-radius: 12px; background: var(--blue); color: #fff; font-weight: 600; font-size: 17px; }
.btn:disabled { opacity: .5; }
.btn.secondary { background: transparent; color: var(--blue); font-weight: 400; height: 44px; margin-top: 4px; }

.welcome { padding: 24px 0 8px; }
.welcome .w-icon { width: 76px; height: 76px; border-radius: 18px; margin: 4px auto 14px; overflow: hidden; box-shadow: 0 4px 14px rgba(0, 0, 0, .12); }
.welcome .w-icon img { width: 100%; height: 100%; display: block; }
.welcome h1 { text-align: center; font-size: 30px; line-height: 36px; font-weight: 700; margin: 0 32px 26px; }
.feature { display: flex; gap: 16px; margin: 0 36px 22px; align-items: flex-start; }
.feature .f-icon { color: var(--blue); flex: none; width: 34px; display: grid; place-items: center; padding-top: 2px; }
.feature .f-icon svg { width: 28px; height: 28px; }
.feature h4 { margin: 0; font-size: 15px; font-weight: 600; line-height: 20px; }
.feature p { margin: 2px 0 0; font-size: 15px; color: var(--text2); line-height: 20px; }

/* ---------- alerts ---------- */
.alert-wrap { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(0, 0, 0, .38); opacity: 0; transition: opacity .2s; padding: 24px; }
.alert-wrap.open { opacity: 1; }
.alert { width: 270px; max-width: 100%; background: var(--alert); border-radius: 14px; overflow: hidden; text-align: center; transform: scale(1.12); transition: transform .22s cubic-bezier(.2, .9, .3, 1.1); }
.alert-wrap.open .alert { transform: none; }
.alert-text { padding: 19px 16px 18px; }
.alert-text h3 { font-size: 17px; font-weight: 600; margin: 0 0 3px; line-height: 22px; }
.alert-text p { font-size: 13px; margin: 0; line-height: 17px; }
.alert-btns { display: flex; border-top: .5px solid var(--sep); }
.alert-btns.stack { flex-direction: column; }
.alert-btns button { flex: 1; min-height: 44px; color: var(--blue); font-size: 17px; padding: 8px; }
.alert-btns:not(.stack) button + button { border-left: .5px solid var(--sep); }
.alert-btns.stack button + button { border-top: .5px solid var(--sep); }
.alert-btns .bold { font-weight: 600; }
.alert-btns .danger { color: var(--red); }

/* ---------- photo viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 30; background: #000; display: grid; place-items: center; opacity: 0; transition: opacity .2s; }
.viewer.open { opacity: 1; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .v-close { position: absolute; top: calc(env(safe-area-inset-top) + 8px); left: 12px; color: #fff; font-size: 17px; padding: 10px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 8px); transform: translate(-50%, calc(-100% - 60px));
  background: var(--toast); color: var(--text); padding: 11px 18px; border-radius: 22px; font-size: 15px; font-weight: 500;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .18); transition: transform .4s cubic-bezier(.2, .85, .25, 1); z-index: 50;
  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 32px); white-space: nowrap;
}
#toast svg { color: var(--green); width: 18px; height: 18px; flex: none; }
#toast.show { transform: translate(-50%, 0); }

@media (min-width: 700px) {
  #app { max-width: 480px; margin: 0 auto; box-shadow: 0 0 0 .5px var(--sep); }
  .sheet { max-width: 480px; margin: 0 auto; }
}
