:root {
  --bg: #1a1216;
  --bg-deep: #140d11;
  --bar: #3d1f2c;
  --teal: #ec4899;
  --accent: #ec4899;
  --teal-dim: #9d174d;
  --out: #9d2463;
  --in: #3a2430;
  --text: #fde8f0;
  --muted: #c4a4b2;
  --line: #4a2a38;
  --gold: #ffd279;
  --danger: #f15c6d;
  --fab: #ec4899;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html, body, input, textarea, button {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}
body {
  background: #0a0a0a;
  color: var(--text);
  overflow: hidden;
  word-spacing: normal;
  letter-spacing: 0;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 430px;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}

@media (min-width: 520px) {
  body { display: grid; place-items: center; }
  #app {
    height: min(844px, 96vh);
    border-radius: 28px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  }
}

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
[hidden] { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(10px + var(--safe-top)) 8px 10px 16px;
  background: var(--bar);
  min-height: 58px;
}
.topbar h1 { flex: 1; margin: 0; font-size: 1.25rem; font-weight: 600; }
.top-actions { display: flex; }
.icon-btn {
  width: 42px; height: 42px; border: 0; background: transparent; color: var(--text);
  border-radius: 50%; display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn.ghost { color: var(--muted); width: 36px; height: 36px; }
.icon-btn:active { background: rgba(255,255,255,.06); }

.search-row { background: var(--bar); padding: 0 12px 10px; }
.search-row input {
  width: 100%; border: 0; border-radius: 8px; background: #2a3942; color: var(--text);
  padding: 10px 12px; font: inherit;
}
.search-row input:focus { outline: 1px solid var(--teal); }

.tabs {
  display: grid;
  grid-template-columns: 48px 1fr 1fr 1fr;
  background: var(--bar);
  border-bottom: 1px solid #162026;
}
.tab {
  position: relative;
  border: 0; background: transparent; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; font-weight: 500;
  font-size: .8rem; padding: 12px 4px 14px; cursor: pointer;
}
.tab.camera { color: var(--muted); display: grid; place-items: center; }
.tab.camera svg { width: 22px; height: 22px; fill: currentColor; }
.tab.active { color: var(--teal); }
.tab.active::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px;
  background: var(--teal); border-radius: 3px 3px 0 0;
}
.tab-badge {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px;
  margin-left: 6px; padding: 0 5px; border-radius: 99px; background: var(--teal);
  color: #111; font-size: .65rem; font-weight: 700;
}

.lists { flex: 1; overflow: auto; background: var(--bg); }
.row-item {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 12px 16px; border: 0; background: transparent; color: inherit;
  text-align: left; cursor: pointer; font: inherit;
}
.row-item + .row-item { box-shadow: inset 72px 1px 0 var(--line); }
.row-item:active { background: #182229; }
.row-body { flex: 1; min-width: 0; }
.row-top { display: flex; justify-content: space-between; gap: 8px; }
.row-name { font-weight: 500; }
.row-time { color: var(--muted); font-size: .75rem; flex-shrink: 0; }
.row-time.unread { color: var(--teal); font-weight: 600; }
.row-sub { color: var(--muted); font-size: .84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; display: flex; align-items: center; gap: 4px; }
.unread-dot {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px;
  background: var(--teal); color: #052e26; font-size: .7rem; font-weight: 700;
  display: grid; place-items: center;
}
.section-label {
  color: var(--muted); font-size: .78rem; padding: 14px 16px 6px; text-transform: none;
}

.avatar {
  width: 52px; height: 52px; border-radius: 50%; background: #2a3942;
  background-size: cover; background-position: center; flex-shrink: 0;
}
.avatar.sm { width: 40px; height: 40px; }
.avatar.xl { width: 128px; height: 128px; }
.avatar.mosaic {
  display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; background: #203036;
}
.avatar.mosaic span { background-size: cover; background-position: center; }
.ring { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--teal); }
.ring.seen { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px #54656f; }

.fab {
  position: absolute; right: 16px; bottom: calc(18px + var(--safe-bot));
  width: 56px; height: 56px; border: 0; border-radius: 50%;
  background: var(--fab); color: #fff; display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.35); cursor: pointer;
}
.fab svg { width: 24px; height: 24px; fill: currentColor; }
.fab.mini {
  right: 22px; bottom: calc(84px + var(--safe-bot));
  width: 46px; height: 46px; background: #3b4a54;
}

.who { background: #0b141a; padding: 48px 22px 24px; overflow: auto; }
.who-brand { text-align: center; margin-bottom: 28px; }
.who-logo { width: 72px; height: 72px; }
.who h1 { margin: 12px 0 6px; font-size: 1.6rem; }
.who-brand p, .who h2 { color: var(--muted); font-weight: 400; }
.who h2 { font-size: 1rem; margin: 0 0 14px; }
.who-grid { display: grid; gap: 10px; }
.who-card {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 12px; border: 0; border-radius: 14px; background: var(--bar);
  color: inherit; font: inherit; cursor: pointer; text-align: left;
}
.who-card:active { filter: brightness(1.08); }
.who-card b { display: block; }
.who-card span { color: var(--muted); font-size: .85rem; }

.thread { background: var(--bg-deep); }
.thread-bar { padding-left: 4px; }
.thread-who { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.thread-who .meta { min-width: 0; }
.thread-who .meta b { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-who .meta small { color: var(--muted); font-size: .75rem; }

.thread-log {
  flex: 1; overflow: auto; padding: 12px 10px 8px;
  background: #0b141a url("wallpaper.svg") center / cover;
}
.day-pill, .lock-note {
  width: fit-content; max-width: 88%; margin: 8px auto;
  padding: 6px 12px; border-radius: 8px; text-align: center;
}
.day-pill { background: #182229; color: var(--muted); font-size: .75rem; letter-spacing: .04em; }
.lock-note { background: #1d282f; color: var(--gold); font-size: .72rem; line-height: 1.35; }

.bubble {
  max-width: 82%; margin: 3px 8px; padding: 6px 8px 4px;
  border-radius: 8px; position: relative; clear: both;
  box-shadow: 0 1px 0.5px rgba(0,0,0,.13);
}
.bubble.in { float: left; background: var(--in); }
.bubble.out { float: right; background: var(--out); }
.bubble .from { color: #53bdeb; font-size: .78rem; font-weight: 500; margin-bottom: 2px; }
.bubble .txt { white-space: pre-wrap; overflow-wrap: anywhere; word-break: normal; line-height: 1.45; font-size: .95rem; }
.bubble .meta { display: flex; justify-content: flex-end; gap: 4px; color: #8696a0; font-size: .68rem; margin-top: 2px; }
.bubble.out .meta { color: #99beb5; }
.ticks { letter-spacing: -1px; color: #53bdeb; }
.typing { float: left; color: var(--muted); font-size: .85rem; padding: 8px 12px; }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 6px 8px calc(8px + var(--safe-bot));
  background: #0b141a;
}
.composer-box {
  flex: 1; display: flex; align-items: center; gap: 2px;
  background: var(--bar); border-radius: 24px; padding: 2px 6px;
  min-height: 48px;
}
.composer input {
  flex: 1; border: 0; background: transparent; color: var(--text);
  font: inherit; padding: 10px 4px; min-width: 0;
}
.composer input:focus { outline: none; }
.send {
  width: 48px; height: 48px; border: 0; border-radius: 50%;
  background: var(--teal); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.send svg { width: 22px; height: 22px; fill: currentColor; }

.overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.45); z-index: 20;
}
.sheet {
  position: absolute; z-index: 21; background: #233138; color: var(--text);
  border-radius: 8px; overflow: hidden; box-shadow: 0 8px 28px rgba(0,0,0,.4);
}
#menu { top: calc(52px + var(--safe-top)); right: 8px; min-width: 200px; }
#menu button, .people-sheet button {
  display: block; width: 100%; border: 0; background: transparent; color: inherit;
  text-align: left; padding: 14px 18px; font: inherit; cursor: pointer;
}
#menu button:active, .people-sheet button:active { background: rgba(255,255,255,.06); }

.people-sheet, .settings-sheet, .status-sheet {
  left: 16px; right: 16px; top: 20%; border-radius: 12px; padding: 8px 0 12px;
}
.settings-sheet, .status-sheet { padding: 18px; }
.settings-sheet p, .status-sheet p { color: var(--muted); font-size: .9rem; }
.status-sheet textarea {
  width: 100%; min-height: 110px; border: 0; border-radius: 10px;
  background: #111b21; color: var(--text); padding: 12px; font: inherit; resize: vertical;
}
.row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.ghost-btn, .teal-btn {
  border: 0; border-radius: 8px; padding: 10px 16px; font: inherit; cursor: pointer;
}
.ghost-btn { background: transparent; color: var(--muted); }
.teal-btn { background: var(--accent); color: #3b071a; font-weight: 600; }

.call-arrow { width: 14px; height: 14px; fill: none; stroke: var(--teal); flex-shrink: 0; color: var(--teal); }
.call-arrow.missed { stroke: var(--danger); color: var(--danger); }
.call-act { color: var(--teal); }
.call-act svg { width: 22px; height: 22px; fill: currentColor; }

.empty-tab {
  color: var(--muted); text-align: center; padding: 48px 24px; line-height: 1.5;
}

.call-ui {
  background: #0b141a; align-items: center; justify-content: center; gap: 12px;
  z-index: 30; text-align: center;
}
.call-kind { color: var(--teal); letter-spacing: .08em; text-transform: uppercase; font-size: .75rem; }
.call-ui h2 { margin: 4px 0 0; }
#call-state { color: var(--muted); }
.end-call {
  margin-top: 36px; width: 64px; height: 64px; border: 0; border-radius: 50%;
  background: var(--danger); color: #fff; display: grid; place-items: center; cursor: pointer;
}
.end-call svg { width: 30px; height: 30px; fill: currentColor; transform: rotate(135deg); }

.camera-pane {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 16px; color: var(--muted); background: #000; gap: 12px;
}
.camera-pane video, .camera-pane img {
  width: 100%; max-height: 58vh; object-fit: cover; border-radius: 12px; background: #111;
}
.camera-pane .row { width: 100%; justify-content: center; }

.toast {
  position: absolute; left: 50%; bottom: 88px; transform: translateX(-50%);
  background: #3a2430; color: var(--text); padding: 10px 16px; border-radius: 8px;
  font-size: .85rem; z-index: 40; white-space: nowrap;
}

.emoji-tray {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 12px 0;
  background: #140d11;
}
.emoji-tray button {
  border: 0; background: transparent; font-size: 1.35rem; padding: 4px; cursor: pointer;
}

.bubble img.pic {
  display: block; max-width: 220px; max-height: 260px; border-radius: 8px; margin-bottom: 4px;
}
.voice-btn {
  display: flex; align-items: center; gap: 8px; border: 0; background: transparent;
  color: inherit; font: inherit; cursor: pointer; padding: 4px 0;
}
.voice-btn i {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-style: normal;
}
.send.rec { background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.status-view {
  position: absolute; inset: 0; z-index: 28; background: #1a0a12;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px 18px; text-align: center;
}
.status-view img { max-width: 100%; max-height: 58vh; border-radius: 12px; }
.status-view p { font-size: 1.15rem; margin: 16px 0; }
.status-bar { position: absolute; top: 10px; left: 12px; right: 12px; height: 3px; background: #5a3144; }
.status-bar span { display: block; height: 100%; width: 100%; background: var(--accent); }

.call-ui video#call-remote {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: -1;
  background: #0b141a;
}
.call-ui video#call-self {
  position: absolute; right: 14px; top: 72px; width: 96px; height: 128px;
  object-fit: cover; border-radius: 10px; background: #000;
}
.call-actions { display: flex; gap: 18px; margin-top: 28px; }
.answer-call {
  width: 64px; height: 64px; border: 0; border-radius: 50%;
  background: #22c55e; color: #fff; display: grid; place-items: center; cursor: pointer;
}
.answer-call svg { width: 28px; height: 28px; fill: currentColor; }

.hidden-file { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }
