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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --surface-hover: #334155;
    --border-color: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --radius: 12px;
    --radius-sm: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    padding: 40px 20px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Upload Section */
.upload-section {
    max-width: 600px;
    margin: 0 auto;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--surface-color);
}

.upload-area:hover {
    border-color: var(--primary-color);
    background: var(--surface-hover);
}

.upload-area.drag-over {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.upload-icon {
    font-size: 4rem;
    margin-bottom: 20px;
}

.upload-area h3 {
    font-size: 1.3rem;
    margin-bottom: 8px;
}

.upload-area p {
    color: var(--text-secondary);
}

.upload-hint {
    font-size: 0.9rem;
    margin-top: 15px;
}

/* Editor Section */
.editor-section {
    margin-top: 30px;
}

.editor-layout {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 30px;
}

@media (max-width: 1024px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }
}

/* Panels */
.preview-panel,
.options-panel {
    background: var(--surface-color);
    border-radius: var(--radius);
    padding: 20px;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.panel-icon {
    font-size: 1.2rem;
}

/* Preview */
.preview-container {
    background: #0a0a0a;
    border-radius: var(--radius-sm);
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    overflow: hidden;
}

#previewCanvas {
    max-width: 100%;
    max-height: 500px;
    object-fit: contain;
}

.image-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.info-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* Options */
.option-group {
    margin-bottom: 25px;
}

.option-label {
    display: block;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

/* Mode Selector */
.mode-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.mode-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 15px 10px;
    background: var(--surface-hover);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-option:hover {
    background: rgba(99, 102, 241, 0.1);
}

.mode-option.active {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.15);
}

.mode-icon {
    color: var(--text-secondary);
}

.mode-option.active .mode-icon {
    color: var(--primary-color);
}

.mode-option span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.mode-option.active span {
    color: var(--text-primary);
}

/* Sliders */
.slider-group {
    margin-bottom: 15px;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.slider-value {
    color: var(--primary-color);
    font-weight: 600;
}

.slider {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.split-preview-text {
    background: rgba(99, 102, 241, 0.1);
    padding: 12px 15px;
    border-radius: var(--radius-sm);
    text-align: center;
    color: var(--text-secondary);
}

.split-preview-text strong {
    color: var(--primary-color);
    font-size: 1.2rem;
}

/* Toggle */
.toggle-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
}

.toggle {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--border-color);
    transition: 0.3s;
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    transition: 0.3s;
    border-radius: 50%;
}

.toggle input:checked + .toggle-slider {
    background: var(--primary-color);
}

.toggle input:checked + .toggle-slider:before {
    transform: translateX(24px);
}

/* Border Options */
.border-options,
.trim-options {
    margin-top: 15px;
    padding: 15px;
    background: var(--surface-hover);
    border-radius: var(--radius-sm);
}

.option-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 10px;
    opacity: 0.8;
}

/* Trim Mode Selector */
.trim-mode-group {
    margin-bottom: 15px;
}

.trim-mode-label {
    display: block;
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.trim-mode-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.trim-mode-option {
    flex: 1;
    min-width: 70px;
}

.trim-mode-option input {
    display: none;
}

.trim-mode-btn {
    display: block;
    padding: 8px 6px;
    text-align: center;
    background: var(--surface-color);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.trim-mode-btn:hover {
    background: rgba(99, 102, 241, 0.1);
}

.trim-mode-option input:checked + .trim-mode-btn {
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.15);
    color: var(--text-primary);
}

.custom-color-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px;
    background: var(--surface-color);
    border-radius: var(--radius-sm);
}

.custom-color-group input[type="color"] {
    width: 50px;
    height: 32px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.color-picker-group {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.color-picker-group input[type="color"] {
    width: 40px;
    height: 30px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* Output Format */
.output-format {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.output-format select {
    padding: 8px 15px;
    background: var(--surface-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
}

.output-format select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Buttons */
.action-buttons {
    display: flex;
    gap: 10px;
    margin-top: 30px;
}

.btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

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

.btn-secondary:hover {
    background: var(--border-color);
}

/* Result Section */
.result-section {
    background: var(--surface-color);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 30px;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.result-item {
    background: var(--surface-hover);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: transform 0.2s ease;
}

.result-item:hover {
    transform: scale(1.02);
}

.result-item img {
    width: 100%;
    height: 120px;
    object-fit: contain;
    background: #0a0a0a;
    padding: 10px;
}

.result-item-info {
    padding: 10px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.result-item-download {
    display: block;
    padding: 8px;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    text-align: center;
    font-size: 0.85rem;
    transition: background 0.2s ease;
}

.result-item-download:hover {
    background: var(--primary-hover);
}

.result-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.result-actions .btn {
    flex: none;
    min-width: 180px;
}

/* Footer */
footer {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    z-index: 1000;
}

.loading-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);
    }
}

/* Auto Detect Group */
.auto-detect-info {
    margin-bottom: 15px;
}

.auto-detect-hint {
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding: 10px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--primary-color);
}

.auto-detect-result {
    margin-top: 15px;
    padding: 10px;
    background: var(--surface-hover);
    border-radius: var(--radius-sm);
    text-align: center;
}

.auto-detect-result strong {
    color: var(--success-color);
}

.btn-small {
    margin-top: 10px;
    padding: 8px 16px;
    font-size: 0.85rem;
    width: 100%;
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }
    
    .mode-selector {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .image-info {
        grid-template-columns: 1fr;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .result-actions {
        flex-direction: column;
    }
    
    .result-actions .btn {
        width: 100%;
    }
}
