@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800;900&display=swap');

*, *::before, *::after { box-sizing: border-box; }

html { overflow-x: hidden; }

body {
  margin: 0;
  background: linear-gradient(160deg, #4caf61 0%, #2e7d42 40%, #1b5e2f 100%);
  min-height: 100vh;
  min-height: 100dvh;
  font-family: 'Poppins', sans-serif;
  text-align: center;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.main-container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding-top: max(72px, calc(52px + env(safe-area-inset-top, 0px)));
  padding-left: 24px;
  padding-right: 24px;
  padding-bottom: max(48px, calc(28px + env(safe-area-inset-bottom, 0px)));
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── TOPBAR ── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top, 12px)) 16px 12px;
  background: rgba(30, 94, 47, 0.55);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.topbar h1 {
  color: #FFF35A;
  font-size: 1.3rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.3px;
  text-shadow: 0 1px 8px rgba(0,0,0,0.3);
  flex: 1;
  text-align: center;
}

.subtitle {
  color: rgba(255,255,255,0.82);
  font-weight: 500;
  font-size: 0.92rem;
  margin: 8px auto 0;
  max-width: 85%;
  line-height: 1.5;
  letter-spacing: 0.1px;
}

/* ── SUPERSTAR TOGGLE ── */
.superstar-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(255,255,255,0.28);
  border-radius: 50px;
  padding: 8px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.superstar-toggle span {
  color: white;
  font-weight: 700;
  font-size: 0.9rem;
}
.toggle-switch {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}
.toggle-switch input { display: none; }
.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 13px;
  background: rgba(255,255,255,0.25);
  transition: background 0.25s;
}
.toggle-switch input:checked ~ .toggle-track {
  background: #ef4444;
}
.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toggle-switch input:checked ~ .toggle-thumb {
  transform: translateX(18px);
}

/* ── POOP ── */
.poop-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 48px;
  margin-bottom: 0;
  padding-bottom: 32px;
}

/* HALO */
.poop-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -58%);
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: radial-gradient(circle,
    rgba(255,243,90,0.55) 0%,
    rgba(255,230,80,0.25) 45%,
    transparent 72%
  );
  mix-blend-mode: screen;
  pointer-events: none;
  animation: glow-breathe 3s ease-in-out infinite;
  z-index: 0;
}
@keyframes glow-breathe {
  0%, 100% { transform: translate(-50%, -58%) scale(1);    opacity: 0.6; }
  50%       { transform: translate(-50%, -58%) scale(1.25); opacity: 0.9; }
}

/* SPARKLES */
.poop-sparks {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.poop-sparks span {
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255,243,90,0.9);
  box-shadow: 0 0 6px 2px rgba(255,243,90,0.6);
  animation: spark-twinkle 2.4s ease-in-out infinite;
}
/* 8 sparks placed around the poop */
.poop-sparks span:nth-child(1) { top:  2%; left: 48%; animation-delay: 0s;    width:5px; height:5px; }
.poop-sparks span:nth-child(2) { top: 15%; left: 82%; animation-delay: 0.3s;  width:4px; height:4px; }
.poop-sparks span:nth-child(3) { top: 48%; left: 92%; animation-delay: 0.6s;  width:6px; height:6px; }
.poop-sparks span:nth-child(4) { top: 78%; left: 78%; animation-delay: 0.9s;  width:4px; height:4px; }
.poop-sparks span:nth-child(5) { top: 88%; left: 44%; animation-delay: 1.2s;  width:5px; height:5px; }
.poop-sparks span:nth-child(6) { top: 75%; left: 10%; animation-delay: 1.5s;  width:4px; height:4px; }
.poop-sparks span:nth-child(7) { top: 44%; left:  2%; animation-delay: 1.8s;  width:6px; height:6px; }
.poop-sparks span:nth-child(8) { top: 12%; left: 18%; animation-delay: 2.1s;  width:4px; height:4px; }

@keyframes spark-twinkle {
  0%, 100% { transform: scale(0.4); opacity: 0; }
  40%, 60%  { transform: scale(1.2); opacity: 1; }
}

#poop {
  font-size: clamp(90px, 28vw, 120px);
  line-height: 1;
  position: relative;
  z-index: 1;
  cursor: pointer;
  transition: transform 0.1s ease-out;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  filter: drop-shadow(0 10px 20px rgba(0,0,0,0.3));
}

@keyframes poop-alive {
  /* riposo */
  0%   { transform: scale(1)       translateY(0)    rotate(0deg); }
  /* carica — si rimpicciolisce */
  8%   { transform: scale(0.82, 0.88) translateY(3px)  rotate(-4deg); }
  /* pop esplosivo */
  16%  { transform: scale(1.22, 0.88) translateY(-6px)  rotate(4deg); }
  /* salto in aria */
  26%  { transform: scale(0.9,  1.18) translateY(-22px) rotate(-3deg); }
  /* schiacciata atterraggio */
  36%  { transform: scale(1.28, 0.72) translateY(5px)   rotate(0deg); }
  /* rimbalzo 1 */
  44%  { transform: scale(0.94, 1.1)  translateY(-10px) rotate(0deg); }
  /* rimbalzo 2 piccolo */
  51%  { transform: scale(1.06, 0.94) translateY(0)     rotate(0deg); }
  56%  { transform: scale(0.98, 1.03) translateY(-4px)  rotate(0deg); }
  60%  { transform: scale(1)          translateY(0)     rotate(0deg); }
  /* wiggle sinistra-destra */
  65%  { transform: scale(1)          translateY(0)     rotate(-9deg); }
  70%  { transform: scale(1)          translateY(0)     rotate(9deg);  }
  75%  { transform: scale(1)          translateY(0)     rotate(-5deg); }
  80%  { transform: scale(1)          translateY(0)     rotate(0deg);  }
  /* riposo lungo */
  100% { transform: scale(1)          translateY(0)     rotate(0deg);  }
}

@keyframes smash-animation {
  0%   { transform: scale(1, 1); }
  30%  { transform: scale(1.3, 0.7) rotate(5deg); }
  50%  { transform: scale(0.9, 1.1) rotate(-3deg); }
  70%  { transform: scale(1.1, 0.9) rotate(2deg); }
  100% { transform: scale(1, 1); }
}
#poop {
  transform-origin: bottom center;
  animation: poop-alive 3.6s cubic-bezier(0.36, 0.07, 0.19, 0.97) infinite;
}
#poop.smashed { animation: smash-animation 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97); }

#prompt-text {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  white-space: nowrap;
  color: #FFF35A;
  font-size: 0.88rem;
  font-weight: 800;
  text-shadow: 0 1px 4px rgba(0,0,0,0.35);
  opacity: 0;
  transition: opacity 0.35s ease, transform 0.35s ease;
}
#prompt-text.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── INITIAL IMAGE ── */
#initial-image {
  display: block;
  margin: -25px auto 0;
  width: 160px;
  max-width: 75%;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,0.22));
  transition: opacity 0.4s;
  transform-origin: bottom center;
  animation: hand-tap 2.8s ease-in-out infinite;
}

@keyframes hand-tap {
  0%   { transform: translateY(0)    scale(1)         rotate(0deg); }
  14%  { transform: translateY(-12px) scale(1.04, 0.96) rotate(0deg); }
  26%  { transform: translateY(3px)  scale(0.86, 1.16) rotate(0deg); }
  36%  { transform: translateY(-5px) scale(1.02, 0.98) rotate(0deg); }
  44%  { transform: translateY(0)    scale(1)         rotate(0deg); }
  52%  { transform: translateY(0)    scale(1)         rotate(-7deg); }
  58%  { transform: translateY(0)    scale(1)         rotate(7deg); }
  64%  { transform: translateY(0)    scale(1)         rotate(-4deg); }
  70%  { transform: translateY(0)    scale(1)         rotate(0deg); }
  100% { transform: translateY(0)    scale(1)         rotate(0deg); }
}

/* ── RESULTS ── */
#results-area {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  opacity: 0;
  transition: opacity 0.5s;
}
#results-area.visible { display: flex; opacity: 1; }

#all-numbers-wrapper {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  margin-top: 20px;
  margin-bottom: 20px;
}

/* number card */
.numbers-row {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  background: white;
  border-radius: 32px;
  padding: 14px 18px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.13), 0 1px 4px rgba(0,0,0,0.07);
}

.number-ball {
  flex: 1;
  min-width: 0;
  max-width: 44px;
  aspect-ratio: 1;
  font-size: clamp(0.72rem, 3.2vw, 1.05rem);
  color: white;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 800;
  transform: scale(0);
  opacity: 0;
  animation: pop-in 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  background: linear-gradient(145deg, #22c55e, #16a34a);
  box-shadow: 0 3px 10px rgba(22,163,74,0.35);
}
.superstar-ball {
  background: linear-gradient(145deg, #ef4444, #dc2626);
  box-shadow: 0 3px 10px rgba(239,68,68,0.4);
}

@keyframes pop-in { to { transform: scale(1); opacity: 1; } }

/* ── ACTION BUTTONS ── */
#action-buttons-wrapper {
  display: flex;
  gap: 16px;
  align-items: center;
  width: 100%;
  justify-content: center;
}

.action-button {
  cursor: pointer;
  border: none;
  color: white;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: 'Poppins', sans-serif;
  border-radius: 50px;
  min-height: 40px;
  box-shadow: 0 3px 12px rgba(0,0,0,0.2);
}
.action-button:active { transform: scale(0.97); }
@media (hover: hover) {
  .action-button:hover { transform: scale(1.04); box-shadow: 0 6px 22px rgba(0,0,0,0.28); }
}

#resetButton {
  background: rgba(255,255,255,0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(255,255,255,0.38);
  flex: 1;
}
#saveButton {
  background: linear-gradient(135deg, #22c55e 0%, #15803d 100%);
  flex: 1.5;
}
#shareButton {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50px;
  flex-shrink: 0;
  background: rgba(255,255,255,0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(255,255,255,0.38);
}
#shareButton svg { width: 22px; height: 22px; stroke: white; stroke-width: 2.2; }

#saved-numbers-container {
  margin-top: 16px;
  display: none;
  width: 100%;
  justify-content: center;
}
#showSavedButton {
  background: rgba(255,255,255,0.18);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1.5px solid rgba(255,255,255,0.35);
  width: 100%;
}

/* ── TOPBAR BUTTONS ── */
#infoButton, #musicButton {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) {
  #infoButton:hover, #musicButton:hover { background: rgba(255,255,255,0.28); transform: scale(1.1); }
}
#infoButton:active, #musicButton:active { transform: scale(0.93); }
#infoButton { font-size: 0.82rem; font-weight: 800; font-family: 'Poppins', sans-serif; }
#musicButton svg { width: 15px; height: 15px; fill: white; }
#musicButton #sound-on-icon  { display: none; }
#musicButton #sound-off-icon { display: block; }
#musicButton.is-playing #sound-on-icon  { display: block; }
#musicButton.is-playing #sound-off-icon { display: none; }

/* ── POPUP OVERLAY ── */
.popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  justify-content: center;
  align-items: flex-end;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.popup-overlay.visible { display: flex; opacity: 1; }

/* bottom sheet */
.popup-box {
  background: white;
  padding: 8px 24px calc(28px + env(safe-area-inset-bottom, 0px));
  border-radius: 28px 28px 0 0;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 -4px 40px rgba(0,0,0,0.18);
  transform: translateY(100%);
  transition: transform 0.36s cubic-bezier(0.32, 0.72, 0, 1);
  text-align: center;
}
.popup-overlay.visible .popup-box { transform: translateY(0); }

/* drag handle */
.popup-box::before {
  content: '';
  display: block;
  width: 38px;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  margin: 12px auto 20px;
}

.popup-text { color: #111; font-weight: 700; font-size: 1.05rem; margin: 0 0 20px; text-shadow: none; }

.popup-buttons { display: flex; gap: 10px; justify-content: center; }

.confirm-button {
  padding: 14px 24px;
  font-size: 1rem;
  font-weight: 700;
  font-family: 'Poppins', sans-serif;
  border-radius: 50px;
  border: none;
  color: white;
  cursor: pointer;
  min-height: 50px;
  transition: transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.confirm-button:active { transform: scale(0.97); }
@media (hover: hover) { .confirm-button:hover { transform: scale(1.03); } }

.delete-button { background: linear-gradient(135deg, #ef4444, #dc2626); }
#confirm-ok-btn, #delete-confirm-ok-btn { background: linear-gradient(135deg, #22c55e, #15803d); }
#confirm-cancel-btn, #delete-confirm-cancel-btn { background: #f3f4f6; color: #374151; }
#saved-close-btn    { background: #f3f4f6; color: #374151; }
#save-success-ok-btn { background: linear-gradient(135deg, #22c55e, #15803d); width: 100%; }
#info-close-btn { background: linear-gradient(135deg, #22c55e, #15803d); display: block; margin: 20px auto 0; }

/* info sheet */
#info-box {
  text-align: left;
  max-height: 88dvh;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#info-box h2 { margin: 0 0 16px; color: #111; text-align: center; font-size: 1.2rem; }
#info-box p  { font-size: 0.92rem; line-height: 1.65; color: #4b5563; font-weight: 500; text-shadow: none; margin: 0 0 1em; }
#info-box blockquote {
  border-left: 3px solid #22c55e;
  padding: 10px 14px;
  margin: 16px 0;
  font-style: italic;
  color: #111;
  font-weight: 700;
  font-size: 0.9rem;
  background: #f0fdf4;
  border-radius: 0 10px 10px 0;
}

/* saved sheet */
#saved-box { text-align: left; max-height: 78vh; display: flex; flex-direction: column; }
#saved-box h2 { margin: 0 0 16px; color: #111; font-size: 1.2rem; text-align: center; }
#saved-list { overflow-y: auto; flex-grow: 1; }
.saved-date-group { margin-bottom: 16px; }
.saved-date-group:last-child { margin-bottom: 0; }
.saved-date-header {
  font-weight: 700;
  color: #9ca3af;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 10px;
  border-bottom: 1px solid #f3f4f6;
  padding-bottom: 6px;
}
#saved-list .numbers-row {
  margin-top: 8px;
  background: #f9fafb;
  box-shadow: none;
  border: 1px solid #f3f4f6;
  padding: 10px 12px;
  gap: 5px;
}
.saved-ball {
  animation: none;
  transform: scale(1);
  opacity: 1;
  max-width: 34px;
  font-size: 0.78rem;
}
.saved-buttons-footer { margin-top: 20px; display: flex; justify-content: space-between; gap: 10px; }

/* ── DISCLAIMER ── */
.disclaimer {
  margin-top: 10px;
  font-size: 0.7rem;
  font-weight: 400;
  color: rgba(255,255,255,0.45);
  line-height: 1.7;
  text-align: center;
  max-width: 85%;
  text-shadow: none;
}
.disclaimer a {
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  font-weight: 800;
  font-size: 0.78rem;
  background: rgba(255,255,255,0.12);
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ── COOKIE BANNER ── */
#cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: rgba(15, 40, 20, 0.97);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255,255,255,0.1);
  padding: 16px 20px max(20px, env(safe-area-inset-bottom, 20px));
  display: none;
}
#cookie-banner.visible { display: block; }
#cookie-banner p {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.8);
  line-height: 1.5;
  margin-bottom: 12px;
  text-shadow: none;
  font-weight: 400;
}
#cookie-banner a { color: #FFF35A; }
.cookie-buttons {
  display: flex;
  gap: 10px;
}
#cookie-accept, #cookie-decline {
  flex: 1;
  padding: 11px 16px;
  border: none;
  border-radius: 50px;
  font-family: 'Poppins', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#cookie-accept  { background: #22c55e; color: white; }
#cookie-decline { background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.75); border: 1px solid rgba(255,255,255,0.2); }
