/* ============ Dharma AI — "Sacred Dawn" v2, phone-first ============ */
:root {
  --night: #160f2e;
  --dusk: #251a40;
  --plum: #352458;
  --saffron: #f0962e;
  --saffron-deep: #d9701a;
  --gold: #e8b04b;
  --gold-soft: #f4d089;
  --cream: #fbf3e6;
  --parchment: #fffaf1;
  --ink: #2a2018;
  --ink-soft: #6f6253;
  --line: #ece0c9;
  --card-shadow: 0 10px 36px rgba(14, 8, 32, 0.22);
  --glow: 0 0 26px rgba(232, 176, 75, 0.5);
  --radius: 20px;
  --serif: "Marcellus", Georgia, serif;
  --sans: "Inter", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* CRITICAL: make the hidden attribute always win (fixes login overlay) */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--night); overflow: hidden; }

/* ---- ambience ---- */
.bg-aura {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(1100px 560px at 50% -8%, rgba(240,150,46,0.5), transparent 60%),
    radial-gradient(800px 480px at 85% 112%, rgba(124,77,255,0.22), transparent 60%),
    linear-gradient(180deg, var(--night) 0%, var(--dusk) 48%, var(--plum) 100%);
}
.bg-mandala {
  position: fixed; top: -26vmax; left: 50%; width: 64vmax; height: 64vmax; z-index: 0;
  transform: translateX(-50%); opacity: .055; pointer-events: none;
  background: url("/icons/mandala.svg") center/contain no-repeat;
  animation: spin 150s linear infinite;
}
@keyframes spin { to { transform: translateX(-50%) rotate(360deg); } }

#app { position: relative; z-index: 1; display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }

/* ---- avatars (shared) ---- */
.avatar { border-radius: 50%; overflow: hidden; flex: 0 0 auto; }
.avatar .face-svg { display: block; width: 100%; height: 100%; }
.avatar.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.talking .avatar.photo img { animation: breathe-photo 1s ease-in-out infinite alternate; }
@keyframes breathe-photo { from { transform: scale(1); } to { transform: scale(1.06); } }
.face-svg .mouth-open { opacity: 0; }
.talking .face-svg .mouth-open {
  opacity: 1; transform-box: fill-box; transform-origin: center;
  animation: mouth .22s infinite alternate ease-in-out;
}
.talking .face-svg .mouth-smile { opacity: 0; }
@keyframes mouth { from { transform: scaleY(.22); } to { transform: scaleY(1); } }
.face-svg .eyes { transform-box: fill-box; transform-origin: center; animation: blink 4.6s infinite; }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 95.5% { transform: scaleY(.12); } }
.talking .face-svg .glyph-pulse { animation: glyphpulse 1s infinite alternate ease-in-out; transform-box: fill-box; transform-origin: center; }
@keyframes glyphpulse { from { transform: scale(.94); opacity: .6; } to { transform: scale(1.12); opacity: 1; } }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 16px 8px;
}
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand .om { font-size: 26px; color: var(--gold-soft); text-shadow: var(--glow); }
.brand .title { font-family: var(--serif); font-size: 21px; color: #fff; margin: 0; letter-spacing: .4px; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 7px; }
.lang-select {
  background: rgba(255,255,255,.1); color: #fff; border: 1px solid rgba(232,176,75,.45);
  border-radius: 999px; padding: 7px 11px; font: inherit; font-size: 12.5px; font-weight: 600;
  cursor: pointer; -webkit-appearance: none; appearance: none; max-width: 124px;
}
.lang-select option { color: var(--ink); background: #fff; }
.icon-chip {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid rgba(255,255,255,.32);
  background: rgba(255,255,255,.1); color: #fff; font-size: 17px; cursor: pointer; line-height: 1;
}
.icon-chip:active { transform: scale(.92); }
.install-btn {
  background: linear-gradient(135deg, var(--gold), var(--saffron)); color: #2a1800; border: none;
  border-radius: 999px; padding: 8px 13px; font-size: 12.5px; font-weight: 700; cursor: pointer;
}

/* ---- persona rail (story-style) ---- */
.persona-rail {
  display: flex; gap: 14px; overflow-x: auto; padding: 8px 16px 12px;
  scrollbar-width: none;
}
.persona-rail::-webkit-scrollbar { display: none; }
.story { flex: 0 0 auto; background: none; border: none; cursor: pointer; text-align: center; padding: 0; width: 66px; }
.story-ring {
  width: 62px; height: 62px; margin: 0 auto; border-radius: 50%; padding: 3px;
  background: rgba(255,255,255,.16); transition: all .2s;
}
.story.active .story-ring {
  background: conic-gradient(var(--gold), var(--saffron), #e15a8a, var(--gold));
  box-shadow: var(--glow);
}
.story .avatar { width: 100%; height: 100%; border: 2.5px solid var(--night); }
.story-name {
  display: block; margin-top: 5px; font-size: 11px; font-weight: 600;
  color: rgba(255,255,255,.78); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.story.active .story-name { color: var(--gold-soft); }
.story:active .story-ring { transform: scale(.93); }

/* ---- chat ---- */
.chat { flex: 1; overflow-y: auto; padding: 6px 14px 12px; display: flex; flex-direction: column; gap: 16px; }
.chat::-webkit-scrollbar { width: 5px; }
.chat::-webkit-scrollbar-thumb { background: rgba(232,176,75,.3); border-radius: 3px; }

/* welcome */
.welcome { margin: auto 0; text-align: center; padding: 12px 8px; color: #fff; animation: rise .4s ease; }
.welcome .avatar { width: 108px; height: 108px; margin: 0 auto 14px; box-shadow: var(--glow); }
.welcome h2 { font-family: var(--serif); font-weight: 400; font-size: 25px; margin: 0 0 7px; line-height: 1.25; }
.welcome p { font-size: 13.5px; color: var(--gold-soft); max-width: 400px; margin: 0 auto 18px; line-height: 1.55; }
.samples { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; max-width: 430px; margin: 0 auto; }
.sample {
  background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.18); color: #fdeede;
  border-radius: 999px; padding: 10px 16px; font: inherit; font-size: 13.5px; cursor: pointer;
  transition: all .15s; backdrop-filter: blur(6px);
}
.sample:hover, .sample:active { background: rgba(232,176,75,.2); border-color: var(--gold); }

/* messages */
.msg { display: flex; flex-direction: column; animation: rise .32s cubic-bezier(.2,.7,.3,1); }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.msg.user { align-items: flex-end; }
.bubble-user {
  background: linear-gradient(135deg, var(--saffron-deep), var(--saffron)); color: #fff;
  padding: 12px 16px; border-radius: 20px 20px 5px 20px; max-width: 85%; font-size: 15px; line-height: 1.5;
  box-shadow: 0 6px 18px rgba(217,112,26,.32);
}

.answer-card, .perspectives-card, .daily-card {
  background: linear-gradient(180deg, var(--parchment), var(--cream));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 17px; box-shadow: var(--card-shadow); position: relative; overflow: hidden;
}
.answer-card::before, .perspectives-card::before, .daily-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--gold), var(--saffron), var(--gold));
}
.answer-head { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; }
.answer-head .avatar { width: 44px; height: 44px; box-shadow: 0 3px 10px rgba(0,0,0,.18); }
.answer-persona-name { font-family: var(--serif); font-size: 17.5px; color: var(--ink); line-height: 1.05; }
.answer-persona-sub { font-size: 10.5px; color: var(--ink-soft); margin-top: 3px; letter-spacing: .3px; }
.answer-text { font-size: 15.5px; line-height: 1.7; color: #36291c; }
.answer-text p { margin: 0 0 10px; }
.answer-text p:last-child { margin-bottom: 0; }
.cite {
  display: inline-block; background: linear-gradient(135deg, var(--gold-soft), var(--gold)); color: #4a2c00;
  font-weight: 700; font-size: 11px; padding: 1px 7px; border-radius: 7px; cursor: pointer; margin: 0 1px;
  text-decoration: none; vertical-align: middle;
}
.cite:active { background: var(--saffron); color: #fff; }

.sources { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 11px; }
.sources-h { font-family: var(--serif); font-size: 12.5px; color: var(--saffron-deep); letter-spacing: .4px; margin-bottom: 8px; }
.verse {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--gold);
  border-radius: 11px; padding: 10px 12px; margin-bottom: 8px; transition: box-shadow .25s, transform .25s;
}
.verse.flash { box-shadow: 0 0 0 3px var(--gold-soft); transform: scale(1.01); }
.verse-ref { font-weight: 700; color: var(--saffron-deep); font-size: 12.5px; }
.verse-trans { font-size: 14px; line-height: 1.55; margin: 4px 0; color: #3a2d20; font-style: italic; }
.verse-sanskrit { font-size: 13px; color: var(--ink-soft); margin: 3px 0 2px; }
.verse-meta { font-size: 10px; color: var(--ink-soft); opacity: .85; }

.followups { display: flex; flex-direction: column; gap: 8px; margin-top: 13px; }
.followup {
  background: #fff; border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 14px;
  font: inherit; font-size: 13.5px; color: var(--saffron-deep); cursor: pointer; text-align: left;
  font-weight: 600; transition: all .15s;
}
.followup:active { border-color: var(--saffron); background: #fff6ec; }
.followup::before { content: "↳ "; opacity: .6; }

.actions { display: flex; gap: 8px; margin-top: 12px; }
.mini-btn {
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 13px;
  font: inherit; font-size: 12.5px; color: var(--ink-soft); cursor: pointer; font-weight: 600;
}
.mini-btn:active { border-color: var(--saffron); color: var(--saffron-deep); }
.mini-btn.speaking { background: var(--saffron); color: #fff; border-color: var(--saffron); }

.typing { display: inline-flex; gap: 6px; padding: 6px 2px; }
.typing span { width: 9px; height: 9px; border-radius: 50%; background: var(--saffron); opacity: .4; animation: blinkdot 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blinkdot { 0%,80%,100% { opacity: .3; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

/* perspectives */
.perspectives-q { font-family: var(--serif); font-size: 17px; color: var(--ink); margin-bottom: 3px; }
.perspectives-sub { font-size: 11.5px; color: var(--ink-soft); margin-bottom: 12px; }
.pview { display: flex; gap: 11px; padding: 12px 0; border-top: 1px solid var(--line); }
.pview:first-of-type { border-top: none; }
.pview .avatar { width: 40px; height: 40px; margin-top: 2px; box-shadow: 0 3px 10px rgba(0,0,0,.15); }
.pview-body { flex: 1; min-width: 0; }
.pview-name { font-family: var(--serif); font-size: 15.5px; color: var(--saffron-deep); margin-bottom: 3px; }
.pview-text { font-size: 14px; line-height: 1.6; color: #36291c; }

/* daily */
.daily-eyebrow { font-size: 11px; letter-spacing: 1.4px; text-transform: uppercase; color: var(--saffron-deep); font-weight: 700; }
.daily-verse { font-family: var(--serif); font-size: 18px; line-height: 1.45; color: var(--ink); margin: 8px 0 4px; font-style: italic; }
.daily-block { margin-top: 14px; }
.daily-h { font-family: var(--serif); font-size: 13.5px; color: var(--saffron-deep); margin-bottom: 4px; }
.daily-block p { font-size: 14px; line-height: 1.6; margin: 0; color: #36291c; }
.daily-journal {
  margin-top: 14px; background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--gold);
  border-radius: 11px; padding: 11px 13px; font-size: 14px; color: #3a2d20; font-style: italic;
}
.journal-box { margin-top: 12px; }
.journal-box textarea {
  width: 100%; min-height: 80px; resize: vertical; border: 1.5px solid var(--line);
  border-radius: 12px; padding: 11px 13px; font: inherit; font-size: 14px;
  background: #fff; color: var(--ink);
}
.journal-box textarea:focus { outline: none; border-color: var(--saffron); }
.journal-actions { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.journal-saved { font-size: 12px; color: #3f7d52; font-weight: 600; }
.journal-list { margin-top: 14px; }
.journal-entry {
  background: #fff; border: 1px solid var(--line); border-left: 4px solid var(--gold);
  border-radius: 11px; padding: 10px 12px; margin-bottom: 8px;
}
.journal-entry-date { font-size: 10.5px; color: var(--ink-soft); font-weight: 700; margin-bottom: 2px; }
.journal-entry-prompt { font-size: 12px; color: var(--saffron-deep); font-style: italic; margin-bottom: 3px; }
.journal-entry-text { font-size: 13.5px; line-height: 1.55; color: #36291c; white-space: pre-wrap; }

/* ---- composer ---- */
.composer {
  display: flex; align-items: flex-end; gap: 8px; margin: 0 12px 8px;
  padding: 7px; border-radius: 24px;
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); backdrop-filter: blur(14px);
}
#input {
  flex: 1; resize: none; border: none; background: transparent; color: #fff;
  font: inherit; font-size: 15px; padding: 11px 6px; max-height: 130px; line-height: 1.4; min-width: 0;
}
#input::placeholder { color: rgba(255,255,255,.5); }
#input:focus { outline: none; }
.round-btn {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  font-size: 17px; display: grid; place-items: center; transition: transform .12s;
  background: rgba(255,255,255,.13); color: #fff;
}
.round-btn:active { transform: scale(.9); }
.round-btn.send { background: linear-gradient(135deg, var(--gold), var(--saffron)); color: #2a1800; }
.round-btn.listening { background: #e23b3b; color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(226,59,59,.5); } 50% { box-shadow: 0 0 0 10px rgba(226,59,59,0); } }

/* ---- bottom nav ---- */
.bottomnav {
  display: flex; gap: 4px; padding: 6px 14px max(8px, env(safe-area-inset-bottom));
  background: rgba(16,10,34,.72); backdrop-filter: blur(16px);
  border-top: 1px solid rgba(255,255,255,.08);
}
.nav-tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; cursor: pointer; padding: 7px 4px; border-radius: 14px;
  color: rgba(255,255,255,.55); font: inherit; font-size: 10.5px; font-weight: 700; letter-spacing: .3px;
  transition: all .15s;
}
.nav-tab .nav-ico { font-size: 19px; line-height: 1; filter: grayscale(.6) opacity(.7); transition: all .15s; }
.nav-tab.active { color: var(--gold-soft); background: rgba(232,176,75,.12); }
.nav-tab.active .nav-ico { filter: none; transform: translateY(-1px); }
.nav-tab:active { transform: scale(.94); }

/* ---- login ---- */
.login-overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background:
    radial-gradient(900px 500px at 50% -5%, rgba(240,150,46,0.45), transparent 60%),
    linear-gradient(180deg, var(--night), var(--plum));
  padding: 18px;
}
.login-card {
  width: min(380px, 92vw); text-align: center; display: flex; flex-direction: column; gap: 11px;
  background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.15);
  border-radius: 26px; padding: 30px 24px; backdrop-filter: blur(18px); box-shadow: var(--card-shadow);
}
.login-om { font-size: 52px; color: var(--gold-soft); text-shadow: var(--glow); animation: breathe 5s ease-in-out infinite; }
@keyframes breathe { 0%,100% { text-shadow: 0 0 14px rgba(232,176,75,.4); } 50% { text-shadow: 0 0 34px rgba(232,176,75,.9); } }
.login-card h1 { font-family: var(--serif); font-weight: 400; font-size: 30px; margin: 0; color: #fff; }
.login-sub { margin: 0 0 4px; font-size: 13.5px; color: var(--gold-soft); line-height: 1.5; }
.login-faces { display: flex; justify-content: center; gap: 8px; margin: 2px 0 8px; }
.login-faces .avatar { width: 44px; height: 44px; border: 2px solid rgba(255,255,255,.25); }
.login-card input {
  border: 1.5px solid rgba(255,255,255,.25); border-radius: 13px; padding: 13px 15px;
  font: inherit; font-size: 15px; background: rgba(255,255,255,.95); color: var(--ink);
}
.login-card input:focus { outline: none; border-color: var(--gold); }
.login-btn {
  margin-top: 4px; border: none; border-radius: 13px; padding: 14px;
  background: linear-gradient(135deg, var(--gold), var(--saffron)); color: #2a1800;
  font: inherit; font-size: 15.5px; font-weight: 800; cursor: pointer; transition: transform .12s;
}
.login-btn:active { transform: scale(.97); }
.login-btn[disabled] { opacity: .6; }
.login-error { color: #ffb38a; font-size: 13px; font-weight: 600; }

/* ---- speaking overlay ---- */
.speak-overlay {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; align-content: center; gap: 14px;
  background: rgba(13,8,28,.9); backdrop-filter: blur(12px); cursor: pointer;
}
.speak-stage { position: relative; width: 240px; height: 240px; display: grid; place-items: center; }
.ring { position: absolute; inset: 22px; border-radius: 50%; border: 2px solid rgba(232,176,75,.55); opacity: 0; }
.speak-stage.talking .ring { animation: ripple 2.4s infinite ease-out; }
.speak-stage.talking .ring.r2 { animation-delay: .6s; } .speak-stage.talking .ring.r3 { animation-delay: 1.2s; }
@keyframes ripple { from { transform: scale(.7); opacity: .85; } to { transform: scale(1.22); opacity: 0; } }
.speak-face { width: 152px; height: 152px; border-radius: 50%; overflow: hidden; box-shadow: var(--glow); z-index: 1; }
.speak-face .avatar, .speak-face .avatar img, .speak-face .face-svg { width: 100%; height: 100%; display: block; }
.speak-name { font-family: var(--serif); font-size: 24px; color: #fff; text-align: center; }
.speak-hint { font-size: 12px; color: rgba(255,255,255,.55); text-align: center; letter-spacing: .5px; }

/* equalizer bars (visible while talking) */
.eq { display: flex; gap: 4px; align-items: flex-end; height: 22px; justify-content: center; opacity: 0; transition: opacity .2s; }
.talking-page .eq, .speak-overlay .eq { opacity: 1; }
.eq span { width: 4px; border-radius: 2px; background: var(--gold); height: 6px; }
.speak-overlay .eq span, .convo-overlay.talking .eq span { animation: eqbar .7s infinite ease-in-out alternate; }
.eq span:nth-child(2) { animation-delay: .12s; } .eq span:nth-child(3) { animation-delay: .24s; }
.eq span:nth-child(4) { animation-delay: .36s; } .eq span:nth-child(5) { animation-delay: .48s; }
@keyframes eqbar { from { height: 5px; } to { height: 22px; } }

/* ---- conversation mode ---- */
.convo-overlay {
  position: fixed; inset: 0; z-index: 95; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
  background: rgba(13,8,28,.94); backdrop-filter: blur(14px);
}
.convo-close {
  position: absolute; top: max(14px, env(safe-area-inset-top)); right: 16px;
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.1); color: #fff; font-size: 17px; cursor: pointer;
}
.convo-status { font-size: 13px; color: var(--gold-soft); letter-spacing: .4px; min-height: 18px; text-align: center; }
.convo-text {
  max-width: 520px; width: 100%; max-height: 30vh; overflow-y: auto; text-align: center;
  font-size: 16px; line-height: 1.65; color: #fdeede; padding: 0 6px;
}
.convo-text::-webkit-scrollbar { width: 4px; }
.convo-text::-webkit-scrollbar-thumb { background: rgba(232,176,75,.35); border-radius: 2px; }
.convo-mic {
  width: 68px; height: 68px; font-size: 26px; margin-top: 6px;
  background: linear-gradient(135deg, var(--gold), var(--saffron)); color: #2a1800;
  box-shadow: 0 8px 28px rgba(232,176,75,.4);
}
.convo-mic.listening { background: #e23b3b; color: #fff; animation: pulse 1s infinite; }

/* per-view listen */
.pview-name { display: flex; align-items: center; gap: 8px; }
.pview-listen {
  border: none; background: none; cursor: pointer; font-size: 14px; padding: 2px 4px;
  opacity: .65; line-height: 1;
}
.pview-listen:active { transform: scale(.9); }

/* desktop niceties */
@media (min-width: 640px) {
  .chat { padding: 8px 18px 14px; }
  .welcome h2 { font-size: 29px; }
  .answer-text { font-size: 16px; }
  .nav-tab { font-size: 11.5px; }
}
