/* ==========================================================================
   Sapin en Pain d'Épice, Zones de Zoom (2 clics) & 24 Portes 3D (BEM)
   ========================================================================== */

.tree-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* Conteneur à ratio fixe 3:4 invariable entre iPhone 390px et Desktop 16:9 */
.tree-viewport {
  position: relative;
  width: min(94vw, calc((100dvh - 190px) * 0.75), 580px);
  min-width: 280px;
  aspect-ratio: 3 / 4;
  border-radius: 24px;
  overflow: hidden;
  padding: 0;
  border: 4px solid rgba(255, 250, 242, 0.85);
  box-shadow:
    0 22px 55px rgba(3, 8, 22, 0.7),
    0 0 0 5px rgba(200, 35, 51, 0.65),
    0 0 38px rgba(245, 194, 73, 0.18);
  background: #0b172c;
  touch-action: manipulation;
}

.tree-stage {
  position: relative;
  width: 100%;
  height: 100%;
  transform-origin: 50% 50%;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
}

.tree-stage__bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

/* Calque des 5 zones cliquables (Vue Globale -> Clic 1) */
.tree-zones {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.tree-zone {
  position: absolute;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 5px 6px;
  border: 2px dashed rgba(255, 250, 242, 0.22);
  border-radius: 18px;
  background: rgba(255, 226, 138, 0.04);
  cursor: zoom-in;
  transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.22s ease;
}

.tree-zone[data-zone-id="mid-right"] {
  justify-content: flex-end;
}

.tree-zone:hover,
.tree-zone:focus-visible {
  background: rgba(245, 194, 73, 0.14);
  border-color: rgba(255, 226, 138, 0.82);
}

.tree-zone__label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(11, 23, 44, 0.78);
  border: 1px solid rgba(255, 226, 138, 0.52);
  color: var(--color-icing);
  font-size: clamp(0.62rem, 1.8vw, 0.74rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  opacity: 0.85;
  pointer-events: none;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.tree-zone:hover .tree-zone__label,
.tree-zone:focus-visible .tree-zone__label {
  opacity: 1;
  transform: scale(1.05);
}

/* Masque les zones quand on est zoomé ou en transition */
.tree-viewport--zooming .tree-zone,
.tree-viewport--zoomed .tree-zone {
  pointer-events: none;
  opacity: 0;
}

/* Calque des 24 portes positionnées en pourcentages */
.tree-doors {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.door {
  position: absolute;
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  perspective: 900px;
  -webkit-tap-highlight-color: transparent;
  /* CRITIQUE : désactivé en vue globale (Clic 1 obligatoire sur une zone) */
  pointer-events: none;
}

.tree-viewport--zoomed .door {
  pointer-events: auto;
  cursor: pointer;
}

.door__frame {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  transform-style: preserve-3d;
  box-shadow: 0 3px 8px rgba(18, 7, 2, 0.55);
  transition: box-shadow 0.24s ease;
}

/* Fond de la niche éclairée */
.door__inside {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: radial-gradient(circle at 50% 42%, #fff3c4 0%, #e8a43c 55%, #5b260b 100%);
  border: 1.5px solid #ffd97d;
  box-shadow: inset 0 2px 9px rgba(45, 16, 4, 0.72);
  overflow: hidden;
}

.door__icon {
  font-size: clamp(0.85rem, 2.5vw, 1.3rem);
  line-height: 1;
  filter: drop-shadow(0 1px 2px rgba(45, 16, 4, 0.45));
}

.door__opened-badge {
  font-size: clamp(0.5rem, 1.3vw, 0.64rem);
  font-weight: 800;
  color: #4b2009;
  background: rgba(255, 250, 242, 0.85);
  padding: 1px 5px;
  border-radius: 999px;
}

/* Battant en pain d'épice (pivot gauche) */
.door__flap {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: left center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background:
    radial-gradient(circle at 30% 25%, rgba(255, 218, 173, 0.25), transparent 55%),
    linear-gradient(155deg, #a65c2e 0%, #81421d 65%, #5c2a0f 100%);
  border: 2px solid var(--color-icing);
  box-shadow:
    inset 0 0 0 2px rgba(200, 35, 51, 0.55),
    inset 0 2px 4px rgba(255, 232, 198, 0.35),
    0 2px 6px rgba(0, 0, 0, 0.45);
}

/* Poignée dorée */
.door__flap::after {
  content: "";
  position: absolute;
  right: 11%;
  top: 50%;
  transform: translateY(-50%);
  width: clamp(3px, 0.6vw, 5px);
  height: clamp(3px, 0.6vw, 5px);
  border-radius: 50%;
  background: var(--color-gold-bright);
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.5);
}

.door__number {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(0.68rem, 2.1vw, 1.05rem);
  color: var(--color-icing);
  text-shadow: 0 1px 3px rgba(34, 12, 3, 0.85);
  line-height: 1;
}

/* État ouvert persistant */
.door--opened .door__flap {
  transform: rotateY(-120deg);
}

.door--opened .door__inside {
  box-shadow:
    inset 0 0 14px rgba(255, 234, 160, 0.9),
    0 0 10px rgba(245, 194, 73, 0.48);
}

/* État débloqué prêt à ouvrir */
.door--unlocked:not(.door--opened) .door__frame {
  box-shadow:
    0 0 0 2px rgba(255, 226, 138, 0.85),
    0 0 14px rgba(245, 194, 73, 0.62);
}

.door--unlocked:not(.door--opened):hover .door__flap {
  filter: brightness(1.09);
}

/* Halo scintillant lors du déverrouillage à 00:00:00 */
.door--newly-unlocked .door__frame {
  animation: door-midnight-glow 1.5s ease-in-out infinite;
}

@keyframes door-midnight-glow {
  0%,
  100% {
    box-shadow: 0 0 0 2px var(--color-gold-bright), 0 0 14px rgba(255, 226, 138, 0.85);
  }
  50% {
    box-shadow: 0 0 0 4px #ffffff, 0 0 24px rgba(255, 209, 92, 1);
  }
}

/* État futur / verrouillé */
.door--locked .door__flap {
  filter: saturate(0.86) brightness(0.92);
}

.door--locked .door__flap::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 250, 242, 0.65);
}

/* Indicateur Brouillon (Sandbox uniquement) */
.door--draft .door__frame::after {
  content: "B";
  position: absolute;
  top: -4px;
  right: -4px;
  z-index: 4;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #f59e0b;
  color: #1f1302;
  font-size: 9px;
  font-weight: 900;
  display: grid;
  place-items: center;
  border: 1px solid #fffaf2;
  pointer-events: none;
}

/* Bouton "Retour au sapin" */
.tree-back-btn {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.tree-viewport--zoomed .tree-back-btn {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Bandeau d'indice discret sous/dans le sapin */
.tree-hint {
  margin: 0;
  padding: 5px 14px;
  border-radius: 999px;
  background: rgba(9, 19, 38, 0.7);
  border: 1px solid rgba(255, 250, 242, 0.18);
  color: var(--color-icing-soft);
  font-size: 0.8rem;
  text-align: center;
  max-width: 94vw;
}

@media (max-width: 640px) {
  .tree-viewport {
    width: min(94vw, calc((100dvh - 175px) * 0.75), 420px);
    border-radius: 18px;
  }

  .tree-back-btn {
    top: 10px;
    left: 10px;
    min-height: 36px;
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  .tree-zone__label {
    font-size: 0.62rem;
    padding: 2px 7px;
  }
}
