:root {
  --page-padding: 10px;
  --card-padding: 5px;
  --gap: 1px;
  --radius: 24px;
  --piece-radius: 0px;
  --text: #20201f;
  --muted: #6f6b64;
  --surface: #fff;
  --background: #FFFFFF;
  --accent: #222;
  --success-bg: #edf5ee;
  --success-text: #315c38;
  --shadow: 0 18px 60px rgba(33, 28, 21, .10);
}

html,
body {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100svh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--background);
  overscroll-behavior: none;
}

button {
  font: inherit;
}

.app {
  min-height: 100svh;
  display: grid;
  place-items: baseline;
  padding:
    max(var(--page-padding), env(safe-area-inset-top))
    max(var(--page-padding), env(safe-area-inset-right))
    max(var(--page-padding), env(safe-area-inset-bottom))
    max(var(--page-padding), env(safe-area-inset-left));
}

.card {
  width: min(100%, 650px);
  padding: var(--card-padding);
  background: var(--surface);
  border-radius: var(--radius);
}

.header {
  text-align: center;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 750;
  letter-spacing: .16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.7rem, 5vw, 2.5rem);
  line-height: 1.05;
  letter-spacing: -.035em;
}

.intro {
  max-width: 460px;
  margin: 12px auto 0;
  color: var(--muted);
  font-size: .96rem;
  line-height: 1.5;
}

.puzzle-shell {
  position: relative;
  width: min(100%, 520px);
  aspect-ratio: 1;
  margin-inline: auto;
  border-radius: 0px;
  overflow: hidden;
  background: #e8e5df;
}

.puzzle {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: var(--gap);
  background: #fff;
  touch-action: none;
  transition: opacity .4s ease, transform .4s ease;
}

.piece {
  --drag-x: 0px;
  --drag-y: 0px;
  position: relative;
  z-index: 1;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: var(--piece-radius);
  background: #ddd;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transform: translate3d(0, 0, 0);
  transition: transform .16s ease, filter .16s ease, box-shadow .16s ease;
}

.piece img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-user-drag: none;
}

.piece.is-dragging {
  z-index: 10;
  cursor: grabbing;
  transform: translate3d(var(--drag-x), var(--drag-y), 0) scale(1.055);
  box-shadow: 0 15px 30px rgba(0, 0, 0, .22);
  transition: box-shadow .12s ease;
  will-change: transform;
}

.piece.is-target {
  transform: scale(.94);
  filter: brightness(.8);
}

.puzzle.is-solved {
  opacity: 0;
  transform: scale(.985);
  pointer-events: none;
}

.final-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.025);
  pointer-events: none;
  transition: opacity .55s ease, transform .7s ease;
}

.final-image.is-visible {
  opacity: 1;
  transform: scale(1);
}

.status {
  margin: 16px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: .84rem;
}

.success {
  /*display: flex;
  align-items: center;*/
  max-height: 0;
  margin-top: 10px;
  opacity: 0;
  /*padding: 0 16px;
	  gap: 12px;
  overflow: hidden;
  border-radius: 14px;
  color: var(--success-text);
  background: var(--success-bg);
  
  transform: translateY(8px);
  transition: opacity .35s ease, transform .35s ease, max-height .35s ease,
              margin .35s ease, padding .35s ease;*/
}
.success .green {
  padding: 0 16px;
	gap: 12px;
  overflow: hidden;
  border-radius: 14px;
  color: var(--success-text);
  background: var(--success-bg);
}

.success.is-visible {
  max-height: none;
  margin-top: 10px;
  padding-block: 5px;
  opacity: 1;
  transform: translateY(0);
}

.success-icon {
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font-weight: 800;
}

.success strong,
.success span {
  display: block;
}

.success span {
  margin-top: 2px;
  font-size: .88rem;
}

.restart {
  display: none;
  width: 100%;
  max-height: 0;
  margin-top: 0;
  padding: 0 18px;
  overflow: hidden;
  border: 0;
  border-radius: 12px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
  opacity: 0;
  cursor: pointer;
  transition: opacity .3s ease, max-height .3s ease, margin .3s ease, padding .3s ease;
}

.restart.is-visible {
  max-height: 60px;
  margin-top: 12px;
  padding-block: 14px;
  opacity: 1;
}


/* --------------------------------------------------
   Progression
-------------------------------------------------- */

.progress-block {
  margin-bottom: 16px;
}

.progress-copy {
  display: flex;
  align-items: baseline;
  justify-content: space-between;

  gap: 15px;

  margin-bottom: 8px;

  font-size: 0.84rem;
}

.progress-copy strong {
  font-weight: 700;
}

.progress-copy span {
  color: var(--muted);

  font-variant-numeric: tabular-nums;
}

.progress {
  height: 6px;

  overflow: hidden;

  background: #e8e4de;

  border-radius: 999px;
}

.progress-value {
  display: block;

  width: 44.444%;
  height: 100%;

  background: var(--accent);

  border-radius: inherit;
}

/* --------------------------------------------------
   Mosaïque 3 × 3
-------------------------------------------------- */

.mosaic {
  width: min(100%, 520px);

  aspect-ratio: 1;

  display: grid;

  grid-template-columns:
    repeat(3, 1fr);

  grid-template-rows:
    repeat(3, 1fr);

  gap: 1px;

  margin-inline: auto;
  padding: 5px;

  background: #ded9d1;

  border-radius: 0px;

  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.03);
}

.tile {
  position: relative;

  min-width: 0;
  min-height: 0;

  overflow: hidden;

  border-radius: 0px;
}


/* --------------------------------------------------
   Fragment trouvé
-------------------------------------------------- */

.tile.found {
  background: #dddddd;
}

.tile.found img {
  display: block;

  width: 100%;
  height: 100%;

  object-fit: cover;
}

.found-badge {
  position: absolute;

  top: 7px;
  right: 7px;

  width: 23px;
  height: 23px;

  display: grid;
  place-items: center;

  color: var(--success);
  background: var(--success-background);

  border-radius: 50%;

  box-shadow:
    0 2px 8px rgba(0, 0, 0, 0.10);

  font-size: 0.72rem;
  font-weight: 900;
}


/* --------------------------------------------------
   Fragment manquant
-------------------------------------------------- */

.tile.missing {
  display: flex;
  flex-direction: column;

  align-items: center;
  justify-content: center;

  gap: 7px;

  color: #9b958c;

  background:
    radial-gradient(
      circle at 50% 45%,
      rgba(255, 255, 255, 0.7),
      transparent 48%
    ),
    var(--empty);

  border:
    1.5px dashed var(--empty-border);
}

.tile-number {
  position: absolute;

  top: 8px;
  left: 9px;

  color: #aaa49b;

  font-size: 0.65rem;
  font-weight: 750;

  letter-spacing: 0.08em;
}

.missing-label {
  font-size: 0.68rem;
  font-weight: 650;
}


/* --------------------------------------------------
   Icône cadenas
-------------------------------------------------- */

.lock {
  position: relative;

  width: 20px;
  height: 16px;

  margin-top: 5px;

  border: 2px solid currentColor;
  border-radius: 4px;

  opacity: 0.72;
}

.lock::before {
  content: "";

  position: absolute;

  left: 50%;
  bottom: 11px;

  width: 11px;
  height: 10px;

  border: 2px solid currentColor;
  border-bottom: 0;

  border-radius:
    8px 8px 0 0;

  transform:
    translateX(-50%);
}


/* --------------------------------------------------
   Message d'aide
-------------------------------------------------- */

.hint {
  display: flex;
  align-items: center;

  gap: 13px;

  margin-top: 18px;
  padding: 14px 15px;

  background: #f5f3ef;

  border-radius: 14px;
}

.hint-icon {
  flex: 0 0 36px;

  width: 36px;
  height: 36px;

  display: grid;
  place-items: center;

  border:
    1px solid #d8d3cb;

  border-radius: 50%;

  font-size: 1.2rem;
}

.hint-content {
  min-width: 0;
}

.hint strong {
  display: block;

  font-size: 0.90rem;
}

.hint p {
  margin: 3px 0 0;

  color: var(--muted);

  font-size: 0.78rem;
  line-height: 1.4;
}

.reveal-section {
    text-align: center;
    margin: 18px auto;
}

#reveal-image {
    margin-top: 25px;
    scroll-margin-top: 20px;
}

#reveal-image img {
    display: block;
    width: 100%;
    max-width: 520px;
    height: auto;
    margin: 0 auto;
    border-radius: 12px;
}

#reveal-image[hidden] {
    display: none;
}
.reveal-image-btn {
  width: 100%;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  color: #fff;
  background: var(--accent);
  font-weight: 700;
  max-height: 60px;
  padding-block: 14px;
  opacity: 1;
  cursor: pointer;
}

/* Petits smartphones : anciens iPhone SE, écrans ~320–374 px */
@media (max-width: 374px) {
  :root {
    --page-padding: 5px;
    --card-padding: 10px;
    --gap: 3px;
    --radius: 18px;
    --piece-radius: 0px;
  }

  .header {
    margin-bottom: 16px;
  }

  h1 {
    font-size: 1.55rem;
  }

  .intro {
    font-size: .84rem;
  }
}

/* Smartphones standards : iPhone/Android ~375–430 px */
@media (min-width: 375px) and (max-width: 430px) {
  :root {
    --page-padding: 5px;
    --card-padding: 5px;
    --gap: 1px;
    --radius: 20px;
  }

  .header {
    margin-bottom: 18px;
  }
}

/* Grands smartphones */
@media (min-width: 431px) and (max-width: 600px) {
  :root {
    --page-padding: 5px;
    --card-padding: 5px;
  }
}

/* Téléphones en paysage : priorité à la hauteur disponible */
@media (orientation: landscape) and (max-height: 520px) {
  :root {
    --page-padding: 5px;
    --card-padding: 5px;
    --gap: 1px;
  }

  .app {
    display: block;
  }

  .card {
    margin-inline: auto;
  }

  .header {
    margin-bottom: 10px;
  }

  .eyebrow,
  .intro {
    display: none;
  }

  h1 {
    font-size: 1.25rem;
  }

  .status {
    margin-top: 8px;
  }
}

/* Tablettes et desktop */
@media (min-width: 768px) {
  :root {
  }
}

/* Respect des réglages d'accessibilité */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
