:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --secondary: #64748b;
    --secondary-hover: #475569;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --card-back: #1e293b;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --success: #22c55e;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent; /* 터치 시 파란 박스 제거 */
}

body {
    font-family: 'Pretendard', sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 10px;
    touch-action: manipulation; /* 핀치 줌 방지 및 터치 최적화 */
    overflow-x: hidden;
}

.game-container {
    background: white;
    width: 100%;
    max-width: 800px;
    padding: 1.5rem;
    border-radius: 20px;
    box-shadow: var(--shadow);
    text-align: center;
}

header h1 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 800;
    background: linear-gradient(to right, #6366f1, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.controls {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.select-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
}

.select-wrapper label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

select {
    padding: 0.5rem;
    border-radius: 10px;
    border: 2px solid #e2e8f0;
    font-size: 0.9rem;
    min-width: 120px;
}

button {
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
}

.primary-btn { background-color: var(--primary); color: white; }
.secondary-btn { background-color: #e2e8f0; color: var(--secondary); }

.stats-panel { margin-bottom: 1rem; }
#status-message {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--primary);
}

#timer-bar-container {
    width: 100%;
    max-width: 300px;
    height: 4px;
    background-color: #e2e8f0;
    margin: 0 auto;
    border-radius: 2px;
    overflow: hidden;
    opacity: 0;
}
#timer-bar-container.active { opacity: 1; }
#timer-bar { width: 100%; height: 100%; background-color: var(--primary); transform-origin: left; }

.game-board-wrapper {
    position: relative;
    width: 100%;
    background: #f1f5f9;
    padding: 10px;
    border-radius: 16px;
    display: flex;
    justify-content: center;
}

.grid {
    display: grid;
    gap: 8px;
    width: 100%;
    max-width: 500px; /* 모바일 기준 최대 크기 */
}

/* 난이도별 열 개수 */
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-6 { grid-template-columns: repeat(6, 1fr); }
.grid-8 { grid-template-columns: repeat(8, 1fr); }
.grid-10 { grid-template-columns: repeat(10, 1fr); }

.card {
    aspect-ratio: 1/1;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.card.flipped { transform: rotateY(180deg); }

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem; /* 기본 모바일 크기 */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* 난이도가 높아질수록 폰트 크기 줄임 */
.grid-8 .card-face { font-size: 1.1rem; }
.grid-10 .card-face { font-size: 0.9rem; }

.card-back { background-color: var(--card-back); color: white; }
.card-front { background-color: var(--card-front); transform: rotateY(180deg); border: 2px solid transparent; }
.card.matched .card-front { border-color: var(--success); background-color: #f0fdf4; }

.overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 16px;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
}
.overlay.show { opacity: 1; pointer-events: auto; }

.overlay-content {
    background: white;
    padding: 2rem;
    border-radius: 24px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
    transform: scale(0.8);
}
.overlay.show .overlay-content { transform: scale(1); }

/* 데스크탑 환경에서 크기 키우기 */
@media (min-width: 600px) {
    header h1 { font-size: 2.5rem; }
    .grid { max-width: 800px; gap: 12px; }
    .card-face { font-size: 2.5rem; border-radius: 14px; }
    .grid-8 .card-face { font-size: 1.8rem; }
    .grid-10 .card-face { font-size: 1.5rem; }
}
