/* ================================================================
   COMPANION NARRATIVO – CamiCare / Cuentitos  (rediseño v2)
   Solo activo en ver.php. Aparece al 95% de scroll.

   Fases:
   1. Centrado inferior · protagonista · emoción
   2. Imagen cami_thankyou · cierre cálido
   3. Lateral inferior-derecha · tarjeta de sugerencia
   4. Presencia silenciosa · cami_present
   ================================================================ */

/* ── Wrapper: controla posición y opacidad global ── */
#ct-companion-wrapper {
  position: fixed;
  z-index: 210;
  bottom: 28px;
  /* Estado inicial: centrado */
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  /* SOLO transiciona opacidad; posición cambia mientras opacity = 0 */
  transition: opacity 0.45s ease;
  pointer-events: none;
}

#ct-companion-wrapper.ct-companion--active {
  pointer-events: auto;
}

#ct-companion-wrapper.is-visible {
  opacity: 1;
}

/* Estado lateral (fase 3+): se aplica vía JS mientras opacity = 0 */
#ct-companion-wrapper.ct-companion--lateral {
  left: 20px;
  bottom: 28px;
  transform: none;
}

/* ── Fila interior: card (izquierda) + figura (derecha) ── */
.ct-companion__row {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 14px;
}

/* ── Figura: burbuja + avatar ── */
.ct-companion__figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Avatar ── */
.ct-companion__avatar {
  display: block;
  width: 150px;     /* fase 1-2: protagonista */
  height: 150px;
  object-fit: contain;
  filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.10));
  transition: opacity 0.35s ease, width 0.5s ease, height 0.5s ease;
}

/* Avatar más pequeño en modo lateral (fase 3) */
#ct-companion-wrapper.ct-companion--lateral .ct-companion__avatar {
  width: 118px;
  height: 118px;
}

/* Avatar reducido en modo silencioso (fase 4) */
#ct-companion-wrapper.ct-companion--silent .ct-companion__avatar {
  width: 100px;
  height: 100px;
}

/* ── Burbuja de diálogo ── */
.ct-companion__bubble {
  background: rgba(255, 255, 255, 0.96);
  border-radius: 14px;
  padding: 12px 18px 13px;
  max-width: 238px;
  text-align: center;
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.07),
    0 0 0 1px rgba(0, 0, 0, 0.05);
  position: relative;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

/* Cola apuntando hacia el avatar (abajo) */
.ct-companion__bubble::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 8px solid rgba(255, 255, 255, 0.96);
}

.ct-companion__bubble.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Tinte emocional sutil en la burbuja */
body[data-emocion] .ct-companion__bubble {
  border-top: 2px solid var(--acento, #c9957a);
}

.ct-companion__msg {
  margin: 0;
  font-family: var(--ct-serif, 'Lora', Georgia, serif);
  font-size: 0.84rem;
  line-height: 1.52;
  color: var(--ct-text, #3a3a3a);
}

/* ── Tarjeta de sugerencia ── */
.ct-companion__card {
  width: 214px;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.10),
    0 2px 8px rgba(0, 0, 0, 0.06),
    0 0 0 1px rgba(0, 0, 0, 0.04);
  opacity: 0;
  transform: translateX(10px);  /* entra desde la derecha */
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.ct-companion__card.is-visible {
  opacity: 1;
  transform: translateX(0);
}

/* Acento emocional: franja superior */
body[data-emocion] .ct-companion__card {
  border-top: 3px solid var(--acento, #c9957a);
}

/* Media: imagen de portada */
.ct-companion__card-media {
  width: 100%;
  height: 96px;
  overflow: hidden;
  background: var(--bg-radial, rgba(201, 149, 122, 0.10));
  display: flex;
  align-items: center;
  justify-content: center;
}

.ct-companion__card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Sin imagen: gradiente tintado */
.ct-companion__card-media--empty {
  background: linear-gradient(
    135deg,
    var(--bg-radial, rgba(201, 149, 122, 0.15)),
    var(--bg-base, #fdfaf7) 80%
  );
}

/* Modo colección: todos leídos */
.ct-companion__card--collection .ct-companion__card-media {
  height: 0;
  padding: 0;
}

.ct-companion__card--collection .ct-companion__card-body {
  padding-top: 16px;
}

.ct-companion__card--collection .ct-companion__card-titulo {
  color: var(--acento, #c9957a);
}

/* Cuerpo textual */
.ct-companion__card-body {
  padding: 12px 14px 14px;
}

.ct-companion__card-titulo {
  margin: 0 0 5px;
  font-family: var(--ct-serif, 'Lora', Georgia, serif);
  font-size: 0.87rem;
  font-weight: 600;
  color: var(--ct-text, #3a3a3a);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ct-companion__card-excerpt {
  margin: 0 0 10px;
  font-size: 0.73rem;
  color: var(--ct-text-soft, #777);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ct-companion__card-btn {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  font-family: var(--ct-sans, system-ui, sans-serif);
  font-size: 0.74rem;
  font-weight: 500;
  line-height: 1;
  background: var(--acento, #c9957a);
  color: #fff !important;
  text-decoration: none;
  transition: opacity 0.25s ease;
}

.ct-companion__card-btn:hover {
  opacity: 0.72;
}

/* ── Botón de música: se desplaza cuando el companion aparece ── */
#ct-ambiente-btn {
  transition: transform 0.5s ease, opacity 0.3s ease, background 0.3s ease !important;
}

.ct-ambiente-btn--companion-up {
  transform: translateY(-70px) !important;
}

/* ── Mobile ── */
@media (max-width: 520px) {
  #ct-companion-wrapper {
    bottom: 16px;
  }

  #ct-companion-wrapper.ct-companion--lateral {
    left: 10px;
    bottom: 16px;
  }

  .ct-companion__avatar {
    width: 120px;
    height: 120px;
  }

  #ct-companion-wrapper.ct-companion--lateral .ct-companion__avatar {
    width: 94px;
    height: 94px;
  }

  .ct-companion__card {
    width: 176px;
  }

  .ct-companion__card-media {
    height: 74px;
  }

  .ct-companion__bubble {
    max-width: 194px;
    padding: 10px 14px 11px;
  }

  .ct-companion__msg {
    font-size: 0.79rem;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  #ct-companion-wrapper,
  .ct-companion__avatar,
  .ct-companion__bubble,
  .ct-companion__card,
  #ct-ambiente-btn {
    transition: opacity 0.15s ease !important;
    transform: none !important;
    animation: none !important;
  }

  .ct-companion__bubble::after {
    /* Sin transición, mantenemos la forma */
  }
}

/* ── Modo noche ────────────────────────────────────────────────── */
.modo-noche #ct-companion-wrapper .ct-companion__bubble {
  background: #2a2018;
  box-shadow:
    0 4px 20px rgba(0, 0, 0, .35),
    0 0 0 1px rgba(255, 255, 255, .06);
}

.modo-noche #ct-companion-wrapper .ct-companion__bubble::after {
  border-top-color: #2a2018;
}

.modo-noche #ct-companion-wrapper .ct-companion__msg {
  color: #f0e8d8;
}

.modo-noche #ct-companion-wrapper .ct-companion__card {
  background: #2a2018;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, .40),
    0 2px 8px rgba(0, 0, 0, .28),
    0 0 0 1px rgba(255, 255, 255, .05);
}

.modo-noche #ct-companion-wrapper .ct-companion__card-body {
  background: #2a2018;
}

.modo-noche #ct-companion-wrapper .ct-companion__card-media--empty {
  background: linear-gradient(
    135deg,
    rgba(212, 165, 116, .10),
    #231d18 80%
  );
}

.modo-noche #ct-companion-wrapper .ct-companion__card-titulo {
  color: #f0e8d8;
}

.modo-noche #ct-companion-wrapper .ct-companion__card-excerpt {
  color: #a89880;
}
