:root {
  --notte: #1f2a24;
  --notte-2: #2b3a31;
  --crema: #f7efe2;
  --carta: #fbf6ec;
  --rosso: #b8433a;
  --rosso-scuro: #8e2f2a;
  --verde: #3f6b4f;
  --verde-scuro: #2c4a38;
  --oro: #e0b050;
  --kraft: #c9a57a;
  --inchiostro: #3a2a22;
  --inchiostro-2: #6b5546;
  --gap: 10px;
  --cols: 4;
  --raggio: 14px;
  --serif: "Fraunces", Georgia, serif;
  --mano: "Caveat", "Segoe Print", cursive;
  --sans: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--sans);
  color: var(--crema);
  background:
    radial-gradient(ellipse 90% 50% at 50% 0%, rgba(224, 176, 80, .16), transparent 70%),
    radial-gradient(ellipse at 50% 30%, var(--notte-2) 0%, var(--notte) 55%, #161d19 100%) fixed;
  background-color: var(--notte);
  overflow-x: hidden;
}

#neve {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* ---------- ghirlanda di lucine ---------- */
.ghirlanda {
  position: relative;
  height: 54px;
  z-index: 1;
}
.ghirlanda svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.lucina {
  position: absolute;
  width: 11px;
  height: 16px;
  margin-left: -5.5px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: var(--c);
  box-shadow: 0 0 10px 2px var(--c);
  animation: luccica 2.4s ease-in-out infinite;
  animation-delay: var(--d);
}
.lucina::before {
  content: "";
  position: absolute;
  top: -4px; left: 2.5px;
  width: 6px; height: 5px;
  border-radius: 2px;
  background: #4a4a3e;
}
@keyframes luccica {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; box-shadow: 0 0 4px 0 var(--c); }
}

/* ---------- testata ---------- */
.testata {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 4px 16px 18px;
}
.testata h1 {
  font-family: var(--mano);
  font-weight: 700;
  font-size: clamp(2.6rem, 9vw, 3.6rem);
  line-height: 1;
  margin: 6px 0 8px;
  color: var(--crema);
  text-shadow: 0 2px 0 rgba(0,0,0,.25);
}
.sottotitolo {
  margin: 0 auto;
  max-width: 34ch;
  color: rgba(247, 239, 226, .8);
  font-size: 1rem;
  line-height: 1.45;
}

/* ---------- griglia ---------- */
.contenitore {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
  container-type: inline-size;
}
.griglia {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-auto-rows: calc((100cqi - (var(--cols) - 1) * var(--gap)) / var(--cols));
  grid-auto-flow: dense;
}
@media (min-width: 640px) {
  :root { --cols: 7; --gap: 12px; }
}

.porta {
  position: relative;
  border: 0;
  padding: 0;
  margin: 0;
  background: none;
  cursor: pointer;
  border-radius: var(--raggio);
  perspective: 800px;
  font: inherit;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
}
.porta.larga { grid-column: span 2; }
.porta:focus-visible { outline: 3px solid var(--oro); outline-offset: 3px; }

.interno {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle at 50% 40%, rgba(224,176,80,.25), transparent 65%),
    #2a1d17;
  box-shadow: inset 0 3px 10px rgba(0,0,0,.6);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 2px;
}
.interno .em { font-size: clamp(1.5rem, 7cqi, 2.1rem); line-height: 1; }
.interno .n { font-family: var(--serif); font-size: .75rem; color: rgba(247,239,226,.6); }

.anta {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  display: grid;
  place-items: center;
  transform-origin: left center;
  transition: transform .9s cubic-bezier(.3, .7, .25, 1);
  box-shadow: 0 4px 0 rgba(0,0,0,.22), 0 8px 18px rgba(0,0,0,.25);
  background-color: var(--bg);
  background-image: radial-gradient(rgba(255,255,255,.09) 1.2px, transparent 1.6px);
  background-size: 12px 12px;
  color: var(--fg);
  backface-visibility: hidden;
}
.anta::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: calc(var(--raggio) - 5px);
  border: 2px dashed var(--cucitura);
  pointer-events: none;
}
.anta .num {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(1.4rem, 7cqi, 2.1rem);
  line-height: 1;
  position: relative;
}
.porta.larga .anta .num { font-size: clamp(1.8rem, 9cqi, 2.6rem); }
.anta .deco {
  position: absolute;
  font-size: .8rem;
  right: 10px;
  bottom: 8px;
  opacity: .9;
}

.c-rossa { --bg: var(--rosso); --fg: var(--crema); --cucitura: rgba(247,239,226,.4); }
.c-verde { --bg: var(--verde); --fg: var(--crema); --cucitura: rgba(247,239,226,.35); }
.c-crema { --bg: #f1e3c8; --fg: var(--rosso-scuro); --cucitura: rgba(184,67,58,.35); }
.c-kraft { --bg: var(--kraft); --fg: #4b3424; --cucitura: rgba(75,52,36,.35); }

/* nastro sulle porte larghe */
.porta.larga .anta::after {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  left: calc(50% - 7px);
  width: 14px;
  background: var(--oro);
  opacity: .85;
  box-shadow: 0 0 0 2px rgba(0,0,0,.06);
}
.porta.larga .anta .num {
  z-index: 1;
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 10px;
}

@media (hover: hover) {
  .porta.sbloccata:not(.aperta):hover .anta { transform: rotateY(-14deg); }
}
.porta.aperta .anta { transform: rotateY(-104deg); }
.porta.aperta { z-index: 2; }

.porta.oggi:not(.aperta) .anta {
  animation: oggi 2.2s ease-in-out infinite;
}
@keyframes oggi {
  0%, 100% { box-shadow: 0 4px 0 rgba(0,0,0,.22), 0 0 0 0 rgba(224,176,80,.0); }
  50% { box-shadow: 0 4px 0 rgba(0,0,0,.22), 0 0 0 5px rgba(224,176,80,.55), 0 0 26px rgba(224,176,80,.5); }
}

.porta.no { animation: no .45s ease; }
@keyframes no {
  20% { transform: translateX(-5px) rotate(-1.5deg); }
  40% { transform: translateX(5px) rotate(1.5deg); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

/* ---------- piede ---------- */
.piede {
  position: relative;
  z-index: 1;
  margin-top: 40px;
  padding: 70px 16px 28px;
  text-align: center;
  color: var(--inchiostro-2);
}
.collina {
  position: absolute;
  inset: 0;
  background: #eef0ea;
  clip-path: path("M0 40 C 120 0, 260 10, 380 30 S 640 70, 800 22 S 1100 0, 1400 34 L 1400 400 L 0 400 Z");
  z-index: -1;
}
@supports not (clip-path: path("M0 0")) {
  .collina { border-radius: 50% 50% 0 0 / 40px 40px 0 0; }
}
.piede p {
  margin: 0 0 8px;
  font-family: var(--mano);
  font-size: 1.5rem;
  color: var(--verde-scuro);
}

.link-btn {
  font: inherit;
  font-size: .85rem;
  background: none;
  border: 0;
  padding: 4px 6px;
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.anteprima {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 20;
  background: rgba(0,0,0,.75);
  color: #fff;
  font-size: .8rem;
  padding: 6px 12px;
  border-radius: 99px;
  white-space: nowrap;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: 18px;
  z-index: 30;
  transform: translate(-50%, -140%);
  background: var(--carta);
  color: var(--inchiostro);
  padding: 10px 16px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  font-weight: 600;
  max-width: calc(100vw - 32px);
  text-align: center;
  transition: transform .35s ease;
}
.toast.vis { transform: translate(-50%, 0); }

/* ---------- finestra ---------- */
.finestra {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(520px, calc(100vw - 24px));
  max-width: none;
  max-height: calc(100dvh - 24px);
  overflow: visible;
  color: var(--inchiostro);
}
.finestra::backdrop {
  background: rgba(14, 19, 16, .62);
  backdrop-filter: blur(3px);
}
.finestra[open] { animation: entra .4s cubic-bezier(.3,.8,.3,1.1); }
@keyframes entra {
  from { opacity: 0; transform: translateY(20px) scale(.96); }
}

.carta {
  position: relative;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(224,176,80,.12), transparent 60%),
    var(--carta);
  border-radius: 18px;
  padding: 30px 22px 24px;
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.carta::before {
  /* nastro adesivo */
  content: "";
  position: absolute;
  top: -10px;
  left: 50%;
  width: 96px;
  height: 24px;
  transform: translateX(-50%) rotate(-3deg);
  background: rgba(184, 67, 58, .55);
  background-image: repeating-linear-gradient(45deg, rgba(255,255,255,.25) 0 6px, transparent 6px 12px);
  border-radius: 2px;
}
.chiudi {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: rgba(58,42,34,.07);
  color: var(--inchiostro-2);
  font-size: 1rem;
  cursor: pointer;
}
.chiudi:hover { background: rgba(58,42,34,.13); }

.f-giorno {
  margin: 0;
  text-align: center;
  font-size: .8rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--rosso);
}
.f-titolo {
  margin: 4px 0 18px;
  text-align: center;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.55rem;
  line-height: 1.2;
  color: var(--verde-scuro);
}
.f-corpo { font-size: 1.02rem; line-height: 1.55; }

/* ---------- contenuti ---------- */
.icona-grande { font-size: 3rem; text-align: center; margin: 0 0 8px; line-height: 1; }

.frase p {
  font-family: var(--mano);
  font-size: 1.75rem;
  line-height: 1.25;
  text-align: center;
  margin: 0 0 14px;
  color: var(--inchiostro);
}

.istruzioni {
  text-align: center;
  color: var(--inchiostro-2);
  margin: 0 0 14px;
}

.btn {
  font: inherit;
  font-weight: 800;
  border: 0;
  border-radius: 12px;
  padding: 11px 18px;
  background: var(--rosso);
  color: var(--crema);
  cursor: pointer;
  box-shadow: 0 3px 0 var(--rosso-scuro);
  transition: transform .1s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--rosso-scuro); }
.btn.sec { background: #eadcc4; color: var(--inchiostro); box-shadow: 0 3px 0 #cdb998; }
.btn:disabled { opacity: .5; cursor: default; }
.azioni { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }

.premio {
  margin-top: 18px;
  padding: 16px 16px;
  border-radius: 14px;
  background: #fff8e6;
  border: 2px dashed var(--oro);
  text-align: center;
  animation: entra .5s ease;
}
.premio .extra { font-size: .85rem; font-weight: 800; color: var(--verde); margin: 0 0 6px; text-transform: uppercase; letter-spacing: .08em; }
.premio p { margin: 0; font-family: var(--mano); font-size: 1.6rem; line-height: 1.25; }

/* memory */
.memory {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 340px;
  margin: 0 auto;
}
.carta-m {
  aspect-ratio: 3 / 4;
  border: 0;
  padding: 0;
  background: none;
  perspective: 500px;
  cursor: pointer;
  position: relative;
}
.carta-m span {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  transition: transform .45s ease;
}
.carta-m .retro {
  background: var(--verde);
  background-image: radial-gradient(rgba(255,255,255,.14) 1.5px, transparent 2px);
  background-size: 10px 10px;
  box-shadow: 0 2px 0 var(--verde-scuro);
}
.carta-m .fronte {
  background: #fff;
  font-size: 1.9rem;
  transform: rotateY(180deg);
  box-shadow: 0 2px 0 #d9ccb4;
}
.carta-m.girata .retro { transform: rotateY(-180deg); }
.carta-m.girata .fronte { transform: rotateY(0); }
.carta-m.trovata .fronte { background: #fff3cf; }

/* anagramma */
.slot-riga, .tessere {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 0 0 14px;
}
.slot, .tessera {
  width: clamp(24px, calc((100% - (var(--n, 8) - 1) * 6px) / var(--n, 8)), 38px);
  height: 44px;
  border-radius: 9px;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.3rem;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
}
.slot { background: rgba(58,42,34,.08); border-bottom: 3px solid rgba(58,42,34,.2); color: var(--inchiostro); cursor: pointer; }
.tessera { background: var(--kraft); color: #3b2a1c; box-shadow: 0 3px 0 #9d7e58; cursor: pointer; }
.tessera.usata { visibility: hidden; }
.slot-riga.giusto .slot { background: #dcecd8; border-color: var(--verde); }
.slot-riga.sbagliato { animation: no .45s ease; }
.indizio { text-align: center; font-style: italic; color: var(--inchiostro-2); margin: 10px 0 0; }

/* quiz */
.quiz-n { text-align: center; font-size: .8rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--inchiostro-2); margin: 0 0 6px; }
.quiz-d { text-align: center; font-family: var(--serif); font-size: 1.2rem; margin: 0 0 14px; }
.quiz-opz { display: grid; gap: 8px; }
.quiz-opz button {
  font: inherit;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid #e5d6bb;
  background: #fff;
  color: var(--inchiostro);
  cursor: pointer;
}
.quiz-opz button.ok { border-color: var(--verde); background: #e3f0df; }
.quiz-opz button.ko { border-color: var(--rosso); background: #f8e1de; }
.quiz-nota { text-align: center; color: var(--inchiostro-2); font-style: italic; margin: 10px 0 0; }

/* indovinello */
.indovinello-testo {
  font-family: var(--serif);
  font-size: 1.2rem;
  text-align: center;
  margin: 0 0 16px;
  font-style: italic;
}
.campo {
  display: flex;
  gap: 8px;
}
.campo input {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 11px 14px;
  border-radius: 12px;
  border: 2px solid #e5d6bb;
  background: #fff;
  color: var(--inchiostro);
}
.campo input:focus { outline: none; border-color: var(--oro); }
.campo.sbagliato { animation: no .45s ease; }

/* acchiappa */
.campo-gioco {
  position: relative;
  height: 340px;
  border-radius: 14px;
  overflow: hidden;
  background: linear-gradient(#20302a, #36503f);
  touch-action: manipulation;
  user-select: none;
}
.campo-gioco .ogg {
  position: absolute;
  top: 0;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
  padding: 6px;
  will-change: transform;
}
.campo-gioco .ogg.preso { transition: transform .25s, opacity .25s; opacity: 0; }
.hud {
  position: absolute;
  top: 8px; left: 10px; right: 10px;
  display: flex;
  justify-content: space-between;
  color: var(--crema);
  font-weight: 800;
  z-index: 2;
  pointer-events: none;
}
.sovra {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  text-align: center;
  color: var(--crema);
  padding: 20px;
  background: rgba(20,30,25,.55);
  z-index: 3;
}
.sovra p { margin: 0; }

/* gratta */
.gratta {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  min-height: 170px;
  user-select: none;
}
.gratta .buono {
  padding: 22px 18px;
  min-height: 170px;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  background: #fff8e6;
  border: 2px dashed var(--rosso);
  border-radius: 14px;
}
.buono .etichetta { font-size: .78rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; color: var(--rosso); margin: 0 0 6px; }
.buono .testo { font-family: var(--mano); font-size: 1.7rem; line-height: 1.2; margin: 0; }
.buono .scad { font-size: .8rem; color: var(--inchiostro-2); margin: 10px 0 0; }
.gratta canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
  transition: opacity .6s;
}

/* albero */
.albero-box { text-align: center; }
.albero-box svg { width: 100%; max-width: 280px; height: auto; display: block; margin: 0 auto; touch-action: manipulation; }
.albero-box .chioma { cursor: crosshair; }
.palette { display: flex; justify-content: center; gap: 8px; margin: 10px 0 0; }
.palette button {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 0 0 2px #e5d6bb;
  background: var(--c);
  cursor: pointer;
  padding: 0;
}
.palette button.sel { box-shadow: 0 0 0 3px var(--inchiostro); }
.albero-box .stella { opacity: 0; transition: opacity .6s, transform .6s; transform-origin: 100px 24px; transform: scale(.3); }
.albero-box.accese .stella { opacity: 1; transform: scale(1); }
.albero-box.accese .pallina { animation: pallina 1.8s ease-in-out infinite; animation-delay: var(--d); }
@keyframes pallina {
  50% { filter: brightness(1.5) drop-shadow(0 0 4px #ffd77a); }
}

/* lettera */
.lettera p {
  font-family: var(--mano);
  font-size: 1.55rem;
  line-height: 1.3;
  margin: 0 0 14px;
}
.lettera .firma { text-align: right; font-size: 1.8rem; }

/* coriandoli / cuori */
.volo {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  font-size: 1.4rem;
  animation: volo 1.4s cubic-bezier(.2,.6,.3,1) forwards;
}
@keyframes volo {
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--r)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
