/* =========================================================================
   SCIMMIA — stile Pixel Art / Retro-Arcade
   ========================================================================= */

:root {
  --bg:        #0e0e1a;
  --bg-2:      #1a1a2e;
  --panel:     #15152b;
  --indigo:    #4f46e5;
  --indigo-2:  #818cf8;
  --orange:    #f97316;
  --cyan:      #00ffff;
  --pink:      #ff006e;
  --green:     #05ffa1;
  --yellow:    #ffd23f;
  --text:      #eef2ff;
  --muted:     #9aa0c7;
  --line:      rgba(129, 140, 248, 0.25);

  --pixel: 'Press Start 2P', system-ui, monospace;
  --term:  'VT323', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--term);
  font-size: 20px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* sfondo a griglia retro + glow d'angolo */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 15% 10%, rgba(79, 70, 229, 0.35), transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(255, 0, 110, 0.25), transparent 45%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: 0.25;
  mask-image: linear-gradient(180deg, transparent, #000 25%, #000 75%, transparent);
  -webkit-mask-image: linear-gradient(180deg, transparent, #000 25%, #000 75%, transparent);
}

/* scanline CRT globale */
.crt-overlay {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.18) 3px,
    rgba(0, 0, 0, 0) 4px
  );
  mix-blend-mode: multiply;
}

h1, h2, h3, .pixel { font-family: var(--pixel); }

a { color: var(--cyan); }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ----------------------------- HERO ------------------------------------- */
.hero {
  text-align: center;
  padding: 56px 16px 24px;
}
.hero .logo {
  font-family: var(--pixel);
  font-size: clamp(22px, 6vw, 46px);
  line-height: 1.4;
  letter-spacing: 1px;
  color: var(--yellow);
  text-shadow:
    0 0 8px rgba(255, 210, 63, 0.7),
    4px 4px 0 var(--pink);
  margin: 0;
}
.hero .tagline {
  margin-top: 18px;
  font-size: clamp(18px, 2.4vw, 24px);
  color: var(--indigo-2);
}
.hero .sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 18px;
}
.progress-bar {
  margin: 26px auto 0;
  max-width: 420px;
  height: 16px;
  border: 2px solid var(--indigo);
  background: #0a0a16;
  box-shadow: 0 0 10px rgba(79, 70, 229, 0.5);
  position: relative;
}
.progress-bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--indigo-2));
  transition: width 600ms steps(12, end);
}
.progress-label {
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--muted);
  margin-top: 8px;
}

/* ----------------------------- GRIGLIA CARD ----------------------------- */
.grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(116px, 1fr));
  gap: 16px;
  padding: 30px 2px 46px;
  overflow-x: auto;          /* tutte e 7 le card sulla stessa riga */
  scrollbar-width: thin;
}

.card {
  position: relative;
  aspect-ratio: 3 / 4;
  perspective: 1000px;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  font-family: var(--term);
  color: var(--text);
}
.card:focus-visible { outline: 3px solid var(--cyan); outline-offset: 4px; }

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 700ms cubic-bezier(.2,.8,.2,1);
}
.card.is-done .card-inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border: 3px solid var(--indigo);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 18px;
  overflow: hidden;
}

/* fronte (coperta) */
.face-front {
  background:
    radial-gradient(circle at 50% 30%, rgba(79,70,229,0.35), transparent 70%),
    var(--panel);
  box-shadow: inset 0 0 0 2px #0a0a16, 0 8px 0 rgba(0,0,0,0.4);
}
.card .level-tag {
  font-family: var(--pixel);
  font-size: 9px;
  color: var(--muted);
  letter-spacing: 1px;
}
.card .icon-box {
  width: 72px; height: 72px;
  margin: 14px auto;
  display: grid; place-items: center;
}
.card .icon-box svg { width: 100%; height: 100%; }
.card .game-title {
  font-family: var(--pixel);
  font-size: 11px;
  line-height: 1.6;
  color: var(--text);
}
.card .game-desc {
  font-size: 16px;
  color: var(--muted);
  margin-top: 8px;
}
.card .cta {
  margin-top: auto;
  font-family: var(--pixel);
  font-size: 10px;
  padding: 9px 12px;
  border: 2px solid var(--orange);
  color: var(--orange);
  background: #0a0a16;
  transition: background 200ms, color 200ms, box-shadow 200ms;
}

/* stati interattivi */
.card.is-playable:hover .face-front,
.card.is-playable:focus-visible .face-front {
  box-shadow: inset 0 0 0 2px #0a0a16, 0 0 18px rgba(0,255,255,0.55);
  border-color: var(--cyan);
}
.card.is-playable:hover .cta {
  background: var(--orange);
  color: #0a0a16;
  box-shadow: 0 0 14px rgba(249,115,22,0.8);
}

/* card bloccata per data */
.card.is-locked { cursor: not-allowed; }
.card.is-locked .face-front { filter: grayscale(0.85) brightness(0.6); border-color: #3a3a55; }
.card.is-locked .cta {
  border-color: var(--muted);
  color: var(--muted);
}
.card .lock-icon { width: 40px; height: 40px; margin: 10px auto 0; opacity: .8; }

/* retro (rivelata) */
.face-back {
  transform: rotateY(180deg);
  background:
    radial-gradient(circle at 50% 35%, rgba(5,255,161,0.18), transparent 70%),
    linear-gradient(160deg, #16213e, #0a0a16);
  border-color: var(--green);
  box-shadow: inset 0 0 24px rgba(5,255,161,0.25), 0 0 22px rgba(5,255,161,0.35);
}
.face-back .letter {
  font-family: var(--pixel);
  font-size: clamp(46px, 9vw, 76px);
  color: var(--green);
  text-shadow: 0 0 14px rgba(5,255,161,0.8), 4px 4px 0 rgba(0,0,0,0.5);
}
.face-back .gag {
  margin-top: 16px;
  font-size: 17px;
  color: var(--text);
}
.face-back .stamp {
  margin-top: 12px;
  font-family: var(--pixel);
  font-size: 8px;
  color: var(--muted);
  border: 1px solid var(--muted);
  padding: 4px 8px;
  transform: rotate(-6deg);
}

/* ----------------------------- REVEAL FINALE ---------------------------- */
.final {
  display: none;
  text-align: center;
  padding: 30px 16px 90px;
}
.final.show { display: block; }
.final .word {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0 26px;
}
.final .word span {
  font-family: var(--pixel);
  font-size: clamp(28px, 8vw, 64px);
  color: var(--yellow);
  text-shadow: 0 0 16px rgba(255,210,63,0.85), 4px 4px 0 var(--pink);
  opacity: 0;
  transform: translateY(20px) scale(.6);
}
.final .word span.pop {
  animation: pop 500ms cubic-bezier(.2,1.6,.4,1) forwards;
}
@keyframes pop { to { opacity: 1; transform: translateY(0) scale(1); } }

.final .phrase {
  font-family: var(--pixel);
  font-size: clamp(16px, 3.4vw, 30px);
  color: var(--cyan);
  text-shadow: 0 0 12px rgba(0,255,255,0.8);
  min-height: 1.4em;
  border-right: 4px solid var(--cyan);
  display: inline-block;
  white-space: pre;
  padding-right: 4px;
}
.final .phrase.blink { animation: caret 800ms steps(1) infinite; }
@keyframes caret { 50% { border-color: transparent; } }
.final .confetti-note { margin-top: 24px; color: var(--muted); }

/* ----------------------------- OVERLAY GIOCO ---------------------------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(6, 6, 16, 0.96);
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  overflow-y: auto;
}
.overlay.show { display: flex; }
.overlay .game-head {
  width: 100%;
  max-width: 640px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 14px;
}
.overlay .game-head h2 {
  font-size: 13px;
  color: var(--yellow);
  margin: 0;
  text-shadow: 0 0 8px rgba(255,210,63,0.6);
}
.overlay .game-meta { font-size: 16px; color: var(--muted); }
.overlay .game-stage {
  width: 100%;
  max-width: 640px;
  background: var(--panel);
  border: 3px solid var(--indigo);
  box-shadow: 0 0 24px rgba(79,70,229,0.4);
  padding: 16px;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.overlay .hint {
  color: var(--muted);
  font-size: 16px;
  text-align: center;
  margin: 6px 0 14px;
}

/* bottoni generici */
.btn {
  font-family: var(--pixel);
  font-size: 11px;
  padding: 11px 16px;
  border: 2px solid var(--indigo);
  background: #0a0a16;
  color: var(--text);
  cursor: pointer;
  transition: background 200ms, color 200ms, box-shadow 200ms, border-color 200ms;
  min-height: 44px;
}
.btn:hover { background: var(--indigo); box-shadow: 0 0 14px rgba(79,70,229,0.8); }
.btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }
.btn-ghost { border-color: var(--muted); }
.btn-ghost:hover { background: var(--muted); color: #0a0a16; box-shadow: none; }
.btn-cta { border-color: var(--orange); color: var(--orange); }
.btn-cta:hover { background: var(--orange); color: #0a0a16; box-shadow: 0 0 14px rgba(249,115,22,0.8); }

.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* messaggio vittoria nel gioco */
.win-banner {
  text-align: center;
  padding: 20px;
}
.win-banner .big {
  font-family: var(--pixel);
  font-size: 18px;
  color: var(--green);
  text-shadow: 0 0 12px rgba(5,255,161,0.8);
}

canvas { image-rendering: pixelated; touch-action: none; max-width: 100%; }

/* ----------------------------- FOOTER ----------------------------------- */
.foot {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 20px 0 40px;
}

/* ----------------------------- D-PAD touch ------------------------------ */
.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
  margin: 14px auto 0;
}
.dpad button {
  font-family: var(--pixel);
  font-size: 16px;
  border: 2px solid var(--indigo);
  background: #0a0a16;
  color: var(--cyan);
  cursor: pointer;
}
.dpad button:active { background: var(--indigo); }
.dpad .up    { grid-area: 1 / 2; }
.dpad .left  { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; }
.dpad .down  { grid-area: 3 / 2; }
.dpad .mid   { grid-area: 2 / 2; visibility: hidden; }

/* ----------------------------- RESPONSIVE ------------------------------- */
@media (max-width: 480px) {
  html, body { font-size: 18px; }
  /* restano sulla stessa riga: colonne più strette + scroll orizzontale */
  .grid { grid-template-columns: repeat(7, minmax(92px, 1fr)); gap: 10px; }
  .hero { padding: 36px 12px 16px; }
  .card .game-title { font-size: 9px; }
  .card .game-desc { font-size: 13px; }
}

/* ----------------------------- REDUCED MOTION --------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .card-inner { transition: none; }
}
