/* Noop — night theme */
:root {
  --bg: #0b0d14;
  --bg-2: #10131c;
  --surface: #161a26;
  --surface-2: #1d2231;
  --line: #242a3b;
  --text: #e8e9f3;
  --muted: #8a90a8;
  --accent: #8b8fff;
  --accent-2: #6366f1;
  --mine: #3b3f9a;
  --mine-2: #4246a8;
  --theirs: #1a1f2d;
  --saved: #e2b55a;
  --danger: #f2626b;
  --ok: #4ade80;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: 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);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  /* app feel: no pull-to-refresh, no rubber band, no page scroll */
  overscroll-behavior: none;
  overflow: hidden;
}
body { position: fixed; inset: 0; }
#app { height: var(--app-h, 100dvh); display: flex; flex-direction: column; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
a { color: var(--accent); }
h1, h3, h4 { margin: 0; }
.hidden { display: none; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.accent { color: var(--accent); }
.small { font-size: 13px; }
.center { text-align: center; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; min-width: 0; }
.icon { flex: none; display: block; }
.error { color: var(--danger); margin: 0; font-size: 14px; }

/* ---- buttons & inputs ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px; font-weight: 600; font-size: 15px;
  background: var(--surface-2); transition: filter .15s, transform .1s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.btn.ghost { background: var(--surface-2); }
.btn.danger { background: rgba(242, 98, 107, .14); color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; flex: none; color: var(--text);
}
.icon-btn:active:not(:disabled) { background: var(--surface-2); }
.icon-btn.on { color: var(--accent); }
.icon-btn.dim { color: var(--muted); }
.icon-btn.danger { color: var(--danger); }
.input {
  width: 100%; min-height: 46px; padding: 0 14px; border-radius: 12px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--bg-2); border: 1px solid var(--line); outline: none;
}
.input:focus { border-color: var(--accent-2); }

/* ---- layout ---- */
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding-bottom: calc(16px + var(--safe-b)); }
.bar {
  display: flex; align-items: center; gap: 4px; padding: calc(6px + var(--safe-t)) 6px 6px;
  background: var(--bg-2); border-bottom: 1px solid var(--line); min-height: calc(56px + var(--safe-t)); flex: none;
}
.bar .title { display: flex; flex-direction: column; min-width: 0; padding: 0 6px; }
.bar .title small { color: var(--muted); font-size: 13px; }
.bar.top { padding-left: 14px; }
.brand-sm { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: .3px; }
.conn { width: 8px; height: 8px; border-radius: 50%; background: var(--saved); margin-right: 8px; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.pad { padding: 14px 16px 4px; }
.section { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; padding: 18px 16px 6px; }
.empty { text-align: center; color: var(--muted); padding: 48px 24px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty p { margin: 0; }
.splash { flex: 1; display: grid; place-items: center; }
.splash .logo { animation: pulse 1.4s infinite; }

.tabs { display: flex; gap: 6px; padding: 8px 12px; background: var(--bg-2); border-bottom: 1px solid var(--line); flex: none; }
.tabs button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; height: 36px; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: 14px; }
.tabs button.on { background: var(--surface-2); color: var(--text); }

.banner { display: flex; align-items: center; gap: 12px; margin: 12px 12px 4px; padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); font-size: 14px; }
.banner > span { flex: 1; }
.banner .icon { color: var(--accent); }

/* ---- avatars ---- */
.avatar { position: relative; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; width: 44px; height: 44px; font-size: 18px; }
.avatar.s36 { width: 36px; height: 36px; font-size: 15px; }
.avatar.s56 { width: 56px; height: 56px; font-size: 22px; }
.avatar.s72 { width: 72px; height: 72px; font-size: 28px; }
.avatar.ghost { background: var(--surface-2); color: var(--muted); }
.avatar .dot { position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2px solid var(--bg-2); }
.avatar.c0 { background: linear-gradient(135deg, #818cf8, #4f46e5); }
.avatar.c1 { background: linear-gradient(135deg, #38bdf8, #0369a1); }
.avatar.c2 { background: linear-gradient(135deg, #2dd4bf, #0f766e); }
.avatar.c3 { background: linear-gradient(135deg, #4ade80, #15803d); }
.avatar.c4 { background: linear-gradient(135deg, #facc15, #a16207); }
.avatar.c5 { background: linear-gradient(135deg, #fb923c, #c2410c); }
.avatar.c6 { background: linear-gradient(135deg, #f472b6, #be185d); }
.avatar.c7 { background: linear-gradient(135deg, #c084fc, #7e22ce); }

/* ---- lists ---- */
.item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 16px; text-align: left; }
button.item:active { background: var(--surface); }
.item.off { opacity: .5; }
.item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.item-line > .ellipsis { flex: 1; }
.item-time { font-size: 12px; color: var(--muted); flex: none; }
.preview { color: var(--muted); font-size: 14px; }
.preview .icon { display: inline-block; vertical-align: -2px; }
.item-flags { display: flex; align-items: center; gap: 6px; flex: none; }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--accent-2); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.badge.mute { background: var(--surface-2); color: var(--muted); }

/* ---- conversation ---- */
.conv .peer { display: flex; align-items: center; gap: 8px; text-align: left; min-width: 0; padding: 2px 4px; border-radius: 10px; }
.conv .peer .title { padding: 0; }
.msgs {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column-reverse; /* stays anchored at the bottom */
  background:
    radial-gradient(1200px 600px at 100% 0%, rgba(99, 102, 241, .06), transparent 60%),
    radial-gradient(900px 500px at 0% 100%, rgba(14, 165, 233, .04), transparent 60%), var(--bg);
}
.msgs-inner { padding: 10px 10px 6px; display: flex; flex-direction: column; }
.hint { text-align: center; color: var(--muted); padding: 40px 30px; }
.hint p { margin: 4px 0; }
.day { align-self: center; margin: 12px 0 6px; }
.day span { display: inline-block; padding: 4px 12px; border-radius: 12px; background: rgba(22, 26, 38, .9); color: var(--muted); font-size: 12px; font-weight: 600; }

.row { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.row.first { margin-top: 8px; }
.row.mine { justify-content: flex-end; }
.row.selecting { cursor: pointer; }
.row.flash .bubble { animation: flash 1.2s; }
@keyframes flash { 30% { box-shadow: 0 0 0 3px var(--accent); } }

.bubble {
  position: relative; max-width: min(78%, 560px); padding: 7px 11px 6px; border-radius: var(--radius);
  background: var(--theirs); display: flow-root; word-wrap: break-word; overflow-wrap: anywhere;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: pan-y;
  transition: transform .18s ease, background .15s;
}
.row.theirs.first .bubble { border-top-left-radius: 6px; }
.row.mine .bubble { background: linear-gradient(160deg, var(--mine-2), var(--mine)); }
.row.mine.first .bubble { border-top-right-radius: 6px; }
.bubble.saved { box-shadow: inset 0 0 0 1.5px var(--saved); }
.bubble.selected { filter: brightness(1.35); }
.bubble.big { background: none !important; box-shadow: none; padding: 0 2px; }
.bubble.big .text > span:first-child { font-size: 44px; line-height: 1.15; }
.bubble.big .meta { background: rgba(16, 19, 28, .8); padding: 1px 6px; border-radius: 8px; }
.bubble.big.saved .meta { box-shadow: inset 0 0 0 1px var(--saved); }
.text { white-space: pre-wrap; font-size: 15.5px; }
.meta {
  float: right; display: inline-flex; align-items: center; gap: 4px; margin: 6px 0 -3px 10px;
  font-size: 11px; color: rgba(232, 233, 243, .55); white-space: nowrap; position: relative; top: 3px;
}
.meta em { font-style: normal; }
.saved-ic { color: var(--saved); }
.ticks { color: rgba(232, 233, 243, .6); }
.ticks.read { color: #a5f3fc; }
.quote {
  display: flex; flex-direction: column; margin: 1px 0 5px; padding: 4px 8px; border-left: 3px solid var(--accent);
  border-radius: 6px; background: rgba(255, 255, 255, .06); font-size: 13px; max-width: 100%; cursor: pointer;
}
.quote b { color: var(--accent); font-size: 12.5px; }
.quote span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: rgba(232, 233, 243, .75); }
.row.mine .quote { border-left-color: #c7d2fe; }
.row.mine .quote b { color: #c7d2fe; }
.check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted); flex: none; display: grid; place-items: center; color: transparent; order: -1; }
.check.on { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.check.no { opacity: .25; }
.row.mine.selecting { justify-content: space-between; }

.composer-wrap { flex: none; background: var(--bg-2); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.compose-ctx { display: flex; align-items: center; gap: 10px; padding: 8px 6px 0 14px; }
.ctx-body { flex: 1; min-width: 0; display: flex; flex-direction: column; border-left: 2px solid var(--accent); padding-left: 10px; font-size: 13px; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 12px; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); outline: none; background: var(--bg); color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.35; padding: 10px 14px; border-radius: 22px; max-height: 148px; min-height: 44px;
}
.composer textarea:focus { border-color: #343b55; }
.send { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--muted); transition: background .15s, color .15s; }
.send.on { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }

/* ---- overlays ---- */
.overlay {
  position: fixed; inset: 0; z-index: 20; background: rgba(4, 5, 10, .66); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s;
}
.modal {
  position: relative; width: 100%; max-width: 400px; max-height: 90%; overflow: auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: 20px; padding: 20px; display: flex; flex-direction: column; gap: 12px; animation: pop .18s;
}
.modal form { display: flex; flex-direction: column; gap: 12px; }
.modal p { margin: 0; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.modal .close { position: absolute; top: 10px; right: 10px; }
.overlay:has(.sheet) { align-items: flex-end; padding: 0; }
.modal.sheet { max-width: 520px; border-radius: 20px 20px 0 0; padding: 8px 8px calc(12px + var(--safe-b)); gap: 0; animation: up .2s ease-out; }
.sheet-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.preview-text { color: var(--muted); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 30vh; overflow: auto; }
.sheet-btn { display: flex; align-items: center; gap: 14px; width: 100%; padding: 13px 14px; border-radius: 12px; text-align: left; font-size: 16px; }
.sheet-btn:active { background: var(--surface-2); }
.sheet-btn.danger { color: var(--danger); }
.sheet-note { padding: 12px 14px; color: var(--muted); font-size: 13px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%); z-index: 30;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: #262c40; color: var(--text);
  font-size: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, .4); animation: fade .2s; text-align: center;
}
.toast.error { background: #3a1d24; color: #ffc9cd; }

/* ---- pin pad ---- */
.lock-screen .lock-body { flex: 1; overflow: auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 12px 16px calc(24px + var(--safe-b)); }
.lock-name { font-weight: 600; font-size: 18px; margin-bottom: 8px; }
.pinpad { display: flex; flex-direction: column; align-items: center; gap: 12px; width: 100%; max-width: 320px; }
.pin-modal { align-items: center; padding-top: 34px; }
.pin-title { font-size: 18px; font-weight: 600; }
.pin-sub { font-size: 14px; color: var(--muted); min-height: 20px; text-align: center; }
.pin-sub.err { color: var(--danger); }
.dots { display: flex; gap: 18px; margin: 8px 0 14px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); transition: background .1s, border-color .1s, transform .1s; }
.dots i.on { background: var(--accent); border-color: var(--accent); transform: scale(1.1); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.keys { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px 26px; justify-content: center; }
.key { width: 76px; height: 76px; border-radius: 50%; background: var(--surface-2); font-size: 28px; font-weight: 500; display: grid; place-items: center; transition: background .1s, transform .08s; }
.key:active:not(:disabled) { background: #2b3249; transform: scale(.95); }
.key.del { background: none; color: var(--muted); }

/* ---- auth ---- */
.auth { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b)); }
.auth-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 24px; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.brand h1 { font-size: 30px; letter-spacing: .5px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack p { margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

/* ---- settings ---- */
.settings { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.me-card { display: flex; align-items: center; gap: 14px; padding: 4px 4px 6px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.card p { margin: 0; }
.card .btn { align-self: flex-start; }
.row-input { display: flex; gap: 8px; }
.version { margin-top: 6px; }

.modal.install { align-items: center; gap: 20px; padding: 28px 20px 20px; max-width: 320px; }
.ios-hint { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; font-size: 15px; }

@media (min-width: 720px) {
  #app { max-width: 760px; margin: 0 auto; width: 100%; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
