:root {
  --bg: #e9f0ee; --surface: #ffffff; --text: #12211f; --muted: #5d716d;
  --theirs: #ffffff; --mine-a: #0f8a7e; --mine-b: #0b6f7a; --mine-text: #ffffff;
  --accent: #0f8a7e; --accent-soft: #d8f0ec; --border: #d5e0dd; --danger: #d92d20;
  --shadow: 0 1px 2px rgba(15, 40, 36, .12);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1413; --surface: #12201e; --text: #e7f1ef; --muted: #8aa29d;
    --theirs: #1b2d2a; --accent: #2bc4b2; --accent-soft: #17332f; --border: #243a36;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 16px/1.45 var(--font); background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }

/* avatars */
.avatar { width: 2.6rem; height: 2.6rem; border-radius: 50%; flex: none; display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(135deg, var(--mine-a), #5fd3c4); color: #fff; font-weight: 800; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.xl { width: 7rem; height: 7rem; font-size: 2.6rem; margin: .25rem auto .75rem; }
.avatar-btn { width: 2.6rem; height: 2.6rem; border-radius: 50%; padding: 0; display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(135deg, var(--mine-a), #5fd3c4); color: #fff; font-weight: 800; box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent-soft); }
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

/* buttons */
.btn-primary { background: linear-gradient(135deg, var(--mine-a), var(--mine-b)); color: #fff; font-weight: 700; border-radius: 14px; padding: .85rem 1rem; width: 100%; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost, .btn-danger { flex: 1; padding: .8rem 1rem; border-radius: 14px; font-weight: 700; }
.btn-ghost { background: var(--accent-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.icon-btn { width: 2.5rem; height: 2.5rem; display: grid; place-items: center; border-radius: 50%; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn.danger { color: var(--danger); }
.icon-btn svg, .fab svg { width: 1.3rem; height: 1.3rem; }
.fab { width: 2.9rem; height: 2.9rem; border-radius: 50%; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--mine-a), var(--mine-b)); flex: none; box-shadow: var(--shadow); }

/* login */
.login-page { display: flex; align-items: center; justify-content: center; padding: 1.25rem;
  background: radial-gradient(60rem 30rem at 10% -10%, #bfeee6 0, transparent 60%), radial-gradient(50rem 30rem at 110% 110%, #cfe3f7 0, transparent 60%), var(--bg); }
@media (prefers-color-scheme: dark) {
  .login-page { background: radial-gradient(60rem 30rem at 10% -10%, #0f3b36 0, transparent 60%), radial-gradient(50rem 30rem at 110% 110%, #0f2a40 0, transparent 60%), var(--bg); }
}
.login-card { width: 100%; max-width: 24rem; background: var(--surface); border-radius: 24px; padding: 2rem 1.6rem; box-shadow: 0 20px 50px rgba(8, 50, 44, .18); }
.login-card h1 { margin: 0 0 .4rem; font-size: 1.9rem; font-weight: 800; letter-spacing: -.02em; }
.login-card .lead { margin: 0; font-size: 1.05rem; }
.login-card .muted { margin: .2rem 0 1.2rem; }
.who-pick { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1rem; }
.who { display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 14px; font-weight: 700; }
.who:hover { background: var(--accent-soft); }
.who .avatar { width: 2rem; height: 2rem; font-size: .9rem; }
.login-card label { display: block; font-size: .8rem; font-weight: 700; margin: .8rem 0 .3rem; color: var(--muted); }
.login-card input { width: 100%; padding: .75rem .9rem; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); }
.login-card .btn-primary { margin-top: 1.2rem; }
.form-error { color: var(--danger); font-size: .875rem; margin: .7rem 0 0; }

/* chat shell */
.chat { height: 100dvh; max-width: 44rem; margin: 0 auto; display: flex; flex-direction: column; background: var(--bg); position: relative; }
@media (min-width: 46rem) { .chat { box-shadow: 0 0 40px rgba(8, 50, 44, .15); } }
.bar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1rem; padding-top: max(.7rem, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border); z-index: 2; }
.who-bar { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.who-bar h1 { margin: 0; font-size: 1.05rem; font-weight: 800; line-height: 1.2; }
.status { margin: 0; font-size: .78rem; color: var(--muted); }
.status.online { color: var(--accent); font-weight: 700; }
.status.online::before { content: ""; display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; background: var(--accent); margin-right: .35rem; }
.status.typing-now { color: var(--accent); font-weight: 700; font-style: italic; }

/* messages */
.messages { flex: 1; overflow-y: auto; padding: 1rem .9rem .5rem; display: flex; flex-direction: column; gap: .3rem; overscroll-behavior: contain; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 2rem; }
.day { align-self: center; margin: .8rem 0 .4rem; font-size: .72rem; font-weight: 700; color: var(--muted); background: var(--surface); padding: .2rem .7rem; border-radius: 99px; box-shadow: var(--shadow); }
.row { display: flex; padding-bottom: .55rem; border-radius: 12px; }
.row.mine { justify-content: flex-end; }
.stack { max-width: min(80%, 28rem); touch-action: pan-y; position: relative; }
.bubble { padding: .45rem .75rem .3rem; border-radius: 18px; background: var(--theirs); box-shadow: var(--shadow);
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.theirs .bubble { border-bottom-left-radius: 6px; }
.mine .bubble { background: linear-gradient(135deg, var(--mine-a), var(--mine-b)); color: var(--mine-text); border-bottom-right-radius: 6px; }
.text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.foot { text-align: right; font-size: .68rem; opacity: .65; margin-top: .1rem; }
.flash { animation: flash 1.3s ease; }
@keyframes flash { 0%, 60% { background: var(--accent-soft); } 100% { background: transparent; } }

.quote { display: block; width: 100%; text-align: left; border-left: 3px solid var(--accent); background: rgba(0, 0, 0, .07);
  border-radius: 8px; padding: .3rem .55rem; margin-bottom: .35rem; }
.mine .quote { border-left-color: #fff; background: rgba(255, 255, 255, .18); }
.quote strong { display: block; font-size: .74rem; }
.quote span { display: block; font-size: .82rem; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 16rem; }

.media { margin: .1rem 0 .3rem; font-size: .9rem; }
.media img, .media video { display: block; max-width: 100%; max-height: 18rem; border-radius: 12px; }
.filelink { color: inherit; font-weight: 700; }

.voice { display: flex; align-items: center; gap: .6rem; min-width: 12.5rem; padding: .15rem 0 .2rem; }
.vplay { width: 2.2rem; height: 2.2rem; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #fff; flex: none; }
.vplay svg { width: 1.1rem; height: 1.1rem; }
.vplay.on { animation: pulse 1.2s infinite; }
.mine .vplay { background: #fff; color: var(--mine-a); }
.vtrack { flex: 1; height: .3rem; border-radius: 99px; background: rgba(120, 140, 136, .35); cursor: pointer; position: relative; }
.vtrack::before { content: ""; position: absolute; inset: -.6rem 0; }
.vbar { height: 100%; width: 0; border-radius: 99px; background: var(--accent); }
.mine .vbar { background: #fff; }
.vtime { font-size: .75rem; font-variant-numeric: tabular-nums; opacity: .85; min-width: 2.2rem; text-align: right; }
@keyframes pulse { 50% { box-shadow: 0 0 0 .35rem rgba(15, 138, 126, .2); } }

.reacts { display: flex; gap: .25rem; margin: -.3rem .55rem 0; position: relative; z-index: 1; }
.mine .reacts { justify-content: flex-end; }
.reacts:empty { display: none; }
.chip { background: var(--surface); border: 1px solid var(--border); border-radius: 99px; padding: .02rem .45rem; font-size: .82rem; box-shadow: var(--shadow); }
.chip.mine { border-color: var(--accent); background: var(--accent-soft); }

.typing { align-self: flex-start; margin: 0 0 .5rem .9rem; background: var(--theirs); padding: .6rem .8rem; border-radius: 18px 18px 18px 6px; box-shadow: var(--shadow); display: flex; gap: .25rem; width: fit-content; }
.typing span { width: .45rem; height: .45rem; border-radius: 50%; background: var(--muted); animation: bounce 1.1s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-.3rem); opacity: 1; } }

.banner { margin: 0; padding: .55rem 1rem; background: #fee4e2; color: #912018; font-size: .85rem; }

/* composer */
.strip { display: flex; align-items: center; gap: .5rem; margin: 0 .75rem; padding: .4rem .4rem .4rem .75rem; background: var(--surface); border-left: 3px solid var(--accent); border-radius: 12px 12px 0 0; }
.strip-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.strip-body strong { font-size: .76rem; color: var(--accent); }
.strip-body span { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.composer { display: flex; align-items: center; gap: .5rem; padding: .6rem .75rem; padding-bottom: max(.6rem, env(safe-area-inset-bottom)); }
.field { flex: 1; min-width: 0; display: flex; align-items: center; background: var(--surface); border-radius: 99px; padding-left: 1rem; box-shadow: var(--shadow); }
.field input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; padding: .7rem 0; }
.rec { background: var(--bg); }
.rec-info { flex: 1; display: flex; align-items: center; gap: .6rem; background: var(--surface); border-radius: 99px; padding: .7rem 1rem; box-shadow: var(--shadow); font-variant-numeric: tabular-nums; }
.rec-dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.emoji-panel { margin: 0 .75rem; max-height: 14rem; overflow-y: auto; background: var(--surface); border-radius: 16px 16px 0 0; padding: .5rem .6rem; box-shadow: var(--shadow); }
.emoji-group { font-size: .72rem; font-weight: 700; color: var(--muted); margin: .3rem 0 .15rem; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.4rem, 1fr)); }
.emoji-grid button { font-size: 1.45rem; padding: .2rem; border-radius: 10px; }
.emoji-grid button:hover { background: var(--accent-soft); }

/* sheets */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(5, 20, 18, .5); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 24rem; background: var(--surface); border-radius: 24px 24px 0 0; padding: .9rem .9rem calc(.9rem + env(safe-area-inset-bottom)); animation: rise .2s ease; }
@media (min-width: 40rem) { .overlay { align-items: center; } .sheet { border-radius: 24px; padding-bottom: .9rem; } }
@keyframes fade { from { opacity: 0; } } @keyframes rise { from { transform: translateY(1.5rem); opacity: 0; } }
.sheet-title { margin: 0 0 .3rem; font-size: 1.1rem; } .sheet-title.center { text-align: center; margin-bottom: .6rem; }
.sheet .muted { margin: 0 0 1rem; }
.dialog-actions { display: flex; gap: .6rem; }
.sheet-item { display: flex; align-items: center; gap: .8rem; width: 100%; padding: .8rem .6rem; border-radius: 12px; font-weight: 600; text-align: left; }
.sheet-item:hover { background: var(--accent-soft); }
.sheet-item svg { width: 1.3rem; height: 1.3rem; color: var(--muted); }
.sheet-item.danger, .sheet-item.danger svg { color: var(--danger); }
.react-row { display: flex; justify-content: space-between; background: var(--bg); border-radius: 99px; padding: .3rem .5rem; margin-bottom: .5rem; }
.react-row button { font-size: 1.6rem; width: 2.8rem; height: 2.8rem; border-radius: 50%; transition: transform .1s; }
.react-row button:hover { transform: scale(1.2); }
.react-row button.on { background: var(--accent-soft); }

.toast { position: fixed; top: max(1rem, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 30; max-width: calc(100% - 2rem);
  background: var(--text); color: var(--bg); padding: .7rem 1.1rem; border-radius: 99px; font-weight: 600; font-size: .9rem; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); animation: rise .25s ease; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.boot { text-align: center; padding: 3rem 1.5rem; color: var(--muted); }
.boot a { color: var(--accent); font-weight: 700; }
.boot small { display: block; margin: .5rem 0; word-break: break-word; }
