:root {
  --blue: #2563eb;
  --blue-dim: #1d4ed8;
  --bg: oklch(0.97 0 0);
  --bg-chat: #ffffff;
  --bubble-in: #f1f1f4;
  --bubble-in-text: #0b0b0f;
  --bubble-out: var(--blue);
  --bubble-out-text: #ffffff;
  --muted: #8a8a94;
  --line: #e7e7ec;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.12);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(0.2 0 0);
    --bg-chat: oklch(0.24 0 0);
    --bubble-in: oklch(0.3 0 0);
    --bubble-in-text: #f5f5f7;
    --line: oklch(0.32 0 0);
    --muted: #9a9aa3;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--bubble-in-text);
  overscroll-behavior: none;
}

.app {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg-chat);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.screen { flex: 1; display: flex; flex-direction: column; min-height: 100dvh; }
.screen[hidden] { display: none !important; }

/* ---------- Waiting / Joined (Cupid-style) ---------- */
.screen-queue {
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  text-align: center;
}
.wait-card {
  position: relative;
  width: 100%;
  max-width: 380px;
}
/* animated gradient border that "dances" around the card */
.wait-border {
  position: absolute; inset: -3px;
  border-radius: 18px;
  overflow: hidden;
  pointer-events: none;
}
.wait-border::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--blue), transparent);
  opacity: 0.8;
}
.wait-border-1::before { animation: borderDance1 3s linear infinite; }
.wait-border-2::before {
  background: linear-gradient(90deg, transparent, #3b82f6, transparent);
  animation: borderDance2 3s linear infinite;
}
@keyframes borderDance1 {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
@keyframes borderDance2 {
  0% { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}
.wait-inner {
  position: relative;
  background: var(--bg-chat);
  border: 1px solid var(--line);
  border-radius: 15px;
  box-shadow: var(--shadow);
  padding: 30px 24px;
}
.wait-state {
  display: flex; flex-direction: column;
  align-items: center; gap: 22px;
}
.wait-title {
  margin: 0;
  font-weight: 700;
  line-height: 1.2;
  color: var(--bubble-in-text);
  font-size: clamp(1.25rem, 5vw, 2rem);
}
.wait-avatar {
  position: relative;
  flex-shrink: 0;
  width: 128px; height: 128px;
}
.wait-avatar img {
  width: 100%; height: 100%;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--line);
  user-select: none;
  -webkit-user-drag: none;
}
/* green presence dot, bottom-right of avatar */
.wait-presence {
  position: absolute;
  width: 26px; height: 26px;
  background: #22c55e;
  border: 3px solid var(--bg-chat);
  border-radius: 50%;
  bottom: 14.6%; right: 14.6%;
  transform: translate(50%, 50%);
}
.wait-lastseen {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}
.wait-badge {
  display: inline-flex;
  align-items: center;
  padding: 8px 18px;
  border-radius: 99px;
  border: 1px solid rgba(37, 99, 235, 0.35);
  background: rgba(37, 99, 235, 0.1);
  color: var(--blue);
  font-weight: 600;
  font-size: 14px;
}
.wait-joined-sub {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.45;
}

/* ---------- Blocked ---------- */
.screen-blocked { align-items: center; justify-content: center; padding: 32px; text-align: center; }
.blocked-card { max-width: 320px; }
.blocked-card h1 { font-size: 20px; margin: 0 0 8px; }
.blocked-card p { color: var(--muted); margin: 0; }

/* ---------- Chat header (Cupid exact) ---------- */
.chat-header {
  position: sticky; top: 0; z-index: 20; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: var(--bg-chat);
  border-bottom: 1px solid var(--line);
  touch-action: manipulation;
}
.icon-btn {
  border: none; background: transparent; color: var(--muted);
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  flex: 0 0 auto; transition: color .15s, background .15s;
}
.icon-btn:hover { color: var(--fg); background: rgba(127,127,127,.1); }
.icon-btn:active { background: var(--bubble-in); }
.chat-head-info { display: flex; align-items: center; gap: 16px; flex: 1; min-width: 0; }
.chat-head-avatar { position: relative; flex: 0 0 auto; }
.chat-head-avatar img {
  width: 56px; height: 56px; border-radius: 50%; object-fit: cover;
  box-shadow: 0 0 0 2px var(--line);
}
.online-dot {
  position: absolute; bottom: 14.64%; right: 14.64%; transform: translate(50%,50%);
  width: 16px; height: 16px; border-radius: 50%;
  background: #22c55e; border: 2px solid var(--bg-chat);
}
.online-dot.offline { background: #9ca3af; }
.chat-head-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-name-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-name { font-weight: 700; font-size: 18px; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.verified-badge { flex: 0 0 auto; fill: var(--blue); color: var(--bg-chat); }
.chat-status { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.disconnect-notice {
  align-self: center;
  margin: 8px auto;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(156, 163, 175, 0.12);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.chat-head-actions { position: relative; display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }

/* ---------- 3-dots popover (Cupid exact) ---------- */
.dots-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 80;
  min-width: 224px; padding: 8px;
  display: flex; flex-direction: column; gap: 4px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-radius: 8px; box-shadow: 0 10px 38px rgba(0,0,0,0.22);
  animation: menuIn 0.15s ease;
  transform-origin: top right;
}
@media (prefers-color-scheme: dark) { .dots-menu { background: rgba(30,30,34,0.92); } }
@keyframes menuIn { from { opacity: 0; transform: scale(.95) translateY(-4px); } to { opacity: 1; transform: none; } }
.dots-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 8px 12px; border: none; background: transparent;
  border-radius: 6px; font-size: 14px; color: var(--bubble-in-text);
  cursor: pointer; transition: background .12s;
}
.dots-item:hover { background: rgba(127,127,127,.12); }
.dots-item svg { color: var(--muted); flex: 0 0 auto; }

/* ---------- Call dialog (Cupid exact: centered card on dark scrim) ---------- */
.call-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,0.8);
  display: grid; place-items: center;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.call-dialog {
  width: calc(100% - 2rem); max-width: 28rem;
  background: var(--bg-chat);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
  padding: 24px;
  display: grid; gap: 16px;
  animation: dialogIn .2s cubic-bezier(.16,1,.3,1);
  text-align: center;
}
@keyframes dialogIn { from { opacity: 0; transform: scale(.95) translateY(8px); } to { opacity: 1; transform: none; } }
.call-title { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; color: var(--bubble-in-text); }
.call-sub { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.5; }
.call-ok {
  justify-self: end; border: none; cursor: pointer;
  background: var(--blue); color: #fff; font-size: 14px; font-weight: 600;
  padding: 8px 20px; border-radius: 8px;
  transition: background .15s;
}
.call-ok:active { background: var(--blue-dim); }

/* ---------- Messages ---------- */
/* Cupid exact: row spans full width; bubble max-w 80%; w-20 timestamp gutter on side */
.messages {
  flex: 1; overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex; flex-direction: column; gap: 2px;
  scroll-behavior: smooth;
}
.msg-row {
  display: flex; width: 100%; align-items: flex-end;
  animation: rise 0.22s ease;
}
.msg-row.out { justify-content: flex-end; }
.msg-row.in { justify-content: flex-start; }
.msg-bubble-wrap { max-width: 80%; min-width: 0; }
.bubble {
  padding: 12px;               /* p-3 */
  font-size: 14px; line-height: 1.4;   /* text-sm */
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  display: inline-block; max-width: 100%; min-width: 0;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
/* Cupid: incoming = muted bg, radius 24px 24px 24px 4px (tail bottom-left) */
.msg-row.in .bubble { background: var(--bubble-in); color: var(--bubble-in-text); border-radius: 24px 24px 24px 4px; }
/* Cupid: outgoing = blue-600 white, radius 24px all */
.msg-row.out .bubble { background: #2563eb; color: #fff; border-radius: 24px; }
/* w-20 timestamp gutter, text-xs muted opacity-60 */
.msg-time {
  width: 80px; flex-shrink: 0; padding: 0 16px 2px 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--muted); opacity: 0.6;
  align-self: center;
}
/* small 28px avatar next to her incoming rows (Cupid: h-7 w-7 ring-1) */
.msg-avatar {
  width: 28px; height: 28px; flex-shrink: 0;
  margin: 0 8px 0 0; align-self: flex-end;
}
.msg-avatar img {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
  box-shadow: 0 0 0 1px var(--line);
}
/* Seen receipt under outgoing bubble (Cupid: mt-1 text-xs muted, mr-3) */
.msg-seen {
  font-size: 12px; color: var(--muted);
  margin: 4px 12px 0 0;
  text-align: right;
}
/* Appears when she's read it — gentle fade/slide, like Cupid's receipt */
.msg-seen:not([data-pending="1"]) { animation: seenIn .25s ease-out; }
.msg-seen[data-pending="1"] { min-height: 0; }
@keyframes seenIn { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.msg-out-col { display: flex; flex-direction: column; align-items: flex-end; flex: 1; min-width: 0; padding: 0 16px; }
.msg-row.out .msg-bubble-wrap { max-width: 80%; }
.bubble.cta {
  background: var(--blue); color: #fff;
  text-align: center; font-weight: 650;
  padding: 14px 16px; cursor: pointer;
  border-radius: 16px;
}
.bubble.cta small { display: block; font-weight: 400; opacity: 0.85; font-size: 12px; margin-top: 3px; }
.msg-meta { font-size: 10px; color: var(--muted); margin: 2px 6px 0; }

/* ---------- Snaps in chat (Cupid "View photo" pill) ---------- */
.snap-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 16px; min-width: 0;
  background: var(--bubble-in); color: var(--bubble-in-text);
  border-radius: 24px; cursor: pointer;
  font-size: 14px; font-weight: 700;
  animation: rise 0.22s ease;
  transition: filter 0.15s ease;
  user-select: none; -webkit-user-select: none;
}
.snap-pill:hover { filter: brightness(0.95); }
.snap-pill.out { background: var(--bubble-out, #2563eb); color: #fff; }
.snap-pill .pill-play { width: 16px; height: 16px; color: #2563eb; flex-shrink: 0; }
.snap-pill.out .pill-play { color: #fff; }
.snap-pill .pill-label { font-weight: 700; }
.snap-pill.viewed { opacity: 0.55; cursor: default; font-weight: 500; }
.snap-pill.viewed:hover { filter: none; }

/* ---------- Typing ---------- */
.typing {
  align-self: flex-start;
  background: var(--bubble-in);
  border-radius: var(--radius);
  border-bottom-left-radius: 7px;
  padding: 12px 16px; margin: 0 0 0 4px;
  display: flex; gap: 4px; width: fit-content;
}
.typing[hidden] { display: none !important; }
.typing .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing .dot:nth-child(2) { animation-delay: 0.15s; }
.typing .dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Camera bubble — she's "taking a photo", replaces the dots before a snap */
.cam-typing { padding: 12px 18px; color: var(--muted); }
.cam-typing svg { animation: campulse 1.1s infinite ease-in-out; }
@keyframes campulse { 0%,100% { opacity: 0.45; transform: scale(1); } 50% { opacity: 1; transform: scale(1.12); } }

/* ---------- Composer (Cupid floating pill) ---------- */
.composer {
  position: sticky; bottom: 0; z-index: 20;
  padding: 8px 16px calc(max(12px, var(--safe-bottom)));
  background: transparent;
}
.composer-pill {
  display: flex; align-items: center; gap: 8px;
  background: rgba(127,127,127,.14);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--line);
  border-radius: 31px;
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  touch-action: manipulation;
}
.composer-icon {
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: transparent; color: var(--muted);
  display: grid; place-items: center; cursor: pointer; flex: 0 0 auto;
  transition: color .15s, background .15s;
}
.composer-icon:hover { color: var(--fg); background: rgba(127,127,127,.12); }
.composer-input {
  flex: 1; min-width: 0; border: none; outline: none;
  background: transparent; color: var(--bubble-in-text);
  font-size: 15px; padding: 6px 2px;
}
.composer-input::placeholder { color: var(--muted); }
.send-btn {
  width: 40px; height: 40px; border-radius: 50%; flex: 0 0 auto;
  border: none; background: var(--blue); color: #fff;
  display: grid; place-items: center; cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.send-btn:active { transform: scale(.92); }
.send-btn:disabled { opacity: .45; cursor: default; }
.fan-pic { max-width: 220px; border-radius: 16px; display: block; }

/* ---------- Snap viewer (fullscreen) ---------- */
.snap-viewer {
  position: fixed; inset: 0; z-index: 60;
  background: #000;
  display: grid; place-items: center;
  animation: rise 0.2s ease;
}
.snap-viewer[hidden] { display: none !important; }
.snap-frame { position: relative; width: 100%; height: 100dvh; display: flex; align-items: center; justify-content: center; padding: calc(var(--safe-top) + 12px) 16px 16px; box-sizing: border-box; }
.snap-frame img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; border-radius: 16px; user-select: none; -webkit-user-drag: none; }
.snap-frame img[hidden] { display: none !important; }
.snap-close {
  position: absolute; top: calc(var(--safe-top) + 12px); left: 12px; z-index: 5;
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0,0,0,0.5); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.snap-close:hover { background: rgba(0,0,0,0.7); }
.snap-tap {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: #fff; font-size: 14px; font-weight: 600;
  background: rgba(0,0,0,0.4); padding: 10px 18px; border-radius: 99px;
  backdrop-filter: blur(6px);
}
.snap-timer {
  position: absolute; top: calc(var(--safe-top) + 12px); left: 12px; right: 12px;
  height: 4px; background: rgba(255,255,255,0.3); border-radius: 99px; overflow: hidden;
}
.snap-timer::after {
  content: ""; display: block; height: 100%; width: 100%;
  background: #fff; transform-origin: left;
}
.snap-timer.run::after { animation: drain linear forwards; }
@keyframes drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; justify-content: center;
  animation: rise 0.18s ease;
}
.modal[hidden] { display: none !important; }
.modal-card {
  background: var(--bg-chat);
  width: 100%; max-width: 520px;
  border-radius: 22px 22px 0 0;
  padding: 18px 18px calc(var(--safe-bottom) + 18px);
  animation: slideup 0.25s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { font-size: 18px; margin: 0; font-weight: 700; }
.modal-sub { color: var(--muted); font-size: 14px; margin: 4px 0 14px; }
.report-options { display: flex; flex-direction: column; gap: 2px; }
.report-opt {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 6px; border-bottom: 1px solid var(--line);
  cursor: pointer; font-size: 15px;
}
.report-opt:last-child { border-bottom: none; }
.report-opt .check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); }
.report-opt.sel .check { border-color: var(--blue); background: var(--blue); }
.report-text {
  width: 100%; margin-top: 14px; border: 1px solid var(--line);
  border-radius: 14px; padding: 12px; font-size: 15px; resize: none;
  min-height: 84px; background: var(--bg-chat); color: var(--bubble-in-text);
}
.primary-btn {
  width: 100%; margin-top: 14px; border: none; cursor: pointer;
  background: var(--blue); color: #fff; font-size: 16px; font-weight: 650;
  padding: 15px; border-radius: 14px;
}
.primary-btn:active { background: var(--blue-dim); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 96px);
  transform: translateX(-50%); z-index: 90;
  background: rgba(15,23,42,0.92); color: #fff;
  padding: 11px 18px; border-radius: 99px; font-size: 14px;
  animation: rise 0.2s ease; max-width: 88%; text-align: center;
}
.toast[hidden] { display: none !important; }
