:root {
  --bg: #0f0f12;
  --surface: #1a1a20;
  --surface-2: #24242c;
  --line: #2a2a33;
  --text: #f2f2f5;
  --muted: #8b8b96;
  --accent: #8b5cf6;
  --accent-2: #ff5c8a;
  --snap: #ff5c8a;
  --chat: #4da3ff;
  --danger: #ff5a5a;
  --grad: linear-gradient(135deg, var(--accent), var(--accent-2));
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
input {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; width: 100%; outline: none;
}
input:focus { border-color: var(--accent); }
[hidden] { display: none !important; }

.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
#app { height: 100dvh; }
.screen { display: flex; flex-direction: column; height: 100dvh; }
header.top {
  display: grid; grid-template-columns: 56px 1fr 56px; align-items: center;
  padding: calc(var(--top) + 8px) 12px 8px; border-bottom: 1px solid var(--line); flex: none;
}
header.top h1 { margin: 0; text-align: center; font-size: 19px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
header.top .sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.hl { justify-self: start; } .hr { justify-self: end; }
.iconbtn {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); position: relative; flex: none;
}
.iconbtn.plain { background: none; }
.iconbtn.accent { background: var(--grad); }
.badge {
  position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; border-radius: 9px;
  background: var(--accent-2); font-size: 11px; font-weight: 700; display: grid; place-items: center; padding: 0 5px;
}
.list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.empty { color: var(--muted); text-align: center; padding: 40px 24px; }

nav.bottom {
  flex: none; display: flex; justify-content: space-around; align-items: center;
  padding: 10px 0 calc(var(--bottom) + 10px); border-top: 1px solid var(--line); background: var(--bg);
}
nav.bottom button { padding: 8px 32px; color: var(--muted); }
nav.bottom button.on { color: var(--text); }
nav.bottom .icon { width: 28px; height: 28px; }

/* ---------- rows ---------- */
.row {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.row:active { background: var(--surface); }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 20px; color: #fff;
}
.avatar.small { width: 36px; height: 36px; font-size: 15px; }
.rowmain { flex: 1; min-width: 0; }
.name { font-weight: 600; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.mark { width: 11px; height: 11px; border-radius: 2px; border: 2px solid var(--muted); flex: none; }
.status.snap .mark { border-color: var(--snap); }
.status.chat .mark { border-color: var(--chat); }
.status.sent .mark { transform: rotate(45deg); border-radius: 1px; }
.status.new .mark { background: currentColor; border-color: currentColor; }
.status.snap.new { color: var(--snap); font-weight: 650; }
.status.chat.new { color: var(--chat); font-weight: 650; }

.section { padding: 18px 16px 6px; color: var(--muted); font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; }
.actions { display: flex; gap: 8px; }
.pillbtn { padding: 7px 14px; border-radius: 999px; background: var(--surface-2); font-size: 14px; font-weight: 600; }
.pillbtn.go { background: var(--grad); }
.pillbtn.danger { color: var(--danger); }
.addrow { display: flex; gap: 8px; padding: 14px 16px; }
.addrow input { flex: 1; }

.primary {
  background: var(--grad); color: #fff; font-weight: 700; border-radius: 999px; padding: 13px 22px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.primary.small { padding: 10px 18px; }
.primary .icon { width: 20px; height: 20px; }
.link { color: var(--muted); text-decoration: underline; padding: 8px; }
.danger-text { color: var(--danger); }

/* ---------- auth ---------- */
form.auth {
  max-width: 380px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column;
  justify-content: center; gap: 12px; padding: 24px;
}
.logo {
  font-size: 44px; font-weight: 800; letter-spacing: -.02em; text-align: center;
  background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.muted { color: var(--muted); text-align: center; margin: 0 0 12px; }
.err { color: var(--danger); margin: 0; min-height: 1.2em; font-size: 14px; }
.note { background: var(--surface-2); border-radius: 12px; padding: 12px; margin: 0; font-size: 14px; }

/* ---------- conversation ---------- */
.msgs { flex: 1; overflow-y: auto; padding: 12px 12px 4px; display: flex; flex-direction: column; gap: 4px; }
.msg { display: flex; flex-direction: column; max-width: 80%; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.them { align-self: flex-start; align-items: flex-start; }
.from { font-size: 12px; color: var(--muted); margin: 8px 0 2px 4px; font-weight: 600; }
.bubble {
  padding: 9px 13px; border-radius: 18px; background: var(--surface-2); white-space: pre-wrap;
  word-break: break-word; -webkit-user-select: text; user-select: text;
}
.msg.me .bubble { background: var(--accent); }
.meta { font-size: 11px; color: var(--muted); margin: 2px 6px 4px; }
.snapchip {
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 14px;
  border: 1.5px solid var(--snap); color: var(--snap); font-weight: 650; font-size: 15px;
}
.snapchip.done { border-color: var(--line); color: var(--muted); font-weight: 500; }
.snapchip .icon { width: 18px; height: 18px; }
.notice { text-align: center; color: var(--muted); font-size: 13px; margin: 10px 20px; }
form.composer {
  flex: none; display: flex; gap: 8px; align-items: center;
  padding: 8px 10px calc(var(--bottom) + 8px); border-top: 1px solid var(--line);
}
form.composer input { border-radius: 999px; padding: 10px 16px; }

/* ---------- camera / preview / viewer ---------- */
.cam { position: fixed; inset: 0; background: #000; overflow: hidden; }
.cam video, .cam img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam video.mirror { transform: scaleX(-1); }
.cam .fit { object-fit: contain; }
.camtop {
  position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center;
  padding: calc(var(--top) + 12px) 14px 12px; gap: 10px; z-index: 2;
}
.camtop .to { background: rgba(0,0,0,.45); padding: 6px 14px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.cam .iconbtn { background: rgba(0,0,0,.45); }
.cambottom {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-around; align-items: center;
  padding: 16px 20px calc(var(--bottom) + 24px); z-index: 2;
}
.shutter {
  width: 78px; height: 78px; border-radius: 50%; border: 5px solid #fff; background: rgba(255,255,255,.15);
  transition: transform .15s, background .15s; touch-action: none;
}
.shutter.rec { transform: scale(1.18); background: var(--danger); border-color: var(--danger); }
.camerr {
  position: absolute; top: 40%; left: 24px; right: 24px; text-align: center; color: var(--muted); z-index: 1;
}
.camhint { position: absolute; bottom: calc(var(--bottom) + 122px); left: 0; right: 0; text-align: center; color: rgba(255,255,255,.7); font-size: 13px; z-index: 2; pointer-events: none; }
input.caption {
  position: absolute; left: 0; right: 0; top: 58%; z-index: 3; border-radius: 0; border: 0;
  background: rgba(0,0,0,.55); text-align: center; font-size: 18px; padding: 10px 16px;
}
.capbar {
  position: absolute; left: 0; right: 0; top: 58%; z-index: 3; background: rgba(0,0,0,.55);
  text-align: center; font-size: 18px; padding: 10px 16px; word-break: break-word;
}
.tools { display: flex; flex-direction: column; gap: 12px; }
.pill { background: rgba(0,0,0,.45); border-radius: 999px; padding: 8px 14px; font-weight: 700; min-width: 54px; }

.viewer { position: fixed; inset: 0; z-index: 50; background: #000; }
.viewer video, .viewer img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.vfrom { position: absolute; top: calc(var(--top) + 14px); left: 16px; font-weight: 700; z-index: 2; text-shadow: 0 1px 4px #000; }
.countdown {
  position: absolute; top: calc(var(--top) + 10px); right: 14px; z-index: 2; min-width: 32px; height: 32px; border-radius: 16px;
  background: rgba(0,0,0,.5); display: grid; place-items: center; font-weight: 700; padding: 0 8px;
}
.countdown:empty { display: none; }
.spinner {
  position: absolute; top: 50%; left: 50%; width: 40px; height: 40px; margin: -20px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.2); border-top-color: #fff; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- picker / modal / toast ---------- */
label.row input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.sendbar { margin: 10px 16px calc(var(--bottom) + 12px); }
.modal-bg { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.6); display: grid; place-items: center; padding: 20px; }
.modal { background: var(--surface); border-radius: 20px; padding: 22px; max-width: 360px; width: 100%; text-align: center; }
.modal h2 { margin: 0 0 8px; font-size: 18px; }
.modal p { color: var(--muted); font-size: 14px; }
.code { font: 600 22px/1.6 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .04em; color: var(--text); margin: 14px 0; }
.settings { padding: 8px 16px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--surface); border-radius: 16px; padding: 16px; }
.card p { margin: 6px 0 12px; color: var(--muted); font-size: 14px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--bottom) + 96px); transform: translate(-50%, 20px);
  background: var(--surface-2); padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; transition: .2s; pointer-events: none; z-index: 100; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.center { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 24px; text-align: center; }
