/* =========================
퍼즐게임
========================= */

.puzzle-game-wrap {
    --tile-w: 140px;
    --tile-h: 140px;

    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 730px;
    margin: 0 auto 40px;
    padding: 20px;
    background-color: #f5f5f5;
    font-family: sans-serif;
    box-sizing: border-box;
}

.puzzle-game-wrap * {
    box-sizing: border-box;
}

.puzzle-game-wrap h1 {
    margin: 20px 0 0;
    font-size: 32px;
    text-align: center;
}

.puzzle-game-wrap p {
    margin: 15px 0;
    font-size: 18px;
    line-height: 1.4;
    color: #555;
}


/* =========================
게임 영역
========================= */

.puzzle-game-wrap .game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    width: 100%;
}


/* =========================
보드 / 퍼즐 조각 영역
========================= */

.puzzle-game-wrap .board,
.puzzle-game-wrap .pieces-area {
    display: grid;

    grid-template-columns:
        repeat(4, var(--tile-w));

    grid-template-rows:
        repeat(2, var(--tile-h));
}


/* 완성 보드 */
.puzzle-game-wrap .board {
    border: 2px solid #333;
    background: #fff;
}


/* 퍼즐 조각 대기 영역 */
.puzzle-game-wrap .pieces-area {
    gap: 10px;
    padding: 15px;

    background: #e9ecef;
    border-radius: 12px;
}


/* =========================
슬롯
========================= */

.puzzle-game-wrap .slot,
.puzzle-game-wrap .piece-holder {
    width: var(--tile-w);
    height: var(--tile-h);
}


/*
보드 내부선

모든 칸에 border를 주면
맞닿는 부분이 2px처럼 보이기 때문에

오른쪽 / 아래쪽에만 1px 지정
*/
.puzzle-game-wrap .board .slot {
    border: 0;

    border-right: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
}


/* 마지막 열 오른쪽 선 제거 */
.puzzle-game-wrap .board .slot:nth-child(4n) {
    border-right: 0;
}


/* 마지막 행 아래 선 제거 */
.puzzle-game-wrap .board .slot:nth-child(n + 5) {
    border-bottom: 0;
}


/* 대기 중 퍼즐 칸 */
.puzzle-game-wrap .piece-holder {
    border: 1px solid #ddd;
}


/* =========================
실제 퍼즐 이미지 조각
========================= */

.puzzle-game-wrap .tile {
    width: 100%;
    height: 100%;

    background-repeat: no-repeat;

    cursor: grab;

    touch-action: none;

    user-select: none;
    -webkit-user-select: none;

    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;

    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}


/* 드래그 중 */
.puzzle-game-wrap .tile.dragging {
    position: fixed !important;

    z-index: 10000 !important;

    pointer-events: none;

    opacity: 0.96;

    box-shadow:
        5px 5px 15px rgba(0, 0, 0, 0.3);

    will-change:
        transform,
        left,
        top;
}


/* 보드에 들어간 조각 */
.puzzle-game-wrap .tile.fixed {
    cursor: default;
    border: none;
}


/* =========================
새로고침 버튼
========================= */

.puzzle-game-wrap #main-restart {
    margin-top: 30px;

    padding: 10px 25px;

    background: #333;
    color: #fff;

    border: none;
    border-radius: 5px;

    cursor: pointer;
}


/* =========================
완성 모달
========================= */

.puzzle-game-wrap #win-modal {
    display: none;

    position: fixed;
    inset: 0;

    z-index: 99999;

    align-items: center;
    justify-content: center;

    background:
        rgba(0, 0, 0, 0.7);
}


.puzzle-game-wrap .modal-content {
    position: relative;

    width: 90%;
    max-width: 320px;

    padding: 30px;

    background: #fff;

    border-radius: 15px;

    text-align: center;
}


.puzzle-game-wrap .modal-close {
    position: absolute;

    top: 10px;
    right: 10px;

    width: 32px;
    height: 32px;

    padding: 0;

    border: none;
    border-radius: 50%;

    background: #fff;
    color: #000;

    font-size: 22px;
    line-height: 1;
    font-weight: 700;

    display: flex;
    align-items: center;
    justify-content: center;

    cursor: pointer;

    box-shadow:
        0 2px 6px rgba(0, 0, 0, 0.2);
}


.puzzle-game-wrap .modal-close:hover {
    background: #f1f1f1;
}


.puzzle-game-wrap .btn-group {
    display: flex;
    flex-direction: column;

    gap: 10px;

    margin-top: 20px;

    align-items: center;
}


.puzzle-game-wrap .modal-btn {
    width: 100%;
    max-width: 220px;

    padding: 12px;

    border-radius: 8px;

    font-weight: bold;
    text-decoration: none;

    display: inline-block;

    text-align: center;
}


.puzzle-game-wrap .go-link {
    background: #2ecc71;
    color: #fff;
}


.puzzle-game-wrap .restart {
    background: #34495e;
    color: #fff;

    border: none;

    cursor: pointer;
}


/* =========================
모바일
========================= */

@media (max-width: 600px) {

    .puzzle-game-wrap {
        padding: 20px 10px;
    }

    .puzzle-game-wrap h1 {
        font-size: 24px;
    }

    .puzzle-game-wrap p {
        font-size: 15px;
    }

    .puzzle-game-wrap .pieces-area {
        gap: 5px;
        padding: 10px;
    }

    .puzzle-game-wrap .modal-content {
        padding: 26px 20px 20px;
    }

    .puzzle-game-wrap .modal-close {
        top: 8px;
        right: 8px;

        width: 30px;
        height: 30px;

        font-size: 20px;
    }
}