/* ══════════════════════════════════════════════════════════════
   RHYTHME · Luna the Floating Mascot
   Cute crescent moon with watery eyes — your in-app companion.
   Floats above the nav, opens a chat panel, tracks credits.
   ══════════════════════════════════════════════════════════════ */

/* ── Floating button ── */
#lunaBtn {
  position: fixed;
  bottom: 96px;
  right: 16px;
  z-index: 9999;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  padding: 0;
  background: linear-gradient(135deg, rgba(196, 181, 224, 0.9), rgba(245, 198, 184, 0.9));
  box-shadow: 0 8px 24px -6px rgba(122, 92, 150, 0.4), 0 2px 8px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s;
  animation: lunaFloat 3.5s ease-in-out infinite;
  -webkit-tap-highlight-color: transparent;
}
#lunaBtn:hover { transform: scale(1.08); box-shadow: 0 12px 32px -6px rgba(122, 92, 150, 0.5); }
#lunaBtn:active { transform: scale(0.95); }
#lunaBtn img {
  width: 54px;
  height: 54px;
  object-fit: contain;
  border-radius: 50%;
  pointer-events: none;
}

/* Notification dot */
#lunaBtn .luna-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background: #e89580;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
  animation: lunaPulse 2s ease-in-out infinite;
}
#lunaBtn.has-msg .luna-dot { display: block; }

@keyframes lunaFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
@keyframes lunaPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.2); }
}

/* ── Chat panel ── */
#lunaPanel {
  position: fixed;
  bottom: 170px;
  right: 16px;
  z-index: 9998;
  width: min(340px, calc(100vw - 32px));
  max-height: 60vh;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 24px;
  border: 1px solid rgba(196, 181, 224, 0.3);
  box-shadow: 0 20px 60px -12px rgba(122, 92, 150, 0.35), 0 4px 16px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s;
}
#lunaPanel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Panel header */
.luna-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  background: linear-gradient(135deg, rgba(196, 181, 224, 0.25), rgba(245, 198, 184, 0.2));
  border-bottom: 1px solid rgba(196, 181, 224, 0.2);
}
.luna-header img {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: contain;
}
.luna-header .luna-info { flex: 1; min-width: 0; }
.luna-header .luna-name {
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 600;
  font-size: 16px;
  color: #3d2f52;
  line-height: 1.2;
}
.luna-header .luna-status {
  font-size: 11px;
  color: #8a78a0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.luna-header .luna-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6ba88a;
  display: inline-block;
}
.luna-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(107, 82, 142, 0.08);
  color: #8a78a0;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.luna-close:hover { background: rgba(107, 82, 142, 0.15); }

/* Credits display */
.luna-credits {
  padding: 8px 16px;
  background: rgba(196, 181, 224, 0.08);
  border-bottom: 1px solid rgba(196, 181, 224, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: #8a78a0;
}
.luna-credits b { color: #7a5c96; font-weight: 700; }
.luna-credits .luna-upgrade {
  color: #d49a8a;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

/* Messages */
.luna-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.luna-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: lunaMsgIn 0.3s ease-out;
}
@keyframes lunaMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.luna-msg.luna-bot {
  align-self: flex-start;
  background: linear-gradient(135deg, rgba(196, 181, 224, 0.2), rgba(245, 198, 184, 0.15));
  border: 1px solid rgba(196, 181, 224, 0.25);
  color: #3d2f52;
  border-bottom-left-radius: 6px;
}
.luna-msg.luna-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #7a5c96, #9b7bb0);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.luna-msg.luna-error {
  align-self: center;
  background: rgba(196, 122, 106, 0.1);
  border: 1px solid rgba(196, 122, 106, 0.25);
  color: #c47a6a;
  font-size: 12px;
  text-align: center;
  max-width: 90%;
}

/* Typing indicator */
.luna-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(196, 181, 224, 0.2), rgba(245, 198, 184, 0.15));
  border: 1px solid rgba(196, 181, 224, 0.25);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
}
.luna-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #7a5c96;
  opacity: 0.4;
  animation: lunaTyping 1.2s ease-in-out infinite;
}
.luna-typing span:nth-child(2) { animation-delay: 0.2s; }
.luna-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes lunaTyping {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* Quick suggestion chips */
.luna-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 8px;
}
.luna-chip {
  padding: 6px 12px;
  border-radius: 14px;
  background: rgba(196, 181, 224, 0.12);
  border: 1px solid rgba(196, 181, 224, 0.25);
  color: #7a5c96;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.luna-chip:hover {
  background: rgba(196, 181, 224, 0.25);
  transform: translateY(-1px);
}

/* Input area */
.luna-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(196, 181, 224, 0.15);
  background: rgba(255, 255, 255, 0.6);
}
.luna-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid rgba(196, 181, 224, 0.3);
  background: #fff;
  font-size: 13.5px;
  font-family: 'Manrope', system-ui, sans-serif;
  color: #3d2f52;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.luna-input:focus {
  border-color: rgba(122, 92, 150, 0.5);
  box-shadow: 0 0 0 3px rgba(122, 92, 150, 0.1);
}
.luna-input::placeholder { color: #a898bc; }
.luna-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #7a5c96, #9b7bb0);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, opacity 0.2s;
  flex-shrink: 0;
}
.luna-send:hover { transform: scale(1.08); }
.luna-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* Disclaimer */
.luna-disclaimer {
  padding: 6px 16px 10px;
  font-size: 10px;
  color: #a898bc;
  text-align: center;
  line-height: 1.4;
}

/* ── Onboarding tooltip (first visit) ── */
#lunaTooltip {
  position: fixed;
  bottom: 168px;
  right: 16px;
  z-index: 9997;
  max-width: 200px;
  background: #3d2f52;
  color: #fff;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 12px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(61, 47, 82, 0.3);
  animation: lunaTooltipIn 0.5s ease-out;
}
#lunaTooltip::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 24px;
  width: 12px;
  height: 12px;
  background: #3d2f52;
  transform: rotate(45deg);
}
@keyframes lunaTooltipIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Offline guide: bounded accessibility/readability fixes, keeping Luna's design. */
#lunaPanel[hidden] { display: none !important; }
#lunaPanel { bottom: calc(var(--shell-bottom-size, 82px) + 84px); right: max(12px, var(--shell-safe-right, 0px)); max-height: calc(100dvh - var(--shell-top-size, 69px) - var(--shell-bottom-size, 82px) - 108px); background: var(--card-solid); color: var(--ink); }
#lunaBtn { bottom: calc(var(--shell-bottom-size, 82px) + 12px); right: max(12px, var(--shell-safe-right, 0px)); }
#lunaPanel .luna-header { padding: 10px 12px; flex-shrink: 0; }
#lunaPanel .luna-name { color: var(--ink); font-size: 1rem; }
#lunaPanel .luna-status { color: var(--taupe); font-size: .7rem; }
#lunaPanel .luna-status::before { display: none; }
#lunaPanel .luna-close, #lunaPanel .luna-send { width: 44px; height: 44px; flex: 0 0 44px; }
#lunaPanel .luna-close { color: var(--ink); }
#lunaPanel .luna-credits { font-size: .72rem; color: var(--taupe); padding: 8px 12px; flex-shrink: 0; }
#lunaPanel .luna-messages { min-height: 72px; flex: 1 1 auto; padding: 10px; }
#lunaPanel .luna-msg { font-size: .85rem; max-width: 95%; flex-shrink: 0; }
#lunaPanel .luna-bot { background: var(--sunken); color: var(--ink); }
#lunaPanel .luna-user { background: #6b4e87; color: #fff; }
#lunaPanel .luna-chip { min-height: 44px; white-space: normal; font: 600 .72rem/1.3 var(--sans); color: var(--ink); }
#lunaPanel .luna-suggestions { flex-shrink: 0; padding: 4px 10px; }
#lunaPanel .luna-input-row { flex-shrink: 0; padding: 8px 10px; background: var(--card-solid); }
#lunaPanel .luna-input { min-width: 0; width: 0; min-height: 44px; font-size: max(16px, .85rem); background: var(--card-solid); color: var(--ink); }
#lunaPanel .luna-input::placeholder { color: var(--taupe); }
#lunaPanel .luna-disclaimer { flex-shrink: 0; color: var(--taupe); font-size: .65rem; padding: 4px 10px 8px; }
#lunaPanel .luna-read-more { display: inline-flex; min-height: 44px; align-items: center; color: var(--mauve); text-decoration: underline; font-weight: 700; font-size: .78rem; overflow-wrap: anywhere; }
#lunaPanel .luna-disclaimer .luna-read-more { margin-left: .5rem; }
#lunaPanel .luna-source { min-width: 44px; min-height: 44px; margin-top: .5rem; cursor: pointer; }
#lunaPanel .luna-source-label { font-size: .75rem; margin-left: .25rem; color: var(--taupe); }
#lunaPanel :focus-visible, #lunaBtn:focus-visible { outline: 3px solid var(--mauve); outline-offset: 2px; }
@media (max-height: 700px) { #lunaPanel { top: calc(var(--shell-safe-top, 0px) + 8px); bottom: calc(var(--shell-safe-bottom, 0px) + 8px); max-height: none; z-index: 10000; } }
@media (prefers-reduced-motion: reduce) { #lunaBtn, #lunaPanel, #lunaPanel * { animation: none !important; transition: none !important; } }

/* Extra-large text needs the available height instead of a small floating card. */
html[data-fontsize="xlarge"] #lunaPanel { top: calc(var(--shell-safe-top, 0px) + 8px); bottom: calc(var(--shell-safe-bottom, 0px) + 8px); max-height: none; z-index: 10000; }

#lunaPanel .luna-msg .luna-read-more { display: flex; margin-top: .4rem; }
