:root {
    --bg-color: #f1f5f9;
    --panel-bg: rgba(255, 255, 255, 0.6);
    --panel-border: rgba(0, 0, 0, 0.08);
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --glass-blur: 16px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    overflow: hidden;
    background-image: 
        radial-gradient(at 0% 0%, rgba(59, 130, 246, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.15) 0px, transparent 50%);
}

.app-container {
    display: flex;
    width: 100%;
    height: 100vh;
}

/* Glassmorphism Panel */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--panel-border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

/* Sidebar */
.sidebar {
    width: 380px;
    min-width: 380px;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
    border-right: 1px solid var(--panel-border);
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

.logo {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 24px;
    letter-spacing: -0.5px;
}

.logo span {
    color: var(--accent);
}

.control-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--panel-border);
}
.control-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.control-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
}

/* Upload Area */
.upload-zone {
    border: 2px dashed rgba(0,0,0,0.15);
    border-radius: 12px;
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.01);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent);
    background: rgba(59, 130, 246, 0.05);
    transform: translateY(-2px);
}

.upload-zone svg {
    color: var(--text-secondary);
    margin-bottom: 12px;
    transition: color 0.3s;
}

.upload-zone:hover svg, .upload-zone.dragover svg {
    color: var(--accent);
}

.upload-zone p {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
}

.upload-zone .sub-text {
    font-size: 12px;
    color: var(--text-secondary);
}

.upload-actions {
    display: flex;
    gap: 10px;
}

.hidden-input {
    display: none;
}

/* Buttons */
.btn {
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-secondary {
    background: rgba(0,0,0,0.05);
    color: var(--text-primary);
    flex: 1;
}

.btn-secondary:hover {
    background: rgba(0,0,0,0.08);
}

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-large {
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 600;
    margin-top: 10px;
    position: relative;
}

/* Image List */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.section-header h3 {
    margin-bottom: 0;
}
.header-actions {
    display: flex;
    gap: 8px;
}
.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    padding: 4px;
    display: flex;
    transition: all 0.2s;
}
.btn-icon:hover {
    color: var(--text-primary);
    background: rgba(0,0,0,0.05);
}

.image-list {
    list-style: none;
    max-height: 250px;
    overflow-y: auto;
    padding-right: 4px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.image-list::-webkit-scrollbar {
    width: 4px;
}
.image-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 2px;
}

.list-item {
    display: flex;
    align-items: center;
    background: rgba(255,255,255,0.5);
    border-radius: 8px;
    padding: 8px;
    gap: 12px;
    cursor: grab;
    border: 1px solid rgba(0,0,0,0.03);
    transition: background 0.2s, border 0.2s, box-shadow 0.2s;
}
.list-item:hover {
    background: #ffffff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}
.list-item:active {
    cursor: grabbing;
}
.list-item.dragging {
    opacity: 0.5;
    border: 1px dashed var(--accent);
}
.list-item.drag-over {
    border-top: 2px solid var(--accent);
}

.item-thumb {
    width: 48px;
    height: 48px;
    border-radius: 4px;
    object-fit: cover;
    background: #e2e8f0;
}
.item-info {
    flex: 1;
    overflow: hidden;
}
.item-name {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}
.item-meta {
    font-size: 11px;
    color: var(--text-secondary);
}
.item-actions {
    display: flex;
    gap: 4px;
}
.btn-rotate, .btn-delete, .btn-move-up, .btn-move-down {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-rotate:hover { color: var(--text-primary); background: rgba(0,0,0,0.05); }
.btn-move-up:hover:not(:disabled), .btn-move-down:hover:not(:disabled) { color: var(--text-primary); background: rgba(0,0,0,0.05); }
.btn-move-up:disabled, .btn-move-down:disabled { opacity: 0.2; cursor: not-allowed; }
.btn-delete:hover { color: var(--danger); background: rgba(239, 68, 68, 0.1); }

/* Settings */
.setting-group {
    margin-bottom: 16px;
}
.setting-group > label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.radio-group {
    display: flex;
    gap: 8px;
}
.radio-label {
    flex: 1;
    cursor: pointer;
}
.radio-label input {
    display: none;
}
.radio-btn {
    display: block;
    text-align: center;
    padding: 8px;
    background: rgba(0,0,0,0.03);
    border-radius: 6px;
    font-size: 13px;
    border: 1px solid transparent;
    transition: all 0.2s;
}
.radio-label input:checked + .radio-btn {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--accent);
    color: var(--accent-hover);
    font-weight: 500;
}

.custom-select, .custom-input {
    width: 100%;
    padding: 10px;
    background: #ffffff;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.custom-select:focus, .custom-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.custom-select option {
    background: #ffffff;
}

.custom-range {
    width: 100%;
    accent-color: var(--accent);
}

.color-picker-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #ffffff;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid rgba(0,0,0,0.1);
}
input[type="color"] {
    -webkit-appearance: none;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    background: none;
}
input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}
input[type="color"]::-webkit-color-swatch {
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 4px;
}
#gapColorHex {
    font-size: 13px;
    font-family: monospace;
}

/* Loader */
.loader {
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    position: absolute;
}
.hidden {
    display: none !important;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Main Area */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow: hidden;
    min-height: 0;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.preview-header h2 {
    font-size: 20px;
    font-weight: 600;
}
.preview-info {
    font-size: 13px;
    color: var(--text-secondary);
    background: rgba(0,0,0,0.05);
    padding: 4px 12px;
    border-radius: 12px;
}

.preview-controls {
    display: flex;
    align-items: center;
    flex-direction: row;
    flex-wrap: nowrap;
    flex-shrink: 0;
    gap: 4px;
    background: rgba(0, 0, 0, 0.03);
    padding: 3px 8px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

#zoomLevelVal {
    font-size: 12px;
    font-weight: 600;
    min-width: 52px;
    text-align: center;
    color: var(--text-primary);
}

.canvas-container {
    flex: 1;
    border-radius: 12px;
    position: relative;
    overflow: auto;
    min-height: 0;
    /* NO text-align:center and NO flex centering.
       Both prevent scrolling to the top/left when canvas overflows.
       Centering is handled by JS margins instead. */
}

.canvas-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.canvas-container::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

#mergeCanvas {
    /* All sizing and margins are set programmatically by applyZoomCSS() */
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    display: none;    /* hidden until images are added; JS sets display:block */
    position: relative; /* needed so JS margins work correctly */
}
.magnifier-glass {
    position: absolute;
    width: 150px;
    height: 150px;
    border-radius: 50%;
    border: 3px solid var(--accent);
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    pointer-events: none; /* Let mouse events pass through */
    display: none;
    background: #fff;
    overflow: hidden;
    z-index: 100;
}

#magnifierCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.btn-icon.active {
    color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

.empty-state {
    position: absolute;
    text-align: center;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--text-primary);
    margin-bottom: 8px;
}
.empty-state p {
    font-size: 14px;
    max-width: 250px;
}

@media (max-width: 768px) {
    body {
        overflow: auto;
    }
    .app-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    .sidebar {
        width: 100%;
        height: auto;
        min-width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--panel-border);
        overflow-y: visible;
        padding-bottom: calc(30px + env(safe-area-inset-bottom));
    }
    .preview-area {
        height: 75vh;
        min-height: 450px;
        padding: 12px;
    }
    .preview-header {
        flex-direction: column;
        align-items: center;
        gap: 12px;
        margin-bottom: 15px;
    }
    .preview-controls {
        width: auto;
        max-width: 100%;
        justify-content: center;
    }
    .canvas-container {
        min-height: 380px;
    }
    .upload-actions {
        flex-direction: column;
        gap: 8px;
    }
    .btn {
        min-height: 44px; /* Touch target size */
    }
    .btn-large {
        padding: 12px;
        font-size: 15px;
    }
    .export-section {
        padding-bottom: env(safe-area-inset-bottom);
    }
}
