* {
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    background-image: url('1.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
}

#app {
    background: rgba(255, 255, 255, 0.5);
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    text-align: center;
    backdrop-filter: blur(3px);

    max-width: 1200px;
}

h1 {
    color: #333;
    font-size: 3em;
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    background: linear-gradient(45deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

h2 {
    color: #333;
    margin-bottom: 20px;
}

#level-selection {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 20px;
    margin-top: 30px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.level-card {
    background-color: #f8f9fa;
    border-radius: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5em;
    cursor: pointer;
    transition: all 0.3s ease;
    overflow: hidden;
    position: relative;
    border: 3px solid transparent;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
    min-height: 120px;
    aspect-ratio: 1;
}

.level-card:hover:not(.locked) {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
    border-color: #667eea;
}

.level-card.locked {
    background-color: #e9ecef;
    cursor: not-allowed;
    opacity: 0.6;
}

.level-card.completed {
    border-color: #28a745;
    box-shadow: 0 8px 16px rgba(40, 167, 69, 0.3);
}

.level-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 17px;
    transition: transform 0.3s ease;
}

.level-card:hover:not(.locked) img {
    transform: scale(1.1);
}

.level-card .overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 2.5em;
    border-radius: 17px;
    backdrop-filter: blur(2px);
}

.level-card .level-number {
    position: absolute;
    bottom: 5px;
    right: 8px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8em;
    font-weight: bold;
}

#puzzle-game {
    display: none;
    margin-top: 30px;
}

.cheat-code-input {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 10px;
}

.cheat-code-input input {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 20px;
    font-size: 0.9em;
    outline: none;
    transition: border-color 0.3s ease;
    min-width: 200px;
}

.cheat-code-input input:focus {
    border-color: #667eea;
}

.cheat-code-input input::placeholder {
    color: #999;
}

.cheat-code-input button {
    padding: 8px 16px;
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.3s ease;
}

.cheat-code-input button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.main-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 20px;
}

.support-link-container {
    text-align: center;
    margin-top: 15px;
}

.support-link {
    font-size: 0.8em;
    color: #764ba2;
    text-decoration: none;
    transition: color 0.3s ease;
}

.support-link:hover {
    color: #667eea;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.back-button {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1em;
    transition: all 0.3s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    min-height: 44px; /* Taille minimale pour le tactile */
}

.back-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.game-info {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.timer, .moves-counter {
    background: rgba(255, 255, 255, 0.8);
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    color: #333;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-size: 1em;
}

#puzzle-container {
    display: flex;
    gap: 30px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: nowrap;
    max-width: 1400px;
    margin: 0 auto;
}

#game-sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 320px;
    min-width: 280px;
    flex: 0 0 auto;
}

#preview-sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 250px;
    min-width: 200px;
    flex: 0 0 auto;
}

#image-preview {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    padding: 15px;
    border: 3px solid #28a745;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    text-align: center;
}

#image-preview h3 {
    margin-top: 0;
    margin-bottom: 10px;
    color: #333;
    font-size: 1.1em;
}

#preview-image {
    width: 100%;
    max-width: 200px;
    height: auto;
    border-radius: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

#puzzle-board {
    display: grid;
    gap: 3px;
    border: 3px solid #667eea;
    border-radius: 15px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);

    justify-self: center;
}

#pieces-area {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    padding: 20px;
    border: 3px solid #764ba2;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
    margin: 0 auto;
}


#pieces-area h3 {
    margin-top: 0;
    color: #333;
    font-size: 1.2em;
}

#pieces-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

#pieces-container {
    display: grid;
    /* La grille sera définie dynamiquement en JavaScript */
    /* grid-template-columns sera défini par JS selon puzzleSize */
    gap: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    justify-content: center;
    align-items: start;
}


.puzzle-piece {
    border: 2px solid #ddd;
    cursor: grab;
    background-size: cover;
    background-repeat: no-repeat;
    border-radius: 8px;
    transition: all 0.3s ease;
    position: relative;
    min-height: 90px;
    width: 90px;
    height: 90px;
    touch-action: none; /* Empêche le scroll lors du drag */
}

.puzzle-piece:hover {
    transform: scale(1.05);
    border-color: #667eea;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.puzzle-piece.dragging {
    opacity: 0.8;
    transform: rotate(5deg) scale(1.1);
    z-index: 1000;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.puzzle-piece.correct {
    border-color: #28a745;
    box-shadow: 0 0 10px rgba(40, 167, 69, 0.5);
    animation: correctPiece 0.5s ease;
}

.drop-zone.filled .puzzle-piece {
    transform: scale(1.1);
    transition: transform 0.3s ease;
}

.drop-zone {
    border: 3px dashed #ccc;
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 12px;
    transition: all 0.3s ease;
    position: relative;
    min-height: 100px;
    min-width: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-zone.drag-over {
    border-color: #667eea;
    background-color: rgba(102, 126, 234, 0.1);
    transform: scale(1.02);
}

.drop-zone.filled {
    border-color: #28a745;
}

/* Clone de drag pour le feedback tactile */
#drag-clone {
    pointer-events: none;
    z-index: 9999;
}

@keyframes correctPiece {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes fireworks {
    0% { 
        transform: scale(0.5);
        opacity: 1;
    }
    50% { 
        transform: scale(1.2);
        opacity: 0.8;
    }
    100% { 
        transform: scale(2);
        opacity: 0;
    }
}

@keyframes sparkle {
    0%, 100% { 
        transform: scale(0) rotate(0deg);
        opacity: 0;
    }
    50% { 
        transform: scale(1) rotate(180deg);
        opacity: 1;
    }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-20px);
    }
    60% {
        transform: translateY(-10px);
    }
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
    }
    70% {
        box-shadow: 0 0 0 20px rgba(40, 167, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0);
    }
}

.firework-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    pointer-events: none;
    z-index: 1000;
}

.sparkle-effect {
    position: absolute;
    width: 20px;
    height: 20px;
    pointer-events: none;
    z-index: 999;
    animation: sparkle 0.6s ease-out;
}

.correct-placement {
    animation: bounce 0.6s ease, pulse 1s ease;
}

.completion-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.5s ease;
}

.completion-content {
    background: white;
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.5s ease;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
}

.completion-content h2 {
    color: #28a745;
    font-size: 2.5em;
    margin-bottom: 20px;
}

.completion-content video {
    max-width: 400px;
    width: 100%;
    border-radius: 15px;
    margin: 20px 0;
}

.next-level-button {
    background: linear-gradient(45deg, #28a745, #20c997);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 1.2em;
    margin: 10px;
    transition: all 0.3s ease;
    min-height: 44px; /* Taille minimale pour le tactile */
}

.next-level-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { 
        transform: translateY(50px);
        opacity: 0;
    }
    to { 
        transform: translateY(0);
        opacity: 1;
    }
}

/* Media queries pour mobile */
@media (max-width: 768px) {
    body {
        padding: 10px;
        background-attachment: scroll; /* Meilleure performance sur mobile */
    }

    #app {
        padding: 20px;
        width: 100%;
        max-width: none;
    }

    h1 {
        font-size: 2em;
        margin-bottom: 20px;
    }

    #level-selection {
        grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
        gap: 15px;
        max-width: none;
    }

    .level-card {
        min-height: 100px;
        font-size: 1.2em;
    }

    .level-card .overlay {
        font-size: 2em;
    }

    .game-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .game-info {
        justify-content: center;
        gap: 15px;
    }

    #puzzle-container {
        flex-direction: column;
        gap: 20px;
        align-items: center;
    }

    #game-sidebar, #preview-sidebar {
        max-width: 100%;
        min-width: auto;
        width: 100%;
        order: 2;
    }

    #puzzle-board {
        order: 1;

        justify-self: center;
    }

    #preview-sidebar {
        order: 3;
    }

    #pieces-container {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }

    .puzzle-piece {
        width: 70px;
        height: 70px;
        min-height: 70px;
    }

    .drop-zone {
        min-height: 80px;
        min-width: 80px;
    }

    .cheat-code-input {
        flex-direction: column;
        gap: 10px;
    }

    .cheat-code-input input {
        min-width: auto;
        width: 100%;
        max-width: 250px;
    }

    .completion-content {
        padding: 20px;
        margin: 10px;
    }

    .completion-content h2 {
        font-size: 2em;
    }

    .completion-content video {
        max-width: 100%;
    }

    .timer, .moves-counter {
        font-size: 0.9em;
        padding: 6px 12px;
    }
}

@media (max-width: 480px) {
    #app {
        padding: 15px;
    }

    h1 {
        font-size: 1.8em;
    }

    #level-selection {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .level-card {
        min-height: 80px;
        font-size: 1em;
    }

    .level-card .level-number {
        width: 20px;
        height: 20px;
        font-size: 0.7em;
    }

    #pieces-container {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }

    .puzzle-piece {
        width: 60px;
        height: 60px;
        min-height: 60px;
    }

    .drop-zone {
        min-height: 70px;
        min-width: 70px;
    }

    .back-button, .next-level-button {
        padding: 10px 20px;
        font-size: 0.9em;
    }

    .completion-content {
        padding: 15px;
    }

    .completion-content h2 {
        font-size: 1.8em;
    }
}

/* Amélioration pour les écrans tactiles */
@media (hover: none) and (pointer: coarse) {
    .puzzle-piece:hover {
        transform: none;
    }
    
    .level-card:hover:not(.locked) {
        transform: none;
    }
    
    .level-card:hover:not(.locked) img {
        transform: none;
    }
    
    .back-button:hover,
    .next-level-button:hover {
        transform: none;
    }
    
    /* Augmenter la taille des zones tactiles */
    .puzzle-piece {
        min-height: 80px;
        min-width: 80px;
    }
    
    .drop-zone {
        min-height: 90px;
        min-width: 90px;
    }
}

