/* ── Base ─────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

:root {
  --bg: #f4f1f9;
  --bg-card: #ffffff;
  --bg-subtle: #ece8f5;
  --gold: #7252b0;
  --gold-mid: #8f6ecf;
  --gold-light: #b09ce4;
  --gold-pale: #ece8f5;
  --sage: #9a7c18;
  --sage-pale: #fdf4d8;
  --text: #1e1538;
  --text-mid: #6b50a8;
  --text-soft: #9e8ec0;
  --bubble-me: #e0d8f5;
  --bubble-ai: #fdf4d8;
  --border: rgba(114, 82, 176, 0.18);
  --shadow-sm: 0 2px 12px rgba(60, 30, 120, 0.07);
  --shadow-md: 0 6px 24px rgba(60, 30, 120, 0.12);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html,
body {
  height: 100%;
  height: 100dvh;
  margin: 0;
  font-family: 'Lato', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}

/* ── Subtle warm texture ──────────────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(130, 100, 220, 0.08) 0%, transparent 65%),
    radial-gradient(ellipse 40% 30% at 15% 100%, rgba(100, 60, 200, 0.05) 0%, transparent 55%),
    radial-gradient(ellipse 40% 30% at 85% 100%, rgba(154, 124, 24, 0.04) 0%, transparent 55%);
  pointer-events: none;
  z-index: 0;
}

/* ── Screen router ────────────────────────────────────────────── */
.screen {
  display: none !important;
  position: fixed;
  inset: 0;
  z-index: 10;
  /* iOS Safe Area Support */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  /* Use dvh (Dynamic Viewport Height) with vh fallback */
  height: 100vh;
  height: 100dvh;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex !important;
  flex-direction: column;
}

/* ── Animations ───────────────────────────────────────────────── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-16px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse-glow {

  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(130, 100, 220, 0.35);
  }

  50% {
    box-shadow: 0 0 0 10px rgba(130, 100, 220, 0);
  }
}

@keyframes dots {

  0%,
  100% {
    opacity: .3;
  }

  50% {
    opacity: 1;
  }
}

@keyframes shimmer {
  0% {
    background-position: -200% center;
  }

  100% {
    background-position: 200% center;
  }
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(100%);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fadeup {
  animation: fadeUp .5s ease both;
}

.animate-slidein {
  animation: slideIn .4s ease both;
}

/* ── Buttons ──────────────────────────────────────────────────── */
.btn-gold {
  background: linear-gradient(135deg, #8f6ecf 0%, #4a3490 100%);
  color: #ffffff;
  font-family: 'Lato', sans-serif;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: none;
  border-radius: 12px;
  padding: 14px 28px;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: filter .2s, transform .15s;
  position: relative;
  overflow: hidden;
}

.btn-gold::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
      transparent 0%, rgba(255, 255, 255, .18) 50%, transparent 100%);
  background-size: 200%;
  animation: shimmer 2.5s infinite;
}

.btn-gold:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn-gold:active {
  transform: translateY(0);
  filter: brightness(.95);
}

.btn-ghost {
  background: transparent;
  border: 1.5px solid rgba(114, 82, 176, .45);
  color: var(--gold);
  border-radius: 12px;
  padding: 12px 24px;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  font-family: 'Lato', sans-serif;
  font-weight: 600;
  transition: background .2s, border-color .2s;
}

@media (hover: hover) {
  .btn-ghost:hover {
    background: rgba(114, 82, 176, .08);
    border-color: var(--gold);
  }
}

.btn-ghost:active {
  background: rgba(114, 82, 176, .12);
  border-color: var(--gold);
}

/* ── Inputs ───────────────────────────────────────────────────── */
.inp {
  background: rgba(30, 21, 56, .04);
  border: 1.5px solid rgba(114, 82, 176, .28);
  border-radius: 12px;
  color: var(--text);
  font-family: 'Lato', sans-serif;
  font-size: 16px;
  padding: 13px 16px;
  min-height: 48px;
  width: 100%;
  outline: none;
  touch-action: manipulation;
  transition: border-color .2s, background .2s;
  -webkit-appearance: none;
  appearance: none;
}

.inp::placeholder {
  color: rgba(30, 21, 56, .35);
}

.inp:focus {
  border-color: var(--gold);
  background: rgba(30, 21, 56, .06);
}

select.inp option {
  background: #ffffff;
  color: #1e1538;
}

/* ── Progress bar ─────────────────────────────────────────────── */
.progress-bar {
  height: 3px;
  background: rgba(114, 82, 176, .15);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #4a3490, #8f6ecf, #b09ce4);
  border-radius: 99px;
  transition: width .4s cubic-bezier(.4, 0, .2, 1);
}

/* ── Persona cards (onboarding religion select) ───────────────── */
.persona-card {
  background: rgba(30, 21, 56, .03);
  border: 1.5px solid rgba(114, 82, 176, .2);
  border-radius: 16px;
  padding: 12px 16px;
  cursor: pointer;
  touch-action: manipulation;
  transition: all .2s;
  -webkit-user-select: none;
  user-select: none;
}

@media (hover: hover) {
  .persona-card:hover {
    background: rgba(114, 82, 176, .08);
    border-color: var(--gold);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
  }
}

.persona-card:active {
  background: rgba(114, 82, 176, .1);
  border-color: var(--gold);
  transform: scale(0.98);
}

.persona-card.selected {
  background: rgba(114, 82, 176, .08);
  border-color: var(--gold);
  box-shadow: var(--shadow-sm);
}

.persona-card-v {
  background: var(--bg-card);
  border: 1.5px solid rgba(114, 82, 176, .18);
  border-radius: 20px;
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  text-align: left;
  gap: 12px;
  transition: all .22s;
  box-shadow: var(--shadow-sm);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  min-height: 80px;
}

.persona-avatar-selection {
  width: 72px;
  height: 72px;
  min-width: 72px;
  min-height: 72px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  box-shadow: 0 4px 16px rgba(60, 30, 120, 0.15);
  border: 1px solid rgba(114, 82, 176, 0.15);
  background: #fff;
}

.persona-avatar-selection img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

@media (hover: hover) {
  .persona-card-v:hover {
    border-color: var(--gold);
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
  }
}

.persona-card-v:active {
  transform: scale(0.97);
  box-shadow: 0 1px 6px rgba(60, 30, 120, .08);
}

/* ── Chat layout ──────────────────────────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

#chat-messages::-webkit-scrollbar {
  width: 4px;
}

#chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: rgba(114, 82, 176, .25);
  border-radius: 99px;
}

/* ── Chat bubbles ─────────────────────────────────────────────── */
.bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: slideIn .3s ease both;
}

.bubble-wrap.me {
  justify-content: flex-end;
}

.bubble-wrap.ai {
  justify-content: flex-start;
}

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  line-height: 1.55;
  font-size: 15px;
  position: relative;
  word-break: break-word;
}

.bubble.me {
  background: linear-gradient(135deg, #e2dbf7 0%, #d4caf0 100%);
  color: #1e1538;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(60, 30, 120, .1);
}

.bubble.ai {
  background: linear-gradient(135deg, #fdfaf0 0%, #fdf4d8 100%);
  color: #2a1e08;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(60, 30, 120, .06);
}

.bubble-time {
  font-size: 11px;
  opacity: 0.45;
  margin-top: 4px;
  text-align: right;
}

.bubble.ai .bubble-time {
  text-align: left;
}

.avatar-bubble {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4a3490, #8f6ecf);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(60, 30, 120, .18);
}

/* ── Typing indicator ─────────────────────────────────────────── */
.typing-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(30, 21, 56, .4);
  margin: 0 2px;
  animation: dots 1.2s infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: .2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: .4s;
}

/* ── Chat input bar ───────────────────────────────────────────── */
#chat-input-bar {
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: rgba(244, 241, 249, .97);
  border-top: 1px solid rgba(114, 82, 176, .12);
  backdrop-filter: blur(12px);
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#msg-input {
  flex: 1;
  background: rgba(30, 21, 56, .05);
  border: 1.5px solid rgba(114, 82, 176, .25);
  border-radius: 22px;
  color: var(--text);
  font-family: 'Lato', sans-serif;
  font-size: 16px;
  padding: 10px 16px;
  resize: none;
  outline: none;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color .2s;
  -webkit-appearance: none;
  appearance: none;
}

#msg-input::placeholder {
  color: rgba(30, 21, 56, .38);
}

#msg-input:focus {
  border-color: var(--gold);
}

#action-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(30, 21, 56, .06);
  border: 1.5px solid rgba(114, 82, 176, .2);
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: rgba(30, 21, 56, .55);
  transition: background .2s, border-color .2s, color .2s, transform .15s;
}

#action-btn:active {
  transform: scale(.9);
}

#action-btn.send-mode {
  background: linear-gradient(135deg, #8f6ecf, #4a3490);
  border-color: transparent;
  color: #fff;
  animation: pulse-glow 2s infinite;
}

#action-btn.recording {
  background: linear-gradient(135deg, #d93030, #941010);
  border-color: transparent;
  color: #fff;
  animation: pulse-glow .7s infinite;
}

#action-btn.send-mode:active,
#action-btn.recording:active {
  transform: scale(.9);
  animation: none;
}

@media (hover: hover) {

  #action-btn.send-mode:hover,
  #action-btn.recording:hover {
    filter: brightness(1.1);
  }
}

#action-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
  animation: none;
}

/* ── Chat header ──────────────────────────────────────────────── */
#chat-header {
  background: rgba(244, 241, 249, .96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(114, 82, 176, .14);
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 20;
  box-shadow: 0 2px 8px rgba(60, 30, 120, .05);
}

/* ── Payment modal ────────────────────────────────────────────── */
#payment-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(80, 40, 140, .25);
  backdrop-filter: blur(8px);
  display: none;
  align-items: flex-end;
  justify-content: center;
}

#payment-modal.open {
  display: flex;
}

.modal-sheet {
  background: var(--bg-card);
  border-top: 1.5px solid rgba(114, 82, 176, .2);
  border-radius: 28px 28px 0 0;
  width: 100%;
  max-width: 480px;
  padding: 28px 24px;
  padding-bottom: calc(28px + var(--safe-bottom));
  animation: modalIn .35s cubic-bezier(.4, 0, .2, 1);
  box-shadow: 0 -4px 32px rgba(60, 30, 120, .12);
}

/* ── QR code container ────────────────────────────────────────── */
#qr-container {
  background: #f9f9f9;
  border: 1.5px solid rgba(114, 82, 176, .15);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#qr-container img {
  max-width: 100%;
  border-radius: 8px;
}

/* ── PIX copy box ─────────────────────────────────────────────── */
.pix-code-box {
  background: rgba(30, 21, 56, .04);
  border: 1px solid rgba(114, 82, 176, .2);
  border-radius: 12px;
  padding: 12px;
  font-size: 11px;
  font-family: monospace;
  color: var(--gold);
  word-break: break-all;
  max-height: 80px;
  overflow: hidden;
  position: relative;
}

/* ── Divider with text ────────────────────────────────────────── */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: rgba(30, 21, 56, .3);
  font-size: 12px;
  letter-spacing: .08em;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(114, 82, 176, .18);
}

/* ── Splash screen ────────────────────────────────────────────── */
#screen-splash {
  background: linear-gradient(160deg, #f4f1f9 0%, #ece8f5 50%, #e4ddf5 100%);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}

.candle-glow {
  position: absolute;
  width: 320px;
  height: 320px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(130, 100, 220, .18) 0%, transparent 70%);
  animation: pulse-glow 3s infinite;
}

/* ── Onboarding ───────────────────────────────────────────────── */
#screen-onboarding {
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.onboard-step {
  display: none;
}

.onboard-step.active {
  display: block;
  animation: fadeUp .4s ease both;
}

/* ── Persona selector ─────────────────────────────────────────── */
#screen-persona {
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* ── Chat screen ──────────────────────────────────────────────── */
#screen-chat {
  background: linear-gradient(180deg, #f4f1f9 0%, #ece8f5 100%);
  transition: height .1s ease, top .1s ease;
}

/* ── Responsive max-width container ───────────────────────────── */
.container {
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

/* ── Date separator ──────────────────────────────────────────── */
.date-sep {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px 0 6px;
}

.date-sep span {
  background: rgba(114, 82, 176, .1);
  border: 1px solid rgba(114, 82, 176, .2);
  border-radius: 99px;
  padding: 3px 14px;
  font-size: 11px;
  color: rgba(30, 21, 56, .5);
  letter-spacing: .05em;
  user-select: none;
}


/* ── PWA install button ───────────────────────────────────────── */
#install-btn {
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(114, 82, 176, .08);
  border: 1px solid rgba(114, 82, 176, .28);
  border-radius: 99px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--gold);
  cursor: pointer;
  touch-action: manipulation;
  transition: all .2s;
  font-family: 'Lato', sans-serif;
  font-weight: 600;
}

#install-btn:active {
  background: rgba(114, 82, 176, .16);
}

/* ── Generate prayer button ──────────────────────────────────── */
@keyframes pulse-once {
  0% { transform: scale(1); box-shadow: 0 4px 12px rgba(60, 30, 120, .12); }
  50% { transform: scale(1.1); box-shadow: 0 8px 24px rgba(114, 82, 176, .3); }
  100% { transform: scale(1); box-shadow: 0 4px 12px rgba(60, 30, 120, .12); }
}

/* ── Generate prayer button (beside AI bubble) ────────────────── */
.gen-prayer-btn {
  align-self: flex-end;
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  color: #7252b0;
  background: #fff;
  border: 1px solid rgba(114, 82, 176, .2);
  border-radius: 99px;
  padding: 6px 12px;
  cursor: pointer;
  transition: all .25s cubic-bezier(.4, 0, .2, 1);
  font-family: 'Lato', sans-serif;
  box-shadow: 0 4px 12px rgba(60, 30, 120, .12);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  animation: pulse-once 1.5s ease-in-out 2; /* 1.5s * 2 = 3s total */
}

.gen-prayer-btn:hover {
  background: #7252b0;
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(114, 82, 176, .25);
}

.gen-prayer-btn:active {
  transform: scale(0.95);
}

/* ── Prayer modal ─────────────────────────────────────────────── */
#prayer-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(14, 8, 32, .75);
  backdrop-filter: blur(10px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 16px;
  box-sizing: border-box;
}

#prayer-modal.open {
  display: flex;
}

.prayer-sheet {
  background: #000;
  border-radius: 24px;
  padding: 0;
  width: 100%;
  max-width: 480px;
  animation: modalIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  position: relative;
  margin: auto;
  overflow: hidden;
}

.prayer-close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(114, 82, 176, .1);
  color: rgba(30, 21, 56, .5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
  z-index: 2;
}

.prayer-close-btn:hover {
  background: rgba(114, 82, 176, .2);
  color: #7252b0;
}

.prayer-fab {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(30, 20, 60, 0.65);
  backdrop-filter: blur(8px);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.35);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.prayer-fab:hover {
  background: rgba(114, 82, 176, 0.9);
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(114, 82, 176, 0.4);
}

.prayer-fab:active {
  transform: scale(0.95);
}

#prayer-preview-img {
  width: 100%;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(60, 30, 120, .15);
}

/* ── Toast ────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(28, 14, 54, .88);
  border: 1px solid rgba(114, 82, 176, .35);
  border-radius: 16px;
  padding: 10px 20px;
  font-size: 14px;
  color: #d8c8ff;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
  white-space: normal;
  max-width: min(320px, calc(100vw - 40px));
  text-align: center;
  line-height: 1.4;
}

#toast.show {
  opacity: 1;
}

/* 🕯️ Religious Animations */
@keyframes flicker {
  0% { opacity: 0.8; transform: scale(0.98); }
  50% { opacity: 1; transform: scale(1.02); }
  100% { opacity: 0.8; transform: scale(0.98); }
}

@keyframes glow-pulse {
  0% { filter: drop-shadow(0 0 5px rgba(143, 110, 207, 0.4)); transform: scale(1); }
  50% { filter: drop-shadow(0 0 20px rgba(143, 110, 207, 0.8)); transform: scale(1.05); }
  100% { filter: drop-shadow(0 0 5px rgba(143, 110, 207, 0.4)); transform: scale(1); }
}

@keyframes float-gentle {
  0% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
  100% { transform: translateY(0); }
}

@keyframes star-expand {
  0% { transform: scale(0.8) rotate(0deg); opacity: 0.5; }
  50% { transform: scale(1.2) rotate(180deg); opacity: 1; }
  100% { transform: scale(0.8) rotate(360deg); opacity: 0.5; }
}

.rel-anim-candle { animation: flicker 1.5s infinite ease-in-out; font-size: 50px; }
.rel-anim-cross { animation: glow-pulse 2s infinite ease-in-out; font-size: 50px; color: #7252b0; }
.rel-anim-dove { animation: float-gentle 3s infinite ease-in-out; font-size: 50px; }
.rel-anim-star { animation: star-expand 4s infinite ease-in-out; font-size: 50px; color: #f1c40f; }