:root {
    --primary-color: #005a8d;
    --secondary-color: #ffc107;
    --light-color: #f0f8ff;
    --dark-color: #333;
    --board-size: 72vh; 
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--light-color);
    color: var(--dark-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    height: 100vh;
    margin: 0;
    padding: 1rem;
    box-sizing: border-box;
    text-align: center;
    overflow: hidden; 

    /* Impede a seleção de texto e elementos em todo o jogo */
    -webkit-user-select: none; /* Safari */
    -ms-user-select: none;     /* IE 10+ e Edge */
    user-select: none;         /* Padrão moderno */
}

h1 {
    color: var(--primary-color);
    margin: 0 0 0.5rem 0;
    font-size: 2rem;
}

p {
    margin: 0 0 1.5rem 0;
    font-size: 1.1rem;
}

.game-layout {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 3rem; 
    width: 100%;
    max-width: 1200px;
    height: calc(100vh - 130px); 
}

.left-panel {
    flex: 1; 
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
}

#game-container {
    padding: 12px;
    background-color: var(--primary-color);
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.25);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.5s ease;
}

#win-overlay:not(.hidden) ~ .game-layout #game-container {
    box-shadow: 0 0 30px var(--secondary-color);
    transform: scale(1.02);
}

#game-board {
    display: grid;
    border: 3px solid #fff;
    width: var(--board-size);
    height: var(--board-size);
    max-width: 800px; 
    max-height: 800px;
    background-color: #fff;
}

.puzzle-piece {
    border: 1px solid rgba(0, 60, 94, 0.4);
    transition: transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.puzzle-piece:hover {
    filter: brightness(1.1);
}

.puzzle-piece:active {
    transform: scale(0.95);
}

.right-panel {
    width: 340px; 
    flex-shrink: 0; 
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: rgba(0, 90, 141, 0.08);
    padding: 1.5rem;
    border-radius: 12px;
    height: 100%;
    max-height: var(--board-size); 
    box-sizing: border-box;
}

#puzzle-selection {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

#puzzle-selection h2 {
    font-size: 1.3rem;
    margin-top: 0;
    margin-bottom: 1rem;
    color: var(--primary-color);
}

#thumbnails {
    display: grid;
    grid-template-columns: repeat(3, 1fr); 
    gap: 15px;
    padding: 10px;
    overflow-y: auto; 
    flex: 1;
}

#thumbnails::-webkit-scrollbar {
    width: 8px;
}
#thumbnails::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.05);
    border-radius: 10px;
}
#thumbnails::-webkit-scrollbar-thumb {
    background-color: var(--primary-color);
    border-radius: 10px;
}

.thumbnail-image {
    width: 100%;
    aspect-ratio: 1 / 1; 
    object-fit: cover;
    border-radius: 10px;
    border: 4px solid transparent;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
}

.thumbnail-image:hover {
    transform: scale(1.05);
}

.thumbnail-image.selected {
    border-color: var(--secondary-color);
    box-shadow: 0 0 15px rgba(255, 193, 7, 0.6);
}

#win-overlay {
    position: fixed;
    bottom: 30px; 
    right: 30px;  
    width: auto;
    height: auto;
    background-color: transparent; 
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease-in-out;
}

#win-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: all;
}

#win-message {
    background-color: white;
    color: var(--dark-color);
    padding: 1.5rem 2rem;
    border-radius: 15px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    border: 4px solid var(--secondary-color);
    transform: translateY(50px); 
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#win-overlay:not(.hidden) #win-message {
    transform: translateY(0);
}

#win-message h2 {
    margin: 0;
    color: var(--primary-color);
    font-size: 1.5rem;
}

#win-message p {
    margin: 5px 0 15px 0;
    font-size: 1rem;
}

.hidden {
    display: none;
}

button {
    margin-top: 10px;
    padding: 10px 20px;
    font-size: 1rem;
    font-family: 'Poppins', sans-serif;
    cursor: pointer;
    background-color: var(--secondary-color);
    border: none;
    border-radius: 8px;
    color: var(--dark-color);
    font-weight: 600;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    transition: background-color 0.2s, transform 0.1s;
}

button:hover {
    background-color: #ffa000;
    transform: translateY(-2px);
}

@media (max-width: 850px) {
    body {
        overflow: auto; 
        height: auto;
    }
    .game-layout {
        flex-direction: column;
        height: auto;
        gap: 2rem;
    }
    :root {
        --board-size: 85vw; 
    }
    .right-panel {
        width: 100%;
        max-height: none;
    }
    #win-overlay {
        bottom: 10px;
        right: 10px;
        left: 10px; 
    }
}