/* CSS 변수 정의 */
:root {
    --primary-color: #667eea;
    --primary-hover: #5a67d8;
    --secondary-color: #764ba2;
    --secondary-hover: #6b46c1;
    --accent-color: #f093fb;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #23233b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 24px rgba(102,126,234,0.10);
    --shadow-lg: 0 8px 32px rgba(102,126,234,0.15);
    --radius: 12px;
    --radius-lg: 18px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, var(--background) 0%, #e0e7ef 100%);
    color: var(--text-primary);
    min-height: 100vh;
    position: fixed;
    width: 100%;
    height: 100%;
    touch-action: manipulation;
    overflow: hidden;
}

.container {
    height: 100vh;
    overflow-y: auto;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 400px;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.game-header h1 {
    font-size: 2.5rem;
    font-weight: 900;
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color), var(--accent-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0;
}

.score-box {
    background: var(--surface);
    color: var(--secondary-color);
    border-radius: var(--radius);
    padding: 0.5rem 1.2rem;
    font-weight: 700;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 1.1rem;
    min-width: 80px;
}

.menu-btn {
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 0.5rem 1.2rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.menu-btn:hover {
    background: var(--secondary-hover);
    transform: translateY(-1px);
}

.game-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    width: 100%;
    max-width: 400px;
    min-height: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.game-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: repeat(4, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1;
    background: #bbada0;
    border-radius: var(--radius);
    padding: 8px;
}

.game-cell {
    background: #cdc1b4;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.2rem, 4vw, 2rem);
    font-weight: bold;
    color: #776e65;
    transition: all 0.15s ease-in-out;
    user-select: none;
}

.game-cell.tile-2 { background: #eee4da; color: #776e65; }
.game-cell.tile-4 { background: #ede0c8; color: #776e65; }
.game-cell.tile-8 { background: #f2b179; color: #f9f6f2; }
.game-cell.tile-16 { background: #f59563; color: #f9f6f2; }
.game-cell.tile-32 { background: #f67c5f; color: #f9f6f2; }
.game-cell.tile-64 { background: #f65e3b; color: #f9f6f2; }
.game-cell.tile-128 { background: #edcf72; color: #f9f6f2; }
.game-cell.tile-256 { background: #edcc61; color: #f9f6f2; }
.game-cell.tile-512 { background: #edc850; color: #f9f6f2; }
.game-cell.tile-1024 { background: #edc53f; color: #f9f6f2; font-size: clamp(1rem, 3.5vw, 1.6rem); }
.game-cell.tile-2048 { background: #edc22e; color: #f9f6f2; font-size: clamp(1rem, 3.5vw, 1.6rem); }

.game-actions {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.game-actions button {
    background: linear-gradient(45deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 0.7rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.game-actions button:hover {
    background: var(--accent-color);
    transform: translateY(-1px);
}

/* 모바일 컨트롤 */
.mobile-controls {
    display: none;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
    width: 100%;
    max-width: 300px;
}

.control-info {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.swipe-area {
    background: var(--surface);
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 1rem;
    text-align: center;
    touch-action: none;
    user-select: none;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(30, 30, 40, 0.8);
    backdrop-filter: blur(10px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    color: var(--text-primary);
    border-radius: var(--radius-lg);
    padding: 2rem 2.5rem;
    box-shadow: var(--shadow-lg);
    text-align: center;
    min-width: 260px;
    max-width: 90vw;
}

.modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.modal-content p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

#modalClose {
    margin-top: 1rem;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    padding: 0.6rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#modalClose:hover {
    background: var(--secondary-hover);
    transform: translateY(-1px);
}

/* 반응형 디자인 */
@media (max-width: 768px) {
    .container {
        padding: 1rem 0.5rem;
    }

    .game-header {
        max-width: 100%;
        margin-bottom: 1rem;
    }

    .game-header h1 {
        font-size: 2rem;
    }

    .game-container {
        max-width: 100%;
        padding: 1rem;
        min-height: auto;
    }

    .game-grid {
        max-width: 280px;
        gap: 6px;
        padding: 6px;
    }

    .mobile-controls {
        display: flex;
    }

    .game-actions {
        gap: 0.5rem;
    }

    .game-actions button {
        padding: 0.6rem 1rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .game-header h1 {
        font-size: 1.8rem;
    }

    .score-box {
        padding: 0.4rem 0.8rem;
        font-size: 1rem;
        min-width: 70px;
    }

    .menu-btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.9rem;
    }

    .game-grid {
        max-width: 260px;
        gap: 4px;
        padding: 4px;
    }

    .game-cell {
        font-size: clamp(1rem, 3.5vw, 1.6rem);
    }

    .game-cell.tile-1024,
    .game-cell.tile-2048 {
        font-size: clamp(0.8rem, 3vw, 1.2rem);
    }

    .modal-content {
        padding: 1.5rem 1rem;
        min-width: 0;
    }
}

/* 애니메이션 */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.game-cell:not(:empty) {
    animation: slideIn 0.2s ease-in-out;
}

/* 접근성 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 포커스 스타일 */
button:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}