:root {
  --ink: #f3f6fb;
  --mute: #a9b8d1;
  --gold: #f3c969;
  --red: #e0372b;
  --red2: #b3202a;
  --pine: #16794f;
  --glass: rgba(8, 17, 38, 0.66);
  --line: rgba(255, 255, 255, 0.13);
  --serif: "DM Serif Display", Georgia, "Times New Roman", serif;
  --sans: Outfit, system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; min-width: 0; }
html, body { height: 100%; }
body {
  margin: 0; overflow: hidden; color: var(--ink); font: 16px/1.5 var(--sans);
  background: radial-gradient(120% 90% at 50% 100%, #1d3b73 0%, #0b1c44 45%, #030717 100%);
  -webkit-tap-highlight-color: transparent;
}
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.nogl #gl { display: none; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1, h2 { font-family: var(--serif); font-weight: 400; line-height: 1.02; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(40px, 5vw, 54px); }
h2 { font-size: clamp(30px, 4vw, 38px); }
p { margin: 0; }
b { font-weight: 600; }

/* ---------- pannelli ---------- */
#app { position: fixed; inset: 0; pointer-events: none; }
.panel {
  position: absolute; pointer-events: auto; display: flex; flex-direction: column;
  background: var(--glass); border: 1px solid var(--line); border-radius: 26px;
  backdrop-filter: blur(20px) saturate(1.35); -webkit-backdrop-filter: blur(20px) saturate(1.35);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  animation: rise 0.7s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.panel.side { left: 24px; top: 24px; bottom: 24px; width: min(410px, calc(100vw - 48px)); }
.panel.center { left: 50%; bottom: 28px; transform: translateX(-50%); width: min(540px, calc(100vw - 24px)); padding: 24px 26px 26px; text-align: center; animation-name: riseC; }
.scroll { flex: 1; overflow: auto; padding: 28px 26px 12px; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent; }
.dock { padding: 14px 26px 22px; border-top: 1px solid var(--line); }
.dock.row3 { display: flex; gap: 8px; }
.dock.row3 .btn { flex: 1; padding-inline: 8px; }
@keyframes rise { from { opacity: 0; transform: translateY(24px) scale(0.985); } }
@keyframes riseC { from { opacity: 0; transform: translateX(-50%) translateY(24px) scale(0.985); } }

.eyebrow { font-size: 13px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold); margin-bottom: 10px; font-weight: 500; }
.lead { color: var(--mute); margin-top: 12px; font-size: 16px; }
.lead.small { font-size: 15px; margin-top: 8px; }
.note { color: var(--mute); font-size: 13.5px; margin-top: 14px; }
.hint { color: var(--mute); font-size: 14px; margin-top: 10px; min-height: 1.4em; }
.err { color: #ff8f86; font-weight: 500; min-height: 1.4em; font-size: 14.5px; margin-bottom: 6px; }
.sub { color: var(--mute); font-size: 14px; margin: 14px 0 8px; }

/* ---------- form ---------- */
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; min-height: 46px;
}
textarea { resize: vertical; min-height: 64px; }
select option { color: #111; }
input::placeholder, textarea::placeholder { color: #7f90ad; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--gold); }
label { display: block; font-size: 13.5px; color: var(--mute); font-weight: 500; }
label input, label textarea { margin-top: 6px; color: var(--ink); }
.addrow { display: flex; gap: 8px; margin-top: 22px; }
.fields { display: grid; gap: 12px; padding: 4px 0 6px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pairrow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pairrow select { flex: 1 1 110px; width: auto; }
.switch { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; color: var(--ink); font-size: 15px; }
.switch input { width: 22px; height: 22px; min-height: 0; margin: 2px 0 0; accent-color: var(--red); flex: none; }
.switch small { display: block; color: var(--mute); font-size: 13px; font-weight: 400; }
.exlist { list-style: none; margin: 8px 0 0; padding: 0; }
.exlist li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--line); font-size: 15px; }

.acc { margin-top: 14px; border: 1px solid var(--line); border-radius: 16px; padding: 0 14px; background: rgba(255, 255, 255, 0.035); }
.acc summary { cursor: pointer; padding: 13px 0; font-weight: 500; list-style: none; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.acc summary::-webkit-details-marker { display: none; }
.acc summary::after { content: "+"; color: var(--gold); font-size: 20px; line-height: 1; }
.acc[open] summary::after { content: "–"; }
.acc summary small { color: var(--mute); font-weight: 400; margin-left: auto; margin-right: 6px; }
.acc[open] { padding-bottom: 12px; }

/* ---------- bottoni ---------- */
.btn {
  font: inherit; font-weight: 600; font-size: 15px; border: 0; border-radius: 14px; min-height: 46px; padding: 10px 18px;
  cursor: pointer; color: #fff; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.15s ease, filter 0.15s ease, background 0.2s;
}
.btn:hover:not(:disabled) { filter: brightness(1.1); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: linear-gradient(180deg, #2b9a68, #16794f); }
.btn.cta { width: 100%; font-size: 17px; min-height: 54px; background: linear-gradient(180deg, #ee4a3d, var(--red2)); box-shadow: 0 10px 30px -10px rgba(224, 55, 43, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.3); }
.btn.cta:not(:disabled) { animation: glow 2.6s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 10px 38px -4px rgba(255, 120, 70, 0.95), inset 0 1px 0 rgba(255, 255, 255, 0.3); } }
.btn.ghost { background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); }
.btn.wa { background: linear-gradient(180deg, #2bc46b, #1a9c52); }
.btn.sm { min-height: 40px; padding: 6px 14px; font-size: 14px; }
.linkbtn { background: none; border: 0; color: var(--mute); font: inherit; font-size: 13.5px; text-decoration: underline; cursor: pointer; margin-top: 14px; padding: 6px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.row .btn { flex: 1 1 140px; }

/* ---------- chip ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; margin: 16px 0 0; padding: 0; }
.chips.center { justify-content: center; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 6px 6px 12px; font-weight: 500; animation: pop 0.4s cubic-bezier(0.3, 1.6, 0.5, 1) both;
}
.chip i { width: 12px; height: 12px; border-radius: 4px; background: var(--c); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25); flex: none; }
.chip button { all: unset; cursor: pointer; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: var(--mute); font-size: 19px; line-height: 1; }
.chip button:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.chip button:focus-visible { outline: 3px solid var(--gold); }
.chips.pick .chip { padding: 10px 16px; cursor: pointer; font-size: 16px; }
.chips.pick .chip:hover, .chips.pick .chip:focus-visible { background: rgba(243, 201, 105, 0.2); border-color: var(--gold); }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }

/* ---------- risultati ---------- */
.tabs { display: flex; gap: 4px; margin: 18px 0 8px; padding: 4px; background: rgba(255, 255, 255, 0.06); border-radius: 14px; }
.tabs button { flex: 1; font: inherit; font-weight: 500; font-size: 14px; color: var(--mute); background: none; border: 0; border-radius: 10px; padding: 10px 6px; cursor: pointer; min-height: 42px; }
.tabs button[aria-selected="true"] { background: rgba(255, 255, 255, 0.14); color: #fff; }
.links { list-style: none; margin: 0; padding: 0; }
.links li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.links li:last-child { border: 0; }
.links strong { font-size: 17px; font-weight: 500; overflow-wrap: anywhere; }
.links li.done strong::after { content: " ✓"; color: #5be39a; }

/* ---------- rivelazione ---------- */
.bigname { font-family: var(--serif); font-size: clamp(36px, 9vw, 52px); line-height: 1.05; color: var(--gold); margin: 6px 0 4px; overflow-wrap: anywhere; text-shadow: 0 0 30px rgba(255, 170, 40, 0.5); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; text-align: left; }
.fact { background: rgba(255, 255, 255, 0.07); border-radius: 14px; padding: 10px 14px; }
.fact span { display: block; font-size: 12.5px; color: var(--mute); }
.fact b { font-size: 16px; font-weight: 500; overflow-wrap: anywhere; }
.confirm { margin-top: 18px; }
.confirm p { font-size: 18px; }

/* ---------- varie ---------- */
.caption { position: fixed; left: 50%; top: 14%; transform: translateX(-50%); z-index: 5; font-family: var(--serif); font-size: clamp(26px, 5vw, 46px); text-align: center; width: min(92vw, 800px); text-shadow: 0 0 30px rgba(255, 200, 100, 0.7), 0 2px 12px rgba(0, 0, 0, 0.6); opacity: 0; transition: opacity 0.5s; pointer-events: none; }
.caption.on { opacity: 1; }
.fab { position: fixed; right: 16px; top: 16px; z-index: 6; width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); color: #fff; display: grid; place-items: center; cursor: pointer; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: #fff; color: #10203a; padding: 10px 18px; border-radius: 999px; font-weight: 500; opacity: 0; pointer-events: none; transition: 0.3s; z-index: 10; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
body[data-view="draw"] .panel { opacity: 0; pointer-events: none; transition: opacity 0.4s; }

/* ---------- mobile: pannello come bottom-sheet ---------- */
@media (max-width: 899px) {
  .panel.side, .panel.center { left: 10px; right: 10px; width: auto; transform: none; top: auto; bottom: max(10px, env(safe-area-inset-bottom)); max-height: 56dvh; animation-name: rise; }
  .panel.center { padding: 20px 18px 20px; overflow: auto; }
  .panel.side { max-height: 58dvh; }
  .scroll { padding: 22px 18px 10px; }
  .dock { padding: 12px 18px 16px; }
  h1 { font-size: 38px; }
  .lead { font-size: 15px; }
  .fab { top: 10px; right: 10px; }
  .panel.side .scroll > .lead { display: none; }
  .panel.side { max-height: 52dvh; }
}
@media (max-height: 640px) and (max-width: 899px) { .panel.side { max-height: 64dvh; } .lead { display: none; } }
@media (prefers-reduced-motion: reduce) {
  .panel, .chip, .btn.cta:not(:disabled) { animation: none !important; }
  * { transition-duration: 0.01ms !important; }
}

/* rivelazione: pannello compatto, il nome grande lo mostra la scena 3D */
#pRev.done > .eyebrow, #pRev.done > h2 { display: none; }
#pRev.done .lead { margin-top: 0; }
#pRev.done .bigname { font-size: clamp(32px, 7vw, 42px); margin: 2px 0 0; }
#pRev.done .facts { margin-top: 10px; gap: 8px; }
#pRev.done .fact { padding: 7px 12px; }
#pRev.done .fact b { font-size: 15px; }
#pRev.done .note { margin-top: 10px; }
#pRev.done .row { margin-top: 10px; }
