.app-container {
    width: 100%;
    max-width: 800px;
    margin: 0.5rem auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    min-height: 500px;
    position: relative;
    padding-bottom: 20px;
}

.screen {
    display: none;
    padding: 1.5rem;
    text-align: center;
}

.screen.active {
    display: block;
}

.title {
    font-size: 2.5rem;
    color: var(--brand);
    margin-bottom: 1rem;
    font-family: 'Fredoka', sans-serif;
}

.subtitle {
    font-size: 1.2rem;
    color: #64748b;
    margin-bottom: 2rem;
}

.btn-play {
    background-color: var(--brand);
    color: white;
    border: none;
    padding: 1rem 2rem;
    font-size: 1.5rem;
    border-radius: 50px;
    cursor: pointer;
    font-family: 'Fredoka', sans-serif;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 0 #3b82f6;
    margin: 0.5rem;
}

.btn-play:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #3b82f6;
}

.btn-play:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #3b82f6;
}

.game-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.btn-mini-home {
    background: #f1f5f9;
    border: none;
    font-size: 1.5rem;
    padding: 10px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 0 #cbd5e1;
}

.score {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--ink);
}




.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.option-btn {
    background: white;
    border: 3px solid #e2e8f0;
    border-radius: 15px;
    padding: 0.75rem;
    font-size: 1.2rem;
    font-family: 'Fredoka', sans-serif;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
    transition: all 0.2s;
}

.option-btn:hover {
    border-color: var(--brand);
    background: #f0f9ff;
    transform: scale(1.05);
}

/* Modals */
.modal-overlay {
    background: rgba(0,0,0,0.5);
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
}
.modal-overlay.active {
    display: flex;
}
.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 20px;
    text-align: center;
    border: 5px solid #22c55e;
    max-width: 400px;
    width: 90%;
    animation: bounceIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes bounceIn {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.modal-feedback {
    font-size: 2rem;
    font-weight: bold;
    color: #22c55e;
    margin-bottom: 1rem;
}




/* ATTENZIONE: .learn-grid NON dev'essere una griglia.
   Da quando «Impara» è raggruppato per famiglia, qui dentro ci sono
   intestazioni (.learn-fam) e righe (.learn-row) che vanno impilate.
   Con `display: grid` finivano ognuna in una cella, e il titolo di una
   famiglia si ritrovava di fianco alla frutta di un'altra. La griglia
   sta dentro .learn-row, non qui. */
.learn-grid {
    display: block;
    margin-top: 1rem;
}

.fruit-card {
    background: white;
    border: 3px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px 5px 5px 5px;
    cursor: pointer;
    transition: transform .2s, border-color .2s, box-shadow .2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    /* è un <button>: senza queste eredita il font di sistema e non
       riempie la cella della griglia */
    width: 100%;
    font-family: inherit;
    font-size: inherit;
    text-align: center;
}

.fruit-card:hover {
    transform: scale(1.05);
    border-color: #f59e0b;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.fruit-card.playing {
    border-color: #22c55e;
    transform: scale(1.1);
}

.fruit-card img {
    width: 70px;
    height: 70px;
    object-fit: contain;
    margin: 0;
}

.fruit-card .fruit-name {
    font-weight: 600;
    color: var(--ink);
    font-size: 0.9rem;
    line-height: 1.1;
    margin-top: -4px;
}

/* ---------- La scheda per gli adulti ----------
   Identica a quella delle altre app kids: stesso riquadro tratteggiato,
   stessi titoli, stesso riquadro azzurro per il consiglio finale. Va
   tenuta uguale, non personalizzata: chi passa da un'app all'altra
   deve ritrovare la stessa cosa nello stesso posto. */
.info-box {
    background: #fff;
    border: 2px dashed #cfe2e2;
    border-radius: 18px;
    padding: 1.3rem 1.4rem;
    margin-top: 2.2rem;
    width: 100%;
    text-align: left;
    color: #3b4a4a;
    font-size: 0.95rem;
    line-height: 1.6;
}

.info-box h2 {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.15rem;
    color: var(--brand);
    margin: 0 0 0.7rem;
}

.info-box h3 {
    font-family: 'Fredoka', sans-serif;
    font-size: 1rem;
    color: var(--brand);
    margin: 1.1rem 0 0.4rem;
}

.info-box p { margin: 0 0 0.55rem; }
.info-box ul { margin: 0 0 0.55rem; padding-left: 1.2rem; }
.info-box li { margin-bottom: 0.35rem; }

.info-box .info-tip {
    margin-top: 0.9rem;
    background: #f0fdfa;
    border-radius: 12px;
    padding: 0.6rem 0.8rem;
}

/* ---------- Selettore della lingua ---------- */
.lang-switch {
    display: flex;
    gap: 6px;
    margin: 0 0 1.4rem;
    flex-wrap: wrap;
    justify-content: center;
}

.lang-btn {
    appearance: none;
    border: 2px solid #d7efec;
    background: #fff;
    border-radius: 999px;
    padding: 0.35rem 0.8rem;
    font-family: var(--kids-font-body);
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--ink-2);
    cursor: pointer;
    box-shadow: var(--kids-shadow-sm);
    transition: transform .15s ease, background .15s ease, border-color .15s ease;
}

.lang-btn:hover { transform: translateY(-2px); }
.lang-btn.active { border-color: var(--brand); background: #eff6ff; color: var(--brand); }

/* ---------- Le cinque modalità ---------- */
.choose-label {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--brand);
    margin: 0 0 1rem;
}

.level-grid {
    display: grid;
    gap: 0.7rem;
    max-width: 460px;
    margin: 0 auto 2rem;
}

.level-card {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    text-align: left;
    background: #fff;
    border: 3px solid #e2e8f0;
    border-radius: 20px;
    padding: 0.9rem 1rem;
    cursor: pointer;
    font-family: inherit;
    transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.level-card:hover {
    transform: translateY(-3px);
    border-color: var(--brand);
    box-shadow: 0 8px 18px rgba(0, 0, 0, .1);
}

.level-icon { font-size: 2.1rem; line-height: 1; flex: none; }
.level-text { display: flex; flex-direction: column; gap: 2px; }

.level-name {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--ink);
}

.level-desc { font-size: .9rem; color: #4b5563; line-height: 1.25; }

/* ---------- Il passaggio fra una domanda e l'altra ----------
   Dissolvenza, non scatto. Sfumano insieme la consegna, la foto e le
   opzioni; il resto (punteggio, pulsanti) resta fermo, così il bambino
   non perde i punti di riferimento mentre cambia il contenuto.

   Lo spostamento verso l'alto è di 6 px soltanto: basta a far capire
   che qualcosa se ne va, e non abbastanza da sembrare un rimbalzo.

   `prefers-reduced-motion` è rispettato: a chi il movimento dà
   fastidio resta la sola dissolvenza, senza spostamento. */
#game-screen .prompt-card,
#game-screen .foto-box,
#game-screen .options-grid {
    transition: opacity .4s ease, transform .4s ease;
}

#game-screen.in-uscita .prompt-card,
#game-screen.in-uscita .foto-box,
#game-screen.in-uscita .options-grid {
    opacity: 0;
    transform: translateY(-6px);
}

@media (prefers-reduced-motion: reduce) {
    #game-screen.in-uscita .prompt-card,
    #game-screen.in-uscita .foto-box,
    #game-screen.in-uscita .options-grid { transform: none; }
}

/* ---------- La consegna, sempre anche a voce ---------- */
.prompt-card {
    position: relative;
    background: #fff;
    border: 3px solid #e2e8f0;
    border-radius: 20px;
    padding: 0.9rem 3.4rem 0.9rem 1rem;
    margin: 0 auto 1rem;
    max-width: 560px;
}

.prompt-text {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.3;
    min-height: 1.4em;
}

.say-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--brand);
    background: #eff6ff;
    font-size: 1.3rem;
    cursor: pointer;
    line-height: 1;
}

/* ---------- La foto grande ---------- */
.foto-box { margin: 0 auto 1rem; }

.foto-box img {
    max-width: 100%;
    max-height: 230px;
    border-radius: 18px;
    object-fit: contain;
    background: #fff;
    box-shadow: 0 6px 16px rgba(0, 0, 0, .12);
}

/* ---------- Le opzioni ----------
   Tre disposizioni diverse: parole a due colonne, foto a due
   colonne, cesti a due colonne larghe. */
.options-grid {
    display: grid;
    gap: 0.7rem;
    max-width: 560px;
    margin: 0 auto;
}

.options-grid.parole { grid-template-columns: repeat(2, 1fr); }
.options-grid.foto   { grid-template-columns: repeat(2, 1fr); }
.options-grid.cesti  { grid-template-columns: repeat(2, 1fr); }

.option-foto {
    border: 3px solid #e2e8f0;
    background: #fff;
    border-radius: 18px;
    padding: 0.5rem;
    cursor: pointer;
    transition: transform .15s ease, border-color .15s ease;
}

.option-foto img {
    width: 100%;
    height: 110px;
    object-fit: contain;
    display: block;
}

.option-foto:hover { transform: translateY(-3px); border-color: var(--brand); }

.option-cesto {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    border: 3px solid #e2e8f0;
    background: #fff;
    border-radius: 18px;
    padding: 0.8rem 0.5rem;
    cursor: pointer;
    font-family: inherit;
    transition: transform .15s ease, border-color .15s ease;
}

.option-cesto:hover { transform: translateY(-3px); border-color: var(--brand); }
.cesto-e { font-size: 2rem; line-height: 1; }

.cesto-n {
    font-family: 'Fredoka', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    text-align: center;
    line-height: 1.15;
}

/* La risposta giusta si accende sempre, anche quando è stata
   sbagliata: è lì che si impara. */
.option-btn.giusto,
.option-foto.giusto,
.option-cesto.giusto {
    border-color: #22c55e;
    background: #f0fdf4;
    box-shadow: 0 0 0 4px rgba(34, 197, 94, .18);
}

/* Lo sbaglio si smorza, non si punisce: nessuna X, nessun rosso
   acceso, nessuna faccia triste (guida, cap. 6). */
.option-btn.sbagliato,
.option-foto.sbagliato,
.option-cesto.sbagliato {
    border-color: #cbd5e1;
    opacity: .45;
}

/* Una scelta gia' provata e sbagliata: resta al suo posto — sparire
   sposterebbe le altre sotto il dito — ma si spegne e non si tocca
   piu'. Il giro non e' finito: si riprova sulle rimanenti, e la
   risposta giusta non viene MAI svelata dall'app. */
.option-btn.fuori,
.option-foto.fuori,
.option-cesto.fuori {
    opacity: .3;
    pointer-events: none;
    filter: grayscale(1);
    box-shadow: none;
    transform: none;
}

/* Appena si azzecca, tutte si bloccano: un secondo tocco non conta. */
.option-btn.locked,
.option-foto.locked,
.option-cesto.locked { pointer-events: none; }

/* ---------- Il riscontro ----------
   Sta nella pagina e non in una finestra sopra tutto: dopo un
   errore la foto giusta deve restare guardabile. */
.feedback-msg {
    display: none;
    max-width: 560px;
    margin: 1rem auto 0;
    padding: 1rem;
    border-radius: 18px;
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.35;
}

.feedback-msg.correct,
.feedback-msg.mostra { display: block; }

.feedback-msg.correct { background: #f0fdf4; border: 3px solid #22c55e; color: #166534; }
.feedback-msg.mostra  { background: #eff6ff; border: 3px solid #3b82f6; color: #1e3a8a; }

.feedback-foto {
    display: block;
    max-height: 130px;
    margin: 0 auto 0.6rem;
    border-radius: 14px;
    background: #fff;
}

.btn-avanti {
    display: block;
    margin: 0.9rem auto 0;
    padding: 0.7rem 1.8rem;
    border: none;
    border-radius: 999px;
    background: var(--brand);
    color: #fff;
    font-family: 'Fredoka', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
}

/* ---------- «Impara»: raggruppato per famiglia ----------
   La classificazione si vede prima ancora di doverla fare. */
.learn-fam {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.15rem;
    color: var(--brand);
    margin: 1.2rem 0 0.5rem;
    text-align: left;
}

.learn-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 0.6rem;
    align-items: stretch;
}

/* ---------- Bottoni finali ---------- */
.result-buttons {
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn-stampa { background-color: #3b82f6; }

/* ---------- La lente di «Impara» ---------- */
.modal-content.lente {
    max-width: 500px;
    padding: 1rem;
    border: none;
    background: transparent;
    box-shadow: none;
}

.modal-content.lente img {
    max-width: 100%;
    max-height: 50vh;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
    object-fit: contain;
    background: #fff;
    padding: 1.5rem;
}

#enlarged-name {
    color: #fff;
    font-size: 2.6rem;
    font-family: 'Fredoka', sans-serif;
    font-weight: bold;
    margin-top: 1rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, .8);
}

/* Il 🔊 spento resta visibile ma spento, non sparisce */
.audio-btn.spento { opacity: .55; }


.certificate-container {
    background: #fffbef;
    border: 4px dashed #f59e0b;
    outline: 6px solid #10b981;
    outline-offset: 3px;
    padding: 15px;
    border-radius: 15px;
    max-width: 500px;
    width: 90%;
    margin: 5px auto 15px;
    position: relative;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
    text-align: center;
}

.certificate-container::before,
.certificate-container::after {
    content: '★';
    position: absolute;
    font-size: 24px;
    color: #fbbf24;
    top: 5px;
}

.certificate-container::before {
    left: 8px;
    transform: rotate(-15deg);
}

.certificate-container::after {
    right: 8px;
    transform: rotate(15deg);
}

.cert-header {
    font-family: 'Fredoka', sans-serif;
    color: #fff;
    background: #ef4444;
    display: inline-block;
    padding: 5px 20px;
    border-radius: 50px;
    font-size: 1.2rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
    box-shadow: 0 3px 0 #b91c1c;
    transform: rotate(-2deg);
}

.cert-text {
    font-size: 0.9rem;
    color: #4b5563;
    margin: 2px 0;
    font-family: 'Inter', sans-serif;
}


.cert-title {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.3rem;
    color: #d97706;
    margin: 2px 0 8px;
    text-decoration: underline wavy #fcd34d;
    text-underline-offset: 4px;
}

.cert-body {
    background: #ffffff;
    padding: 10px;
    border-radius: 10px;
    margin: 5px 0;
    border: 2px solid #e5e7eb;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

.cert-message {
    font-size: 0.95rem;
    color: #374151;
    font-style: italic;
    margin-bottom: 5px;
    line-height: 1.3;
}

.cert-score {
    font-size: 1.1rem;
    font-weight: bold;
    color: #10b981;
    background: #ecfdf5;
    display: inline-block;
    padding: 3px 10px;
    border-radius: 6px;
}

.cert-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: 10px;
    font-size: 0.8rem;
    color: #9ca3af;
    border-top: 1px dashed #d1d5db;
    padding-top: 5px;
}

.cert-signature {
    font-family: 'Fredoka', sans-serif;
    color: var(--brand);
    font-size: 1rem;
}

.cert-date {
    font-weight: bold;
}

/* ---------- Tablet ----------
   Da 700px in su lo schermo è largo il doppio di un telefono, e
   lasciare tutto a due colonne dentro un contenitore da 800 spreca
   metà pagina: le foto restano francobolli e le dita hanno spazio
   che non viene usato. Qui si allarga il contenitore e si passa a
   quattro colonne dove le opzioni sono quattro. */
@media (min-width: 700px) {
    .app-container { max-width: 980px; }

    .options-grid.parole,
    .options-grid.foto,
    .options-grid.cesti {
        grid-template-columns: repeat(4, 1fr);
        max-width: 900px;
    }

    .option-foto img { height: 150px; }

    .foto-box img { max-height: 300px; }

    .level-grid {
        grid-template-columns: repeat(2, 1fr);
        max-width: 820px;
    }

    .prompt-text { font-size: 1.4rem; }

    .option-btn { font-size: 1.2rem; padding: 1rem 0.75rem; }

    .learn-row { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
    .fruit-card img { width: 90px; height: 90px; }

    .feedback-msg { font-size: 1.2rem; }
    .feedback-foto { max-height: 170px; }
}

/* Ottimizzazione Mobile e Tablet */
@media (max-width: 600px) {
    .app-container {
        margin: 1rem auto;
        width: 95%;
        border-radius: 15px;
    }
    
    .screen {
        padding: 1rem;
    }
    
    .title {
        font-size: 1.8rem;
    }
    
    .foto-box img {
        max-height: 180px;
    }

    .options-grid {
        gap: 0.5rem;
    }

    .option-btn {
        font-size: 1rem;
        padding: 0.5rem;
    }
    
    #modal-image .modal-content {
        padding: 0.5rem;
    }
    
    #enlarged-name {
        font-size: 2rem !important;
    }
}

/* ---------- Stampa dell'attestato ----------
   Al posto di html2canvas dal CDN si usa la stampa del browser: sulla
   pagina resta il solo attestato, e da lì si stampa o si salva in PDF. */
@media print {
    body * { visibility: hidden !important; }
    #certificate, #certificate * { visibility: visible !important; }
    #certificate {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        box-shadow: none;
    }
    .site-header, .site-footer, .result-buttons, .btn-download, .btn-play { display: none !important; }
}
