/* Pixel Painter Drawing Interface
 * 
 * NOTE: Use Bootstrap utility classes as much as possible instead of custom CSS.
 * Only add custom CSS when Bootstrap classes cannot achieve the desired styling.
 */

:root {
    /* Grid positioning - easily configurable */
    --grid-top: 16%;
    --grid-left: 50%;
    --grid-width: 37.5%;
    --grid-height: auto;
    --grid-translate-x: -50%;
    --grid-translate-y: 0;
    /* Color selector scaling */
    --color-selector-scale: 1;
}

.pixel-painter-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 0.375rem;
}

.pixel-painter-background {
    width: 110%;
    height: auto;
    display: block;
    margin-left: -5%;
    object-fit: cover;
    object-position: center;
    user-select: none;
    -webkit-user-drag: none;
    -moz-user-select: none;
    -ms-user-select: none;
    border-radius: 0.375rem;
}

.pixel-painter-grid {
    position: absolute;
    top: var(--grid-top);
    left: var(--grid-left);
    width: var(--grid-width);
    aspect-ratio: 1;
    transform: translate(var(--grid-translate-x), var(--grid-translate-y));
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    gap: 0px;
    background-color: rgba(0, 0, 0, 0.7);
    padding: 1px;
    border-radius: 4px;
}

.pixel-cell {
    background-color: #000;
    /* border: 1px solid rgba(128, 128, 128, 0.4); */
    border: 1px solid rgba(77, 77, 77, 0.7);
    cursor: pointer;
    transition: opacity 0.2s, border-color 0.1s;
    box-sizing: border-box;
    position: relative;
}

.pixel-cell::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 1px;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.25) 0%, transparent 40%, rgba(0, 0, 0, 0.5) 100%);
    pointer-events: none;
    mix-blend-mode: soft-light;
}

.pixel-cell:hover {
    opacity: 0.9;
    border-color: rgba(255, 255, 255, 0.8);
    z-index: 10;
    position: relative;
}

/* Color selector overlay */
.color-selector-overlay {
    position: absolute;
    bottom: 8%;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(0, 0, 0, 0.7);
    width: 95%;
    max-width: 360px;
    gap: 0.25rem !important; /* Minimal gap instead of gap-2 */
    padding-top: 0.25rem !important; /* Minimal top padding */
    padding-bottom: 0.25rem !important; /* Minimal bottom padding */
}

.mix-colors-label {
    margin-top: 0.125rem;
    margin-bottom: 0.125rem;
    font-size: .8rem; 
    text-transform: uppercase;
}

.select-color-wrapper {
    margin-top: 0.375rem; /* Tiny bit of space between custom squares and select color */
}

.color-swatches-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
}

.color-swatch {
    aspect-ratio: 1;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 4px;
    transition: transform 0.1s, border-color 0.1s;
}

.color-swatch:hover,
.custom-color-swatch:hover {
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.9);
}

.color-swatch.active,
.custom-color-swatch.active {
    transform: scale(1.1);
    border-width: 3px;
    border-color: rgba(255, 255, 255, 1);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.6);
}

.custom-color-swatch {
    aspect-ratio: 1;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 4px;
    transition: transform 0.1s, border-color 0.1s;
    background-color: #000000;
    color: transparent;
    cursor: pointer;
    padding: 0;
    text-align: center;
    font-size: 0;
    appearance: none;
    -webkit-appearance: none;
}


.color-picker-wrapper {
    position: relative;
    display: inline-block;
}

.color-picker-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-weight: bolder;
    font-size: 0.8rem;
    text-transform: uppercase;
    color: rgba(0, 0, 0, 0.9);
    text-shadow: 
        -0.5px -0.5px 0 rgba(255, 255, 255, 0.7),
        0.5px -0.5px 0 rgba(255, 255, 255, 0.7),
        -0.5px 0.5px 0 rgba(255, 255, 255, 0.7),
        0.5px 0.5px 0 rgba(255, 255, 255, 0.7);
    cursor: pointer;
    pointer-events: none;
    z-index: 1;
    white-space: nowrap;
}

.color-picker-input {
    width: 128px;
    height: 32px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    cursor: pointer;
    padding: 0;
    background-color: #ffffff;
    color: transparent;
    font-weight: bolder;
    font-size: 0.8rem;
    text-transform: uppercase;
    text-align: center;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    transition: transform 0.1s, border-color 0.1s;
    position: relative;
    display: block;
}

.color-picker-input:hover {
    transform: scale(1.03);
    border-color: rgba(255, 255, 255, 0.9);
}

.color-picker-input::placeholder {
    color: rgba(0, 0, 0, 0.9);
    text-shadow: 
        -0.5px -0.5px 0 rgba(255, 255, 255, 0.7),
        0.5px -0.5px 0 rgba(255, 255, 255, 0.7),
        -0.5px 0.5px 0 rgba(255, 255, 255, 0.7),
        0.5px 0.5px 0 rgba(255, 255, 255, 0.7);
    opacity: 1;
}

.color-picker-input:not(:placeholder-shown) {
    color: transparent;
}

/* Save button uses btn-magenta from main styles */
#save-image:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Main layout container */
.pixel-painter-main-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

@media (min-width: 992px) {
    .pixel-painter-main-layout {
        gap: 40px;
    }
}

/* On mobile, sidebar goes below content */
.pixel-painter-sidebar {
    order: 2;
    margin-top: 30px;
}

.pixel-painter-content {
    order: 1;
}

/* On larger screens, sidebar on left */
@media (min-width: 992px) {
    .pixel-painter-main-layout {
        flex-direction: row;
        align-items: flex-start;
    }
    
    .pixel-painter-sidebar {
        flex: 0 0 260px;
        order: -1;
        margin-top: 0;
        position: sticky;
        top: 20px;
    }
    
    .pixel-painter-content {
        flex: 1;
        min-width: 0;
    }
}


.image-thumbnail {
    width: 100%;
}

.thumbnail-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    aspect-ratio: 1;
    gap: 1px;
    background-color: #000;
    padding: 2px;
}

.thumbnail-pixel {
    background-color: #000;
    border: 1px solid rgba(128, 128, 128, 0.15);
    box-sizing: border-box;
    position: relative;
}

.thumbnail-pixel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 1px;
    background: radial-gradient(circle at center, rgba(255, 255, 255, 0.25) 0%, transparent 40%, rgba(0, 0, 0, 0.5) 100%);
    pointer-events: none;
    mix-blend-mode: soft-light;
}


/* Color Picker Modal */
.color-picker-modal hex-color-picker {
    width: 270px;
    height: 180px;
}

.color-preview-box {
    border: 2px solid rgba(0, 0, 0, 0.2);
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Source Modal */
#source-modal .form-control {
    font-family: 'Courier New', monospace;
}

@media (max-width: 575.98px) {
    #source-modal .bg-white {
        max-width: 95% !important;
        padding: 1rem !important;
    }
    
    #source-modal textarea {
        min-height: 200px !important;
        font-size: 0.75rem !important;
    }
    
    #source-modal h3 {
        font-size: 1.1rem;
    }
}

/* Optimize for small screens (< 576px) */
@media (max-width: 575.98px) {
    .pixel-painter-container {
        max-width: 100%;
        padding-bottom: 30%; /* Extra height to accommodate zoomed background */
    }
    
    :root {
        --grid-width: 55%; /* Larger grid on small screens */
        --grid-top: 7.5%;
    }
    
    .pixel-painter-background {
        transform: scale(1.5); /* Zoom background image to match larger grid */
        transform-origin: center 30%; /* Scale from slightly above center */
        object-position: center 25%; /* Show more of the top of the image */
    }
    
    
    .color-selector-overlay {
        bottom: 8%;
    }
}
