/* iMessage-style dark theme. SF Pro appears on Apple devices; others use their system font. */
:root {
  color-scheme: dark;
  --bg: #000;
  --bar: rgba(28, 28, 30, .82);
  --field: #1c1c1e;
  --field2: #2c2c2e;
  --sep: rgba(84, 84, 88, .65);
  --text: #fff;
  --dim: #8e8e93;
  --blue: #0a84ff;
  --sent: #0b84fe;
  --recv: #262629;
  --red: #ff453a;
  --green: #30d158;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro", "Helvetica Neue", system-ui, Roboto, "Segoe UI", Ubuntu, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, "Ubuntu Mono", Consolas, monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --nav-h: 100px;
  --comp-h: 60px;
  box-sizing: border-box;
}
*, *::before, *::after { box-sizing: inherit; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); }
body {
  color: var(--text);
  font: 17px/1.29 var(--font);
  letter-spacing: -0.41px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
code { font-family: var(--mono); font-size: .9em; background: var(--field2); padding: 1px 5px; border-radius: 5px; }

/* ---------- setup / start / join (iOS Settings style) ---------- */
.gate { min-height: 100%; padding: calc(var(--safe-t) + 44px) 16px calc(var(--safe-b) + 24px); }
.gate-inner { max-width: 30rem; margin: 0 auto; }
.large-title { font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: .37px; margin: 0; }
.sub { color: var(--dim); margin: 4px 0 28px; }
.section-h { font-size: 13px; font-weight: 400; text-transform: uppercase; color: var(--dim); letter-spacing: -.08px; margin: 0 0 7px 16px; }
.group { background: var(--field); border-radius: 10px; overflow: hidden; margin-bottom: 8px; }
.row-input, .row-select {
  display: flex; align-items: center; width: 100%; min-height: 44px; padding: 11px 16px;
  background: transparent; border: 0; border-radius: 0; outline: none;
}
.group > * + * { border-top: .5px solid var(--sep); }
.row-input::placeholder { color: #636366; }
.row-select { justify-content: space-between; gap: 12px; }
.row-select select { background: transparent; border: 0; color: var(--dim); text-align: right; appearance: none; -webkit-appearance: none; padding-right: 2px; outline: none; }
.row-select select option { background: var(--field); color: var(--text); }
.foot { font-size: 13px; line-height: 18px; color: var(--dim); margin: 0 16px 22px; letter-spacing: -.08px; }
.btn-fill {
  display: block; width: 100%; height: 50px; border: 0; border-radius: 12px;
  background: var(--blue); color: #fff; font-weight: 600;
}
.btn-fill:disabled { opacity: .45; }
.btn-plain { display: block; width: 100%; height: 44px; border: 0; background: none; color: var(--blue); margin-top: 6px; }
.btn-tinted { flex: 1; height: 40px; border: 0; border-radius: 10px; background: rgba(10, 132, 255, .18); color: var(--blue); font-weight: 600; }
.msgline { min-height: 1.3em; font-size: 15px; color: var(--dim); text-align: center; margin: 16px 8px 0; }
.msgline.err { color: var(--red); }

/* ---------- chat ---------- */
.chat { position: relative; height: 100%; overflow: hidden; }
.nav {
  position: absolute; z-index: 5; top: 0; left: 0; right: 0;
  padding: calc(var(--safe-t) + 6px) 8px 8px;
  display: grid; grid-template-columns: 52px 1fr 52px; align-items: center;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--sep);
}
.nav-btn { width: 44px; height: 44px; border: 0; background: none; display: grid; place-items: center; border-radius: 22px; }
.nav-btn svg { width: 25px; height: 25px; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn.blue svg { stroke: var(--blue); }
.nav-btn.red svg { stroke: var(--red); }
#c-invite { justify-self: end; }
.nav-center { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; padding: 0; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(180deg, #a5abb8, #858994); color: #fff;
  font-size: 18px; font-weight: 600; letter-spacing: 0;
}
.nav-title { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; line-height: 14px; max-width: 100%; }
.nav-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-title svg { width: 6px; height: 10px; fill: none; stroke: var(--dim); stroke-width: 1.8; flex: none; }
.nav-sub { font-size: 11px; line-height: 13px; color: var(--dim); }
.nav-sub.close { color: var(--red); }
.fuse { position: absolute; left: 0; right: 0; bottom: -.5px; height: 1.5px; }
.fuse-fill { height: 100%; width: 100%; background: var(--blue); opacity: .7; transition: width 1s linear; }

.status {
  position: absolute; z-index: 4; top: calc(var(--nav-h) + 8px); left: 50%; transform: translateX(-50%);
  background: var(--field2); color: var(--dim); font-size: 13px; padding: 5px 12px; border-radius: 14px; white-space: nowrap;
}

.list {
  position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--nav-h) + 10px) 16px calc(var(--comp-h) + 10px);
  display: flex; flex-direction: column;
}
.empty { margin: auto; text-align: center; color: var(--dim); font-size: 15px; max-width: 18rem; padding: 24px; }
.stamp, .sys { align-self: center; text-align: center; color: var(--dim); font-size: 11px; line-height: 13px; margin: 14px 0 8px; }
.stamp b { font-weight: 600; }

.msg { display: flex; flex-direction: column; align-items: flex-start; margin-top: 8px; }
.msg.cont { margin-top: 2px; }
.msg.mine { align-items: flex-end; }
.who { font-size: 11px; color: var(--dim); margin: 0 0 2px 14px; }
.bubble {
  position: relative; max-width: min(75%, 30rem); padding: 7px 12px; border-radius: 18px;
  background: var(--recv); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 22px;
}
.mine .bubble { background: var(--sent); }
.bubble .txt { position: relative; z-index: 2; }
/* tails on the last bubble of a group */
.bubble.tail::before, .bubble.tail::after { content: ""; position: absolute; bottom: 0; height: 20px; }
.mine .bubble.tail::before { right: -8px; width: 20px; background: var(--sent); border-bottom-left-radius: 15px; z-index: 0; }
.mine .bubble.tail::after { right: -10px; width: 10px; background: var(--bg); border-bottom-left-radius: 10px; z-index: 1; }
.theirs .bubble.tail::before { left: -8px; width: 20px; background: var(--recv); border-bottom-right-radius: 15px; z-index: 0; }
.theirs .bubble.tail::after { left: -10px; width: 10px; background: var(--bg); border-bottom-right-radius: 10px; z-index: 1; }
.bubble.media { padding: 0; background: none !important; overflow: hidden; }
.bubble.media::before, .bubble.media::after { display: none; }
.bubble img { display: block; max-width: 100%; max-height: 55vh; border-radius: 18px; cursor: zoom-in; }
.bubble.jumbo { background: none !important; padding: 0 2px; font-size: 48px; line-height: 58px; letter-spacing: 0; }
.bubble.warn { background: transparent; border: 1px solid var(--red); color: var(--red); font-size: 15px; }
.file-card { position: relative; z-index: 2; display: flex; align-items: center; gap: 10px; min-width: 200px; padding: 2px 0; }
.file-icon { width: 34px; height: 40px; flex: none; border-radius: 6px; background: rgba(255,255,255,.18); display: grid; place-items: center; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.file-info { flex: 1; min-width: 0; }
.fname { font-size: 15px; line-height: 19px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fsize { font-size: 13px; opacity: .7; }
.file-dl { border: 0; background: rgba(255,255,255,.2); color: #fff; height: 30px; padding: 0 12px; border-radius: 15px; font-size: 14px; font-weight: 600; flex: none; }
.receipt { font-size: 11px; line-height: 13px; color: var(--dim); margin: 3px 4px 0; }
.receipt b { font-weight: 600; }

.composer {
  position: absolute; z-index: 5; left: 0; right: 0; bottom: 0;
  display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(var(--safe-b) + 8px);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.plus-btn {
  width: 36px; height: 36px; flex: none; border: 0; border-radius: 50%; background: var(--field2);
  display: grid; place-items: center; margin-bottom: 1px;
}
.plus-btn svg { width: 20px; height: 20px; fill: none; stroke: #aeaeb2; stroke-width: 2.2; stroke-linecap: round; }
.pill {
  flex: 1; display: flex; align-items: flex-end; min-height: 38px;
  border: 1px solid #3a3a3c; border-radius: 19px; background: var(--bg); padding: 0 3px 3px 14px;
}
.pill textarea {
  flex: 1; resize: none; border: 0; outline: none; background: transparent;
  padding: 7px 0 4px; line-height: 22px; max-height: 9.5rem; font-size: 17px;
}
.pill textarea::placeholder { color: #636366; }
.send-btn {
  width: 30px; height: 30px; flex: none; border: 0; border-radius: 50%; background: var(--blue);
  display: grid; place-items: center; margin-left: 6px;
}
.send-btn svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.chat.dragging .list { outline: 2px dashed var(--blue); outline-offset: -10px; }

/* ---------- sheets ---------- */
.sheet {
  width: min(26rem, calc(100% - 24px)); border: 0; border-radius: 14px;
  background: var(--field); color: var(--text); padding: 20px 16px 10px;
}
.sheet::backdrop, .action-sheet::backdrop { background: rgba(0, 0, 0, .55); }
.sheet h2 { margin: 0 0 6px; font-size: 17px; font-weight: 600; text-align: center; }
.sheet .group { background: var(--field2); }
.sheet .row-select select option { background: var(--field2); }
.sheet-text { color: var(--dim); font-size: 13px; line-height: 18px; text-align: center; margin: 0 4px 14px; }
.sheet-text.small { margin-top: 10px; }
.sheet .btn-fill { margin-top: 12px; }
.sheet-row { display: flex; gap: 8px; margin-top: 10px; }
.invite-out input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 0; background: var(--bg);
  font-family: var(--mono); font-size: 12px; color: var(--dim); letter-spacing: 0;
}
.people { list-style: none; padding: 0; margin: 8px 0 16px; background: var(--field2); border-radius: 10px; }
.people li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; }
.people li + li { border-top: .5px solid var(--sep); }
.people .avatar { width: 32px; height: 32px; font-size: 14px; }
.people .pname { flex: 1; min-width: 0; }
.people .pmeta { display: block; font-size: 13px; color: var(--dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #48484a; flex: none; }
.dot.on { background: var(--green); }
.code-box { text-align: center; font-family: var(--mono); font-size: 20px; letter-spacing: 2px; padding: 12px; background: var(--bg); border-radius: 10px; }

.action-sheet {
  position: fixed; inset: auto 0 0 0; margin: 0 auto; width: min(26rem, calc(100% - 16px));
  border: 0; background: none; padding: 0 0 calc(var(--safe-b) + 8px); color: var(--text);
}
.as-group { background: rgba(44, 44, 46, .96); border-radius: 14px; overflow: hidden; margin-bottom: 8px; }
.as-title { margin: 0; padding: 14px 16px; font-size: 13px; line-height: 18px; color: var(--dim); text-align: center; }
.as-btn { display: block; width: 100%; min-height: 57px; border: 0; border-top: .5px solid var(--sep); background: none; font-size: 20px; color: var(--blue); }
.as-btn.red { color: var(--red); }
.as-btn.cancel { border: 0; border-radius: 14px; background: rgba(44, 44, 46, .96); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 80px); transform: translateX(-50%); z-index: 50;
  background: rgba(58, 58, 60, .96); color: #fff; padding: 10px 16px; border-radius: 14px;
  font-size: 15px; width: max-content; max-width: calc(100% - 32px); text-align: center;
}
.viewer { position: fixed; inset: 0; background: #000; display: grid; place-items: center; z-index: 40; cursor: zoom-out; }
.viewer img { max-width: 100vw; max-height: 100vh; }

@media (prefers-reduced-motion: reduce) { .fuse-fill { transition: none; } }

/* ---------- chat list ---------- */
.listscreen { min-height: 100%; padding: calc(var(--safe-t) + 4px) 0 calc(var(--safe-b) + 24px); max-width: 40rem; margin: 0 auto; }
.list-bar { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px 0 16px; height: 44px; }
.text-btn { border: 0; background: none; font-size: 17px; padding: 8px 0; }
.text-btn.red, .btn-plain.red { color: var(--red); }
.list-title { padding: 0 16px 8px; }
.chat-list { list-style: none; margin: 0; padding: 0; }
.chat-item { display: flex; align-items: center; gap: 12px; padding: 0 0 0 10px; cursor: pointer; }
.chat-item:active { background: var(--field); }
.unread-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--blue); flex: none; visibility: hidden; }
.chat-item.unread .unread-dot { visibility: visible; }
.chat-item .avatar { width: 46px; height: 46px; flex: none; font-size: 19px; }
.ci-body { flex: 1; min-width: 0; padding: 11px 16px 11px 0; border-bottom: .5px solid var(--sep); }
.ci-top { display: flex; align-items: baseline; gap: 8px; }
.ci-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-time { font-size: 15px; color: var(--dim); flex: none; }
.ci-prev { font-size: 15px; line-height: 20px; color: var(--dim); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 40px; }
.chat-item.unread .ci-prev { color: var(--text); }
.ci-tag { font-size: 12px; color: var(--dim); }
.list-empty { color: var(--dim); text-align: center; padding: 40px 32px 12px; margin: 0; }
.foot.center { text-align: center; margin-top: 18px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--blue); font-size: 17px; padding: 0; margin: -30px 0 18px -6px; }
.back-link svg, .nav-btn.back svg { width: 12px; height: 20px; fill: none; stroke: var(--blue); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.nav-btn.back { display: flex; gap: 4px; width: auto; padding: 0 8px; justify-content: flex-start; }
.back-count { font-size: 15px; color: var(--blue); min-width: 1ch; }

/* iOS-style switch */
.switch-row { cursor: pointer; }
.switch-row span { color: var(--text); }
.switch { appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px; background: #39393d; position: relative; flex: none; margin: 0; cursor: pointer; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); transition: transform .2s; }
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: .5; }
.sheet-text.left { text-align: left; margin: 6px 4px 16px; }

.ntfy-box { margin: -6px 0 16px; }
.ntfy-line { display: flex; align-items: baseline; gap: 10px; padding: 6px 4px; font-size: 13px; color: var(--dim); }
.ntfy-line span { width: 3.5em; flex: none; }
.ntfy-line code { background: var(--bg); color: var(--text); overflow-wrap: anywhere; letter-spacing: 0; font-size: 12px; padding: 3px 6px; }
.btn-tinted.link { display: grid; place-items: center; text-decoration: none; font-size: 17px; }
