/* Papa Drawing - Global Variables */
:root {
    --primary-color: #00A3FF;
    --secondary-color: #00D26A;
    --bg-color: #f8fbff;
    --ui-bg: #ffffff;
    --text-color: #333333;
    --border-color: #e2e8f0;
}

/* Reset & Typography */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

input, textarea {
    -webkit-user-select: auto;
    user-select: auto;
}

body, html {
    width: 100%;
    height: 100%;
    font-family: 'Fredoka', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden; /* 터치 스크롤 및 당겨서 새로고침 방지 */
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* 상단 헤더 영역 */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background-color: var(--ui-bg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    z-index: 10;
}

.logo {
    flex: 1;
    display: flex;
    justify-content: flex-start;
}

.logo-text {
    font-size: 28px;
    font-weight: 700;
    color: #FF4B4B;
}

.search-container {
    display: flex;
    flex: 2;
    justify-content: center;
    align-items: center;
    max-width: 600px;
    margin: 0 20px;
    gap: 10px;
}

.search-btn-group {
    display: flex;
    gap: 10px;
}

#searchInput {
    flex: 1;
    padding: 10px 16px;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

#searchInput:focus {
    border-color: var(--primary-color);
}

.bubbly-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 20px;
    font-size: 16px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
    white-space: nowrap;
    min-width: 105px;
}

.bubbly-btn:active {
    transform: scale(0.95);
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
}
.primary-btn:hover { background-color: #008be5; }

.secondary-btn {
    background-color: var(--secondary-color);
    color: white;
}
.secondary-btn:hover { background-color: #00b85c; }

.bubbly-btn:disabled {
    background-color: #cbd5e1;
    cursor: not-allowed;
    transform: none;
}

#micBtn {
    min-width: 46px !important;
}

/* 마이크 애니메이션 */
#micBtn.recording {
    background-color: #FF4B4B !important;
    animation: magicPulse 1.5s infinite;
}

@keyframes magicPulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 75, 75, 0.7); }
    70% { box-shadow: 0 0 0 15px rgba(255, 75, 75, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 75, 75, 0); }
}

/* 중앙 캔버스 영역 */
.canvas-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.canvas-container {
    width: 100%;
    height: 100%;
    background-color: white;
    border-radius: 24px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    will-change: transform;
}

.canvas-action-buttons {
    position: absolute;
    top: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10;
}

/* 액션 버튼 공통 */

.action-icon-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.1s, background-color 0.2s;
}

.action-icon-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}
.action-icon-btn:active {
    transform: scale(0.95);
}
.action-icon-btn:disabled {
    background-color: #cbd5e1 !important;
    cursor: not-allowed;
    transform: none;
}

.canvas-history-buttons {
    position: absolute;
    top: 30px;
    left: 30px;
    display: flex;
    flex-direction: row;
    gap: 8px;
    z-index: 10;
}

#drawingCanvas, #tempCanvas, #outlineCanvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: crosshair;
}

/* 하단 툴바 영역 - 플로팅 UI로 변경 */
.bottom-toolbar {
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    bottom: 40px;
    left: 0;
    width: 100%;
    pointer-events: none; /* 캔버스 터치 방해 금지 */
    z-index: 100;
    background: transparent;
    box-shadow: none;
}

.toolbar-content {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 0 20px;
    pointer-events: auto; /* 버튼들은 클릭 가능하게 */
}

.tools-group, .size-group, .colors-group, .opacity-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 600px;
}

/* 툴 설정 팝업 스타일 */
.tool-settings-popup {
    position: absolute;
    bottom: calc(100% + 15px);
    left: 50%; /* JS에서 툴바 버튼 위치로 자동 계산 */
    transform: translateX(-50%);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    padding: 20px;
    z-index: 1000;
    border: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 320px; /* 굵기 버튼이 줄바꿈되지 않게 크기 확장 */
    pointer-events: auto;
}
.tool-settings-popup::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 10px 10px 0;
    border-style: solid;
    border-color: #fff transparent transparent transparent;
}
.tool-settings-popup::before {
    content: '';
    position: absolute;
    bottom: -13px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 12px 12px 0;
    border-style: solid;
    border-color: var(--border-color) transparent transparent transparent;
}
.size-tools-list {
    flex-wrap: wrap;
    justify-content: center;
}

.popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}
.close-popup-btn {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    line-height: 1;
    color: #94a3b8;
}
.close-popup-btn:hover { color: #ff4b4b; }

.popup-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.popup-btn {
    width: 44px;
    height: 44px;
}

.group-title {
    font-size: 14px;
    font-weight: 600;
    color: #94a3b8;
}

.tools-list {
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    width: 100%;
    gap: 10px;
}

.color-palette {
    display: flex;
    align-items: center;
    gap: 12px;
}

.grid-palette {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    justify-items: center;
}

.tool-btn {
    width: 60px;
    height: 60px;
    border: 3px solid white;
    border-radius: 50%;
    background-color: white;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.tool-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

.tool-btn.active {
    border-color: var(--primary-color);
    background-color: #eff6ff;
    transform: scale(1.1);
}

/* 굵기 버튼 배경 및 테두리 제거 */
.size-btn {
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
}
.size-btn:hover {
    transform: scale(1.1) !important;
    box-shadow: none !important;
}
.size-btn.active {
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    transform: scale(1.2) !important;
}
.size-btn.active .size-icon {
    background-color: var(--primary-color) !important;
}

.divider {
    display: none;
}

.color-chip {
    width: 44px;
    height: 44px;
    border: 3px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.color-chip:hover {
    transform: scale(1.1);
}

.color-chip.active {
    border-color: var(--text-color);
    transform: scale(1.15);
}

/* 모바일 반응형 처리 - 유아 사용성 최적화 */
@media (max-width: 768px) {
    .top-bar {
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 6px;
        padding: 10px;
        align-items: center;
    }
    .logo {
        width: auto;
        justify-content: flex-start;
        flex: 0 0 auto;
    }
    .logo-text {
        font-size: 18px;
    }
    .header-spacer {
        display: none;
    }
    .search-container {
        width: auto;
        flex: 1;
        max-width: 100%;
        margin: 0;
        gap: 4px;
        order: unset;
        margin-top: 0;
        flex-direction: row;
    }
    #searchInput {
        width: 100%;
        min-width: 0;
        flex: 1;
        padding: 8px 10px;
        font-size: 14px;
        height: 40px;
    }
    .search-btn-group {
        display: flex;
        justify-content: flex-end;
        gap: 4px;
        width: auto;
        flex: 0 0 auto;
    }
    .search-btn-group .bubbly-btn {
        padding: 0 8px;
        height: 40px;
        font-size: 13px;
        white-space: nowrap;
        flex: 0 0 auto;
        min-width: unset;
    }
    #micBtn {
        width: 40px !important;
        height: 40px !important;
        padding: 0 !important;
        flex: 0 0 40px !important;
        min-width: 40px !important;
    }

    .bubbly-btn .icon { margin-right: 2px; }

    .canvas-wrapper {
        padding: 10px 5px;
    }
    
    .canvas-action-buttons {
        top: 15px;
        right: 15px;
        gap: 6px;
    }
    
    .action-icon-btn {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    .canvas-history-buttons {
        top: 15px;
        left: 15px;
        bottom: auto;
        transform: scale(0.9);
        transform-origin: top left;
        gap: 6px;
    }

    /* 하단 툴바 최적화 - 모바일 플로팅 유지 */
    .bottom-toolbar {
        bottom: 35px;
    }
    .toolbar-content {
        padding: 0 10px;
        gap: 8px;
        width: 100%;
        max-width: 100%;
    }
    .tools-group, .size-group, .colors-group {
        flex-shrink: 0;
        gap: 4px;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        width: 100%;
    }
    .tools-list {
        flex-wrap: nowrap; 
        justify-content: center;
        width: auto;
        gap: 6px;
    }
    
    .tool-settings-popup {
        width: 310px; /* 굵기 버튼 가로 배치 유지 */
        padding: 16px;
    }
    .grid-palette {
        grid-template-columns: repeat(5, 1fr);
        gap: 10px;
    }
    .tool-btn {
        width: 50px;
        height: 50px;
        font-size: 24px;
        border-radius: 50%;
    }
    .color-chip {
        width: 34px;
        height: 34px;
    }
    .group-title {
        font-size: 11px;
        margin-bottom: 2px;
    }
    .divider {
        display: none; 
    }
}