/* ===========================
   RESET & BASE
=========================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #fdf6f0;
  --color-bg-soft: #fdeef6;
  --color-primary: #e8739a;
  --color-primary-dark: #d4547f;
  --color-card-bg: #ffffff;
  --color-card-back: #f9d5e5;
  --color-card-shadow: rgba(232, 115, 154, 0.2);
  --color-text: #4a3040;
  --color-text-soft: #9a7a8a;
  --color-overlay: rgba(30, 10, 20, 0.75);

  --card-size: min(38vw, 160px);
  --card-gap: clamp(10px, 3vw, 20px);
  --border-radius-card: 16px;
  --transition-flip: 0.5s;
}

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Georgia', serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===========================
   LAYOUT APP
=========================== */
#app {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.screen.active {
  display: flex;
}

/* ===========================
   MENU
=========================== */
.menu-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
  animation: fadeInUp 0.6s ease both;
}

.title {
  font-size: clamp(2.8rem, 12vw, 5rem);
  color: var(--color-primary);
  letter-spacing: 0.1em;
  font-style: italic;
}

.subtitle {
  font-size: clamp(0.9rem, 3.5vw, 1.1rem);
  color: var(--color-text-soft);
  font-style: italic;
}

.best-score {
  font-size: 0.85rem;
  color: var(--color-text-soft);
  min-height: 20px;
}

/* ===========================
   BOUTONS
=========================== */
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 14px 40px;
  font-size: clamp(0.95rem, 3.5vw, 1.1rem);
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  min-width: 48px;
  min-height: 48px;
  box-shadow: 0 4px 16px var(--color-card-shadow);
}

.btn-primary:active {
  background: var(--color-primary-dark);
  transform: scale(0.97);
}

@media (hover: hover) {
  .btn-primary:hover {
    background: var(--color-primary-dark);
    box-shadow: 0 6px 20px var(--color-card-shadow);
  }
}

/* ===========================
   GAME SCREEN
=========================== */
.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 480px;
  margin-bottom: clamp(16px, 4vw, 32px);
}

.title-small {
  font-size: clamp(1.5rem, 6vw, 2rem);
  color: var(--color-primary);
  font-style: italic;
}

.moves-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--color-card-bg);
  border-radius: 12px;
  padding: 8px 16px;
  box-shadow: 0 2px 10px var(--color-card-shadow);
  min-width: 64px;
}

#moves-count {
  font-size: 1.5rem;
  font-weight: bold;
  color: var(--color-primary);
  line-height: 1;
}

.moves-label {
  font-size: 0.65rem;
  color: var(--color-text-soft);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.game-main {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

/* ===========================
   GRILLE DE CARTES
=========================== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, var(--card-size));
  grid-template-rows: repeat(2, var(--card-size));
  gap: var(--card-gap);
}

/* ===========================
   CARTE - FLIP 3D
=========================== */
.card {
  width: var(--card-size);
  height: var(--card-size);
  cursor: pointer;
  perspective: 1000px;
  border-radius: var(--border-radius-card);
  /* zone tactile minimum 48px garantie par card-size */
}

.card-inner {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform var(--transition-flip) cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--border-radius-card);
}

.card.flipped .card-inner,
.card.matched .card-inner {
  transform: rotateY(180deg);
}

.card-front,
.card-back {
  position: absolute;
  inset: 0;
  border-radius: var(--border-radius-card);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px var(--color-card-shadow);
}

/* Dos de la carte */
.card-back {
  background: var(--color-card-back);
  background-image: radial-gradient(circle at 30% 30%, #ffeaf4, var(--color-card-back));
  font-size: clamp(1.8rem, 8vw, 2.8rem);
}

/* Face de la carte */
.card-front {
  background: var(--color-card-bg);
  transform: rotateY(180deg);
  overflow: hidden;
}

.card-front img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--border-radius-card);
  display: block;
}

/* Carte matchée */
.card.matched .card-front {
  box-shadow: 0 4px 20px rgba(232, 115, 154, 0.5);
  outline: 3px solid var(--color-primary);
}

/* ===========================
   OVERLAY VICTOIRE
=========================== */
.win-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.win-overlay.hidden {
  display: none;
}

.win-overlay.visible {
  opacity: 1;
}

.win-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
  padding: 32px 24px;
  z-index: 101;
  animation: winEntrance 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.win-image {
  width: min(70vw, 280px);
  height: min(70vw, 280px);
  object-fit: cover;
  border-radius: 24px;
  box-shadow: 0 8px 40px rgba(232, 115, 154, 0.5);
}

.win-message {
  font-size: clamp(1.1rem, 4.5vw, 1.5rem);
  color: #fff;
  font-style: italic;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.win-score {
  font-size: clamp(0.85rem, 3vw, 1rem);
  color: rgba(255, 255, 255, 0.8);
}

/* ===========================
   COEURS ANIMÉS
=========================== */
.hearts-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  overflow: hidden;
}

.heart {
  position: absolute;
  bottom: -60px;
  font-size: 1.5rem;
  animation: floatHeart linear forwards;
  opacity: 0.9;
  user-select: none;
}

/* ===========================
   TRANSITION DE NIVEAU
=========================== */
.level-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 110;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.level-overlay.hidden {
  display: none;
}

.level-overlay.visible {
  opacity: 1;
}

.level-content {
  text-align: center;
  animation: winEntrance 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.level-eyebrow {
  color: rgba(255, 255, 255, 0.75);
  font-size: clamp(0.8rem, 3vw, 1rem);
  font-style: italic;
}

.level-title {
  color: #fff;
  font-size: clamp(2rem, 9vw, 3.2rem);
  font-style: italic;
  letter-spacing: 0.04em;
  margin: 8px 0;
}

.level-sub {
  color: rgba(255, 255, 255, 0.8);
  font-size: clamp(0.9rem, 3.5vw, 1.1rem);
  font-style: italic;
}

/* ===========================
   PENDU (NIVEAU 2)
=========================== */
.hangman-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(14px, 3.5vw, 24px);
  width: 100%;
  max-width: 480px;
  flex: 1;
  justify-content: center;
}

.hangman-instruction {
  color: var(--color-text-soft);
  font-style: italic;
  font-size: clamp(0.9rem, 3.5vw, 1.1rem);
}

/* Dessin du pendu */
.gallows {
  width: min(45vw, 180px);
  height: auto;
}

.gallows-frame {
  stroke: var(--color-primary-dark);
  stroke-width: 6;
  stroke-linecap: round;
}

.hangman-part {
  stroke: var(--color-primary);
  stroke-width: 5;
  stroke-linecap: round;
  fill: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

.hangman-part.visible {
  opacity: 1;
}

/* Mot à deviner */
.word-display {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 8px;
  width: 100%;
}

.word-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: clamp(22px, 7vw, 34px);
  height: clamp(30px, 9vw, 44px);
  border-bottom: 3px solid var(--color-primary);
  font-size: clamp(1.2rem, 5.5vw, 1.8rem);
  font-weight: bold;
  color: var(--color-primary-dark);
  text-transform: uppercase;
}

.word-letter.revealed {
  animation: popLetter 0.3s ease both;
}

.word-space {
  width: clamp(12px, 4vw, 24px);
}

/* Clavier tactile */
.keyboard {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: 100%;
  max-width: 420px;
}

.key {
  min-width: 48px;
  min-height: 48px;
  flex: 0 0 auto;
  border: none;
  border-radius: 12px;
  background: var(--color-card-bg);
  color: var(--color-text);
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 2px 8px var(--color-card-shadow);
  transition: transform 0.12s, background 0.2s, color 0.2s, opacity 0.2s;
}

.key:active {
  transform: scale(0.92);
}

@media (hover: hover) {
  .key:hover:not(:disabled) {
    background: var(--color-card-back);
  }
}

.key:disabled {
  cursor: default;
  box-shadow: none;
}

.key.correct {
  background: var(--color-primary);
  color: #fff;
}

.key.wrong {
  background: #e0d5db;
  color: var(--color-text-soft);
  opacity: 0.6;
}

/* Cœur de victoire du niveau 2 */
.hangman-heart {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(6rem, 40vw, 12rem);
  color: var(--color-primary);
  pointer-events: none;
  opacity: 0;
  z-index: 105;
}

.hangman-heart.beating {
  animation: heartPop 1.8s ease both;
}

.lose-emoji {
  font-size: clamp(3.5rem, 18vw, 6rem);
}

/* ===========================
   ANIMATIONS
=========================== */
@keyframes popLetter {
  from {
    transform: scale(0.4);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes heartPop {
  0% {
    opacity: 0;
    transform: scale(0.2);
  }
  30% {
    opacity: 1;
    transform: scale(1.1);
  }
  45% {
    transform: scale(0.95);
  }
  60% {
    transform: scale(1.05);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes winEntrance {
  from {
    opacity: 0;
    transform: scale(0.75);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes floatHeart {
  0% {
    transform: translateY(0) scale(1) rotate(0deg);
    opacity: 0.9;
  }
  80% {
    opacity: 0.7;
  }
  100% {
    transform: translateY(-110vh) scale(0.6) rotate(20deg);
    opacity: 0;
  }
}

/* ===========================
   RESPONSIVE
=========================== */

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
  :root {
    --card-size: min(30vh, 130px);
    --card-gap: 10px;
  }

  .screen {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    padding: 12px;
  }

  .game-header {
    width: 100%;
    margin-bottom: 8px;
  }

  .win-image {
    width: min(35vh, 180px);
    height: min(35vh, 180px);
  }

  /* Pendu en paysage : layout compact horizontal */
  .hangman-main {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 20px;
    max-width: 100%;
  }

  .hangman-instruction {
    width: 100%;
  }

  .gallows {
    width: min(22vh, 120px);
  }

  .word-display,
  .keyboard {
    flex: 1 1 280px;
  }

  .word-letter {
    height: 36px;
    font-size: 1.3rem;
  }
}

/* Tablette */
@media (min-width: 600px) {
  :root {
    --card-size: min(28vw, 180px);
    --card-gap: 20px;
  }
}

/* Desktop */
@media (min-width: 1024px) {
  :root {
    --card-size: 200px;
    --card-gap: 24px;
  }

  .screen {
    padding: 40px;
  }
}
