.chat-shell {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(8, 6, 13, 0.96);
  backdrop-filter: blur(20px);
  display: grid;
  place-items: center;
}
.chat-frame {
  position: relative;
  overflow: hidden;
  width: min(760px, 100%);
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle 420px at 85% 0%, rgba(255, 94, 132, 0.14), transparent 70%),
    #110c17;
  border-inline: 1px solid var(--rule);
}
.chat-backdrop {
  position: absolute;
  inset: -20px;
  z-index: 0;
  background-size: cover;
  background-position: center 18%;
  filter: blur(28px) saturate(1.2) brightness(0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}
.chat-frame.with-backdrop .chat-backdrop { opacity: 0.24; }
.chat-frame > :not(.chat-backdrop) { position: relative; z-index: 1; }

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(10px, var(--tg-safe-top, env(safe-area-inset-top))) 12px 10px;
  background: rgba(20, 14, 28, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--rule);
  flex: 0 0 auto;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--peach); }
.chat-person-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  padding: 2px 4px;
  text-align: left;
}
.chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 15%;
  border: 2px solid var(--peach);
  flex-shrink: 0;
}
.chat-person-meta { flex: 1; min-width: 0; }
.chat-name-row { display: flex; align-items: center; gap: 7px; }
.chat-name-row strong { font-size: 0.98rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.online-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.67rem;
  font-weight: 700;
  color: var(--green);
}
.online-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.affinity-inline { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.affinity-inline span { font-size: 0.71rem; color: var(--muted); white-space: nowrap; }
.affinity-track { flex: 1; max-width: 130px; height: 5px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.affinity-fill { height: 100%; width: 0%; background: var(--grad); border-radius: 999px; transition: width 0.35s ease; }
.chat-header-actions { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.mini-wallet {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 156, 110, 0.35);
  background: rgba(255, 107, 139, 0.14);
  font-size: 0.78rem;
  font-weight: 800;
}

.chat-banner {
  padding: 7px 14px;
  font-size: 0.74rem;
  color: #ffd7c4;
  background: rgba(255, 156, 110, 0.12);
  border-bottom: 1px solid rgba(255, 156, 110, 0.25);
  text-align: center;
}
.chat-levelup {
  padding: 9px 14px;
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
  color: #190813;
  background: var(--grad);
  animation: levelup-pop 0.35s ease;
}
@keyframes levelup-pop {
  from { transform: translateY(-8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg-row { display: flex; gap: 9px; align-items: flex-end; max-width: 88%; }
.msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.assistant { align-self: flex-start; }
.msg-mini-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 15%;
  flex-shrink: 0;
}
.msg-stack { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.msg-row.user .msg-stack { align-items: flex-end; }
.msg-bubble {
  padding: 11px 14px;
  border-radius: 18px;
  font-size: 0.93rem;
  line-height: 1.45;
  word-break: break-word;
}
.msg-row.assistant .msg-bubble {
  background: rgba(32, 24, 43, 0.92);
  border: 1px solid var(--rule);
  border-bottom-left-radius: 5px;
  color: #f8effb;
}
.msg-row.user .msg-bubble {
  background: var(--grad);
  border-bottom-right-radius: 5px;
  color: #190813;
  font-weight: 600;
}
.msg-row.gift .msg-bubble {
  background: linear-gradient(135deg, rgba(255, 94, 132, 0.28), rgba(255, 156, 110, 0.24));
  border: 1px solid rgba(255, 156, 110, 0.5);
  color: #fff;
}
.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-inline: 4px;
  font-size: 0.68rem;
  color: var(--muted);
}
.msg-tool {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
}
.msg-tool:hover, .msg-tool.speaking { color: var(--peach-2); background: rgba(255, 107, 139, 0.14); }
.msg-action { font-style: italic; color: #f6b8d0; }
.msg-row.user .msg-action { color: #3a0f26; }
.msg-photo-wrap {
  margin-bottom: 8px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  cursor: zoom-in;
  position: relative;
}
.msg-photo {
  display: block;
  width: min(270px, 68vw);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  object-position: center 15%;
}
.msg-video {
  display: block;
  width: min(270px, 68vw);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #09060d;
}
.msg-animate-btn {
  position: absolute;
  bottom: 8px;
  right: 8px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 0;
  background: var(--grad);
  color: #170912;
  font-size: 0.68rem;
  font-weight: 800;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.45);
}
.msg-photo-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(12, 9, 17, 0.78);
  font-size: 0.68rem;
  font-weight: 700;
  color: #ffd4df;
}

/* Contextual Suggestions Strip */
.chat-suggestions {
  display: flex;
  gap: 6px;
  padding: 6px 12px 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 0 0 auto;
}
.chat-suggestions::-webkit-scrollbar { display: none; }
.suggestion-pill {
  flex: 0 0 auto;
  max-width: 260px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 107, 139, 0.35);
  background: rgba(255, 107, 139, 0.1);
  color: #ffe0ea;
  font-size: 0.76rem;
  font-weight: 600;
}
.suggestion-pill:hover { background: rgba(255, 107, 139, 0.22); border-color: var(--peach); }

/* Typing wave */
.typing-dots { display: inline-flex; gap: 5px; align-items: center; padding: 4px 2px; }
.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--peach);
  animation: chat-bounce 1.1s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Interactive Drawers (Photo / Gifts / Album / Context & Memory) */
.chat-drawer {
  flex: 0 0 auto;
  padding: 14px;
  background: rgba(27, 20, 38, 0.97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--rule-strong);
  display: grid;
  gap: 10px;
  max-height: 58dvh;
  overflow-y: auto;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer-head strong { font-size: 0.92rem; }
.drawer-close { border: 0; background: transparent; color: var(--muted); font-size: 1.25rem; padding: 2px 6px; }
.drawer-label { margin: 2px 0 -4px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--peach-2); font-weight: 700; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.choice-chip {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.77rem;
  font-weight: 600;
}
.choice-chip[aria-pressed=true] { background: rgba(255, 107, 139, 0.22); border-color: var(--peach); color: #fff; }
.drawer-input, .drawer-textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--rule);
  background: var(--bg);
  color: var(--text);
  font-size: 0.86rem;
}
.drawer-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--rule);
  font-size: 0.82rem;
}
.gifts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.gift-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  border-radius: 14px;
  border: 1px solid var(--rule);
  background: var(--surface);
  text-align: center;
}
.gift-card:hover:not(:disabled) { border-color: var(--peach); background: var(--surface-2); }
.gift-ico { font-size: 1.6rem; }
.gift-name { font-size: 0.82rem; font-weight: 700; }
.gift-meta { font-size: 0.72rem; color: var(--peach-2); font-weight: 600; }

/* Album grid inside chat */
.album-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.album-item {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 3 / 4;
  border: 1px solid var(--rule);
  background: var(--bg);
  padding: 0;
  cursor: zoom-in;
}
.album-item img, .album-item video { width: 100%; height: 100%; object-fit: cover; object-position: center 15%; display: block; }
.album-tag {
  position: absolute;
  bottom: 4px;
  left: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(12, 9, 17, 0.78);
  font-size: 0.62rem;
  font-weight: 700;
  color: #ffd4df;
}

/* Affinity Roadmap */
.roadmap { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.roadmap-step {
  padding: 7px 4px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--rule);
  text-align: center;
  font-size: 0.66rem;
  color: var(--muted);
}
.roadmap-step strong { display: block; font-size: 0.72rem; color: #fff; margin-bottom: 2px; }
.roadmap-step.unlocked { background: rgba(255, 107, 139, 0.16); border-color: rgba(255, 107, 139, 0.45); color: #ffd4df; }
.roadmap-step.current { background: var(--grad); color: #170912; border-color: transparent; }
.roadmap-step.current strong { color: #170912; }

/* Quick bar & Composer */
.chat-quickbar {
  display: flex;
  gap: 6px;
  padding: 8px 12px 6px;
  overflow-x: auto;
  scrollbar-width: none;
  border-top: 1px solid var(--rule);
  background: rgba(17, 12, 23, 0.94);
  flex: 0 0 auto;
}
.chat-quickbar::-webkit-scrollbar { display: none; }
.quick-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: #f3e4f5;
  font-size: 0.76rem;
  font-weight: 700;
}
.quick-chip:hover { border-color: var(--peach); background: rgba(255, 107, 139, 0.15); }
.quick-chip span { color: var(--peach-2); font-size: 0.7rem; }

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px max(12px, var(--tg-safe-bottom, env(safe-area-inset-bottom)));
  background: rgba(17, 12, 23, 0.98);
  flex: 0 0 auto;
}
.chat-composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 130px;
  resize: none;
  border: 1px solid var(--rule);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  padding: 11px 16px;
  font-size: 0.94rem;
  line-height: 1.35;
}
.chat-composer textarea:focus { border-color: var(--peach); outline: none; }
.chat-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--grad);
  color: #170912;
  font-size: 1.1rem;
  font-weight: 900;
  flex-shrink: 0;
}

/* Lightbox */
.lightbox {
  width: min(560px, calc(100% - 20px));
  background: #0d0a12;
  padding: 12px;
  align-items: center;
}
.lightbox img, .lightbox video { width: 100%; max-height: 78dvh; object-fit: contain; border-radius: 14px; }
.lightbox p { margin: 10px 6px 4px; font-size: 0.85rem; color: var(--muted); text-align: center; }
.lightbox-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: rgba(12, 9, 17, 0.85);
  font-size: 1.3rem;
}
