body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    background-color: #1a3a1a;
    color: #fff;
    margin: 0;
    padding: 1em;
    box-sizing: border-box;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1em;
}

#game-board {
    position: relative;
    width: calc(12 * var(--tile-width) + 12 * var(--tile-gap-x));
    height: calc(4 * var(--tile-height) + 4 * var(--tile-gap-y));
    margin: 2em auto;
}

#game-message {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 2rem 3rem;
    border-radius: 15px;
    text-align: center;
    font-size: 1.5rem;
    z-index: 1000;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    border: 2px solid #4caf50;
    pointer-events: none; /* Allow seeing behind, but maybe block interactions? */
}

#game-message.hidden {
    display: none;
}

/* Base Tile Dimensions */
:root {
    --tile-width: 56.888pt; /* Derived from SVG width / 9 */
    --tile-height: 76.8pt; /* Derived from SVG height / 5 */
    --tile-depth: 0.5vw;
    --tile-gap-x: 0.1vw;
    --tile-gap-y: 0.1vw;
}

.tile {
    position: absolute;
    width: var(--tile-width);
    height: var(--tile-height);
    background-color: #c5c5c5; /* Fallback for transparency */
    border: 2px solid #b9b9b9;
    border-radius: 5%;
    box-sizing: border-box;
    cursor: default; /* Default cursor for blocked tiles */
    transition:
        transform 0.2s,
        box-shadow 0.2s;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;

    /* Positioning using CSS variables */
    left: calc(var(--x) * (var(--tile-width) / 2 + var(--tile-gap-x) / 2));
    top: calc(var(--y) * (var(--tile-height) / 2 + var(--tile-gap-y) / 2));
    z-index: var(--z);

    transform: translate(
        calc(var(--z) * var(--tile-depth)),
        calc(var(--z) * var(--tile-depth) * -1)
    );
    box-shadow: calc(var(--tile-depth) * -1) calc(var(--tile-depth)) 5px
        rgba(0, 0, 0, 0.3);

    filter: brightness(0.9); /* Slightly darken blocked tiles */
}

.tile.free {
    cursor: pointer;
    filter: brightness(1); /* Full brightness for free tiles */
}

.tile-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none; /* Allow clicks to pass through to the tile div */
}

.tile.free:hover {
    transform: translate(
            calc(var(--z) * var(--tile-depth)),
            calc(var(--z) * var(--tile-depth) * -1)
        )
        scale(1.1);
    z-index: 100;
}

.tile.selected {
    box-shadow:
        calc(var(--tile-depth) * -1) calc(var(--tile-depth)) 5px
            rgba(0, 0, 0, 0.3),
        0 0 0 3px #4caf50; /* Highlight for selected tile */
}

.tile.matched {
    animation: fadeOut 0.3s forwards;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

.tile.hint {
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
    0%,
    100% {
        transform: translate(
                calc(var(--z) * var(--tile-depth)),
                calc(var(--z) * var(--tile-depth) * -1)
            )
            scale(1);
    }
    50% {
        transform: translate(
                calc(var(--z) * var(--tile-depth)),
                calc(var(--z) * var(--tile-depth) * -1)
            )
            scale(1.05);
        box-shadow:
            calc(var(--tile-depth) * -1) calc(var(--tile-depth)) 5px
                rgba(0, 0, 0, 0.3),
            0 0 0 4px #ffd700; /* Gold highlight for hint */
    }
}

#controls {
    display: flex;
    gap: 1em;
}

button {
    padding: 0.8em 1.5em;
    font-size: 1em;
    border: none;
    background-color: #4caf50;
    color: white;
    cursor: pointer;
    border-radius: 5px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5em;
}

.btn-icon {
    width: 1.2em;
    height: 1.2em;
    object-fit: contain;
}

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

/* Responsive adjustments for iPad / smaller screens */
@media (max-width: 1024px) {
    :root {
        --tile-width: 5vw;
        --tile-height: 6.5vw;
    }
    #game-board {
        transform: scale(0.9);
        margin-top: 1em;
    }
}

@media (max-width: 768px) {
    :root {
        --tile-width: 6vw;
        --tile-height: 8vw;
    }
    #game-board {
        transform: scale(0.8);
        margin-top: -1em;
    }
}

@media (max-width: 480px) {
    :root {
        --tile-width: 8vw;
        --tile-height: 10vw;
    }
    #game-board {
        transform: scale(0.6);
        margin-top: -3em;
    }
}
