:root {
  --cream: #fffaf7;
  --blush: #f7e3e4;
  --rose: #a94f62;
  --rose-dark: #783545;
  --ink: #422f33;
  --muted: #786368;
  --white: #ffffff;
  --shadow: 0 24px 70px rgba(95, 48, 58, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 10%, rgba(255, 255, 255, 0.9), transparent 32%),
    radial-gradient(circle at 88% 90%, rgba(218, 169, 175, 0.28), transparent 34%),
    linear-gradient(145deg, #f9ecec, var(--cream));
  font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif;
}

button,
a {
  font: inherit;
}

.page-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 3rem);
}

.puzzle-card {
  width: min(100%, 46rem);
  padding: clamp(1.2rem, 4vw, 2.6rem);
  text-align: center;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 2rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.intro {
  margin-bottom: 1.5rem;
}

.eyebrow {
  margin: 0 0 0.55rem;
  color: var(--rose);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.85rem, 6vw, 3rem);
  font-weight: 500;
  line-height: 1.12;
}

h1 span {
  color: var(--rose);
}

.intro > p:last-child {
  margin: 0.7rem auto 0;
  color: var(--muted);
}

.puzzle {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  width: min(100%, 30rem);
  /* photo.jpg est au format portrait 3:4 : ce ratio évite toute déformation. */
  aspect-ratio: 3 / 4;
  margin: 0 auto;
  overflow: hidden;
  border: 5px solid var(--white);
  border-radius: 1.25rem;
  background: var(--blush);
  box-shadow: 0 14px 38px rgba(90, 47, 56, 0.18);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.tile {
  position: relative;
  min-width: 0;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 0;
  background-image: url("photo.jpg");
  background-repeat: no-repeat;
  background-size: 600% 800%;
  cursor: grab;
  transition: filter 160ms ease, box-shadow 160ms ease, transform 160ms ease;
  -webkit-tap-highlight-color: transparent;
}

.tile:hover,
.tile:focus-visible {
  z-index: 1;
  filter: brightness(1.06);
  outline: none;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.9);
}

.tile.selected,
.tile.dragging {
  z-index: 2;
  transform: scale(0.92);
  filter: brightness(1.1);
  box-shadow: inset 0 0 0 3px var(--rose);
  cursor: grabbing;
}

.puzzle.solved .tile {
  border-color: transparent;
  cursor: default;
}

.instructions {
  max-width: 34rem;
  margin: 1.15rem auto 0.8rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.restart-button,
.surprise-button {
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.restart-button {
  padding: 0.55rem 0.95rem;
  color: var(--rose-dark);
  background: var(--blush);
  font-size: 0.82rem;
  font-weight: 650;
}

.restart-button:hover,
.restart-button:focus-visible,
.surprise-button:hover,
.surprise-button:focus-visible {
  transform: translateY(-2px);
}

.success {
  margin-top: 1.3rem;
  padding: 1.1rem;
  border-radius: 1.2rem;
  background: linear-gradient(135deg, #fff4f3, #f7e3e4);
  animation: reveal 650ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.success[hidden] {
  display: none;
}

.success p {
  margin: 0 0 1rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.05rem, 3.5vw, 1.3rem);
  line-height: 1.5;
}

.surprise-button {
  display: inline-block;
  padding: 0.8rem 1.25rem;
  color: var(--white);
  background: var(--rose-dark);
  box-shadow: 0 8px 20px rgba(120, 53, 69, 0.25);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
}

.celebration {
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  pointer-events: none;
}

.confetti {
  position: absolute;
  top: -1.5rem;
  width: 0.55rem;
  height: 0.8rem;
  border-radius: 0.2rem;
  animation: fall var(--duration) ease-in forwards;
  animation-delay: var(--delay);
}

@keyframes reveal {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fall {
  0% { opacity: 0; transform: translate3d(0, -5vh, 0) rotate(0); }
  12% { opacity: 1; }
  100% { opacity: 0; transform: translate3d(var(--drift), 105vh, 0) rotate(520deg); }
}

@media (max-width: 520px) {
  .page-shell {
    align-items: start;
    padding: 0.75rem;
  }

  .puzzle-card {
    padding: 1rem;
    border-radius: 1.4rem;
  }

  .intro {
    margin: 0.4rem 0 1rem;
  }

  .puzzle {
    border-width: 3px;
    border-radius: 0.85rem;
  }

  .instructions {
    font-size: 0.79rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
