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

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --white: #faf9f7;
  --cream: #f3f1ec;
  --sand: #e8e4dc;
  --stone: #c4bfb6;
  --ink: #2c2a26;
  --ink-soft: #5c5850;
  --ink-faint: #9a958b;
  --teal: #0d9488;
  --teal-soft: #ccfbf1;
  --teal-deep: #0a7a70;
  --coral: #dc6b4a;
  --coral-soft: #fce8e2;
}

body {
  font-family: 'Tajawal', sans-serif;
  background: var(--white);
  color: var(--ink);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════ SCREENS ═══════════════════ */
.screen { display: none; min-height: 100dvh; align-items: center; justify-content: center; }
.screen.active { display: flex; }

/* ═══════════════════ HOME ═══════════════════ */
.home-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 32px 24px;
  gap: 12px;
  text-align: center;
}

.age-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.age-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
  cursor: pointer;
}

.age-warning {
  font-size: 12px;
  font-weight: 500;
  color: var(--stone);
  line-height: 1.7;
  max-width: 280px;
}

.legal-links {
  display: flex;
  gap: 8px;
  font-size: 12px;
  margin-top: 8px;
}
.legal-links a {
  color: var(--stone);
  text-decoration: none;
}
.legal-links a:hover { color: var(--ink-faint); }

.logo {
  font-size: 80px;
  font-weight: 900;
  color: var(--ink);
  line-height: 1;
  margin-bottom: 4px;
}

.tagline {
  font-size: 17px;
  font-weight: 500;
  color: var(--ink-faint);
  margin-bottom: 20px;
}

.online-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--teal);
  background: var(--teal-soft);
  padding: 6px 14px;
  border-radius: 100px;
  margin-bottom: 8px;
  line-height: 1;
}
.online-badge span {
  display: flex;
  align-items: center;
}
.online-badge.in-header {
  background: var(--cream);
  color: var(--ink-faint);
  padding: 4px 10px;
  font-size: 12px;
}
.online-dot {
  width: 7px;
  height: 7px;
  background: var(--teal);
  border-radius: 50%;
  animation: blink 2s ease infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ═══════════════════ BUTTONS ═══════════════════ */
.btn {
  font-family: 'Tajawal', sans-serif;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  font-size: 19px;
  background: var(--ink);
  color: var(--white);
  padding: 16px 52px;
  border-radius: 100px;
  letter-spacing: 0.3px;
}
.btn-primary:hover { background: #1a1916; }

.btn-ghost {
  font-size: 15px;
  background: transparent;
  color: var(--ink-faint);
  padding: 10px 28px;
  border-radius: 100px;
  border: 1.5px solid var(--sand);
}
.btn-ghost:hover { border-color: var(--stone); color: var(--ink-soft); }

.btn-skip {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--coral);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 11px;
}
.btn-skip:active { transform: scale(0.9); }
.btn-skip:hover { background: #c85a3c; }
.btn-skip img { width: 100%; height: 100%; filter: brightness(0) invert(1); }

/* Chat end buttons (inline in chat) */
.chat-end-btn {
  font-family: 'Tajawal', sans-serif;
  font-size: 14px;
  font-weight: 700;
  border: none;
  border-radius: 100px;
  padding: 10px 24px;
  cursor: pointer;
  margin: 4px;
  transition: all 0.15s;
}
.chat-end-btn:active { transform: scale(0.96); }
.chat-end-btn.primary { background: var(--ink); color: var(--white); }
.chat-end-btn.primary:hover { background: #1a1916; }
.chat-end-btn.ghost { background: transparent; color: var(--ink-faint); border: 1.5px solid var(--sand); }
.chat-end-btn.ghost:hover { border-color: var(--stone); }

.back-link {
  color: var(--stone);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  margin-top: 24px;
  transition: color 0.15s;
}
.back-link:hover { color: var(--ink-faint); }

/* ═══════════════════ SEARCHING ═══════════════════ */
.searching-anim {
  position: relative;
  width: 90px;
  height: 90px;
  margin-bottom: 24px;
}
.pulse-ring {
  position: absolute;
  inset: 0;
  border: 2px solid var(--teal);
  border-radius: 50%;
  animation: pulse-ring 2s ease-out infinite;
}
.pulse-ring.delay { animation-delay: 1s; }
@keyframes pulse-ring {
  0% { transform: scale(0.5); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}
.pulse-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 20px; height: 20px;
  background: var(--teal);
  border-radius: 50%;
}

.searching-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.dots {
  display: inline-block;
  width: 20px;
  text-align: right;
  direction: ltr;
}
.dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ═══════════════════ CHAT SCREEN ═══════════════════ */
#screen-chat {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  height: 100%;
  position: fixed;
  inset: 0;
  background: var(--cream);
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--sand);
  flex-shrink: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stranger-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}

.stranger-flag {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--sand);
  flex-shrink: 0;
}

/* ═══════════════════ MESSAGES ═══════════════════ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.message {
  max-width: 78%;
  padding: 10px 15px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
  unicode-bidi: plaintext;
  direction: auto;
}

.message-me {
  align-self: flex-end;
  background: var(--teal);
  color: white;
  border-radius: 18px 18px 4px 18px;
}

.message-stranger {
  align-self: flex-start;
  background: var(--white);
  color: var(--ink);
  border-radius: 18px 18px 18px 4px;
  border: 1px solid var(--sand);
}

.message-system {
  align-self: center;
  background: transparent;
  color: var(--stone);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 10px 0;
}

/* ═══════════════════ TYPING ═══════════════════ */
.typing-indicator {
  padding: 4px 20px 8px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.typing-indicator.hidden { display: none; }
.typing-dot {
  width: 5px;
  height: 5px;
  background: var(--stone);
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* ═══════════════════ INPUT BAR ═══════════════════ */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: var(--white);
  border-top: 1px solid var(--sand);
  flex-shrink: 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.chat-input-bar input {
  flex: 1;
  font-family: 'Tajawal', sans-serif;
  font-size: 15px;
  font-weight: 500;
  padding: 11px 16px;
  border-radius: 100px;
  border: 1.5px solid var(--sand);
  background: var(--cream);
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s;
}
.chat-input-bar input::placeholder { color: var(--stone); }
.chat-input-bar input:focus { border-color: var(--teal); }

.btn-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--teal);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 10px;
}
.btn-send:active { transform: scale(0.9); }
.btn-send:hover { background: var(--teal-deep); }
.btn-send img {
  width: 100%;
  height: 100%;
  filter: brightness(0) invert(1);
}

/* ═══════════════════ OVERLAY ═══════════════════ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(44, 42, 38, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.overlay.hidden { display: none; }
.overlay-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 36px 32px;
  background: var(--white);
  border-radius: 24px;
  margin: 20px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.15);
}
.overlay-content p {
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
}

/* ═══════════════════ TOAST ═══════════════════ */
.toast-popup {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--coral);
  color: white;
  font-family: 'Tajawal', sans-serif;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 20px;
  border-radius: 100px;
  z-index: 100;
  transition: opacity 0.3s;
  box-shadow: 0 4px 20px rgba(220, 107, 74, 0.3);
}
.toast-popup.fade-out { opacity: 0; }

/* ═══════════════════ RESPONSIVE ═══════════════════ */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
.shake { animation: shake 0.4s ease; }

@media (max-width: 480px) {
  .logo { font-size: 60px; }
  .btn-primary { font-size: 17px; padding: 14px 44px; }
  .message { max-width: 84%; }
}
