:root {
  color-scheme: dark;
  --bg: #0a1023;
  --panel: rgba(20, 29, 58, .93);
  --panel-2: #1b2443;
  --line: rgba(255,255,255,.08);
  --text: #f7f9ff;
  --muted: #96a1bf;
  --blue: #446dff;
  --cyan: #30dbf2;
  --danger: #ff4f73;
  --safe: #3cd68b;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #060b19; color: var(--text); }
body { min-height: 100dvh; overflow: hidden; }
button, input, textarea { font: inherit; }
button { color: inherit; }
button:active { transform: scale(.96); }
.hidden { display: none !important; }
.visually-hidden { position: fixed; left: -9999px; opacity: 0; }

.app-shell {
  width: min(100%, 720px);
  height: 100dvh;
  margin: auto;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(circle at 88% 10%, rgba(29, 91, 255, .15), transparent 30%),
    linear-gradient(180deg, #0f1730 0%, var(--bg) 45%, #090f20 100%);
}
.topbar {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 18px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 17, 37, .75);
  backdrop-filter: blur(22px);
  z-index: 5;
}
.profile-button, .round-button { border: 0; padding: 0; background: var(--panel-2); width: 44px; height: 44px; border-radius: 15px; position: relative; cursor: pointer; }
.profile-button img { width: 100%; height: 100%; object-fit: cover; border-radius: 15px; }
.online-dot { position: absolute; right: -2px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--safe); border: 3px solid #11182f; }
.round-button { font-size: 20px; background: linear-gradient(145deg, #273151, #1a2240); }
.room-heading { background: none; border: 0; padding: 2px; text-align: left; cursor: pointer; min-width: 0; }
.room-heading strong { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-heading span { color: var(--muted); font-size: 11px; }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #f6b44b; margin-right: 5px; }
.status-dot.connected { background: var(--safe); box-shadow: 0 0 8px rgba(60,214,139,.7); }

.messages { overflow-y: auto; padding: 18px 16px 28px; scroll-behavior: smooth; overscroll-behavior: contain; }
.day-divider { margin: 12px auto 18px; width: fit-content; color: #71809f; font-size: 11px; }
.empty-state { min-height: 65vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 30px; color: var(--muted); }
.empty-state img { width: 84px; height: 84px; object-fit: cover; border-radius: 25px; box-shadow: 0 20px 50px rgba(26,80,255,.25); }
.empty-state h1 { color: var(--text); font-size: 21px; margin: 22px 0 8px; }
.empty-state p { max-width: 280px; font-size: 13px; line-height: 1.7; margin: 0; }
.message-row { display: flex; gap: 9px; align-items: flex-end; margin: 7px 0 15px; animation: message-in .22s ease-out; }
.message-row.mine { flex-direction: row-reverse; }
.message-avatar { width: 32px; height: 32px; border-radius: 11px; object-fit: cover; flex: 0 0 auto; background: #1b2547; }
.message-stack { max-width: min(76%, 500px); }
.sender-name { display: block; font-size: 10px; color: #7f8aa8; margin: 0 0 5px 5px; }
.mine .sender-name { text-align: right; margin: 0 5px 5px 0; }
.bubble { position: relative; background: #202a4c; border: 1px solid rgba(255,255,255,.05); border-radius: 6px 18px 18px 18px; padding: 10px 13px 7px; box-shadow: 0 8px 20px rgba(0,0,0,.12); word-wrap: break-word; }
.mine .bubble { background: linear-gradient(140deg, #4165ed, #684cff); border-color: rgba(255,255,255,.12); border-radius: 18px 6px 18px 18px; }
.bubble p { margin: 0; font-size: 15px; line-height: 1.5; white-space: pre-wrap; }
.bubble-meta { display: flex; align-items: center; justify-content: flex-end; gap: 5px; color: rgba(255,255,255,.55); font-size: 9px; margin-top: 3px; min-width: 44px; }
.media-bubble { padding: 4px; overflow: hidden; }
.media-bubble img, .media-bubble video { display: block; width: min(260px, 64vw); max-height: 340px; object-fit: cover; border-radius: 14px; background: #0a0f22; }
.media-bubble .bubble-meta { position: absolute; right: 9px; bottom: 8px; padding: 3px 6px; border-radius: 8px; background: rgba(0,0,0,.5); color: white; }
.audio-bubble { min-width: 168px; cursor: pointer; }
.audio-line { display: flex; align-items: center; gap: 9px; }
.audio-play { width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(255,255,255,.16); }
.audio-bars { height: 24px; display: flex; align-items: center; gap: 2px; flex: 1; }
.audio-bars i { width: 3px; border-radius: 2px; background: rgba(255,255,255,.75); }
.edit-message { position: absolute; left: -36px; top: 8px; opacity: 0; border: 0; background: #1a2341; border-radius: 10px; width: 30px; height: 30px; transition: opacity .2s; }
.mine:hover .edit-message, .mine:focus-within .edit-message { opacity: 1; }
@keyframes message-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.panel { padding: 12px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--line); backdrop-filter: blur(20px); }
.panel-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 9px; color: var(--muted); font-size: 12px; }
.panel-title button { border: 0; background: transparent; color: #87a1ff; }
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; max-height: 160px; overflow: auto; }
.emoji-grid button { aspect-ratio: 1; font-size: 23px; border: 0; background: transparent; border-radius: 12px; }
.emoji-grid button:hover { background: rgba(255,255,255,.08); }
.attach-panel { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding-top: 18px; }
.attach-item { border: 0; background: transparent; display: grid; justify-items: center; gap: 8px; }
.attach-item span { width: 54px; height: 54px; display: grid; place-items: center; background: #212b4d; border-radius: 17px; font-size: 24px; }
.attach-item b { font-size: 11px; color: var(--muted); }

.composer-wrap { background: rgba(12,18,39,.94); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 4; }
.composer { min-height: 64px; padding: 9px 12px; display: flex; align-items: flex-end; gap: 8px; }
.composer-icon { width: 42px; height: 42px; flex: 0 0 auto; border: 0; border-radius: 14px; background: #1a2341; font-size: 20px; }
.input-wrap { min-height: 42px; flex: 1; display: flex; align-items: flex-end; background: #171f3b; border: 1px solid var(--line); border-radius: 15px; padding: 7px 5px 7px 12px; }
.input-wrap:focus-within { border-color: rgba(80,109,255,.7); box-shadow: 0 0 0 3px rgba(68,109,255,.1); }
.input-wrap textarea { width: 100%; max-height: 100px; resize: none; border: 0; outline: 0; color: var(--text); background: transparent; line-height: 1.45; padding: 2px 0; }
.input-wrap textarea::placeholder { color: #697593; }
.input-wrap button { width: 30px; height: 28px; border: 0; background: transparent; color: #9ca9c8; font-size: 21px; }
.send-button { width: 42px; height: 42px; flex: 0 0 auto; border: 0; border-radius: 14px; background: linear-gradient(145deg, #4a75ff, #5f44ee); box-shadow: 0 9px 22px rgba(69,92,240,.28); }
.editing-bar { height: 34px; padding: 0 15px; display: flex; align-items: center; justify-content: space-between; color: #9eb0ff; font-size: 12px; background: rgba(68,109,255,.1); }
.editing-bar button { border: 0; background: none; color: #ff8ca3; }
.record-button { margin: 0 12px 10px; width: calc(100% - 24px); height: 74px; border: 1px solid rgba(64,219,242,.2); border-radius: 18px; background: linear-gradient(135deg, rgba(55,103,255,.18), rgba(48,219,242,.09)); display: grid; grid-template-columns: 34px 1fr; grid-template-rows: 1fr 1fr; text-align: left; align-items: end; column-gap: 10px; }
.record-button .record-pulse { grid-row: 1 / 3; width: 28px; height: 28px; align-self: center; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 8px rgba(255,79,115,.13); }
.record-button.recording .record-pulse { animation: pulse 1s infinite; }
.record-button b { font-size: 13px; }
.record-button small { color: var(--muted); align-self: start; }
@keyframes pulse { 50% { box-shadow: 0 0 0 14px rgba(255,79,115,0); } }

.modal-backdrop { position: fixed; inset: 0; z-index: 20; display: grid; align-items: end; background: rgba(3,6,18,.7); backdrop-filter: blur(7px); }
.modal-card { width: min(100%, 720px); margin: auto; padding: 25px 22px calc(24px + env(safe-area-inset-bottom)); border-radius: 28px 28px 0 0; border: 1px solid var(--line); background: #151d38; box-shadow: 0 -20px 70px rgba(0,0,0,.35); animation: sheet-up .25s ease-out; }
.modal-card.compact { padding-bottom: calc(35px + env(safe-area-inset-bottom)); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
.modal-head { display: flex; justify-content: space-between; align-items: start; margin-bottom: 20px; }
.modal-head small { text-transform: uppercase; letter-spacing: .12em; color: #6887ff; }
.modal-head h2 { font-size: 19px; margin: 5px 0 0; }
.modal-head button { border: 0; background: #222c4c; width: 34px; height: 34px; border-radius: 11px; font-size: 20px; }
.avatar-editor { margin: 0 auto 22px; display: grid; gap: 8px; justify-items: center; border: 0; background: transparent; color: #8fa6ff; font-size: 12px; }
.avatar-editor img { width: 86px; height: 86px; border-radius: 28px; object-fit: cover; border: 3px solid rgba(102,132,255,.45); }
.field { display: grid; gap: 8px; color: var(--muted); font-size: 12px; }
.field input { height: 48px; border: 1px solid var(--line); border-radius: 15px; background: #10172d; color: var(--text); outline: 0; padding: 0 14px; }
.field input:focus { border-color: #5877ff; }
.primary-action { width: 100%; height: 49px; border: 0; border-radius: 15px; margin-top: 18px; background: linear-gradient(135deg, #4d78ff, #6845eb); font-weight: 700; }

.call-screen { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; background: radial-gradient(circle at 50% 20%, #203879, #0a1024 55%, #050814); overflow: hidden; padding: calc(80px + env(safe-area-inset-top)) 20px calc(42px + env(safe-area-inset-bottom)); }
.call-glow { position: absolute; width: 330px; height: 330px; border-radius: 50%; top: 20px; background: rgba(38,100,255,.25); filter: blur(60px); }
.call-screen > *:not(.call-glow) { z-index: 1; }
.call-screen > img { width: 112px; height: 112px; border-radius: 36px; object-fit: cover; box-shadow: 0 20px 80px rgba(33,95,255,.4); }
.call-screen > p { color: #6fcff0; letter-spacing: .12em; font-size: 11px; margin: 30px 0 8px; }
.call-screen h2 { font-size: 21px; margin: 0; text-align: center; }
.call-screen > span { color: var(--muted); font-size: 13px; }
.call-wave { height: 48px; display: flex; align-items: center; gap: 5px; margin: 28px 0 8px; }
.call-wave i { width: 4px; height: 12px; border-radius: 4px; background: linear-gradient(#5ef4ec, #5577ff); animation: wave .8s ease-in-out infinite alternate; }
.call-wave i:nth-child(2) { animation-delay: -.5s; }.call-wave i:nth-child(3) { animation-delay: -.2s; }.call-wave i:nth-child(4) { animation-delay: -.65s; }.call-wave i:nth-child(5) { animation-delay: -.35s; }
@keyframes wave { to { height: 42px; } }
.call-actions { width: min(330px, 90vw); margin-top: auto; display: flex; justify-content: space-between; align-items: center; }
.call-tool { width: 72px; border: 0; background: transparent; display: grid; gap: 9px; justify-items: center; }
.call-tool span { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,.11); font-size: 20px; }
.call-tool b { color: var(--muted); font-size: 11px; }
.hangup { width: 68px; height: 68px; border: 0; border-radius: 50%; background: var(--danger); font-size: 27px; transform: rotate(135deg); box-shadow: 0 13px 30px rgba(255,45,94,.27); }
.hangup:active { transform: rotate(135deg) scale(.96); }
.incoming-actions { margin-top: auto; width: min(300px, 85vw); display: flex; justify-content: space-between; }
.incoming-actions button { width: 82px; height: 56px; border: 0; border-radius: 18px; font-weight: 700; }
.decline { background: var(--danger); }.accept { background: var(--safe); }
.incoming-actions:not(.hidden) + audio, .incoming-actions:not(.hidden) ~ .call-actions { display: none; }
.toast { position: fixed; z-index: 50; bottom: calc(92px + env(safe-area-inset-bottom)); left: 50%; transform: translate(-50%, 20px); background: rgba(5,8,20,.92); border: 1px solid var(--line); border-radius: 13px; padding: 10px 14px; font-size: 12px; opacity: 0; pointer-events: none; transition: .2s; box-shadow: 0 10px 35px rgba(0,0,0,.25); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 721px) {
  body { background: radial-gradient(circle at center, #18264d, #050815 65%); padding: 18px; }
  .app-shell { height: calc(100dvh - 36px); border-radius: 30px; border: 1px solid var(--line); box-shadow: 0 30px 100px rgba(0,0,0,.45); }
  .modal-card { margin-bottom: 18px; border-radius: 28px; }
}
