.game-container {
    position: relative;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
}

h1 {
    margin: 0;
    font-size: 1.8em;
}

.container {
    text-align: center;
    margin: 0 auto 20px auto;
    max-width: 500px;
}

#game-board {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    width: 400px;
    height: 400px;
    margin: 20px auto;
    padding: 5px;
    background-color: #333;
    border-radius: 5px;
    position: relative;
}

.tile {
    position: relative;
    border: 2px solid #666;
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.2s;
    aspect-ratio: 1;
    background-image: url('puzzle-bg.svg');
    background-size: 400% 400%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tile::after {
    content: attr(data-number);
    position: absolute;
    font-size: 2em;
    color: rgba(255, 255, 255, 0.5);
    text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    opacity: 1;
    transition: opacity 0.5s ease-in-out;
}

.tile:hover {
    transform: scale(1.02);
}

.empty {
    background-color: transparent;
    border: none;
    cursor: default;
}

button {
    padding: 10px 20px;
    font-size: 1em;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#shuffle {
    position: static;
}

button:hover {
    background-color: #45a049;
}

#shuffle, #image-select-button {
    padding: 18px 30px;
    font-size: 1.3em;
}

.game-won .tile::after {
    opacity: 0;
}

.game-won .tile {
    opacity: 0;
    transition: opacity 0.2s ease-in-out 1s;
}

#game-board.game-won {
    background-color: white;
    transition: background-color 1s ease-in-out 1s;
}

.win-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border-radius: 5px;
    animation: reveal-wipe 1s ease-in-out forwards, dissolve-edges 1s ease-in-out 1s forwards;
}

@keyframes reveal-wipe {
    from {
        clip-path: polygon(0 0, 0 0, 0 100%, 0 100%);
    }
    to {
        clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
    }
}

@keyframes dissolve-edges {
    from {
        -webkit-mask-image: radial-gradient(circle at center, black 283px, transparent 283px);
        mask-image: radial-gradient(circle at center, black 283px, transparent 283px);
    }
    to {
        -webkit-mask-image: radial-gradient(circle at center, black var(--mask-end-inner-radius), transparent var(--mask-end-outer-radius));
        mask-image: radial-gradient(circle at center, black var(--mask-end-inner-radius), transparent var(--mask-end-outer-radius));
    }
}

/* New Styles for Image Selection Modal */
.hidden {
    display: none !important;
}

#image-select-button {
    background-color: #007BFF;
}

#image-select-button:hover {
    background-color: #0056b3;
}

#image-select-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.image-select-modal {
    background-color: white;
    padding: 20px;
    border-radius: 10px;
    width: 80%;
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    text-align: center;
    color: #333;
}

.image-select-modal .close-button {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 2em;
    background: none;
    border: none;
    cursor: pointer;
    color: #333;
    padding: 0;
}

.image-select-modal .back-button {
    display: block;
    margin-bottom: 15px;
    background: #6c757d;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    width: fit-content;
}

.image-select-modal .back-button:hover {
    background: #5a6268;
}

.category-list, .image-options {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.category-button {
    padding: 20px 30px;
    font-size: 1.2em;
    background-color: #17a2b8;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.category-button:hover {
    background-color: #138496;
}

.selectable-image {
    border: 3px solid transparent;
    border-radius: 5px;
    cursor: pointer;
    transition: border-color 0.2s;
    object-fit: cover;
}

.selectable-image:hover {
    border-color: #007BFF;
}

.selectable-image.selected {
    border-color: #28a745;
    box-shadow: 0 0 10px #28a745;
}

/* Confetti overlay displayed across the whole page (including puzzle area) */
.confetti-overlay {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    overflow: hidden;
    z-index: 200;
}

.confetti-piece {
    position: absolute;
    will-change: transform;
    opacity: 0.95;
    filter: drop-shadow(0 2px 1px rgba(0,0,0,0.2));
    animation-name: confetti-fall;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}

@keyframes confetti-fall {
    0% {
        transform: translate(0, -10vh) rotate(0deg);
    }
    100% {
        transform: translate(var(--drift, 0px), 110vh) rotate(var(--rotation, 360deg));
    }
}

/* Title area with coin counter */
.title-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.coin-display {
    display: flex;
    align-items: center;
    gap: 8px;
}

.coin-frame {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 6px;
    min-width: 40px;
    height: 32px;
    background: #f5f7fb;
    border: 1px solid #e3e7ee;
    border-radius: 6px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.5);
}

.coin {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-image: url('monete.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

#coin-count {
    font-weight: 600;
    color: #333;
}

.coin-frame.bump {
    animation: coin-bump 0.3s ease;
}

@keyframes coin-bump {
    0% { transform: scale(1); }
    40% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* Magic wand helper button */
#magic-wand {
    position: fixed;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    z-index: 150;
    padding: 14px 18px;
    font-size: 1.1em;
    background-color: #8e44ad;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

#magic-wand:hover {
    background-color: #7d3c98;
}

#magic-wand:disabled {
    background-color: #b9b9b9;
    cursor: not-allowed;
}
