/* --- BIẾN MÀU SẮC & CẤU HÌNH CHUNG --- */
:root {
    --wpcb-bg-color: #ffffff;
    --wpcb-border-color: #e2e4e7;
    --wpcb-primary-color: #2271b1; /* Màu xanh chuẩn WP */
    --wpcb-text-color: #3c434a;
    --wpcb-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    --wpcb-spacing: 15px;
}

/* --- KHUNG BAO NGOÀI (WRAPPER) --- */
.coloring-app-wrapper {
    /* Reset box-sizing để padding không làm vỡ layout */
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    margin: 30px auto;
    padding: var(--wpcb-spacing);
    background: #fcfcfc;
    border: 1px solid var(--wpcb-border-color);
    border-radius: 8px;
    box-shadow: var(--wpcb-shadow);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.coloring-app-wrapper * {
    box-sizing: border-box; /* Đảm bảo mọi phần tử con đều tính toán kích thước đúng */
}

/* --- THANH CÔNG CỤ (TOOLBAR) --- */
.coloring-toolbar {
    display: flex;
    flex-direction: column;
    gap: var(--wpcb-spacing);
    margin-bottom: 20px;
    border-bottom: 1px solid var(--wpcb-border-color);
    padding-bottom: 20px;
}

/* Màn hình Tablet trở lên: Xếp ngang */
@media (min-width: 768px) {
    .coloring-toolbar {
        /* flex-direction: row; */
        align-items: flex-start;
        justify-content: space-between;
    }
    
    .palette {
        flex: 1; /* Chiếm phần lớn diện tích */
        margin-right: 20px;
        justify-content: flex-start !important;
    }

    .tools {
        flex: 0 0 auto; /* Không co giãn, giữ kích thước vừa đủ nội dung */
        flex-direction: column; /* Xếp dọc các nút công cụ bên phải cho gọn */
    }
}

/* --- BẢNG MÀU (PALETTE) --- */
.palette {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.color-swatch {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.color-swatch:hover {
    transform: scale(1.1);
    z-index: 10;
}

.color-swatch.active {
    transform: scale(1.15);
    border-color: #333;
    box-shadow: 0 4px 8px rgba(0,0,0,0.25);
}

/* Dấu tích chọn màu đang active */
.color-swatch.active::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

/* --- CÁC NÚT CHỨC NĂNG (TOOLS) --- */
.tools {
    /* display: flex;
    gap: 10px; */
    justify-content: center;
    flex-wrap: wrap;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

/* --- ĐIỀU CHỈNH KÍCH CỠ BÚT --- */
.brush-size-control {
    width: 100%;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 6px;
    margin-top: 10px;
}

.brush-size-control label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--wpcb-text-color);
    margin-bottom: 8px;
}

.brush-size-control #brush-size-value {
    color: var(--wpcb-primary-color);
    font-weight: 700;
}

.brush-size-control input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.brush-size-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--wpcb-primary-color);
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

.brush-size-control input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 6px rgba(0,0,0,0.3);
}

.brush-size-control input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--wpcb-primary-color);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s ease;
}

.brush-size-control input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 3px 6px rgba(0,0,0,0.3);
}

/* Reset toàn bộ style nút bấm của Theme để tránh xung đột */
.tool-btn {
    appearance: none;
    -webkit-appearance: none;
    background: #fff;
    border: 1px solid var(--wpcb-border-color);
    color: var(--wpcb-text-color);
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    line-height: 1.2;
    text-transform: none;
    margin: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.tool-btn:hover {
    background-color: #f0f0f1;
    border-color: #8c8f94;
    color: #1d2327;
}

.tool-btn.active {
    background-color: var(--wpcb-primary-color);
    border-color: var(--wpcb-primary-color);
    color: #fff;
    box-shadow: 0 2px 4px rgba(34, 113, 177, 0.3);
}

/* Icon trong nút (nếu có dùng icon font hoặc emoji) */
.tool-btn i, .tool-btn span {
    pointer-events: none;
}

/* --- CANVAS --- */
canvas#coloring-canvas {
    display: block;
    background-color: #fff;
    /* Quan trọng: max-width 100% để không tràn, nhưng giữ nguyên kích thước gốc */
    max-width: 100% !important;
    width: auto !important;
    height: auto !important;
    /* Không scale up - chỉ scale down nếu lớn hơn container */
    border: 1px dashed #ccc; /* Viền nét đứt nhẹ để phân biệt vùng vẽ */
    cursor: crosshair; /* Con trỏ hình chữ thập */
    touch-action: none; /* Ngăn cuộn trang khi chạm vào canvas trên mobile */
    /* Đảm bảo ảnh không bị vỡ */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    /* Hoặc dùng auto để ảnh mượt */
    image-rendering: auto;
}

/* Gallery đã được bỏ - mỗi ảnh có nút riêng để tô màu */

/* --- NÚT TÔ MÀU BÊN DƯỚI ẢNH --- */
.wpcb-image-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
    max-width: 100%;
    margin-bottom: 15px;
}

.wpcb-coloring-btn {
    display: block;
    width: 100%;
    max-width: 300px;
    margin: 10px auto;
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

.wpcb-coloring-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

.wpcb-coloring-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.wpcb-coloring-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    background: #6c757d;
}

/* --- RESPONSIVE CHO MOBILE NHỎ --- */
@media (max-width: 480px) {
    .coloring-app-wrapper {
        padding: 10px;
        margin: 10px auto;
        border: none; /* Bỏ viền trên mobile cho thoáng */
        background: transparent;
        box-shadow: none;
    }
    
    .palette {
        gap: 6px;
    }
    
    .color-swatch {
        width: 30px;
        height: 30px;
    }
    
    .tool-btn {
        padding: 8px 12px;
        font-size: 13px;
        flex: 1 1 auto; /* Các nút tự chia đều chiều rộng */
        justify-content: center;
    }
    
    .wpcb-coloring-btn {
        max-width: 100%;
        padding: 10px 20px;
        font-size: 14px;
    }
}