@font-face { font-family: "AmolaFont"; src: url("font/amola.woff2") format("woff2"); font-display: block; }
* { box-sizing: border-box; }
:root { --oro: #ffcf1f; --testo: #1b2a3a; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column; color: #fff;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(120% 90% at 50% 0%, #1b3a9c, #0d1b4d 70%) fixed; /* come il Puzzle */
  -webkit-user-select: none; user-select: none;
}
main { flex: 1; padding: 14px; width: 100%; max-width: 760px; margin: 0 auto; }
main:has(#gioco:not([hidden])) { max-width: none; }
footer { text-align: center; font-size: 13px; padding: 8px; color: #b9c7ff; background: rgba(0, 0, 0, .25); }
footer a { color: #fff; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }

/* Pannelli (menu, creazione) */
.pannello {
  background: linear-gradient(180deg, #fffdf6, #f6efdc); color: var(--testo);
  border-radius: 22px; padding: 20px 22px 24px; border: 4px solid #fff;
  box-shadow: 0 14px 30px rgba(0, 0, 0, .45), inset 0 0 0 3px #e8d9a8;
}
img.logo { display: block; width: 96px; height: 96px; margin: 0 auto; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, .35)); }
h1 { text-align: center; font-size: 2.6rem; margin: 6px 0 10px; color: #c0392b; text-shadow: 0 3px 0 #ffd93b; }
h1 span { color: var(--oro); text-shadow: 0 2px 0 #c98f00; }
label { display: block; font-size: 1.4rem; margin: 16px 0; font-weight: 700; }
select {
  font-size: 1.4rem; padding: 10px; margin-top: 6px; width: 100%; border-radius: 12px;
  border: 3px solid #1d4fc4; background: #fff; color: var(--testo); font-family: inherit;
}
.riga input { width: 28px; height: 28px; vertical-align: middle; }
.nota { font-size: 1.05rem; color: #456; }
.errore { color: #b00020; font-size: 1.2rem; font-weight: 700; }

/* Pulsanti */
button {
  font-family: inherit; font-size: 1.25rem; font-weight: 700; min-height: 52px; padding: 8px 22px;
  border-radius: 14px; border: 0; color: #fff; cursor: pointer; touch-action: manipulation;
  background: linear-gradient(180deg, #4f8cff, #2358d4); box-shadow: 0 5px 0 #173a94, 0 8px 12px rgba(0, 0, 0, .3);
  transition: transform .08s, box-shadow .08s;
}
button:active { transform: translateY(4px); box-shadow: 0 1px 0 #173a94, 0 3px 6px rgba(0, 0, 0, .3); }
button.grande {
  width: 100%; font-size: 1.8rem; min-height: 70px; margin-top: 14px;
  background: linear-gradient(180deg, #ffb347, #ff7a00); box-shadow: 0 6px 0 #b34f00, 0 10px 16px rgba(0, 0, 0, .3);
}
button.grande:active { box-shadow: 0 1px 0 #b34f00; }
button.chiaro { background: #fff; color: #1d4fc4; border: 3px solid #1d4fc4; box-shadow: 0 4px 0 #9fb6ee; }
button.piccolo { min-height: 44px; padding: 4px 14px; font-size: 1.05rem; }
#voce { margin-left: auto; }
.riga2 { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }

.cartella { margin-top: 22px; padding-top: 14px; border-top: 2px dashed #d4c595; }
.cartella h2 { margin: 0 0 4px; font-size: 1.3rem; color: #1d4fc4; }
.stato { font-weight: 700; color: #0d6b3a; min-height: 1.2em; margin: 6px 0; }
.stato.avviso { color: #b35400; }

/* Creazione coppie */
input[type=text] { font-size: 1.3rem; padding: 10px; border-radius: 10px; border: 3px solid #9ab; width: 100%; margin-top: 6px; font-family: inherit; user-select: text; -webkit-user-select: text; }
.coppia { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 14px; padding-bottom: 14px; border-bottom: 2px dashed #d4c595; }
.lato { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.lato input[type=text] { margin-top: 0; flex: 1 1 100%; }
.lato .mini { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; border: 2px solid #9ab; }
.foto, .lato .togli {
  font-size: 1.05rem; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 3px solid #1d4fc4;
  color: #1d4fc4; background: #fff; cursor: pointer; margin: 0; display: inline-flex; align-items: center; font-weight: 700;
}
.lato .togli { border-color: #c0392b; color: #c0392b; box-shadow: none; min-height: 44px; }
.coppia > .x { min-height: 48px; padding: 4px 14px; background: #d94a3a; box-shadow: 0 4px 0 #8f2a1e; }
@media (max-width: 640px) { .coppia { flex-wrap: wrap; } .coppia > .x { width: 100%; } }

/* Menu su due colonne sugli schermi larghi (LIM, computer) */
main:has(#scelta:not([hidden])) { max-width: 1100px; }
.colonne { display: block; }
@media (min-width: 900px) {
  .colonne { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 36px; align-items: start; }
  #scelta { padding-top: 12px; }
  #scelta img.logo { width: 76px; height: 76px; }
  #scelta h1 { margin: 2px 0 0; font-size: 2.2rem; }
  #scelta label { margin: 10px 0; }
  #scelta button.grande { margin-top: 10px; }
  .colB .riga2 { margin-top: 12px; }
  .colB .cartella { margin-top: 14px; padding-top: 10px; }
}

/* Menu iniziale un po' più compatto */
main:has(#scelta:not([hidden])) { max-width: 960px; }
#scelta { padding: 14px 18px 18px; }
#scelta img.logo { width: 64px; height: 64px; }
#scelta h1 { font-size: 2.1rem; }
#scelta label { font-size: 1.2rem; margin: 8px 0; }
#scelta select { font-size: 1.2rem; padding: 7px 10px; }
#scelta button { font-size: 1.1rem; min-height: 46px; padding: 6px 18px; }
#scelta button.grande { font-size: 1.55rem; min-height: 60px; }
#scelta .nota, #scelta .stato { font-size: .95rem; }
#scelta .cartella h2 { font-size: 1.15rem; }
#scelta a.home { margin-top: 12px; padding: 3px 12px; }
#scelta a.home img { width: 112px; height: auto; }

/* Ritorno alla home del sito (come nel Puzzle) */
a.home { display: inline-block; margin-top: 20px; padding: 4px 14px; background: #fff; border-radius: 16px; line-height: 0; box-shadow: 0 4px 0 #9aa8d8; }
a.home img { display: block; }
a.home:focus-visible { outline: 5px solid var(--oro); outline-offset: 3px; }

/* Barra di gioco */
.barra { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.barra button { min-height: 48px; }
.chip { background: rgba(0, 0, 0, .35); border-radius: 999px; padding: 8px 18px; font-size: 1.25rem; font-weight: 700; border: 2px solid rgba(255, 255, 255, .25); }

/* Griglia e carte 3D: dimensioni calcolate da app.js */
#griglia {
  display: grid; gap: 12px; justify-content: center; align-content: center;
  height: calc(100vh - 170px); height: calc(100dvh - 170px); min-height: 260px;
  grid-template-columns: repeat(var(--col, 4), var(--cw, 100px)); grid-auto-rows: var(--ch, 130px);
}
.carta {
  width: var(--cw); height: var(--ch); perspective: 900px; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; outline: none;
}
.inner {
  position: relative; width: 100%; height: 100%; transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d; transition: transform .6s cubic-bezier(.3, .8, .3, 1.08);
}
.carta.su .inner { transform: rotateY(180deg); }
.retro, .fronte {
  position: absolute; inset: 0; border-radius: calc(var(--cw) * .09); border: calc(var(--cw) * .045) solid #fff;
  -webkit-backface-visibility: hidden; backface-visibility: hidden; overflow: hidden;
  box-shadow: 0 6px 12px rgba(0, 0, 0, .45), 0 1px 2px rgba(0, 0, 0, .5);
}
.retro {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .22) 0 18%, transparent 19%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .13) 0 6px, transparent 6px 14px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, .13) 0 6px, transparent 6px 14px),
    linear-gradient(145deg, #5b92ff, #1d4fc4 70%);
}
.retro::before {
  content: ""; position: absolute; inset: 7%; border-radius: calc(var(--cw) * .06);
  border: 2px solid rgba(255, 255, 255, .55);
}
.retro::after {
  content: "\2605"; position: absolute; left: 0; right: 0; top: 12%; text-align: center;
  font-size: calc(var(--cw) * .2); line-height: 1; color: var(--oro); text-shadow: 0 2px 0 #b8860b, 0 0 10px rgba(255, 217, 59, .6);
}
.marchio {
  position: absolute; left: 0; right: 0; top: 50%; text-align: center; white-space: nowrap;
  font-family: "AmolaFont", "Pacifico", "Segoe Script", "Bradley Hand", cursive; font-weight: 400;
  font-size: calc(var(--cw) * .17); line-height: 1; color: #fff;
  transform: translateY(-30%) rotate(-9deg);
  text-shadow: 0 2px 0 #173a94, 0 0 8px rgba(255, 255, 255, .45);
}
.fronte {
  transform: rotateY(180deg); background: linear-gradient(160deg, #fffef8, #f3ead2);
  display: flex; align-items: center; justify-content: center; color: var(--testo);
  font-weight: 800; text-align: center; font-size: var(--fs, 20px); line-height: 1.1; padding: 6%;
}
.fronte::after { /* riflesso della carta */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(120deg, rgba(255, 255, 255, .55) 0%, transparent 35%);
}
.fronte.conTitolo { display: block; padding: 0; } /* resta position: absolute come ogni faccia: i figli si posizionano rispetto a lei */
.fronte.conTitolo img { position: absolute; left: 5%; top: 5%; width: 90%; height: 90%; object-fit: contain; }
.fronte.conTitolo .titolo { /* il nome si sovrappone alla figura, in basso, su una fascia chiara semitrasparente */
  position: absolute; left: 0; right: 0; bottom: 4%; margin: 0 auto; width: max-content; z-index: 2; max-width: 96%;
  padding: .05em .3em; text-align: center; line-height: 1.05; background: rgba(255, 255, 255, .82);
  border-radius: .5em; box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}
/* Scritte in 3D: spessore, luce da sinistra, riflesso che scorre e piccole stelle che brillano */
.scritta {
  display: inline-block; position: relative; color: #1d3350; letter-spacing: .01em;
  text-shadow: -1px -1px 0 rgba(255, 255, 255, .95), 0 1px 0 #f4ecd0, 0 2px 0 #d9c995, 0 3px 0 #c2b07a, 0 4px 0 #a99763, 0 5px 0 #8f7e4f, 0 8px 10px rgba(60, 40, 0, .38);
}
.scritta::after { /* riflesso lucido che attraversa le lettere */
  content: attr(data-t); position: absolute; left: 0; top: 0; width: 100%; color: transparent; text-shadow: none; pointer-events: none;
  background: linear-gradient(105deg, transparent 38%, rgba(255, 255, 255, .95) 50%, transparent 62%) 150% 0 / 250% 100% no-repeat;
  -webkit-background-clip: text; background-clip: text;
  animation: luccica 4.2s ease-in-out infinite; animation-delay: var(--d, 0s);
}
@keyframes luccica { 0%, 55% { background-position: 150% 0; } 80%, 100% { background-position: -60% 0; } }
.scritta::before { /* piccola stella che brilla */
  content: "\2726"; position: absolute; right: -.5em; top: -.55em; font-size: .6em; line-height: 1; color: #fff7b0; opacity: 0; pointer-events: none;
  text-shadow: 0 0 4px #ffd93b, 0 0 9px #ffb300; animation: stellina 3.6s ease-in-out infinite; animation-delay: var(--d, 0s);
}
@keyframes stellina { 0%, 62%, 100% { opacity: 0; transform: scale(.2) rotate(0); } 74% { opacity: 1; transform: scale(1.15) rotate(35deg); } 88% { opacity: 0; transform: scale(.4) rotate(70deg); } }
.fronte.conTitolo .scritta { text-shadow: -1px -1px 0 #fff, 0 1px 0 #e8dcae, 0 2px 0 #cdbb83, 0 3px 0 #b3a16c, 0 5px 6px rgba(60, 40, 0, .35); }
/* Figure come oggetti veri (effetto degli scacchi): ombra a terra, bordo di luce, stellina e comparsa con rimbalzo */
.fronte.fig {
  background: radial-gradient(ellipse 42% 6% at 50% 90%, rgba(70, 45, 0, .30), transparent 100%), radial-gradient(ellipse at 50% 38%, #ffffff 0%, #fbf4de 55%, #efe2bb 100%);
}
.fronte.fig img { filter: drop-shadow(-1px -1px 0 rgba(255, 255, 255, .85)) drop-shadow(0 6px 4px rgba(60, 40, 0, .38)); }
.carta.su .fronte.fig img { animation: emerge .75s cubic-bezier(.2, 1.6, .4, 1) .3s both; }
@keyframes emerge { from { transform: scale(.65) translateY(10%); opacity: .2; } to { transform: none; opacity: 1; } }
.fronte.fig::before { /* piccola stella che brilla sulla figura */
  content: "\2726"; position: absolute; right: 12%; top: 11%; z-index: 3; font-size: calc(var(--cw) * .14); line-height: 1; color: #fffbd0; opacity: 0; pointer-events: none;
  text-shadow: 0 0 5px #ffd93b, 0 0 12px #ffb300; animation: stellina 3.6s ease-in-out infinite; animation-delay: var(--d, 0s);
}
.fronte.fig.conTitolo::before { top: 9%; }
.fronte img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.carta.trovata .fronte { background: linear-gradient(160deg, #f6fff0, #d3f5c7); border-color: #ffe27a; }
.carta.trovata .inner { cursor: default; }
@media (hover: hover) {
  .carta:not(.su):hover .inner { transform: translateY(-6px) rotateX(8deg); }
  .carta:not(.su):hover .retro { box-shadow: 0 14px 20px rgba(0, 0, 0, .45); }
}

/* Animazioni */
.carta.alza { animation: alza .6s ease; z-index: 2; }
@keyframes alza { 50% { transform: translateY(-14px) scale(1.08); } }
.carta.no { animation: scuoti .45s ease; }
@keyframes scuoti { 20%, 60% { transform: translateX(-9px) rotate(-2deg); } 40%, 80% { transform: translateX(9px) rotate(2deg); } }
.carta.nuova .fronte { animation: pulsa .8s ease; }
@keyframes pulsa {
  0%, 100% { transform: rotateY(180deg) scale(1); box-shadow: 0 6px 12px rgba(0, 0, 0, .45); }
  40% { transform: rotateY(180deg) scale(1.12); box-shadow: 0 0 0 6px rgba(255, 217, 59, .8), 0 0 36px 10px rgba(255, 217, 59, .9); }
}

/* Fine partita: le carte brillano (bagliore e riflesso che scorre) */
.carta.festa .fronte { animation: brilla 1.4s ease-in-out infinite; animation-delay: var(--d, 0s); }
@keyframes brilla {
  0%, 100% { box-shadow: 0 6px 12px rgba(0, 0, 0, .45); filter: brightness(1); }
  50% { box-shadow: 0 0 0 4px rgba(255, 217, 59, .95), 0 0 30px 8px rgba(255, 217, 59, .85); filter: brightness(1.12) saturate(1.15); }
}
.carta.festa .fronte::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 2;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, .95) 50%, transparent 65%);
  transform: translateX(-130%); animation: riflesso 1.4s ease-in-out infinite; animation-delay: var(--d, 0s);
}
@keyframes riflesso { 0% { transform: translateX(-130%); } 60%, 100% { transform: translateX(130%); } }

/* Fine partita */
#fine { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, .35); }
#fine[hidden] { display: none; }
.coppa {
  background: linear-gradient(180deg, #fffdf6, #f6efdc); color: var(--testo); border-radius: 24px; border: 5px solid var(--oro);
  padding: 22px 30px 28px; text-align: center; width: min(90vw, 460px); box-shadow: 0 20px 50px rgba(0, 0, 0, .6);
  animation: entra .6s cubic-bezier(.2, 1.4, .4, 1);
}
.coppa p { font-size: 1.6rem; font-weight: 800; margin: 8px 0 4px; }
.coppa .chiaro { margin-top: 14px; width: 100%; }
.stelle { font-size: 3rem; color: var(--oro); text-shadow: 0 3px 0 #b8860b; letter-spacing: .2em; }
@keyframes entra { from { transform: scale(.3) rotate(-8deg); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .inner { transition-duration: .01s; }
  .scritta::before, .scritta::after, .fronte.fig::before, .carta.su .fronte.fig img { animation: none; }
  .carta.alza, .carta.no, .carta.nuova .fronte, .coppa, .carta.festa .fronte, .carta.festa .fronte::before { animation: none; }
}
