/* ============================================================
   buddy.css — Site companion mascot system
   ============================================================ */

/* ---- Buddy Orb ---- */
.buddy-orb {
  position: fixed;
  bottom: 110px;
  right: 22px;
  width: 58px;
  height: 58px;
  z-index: 9000;
  cursor: grab;
  user-select: none;
  touch-action: none;
  display: none; /* shown by JS when enabled or when admin */
}

.buddy-orb.buddy-visible {
  display: block;
}

/* Admin sees orb always — faded when buddy is disabled so it's unobtrusive */
.buddy-orb.buddy-visible:not(.buddy-enabled) .buddy-orb-inner {
  opacity: 0.65;
  filter: grayscale(0.3);
  animation: none !important;
}

/* Hint tooltip for admin when buddy is not yet enabled */
.buddy-orb.buddy-visible:not(.buddy-enabled)::after {
  content: 'Click to configure';
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--surface-2, #1a1a2e);
  color: var(--text-subtle, rgba(255,255,255,.5));
  font-size: 0.68rem;
  padding: 3px 9px;
  border-radius: 8px;
  white-space: nowrap;
  border: 1px solid var(--border, rgba(255,255,255,.1));
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}

.buddy-orb.buddy-visible:not(.buddy-enabled):hover::after {
  opacity: 1;
}

.buddy-orb.buddy-dragging {
  cursor: grabbing;
}

.buddy-orb-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 35% 35%, rgba(196,181,253,.25) 0%, rgba(124,58,237,.12) 100%);
  box-shadow:
    0 0 0 1.5px rgba(124,58,237,.45),
    0 4px 18px rgba(124,58,237,.30),
    0 0 30px rgba(124,58,237,.15);
  transition: box-shadow .2s, transform .15s;
  animation: buddyFloat 3.5s ease-in-out infinite;
}

.buddy-orb:hover .buddy-orb-inner,
.buddy-orb.buddy-active .buddy-orb-inner {
  box-shadow:
    0 0 0 2px rgba(124,58,237,.8),
    0 6px 28px rgba(124,58,237,.5),
    0 0 45px rgba(124,58,237,.25);
  transform: scale(1.08);
}

.buddy-orb-inner svg {
  width: 38px;
  height: 38px;
}

.buddy-char-img {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

/* Float animation */
@keyframes buddyFloat {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-7px); }
}

.buddy-orb.buddy-active .buddy-orb-inner {
  animation: buddyFloat 2s ease-in-out infinite;
}

/* Poof appear/disappear */
@keyframes buddyPoof {
  0%   { transform: scale(0.2); opacity: 0; }
  40%  { transform: scale(1.15); opacity: 1; }
  70%  { transform: scale(0.93); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes buddyPoofOut {
  0%   { transform: scale(1); opacity: 1; }
  40%  { transform: scale(1.15); opacity: .7; }
  100% { transform: scale(0.1); opacity: 0; }
}

.buddy-orb.buddy-poof-in .buddy-orb-inner {
  animation: buddyPoof .45s cubic-bezier(.36,.07,.19,.97) both;
}

.buddy-orb.buddy-poof-out .buddy-orb-inner {
  animation: buddyPoofOut .35s cubic-bezier(.36,.07,.19,.97) both;
}

/* Flipped orientation (faces center) */
.buddy-orb.buddy-flipped .buddy-orb-inner {
  transform: scaleX(-1);
}
.buddy-orb.buddy-flipped:hover .buddy-orb-inner,
.buddy-orb.buddy-flipped.buddy-active .buddy-orb-inner {
  transform: scaleX(-1) scale(1.08);
}

/* ---- Chat Bubble ---- */
.buddy-bubble {
  position: fixed;
  top: -9999px;
  left: -9999px;
  z-index: 9001;
  max-width: 300px;
  min-width: 180px;
  pointer-events: auto;
  filter: drop-shadow(0 6px 20px rgba(0,0,0,.35));
  transition: opacity .2s;
}

.buddy-bubble.hidden {
  display: none;
}

.buddy-bubble-inner {
  background: var(--buddy-bubble-bg, #7c3aed);
  color: var(--buddy-bubble-txt, #fff);
  border-radius: 18px;
  padding: 12px 16px 12px 14px;
  position: relative;
  font-size: 0.92rem;
  line-height: 1.5;
  word-break: break-word;
}

.buddy-bubble-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: rgba(255,255,255,.2);
  border: none;
  color: inherit;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
  transition: background .15s;
}

.buddy-bubble-close:hover {
  background: rgba(255,255,255,.35);
}

.buddy-bubble-msg {
  padding-right: 16px;
  margin-bottom: 2px;
}

.buddy-bubble-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  padding: 5px 12px;
  border-radius: 20px;
  background: rgba(255,255,255,.18);
  color: inherit;
  font-size: 0.83rem;
  font-weight: 700;
  text-decoration: none;
  transition: background .15s;
  border: 1px solid rgba(255,255,255,.25);
}

.buddy-bubble-link:hover {
  background: rgba(255,255,255,.3);
  color: inherit;
  text-decoration: none;
}

.buddy-bubble-link.hidden {
  display: none;
}

/* Tail — points toward the orb */
.buddy-bubble-tail {
  width: 0;
  height: 0;
  position: absolute;
}

/* tail positions set by JS via data-tail-dir */
.buddy-bubble[data-tail="bottom-right"] .buddy-bubble-tail {
  bottom: -10px;
  right: 22px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 11px solid var(--buddy-bubble-bg, #7c3aed);
}
.buddy-bubble[data-tail="bottom-left"] .buddy-bubble-tail {
  bottom: -10px;
  left: 22px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 11px solid var(--buddy-bubble-bg, #7c3aed);
}
.buddy-bubble[data-tail="top-right"] .buddy-bubble-tail {
  top: -10px;
  right: 22px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 11px solid var(--buddy-bubble-bg, #7c3aed);
}
.buddy-bubble[data-tail="top-left"] .buddy-bubble-tail {
  top: -10px;
  left: 22px;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 11px solid var(--buddy-bubble-bg, #7c3aed);
}

/* Bubble appear animation */
@keyframes bubbleIn {
  0%   { transform: scale(0.7) translateY(10px); opacity: 0; }
  80%  { transform: scale(1.04) translateY(-2px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.buddy-bubble:not(.hidden) {
  animation: bubbleIn .35s cubic-bezier(.36,.07,.19,.97) both;
}

/* ---- Buddy Settings Panel ---- */
.buddy-settings-panel {
  position: fixed;
  z-index: 9002;
  background: var(--surface-2, #1a1a2e);
  border: 1px solid var(--border, rgba(255,255,255,.1));
  border-radius: 16px;
  width: 280px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
  overflow: hidden;
  bottom: 180px;
  right: 22px;
}

.buddy-settings-panel.hidden {
  display: none;
}

.buddy-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border, rgba(255,255,255,.1));
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}

.buddy-settings-close {
  background: none;
  border: none;
  color: var(--text-subtle);
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0 4px;
  transition: color .15s;
}
.buddy-settings-close:hover { color: var(--text); }

.buddy-settings-body {
  padding: 10px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
}

.buddy-setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.buddy-setting-label {
  font-size: 0.85rem;
  color: var(--text-subtle);
  flex: 1;
}

.buddy-upload-btn {
  font-size: 0.8rem;
  padding: 4px 12px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  transition: background .15s;
  white-space: nowrap;
}

.buddy-upload-btn:hover {
  background: color-mix(in srgb, var(--accent) 25%, transparent);
}

/* Toggle switch for buddy settings */
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-knob {
  position: absolute;
  inset: 0;
  background: var(--border, rgba(255,255,255,.15));
  border-radius: 22px;
  transition: background .2s;
}

.toggle-knob::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}

.toggle-switch input:checked + .toggle-knob {
  background: var(--accent);
}

.toggle-switch input:checked + .toggle-knob::before {
  transform: translateX(18px);
}

/* ---- Orb shapes ---- */
.buddy-orb-square .buddy-orb-inner {
  border-radius: 10px;
}
.buddy-orb-square .buddy-char-img {
  border-radius: 8px;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.buddy-orb-free .buddy-orb-inner {
  border-radius: 0 !important;
  background: none !important;
  box-shadow: none !important;
  border: none !important;
}
.buddy-orb-free .buddy-char-img {
  border-radius: 0 !important;
  object-fit: contain !important;
  width: 100% !important;
  height: 100% !important;
}
.buddy-orb-free #buddy-default-icon {
  display: none !important;
}

/* ---- Float animation off ---- */
.buddy-float-off .buddy-orb-inner,
.buddy-float-off:hover .buddy-orb-inner,
.buddy-float-off.buddy-active .buddy-orb-inner {
  animation: none !important;
}

/* ---- Orb dismiss button (visitors) ---- */
.buddy-orb-close-btn {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(15,15,30,0.85);
  color: rgba(255,255,255,0.8);
  border: 1.5px solid rgba(255,255,255,0.25);
  cursor: pointer;
  font-size: 11px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9001;
  line-height: 1;
  padding: 0;
  transition: background .15s;
  pointer-events: auto;
}
.buddy-orb:hover .buddy-orb-close-btn {
  display: flex;
}
.buddy-orb-close-btn:hover {
  background: rgba(180,20,20,0.9);
  color: #fff;
}

/* ---- Bubble image ---- */
.buddy-bubble-img {
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 8px;
  display: block;
}
.buddy-bubble-img.hidden { display: none; }

/* ---- Settings char image thumbs ---- */
.buddy-img-thumb {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent, #7c3aed);
  flex-shrink: 0;
}
.buddy-orb-free .buddy-img-thumb,
.buddy-orb-square .buddy-img-thumb {
  border-radius: 6px;
}
.buddy-img-thumb.hidden { display: none; }

/* ---- Settings select boxes ---- */
.buddy-settings-body select {
  background: var(--surface-1, #0d0d18);
  color: var(--text, #fff);
  border: 1px solid var(--border, rgba(255,255,255,.15));
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 0.82rem;
  cursor: pointer;
  outline: none;
  flex-shrink: 0;
}
.buddy-settings-body select:focus {
  border-color: var(--accent, #7c3aed);
}

/* ---- Trigger star button on cards ---- */
.card-trigger-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
  color: var(--text-subtle);
  opacity: 0.35;
  transition: opacity .2s, color .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-trigger-btn:hover {
  opacity: 0.8;
  color: var(--accent);
}

.card-trigger-btn.trigger-active {
  opacity: 1;
  color: #fbbf24;
}

.card-trigger-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ---- Trigger modal labels ---- */
.trigger-field-label {
  display: flex;
  flex-direction: column;
  font-size: 0.82rem;
  color: var(--text-subtle);
  font-weight: 600;
}
