:root {
  --pine: #10241C;
  --pine-2: #183428;
  --pine-3: #23473A;
  --holly: #E0234E;
  --holly-dark: #B5163B;
  --gold: #E9B949;
  --gold-soft: #F6E3AE;
  --snow: #F6F8FA;
  --ice: #A8D3E6;
  --ink: #17202A;
  --ink-soft: #55606C;
  --line: #DCE3E8;
  --ok: #2E9E6A;
  --display: 'Bricolage Grotesque', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --r-panel: 22px;
  --r-tile: 12px;
  --tab-h: 68px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--pine);
  color: var(--snow);
  font: 17px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; border-radius: 6px; }

#snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
#app { position: relative; z-index: 1; max-width: 560px; margin: 0 auto; padding: 18px 16px calc(var(--tab-h) + 32px); }
body.no-tabs #app { padding-bottom: 40px; }

/* ---------- Testata ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { width: 38px; height: 38px; flex: none; }
.brand-name { font: 800 21px/1 var(--display); letter-spacing: -0.02em; }
.brand-sub { display: block; font: 500 12px/1.2 var(--body); color: var(--ice); margin-top: 3px; }
.me-chip { display: flex; align-items: center; gap: 8px; background: var(--pine-2); border: 1px solid var(--pine-3); border-radius: 999px; padding: 5px 12px 5px 6px; text-decoration: none; font-size: 15px; }
.me-chip .av { font-size: 22px; width: 30px; height: 30px; display: grid; place-items: center; background: var(--pine-3); border-radius: 50%; }

/* ---------- Tipografia ---------- */
h1, h2, h3 { font-family: var(--display); letter-spacing: -0.02em; margin: 0; }
h1 { font-size: 34px; line-height: 1.05; font-weight: 800; }
h2 { font-size: 23px; line-height: 1.15; font-weight: 700; }
h3 { font-size: 18px; line-height: 1.25; font-weight: 700; }
.lead { color: var(--ice); font-size: 18px; margin: 10px 0 0; }
.muted { color: var(--ink-soft); }
.on-dark .muted, .muted-dark { color: #A9BDB4; }
.small { font-size: 14px; }
p { margin: 8px 0; }

/* ---------- Pannelli ---------- */
.panel { background: var(--snow); color: var(--ink); border-radius: var(--r-panel); padding: 20px; margin: 14px 0; }
.panel.dark { background: var(--pine-2); color: var(--snow); border: 1px solid var(--pine-3); }
.panel h2 + p, .panel h3 + p { margin-top: 6px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.section-title { margin: 28px 4px 4px; }
.section-title + .muted-dark { margin: 2px 4px 0; }

/* ---------- Bottoni ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 14px; padding: 13px 20px; cursor: pointer;
  font: 700 17px/1.2 var(--display); text-decoration: none;
  background: var(--holly); color: #fff;
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:hover { background: var(--holly-dark); }
.btn.block { width: 100%; }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.gold:hover { background: #DDA935; }
.btn.ghost { background: transparent; color: inherit; border: 2px solid currentColor; }
.btn.ghost:hover { background: rgba(127,127,127,.12); }
.btn.quiet { background: rgba(127,127,127,.14); color: inherit; }
.btn.quiet:hover { background: rgba(127,127,127,.24); }
.btn.small { padding: 8px 14px; font-size: 15px; border-radius: 10px; }
.btn.danger { background: transparent; color: var(--holly); border: 2px solid var(--holly); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > .btn { flex: 1 1 auto; }
.stack > * + * { margin-top: 10px; }

/* ---------- Form ---------- */
label.field { display: block; margin: 14px 0; }
label.field > span { display: block; font-weight: 700; margin-bottom: 6px; }
label.field > small { display: block; color: var(--ink-soft); margin-top: 5px; font-size: 14px; }
.input, textarea.input, select.input {
  width: 100%; border: 2px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 12px; padding: 12px 14px; font-size: 17px; outline: none;
}
.input:focus { border-color: var(--pine-3); }
textarea.input { min-height: 84px; resize: vertical; }
.pin-input { letter-spacing: .5em; font: 700 26px/1 var(--display); text-align: center; }
.code-input { letter-spacing: .3em; font: 800 28px/1 var(--display); text-align: center; text-transform: uppercase; }

.tabs { display: grid; grid-template-columns: 1fr 1fr; background: #E6ECEF; border-radius: 14px; padding: 4px; margin-bottom: 6px; }
.tabs button { border: 0; background: transparent; padding: 10px; border-radius: 11px; font-weight: 700; cursor: pointer; color: var(--ink-soft); }
.tabs button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(16,36,28,.15); }

/* ---------- Chip interessi ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 13px; border-radius: 999px;
  border: 2px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; font-size: 15px; font-weight: 700;
  user-select: none;
}
.chip.on { background: var(--pine); border-color: var(--pine); color: #fff; }
.chip.static { cursor: default; }
.chip .x { opacity: .6; margin-left: 2px; }
.chip.gold { background: var(--gold-soft); border-color: var(--gold); }
.budget-chips .chip.on { background: var(--holly); border-color: var(--holly); }

.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 8px; }
.avatar-grid button { font-size: 26px; height: 50px; border-radius: 14px; border: 2px solid var(--line); background: #fff; cursor: pointer; }
.avatar-grid button.on { border-color: var(--holly); background: #FDE8ED; }

/* ---------- Benvenuto ---------- */
.hero { padding: 26px 4px 8px; }
.hero h1 { font-size: 44px; line-height: .98; }
.hero h1 .line2 { display: block; color: var(--gold); }
.how { list-style: none; padding: 0; margin: 22px 0 6px; display: grid; gap: 12px; }
.how li { display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: start; color: var(--snow); }
.how .n { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--gold); color: var(--gold); display: grid; place-items: center; font: 800 18px/1 var(--display); }
.how b { display: block; font-family: var(--display); font-size: 18px; }
.how span { color: #B9CCC3; font-size: 15px; }

.invite-banner { background: var(--gold); color: var(--ink); border-radius: var(--r-panel); padding: 16px 18px; display: flex; gap: 14px; align-items: center; margin: 14px 0; }
.invite-banner .big { font-size: 38px; }

/* ---------- Gruppi ---------- */
.group-card { display: grid; grid-template-columns: 54px 1fr auto; gap: 14px; align-items: center; text-decoration: none; background: var(--snow); color: var(--ink); border-radius: var(--r-panel); padding: 16px; margin: 10px 0; }
.group-card .emo { font-size: 32px; width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; background: #E8EFEC; }
.group-card h3 { font-size: 19px; }
.group-card .meta { font-size: 14px; color: var(--ink-soft); }
.badge { display: inline-block; font: 700 12px/1 var(--body); padding: 5px 9px; border-radius: 999px; background: #E8EFEC; color: var(--pine); }
.badge.red { background: var(--holly); color: #fff; }
.badge.gold { background: var(--gold); color: var(--ink); }
.badge.ok { background: #D7F0E3; color: #17704A; }

.group-hero { padding: 8px 4px 4px; }
.group-hero .emo { font-size: 46px; line-height: 1; }
.group-hero h1 { margin-top: 8px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 16px; }
.fact { background: var(--pine-2); border: 1px solid var(--pine-3); border-radius: 16px; padding: 12px 14px; }
.fact b { display: block; font: 800 24px/1.1 var(--display); color: var(--gold); }
.fact span { font-size: 14px; color: #B9CCC3; }
.message-note { margin-top: 14px; padding: 12px 16px; border-left: 4px solid var(--gold); color: var(--snow); background: rgba(233,185,73,.08); border-radius: 0 12px 12px 0; font-style: italic; }

.code-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--pine); color: #fff; border-radius: 16px; padding: 14px 18px; margin: 10px 0 12px; }
.code-box b { font: 800 32px/1 var(--display); letter-spacing: .18em; color: var(--gold); }

.members { list-style: none; padding: 0; margin: 8px 0 0; }
.members li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.members li:last-child { border-bottom: 0; }
.members .av { font-size: 24px; width: 40px; height: 40px; border-radius: 50%; background: #EEF2F4; display: grid; place-items: center; flex: none; }
.members .nm { flex: 1; font-weight: 700; }
.members .nm small { display: block; font-weight: 400; color: var(--ink-soft); font-size: 13px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 18px; padding: 6px 8px; border-radius: 8px; color: var(--ink-soft); }
.icon-btn:hover { background: #EEF2F4; }

.progress { height: 12px; background: #E3E9EC; border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.progress > i { display: block; height: 100%; background: var(--ok); border-radius: 999px; transition: width .4s ease; }

/* ---------- Bustina e carta (la rivelazione) ---------- */
.pack-stage { perspective: 1200px; display: grid; place-items: center; padding: 18px 0 8px; }
.pack {
  position: relative; width: 230px; height: 340px; border: 0; padding: 0; cursor: pointer; border-radius: 14px;
  background:
    repeating-linear-gradient(115deg, rgba(255,255,255,.0) 0 18px, rgba(255,255,255,.08) 18px 20px),
    linear-gradient(160deg, var(--holly) 0%, #8E0F2D 70%);
  box-shadow: 0 20px 40px rgba(0,0,0,.45), inset 0 0 0 3px rgba(233,185,73,.8);
  color: #fff; overflow: hidden;
}
.pack::before, .pack::after { /* bordi seghettati della bustina */
  content: ''; position: absolute; left: 0; right: 0; height: 12px;
  background: linear-gradient(135deg, transparent 6px, #C6C9CC 0) 0 0/12px 12px, linear-gradient(225deg, transparent 6px, #C6C9CC 0) 0 0/12px 12px;
  opacity: .9;
}
.pack::before { top: 0; }
.pack::after { bottom: 0; transform: rotate(180deg); }
.pack .pack-top { position: absolute; top: 0; left: 0; right: 0; height: 62px; border-bottom: 2px dashed rgba(255,255,255,.55); transition: transform .5s cubic-bezier(.3,.7,.3,1), opacity .5s; transform-origin: 10% 100%; }
.pack .pack-brand { position: absolute; top: 80px; left: 0; right: 0; text-align: center; font: 800 26px/1 var(--display); letter-spacing: -0.01em; }
.pack .pack-brand small { display: block; font: 700 13px/1.4 var(--body); color: var(--gold-soft); letter-spacing: .04em; margin-top: 6px; }
.pack .pack-art { position: absolute; top: 140px; left: 0; right: 0; text-align: center; font-size: 84px; line-height: 1; filter: drop-shadow(0 6px 10px rgba(0,0,0,.35)); }
.pack .pack-cta { position: absolute; bottom: 28px; left: 0; right: 0; text-align: center; font: 700 15px/1.3 var(--body); }
.pack:not(.torn) { animation: wiggle 3.2s ease-in-out infinite; }
.pack.torn .pack-top { transform: translate(40px, -60px) rotate(-24deg); opacity: 0; }
.pack.torn { animation: none; transition: transform .6s .35s ease, opacity .4s .55s; transform: translateY(160px) scale(.9); opacity: 0; }
@keyframes wiggle { 0%, 86%, 100% { transform: rotate(0); } 90% { transform: rotate(-3deg); } 94% { transform: rotate(3deg); } 97% { transform: rotate(-1deg); } }

.tcard-wrap { perspective: 1200px; }
.tcard {
  position: relative; border-radius: 20px; padding: 10px; color: var(--ink);
  background: linear-gradient(145deg, #F3D27A, var(--gold) 40%, #B9892A 100%);
  box-shadow: 0 18px 40px rgba(0,0,0,.4);
  transform-style: preserve-3d;
}
.tcard.enter { animation: cardIn .9s cubic-bezier(.2,.8,.2,1) both; }
@keyframes cardIn { 0% { transform: translateY(80px) rotateY(180deg) scale(.8); opacity: 0; } 60% { opacity: 1; } 100% { transform: none; } }
.tcard-inner { background: var(--snow); border-radius: 13px; overflow: hidden; }
.tcard-name { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: #fff; border-bottom: 2px solid var(--gold); }
.tcard-name h2 { font-size: 24px; }
.tcard-name .lvl { font: 800 14px/1 var(--display); color: var(--holly); }
.tcard-art {
  position: relative; height: 150px; display: grid; place-items: center; font-size: 86px;
  background: radial-gradient(circle at 50% 120%, var(--pine-3), var(--pine) 70%);
  overflow: hidden;
}
.tcard-art::after { /* riflesso olografico */
  content: ''; position: absolute; inset: -50%;
  background: linear-gradient(115deg, transparent 35%, rgba(168,211,230,.35) 45%, rgba(233,185,73,.35) 50%, rgba(224,35,78,.25) 55%, transparent 65%);
  transform: translateX(var(--holo, -30%));
  transition: transform .2s ease-out;
  mix-blend-mode: screen;
}
.tcard-body { padding: 12px 16px 16px; }
.tcard-type { font-size: 13px; color: var(--ink-soft); border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 10px; }
.attr { display: grid; grid-template-columns: 26px 1fr; gap: 8px; padding: 6px 0; }
.attr .ic { font-size: 18px; }
.attr b { display: block; font-size: 14px; }
.attr p { margin: 2px 0 0; font-size: 15px; }
.tcard-foot { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-soft); padding: 8px 16px 10px; border-top: 1px solid var(--line); }

/* ---------- Prodotti ---------- */
.products { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 12px; }
.product { position: relative; background: #fff; border: 1px solid var(--line); border-radius: var(--r-tile); overflow: hidden; display: flex; flex-direction: column; color: var(--ink); }
.product .img { aspect-ratio: 1; background: #EEF2F4; display: grid; place-items: center; font-size: 44px; }
.product .img img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.product .info { padding: 10px 11px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.product .t { font-size: 14px; line-height: 1.3; font-weight: 700; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.product .p { font: 800 18px/1 var(--display); color: var(--holly); margin-top: auto; padding-top: 6px; }
.product .go { font-size: 13px; font-weight: 700; color: var(--pine-3); text-decoration: underline; }
.heart { position: absolute; top: 8px; right: 8px; width: 38px; height: 38px; border-radius: 50%; border: 0; background: rgba(255,255,255,.95); color: var(--holly); font-size: 22px; line-height: 1; cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.heart.on { background: var(--holly); color: #fff; }
.empty { text-align: center; padding: 22px 10px; color: var(--ink-soft); }
.empty .big { font-size: 40px; display: block; margin-bottom: 6px; }

/* ---------- Domande ---------- */
.qa { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 10px 0; background: #fff; }
.qa .q { font-weight: 700; }
.qa .a { margin-top: 6px; padding-left: 10px; border-left: 3px solid var(--ok); }
.qa .wait { color: var(--ink-soft); font-size: 14px; margin-top: 4px; }

/* ---------- Avvisi ---------- */
.alert { display: flex; gap: 12px; align-items: center; background: var(--gold); color: var(--ink); border-radius: 16px; padding: 14px 16px; margin: 12px 0; text-decoration: none; font-weight: 700; }
.alert .big { font-size: 28px; }
.alert.red { background: var(--holly); color: #fff; }
.promo { border: 2px dashed var(--gold); border-radius: 18px; padding: 14px 16px; color: var(--gold-soft); margin: 18px 0; }
.promo b { color: var(--gold); }

/* ---------- Barra in basso ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(16,36,28,.96); backdrop-filter: blur(8px); border-top: 1px solid var(--pine-3);
  display: grid; grid-template-columns: repeat(3, 1fr);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: #9FB4AA; font-size: 13px; font-weight: 700; }
.tabbar a .i { font-size: 22px; filter: grayscale(.6); }
.tabbar a.on { color: #fff; }
.tabbar a.on .i { filter: none; }
.tabbar a .dot { position: absolute; margin: -26px 0 0 26px; width: 9px; height: 9px; border-radius: 50%; background: var(--holly); }
body.no-tabs .tabbar { display: none; }

/* ---------- Toast e finestre ---------- */
#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 18px); transform: translate(-50%, 20px); opacity: 0; z-index: 50; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 700; max-width: calc(100% - 32px); transition: .25s ease; pointer-events: none; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--holly); }

.modal-back { position: fixed; inset: 0; z-index: 40; background: rgba(6,16,12,.7); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--snow); color: var(--ink); width: 100%; max-width: 560px; border-radius: 24px 24px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); max-height: 90dvh; overflow: auto; animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .modal-back { align-items: center; } .modal { border-radius: 24px; } }

.confetti { position: fixed; top: -12px; width: 9px; height: 14px; z-index: 60; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }

/* ---------- Pannello negozio ---------- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--pine-2); border: 1px solid var(--pine-3); border-radius: 14px; padding: 12px; }
.stat b { display: block; font: 800 26px/1 var(--display); color: var(--gold); }
.stat span { font-size: 13px; color: #B9CCC3; }
.bars { display: grid; gap: 8px; margin-top: 8px; }
.bar { display: grid; grid-template-columns: 1fr auto; gap: 8px; font-size: 15px; }
.bar i { grid-column: 1 / -1; height: 8px; background: var(--gold); border-radius: 999px; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list td, table.list th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }

.footer { text-align: center; color: #8FA79C; font-size: 14px; margin-top: 30px; }
.footer a { color: var(--gold); }
.loading { text-align: center; padding: 60px 0; color: var(--ice); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  #snow { display: none; }
}
