:root {
  --bg: #07070d;
  --panel: #12121d;
  --panel-2: #181828;
  --text: #f2f2f7;
  --text-dim: #9494ab;
  --accent: #00ffb2;
  --accent-2: #8b5cff;
  --accent-3: #00c2ff;
  --danger: #ff4d6d;
  --gold: #ffb14d;
  --radius: 20px;
  --glow-green: 0 0 24px rgba(0, 255, 178, 0.35);
  --glow-purple: 0 0 24px rgba(139, 92, 255, 0.3);
  /* font "display" per i momenti grandi: SF Rounded su iOS/macOS,
     fallback di sistema altrove — zero byte scaricati */
  --font-display: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold",
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

/* sfondo vivo: due nebulose neon che derivano lentamente */
body::before {
  content: "";
  position: fixed;
  inset: -30%;
  background:
    radial-gradient(38% 30% at 22% 18%, rgba(139, 92, 255, 0.16), transparent 70%),
    radial-gradient(34% 28% at 80% 75%, rgba(0, 255, 178, 0.12), transparent 70%),
    radial-gradient(26% 22% at 70% 20%, rgba(0, 194, 255, 0.08), transparent 70%);
  animation: aurora 16s ease-in-out infinite alternate;
  pointer-events: none;
  z-index: 0;
}
@keyframes aurora {
  from { transform: translate3d(-3%, -2%, 0) scale(1); }
  to   { transform: translate3d(3%, 3%, 0) scale(1.08); }
}

.screen {
  display: none;
  position: fixed;
  inset: 0;
  overflow-y: auto;
  /* i bagliori decorativi assoluti (es. hero::before) sbordano di proposito:
     senza questo, il browser aggiunge uno scroll orizzontale senza senso */
  overflow-x: hidden;
  z-index: 1;
}
.screen.active {
  display: block;
  animation: screenIn 0.35s ease both;
}
@keyframes screenIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- HOME ---------- */
/* il contenitore scrollabile è a tutta larghezza (la rotella funziona
   ovunque, anche su desktop); la colonna è l'elemento interno */
#screen-home {
  padding: 0;
}
.home-inner {
  max-width: 480px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px 32px;
}

.logo {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
}
.logo-mark {
  width: 54px;
  height: 54px;
  border-radius: 15px;
  box-shadow: 0 0 18px rgba(0, 255, 178, 0.25);
  flex: none;
}
.logo h1 {
  font-family: var(--font-display);
  font-size: 2.6rem;
  font-weight: 900;
  letter-spacing: -1.5px;
}
.logo h1 span {
  background: linear-gradient(115deg, var(--accent), var(--accent-3));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 14px rgba(0, 255, 178, 0.45));
}
.tagline {
  color: var(--text-dim);
  margin-top: 2px;
  letter-spacing: 0.4px;
}
.btn-mute {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid #262640 !important;
}

/* banner del duello ricevuto: sopra la hero, non si può non vedere */
.duel-banner {
  margin-top: 20px;
  padding: 18px;
  text-align: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, var(--panel-2), var(--panel)) padding-box,
    linear-gradient(135deg, rgba(255, 177, 77, 0.7), rgba(255, 77, 109, 0.6)) border-box;
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.45), 0 0 24px rgba(255, 177, 77, 0.25);
}
.duel-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1.45;
}
.duel-banner .btn-primary {
  background: linear-gradient(115deg, var(--gold), #ff8f5c);
  box-shadow: 0 0 22px rgba(255, 177, 77, 0.4);
}

.result-duel {
  margin-top: 10px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  min-height: 1.2em;
}
.duel-name-row { margin-top: 12px; }
.duel-name-row input {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid #2e2e48;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 1rem;
  text-align: center;
}

/* hero del giorno: niente scatola — la sfida è il palcoscenico */
.hero {
  position: relative;
  margin-top: 20px;
  padding: 26px 8px 8px;
  text-align: center;
}
.hero::before {
  content: "";
  position: absolute;
  inset: -10% -30%;
  background: radial-gradient(50% 55% at 50% 38%, rgba(0, 255, 178, 0.13), transparent 70%);
  pointer-events: none;
}
.hero > * { position: relative; }
.daily-label {
  display: inline-block;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 3px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0, 255, 178, 0.08);
  border: 1px solid rgba(0, 255, 178, 0.25);
}
.daily-emoji {
  font-size: 5.2rem;
  margin: 18px 0 8px;
  filter: drop-shadow(0 8px 26px rgba(0, 255, 178, 0.35));
  animation: floaty 3.2s ease-in-out infinite;
}
@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-7px); }
}
/* attract mode: il gioco che si gioca da solo al posto dell'emoji statica */
.attract-wrap {
  position: relative;
  margin: 14px auto 4px;
  max-width: 400px;
  cursor: pointer; /* la demo è essa stessa un bottone Gioca */
}
.attract-wrap canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 16px;
  border: 1px solid #262640;
  background: #0d0d17;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
.attract-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  border: 1px solid #2e2e48;
  border-radius: 999px;
  padding: 3px 9px;
  background: rgba(7, 7, 13, 0.65);
}
.hero h2 { font-family: var(--font-display); font-size: 1.65rem; font-weight: 900; letter-spacing: -0.5px; }
.hero p { color: var(--text-dim); margin-top: 8px; font-size: 0.95rem; line-height: 1.45; max-width: 40ch; margin-inline: auto; }
.daily-best { margin-top: 12px; font-size: 0.9rem; color: var(--accent); min-height: 1.2em; }
.daily-streak { margin-top: 4px; font-size: 0.9rem; color: var(--gold); min-height: 1.2em; text-shadow: 0 0 12px rgba(255, 177, 77, 0.4); }

.btn-primary {
  margin-top: 18px;
  width: 100%;
  max-width: 340px;
  padding: 15px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(115deg, var(--accent), var(--accent-3));
  color: #03130d;
  font-size: 1.05rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  cursor: pointer;
  box-shadow: var(--glow-green);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 0 12px rgba(0, 255, 178, 0.25);
}
.btn-primary:disabled { opacity: 0.5; }

.btn-secondary {
  margin-top: 10px;
  width: 100%;
  padding: 13px;
  border: 1px solid #2e2e48;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.12s ease;
}
.btn-secondary:active { transform: scale(0.98); border-color: var(--accent); }

/* Il duello non deve sparire accanto al RIPROVA: bordo viola sempre
   visibile, e al nuovo record si accende (è IL momento dello sfidare) */
#btn-duel { border-color: rgba(139, 92, 255, 0.55); }
/* Condividi in ciano: visibile ma un gradino sotto il duello — la
   scala resta RIPROVA > sfida > condividi > home */
#btn-share {
  border-color: rgba(0, 194, 255, 0.45);
  box-shadow: 0 0 12px rgba(0, 194, 255, 0.18);
}
#btn-duel.btn-peak {
  border-color: var(--accent-2);
  background: linear-gradient(115deg, rgba(139, 92, 255, 0.28), rgba(0, 194, 255, 0.18));
  box-shadow: 0 0 18px rgba(139, 92, 255, 0.35);
  font-weight: 700;
}

.training { margin-top: 32px; }
.training-label {
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 12px;
}
/* griglia a mattonelle: niente scroll orizzontale, niente card tagliate,
   identica su mobile e desktop */
.challenge-grid {
  display: grid;
  /* minmax(0, 1fr), non 1fr: altrimenti il contenuto più largo (es. un
     nome lungo) allarga la sua colonna e la griglia sborda a destra */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.challenge-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
  background: var(--panel);
  border: 1px solid #232338;
  border-radius: 16px;
  padding: 14px 10px 12px;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.challenge-card:active {
  transform: scale(0.96);
  border-color: rgba(0, 255, 178, 0.5);
  box-shadow: var(--glow-green);
}
.challenge-card .c-emoji {
  font-size: 1.8rem;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(0, 255, 178, 0.1), rgba(139, 92, 255, 0.14));
  border: 1px solid rgba(139, 92, 255, 0.25);
}
.challenge-card .c-name {
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1.2;
  min-height: 2.4em;
  display: flex;
  align-items: center;
  max-width: 100%;
  overflow-wrap: break-word;
}
.challenge-card .c-sub {
  color: var(--text-dim);
  font-size: 0.72rem;
  line-height: 1.25;
  max-width: 100%;
  overflow-wrap: break-word;
}
.challenge-card .c-stars {
  font-size: 0.8rem;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(0, 255, 178, 0.5);
  min-height: 1.1em;
}

.privacy-note {
  margin-top: 28px;
  color: var(--text-dim);
  font-size: 0.8rem;
  text-align: center;
}
.privacy-note a { color: var(--accent); }
.status-note {
  margin-top: 8px;
  color: var(--danger);
  font-size: 0.85rem;
  text-align: center;
  min-height: 1.2em;
}

/* ---------- GIOCO ---------- */
#screen-game { background: #000; }

#cam { display: none; }

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#fx-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.fx-emoji {
  position: absolute;
  font-size: 2.6rem;
  will-change: transform;
  animation: fly linear forwards;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.6));
}
@keyframes fly {
  from { transform: translate(var(--x0), var(--y0)) rotate(0deg); }
  to   { transform: translate(var(--x1), var(--y1)) rotate(var(--rot)); }
}

#screen-game.flash::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0.55;
  animation: flashfade 0.35s forwards;
  pointer-events: none;
}
@keyframes flashfade { to { opacity: 0; } }

.hud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  padding: max(16px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
}

.hud-top {
  display: flex;
  align-items: center;
  gap: 12px;
}
.btn-icon {
  pointer-events: auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(7, 7, 13, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}
.hud-title {
  font-weight: 800;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(7, 7, 13, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 0.92rem;
}
.hud-timer {
  font-family: var(--font-display);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--accent);
  text-shadow: 0 0 16px rgba(0, 255, 178, 0.6), 0 1px 4px rgba(0, 0, 0, 0.8);
}

.meter {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.meter-track {
  position: relative;
  width: 14px;
  height: 180px;
  border-radius: 7px;
  background: rgba(7, 7, 13, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.15);
  overflow: hidden;
}
.meter-fill {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 0%;
  background: linear-gradient(180deg, var(--accent), var(--accent-3));
  box-shadow: 0 0 12px rgba(0, 255, 178, 0.7);
  transition: height 0.08s linear;
}
.meter-threshold {
  position: absolute;
  width: 100%;
  height: 2px;
  background: #fff;
  box-shadow: 0 0 6px #fff;
}
.meter-band {
  position: absolute;
  width: 100%;
  background: rgba(0, 255, 178, 0.28);
}
.meter-label {
  font-size: 0.7rem;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  writing-mode: vertical-rl;
}

.hud-center {
  align-self: center;
  font-family: var(--font-display);
  font-size: 5rem;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 30px rgba(0, 255, 178, 0.6), 0 2px 12px rgba(0, 0, 0, 0.7);
  min-height: 1em;
}
.hud-center.small { font-size: 1.4rem; font-weight: 800; }
.hud-center.pop { animation: pop 0.35s ease; }
/* codice colore dei momenti: verde = via, oro = livello, rosso = avviso */
.hud-center[data-tone="go"] {
  color: var(--accent);
  text-shadow: 0 0 36px rgba(0, 255, 178, 0.9), 0 2px 12px rgba(0, 0, 0, 0.7);
}
.hud-center[data-tone="gold"] {
  color: var(--gold);
  text-shadow: 0 0 26px rgba(255, 177, 77, 0.8), 0 2px 10px rgba(0, 0, 0, 0.7);
}
.hud-center[data-tone="warn"] {
  color: #ff8fa3;
  text-shadow: 0 0 26px rgba(255, 77, 109, 0.8), 0 2px 10px rgba(0, 0, 0, 0.7);
}
@keyframes pop {
  from { transform: scale(1.6); opacity: 0.3; }
  to   { transform: scale(1); opacity: 1; }
}

.hud-bottom { display: flex; flex-direction: column; gap: 8px; }
.practice-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.practice-bar[hidden] { display: none; }
.practice-text {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(7, 7, 13, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 255, 178, 0.3);
  line-height: 1.4;
  max-width: 480px;
}
.practice-sub {
  /* risponde a "che significa riscaldamento?" senza tornare alla prosa:
     una riga sulla STANZA, non sulla meccanica (feedback 34enne) */
  margin-top: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
}
.attract-caption { margin: 18px 0 10px; }
#grid-attract-slot .attract-wrap { margin: 0 auto 6px; }
.practice-label {
  /* dice "non è il gioco vero" senza prosa da leggere */
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}
.btn-via {
  pointer-events: auto;
  width: auto;
  min-width: 180px;
  margin-top: 0;
  padding: 13px 34px;
}
.progress-track {
  height: 14px;
  border-radius: 7px;
  background: rgba(7, 7, 13, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.15);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 14px rgba(0, 255, 178, 0.6);
  transition: width 0.1s linear;
}
.hud-hint {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  min-height: 1.3em;
}

/* ---------- RISULTATO ---------- */
#screen-result {
  display: none;
  background: rgba(7, 7, 13, 0.96);
}
#screen-result.active { display: flex; align-items: center; justify-content: center; }

.result-card {
  width: min(92vw, 400px);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 30px 24px;
  text-align: center;
  background:
    linear-gradient(160deg, var(--panel-2), var(--panel)) padding-box,
    linear-gradient(135deg, rgba(0, 255, 178, 0.5), rgba(139, 92, 255, 0.5)) border-box;
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.6), var(--glow-purple);
  animation: cardIn 0.4s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes cardIn {
  from { transform: scale(0.85) translateY(16px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.result-emoji {
  font-size: 4rem;
  filter: drop-shadow(0 6px 20px rgba(0, 255, 178, 0.3));
  animation: floaty 3.2s ease-in-out infinite;
}
.result-card h2 { margin-top: 10px; font-weight: 800; font-family: var(--font-display); }
.result-stars { font-size: 2rem; margin-top: 10px; letter-spacing: 6px; min-height: 1.2em; }
.result-stars span {
  display: inline-block;
  opacity: 0;
  animation: starPop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) forwards;
}
.result-stars span.on {
  color: var(--accent);
  text-shadow: 0 0 18px rgba(0, 255, 178, 0.7);
}
.result-stars span.off { color: rgba(255, 255, 255, 0.15); }
@keyframes starPop {
  from { opacity: 0; transform: scale(0) rotate(-40deg); }
  to   { opacity: 1; transform: scale(1) rotate(0); }
}
.result-detail { color: var(--text-dim); margin-top: 12px; line-height: 1.4; }
.result-best { color: var(--accent); margin-top: 6px; font-size: 0.9rem; min-height: 1.2em; }
.result-streak { color: var(--gold); margin-top: 6px; font-size: 0.95rem; min-height: 1.2em; text-shadow: 0 0 12px rgba(255, 177, 77, 0.4); }

.face-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 2px solid var(--accent);
  box-shadow: 0 0 16px rgba(0, 255, 178, 0.4), inset 0 0 14px rgba(0, 255, 178, 0.08);
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  transition: box-shadow 0.15s ease;
}
.face-toggle:has(input:checked) {
  box-shadow: 0 0 26px rgba(0, 255, 178, 0.7), inset 0 0 16px rgba(0, 255, 178, 0.15);
}
.face-toggle img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  background: #000;
  border: 1px solid rgba(0, 255, 178, 0.3);
}
.face-toggle-text {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-dim);
}
.face-toggle input { accent-color: var(--accent); width: 18px; height: 18px; }

.result-actions { margin-top: 18px; }

/* coriandoli sulla vittoria */
.confetti {
  position: absolute;
  top: -20px;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  z-index: 5;
  pointer-events: none;
  animation: confettiFall 1.9s ease-in forwards;
}
@keyframes confettiFall {
  from { transform: translateY(0) rotate(0deg); opacity: 1; }
  to   { transform: translateY(105vh) rotate(680deg); opacity: 0.8; }
}
