/* Reset e stili base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    overflow-x: hidden;
}

/* Container principale */
.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* Gestione delle schermate */
.screen {
    display: none;
    width: 100%;
    min-height: 100vh;
}

.screen.active {
    display: block;
}

/* Header di benvenuto */
.welcome-header {
    text-align: center;
    margin-bottom: 30px;
}

.welcome-header h1 {
    font-family: 'Dancing Script', cursive;
    font-size: 2.5rem;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    margin-bottom: 10px;
    animation: pulse 2s infinite;
}

.welcome-header h2 {
    font-family: 'Dancing Script', cursive;
    font-size: 2rem;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    margin-bottom: 15px;
}

.subtitle {
    color: #fff;
    font-size: 1.1rem;
    font-weight: 300;
    opacity: 0.9;
}

/* Card container */
.card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 30px 25px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 450px;
}

.card h2 {
    text-align: center;
    margin-bottom: 25px;
    color: #333;
    font-size: 1.5rem;
}

/* Bottoni difficoltÃƒÂ  */
.difficulty-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.difficulty-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 15px;
    border: none;
    border-radius: 15px;
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%);
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Poppins', sans-serif;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.difficulty-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

.difficulty-btn:active {
    transform: translateY(-1px);
}

.difficulty-btn i {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.difficulty-btn span {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 3px;
}

.difficulty-btn small {
    font-size: 0.8rem;
    opacity: 0.9;
}

/* Bottoni numerici */
.number-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 12px;
    margin-bottom: 25px;
}

.number-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 18px 10px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    color: #333;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Poppins', sans-serif;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.number-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.number-btn i {
    font-size: 1.2rem;
    margin-bottom: 5px;
    color: #e91e63;
}

.number-btn span {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 3px;
}

.number-btn small {
    font-size: 0.7rem;
    opacity: 0.8;
}

/* Bottone indietro */
.back-btn-container {
    text-align: center;
}

.back-btn {
    padding: 12px 20px;
    border: none;
    border-radius: 25px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
}

.back-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

/* Header del gioco */
.game-header {
    margin-bottom: 25px;
    text-align: center;
}

.progress-info h3 {
    color: #fff;
    font-size: 1.3rem;
    margin-bottom: 10px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.3);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #ff9a9e 0%, #fecfef 100%);
    width: 0%;
    transition: width 0.5s ease;
    border-radius: 4px;
}

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

.control-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 20px;
    background: rgba(255,255,255,0.9);
    color: #333;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Poppins', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

.control-btn:hover {
    background: #fff;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.control-btn i {
    margin-right: 5px;
}

/* Container del puzzle */
.puzzle-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px 0;
    position: relative;
}

.puzzle-grid {
    display: grid;
    gap: 2px;
    background: #fff;
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    max-width: 90vw;
    max-height: 60vh;
}

/* Dimensioni dinamiche della griglia */
.puzzle-grid.size-3 {
    grid-template-columns: repeat(3, 1fr);
    width: min(300px, 90vw);
    height: min(300px, 60vh);
}

.puzzle-grid.size-4 {
    grid-template-columns: repeat(4, 1fr);
    width: min(320px, 90vw);
    height: min(320px, 60vh);
}

.puzzle-grid.size-5 {
    grid-template-columns: repeat(5, 1fr);
    width: min(350px, 90vw);
    height: min(350px, 60vh);
}

.puzzle-grid.size-6 {
    grid-template-columns: repeat(6, 1fr);
    width: min(360px, 90vw);
    height: min(360px, 60vh);
}

/* Pezzi del puzzle */
.puzzle-piece {
    background-size: cover;
    background-position: center;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.puzzle-piece:hover {
    border-color: #ff9a9e;
    transform: scale(1.02);
    z-index: 2;
}

.puzzle-piece.empty {
    background: linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
                linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 10px 10px;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
    border: 2px dashed #ccc;
    cursor: default;
}

.puzzle-piece.empty:hover {
    border-color: #ccc;
    transform: none;
}

/* Anteprima immagine */
.preview-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.preview-modal.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

.preview-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}

.preview-content img {
    width: 100%;
    height: auto;
    border-radius: 10px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}

.close-preview {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255,255,255,0.9);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.close-preview:hover {
    background: #fff;
    transform: scale(1.1);
}

/* Statistiche del gioco */
.game-stats {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.stat {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.9);
    padding: 12px 18px;
    border-radius: 20px;
    font-size: 0.9rem;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

.stat i {
    color: #e91e63;
    font-size: 1rem;
}

/* Schermata finale */
.final-content {
    text-align: center;
    position: relative;
}

.hearts-animation {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 200px;
    height: 100px;
    pointer-events: none;
}

.heart {
    position: absolute;
    color: #e91e63;
    animation: floatHeart 3s infinite ease-in-out;
}

.heart1 { left: 10%; animation-delay: 0s; font-size: 1.2rem; }
.heart2 { left: 25%; animation-delay: 0.5s; font-size: 0.8rem; }
.heart3 { left: 45%; animation-delay: 1s; font-size: 1.5rem; }
.heart4 { left: 65%; animation-delay: 1.5s; font-size: 1rem; }
.heart5 { left: 80%; animation-delay: 2s; font-size: 0.9rem; }
.heart6 { left: 90%; animation-delay: 2.5s; font-size: 1.1rem; }

.final-message {
    margin: 80px 0 40px 0;
    background: rgba(255,255,255,0.95);
    padding: 40px 30px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}

.typewriter {
    font-family: 'Dancing Script', cursive;
    font-size: 2.5rem;
    font-weight: 700;
    color: #e91e63;
    margin-bottom: 20px;
    overflow: hidden;
    border-right: 3px solid #e91e63;
    white-space: nowrap;
    margin: 0 auto;
    letter-spacing: 0.1em;
    animation: typewriter 4s steps(40, end), blink-caret 0.75s step-end infinite;
}

.celebration-emojis {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 20px;
}

.emoji {
    font-size: 2rem;
    animation: bounce 1s infinite alternate;
}

.emoji:nth-child(1) { animation-delay: 0s; }
.emoji:nth-child(2) { animation-delay: 0.2s; }
.emoji:nth-child(3) { animation-delay: 0.4s; }
.emoji:nth-child(4) { animation-delay: 0.6s; }
.emoji:nth-child(5) { animation-delay: 0.8s; }

.final-stats {
    background: rgba(255,255,255,0.9);
    padding: 25px;
    border-radius: 15px;
    margin: 30px 0;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

.final-stats h3 {
    margin-bottom: 20px;
    color: #333;
    font-size: 1.3rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 15px;
}

.stat-item {
    text-align: center;
    padding: 15px 10px;
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
    border-radius: 10px;
}

.stat-item i {
    font-size: 1.5rem;
    color: #e91e63;
    margin-bottom: 8px;
    display: block;
}

.stat-item span {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 5px;
    opacity: 0.8;
}

.stat-item strong {
    font-size: 1.2rem;
    color: #333;
    font-weight: 700;
}

.play-again-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    padding: 15px 30px;
    border-radius: 25px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Poppins', sans-serif;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.play-again-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.3);
}

/* Loading overlay */
.loading-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(102, 126, 234, 0.9);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    backdrop-filter: blur(5px);
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    font-size: 3rem;
    color: #fff;
    animation: spin 2s linear infinite;
    margin-bottom: 20px;
}

.loading-overlay p {
    color: #fff;
    font-size: 1.2rem;
    text-align: center;
    font-weight: 300;
}

/* Animazioni */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes floatHeart {
    0%, 100% { 
        transform: translateY(0px) rotate(0deg);
        opacity: 0.7;
    }
    50% { 
        transform: translateY(-20px) rotate(180deg);
        opacity: 1;
    }
}

@keyframes typewriter {
    from { width: 0; }
    to { width: 100%; }
}

@keyframes blink-caret {
    from, to { border-color: transparent; }
    50% { border-color: #e91e63; }
}

@keyframes bounce {
    0% { transform: translateY(0px); }
    100% { transform: translateY(-10px); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 480px) {
    .container {
        padding: 15px;
    }
    
    .welcome-header h1 {
        font-size: 2rem;
    }
    
    .welcome-header h2 {
        font-size: 1.7rem;
    }
    
    .card {
        padding: 25px 20px;
    }
    
    .difficulty-buttons {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .difficulty-btn {
        padding: 18px 15px;
    }
    
    .number-buttons {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }
    
    .number-btn {
        padding: 15px 8px;
    }
    
    .game-controls {
        gap: 8px;
    }
    
    .control-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
    
    .game-stats {
        gap: 15px;
    }
    
    .stat {
        padding: 10px 14px;
        font-size: 0.8rem;
    }
    
    .typewriter {
        font-size: 2rem;
    }
    
    .celebration-emojis .emoji {
        font-size: 1.5rem;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .puzzle-grid.size-3 {
        width: min(280px, 85vw);
        height: min(280px, 55vh);
    }
    
    .puzzle-grid.size-4 {
        width: min(300px, 85vw);
        height: min(300px, 55vh);
    }
    
    .puzzle-grid.size-5 {
        width: min(320px, 85vw);
        height: min(320px, 55vh);
    }
    
    .puzzle-grid.size-6 {
        width: min(340px, 85vw);
        height: min(340px, 55vh);
    }
}

@media (max-width: 360px) {
    .welcome-header h1 {
        font-size: 1.8rem;
    }
    
    .typewriter {
        font-size: 1.7rem;
    }
    
    .number-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
}