/* L'album « Ma collection » : un classeur à anneaux, couverture de cuir, pages à pochettes que l'on tourne.
   (js/bibliotheque.js construit les pages ; les onglets de thèmes sont les intercalaires, au-dessus du classeur.) */

.fenetre-collection {
  --page-album: #f3ecd8;
  --page-album-bord: #d8cdb0;
  --page-album-encre: #7b705a;
  --cuir-clair: #7e3232;
  --cuir-fonce: #4b1a1e;
  --page-temps: 560ms;
  color: var(--sur-bureau);
  background: color-mix(in srgb, var(--bureau) 82%, #000);
  max-width: 520px;
}

:root[data-theme="sombre"] .fenetre-collection {
  --page-album: #27332f;
  --page-album-bord: #1a2321;
  --page-album-encre: #8fa39c;
}

.fenetre-collection .collection-choix {
  color: var(--sur-bureau);
}

.fenetre-collection .collection-vide,
.fenetre-collection .collection-test,
.fenetre-collection .collection-filtre-resultat {
  color: var(--sur-bureau);
}

/* Les intercalaires sont collés au classeur */
.fenetre-collection .collection-univers {
  margin-bottom: 0;
  padding-top: 4px;
}

.fenetre-collection .collection-univers .tous {
  color: #1b2a2b;
  background: var(--sur-bureau);
}

/* ---------- Le classeur ---------- */

.livre {
  position: relative;
  /* Sur un écran large mais peu haut, le classeur rétrécit pour tenir dans la fenêtre sans trop faire défiler (une page fait environ 0,74 fois sa hauteur en largeur) */
  max-width: max(300px, min(470px, calc((100vh - 310px) * 0.74)));
  margin: 0 auto 4px;
  padding-left: 12px;       /* la place des anneaux, qui dépassent à gauche */
}

.livre-scene {
  position: relative;
  display: grid;
  perspective: 1700px;
  touch-action: pan-y;      /* un glissement horizontal tourne la page, un glissement vertical fait défiler la fenêtre */
}

.livre-page {
  grid-area: 1 / 1;
  position: relative;
  min-width: 0;
}

.livre-page[hidden] {
  display: none;
}

/* La page invisible qui donne sa taille au classeur (la couverture a donc toujours la taille d'une page ouverte) */
.livre-gabarit {
  visibility: hidden;
  pointer-events: none;
}

/* La page du dessus, celle qui se tourne autour du dos du classeur */
.livre-page-haut {
  z-index: 2;
  transform-origin: left center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  will-change: transform;
}

.livre-page-haut::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 3px 10px 10px 3px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.05), rgba(0, 0, 0, 0.5));
  opacity: 0;
}

.livre-page-haut.avant {
  animation: page-avant var(--page-temps) cubic-bezier(0.5, 0.05, 0.35, 1) forwards;
}

.livre-page-haut.avant::after {
  animation: page-ombre var(--page-temps) ease-in forwards;
}

.livre-page-haut.arriere {
  animation: page-arriere var(--page-temps) cubic-bezier(0.5, 0.05, 0.35, 1) forwards;
}

.livre-page-haut.arriere::after {
  animation: page-ombre-retour var(--page-temps) ease-out forwards;
}

@keyframes page-avant {
  from { transform: rotateY(0deg); }
  to   { transform: rotateY(-100deg); }
}

@keyframes page-arriere {
  from { transform: rotateY(-100deg); }
  to   { transform: rotateY(0deg); }
}

@keyframes page-ombre {
  from { opacity: 0; }
  to   { opacity: 0.8; }
}

@keyframes page-ombre-retour {
  from { opacity: 0.8; }
  to   { opacity: 0; }
}

/* La page du dessous reçoit l'ombre de celle qui se tourne */
.livre-page-bas::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 3px 10px 10px 3px;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.32), transparent 70%);
  opacity: 0;
}

.livre-scene.tourne-avant .livre-page-bas::after {
  animation: ombre-dessous-avant var(--page-temps) ease-out forwards;
}

.livre-scene.tourne-arriere .livre-page-bas::after {
  animation: ombre-dessous-arriere var(--page-temps) ease-in forwards;
}

@keyframes ombre-dessous-avant {
  from { opacity: 1; }
  to   { opacity: 0; }
}

@keyframes ombre-dessous-arriere {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Les trois anneaux du classeur : ils restent en place pendant que la page se tourne */
.livre-anneaux {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -12px;
  z-index: 3;
  width: 40px;
  pointer-events: none;
}

.livre-anneaux i {
  position: absolute;
  left: 0;
  width: 38px;
  height: 14px;
  border-radius: 7px;
  background: linear-gradient(180deg, #fbfbfb 0%, #b9bec4 38%, #7c828a 60%, #e8eaed 100%);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(0, 0, 0, 0.22);
}

.livre-anneaux i::after {
  content: "";
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 5px;
  right: 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.28);
}

.livre-anneaux i:nth-child(1) { top: 13%; }
.livre-anneaux i:nth-child(2) { top: calc(50% - 7px); }
.livre-anneaux i:nth-child(3) { bottom: 13%; }

/* ---------- Une page de pochettes ---------- */

.livre-feuille {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  padding: 16px 12px 10px 30px;
  color: #1b2a2b;
  background: var(--page-album);
  border-radius: 3px 10px 10px 3px;
  box-shadow:
    1px 0 0 var(--page-album-bord),
    3px 2px 0 color-mix(in srgb, var(--page-album) 82%, #000),
    5px 4px 0 color-mix(in srgb, var(--page-album) 70%, #000),
    0 16px 26px -10px rgba(0, 0, 0, 0.7);
}

:root[data-theme="sombre"] .livre-feuille {
  color: #e9efea;
}

/* Les trous des anneaux */
.livre-feuille::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 28px;
  border-radius: 3px 0 0 3px;
  background:
    radial-gradient(circle at 14px 13%, rgba(0, 0, 0, 0.5) 0 4.5px, transparent 5.5px),
    radial-gradient(circle at 14px 50%, rgba(0, 0, 0, 0.5) 0 4.5px, transparent 5.5px),
    radial-gradient(circle at 14px 87%, rgba(0, 0, 0, 0.5) 0 4.5px, transparent 5.5px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.1), transparent);
}

.livre-grille {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: space-between;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Une pochette en plastique : on voit la carte à travers, avec un reflet et un bord plus clair en haut */
.pochette {
  position: relative;
  padding: 6px 3px 3px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.28);
  border: 1px solid rgba(70, 60, 35, 0.25);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.55), inset 0 -3px 5px -3px rgba(0, 0, 0, 0.18);
}

:root[data-theme="sombre"] .pochette {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.12), inset 0 -3px 5px -3px rgba(0, 0, 0, 0.4);
}

.pochette::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(115deg, rgba(255, 255, 255, 0.34) 0, rgba(255, 255, 255, 0) 26%, rgba(255, 255, 255, 0) 70%, rgba(255, 255, 255, 0.16) 100%);
}

.pochette .emplacement {
  color: var(--page-album-encre);
  border-color: color-mix(in srgb, var(--page-album-encre) 55%, transparent);
}

.pochette-libre {
  min-height: 0;
}

.pochette-libre .vide {
  display: block;
  width: 100%;
  aspect-ratio: 5 / 7;
}

.livre-numero {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-align: center;
  color: var(--page-album-encre);
}

/* ---------- La couverture ---------- */

.couverture {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  width: 100%;
  height: 100%;
  padding: 34px 26px 28px 44px;
  font-family: inherit;
  text-align: left;
  color: var(--or-1);
  cursor: pointer;
  border: 0;
  border-radius: 4px 12px 12px 4px;
  background:
    radial-gradient(circle at 24% 12%, rgba(255, 255, 255, 0.13), transparent 52%),
    repeating-linear-gradient(45deg, rgba(0, 0, 0, 0.06) 0 2px, transparent 2px 4px),
    linear-gradient(140deg, var(--cuir-clair), var(--cuir-fonce));
  box-shadow:
    inset 0 0 0 1px rgba(255, 215, 140, 0.16),
    inset 12px 0 14px -10px rgba(0, 0, 0, 0.55),
    0 16px 26px -10px rgba(0, 0, 0, 0.75);
}

/* La couture dorée autour de la couverture */
.couverture::before {
  content: "";
  position: absolute;
  inset: 14px 14px 14px 34px;
  border: 1.5px dashed rgba(247, 224, 138, 0.5);
  border-radius: 3px;
  pointer-events: none;
}

.couverture-titre {
  font-size: 2.3rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--or-1);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.65), 0 0 16px rgba(247, 224, 138, 0.22);
}

.couverture-compte {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 8px;
  color: rgba(247, 224, 138, 0.82);
}

.couverture-compte b {
  font-size: 3.6rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--or-3);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
}

.couverture-progres {
  display: block;
  height: 6px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 3px;
}

.couverture-progres i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--or-2), var(--or-3));
}

.couverture-ouvrir {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: rgba(247, 224, 138, 0.8);
  animation: couverture-appel 2.6s ease-in-out infinite;
}

@keyframes couverture-appel {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

/* ---------- Les boutons pour tourner les pages ---------- */

.livre-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 14px;
  color: var(--sur-bureau);
}

.livre-nav button {
  flex: none;
  width: 54px;
  height: 44px;
  font-size: 1.7rem;
  line-height: 1;
  color: var(--encre);
  cursor: pointer;
  background: var(--papier);
  border: 0;
  border-radius: 3px;
}

.livre-nav button:disabled {
  opacity: 0.3;
  cursor: default;
}

.livre-nav button:active:not(:disabled) {
  transform: translateY(1px);
}

.livre-position {
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

/* Les boutons du bas de la fenêtre se lisent sur la table */
.fenetre-collection #collection-fermer {
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--bureau) 82%, #000);
}

@media (min-width: 560px) {
  .livre-feuille { padding: 20px 16px 12px 36px; gap: 10px; }
  .livre-grille { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .couverture-ouvrir { animation: none; }
  .livre-page-haut.avant,
  .livre-page-haut.arriere { animation: none; }
}

/* ---------- La recherche dans l'album ---------- */

.collection-recherche {
  margin-bottom: 12px;
}

.collection-recherche input {
  width: 100%;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 1rem;           /* au moins 16 px : sinon l'iPhone zoome sur la page quand on touche le champ */
  font-weight: 400;
  color: var(--encre);
  background: var(--papier);
  border: 1.5px solid var(--trait);
  border-radius: 3px;
}

.collection-resultats {
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
  background: var(--papier);
  border-radius: 3px;
  overflow: hidden;
}

.collection-resultats[hidden] {
  display: none;
}

.collection-resultat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 12px 7px 10px;
  font-family: inherit;
  color: var(--encre);
  text-align: left;
  cursor: pointer;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--trait);
}

.collection-resultats li:last-child .collection-resultat {
  border-bottom: 0;
}

.collection-resultat:hover,
.collection-resultat:focus-visible {
  background: var(--papier-2);
}

.collection-resultat-vide {
  padding: 10px 12px;
  font-size: 0.85rem;
  color: var(--encre-douce);
}

/* La carte qu'on vient de chercher : un halo doré qui pulse, pour la repérer sur la page */
.pochette.trouvee {
  animation: carte-trouvee 2.4s ease-out 0.35s 1 both;
}

@keyframes carte-trouvee {
  0%   { box-shadow: 0 0 0 0 rgba(255, 217, 90, 0.95), 0 0 0 0 rgba(255, 217, 90, 0.7); }
  30%  { box-shadow: 0 0 0 5px rgba(255, 217, 90, 0.95), 0 0 22px 8px rgba(255, 217, 90, 0.7); }
  100% { box-shadow: 0 0 0 0 rgba(255, 217, 90, 0), 0 0 0 0 rgba(255, 217, 90, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .pochette.trouvee { animation: none; box-shadow: 0 0 0 3px rgba(255, 217, 90, 0.95); }
}

/* ---------- Un emplacement vide qu'on peut toucher (pour un indice) ---------- */

.emplacement-cliquable {
  padding: 0;
  font: inherit;
  cursor: pointer;
  background: transparent;
}

.emplacement-cliquable:hover,
.emplacement-cliquable:focus-visible,
.emplacement.choisi {
  border-color: #ffd95a;
  box-shadow: 0 0 0 2px rgba(255, 217, 90, 0.55);
}

.livre-indice {
  margin: 12px 0 0;
  padding: 10px 14px;
  font-size: 0.92rem;
  line-height: 1.4;
  color: #2a2410;
  background: var(--postit, #ffd95a);
  border-radius: 3px;
  box-shadow: var(--ombre-papier);
  transform: rotate(-0.6deg);
}

.livre-indice[hidden] {
  display: none;
}
