:root {
  --bg: #d6ecfa;
  --bg-2: #eef7fd;
  --card: #ffffff;
  --card-2: #e3f1fb;
  --line: rgba(22, 74, 120, 0.12);
  --text: #0f2a44;
  --muted: #5d7c98;
  --gold: #f4b81c;
  --gold-2: #ffd766;
  --pink: #22a6ee;
  --violet: #3f6ff0;
  --accent: #1b8fd6;
  --pos: #12a7f0;
  --neg: #ee4b5d;
  --shadow: 0 6px 22px rgba(22, 74, 120, 0.10);
  --radius: 20px;
  --nav-h: 72px;
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
.guest-pick, .rule-pick { color: var(--text); }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.4;
  background:
    radial-gradient(900px 500px at 110% -10%, rgba(255, 255, 255, 0.85), transparent 60%),
    radial-gradient(700px 500px at -20% 20%, rgba(120, 200, 245, 0.45), transparent 60%),
    linear-gradient(180deg, #e6f4fd, var(--bg));
  background-attachment: fixed;
}
h1, h2, h3 { font-family: var(--font-display); margin: 0; letter-spacing: -0.02em; }
button, input, textarea, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

.app { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(var(--nav-h) + 110px); }

/* ---------- testata ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0 16px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-badge {
  flex: none; width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: 20px; color: #3a2600;
  background: linear-gradient(135deg, var(--gold-2), var(--gold) 50%, #e2a521);
  box-shadow: 0 6px 18px rgba(244, 184, 28, .4);
}
.brand-badge.long { font-size: 15px; }
.brand-badge.is-emoji { font-size: 24px; }
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text p { margin: 0; font-size: 13px; color: var(--muted); }

/* ---------- card e bottoni ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.btn {
  border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px;
  transition: transform .1s ease, opacity .2s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn-primary { background: linear-gradient(135deg, var(--pink), var(--violet)); color: #fff; box-shadow: 0 8px 22px rgba(27, 143, 214, .35); }
.btn-gold { background: linear-gradient(135deg, var(--gold-2), var(--gold)); color: #3a2600; }
.btn-ghost { background: var(--card-2); }
.btn-danger { background: var(--neg); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--neg); padding-inline: 8px; }
.btn-block { width: 100%; }
a.btn { text-decoration: none; color: var(--text); white-space: nowrap; flex: none; }
.btn-sm { min-height: 38px; padding: 8px 12px; font-size: 14px; border-radius: 12px; }
.icon-btn { background: var(--card-2); border: 0; width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 17px; flex: none; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.input {
  width: 100%; background: var(--bg-2); border: 1.5px solid var(--line); border-radius: 14px;
  padding: 14px 16px; outline: none; min-height: 52px;
}
.input:focus { border-color: var(--accent); }

/* ---------- avatar ---------- */
.av { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; background: var(--card-2); font-size: 22px; flex: none; }

/* ---------- registrazione ---------- */
.hero-30 {
  font-family: var(--font-display); font-weight: 800; font-size: 120px; line-height: .9; text-align: center;
  background: linear-gradient(160deg, #7fd6ff 5%, var(--pink) 45%, var(--violet));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 10px 24px rgba(27, 143, 214, .25));
  margin: 12px 0 4px;
}
.hero-30.small { font-size: 90px; }
.hero-30.long { font-size: 80px; }
.hero-30.small.long { font-size: 60px; }
.hero-30.is-emoji { background: none; color: inherit; font-size: 96px; line-height: 1.1; }
.hero-30.small.is-emoji { font-size: 72px; }
.welcome { text-align: center; margin-bottom: 22px; }
.welcome h2 { font-size: 26px; }
.welcome p { margin: 6px 0 0; color: var(--muted); }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 14px; width: 100%; }
.error { color: var(--neg); font-size: 14px; margin: -4px 0 12px; min-height: 1em; }

/* ---------- saldo ---------- */
.balance {
  position: relative; overflow: hidden; text-align: center; padding: 26px 18px 22px;
  background: linear-gradient(160deg, #ffffff, #eaf6fe);
  border: 1px solid rgba(27, 143, 214, .25);
}
.balance::before {
  content: attr(data-badge); position: absolute; right: -14px; bottom: -40px; font-family: var(--font-display); font-weight: 800;
  font-size: 170px; color: rgb(27, 143, 214); opacity: .08; line-height: 1; pointer-events: none;
}
.balance .who { display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; font-size: 18px; }
.balance .who .av { width: 36px; height: 36px; font-size: 20px; }
.balance .num {
  font-family: var(--font-display); font-weight: 800; font-size: 84px; line-height: 1; margin: 10px 0 2px;
  font-variant-numeric: tabular-nums;
}
.balance .num.bump { animation: bump .6s ease; }
.balance .label { color: var(--muted); font-size: 14px; }
.balance .rank { display: inline-block; margin-top: 12px; padding: 6px 12px; border-radius: 99px; background: rgba(27, 143, 214, .12); color: var(--accent); font-weight: 700; font-size: 14px; }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.18); } 100% { transform: scale(1); } }

/* ---------- tabs ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: rgba(255, 255, 255, .7); backdrop-filter: blur(8px); padding: 4px; border-radius: 16px; margin: 18px 0 14px; position: sticky; top: 8px; z-index: 5; border: 1px solid var(--line); }
.seg button { border: 0; background: none; border-radius: 12px; padding: 11px 6px; font-weight: 700; color: var(--muted); cursor: pointer; font-size: 15px; }
.seg button.on { background: var(--accent); color: #fff; }

/* ---------- liste ---------- */
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.row .icon-btn { width: 36px; height: 36px; font-size: 15px; }
.row.wrap .title, .row.wrap .sub { white-space: normal; }
.row { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .pts { font-family: var(--font-display); font-weight: 800; font-size: 20px; font-variant-numeric: tabular-nums; flex: none; }
.row.me { border-color: var(--pos); background: linear-gradient(90deg, rgba(18, 167, 240, .12), var(--card)); }
.row.void { opacity: .45; }
.row.void .title, .row.void .pts { text-decoration: line-through; }
.rank-pos { width: 30px; text-align: center; font-weight: 800; font-size: 18px; flex: none; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 34px 16px; }
.empty .big { font-size: 44px; display: block; margin-bottom: 8px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 22px 0 10px; }
.section-title h2 { font-size: 18px; }

.podium { display: grid; grid-template-columns: 1fr 1.15fr 1fr; align-items: end; gap: 8px; margin-bottom: 12px; }
.podium .p { text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 6px; box-shadow: var(--shadow); }
.podium .p.first { border-color: var(--gold); padding-block: 22px; background: linear-gradient(180deg, #fff3cc, #ffffff); }
.podium .m { font-size: 26px; }
.podium .a { font-size: 30px; margin: 4px 0; }
.podium .n { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.podium .s { font-family: var(--font-display); font-weight: 800; font-size: 20px; }

.frozen { text-align: center; padding: 40px 20px; }
.frozen .big { font-size: 56px; }
.frozen h3 { font-size: 22px; margin: 8px 0 6px; }

/* ---------- popup punti ---------- */
.pop {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; pointer-events: none;
  background: radial-gradient(circle, rgba(255, 255, 255, .85), rgba(214, 236, 250, .5));
  animation: fadeout 2.6s ease forwards;
}
.pop .box { text-align: center; animation: popin .5s cubic-bezier(.2, 1.6, .4, 1); }
.pop .e { font-size: 70px; }
.pop .v { font-family: var(--font-display); font-weight: 800; font-size: 96px; line-height: 1; }
.pop .t { font-weight: 700; font-size: 20px; margin-top: 6px; }
@keyframes popin { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fadeout { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }
.particle {
  position: fixed; left: 50%; top: 45%; font-size: 26px; z-index: 51; pointer-events: none;
  animation: fly 1.4s cubic-bezier(.15, .7, .3, 1) forwards;
}
@keyframes fly {
  from { transform: translate(-50%, -50%) scale(.4); opacity: 1; }
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy) + 120px)) rotate(var(--rot)) scale(1); opacity: 0; }
}
.shake { animation: shake .5s ease; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- toast ---------- */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); top: max(12px, env(safe-area-inset-top)); z-index: 60; display: grid; gap: 8px; width: min(92vw, 520px); }
.toast {
  display: flex; align-items: center; gap: 12px; justify-content: space-between;
  background: #0f2a44; color: #fff; border-radius: 14px; padding: 12px 14px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(15, 42, 68, .3); animation: up .3s ease; transition: opacity .4s, transform .4s;
}
.toast button { border: 0; background: var(--pos); color: #fff; border-radius: 10px; padding: 8px 12px; font-weight: 700; cursor: pointer; flex: none; }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes up { from { transform: translateY(-16px); opacity: 0; } }

/* ---------- modale ---------- */
.modal {
  border: 1px solid var(--line); border-radius: 24px; background: var(--bg-2); color: var(--text);
  padding: 22px 18px 18px; width: min(94vw, 480px); max-height: 90dvh; box-shadow: 0 20px 60px rgba(15, 42, 68, .3);
}
.modal::backdrop { background: rgba(15, 42, 68, .45); backdrop-filter: blur(4px); }
.modal h3 { font-size: 21px; margin-bottom: 14px; }
.modal-body p { margin: 0 0 8px; }
.modal-actions { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.modal-actions .spacer { flex: 1; }

/* ---------- admin ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: rgba(255, 255, 255, .92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr);
}
.nav button { border: 0; background: none; color: var(--muted); display: grid; place-items: center; align-content: center; gap: 2px; font-size: 11.5px; font-weight: 600; cursor: pointer; }
.nav button .i { font-size: 22px; filter: grayscale(1); opacity: .7; }
.nav button.on { color: var(--text); }
.nav button.on .i { filter: none; opacity: 1; }

.step { font-size: 13px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin: 18px 0 10px; }
.rule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rule-pick {
  text-align: left; border: 2px solid var(--line); background: var(--card); border-radius: 16px; padding: 10px;
  cursor: pointer; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center; min-height: 64px;
}
.rule-pick .e { font-size: 24px; grid-row: span 2; }
.rule-pick .n { font-weight: 700; font-size: 13.5px; line-height: 1.2; }
.rule-pick .p { font-family: var(--font-display); font-weight: 800; font-size: 15px; }
.rule-pick.on { border-color: var(--accent); background: rgba(27, 143, 214, .12); }
.rule-pick.manual { border-style: dashed; }

.guest-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.guest-pick {
  border: 2px solid var(--line); background: var(--card); border-radius: 16px; padding: 10px 6px; cursor: pointer;
  display: grid; justify-items: center; gap: 2px; position: relative;
}
.guest-pick .a { font-size: 28px; }
.guest-pick .n { font-weight: 700; font-size: 14px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guest-pick .s { font-size: 12px; color: var(--muted); }
.guest-pick.on { border-color: var(--accent); background: rgba(27, 143, 214, .12); }
.guest-pick.on::after { content: '✓'; position: absolute; top: 6px; right: 8px; color: var(--accent); font-weight: 800; }
.tools { display: flex; gap: 8px; margin-bottom: 10px; }
.tools .input { min-height: 46px; padding-block: 10px; }

.confirm-bar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 15;
  padding: 12px 16px; background: linear-gradient(180deg, transparent, rgba(214, 236, 250, .95) 30%);
}
.confirm-bar .inner { max-width: 528px; margin: 0 auto; }
.confirm-bar .btn { width: 100%; font-size: 17px; min-height: 58px; }

.pm-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.pm-toggle input { position: absolute; opacity: 0; }
.pm-toggle span { display: block; text-align: center; padding: 12px; border-radius: 14px; background: var(--bg-2); border: 2px solid var(--line); font-weight: 700; cursor: pointer; }
.pm-toggle input:checked + span.b { border-color: var(--pos); color: var(--pos); background: rgba(18, 167, 240, .1); }
.pm-toggle input:checked + span.m { border-color: var(--neg); color: var(--neg); background: rgba(238, 75, 93, .08); }
.emoji-input { font-size: 28px; text-align: center; width: 96px; }
.emoji-picker .hint { margin: 0; font-size: 12px; color: var(--muted); }
.emoji-tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px; }
.emoji-tabs button { flex: none; border: 2px solid transparent; background: var(--bg-2); border-radius: 10px; padding: 4px 8px; font-size: 20px; cursor: pointer; }
.emoji-tabs button.on { border-color: var(--gold); background: rgba(244, 184, 28, .15); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 4px; max-height: 210px; overflow-y: auto; padding: 2px; }
.emoji-grid[hidden] { display: none; }
.emoji-grid .cat { grid-column: 1 / -1; font-size: 12px; font-weight: 700; color: var(--muted); margin: 2px 0; }
.emoji-grid button { aspect-ratio: 1; border: 2px solid transparent; background: var(--bg-2); border-radius: 12px; font-size: 22px; cursor: pointer; padding: 0; }
.emoji-grid button.on { border-color: var(--gold); background: rgba(244, 184, 28, .15); }
.emoji-picker { display: grid; gap: 8px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch { position: relative; width: 58px; height: 34px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--card-2); border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 26px; height: 26px; left: 4px; top: 4px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--pos); }
.switch input:checked + span::before { transform: translateX(24px); }
.stack { display: grid; gap: 12px; }
.danger-zone { border-color: rgba(238, 75, 93, .35); }

.pin-wrap { min-height: 80dvh; display: grid; place-content: center; text-align: center; gap: 14px; }
.pin-input { text-align: center; font-size: 30px; letter-spacing: .4em; font-weight: 800; }

/* ---------- icone (Heroicons) ---------- */
.hi { width: 1.2em; height: 1.2em; flex: none; vertical-align: -0.25em; }
.hi.big { display: block; width: 48px; height: 48px; margin: 0 auto 10px; color: var(--accent); opacity: .8; }
.nav .hi.i { width: 26px; height: 26px; }
.nav button.on .hi.i { color: var(--accent); }
.icon-btn { display: grid; place-items: center; color: var(--accent); }
.icon-btn .hi { width: 20px; height: 20px; }
.icon-btn.danger { color: var(--neg); }
.h-icon { display: flex; align-items: center; gap: 8px; }
.h-icon .hi { color: var(--accent); }
.h-icon.neg .hi { color: var(--neg); }
.rule-pick .e .hi { width: 26px; height: 26px; color: var(--accent); vertical-align: middle; }
.toast > span { display: flex; align-items: center; gap: 8px; }
.toast > span .hi { color: var(--pos); }
.rank .hi, .link-btn .hi, .btn .hi { vertical-align: -0.22em; }
.section-title h2 { display: flex; align-items: center; gap: 6px; }
.section-title h2 .hi { color: var(--accent); }
.pm-toggle span { display: flex; align-items: center; justify-content: center; gap: 6px; }
.search { position: relative; flex: 1; display: block; }
.search .hi { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search .input { padding-left: 42px; }
