:root {
  --fond-1: #2a0614;
  --fond-2: #5c0f2e;
  --fond-3: #8e1a45;
  --creme: #fff4ec;
  --rose-pale: #fbe3e8;
  --rose: #f4a7b9;
  --framboise: #e04a6f;
  --rouge: #b3123f;
  --or: #f0c987;
  --texte-sombre: #3b0a1e;
  --rayon: 16px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100dvh;
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--creme);
  background:
    radial-gradient(120% 60% at 50% 0%, var(--fond-3) 0%, transparent 70%),
    linear-gradient(180deg, var(--fond-2) 0%, var(--fond-1) 100%);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  padding:
    calc(env(safe-area-inset-top) + 20px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 24px)
    calc(env(safe-area-inset-left) + 16px);
}

/* ---------- Cœurs qui flottent en fond ---------- */
#coeurs-fond {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.coeur-flottant {
  position: absolute;
  bottom: -40px;
  color: var(--rose);
  opacity: 0;
  animation: monter linear forwards;
  will-change: transform, opacity;
}
@keyframes monter {
  0%   { transform: translate(0, 0) rotate(0deg); opacity: 0; }
  10%  { opacity: var(--op, .35); }
  100% { transform: translate(var(--dx, 20px), -110vh) rotate(var(--rot, 30deg)); opacity: 0; }
}

header, main, footer { position: relative; z-index: 1; }

/* ---------- En-tête ---------- */
.entete {
  text-align: center;
  margin: 4px auto 20px;
  max-width: 520px;
}
.surtitre {
  margin: 0;
  font-family: "Playfair Display", serif;
  font-style: italic;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: .04em;
  color: var(--rose);
}
.titre {
  margin: 0;
  font-family: "Dancing Script", cursive;
  font-weight: 700;
  font-size: clamp(2.6rem, 12vw, 3.6rem);
  line-height: 1.05;
  color: var(--creme);
  text-shadow: 0 2px 18px rgba(224, 74, 111, .55);
}
.compteur {
  display: inline-block;
  margin: 12px 0 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 244, 236, .1);
  border: 1px solid rgba(255, 244, 236, .18);
  font-size: .9rem;
  font-weight: 600;
}

/* ---------- Grille des portes ---------- */
main { max-width: 520px; margin: 0 auto; }

.grille {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  /* lignes carrées : (largeur de la grille - 3 espaces) / 4 */
  grid-auto-rows: calc((min(100vw - 32px, 520px) - 30px) / 4);
  grid-auto-flow: dense;
  gap: 10px;
}

.porte {
  position: relative;
  border: 0;
  padding: 0;
  margin: 0;
  border-radius: var(--rayon);
  background: rgba(0, 0, 0, .25);
  perspective: 700px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  min-height: 0;
}
.porte.large { grid-column: span 2; }
.porte.grande { grid-column: span 2; grid-row: span 2; }

/* Intérieur (visible quand la porte est ouverte) */
.porte .interieur {
  position: absolute;
  inset: 0;
  border-radius: var(--rayon);
  background: radial-gradient(circle at 50% 45%, #ffd6e0 0%, var(--framboise) 70%);
  display: grid;
  place-items: center;
  box-shadow: inset 0 2px 12px rgba(0, 0, 0, .35);
  font-size: 1.6rem;
}
.porte.grande .interieur { font-size: 3rem; }

/* Battant (la face avant) */
.porte .battant {
  position: absolute;
  inset: 0;
  border-radius: var(--rayon);
  transform-origin: left center;
  transition: transform .75s cubic-bezier(.3, 1.3, .5, 1), box-shadow .3s;
  backface-visibility: hidden;
  display: grid;
  place-items: center;
  background: var(--fond-porte, var(--rose));
  color: var(--texte-porte, var(--texte-sombre));
  box-shadow: 0 6px 14px rgba(0, 0, 0, .3), inset 0 0 0 2px rgba(255, 255, 255, .25);
  overflow: hidden;
}
.porte .battant::after {
  /* petit ruban décoratif */
  content: "";
  position: absolute;
  inset: 6px;
  border: 1.5px dashed rgba(255, 255, 255, .45);
  border-radius: calc(var(--rayon) - 6px);
  pointer-events: none;
}
.porte .numero {
  font-family: "Playfair Display", serif;
  font-weight: 700;
  font-size: clamp(1.4rem, 7vw, 1.9rem);
  line-height: 1;
}
.porte.grande .numero { font-size: clamp(3rem, 15vw, 4rem); }
.porte .mini-coeur {
  position: absolute;
  bottom: 8px;
  right: 10px;
  font-size: .8rem;
  opacity: .8;
}
.porte .cadenas {
  position: absolute;
  top: 7px;
  right: 9px;
  font-size: .7rem;
  opacity: .55;
}

/* Variantes de couleurs */
.porte.c0 { --fond-porte: linear-gradient(145deg, #ffd1dc, #f4a7b9); }
.porte.c1 { --fond-porte: linear-gradient(145deg, #e04a6f, #b3123f); --texte-porte: var(--creme); }
.porte.c2 { --fond-porte: linear-gradient(145deg, #fff4ec, #fbe3e8); }
.porte.c3 { --fond-porte: linear-gradient(145deg, #c2185b, #7a0e33); --texte-porte: var(--creme); }
.porte.c4 { --fond-porte: linear-gradient(145deg, #f7c59f, #f08a8a); }
.porte.grande { --fond-porte: linear-gradient(145deg, #e04a6f 0%, #b3123f 60%, #7a0e33 100%); --texte-porte: var(--or); }

/* États */
.porte.verrouillee .battant { filter: saturate(.75) brightness(.9); }

.porte.disponible .battant {
  animation: pulse 2.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 6px 14px rgba(0,0,0,.3), 0 0 0 0 rgba(240, 201, 135, .0), inset 0 0 0 2px rgba(255,255,255,.25); }
  50%      { box-shadow: 0 6px 14px rgba(0,0,0,.3), 0 0 18px 4px rgba(240, 201, 135, .65), inset 0 0 0 2px rgba(255,255,255,.5); }
}
.porte.aujourdhui::before {
  content: "aujourd'hui";
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--or);
  color: var(--texte-sombre);
  font-size: .6rem;
  font-weight: 800;
  letter-spacing: .03em;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
}

.porte.ouverte .battant,
.porte.ouvre .battant {
  transform: rotateY(-108deg);
  box-shadow: 0 6px 14px rgba(0, 0, 0, .1);
}

.porte.secoue { animation: secoue .45s ease; }
@keyframes secoue {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px) rotate(-2deg); }
  40% { transform: translateX(5px) rotate(2deg); }
  60% { transform: translateX(-3px) rotate(-1deg); }
  80% { transform: translateX(3px) rotate(1deg); }
}

.porte:focus-visible { outline: 3px solid var(--or); outline-offset: 3px; }

.progression {
  text-align: center;
  font-size: .85rem;
  color: var(--rose);
  margin: 18px 0 0;
}

.pied {
  text-align: center;
  margin-top: 26px;
  font-family: "Dancing Script", cursive;
  font-size: 1.35rem;
  color: var(--rose);
}

/* ---------- Fenêtre du cadeau (bottom sheet) ---------- */
.voile {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(20, 2, 10, .6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fondu .25s ease;
}
.voile[hidden] { display: none; }
@keyframes fondu { from { opacity: 0; } }

.cadeau {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--creme);
  color: var(--texte-sombre);
  border-radius: 26px 26px 0 0;
  padding: 26px 22px calc(env(safe-area-inset-bottom) + 28px);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .4);
  animation: monte .45s cubic-bezier(.2, 1.1, .4, 1);
}
.cadeau::before {
  content: "";
  display: block;
  width: 44px;
  height: 5px;
  border-radius: 99px;
  background: rgba(59, 10, 30, .18);
  margin: -12px auto 14px;
}
@keyframes monte { from { transform: translateY(100%); } }

@media (min-width: 600px) {
  .voile { align-items: center; }
  .cadeau { border-radius: 26px; margin: 16px; }
  .cadeau::before { display: none; }
}

.fermer {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  background: var(--rose-pale);
  color: var(--rouge);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.cadeau-date {
  margin: 0;
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--framboise);
}
.cadeau-titre {
  margin: 4px 40px 16px 0;
  font-family: "Dancing Script", cursive;
  font-size: 2.2rem;
  line-height: 1.1;
  color: var(--rouge);
}
.cadeau-contenu > * + * { margin-top: 18px; }

.bloc-texte {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.6;
  white-space: pre-line;
}
.bloc-photo { margin: 0; }
.bloc-photo img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(59, 10, 30, .2);
  background: var(--rose-pale);
}
.bloc-photo figcaption,
.bloc-audio p {
  margin: 8px 0 0;
  font-size: .9rem;
  font-style: italic;
  color: #7a3a52;
  text-align: center;
}
.bloc-audio {
  background: var(--rose-pale);
  border-radius: 14px;
  padding: 14px;
}
.bloc-audio audio { width: 100%; display: block; }
.bloc-video video { width: 100%; border-radius: 14px; display: block; }

/* Explosion de cœurs à l'ouverture */
.eclat {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  font-size: 1.2rem;
  animation: eclat .9s ease-out forwards;
}
@keyframes eclat {
  from { transform: translate(-50%, -50%) scale(.4); opacity: 1; }
  to   { transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(1.2) rotate(var(--r)); opacity: 0; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translate(-50%, 30px);
  z-index: 30;
  max-width: calc(100% - 32px);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--creme);
  color: var(--texte-sombre);
  font-weight: 600;
  font-size: .92rem;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

body.bloque { overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  #coeurs-fond { display: none; }
}
