/* General Reset & Body Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: #f0f2f5;
    min-height: 100vh;
    padding: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Main Container */
.container {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.1);
    overflow: hidden;
}

/* Header */
.header {
    background: linear-gradient(135deg, #ea9466 0%, #af2413 100%);
    color: white;
    padding: 2rem;
    text-align: center;
}

.header h1 {
    font-size: 2.5em;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

.header p {
    opacity: 0.9;
    font-size: 1.1em;
}

/* Content Layout */
.content {
    padding: 2.5rem;
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 2.5rem;
    align-items: start;
}

.left-panel {
    width: 300px;
    position: sticky;
    top: 2.5rem;
}

/* Upload Box */
.upload-box {
    aspect-ratio: 4500 / 5400;
    width: 100%;
    border: 3px dashed #d0d7e6;
    border-radius: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #f8f9fa;
    position: relative;
    overflow: hidden;
}

.upload-box:hover, .upload-box.dragover {
    border-color: #667eea;
    background: #eef1ff;
}

.upload-placeholder {
    text-align: center;
    padding: 20px;
    transition: opacity 0.3s ease;
}

.upload-icon {
    font-size: 3em;
    line-height: 1;
    margin-bottom: 1rem;
    color: #667eea;
}

.upload-placeholder h3 {
    font-size: 1.2em;
    color: #333;
    margin-bottom: 0.5rem;
}

.upload-placeholder p {
    font-size: 0.9em;
    color: #666;
}

input[type="file"] {
    display: none;
}

/* Image Preview in Upload Box */
.image-preview {
    width: 100%;
    height: 100%;
    display: none;
    position: relative;
}

.image-preview img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.remove-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(220, 53, 69, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 35px;
    height: 35px;
    font-size: 1.5em;
    font-weight: bold;
    line-height: 35px;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
}

.remove-btn:hover {
    background: #c82333;
    transform: scale(1.1);
}

/* Right Panel and Sections */
.preview-section, .generate-section {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 1.5rem;
}

.generate-section {
    margin-top: 1.5rem;
    text-align: center;
}

.preview-section h2 {
    color: #667eea;
    margin-bottom: 1.5rem;
    font-size: 1.5em;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 0.75rem;
}

/* Canvas & Loading */
.canvas-wrapper {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
    position: relative;
}

#previewCanvas {
    border: 1px solid #dee2e6;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
    cursor: default;
}

#previewCanvas.dragging {
    cursor: move !important;
}

/* New loading styles */
.loading-area {
    display: none; /* Hidden by default */
    position: absolute;
    background: rgba(255, 255, 255, 0.7);
    align-items: center;
    justify-content: center;
    pointer-events: none; /* Allow clicks to pass through */
    border-radius: 10px;
    transition: opacity 0.3s ease;
}
.loading-area.active { 
    display: flex; 
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #eef1ff;
    border-top: 5px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Controls */
.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.control-box, .background-controls {
    background: white;
    padding: 1rem;
    border-radius: 10px;
    border: 1px solid #e0e0e0;
}

.control-box-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.control-box-header h3 {
    margin-bottom: 0;
    font-size: 1.1em;
    font-weight: 600;
    color: #333;
}

.control-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.hint {
    margin-top: 0.75rem;
    font-size: 0.85em;
    color: #777;
    text-align: center;
}

/* Toggle Switch Styles */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 28px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: #667eea;
}

input:checked + .slider:before {
    transform: translateX(22px);
}


/* Buttons */
.btn {
    padding: 0.5rem;
    border: 2px solid #d0d7e6;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #444;
    height: 44px; /* Ensure consistent button height */
}
.btn:hover {
    border-color: #667eea;
    background: #eef1ff;
    color: #667eea;
    transform: translateY(-2px);
}
.btn:active {
    transform: translateY(0);
}
.btn img {
    width: 24px;
    height: 24px;
}

.btn-primary-alt {
    border-color: #667eea;
    background-color: #eef1ff;
    color: #667eea;
}
.btn-primary-alt:hover {
    background-color: #667eea;
    color: white;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border-color: #6c757d;
}
.btn-secondary:hover {
    background: #5a6268;
    border-color: #5a6268;
    color: white;
}

.btn-primary {
    background: linear-gradient(0deg, #7d2c00 0%, #c16401 100%);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}
.btn-primary:hover {
    background: linear-gradient(0deg, #c16401 0%, #7d2c00 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    color: white;
}

.btn-generate {
    padding: 1rem 2.5rem;
    font-size: 1.1em;
    font-weight: 600;
    height: auto; /* Override fixed height for this larger button */
    margin: auto;
}


/* Form Elements & Background Presets */
.background-controls .control-row {
    justify-content: flex-start;
}
.background-controls h3 {
     color: #333;
    margin-bottom: 1rem;
    font-size: 1.1em;
    font-weight: 600;
}

.btn-bg {
    width: 36px;
    height: 36px;
    min-width: 36px;
    padding: 4px;
    border: 2px solid #d0d7e6;
    border-radius: 50%; /* Make them circles */
    transition: all 0.2s ease;
    background-clip: content-box;
}

.btn-bg:hover {
    transform: scale(1.1);
}

.btn-bg.active {
    border-color: #667eea;
    box-shadow: 0 0 0 2px white, 0 0 0 4px #667eea;
}

/* Style for transparent button swatch */
.btn-bg[data-color="transparent"] {
    background-image: linear-gradient(45deg, #ccc 25%, transparent 25%), 
                      linear-gradient(-45deg, #ccc 25%, transparent 25%), 
                      linear-gradient(45deg, transparent 75%, #ccc 75%), 
                      linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
    background-color: white;
}
/* Preset color styles */
.btn-bg[data-color="#000000"] { background-color: #000000; }
.btn-bg[data-color="#34495e"] { background-color: #34495e; }
.btn-bg[data-color="#2c3e50"] { background-color: #2c3e50; }
.btn-bg[data-color="#c0392b"] { background-color: #c0392b; }


/* Custom Color Picker Styles */
.btn-bg-custom {
    position: relative;
    padding: 0;
    overflow: hidden;
    background-image: conic-gradient(red, yellow, lime, aqua, blue, magenta, red);
}

.btn-bg-custom input[type="color"] {
    position: absolute;
    top: -10px;
    left: -10px;
    width: 60px;
    height: 60px;
    opacity: 0;
    cursor: pointer;
}


/* Responsive Design */
@media (max-width: 1200px) {
    .content {
        grid-template-columns: 1fr;
    }
    
    .left-panel {
        width: 100%;
        max-width: 400px;
        margin: 0 auto 2.5rem auto;
        position: static;
    }
}

@media (max-width: 768px) {
    body {
        padding: 1rem;
    }
    .content {
        padding: 1.5rem;
        gap: 1.5rem;
    }
    .header {
        padding: 1.5rem;
    }
    .header h1 {
        font-size: 2em;
    }
    .controls-grid {
        grid-template-columns: 1fr;
    }
}

