:root {
  --night: #0B0720;
  --panel: #150C3A;
  --deep: #1E1250;
  --violet: #7C4DFF;
  --violet-dark: #4A2BC4;
  --gold: #FFC857;
  --mist: #5CE1E6;
  --text: #EDE7FF;
  --dim: #9C93C9;
  --danger: #FF6B8A;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--night);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 15px;
  overflow: hidden;
}
#app { height: 100dvh; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
.hidden { display: none !important; }

/* splash */
#splash { height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.splash-logo { font-size: 56px; }
.splash-name { font-size: 26px; font-weight: 800; color: var(--gold); }
.splash-tag { color: var(--dim); font-size: 13px; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel); padding: 10px 12px;
  border-bottom: 1px solid var(--deep);
  min-height: 56px; flex: 0 0 auto;
}
.topbar .title { font-weight: 800; font-size: 17px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-size: 11px; color: var(--dim); font-weight: 400; }
.back-btn { background: none; border: none; color: var(--gold); font-size: 20px; cursor: pointer; padding: 4px 8px; }
.icon-btn { background: none; border: none; color: var(--dim); font-size: 18px; cursor: pointer; padding: 6px; }
.icon-btn:hover { color: var(--gold); }

/* buttons */
.btn { border: none; cursor: pointer; font-weight: 700; font-size: 15px; padding: 12px 18px; border-radius: 12px; width: 100%; }
.btn.gold { background: var(--gold); color: var(--night); }
.btn.gold:disabled { background: var(--panel); color: var(--dim); }
.btn.ghost { background: transparent; color: var(--mist); border: 1px solid var(--mist); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.small { width: auto; padding: 8px 14px; font-size: 13px; }

/* forms */
.screen { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.field label { display: block; color: var(--dim); font-size: 12px; margin-bottom: 4px; }
.field input, .field textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--deep); border-radius: 12px;
  color: var(--text); padding: 12px; font-size: 15px; font-family: inherit; outline: none; resize: none;
}
.field input:focus, .field textarea:focus { border-color: var(--violet); }
.form-err { color: var(--danger); font-size: 13px; }
.form-note { color: var(--dim); font-size: 12px; }
.brand-head { text-align: center; padding: 24px 0 8px; }
.brand-head .logo { font-size: 44px; }
.brand-head .name { color: var(--gold); font-weight: 800; font-size: 22px; }
.brand-head .tag { color: var(--dim); font-size: 12px; }

/* stories bar */
.stories-bar { display: flex; gap: 12px; overflow-x: auto; padding: 12px; background: var(--night); flex: 0 0 auto; border-bottom: 1px solid var(--deep); }
.story-item { display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; flex: 0 0 auto; }
.story-ring { width: 58px; height: 58px; border-radius: 50%; padding: 3px; background: var(--deep); }
.story-ring.unseen { background: linear-gradient(135deg, var(--gold), var(--violet)); }
.story-ring img, .story-ring .avatar-fallback { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: var(--panel); display: flex; align-items: center; justify-content: center; font-size: 20px; }
.story-item .lbl { font-size: 11px; color: var(--dim); max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* chat list */
.chat-list { flex: 1; overflow-y: auto; }
.chat-row { display: flex; align-items: center; gap: 10px; padding: 12px; cursor: pointer; border-bottom: 1px solid var(--panel); }
.chat-row:hover { background: var(--panel); }
.chat-row .meta { flex: 1; min-width: 0; }
.chat-row .name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.chat-row .last { color: var(--dim); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row .side { text-align: left; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.chat-row .time { color: var(--dim); font-size: 11px; }
.unread { background: var(--gold); color: var(--night); font-size: 11px; font-weight: 800; border-radius: 999px; min-width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; padding: 0 6px; }

.avatar { border-radius: 50%; object-fit: cover; background: var(--panel); flex: 0 0 auto; }
.avatar-fallback { border-radius: 50%; background: var(--violet-dark); color: var(--text); display: flex; align-items: center; justify-content: center; font-weight: 800; flex: 0 0 auto; }
.dev-badge { background: linear-gradient(90deg, var(--gold), var(--mist)); color: var(--night); font-size: 10px; font-weight: 800; border-radius: 8px; padding: 2px 6px; white-space: nowrap; }

/* messages */
.msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.msg-row { display: flex; }
.msg-row.mine { justify-content: flex-end; }
.bubble { max-width: 78%; background: var(--panel); border-radius: 14px; padding: 8px 10px; position: relative; cursor: default; }
.msg-row.mine .bubble { background: var(--violet-dark); }
.bubble .reply-quote { border-right: 3px solid var(--gold); padding-right: 6px; margin-bottom: 6px; color: var(--dim); font-size: 12px; }
.bubble .txt { white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.bubble img.media { max-width: 240px; max-height: 300px; border-radius: 10px; display: block; cursor: zoom-in; }
.bubble video.media { max-width: 240px; max-height: 300px; border-radius: 10px; display: block; }
.bubble .caption { margin-top: 6px; font-size: 14px; white-space: pre-wrap; }
.bubble .m-meta { display: flex; gap: 6px; justify-content: flex-end; align-items: center; margin-top: 4px; font-size: 10px; color: var(--dim); }
.bubble .reactions { position: absolute; bottom: -12px; left: 8px; background: var(--deep); border-radius: 999px; padding: 1px 6px; font-size: 12px; }
.bubble .ai-tag { background: var(--mist); color: var(--night); font-size: 9px; font-weight: 800; border-radius: 6px; padding: 1px 5px; }
.msg-row .acts { display: none; flex-direction: column; justify-content: center; gap: 2px; margin: 0 4px; }
.msg-row:hover .acts { display: flex; }
.acts button { background: var(--panel); border: none; color: var(--dim); border-radius: 8px; cursor: pointer; font-size: 13px; padding: 3px 7px; }
.acts button:hover { color: var(--gold); }

/* composer */
.composer { flex: 0 0 auto; display: flex; align-items: flex-end; gap: 8px; padding: 10px; background: var(--panel); border-top: 1px solid var(--deep); }
.composer textarea { flex: 1; background: var(--night); border: 1px solid var(--deep); border-radius: 12px; color: var(--text); padding: 10px; font-family: inherit; font-size: 15px; resize: none; max-height: 110px; outline: none; }
.send-btn { background: var(--gold); color: var(--night); border: none; border-radius: 50%; width: 44px; height: 44px; font-size: 18px; cursor: pointer; flex: 0 0 auto; }
.send-btn:disabled { background: var(--deep); color: var(--dim); }
.reply-strip { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; background: var(--panel); padding: 6px 12px; border-top: 1px solid var(--deep); font-size: 12px; color: var(--dim); }
.reply-strip .x { margin-right: auto; background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; }

/* AI panel */
.ai-panel { flex: 0 0 auto; max-height: 45%; overflow-y: auto; background: var(--night); border-top: 1px solid var(--violet); padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.ai-panel .ai-head { color: var(--violet); font-size: 12px; font-weight: 700; }
.ai-msg { border-radius: 10px; padding: 8px 10px; font-size: 14px; white-space: pre-wrap; }
.ai-msg.q { background: var(--violet-dark); align-self: flex-start; }
.ai-msg.a { background: var(--panel); align-self: flex-end; }
.ai-msg .send-answer { margin-top: 6px; }

/* story viewer overlay */
.viewer { position: fixed; inset: 0; background: #000; z-index: 50; display: flex; flex-direction: column; }
.viewer .prog-row { display: flex; gap: 4px; padding: 10px 10px 0; }
.viewer .prog { flex: 1; height: 3px; background: rgba(255,255,255,.3); border-radius: 2px; overflow: hidden; }
.viewer .prog > div { height: 100%; background: var(--gold); width: 0; }
.viewer .v-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: rgba(0,0,0,.35); }
.viewer .v-head .n { font-weight: 700; font-size: 14px; color: #fff; display: flex; gap: 6px; align-items: center; }
.viewer .v-head .t { color: rgba(255,255,255,.7); font-size: 11px; }
.viewer .v-body { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.viewer .v-body img, .viewer .v-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .v-text { font-size: 26px; font-weight: 800; color: #fff; text-align: center; padding: 28px; }
.viewer .v-caption { position: absolute; bottom: 12px; left: 0; right: 0; text-align: center; color: #fff; text-shadow: 0 1px 4px #000; font-size: 15px; padding: 0 20px; }
.viewer .v-foot { padding: 10px; background: rgba(0,0,0,.4); display: flex; gap: 8px; align-items: center; }
.viewer .v-foot input { flex: 1; background: rgba(255,255,255,.12); border: none; border-radius: 999px; color: #fff; padding: 10px 14px; outline: none; font-family: inherit; }
.viewer .v-close { background: none; border: none; color: #fff; font-size: 22px; cursor: pointer; }
.viewer .v-del { background: none; border: none; color: var(--danger); font-size: 18px; cursor: pointer; }
.viewer .v-seen { background: none; border: none; color: var(--gold); font-size: 13px; cursor: pointer; white-space: nowrap; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--panel); border-radius: 16px; padding: 18px; max-width: 420px; width: 100%; display: flex; flex-direction: column; gap: 12px; }
.modal-title { font-weight: 800; color: var(--gold); font-size: 16px; }
.modal-body { color: var(--text); font-size: 14px; white-space: pre-wrap; }
.modal-actions { display: flex; gap: 10px; }

/* toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--deep); color: var(--text); border: 1px solid var(--violet); padding: 10px 18px; border-radius: 999px; z-index: 70; font-size: 14px; max-width: 90%; }

/* media composer (pre-send) */
.mediacomp { position: fixed; inset: 0; background: #000; z-index: 55; display: flex; flex-direction: column; }
.mediacomp .mc-body { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.mediacomp .mc-body img, .mediacomp .mc-body video { max-width: 100%; max-height: 100%; object-fit: contain; }
.mediacomp .mc-bar { display: flex; gap: 8px; align-items: center; padding: 10px; background: rgba(0,0,0,.55); }
.mediacomp .mc-bar input { flex: 1; background: rgba(255,255,255,.12); border: none; border-radius: 999px; color: #fff; padding: 10px 14px; outline: none; font-family: inherit; }
.mc-tools { display: flex; gap: 6px; padding: 8px 10px 0; flex-wrap: wrap; }
.mc-tools .chip { background: var(--deep); color: var(--text); border: 1px solid var(--violet); border-radius: 999px; padding: 6px 12px; font-size: 12px; cursor: pointer; }
.mc-tools .chip.on { background: var(--violet); }
.mc-undo { background: var(--deep); border: 1px solid var(--gold); color: var(--gold); border-radius: 999px; padding: 6px 12px; font-size: 12px; cursor: pointer; }

.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--dim); gap: 8px; padding: 30px; text-align: center; }
.tabs { display: flex; background: var(--panel); flex: 0 0 auto; }
.tabs button { flex: 1; background: none; border: none; color: var(--dim); padding: 10px; font-size: 14px; font-weight: 700; cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--gold); border-bottom-color: var(--gold); }

* { scrollbar-width: thin; scrollbar-color: #4A2BC4 #150C3A; }

.msg-row { justify-content: flex-end; }
.msg-row.mine { justify-content: flex-start; }
