* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Comic Sans MS", "Chalkboard SE", "Segoe UI", sans-serif;
  background: linear-gradient(160deg, #ffe9f3 0%, #e3f2ff 50%, #fff9d9 100%);
  min-height: 100vh;
  min-height: 100dvh;
  color: #4a3b5c;
  overflow-x: hidden;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  min-height: 44px;
}

.ecran {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 48px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(48px, env(safe-area-inset-bottom));
  max-width: 680px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
}

.ecran.actif {
  display: flex;
}

.titre-app {
  font-size: clamp(2rem, 7vw, 3.2rem);
  text-align: center;
  margin-top: 10vh;
  color: #7b4fc9;
  text-shadow: 2px 2px 0 #ffffff;
}

.sous-titre {
  font-size: 1.4rem;
  margin: 12px 0 40px;
  color: #b0679a;
}

.titre-ecran {
  font-size: 1.8rem;
  margin: 16px 0 24px;
  color: #7b4fc9;
  text-align: center;
}

.menu-boutons {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
  max-width: 440px;
}

.gros-bouton {
  font-family: inherit;
  font-size: 1.35rem;
  padding: 22px 26px;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.1s, box-shadow 0.1s;
  color: #ffffff;
  text-align: center;
}

.gros-bouton:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}

.bouton-coffre {
  background: linear-gradient(135deg, #ff9f4a, #ff6f91);
}

.bouton-magique {
  background: linear-gradient(135deg, #7b4fc9, #4aa8ff);
}

.bouton-histoire {
  background: linear-gradient(135deg, #34c9a3, #2f9de0);
}

.bouton-retour {
  align-self: flex-start;
  font-family: inherit;
  font-size: 1.05rem;
  padding: 10px 18px;
  border: none;
  border-radius: 16px;
  background: #ffffffcc;
  color: #7b4fc9;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1);
}

/* Formulaire histoire magique */
.formulaire-magique {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.etiquette {
  font-size: 1.25rem;
  color: #4a3b5c;
}

.champ-prenom {
  font-family: inherit;
  font-size: 1.4rem;
  padding: 14px 18px;
  border: 3px solid #c8a6f2;
  border-radius: 18px;
  outline: none;
  text-align: center;
}

.champ-prenom:focus {
  border-color: #7b4fc9;
}

.grille-themes,
.grille-sexe {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.grille-ages {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.grille-hobbies {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.grille-hobbies .bouton-theme {
  font-size: 0.95rem;
  padding: 12px 6px;
}

.grille-ages .bouton-theme {
  font-size: 1.05rem;
  padding: 12px 6px;
}

.champ-hobby {
  font-size: 1.05rem;
}

.bouton-theme {
  font-family: inherit;
  font-size: 1.1rem;
  padding: 16px 10px;
  border: 3px solid transparent;
  border-radius: 18px;
  background: #ffffffd9;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.08);
  color: #4a3b5c;
}

.bouton-theme.choisi {
  border-color: #7b4fc9;
  background: #f0e6ff;
  transform: scale(1.03);
}

.grille-couleurs {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.bouton-couleur {
  width: 52px;
  height: 52px;
  min-height: 52px;
  border-radius: 50%;
  border: 4px solid #ffffff;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
  transition: transform 0.1s;
}

.bouton-couleur.choisi {
  transform: scale(1.18);
  border-color: #4a3b5c;
}

.grille-animaux {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.grille-animaux .bouton-theme {
  font-size: 0.95rem;
  padding: 12px 4px;
}

.bouton-surprise {
  background: linear-gradient(135deg, #ffd166, #ff8fab) !important;
  font-weight: bold;
}

.indicateur-micro {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  padding: 10px 18px;
  background: #ffffffd9;
  border-radius: 999px;
  font-size: 1.05rem;
  color: #7b4fc9;
  box-shadow: 0 4px 12px rgba(123, 79, 201, 0.15);
}

.micro-pulse {
  font-size: 1.4rem;
  animation: pulser 1.1s ease-in-out infinite;
}

@keyframes pulser {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: 0.7; }
}

.bouton-choix .badge-mot {
  display: block;
  font-size: 0.85rem;
  margin-top: 5px;
  opacity: 0.9;
  font-weight: normal;
}

.bouton-choix.choix-valide {
  background: linear-gradient(135deg, #34c9a3, #2f9de0);
  transform: scale(1.04);
}

.message-info {
  font-size: 1.05rem;
  color: #d0486b;
  text-align: center;
  min-height: 1.4em;
}

/* Chargement */
.chargement {
  margin-top: 30vh;
  text-align: center;
}

.baguette {
  font-size: 5rem;
  animation: flotter 1.2s ease-in-out infinite alternate;
}

@keyframes flotter {
  from { transform: translateY(0) rotate(-12deg); }
  to { transform: translateY(-22px) rotate(12deg); }
}

.texte-chargement {
  font-size: 1.4rem;
  margin-top: 18px;
  color: #7b4fc9;
}

/* Lecture d'histoire */
.titre-histoire {
  font-size: 1.6rem;
  margin: 14px 0 18px;
  color: #7b4fc9;
  text-align: center;
}

.carte-page {
  background: #ffffffe6;
  border-radius: 28px;
  padding: 26px 24px;
  width: 100%;
  box-shadow: 0 8px 24px rgba(123, 79, 201, 0.18);
  text-align: center;
}

.emoji-page {
  font-size: 4.5rem;
  margin-bottom: 14px;
  animation: apparaitre 0.5s ease;
}

@keyframes apparaitre {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.texte-page {
  font-size: 1.35rem;
  line-height: 1.65;
  margin-bottom: 20px;
}

.bouton-audio {
  font-family: inherit;
  font-size: 1.15rem;
  padding: 12px 26px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffc94a, #ff9f4a);
  color: #5c3a00;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.12);
}

.bouton-audio.en-lecture {
  background: linear-gradient(135deg, #ff8a8a, #ff5c7a);
  color: #ffffff;
}

.zone-choix {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  margin-top: 22px;
}

.bouton-choix {
  font-family: inherit;
  font-size: 1.2rem;
  padding: 18px 22px;
  border: none;
  border-radius: 20px;
  background: linear-gradient(135deg, #4aa8ff, #7b4fc9);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.12);
  transition: transform 0.1s;
}

.bouton-choix:active {
  transform: translateY(3px);
}

.bouton-fin {
  background: linear-gradient(135deg, #34c9a3, #2f9de0);
}

/* ---------- MOBILE (téléphones) ---------- */
@media (max-width: 520px) {
  .titre-app {
    margin-top: 5vh;
    font-size: 2.1rem;
  }

  .sous-titre {
    font-size: 1.2rem;
    margin: 10px 0 28px;
  }

  .titre-ecran {
    font-size: 1.45rem;
    margin: 10px 0 18px;
  }

  .gros-bouton {
    font-size: 1.15rem;
    padding: 18px 18px;
    border-radius: 20px;
  }

  .menu-boutons {
    max-width: 100%;
  }

  .formulaire-magique {
    max-width: 100%;
    gap: 12px;
  }

  .etiquette {
    font-size: 1.1rem;
  }

  .champ-prenom {
    font-size: 1.25rem;
    padding: 12px 14px;
  }

  /* Grilles resserrées mais tactiles */
  .grille-hobbies {
    grid-template-columns: repeat(2, 1fr);
  }

  .grille-hobbies .bouton-theme {
    font-size: 1rem;
    padding: 13px 8px;
  }

  .grille-ages {
    gap: 8px;
  }

  .grille-ages .bouton-theme {
    font-size: 1rem;
    padding: 12px 4px;
  }

  .grille-themes .bouton-theme,
  .grille-sexe .bouton-theme {
    font-size: 1.05rem;
    padding: 14px 8px;
  }

  .grille-animaux {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .grille-animaux .bouton-theme {
    font-size: 0.85rem;
    padding: 10px 2px;
  }

  .bouton-couleur {
    width: 46px;
    height: 46px;
    min-height: 46px;
  }

  .indicateur-micro {
    font-size: 0.95rem;
    padding: 9px 14px;
  }

  /* Lecture d'histoire */
  .titre-histoire {
    font-size: 1.25rem;
    margin: 10px 0 14px;
  }

  .carte-page {
    padding: 20px 16px;
    border-radius: 22px;
  }

  .emoji-page {
    font-size: 3.6rem;
    margin-bottom: 10px;
  }

  .texte-page {
    font-size: 1.18rem;
    line-height: 1.6;
    margin-bottom: 16px;
  }

  .bouton-audio {
    font-size: 1.1rem;
    padding: 12px 22px;
    width: 100%;
  }

  .zone-choix {
    margin-top: 16px;
    gap: 12px;
  }

  .bouton-choix {
    font-size: 1.1rem;
    padding: 16px 16px;
  }

  .bouton-retour {
    font-size: 1rem;
    padding: 10px 14px;
  }

  .chargement {
    margin-top: 24vh;
  }

  .baguette {
    font-size: 4rem;
  }

  .texte-chargement {
    font-size: 1.2rem;
    padding: 0 12px;
  }
}

/* Très petits écrans */
@media (max-width: 360px) {
  .grille-ages {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .grille-ages .bouton-theme {
    font-size: 0.92rem;
  }

  .gros-bouton {
    font-size: 1.05rem;
  }
}

/* Respect des préférences d'animation */
@media (prefers-reduced-motion: reduce) {
  .baguette,
  .emoji-page {
    animation: none !important;
  }
}
