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

:root {
    --bg-dark: #1e1e1e;
    --bg-panel: #2d2d2d;
    --bg-panel-section: #383838;
    --bg-input: #3c3c3c;
    --bg-canvas: #252525;
    --border-color: #404040;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-muted: #707070;
    --accent-color: #4f9eff;
    --accent-hover: #3d8be8;
    --success-color: #4caf50;
    --danger-color: #f44336;
    --canvas-checker-1: #2a2a2a;
    --canvas-checker-2: transparent;
}

[data-theme="light"] {
    --bg-dark: #e8e8e8;
    --bg-panel: #f5f5f5;
    --bg-panel-section: #ffffff;
    --bg-input: #ffffff;
    --bg-canvas: #d0d0d0;
    --border-color: #d0d0d0;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-muted: #999999;
    --accent-color: #2196f3;
    --accent-hover: #1976d2;
    --canvas-checker-1: #c0c0c0;
    --canvas-checker-2: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    min-height: 100vh;
    color: var(--text-primary);
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

.app-header {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 16px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.mobile-tabs {
    display: none;
}

.app-header h1 {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.header-actions {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 12px;
}

.publish-link {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1px 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 12px;
    line-height: 16px;
    transition: all 0.2s;
}

.publish-link:hover {
    border-color: var(--accent-color);
    background: var(--bg-panel-section);
    color: var(--accent-color);
}

.publish-link i {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

.theme-toggle {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.theme-toggle:hover {
    border-color: var(--accent-color);
    background: var(--bg-panel-section);
}

.theme-icon-light,
.theme-icon-dark {
    width: 16px;
    height: 16px;
    stroke: var(--text-primary);
}

.theme-icon-dark {
    display: none;
}

[data-theme="light"] .theme-icon-light {
    display: none;
}

[data-theme="light"] .theme-icon-dark {
    display: block;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.panel {
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-left {
    width: 270px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
}

.panel-right {
    width: 240px;
    flex-shrink: 0;
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
}

.panel-main {
    flex: 1;
    min-width: 0;
    background: var(--bg-canvas);
    display: flex;
    flex-direction: column;
}

.panel-section {
    border-bottom: 1px solid var(--border-color);
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-section-preview {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-section-preview .section-content,
.panel-section:not(.collapsible) {
    padding: 12px;
}

.collapsible .section-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
    margin: 0;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.collapsible .section-header:hover {
    background: var(--bg-panel-section);
}

.collapse-icon {
    width: 12px;
    height: 12px;
    transition: transform 0.2s;
    stroke: var(--text-muted);
    flex-shrink: 0;
}

.collapsible.collapsed .collapse-icon {
    transform: rotate(-90deg);
}

.collapsible .section-content {
    padding: 0 12px 12px 12px;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.2s ease;
    max-height: 500px;
    opacity: 1;
}

.collapsible.collapsed .section-content {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
}

.panel h2 {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.canvas-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.canvas-title {
    font-size: 12px;
    color: var(--text-secondary);
}

.canvas-header .hint {
    font-size: 11px;
    color: var(--text-muted);
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.zoom-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.zoom-btn:hover {
    border-color: var(--accent-color);
    background: var(--bg-panel-section);
    color: var(--text-primary);
}

.zoom-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
}

.zoom-value {
    font-size: 11px;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: center;
}

.history-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

.history-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.history-btn:hover:not(:disabled) {
    border-color: var(--accent-color);
    background: var(--bg-panel-section);
    color: var(--text-primary);
}

.history-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.history-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
}

.history-info {
    font-size: 10px;
    color: var(--text-muted);
    min-width: 30px;
    text-align: center;
}


/* ===== Import toggle IA ===== */
.import-ai-toggle {
    margin-bottom: 12px;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.toggle-label input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 36px;
    height: 20px;
    border-radius: 10px;
    background: var(--border-color, #555);
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-label input[type="checkbox"]::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s;
}

.toggle-label input[type="checkbox"]:checked {
    background: var(--accent-color, #7c6af7);
}

.toggle-label input[type="checkbox"]:checked::after {
    transform: translateX(16px);
}

.toggle-text {
    font-weight: 500;
}


/* ===== Conteneur fixe import (garde la hauteur stable au toggle) ===== */
.import-mode-container {
    position: relative;
    height: 360px; /* hauteur fixe commune aux deux modes */
    margin-bottom: 10px;
}

.import-mode-panel {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
}

.import-mode-panel.hidden {
    display: none;
}

/* Dans le conteneur fixe, upload-area remplit tout l'espace */
.import-mode-panel .upload-area {
    flex: 1;
    margin-bottom: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* background-remover prend l'espace restant, bouton en bas */
.import-mode-panel background-remover {
    flex: 1;
    min-height: 0;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 6px;
    padding: 50px 4px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 10px;
    background: #212529;
}

.upload-area:hover {
    border-color: var(--accent-color);
    background: rgba(79, 158, 255, 0.1);
}

.upload-area.dragover {
    border-color: var(--accent-color);
    background: rgba(79, 158, 255, 0.15);
}

.upload-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 8px;
    stroke: #f8f9fa;
}

.upload-text {
    color: #f8f9fa;
    font-size: 1.2rem;
	font-weight:600;
    line-height: 1.4;
}

#fileInput {
    display: none;
}

.mode-switch {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.mode-btn {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-input);
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.mode-btn:hover {
    border-color: var(--accent-color);
    color: var(--text-primary);
}

.mode-btn.active {
    border-color: var(--accent-color);
    background: var(--accent-color);
    color: white;
}

.mode-hint {
    font-size: 10px;
    color: var(--text-muted);
    padding: 6px 8px;
    background: var(--bg-panel-section);
    border-radius: 4px;
}

.control-group {
    margin-bottom: 12px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group label {
    display: block;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-row span {
    font-size: 11px;
    color: var(--text-muted);
}

.cell-size-row {
    flex-wrap: wrap;
}

.cell-size-row input[type="number"] {
    width: 56px;
}

.btn-icon {
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid var(--border-color);
    background: var(--accent-color);
    color: white;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-icon:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.btn-icon svg {
    width: 14px;
    height: 14px;
    stroke: white;
}

input[type="number"] {
    width: 50px;
    padding: 4px 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 11px;
    text-align: center;
    background: var(--bg-input);
    color: var(--text-primary);
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-color);
}

input[type="range"] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    background: var(--bg-input);
    border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 12px;
    height: 12px;
    background: var(--accent-color);
    border-radius: 50%;
    cursor: pointer;
}

input[type="color"] {
    width: 32px;
    height: 24px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
    padding: 2px;
}

input[type="text"] {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 11px;
    background: var(--bg-input);
    color: var(--text-primary);
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-color);
}

.value-display {
    min-width: 36px;
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 11px;
    color: var(--text-secondary);
}

.checkbox-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: var(--accent-color);
}

.control-hint {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

.individual-mode-toggle {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.btn {
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 6px;
}

.btn:last-child {
    margin-bottom: 0;
}

.btn-small {
    padding: 5px 8px;
    font-size: 10px;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-primary svg {
    width: 14px;
    height: 14px;
    stroke: white;
    margin-right: 4px;
    vertical-align: middle;
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:disabled {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:not(:disabled) {
    background: var(--accent-color);
    color: white;
    border: 1px solid var(--accent-color);
}


.btn-secondary:hover {
    background: var(--bg-panel-section);
    color: var(--text-primary);
}

.btn-secondary:not(:disabled):hover {
    background: var(--accent-color);
    color: white;
    border: 1px solid var(--accent-color);
}

.btn-secondary svg {
    width: 14px;
    height: 14px;
    stroke: var(--text-secondary);
    margin-right: 4px;
    vertical-align: middle;
}

.btn-secondary:hover svg {
    stroke: var(--text-primary);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #d32f2f;
}

.btn-danger svg {
    width: 14px;
    height: 14px;
    stroke: white;
    margin-right: 4px;
    vertical-align: middle;
}

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


.canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-canvas);
    background-image:
        linear-gradient(45deg, var(--canvas-checker-1) 25%, var(--canvas-checker-2) 25%),
        linear-gradient(-45deg, var(--canvas-checker-1) 25%, var(--canvas-checker-2) 25%),
        linear-gradient(45deg, var(--canvas-checker-2) 75%, var(--canvas-checker-1) 75%),
        linear-gradient(-45deg, var(--canvas-checker-2) 75%, var(--canvas-checker-1) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#mainCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: grab;
}

#mainCanvas:active {
    cursor: grabbing;
}

.canvas-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    pointer-events: none;
}

.canvas-placeholder .placeholder-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 10px;
    opacity: 0.5;
    stroke: var(--text-muted);
}

.canvas-placeholder p {
    font-size: 12px;
}

#mainCanvas {
    transform: translateZ(0);
    will-change: transform;
}

.preview-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    flex: 1;
    padding-right: 4px;
}

.preview-item {
    position: relative;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    cursor: default;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border: 1px solid transparent;
}

.preview-item:hover {
    border-color: var(--accent-color);
    background: var(--bg-panel-section);
}

.preview-item .index {
    font-size: 10px;
    color: var(--text-muted);
    min-width: 20px;
    flex-shrink: 0;
}

.preview-item img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    background: var(--bg-canvas);
    border-radius: 3px;
    flex-shrink: 0;
    cursor: pointer;
}

.preview-item img:hover {
    opacity: 0.8;
}

.preview-item .preview-placeholder {
    width: 36px;
    height: 36px;
    background: var(--bg-canvas);
    border-radius: 3px;
    flex-shrink: 0;
}

.preview-item .preview-name {
    flex: 1;
    min-width: 0;
    font-size: 11px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: background 0.2s;
}

.preview-item .preview-name:hover {
    background: var(--bg-panel);
}

.preview-item .preview-name.disabled-text {
    color: var(--text-muted);
    cursor: default;
}

.preview-item .preview-name.disabled-text:hover {
    background: transparent;
}

.preview-item .name-input {
    width: 100%;
    padding: 2px 4px;
    font-size: 11px;
    border: 1px solid var(--accent-color);
    border-radius: 3px;
    background: var(--bg-input);
    color: var(--text-primary);
    outline: none;
}

.preview-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.2s;
}

.preview-item:hover .preview-actions {
    opacity: 1;
}

.action-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: var(--bg-panel);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.action-btn:hover {
    background: var(--accent-color);
    color: white;
}

.action-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
}

.preview-item.disabled {
    opacity: 0.6;
}

.preview-item.disabled:hover {
    opacity: 0.8;
}

.image-info {
    background: var(--bg-panel-section);
    border-radius: 4px;
    padding: 8px;
    font-size: 10px;
    color: var(--text-secondary);
}

.image-info p {
    margin-bottom: 4px;
    display: flex;
    gap: 4px;
}

.image-info p:last-child {
    margin-bottom: 0;
}

.image-info strong {
    color: var(--text-muted);
    font-weight: normal;
}

.quick-grids {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 10px;
}

.quick-grid-btn {
    padding: 4px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.quick-grid-btn:hover {
    border-color: var(--accent-color);
    color: var(--text-primary);
}

.quick-grid-btn.active {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}

.progress-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.progress-box {
    background: var(--bg-panel);
    padding: 24px 40px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.progress-box .spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--bg-input);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 11px;
    background: var(--bg-input);
    color: var(--text-primary);
    cursor: pointer;
}

select:focus {
    outline: none;
    border-color: var(--accent-color);
}

.preview-list::-webkit-scrollbar,
.panel-left::-webkit-scrollbar,
.panel-right::-webkit-scrollbar {
    width: 6px;
}

.preview-list::-webkit-scrollbar-track,
.panel-left::-webkit-scrollbar-track,
.panel-right::-webkit-scrollbar-track {
    background: var(--bg-panel);
}

.preview-list::-webkit-scrollbar-thumb,
.panel-left::-webkit-scrollbar-thumb,
.panel-right::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.preview-list::-webkit-scrollbar-thumb:hover,
.panel-left::-webkit-scrollbar-thumb:hover,
.panel-right::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background: var(--bg-panel);
    border-radius: 8px;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border-color);
}

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

.modal-header h3 {
    margin: 0;
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 500;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}

.modal-body {
    padding: 16px;
}

.crop-canvas-container {
    position: relative;
    background: var(--bg-canvas);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 350px;
    max-height: 55vh;
}

#cropCanvas {
    max-width: 100%;
    max-height: 55vh;
    cursor: move;
}

.crop-controls {
    margin-top: 12px;
}

.crop-info {
    display: flex;
    gap: 16px;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding: 8px;
    background: var(--bg-panel-section);
    border-radius: 4px;
}

.crop-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.crop-actions .btn {
    width: auto;
    padding: 8px 16px;
    margin-bottom: 0;
}

.image-preview-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.image-preview-content .modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
}

.image-preview-content img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.image-preview-info {
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-panel);
    padding: 8px 16px;
    border-radius: 4px;
}

.sponsor-affix {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 999;
    cursor: pointer;
}

.sponsor-collapsed {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #d4a574 0%, #c9956c 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(201, 149, 108, 0.4);
    transition: all 0.3s ease;
}

.sponsor-collapsed .sponsor-icon {
    width: 18px;
    height: 18px;
    stroke: white;
    fill: white;
}

.sponsor-affix:hover .sponsor-collapsed {
    transform: scale(1.1);
}

.sponsor-expanded {
    position: absolute;
    bottom: 50px;
    left: 0;
    background: var(--bg-panel);
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s ease;
    min-width: 180px;
    text-align: center;
}

.sponsor-affix:hover .sponsor-expanded {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.sponsor-title {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.sponsor-qrcode {
    width: 140px;
    height: 140px;
    border-radius: 6px;
    display: block;
    margin: 0 auto 8px;
}

.sponsor-text {
    font-size: 10px;
    color: var(--text-muted);
}

@media (max-width: 1024px) {
    .panel-left {
        width: 180px;
    }

    .panel-right {
        width: 200px;
    }
}

@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
    }

    .panel-left,
    .panel-right {
        width: 100%;
        max-height: 200px;
        border: none;
        border-bottom: 1px solid var(--border-color);
    }

    .panel-main {
        min-height: 300px;
    }

    .sponsor-affix {
        bottom: 10px;
        left: 10px;
    }

    .sponsor-collapsed {
        width: 36px;
        height: 36px;
    }
}

/* tablet */

@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .panel-left {
        width: 200px;
    }

    .panel-right {
        width: 220px;
    }

    .mode-btn,
    .quick-grid-btn,
    .btn {
        min-height: 44px;
        font-size: 13px;
    }

    .zoom-btn,
    .history-btn {
        width: 36px;
        height: 36px;
    }

    .zoom-btn svg,
    .history-btn svg {
        width: 18px;
        height: 18px;
    }

    input[type="range"] {
        height: 6px;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }

    .upload-area {
        padding: 30px 15px;
    }

    .upload-icon {
        width: 40px;
        height: 40px;
    }

    .preview-item {
        padding: 8px 10px;
    }

    .preview-item img {
        width: 44px;
        height: 44px;
    }

    .action-btn {
        width: 32px;
        height: 32px;
    }

    .collapsible .section-header {
        padding: 12px;
        font-size: 12px;
    }

    input[type="number"],
    input[type="text"],
    select {
        min-height: 36px;
        font-size: 13px;
    }

    input[type="color"] {
        width: 44px;
        height: 36px;
    }

    .btn-icon {
        width: 36px;
        height: 36px;
    }

    .btn-icon svg {
        width: 18px;
        height: 18px;
    }

    .sponsor-collapsed {
        width: 50px;
        height: 50px;
    }

    .sponsor-collapsed .sponsor-icon {
        width: 24px;
        height: 24px;
    }
}

/* phone */

@media (max-width: 767px) and (orientation: portrait) {
    body {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        touch-action: auto;
    }

    .app-container {
        height: auto !important;
        min-height: 100vh;
        overflow-y: visible;
    }

    .app-header {
        flex-direction: column;
        padding: 10px 16px 0;
        position: sticky;
        top: 0;
        z-index: 100;
        background: var(--bg-panel);
    }

    .app-header h1 {
        font-size: 18px;
        margin-bottom: 8px;
    }

    .header-actions {
        position: static;
        transform: none;
        width: 100%;
        justify-content: center;
        margin-bottom: 12px;
    }

    .publish-link {
        padding: 4px 10px;
        font-size: 12px;
    }

    .publish-link span {
        display: inline;
    }

    .theme-toggle {
        padding: 6px 10px;
    }

    .mobile-tabs {
        display: flex;
        width: 100%;
        border-bottom: 2px solid var(--border-color);
        margin: 0 -16px;
        padding: 0 16px;
        background: var(--bg-panel);
    }

    .mobile-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        padding: 10px 8px;
        border: none;
        background: transparent;
        color: var(--text-muted);
        cursor: pointer;
        transition: all 0.2s;
        position: relative;
        font-size: 11px;
    }

    .mobile-tab svg {
        width: 22px;
        height: 22px;
        stroke: currentColor;
    }

    .mobile-tab.active {
        color: var(--accent-color);
    }

    .mobile-tab.active::after {
        content: '';
        position: absolute;
        bottom: -2px;
        left: 0;
        right: 0;
        height: 2px;
        background: var(--accent-color);
    }

    @media (min-width: 768px) {
        .mobile-tabs {
            display: none !important;
        }
    }

    .main-content {
        flex-direction: column;
        min-height: calc(100vh - 140px);
    }

    .panel-left,
    .panel-main,
    .panel-right {
        display: none;
        width: 100%;
        border: none;
        max-height: none;
    }

    body[data-mobile-tab="settings"] .panel-left {
        display: block;
        order: 1;
    }

    body[data-mobile-tab="workspace"] .panel-main {
        display: flex;
        order: 1;
        min-height: 70vh;
    }

    body[data-mobile-tab="resources"] .panel-right {
        display: block;
        order: 1;
    }

    .panel-left {
        overflow-y: auto;
        padding-bottom: 20px;
    }

    .panel-main {
        background: var(--bg-canvas);
    }

    .canvas-header {
        padding: 8px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .canvas-title {
        display: none;
    }

    .zoom-controls {
        flex: 1;
        justify-content: center;
    }

    .history-controls {
        flex: 1;
        justify-content: center;
        margin-left: 0;
    }

    .canvas-header .hint {
        width: 100%;
        text-align: center;
        font-size: 10px;
    }

    .canvas-container {
        touch-action: none;
        -webkit-user-select: none;
        user-select: none;
    }

    #mainCanvas {
        touch-action: none;
    }

    .panel-right {
        overflow-y: auto;
        padding-bottom: 20px;
    }

    .btn {
        min-height: 48px;
        font-size: 15px;
        padding: 12px 16px;
    }

    .mode-btn,
    .quick-grid-btn {
        min-height: 44px;
        font-size: 14px;
        padding: 10px 12px;
    }

    .zoom-btn,
    .history-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
    }

    .zoom-btn svg,
    .history-btn svg {
        width: 20px;
        height: 20px;
    }

    .action-btn {
        width: 42px;
        height: 42px;
    }

    .action-btn svg {
        width: 18px;
        height: 18px;
    }

    .control-group {
        margin-bottom: 16px;
    }

    .control-row {
        gap: 12px;
    }

    input[type="number"],
    input[type="text"],
    select {
        min-height: 44px;
        font-size: 16px;
        padding: 10px 12px;
    }

    input[type="range"] {
        height: 8px;
        -webkit-tap-highlight-color: transparent;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 28px;
        height: 28px;
    }

    input[type="color"] {
        width: 54px;
        height: 44px;
    }

    .btn-icon {
        width: 44px;
        height: 44px;
        min-width: 44px;
    }

    .btn-icon svg {
        width: 20px;
        height: 20px;
    }

    .upload-area {
        padding: 40px 20px;
        margin-bottom: 16px;
    }

    .upload-icon {
        width: 52px;
        height: 52px;
    }

    .upload-text {
        font-size: 14px;
    }

    .collapsible .section-header {
        padding: 14px 16px;
        font-size: 13px;
        -webkit-tap-highlight-color: transparent;
    }

    .collapse-icon {
        width: 16px;
        height: 16px;
    }

    .panel h2 {
        font-size: 13px;
        margin-bottom: 14px;
    }

    .mode-switch {
        gap: 10px;
    }

    .quick-grids {
        gap: 8px;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
    }

    .preview-list {
        gap: 10px;
        padding-right: 0;
    }

    .preview-item {
        padding: 12px 14px;
        -webkit-tap-highlight-color: transparent;
    }

    .preview-item img {
        width: 52px;
        height: 52px;
    }

    .preview-item .index {
        min-width: 26px;
        font-size: 12px;
    }

    .preview-item .preview-name {
        font-size: 14px;
    }

    .preview-item .preview-actions {
        opacity: 1;
    }

    .image-info {
        padding: 12px;
        font-size: 12px;
    }

    .modal-content {
        max-width: 95vw;
        max-height: 95vh;
    }

    .modal-header {
        padding: 14px 16px;
    }

    .modal-header h3 {
        font-size: 15px;
    }

    .modal-close {
        width: 32px;
        height: 32px;
        font-size: 24px;
    }

    .modal-body {
        padding: 16px;
    }

    .crop-canvas-container {
        min-height: 300px;
        max-height: 55vh;
    }

    .crop-info {
        font-size: 12px;
        padding: 10px;
    }

    .crop-actions {
        flex-wrap: wrap;
        gap: 10px;
    }

    .crop-actions .btn {
        flex: 1;
        min-width: 120px;
    }

    .image-preview-content {
        max-width: 95vw;
        max-height: 95vh;
    }

    .image-preview-content img {
        max-height: 85vh;
    }

    .image-preview-info {
        font-size: 13px;
        padding: 10px 16px;
    }

    .sponsor-affix {
        bottom: 80px;
        right: 16px;
        left: auto;
    }

    .sponsor-collapsed {
        width: 56px;
        height: 56px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .sponsor-collapsed .sponsor-icon {
        width: 28px;
        height: 28px;
    }

    .sponsor-expanded {
        bottom: auto;
        top: -260px;
        right: 0;
        left: auto;
    }

    .progress-box {
        padding: 24px 32px;
        margin: 0 20px;
    }

    .value-display {
        min-width: 48px;
        font-size: 14px;
    }

    .zoom-value {
        min-width: 52px;
        font-size: 13px;
    }

    .history-info {
        min-width: 40px;
        font-size: 12px;
    }

    .checkbox-label {
        font-size: 14px;
        -webkit-tap-highlight-color: transparent;
    }

    .checkbox-label input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }

    .control-hint,
    .mode-hint {
        font-size: 12px;
        line-height: 1.5;
    }

    .panel-left::-webkit-scrollbar,
    .panel-right::-webkit-scrollbar,
    .preview-list::-webkit-scrollbar {
        width: 4px;
    }

    button,
    .upload-area,
    .preview-item,
    .action-btn {
        -webkit-tap-highlight-color: transparent;
    }
}

@media (max-width: 374px) and (orientation: portrait) {
    .app-header h1 {
        font-size: 16px;
    }

    .mobile-tab {
        font-size: 10px;
        padding: 8px 4px;
    }

    .mobile-tab svg {
        width: 20px;
        height: 20px;
    }

    .quick-grids {
        grid-template-columns: repeat(3, 1fr);
    }

    .zoom-controls {
        gap: 4px;
    }

    .zoom-btn,
    .history-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }

    .crop-actions .btn {
        min-width: 100px;
        font-size: 13px;
    }

    .sponsor-collapsed {
        width: 48px;
        height: 48px;
    }

    .sponsor-collapsed .sponsor-icon {
        width: 24px;
        height: 24px;
    }
}
