:root {
  --paper: #f5f1e8;
  --card: #fcfaf5;
  --ink: #1d1c1a;
  --ink-soft: rgba(29, 28, 26, .62);
  --rule: rgba(29, 28, 26, .2);
  --green: #1f3a31;
  --gold: #9c7f45;
  --sun: #f2b632;
  --coral: #e8674f;
  --teal: #2a9d8f;
  --gold-light: #cdb27a;

  --serif: "Cormorant Garamond", "Iowan Old Style", Garamond, Georgia, serif;
  --sans: "Jost", "Futura", "Century Gothic", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--paper) url(assets/coriandoli.svg) 0 0 / 420px; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 500;
  line-height: 1.38;
  -webkit-font-smoothing: antialiased;
}

body.is-wrapped { overflow: hidden; }

/* festone di bandierine in cima a ogni pagina */
body::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 40px;
  background: url(assets/bandierine.svg) center top / 220px 40px repeat-x;
  pointer-events: none;
}

h1, h2, h3, p, dl, dd, ol, ul, figure { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button, input { font: inherit; color: inherit; border-radius: 0; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

:focus-visible { outline: 1.5px solid var(--green); outline-offset: 3px; }
h2:focus-visible { outline: none; }

/* ---------- Pacco ---------- */

.wrap {
  --x: 29%;
  --y: 57%;
  --w: clamp(40px, 9vw, 58px);
  position: fixed;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  color: var(--paper);
}

.wrap-half {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50.5%;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .04) 0 1px, transparent 1px 7px),
    var(--green);
  transition: transform 1s cubic-bezier(.7, 0, .2, 1) .5s;
}
.wrap-left { left: 0; }
.wrap-right { right: 0; }

.ribbon {
  position: absolute;
  box-shadow: 0 0 14px rgba(0, 0, 0, .28);
  transition: transform .5s cubic-bezier(.6, 0, .3, 1) .12s;
}
.ribbon-v {
  top: 0;
  bottom: 0;
  left: calc(var(--x) - var(--w) / 2);
  width: var(--w);
  background: linear-gradient(90deg, #8d7340, #cdb27a 24%, #e6d5a8 50%, #cdb27a 76%, #8d7340);
}
.ribbon-h {
  left: 0;
  right: 0;
  top: calc(var(--y) - var(--w) / 2);
  height: var(--w);
  background: linear-gradient(#8d7340, #cdb27a 24%, #e6d5a8 50%, #cdb27a 76%, #8d7340);
}

.bow {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: clamp(168px, 44vw, 240px);
  margin: calc(clamp(168px, 44vw, 240px) * -.36) 0 0 calc(clamp(168px, 44vw, 240px) * -.5);
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 8px 9px rgba(0, 0, 0, .38));
  animation: bow-wiggle 4s ease-in-out infinite;
}
.bow svg { display: block; width: 100%; }
.bow:focus-visible { outline-color: var(--paper); outline-offset: 6px; }
.bow-loop { fill: #cdb27a; }
.bow-fold { fill: #8d7340; }
.bow-tail { fill: #b0955a; }
.bow-knot { fill: #dcc892; stroke: #9c7f45; stroke-width: 1.5; }

.wrap-to, .wrap-hint {
  position: absolute;
  left: calc(var(--x) + var(--w) / 2 + 1.5rem);
  right: 1.25rem;
  transition: opacity .3s;
}
.wrap-to {
  top: 20%;
  font-size: clamp(2.8rem, 11vw, 5rem);
  font-style: italic;
  font-weight: 400;
  line-height: 1;
}
.wrap-hint {
  top: calc(var(--y) + var(--w) / 2 + 2.2rem);
  font-family: var(--sans);
  font-size: .72rem;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--gold-light);
}

.wrap.is-open .bow { animation: bow-pop .5s cubic-bezier(.5, 0, .8, .4) forwards; pointer-events: none; }
.wrap.is-open .ribbon-v { transform: scaleY(0); }
.wrap.is-open .ribbon-h { transform: scaleX(0); }
.wrap.is-open .wrap-left { transform: translateX(-101%); }
.wrap.is-open .wrap-right { transform: translateX(101%); }
.wrap.is-open .wrap-to, .wrap.is-open .wrap-hint { opacity: 0; }

@keyframes bow-wiggle {
  0%, 64%, 100% { transform: rotate(0); }
  70% { transform: rotate(-4deg) scale(1.03); }
  78% { transform: rotate(3deg) scale(1.03); }
  86% { transform: rotate(-1.5deg); }
}
@keyframes bow-pop {
  35% { transform: scale(1.15) rotate(-8deg); opacity: 1; }
  100% { transform: scale(.2) rotate(40deg); opacity: 0; }
}

.confetti {
  position: fixed;
  inset: 0;
  z-index: 9;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- Pagina ---------- */

.stage {
  width: min(100% - 2.75rem, 31rem);
  margin: 0 auto;
  padding: 4rem 0 4.5rem;
}

.progress {
  height: 1px;
  margin-bottom: clamp(2rem, 8vh, 4rem);
  background: var(--rule);
  transition: opacity .4s;
}
.progress span {
  display: block;
  width: 0;
  height: 2px;
  margin-top: -.5px;
  background: var(--ink);
  transition: width .6s cubic-bezier(.4, 0, .2, 1);
}
.progress.is-hidden { opacity: 0; }

.step { display: none; }
.step.is-active { display: block; animation: step-in .7s cubic-bezier(.2, .7, .2, 1) both; }

@keyframes step-in { from { opacity: 0; transform: translateY(16px); } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

.eyebrow {
  font-family: var(--sans);
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--gold);
}

h2 {
  margin-top: .7rem;
  font-size: clamp(2.5rem, 10.5vw, 3.3rem);
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: -.01em;
  outline: none;
}

.intro { margin-top: .9rem; color: var(--ink-soft); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: .8rem;
  margin-top: 2rem;
  padding: 1rem 1.5rem;
  border: 1px solid var(--ink);
  font-family: var(--sans);
  font-size: .76rem;
  font-weight: 500;
  letter-spacing: .2em;
  text-transform: uppercase;
  cursor: pointer;
  background: var(--card);
  box-shadow: 5px 5px 0 var(--sun);
  transition: transform .15s, box-shadow .15s, background .2s, color .2s, opacity .2s;
}
.btn::after { content: "→"; letter-spacing: 0; transition: transform .2s; }
.btn:hover:not(:disabled), .btn:active:not(:disabled) { background: var(--ink); color: var(--paper); }
.btn:hover:not(:disabled)::after { transform: translateX(4px); }
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--sun); }
.btn:disabled { opacity: .35; cursor: default; }

.link {
  padding: 0;
  border: 0;
  background: none;
  font-family: var(--sans);
  font-size: .8rem;
  color: var(--ink-soft);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  cursor: pointer;
}
.link:hover { color: var(--ink); }

.music-toggle {
  position: fixed;
  right: .9rem;
  bottom: .9rem;
  z-index: 5;
  padding: .45rem .7rem;
  border: 1px solid var(--rule);
  background: var(--paper);
  font-family: var(--sans);
  font-size: .68rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-decoration: line-through;
  cursor: pointer;
}
.music-toggle[aria-pressed="true"] { border-color: var(--gold); color: var(--ink); text-decoration: none; }
.is-wrapped .music-toggle { display: none; }

.status {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: .8rem;
  font-family: var(--sans);
  font-size: .8rem;
  letter-spacing: .04em;
  color: var(--ink-soft);
}

.solved {
  margin-top: 2.2rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--ink);
  animation: rise .7s both;
}
.clue { margin-top: .5rem; font-size: 1.55rem; font-style: italic; line-height: 1.25; }
.feedback { min-height: 1.4em; margin-top: .9rem; font-style: italic; }

/* ---------- Auguri ---------- */

.step-auguri { padding-top: clamp(1rem, 9vh, 5rem); }

.auguri-title { margin-top: 1.3rem; font-weight: 400; line-height: 1; }
.auguri-small { display: block; font-size: clamp(1.8rem, 7.5vw, 2.4rem); font-style: italic; }
.auguri-name {
  display: block;
  margin: 0 0 0 -.05em;
  font-size: clamp(6.6rem, 37vw, 11.5rem);
  font-style: italic;
  font-weight: 500;
  line-height: .9;
  letter-spacing: -.03em;
}
.lead {
  max-width: 25rem;
  margin-top: 2.2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--gold);
  font-size: 1.4rem;
}

/* l'ingresso parte solo quando il pacco è aperto */
.is-wrapped .step-auguri > * { opacity: 0; }
.is-unwrapped .step-auguri > * { animation: rise 1s cubic-bezier(.2, .7, .2, 1) both; }
.is-unwrapped .step-auguri > :nth-child(1) { animation-delay: 1s; }
.is-unwrapped .step-auguri > :nth-child(2) { animation-delay: 1.25s; }
.is-unwrapped .step-auguri > .collage { animation: none; }
.is-unwrapped .step-auguri > .lead { animation-delay: 3s; }
.is-unwrapped .step-auguri > .btn { animation-delay: 3.3s; }

/* stampe buttate sul tavolo: posizione, larghezza e inclinazione arrivano dall'HTML */
.collage {
  position: relative;
  aspect-ratio: 1 / 1.12;
  margin: 2.4rem -.4rem 0;
}
.print {
  position: absolute;
  left: var(--l);
  top: var(--t);
  width: var(--w);
  aspect-ratio: 3 / 4;
  padding: 4px 4px 11px;
  border: 0;
  background: #fff;
  box-shadow: 0 1px 2px rgba(29, 28, 26, .22), 0 7px 16px -7px rgba(29, 28, 26, .4);
  transform: translate(var(--tx, 0), var(--ty, 0)) rotate(var(--r)) scale(var(--s, 1));
  transition: transform .5s cubic-bezier(.2, .7, .2, 1), box-shadow .5s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.print.is-wide { aspect-ratio: 4 / 3; }
.print img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: var(--p);
}
.print.is-lifted {
  --r: 0deg;
  z-index: 2;
  box-shadow: 0 2px 4px rgba(29, 28, 26, .2), 0 24px 40px -14px rgba(29, 28, 26, .55);
}
.print:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.is-unwrapped .print { animation: deal .8s cubic-bezier(.2, .8, .25, 1) both; animation-delay: calc(1.9s + var(--i) * .13s); }
@keyframes deal {
  from { opacity: 0; transform: translateY(-2.2rem) rotate(calc(var(--r) * -3)) scale(1.18); }
}

/* ---------- Esame di teoria ---------- */

.exam-answers { display: flex; gap: 1.2rem; }
.exam-answers .btn { flex: 1; justify-content: center; margin-top: 1.4rem; }
.exam-answers .btn::after { content: none; }
.exam-answers .btn.is-right { background: var(--green); color: var(--paper); opacity: 1; }
.exam-answers .btn.is-wrong { background: var(--coral); color: #fff; opacity: 1; animation: shake .4s; }

/* ---------- Nuvolette ---------- */

.bubble {
  position: fixed;
  left: var(--left, .9rem);
  top: var(--top, 50%);
  z-index: 6;
  max-width: min(17rem, calc(100vw - 2rem));
  padding: .8rem 1rem .85rem;
  border: 1.5px solid var(--ink);
  border-radius: 1.3rem;
  background: #fff;
  box-shadow: 5px 5px 0 var(--bubble-color, var(--coral));
  font-size: 1.12rem;
  font-style: italic;
  line-height: 1.22;
  text-align: left;
  transform: rotate(var(--tilt, -2deg));
  cursor: pointer;
  animation: bubble-in .45s cubic-bezier(.3, 1.5, .5, 1) both;
}
/* l'angolo a punta cambia a ogni nuvoletta */
.bubble[data-tail="0"] { border-bottom-left-radius: .2rem; }
.bubble[data-tail="1"] { border-bottom-right-radius: .2rem; }
.bubble[data-tail="2"] { border-top-left-radius: .2rem; }
.bubble[data-tail="3"] { border-top-right-radius: .2rem; }
.bubble.is-leaving { animation: bubble-out .3s ease-in both; }
@keyframes bubble-in { from { opacity: 0; transform: rotate(calc(var(--tilt, -2deg) * 4)) scale(.4); } }
@keyframes bubble-out { to { opacity: 0; transform: rotate(var(--tilt, -2deg)) scale(.7); } }

/* ---------- Messaggio vocale ---------- */

/* cartoline sbiadite sparse dietro la pagina: sta fuori dallo step per restare ferma mentre la pagina scorre */
.postcards {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transition: opacity .9s, visibility 0s .9s;
}
body:has(#messaggio.is-active) .postcards { opacity: 1; visibility: visible; transition-delay: 0s; }
.postcards img {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: clamp(10.5rem, 46vw, 19rem);
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 5px solid #fff;
  box-shadow: 0 6px 18px -8px rgba(29, 28, 26, .5);
  opacity: .42;
  filter: saturate(.75);
  transform: rotate(var(--r));
}
body:has(#messaggio.is-active) .postcards img { animation: drift var(--d, 9s) ease-in-out infinite alternate; }
.postcards img:nth-child(2n) { --d: 11s; animation-direction: alternate-reverse; }
.postcards img:nth-child(3n) { --d: 7.5s; }
@keyframes drift {
  from { transform: translate(-10px, 8px) rotate(calc(var(--r) - 3deg)); }
  to { transform: translate(12px, -10px) rotate(calc(var(--r) + 3deg)); }
}
.postcards img.is-tall { width: clamp(8rem, 35vw, 14.5rem); aspect-ratio: 3 / 4; }
.postcards::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 75% 46% at 50% 44%, var(--paper) 45%, rgba(245, 241, 232, 0) 100%);
}

.step-voice { padding-top: clamp(2rem, 14vh, 7rem); }
.voice {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: .5rem 1.2rem;
  margin-top: 2rem;
}
.voice-play {
  grid-row: span 2;
  position: relative;
  width: 4.2rem;
  height: 4.2rem;
  border: 1px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  cursor: pointer;
  transition: background .2s;
}
.voice-play::before {
  content: "";
  position: absolute;
  left: 53%;
  top: 50%;
  border-style: solid;
  border-width: .62rem 0 .62rem 1rem;
  border-color: transparent transparent transparent var(--ink);
  transform: translate(-50%, -50%);
}
.voice-play.is-playing::before {
  left: 50%;
  width: .32rem;
  height: 1.15rem;
  border-width: 0 .3rem;
  border-color: var(--ink);
}
.voice-play:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.voice-track { align-self: end; height: 1px; background: var(--ink-soft); }
.voice-track span { display: block; width: 0; height: 3px; margin-top: -1px; background: var(--green); }
.voice-time { align-self: start; font-family: var(--sans); font-size: .78rem; color: var(--ink-soft); }

/* ---------- Memory ---------- */

.memory {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .5rem;
  margin-top: 1.5rem;
}
.mcard {
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 0;
  background: none;
  perspective: 700px;
  cursor: pointer;
}
.mcard-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .55s cubic-bezier(.4, 0, .2, 1);
}
.mcard.is-up .mcard-inner { transform: rotateY(180deg); }
.mcard-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.mcard-back {
  background: var(--green);
  box-shadow: inset 0 0 0 5px var(--green), inset 0 0 0 6px rgba(205, 178, 122, .7);
  color: var(--gold-light);
  font-size: 1.7rem;
  font-style: italic;
}
.mcard-front {
  transform: rotateY(180deg);
  background: var(--card);
  border: 1px solid var(--rule);
  font-size: 1.9rem;
  transition: border-color .3s;
}
.mcard-front img { width: 100%; height: 100%; object-fit: cover; }
.mcard.is-matched { cursor: default; }
.mcard.is-matched .mcard-front { border-color: var(--gold); }

/* ---------- Combinazione ---------- */

.code { display: flex; align-items: flex-start; gap: 1.5rem; margin-top: 1.6rem; }
.code-slots { flex: 0 0 7.5rem; border: 1px solid var(--ink); }
.slot {
  display: block;
  width: 100%;
  height: 2.6rem;
  padding: 0;
  border: 0;
  background: var(--card);
  cursor: pointer;
}
.slot + .slot { border-top: 1px solid var(--ink); }
.slot.is-empty { background: repeating-linear-gradient(135deg, transparent 0 5px, var(--rule) 5px 6px) var(--card); cursor: default; }
.code-side { flex: 1; }
.code-palette { display: flex; flex-wrap: wrap; gap: .6rem; }
.swatch {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
  transition: opacity .2s, transform .15s;
}
.swatch:active { transform: scale(.92); }
.swatch:disabled { opacity: .18; cursor: default; }
.code .btn { margin-top: 1.2rem; padding: .8rem 1.2rem; }

.code-history { margin-top: 1.6rem; border-top: 1px solid var(--rule); }
.code-history li {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .7rem 0;
  border-bottom: 1px solid var(--rule);
  font-family: var(--sans);
  font-size: .86rem;
  font-weight: 400;
  animation: rise .4s both;
}
.code-n { width: 1.2rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.mini { flex: 0 0 2.4rem; border: 1px solid var(--ink); }
.mini i { display: block; height: .5rem; }

.flag { width: 6rem; margin-top: 1.2rem; border: 1px solid var(--ink); animation: rise .7s both; }
.flag i { display: block; height: 1.25rem; }
.flag i:nth-child(1) { background: #2a63a8; }
.flag i:nth-child(2) { background: #1d1c1a; }
.flag i:nth-child(3) { background: #fff; }

/* ---------- Cifrario ---------- */

.cipher-text {
  margin-top: 1.6rem;
  padding: 1.2rem 1.1rem;
  border: 1px solid var(--ink);
  background: var(--card);
  font-family: var(--sans);
  font-size: .98rem;
  font-weight: 400;
  line-height: 1.75;
  letter-spacing: .14em;
}
.cipher-control { display: flex; align-items: center; gap: .7rem; margin-top: 1rem; }
.cipher-control input { flex: 1; min-width: 0; accent-color: var(--green); }
.cipher-control output {
  width: 1.6rem;
  font-family: var(--sans);
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.step-btn {
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  border: 1px solid var(--ink);
  background: none;
  font-family: var(--sans);
  font-size: 1.1rem;
  cursor: pointer;
}
.step-btn:active { background: var(--ink); color: var(--paper); }

.answer { margin-top: 2rem; }
.answer label {
  font-family: var(--sans);
  font-size: .7rem;
  font-weight: 500;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.answer-row { display: flex; align-items: flex-end; gap: 1rem; }
.answer input {
  flex: 1;
  min-width: 0;
  padding: .4rem 0;
  border: 0;
  border-bottom: 1px solid var(--ink);
  background: none;
  font-size: 1.5rem;
  font-style: italic;
  outline: none;
}
.answer input:focus { border-bottom-color: var(--green); box-shadow: 0 1px 0 var(--green); }
.answer .btn { margin-top: 0; padding: .8rem 1.1rem; }

/* ---------- Acrostico ---------- */

.acro { margin-top: 1.4rem; counter-reset: acro; border-top: 1px solid var(--rule); }
.acro li {
  position: relative;
  padding: .9rem 0 .9rem 2rem;
  border-bottom: 1px solid var(--rule);
  counter-increment: acro;
}
.acro li::before {
  content: counter(acro);
  position: absolute;
  left: 0;
  top: 1.2rem;
  font-family: var(--sans);
  font-size: .78rem;
  color: var(--gold);
}
.acro label { display: block; line-height: 1.25; }
.acro small { font-family: var(--sans); font-size: .74rem; color: var(--ink-soft); white-space: nowrap; }
.acro input, .acro-word {
  display: block;
  width: 100%;
  margin-top: .35rem;
  padding: .25rem 0;
  border: 0;
  border-bottom: 1px dashed var(--ink-soft);
  background: none;
  font-family: var(--sans);
  font-size: 1.02rem;
  font-weight: 500;
  letter-spacing: .3em;
  text-transform: uppercase;
  outline: none;
}
.acro input:focus { border-bottom: 1px solid var(--green); }
.acro input::placeholder { color: var(--rule); }
.acro-word { border-bottom-color: transparent; animation: rise .4s both; }
.acro-word b { font-weight: 500; transition: color .5s, font-size .5s; }
.acro.is-complete .acro-word b { color: var(--gold); font-size: 1.45rem; }

/* ---------- Puntini ---------- */

.board {
  margin-top: 1.5rem;
  border: 1px solid var(--ink);
  background: var(--card);
  overflow: hidden;
}
#dots {
  display: block;
  width: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
}
.scene { opacity: 0; transition: opacity 1.2s ease .25s; }

.dots-line, .dots-rubber {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.dots-rubber { stroke-width: 1.4; stroke-dasharray: 3 4; opacity: .55; }

.dot circle { fill: var(--card); stroke: var(--ink); stroke-width: 1.2; }
.dot text { font-family: var(--sans); font-size: 8px; fill: var(--ink-soft); }
.dot.is-done circle { fill: var(--ink); }
.dot.is-next circle { fill: var(--gold); stroke: var(--gold); }
.dot.is-next text { fill: var(--ink); font-weight: 500; }
.dot .dot-ring { opacity: 0; }
.dot.is-next .dot-ring { fill: none; animation: ring 1.5s ease-out infinite; }

@keyframes ring {
  from { r: 4px; opacity: .9; }
  to { r: 13px; opacity: 0; }
}

.board.is-complete .scene { opacity: 1; }
.board.is-complete #dots { cursor: default; }
.board.is-complete #dots-points { opacity: 0; transition: opacity .6s; }

/* ---------- Cartolina ---------- */

.jigsaw {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  aspect-ratio: 3 / 2;
  margin-top: 1.5rem;
  padding: 3px;
  border: 1px solid var(--ink);
  background: var(--card);
  transition: gap .8s, padding .8s;
}
.tile {
  padding: 0;
  border: 0;
  background-color: var(--paper);
  background-repeat: no-repeat;
  background-size: 400% 300%;
  cursor: pointer;
  transition: transform .18s, box-shadow .18s;
}
.tile.is-picked { transform: scale(.9); box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--gold); z-index: 1; }
.jigsaw.is-complete { gap: 0; padding: 0; }
.jigsaw.is-complete .tile { cursor: default; }

.options { margin-top: 1.1rem; border-top: 1px solid var(--ink); }
.option {
  display: flex;
  align-items: baseline;
  gap: 1.1rem;
  width: 100%;
  padding: .8rem .4rem;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: none;
  text-align: left;
  font-size: 1.45rem;
  cursor: pointer;
  transition: background .15s, color .15s, opacity .2s;
}
.option-key { font-family: var(--sans); font-size: .72rem; color: var(--gold); }
.option:hover:not(:disabled) { background: rgba(29, 28, 26, .05); }
.option:disabled { cursor: default; }
.option.is-wrong { opacity: .4; text-decoration: line-through; text-decoration-thickness: 1px; animation: shake .4s; }
.option.is-right { background: var(--green); color: var(--paper); }
.option.is-right .option-key { color: var(--gold-light); }

@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

/* ---------- Video ---------- */

.video-frame { margin-top: 1.6rem; border: 1px solid var(--ink); background: var(--ink); }
.video-frame video { display: block; width: 100%; max-height: 70vh; }
.video-missing {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 5;
  max-height: 60vh;
  width: 100%;
  padding: 2rem;
  background: var(--card);
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: .82rem;
  line-height: 1.7;
  text-align: center;
}

/* ---------- Carta d'imbarco ---------- */

.ticket {
  margin-top: 1.8rem;
  border: 1px solid var(--ink);
  background: var(--card);
  box-shadow: 0 24px 30px -26px rgba(29, 28, 26, .5);
  animation: ticket-in 1.1s cubic-bezier(.2, .8, .2, 1) .25s both;
}
@keyframes ticket-in { from { opacity: 0; transform: translateY(36px) rotate(-2deg); } }

.ticket-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: .8rem 1.25rem .7rem;
  border-bottom: 1px solid var(--ink);
  font-family: var(--sans);
  font-size: .64rem;
  font-weight: 500;
  letter-spacing: .24em;
  text-transform: uppercase;
}
.ticket-brand {
  font-family: var(--serif);
  font-size: 1.5rem;
  font-style: italic;
  letter-spacing: 0;
  text-transform: none;
}

.ticket-main { padding: 1.5rem 1.25rem 1.6rem; }

.route { display: flex; align-items: center; gap: .9rem; }
.route-end b {
  display: block;
  font-size: clamp(3rem, 14vw, 4.2rem);
  font-weight: 500;
  line-height: .9;
}
.route-end span { font-family: var(--sans); font-size: .74rem; font-weight: 400; color: var(--ink-soft); }
.route-to { text-align: right; }
.route-to b { color: var(--green); }
.route-path {
  flex: 1;
  display: grid;
  place-items: center;
  align-self: flex-start;
  height: clamp(3rem, 14vw, 3.7rem);
  background: linear-gradient(90deg, var(--ink-soft) 50%, transparent 0) center / 8px 1px repeat-x;
}
.route-path svg { width: 1.7rem; padding: 0 .3rem; background: var(--card); fill: var(--gold); }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem 1.25rem; margin-top: 1.6rem; }
.field-wide { grid-column: 1 / -1; }
.fields dt {
  font-family: var(--sans);
  font-size: .6rem;
  font-weight: 500;
  letter-spacing: .24em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.fields dd {
  margin-top: .15rem;
  font-family: var(--sans);
  font-size: .98rem;
  font-weight: 500;
  letter-spacing: .08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.ticket-stub { padding: 1.4rem 1.25rem 1.5rem; border-top: 1px dashed var(--ink); }
.ticket-stub .fields { margin-top: 0; }

.barcode {
  height: 42px;
  margin-top: 1.3rem;
  background: repeating-linear-gradient(90deg,
    var(--ink) 0 2px, transparent 2px 5px,
    var(--ink) 5px 6px, transparent 6px 8px,
    var(--ink) 8px 12px, transparent 12px 14px,
    var(--ink) 14px 15px, transparent 15px 19px);
}

.signature { margin-top: 2.4rem; font-size: 1.5rem; font-style: italic; line-height: 1.3; }
.signature span { display: block; margin-top: .3rem; font-size: 1.85rem; color: var(--green); }

.postscript { margin-top: 1.4rem; color: var(--ink-soft); font-size: 1.15rem; }

.diary { margin: 3.5rem 0 2rem; padding-top: 1.4rem; border-top: 1px solid var(--ink); }
.diary h3 { margin-top: .5rem; font-size: 1.9rem; font-weight: 400; }
.diary p:last-child { margin-top: .4rem; color: var(--ink-soft); }

/* ---------- Schermi larghi ---------- */

@media (min-width: 760px) {
  .stage { padding-top: 4.5rem; }
  .stage:has(.step-ticket.is-active) { width: min(100% - 4rem, 47rem); }
  .step-ticket > :not(.ticket) { max-width: 31rem; }

  .ticket { display: grid; grid-template-columns: 1fr 13.5rem; }
  .ticket-head { grid-column: 1 / -1; padding-inline: 1.75rem; }
  .ticket-main { padding: 1.9rem 1.75rem 2rem; }
  .ticket-stub {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 1.9rem 1.5rem 2rem;
    border-top: 0;
    border-left: 1px dashed var(--ink);
  }
  .ticket-stub .fields { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  body:has(#messaggio.is-active) .postcards img { animation: none; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-delay: 0s !important;
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
  }
}
