/* ===== Hub PWA — stile coerente con la home (playful chiaro) ===== */
:root {
  --primary: #FF6B6B;     /* sovrascritto a runtime col tema dell'utente */
  --yellow: #FFD93D; --coral: #FF6B6B; --green: #2DCE89;
  --dark: #1a1a2e; --white: #fff; --bg: #FFF9F0; --muted: #6b7280;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body { font-family: 'Nunito', sans-serif; background: var(--bg); color: var(--dark); min-height: 100dvh; }
.hidden { display: none !important; }

/* ---- Lobby ---- */
#lobby { max-width: 760px; margin: 0 auto; padding: 22px 16px 40px; }
.hero { text-align: center; padding: 18px 8px 26px; position: relative; }
.hero > *:not(.hero-polaroids) { position: relative; z-index: 1; }

/* ---- Polaroid decorative con le foto della collezione ---- */
.hero-polaroids { position: absolute; inset: -6px 0 0; pointer-events: none; z-index: 0; }
.hero-polaroids .polaroid {
  position: absolute; background: #fff; border: 2px solid var(--dark);
  padding: 4px 4px 13px; box-shadow: 3px 3px 0 var(--dark); width: 66px;
}
.hero-polaroids .polaroid img { width: 100%; height: 56px; object-fit: cover; display: block; }
.hero-polaroids .pp0 { top: -4px; left: 1%; transform: rotate(-8deg); }
.hero-polaroids .pp1 { top: 0; right: 1%; transform: rotate(7deg); }
.hero-polaroids .pp2, .hero-polaroids .pp3 { display: none; }
@media (min-width: 640px) {
  .hero-polaroids .polaroid { width: 84px; }
  .hero-polaroids .polaroid img { height: 74px; }
  .hero-polaroids .pp2 { display: block; bottom: -10px; left: 7%; transform: rotate(5deg); }
  .hero-polaroids .pp3 { display: block; bottom: -6px; right: 8%; transform: rotate(-6deg); }
}
.hero .badge {
  display: inline-block; background: var(--coral); color: #fff;
  font-weight: 800; font-size: 12px; letter-spacing: .5px; text-transform: uppercase;
  padding: 6px 14px; border-radius: 999px; margin-bottom: 12px; border: 2px solid var(--dark);
}
.hero h1 { font-family: 'Fredoka One', cursive; margin: 0 0 6px; font-size: clamp(1.8rem, 6vw, 2.2rem); color: var(--dark); }
.hero p { margin: 0; color: var(--muted); font-size: 15px; font-weight: 600; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-top: 20px; }
.game-card {
  background: var(--white); border: 3px solid var(--dark); border-radius: 20px;
  padding: 18px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 10px;
  min-height: 150px; box-shadow: 5px 5px 0 var(--dark); transition: transform .15s, box-shadow .15s;
}
.game-card:active { transform: translate(2px, 2px); box-shadow: 3px 3px 0 var(--dark); }
.game-card .icon { font-size: 40px; }
.game-card .name { font-family: 'Fredoka One', cursive; font-size: 18px; }
.game-card .best { margin-top: auto; color: var(--muted); font-size: 13px; font-weight: 800; }
.game-card .best b { color: var(--primary); }

.game-card { position: relative; }
.game-card .ribbon {
  position: absolute; top: -10px; right: -8px; background: var(--yellow); color: var(--dark);
  border: 2px solid var(--dark); border-radius: 999px; font-size: 11px; font-weight: 800;
  padding: 4px 10px; transform: rotate(6deg); box-shadow: 2px 2px 0 var(--dark);
}
.game-card.locked { opacity: .62; filter: grayscale(.4); }
.game-card.locked .ribbon.lock { background: var(--white); font-size: 13px; }
.game-card.locked .best { color: var(--muted); }

/* ---- Nome giocatore ---- */
.name-chip {
  margin-top: 12px; background: var(--white); border: 2px solid var(--dark); border-radius: 999px;
  padding: 7px 16px; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 13px;
  color: var(--dark); cursor: pointer; box-shadow: 3px 3px 0 var(--dark);
}
.name-chip:active { transform: translate(1px, 1px); box-shadow: 2px 2px 0 var(--dark); }
#nameModal, #gbModal, #tourneyModal {
  position: fixed; inset: 0; z-index: 60; background: rgba(26,26,46,.55);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.nm-card {
  background: var(--white); border: 3px solid var(--dark); border-radius: 20px;
  box-shadow: 6px 6px 0 var(--dark); padding: 22px; max-width: 320px; width: 100%; text-align: center;
}
.nm-emoji { font-size: 38px; }
.nm-card h3 { font-family: 'Fredoka One', cursive; margin: 6px 0; font-weight: 400; }
.nm-card p { color: var(--muted); font-size: 13px; font-weight: 600; margin: 0 0 12px; }
#nameInput, #gbName {
  width: 100%; border: 3px solid var(--dark); border-radius: 12px; padding: 11px 12px;
  font-size: 16px; font-weight: 800; font-family: inherit; text-align: center; outline: none;
}
#nameInput:focus, #gbName:focus { border-color: var(--primary); }
.nm-row { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.nm-row button {
  border: 3px solid var(--dark); border-radius: 50px; padding: 10px 20px; font-weight: 400;
  font-family: 'Fredoka One', cursive; font-size: 15px; background: var(--green); color: #fff;
  cursor: pointer; box-shadow: 4px 4px 0 var(--dark);
}
.nm-row button.ghost { background: var(--white); color: var(--dark); }
.nm-row button:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--dark); }

.section-title { font-family: 'Fredoka One', cursive; margin: 30px 0 12px; font-size: 18px; color: var(--dark); }
.lb { background: var(--white); border: 3px solid var(--dark); border-radius: 16px; padding: 6px 4px; box-shadow: 5px 5px 0 var(--dark); }
.lb-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 2px solid #f0ece2; }
.lb-row:last-child { border-bottom: 0; }
.lb-row .rank { width: 26px; font-family: 'Fredoka One', cursive; color: var(--primary); text-align: center; }
.lb-row .who { flex: 1; font-weight: 800; }
.lb-row .pts { font-weight: 900; }
.lb-empty { color: var(--muted); padding: 16px; text-align: center; font-size: 14px; font-weight: 600; }
.lb-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 10px 6px; }
.lb-chips .chip {
  border: 2px solid var(--dark); border-radius: 999px; background: #fff; color: var(--dark);
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 12px; padding: 5px 12px; cursor: pointer;
}
.lb-chips .chip.on { background: var(--primary); color: #fff; }
.lb-row .rank.medal { font-size: 18px; }
.lb-row.top1 { background: #fff8dc; border-radius: 10px; }
.lb-row.top1 .who, .lb-row.top1 .pts { color: #8a6d00; }

/* ---- Torneo ---- */
#tourneyBar { margin: 16px 0 4px; }
.t-cta {
  display: block; width: 100%; border: 3px solid var(--dark); border-radius: 16px;
  background: var(--white); color: var(--dark); font-family: 'Fredoka One', cursive;
  font-size: 16px; padding: 14px; cursor: pointer; box-shadow: 5px 5px 0 var(--dark);
}
.t-cta:active { transform: translate(2px, 2px); box-shadow: 3px 3px 0 var(--dark); }
.t-cta.live { background: var(--primary); color: #fff; animation: tPulse 1.6s ease infinite; }
.t-cta.done { background: var(--yellow); }
@keyframes tPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.015); } }
.t-cta small { display: block; font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 12px; opacity: .85; margin-top: 3px; }
.t-chips { display: flex; flex-wrap: wrap; gap: 7px; justify-content: center; margin-top: 10px; }
.t-chips .chip {
  border: 2px solid var(--dark); border-radius: 999px; background: #fff; color: var(--dark);
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 13px; padding: 7px 13px; cursor: pointer;
}
.t-chips .chip.on { background: var(--primary); color: #fff; }
#tourneyView {
  position: fixed; inset: 0; z-index: 40; background: var(--dark); color: #fff;
  display: flex; flex-direction: column; align-items: center; padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  overflow: hidden;
}
#tourneyView::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background-image: radial-gradient(circle, rgba(255,217,61,.12) 1.5px, transparent 1.5px);
  background-size: 28px 28px;
}
#tourneyView > * { position: relative; z-index: 2; }
#tvClose {
  position: absolute; top: 14px; right: 16px; z-index: 3; width: 38px; height: 38px;
  border: 2px solid rgba(255,255,255,.5); border-radius: 50%; background: rgba(0,0,0,.3);
  color: #fff; font-size: 16px; font-weight: 800; cursor: pointer;
}
.tv-head { text-align: center; margin-top: 8px; }
.tv-kicker { font-weight: 800; font-size: 14px; letter-spacing: 1px; text-transform: uppercase; color: var(--yellow); }
.tv-game { font-family: 'Fredoka One', cursive; font-size: clamp(1.6rem, 6vw, 2.4rem); margin-top: 2px; }
.tv-timer {
  font-family: 'Fredoka One', cursive; font-size: clamp(3rem, 14vw, 5.5rem);
  color: var(--yellow); line-height: 1.1; font-variant-numeric: tabular-nums;
}
.tv-timer.low { color: #ff8a80; animation: tPulse .8s ease infinite; }
.tv-board {
  flex: 1; min-height: 0; width: 100%; max-width: 560px; overflow-y: auto;
  background: rgba(255,255,255,.07); border: 2px solid rgba(255,255,255,.18);
  border-radius: 18px; padding: 8px 6px; margin: 14px 0;
}
.tv-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-bottom: 1px solid rgba(255,255,255,.1); font-weight: 800; font-size: 17px;
}
.tv-row:last-child { border-bottom: 0; }
.tv-row .rank { width: 34px; text-align: center; font-family: 'Fredoka One', cursive; color: var(--yellow); }
.tv-row .who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tv-row .pts { font-variant-numeric: tabular-nums; font-size: 19px; }
.tv-row.top1 { background: rgba(255,217,61,.14); border-radius: 12px; font-size: 20px; }
.tv-empty { color: rgba(255,255,255,.6); text-align: center; padding: 30px 14px; font-weight: 700; }
#tvPlay {
  border: 3px solid #fff; border-radius: 50px; padding: 13px 30px;
  font-family: 'Fredoka One', cursive; font-size: 17px; background: var(--primary);
  color: #fff; cursor: pointer; box-shadow: 0 6px 16px rgba(0,0,0,.4); flex: none;
}
#tvPlay:active { transform: scale(.96); }

/* ---- Libro degli ospiti ---- */
.gb-sub { color: var(--muted); font-size: 13px; font-weight: 600; margin: -4px 0 12px; }
.gb-cta {
  display: block; width: 100%; border: 3px solid var(--dark); border-radius: 16px;
  background: var(--yellow); color: var(--dark); font-family: 'Fredoka One', cursive;
  font-size: 16px; padding: 14px; cursor: pointer; box-shadow: 5px 5px 0 var(--dark); margin-bottom: 14px;
}
.gb-cta:active { transform: translate(2px, 2px); box-shadow: 3px 3px 0 var(--dark); }
.gb-wall { display: flex; flex-direction: column; gap: 12px; }
.gb-entry { background: #fff; border: 3px solid var(--dark); border-radius: 16px; box-shadow: 4px 4px 0 var(--dark); padding: 12px 14px; }
.gb-head { font-weight: 900; font-size: 14px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.gb-when { color: var(--muted); font-size: 11px; font-weight: 700; }
.gb-text { margin: 6px 0 0; font-weight: 600; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.gb-photo { width: 100%; max-height: 260px; object-fit: cover; border: 2px solid var(--dark); border-radius: 12px; margin-top: 8px; display: block; }
.gb-entry audio { width: 100%; margin-top: 8px; }
.gb-card { max-width: 380px; }
.gb-card textarea {
  width: 100%; border: 3px solid var(--dark); border-radius: 12px; padding: 10px 12px;
  font-size: 15px; font-weight: 700; font-family: inherit; resize: vertical; margin-top: 8px; outline: none;
}
.gb-card textarea:focus { border-color: var(--primary); }
.gb-tools { display: flex; gap: 8px; justify-content: center; margin-top: 10px; flex-wrap: wrap; }
.gb-tool {
  border: 2px solid var(--dark); border-radius: 999px; background: #fff; color: var(--dark);
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 13px; padding: 8px 14px;
  cursor: pointer; box-shadow: 2px 2px 0 var(--dark);
}
.gb-tool.on { background: var(--coral); color: #fff; }
#gbAttach .gb-chipfile {
  display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; font-weight: 800;
  background: #f4ede1; border: 2px solid var(--dark); border-radius: 10px; padding: 6px 10px; text-align: left;
}
#gbAttach .gb-chipfile button { margin-left: auto; border: 0; background: transparent; cursor: pointer; font-size: 14px; }
#gbAttach img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; border: 2px solid var(--dark); }
#gbAttach audio { height: 32px; max-width: 170px; }
.gb-info { color: #b02a2a; font-size: 12px; font-weight: 800; min-height: 14px; margin: 6px 0 0; }

/* ---- Loop virale ---- */
.made-by {
  text-align: center; margin-top: 28px; color: var(--muted); font-size: 13px; font-weight: 700;
}
.made-by a { color: var(--primary); font-weight: 800; }

/* ---- Install banner ---- */
#installBar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  background: var(--dark); color: #fff; padding: 11px 14px; font-weight: 800; font-size: 14px;
  border-bottom: 4px solid var(--yellow);
}
#installBar button { margin-left: auto; background: var(--green); color: #fff; border: 2px solid #fff; border-radius: 10px; padding: 8px 14px; font-weight: 800; cursor: pointer; }
#installBar .close { background: transparent; border: 0; padding: 8px; }

/* ---- Player overlay (iframe) ---- */
#player { position: fixed; inset: 0; z-index: 50; background: #fff; display: flex; flex-direction: column; }
#playerBar { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--dark); color: #fff; border-bottom: 4px solid var(--yellow); }
#playerBar button { background: var(--coral); color: #fff; border: 2px solid #fff; border-radius: 10px; padding: 8px 14px; font-weight: 800; cursor: pointer; flex: none; white-space: nowrap; }
#playerBar .title { font-family: 'Fredoka One', cursive; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#playerBar .best { margin-left: auto; color: rgba(255,255,255,.8); font-size: 13px; font-weight: 800; white-space: nowrap; flex: none; }
@media (max-width: 420px) {
  #playerBar { gap: 7px; padding: 8px 10px; }
  #playerBar button { padding: 7px 10px; font-size: 13px; }
  #playerBar .best { font-size: 11px; }
}
#gameFrame { flex: 1; width: 100%; border: 0; background: var(--bg); }

/* ---- Bottone sfida (share punteggio) ---- */
#playerBar .share { background: var(--green); }
#playerBar .share.pulse { animation: sharePulse 1.2s ease 2; }
@keyframes sharePulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }

/* ---- Reveal primo accesso (la "scartata" del regalo) ---- */
#reveal {
  position: fixed; inset: 0; z-index: 80; background: var(--primary);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 28px 22px; text-align: center; overflow: hidden;
}
#reveal::after { /* vignetta morbida come nelle icone */
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at 50% 32%, rgba(255,255,255,.20), rgba(0,0,0,.18) 78%);
  pointer-events: none;
}
#reveal > * { position: relative; z-index: 2; }
#reveal .rv-kicker {
  color: rgba(255,255,255,.95); font-weight: 800; font-size: 16px; letter-spacing: .4px;
  opacity: 0; animation: rvFade .9s ease .15s forwards;
}
#reveal .rv-photos { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 20px 0 10px; max-width: 430px; }
#reveal .rv-photos .polaroid {
  width: 92px; background: #fff; border: 2px solid var(--dark);
  padding: 4px 4px 14px; box-shadow: 4px 4px 0 rgba(0,0,0,.28);
  opacity: 0; transform: scale(.2) rotate(0deg);
}
#reveal .rv-photos .polaroid.in { animation: rvPop .55s cubic-bezier(.2,1.6,.4,1) forwards; }
#reveal .rv-photos img { width: 100%; height: 84px; object-fit: cover; display: block; }
#reveal h1 {
  font-family: 'Fredoka One', cursive; color: #fff; margin: 8px 0 2px;
  font-size: clamp(1.9rem, 7vw, 2.6rem); text-shadow: 3px 3px 0 rgba(0,0,0,.22);
  opacity: 0; transform: scale(.2);
}
#reveal h1.in { animation: rvPop .6s cubic-bezier(.2,1.6,.4,1) forwards; }
#reveal .rv-open {
  margin-top: 22px; border: 3px solid var(--dark); border-radius: 50px; padding: 14px 30px;
  font-family: 'Fredoka One', cursive; font-size: 18px; background: var(--yellow); color: var(--dark);
  cursor: pointer; box-shadow: 5px 5px 0 rgba(0,0,0,.3); opacity: 0; transform: scale(.2);
}
#reveal .rv-open.in { animation: rvPop .55s cubic-bezier(.2,1.6,.4,1) forwards; }
#reveal .rv-open:active { transform: translate(2px, 2px); }
#reveal .rv-skip {
  position: absolute; top: 14px; right: 16px; z-index: 3; background: rgba(0,0,0,.28);
  color: #fff; border: 0; border-radius: 999px; padding: 8px 14px;
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 12px; cursor: pointer;
}
.rv-confetti {
  position: absolute; top: -16px; width: 10px; height: 14px; border-radius: 2px;
  z-index: 1; animation: rvFall linear forwards;
}
@keyframes rvFade { to { opacity: 1; } }
@keyframes rvPop { to { opacity: 1; transform: scale(1) rotate(var(--rot, 0deg)); } }
@keyframes rvFall { to { transform: translateY(112vh) rotate(720deg); } }

/* ---- Loader / error ---- */
.center { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px; text-align: center; }
.center h2 { font-family: 'Fredoka One', cursive; }
.center p { color: var(--muted); font-weight: 600; }
.spinner { width: 42px; height: 42px; border: 5px solid rgba(26,26,46,.15); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
