:root {
  --night: #160b22;
  --night-2: #2a0d27;
  --cream: #fff5e6;
  --cream-2: #f6e6cf;
  --ink: #23131f;
  --ink-soft: #6e5866;
  --red: #ff3b4f;
  --red-deep: #c81d3a;
  --orange: #ff8a1f;
  --gold: #ffc83d;
  --on-dark: #f6ecff;
  --on-dark-soft: #c4b2d4;
  --display: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--on-dark);
  font: 19px/1.45 var(--display);
  background:
    radial-gradient(120% 60% at 50% -10%, #5a1640 0%, rgba(90, 22, 64, 0) 60%),
    radial-gradient(80% 50% at 100% 100%, #3a1036 0%, rgba(58, 16, 54, 0) 70%),
    linear-gradient(180deg, var(--night) 0%, #1c0c24 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* stelline che brillano */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.sky i {
  position: absolute; width: 3px; height: 3px; border-radius: 50%;
  background: #fff; opacity: .15;
  animation: twinkle var(--d, 3s) ease-in-out var(--w, 0s) infinite;
}
.sky i.gold { background: var(--gold); }
@keyframes twinkle { 50% { opacity: .9; transform: scale(1.6); } }

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

main {
  position: relative; z-index: 1;
  max-width: 460px; margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(40px, env(safe-area-inset-bottom));
}

.loading { text-align: center; color: var(--on-dark-soft); margin-top: 42vh; }

/* ---------- intestazione ---------- */
.hero { text-align: center; padding: 8px 0 18px; }
.hero .gift { width: 112px; height: 112px; margin: 0 auto -6px; }
h1 {
  font-family: var(--display); font-weight: 800; letter-spacing: -.02em;
  font-size: clamp(42px, 13vw, 58px); line-height: .95; margin: 6px 0 12px;
}
h1 .hot {
  display: block;
  background: linear-gradient(90deg, var(--red) 0%, var(--orange) 55%, var(--gold) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.when {
  display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center;
  padding: 8px 14px; border-radius: 999px; font-size: 16px; font-weight: 600;
  background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .14); color: var(--on-dark);
  flex-direction: column; gap: 2px; border-radius: 18px; padding: 10px 18px;
}
.when span { white-space: nowrap; }
.when span:first-child { font-weight: 800; font-size: 18px; }
.lead { margin: 22px 0 12px; font-size: 20px; font-weight: 700; text-align: center; }

/* ---------- elenco nomi ---------- */
.names { display: grid; gap: 12px; }

.name {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 66px; padding: 14px 14px 14px 20px;
  font: 700 22px/1.2 var(--display); text-align: left; color: var(--ink);
  background: var(--cream); border: 0; border-radius: 18px;
  box-shadow: 0 5px 0 var(--cream-2), 0 10px 24px rgba(0, 0, 0, .35);
  cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: transform .08s, box-shadow .08s;
  animation: rise .45s cubic-bezier(.2, .8, .2, 1) both;
  animation-delay: calc(var(--i, 0) * 35ms);
}
.name:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--cream-2), 0 4px 10px rgba(0, 0, 0, .3); }
.name .go {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 20px;
  background: var(--red); color: #fff;
}

.done-title {
  margin: 28px 0 10px; font-size: 15px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--on-dark-soft); display: flex; align-items: center; gap: 10px;
}
.done-title::after { content: ""; flex: 1; height: 1px; background: rgba(255, 255, 255, .15); }

.name.is-done {
  color: var(--on-dark-soft); background: rgba(255, 255, 255, .06);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12); min-height: 58px; font-size: 20px;
}
.name.is-done:active { transform: scale(.98); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12); }
.name .tag { flex: none; font-size: 14px; font-weight: 700; padding: 6px 12px; border-radius: 999px; }
.name .tag.done { background: rgba(255, 255, 255, .1); color: var(--on-dark-soft); }
.name .tag.mine { background: var(--gold); color: var(--ink); }
.name.is-mine { color: var(--on-dark); box-shadow: inset 0 0 0 2px var(--gold); }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* ---------- schede ---------- */
.card {
  position: relative; text-align: center; color: var(--ink);
  background: var(--cream); border-radius: 26px; padding: 30px 20px 22px;
  box-shadow: 0 7px 0 var(--cream-2), 0 24px 50px rgba(0, 0, 0, .45);
  margin-top: 10vh; animation: pop .45s cubic-bezier(.2, 1.3, .4, 1) both;
}
.card p { margin: 0 0 12px; }
.card .small { color: var(--ink-soft); font-size: 17px; }
.card .who { font-weight: 800; font-size: 36px; line-height: 1.05; letter-spacing: -.02em; margin-bottom: 14px; word-break: break-word; }
@keyframes pop { from { opacity: 0; transform: translateY(20px) scale(.92); } }

.btn {
  display: block; width: 100%; min-height: 62px; margin-top: 12px; padding: 14px 18px;
  font: 800 21px/1.2 var(--display); border: 0; border-radius: 18px; cursor: pointer;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; transition: transform .08s, box-shadow .08s;
}
.btn.primary { background: var(--red); color: #fff; box-shadow: 0 5px 0 var(--red-deep); }
.btn.primary:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--red-deep); }
.btn.secondary { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--cream-2); }
.btn.secondary:active { transform: scale(.98); }
.btn.on-dark { color: var(--on-dark); box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25); }

/* ---------- estrazione ---------- */
.stage { text-align: center; padding-top: 6vh; }
.stage .gift { width: 170px; height: 170px; margin: 0 auto 8px; }

.stage .label { font-size: 20px; font-weight: 700; color: var(--on-dark-soft); margin: 0 0 16px; }

.reel {
  position: relative; height: 84px; overflow: hidden; border-radius: 22px;
  background: var(--cream); box-shadow: 0 6px 0 var(--cream-2), 0 20px 40px rgba(0, 0, 0, .45);
}
.reel::before, .reel::after {
  content: ""; position: absolute; left: 0; right: 0; height: 26px; z-index: 2; pointer-events: none;
}
.reel::before { top: 0; background: linear-gradient(var(--cream), rgba(255, 245, 230, 0)); }
.reel::after { bottom: 0; background: linear-gradient(rgba(255, 245, 230, 0), var(--cream)); }
.reel ul { list-style: none; margin: 0; padding: 0; will-change: transform; }
.reel li {
  height: 84px; display: grid; place-items: center; padding: 0 12px;
  font-weight: 800; font-size: 32px; color: var(--ink); letter-spacing: -.01em; white-space: nowrap;
}

.flash { position: fixed; inset: 0; background: #fff; z-index: 6; pointer-events: none; animation: flash .5s ease-out forwards; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }
.jolt { animation: jolt .4s cubic-bezier(.36, .07, .19, .97); }
@keyframes jolt {
  20% { transform: translate(-6px, 3px); } 40% { transform: translate(5px, -4px); }
  60% { transform: translate(-3px, 2px); } 80% { transform: translate(2px, -1px); }
}

/* ---------- risultato ---------- */
.result .target {
  font-weight: 800; font-size: clamp(44px, 14vw, 60px); line-height: 1; letter-spacing: -.03em;
  margin: 6px 0 16px; word-break: break-word;
  background: linear-gradient(90deg, var(--red-deep), var(--red) 45%, var(--orange));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: zoom .6s cubic-bezier(.2, 1.5, .4, 1) .1s both;
}
@keyframes zoom { from { transform: scale(.3); opacity: 0; } }
.result .secret { font-size: 22px; font-weight: 800; margin-bottom: 18px; }
.info { text-align: left; background: #fde9d6; border-radius: 18px; padding: 6px 16px; margin: 0 0 16px; }
.info .row { display: flex; gap: 12px; padding: 12px 0; font-size: 17px; line-height: 1.35; }
.info .row + .row { border-top: 1px dashed rgba(35, 19, 31, .18); }
.info .ico { flex: none; font-size: 22px; line-height: 1.1; }
.info b { font-weight: 800; }
.tagline {
  display: inline-block; margin-top: 6px; padding: 4px 10px; border-radius: 8px; transform: rotate(-2deg);
  background: var(--cream); border: 2px dashed var(--red); color: var(--red-deep); font-weight: 800;
}

/* ---------- pacco regalo furbetto (svg) ---------- */
.gift svg { width: 100%; height: 100%; overflow: visible; }
.gift .box { transform-box: fill-box; transform-origin: 50% 100%; animation: wiggle 3.4s ease-in-out infinite; }
.gift .lid { transform-box: fill-box; transform-origin: 50% 100%; }
.gift .pupil { animation: peek 3.4s ease-in-out infinite; }
.gift .puff { opacity: 0; transform-box: fill-box; transform-origin: center; animation: puff 3.4s ease-out infinite; }
.gift .prr { font: italic 800 12px var(--display); fill: #c9f27b; }

/* ogni 3 secondi: si schiaccia, nuvoletta verde, occhi che guardano altrove con aria innocente */
@keyframes wiggle {
  0%, 60%, 100% { transform: none; }
  64% { transform: scale(1.09, .9); }
  69% { transform: scale(.94, 1.08) translateY(-3px); }
  75% { transform: scale(1.03, .97); }
  82% { transform: none; }
}
@keyframes puff {
  0%, 63% { opacity: 0; transform: translate(0, 0) scale(.2); }
  68% { opacity: 1; }
  85% { opacity: .85; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.5); }
}
@keyframes peek {
  0%, 62% { transform: none; }
  66%, 90% { transform: translate(3px, -2px); }
  100% { transform: none; }
}

/* durante l'estrazione: si agita e scoreggia a raffica */
.gift.agitated .box { animation: rattle .16s linear infinite; }
.gift.agitated .puff { animation: puff-fast 1s ease-out infinite; }
.gift.agitated .pupil { animation: none; transform: translate(3px, -2px); }
@keyframes rattle {
  25% { transform: translate(-2px, 1px) rotate(-3deg) scale(1.02, .98); }
  75% { transform: translate(2px, -1px) rotate(3deg) scale(.98, 1.02); }
}
@keyframes puff-fast {
  0% { opacity: 1; transform: translate(0, 0) scale(.2); }
  60% { opacity: .9; }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(1.6); }
}

/* il nome è uscito: salta il coperchio */
.gift.open .box { animation: none; }
.gift.open .puff { animation: none; opacity: 0; }
.gift.open .lid { animation: lid-off .7s cubic-bezier(.2, .8, .3, 1) forwards; }
@keyframes lid-off { to { transform: translate(16px, -70px) rotate(28deg); opacity: 0; } }

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