/* Style Global */
html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: 'Georgia', serif;
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  /* Corrections pour iOS */
  -webkit-text-size-adjust: 100%;
  position: relative;
}

/* Fond flou */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url('images/background.jpg') no-repeat center center fixed;
  background-size: cover;
  filter: blur(12px) brightness(0.4);
  opacity: 0.6;
  z-index: -1;
}

/* Conteneur principal */
#welcomePage, #navigationContainer {
  position: relative;
  z-index: 1;
  width: 90%;
  max-width: 1200px;
}

/* Page d'accueil */
#welcomePage {
  text-align: center;
}

#welcomePage h1 {
  font-size: clamp(2rem, 4vw, 5rem);
  margin-bottom: 1rem;
}

#welcomePage p {
  font-size: clamp(1rem, 2vw, 2.5rem);
}

/* Bouton responsive */
#startButton {
  padding: 12px 24px;
  font-size: clamp(1rem, 1.2vw, 1.5rem);
  cursor: pointer;
  background-color: rgba(70, 70, 70, 0.7);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 5px;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  appearance: none;
  -webkit-appearance: none;
}

#startButton:hover {
  background-color: rgba(90, 90, 90, 0.9);
  transform: scale(1.05);
}

/* Conteneur de navigation */
#navigationContainer {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 1000px;
  gap: 20px;
  min-height: 100vh; /* Assure une hauteur minimale */
  box-sizing: border-box;
  padding: 20px 0;
}

/* Conteneur du livre */
#bookContainer {
  width: 100%;
  max-width: 800px;
  perspective: 1500px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Livre */
#book {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

/* Style des pages */
.page {
  position: relative;
  width: 100%;
  display: none;
  opacity: 0;
  transition: opacity 0.5s ease;
  backface-visibility: hidden;
}

.page.active {
  display: block;
  opacity: 1;
  z-index: 10;
  transform: rotateY(0deg);
}

.page-content {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  box-sizing: border-box;
  text-align: center;
}

/* Conteneur d'image avec défilement */
.image-container {
  width: 100%;
  max-width: 900px;
  max-height: 65vh;
  overflow: auto;
  margin: 10px 0;
  padding: 5px;
  box-sizing: border-box;
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 5px;
  -webkit-overflow-scrolling: touch;
  /* Corrections pour iOS */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  position: relative;
}

/* Uniformisation des images */
.image-container img {
  width: 100%;
  height: auto;
  max-height: 65vh;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  /* Corrections pour iOS */
  -webkit-transform: translate3d(0,0,0);
  transform: translate3d(0,0,0);
}

/* Boutons de navigation */
.navigationControls {
  display: flex;
  justify-content: space-between;
  width: 100%;
  max-width: 400px;
  margin: 15px 0;
  z-index: 100;
  position: relative;
  /* Assure que les boutons restent visibles */
  top: 0;
  left: 0;
}

#prevButton, #nextButton {
  font-size: clamp(0.8rem, 1vw, 1.2rem);
  padding: 10px 20px;
  cursor: pointer;
  background-color: rgba(70, 70, 70, 0.7);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 5px;
  transition: all 0.3s ease;
  z-index: 200;
  -webkit-tap-highlight-color: transparent;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
}

#prevButton:hover, #nextButton:hover {
  background-color: rgba(90, 90, 90, 0.9);
}

/* Conteneur de réponse */
#answerContainer {
  display: none;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 500px;
  z-index: 100;
  margin-top: 20px;
}

#answerInput {
  flex: 1;
  padding: 10px;
  font-size: 16px;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 5px;
  background-color: rgba(70, 70, 70, 0.7);
  color: white;
  appearance: none;
  -webkit-appearance: none;
}

#submitAnswer {
  padding: 10px 20px;
  font-size: 16px;
  cursor: pointer;
  background-color: rgba(70, 70, 70, 0.7);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-radius: 5px;
  white-space: nowrap;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  appearance: none;
  -webkit-appearance: none;
}

#submitAnswer:hover {
  background-color: rgba(90, 90, 90, 0.9);
}

/* Animation de tournement de page */
@keyframes pageFlipForward {
  0% {
    transform: rotateY(0deg);
    z-index: 10;
  }
  100% {
    transform: rotateY(-180deg);
    z-index: 0;
  }
}

@keyframes pageFlipBackward {
  0% {
    transform: rotateY(-180deg);
    z-index: 0;
  }
  100% {
    transform: rotateY(0deg);
    z-index: 10;
  }
}

/* Stylisation de la scrollbar */
.image-container::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.image-container::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

.image-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
}

.image-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

/* Ajustements pour tablettes */
@media (max-width: 768px) {
  #navigationContainer {
    padding: 15px 0;
    min-height: 100vh;
  }
  
  .image-container {
    max-height: 55vh;
  }
  
  .image-container img {
    max-height: 55vh;
  }
  
  .navigationControls {
    width: 100%;
    max-width: 500px;
    margin: 20px 0;
  }
  
  #prevButton, #nextButton {
    padding: 12px 24px;
    font-size: 16px;
    min-width: 110px;
  }
}

/* Ajustements pour mobiles */
@media (max-width: 600px) {
  #navigationContainer {
    flex-direction: column;
    gap: 15px;
    padding: 10px 0;
    min-height: 100vh;
  }
  
  .image-container {
    max-height: 45vh;
  }
  
  .image-container img {
    max-height: 45vh;
  }
  
  .navigationControls {
    width: 100%;
    justify-content: space-between;
    margin: 15px 0;
    order: 1; /* Place les boutons en premier */
  }
  
  #bookContainer {
    order: 2; /* Place le livre après les boutons */
  }
  
  #answerContainer {
    width: 95%;
    flex-direction: column;
    order: 3; /* Place la réponse en dernier */
  }
  
  #prevButton, #nextButton {
    padding: 15px 25px;
    font-size: 18px;
    min-width: 120px;
  }
  
  #answerInput, #submitAnswer {
    width: 100%;
    padding: 15px;
    font-size: 18px;
  }
}

/* Corrections spécifiques pour Safari iOS */
@supports (-webkit-touch-callout: none) {
  /* Détection spécifique de Safari iOS */
  html, body {
    height: -webkit-fill-available;
    position: relative;
  }
  
  #navigationContainer {
    height: -webkit-fill-available;
    min-height: -webkit-fill-available;
  }
  
  .image-container {
    -webkit-overflow-scrolling: touch;
    overflow: auto;
  }
  
  .image-container img {
    max-width: 100%;
    width: auto;
    height: auto;
  }
  
  /* Optimisations spécifiques par appareil iOS */
  @media (max-width: 896px) {
    /* iPhone et iPad en mode portrait/paysage */
    .image-container {
      max-height: 50vh;
      overflow: auto;
    }
    
    .image-container img {
      max-height: 48vh;
    }
    
    .navigationControls {
      position: sticky;
      top: 10px;
      z-index: 300;
      background-color: rgba(0, 0, 0, 0.3);
      padding: 10px;
      border-radius: 10px;
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);
    }
    
    /* Optimisations spécifiques par page */
    #page1 .image-container img {
      max-width: 85%;
      margin: 0 auto;
    }
    
    #page2 .image-container img {
      max-width: 95%;
      margin: 0 auto;
    }
    
    #page3 .image-container img {
      max-width: 70%;
      max-height: 45vh;
      margin: 0 auto;
    }
    
    #page4 .image-container img {
      max-width: 80%;
      max-height: 45vh;
      margin: 0 auto;
    }
  }
  
  /* Corrections pour très petits écrans iOS */
  @media (max-width: 414px) {
    .navigationControls {
      position: fixed;
      top: 20px;
      left: 50%;
      transform: translateX(-50%);
      width: 90%;
      z-index: 1000;
    }
    
    #bookContainer {
      margin-top: 80px; /* Espace pour les boutons fixes */
    }
    
    .image-container {
      max-height: 40vh;
    }
    
    .image-container img {
      max-height: 38vh;
    }
  }
}