* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 20px;
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.main-content {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 20px;
}

/* 控制面板 */
.control-panel {
    background: var(--bg-card);
    padding: 25px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    height: fit-content;
    position: sticky;
    top: 20px;
}

.panel-section {
    margin-bottom: 25px;
}

.panel-section label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.form-control {
    width: 100%;
    padding: 12px;
    background: var(--bg-dark);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

textarea.form-control {
    resize: vertical;
    font-family: inherit;
}

.model-info {
    margin-top: 12px;
    padding: 15px;
    background: var(--bg-dark);
    border-radius: 10px;
    font-size: 0.9rem;
    line-height: 1.6;
}

.model-info p {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.model-info strong {
    color: var(--text-primary);
}

.file-input {
    width: 100%;
    padding: 10px;
    background: var(--bg-dark);
    border: 2px dashed var(--border-color);
    border-radius: 10px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
}

.file-input:hover {
    border-color: var(--primary-color);
}

.reference-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.reference-item {
    position: relative;
    display: inline-block;
}

.reference-preview img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid var(--border-color);
}

.delete-reference-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--danger-color);
    color: white;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    z-index: 10;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.delete-reference-btn:hover {
    background: var(--danger-hover);
    transform: scale(1.1);
}

.delete-reference-btn:active {
    transform: scale(0.95);
    background: var(--danger-hover);
}

/* 按钮 */
.btn-primary,
.btn-secondary,
.btn-danger {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    color: white;
    font-size: 1.05rem;
    padding: 14px;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(99, 102, 241, 0.4);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

/* 图像展示区 */
.gallery {
    background: var(--bg-card);
    padding: 25px;
    border-radius: 16px;
    box-shadow: var(--shadow);
    min-height: 500px;
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.image-item {
    position: relative;
    background: var(--bg-dark);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.3s ease;
}

.image-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
}

.image-item img {
    width: 100%;
    height: auto;
    aspect-ratio: auto;
    object-fit: contain;
    display: block;
    background: var(--bg-dark);
    min-height: 200px;
    max-height: 600px;
}

.image-placeholder {
    width: 100%;
    height: 280px;
    min-height: 200px;
    background: linear-gradient(90deg, var(--bg-dark) 25%, var(--bg-hover) 50%, var(--bg-dark) 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
    border-radius: 12px 12px 0 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-info {
    padding: 15px;
}

.image-prompt {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.image-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-close {
    position: absolute;
    top: 30px;
    right: 50px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
}

.modal-close:hover {
    color: var(--danger-color);
}

.modal-content {
    display: block;
    max-width: 90%;
    max-height: 80vh;
    margin: 50px auto;
    object-fit: contain;
}

.modal-caption {
    text-align: center;
    padding: 20px;
    color: white;
}

.modal-caption p {
    margin-bottom: 15px;
    font-size: 1.1rem;
}

/* 响应式设计 */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .control-panel {
        position: static;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    }
}

@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .header-actions {
        width: 100%;
        justify-content: center;
    }

    .control-panel {
        padding: 20px;
    }
    
    /* 手机端删除按钮更大 */
    .delete-reference-btn {
        width: 32px;
        height: 32px;
        font-size: 20px;
        top: -10px;
        right: -10px;
    }
    
    /* 手机端预览图更大，方便操作 */
    .reference-preview img {
        width: 80px;
        height: 80px;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
    }

    .image-item img {
        min-height: 150px;
        max-height: 400px;
    }

    .modal-content {
        max-width: 95%;
        margin: 20px auto;
    }

    .modal-close {
        top: 15px;
        right: 20px;
        font-size: 30px;
    }
}
