/* Sfondo a macchie morbide, carte "vetro", scelte A (corallo) e B (verde acqua), oro per la magia */
:root {
  --bg: #FFF6F1;
  --blob1: #FFC2CC;
  --blob2: #BDEFE6;
  --blob3: #FFE9A8;
  --card: rgba(255,255,255,.78);
  --card-solid: #FFFFFF;
  --card-edge: rgba(255,255,255,.95);
  --ink: #2B1D3A;
  --muted: #86738F;
  --a: #FF5470;
  --a-soft: #FFE6EA;
  --b: #12A594;
  --b-soft: #DDF6F1;
  --gold: #FFB938;
  --chip: rgba(255,255,255,.7);
  --shadow: 0 20px 50px -18px rgba(90,40,80,.35);
  --display: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --body: "Nunito", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #160F1F; --blob1: #5A2140; --blob2: #144A45; --blob3: #4A3A12;
    --card: rgba(38,27,50,.8); --card-solid: #261B32; --card-edge: rgba(255,255,255,.08);
    --ink: #F8EFFA; --muted: #B6A3C2; --a: #FF7189; --a-soft: #46202E;
    --b: #2FD0BD; --b-soft: #133B38; --gold: #FFC75A; --chip: rgba(255,255,255,.08);
    --shadow: 0 20px 50px -18px rgba(0,0,0,.7); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px;
  padding: max(20px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(32px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  overflow-x: hidden; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.blobs { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.blobs i { position: absolute; border-radius: 50%; filter: blur(60px); opacity: .9; animation: drift 18s ease-in-out infinite alternate; }
.blobs i:nth-child(1) { width: 60vmax; height: 60vmax; background: var(--blob1); top: -25vmax; left: -20vmax; }
.blobs i:nth-child(2) { width: 50vmax; height: 50vmax; background: var(--blob2); bottom: -22vmax; right: -18vmax; animation-delay: -6s; }
.blobs i:nth-child(3) { width: 34vmax; height: 34vmax; background: var(--blob3); top: 40%; left: 55%; animation-delay: -12s; }
@keyframes drift { to { transform: translate(4vmax, 3vmax) scale(1.08); } }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

#app { position: relative; z-index: 1; }
.wrap { max-width: 580px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

/* testata */
header.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-family: var(--display); font-weight: 700; font-size: clamp(1.8rem, 7vw, 2.4rem); line-height: 1; margin: 0; letter-spacing: -0.01em; }
h1 span, .grad { background: linear-gradient(90deg, var(--a), var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.pill { font-weight: 800; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .85rem; background: var(--chip); padding: 6px 11px; border-radius: 999px; white-space: nowrap; border: 1px solid var(--card-edge); }
.top .brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.top h1 { font-size: clamp(1.35rem, 6.2vw, 2.4rem); white-space: nowrap; }
.homebtn {
  flex: none; width: 44px; height: 44px; border-radius: 14px; cursor: pointer; font-size: 1.3rem; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--card-edge); box-shadow: var(--shadow); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  transition: transform .15s ease;
}
.homebtn:active { transform: scale(.94); }
.ghost.mix { align-self: center; padding: 11px 18px; border-radius: 999px; }

/* chip */
.chips-wrap { margin-inline: calc(-1 * max(16px, env(safe-area-inset-left, 0px))); }
.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 4px max(16px, env(safe-area-inset-left, 0px)) 6px;
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 24px), transparent 100%);
          mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 24px), transparent 100%);
}
.chips::-webkit-scrollbar { display: none; }
.chips.wrapme { flex-wrap: wrap; overflow: visible; -webkit-mask-image: none; mask-image: none; }
.chip {
  flex: none; border: 1px solid var(--card-edge); background: var(--chip); color: var(--ink);
  font: 700 .86rem var(--body); padding: 8px 13px; border-radius: 999px; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); display: inline-flex; gap: 6px; align-items: center;
  transition: transform .15s ease, background .2s ease;
}
.chip small { font-weight: 800; color: var(--muted); font-size: .72rem; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip[aria-pressed="true"] small { color: var(--bg); opacity: .7; }
.chip:active { transform: scale(.96); }

/* carte */
.card {
  position: relative; background: var(--card); border: 1px solid var(--card-edge); border-radius: 28px;
  box-shadow: var(--shadow); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  padding: 22px 18px 20px; display: flex; flex-direction: column; gap: 12px;
}
.enter > * { animation: pop .5s cubic-bezier(.2,1.4,.4,1) both; }
.enter > *:nth-child(2) { animation-delay: .05s; }
.enter > *:nth-child(3) { animation-delay: .1s; }
.enter > *:nth-child(4) { animation-delay: .15s; }
.enter > *:nth-child(5) { animation-delay: .2s; }
.enter > *:nth-child(n+6) { animation-delay: .25s; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.95); } }

.tag { align-self: center; font-size: .74rem; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); background: var(--chip); padding: 5px 11px; border-radius: 999px; }
.lead { font-family: var(--display); font-weight: 700; font-size: 1.6rem; margin: 2px 0; text-align: center; }
.sub { color: var(--muted); font-weight: 700; text-align: center; margin: 0; line-height: 1.45; text-wrap: balance; }

.opt {
  position: relative; width: 100%; text-align: left; cursor: pointer; border: 2px solid transparent; border-radius: 20px;
  font: 800 1.1rem/1.3 var(--body); padding: 16px 16px 16px 62px; color: var(--ink); min-height: 76px;
  transition: transform .18s ease, opacity .25s ease, background .25s ease, box-shadow .25s ease; text-wrap: balance;
}
.opt::before {
  content: attr(data-l); position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center;
  font: 700 1.1rem var(--display); color: #fff;
}
.opt.a { background: var(--a-soft); } .opt.a::before { background: var(--a); }
.opt.b { background: var(--b-soft); } .opt.b::before { background: var(--b); }
.opt:active { transform: scale(.98); }
.opt.chosen.a { background: var(--a); color: #fff; box-shadow: 0 12px 28px -10px var(--a); }
.opt.chosen.b { background: var(--b); color: #fff; box-shadow: 0 12px 28px -10px var(--b); }
.opt.chosen::before { background: rgba(255,255,255,.28); }
.opt.faded { opacity: .4; transform: scale(.97); }
.or { align-self: center; font: 700 .85rem var(--display); color: var(--muted); letter-spacing: .06em; text-transform: uppercase; margin: -4px 0; }
.why { text-align: center; font-weight: 800; font-size: 1.05rem; min-height: 2.8em; display: flex; align-items: center; justify-content: center; text-wrap: balance; }
.why.idle { color: var(--muted); font-weight: 700; font-size: .95rem; }

/* bottoni */
.actions { display: flex; gap: 10px; }
.btn {
  flex: 1; cursor: pointer; color: #fff; border: 0; border-radius: 20px; padding: 17px; font: 700 1.2rem var(--display);
  background: linear-gradient(100deg, var(--a), #FF8A4C 55%, var(--gold)); box-shadow: 0 14px 30px -12px var(--a);
  transition: transform .15s ease, filter .2s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { filter: grayscale(.6); opacity: .6; cursor: default; }
.ghost {
  cursor: pointer; background: var(--chip); color: var(--ink); border: 1px solid var(--card-edge);
  border-radius: 20px; padding: 14px 18px; font: 800 .95rem var(--body); backdrop-filter: blur(8px);
}
.ghost:disabled { opacity: .4; cursor: default; }
.link { background: none; border: 0; color: var(--muted); font: 700 .9rem var(--body); text-decoration: underline; cursor: pointer; padding: 6px; align-self: center; }
.tips { color: var(--muted); font-size: .9rem; line-height: 1.5; margin: 0; text-align: center; }
.tips b { color: var(--ink); }

/* home */
.hero { text-align: center; display: flex; flex-direction: column; gap: 10px; padding-top: 12px; }
.hero h1 { font-size: clamp(2.4rem, 11vw, 3.4rem); }
.modes { display: grid; gap: 12px; }
.mode {
  display: grid; grid-template-columns: 54px 1fr; gap: 4px 14px; align-items: center; text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--card-edge); border-radius: 24px; padding: 16px; box-shadow: var(--shadow);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); transition: transform .15s ease;
}
.mode:active { transform: scale(.98); }
.mode .ico { grid-row: span 2; width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center; font-size: 1.7rem; background: var(--a-soft); }
.mode:nth-child(2) .ico { background: var(--b-soft); }
.mode:nth-child(3) .ico { background: var(--chip); }
.mode:nth-child(4) .ico { background: var(--chip); }
.mode b { font: 700 1.2rem var(--display); }
.mode span.d { color: var(--muted); font-weight: 700; font-size: .92rem; line-height: 1.35; }
.joinrow { display: flex; gap: 8px; grid-column: 2; margin-top: 6px; }

input.field {
  width: 100%; min-width: 0; border: 2px solid var(--card-edge); background: var(--card-solid); color: var(--ink);
  border-radius: 16px; padding: 14px 16px; font: 800 1.1rem var(--body);
}
input.code { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-family: var(--display); }

/* giocatori */
.players { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 0; }
.player {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px;
  background: var(--chip); border: 1px solid var(--card-edge); font-weight: 800;
}
.player .av { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font: 700 .9rem var(--display); flex: none; }
.player.off { opacity: .45; }
.player.done { background: var(--b-soft); }
.player .st { font-size: .85em; }
.player button { background: none; border: 0; cursor: pointer; color: var(--muted); font-weight: 800; padding: 0 2px; }

/* risultati */
.result { display: grid; grid-template-columns: 1fr; gap: 10px; }
.res {
  position: relative; overflow: hidden; border-radius: 20px; padding: 14px 16px 14px 62px; min-height: 70px;
  font-weight: 800; display: flex; flex-direction: column; justify-content: center; gap: 4px;
}
.res.a { background: var(--a-soft); } .res.b { background: var(--b-soft); }
.res .bar { position: absolute; inset: 0 auto 0 0; width: 0; opacity: .22; transition: width 1s cubic-bezier(.2,.9,.3,1); }
.res.a .bar { background: var(--a); } .res.b .bar { background: var(--b); }
.res .num { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; color: #fff; font: 700 1.2rem var(--display); }
.res.a .num { background: var(--a); } .res.b .num { background: var(--b); }
.res .txt { position: relative; line-height: 1.3; }
.res .who { position: relative; font-size: .85rem; color: var(--muted); font-weight: 700; }

.spot {
  text-align: center; border-radius: 22px; padding: 16px; background: linear-gradient(120deg, color-mix(in srgb, var(--gold) 28%, transparent), color-mix(in srgb, var(--a) 16%, transparent));
  display: flex; flex-direction: column; gap: 4px; align-items: center;
}
.spot .small { font-weight: 800; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; }
.spot .name { font: 700 2rem var(--display); line-height: 1.1; }
.spot .ask { font-weight: 800; text-wrap: balance; }
.spot.rolling .name { filter: blur(.5px); }

/* passa il telefono */
.pass { text-align: center; align-items: center; padding-block: 36px; }
.pass .big { font: 700 2.4rem var(--display); line-height: 1.05; }

/* magia */
.magic {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; align-content: center; gap: 22px;
  background: color-mix(in srgb, var(--bg) 55%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  opacity: 0; pointer-events: none; transition: opacity .3s ease;
}
.magic.on { opacity: 1; pointer-events: auto; }
.orb {
  width: 110px; height: 110px; border-radius: 50%; position: relative;
  background: conic-gradient(from 0deg, var(--a), var(--gold), var(--b), var(--a));
  animation: spin 1.1s linear infinite; filter: drop-shadow(0 0 28px var(--gold));
}
.orb::after { content: ""; position: absolute; inset: 10px; border-radius: 50%; background: var(--card-solid); }
.orb b { position: absolute; inset: 0; display: grid; place-items: center; z-index: 1; font-size: 2.3rem; animation: spin 1.1s linear infinite reverse; }
@keyframes spin { to { transform: rotate(360deg); } }
.spell { font: 600 1.25rem var(--display); color: var(--ink); text-align: center; padding-inline: 16px; }

.net { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(14px, env(safe-area-inset-bottom, 0px)); z-index: 70; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 800; font-size: .9rem; }

.sndbox { position: fixed; z-index: 55; right: max(14px, env(safe-area-inset-right, 0px)); bottom: max(14px, env(safe-area-inset-bottom, 0px)); display: flex; gap: 8px; align-items: center; }
.snd.off { opacity: .5; }
.snd {
  min-width: 46px; height: 46px; border-radius: 999px; border: 1px solid var(--card-edge); background: var(--card); color: var(--ink);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); box-shadow: var(--shadow); cursor: pointer; font: 800 1.1rem var(--body); padding: 0 12px;
}
.snd.wide { font-size: 1rem; padding: 0 18px; animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 50% { transform: scale(1.06); } }
body.tvmode .snd { font-size: 1.4rem; height: 58px; min-width: 58px; }

/* ---------- TV ---------- */
body.tvmode { padding: 0; }
.tv { position: relative; z-index: 1; min-height: 100vh; min-height: 100dvh; font-size: clamp(13px, 1.15vw, 30px); padding: 2.2em 4em 2.6em; display: flex; flex-direction: column; gap: 1.6em; }
.tv .tvtop { display: flex; justify-content: space-between; align-items: center; gap: 1em; }
.tv .tvtop h1 { font-size: 2.4em; }
.tv .tvtop .pill { font-size: .95em; padding: .5em 1em; }
.tv .lobby { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 3em; align-items: center; }
.tv .qrbox { background: #fff; border-radius: 1.6em; padding: 1.4em; box-shadow: var(--shadow); width: min(100%, 22em); justify-self: center; display: flex; flex-direction: column; gap: .8em; align-items: center; }
.tv .qrbox svg { width: 100%; height: auto; display: block; }
.tv .qrbox .c { color: #2B1D3A; font: 700 1.1em var(--display); text-align: center; }
.tv .qrbox .c b { font-size: 1.9em; letter-spacing: .22em; display: block; color: #FF5470; }
.tv .qrbox .u { color: #86738F; font-weight: 800; font-size: .85em; text-align: center; word-break: break-all; }
.tv .side { display: flex; flex-direction: column; gap: 1.2em; min-width: 0; }
.tv .side h2 { font: 700 2.4em var(--display); margin: 0; line-height: 1.1; text-wrap: balance; }
.tv .side p { margin: 0; font-size: 1.15em; color: var(--muted); font-weight: 700; line-height: 1.45; }
.tv .players { gap: .6em; }
.tv .player { font-size: 1.15em; padding: .35em .8em .35em .35em; }
.tv .player .av { width: 1.8em; height: 1.8em; font-size: .9em; }
.tv .btn { font-size: 1.4em; padding: .8em 1.4em; flex: none; align-self: flex-start; }
.tv .ghost { font-size: 1em; padding: .8em 1.2em; }
.tv .stage { flex: 1; display: flex; flex-direction: column; gap: 1.2em; justify-content: safe center; max-width: 72em; width: 100%; margin: 0 auto; }
.tv .tag { font-size: .95em; padding: .45em 1em; }
.tv .lead { font-size: 2.6em; }
.tv .duel { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1.4em; align-items: stretch; }
.tv .duel .or { align-self: center; font-size: 1.3em; margin: 0; }
.tv .choice { position: relative; overflow: hidden; border-radius: 1.4em; padding: 1em 1.2em 1em 3.1em; font: 800 1.9em/1.25 var(--body); display: flex; flex-direction: column; justify-content: center; gap: .3em; min-height: 4.6em; text-wrap: balance; }
.tv .choice.a { background: var(--a-soft); } .tv .choice.b { background: var(--b-soft); }
.tv .choice .badge { position: absolute; left: .6em; top: 50%; transform: translateY(-50%); width: 1.8em; height: 1.8em; border-radius: .5em; display: grid; place-items: center; color: #fff; font: 700 1em var(--display); }
.tv .choice.a .badge { background: var(--a); } .tv .choice.b .badge { background: var(--b); }
.tv .choice .bar { position: absolute; inset: auto 0 0 0; height: 0; opacity: .25; transition: height 1.1s cubic-bezier(.2,.9,.3,1); }
.tv .choice.a .bar { background: var(--a); } .tv .choice.b .bar { background: var(--b); }
.tv .choice .t, .tv .choice .who, .tv .choice .cnt { position: relative; }
.tv .choice .cnt { font: 700 1.3em var(--display); line-height: 1; }
.tv .choice .who { font-size: .5em; color: var(--muted); font-weight: 800; }
.tv .voters { display: flex; justify-content: center; }
.tv .spot { padding: 1.2em; }
.tv .spot .small { font-size: .9em; }
.tv .spot .name { font-size: 3.2em; }
.tv .spot .ask { font-size: 1.5em; }
.tv .tvactions { display: flex; justify-content: center; gap: 1em; }
.tv .tvactions .btn { align-self: center; }
.tv .status { text-align: center; font-size: 1.2em; color: var(--muted); font-weight: 800; }

@media (max-width: 760px) {
  .tv { padding: 1.6em 1.2em; font-size: 15px; }
  .tv .lobby { grid-template-columns: 1fr; }
  .tv .duel { grid-template-columns: 1fr; }
  .tv .choice { font-size: 1.3em; }
  .tv .lead { font-size: 2em; }
}

@media (prefers-reduced-motion: reduce) {
  .blobs i, .orb, .orb b { animation: none; }
  .enter > * { animation: none; }
  .res .bar, .tv .choice .bar { transition: none; }
}
