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

body {
    font-family: 'Arial', 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: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

h1 {
    text-align: center;
    padding: 30px 0;
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
    font-size: 2.5em;
    margin-bottom: 0;
}

.upload-section {
    padding: 40px;
}

.upload-area {
    border: 3px dashed #667eea;
    border-radius: 15px;
    padding: 60px 20px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    background: #f8f9ff;
}

.upload-area:hover {
    border-color: #764ba2;
    background: #f0f2ff;
    transform: translateY(-2px);
}

.upload-area.dragover {
    border-color: #764ba2;
    background: #e8ebff;
    transform: scale(1.02);
}

#imageInput {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.upload-text p {
    font-size: 1.5em;
    color: #333;
    margin-bottom: 10px;
}

.upload-text span {
    color: #666;
    font-size: 1em;
}

.preview-section {
    padding: 40px;
    border-top: 1px solid #eee;
}

.preview-section h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.8em;
    text-align: center;
}

.original-image-container {
    text-align: center;
    margin-bottom: 30px;
}

#originalImage {
    max-width: 100%;
    max-height: 400px;
    border-radius: 10px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.grid-section {
    padding: 40px;
    border-top: 1px solid #eee;
    background: #f8f9ff;
}

.grid-section h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.8em;
    text-align: center;
}

.grid-header {
    margin-bottom: 30px;
}

.spacing-control {
    text-align: center;
    margin-top: 15px;
    padding: 15px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.format-control {
    text-align: center;
    margin-top: 10px;
    padding: 15px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.spacing-control label,
.format-control label {
    font-weight: bold;
    color: #333;
    margin-right: 10px;
}

#formatSelect {
    padding: 5px 10px;
    border: 2px solid #ddd;
    border-radius: 6px;
    background: white;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.margin-controls,
.gap-controls {
    text-align: center;
    margin-top: 10px;
    padding: 20px;
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.margin-controls h4,
.gap-controls h4 {
    margin-bottom: 15px;
    color: #333;
    font-size: 16px;
}

.margin-grid,
.gap-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.margin-item,
.gap-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.margin-item label,
.gap-item label {
    font-weight: bold;
    color: #555;
    font-size: 14px;
}

.margin-item input[type="range"],
.gap-item input[type="range"] {
    width: 120px;
    accent-color: #667eea;
}

.margin-item span,
.gap-item span {
    font-weight: bold;
    color: #667eea;
    background: #f0f2ff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.btn-small {
    padding: 8px 16px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.3s ease;
}

.btn-small:hover {
    background: #c82333;
    transform: translateY(-1px);
}

#spacingSlider {
    width: 200px;
    margin: 0 10px;
    accent-color: #667eea;
}

#spacingValue {
    font-weight: bold;
    color: #667eea;
    background: #f0f2ff;
    padding: 4px 8px;
    border-radius: 4px;
}

.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    max-width: 600px;
    margin: 0 auto 40px auto;
}

.grid-item {
    border: 1px solid #ddd;
    cursor: pointer;
    transition: all 0.3s ease;
    background: white;
    display: block;
    position: relative;
}

.grid-item:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
    border-color: #667eea;
}

.grid-item:hover::after {
    content: attr(data-position);
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 10;
}

.grid-item.selected {
    border-color: #667eea;
    border-width: 3px;
    box-shadow: 0 0 15px rgba(102, 126, 234, 0.5);
}

.download-buttons {
    text-align: center;
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
}

.download-buttons button {
    padding: 12px 30px;
    font-size: 1.1em;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: bold;
}

#downloadAll {
    background: linear-gradient(45deg, #667eea, #764ba2);
    color: white;
}

#downloadAll:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(102, 126, 234, 0.3);
}

#downloadAllZip {
    background: linear-gradient(45deg, #4CAF50, #45a049);
    color: white;
}

#downloadAllZip:hover {
    background: linear-gradient(45deg, #45a049, #3d8b40);
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(76, 175, 80, 0.3);
}

#downloadSelected {
    background: #28a745;
    color: white;
}

#downloadSelected:hover {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(40, 167, 69, 0.3);
}

#reset {
    background: #dc3545;
    color: white;
}

#reset:hover {
    background: #c82333;
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(220, 53, 69, 0.3);
}

/* 响应式设计 */
@media (max-width: 768px) {
    .container {
        margin: 0 10px;
        border-radius: 15px;
    }
    
    h1 {
        font-size: 2em;
        padding: 20px 0;
    }
    
    .upload-section,
    .preview-section,
    .grid-section {
        padding: 20px;
    }
    
    .upload-area {
        padding: 40px 15px;
    }
    
    .grid-container {
        max-width: 300px;
        gap: 10px;
    }
    
    .download-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .download-buttons button {
        width: 200px;
    }
    
    /* 边距和间距控制移动端调整 */
    .margin-grid,
    .gap-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .margin-item input[type="range"],
    .gap-item input[type="range"] {
        width: 150px;
    }
}

@media (max-width: 480px) {
    .upload-text p {
        font-size: 1.2em;
    }
    
    .grid-container {
        max-width: 250px;
        gap: 8px;
    }
}