:root {
  --bg: #0f1115;
  --bubble-me: #4f7cff;
  --bubble-them: #23262f;
  --text: #f2f2f5;
  --accent: #ff5c9e;
  --muted: #7a7d87;
  font-family: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden; /* only .messages scrolls — header/composer must never scroll off */
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 480px;
  height: 100dvh; /* dynamic viewport height: adjusts correctly when mobile keyboard opens */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.screen { padding: 24px; display: flex; flex-direction: column; gap: 12px; height: 100%; overflow: hidden; }
#chat.screen { padding: 0; gap: 0; }
.hidden { display: none !important; }

h1 { margin: 0; font-size: 28px; }
h2 { margin: 0; font-size: 20px; }
.tagline { opacity: 0.7; margin-top: -8px; }

input {
  background: #1a1d24;
  border: 1px solid #2c2f38;
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  width: 100%;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
button:active { transform: scale(0.98); }

.ghost-btn {
  background: transparent;
  color: var(--text);
  padding: 6px 10px;
  font-weight: 500;
}

.tabs { display: flex; gap: 8px; margin-bottom: 4px; }
.tab {
  flex: 1;
  background: #1a1d24;
  color: var(--muted);
  font-weight: 600;
}
.tab.active { background: var(--accent); color: white; }

.avatar-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.avatar-option {
  font-size: 28px;
  background: #1a1d24;
  border-radius: 12px;
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border: 2px solid transparent;
}
.avatar-option.selected { border-color: var(--accent); }

.error { color: #f87171; font-size: 13px; }

.row { display: flex; gap: 8px; }
.row input { flex: 1; }

/* --- Chat list --- */
.list-header { display: flex; justify-content: space-between; align-items: center; }

.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }

.chat-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  cursor: pointer;
}
.chat-list-item:hover { background: #1a1d24; }

.chat-list-avatar {
  position: relative;
  font-size: 30px;
  width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  background: #1a1d24;
  border-radius: 50%;
  flex-shrink: 0;
}
.emotion-badge {
  position: absolute;
  bottom: -2px; right: -2px;
  font-size: 14px;
  background: #0f1115;
  border-radius: 50%;
  padding: 1px;
}

.chat-list-body { flex: 1; min-width: 0; }
.chat-list-name { font-weight: 600; font-size: 15px; }
.chat-list-preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-list-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.chat-list-time { font-size: 11px; color: var(--muted); }
.unread-badge {
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
}

.empty-state { color: var(--muted); text-align: center; margin-top: 40px; font-size: 14px; }

/* --- Chat screen --- */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  border-bottom: 1px solid #22252d;
  gap: 8px;
}
.chat-header #room-with { flex: 1; font-weight: 600; }

.pet-corner { display: flex; flex-direction: column; align-items: center; gap: 2px; }

.pet-face {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: #1a1d24;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
  border: 3px solid #333;
  transition: border-color 0.4s ease, transform 0.3s ease;
}

.pet-face.happy  { border-color: #4ade80; }
.pet-face.angry  { border-color: #f87171; animation: shake 0.4s; }
.pet-face.sad    { border-color: #60a5fa; }
.pet-face.flirty { border-color: #f472b6; }
.pet-face.bored  { border-color: #a1a1aa; }
.pet-face.neutral{ border-color: #52525b; filter: grayscale(0.6); opacity: 0.6; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.pet-label { font-size: 11px; opacity: 0.6; text-transform: capitalize; }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }

.bubble-wrap { display: flex; flex-direction: column; max-width: 75%; }
.bubble-wrap.me { align-self: flex-end; align-items: flex-end; }
.bubble-wrap.them { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.35;
}
.bubble-wrap.me .bubble { background: var(--bubble-me); border-bottom-right-radius: 4px; }
.bubble-wrap.them .bubble { background: var(--bubble-them); border-bottom-left-radius: 4px; }

.bubble-meta {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 2px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.tick { font-size: 12px; }
.tick.read { color: #4f9dff; }

.composer { display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid #22252d; }
.composer input { flex: 1; }

/* --- Profile picture / media additions --- */
.me-row { display: flex; align-items: center; gap: 10px; }
.my-avatar, .chat-friend-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #1a1d24;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  overflow: hidden;
  cursor: pointer;
  flex-shrink: 0;
}
.my-avatar img, .chat-friend-avatar img, .chat-list-avatar img {
  width: 100%; height: 100%; object-fit: cover;
}

.icon-btn {
  background: #1a1d24;
  padding: 10px 12px;
  font-size: 18px;
  touch-action: none;
}

.recording-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #2a1418;
  font-size: 13px;
}
.recording-banner .ghost-btn { margin-left: auto; }

.msg-image {
  max-width: 240px;
  border-radius: 12px;
  display: block;
}

.msg-audio {
  width: 220px;
}

.mic-btn-recording { background: #f87171 !important; color: white; }

/* --- Reply / swipe --- */
.bubble-wrap {
  position: relative;
  touch-action: pan-y;
  transition: transform 0.15s ease;
}

.swipe-reply-hint {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  opacity: 0;
  transition: opacity 0.1s ease;
  pointer-events: none;
}
.bubble-wrap.me .swipe-reply-hint { left: -28px; }
.bubble-wrap.them .swipe-reply-hint { right: -28px; }

.quoted-reply {
  border-left: 3px solid var(--accent);
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  padding: 4px 8px;
  margin-bottom: 4px;
  font-size: 12.5px;
  max-width: 100%;
}
.quoted-reply-sender { font-weight: 700; color: var(--accent); }
.quoted-reply-text {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #1a1d24;
  border-top: 1px solid #2c2f38;
}
.reply-preview-content { flex: 1; border-left: 3px solid var(--accent); padding-left: 8px; min-width: 0; }
.reply-preview-sender { font-size: 12px; font-weight: 700; color: var(--accent); }
.reply-preview-text {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
