/* 게임 컨테이너 - 기본 숨김 */
#game-container {
    display: none;
    /* 초기에는 완전히 숨김 */
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #ffeef8 0%, #e3f2fd 100%);
    border: 3px solid #ffb3d9;
    border-radius: 12px;
    margin: 20px 0;
    box-shadow: 0 4px 12px rgba(255, 158, 205, 0.3);
}

#game-container.active {
    display: flex;
    /* 활성화 시 표시 */
    animation: slideDown 0.5s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 게임 헤더 */
.game-header {
    text-align: center;
    margin-bottom: 20px;
    color: #d81b60;
}

.game-title {
    font-size: 1.5rem;
    margin-bottom: 5px;
    text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.5);
    color: #ff9ecd;
}

.game-header p {
    color: #666;
}

/* 게임 보드 */
.game-board {
    position: relative;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.6);
    padding: 15px;
    border: 3px solid #ffb3d9;
    border-radius: 12px;
    margin-bottom: 20px;
}

/* 타일 */
.tile {
    position: relative;
    aspect-ratio: 1;
    background: linear-gradient(135deg, #fff5f8 0%, #ffe8f0 100%);
    border: 2px solid #ffc4dd;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: bold;
    transition: all 0.2s;
    color: #ff9ecd;
    min-width: 0;
    /* Grid item shrinking fix */
    overflow: hidden;
    /* Prevent content overflow */
}

.tile:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(255, 158, 205, 0.4);
}

.tile.goal {
    background: linear-gradient(135deg, #ffd6e8 0%, #ffb3d9 100%);
    color: #d81b60;
    font-weight: bold;
}

.tile-content {
    text-align: center;
}

/* 플레이어 토큰 */
.player-token {
    position: absolute;
    width: 35px;
    height: 35px;
    background: radial-gradient(circle, #ff9ecd 0%, #ff6b9d 100%);
    border: 3px solid #fff;
    border-radius: 50%;
    transition: all 0.3s ease;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(255, 107, 157, 0.5);
}

.player-token::after {
    content: '💕';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.3rem;
}

/* 게임 컨트롤 */
.game-controls {
    text-align: center;
    color: #666;
}

.dice-area {
    width: 90px;
    height: 90px;
    background: linear-gradient(135deg, #ffffff 0%, #fff5f8 100%);
    border: 3px solid #ffb3d9;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3.5rem;
    cursor: pointer;
    margin: 0 auto 15px;
    transition: all 0.2s;
    box-shadow: 0 4px 8px rgba(255, 158, 205, 0.3);
}

.dice-area:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 12px rgba(255, 158, 205, 0.4);
}

.dice-area:active {
    transform: scale(0.95);
}

.dice-area.rolling {
    animation: shake 0.5s infinite;
}

@keyframes shake {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-15deg);
    }

    75% {
        transform: rotate(15deg);
    }
}

#game-status {
    font-size: 1rem;
    margin: 10px 0;
    color: #ff9ecd;
    font-weight: bold;
}

/* 스토리 모달 */
.story-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.story-modal.active {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.story-modal-content {
    background: linear-gradient(135deg, #ffeef8 0%, #fff5f8 100%);
    border: 4px solid #ffb3d9;
    border-radius: 16px;
    padding: 30px 25px;
    text-align: center;
    box-shadow: 0 8px 24px rgba(255, 158, 205, 0.4);
    max-width: 90%;
    width: 400px;
    animation: popIn 0.3s ease-out;
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

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

.story-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    background: linear-gradient(135deg, #fff 0%, #ffe8f0 100%);
    border: 3px solid #ffc4dd;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    position: relative;
    overflow: hidden;
}

.story-icon::before {
    content: '';
    width: 50px;
    height: 50px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    image-rendering: pixelated;
}

/* 기본 아이콘 */
.story-icon::before {
    background-image: url('assets/icon-ring.png');
}

/* 각 스토리별 아이콘 */
.story-icon.icon-book::before {
    background-image: url('assets/icon-book.png');
}

.story-icon.icon-pen::before {
    background-image: url('assets/icon-pen.png');
}

.story-icon.icon-heart::before {
    background-image: url('assets/icon-heart.png');
}

.story-icon.icon-sticker::before {
    background-image: url('assets/icon-sticker.png');
}

.story-icon.icon-chess::before {
    background-image: url('assets/icon-chess.png');
}

.story-icon.icon-ring::before {
    background-image: url('assets/icon-ring.png');
}

.story-icon.icon-flower::before {
    background-image: url('assets/icon-flower.png');
}

.story-title {
    font-size: 1.3rem;
    font-weight: bold;
    color: #d81b60;
    margin-bottom: 15px;
}

.story-text {
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 20px;
    color: #333;
    white-space: pre-line;
    word-break: keep-all;
}

/* 반응형 */
@media (max-width: 480px) {
    .game-board {
        max-width: 320px;
        gap: 6px;
        padding: 10px;
    }

    .tile {
        font-size: 0.8rem;
    }

    .player-token {
        width: 28px;
        height: 28px;
    }

    .player-token::after {
        font-size: 1.1rem;
    }

    .dice-area {
        width: 75px;
        height: 75px;
        font-size: 3rem;
    }

    .story-modal-content {
        width: 90%;
        padding: 25px 20px;
    }
}


/* 완료된 타일 아이콘 */
.tile-icon {
    width: 80%;
    height: 80%;
    object-fit: contain;
    image-rendering: pixelated;
    animation: popIn 0.3s ease-out;
    max-width: 100%;
    /* Safety */
    max-height: 100%;
    /* Safety */
}

.tile.completed {
    background: linear-gradient(135deg, #fff 0%, #ffeef8 100%);
    border-color: #ff9ecd;
}

/* Scroll to Top Button */
#scroll-top-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999;
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: 1.2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s, transform 0.2s;
    pointer-events: none;
    /* Hidden state */
}

#scroll-top-btn.visible {
    opacity: 1;
    pointer-events: auto;
    cursor: pointer;
}

/* 스크롤 중에는 투명하게 */
#scroll-top-btn.visible.scrolling {
    opacity: 0.3;
}

#scroll-top-btn:active {
    transform: scale(0.95);
}

/* Daily Theme */
.story-modal-content.daily-theme {
    background: linear-gradient(135deg, #f3faff 0%, #e3f2fd 100%);
    border: 4px solid #90caf9;
    box-shadow: 0 8px 24px rgba(144, 202, 249, 0.4);
}

.daily-theme .story-title {
    color: #0288d1;
}

.daily-theme .story-icon {
    background: linear-gradient(135deg, #fff 0%, #e1f5fe 100%);
    border: 3px solid #b3e5fc;
}

/* Daily Icons */
.story-icon.icon-diary::before {
    background-image: url('assets/icon-diary.png');
}

.story-icon.icon-card::before {
    background-image: url('assets/icon-card.png');
}

/* 게임 컨트롤 버튼 레이아웃 */
.control-buttons {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin: 0 auto 15px;
}

/* 오토플레이 / 스킵 버튼 */
.game-control-btn {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #ffffff 0%, #fff5f8 100%);
    border: 3px solid #ffb3d9;
    border-radius: 10px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 6px rgba(255, 158, 205, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.game-control-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(255, 158, 205, 0.4);
}

.game-control-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(255, 158, 205, 0.3);
}

/* 오토플레이 활성화 상태 */
#auto-play-btn.active {
    background: linear-gradient(135deg, #ffd6e8 0%, #ffb3d9 100%);
    border-color: #ff9ecd;
    animation: pulse-auto 1s ease-in-out infinite;
}

@keyframes pulse-auto {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

/* 반응형 */
@media (max-width: 480px) {
    .control-buttons {
        gap: 10px;
    }

    .game-control-btn {
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }
}