/* =============================================================
   music.css — Styles exclusifs au Mode Music
   Contient : lecteur audio custom P5, boîte de victoire,
              dark mode, responsive.

   Thèmes de couleur par série (variables CSS — modifiées par JS) :
   P1→violet · P2IS→orange · P2EP→lavande · P3→bleu
   P4→jaune-or · P5→rouge (défaut) · PQ→orange
   ============================================================= */

/* ─── 1. AUDIO NATIF — caché, contrôlé via JS ─────────────── */

audio {
  display: none;
}

/* ─── 2. WRAPPER AUDIO ─────────────────────────────────────── */

/*
 * CSS custom properties — valeurs par défaut : thème Persona 5 (rouge).
 * Remplacées par JS via setPlayerTheme() selon le jeu d'origine de la musique.
 */
.audio-wrapper {
  /* Sans border-box, le padding s'ajoute à max-width et le lecteur déborde de
     l'écran sur mobile (380px de large pour un viewport de 375px). */
  box-sizing: border-box;

  --player-accent: #e63946;
  --player-accent-dark: #c1121f;
  --player-accent-light: #ff8fa3;
  --player-glow: rgba(230, 57, 70, 0.35);
  --player-glow-strong: rgba(230, 57, 70, 0.55);
  --player-glow-subtle: rgba(230, 57, 70, 0.04);
  --player-btn-glow: rgba(230, 57, 70, 0.7);
  --player-btn-glow-strong: rgba(230, 57, 70, 0.9);
  --player-btn-glow-max: rgba(230, 57, 70, 1);

  background: linear-gradient(150deg, #1a0505 0%, #0d0d0d 60%, #150a0a 100%);
  border: 2px solid var(--player-accent);
  border-radius: 6px 22px 6px 22px; /* asymétrique — style P5 */
  padding: 24px 28px 20px;
  /* Largeur fixée plutôt que fit-content : le lecteur ne rétrécit plus selon la
     longueur du titre affiché, et il s'aligne sur le panneau de paroles Expert
     (même expression), pour que basculer d'un mode à l'autre ne fasse pas sauter
     la mise en page. */
  width: min(560px, 92vw);
  margin: 30px auto;
  position: relative;
  overflow: hidden;

  box-shadow:
    0 0 24px var(--player-glow),
    0 6px 40px rgba(0, 0, 0, 0.85),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);

  transition:
    box-shadow 0.3s ease,
    border-color 0.3s ease;
}

/* ── P3P : bordure tournante mi-bleu (Makoto) / mi-rose (Kotone) ──────────────
   Activée via .p3p-duality (posée par setPlayerTheme quand la chanson est P3P).
   L'angle du conic-gradient est animé via @property : la bordure arrondie reste
   fixe, seul le dégradé tourne (contrairement à un transform:rotate qui ferait
   tourner tout le rectangle). #audioBox a overflow:hidden → anneau interne. */
@property --p3p-angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}
#audioBox.p3p-duality {
  border-color: transparent;
}
#audioBox.p3p-duality::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 2px; /* épaisseur de l'anneau */
  background: conic-gradient(
    from var(--p3p-angle),
    #3b82f6,
    #93c5fd 20%,
    #3b82f6 40%,
    #ec4899 60%,
    #f9a8d4 80%,
    #ec4899
  );
  /* Ne garde que l'anneau : masque plein moins la zone de contenu */
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  z-index: 3;
  animation: p3pSpin 4s linear infinite;
}
@keyframes p3pSpin {
  to {
    --p3p-angle: 360deg;
  }
}
@media (prefers-reduced-motion: reduce) {
  #audioBox.p3p-duality::after {
    animation: none;
  }
}

/* Grille diagonale décorative P5 en fond */
.audio-wrapper::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    -50deg,
    transparent,
    transparent 12px,
    var(--player-glow-subtle) 12px,
    var(--player-glow-subtle) 13px
  );
  border-radius: inherit;
}

.audio-wrapper:hover {
  border-color: var(--player-accent-light);
  box-shadow:
    0 0 36px var(--player-glow-strong),
    0 6px 50px rgba(0, 0, 0, 0.9),
    inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* ─── 3. LECTEUR CUSTOM P5 ─────────────────────────────────── */

.p5-player {
  position: relative;
  z-index: 1;
}

/* ── Coin coupé (signature P5) ── */
.p5-player::before {
  content: "";
  position: absolute;
  top: -20px;
  left: -24px;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 32px 32px 0 0;
  border-color: var(--player-accent) transparent transparent transparent;
  pointer-events: none;
}

/* ── En-tête : label + barres sonores ── */
.p5-player-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.p5-player-label {
  font-family: "Oswald", "Arial Narrow", Arial, sans-serif;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--player-accent);
  user-select: none;
}

/* ── Barres sonores animées ── */
.p5-sound-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 26px;
}

.p5-sound-bars span {
  display: block;
  width: 4px;
  min-height: 4px;
  background: var(--player-accent);
  border-radius: 2px 2px 0 0;
  transition: height 0.15s ease;
}

/* Quand lecture en cours → animation par décalage */
.p5-sound-bars.playing span:nth-child(1) {
  animation: p5bar 0.75s ease-in-out infinite;
}
.p5-sound-bars.playing span:nth-child(2) {
  animation: p5bar 0.55s ease-in-out 0.12s infinite;
}
.p5-sound-bars.playing span:nth-child(3) {
  animation: p5bar 0.9s ease-in-out 0.06s infinite;
}
.p5-sound-bars.playing span:nth-child(4) {
  animation: p5bar 0.65s ease-in-out 0.2s infinite;
}
.p5-sound-bars.playing span:nth-child(5) {
  animation: p5bar 1s ease-in-out 0.04s infinite;
}

@keyframes p5bar {
  0%,
  100% {
    height: 4px;
    opacity: 0.6;
  }
  50% {
    height: 20px;
    opacity: 1;
  }
}

/* ── Zone contrôles : bouton + timeline ── */
.p5-player-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* ── Bouton Play / Pause ── */
.p5-play-btn {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--player-accent);
  border: 2px solid rgba(255, 255, 255, 0.85);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;

  box-shadow:
    0 0 14px var(--player-btn-glow),
    0 2px 8px rgba(0, 0, 0, 0.6);

  transition:
    background 0.2s,
    transform 0.12s,
    box-shadow 0.2s;
  user-select: none;
}

/* Centrage optique du ▶ : le glyphe est asymétrique, flex le centre sur sa
   boîte et pas sur ce qu'on voit (retour Hamza du 2026-09-16). */
#p5PlayIcon {
  text-indent: 3px;
}
#p5PlayIcon.is-pause {
  text-indent: 0;
}

.p5-play-btn:hover {
  background: var(--player-accent-dark);
  transform: scale(1.1);
  box-shadow:
    0 0 24px var(--player-btn-glow-strong),
    0 2px 12px rgba(0, 0, 0, 0.7);
}

.p5-play-btn:active {
  transform: scale(0.94);
}

/* Légère animation de pulsation quand en pause */
.p5-play-btn.idle {
  animation: p5pulse 2.5s ease-in-out infinite;
}

@keyframes p5pulse {
  0%,
  100% {
    box-shadow:
      0 0 14px var(--player-btn-glow),
      0 2px 8px rgba(0, 0, 0, 0.6);
  }
  50% {
    box-shadow:
      0 0 28px var(--player-btn-glow-max),
      0 2px 14px rgba(0, 0, 0, 0.7);
  }
}

/* ── Timeline ── */
.p5-timeline {
  flex: 1;
}

/* Barre de progression — piste cliquable */
.p5-progress {
  height: 8px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  cursor: pointer;
  position: relative;
  overflow: visible;
}

.p5-progress:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Remplissage coloré — dégradé standard ou custom (ex: P3P bleu→rose) */
.p5-progress-fill {
  height: 100%;
  width: 0%;
  background: var(
    --player-fill-gradient,
    linear-gradient(
      90deg,
      var(--player-accent-dark),
      var(--player-accent) 70%,
      var(--player-accent-light)
    )
  );
  border-radius: 3px;
  position: relative;
  transition: width 0.15s linear;
}

/* Curseur blanc au bout de la barre */
.p5-progress-fill::after {
  content: "";
  position: absolute;
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 0 8px var(--player-btn-glow-strong);
  opacity: 0;
  transition: opacity 0.2s;
}

.p5-progress:hover .p5-progress-fill::after {
  opacity: 1;
}

/* ── Volume ───────────────────────────────────────────────────────────────────
   Réutilise .p5-progress / .p5-progress-fill : le dégradé vient des mêmes
   variables --player-* que la timeline, donc setPlayerTheme() colore le volume
   en même temps que le reste, sans une seule règle de thème supplémentaire. */
.p5-volume {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  width: clamp(70px, 18%, 120px);
}

.p5-mute-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.2s, transform 0.15s;
}

.p5-mute-btn:hover {
  opacity: 1;
  transform: scale(1.15);
}

.p5-volume-track {
  flex: 1;
  height: 5px; /* volontairement plus fine que la timeline — contrôle secondaire */
}

/* Curseur visible en permanence : sans lui, un volume à 0 n'a aucune poignée
   à attraper — la piste paraîtrait morte plutôt que réglable. */
.p5-volume-track .p5-progress-fill::after {
  opacity: 0.6;
  width: 10px;
  height: 10px;
}

.p5-volume-track:hover .p5-progress-fill::after {
  opacity: 1;
}

/* Sous 480px la ligne play + timeline + volume devient trop serrée : le volume
   passe sous la timeline, pleine largeur. */
@media (max-width: 480px) {
  .p5-player-controls {
    flex-wrap: wrap;
  }

  .p5-volume {
    width: 100%;
    margin-top: 8px;
  }
}

/* Temps courant / durée */
.p5-time-row {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  font-size: 0.68rem;
  font-family: "Courier New", monospace;
  color: rgba(255, 255, 255, 0.45);
  user-select: none;
}

/* ─── 4. VICTOIRE — MUSIC MODE ──────────────────────────────── */

body.music-mode .victory-box {
  max-width: 750px;
  padding: 30px 35px;
  border: 4px solid #f5067d;
  box-shadow: 0 0 28px #f73093b9;
}

body.music-mode .victory-box img {
  width: 300px;
  height: auto;
  max-height: none;
  border-radius: 16px;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

/* ─── 5. DARK MODE ──────────────────────────────────────────── */

/*
 * En dark mode, les couleurs du lecteur suivent le thème de série (CSS variables).
 * Seul le fond est légèrement plus sombre pour renforcer le contraste.
 */
body.darkmode .audio-wrapper {
  background: linear-gradient(150deg, #0c0c0c 0%, #080808 60%, #0c0c0c 100%);
}

body.music-mode.darkmode .victory-box {
  background-color: #2c1f2f;
  border-color: #ff66cc;
  box-shadow: 0 0 30px rgba(255, 102, 204, 0.6);
}

/* ─── 6. RESPONSIVE ─────────────────────────────────────────── */

@media (max-width: 768px) {
  .audio-wrapper {
    /* Le plafond à 400px datait du lecteur étroit : sur une tablette il laissait
       la moitié de la largeur inutilisée. Le lecteur suit désormais la même
       expression que sur desktop, borné par la fenêtre. */
    width: min(520px, 92vw);
    padding: 18px 20px 15px;
    margin: 20px auto;
    min-width: unset;
  }

  .p5-play-btn {
    width: 42px;
    height: 42px;
    font-size: 1rem;
  }

  body.music-mode .victory-box {
    max-width: 95%;
    padding: 20px 15px;
  }
  body.music-mode .victory-box img {
    width: 200px;
  }
}

@media (max-width: 480px) {
  .audio-wrapper {
    width: 94%;
    padding: 14px 14px 12px;
    border-radius: 4px 16px 4px 16px;
  }

  .p5-player-label {
    font-size: 0.6rem;
  }
  .p5-play-btn {
    width: 38px;
    height: 38px;
    font-size: 0.9rem;
  }
  .p5-time-row {
    font-size: 0.62rem;
  }

  body.music-mode .victory-box img {
    width: 160px;
  }
  body.music-mode .victory-box {
    padding: 15px 10px;
  }

  /* Réduit le gap de la rangée Replay|Input|Submit sur mobile */
  .input-wrapper > div {
    gap: 8px;
    width: min(340px, 95vw);
    box-sizing: border-box;
  }
}

/* ═════════════════════════════════════════════════════════════════════════════
   MODE EXPERT
   Habillage plus dur que le mode normal : rouge sang, angles cassés, gros
   contraste. Le mode normal garde son thème par opus — ici la couleur est
   volontairement constante, c'est la signature du mode.
   ═════════════════════════════════════════════════════════════════════════════ */


.expert-lyrics-wrapper {
  box-sizing: border-box; /* cf. .audio-wrapper : sinon le padding déborde du viewport */
  width: min(560px, 92vw);
  margin: 18px auto;
  padding: 14px 16px 10px;
  background: rgba(12, 12, 14, 0.92);
  border: 2px solid #e63946;
  border-radius: 4px;
  box-shadow: 0 0 24px rgba(230, 57, 70, 0.28);
}

.expert-lyrics-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  font-family: "Courier New", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #e63946;
}

.expert-lyrics-count {
  color: rgba(255, 255, 255, 0.45);
  letter-spacing: 0.08em;
}

/* Liste défilante : les vers précédents restent lisibles au-dessus, comme sur un
   lecteur de streaming. Hauteur bornée pour que le champ de réponse reste visible
   sans scroller la page entière. */
.expert-lyrics-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: min(46vh, 320px);
  overflow-y: auto;
  scroll-behavior: smooth;
}

.expert-lyric-line {
  padding: 7px 4px;
  font-size: 0.98rem;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.42);
  transition: color 0.25s;
}

/* Le vers qui vient d'apparaître — c'est lui qu'on lit, les autres sont du contexte. */
.expert-lyric-line.current {
  color: #fff;
  font-weight: 700;
  font-size: 1.1rem;
  text-shadow: 0 0 12px rgba(230, 57, 70, 0.55);
}

/* Machine à écrire — curseur clignotant pendant la frappe du vers courant.
   Le curseur est un ::after et non un caractère du texte : une frappe
   interrompue laisserait sinon un « | » collé au vers. */
.expert-lyric-line.typing::after {
  content: "▌";
  margin-left: 2px;
  color: #e63946;
  animation: lyricCaret 0.7s steps(1) infinite;
}

@keyframes lyricCaret {
  50% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .expert-lyric-line.typing::after {
    animation: none;
  }
}

/* Vers révélés seulement en fin de partie : jamais gagnés, donc en retrait. */
.expert-lyric-line.unheard {
  color: rgba(255, 255, 255, 0.28);
  font-style: italic;
}

.expert-lyrics-list::-webkit-scrollbar {
  width: 6px;
}

.expert-lyrics-list::-webkit-scrollbar-thumb {
  background: rgba(230, 57, 70, 0.55);
  border-radius: 3px;
}

@media (max-width: 480px) {
  .expert-lyrics-wrapper {
    padding: 12px 12px 8px;
  }

  .expert-lyric-line {
    font-size: 0.92rem;
  }

  .expert-lyric-line.current {
    font-size: 1rem;
  }
}
