/* La mappa interattiva della Community L-5. Si carica solo quando la si apre. */

.mappa {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 90% at 50% 40%, #2a2150 0%, #120e24 60%, #07050f 100%);
  color: #2b1d0e;
  opacity: 0; visibility: hidden;
  transition: opacity .45s ease, visibility 0s linear .45s;
  overscroll-behavior: contain;
  touch-action: none;
}
.mappa.aperta { opacity: 1; visibility: visible; transition: opacity .45s ease; }
body.mappa-attiva { overflow: hidden; }

.mappa-titolo {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font-family: Georgia, "Times New Roman", serif; font-size: 20px; letter-spacing: .12em; text-transform: uppercase;
  color: #f3d58a; text-shadow: 0 0 18px rgba(243, 213, 138, .55); white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity .8s ease .9s;
}
.mappa.aperta .mappa-titolo { opacity: 1; }
.mappa-aiuto {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
  font-size: 13px; color: #cfc4f0; opacity: .8; pointer-events: none; text-align: center; padding: 0 16px;
}

.mappa-chiudi {
  position: absolute; top: 10px; right: 12px; z-index: 5;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid rgba(243, 213, 138, .5);
  background: rgba(20, 14, 40, .7); color: #f3d58a; font-size: 26px; line-height: 1; cursor: pointer;
  transition: transform .2s, background .2s;
}
.mappa-chiudi:hover { transform: rotate(90deg); background: rgba(60, 40, 100, .8); }

/* La scena: prospettiva per l'inclinazione 3D. */
.mappa-scena { perspective: 1400px; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.mappa-foglio {
  position: relative;
  width: min(96vw, calc((100vh - 90px) * 1.5));
  aspect-ratio: 3 / 2;
  transform-style: preserve-3d;
  border-radius: 10px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .7), 0 0 0 1px rgba(243, 213, 138, .25), 0 0 60px rgba(243, 180, 80, .15);
  overflow: hidden;
  clip-path: inset(0 50% 0 50% round 10px);
  transition: clip-path 1.1s cubic-bezier(.7, 0, .2, 1) .15s;
  will-change: transform;
}
.mappa.aperta .mappa-foglio { clip-path: inset(0 0 0 0 round 10px); }

/* La lente: quello che si ingrandisce e si sposta (immagine, particelle, impronte, stanze). */
.mappa-lente { position: absolute; inset: 0; transform-origin: 0 0; will-change: transform; }
.mappa-lente.animata { transition: transform .95s cubic-bezier(.65, 0, .25, 1); }
.mappa-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.mappa-canvas, .mappa-orme { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

/* Il faro: scurisce tutto tranne la stanza scelta. */
.mappa-faro {
  position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity .7s ease;
  background: radial-gradient(circle at var(--fx, 50%) var(--fy, 50%), transparent 0, transparent 12%, rgba(8, 5, 20, .55) 26%, rgba(8, 5, 20, .78) 60%);
}
.mappa-faro.acceso { opacity: 1; }

/* Le stanze. */
.stanza {
  position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -50%) scale(0);
  width: 44px; height: 44px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  background: radial-gradient(circle, rgba(255, 226, 150, .95) 0 34%, rgba(214, 150, 40, .9) 35% 58%, rgba(214, 150, 40, 0) 60%);
  font-size: 18px; line-height: 44px; text-align: center;
  filter: drop-shadow(0 0 6px rgba(255, 200, 90, .9));
  transition: transform .5s cubic-bezier(.3, 1.6, .5, 1);
}
.mappa.pronta .stanza { transform: translate(-50%, -50%) scale(var(--sc, 1)); transition-delay: var(--ritardo, 0s); }
.stanza::before, .stanza::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid rgba(255, 214, 120, .85);
  animation: anello 2.4s ease-out infinite; pointer-events: none;
}
.stanza::after { animation-delay: 1.2s; }
@keyframes anello { from { transform: scale(.7); opacity: .95; } to { transform: scale(1.9); opacity: 0; } }
.stanza:hover, .stanza:focus-visible { --sc: 1.18; outline: none; }
.stanza:focus-visible { box-shadow: 0 0 0 3px #fff; }
.stanza .etichetta {
  position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translate(-50%, 6px);
  white-space: nowrap; font: 700 13px/1.2 Georgia, serif; letter-spacing: .04em; color: #3a2508;
  background: linear-gradient(#f7e7c0, #e9d29c); border: 1px solid #b8893e; border-radius: 6px; padding: 5px 9px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.stanza:hover .etichetta, .stanza:focus-visible .etichetta { opacity: 1; transform: translate(-50%, 0); }
.mappa.zoom .stanza { --sc: .8; }
.mappa.zoom .stanza.scelta { --sc: 1.1; }

/* Il gufo in volo. */
.mappa-gufo {
  position: absolute; top: 8%; left: -8%; font-size: 30px; pointer-events: none; z-index: 3;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .5)); transform: scaleX(-1);
}
.mappa-gufo.vola { animation: volo 9s linear forwards; }
@keyframes volo {
  0% { left: -8%; top: 12%; }
  25% { top: 6%; }
  50% { top: 14%; }
  75% { top: 7%; }
  100% { left: 108%; top: 11%; }
}

/* La scheda della stanza. */
.mappa-scheda {
  position: absolute; z-index: 6; right: 18px; top: 50%; width: min(360px, calc(100vw - 32px));
  transform: translate(120%, -50%); opacity: 0;
  background: linear-gradient(160deg, #fbf0d4, #ecd9a6); color: #2b1d0e;
  border: 1px solid #b8893e; border-radius: 14px; padding: 20px 20px 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6), inset 0 0 40px rgba(160, 110, 40, .25);
  transition: transform .6s cubic-bezier(.2, 1.2, .3, 1), opacity .4s ease;
}
.mappa-scheda.visibile { transform: translate(0, -50%); opacity: 1; }
.mappa-scheda > * { opacity: 0; transform: translateY(8px); transition: opacity .4s, transform .4s; }
.mappa-scheda.visibile > * { opacity: 1; transform: none; }
.mappa-scheda.visibile > *:nth-child(2) { transition-delay: .12s; }
.mappa-scheda.visibile > *:nth-child(3) { transition-delay: .22s; }
.mappa-scheda.visibile > *:nth-child(4) { transition-delay: .32s; }
.mappa-scheda.visibile > *:nth-child(5) { transition-delay: .42s; }
.mappa-scheda h3 { font: 700 23px/1.15 Georgia, serif; margin: 0 0 4px; display: flex; gap: 10px; align-items: center; }
.mappa-scheda .accesso { display: inline-block; font-size: 12.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #fff; background: #7c1f2e; border-radius: 4px; padding: 2px 8px; margin: 2px 0 10px; }
.mappa-scheda .accesso.tutti { background: #1f7a45; }
.mappa-scheda p { margin: 0 0 12px; font-size: 16px; line-height: 1.5; }
.mappa-scheda .azioni { display: flex; flex-wrap: wrap; gap: 8px; }
.mappa-scheda .azioni a, .mappa-scheda .azioni button {
  font: 700 14.5px/1 system-ui, sans-serif; border-radius: 22px; padding: 10px 15px; cursor: pointer; text-decoration: none;
  border: 1px solid #7a5418; background: #3a2508; color: #fbe9bd;
}
.mappa-scheda .azioni .secondaria { background: transparent; color: #3a2508; }
.mappa-scheda .x { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 22px; color: #7a5418; cursor: pointer; opacity: 1; transform: none; }

@media (max-width: 760px) {
  .mappa-titolo { font-size: 15px; top: 18px; }
  .mappa-foglio { width: 100vw; height: auto; border-radius: 0; }
  .stanza { width: 34px; height: 34px; line-height: 34px; font-size: 14px; }
  .mappa-scheda { right: 50%; top: auto; bottom: 12px; transform: translate(50%, 130%); }
  .mappa-scheda.visibile { transform: translate(50%, 0); }
  .mappa-aiuto { bottom: auto; top: 44px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .mappa, .mappa-foglio, .mappa-lente.animata, .stanza, .mappa-scheda, .mappa-scheda > *, .mappa-faro { transition: none !important; }
  .stanza::before, .stanza::after { animation: none; }
  .mappa-gufo { display: none; }
}
