* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

#game-board {
    touch-action: none;
}

body {
    font-family: Arial, sans-serif;
    background: #faf8ef;
    display: flex;
    justify-content: center;
    padding: 40px 20px;
}

.container {
    width: 420px;
    position:relative;
}

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


h1.title {
    color: #73916a;
    margin: 0 0 40px;
    font-size: 40px;
    text-align: center;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    height: 120px;
}

.score-inner {
    display: grid;
    height: 100%;
}

.score-inner span {
    font-size: 2.4rem;
    font-weight: bold;
}

span.label {
    font-size: 1.4rem;
    font-weight: normal;
}

.score-box.best-score {
    background: #b5d1ac;
}

.score-box {
    width: 45%;
    background: #c0c7be;
    color: white;
    padding: 10px 18px;
    border-radius: 8px;
    text-align: center;
}

.score-title {
    font-size: 12px;
}

.score {
    font-size: 26px;
    font-weight: bold;
}

#restart {
    margin-top: 10px;
    width: 100%;
    padding: 10px;
    background: #8f7a66;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
}

#restart:hover {
    background: #7a6756;
}

#game-board {
    margin-top: 20px;
    background: #bbada0;
    border-radius: 10px;
    padding: 10px;
    justify-content: center;
    display: grid;
    grid-template-columns: repeat(4, 90px);
    grid-template-rows: repeat(4, 90px);
    gap: 10px;

    touch-action: none;
}

.cell {
    position: relative;
    width: 90px;
    height: 90px;
    border-radius: 6px;
    background: #cdc1b4;

    display: flex;
    justify-content: center;
    align-items: center;

    font-size: 32px;
    font-weight: bold;
    color: #776e65;
}

.tile-number{
    position: absolute;
    top: 0;
    left: 4px;
    font-size: 24px;
    font-weight: 800;
    color: #ffffff;
    z-index: 10;
    background: none;
    padding: 0;
    text-shadow: 0 1px 2px rgb(30 4 4 / 90%), 0 0 6px rgba(0, 0, 0, 0.35);
}

.cell img{
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.tile-2 { background: #fdf9f2; color: white; }
.tile-4 { background: #4aa0fb;color: white; }
.tile-8 { background: #fcffd9; color: white; }
.tile-16 { background: #f7d8ff; color: white;}
.tile-32 { background: #ff5f99; color: white;}
.tile-64 { background: #ff96a3; color: white; }
.tile-128 { background: #bd2525; color: white; font-size: 26px; }
.tile-256 { background: #ff7ce8; color: white; font-size: 26px; }
.tile-512 { background: #c7fff3; color: white; font-size: 26px; }
.tile-1024 { background: #15f3f5; color: white; font-size: 22px; }
.tile-2048 { background: #209bff; color: white; font-size: 22px; }
.tile-4096 { background: #fffad5; color: white; font-size: 22px; }

@keyframes pop {

    0% {
        transform: scale(0.5);
    }

    40% {
        transform: scale(1.25);
    }

    60% {
        transform: scale(0.92);
    }

    80% {
        transform: scale(1.08);
    }

    100% {
        transform: scale(1);
    }

}

.pop img{
    animation: pop 320ms cubic-bezier(.18,1.5,.45,1);
}

#restart-btn {
    margin: 0 0 40px;
    padding: 12px 24px;
    background: linear-gradient(180deg, #a4dd92, #64c333);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 18px;
    font-weight: bold;
    transition: all .15s ease;
    box-shadow: 0 5px 0 #628457, 0 8px 16px rgba(0, 0, 0, .18);
    width: 100%;
}

#restart-btn:hover{

    transform: translateY(-2px);

    box-shadow:
        0 7px 0 #3E9620,
        0 10px 20px rgba(0,0,0,.22);

}

.instructions {
    margin: 16px 0;
    text-align: center;
    color: #868f85;
}

.instructions p {
    text-align: left;
}



.message{

    position: absolute;

    inset: 0;

    display:flex;

    justify-content:center;

    align-items:center;

    background:rgba(255,255,255,.85);

    backdrop-filter:blur(4px);

    z-index:100;

}

.message p{

    background:white;

    padding:32px 50px;

    border-radius:24px;

    font-size:32px;

    font-weight:bold;

    text-align:center;

    color:#5f4b32;

    box-shadow:0 15px 40px rgba(0,0,0,.2);

}

.hidden{

    display:none;

}

/*---------- クレジット ---------- */
.credit {
    font-size: 0.8rem;
    color: #85918b;
}

.credit a{
    color: inherit;
}

h3 {
    margin: 8px 0 0;
}
/* ---------- オーバーレイ ---------- */

.overlay{

    position:fixed;
    inset:0;

    background:rgba(0,0,0,.45);

    display:flex;
    justify-content:center;
    align-items:center;

    z-index:100;

}

.hidden{
    display:none;
}

.overlay{
    animation: fadeIn .25s;
}

@keyframes fadeIn{
    from{
        opacity:0;
    }
    to{
        opacity:1;
    }
}

.overlay-box{

    width:320px;

    background:white;

    border-radius:20px;

    padding:30px;

    text-align:center;

    animation:popup .35s;

    box-shadow:0 15px 40px rgba(0,0,0,.25);

}

.overlay-box h2{

    font-size:32px;

    margin-bottom:15px;

    color:#5cb85c;

}

.overlay-box p{

    margin-bottom:25px;

    white-space:pre-line;

    line-height:1.7;

}

#overlay-button{

    border:none;

    border-radius:999px;

    padding:12px 28px;

    background:#67d36f;

    color:white;

    font-size:18px;

    cursor:pointer;

}

#overlay-button:hover{

    background:#4fc45a;

}

@keyframes popup{

    from{

        opacity:0;
        transform:scale(.7);

    }

    to{

        opacity:1;
        transform:scale(1);

    }

}

@media (max-width: 500px){

.container{
        width:95vw;
    }

    #game-board{

        grid-template-columns:repeat(4,1fr);
        grid-template-rows:repeat(4,1fr);

        gap:8px;
        padding:8px;
    }

    .cell{

        width:calc((95vw - 48px)/4);
        height:calc((95vw - 48px)/4);

    }

    .tile-number{

        font-size:20px;

    }

    #restart-btn{

        font-size:20px;

    }

}
