:root {
  --purple-900: #241934;
  --purple-700: #3a2560;
  --purple-600: #4b2e83;
  --gold: #c9962c;
  --gold-light: #f0d48a;
  --bg: #1a1226;
  --surface: #2a1e42;
  --surface-2: #34275a;
  --text: #f4f1f8;
  --text-dim: #b9aed0;
  --bubble-me: linear-gradient(135deg, #4b2e83, #6a3fb5);
  --bubble-them: #34275a;
  --success: #3ddc97;
  --radius: 16px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at 50% -10%, #3a2560 0%, var(--bg) 60%);
  color: var(--text);
  overflow: hidden;
}

#app { height: 100vh; display: flex; flex-direction: column; }

.screen { display: none; flex-direction: column; height: 100%; }
.screen.active { display: flex; }

/* ---------- Login ---------- */
#screen-login {
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}
.lamp-emoji {
  font-size: 76px;
  filter: drop-shadow(0 0 24px var(--gold));
  animation: float 3.2s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-10px) rotate(2deg); }
}
.brand-title {
  font-size: 30px;
  font-weight: 800;
  background: linear-gradient(90deg, var(--gold-light), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin: 8px 0 2px;
}
.brand-tagline { color: var(--text-dim); font-size: 14px; margin-bottom: 32px; }

.input-row { width: 100%; max-width: 340px; }
input[type="email"], input[type="text"] {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid #4b3a72;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
input:focus { border-color: var(--gold); }

.btn-primary {
  margin-top: 14px;
  width: 100%;
  max-width: 340px;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(90deg, var(--gold), #e0b84f);
  color: #241934;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; }

.helper-text { color: var(--text-dim); font-size: 12.5px; margin-top: 18px; max-width: 320px; }

.dev-box {
  margin-top: 20px;
  padding: 14px;
  background: var(--surface);
  border: 1px dashed var(--gold);
  border-radius: 12px;
  max-width: 340px;
  font-size: 13px;
  text-align: left;
}
.dev-box b { color: var(--gold-light); }
.dev-box button {
  margin-top: 10px; width: 100%; padding: 10px; border-radius: 8px; border: none;
  background: var(--success); color: #05281d; font-weight: 700; cursor: pointer;
}

/* ---------- Chat list ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; background: var(--purple-700);
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  padding-top: max(16px, env(safe-area-inset-top)); /* iPhone çıxıntısı (notch/saat zolağı) altında qalmasın */
}
.topbar h2 { margin: 0; font-size: 19px; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: rgba(255,255,255,.08); border: none; color: var(--text);
  width: 36px; height: 36px; border-radius: 10px; font-size: 16px; cursor: pointer;
}

.search-box { padding: 10px 14px; }
.search-box input { background: var(--surface); }

.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 90px; }
.chat-item {
  display: flex; gap: 12px; align-items: center;
  padding: 12px; border-radius: 14px; cursor: pointer;
}
.chat-item:active { background: var(--surface); }
.avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--purple-600));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: #fff; flex-shrink: 0; font-size: 18px;
}
.chat-meta { flex: 1; min-width: 0; }
.chat-meta .name { font-weight: 600; font-size: 15px; }
.chat-meta .preview {
  color: var(--text-dim); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-side { text-align: right; }
.chat-side .time { color: var(--text-dim); font-size: 11px; }
.badge {
  background: var(--gold); color: #241934; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 2px 7px; display: inline-block; margin-top: 4px;
}

.fab {
  position: absolute; right: 20px; bottom: 24px;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--gold), #e0b84f);
  font-size: 24px; box-shadow: 0 6px 18px rgba(0,0,0,.4); cursor: pointer;
}

/* ---------- Chat window ---------- */
/* overflow:hidden vacibdir — klaviatura açılanda #app-ın hündürlüyü JS ilə kiçilir (bax app.js/fixKeyboardViewport),
   bu da .cin-panel-in "bağlı" vəziyyətdə ekranın altına gizlənməsini (translateY(100%)) pozub onu görünən edirdi. */
#screen-chat { position: relative; overflow: hidden; }
.chat-header {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: var(--purple-700); box-shadow: 0 2px 10px rgba(0,0,0,.25);
  padding-top: max(14px, env(safe-area-inset-top)); /* iPhone çıxıntısı (notch/saat zolağı) altında qalmasın */
}
.chat-header .back { background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer; }
.chat-header .who { flex: 1; }
.chat-header .who .name { font-weight: 700; font-size: 15px; }
.chat-header .who .status { font-size: 12px; color: var(--text-dim); }

.messages {
  flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px;
}
.bubble {
  max-width: 75%; padding: 10px 14px; border-radius: 16px; font-size: 14.5px; line-height: 1.35;
  position: relative; word-wrap: break-word;
}
.bubble.me {
  align-self: flex-end; background: var(--bubble-me); color: #fff; border-bottom-right-radius: 4px;
}
.bubble.them {
  align-self: flex-start; background: var(--bubble-them); border-bottom-left-radius: 4px;
}
.bubble .meta { display: block; margin-top: 4px; font-size: 10.5px; opacity: .75; text-align: right; }
.typing-indicator { font-size: 12px; color: var(--text-dim); padding: 0 16px 4px; height: 16px; }

.composer {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--purple-700);
  padding-bottom: max(10px, env(safe-area-inset-bottom)); /* iPhone-da alt "home indicator" zolağının üstündə qalsın */
}
.composer input {
  flex: 1; border: none; border-radius: 22px; padding: 12px 16px; background: var(--surface);
  color: var(--text); outline: none;
}
.composer button.send {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--gold), #e0b84f); font-size: 18px; cursor: pointer;
}
.composer button.cin {
  position: relative;
  z-index: 70; /* .cin-panel-dən (z-index yoxdur/auto) həmişə üstdə qalsın ki, tüstü animasiyası panelin altında itməsin */
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: var(--surface-2); font-size: 20px; cursor: pointer;
  overflow: visible;
}
.composer button.attach,
.composer button.mic {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--surface-2); color: var(--text); font-size: 17px; cursor: pointer; flex-shrink: 0;
}
.composer button.mic.recording {
  background: #d64545;
  animation: micPulse 1.1s ease-in-out infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(214,69,69,.55); }
  50% { box-shadow: 0 0 0 8px rgba(214,69,69,0); }
}
.rec-timer {
  color: #ff8a8a; font-size: 12.5px; font-weight: 700; flex-shrink: 0; white-space: nowrap;
}

/* ---------- Şəkil/səs mesaj bubble-ları ---------- */
.bubble img.msg-image {
  display: block; max-width: 220px; max-height: 280px; border-radius: 12px;
  margin-bottom: 2px; object-fit: cover; cursor: pointer;
}
.bubble audio.msg-audio {
  width: 220px; margin-bottom: 2px; display: block;
}
.bubble .media-loading {
  font-size: 12.5px; color: var(--text-dim); padding: 10px 4px; min-width: 120px;
}
.bubble .media-gone {
  font-size: 13px; color: var(--text-dim); font-style: italic;
  display: flex; align-items: center; gap: 6px; padding: 2px 0;
}

.composer button.cin.summoning { animation: lampShake 0.5s ease-in-out; }
@keyframes lampShake {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-12deg); }
  40% { transform: rotate(10deg); }
  60% { transform: rotate(-6deg); }
  80% { transform: rotate(4deg); }
}

/* ---------- Cin çağırma animasiyası (tüstü + cin) ---------- */
.genie-fx {
  position: absolute;
  left: 50%; bottom: 100%;
  width: 70px; height: 130px;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 60;
}
.smoke-puff {
  position: absolute;
  bottom: 0; left: 50%;
  width: 12px; height: 12px;
  background: radial-gradient(circle, rgba(255,255,255,.75), rgba(240,212,138,0) 70%);
  border-radius: 50%;
  opacity: 0;
}
.genie-emerge {
  position: absolute;
  bottom: 6px; left: 50%;
  font-size: 30px;
  opacity: 0;
  transform: translate(-50%, 10px) scale(.3);
  filter: drop-shadow(0 0 10px var(--gold));
}
.genie-fx.play .smoke-puff { animation: smokeRise 1.1s ease-out forwards; }
.genie-fx.play .smoke-puff:nth-child(1) { left: 30%; animation-delay: 0s; }
.genie-fx.play .smoke-puff:nth-child(2) { left: 50%; animation-delay: .08s; }
.genie-fx.play .smoke-puff:nth-child(3) { left: 66%; animation-delay: .16s; }
.genie-fx.play .smoke-puff:nth-child(4) { left: 40%; animation-delay: .22s; }
.genie-fx.play .smoke-puff:nth-child(5) { left: 60%; animation-delay: .3s; }
.genie-fx.play .smoke-puff:nth-child(6) { left: 50%; animation-delay: .38s; }
.genie-fx.play .genie-emerge { animation: genieEmerge .9s cubic-bezier(.34,1.56,.64,1) forwards; animation-delay: .25s; }

@keyframes smokeRise {
  0%   { opacity: 0; transform: translate(-50%, 0) scale(.4); }
  25%  { opacity: .85; }
  100% { opacity: 0; transform: translate(-50%, -95px) scale(1.8); }
}
@keyframes genieEmerge {
  0%   { opacity: 0; transform: translate(-50%, 16px) scale(.2) rotate(-8deg); }
  55%  { opacity: 1; transform: translate(-50%, -18px) scale(1.15) rotate(4deg); }
  75%  { transform: translate(-50%, -10px) scale(1) rotate(-2deg); }
  100% { opacity: 0; transform: translate(-50%, -30px) scale(.9) rotate(0deg); }
}

.cin-usage-badge {
  font-size: 11px; font-weight: 600; color: var(--gold-light);
  background: rgba(201,150,44,.15); border: 1px solid var(--gold);
  border-radius: 999px; padding: 2px 9px; margin-left: 6px; vertical-align: middle;
}
.cin-paywall {
  background: var(--surface-2); border: 1px dashed var(--gold); border-radius: 12px;
  padding: 14px; font-size: 13.5px; text-align: center;
}
.cin-paywall button {
  margin-top: 10px; width: 100%; padding: 11px; border-radius: 10px; border: none;
  background: linear-gradient(90deg, var(--gold), #e0b84f); color: #241934; font-weight: 700; cursor: pointer;
}

/* ---------- Cin panel ---------- */
.cin-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-top: 1px solid var(--gold);
  border-radius: 18px 18px 0 0; padding: 14px; transform: translateY(100%);
  transition: transform .25s ease; max-height: 55%; overflow-y: auto;
}
.cin-panel.open { transform: translateY(0); }
.cin-panel h4 { margin: 0 0 10px; color: var(--gold-light); display: flex; gap: 6px; align-items: center; }
.cin-option {
  background: var(--surface-2); border: none; color: var(--text); text-align: left;
  padding: 12px; border-radius: 10px; margin-bottom: 8px; width: 100%; cursor: pointer; font-size: 14px;
}
.cin-suggestion {
  background: var(--purple-600); border: none; color: #fff; text-align: left;
  padding: 10px 12px; border-radius: 10px; margin-bottom: 6px; width: 100%; cursor: pointer; font-size: 13.5px;
}

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); color: var(--text); padding: 10px 18px; border-radius: 30px;
  font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.4); z-index: 999; opacity: 0; transition: opacity .3s;
}
.toast.show { opacity: 1; }

/* ---------- Zəng ekranı ---------- */
#call-btn { font-size: 18px; }

.call-overlay {
  position: fixed; inset: 0; z-index: 1200;
  background: radial-gradient(circle at 50% 20%, var(--purple-700) 0%, var(--purple-900) 70%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 24px; text-align: center;
}
.call-avatar {
  width: 110px; height: 110px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), #8a5a1f);
  display: flex; align-items: center; justify-content: center;
  font-size: 42px; font-weight: 800; color: var(--purple-900);
  box-shadow: 0 0 0 6px rgba(240,212,138,.15);
  animation: callPulse 1.8s ease-in-out infinite;
}
@keyframes callPulse {
  0%, 100% { box-shadow: 0 0 0 6px rgba(240,212,138,.15); }
  50% { box-shadow: 0 0 0 16px rgba(240,212,138,.05); }
}
.call-name { margin-top: 20px; font-size: 22px; font-weight: 700; }
.call-status { margin-top: 8px; color: var(--text-dim); font-size: 14px; }
.call-actions { display: flex; gap: 28px; margin-top: 56px; }
.call-btn {
  width: 62px; height: 62px; border-radius: 50%; border: none; cursor: pointer;
  font-size: 24px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 16px rgba(0,0,0,.35);
}
.call-btn.end, .call-btn.reject { background: #e5484d; color: #fff; }
.call-btn.accept { background: var(--success); color: #0b3324; }
.call-btn.mute { background: var(--surface-2); color: var(--text); }
.call-btn.mute.muted { background: var(--gold); color: var(--purple-900); }
