/* 기본 스타일 */
body {
    margin: 0;
    padding: 0;
    background-color: #f0f0f0;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-family: Arial, sans-serif;
    height: 100vh; /* 전체 높이를 채우도록 설정 */
    box-sizing: border-box;
}

.toolbar, .difficulty-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 90%;
    max-width: 1200px;
    padding: 10px;
    background-color: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-top: 20px;
    border-radius: 8px;
    flex-wrap: wrap;
}

.toolbar {
    margin-bottom: 10px;
}

.difficulty-toolbar {
    margin-bottom: 20px;
}

.tools, .colors, .actions, .thickness, .stamp-size {
    display: flex;
    align-items: center;
    margin: 5px 0;
}

/* 도구 버튼 스타일링 */
.tool-button {
    width: 50px; /* 버튼의 고정 너비 */
    height: 50px; /* 버튼의 고정 높이 */
    padding: 5px; /* 버튼 내부 패딩 조정 */
    margin-right: 5px; /* 버튼 사이의 마진 조정 */
    border: none;
    background-color: #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s;
}

.tool-button:hover {
    background-color: #d5d5d5; /* 호버 시 배경색 변경 */
}

.tool-button.active {
    background-color: #4CAF50; /* 활성화된 버튼의 배경색 */
}

.tool-button img {
    width: 24px; /* 아이콘의 너비 조정 */
    height: 24px; /* 아이콘의 높이 조정 */
    object-fit: contain; /* 아이콘의 비율 유지 */
}

.tool-button.active img {
    filter: brightness(0) invert(1); /* 아이콘 색상 반전 */
}

#colorPicker {
    padding: 5px;
    border: none;
    cursor: pointer;
    flex: 1 1 auto;
}

.thickness label, .stamp-size label {
    margin-right: 10px;
    font-size: 14px;
}

#thicknessRange, #stampSizeRange {
    width: 100px;
    margin-right: 10px;
}

#thicknessValue, #stampSizeValue {
    font-weight: bold;
}

.actions button, .difficulty-toolbar button, .difficulty-toolbar select {
    padding: 10px 15px;
    margin-left: 10px;
    border: none;
    background-color: #ff6666;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    flex: 1 1 auto;
    text-align: center;
}

.actions button#save, .difficulty-toolbar button#prevDesign, .difficulty-toolbar button#nextDesign, .actions button#undo, .actions button#redo {
    background-color: #4CAF50;
}

.difficulty-toolbar label {
    margin-right: 10px;
    font-size: 16px;
}

/* 캔버스 컨테이너 스타일링 */
.canvas-container {
    position: relative;
    width: 90%;
    max-width: 800px;
    /* 비율 유지 (4:3) */
    padding-top: 75%; /* 600 / 800 = 0.75 -> 75% */
    background-color: #ffffff;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
    overflow: hidden;
}

/* 기존 캔버스 스타일 */
#backgroundCanvas, #drawingCanvas, #stampCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none; /* 기본 터치 동작 비활성화 */
}

#backgroundCanvas {
    z-index: 0;
}

#drawingCanvas {
    z-index: 1;
    cursor: crosshair; /* 기본 커서를 크로스헤어로 설정 */
}

#stampCanvas {
    z-index: 2; /* 도장 캔버스 최상위 레이어 */
    pointer-events: none; /* 도장 캔버스에서 마우스 이벤트 무시 */
}

/* 도장 팔레트 스타일 */
#stampPalette {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#stampPalette button {
    margin: 5px 0;
    border: none;
    background: transparent;
    cursor: pointer;
}

#stampPalette button img {
    width: 50px;
    height: 50px;
    object-fit: contain;
}

/* Undo/Redo 버튼 스타일링 */
.actions button#undo, .actions button#redo {
    background-color: #2196F3;
}

/* 닫기 버튼 스타일링 */
#stampPalette button.close-button {
    background-color: #ff6666;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
}

/* 반응형 디자인 */

/* 모바일 세로 화면 */
@media (max-width: 600px) and (orientation: portrait) {
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .difficulty-toolbar {
        flex-direction: row; /* 컬럼에서 로우로 변경 */
        justify-content: space-between; /* 요소들 사이에 공간 분배 */
        align-items: center; /* 요소들을 수직 가운데 정렬 */
    }

    .difficulty-toolbar select {
        flex: 1; /* 셀렉트 박스가 가능한 공간을 차지하도록 설정 */
        margin-right: 10px; /* 셀렉트 박스와 버튼 사이에 여백 추가 */
    }

    .difficulty-toolbar button {
        flex: none; /* 버튼의 크기를 고정 */
        margin-left: 5px; /* 버튼 사이에 여백 추가 */
    }

    .tools, .colors, .actions, .thickness, .stamp-size {
        justify-content: center;
    }

    .tool-button, .actions button, .difficulty-toolbar button, .difficulty-toolbar select, #colorPicker, #thicknessRange, #stampSizeRange {
        width: 20%;
        margin-left: 5px;
    }

    #thicknessRange, #stampSizeRange {
        width: 100%;
    }

    #thicknessValue, #stampSizeValue {
        display: none; /* 작은 화면에서는 두께 값을 숨김 */
    }

    /* 모바일에서 버튼 크기 증가 */
    .tool-button {
        width: 60px;
        height: 60px;
    }

    .tool-button img {
        width: 28px;
        height: 28px;
    }

    /* 캔버스 컨테이너 비율 조정 */
    .canvas-container {
        padding-top: 75%; /* 4:3 비율 유지 */
    }
}

/* 모바일 가로 화면 */
@media (max-width: 800px) and (orientation: landscape) {
    
    .toolbar, .difficulty-toolbar {
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .tools, .colors, .actions, .thickness, .stamp-size {
        flex: 1 1 100%;
        justify-content: center;
    }

    .tool-button, .actions button, .difficulty-toolbar button, .difficulty-toolbar select, #colorPicker, #thicknessRange, #stampSizeRange {
        flex: 1 1 auto;
        margin: 5px;
    }

    #thicknessValue, #stampSizeValue {
        display: inline; /* 두께 값을 표시 */
    }

    /* 모바일 가로에서도 버튼 크기 증가 */
    .tool-button {
        width: 60px;
        height: 60px;
    }

    .tool-button img {
        width: 28px;
        height: 28px;
    }

    /* 캔버스 컨테이너 비율 조정 */
    .canvas-container {
        padding-top: 75%; /* 4:3 비율 유지 */
    }
}

/* 태블릿 세로 화면 */
@media (min-width: 601px) and (max-width: 1024px) and (orientation: portrait) {
    .toolbar, .difficulty-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .tools, .colors, .actions, .thickness, .stamp-size {
        justify-content: center;
    }

    .tool-button, .actions button, .difficulty-toolbar button, .difficulty-toolbar select, #colorPicker, #thicknessRange, #stampSizeRange {
        width: 100%;
        margin: 5px 0;
    }

    #thicknessRange, #stampSizeRange {
        width: 100%;
    }

    #thicknessValue, #stampSizeValue {
        display: none;
    }

    /* 캔버스 컨테이너 비율 조정 */
    .canvas-container {
        padding-top: 75%; /* 4:3 비율 유지 */
    }
}

/* 태블릿 가로 화면 */
@media (min-width: 601px) and (max-width: 1024px) and (orientation: landscape) {
    .toolbar, .difficulty-toolbar {
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .tools, .colors, .actions, .thickness, .stamp-size {
        flex: 1 1 100%;
        justify-content: center;
    }

    .tool-button, .actions button, .difficulty-toolbar button, .difficulty-toolbar select, #colorPicker, #thicknessRange, #stampSizeRange {
        flex: 1 1 auto;
        margin: 5px;
    }

    #thicknessValue, #stampSizeValue {
        display: inline;
    }

    /* 캔버스 컨테이너 비율 조정 */
    .canvas-container {
        padding-top: 75%; /* 4:3 비율 유지 */
    }
}

/* 데스크탑 이상 */
@media (min-width: 1025px) {
    .toolbar, .difficulty-toolbar {
        flex-direction: row;
        flex-wrap: nowrap;
    }

    .tools, .colors, .actions, .thickness, .stamp-size {
        flex: 1 1 auto;
        justify-content: center;
    }

    .tool-button, .actions button, .difficulty-toolbar button, .difficulty-toolbar select, #colorPicker, #thicknessRange, #stampSizeRange {
        flex: 1 1 auto;
        margin: 0 5px;
    }

    #thicknessValue, #stampSizeValue {
        display: inline;
    }

    .canvas-container {
        width: 800px;
        height: 600px;
        padding-top: 0; /* 고정 높이 사용 */
    }

    #backgroundCanvas, #drawingCanvas {
        width: 100%;
        height: 100%;
    }

    canvas {
        height: 600px; /* 고정 높이 유지 */
    }
}

/* 애니메이션 추가 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
