/* ==========================================================================
   Dunp Bingo — tema estivo cartoon, mobile-first
   ========================================================================== */

:root {
  color-scheme: light;
  font-family: "Baloo 2", ui-rounded, "Segoe UI", system-ui, sans-serif;

  /* Palette tropicale */
  --ink: oklch(0.31 0.06 255);            /* blu notte profondo, testo/contorni */
  --ink-soft: oklch(0.45 0.05 250);       /* testo secondario, contrasto AA su chiaro */
  --shell: oklch(0.98 0.015 90);          /* conchiglia: superficie caselle */
  --sky-hi: oklch(0.87 0.09 230);         /* cielo in alto */
  --sky-lo: oklch(0.93 0.05 210);         /* cielo verso l'orizzonte */
  --sea: oklch(0.72 0.12 210);
  --sun: oklch(0.88 0.16 95);
  --lime: oklch(0.9 0.17 130);            /* casella marcata */
  --mint: oklch(0.78 0.15 165);           /* spunta */
  --coral: oklch(0.68 0.19 15);           /* azione / bingo */
  --mango: oklch(0.85 0.14 80);           /* bonus */
  --focus: oklch(0.55 0.22 300);          /* anello di focus, viola: visibile su ogni sfondo */

  /* Z-index semantico */
  --z-scene: 0;
  --z-content: 1;
  --z-tooltip: 10;
  --z-banner: 20;
  --z-face: 30;

  color: var(--ink);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100dvh;
  margin: 0;
  background: linear-gradient(180deg, var(--sky-hi) 0%, var(--sky-lo) 70%, oklch(0.95 0.04 200) 100%);
}

button {
  font: inherit;
}

/* Focus visibile e coerente ovunque */
:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ==========================================================================
   Scena estiva (decorativa, dietro al contenuto)
   ========================================================================== */

.scene {
  position: fixed;
  inset: 0;
  z-index: var(--z-scene);
  overflow: hidden;
  pointer-events: none;
}

.scene-sun {
  position: absolute;
  top: -22px;
  right: -20px;
  width: clamp(110px, 26vw, 190px);
}

.sun-rays {
  transform-origin: 100px 100px;
  animation: sunSpin 60s linear infinite;
}

.scene-cloud {
  position: absolute;
  width: clamp(70px, 12vw, 120px);
}

.scene-cloud-1 {
  top: 4px;
  left: 47%;
  animation: cloudDrift 26s ease-in-out infinite alternate;
}

.scene-cloud-2 {
  display: none;
  top: 26%;
  right: 1%;
  width: clamp(60px, 8vw, 100px);
  opacity: 0.9;
  animation: cloudDrift 34s ease-in-out infinite alternate-reverse;
}

.scene-sea {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2; /* il mare passa davanti ai tronchi delle palme */
  height: clamp(60px, 12vh, 110px);
}

.sea-wave {
  /* sbordano sotto e ai lati: il movimento non scopre mai il fondo */
  position: absolute;
  right: -40px;
  bottom: -28px;
  left: -40px;
  width: auto;
  height: calc(100% + 28px);
}

.sea-wave-back {
  transform: translateY(-14px);
  animation: waveBobBack 7s ease-in-out infinite alternate;
}

.sea-wave-front {
  animation: waveBobFront 5s ease-in-out infinite alternate;
}

.scene-palm {
  position: absolute;
  bottom: clamp(10px, 3vh, 34px);
  z-index: 1;
  width: clamp(90px, 22vw, 220px);
}

.scene-palm-left {
  left: clamp(-34px, -4vw, -12px);
  transform: rotate(-6deg);
}

.scene-palm-right {
  right: clamp(-34px, -4vw, -12px);
  transform: rotate(6deg) scaleX(-1);
}

/* ==========================================================================
   Layout — base mobile
   ========================================================================== */

.page {
  position: relative;
  z-index: var(--z-content);
  width: min(100% - 20px, 560px);
  margin: 0 auto;
  padding: 18px 0 clamp(90px, 16vh, 150px); /* spazio per il mare */
}

.hero {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
}

.eyebrow-row {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.eyebrow {
  margin: 0;
  padding: 4px 12px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--sun);
  box-shadow: 3px 3px 0 var(--ink);
  font-size: 0.82rem;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: clamp(1.9rem, 9vw, 3.6rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.01em;
  text-wrap: balance;
  text-shadow: 3px 3px 0 oklch(1 0 0 / 0.6);
}

/* --- Regole (tooltip) --- */

.rules-tooltip {
  position: relative;
  display: inline-grid;
  place-items: center;
}

.rules-trigger {
  display: grid;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  background: var(--shell);
  color: var(--ink);
  cursor: help;
  font-size: 0.95rem;
  font-weight: 800;
  line-height: 1;
  place-items: center;
  box-shadow: 2px 2px 0 var(--ink);
}

.rules-bubble {
  position: absolute;
  top: calc(100% + 12px);
  left: 50%;
  z-index: var(--z-tooltip);
  width: min(300px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: var(--shell);
  box-shadow: 5px 5px 0 var(--ink);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  text-transform: none;
  transform: translate(-50%, -6px);
  transition: opacity 140ms ease-out, transform 140ms ease-out;
}

.rules-bubble::after {
  content: "";
  position: absolute;
  top: -8px;
  left: 50%;
  width: 12px;
  height: 12px;
  border-top: 2.5px solid var(--ink);
  border-left: 2.5px solid var(--ink);
  background: var(--shell);
  transform: translateX(-50%) rotate(45deg);
}

.rules-tooltip:hover .rules-bubble,
.rules-tooltip:focus-within .rules-bubble {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --- Stato e azioni --- */

.hero-actions {
  display: grid;
  gap: 10px;
}

.status {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border: 2.5px solid var(--ink);
  border-radius: 14px;
  background: var(--shell);
  box-shadow: 5px 5px 0 var(--ink);
}

.status span {
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 700;
}

.status strong {
  font-size: 1.6rem;
  font-weight: 800;
}

/* ==========================================================================
   Board
   ========================================================================== */

.board-wrap {
  padding: 8px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: oklch(1 0 0 / 0.82);
  box-shadow: 6px 6px 0 var(--ink);
}

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.cell {
  position: relative;
  display: grid;
  min-height: 84px;
  padding: 6px 4px;
  border: 2.5px solid var(--ink);
  border-radius: 12px;
  background: var(--shell);
  color: var(--ink);
  cursor: pointer;
  place-items: center;
  text-align: center;
  overflow-wrap: anywhere;
  hyphens: auto;
  transition: transform 150ms ease-out, background 150ms ease-out, box-shadow 150ms ease-out;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cell span {
  font-size: clamp(0.62rem, 2.6vw, 0.8rem);
  font-weight: 700;
  line-height: 1.2;
}

.cell:hover:not(:disabled) {
  background: oklch(0.96 0.03 200);
  transform: translateY(-2px);
  box-shadow: 0 5px 0 oklch(0.31 0.06 255 / 0.25);
}

.cell:active:not(:disabled) {
  transform: scale(0.96);
}

.cell[aria-pressed="true"],
.cell.marked {
  background: var(--lime);
}

.cell.just-marked {
  animation: markPop 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cell.marked::after {
  content: "✓";
  position: absolute;
  top: 3px;
  right: 3px;
  display: grid;
  width: 20px;
  height: 20px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--mint);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 800;
  place-items: center;
}

.cell.bonus {
  background: var(--mango);
}

.cell.bonus::before {
  content: "🥥";
  display: block;
  margin-bottom: 2px;
  font-size: 1.3rem;
}

.cell.line-hit {
  animation: lineHit 900ms ease-out both;
}

.hint,
.footer {
  width: fit-content;
  margin: 16px auto 0;
  padding: 6px 16px;
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  background: var(--shell);
  box-shadow: 3px 3px 0 var(--ink);
  font-weight: 700;
  text-align: center;
}

.hint {
  font-size: 1rem;
}

.footer {
  font-size: 0.88rem;
}

/* ==========================================================================
   Banner Bingo
   ========================================================================== */

.bingo-banner {
  position: fixed;
  top: 22px;
  left: 50%;
  z-index: var(--z-banner);
  padding: 14px 28px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--coral);
  color: var(--ink);
  font-size: clamp(1.5rem, 6vw, 2rem);
  font-weight: 800;
  box-shadow: 6px 6px 0 var(--ink);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -80px) rotate(-3deg);
}

.bingo-banner.show {
  animation: bannerPop 1500ms ease-out both;
}

/* ==========================================================================
   Fumetto faccia
   ========================================================================== */

.face-bubble {
  position: fixed;
  z-index: var(--z-face);
  width: clamp(57px, 8.4vw, 83px);
  aspect-ratio: 1;
  padding: 5px;
  border: 2.5px solid var(--ink);
  border-radius: 50%;
  background: var(--shell);
  box-shadow: 5px 5px 0 var(--ink);
  pointer-events: none;
  transform-origin: center bottom;
  animation: faceBubblePop 1800ms cubic-bezier(0.2, 0.9, 0.2, 1) both;
}

.face-bubble img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* ==========================================================================
   Errore
   ========================================================================== */

.error {
  grid-column: 1 / -1;
  padding: 24px;
  border: 2.5px solid oklch(0.5 0.19 28);
  border-radius: 12px;
  background: oklch(0.96 0.02 28);
  color: oklch(0.38 0.14 28);
  font-weight: 700;
  text-align: center;
}

/* ==========================================================================
   Animazioni
   ========================================================================== */

@keyframes sunSpin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes cloudDrift {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(28px);
  }
}

@keyframes waveBobBack {
  from {
    transform: translate(0, -14px);
  }

  to {
    transform: translate(-22px, -4px);
  }
}

@keyframes waveBobFront {
  from {
    transform: translate(0, 0);
  }

  to {
    transform: translate(22px, -10px);
  }
}

@keyframes markPop {
  0% {
    transform: scale(0.9);
  }

  55% {
    transform: scale(1.08);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes lineHit {
  0%,
  100% {
    transform: scale(1);
  }

  35% {
    background: var(--sea);
    transform: scale(1.06) rotate(-1deg);
  }

  70% {
    background: var(--sun);
    transform: scale(1.02) rotate(1deg);
  }
}

@keyframes bannerPop {
  0% {
    opacity: 0;
    transform: translate(-50%, -80px) rotate(-5deg) scale(0.8);
  }

  18%,
  82% {
    opacity: 1;
    transform: translate(-50%, 0) rotate(2deg) scale(1);
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -80px) rotate(5deg) scale(0.9);
  }
}

@keyframes faceBubblePop {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.45) rotate(-8deg);
  }

  12% {
    opacity: 1;
    transform: translateY(-14px) scale(1.12) rotate(5deg);
  }

  24% {
    opacity: 1;
    transform: translateY(-4px) scale(0.96) rotate(-4deg);
  }

  42% {
    opacity: 1;
    transform: translateY(-32px) scale(1.02) rotate(3deg);
  }

  68% {
    opacity: 1;
    transform: translateY(-58px) scale(1) rotate(-2deg);
  }

  86% {
    opacity: 0.65;
    transform: translateY(-88px) scale(0.9) rotate(6deg);
  }

  100% {
    opacity: 0;
    transform: translateY(-118px) scale(0.72) rotate(12deg);
  }
}

/* ==========================================================================
   Reduced motion: tutto statico o istantaneo
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .sun-rays,
  .scene-cloud-1,
  .scene-cloud-2,
  .sea-wave-back,
  .sea-wave-front {
    animation: none !important;
  }

  .bingo-banner.show {
    animation: none !important;
    opacity: 1;
    transform: translate(-50%, 0);
  }

  .face-bubble {
    animation: none !important;
    opacity: 1;
  }

  .cell:hover:not(:disabled),
  .cell:active:not(:disabled) {
    transform: none;
  }
}

/* ==========================================================================
   Da tablet in su
   ========================================================================== */

@media (min-width: 720px) {
  .scene-cloud-2 {
    display: block;
  }

  .page {
    width: min(1120px, calc(100% - 48px));
    padding: 32px 0 clamp(110px, 18vh, 170px);
  }

  .hero {
    flex-direction: row;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 24px;
  }

  .hero-actions {
    grid-auto-flow: column;
    align-items: stretch;
    justify-items: end;
  }

  .status {
    display: block;
    min-width: 160px;
    text-align: right;
  }

  .status span,
  .status strong {
    display: block;
  }

  .status strong {
    margin-top: 2px;
  }

  .board-wrap {
    padding: 14px;
    box-shadow: 8px 8px 0 var(--ink);
  }

  .board {
    gap: 10px;
  }

  .cell {
    min-height: 116px;
    padding: 12px;
    border-radius: 14px;
  }

  .cell span {
    font-size: clamp(0.78rem, 1.6vw, 1rem);
  }

  .cell.marked::after {
    top: 7px;
    right: 8px;
    width: 24px;
    height: 24px;
    font-size: 0.95rem;
  }

  .cell.bonus::before {
    font-size: 1.6rem;
    margin-bottom: 5px;
  }
}
