/* ============================================================
   player.css — Styles du lecteur vidéo autonome
   Aucune dépendance externe. Tout est isolé sous .lv-player.
   ============================================================ */

/* --- Variables personnalisables -----------------------------
   On peut surcharger ces variables sur .lv-player ou sur :root
   pour rhabiller le lecteur sans toucher au CSS :

     <div class="lv-player" style="--lv-accent:#e91e63"></div>
   ------------------------------------------------------------ */
.lv-player {
  --lv-accent: #4f8cff;              /* couleur d'accent (barres, focus, CTA) */
  --lv-accent-contrast: #ffffff;     /* texte posé sur l'accent */
  --lv-bg: #000;                     /* fond derrière la vidéo */
  --lv-control-bg: rgba(0, 0, 0, 0.55);
  --lv-control-fg: #fff;
  --lv-rail: rgba(255, 255, 255, 0.28);   /* rail de progression vide */
  --lv-buffer: rgba(255, 255, 255, 0.45); /* portion mise en tampon */
  --lv-radius: 10px;
  --lv-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --lv-menu-bg: rgba(20, 20, 22, 0.96);

  position: relative;
  display: block;
  width: 100%;
  background: var(--lv-bg);
  font-family: var(--lv-font);
  color: var(--lv-control-fg);
  overflow: hidden;
  border-radius: var(--lv-radius);
  /* Le conteneur porte le focus clavier : on veut le voir. */
  outline: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* En plein écran, pas d'arrondi ni de marge. */
.lv-player:fullscreen { border-radius: 0; width: 100%; height: 100%; }
.lv-player:-webkit-full-screen { border-radius: 0; width: 100%; height: 100%; }

.lv-player:focus-visible {
  box-shadow: 0 0 0 3px var(--lv-accent);
}

/* --- Surface vidéo ----------------------------------------- */
.lv-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--lv-bg);
}
.lv-player:fullscreen .lv-stage,
.lv-player:-webkit-full-screen .lv-stage {
  height: 100%;
  aspect-ratio: auto;
}

.lv-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--lv-bg);
  /* On masque les pistes natives : nos propres sous-titres sont rendus
     dans .lv-cues pour garder la maîtrise du style. */
}
.lv-video::cue { opacity: 0; }
.lv-video::-webkit-media-controls { display: none !important; }

/* Zone cliquable transparente : lecture/pause au clic sur l'image. */
.lv-clickzone {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
}

/* --- Sous-titres rendus par le lecteur ---------------------- */
.lv-cues {
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: 84px;                 /* au-dessus de la barre de contrôles */
  text-align: center;
  pointer-events: none;
  transition: bottom 0.2s ease;
  z-index: 3;
}
.lv-player.is-idle .lv-cues { bottom: 24px; }
.lv-cues span {
  display: inline-block;
  background: rgba(0, 0, 0, 0.75);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: clamp(14px, 2.4vw, 22px);
  line-height: 1.35;
  white-space: pre-line;
}
.lv-cues:empty { display: none; }

/* --- Voile central (gros bouton + spinner) ------------------ */
.lv-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
}
.lv-bigplay {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 0;
  background: var(--lv-accent);
  color: var(--lv-accent-contrast);
  display: grid;
  place-items: center;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  transition: transform 0.15s ease, opacity 0.2s ease;
}
.lv-bigplay:hover { transform: scale(1.07); }
.lv-bigplay svg { width: 32px; height: 32px; fill: currentColor; margin-left: 3px; }
.lv-player.is-playing .lv-bigplay,
.lv-player.is-ended .lv-bigplay { display: none; }

.lv-spinner {
  width: 46px;
  height: 46px;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--lv-accent);
  border-radius: 50%;
  animation: lv-spin 0.8s linear infinite;
  display: none;
}
.lv-player.is-buffering .lv-spinner { display: block; }
.lv-player.is-buffering .lv-bigplay { display: none; }
@keyframes lv-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .lv-spinner { animation-duration: 2s; }
  .lv-bigplay { transition: none; }
}

/* --- Barre de contrôles ------------------------------------- */
.lv-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 40px 12px 8px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85), rgba(0, 0, 0, 0));
  z-index: 4;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
/* « idle » = souris immobile pendant la lecture : on cache les contrôles. */
.lv-player.is-idle .lv-controls {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}
/* On ne cache jamais les contrôles si un élément à l'intérieur a le focus
   clavier, sinon la navigation au clavier devient invisible. */
.lv-player.is-idle .lv-controls:focus-within {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.lv-player.is-ended .lv-controls { opacity: 0; pointer-events: none; }

.lv-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* --- Boutons ------------------------------------------------ */
.lv-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--lv-control-fg);
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  cursor: pointer;
  flex: 0 0 auto;
  padding: 0;
}
.lv-btn svg { width: 20px; height: 20px; fill: currentColor; pointer-events: none; }
.lv-btn:hover { background: rgba(255, 255, 255, 0.14); }
.lv-btn:focus-visible,
.lv-menu button:focus-visible,
.lv-scrub:focus-visible {
  outline: 2px solid var(--lv-accent);
  outline-offset: 2px;
}
.lv-btn[aria-pressed="true"] { color: var(--lv-accent); }
.lv-btn.is-text {
  width: auto;
  min-width: 42px;
  padding: 0 10px;
  font: 600 12px/1 var(--lv-font);
  letter-spacing: 0.02em;
}

.lv-time {
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  padding: 0 8px;
  white-space: nowrap;
  opacity: 0.92;
}
.lv-spacer { flex: 1 1 auto; }

/* --- Barre de progression ----------------------------------- */
.lv-scrub {
  position: relative;
  height: 22px;               /* zone de clic confortable */
  margin: 0 4px 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  border-radius: 4px;
}
.lv-track {
  position: relative;
  width: 100%;
  height: 4px;
  background: var(--lv-rail);
  border-radius: 3px;
  transition: height 0.12s ease;
}
.lv-scrub:hover .lv-track,
.lv-scrub.is-dragging .lv-track { height: 7px; }

.lv-buffered,
.lv-played {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 3px;
  width: 0;
}
.lv-buffered { background: var(--lv-buffer); }
.lv-played { background: var(--lv-accent); }

.lv-thumb {
  position: absolute;
  top: 50%;
  left: 0;
  width: 13px;
  height: 13px;
  margin-left: -6.5px;
  border-radius: 50%;
  background: var(--lv-accent);
  transform: translateY(-50%) scale(0);
  transition: transform 0.12s ease;
  pointer-events: none;
}
.lv-scrub:hover .lv-thumb,
.lv-scrub:focus-visible .lv-thumb,
.lv-scrub.is-dragging .lv-thumb { transform: translateY(-50%) scale(1); }

/* Marqueurs de chapitres posés sur le rail. */
.lv-chapmark {
  position: absolute;
  top: 50%;
  width: 2px;
  height: 10px;
  margin-top: -5px;
  background: rgba(255, 255, 255, 0.85);
  pointer-events: none;
  border-radius: 1px;
}

/* --- Aperçu au survol de la barre --------------------------- */
.lv-preview {
  position: absolute;
  bottom: 26px;
  transform: translateX(-50%);
  background: var(--lv-menu-bg);
  border-radius: 6px;
  padding: 4px;
  display: none;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 6;
}
.lv-scrub:hover .lv-preview,
.lv-scrub.is-dragging .lv-preview { display: block; }
.lv-preview canvas {
  display: block;
  width: 160px;
  height: 90px;
  background: #111;
  border-radius: 4px;
}
.lv-preview-chapter {
  font-size: 11px;
  text-align: center;
  padding: 3px 4px 0;
  max-width: 160px;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lv-preview-time {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  padding: 2px 4px 1px;
}

/* --- Volume ------------------------------------------------- */
.lv-volume { display: flex; align-items: center; }
.lv-volume input[type="range"] {
  appearance: none;
  width: 0;
  opacity: 0;
  height: 4px;
  margin: 0;
  background: var(--lv-rail);
  border-radius: 3px;
  transition: width 0.18s ease, opacity 0.18s ease, margin 0.18s ease;
  cursor: pointer;
}
.lv-volume:hover input[type="range"],
.lv-volume:focus-within input[type="range"] {
  width: 72px;
  opacity: 1;
  margin: 0 8px 0 2px;
}
.lv-volume input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--lv-accent);
  cursor: pointer;
}
.lv-volume input[type="range"]::-moz-range-thumb {
  width: 12px; height: 12px; border: 0;
  border-radius: 50%;
  background: var(--lv-accent);
  cursor: pointer;
}
.lv-volume input[type="range"]:focus-visible {
  outline: 2px solid var(--lv-accent);
  outline-offset: 3px;
}

/* --- Menus (vitesse / qualité / sous-titres) ---------------- */
.lv-popup { position: relative; flex: 0 0 auto; }
.lv-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  min-width: 158px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--lv-menu-bg);
  border-radius: 8px;
  padding: 5px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  display: none;
  z-index: 7;
}
.lv-menu[data-open="true"] { display: block; }
.lv-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--lv-control-fg);
  font: 500 13px/1 var(--lv-font);
  padding: 9px 10px;
  border-radius: 5px;
  cursor: pointer;
}
.lv-menu button:hover { background: rgba(255, 255, 255, 0.12); }
.lv-menu button[aria-checked="true"] { color: var(--lv-accent); }
.lv-menu button::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
  flex: 0 0 auto;
}
.lv-menu button[aria-checked="true"]::before { opacity: 1; }
.lv-menu-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.55;
  padding: 6px 10px 5px;
}

/* --- Titre du chapitre courant ------------------------------ */
.lv-chaplabel {
  font-size: 12px;
  opacity: 0.8;
  padding: 0 8px;
  max-width: 28ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lv-chaplabel:empty { display: none; }

/* --- Écran de fin ------------------------------------------- */
.lv-endscreen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.82);
  z-index: 8;
}
.lv-player.is-ended .lv-endscreen { display: flex; }
.lv-endscreen h3 {
  margin: 0;
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 650;
}
.lv-endscreen p { margin: 0; opacity: 0.8; font-size: 14px; max-width: 46ch; }
.lv-end-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.lv-cta {
  background: var(--lv-accent);
  color: var(--lv-accent-contrast);
  border: 0;
  border-radius: 7px;
  padding: 11px 22px;
  font: 650 14px/1 var(--lv-font);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.lv-cta.is-ghost {
  background: transparent;
  color: var(--lv-control-fg);
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, 0.4);
}
.lv-cta:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

/* --- Utilitaires -------------------------------------------- */
.lv-sr {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.lv-player.is-idle { cursor: none; }
[hidden] { display: none !important; }

/* Petits écrans : on allège la barre. */
@media (max-width: 560px) {
  .lv-chaplabel { display: none; }
  .lv-btn { width: 34px; height: 34px; }
  .lv-time { font-size: 11px; padding: 0 4px; }
}

/* --- Mode audio -------------------------------------------- */
/* Pas d'image à afficher : on remplace le cadre 16/9 par une bande
   compacte, et on garde les contrôles visibles en permanence. */
.lv-player.lv-audio .lv-stage {
  aspect-ratio: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 96px;
}
/* L'élément <video> reste dans le flux (certains navigateurs suspendent
   un média en display:none) mais devient invisible. */
.lv-player.lv-audio .lv-video {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.lv-player.lv-audio .lv-clickzone,
.lv-player.lv-audio .lv-center,
.lv-player.lv-audio .lv-preview {
  display: none;
}
.lv-player.lv-audio .lv-controls {
  position: static;
  opacity: 1;
  transform: none;
  background: none;
  padding-top: 0;
}
.lv-player.lv-audio.is-idle .lv-controls {
  opacity: 1;
  transform: none;
}
.lv-player.lv-audio.is-idle { cursor: auto; }

.lv-cover {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 4px;
  min-width: 0;
}
.lv-cover-img {
  width: 56px;
  height: 56px;
  flex: none;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
}
.lv-cover-title {
  font: 600 15px/1.3 var(--lv-font, system-ui, sans-serif);
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
