:root {
  --fondo: #2a0f17;
  --fondo-2: #3d1522;
  --testo: #fbefe6;
  --testo-soft: #e6cfc4;
  --oro: #e8c27a;
  --oro-scuro: #b88a3e;
  --crema: #fbf3e8;
  --inchiostro: #3a1a22;
  --rosa: #e7a1a8;
  --vino: #8e2a3b;
  --bosco: #2f5a46;
  --prugna: #5b2a4a;
  --rosa-scuro: #b8545f;

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px; --space-8: 64px;
  --raggio: 16px;
  --raggio-casella: 12px;
  --ombra: 0 10px 30px rgba(0,0,0,.35);
  --curva: cubic-bezier(.2,.8,.2,1);
  --sicuro-basso: env(safe-area-inset-bottom, 0px);
  --sicuro-alto: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(120% 80% at 50% 0%, var(--fondo-2) 0%, var(--fondo) 60%) fixed, var(--fondo);
  color: var(--testo);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }

/* lucine sfocate sullo sfondo */
.luci {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(6px 6px at 12% 18%, rgba(232,194,122,.55), transparent 70%),
    radial-gradient(4px 4px at 82% 12%, rgba(231,161,168,.55), transparent 70%),
    radial-gradient(5px 5px at 70% 38%, rgba(232,194,122,.35), transparent 70%),
    radial-gradient(3px 3px at 22% 62%, rgba(251,239,230,.4), transparent 70%),
    radial-gradient(5px 5px at 90% 70%, rgba(232,194,122,.35), transparent 70%),
    radial-gradient(4px 4px at 8% 88%, rgba(231,161,168,.4), transparent 70%),
    radial-gradient(160px 160px at 100% 0%, rgba(232,194,122,.10), transparent 70%),
    radial-gradient(220px 220px at 0% 100%, rgba(142,42,59,.35), transparent 70%);
}

.app {
  position: relative; z-index: 1;
  width: min(92%, 520px);
  margin: 0 auto;
  padding: calc(var(--space-6) + var(--sicuro-alto)) 0 calc(var(--space-7) + var(--sicuro-basso));
}

/* testata */
.testa { text-align: center; }
.mese {
  margin: 0 0 var(--space-1);
  font-size: 14px; font-weight: 700; letter-spacing: .02em;
  color: var(--oro);
}
h1 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 380;
  font-size: 28px; line-height: 1.15;
}
h1 em { font-style: italic; font-weight: 400; color: var(--rosa); }

/* frase segreta */
.frase { margin-top: var(--space-5); text-align: center; }
.frase-lettere {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: var(--space-2) var(--space-4);
}
.parola { display: flex; gap: 3px; }
.slot {
  width: 17px; height: 26px;
  display: grid; place-items: center;
  font-family: "Fraunces", Georgia, serif;
  font-size: 19px; font-weight: 400; line-height: 1;
  color: var(--oro);
  border-bottom: 1.5px solid rgba(232,194,122,.35);
}
.slot.vuoto::after {
  content: "♥"; font-family: "Nunito", sans-serif; font-size: 10px; line-height: 1;
  color: rgba(231,161,168,.55);
}
.slot.nuova { animation: accendi 1.2s var(--curva) both; }
.frase.completa .slot { border-bottom-color: transparent; text-shadow: 0 0 12px rgba(232,194,122,.7); }
.frase-nota { margin: var(--space-2) 0 0; font-size: 14px; color: var(--testo-soft); }

@keyframes accendi {
  0% { opacity: 0; transform: translateY(6px) scale(.6); text-shadow: 0 0 0 transparent; }
  60% { opacity: 1; transform: none; text-shadow: 0 0 18px rgba(232,194,122,1); }
  100% { text-shadow: 0 0 6px rgba(232,194,122,.4); }
}

/* blocco di oggi */
.oggi {
  margin-top: var(--space-5);
  padding: var(--space-3) var(--space-4) var(--space-3) var(--space-3);
  border-radius: var(--raggio);
  background: linear-gradient(160deg, rgba(232,194,122,.14), rgba(142,42,59,.22));
  border: 1px solid rgba(232,194,122,.25);
  display: flex; align-items: center; gap: var(--space-3);
}
.oggi .mono { width: 56px; height: 56px; flex: none; border-radius: 50%; object-fit: cover; border: 2px solid var(--oro); }
.oggi-riga { flex: 1; min-width: 0; }
.oggi .pulsante { flex: 1; margin-top: 0; }
.attesa .mono.grande { display: block; width: 140px; height: 140px; margin: 0 auto var(--space-4); border-radius: 50%; object-fit: cover; box-shadow: 0 8px 24px rgba(58,26,34,.18); }
.oggi:empty { display: none; }
.oggi-titolo {
  margin: 0;
  font-size: 14px; font-weight: 700; line-height: 1.3; color: var(--testo-soft);
}
.oggi > .oggi-titolo { font-family: "Fraunces", Georgia, serif; font-weight: 380; font-size: 20px; color: var(--testo); }
.oggi-testo { margin: var(--space-2) 0 0; color: var(--testo-soft); }
.conto {
  margin: 2px 0 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 24px; line-height: 1.1; letter-spacing: .02em; color: var(--oro);
  font-variant-numeric: tabular-nums;
}
.conto small { font-family: "Nunito", sans-serif; font-size: 14px; color: var(--testo-soft); letter-spacing: 0; }

.pulsante {
  display: flex; align-items: center; justify-content: center; gap: var(--space-2);
  width: 100%; min-height: 52px; margin-top: var(--space-4);
  padding: 12px 24px; border: 0; border-radius: 999px;
  background: linear-gradient(180deg, #f0cf8e, var(--oro-scuro));
  color: #2a0f17; font-size: 17px; font-weight: 800;
  box-shadow: 0 6px 20px rgba(232,194,122,.3);
  cursor: pointer;
  transition: transform .15s var(--curva);
}
.pulsante:active { transform: scale(.97); }
.pulsante.secondario {
  background: transparent; color: var(--inchiostro);
  border: 1.5px solid rgba(58,26,34,.25); box-shadow: none; font-weight: 700;
}

/* griglia */
.griglia {
  margin-top: var(--space-5);
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: var(--space-2);
}
.casella {
  position: relative;
  aspect-ratio: 1;
  border: 0; padding: 0;
  border-radius: var(--raggio-casella);
  display: grid; place-items: center;
  cursor: pointer;
  overflow: hidden;
  transition: transform .15s var(--curva);
}
.casella:active { transform: scale(.94); }
.casella .num {
  position: relative; z-index: 2;
  font-family: "Fraunces", Georgia, serif; font-size: 20px; font-weight: 400;
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.3);
}

/* incartata: nastro dorato a croce */
.casella.incartata { background: var(--c, var(--vino)); box-shadow: inset 0 -3px 0 rgba(0,0,0,.18); }
.casella.incartata::before, .casella.incartata::after {
  content: ""; position: absolute; background: rgba(232,194,122,.85); z-index: 1;
}
.casella.incartata::before { left: 50%; top: 0; bottom: 0; width: 6px; transform: translateX(-50%); }
.casella.incartata::after { top: 50%; left: 0; right: 0; height: 6px; transform: translateY(-50%); }
.casella.incartata .num {
  background: var(--c, var(--vino)); border-radius: 50%;
  width: 30px; height: 30px; display: grid; place-items: center;
}

/* oggi: brilla */
.casella.di-oggi { outline: 2px solid var(--oro); outline-offset: 2px; animation: respira 2.4s ease-in-out infinite; }
@keyframes respira {
  0%, 100% { box-shadow: 0 0 0 0 rgba(232,194,122,.0), inset 0 -3px 0 rgba(0,0,0,.18); }
  50% { box-shadow: 0 0 22px 4px rgba(232,194,122,.45), inset 0 -3px 0 rgba(0,0,0,.18); }
}

/* aperta: mostra la lettera */
.casella.aperta {
  background: rgba(251,243,232,.08);
  border: 1px solid rgba(232,194,122,.3);
  align-content: center; gap: 0;
}
.casella.aperta .lettera {
  font-family: "Fraunces", Georgia, serif; font-size: 26px; line-height: 1; color: var(--oro);
}
.casella.aperta .num {
  font-family: "Nunito", sans-serif; font-size: 11px; font-weight: 700;
  color: var(--testo-soft); text-shadow: none; margin-top: 2px;
}

/* futura: chiusa */
.casella.chiusa { filter: saturate(.55) brightness(.55); cursor: default; }
.casella.chiusa:active { transform: none; }
.casella:focus-visible { outline: 3px solid var(--oro); outline-offset: 2px; }

/* animazione dello scarto */
.scarto {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center;
  background: rgba(20,6,10,.7);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.scarto[hidden] { display: none; }
.pacco { position: relative; width: 150px; height: 140px; animation: dondola .5s ease-in-out 2; }
.scatola {
  position: absolute; bottom: 0; left: 8px; right: 8px; height: 100px;
  background: var(--c, var(--vino)); border-radius: 10px;
  box-shadow: var(--ombra);
}
.scatola::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 14px; transform: translateX(-50%); background: var(--oro); }
.coperchio {
  position: absolute; top: 14px; left: 0; right: 0; height: 32px;
  background: var(--c, var(--vino)); filter: brightness(1.12);
  border-radius: 8px; z-index: 2;
  box-shadow: 0 4px 0 rgba(0,0,0,.15);
}
.coperchio::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 14px; transform: translateX(-50%); background: var(--oro); }
.fiocco {
  position: absolute; left: 50%; top: -22px; width: 56px; height: 28px; transform: translateX(-50%);
}
.fiocco::before, .fiocco::after {
  content: ""; position: absolute; top: 0; width: 26px; height: 24px;
  border: 6px solid var(--oro); border-radius: 50% 50% 0 50%;
}
.fiocco::before { left: 0; transform: rotate(-20deg); }
.fiocco::after { right: 0; transform: rotate(20deg) scaleX(-1); }
.scarto.apri .pacco { animation: none; }
.scarto.apri .coperchio { animation: vola .7s var(--curva) forwards; }
.scarto.apri .scatola { animation: brilla .7s ease-out forwards; }
@keyframes dondola { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
@keyframes vola { to { transform: translateY(-160px) rotate(-25deg); opacity: 0; } }
@keyframes brilla { to { box-shadow: 0 0 60px 20px rgba(232,194,122,.6); } }

.cuori { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.cuore {
  position: absolute; left: 50%; top: 50%;
  font-size: 22px; color: var(--rosa);
  animation: esplodi 1.2s var(--curva) forwards;
}
@keyframes esplodi {
  0% { transform: translate(-50%,-50%) scale(.3); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1); opacity: 0; }
}

/* foglio del giorno */
.foglio {
  position: fixed; inset: 0; z-index: 30;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: rgba(20,6,10,.55);
  overscroll-behavior: contain;
}
.foglio[hidden] { display: none; }
.foglio-dentro {
  min-height: 100%;
  width: min(100%, 560px); margin: 0 auto;
  padding: calc(var(--space-4) + var(--sicuro-alto)) var(--space-5) calc(var(--space-6) + var(--sicuro-basso));
  background: var(--crema); color: var(--inchiostro);
  animation: sali .5s var(--curva) both;
}
@media (min-width: 600px) {
  .foglio-dentro { min-height: auto; margin: var(--space-6) auto; border-radius: 24px; box-shadow: var(--ombra); }
}
@keyframes sali { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.foglio-testa { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.foglio-data {
  margin: 0; font-size: 14px; font-weight: 800; letter-spacing: .03em;
  color: var(--rosa-scuro);
}
.chiudi {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: rgba(58,26,34,.08); color: var(--inchiostro);
  cursor: pointer;
}
.lettera-del-giorno {
  margin: var(--space-3) 0 var(--space-5);
  text-align: center;
}
.lettera-del-giorno .grande {
  display: block;
  font-family: "Fraunces", Georgia, serif; font-size: 64px; line-height: 1; color: var(--oro-scuro);
  animation: accendi 1.4s var(--curva) .2s both;
}
.lettera-del-giorno .spiega { display: block; margin-top: var(--space-2); font-size: 14px; color: #7a5560; }

.contenuto { display: flex; flex-direction: column; gap: var(--space-5); }
.contenuto h2 {
  margin: 0; text-align: center;
  font-family: "Fraunces", Georgia, serif; font-weight: 380; font-size: 24px; line-height: 1.2;
}
.biglietto {
  margin: 0;
  font-family: "Caveat", cursive; font-weight: 500;
  font-size: 27px; line-height: 1.35;
  white-space: pre-line;
  color: var(--inchiostro);
}
.foto { margin: 0; }
.foto img {
  display: block; width: 100%; height: auto;
  border-radius: 14px; box-shadow: 0 8px 24px rgba(58,26,34,.18);
}
.foto figcaption { margin-top: var(--space-2); font-family: "Caveat", cursive; font-size: 22px; text-align: center; }
.video video {
  display: block; width: 100%; max-height: 75vh; border-radius: 14px; background: #000;
}

/* lettore audio */
.audio {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-4);
  border-radius: var(--raggio);
  background: #fff; box-shadow: 0 6px 20px rgba(58,26,34,.1);
}
.audio-play {
  width: 60px; height: 60px; flex: none;
  border: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(180deg, var(--rosa-scuro), var(--vino)); color: #fff;
  cursor: pointer;
}
.audio-play svg { margin-left: 3px; }
.audio-play.suona svg { margin-left: 0; }
.audio-info { flex: 1; min-width: 0; }
.audio-etichetta { margin: 0 0 var(--space-2); font-weight: 700; font-size: 15px; }
.audio-barra { position: relative; height: 6px; border-radius: 3px; background: rgba(58,26,34,.12); cursor: pointer; }
.audio-barra span { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 3px; background: var(--rosa-scuro); }
.audio-tempo { margin: var(--space-1) 0 0; font-size: 14px; color: #7a5560; font-variant-numeric: tabular-nums; }

.attesa { text-align: center; color: #7a5560; }
.attesa p { margin: 0; }
.attesa .biglietto { text-align: center; }

.foglio .pulsante.secondario { margin-top: var(--space-6); }

/* invito a installare */
.installa {
  position: fixed; left: 50%; bottom: calc(var(--space-4) + var(--sicuro-basso)); z-index: 10;
  transform: translateX(-50%);
  width: min(92%, 480px);
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  border-radius: var(--raggio);
  background: var(--crema); color: var(--inchiostro);
  box-shadow: var(--ombra);
  font-size: 14px; line-height: 1.45;
}
.installa[hidden] { display: none; }
.installa p { margin: 0; }
.installa svg { vertical-align: -3px; }
.installa-ok {
  flex: none; min-width: 52px; min-height: 44px;
  border: 0; border-radius: 999px; padding: 0 var(--space-4);
  background: var(--vino); color: #fff; font-weight: 800; cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
.oggi > .pulsante:first-child { margin-top: 0; }
