:root {
  /* Colori (modificabili dal pannello Personalizza) */
  --bg: #f6f1e7;
  --paper: #fffdf8;
  --ink: #3e3a33;
  --primary: #5b6b4a;
  --accent: #b8955a;
  --envelope: #e9dfcc;
  --seal: #8c2f2f;

  /* Caratteri */
  --f-script: "Great Vibes", cursive;
  --f-title: "Cormorant Garamond", serif;
  --f-body: "Montserrat", sans-serif;
  --f-seal: "Great Vibes", cursive;

  --radius: 14px;
  --shadow: 0 10px 30px rgb(0 0 0 / .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-weight: 300;
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: lining-nums;
  overflow-x: hidden;
}
body.locked { overflow: hidden; height: 100vh; }
img { max-width: 100%; }
h1, h2, h3 { font-family: var(--f-title); font-weight: 500; color: var(--primary); line-height: 1.2; margin: 0 0 .6em; }
h2 { font-size: clamp(2rem, 6vw, 2.8rem); text-align: center; }
h3 { font-size: 1.5rem; }
a { color: var(--primary); }

/* ============ BUSTA ============ */
#envelope-screen {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background:
    radial-gradient(circle at 20% 15%, rgb(255 255 255 / .6), transparent 50%),
    radial-gradient(circle at 80% 90%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 55%),
    var(--bg);
  transition: opacity 1s ease, visibility 1s;
}
#envelope-screen.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.env-wrap { display: flex; flex-direction: column; align-items: center; gap: 2.2rem; padding: 16px; }
.envelope {
  position: relative;
  width: min(86vw, 440px);
  aspect-ratio: 1.45;
  perspective: 1200px;
  filter: drop-shadow(0 18px 30px rgb(0 0 0 / .18));
  transition: transform 1s ease;
}
.env-back, .env-pocket, .env-flap { position: absolute; inset: 0; border-radius: 6px; }
.env-back { background: color-mix(in srgb, var(--envelope) 82%, #000); }
.env-pocket {
  z-index: 3;
  background:
    linear-gradient(to top right, transparent 49.6%, rgb(0 0 0 / .05) 50%, transparent 50.4%),
    linear-gradient(to top left, transparent 49.6%, rgb(0 0 0 / .05) 50%, transparent 50.4%),
    var(--envelope);
  clip-path: polygon(0 0, 50% 52%, 100% 0, 100% 100%, 0 100%);
}
.env-flap {
  z-index: 4;
  background: linear-gradient(to bottom, color-mix(in srgb, var(--envelope) 94%, #000), var(--envelope));
  clip-path: polygon(0 0, 100% 0, 50% 58%);
  transform-origin: top center;
  transition: transform .9s cubic-bezier(.6,.05,.35,1), z-index 0s .45s;
}
.env-card {
  position: absolute; z-index: 2;
  left: 6%; right: 6%; top: 6%; bottom: 6%;
  background: var(--paper);
  border-radius: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem;
  text-align: center; padding: 1rem; overflow: hidden;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent) inset, 0 0 0 7px var(--paper) inset, 0 0 0 8px color-mix(in srgb, var(--accent) 50%, transparent) inset;
  transition: transform 1.1s cubic-bezier(.3,.7,.3,1) .8s;
}
.card-small { font-family: var(--f-title); letter-spacing: .25em; text-transform: uppercase; font-size: .72rem; color: var(--accent); }
.card-names { font-family: var(--f-script); font-size: clamp(1.8rem, 7vw, 2.6rem); color: var(--primary); line-height: 1.15; }

.seal {
  position: absolute; z-index: 5;
  left: 50%; top: 58%;
  width: 92px; height: 92px;
  transform: translate(-50%, -50%);
  border: 0; padding: 0; background: none; cursor: pointer;
  transition: transform .5s ease, opacity .5s ease;
  animation: pulse 2.4s ease-in-out infinite;
}
.seal svg { width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 3px 4px rgb(0 0 0 / .35)); }
.seal-wax { fill: var(--seal); }
.seal-ring { fill: none; stroke: color-mix(in srgb, var(--seal) 70%, #000); stroke-width: 2.5; opacity: .7; }
.seal-ring.thin { stroke-width: 1; opacity: .5; }
.seal-text { font-family: var(--f-seal); font-weight: 400; font-size: 34px; fill: color-mix(in srgb, var(--seal) 45%, #000); stroke: color-mix(in srgb, var(--seal) 45%, #000); stroke-width: .4px; paint-order: stroke; opacity: .92; }
.seal-amp { font-size: .62em; }
.seal:focus-visible { outline: 2px dashed var(--accent); outline-offset: 6px; border-radius: 50%; }
@keyframes pulse { 50% { transform: translate(-50%, -50%) scale(1.06); } }

.env-hint { font-family: var(--f-title); font-style: italic; font-size: 1.2rem; color: var(--primary); margin: 0; animation: fade 2.4s ease-in-out infinite; }
@keyframes fade { 50% { opacity: .45; } }

/* apertura */
.envelope.open .seal { animation: none; transform: translate(-50%, -50%) scale(1.4); opacity: 0; pointer-events: none; }
.envelope.open .env-flap { transform: rotateX(180deg); z-index: 1; }
.envelope.open .env-card { transform: translateY(-58%); }
.envelope.open + .env-hint { opacity: 0; animation: none; transition: opacity .3s; }
.envelope.zoom { transform: translateY(12%) scale(1.08); }

/* ============ SITO ============ */
#site { opacity: 0; transition: opacity 1.2s ease .2s; }
body:not(.locked) #site { opacity: 1; }

.section { padding: clamp(4rem, 10vw, 6.5rem) 16px; max-width: 1040px; margin: 0 auto; text-align: center; }
.section.narrow { max-width: 680px; }
.section.alt { max-width: none; background: var(--paper); }
.section.alt > * { max-width: 1040px; margin-left: auto; margin-right: auto; }
.section.alt > .form { max-width: 680px; }
.section.alt > .thanks { max-width: 520px; }
.sub { margin-top: -.4rem; margin-bottom: 2.2rem; }

.hero {
  min-height: 100svh;
  display: grid; place-items: center; position: relative;
  padding: 48px 40px; text-align: center;
  background:
    radial-gradient(ellipse at top, rgb(255 255 255 / .7), transparent 60%),
    radial-gradient(ellipse at bottom, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    var(--bg);
}
.hero::before {
  content: ""; position: absolute; inset: 18px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 4px; pointer-events: none;
}
.overline { font-family: var(--f-title); text-transform: uppercase; letter-spacing: .4em; color: var(--accent); font-size: .9rem; margin: 0 0 .8rem; }
.names { font-family: var(--f-script); font-weight: 400; font-size: clamp(3rem, 12vw, 6.5rem); color: var(--primary); margin: 0; line-height: 1.1; }
.names .amp { display: block; font-size: .55em; color: var(--accent); margin: .1em 0; }
.names.small { font-size: 2.4rem; }
.hero-date { font-family: var(--f-title); font-size: clamp(1.3rem, 4vw, 1.7rem); letter-spacing: .08em; margin: .3rem 0 0; }
.hero-place { text-transform: uppercase; letter-spacing: .2em; font-size: .74rem; line-height: 1.9; margin: .6rem 0 0; }
.hero-place span { white-space: nowrap; }
.hero-place span + span::before { content: "·"; margin: 0 .8em; color: var(--accent); }
@media (max-width: 720px) {
  .hero-place { letter-spacing: .14em; }
  .hero-place span { display: block; }
  .hero-place span + span::before { content: none; }
}
.divider { display: flex; align-items: center; justify-content: center; gap: .8rem; color: var(--accent); margin: 1.4rem auto 1rem; }
.divider span { width: 60px; height: 1px; background: currentColor; opacity: .6; }
.scroll-cue { position: absolute; bottom: 36px; left: 50%; transform: translateX(-50%); font-size: 2rem; text-decoration: none; color: var(--accent); animation: bounce 2s infinite; }
@keyframes bounce { 50% { transform: translate(-50%, 8px); } }

.lead { font-family: var(--f-title); font-size: clamp(1.4rem, 4.5vw, 1.9rem); font-style: italic; line-height: 1.5; margin: 0 0 2.5rem; }

.countdown { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; max-width: 460px; margin: 0 auto 2rem; }
.countdown div { background: var(--paper); border-radius: var(--radius); padding: .9rem .2rem; box-shadow: var(--shadow); }
.countdown b { display: block; font-family: var(--f-title); font-size: clamp(1.7rem, 7vw, 2.4rem); font-weight: 500; color: var(--primary); line-height: 1.1; }
.countdown span { font-size: .68rem; text-transform: uppercase; letter-spacing: .12em; }

.btn {
  display: inline-block; cursor: pointer;
  font: 600 .8rem/1 var(--f-body); letter-spacing: .18em; text-transform: uppercase; text-decoration: none;
  padding: 1.05rem 1.9rem; border-radius: 999px;
  background: var(--primary); color: var(--paper); border: 1px solid var(--primary);
  transition: transform .2s, background .2s, color .2s;
}
.btn:hover { transform: translateY(-2px); }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.ghost:hover { background: var(--primary); color: var(--paper); }
.btn.small { padding: .75rem 1.2rem; font-size: .7rem; }
.btn:disabled { opacity: .6; cursor: wait; transform: none; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1.2rem; margin-bottom: 2rem; }
.card { background: var(--bg); border-radius: var(--radius); padding: 2rem 1.4rem; box-shadow: var(--shadow); }
.card .icon { font-size: 1.8rem; color: var(--accent); }
.card .kind { font-family: var(--f-title); text-transform: uppercase; letter-spacing: .3em; color: var(--accent); font-size: .85rem; }
.card h3 { margin: .3rem 0 .2rem; }
.card .time { font-family: var(--f-title); font-size: 1.6rem; color: var(--ink); }
.card p { margin: .2rem 0 1.2rem; }
.map-tabs { display: flex; justify-content: center; gap: .5rem; margin-bottom: 1rem; }
.map-tabs button { font: 600 .72rem var(--f-body); letter-spacing: .15em; text-transform: uppercase; padding: .65rem 1.2rem; border-radius: 999px; cursor: pointer; border: 1px solid var(--primary); background: transparent; color: var(--primary); }
.map-tabs button[aria-selected="true"] { background: var(--primary); color: var(--paper); }
.map { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); height: 320px; }
.map iframe { width: 100%; height: 100%; border: 0; filter: saturate(.75); }

.timeline { list-style: none; padding: 0; margin: 0 auto; position: relative; text-align: left; max-width: 480px; }
.timeline::before { content: ""; position: absolute; left: 78px; top: 8px; bottom: 8px; width: 1px; background: color-mix(in srgb, var(--accent) 60%, transparent); }
.timeline li { display: grid; grid-template-columns: 64px 1fr; gap: 30px; padding: .9rem 0; position: relative; }
.timeline li::before { content: ""; position: absolute; left: 73px; top: 1.45rem; width: 11px; height: 11px; border-radius: 50%; background: var(--bg); border: 2px solid var(--accent); }
.timeline .t { font-family: var(--f-title); font-size: 1.4rem; color: var(--accent); text-align: right; }
.timeline h3 { font-size: 1.3rem; margin: 0; }
.timeline p { margin: 0; font-size: .92rem; }

/* RSVP */
.form { max-width: 620px; text-align: left; background: var(--bg); padding: clamp(1.4rem, 5vw, 2.4rem); border-radius: var(--radius); box-shadow: var(--shadow); }
.field { margin: 0 0 1.2rem; border: 0; padding: 0; min-width: 0; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 520px) { .row { grid-template-columns: 1fr; } }
label, legend { display: block; font-size: .78rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; margin-bottom: .4rem; color: var(--primary); }
input, select, textarea {
  width: 100%; font: 400 1rem var(--f-body); color: var(--ink);
  background: var(--paper); border: 1px solid color-mix(in srgb, var(--ink) 18%, transparent);
  border-radius: 10px; padding: .8rem .9rem; outline: none; transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.choice { display: flex; flex-wrap: wrap; gap: .5rem; }
.choice legend { width: 100%; }
.pill { margin: 0; text-transform: none; letter-spacing: 0; font-weight: 400; font-size: .92rem; color: var(--ink); cursor: pointer; }
.pill input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pill span { display: inline-block; padding: .55rem 1rem; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--ink) 22%, transparent); background: var(--paper); transition: all .2s; }
.pill input:checked + span { background: var(--primary); color: var(--paper); border-color: var(--primary); }
.pill input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.hp { position: absolute; left: -9999px; }
.stepper { display: inline-flex; align-items: center; background: var(--paper); border: 1px solid color-mix(in srgb, var(--ink) 18%, transparent); border-radius: 999px; overflow: hidden; }
.stepper button { width: 48px; height: 46px; border: 0; background: none; font-size: 1.4rem; color: var(--primary); cursor: pointer; }
.stepper button:hover { background: color-mix(in srgb, var(--primary) 10%, transparent); }
.stepper output { min-width: 2.4rem; text-align: center; font-family: var(--f-title); font-size: 1.5rem; color: var(--primary); }
.ospiti { display: grid; gap: 1rem; margin-bottom: 1.2rem; }
.ospite { background: var(--paper); border-radius: var(--radius); padding: 1.1rem 1.1rem .2rem; border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.ospite-head { font-family: var(--f-title); font-size: 1.2rem; color: var(--accent); margin-bottom: .6rem; }
.ospite .pill span { padding: .45rem .85rem; font-size: .86rem; }
.form-error { color: #b3261e; font-size: .9rem; min-height: 1.2em; margin: 0 0 .6rem; }
.form .btn { width: 100%; }
.thanks { max-width: 520px; margin: 0 auto; background: var(--bg); padding: 2.5rem 1.5rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.thanks-icon { font-size: 3rem; color: var(--accent); line-height: 1; }

/* Regalo */
.iban-card { display: grid; gap: .15rem; background: var(--paper); border-radius: var(--radius); padding: 2rem 1.4rem; box-shadow: var(--shadow); margin-top: 1.6rem; border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.iban-card .label { font-size: .7rem; text-transform: uppercase; letter-spacing: .2em; color: var(--accent); margin-top: .7rem; }
.iban-card .label:first-child { margin-top: 0; }
.iban-card code { font-family: var(--f-body); font-size: clamp(.95rem, 4.2vw, 1.25rem); font-weight: 600; letter-spacing: .06em; color: var(--primary); word-break: break-word; }
.iban-card .btn { justify-self: center; margin-top: 1.2rem; }

/* Foto */
.qr { display: block; width: fit-content; margin-left: auto; margin-right: auto; background: #fff; padding: 18px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1.6rem; }
.btn-row { display: flex; flex-wrap: wrap; justify-content: center; gap: .8rem; }
.qr img, .qr canvas { display: block; width: 180px; height: 180px; }

/* Info */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 2rem; text-align: left; align-items: stretch; }
.info-grid > div { display: flex; flex-direction: column; }
.info-grid h3 { text-align: center; }
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: .8rem; grid-auto-rows: 1fr; flex: 1; }
.list li { min-height: 128px; display: flex; flex-direction: column; justify-content: center; background: var(--paper); border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.list b { display: block; font-family: var(--f-title); font-size: 1.2rem; font-weight: 600; color: var(--primary); }
.list small { color: var(--accent); text-transform: uppercase; letter-spacing: .1em; font-size: .72rem; }
.list p { margin: .2rem 0 0; font-size: .92rem; }

.footer { text-align: center; padding: 4rem 16px 6rem; background: var(--paper); }
.footer p { margin: .3rem 0; }
.seal-mini { width: 72px; height: 72px; margin: 0 auto 1rem; }
.seal-mini svg { width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 2px 3px rgb(0 0 0 / .3)); }
.full-names { font-family: var(--f-title); letter-spacing: .12em; text-transform: uppercase; font-size: .8rem; color: var(--accent); margin-bottom: 1rem !important; }
.credit { font-size: .7rem; opacity: .6; margin-top: 1.5rem !important; }

/* Rivelazione allo scroll */
.reveal { opacity: 0; transform: translateY(24px); transition: opacity .9s ease, transform .9s ease; }
.reveal.in { opacity: 1; transform: none; }

/* Musica */
.music-btn {
  position: fixed; right: 16px; bottom: 16px; z-index: 50;
  width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--primary); color: var(--paper); box-shadow: var(--shadow);
  display: grid; place-items: center;
}
.bars { display: flex; gap: 3px; align-items: flex-end; height: 16px; }
.bars i { width: 3px; background: currentColor; height: 4px; border-radius: 2px; }
.music-btn.playing .bars i { animation: eq 1s ease-in-out infinite; }
.music-btn.playing .bars i:nth-child(2) { animation-delay: .2s; }
.music-btn.playing .bars i:nth-child(3) { animation-delay: .4s; }
@keyframes eq { 0%, 100% { height: 4px; } 50% { height: 16px; } }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translate(-50%, 20px); z-index: 300;
  background: var(--ink); color: var(--paper); padding: .7rem 1.2rem; border-radius: 999px; font-size: .88rem;
  opacity: 0; pointer-events: none; transition: all .3s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ============ PANNELLO PERSONALIZZA ============ */
.custom-btn {
  position: fixed; left: 16px; bottom: 16px; z-index: 210;
  border: 0; border-radius: 999px; padding: .8rem 1.1rem; cursor: pointer;
  font: 600 .85rem var(--f-body); background: #1f1f1f; color: #fff; box-shadow: 0 6px 20px rgb(0 0 0 / .25);
}
.custom-panel {
  position: fixed; z-index: 220; top: 0; left: 0; bottom: 0; width: min(340px, 100vw);
  background: #fff; color: #222; font-family: "Montserrat", sans-serif; font-size: 14px;
  box-shadow: 8px 0 30px rgb(0 0 0 / .2); display: flex; flex-direction: column;
  transform: translateX(-105%); transition: transform .35s ease;
}
.custom-panel.open { transform: none; }
.custom-panel header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid #eee; }
.custom-panel header button { border: 0; background: none; font-size: 1.1rem; cursor: pointer; }
.cp-body { padding: 4px 16px 24px; overflow-y: auto; }
.cp-body h4 { margin: 18px 0 8px; font-size: .72rem; text-transform: uppercase; letter-spacing: .12em; color: #777; }
.cp-body select { font-size: 14px; padding: .55rem .7rem; background: #fafafa; color: #222; border-color: #ddd; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.preset { border: 2px solid transparent; border-radius: 10px; padding: 8px; cursor: pointer; background: #f5f5f5; text-align: left; font: 500 12px "Montserrat", sans-serif; color: #222; }
.preset.active { border-color: #222; }
.preset .sw { display: flex; height: 22px; border-radius: 6px; overflow: hidden; margin-bottom: 6px; }
.preset .sw i { flex: 1; }
.colors { display: grid; gap: 8px; }
.colors label { display: flex; align-items: center; justify-content: space-between; text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 13px; color: #222; margin: 0; }
.colors input[type=color] { width: 44px; height: 30px; padding: 2px; border-radius: 6px; border: 1px solid #ddd; background: #fff; cursor: pointer; }
.cp-actions { display: grid; gap: 8px; margin-top: 22px; }
.custom-panel .btn { background: #1f1f1f; border-color: #1f1f1f; color: #fff; width: 100%; }
.custom-panel .btn.ghost { background: #fff; color: #1f1f1f; }
.cp-note { font-size: 12px; color: #777; }

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

/* ============ PAGINA CARICAMENTO FOTO ============ */
.foto-page main { min-height: 100svh; padding-top: 3.5rem; }
.foto-page .names { font-size: clamp(2.8rem, 11vw, 4.5rem); }
.foto-page .lead { font-size: 1.3rem; margin-bottom: 1.8rem; }
.upload-box { margin: 0 auto; }
.upload-box .pick { display: block; text-align: center; padding: 1.3rem; font-size: .85rem; }
.upload-box .hint { font-size: .82rem; text-align: center; margin: .8rem 0 0; }
.upload-box .summary { text-align: center; font-weight: 600; color: var(--primary); margin: 1rem 0 0; min-height: 1.4em; }
.uploads { list-style: none; padding: 0; margin: 1rem 0 0; display: grid; gap: .5rem; }
.uploads li { display: grid; grid-template-columns: 48px 1fr 36px; align-items: center; gap: .8rem; background: var(--paper); border-radius: 10px; padding: .45rem .6rem; font-size: .85rem; }
.uploads .th { width: 48px; height: 48px; border-radius: 8px; background: color-mix(in srgb, var(--accent) 20%, var(--paper)) center / cover; display: grid; place-items: center; font-size: 1.3rem; }
.uploads .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads .st { text-align: center; font-size: 1.2rem; color: var(--accent); }
.uploads li.ok .st { color: var(--primary); font-weight: 700; }
.uploads li.err .nm { color: #b3261e; white-space: normal; }
.uploads li.err button { border: 1px solid #b3261e; color: #b3261e; background: none; border-radius: 50%; width: 32px; height: 32px; font-size: 1rem; cursor: pointer; }
.spin { display: inline-block; width: 18px; height: 18px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.back { margin-top: 2rem; font-size: .9rem; }
