* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Arial, sans-serif;
}

body {
    background-color: #faf8ef;
    color: #776e65;
    line-height: 1.4;
    /* Full-viewport sizing similar to play2048 */
    display: flex;
    flex-direction: column;
    height: 100svh;
    width: 100svw;
}

/* Prevent mobile pull-to-refresh/scroll within the game area */
html, body {
    height: 100%;
    overscroll-behavior: none; /* fully disable pull-to-refresh */
    touch-action: none; /* disable browser gestures globally */
    overflow: hidden; /* prevent any page scroll */
}

/* Scroll jail wrapper: allow 1px internal scroll (sentinel) to neutralize PTR */
#app-root {
    position: fixed;
    inset: 0;
    overflow-y: auto; /* minimal internal scroll */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: none; /* ensure gestures don't scroll root */
}

/* 1px sentinel to keep scrollTop > 0 */
#ptr-sentinel { height: 1px; width: 1px; }

.game-container, .grid-container {
    touch-action: none; /* disable browser gesture handling inside the board */
    overscroll-behavior: contain; /* prevent pull-to-refresh bounce */
}

.container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 12px 16px; /* slightly tighter to fit */
    min-height: 100vh; /* fill viewport height so page itself won't scroll */
    box-sizing: border-box;
}

/* Device-conditional HOW TO PLAY text (JS controls visibility) */
.howto-desktop,
.howto-touch { display: none; }

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

h1 {
    font-size: 80px;
    font-weight: bold;
    color: #776e65;
    margin: 0;
}

.scores {
    display: flex;
    gap: 10px;
}

.score-box {
    background: #bbada0;
    color: white;
    padding: 5px 15px;
    border-radius: 3px;
    text-align: center;
    min-width: 100px;
}

.score-title {
    font-size: 13px;
    text-transform: uppercase;
}

.score-box div:last-child {
    font-size: 20px;
    font-weight: bold;
}

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

button {
    background: #8f7a66;
    color: white;
    border: none;
    border-radius: 3px;
    padding: 10px 20px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
}

button:hover {
    background: #9f8b77;
}

.game-container {
    background: #bbada0;
    border-radius: 6px;
    padding: 15px;
    position: relative;
    margin-bottom: 20px;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-gap: 15px;
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: #bbada0;
    border-radius: 6px;
    padding: 0;
}

.grid-cell {
    background: rgba(238, 228, 218, 0.35);
    border-radius: 3px;
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 35px;
    font-weight: bold;
    color: #776e65;
    transition: all 0.15s ease;
    position: relative;
    overflow: hidden;
}

.tile {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 35px;
    font-weight: bold;
    border-radius: 3px;
    transition: transform 0.15s ease;
    z-index: 10;
}

.tile-2 { background: #eee4da; }
.tile-4 { background: #ede0c8; }
.tile-8 { color: #f9f6f2; background: #f2b179; }
.tile-16 { color: #f9f6f2; background: #f59563; }
.tile-32 { color: #f9f6f2; background: #f67c5f; }
.tile-64 { color: #f9f6f2; background: #f65e3b; }
.tile-128 { 
    color: #f9f6f2; 
    background: #edcf72;
    font-size: 30px;
}
.tile-256 { 
    color: #f9f6f2; 
    background: #edcc61;
    font-size: 30px;
}
.tile-512 { 
    color: #f9f6f2; 
    background: #edc850;
    font-size: 30px;
}
.tile-1024 { 
    color: #f9f6f2; 
    background: #edc53f;
    font-size: 25px;
}
.tile-2048 { 
    color: #f9f6f2; 
    background: #edc22e;
    font-size: 25px;
}

.tile-merged {
    z-index: 20;
    animation: pop 0.2s ease-in-out;
}

.tile-new {
    animation: appear 0.2s ease-in-out;
    animation-fill-mode: backwards;
}

@keyframes appear {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

@keyframes pop {
    0% { opacity: 0.9; }
    50% { opacity: 1; }
    100% { opacity: 1; }
}

.game-over {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(238, 228, 218, 0.73);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: 6px;
    display: none;
}

.game-over h2 {
    font-size: 60px;
    color: #776e65;
    margin-bottom: 20px;
}

.game-explanation {
    color: #776e65;
    text-align: center;
    line-height: 1.6;
    margin-top: 30px;
}

@media (max-width: 520px) {
    /* Avoid content touching the very top edge */
    body { padding-top: 8px; }

    html, body {
        overflow: hidden; /* prevent page scroll that can trigger pull-to-refresh */
        height: 100vh;
    }

    .container {
        padding: 10px;
    }
    
    h1 {
        font-size: 50px;
    }
    
    .score-box {
        min-width: 80px;
        padding: 5px 10px;
    }
    
    .tile {
        font-size: 25px;
    }
    
    .tile-128, .tile-256, .tile-512 {
        font-size: 20px;
    }
    
    .tile-1024, .tile-2048 {
        font-size: 18px;
    }
    
    /* Lock the app fullscreen to avoid pull-to-refresh */
    .container {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
}
