@import url('https://fonts.googleapis.com/css2?family=Gaegu:wght@400;700&family=Nunito:wght@400;700&display=swap');

:root {
    --primary: #FF6B6B;
    --secondary: #4ECDC4;
    --accent: #FFD166;
    --dark: #2F4858;
    --light: #F7FFF7;
}

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

body {
    font-family: 'Gaegu', 'Nunito', sans-serif;
    background-color: #f0f9ff;
    background-image: url('https://www.transparenttextures.com/patterns/cubes.png');
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    background-color: var(--primary);
    color: white;
    text-align: center;
    padding: 12px;
    font-size: 1.8rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    z-index: 10;
}

.header h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.header img {
    width: 32px;
    height: 32px;
}

.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 15px;
    gap: 20px;
    overflow-y: auto;
    width: 100%;
    max-height: calc(100vh - 130px); /* 헤더와 푸터를 고려한 높이 */
}

.game-area {
    display: flex;
    width: 100%;
    max-width: 1200px;
    gap: 30px;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
}

.card-container {
    perspective: 1000px;
    height: 200px;
    width: 160px;
    position: relative;
    cursor: pointer;
    margin: 0 auto 15px;
}

.card {
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    position: relative;
    border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    transition: transform 0.6s;
    will-change: transform; /* 성능 최적화 */
}

.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
}

.card-front {
    background-color: var(--accent);
    color: var(--dark);
    background-image: url('https://cdn-icons-png.flaticon.com/512/1159/1159633.png');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 70%;
}

.card-back {
    background-color: var(--secondary);
    color: white;
    transform: rotateY(180deg);
    padding: 20px;
    text-align: center;
}

/* 카드가 뒤집힌 상태 */
.flipped {
    transform: rotateY(180deg);
}

/* Drawing area */
.drawing-area {
    flex: 1;
    width: 100%;
    max-width: 800px;
    position: relative;
    box-shadow: 0 6px 16px rgba(0,0,0,0.15);
    border-radius: 10px;
    background-color: white;
    display: flex;
    flex-direction: column;
    min-height: 350px; /* 최소 높이 설정 */
    max-height: 60vh; /* 뷰포트 높이의 60%로 제한 */
}

canvas {
    width: 100%;
    height: 350px;
    border-radius: 10px;
    cursor: crosshair;
    background-color: white;
    display: block;
    touch-action: none; /* 모바일에서 캔버스 스크롤 방지 */
    max-height: 50vh; /* 뷰포트 높이의 50%로 제한 */
}

/* 모바일에서 타이머 표시를 위한 추가 스타일 */
.timer-mobile-safe {
    height: 60px;
    width: 100%;
    position: relative;
    pointer-events: none; /* 클릭 이벤트 통과 */
}

/* 타이머 하이라이트 효과 추가 */
.timer.warning {
    animation: pulse 1.5s infinite alternate;
    background-color: #FF6B6B;
}

@keyframes pulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); box-shadow: 0 0 15px rgba(255, 107, 107, 0.8); }
}

.controls {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
    padding: 0 10px 10px;
}

.control-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

button {
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    background-color: var(--dark);
    color: white;
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    font-weight: bold;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem;
}

button:hover {
    background-color: var(--primary);
    transform: translateY(-2px);
}

button:active {
    transform: translateY(0);
}

button img {
    width: 18px;
    height: 18px;
}

.color-picker {
    height: 36px;
    width: 36px;
    padding: 0;
    border: 2px solid var(--dark);
    border-radius: 50%;
    overflow: hidden;
}

input[type="color"] {
    border: none;
    padding: 0;
    width: 200%;
    height: 200%;
    transform: translate(-25%, -25%);
    cursor: pointer;
}

.brush-size {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brush-size span {
    min-width: 24px;
    text-align: center;
}

/* 타이머 스타일 개선 - 모바일에서 표시 개선 */
.timer {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: var(--accent);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.3rem;
    font-weight: bold;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    color: var(--dark);
    z-index: 100; /* 다른 요소보다 상위에 표시 */
    border: 2px solid white; /* 배경과 구분을 위한 테두리 */
}

.footer {
    text-align: center;
    padding: 10px;
    background-color: var(--dark);
    color: white;
    font-size: 0.9rem;
}

.instruction {
    text-align: center;
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--dark);
    background-color: rgba(255, 255, 255, 0.8);
    padding: 10px;
    border-radius: 10px;
    max-width: 800px;
}

#checkAnswerBtn {
    background-color: var(--secondary);
}

#checkAnswerBtn:hover {
    background-color: #3DBBAF;
}

/* 브러시 도구 버튼 스타일 */
.brush-tools {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.tool-btn {
    padding: 8px 12px;
    border-radius: 5px;
    background-color: var(--dark);
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    position: relative;
    overflow: hidden;
}

.tool-btn:after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: rgba(255, 255, 255, 0.5);
    opacity: 0;
    border-radius: 100%;
    transform: scale(1, 1) translate(-50%, -50%);
    transform-origin: 50% 50%;
}

.tool-btn:focus:not(:active)::after {
    animation: ripple 1s ease-out;
}

@keyframes ripple {
    0% {
        transform: scale(0, 0);
        opacity: 0.5;
    }
    20% {
        transform: scale(25, 25);
        opacity: 0.5;
    }
    100% {
        opacity: 0;
        transform: scale(40, 40);
    }
}

.tool-btn.active {
    background-color: var(--primary);
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--primary);
    transform: translateY(-2px);
}

/* 캔버스 최적화 스타일 */
canvas {
    touch-action: none;
    will-change: transform; /* 하드웨어 가속 최적화 */
    position: relative;
    z-index: 5;
}

/* 모바일 최적화 */
@media (max-width: 768px) {

    .control-group:last-child {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
    }
    
    .control-group button {
        flex: 1 1 auto;
        min-width: 100px;
    }
    
    .header {
        font-size: 1.5rem;
        padding: 10px;
    }
    
    .header img {
        width: 28px;
        height: 28px;
    }
    
    .game-area {
        flex-direction: column;
        gap: 15px;
    }
    
    .card-container {
        margin: 0 auto 15px;
        height: 180px;
        width: 140px;
    }
    
    .card-back, .card-front {
        font-size: 1.6rem;
    }
    
    canvas {
        height: 300px;
        max-height: 45vh; /* 모바일에서는 뷰포트 높이의 45%로 조정 */
    }
    
    .controls {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    
    .control-group {
        width: 100%;
        justify-content: center;
    }
    
    .brush-size {
        width: 100%;
        justify-content: center;
    }
    
    /* 모바일에서 타이머 크기 및 위치 조정 */
    .timer {
        width: 45px;
        height: 45px;
        font-size: 1.2rem;
        top: 5px;
        right: 5px;
        z-index: 200; /* 더 높은 z-index */
    }
    
    button {
        padding: 8px 10px;
        font-size: 0.85rem;
    }
    
    .instruction {
        font-size: 1rem;
        padding: 8px;
    }
    
    .game-container {
        padding: 10px;
        max-height: calc(100vh - 110px);
    }
    
    .drawing-area {
        min-height: 300px;
        max-height: 55vh;
        position: relative; /* 타이머를 위한 위치 기준 설정 */
    }
    
    /* 모바일에서 브러시 도구 버튼 작게 조정 */
    .brush-tools .tool-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
    
    .brush-tools .tool-btn img {
        width: 16px;
        height: 16px;
    }
}

/* 초소형 화면 최적화 */
@media (max-width: 375px) {
    .header h1 {
        font-size: 1.3rem;
    }
    
    .header img {
        width: 24px;
        height: 24px;
    }
    
    canvas {
        height: 250px;
        max-height: 40vh; /* 작은 화면에서는 더 작게 조정 */
    }
    
    .controls {
        margin-top: 8px;
    }
    
    .timer {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
        top: 3px;
        right: 3px;
        border: 1px solid white;
    }
    
    .drawing-area {
        min-height: 250px;
        max-height: 50vh;
    }
    
    .game-container {
        padding: 5px;
        max-height: calc(100vh - 100px);
    }
    
    /* 작은 화면에서 브러시 도구 버튼 더 작게 */
    .brush-tools .tool-btn {
        padding: 4px 6px;
        font-size: 0.75rem;
    }
    
    .brush-tools .tool-btn img {
        width: 14px;
        height: 14px;
    }
}

/* Animation for the card */
@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
    40% {transform: translateY(-20px);}
    60% {transform: translateY(-10px);}
}

.bounce {
    animation: bounce 2s infinite;
}

/* 회전 애니메이션 지원 */
.rotating {
    transition: none !important;
}

/* 깜박임 애니메이션 추가 */
@keyframes blink {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0.7; transform: scale(1.1); }
}

/* 그림 그리기 최적화 추가 스타일 */
.drawing-area canvas {
    cursor: crosshair;
    -webkit-tap-highlight-color: transparent; /* iOS 터치 하이라이트 제거 */
}

/* 롬 방지 스타일 */
body.drawing {
    overflow: hidden;
    touch-action: none;
    -webkit-overflow-scrolling: none;
}

/* 모바일에서 그리기 활성화 후 스타일 */
.drawing-active {
    position: relative;
    z-index: 1000;
}