/* ================================================================
   LECTURA EN VOZ – CamiCare / Cuentitos
   Web Speech API · sin dependencias externas.
   Solo activo en ver.php.

   Panel flotante en esquina inferior derecha, apilado sobre el
   botón de ambiente sonoro (bottom: 28px → este panel: 80px).

   Estados:
     IDLE    → solo el botón "Escuchar"
     PLAYING → controles + indicador de reproducción activa
     PAUSED  → controles + botón "Continuar"
   ================================================================ */

/* ── Panel contenedor ── */
#ct-voice-panel {
  position: fixed;
  bottom: 80px;
  right: 20px;
  z-index: 150;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none; /* desactivado globalmente; solo hijos activos */
}

#ct-voice-panel > * {
  pointer-events: auto;
}

/* ── Botón base compartido ── */
.ct-voice-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 44px;
  padding: 0 16px;
  border: 1.5px solid rgba(201, 149, 122, 0.35);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--acento, #c9957a);
  font-family: var(--ct-sans, system-ui, sans-serif);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.2s ease, background 0.2s ease, border-color 0.2s ease,
              box-shadow 0.2s ease;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08), 0 0 0 0 transparent;
}

.ct-voice-btn:hover {
  background: #fff;
  border-color: var(--acento, #c9957a);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.10);
}

.ct-voice-btn:focus-visible {
  outline: 2px solid var(--acento, #c9957a);
  outline-offset: 2px;
}

.ct-voice-btn .icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}

/* ── Botón icono circular (pause / resume / stop) ── */
.ct-voice-btn--icon {
  width: 44px;
  padding: 0;
  border-radius: 50%;
}

/* Botón stop: más discreto */
.ct-voice-btn--stop {
  color: #aaa;
  border-color: rgba(0, 0, 0, 0.10);
}

.ct-voice-btn--stop:hover {
  color: #d95c5c;
  border-color: #d95c5c;
  box-shadow: 0 4px 16px rgba(217, 92, 92, 0.12);
}

/* ── Controles (speed + botones de playback) ── */
#ct-voice-controls {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

/*
 * FIX: El selector de ID tiene mayor especificidad que el atributo
 * [hidden] de la hoja UA del navegador (en Chrome sin !important).
 * Sin esta regla, #ct-voice-controls sería siempre visible.
 */
#ct-voice-controls[hidden] {
  display: none;
}

/* Fila de botones pause / resume / stop */
.ct-voice-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Control de velocidad ── */
.ct-voice-speed {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1.5px solid rgba(201, 149, 122, 0.25);
  border-radius: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.ct-voice-speed__label {
  font-family: var(--ct-sans, system-ui, sans-serif);
  font-size: 0.70rem;
  color: #bbb;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.ct-voice-speed__val {
  font-family: var(--ct-sans, system-ui, sans-serif);
  font-size: 0.76rem;
  color: var(--acento, #c9957a);
  font-weight: 600;
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* Track del slider */
.ct-voice-speed__range {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  border-radius: 2px;
  /* El gradiente de fill se actualiza dinámicamente por JS */
  background: linear-gradient(
    to right,
    var(--acento, #c9957a) 0%,
    var(--acento, #c9957a) 50%,
    rgba(201, 149, 122, 0.22) 50%,
    rgba(201, 149, 122, 0.22) 100%
  );
  outline: none;
  cursor: pointer;
  border: none;
}

.ct-voice-speed__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--acento, #c9957a);
  cursor: pointer;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s ease;
}

.ct-voice-speed__range::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.ct-voice-speed__range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--acento, #c9957a);
  border: none;
  cursor: pointer;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.18);
}

/* ── Párrafo activo durante la lectura ── */
.ct-voice-para--active {
  background: linear-gradient(
    to right,
    var(--bg-radial, rgba(201, 149, 122, 0.10)),
    transparent 80%
  );
  border-left: 2px solid var(--acento, #c9957a);
  padding-left: 12px;
  margin-left: -14px;
  border-radius: 0 2px 2px 0;
  transition: background 0.45s ease, border-color 0.45s ease;
}

/* ── Modo lectura: atenúa el fondo de capas ── */
body.reading-mode #ct-layers {
  opacity: 0.2;
  transition: opacity 0.6s ease;
}

/* ── Artículo en reproducción: ligero énfasis ── */
body.reading-mode .cuentito-article__body {
  transition: color 0.4s ease;
}

/* ── Mobile ── */
@media (max-width: 520px) {
  #ct-voice-panel {
    bottom: 80px;
    right: 12px;
  }

  .ct-voice-speed__range {
    width: 60px;
  }

  .ct-voice-btn--main .ct-voice-label {
    display: none;
  }

  .ct-voice-btn--main {
    width: 44px;
    padding: 0;
    border-radius: 50%;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .ct-voice-btn,
  .ct-voice-para--active,
  body.reading-mode #ct-layers {
    transition: none !important;
  }

  .ct-voice-speed__range::-webkit-slider-thumb {
    transition: none !important;
  }
}
