/* ------------------------------------------------------------------ *
 * Reset
 *
 * Remplace le reset Eric Meyer qui occupait les 90 premieres lignes du
 * fichier et remettait a zero des elements que la page n'utilise pas.
 * ------------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

img,
svg,
iframe {
  display: block;
  max-width: 100%;
}

button,
input {
  font: inherit;
  color: inherit;
}

ul {
  list-style: none;
  padding: 0;
}

a {
  color: inherit;
}

/* ------------------------------------------------------------------ *
 * Jetons
 * ------------------------------------------------------------------ */

:root {
  --bg: #1d1e20;
  --surface: #27282b;
  --surface-sunken: #202123;
  --text: #e1dbf1;
  --text-muted: #9a95ad;
  /* Rouge vif pour le grand texte (titre, bouton), rouge profond derriere
     du petit texte blanc : a 12,8px le blanc sur #e94949 ne plafonne qu'a
     3,81, sous le seuil de 4,5. */
  --brand: #e94949;
  --brand-dark: #b63939;
  --brand-link: #f06464;
  --danger: #c30e0e;
  --safe: #357a38;
  /* Reserve au mode cache et au marqueur adulte : ni le vert du SFW, ni le
     rouge de la marque, pour qu'on voie tout de suite que c'est autre chose. */
  --secret: #8b2fb8;
  --line: rgb(225 219 241 / 0.12);

  /* Surchargee par la couleur dominante de la jaquette, fiche par fiche. */
  --accent: var(--brand);

  --font-display: "Bangers", system-ui, sans-serif;
  --font-body: "Work Sans", system-ui, sans-serif;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 20px rgb(0 0 0 / 0.35);
  --page-max: 820px;
}

::selection {
  background: var(--brand);
  color: var(--text);
}

/* ------------------------------------------------------------------ *
 * Page
 * ------------------------------------------------------------------ */

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  /* Degage le commutateur SFW, qui est fixe en bas a droite. */
  padding-bottom: 4.5rem;
  -webkit-text-size-adjust: 100%;
}

#container {
  width: 100%;
  max-width: var(--page-max);
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

h1,
h2 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.1;
  color: var(--brand);
}

/* 4rem en dur debordait sur mobile : la taille suit maintenant la largeur. */
h1 {
  font-size: clamp(2.25rem, 11vw, 4rem);
  padding: 1.2em 0 0.5em;
  cursor: help;
  text-wrap: balance;
}

#container > p {
  max-width: 58ch;
  color: var(--text-muted);
  text-wrap: pretty;
}

/* ------------------------------------------------------------------ *
 * Bouton
 * ------------------------------------------------------------------ */

.anime-btn {
  font-family: var(--font-display);
  /* Jamais sous 24px : en dessous, Bangers etant en graisse 400, le
     libelle ne compte plus comme grand texte et le blanc sur rouge passe
     sous le seuil. */
  font-size: clamp(1.5rem, 5vw, 1.6rem);
  letter-spacing: 0.02em;
  color: #fff;
  background-color: var(--brand);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.45em 1.4em;
  margin: 2rem 0;
  cursor: pointer;
  box-shadow: var(--shadow);
  /* La page 404 reutilise ce style sur un <a>, qui est inline par defaut :
     sans display explicite, les marges verticales et le collage seraient
     sans effet. */
  display: inline-block;
  text-decoration: none;
  transition:
    background-color 0.2s ease,
    transform 0.2s ease;
  animation: levitate 1.5s infinite alternate ease-in-out;
}

/* Seul le bouton de tirage reste visible au defilement : sur la page 404 il
   n'y a rien a suivre. */
#get-anime-btn {
  position: sticky;
  top: 1rem;
  z-index: 10;
}

@keyframes levitate {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-5px);
  }
}

/* Sans "animation: none", levitate garderait la main sur transform (une
   animation active l'emporte sur une declaration normale) et ce deplacement
   au survol n'aurait aucun effet visible. */
.anime-btn:hover:not(:disabled) {
  background-color: var(--brand-dark);
  animation: none;
  transform: translateY(-5px);
}

.anime-btn:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

.anime-btn:disabled {
  cursor: progress;
  animation: none;
  opacity: 0.75;
}

/* ------------------------------------------------------------------ *
 * Commutateur SFW
 * ------------------------------------------------------------------ */

/* Le commutateur flotte en permanence au-dessus du contenu. Ce halo sombre
   et floute le detache du texte qui defile dessous : sans lui, la pastille
   se lisait comme une collision plutot que comme un controle pose dessus. */
#switch-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 20;
  padding: 0.3rem;
  border-radius: 999px;
  background-color: rgb(29 30 32 / 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background-color 0.2s ease;
}

#switch-container:hover,
#switch-container:focus-within {
  background-color: rgb(29 30 32 / 0.85);
}

/* Le libelle vit dans un <label> et non dans un ::before sur l'<input> : les
   pseudo-elements ne sont pas rendus sur les elements remplaces, donc Firefox
   affichait une pastille vide. */
#sfw-switch {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#sfw-label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  width: 78px;
  height: 30px;
  /* La marge large accueille le pouce ; elle change de cote selon l'etat. */
  padding: 0 9px 0 32px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  background-color: var(--brand-dark);
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.25s ease;
}

#sfw-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background-color: #fff;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.4);
  transition: left 0.25s ease;
}

#sfw-switch:checked + #sfw-label {
  justify-content: flex-start;
  padding: 0 32px 0 9px;
  background-color: var(--safe);
}

#sfw-switch:checked + #sfw-label #sfw-thumb {
  left: calc(100% - 26px);
}

#sfw-switch:focus-visible + #sfw-label {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

/* Mode cache : la couleur l'emporte sur les deux etats normaux, et une
   pulsation unique signale le deverrouillage — sans quoi rien ne dirait
   qu'il vient de se passer quelque chose. */
/* Meme specificite que la regle :checked plus haut, mais declaree apres :
   elle l'emporte donc quel que soit l'etat de la case. */
#switch-container.is-secret #sfw-label {
  background-color: var(--secret);
}

#switch-container.is-secret {
  animation: secret-pop 0.45s ease-out;
}

@keyframes secret-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}

/* ------------------------------------------------------------------ *
 * Zone de tirage
 * ------------------------------------------------------------------ */

/* ------------------------------------------------------------------ *
 * Bande des tirages
 * ------------------------------------------------------------------ */

#history {
  display: flex;
  gap: 0.4rem;
  max-width: 100%;
  padding: 0.25rem 0.25rem 0.5rem;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

/* L'attribut hidden pose display: none, mais la regle ci-dessus l'emporte :
   il faut donc le reaffirmer, sinon la bande resterait visible et vide. */
#history[hidden] {
  display: none;
}

.history-item {
  flex: 0 0 auto;
  width: 44px;
  height: 66px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background-color: var(--surface-sunken);
  overflow: hidden;
  cursor: pointer;
  /* Les vignettes passees s'effacent pour que la fiche affichee reste le
     point de mire. */
  opacity: 0.5;
  transition:
    opacity 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease;
}

.history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-item:hover {
  opacity: 1;
  transform: translateY(-2px);
}

.history-item:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.history-item[aria-pressed="true"] {
  opacity: 1;
  border-color: var(--brand);
  cursor: default;
}

.history-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--text-muted);
}

/* ------------------------------------------------------------------ *
 * Zone de tirage
 * ------------------------------------------------------------------ */

#anime-container {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
  padding-bottom: 2.5rem;
}

/* La fiche precedente reste en place, estompee, pendant le chargement : la
   page ne retrecit plus et le scroll n'a plus besoin d'etre verrouille. */
#anime-container.is-loading > .card {
  opacity: 0.3;
  filter: saturate(0.3);
  pointer-events: none;
}

#anime-container.is-loading {
  min-height: 7rem;
}

#anime-container.is-loading::after {
  content: "";
  position: absolute;
  top: 2.5rem;
  left: 50%;
  width: 44px;
  height: 44px;
  margin-left: -22px;
  border: 3px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error {
  background: var(--danger);
  color: #fff;
  padding: 0.9em 1.2em;
  border-radius: var(--radius-sm);
  max-width: 44ch;
}

/* ------------------------------------------------------------------ *
 * Fiche
 * ------------------------------------------------------------------ */

.card {
  position: relative;
  /* Ouvre un contexte d'empilement, pour que les fonds en z-index negatif
     restent sous le contenu de la fiche sans passer derriere la page. */
  isolation: isolate;
  width: 100%;
  max-width: 560px;
  background-color: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: left;
  animation: card-in 0.25s ease-out;
}

/* La jaquette elle-meme, floutee, sert de fond a sa propre fiche : chaque
   tirage a son ambiance au lieu du meme gris pour tous. L'agrandissement
   evite que le flou laisse apparaitre les bords de l'image. */
.card.has-backdrop::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  background-image: var(--cover);
  background-size: cover;
  background-position: center;
  filter: blur(48px) saturate(1.5);
  transform: scale(1.4);
}

/* Voile sombre par-dessus : sans lui, une jaquette claire rendrait le texte
   illisible. */
.card.has-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(
    160deg,
    rgb(29 30 32 / 0.62),
    rgb(29 30 32 / 0.9) 70%
  );
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

.cover {
  position: relative;
  background-color: var(--surface-sunken);
}

/* Marqueur adulte, visible seulement quand le filtre est coupe. */
.adult-tag {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  padding: 0.15em 0.5em;
  border-radius: var(--radius-sm);
  background-color: var(--secret);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.5);
}

.cover img {
  width: 100%;
  height: auto;
  /* Une jaquette 2:3 pleine largeur donnerait une fiche de 800px de haut.
     On la recadre assez court pour que le titre et la ligne de meta restent
     atteignables sans avoir a faire defiler toute l'affiche. */
  max-height: 16rem;
  object-fit: cover;
  object-position: center 20%;
}

.cover-missing {
  display: grid;
  place-items: center;
  height: 10rem;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.9rem;
}

.card-header {
  padding: 1.1rem 1.25rem 0;
}

.card-header h2 {
  font-size: clamp(1.5rem, 5.5vw, 2rem);
}

.card-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 0.15rem;
}

/* Les faits courts sur une seule ligne, separes par des points medians. */
.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.4rem;
  margin-top: 0.55rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.meta-dot {
  opacity: 0.45;
}

.card-body {
  padding: 1rem 1.25rem 1.35rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

/* Genres */

.genres {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* Pastilles discretes : en rouge plein, elles pesaient autant que la note
   alors qu'elles ne sont qu'une information secondaire. Le rouge reste au
   titre, au bouton et a la note. */
.badge {
  background-color: rgb(225 219 241 / 0.07);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25em 0.7em;
  border-radius: 999px;
}

/* Synopsis */

.synopsis-text {
  font-size: 0.95rem;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 6;
  overflow: hidden;
}

.synopsis.is-expanded .synopsis-text {
  -webkit-line-clamp: unset;
}

.synopsis-toggle {
  background: none;
  border: none;
  padding: 0;
  margin-top: 0.4rem;
  color: var(--brand-link);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.synopsis-toggle:hover {
  text-decoration: underline;
}

/* Statistiques
   Une grille libelle / valeur remplace les dix lignes "Label : valeur"
   empilees, dont la moitie annonçait "Unknown". */

/* Note et audience */

.score-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.score {
  display: inline-flex;
  align-items: baseline;
  gap: 0.12rem;
  padding: 0.15em 0.6em;
  border-radius: var(--radius-sm);
  background-color: var(--brand-dark);
  color: #fff;
  font-family: var(--font-display);
  letter-spacing: 0.03em;
}

.score strong {
  font-size: 1.2rem;
  font-weight: 400;
}

.score-max {
  font-size: 0.75rem;
  opacity: 0.75;
}

.members {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Credits */

.credits {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.8rem;
  font-size: 0.82rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
}

.credits dt {
  color: var(--text-muted);
  white-space: nowrap;
}

.credits dd {
  margin: 0;
}

/* Bande-annonce */

.trailer-section {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
}

/* Discret : c'est une issue de secours quand le lecteur refuse de lire, pas
   une action concurrente du lien vers la fiche. */
.trailer-link {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-decoration: none;
}

.trailer-link:hover,
.trailer-link:focus-visible {
  color: var(--text);
  text-decoration: underline;
}

.trailer {
  position: relative;
  /* L'iframe etant en position absolue, la boite n'a aucun contenu qui la
     dimensionne : sans cette largeur, le parent en align-items: flex-start
     la reduirait a rien. */
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background-color: var(--surface-sunken);
}

.trailer iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Lien source */

.source-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  align-self: flex-start;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--brand-link);
  text-decoration: none;
}

.source-link:hover {
  text-decoration: underline;
}

.external-icon {
  width: 15px;
  height: 15px;
}

/* ------------------------------------------------------------------ *
 * Pied de page
 * ------------------------------------------------------------------ */

footer {
  width: 100%;
  margin-top: auto;
  padding: 1rem 0;
  border-top: 1px solid var(--line);
  color: var(--text-muted);
  font-size: 0.85rem;
}

footer a {
  color: var(--text);
}

/* ------------------------------------------------------------------ *
 * Large : la jaquette passe a cote du contenu
 * ------------------------------------------------------------------ */

@media (min-width: 42rem) {
  .card {
    max-width: none;
    display: grid;
    grid-template-columns: 220px 1fr;
    grid-template-areas:
      "cover header"
      "cover body";
    align-items: start;
  }

  /* La jaquette occupe toute la hauteur de la colonne. Laissee a sa taille
     naturelle, elle flottait au-dessus d'un grand vide qui donnait a la
     fiche un air cassé. */
  .cover {
    grid-area: cover;
    align-self: stretch;
  }

  .cover img {
    height: 100%;
    max-height: none;
    object-position: center;
  }

  .card-header {
    grid-area: header;
    padding-top: 1.35rem;
  }

  .card-body {
    grid-area: body;
  }
}

/* ------------------------------------------------------------------ *
 * Mouvement reduit
 * ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .anime-btn {
    animation: none;
  }
}
