/* ===== MODAL POESIA: immagine lenta, testo, voce ===== */

.pm {
  --pm-night: #0d1726;
  --pm-ink: #f3efe7;
  --pm-muted: #b9c2cf;
  border: 0;
  padding: 0;
  width: min(1100px, 100vw - 32px);
  max-width: none;
  height: min(760px, 100dvh - 32px);
  max-height: none;
  margin: auto;
  border-radius: 18px;
  overflow: hidden;
  background: var(--pm-night);
  color: var(--pm-ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
}

.pm::backdrop {
  background: rgba(8, 14, 24, 0.78);
  backdrop-filter: blur(4px);
}

.pm[open] {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  animation: pm-in 0.45s ease both;
}

@keyframes pm-in {
  from { opacity: 0; transform: translateY(14px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

/* --- immagine che respira --- */
.pm-visual {
  position: relative;
  overflow: hidden;
  background: #000;
}

.pm-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: 60% 40%;
  animation: pm-kenburns 34s ease-in-out infinite alternate;
}

@keyframes pm-kenburns {
  from { transform: scale(1) translate(0, 0); }
  to { transform: scale(1.14) translate(-2.5%, 1.5%); }
}

.pm-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 55%, var(--pm-night));
  pointer-events: none;
}

/* --- testo --- */
.pm-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pm-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 56px 44px 24px 36px;
  overscroll-behavior: contain;
  /* dissolvenza in fondo: la poesia continua sotto */
  -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 32px), transparent);
  mask-image: linear-gradient(180deg, #000 calc(100% - 32px), transparent);
}

.pm-cat {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-sand, #d4c5b0);
}

.pm-title {
  font-family: var(--font-serif);
  font-size: 2.3rem;
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: 0.02em;
  text-transform: none;
  margin: 0.4rem 0 0.8rem;
  color: var(--pm-ink);
}

.pm-title .subtitle { display: none; }

.pm-award {
  display: inline-block;
  font-size: 13px;
  color: var(--pm-night);
  background: var(--color-sand, #d4c5b0);
  border-radius: 999px;
  padding: 0.25rem 0.8rem;
  margin-bottom: 1.2rem;
}

.pm-text .stanza {
  font-family: var(--font-serif);
  font-size: 1.28rem;
  line-height: 1.75;
  color: var(--pm-ink);
  margin: 0 0 1.4rem;
  opacity: 0;
  animation: pm-verse 1.1s ease forwards;
}

@keyframes pm-verse {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.pm-loading {
  color: var(--pm-muted);
  font-style: italic;
}

/* --- barra voce --- */
.pm-bar {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 14px 36px 16px;
  background: rgba(0, 0, 0, 0.18);
}

.pm-bar audio {
  width: 100%;
  height: 44px;
  display: block;
}

.pm-bar-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--pm-muted);
}

.pm-bar-foot a {
  color: var(--pm-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.pm-bar-foot p { margin: 0; }
.pm-bar-foot a { margin-left: auto; }

/* poesia ancora senza voce: resta solo «Apri la pagina» */
.pm-novoice audio,
.pm-novoice .pm-ai { display: none; }
.pm-novoice .pm-bar-foot { margin-top: 0; }

.pm-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: rgba(13, 23, 38, 0.6);
  color: var(--pm-ink);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.pm-close:hover,
.pm-close:focus-visible { background: rgba(13, 23, 38, 0.85); }
.pm-close:focus-visible { outline: 2px solid var(--pm-ink); outline-offset: 2px; }

.poem-card { cursor: pointer; }

/* la pagina sotto non scorre mentre il modal è aperto */
html { scrollbar-gutter: stable; }
html:has(.pm[open]) { overflow: hidden; }

/* --- telefono: immagine sopra, testo sotto --- */
@media (max-width: 768px) {
  .pm {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }

  .pm[open] {
    grid-template-columns: 1fr;
    grid-template-rows: 34dvh 1fr;
  }

  .pm-visual::after {
    background: linear-gradient(180deg, transparent 55%, var(--pm-night));
  }

  .pm-scroll { padding: 8px 20px 20px; }
  .pm-title { font-size: 1.9rem; }
  .pm-text .stanza { font-size: 1.18rem; }
  .pm-bar { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .pm[open], .pm-visual img, .pm-text .stanza { animation: none; opacity: 1; }
}
