/* ═══════════════════════════════════════════════════════════════════
   Waterbomb — foglio di stile unico.

   Stessa famiglia di TableNight (fondo scuro, Bricolage per i titoli,
   Inter Tight per il testo), ma l'accento qui non è la lampada gialla:
   è l'acqua. Il rosso c'è, ed è quello della gomma del palloncino —
   compare solo dove serve tensione.

   Una cosa sola da sapere prima di toccare qualcosa: `--tensione` è
   una variabile che il gioco aggiorna a ogni fotogramma, da 0 a 1,
   mentre il giro va avanti. Tutto quello che «si agita» sullo schermo
   la legge da qui, e va di pari passo con il ticchettio: quando il tic
   corre, il palloncino trema forte e l'alone rosso si allarga. Le due
   cose devono restare agganciate, se no il naso sente una cosa e
   l'occhio ne vede un'altra.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --ink: #031a38;
  --notte: #06407a;
  --fondo: #052a58;
  --acqua: #2ccbff;
  --acqua-lo: #0b8fd6;
  --acqua-hi: #CBF1FF;
  --gomma: #ff4b3e;
  --paper: #F1E9D8;
  --paper-dim: #b5d6ea;
  --line: #ffffff18;
  --line-soft: #ffffff0d;
  --r: 16px;
  --sans: "Inter Tight", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Bricolage Grotesque", Georgia, serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --tensione: 0;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(120% 62% at 50% -8%, #2ccbff55 0%, transparent 58%),
    radial-gradient(90% 50% at 50% 108%, #ff4b3e33 0%, transparent 62%),
    linear-gradient(180deg, var(--notte) 0%, var(--fondo) 46%, var(--ink) 100%);
  background-attachment: fixed;
  color: var(--paper);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* Durante il giro il telefono passa di mano: se la pagina scorre,
   qualcuno la sposta senza volerlo e la carta sparisce a metà. */
body.in-gioco { overflow: hidden; }

svg.defs { position: absolute; width: 0; height: 0; }

#app {
  position: relative;
  max-width: 560px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* ── testata ──────────────────────────────────────────────────────── */

.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 6px 0 4px; flex: none;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand .mark { width: 22px; height: 22px; flex: none; filter: drop-shadow(0 0 10px #4FB6EA55); }
.brand b {
  font-family: var(--display); font-weight: 800; font-size: 16px;
  letter-spacing: -.02em;
}
.lang { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang button {
  background: transparent; border: 0; font-family: var(--mono);
  font-size: 11px; letter-spacing: .1em; padding: 6px 11px; color: var(--paper-dim);
}
.lang button[aria-current="true"] { background: var(--acqua); color: #07222F; }

/* ── schermi ──────────────────────────────────────────────────────── */

.schermo { display: none; flex: 1; flex-direction: column; padding: 8px 0 0; }
.schermo.on { display: flex; animation: entra .32s ease both; }
.schermo.mid { justify-content: center; text-align: center; gap: 4px; }

@keyframes entra {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

h1 {
  font-family: var(--display); font-weight: 800;
  font-size: clamp(2.3rem, 11vw, 3.2rem); line-height: .98;
  letter-spacing: -.04em; margin: 4px 0 10px; text-align: center;
}
h2 {
  font-family: var(--display); font-weight: 800;
  font-size: clamp(1.4rem, 5.4vw, 1.8rem); letter-spacing: -.03em; margin: 0 0 14px;
}
h2.grande { font-size: clamp(1.9rem, 8vw, 2.6rem); margin: 6px 0 10px; line-height: 1.05; }
.eyebrow {
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .16em;
  text-transform: uppercase; color: var(--acqua); margin: 0 0 6px;
}
.lede { color: var(--paper-dim); margin: 0 0 18px; text-wrap: pretty; }
.schermo.mid .lede { max-width: 30ch; margin-left: auto; margin-right: auto; }
.grosso-nome { color: var(--paper); font-size: 1.15rem; }

/* ── bottoni ──────────────────────────────────────────────────────── */

.grosso {
  display: block; width: 100%; border: 0; border-radius: 999px;
  padding: 17px 24px; font-weight: 600; font-size: 1.06rem; letter-spacing: -.01em;
  color: #06222F;
  background: linear-gradient(180deg, var(--acqua-hi) 0%, var(--acqua) 42%, var(--acqua-lo) 100%);
  box-shadow: 0 12px 30px -14px #4FB6EAcc, inset 0 1px 0 #ffffff66;
  transition: transform .12s ease, filter .12s ease;
}
.grosso:active { transform: translateY(2px) scale(.99); filter: brightness(.94); }
.grosso:focus-visible { outline: 3px solid var(--paper); outline-offset: 3px; }

.lnk {
  background: none; border: 0; padding: 10px 6px; color: var(--paper-dim);
  font-size: .95rem; text-decoration: underline; text-underline-offset: 4px;
  text-decoration-color: #ffffff33;
}
.lnk:hover { color: var(--paper); }
.sottobottoni { display: flex; flex-direction: column; align-items: center; gap: 0; margin-top: 6px; }
.lnk.ripr { color: var(--acqua); text-decoration-color: #4FB6EA66; }

.fondo { display: flex; align-items: center; gap: 12px; margin-top: auto; padding-top: 18px; }
.fondo .lnk { flex: none; }
.fondo .grosso { flex: 1; }

/* ── casa: il palloncino ──────────────────────────────────────────── */

.scena-palla {
  display: flex; flex-direction: column; align-items: center;
  margin: 10px 0 2px; flex: none;
}
.palla { width: min(46vw, 190px); transform-origin: 50% 12%; }
.palla svg { display: block; width: 100%; height: auto; filter: drop-shadow(0 22px 34px #0009); }
#pallaCasa { animation: dondola 4.6s ease-in-out infinite; }

@keyframes dondola {
  0%, 100% { transform: translateY(0) rotate(-2.2deg) scale(1, 1); }
  25%      { transform: translateY(-7px) rotate(1.6deg) scale(.985, 1.015); }
  50%      { transform: translateY(0) rotate(2.4deg) scale(1.02, .98); }
  75%      { transform: translateY(-4px) rotate(-1.2deg) scale(.99, 1.01); }
}

.ombra {
  width: min(30vw, 120px); height: 12px; margin-top: -4px; border-radius: 50%;
  background: radial-gradient(50% 50% at 50% 50%, #0009, transparent 72%);
  animation: respiro 4.6s ease-in-out infinite;
}
@keyframes respiro {
  0%, 100% { transform: scaleX(1); opacity: .8; }
  50% { transform: scaleX(.86); opacity: .6; }
}

/* ── impostazioni ─────────────────────────────────────────────────── */

#s-set { padding-bottom: 8px; }
.blocco {
  background: #ffffff07; border: 1px solid var(--line-soft); border-radius: var(--r);
  padding: 14px 14px 12px; margin-bottom: 14px;
}
.et {
  font-family: var(--mono); font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--acqua); margin: 0 0 10px;
}
.nota { font-size: .82rem; color: #7C8794; margin: 10px 0 0; line-height: 1.45; }

.giocatori { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.giocatori li { display: flex; gap: 8px; }
.giocatori input {
  flex: 1; min-width: 0; font: inherit; font-size: 1rem; color: var(--paper);
  background: #ffffff0d; border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 13px;
}
.giocatori input::placeholder { color: #6C7681; }
.giocatori input:focus { outline: 2px solid var(--acqua); outline-offset: -1px; border-color: transparent; }
.giocatori .via {
  flex: none; width: 42px; border: 1px solid var(--line); border-radius: 11px;
  background: transparent; color: var(--paper-dim); font-size: 20px; line-height: 1;
}
.giocatori .via:hover { color: var(--gomma); border-color: #D6564855; }
.lnk.piu { display: block; margin-top: 10px; text-decoration: none; color: var(--acqua); }

.segm { display: flex; flex-direction: column; gap: 8px; }
.segm button {
  display: block; width: 100%; text-align: left; border: 1px solid var(--line);
  background: #ffffff08; border-radius: 12px; padding: 11px 13px; transition: .16s;
}
.segm button b { display: block; font-weight: 600; font-size: .98rem; }
.segm button span { display: block; font-size: .81rem; color: #7C8794; line-height: 1.4; margin-top: 2px; }
.segm button[aria-pressed="true"] {
  background: linear-gradient(180deg, #4FB6EA22, #4FB6EA0e);
  border-color: #4FB6EA88;
  box-shadow: inset 0 0 0 1px #4FB6EA33;
}
.segm button[aria-pressed="true"] b { color: var(--acqua-hi); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  border: 1px solid var(--line); background: #ffffff08; border-radius: 999px;
  padding: 9px 14px; font-size: .9rem; color: var(--paper-dim); transition: .16s;
}
.chips button[aria-pressed="true"] {
  background: #4FB6EA22; border-color: #4FB6EA88; color: var(--acqua-hi);
}

.sw { display: flex; align-items: flex-start; gap: 12px; padding: 9px 0; cursor: pointer; }
.sw + .sw { border-top: 1px solid var(--line-soft); }
.sw input { position: absolute; opacity: 0; width: 0; height: 0; }
.sw .pista {
  flex: none; width: 46px; height: 27px; border-radius: 999px; margin-top: 2px;
  background: #ffffff14; border: 1px solid var(--line); position: relative; transition: .18s;
}
.sw .pista::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 21px; height: 21px;
  border-radius: 50%; background: var(--paper-dim); transition: .18s;
}
.sw input:checked + .pista { background: #4FB6EA55; border-color: #4FB6EAaa; }
.sw input:checked + .pista::after { left: 21px; background: var(--acqua-hi); }
.sw input:focus-visible + .pista { outline: 2px solid var(--paper); outline-offset: 2px; }
.sw .testo b { display: block; font-weight: 600; font-size: .97rem; }
.sw .testo i { display: block; font-style: normal; font-size: .81rem; color: #7C8794; line-height: 1.4; }

.errore { color: #F0938A; font-size: .9rem; min-height: 1.2em; margin: 0 0 6px; }

/* ── pronti ───────────────────────────────────────────────────────── */

#s-pronti .grosso { margin-top: 12px; }
.grosso.avvia { position: relative; overflow: hidden; }
.grosso.avvia::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, #ffffff5c 50%, transparent 70%);
  transform: translateX(-100%);
  animation: luccica 2.8s ease-in-out infinite;
}
@keyframes luccica { 0%, 60% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }

/* ── gioco ────────────────────────────────────────────────────────── */

.schermo.gioca { justify-content: flex-start; position: relative; }

.riga-turno {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex: none; min-height: 40px;
}
.riga-turno .chi {
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .13em;
  text-transform: uppercase; color: var(--acqua);
}
.lnk.esci { font-size: .82rem; padding: 6px 0; }

/* Quanto vale il prossimo passaggio. Sta in mezzo, piccolo: è
   un'informazione utile ma non deve rubare l'occhio alla consegna. */
.riga-turno .vale {
  flex: 1; text-align: center;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em;
  text-transform: uppercase; color: #6F7A86;
}

/* Il "+2" che scappa via dal bottone quando passi. */
.guadagno {
  position: absolute; left: 50%; bottom: 92px; transform: translateX(-50%);
  font-family: var(--display); font-weight: 800; font-size: 2rem;
  color: var(--acqua-hi); text-shadow: 0 2px 14px #0009;
  opacity: 0; pointer-events: none;
}
.guadagno.via { animation: scappa .85s cubic-bezier(.2, .8, .3, 1) both; }
@keyframes scappa {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(.8); }
  22% { opacity: 1; transform: translate(-50%, -6px) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -76px) scale(1); }
}

.carta {
  flex: 1 1 auto; max-height: 46vh;
  display: flex; flex-direction: column; justify-content: center;
  align-items: center; text-align: center; gap: 6px;
  margin: auto 0; padding: 26px 20px;
  border-radius: 22px;
  background: linear-gradient(180deg, #ffffff0f, #ffffff05);
  border: 1px solid var(--line);
  box-shadow:
    inset 0 1px 0 #ffffff1a,
    0 0 calc(10px + 46px * var(--tensione)) calc(-14px + 6px * var(--tensione)) rgba(214, 86, 72, calc(.25 + .55 * var(--tensione)));
}
.carta .di {
  font-family: var(--mono); font-size: 11px; letter-spacing: .2em;
  text-transform: uppercase; color: #6F7A86; margin: 0;
}
.carta .consegna {
  font-family: var(--display); font-weight: 800;
  font-size: clamp(1.85rem, 8.4vw, 2.7rem); line-height: 1.06;
  letter-spacing: -.035em; margin: 0; text-wrap: balance;
}
.carta.gira { animation: giracarta .34s cubic-bezier(.2, .9, .25, 1) both; }
@keyframes giracarta {
  0% { opacity: 0; transform: translateY(14px) scale(.97); }
  100% { opacity: 1; transform: none; }
}

/* Il palloncino piccolo trema sempre più in fretta man mano che il
   giro va avanti, allo stesso ritmo del ticchettio: --tensione segue il
   tempo vero che manca allo scoppio. */
.mini-palla {
  width: calc(74px + 34px * var(--tensione));
  margin: 22px auto;
  animation: trema calc(1.5s - 1.15s * var(--tensione)) ease-in-out infinite;
  filter: drop-shadow(0 8px 16px #0008);
}
.mini-palla svg { display: block; width: 100%; height: auto; }
@keyframes trema {
  0%, 100% { transform: rotate(calc(-3deg - 5deg * var(--tensione))) scale(1, 1); }
  50% { transform: rotate(calc(3deg + 5deg * var(--tensione))) scale(calc(1 + .06 * var(--tensione)), calc(1 - .06 * var(--tensione))); }
}

.passa {
  flex: none; width: 100%; border: 0; border-radius: 20px;
  padding: 24px; font-family: var(--display); font-weight: 800;
  font-size: 1.5rem; letter-spacing: -.02em; color: #2A0A06;
  background: linear-gradient(180deg, #F08A7B 0%, var(--gomma) 55%, #A63A2F 100%);
  box-shadow: 0 16px 34px -16px #D65648cc, inset 0 1px 0 #ffffff55;
  transition: transform .1s ease, filter .1s ease;
}
.passa:active { transform: translateY(3px) scale(.985); filter: brightness(.93); }
.passa:focus-visible { outline: 3px solid var(--paper); outline-offset: 3px; }

.scossa { animation: scossa .5s cubic-bezier(.36, .07, .19, .97) both; }
@keyframes scossa {
  10%, 90% { transform: translate3d(-2px, 1px, 0); }
  20%, 80% { transform: translate3d(5px, -3px, 0); }
  30%, 50%, 70% { transform: translate3d(-9px, 2px, 0); }
  40%, 60% { transform: translate3d(9px, -2px, 0); }
}

/* ── gavettone e fine ─────────────────────────────────────────────── */

/* Lo schermo del gavettone si stacca dal flusso di impilamento e
   passa sopra al velo d'acqua: il testo resta nitido, le gocce gli
   scorrono davanti. */
#s-boom.on, #s-fine.on { position: relative; z-index: 65; }

.zuppo {
  font-size: clamp(3rem, 17vw, 5rem); line-height: .92; margin: 2px 0 10px;
  letter-spacing: -.05em;
  background: linear-gradient(180deg, #fff 0%, var(--acqua-hi) 45%, var(--acqua) 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 18px #4FB6EA66);
  animation: zac .5s cubic-bezier(.18, 1.5, .4, 1) both;
}
@keyframes zac {
  0% { opacity: 0; transform: scale(.55) rotate(-6deg); }
  100% { opacity: 1; transform: none; }
}

.tab { list-style: none; margin: 16px 0; padding: 0; text-align: left; }
.tab li {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border-radius: 11px; background: #ffffff08;
  border: 1px solid var(--line-soft); margin-bottom: 6px;
}
.tab li b { font-weight: 600; flex: 1; }
.tab li i {
  font-style: normal; font-family: var(--mono); font-size: 10.5px;
  color: #6F7A86; letter-spacing: .06em; white-space: nowrap;
}
.tab li span {
  font-family: var(--mono); font-size: 12.5px; color: var(--acqua-hi);
  letter-spacing: .04em; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.tab li.fuori { opacity: .48; }
.tab li.fuori b { text-decoration: line-through; }

#s-boom .grosso, #s-fine .fondo { margin-top: auto; }

/* ── modali ───────────────────────────────────────────────────────── */

.modale {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  background: #05080Ccc; backdrop-filter: blur(6px);
  padding: 18px; padding-bottom: calc(18px + env(safe-area-inset-bottom));
  animation: entra .2s ease both;
}
.modale[hidden] { display: none; }
.foglio {
  width: 100%; max-width: 520px; border-radius: 22px; padding: 22px 20px;
  background: linear-gradient(180deg, #16222E, #0E161E);
  border: 1px solid var(--line);
  box-shadow: 0 30px 70px -30px #000;
  animation: sali .28s cubic-bezier(.2, .9, .25, 1) both;
}
@keyframes sali { from { transform: translateY(28px); } to { transform: none; } }

.passi { list-style: none; counter-reset: p; margin: 0 0 18px; padding: 0; }
.passi li { counter-increment: p; padding: 10px 0 10px 40px; position: relative; border-top: 1px solid var(--line-soft); }
.passi li:first-child { border-top: 0; }
.passi li::before {
  content: counter(p); position: absolute; left: 0; top: 12px;
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--mono); font-size: 12px; color: var(--acqua);
  background: #4FB6EA1f; border: 1px solid #4FB6EA55;
}
.passi li b { display: block; font-weight: 600; }
.passi li span { display: block; font-size: .89rem; color: var(--paper-dim); line-height: 1.45; }
.passi li span b { display: inline; color: var(--paper); }

.modale.scena .foglio {
  background: linear-gradient(180deg, #2E1A18, #1A0F0E);
  border-color: #D6564855;
}
.modale.scena .eyebrow {
  color: var(--gomma); font-size: 26px; letter-spacing: 0; margin: 0 0 2px;
}
.modale.scena .grosso {
  background: linear-gradient(180deg, #F5A899, var(--gomma) 55%, #A63A2F);
  color: #2A0A06;
  box-shadow: 0 12px 30px -14px #D65648cc, inset 0 1px 0 #ffffff55;
}

/* ═══ LO SCOPPIO ═══════════════════════════════════════════════════
   Quattro strati. L'ondata è un gradiente radiale che si allarga dal
   punto dello scoppio: un alone, non un disco — l'acqua che arriva
   addosso non ha un bordo netto. I grumi sono un canvas con una
   sfocatura leggera addosso (il perché non sia un metaball sta scritto
   in js/scoppio.js). Il velo sfoca quello che gli sta sotto. Le
   colature vivono in un contenitore a parte, più in alto di tutto. */

.gav, .gav-alto {
  position: fixed; inset: 0; pointer-events: none;
  opacity: 0; visibility: hidden; transition: opacity .3s ease;
}
.gav { z-index: 60; }
.gav-alto { z-index: 70; }
.gav.on, .gav-alto.on { opacity: 1; visibility: visible; }
.gav.asciuga, .gav-alto.asciuga { opacity: 0; transition: opacity .62s ease; }

.gav-goo, .gav-scia, .gav-teste { position: absolute; inset: 0; display: block; }

/* L'opacità la scrive il gioco fotogramma per fotogramma: qui niente
   transition, o le due cose si darebbero fastidio a vicenda.
   La sfocatura sui grumi è quella del movimento; quella sulle colature
   serve a togliere le costole che lascia la scia quando la goccia
   scorre piano e le passate si sovrappongono quasi ferme. */
.gav-goo { filter: blur(3px); }
.gav-scia { filter: blur(1.4px); }

.gav-onda {
  position: absolute; inset: 0; opacity: 0;
  transform: scale(.14);
  transform-origin: var(--ox, 50%) var(--oy, 50%);
  background: radial-gradient(circle at var(--ox, 50%) var(--oy, 50%),
    #E4F8FFdd 0%, #8FDCFFb0 18%, #3FA6E07a 38%, #1E6E9e33 56%, transparent 72%);
}
.gav.on .gav-onda { animation: ondata .95s cubic-bezier(.16, .8, .3, 1) forwards; }
@keyframes ondata {
  0%   { opacity: 0; transform: scale(.14); }
  12%  { opacity: 1; }
  55%  { opacity: .78; }
  100% { opacity: 0; transform: scale(2.9); }
}

.gav-velo {
  position: absolute; inset: 0; opacity: 0;
  transition: opacity .6s ease;
  backdrop-filter: blur(2px) saturate(1.22) brightness(1.06);
  -webkit-backdrop-filter: blur(2px) saturate(1.22) brightness(1.06);
  background:
    radial-gradient(120% 70% at 26% 16%, #DAF4FF20 0%, transparent 58%),
    radial-gradient(130% 85% at 50% 30%, #9FE3FF1c 0%, transparent 66%),
    linear-gradient(180deg, #A8E6FF12 0%, #2E86B822 100%);
}
.gav.bagnato .gav-velo { opacity: 1; }

/* ── meno movimento ───────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .mini-palla { width: 68px; }
}

/* ── schermi grandi ───────────────────────────────────────────────── */

@media (min-width: 720px) and (min-height: 640px) {
  body { font-size: 18px; }
  .carta { padding: 40px 30px; }
  .passa { padding: 28px; font-size: 1.7rem; }
}
