/* --- Variables and Global Styles --- */
:root {
    --font-family-system: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    
    /* Colors */
    --color-text: #333;
    --color-text-muted: #555;
    --color-background: #f0f0f0;
    --color-surface: #ffffff;
    --color-surface-muted: #f9f9f9;
    --color-border: #ccc;
    --color-border-light: #ddd;
    --color-border-very-light: #eee;
    
    /* Theme Colors */
    --color-primary: #007bff;
    --color-primary-light: #e6f4ff;
    --color-primary-border: #a0cff0;
    --color-primary-hover-bg: #d9effc;
    --color-primary-hover-border: #8ac0e4;

    --color-danger: #e60023;
    --color-danger-hover: #c4001e;
    --color-danger-light-bg: #fff0f0;
    --color-danger-light-border: #f9b3b3;
    --color-danger-light-hover-bg: #fbe5e5;
    --color-danger-light-hover-border: #f7a0a0;

    /* Spacing & Sizing */
    --spacing-main: 24px;
    --spacing-medium: 16px;
    --spacing-small: 12px;
    --spacing-tiny: 8px;
    --border-radius-main: 8px;
    --border-radius-small: 4px;

    /* Effects */
    --shadow-main: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-small: 0 1px 3px rgba(0,0,0,0.05);
    --transition-speed: 0.2s;
}

body {
    font-family: var(--font-family-system);
    margin: 0;
    padding: var(--spacing-main);
    box-sizing: border-box;
    background-color: var(--color-background);
    color: var(--color-text);
}

h1 {
    font-size: 24px;
    margin: 0 0 var(--spacing-medium);
    text-align: center;
}

/* --- Layout --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--spacing-main);
    background-color: var(--color-surface);
    border-radius: var(--border-radius-main);
    box-shadow: var(--shadow-main);
    position: relative;
}

.row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-main);
}

.col {
    box-sizing: border-box;
}

#leftPane {
    flex: 3 1 600px;
    min-width: 300px;
}

#rightPane {
    flex: 1 1 300px;
    min-width: 280px;
    display: flex;
    flex-direction: column;
}

/* --- Components --- */

/* Canvas & Drop Zone */
#canvasWrapper {
    position: relative;
    border: 1px solid var(--color-border-light);
    touch-action: none;
    background-color: #fafafa; /* Keep specific color */
    border-radius: var(--border-radius-small);
    overflow: hidden;
    min-height: 300px;
}

#mainCanvas {
    display: block;
    max-width: 100%;
    height: auto;
}

#overlayCanvas {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#dropZone {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background-color: rgba(250, 250, 250, 0.9);
    border: 3px dashed var(--color-border);
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
    cursor: pointer;
}

#dropZone p {
    color: #666;
    font-size: 16px;
    pointer-events: none;
}

/* Controls & Inputs */
.top-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-medium);
    padding-bottom: var(--spacing-medium);
    border-bottom: 1px solid var(--color-border-very-light);
}

.controls label,
.inline-label {
    font-size: 14px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: var(--spacing-tiny);
    padding: 4px var(--spacing-tiny);
    border: 1px solid #e0e0e0;
    border-radius: 6px;
}

.inline-label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

select {
    font-size: 14px;
    padding: 8px 12px;
    border-radius: var(--border-radius-small);
    border: 1px solid var(--color-border);
}

input[type="color"] {
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background-color: transparent;
}
input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}
input[type="color"]::-webkit-color-swatch {
    border: 1px solid var(--color-border);
    border-radius: 50%;
}

/* Buttons */
button,
input[type="file"]::file-selector-button {
    font-size: 14px;
    padding: 8px 16px;
    border-radius: var(--border-radius-small);
    border: 1px solid var(--color-border);
    background-color: var(--color-surface);
    cursor: pointer;
    transition: background-color var(--transition-speed), box-shadow var(--transition-speed);
}

button:hover,
input[type="file"]::file-selector-button:hover {
    background-color: #f5f5f5;
    border-color: #aaa;
}

#openSettingsBtn {
    background-color: transparent;
    border: 1px solid transparent;
}
#openSettingsBtn:hover {
    background-color: var(--color-background);
    border-color: var(--color-border-light);
}

#resetImageBtn {
    background-color: var(--color-background);
    border-color: var(--color-border);
    display: none;
}
#resetImageBtn:hover {
    background-color: #e5e5e5;
    border-color: #bbb;
}

#clearPanelsBtn {
    background-color: var(--color-danger-light-bg);
    border-color: var(--color-danger-light-border);
}
#clearPanelsBtn:hover {
    background-color: var(--color-danger-light-hover-bg);
    border-color: var(--color-danger-light-hover-border);
}

#exportBtn {
    background-color: var(--color-primary-light);
    border-color: var(--color-primary-border);
    font-weight: bold;
}
#exportBtn:hover {
    background-color: var(--color-primary-hover-bg);
    border-color: var(--color-primary-hover-border);
}

.delete-panel-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: var(--color-danger);
    color: var(--color-surface);
    border: 2px solid var(--color-surface);
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: transform var(--transition-speed), background-color var(--transition-speed);
}
.delete-panel-btn:hover {
    background-color: var(--color-danger-hover);
    transform: scale(1.1);
}

/* Panel List */
.export-controls {
    margin: 0 0 var(--spacing-small);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-medium);
    align-items: flex-start;
}

.button-group {
    display: flex;
    gap: var(--spacing-small);
}

#panelList {
    flex-grow: 1;
    min-height: 100px;
    overflow-y: auto;
    border: 1px solid var(--color-border-light);
    padding: var(--spacing-tiny);
    box-sizing: border-box;
    border-radius: var(--border-radius-small);
    background-color: var(--color-surface-muted);
    transition: border-color var(--transition-speed);
}

.panel-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-small);
    margin: 0 0 var(--spacing-tiny);
    padding: var(--spacing-tiny);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    cursor: pointer;
    border-radius: var(--border-radius-small);
    box-shadow: var(--shadow-small);
    transition: box-shadow var(--transition-speed), transform var(--transition-speed);
    position: relative;
}
.panel-item:hover {
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
    transform: scale(1.02);
}

.panel-thumb {
    width: 80px;
    height: 80px;
    object-fit: contain;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-small);
}

.panel-meta {
    font-size: 13px;
    flex: 1;
}

#info {
    font-size: 13px;
    color: var(--color-text-muted);
    line-height: 1.6;
    text-align: center;
    margin: 0 auto var(--spacing-medium);
    max-width: 600px;
}

/* --- States & Modifiers --- */

/* Drag & Drop States */
.panel-item.dragging {
    opacity: 0.6;
    background: #eef7ff;
}

.panel-item.drop-target-top::before,
.panel-item.drop-target-bottom::after {
    content: '';
    position: absolute;
    left: 0;
    width: 100%;
    height: 4px;
    background-color: var(--color-primary);
    box-shadow: 0 0 8px rgba(0, 123, 255, 0.7);
    z-index: 10;
}

.panel-item.drop-target-top::before {
    top: -4px;
}

.panel-item.drop-target-bottom::after {
    bottom: -4px;
}

#panelList.drop-target-end {
    border-color: transparent;
    border-bottom: 4px solid var(--color-primary);
    box-shadow: 0 4px 8px -4px rgba(0, 123, 255, 0.5);
}

#dropZone.drag-over {
    background-color: rgba(230, 245, 255, 0.9);
    border-color: var(--color-primary);
}

/* Visibility State */
.container.has-image #dropZone {
    display: none;
}

.container.has-image #resetImageBtn {
    display: inline-block;
}

/* Active State */
.panel-item.is-previewing {
    border-color: var(--color-primary);
    box-shadow: 0 0 6px var(--color-primary);
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed) ease-out, visibility 0s var(--transition-speed);
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--color-surface);
    border-radius: var(--border-radius-main);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    z-index: 101;
    width: 90%;
    max-width: 400px;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-speed) ease-out, visibility 0s var(--transition-speed), transform var(--transition-speed) ease-out;
}

.modal.is-visible,
.modal-overlay.is-visible {
    opacity: 1;
    visibility: visible;
    transition-delay: 0s;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-medium);
    border-bottom: 1px solid var(--color-border-very-light);
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
}

.close-btn {
    font-size: 28px;
    font-weight: bold;
    line-height: 1;
    color: var(--color-text-muted);
    background: none;
    border: none;
    padding: 0 8px;
    cursor: pointer;
}
.close-btn:hover {
    color: var(--color-text);
    background-color: transparent; /* Override generic button hover */
    border-color: transparent;
}


.modal-content {
    padding: var(--spacing-medium);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-medium);
}
/* Override for control-group inside modal */
.modal-content .control-group {
    border: none;
    padding: 0;
}

#previewCanvasWrapper {
    padding: var(--spacing-tiny);
    background-color: var(--color-background);
    border-radius: var(--border-radius-small);
    text-align: center;
    line-height: 0; /* Remove extra space below canvas */
}

#previewCanvas {
    max-width: 100%;
    height: auto;
    background-color: var(--color-surface);
}

/* Specific overrides for Preview Modal */
#previewModal {
    max-width: 600px;
}

#previewModal .modal-content {
    max-height: 80vh;
    overflow-y: auto;
}


/* Visibility Class is now handled by modal opacity/visibility */

/* --- Responsive --- */
@media (max-width: 768px) {
    .row {
        flex-direction: column;
    }
}