:root {
  --bg: #FBF7F2;
  --card: #FFFFFF;
  --text: #2E2A26;
  --primary: #7A8F6A;
  --accent: #C9A26B;
  --on-primary: #FFFFFF;
  --font-title: 'Playfair Display', Georgia, serif;
  --font-body: 'Lato', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 18px;
  --muted: color-mix(in srgb, var(--text) 62%, var(--bg));
  --line: color-mix(in srgb, var(--text) 14%, transparent);
  --soft: color-mix(in srgb, var(--primary) 10%, var(--card));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3 { font-family: var(--font-title); font-weight: 700; line-height: 1.2; margin: 0 0 .5em; color: var(--text); }
h1 { font-size: clamp(28px, 8vw, 40px); }
h2 { font-size: 23px; }
a { color: var(--primary); word-break: break-word; }

.view { display: none; min-height: 100dvh; }
.view.active { display: block; }

.wrap {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 18px max(32px, env(safe-area-inset-bottom));
}

/* ── Loader ── */
#loader { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; transition: opacity .3s; }
#loader.hide { opacity: 0; pointer-events: none; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Home ── */
#home .wrap { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; text-align: center; }
.ornament { color: var(--accent); font-size: 28px; letter-spacing: 10px; margin-bottom: 14px; }
.ornament.bottom { margin: 22px 0 0; }
.subtitle { color: var(--muted); margin: 0 0 22px; font-size: 18px; }

input[type=text], textarea {
  width: 100%;
  font: inherit;
  font-size: 17px; /* ≥16px evita lo zoom automatico su iPhone */
  color: var(--text);
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type=text]:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent); }
#home input { text-align: center; font-size: 19px; }
textarea { min-height: 110px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  min-height: 54px;
  margin-top: 14px;
  padding: 12px 20px;
  font: inherit; font-weight: 700; font-size: 17px; letter-spacing: .3px;
  color: var(--on-primary);
  background: var(--primary);
  border: 0; border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: transform .1s, filter .15s, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.ghost { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }

.msg { min-height: 1.4em; margin: 12px 0 0; color: #B04A3A; font-size: 15px; }
.choices { display: grid; gap: 10px; margin-top: 14px; }
.choices button {
  font: inherit; font-size: 17px; padding: 14px; border-radius: 14px; cursor: pointer;
  background: var(--card); color: var(--text); border: 1.5px solid var(--line);
}

/* ── Gioco ── */
#game { position: fixed; inset: 0; min-height: 0; overflow: hidden; background: #6ec6e8; touch-action: none; user-select: none; -webkit-user-select: none; }
#game.active { display: block; }
#game canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.game-head {
  position: absolute; left: 0; right: 0; top: 0; z-index: 2; pointer-events: none;
  padding: max(14px, env(safe-area-inset-top)) 16px 0; text-align: center;
}
.game-head h2 {
  display: inline-block; margin: 0; padding: 8px 16px; font-size: 19px;
  background: rgba(255,255,255,.88); color: #2E2A26; border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
}
.game-score { margin-top: 8px; font: 800 34px/1 var(--font-body); color: #fff; text-shadow: 0 3px 0 rgba(0,0,0,.25); }
.game-overlay {
  position: absolute; inset: 0; z-index: 3; display: none;
  align-items: center; justify-content: center; flex-direction: column; text-align: center;
  padding: 24px;
}
.game-overlay.show { display: flex; }
.pill {
  background: rgba(255,255,255,.92); color: #2E2A26; border-radius: 999px; padding: 10px 20px;
  font-weight: 700; box-shadow: 0 6px 20px rgba(0,0,0,.15); animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(1.05); } }
.retry-card {
  background: rgba(255,255,255,.95); border-radius: 22px; padding: 22px 26px; max-width: 320px; width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,.2); animation: pop .25s ease-out;
}
.retry-card h2 { color: #2E2A26; margin-bottom: 4px; }
.retry-card p { margin: 0; color: #6a625a; font-size: 15px; }
.win { background: rgba(255,255,255,.15); backdrop-filter: blur(2px); }
.win img { width: min(88vw, 420px); max-height: 50dvh; object-fit: contain; animation: grow 0.9s cubic-bezier(.2,1.3,.4,1) both; }
.win .win-box {
  margin-top: 10px; background: rgba(255,255,255,.95); border-radius: 22px; padding: 18px 22px; max-width: 360px; width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,.2); animation: rise .5s .7s both;
}
.win .win-box h2 { color: #2E2A26; font-size: 22px; margin: 0; }
.win .win-date { font-family: var(--font-title); font-weight: 700; font-size: 34px; color: #b0304f; margin: 6px 0 0; letter-spacing: 1px; }
.win .win-date:empty { display: none; }
@keyframes grow { from { transform: scale(0); opacity: 0; } 60% { opacity: 1; } to { transform: scale(1); opacity: 1; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Info / RSVP ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.05);
  border: 1px solid var(--line);
}
.hero { text-align: center; background: var(--soft); }
.hero h1 { font-size: clamp(26px, 7vw, 34px); margin: 0; }
.rich { overflow-wrap: anywhere; }
.rich p { margin: 0 0 .8em; }
.rich ol, .rich ul { margin: 0 0 .9em; padding-left: 1.3em; }
.rich li { margin-bottom: .55em; }
.rich li::marker { color: var(--primary); font-weight: 700; }
.rich strong { color: var(--primary); }

.q { margin: 0 0 20px; }
.q:last-of-type { margin-bottom: 4px; }
.q-label { display: block; font-weight: 700; margin-bottom: 10px; font-size: 18px; }
.yesno { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.yesno button {
  min-height: 50px; font: inherit; font-weight: 700; font-size: 17px; cursor: pointer;
  border-radius: 14px; border: 1.5px solid var(--line); background: var(--card); color: var(--text);
  transition: background .15s, color .15s, border-color .15s;
}
.yesno button.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.yesno button.on.no { background: var(--text); border-color: var(--text); color: var(--bg); }
.member { padding: 12px 0; border-top: 1px solid var(--line); }
.member:first-of-type { border-top: 0; padding-top: 0; }
.member-name { font-weight: 700; margin-bottom: 8px; }
.member .done { color: var(--muted); font-size: 15px; }
.extra { margin-top: 10px; }
.note { background: var(--soft); border-radius: 14px; padding: 14px 16px; margin: 0; }

/* ── PDF ── */
.pdf-card { text-align: center; }
.pdf-card h2 { font-size: 21px; margin-bottom: 4px; }
.pdf-card .pdf-date { color: var(--muted); font-size: 15px; margin: 0 0 4px; }
#pdfBoxThanks { text-align: center !important; }

/* ── Grazie ── */
#thanks .wrap { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; text-align: center; }
.big-heart { font-size: 46px; color: var(--accent); margin-bottom: 8px; }

.fade-in { animation: rise .45s ease-out both; }
