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

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

body {
    font-family: Arial, sans-serif;
    background: #f9f7f5;
    display: flex;
    justify-content: center;
    position: relative;
    min-height: 100vh;
    padding: 40px 20px;
}

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

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


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

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

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

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

span.label {
    font-size: 14px;
    font-weight: normal;
}

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

.score-box {
    width: 45%;
    background: #c7c2be;
    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: -3px;
    left: 3px;
    font-size: 1.3rem;
    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: #f7dfb2;}
.tile-4 { background: #f9b7df;}
.tile-8 { background: #952020; }
.tile-16 { background: #b8d9d1; }
.tile-32 { background: #a7ee98; }
.tile-64 { background: #31b1c3;  }
.tile-128 { background: #f74727;  }
.tile-256 { background: #b97aec;  }
.tile-512 { background: #c6bb21;  }
.tile-1024 { background: linear-gradient(135deg, #6c270d, #7f8069); }
.tile-2048 { background: linear-gradient(135deg, #ff7ac4, #fffefb);}
.tile-4096 { background: linear-gradient(135deg, #011251, #0a0906)}
/*.tile-8192 { background:linear-gradient(135deg, #ebffaf, #befffc);}*/

@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: #ad3c0f;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 18px;
    font-weight: bold;
    transition: all .15s ease;
    box-shadow: 0 5px 0 #8a2d09, 0 8px 16px rgba(0, 0, 0, .18);
    width: 100%;
}

#restart-btn:hover{

    transform: translateY(-2px);

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

}

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

.instructions p {
    font-size: 12px;
    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;

}

    /* --------- リンク ----------  */

    .link {
        margin: 0 0 64px;
        padding: 24px 0 0;
        border-top: 1px solid #CCC;
    }

    .link-item {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        height: 52px;
        border-radius: 4px;
    }

    .link-item a {
        text-decoration: none;
        font-family: none;
        font-weight: bold;
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .link-item a:hover{
        transition: 0.5s;
    }

    .link-item-hiyori{
        background: #afe39b;
        margin: 0 0 16px;
    }

    .link-item-hiyori a{
        color: #5b7f75;
    }

    .link-item-hiyori a:hover{
        background: #a0cf8e;
        transition: 0.5s;
    }

    .link-item-jun{
        background: #9bc8e3;
        margin: 0 0 16px;
    }

    .link-item-jun a{
        color: #5b6b7f;
    }

    .link-item-jun a:hover{
        background: #8ab2ca;
        transition: 0.5s;
    }
    /*
    .link-item-ibara{
        background: #9bc8e3;
        margin: 0 0 16px;
    }

    .link-item-ibara a{
        color: #5b6b7f;
    }

    .link-item-ibara a:hover{
        background: #8ab2ca;
        transition: 0.5s;
    }*/

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

.credit a{
    color: inherit;
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

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


.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 100vh;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9999;
}

.overlay-box {
    width: 320px;
    background: #474948d6;
    color: #ffffff;
    border-radius: 20px;
    padding: 24px;
    text-align: center;
    animation: popup .35s;
    box-shadow: 0 15px 40px rgba(0, 0, 0, .25);
    margin: 40px auto;
}


.hidden{
    display:none;
}

/* ボタンのレイアウト（お好みで調整） */
.button-group {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 15px;
}

.overlay-box h2{

    font-size:32px;

    margin-bottom:15px;

    color:#ff911c;

}

.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:#fb8000;

    color:white;

    font-size:18px;

    cursor:pointer;

}

#overlay-button:hover{

    background:#c56804;

}

@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);

    }
    
    #restart-btn{

        font-size:20px;

    }

}

.slide {
    animation: slide 0.2s ease-out;
}

/* =========================
   パネル移動
   ========================= */

@keyframes tile-slide {

    from {
        transform: scale(0.95);
        opacity: 0.8;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }

}
/* =========================
   音声ボタン
   ========================= */

button#sound-btn {
    color: #7d4638;
    width: 120px;
    height: 42px;
    border-radius: 3px;
    background: #fff8f2;
    margin: 18px 0 18px auto;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid #c1b9b8;
    font-weight: bold;
}