/* --- GENERAL STYLES --- */
* { box-sizing: border-box; }

body { 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    background: #f4f4f9; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    padding: 20px; 
    color: #333; 
    margin: 0;
}
h1 { 
    margin-bottom: 10px; 
    font-size: 1.8em;
    text-align: center;
}

/* Content wrapper (Mobile default: Column) */
.content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 1600px;
    align-items: center;
}

/* Controls Wrapper */
.controls-wrapper { 
    display: flex; 
    flex-direction: column; 
    gap: 10px; 
    width: 100%; 
    max-width: 800px; 
}

/* Center Column (Canvas & Palette) */
.center-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
    max-width: 1000px; /* Limit width on large screens */
}

/* Controls Group (Details/Summary) */
details.controls-group {
    background: white; 
    border-radius: 8px; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.05); 
    width: 100%;
    margin-bottom: 5px;
    overflow: hidden;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

details.controls-group[open] {
    padding-bottom: 15px;
}

summary.group-title {
    font-weight: bold; 
    color: #555; 
    font-size: 0.9em; 
    text-transform: uppercase; 
    padding: 15px;
    cursor: pointer;
    list-style: none;
    background-color: #fff;
    border-bottom: 1px solid transparent;
    transition: background-color 0.2s;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin: 0 !important;
}

/* Add custom indicator */
summary.group-title::after {
    content: '+';
    font-size: 1.2em;
    font-weight: bold;
}

details[open] summary.group-title::after {
    content: '−';
}

/* Hide default marker for webkit */
summary.group-title::-webkit-details-marker {
    display: none;
}

details[open] summary.group-title {
    border-bottom: 1px solid #eee;
    background-color: #fafafa;
}

/* Content inside details */
details.controls-group > *:not(summary) {
    margin-left: 5px;
    margin-right: 5px;
    margin-top: 5px;
}

/* Buttons */
button { 
    cursor: pointer; 
    padding: 10px 15px;
    background: #4a90e2; 
    color: white; 
    border: none; 
    border-radius: 6px;
    font-size: 14px; 
    transition: 0.2s;
    min-height: 44px; /* Touch-friendly size */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
button:hover { background: #357abd; }
button.secondary { background: #6c757d; }
button.secondary:hover { background: #5a6268; }
button.success { background: #28a745; }
button.success:hover { background: #218838; }

input[type="number"] { 
    padding: 8px;
    border: 1px solid #ddd; 
    border-radius: 4px; 
    width: 70px;
    min-height: 40px;
}
select { 
    padding: 8px;
    border-radius: 4px; 
    border: 1px solid #ddd;
    min-height: 40px;
    background-color: white;
}

/* Control groups specific overrides */
.controls-group select { 
    font-size: 13px;
}
.controls-group button.secondary { 
    font-size: 13px;
    background-color: #f8f9fa; 
    border: 1px solid #ddd; 
    color: #666; 
}

/* Palette */
.palette { 
    display: flex; 
    gap: 8px;
    margin: 15px 0; 
    /* Horizontal scroll on mobile */
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    max-width: 100%;
    width: 100%;
    padding: 10px 5px;
    -webkit-overflow-scrolling: touch;
}

/* Scrollbar styling for palette */
.palette::-webkit-scrollbar {
    height: 8px;
}
.palette::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}
.palette::-webkit-scrollbar-track {
    background: transparent;
}


.color-swatch { 
    width: 40px;
    height: 40px;
    border-radius: 50%; 
    cursor: pointer; 
    border: 3px solid transparent; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.1); 
    transition: transform 0.1s;
    min-width: 40px; /* Prevent shrinking */
    flex-shrink: 0;
}
.color-swatch:hover { transform: scale(1.1); }
.color-swatch.active { 
    border-color: #333; 
    transform: scale(1.15); 
    box-shadow: 0 0 8px rgba(0,0,0,0.2); 
}

/* Canvas */
.canvas-container { 
    position: relative; 
    box-shadow: 0 10px 20px rgba(0,0,0,0.15); 
    background: white; 
    padding: 10px; 
    border-radius: 8px;
    max-width: 100%;
    overflow: auto;
    display: flex;
    justify-content: center;
}
canvas { 
    display: block; 
    image-rendering: pixelated;
    max-width: 100%;
    height: auto;
}

.info { 
    margin-top: 10px; 
    font-size: 0.9em; 
    color: #666; 
    font-style: italic;
    text-align: center;
}

/* --- RESPONSIVE DESIGN --- */

/* Mobile adjustments */
@media (max-width: 768px) {
    body { padding: 10px; }
    
    h1 { 
        font-size: 1.5em; 
        margin-bottom: 15px;
    }
    
    .controls-wrapper { gap: 8px; }
    
    button { 
        flex: 1 1 auto;
    }
    
    label {
        display: flex;
        align-items: center;
        gap: 5px;
    }
}

/* Desktop Layout */
@media (min-width: 1024px) {
    .content-wrapper {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 20px;
    }
    
    .controls-wrapper {
        max-width: 280px;
        min-width: 280px;
        flex-shrink: 0;
        position: sticky;
        top: 20px;
        /* Move to left */
        order: -1;
    }
    
    .center-column {
        flex: 1;
        min-width: 0;
    }
    
    /* On desktop, palette wraps */
    .palette {
        flex-wrap: wrap;
        justify-content: center;
        overflow-x: visible;
    }
}

/* Extra large screens */
@media (min-width: 1400px) {
    .controls-wrapper {
        max-width: 300px;
        min-width: 300px;
    }
}


/* --- PRINT STYLES --- */
@media print {
    body { background: white; padding: 0; margin: 0; }
    .controls-wrapper, .palette, h1, .info, .group-title { display: none !important; }
    
    .canvas-container { 
        box-shadow: none; 
        padding: auto; 
        margin: auto; 
        overflow: visible;
    }
    canvas { border: 1px solid #ccc; }
}
