/* Game Container */
#game-container {
    position: relative;
    background: #bbada0;
    border-radius: 6px;
    padding: 15px;
    margin: 30px auto;
    width: 500px !important; /* Force exact width */
    height: 500px !important; /* Force exact height */
    box-sizing: border-box;
}

/* Grid Container */
.grid-container {
    position: absolute;
    top: 15px;
    left: 15px;
    right: 15px;
    bottom: 15px;
    width: 470px;
    height: 470px;
    background: transparent;
    border-radius: 6px;
}

.grid-row {
    display: flex;
    height: 106.25px; /* (470 - 45) / 4 = exact cell size */
    margin-bottom: 15px;
}

.grid-row:last-child {
    margin-bottom: 0;
}

.grid-cell {
    width: 106.25px;
    height: 106.25px;
    background: rgba(238, 228, 218, 0.35);
    border-radius: 3px;
    margin-right: 15px;
}

.grid-cell:last-child {
    margin-right: 0;
}

/* Tile Container */
.tile-container {
    position: absolute;
    top: 15px;
    left: 15px;
    width: 470px;
    height: 470px;
    z-index: 2;
}

/* Tiles */
.tile {
    position: absolute;
    width: 106.25px;
    height: 106.25px;
    transition: 100ms ease-in-out;
    transition-property: transform;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 55px;
    font-weight: bold;
    line-height: 106.25px;
}

.tile-new {
    animation: appear 200ms ease;
}

.tile-merged {
    animation: pop 200ms ease;
}

@keyframes appear {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Tile positions - Based on 470px grid with 15px gaps */
/* Row 1 */
.tile-position-1-1 { transform: translate(0, 0); }
.tile-position-1-2 { transform: translate(121.25px, 0); }
.tile-position-1-3 { transform: translate(242.5px, 0); }
.tile-position-1-4 { transform: translate(363.75px, 0); }

/* Row 2 */
.tile-position-2-1 { transform: translate(0, 121.25px); }  /* row 2, col 1 - DOWN */
.tile-position-2-2 { transform: translate(121.25px, 121.25px); }
.tile-position-2-3 { transform: translate(242.5px, 121.25px); }
.tile-position-2-4 { transform: translate(363.75px, 121.25px); }

/* Row 3 */
.tile-position-3-1 { transform: translate(0, 242.5px); }
.tile-position-3-2 { transform: translate(121.25px, 242.5px); }
.tile-position-3-3 { transform: translate(242.5px, 242.5px); }
.tile-position-3-4 { transform: translate(363.75px, 242.5px); }

/* Row 4 */
.tile-position-4-1 { transform: translate(0, 363.75px); }
.tile-position-4-2 { transform: translate(121.25px, 363.75px); }
.tile-position-4-3 { transform: translate(242.5px, 363.75px); }
.tile-position-4-4 { transform: translate(363.75px, 363.75px); }

/* Tile colors */
.tile-2 { 
    background: #eee4da; 
    color: #776e65; 
    box-shadow: 0 0 30px 10px rgba(243, 215, 116, 0), inset 0 0 0 1px rgba(255, 255, 255, 0);
}

.tile-4 { 
    background: #ede0c8; 
    color: #776e65; 
}

.tile-8 { 
    background: #f2b179; 
    color: #f9f6f2; 
}

.tile-16 { 
    background: #f59563; 
    color: #f9f6f2; 
}

.tile-32 { 
    background: #f67c5f; 
    color: #f9f6f2; 
}

.tile-64 { 
    background: #f65e3b; 
    color: #f9f6f2; 
}

.tile-128 { 
    background: #edcf72; 
    color: #f9f6f2; 
    font-size: 45px;
}

.tile-256 { 
    background: #edcc61; 
    color: #f9f6f2; 
    font-size: 45px;
}

.tile-512 { 
    background: #edc850; 
    color: #f9f6f2; 
    font-size: 45px;
}

.tile-1024 { 
    background: #edc53f; 
    color: #f9f6f2; 
    font-size: 35px;
}

.tile-2048 { 
    background: #edc22e; 
    color: #f9f6f2; 
    font-size: 35px;
}

.tile-super { 
    background: #3c3a32; 
    color: #f9f6f2; 
    font-size: 30px;
}

/* Cupcake mode */
.tile.cupcake-mode {
    font-size: 0;
    line-height: 0;
}

.tile.cupcake-mode img {
    width: 90%;
    height: 90%;
    object-fit: contain;
}

/* Responsive */
@media screen and (max-width: 520px) {
    #game-container {
        width: 100% !important;
        max-width: 500px;
        height: auto !important;
        aspect-ratio: 1 / 1;
        padding: 10px;
    }
    
    .grid-container {
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 10px;
        width: calc(100% - 20px);
        height: calc(100% - 20px);
    }
    
    .grid-row {
        height: calc((100% - 30px) / 4);
        margin-bottom: 10px;
    }

    .grid-row:last-child {
        margin-bottom: 0;
    }
    
    .grid-cell {
        width: calc((100% - 30px) / 4);
        height: 100%;
        margin-right: 10px;
    }

    .grid-cell:last-child {
        margin-right: 0;
    }
    
    .tile-container {
        top: 10px;
        left: 10px;
        right: 10px;
        bottom: 10px;
        width: calc(100% - 20px);
        height: calc(100% - 20px);
    }
    
    .tile {
        width: calc((100vw - 60px) / 4.7);
        height: calc((100vw - 60px) / 4.7);
        max-width: 100px;
        max-height: 100px;
        font-size: 35px;
        line-height: 1;
    }
    
    /* Mobile tile positions - Using percentages */
    .tile-position-1-1 { transform: translate(0, 0); }
    .tile-position-1-2 { transform: translate(calc((100vw - 60px) / 3.88), 0); }
    .tile-position-1-3 { transform: translate(calc((100vw - 60px) / 1.94), 0); }
    .tile-position-1-4 { transform: translate(calc((100vw - 60px) / 1.29), 0); }

    .tile-position-2-1 { transform: translate(0, calc((100vw - 60px) / 3.88)); }
    .tile-position-2-2 { transform: translate(calc((100vw - 60px) / 3.88), calc((100vw - 60px) / 3.88)); }
    .tile-position-2-3 { transform: translate(calc((100vw - 60px) / 1.94), calc((100vw - 60px) / 3.88)); }
    .tile-position-2-4 { transform: translate(calc((100vw - 60px) / 1.29), calc((100vw - 60px) / 3.88)); }

    .tile-position-3-1 { transform: translate(0, calc((100vw - 60px) / 1.94)); }
    .tile-position-3-2 { transform: translate(calc((100vw - 60px) / 3.88), calc((100vw - 60px) / 1.94)); }
    .tile-position-3-3 { transform: translate(calc((100vw - 60px) / 1.94), calc((100vw - 60px) / 1.94)); }
    .tile-position-3-4 { transform: translate(calc((100vw - 60px) / 1.29), calc((100vw - 60px) / 1.94)); }

    .tile-position-4-1 { transform: translate(0, calc((100vw - 60px) / 1.29)); }
    .tile-position-4-2 { transform: translate(calc((100vw - 60px) / 3.88), calc((100vw - 60px) / 1.29)); }
    .tile-position-4-3 { transform: translate(calc((100vw - 60px) / 1.94), calc((100vw - 60px) / 1.29)); }
    .tile-position-4-4 { transform: translate(calc((100vw - 60px) / 1.29), calc((100vw - 60px) / 1.29)); }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 30px;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 24px;
    }
    
    .tile-super {
        font-size: 20px;
    }
}

@media screen and (max-width: 380px) {
    .tile {
        font-size: 30px;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 25px;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 20px;
    }
    
    .tile-super {
        font-size: 16px;
    }
}

/* Score animation */
.score-addition {
    position: absolute;
    right: 30px;
    color: rgba(119, 110, 101, 0.9);
    font-weight: bold;
    font-size: 25px;
    line-height: 25px;
    animation: move-up 600ms ease-in;
    animation-fill-mode: both;
}

@keyframes move-up {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    100% {
        opacity: 0;
        transform: translateY(-50px);
    }
}

/* Support for multiple game instances */
.game-2048-wrapper {
    margin: 20px 0;
}

.game-container-instance {
    position: relative;
    background: #bbada0;
    border-radius: 6px;
    padding: 15px;
    margin: 30px auto;
    width: 500px !important;
    height: 500px !important;
    box-sizing: border-box;
}

/* Rest of your existing game.css stays the same */
/* Just make sure all #game-container references also work with .game-container-instance */