* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
    font-size: 2em;
}

h3 {
    color: #555;
    margin-bottom: 15px;
}

.upload-section {
    text-align: center;
    margin-bottom: 30px;
}

.upload-label {
    display: inline-block;
    padding: 15px 30px;
    background: #667eea;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
}

.upload-label:hover {
    background: #5568d3;
    transform: translateY(-2px);
}

.file-name {
    margin-top: 10px;
    color: #666;
    font-style: italic;
}

.mask-selection {
    margin-bottom: 30px;
}

.mask-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    max-height: 300px;
    overflow-y: auto;
    padding: 10px;
    border: 2px solid #eee;
    border-radius: 8px;
}

.mask-item {
    border: 3px solid transparent;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.mask-item:hover {
    border-color: #667eea;
    transform: scale(1.05);
}

.mask-item.selected {
    border-color: #667eea;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.5);
}

.mask-item img {
    width: 100%;
    height: 100px;
    object-fit: contain;
    background: #f5f5f5;
}

.mask-item span {
    display: block;
    padding: 8px;
    font-size: 12px;
    color: #666;
    word-break: break-all;
}

.workspace {
    margin-bottom: 30px;
}

.canvas-container {
    text-align: center;
    margin-bottom: 20px;
    background: #f5f5f5;
    padding: 20px;
    border-radius: 8px;
}

#mainCanvas {
    max-width: 100%;
    height: auto;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
}

.controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group label {
    font-weight: bold;
    color: #555;
}

.control-group input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
}

.control-group span {
    color: #667eea;
    font-weight: bold;
}

.action-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.btn {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-download {
    display: inline-block;
    margin-top: 12px;
    padding: 10px 24px;
    background: #28a745;
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: bold;
    transition: all 0.3s ease;
}

.btn-download:hover {
    background: #218838;
    transform: translateY(-2px);
}

.result-section {
    background: #f9f9f9;
    padding: 20px;
    border-radius: 8px;
    margin-top: 20px;
}

.result-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.result-item {
    text-align: center;
}

.result-item h4 {
    margin-bottom: 10px;
    color: #555;
}

.result-item img {
    max-width: 100%;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.save-path {
    text-align: center;
    color: #666;
    font-style: italic;
    padding: 10px;
    background: #e9ecef;
    border-radius: 5px;
}

@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    h1 {
        font-size: 1.5em;
    }
    
    .mask-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
}

/* Шапка страницы */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 20px;
}

.page-header h1 {
    margin: 0;
    flex: 1;
}

.gallery-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 15px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    transition: all 0.3s ease;
}

.gallery-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.gallery-btn:active {
    transform: translateY(0);
}

/* Адаптивность для шапки */
@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        text-align: center;
    }
    
    .page-header h1 {
        font-size: 1.5em;
    }
    
    .gallery-btn {
        width: 100%;
        justify-content: center;
    }
}

/* Уведомление о режиме редактирования */
.edit-mode-notice {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(135deg, #fff3cd 0%, #ffe69c 100%);
    border: 2px solid #ffc107;
    border-radius: 10px;
    margin-bottom: 20px;
    color: #856404;
    font-weight: 500;
}

/* Предпросмотр изображения в режиме редактирования */
.edit-image-preview {
    margin-top: 15px;
    text-align: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    border: 2px dashed #667eea;
}

.edit-image-preview img {
    max-width: 300px;
    max-height: 200px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.edit-image-preview span {
    display: block;
    margin-top: 10px;
    color: #666;
    font-size: 14px;
}

/* Отключенная кнопка загрузки */
.upload-label.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #ccc;
}

/* Кнопки действий в карточке */
.action-buttons-small {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-edit-small {
    display: inline-block;
    padding: 6px 15px;
    background: #667eea;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn-edit-small:hover {
    background: #5568d3;
    transform: translateY(-2px);
}

.btn-download-small {
    display: inline-block;
    padding: 6px 15px;
    background: #28a745;
    color: white;
    text-decoration: none;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn-download-small:hover {
    background: #218838;
    transform: translateY(-2px);
}

/* Действия после редактирования */
.edit-actions {
    text-align: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #e8e8e8;
}