/* ==========================================================================
   기본 스타일 초기화 및 전역 설정
   ========================================================================== */
   :root {
    --header-height: 60px;
    --footer-height: 35px;
    --spacing: 20px;
    --page-padding: 20px;
    --primary-color: #4e648c;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    /* 100vh에서 100%로 변경 */
    overflow: hidden;
}

body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

/* ==========================================================================
   타이틀 섹션 스타일 (메인 페이지)
   ========================================================================== */
.title-section {
    background-color: var(--primary-color);
    padding: var(--spacing);
    display: flex;
    align-items: center;
    gap: 20px;
}

.title-section .logo {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 10px;
}

.title-section h1 {
    font-size: 28px;
    color: white;
    margin: 0;
}

/* ==========================================================================
   메인 컨테이너 스타일 (메인 페이지)
   ========================================================================== */
.container {
    flex: 1;
    width: 100%;
    box-sizing: border-box;
    padding: 0 var(--spacing);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    height: calc(100vh - var(--header-height) - var(--footer-height) - var(--spacing));
}

/* ==========================================================================
   게임 갤러리 스타일
   ========================================================================== */
.game-gallery {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    padding: 15px;
    width: 100%;
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}

.game-item {
    background-color: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
    text-decoration: none;
    color: var(--primary-color);
    display: flex;
    flex-direction: column;
    aspect-ratio: 1 / 1;
}

.game-item:hover {
    transform: translateY(-5px);
}

.game-image-container {
    height: 75%;
    overflow: hidden;
}

.game-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.game-title {
    height: 25%;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background-color: white;
}

.game-title h3 {
    margin: 0;
    font-size: 14px;
    color: var(--primary-color);
}

/* ==========================================================================
   게임 페이지 레이아웃
   ========================================================================== */
.game-page {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: #f0f0f0;
    overflow: hidden;
}

/* 게임 페이지 헤더 */
.game-page header {
    flex: 0 0 var(--header-height);
    width: 100%;
    background-color: var(--primary-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 var(--page-padding);
    box-sizing: border-box;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.game-page header h1 {
    margin: 0;
    font-size: 24px;
    color: white;
    font-weight: bold;
}

/* 뒤로가기 링크 */
.game-page .back-link {
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 5px;
    background-color: rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
    font-size: 14px;
}

.game-page .back-link:hover {
    background-color: rgba(255, 255, 255, 0.2);
    text-decoration: none;
}

/* 게임 영역 */
.game-page main {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--spacing);
    min-height: 0;
    overflow: hidden;
}

#gameContainer {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#gameContainer canvas {
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 4/3;
    background-color: #000000;
}

/* ==========================================================================
   푸터 스타일
   ========================================================================== */
footer {
    width: 100%;
    height: var(--footer-height);
    background-color: var(--primary-color);
    display: flex;
    justify-content: center;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1);
}

.game-page footer {
    flex: 0 0 var(--footer-height);
}

footer p {
    margin: 0;
    line-height: var(--footer-height);
    text-align: center;
}

/* 저작권 링크 스타일 */
.copyright-link {
    color: white;
    text-decoration: none;
    font-size: 12px;
    transition: all 0.3s ease;
}

.copyright-link:hover {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
}

/* ==========================================================================
   4:3 비율 유지를 위한 반응형 조정
   ========================================================================== */
@media (min-aspect-ratio: 4/3) {
    #gameContainer canvas {
        height: calc(100vh - var(--header-height) - var(--footer-height) - (var(--spacing) * 2));
        width: calc((100vh - var(--header-height) - var(--footer-height) - (var(--spacing) * 2)) * 4/3);
    }
}

@media (max-aspect-ratio: 4/3) {
    #gameContainer canvas {
        width: calc(100vw - (var(--spacing) * 2));
        height: calc((100vw - (var(--spacing) * 2)) * 3/4);
        max-height: calc(100vh - var(--header-height) - var(--footer-height) - (var(--spacing) * 2));
    }
}

/* ==========================================================================
   반응형 디자인
   ========================================================================== */
@media (max-width: 900px) {
    .title-section .logo {
        width: 60px;
        height: 60px;
    }

    .title-section h1 {
        font-size: 24px;
    }

    .game-gallery {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }

    .game-page header h1 {
        font-size: 20px;
    }

    .game-page .back-link {
        font-size: 13px;
        padding: 6px 12px;
    }
}

@media (max-width: 600px) {
    .title-section {
        padding: 15px;
        gap: 15px;
    }

    .title-section .logo {
        width: 50px;
        height: 50px;
    }

    .title-section h1 {
        font-size: 20px;
    }

    .game-gallery {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
    }

    .game-page header h1 {
        font-size: 18px;
    }

    .game-page .back-link {
        font-size: 12px;
        padding: 5px 10px;
    }
}

@media (min-width: 768px) {
    .game-gallery {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1024px) {
    .game-gallery {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ==========================================================================
   iOS Safari 높이 버그 수정
   ========================================================================== */
@supports (-webkit-touch-callout: none) {
    .game-page {
        height: -webkit-fill-available;
    }
}