:root {
  --night: #0b1d3a;
  --night-2: #13284d;
  --red: #c8102e;
  --red-dark: #8f0b20;
  --gold: #d4af37;
  --gold-soft: #f3d98b;
  --green: #1d6b3a;
  --paper: #fbf6ea;
  --paper-edge: #e9dcc0;
  --ink: #2a2118;
  --muted: #5e5246;
  --text-on-night: #f4efe6;
  --envelope: #b9d3a4;
  --envelope-dark: #9fbf88;
  --radius: 14px;
  --serif: 'EB Garamond', Georgia, 'Times New Roman', serif;
  --festive: 'Mountains of Christmas', 'EB Garamond', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
html { background: var(--night); }

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at 50% -10%, #23467f 0%, transparent 60%),
    radial-gradient(ellipse at 80% 110%, #1b3b2a 0%, transparent 55%),
    linear-gradient(180deg, var(--night) 0%, var(--night-2) 100%);
  background-attachment: fixed;
  color: var(--text-on-night);
  font-family: var(--sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body.no-scroll { overflow: hidden; }

#snow, #confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#snow { z-index: 0; }
#confetti { z-index: 60; }

/* ---------- Lucine ---------- */
.garland {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 26px;
  z-index: 5;
  pointer-events: none;
  background:
    radial-gradient(circle at 12px 14px, #ff4d4d 0 5px, transparent 6px) 0 0 / 96px 26px repeat-x,
    radial-gradient(circle at 36px 18px, #ffd54a 0 5px, transparent 6px) 0 0 / 96px 26px repeat-x,
    radial-gradient(circle at 60px 14px, #6ec6ff 0 5px, transparent 6px) 0 0 / 96px 26px repeat-x,
    radial-gradient(circle at 84px 18px, #7dff8a 0 5px, transparent 6px) 0 0 / 96px 26px repeat-x;
  filter: drop-shadow(0 0 6px rgba(255, 230, 150, .7));
  animation: twinkle 1.6s steps(2, jump-none) infinite;
}
.garland::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 12px;
  border-bottom: 2px solid #2c4a2c;
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
@keyframes twinkle {
  0% { filter: drop-shadow(0 0 6px rgba(255, 230, 150, .8)) brightness(1.1); }
  100% { filter: drop-shadow(0 0 2px rgba(255, 230, 150, .3)) brightness(.75); }
}

/* ---------- Layout ---------- */
.wrap {
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: 44px 16px 28px;
}

.masthead { text-align: center; }
.eyebrow {
  margin: 0;
  font-family: var(--serif);
  font-variant: small-caps;
  letter-spacing: .14em;
  color: var(--gold-soft);
  font-size: .95rem;
}
h1 {
  margin: 2px 0 2px;
  font-family: var(--festive);
  font-size: clamp(2rem, 9vw, 2.9rem);
  line-height: 1.05;
  color: #fff;
  text-shadow: 0 2px 0 var(--red-dark), 0 0 22px rgba(255, 215, 120, .35);
}
.sub {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-style: italic;
  color: #cdd6e6;
  font-size: 1rem;
}

/* ---------- Scena ---------- */
.scene {
  position: relative;
  margin: 10px auto 0;
  padding-top: 92px;
  max-width: 440px;
}
.scene svg { display: block; width: 100%; height: auto; overflow: visible; }

.bubble {
  position: absolute;
  /* ancorato dal basso: la punta tocca sempre il cappello, qualunque sia la lunghezza del testo */
  bottom: calc(100% - 88px);
  left: 0;
  right: 0;
  width: fit-content;
  max-width: 84%;
  margin: 0 auto;
  padding: 10px 14px;
  background: #fff;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.3;
  border-radius: 16px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
  opacity: 0;
  transform: translateY(6px) scale(.96);
  transform-origin: 50% 100%;
  transition: opacity .35s ease, transform .35s ease;
  z-index: 2;
}
.bubble::after {
  content: '';
  position: absolute;
  left: 52%;
  bottom: -10px;
  border: 10px solid transparent;
  border-top-color: #fff;
  border-bottom: 0;
}
.bubble.show { opacity: 1; transform: none; }

.spine {
  font-family: var(--serif);
  font-size: 6px;
  font-weight: 700;
  fill: var(--gold-soft);
  text-anchor: middle;
}
.cover-title text {
  font-family: var(--serif);
  fill: var(--gold);
  text-anchor: middle;
  letter-spacing: .04em;
}
.desk-title {
  font-family: var(--serif);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .08em;
  fill: var(--gold-soft);
  text-anchor: middle;
}
.plaque-text {
  font-family: var(--serif);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  fill: #3b2a08;
  text-anchor: middle;
}
.desk-title.small { font-size: 7.4px; font-style: italic; letter-spacing: .02em; }

/* Animazioni di Babbo Natale */
#head, #book, #eyes, #glasses, #brows, #pompom, #gavel, .eye, .star {
  transform-box: fill-box;
}
#head { transform-origin: 50% 100%; animation: head-tilt 6s ease-in-out infinite; }
#book { transform-origin: 50% 50%; animation: book-bob 4.5s ease-in-out infinite; }
#eyes { animation: reading 5s ease-in-out infinite; }
.eye { transform-origin: 50% 50%; animation: blink 4.2s infinite; }
#glasses { animation: glasses-slide 8s ease-in-out infinite; }
#brows { animation: brows 9s ease-in-out infinite; }
#pompom { transform-origin: 0% 0%; animation: pompom 3s ease-in-out infinite; }
#gavel { transform-origin: 100% 50%; }
.star { transform-origin: 50% 50%; animation: star 2.4s ease-in-out infinite; }
.bulb { animation: bulb 1.8s ease-in-out infinite; }
.bulb.b2 { animation-delay: .6s; }
.bulb.b3 { animation-delay: 1.2s; }

@keyframes head-tilt { 0%, 100% { transform: rotate(-1.5deg); } 50% { transform: rotate(1.5deg); } }
@keyframes book-bob {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-4px) rotate(1deg); }
  72% { transform: translateY(-2px) rotate(-2.5deg); }
}
@keyframes reading {
  0% { transform: translate(-4px, 2px); }
  28% { transform: translate(4px, 2px); }
  32% { transform: translate(-4px, 4px); }
  60% { transform: translate(4px, 4px); }
  64% { transform: translate(-4px, 5px); }
  92% { transform: translate(4px, 5px); }
  100% { transform: translate(-4px, 2px); }
}
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.1); } }
@keyframes glasses-slide {
  0%, 30% { transform: translateY(0); }
  70% { transform: translateY(6px); }
  76% { transform: translateY(6px); }
  80%, 100% { transform: translateY(0); }
}
@keyframes brows {
  0%, 40%, 56%, 100% { transform: translateY(0); }
  45%, 51% { transform: translateY(-6px); }
}
@keyframes pompom { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(10deg); } }
@keyframes star { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.18); opacity: .8; } }
@keyframes bulb { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* Quando parla: sopracciglia su */
.talk #brows { animation: brows-talk 1.2s ease-in-out; }
@keyframes brows-talk { 0%, 100% { transform: translateY(0); } 25%, 75% { transform: translateY(-7px); } }

/* Colpo di martelletto */
.slam #gavel { animation: gavel-slam .9s cubic-bezier(.3, .0, .3, 1); }
.slam #brows { animation: brows-talk .9s ease-in-out; }
@keyframes gavel-slam {
  0% { transform: rotate(0); }
  35% { transform: rotate(38deg); }
  55% { transform: rotate(-6deg); }
  65% { transform: rotate(4deg); }
  100% { transform: rotate(0); }
}
.shake .wrap { animation: shake .45s .45s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-4px, 2px); }
  40% { transform: translate(4px, -2px); }
  60% { transform: translate(-3px, 1px); }
  80% { transform: translate(2px, -1px); }
}

/* ---------- Scheda ---------- */
.card {
  position: relative;
  margin: -6px auto 0;
  padding: 22px 20px 20px;
  background: var(--paper);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .35), inset 0 0 0 1px var(--paper-edge);
  font-family: var(--serif);
  font-size: 1.12rem;
  text-align: center;
}
.card::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(212, 175, 55, .55);
  border-radius: calc(var(--radius) - 5px);
  pointer-events: none;
}
.card h2 { margin: 0 0 8px; font-size: 1.5rem; color: var(--red-dark); }
.card p { margin: 0 0 12px; }
.greet { font-size: 1.25rem; }
.muted { color: var(--muted); }
.fine { margin: 12px 0 0 !important; font-size: .95rem; font-style: italic; color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 26px;
  border: 0;
  border-radius: 999px;
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary {
  margin-top: 4px;
  background: linear-gradient(180deg, #e0263c, var(--red-dark));
  color: #fff;
  box-shadow: 0 6px 0 #5e0715, 0 10px 24px rgba(200, 16, 46, .45);
  animation: pulse 2.4s ease-in-out infinite;
}
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #5e0715, 0 4px 10px rgba(200, 16, 46, .4); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 6px 0 #5e0715, 0 10px 24px rgba(200, 16, 46, .45); }
  50% { box-shadow: 0 6px 0 #5e0715, 0 10px 34px rgba(255, 90, 90, .75); }
}
.btn-ghost {
  background: transparent;
  color: var(--red-dark);
  border: 2px solid var(--red-dark);
  font-size: 1.05rem;
}
.btn-ghost:hover { background: rgba(143, 11, 32, .07); }
.btn:focus-visible, .seal:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.foot {
  margin-top: 18px;
  text-align: center;
  font-family: var(--serif);
  font-style: italic;
  font-size: .9rem;
  color: #a9b6cc;
}

/* ---------- Busta verde degli atti giudiziari ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
  background: rgba(5, 12, 26, .82);
  backdrop-filter: blur(3px);
  animation: fade-in .35s ease;
}
.overlay[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.env-stage { text-align: center; transition: opacity .35s ease, transform .35s ease; }
.env-stage.leave { opacity: 0; transform: scale(.92); }
.env-stage[hidden] { display: none; }
.env-hint {
  margin: 0 0 18px;
  font-family: var(--serif);
  font-size: 1.2rem;
  font-style: italic;
  color: var(--gold-soft);
  animation: hint 1.6s ease-in-out infinite;
}
.env-stage:has(.envelope.open) .env-hint { visibility: hidden; }
@keyframes hint { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

.envelope {
  position: relative;
  width: min(320px, 86vw);
  aspect-ratio: 16 / 10;
  margin: 70px auto 0;
  perspective: 900px;
  animation: drop-in .7s cubic-bezier(.2, 1.4, .4, 1);
}
@keyframes drop-in {
  from { transform: translateY(-60vh) rotate(-12deg); }
  to { transform: none; }
}
.env-back, .env-pocket, .env-flap { position: absolute; inset: 0; border-radius: 6px; }
.env-back { background: var(--envelope-dark); box-shadow: 0 20px 40px rgba(0, 0, 0, .5); }

.env-letter {
  position: absolute;
  left: 7%; right: 7%;
  top: 8%;
  height: 84%;
  padding: 14px 16px;
  background: var(--paper);
  border-radius: 4px;
  z-index: 1;
  transition: transform .7s .45s cubic-bezier(.3, .8, .3, 1);
}
.env-letter span {
  display: block;
  height: 6px;
  margin: 8px 0;
  border-radius: 3px;
  background: #e2d6bb;
}
.env-letter span:nth-child(2) { width: 80%; }
.env-letter span:nth-child(3) { width: 60%; }

.env-pocket {
  z-index: 2;
  background: var(--envelope);
  clip-path: polygon(0 0, 50% 46%, 100% 0, 100% 100%, 0 100%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-start;
  padding: 12px 14px;
  text-align: left;
  color: #1f3a1a;
  font-family: var(--serif);
}
.env-stamp {
  margin: 0 0 4px;
  padding: 1px 8px;
  border: 2px solid #2f5a26;
  font-weight: 700;
  font-size: .8rem;
  letter-spacing: .12em;
  transform: rotate(-3deg);
}
.env-to { margin: 0; font-size: .92rem; line-height: 1.25; }

.env-flap {
  z-index: 3;
  background: linear-gradient(180deg, #c7ddb4, var(--envelope));
  clip-path: polygon(0 0, 100% 0, 50% 50%);
  transform-origin: 50% 0;
  transition: transform .6s ease, z-index 0s .3s;
}
.envelope.open .env-flap { transform: rotateX(180deg); z-index: 0; }
.envelope.open .env-letter { transform: translateY(-62%); }

.seal {
  position: absolute;
  left: 50%;
  top: 44%;
  z-index: 4;
  border-radius: 50%;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  display: flex;
  animation: seal-pulse 1.6s ease-in-out infinite;
}
.seal-half {
  flex: 1;
  display: flex;
  align-items: center;
  font-family: var(--festive);
  font-size: 1.6rem;
  color: #ffd7cf;
  background: radial-gradient(circle at 30% 30%, #d8323f, #8a0f1c 70%);
  transition: transform .45s ease, opacity .45s ease;
  text-shadow: 0 1px 0 #5e0715;
}
.seal-half.left { justify-content: flex-end; padding-right: 1px; border-radius: 32px 0 0 32px; }
.seal-half.right { justify-content: flex-start; padding-left: 1px; border-radius: 0 32px 32px 0; }
.seal.broken { animation: none; }
.seal.broken .left { transform: translate(-40px, 30px) rotate(-50deg); opacity: 0; }
.seal.broken .right { transform: translate(40px, 30px) rotate(50deg); opacity: 0; }
@keyframes seal-pulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0 rgba(255, 200, 120, 0)); }
  50% { transform: scale(1.08); filter: drop-shadow(0 0 10px rgba(255, 200, 120, .8)); }
}

/* ---------- Sentenza ---------- */
.sentence {
  position: relative;
  width: min(480px, 100%);
  margin: auto;
  padding: 26px 22px 22px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .6), transparent 30%),
    var(--paper);
  color: var(--ink);
  border-radius: 6px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, .55), inset 0 0 0 1px var(--paper-edge);
  font-family: var(--serif);
  font-size: 1.06rem;
  line-height: 1.45;
  text-align: center;
  transform-origin: 50% 0;
}
.sentence[hidden] { display: none; }
.sentence::before {
  content: '';
  position: absolute;
  inset: 8px;
  border: 1px double rgba(212, 175, 55, .7);
  border-radius: 3px;
  pointer-events: none;
}
.sentence.unfold { animation: unfold .7s cubic-bezier(.2, .9, .3, 1.1); }
@keyframes unfold {
  from { transform: perspective(900px) rotateX(-75deg) translateY(40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.sent-head p { margin: 0; }
.small-caps { font-variant: small-caps; letter-spacing: .1em; }
.sent-head h2 {
  margin: 6px 0 2px;
  font-family: var(--festive);
  font-size: 1.8rem;
  line-height: 1.1;
  color: var(--red-dark);
}
.sent-num { margin-top: 6px !important; font-style: italic; font-size: .95rem; color: var(--muted); }

.sent-body { margin-top: 14px; text-align: left; }
.sent-body p { margin: 0 0 8px; }
.sent-body em { font-variant: small-caps; font-style: normal; font-weight: 600; letter-spacing: .04em; }
.sent-body .center { text-align: center; }
.pqm {
  margin: 14px 0 4px !important;
  text-align: center;
  font-weight: 700;
  letter-spacing: .3em;
}
.giver { font-size: 1.25rem; font-weight: 600; }
.receiver {
  margin: 4px 0 12px !important;
  font-family: var(--festive);
  font-size: clamp(1.9rem, 9vw, 2.5rem);
  line-height: 1.1;
  color: var(--red);
  text-shadow: 0 2px 0 rgba(143, 11, 32, .15);
}
.sentence.unfold .receiver { animation: reveal-name .9s .9s both cubic-bezier(.2, 1.6, .4, 1); }
@keyframes reveal-name {
  from { opacity: 0; transform: scale(2.2); filter: blur(6px); }
  to { opacity: 1; transform: none; filter: none; }
}

.sent-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}
.stamp {
  flex: none;
  width: 92px;
  height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px double rgba(200, 16, 46, .8);
  border-radius: 50%;
  color: rgba(200, 16, 46, .85);
  font-size: .7rem;
  font-weight: 700;
  line-height: 1.15;
  text-transform: uppercase;
  letter-spacing: .06em;
  transform: rotate(-14deg);
}
.sentence.unfold .stamp { animation: stamp .45s 1.7s both cubic-bezier(.3, 1.6, .5, 1); }
@keyframes stamp {
  from { opacity: 0; transform: rotate(-14deg) scale(2.4); }
  to { opacity: 1; transform: rotate(-14deg) scale(1); }
}
.sign { text-align: right; }
.sign p { margin: 0; }
.signature {
  font-family: var(--festive);
  font-size: 1.7rem;
  color: #1c3a6e;
  transform: rotate(-4deg);
}
.sent-note {
  margin: 12px 0 16px;
  font-size: .88rem;
  font-style: italic;
  color: var(--muted);
}

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