@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700;800&display=swap');

:root {
  --bg: #0b0e17;
  --bg-elev: #10141f;
  --card: #171d2e;
  --card-2: #1d2436;
  --line: #262e45;
  --text: #eceafc;
  --text-dim: #9098b5;
  --accent: #a16bff;
  --accent-soft: rgba(161, 107, 255, .16);
  --accent-2: #37e6c4;
  --danger: #ff5d7a;
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Vazirmatn', sans-serif;
  direction: rtl;
}

body {
  display: flex;
  justify-content: center;
}

#app-frame {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 60px rgba(0,0,0,.5);
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; }
input, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ---------- ghost/mask signature element ---------- */
.ghost-avatar {
  width: 100%; height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #2a2f47 0%, #171b2b 60%, #0d0f19 100%);
  position: relative;
  overflow: hidden;
}
.ghost-avatar::after {
  content: '';
  position: absolute; inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 6px 6px;
  opacity: .5;
}
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  overflow: hidden; flex-shrink: 0;
  border: 1px solid var(--line);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.id-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; letter-spacing: .5px;
  padding: 3px 10px;
  border: 1px dashed var(--accent);
  color: var(--accent);
  border-radius: 999px;
  background: var(--accent-soft);
  font-weight: 600;
  direction: ltr;
}

/* ---------- auth screens ---------- */
#screen-auth {
  flex: 1; display: flex; flex-direction: column;
  justify-content: center; padding: 32px 24px;
  background:
    radial-gradient(circle at 20% -10%, rgba(161,107,255,.25), transparent 45%),
    radial-gradient(circle at 100% 110%, rgba(55,230,196,.15), transparent 45%),
    var(--bg);
}
.auth-logo {
  text-align: center; margin-bottom: 28px;
}
.auth-logo .mark {
  width: 64px; height: 64px; margin: 0 auto 14px;
  border-radius: 22px;
  background: linear-gradient(145deg, var(--accent), #6a3fd1);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  box-shadow: 0 10px 30px rgba(161,107,255,.35);
}
.auth-logo h1 { font-size: 22px; font-weight: 800; margin: 0; }
.auth-logo p { color: var(--text-dim); font-size: 13px; margin-top: 6px; }

.auth-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}
.tabs-switch {
  display: flex; background: var(--bg-elev);
  border-radius: 12px; padding: 4px; margin-bottom: 18px;
}
.tabs-switch button {
  flex: 1; padding: 10px; border-radius: 9px;
  background: transparent; color: var(--text-dim); font-weight: 600; font-size: 14px;
}
.tabs-switch button.active { background: var(--accent); color: #fff; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 13px 14px; border-radius: 12px;
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--text);
  font-size: 14px; direction: ltr; text-align: right;
}
.field input:focus { outline: none; border-color: var(--accent); }

.btn-primary {
  width: 100%; padding: 13px; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 15px;
  transition: transform .15s;
}
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .5; }

.form-msg { font-size: 13px; margin: 8px 0; min-height: 18px; }
.form-msg.error { color: var(--danger); }
.form-msg.ok { color: var(--accent-2); }

.otp-boxes { display: flex; gap: 8px; direction: ltr; margin-bottom: 6px; }
.otp-boxes input {
  width: 42px; height: 52px; text-align: center; font-size: 20px;
  border-radius: 10px; background: var(--bg-elev); border: 1px solid var(--line); color: var(--text);
}

/* ---------- main app shell ---------- */
#screen-main { flex: 1; display: none; flex-direction: column; min-height: 100vh; }
#screen-main.active { display: flex; }

.topbar {
  padding: 16px 18px 0;
  display: flex; flex-direction: column; gap: 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; }
.topbar-row h2 { font-size: 18px; margin: 0; font-weight: 800; }

.top-tabs { display: flex; gap: 22px; }
.top-tabs button {
  background: none; color: var(--text-dim); font-size: 14px; font-weight: 700;
  padding: 10px 2px; border-bottom: 2px solid transparent;
}
.top-tabs button.active { color: var(--text); border-color: var(--accent); }

.list-wrap { flex: 1; overflow-y: auto; padding: 14px 16px 90px; }
.chat-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px;
}
.chat-card .info { flex: 1; min-width: 0; }
.chat-card .info h3 { font-size: 15px; margin: 0 0 4px; font-weight: 700; }
.chat-card .info span { font-size: 12px; color: var(--text-dim); }
.chat-card .chat-icon {
  width: 44px; height: 44px; border-radius: 14px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
  background: var(--accent-soft); color: var(--accent);
}
.chat-card button.join-btn {
  padding: 8px 14px; border-radius: 10px; font-size: 12px; font-weight: 700;
  background: var(--accent); color: #fff;
}
.chat-card button.join-btn.joined { background: var(--bg-elev); color: var(--accent-2); border: 1px solid var(--accent-2); }

.empty-state { text-align: center; color: var(--text-dim); padding: 60px 20px; font-size: 14px; }

.fab {
  position: absolute; left: 18px; bottom: 92px;
  width: 54px; height: 54px; border-radius: 50%;
  background: linear-gradient(145deg, var(--accent), #6a3fd1);
  color: #fff; font-size: 26px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 24px rgba(161,107,255,.4);
  z-index: 5;
}

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: sticky; bottom: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-around;
  background: var(--bg-elev); border-top: 1px solid var(--line);
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  z-index: 4;
}
.nav-btn {
  background: none; display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--text-dim); font-size: 11px; font-weight: 600; width: 70px;
}
.nav-btn .ico { font-size: 20px; }
.nav-btn.active { color: var(--accent); }
.nav-btn.center .ico {
  width: 46px; height: 46px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); font-size: 22px;
}
.nav-btn.center.active .ico { background: var(--accent); color: #fff; }

/* ---------- modal (create / join chat) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,7,12,.7);
  display: none; align-items: flex-end; justify-content: center; z-index: 30;
}
.modal-backdrop.active { display: flex; }
.modal-sheet {
  width: 100%; max-width: 480px; background: var(--card);
  border-radius: 22px 22px 0 0; padding: 22px; border: 1px solid var(--line); border-bottom: none;
}
.modal-sheet h3 { margin: 0 0 16px; font-size: 16px; font-weight: 800; }
.seg { display: flex; gap: 8px; margin-bottom: 16px; }
.seg button {
  flex: 1; padding: 10px; border-radius: 10px; background: var(--bg-elev);
  color: var(--text-dim); font-size: 13px; font-weight: 700; border: 1px solid var(--line);
}
.seg button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.code-result {
  text-align: center; padding: 16px; border-radius: 12px; background: var(--bg-elev);
  margin-top: 10px; display: none;
}
.code-result.active { display: block; }
.code-result .code { font-size: 26px; font-weight: 800; letter-spacing: 6px; color: var(--accent-2); direction: ltr; }
.close-modal { text-align: center; color: var(--text-dim); font-size: 13px; margin-top: 14px; display: block; width: 100%; padding: 6px; }

/* ---------- chat room ---------- */
#screen-chat {
  position: fixed; inset: 0; max-width: 480px; margin: 0 auto;
  background: var(--bg); display: none; flex-direction: column; z-index: 20;
}
#screen-chat.active { display: flex; }
.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  background: var(--bg-elev); border-bottom: 1px solid var(--line);
}
.chat-header .back-btn { font-size: 20px; color: var(--text-dim); }
.chat-header .title { flex: 1; }
.chat-header .title h3 { margin: 0; font-size: 15px; font-weight: 700; }
.chat-header .title span { font-size: 11px; color: var(--text-dim); }
.chat-header .menu-btn { font-size: 18px; color: var(--text-dim); padding: 4px 8px; }

.messages {
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
}
.msg-row { display: flex; gap: 8px; max-width: 82%; }
.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-row .bubble {
  background: var(--card); border: 1px solid var(--line);
  padding: 9px 13px; border-radius: 16px 16px 16px 4px; font-size: 14px; line-height: 1.7;
  word-break: break-word;
}
.msg-row.mine .bubble { background: var(--accent); border-color: var(--accent); border-radius: 16px 16px 4px 16px; color: #fff; }
.msg-row .bubble img { max-width: 100%; border-radius: 10px; display: block; }
.msg-row .bubble.sticker { background: none; border: none; padding: 0; font-size: 46px; }
.msg-row .meta { font-size: 10px; color: var(--text-dim); margin-top: 4px; }
.msg-row.mine .meta { text-align: left; color: rgba(255,255,255,.65); }

.chat-input-bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  background: var(--bg-elev); border-top: 1px solid var(--line);
}
.chat-input-bar textarea {
  flex: 1; resize: none; max-height: 90px; padding: 11px 14px; border-radius: 20px;
  background: var(--card); border: 1px solid var(--line); color: var(--text); font-size: 14px;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; background: var(--card);
  color: var(--text-dim); font-size: 18px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); flex-shrink: 0;
}
.icon-btn.send { background: var(--accent); color: #fff; border: none; }

.sticker-panel {
  display: none; grid-template-columns: repeat(6, 1fr); gap: 6px;
  padding: 12px 14px; background: var(--bg-elev); border-top: 1px solid var(--line);
  max-height: 160px; overflow-y: auto;
}
.sticker-panel.active { display: grid; }
.sticker-panel button { background: none; font-size: 26px; padding: 4px; border-radius: 8px; }
.sticker-panel button:active { background: var(--card); }

/* ---------- profile & settings ---------- */
#screen-profile, #screen-settings {
  position: fixed; inset: 0; max-width: 480px; margin: 0 auto;
  background: var(--bg); display: none; flex-direction: column; z-index: 20; overflow-y: auto;
}
#screen-profile.active, #screen-settings.active { display: flex; }
.sub-header {
  display: flex; align-items: center; gap: 12px; padding: 16px;
  background: var(--bg-elev); border-bottom: 1px solid var(--line);
}
.sub-header h3 { margin: 0; font-size: 16px; font-weight: 800; }
.sub-header .back-btn { font-size: 20px; color: var(--text-dim); }

.profile-hero { display: flex; flex-direction: column; align-items: center; padding: 28px 20px; gap: 12px; }
.profile-hero .avatar-lg {
  width: 96px; height: 96px; border-radius: 50%; overflow: hidden; position: relative;
  border: 2px solid var(--accent);
}
.profile-hero .avatar-lg img { width: 100%; height: 100%; object-fit: cover; }
.profile-hero .avatar-lg .edit-badge {
  position: absolute; bottom: 0; left: 0; width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px;
  border: 2px solid var(--bg);
}

.info-list { padding: 0 16px 20px; }
.info-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 4px; border-bottom: 1px solid var(--line);
}
.info-row .lbl { color: var(--text-dim); font-size: 13px; }
.info-row .val { font-size: 14px; font-weight: 600; direction: ltr; }
.info-row input {
  background: transparent; border: none; color: var(--text); font-size: 14px; text-align: left; direction: ltr; width: 60%;
}

.settings-group { padding: 6px 16px 20px; }
.settings-group h4 { font-size: 12px; color: var(--text-dim); margin: 18px 4px 8px; font-weight: 700; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 4px; border-bottom: 1px solid var(--line); font-size: 14px;
}
.settings-row.danger { color: var(--danger); }
.font-size-ctrl { display: flex; align-items: center; gap: 10px; }
.font-size-ctrl button {
  width: 30px; height: 30px; border-radius: 8px; background: var(--card); color: var(--text);
  border: 1px solid var(--line); font-size: 15px;
}
.font-size-ctrl span { min-width: 30px; text-align: center; font-size: 13px; color: var(--text-dim); }

.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--line); padding: 10px 18px; border-radius: 12px;
  font-size: 13px; z-index: 50; opacity: 0; transition: opacity .25s; pointer-events: none;
}
.toast.show { opacity: 1; }
