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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f0f23;
    color: #e0e0e0;
    min-height: 100vh;
}

#app {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

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

header h1 {
    font-size: 2rem;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: #888;
    margin-top: 4px;
    font-size: 0.95rem;
}

/* Upload Zone */
.dropzone {
    border: 2px dashed #444;
    border-radius: 16px;
    padding: 60px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #1a1a2e;
    margin: 20px 0;
}

.dropzone:hover,
.dropzone.dragover {
    border-color: #667eea;
    background: #1e1e3a;
}

.dropzone-content {
    pointer-events: none;
}

.upload-icon {
    color: #555;
    margin-bottom: 16px;
}

.dropzone:hover .upload-icon {
    color: #667eea;
}

.dropzone p {
    font-size: 1.1rem;
    margin-bottom: 8px;
}

.file-limit {
    color: #666;
    font-size: 0.85rem;
}

/* Toolbar */
#toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: #1a1a2e;
    border-radius: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    border-right: 1px solid #333;
}

.tool-group:last-child {
    border-right: none;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: #aaa;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    white-space: nowrap;
}

.tool-btn:hover {
    background: #2a2a4a;
    color: #fff;
}

.tool-btn.active {
    background: #667eea;
    color: #fff;
}

.tool-btn svg {
    flex-shrink: 0;
}

/* Canvas */
#canvas-wrapper {
    display: flex;
    justify-content: center;
    overflow: auto;
    background: #111;
    border-radius: 12px;
    padding: 16px;
    min-height: 300px;
}

#canvas-container {
    position: relative;
    display: inline-block;
    cursor: crosshair;
}

#image-canvas,
#mask-canvas {
    display: block;
}

#mask-canvas,
#preview-canvas {
    position: absolute;
    top: 0;
    left: 0;
}

#preview-canvas {
    pointer-events: auto;
}

/* Action Bar */
#action-bar {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 16px 0;
}

.primary-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 32px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.secondary-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: #2a2a4a;
    color: #ccc;
    border: 1px solid #444;
    border-radius: 12px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s;
}

.secondary-btn:hover {
    background: #3a3a5a;
    color: #fff;
}

/* Result Comparison */
#result-view h2 {
    text-align: center;
    margin-bottom: 16px;
    font-size: 1.3rem;
}

#comparison-container {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

#comparison-slider {
    position: relative;
    display: inline-block;
    overflow: hidden;
    border-radius: 12px;
    max-width: 100%;
    user-select: none;
    -webkit-user-select: none;
}

#comparison-before,
#comparison-after {
    position: relative;
}

#comparison-before img {
    display: block;
    max-width: 100%;
    height: auto;
}

#comparison-after {
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 100%;
    overflow: hidden;
}

#comparison-after img {
    display: block;
    max-width: none;
    height: auto;
}

.comparison-label {
    position: absolute;
    bottom: 12px;
    padding: 4px 12px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border-radius: 6px;
    font-size: 0.85rem;
}

#comparison-before .comparison-label {
    right: 12px;
}

#comparison-after .comparison-label {
    left: 12px;
}

#slider-handle {
    position: absolute;
    top: 0;
    left: 50%;
    width: 4px;
    height: 100%;
    cursor: ew-resize;
    z-index: 10;
    transform: translateX(-50%);
}

.slider-line {
    position: absolute;
    top: 0;
    left: 50%;
    width: 2px;
    height: 100%;
    background: #fff;
    transform: translateX(-50%);
}

.slider-circle {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    background: #fff;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.slider-circle svg {
    color: #333;
}

#result-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
}

/* Compress Panel */
#compress-panel {
    background: #1a1a2e;
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 20px;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
}

#compress-panel h3 {
    font-size: 1rem;
    color: #667eea;
    margin-bottom: 16px;
    text-align: center;
}

.compress-controls {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.compress-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.compress-row label {
    font-size: 0.9rem;
    color: #aaa;
    min-width: 40px;
}

.compress-row select {
    flex: 1;
    padding: 6px 10px;
    background: #2a2a4a;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
}

.quality-slider {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
}

.quality-slider input[type="range"] {
    flex: 1;
    accent-color: #667eea;
}

#compress-quality-value {
    font-size: 0.9rem;
    color: #aaa;
    min-width: 36px;
    text-align: right;
}

.compress-info {
    display: flex;
    justify-content: space-between;
    background: #111;
    border-radius: 8px;
    padding: 12px 16px;
    margin-top: 4px;
}

.size-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.size-label {
    font-size: 0.75rem;
    color: #666;
}

.size-value {
    font-size: 0.9rem;
    color: #e0e0e0;
    font-weight: 600;
}

.compressed-btn {
    background: linear-gradient(135deg, #2d8a4e, #1a6b38);
}

.compressed-btn:hover {
    box-shadow: 0 4px 20px rgba(45, 138, 78, 0.4);
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-content {
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #333;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

#loading-text {
    color: #ccc;
    font-size: 1rem;
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    color: #fff;
    font-size: 0.9rem;
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

.toast.success { background: #2d8a4e; }
.toast.error { background: #c0392b; }
.toast.info { background: #2980b9; }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Help Modal */
#help-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    background: #1a1a2e;
    border-radius: 16px;
    width: 90%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px 12px;
    border-bottom: 1px solid #333;
}

.modal-header h3 {
    font-size: 1.2rem;
    color: #fff;
}

.modal-close {
    background: none;
    border: none;
    color: #888;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.modal-close:hover {
    color: #fff;
}

.modal-body {
    padding: 16px 24px 24px;
}

.help-section {
    margin-bottom: 20px;
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h4 {
    font-size: 0.95rem;
    color: #667eea;
    margin-bottom: 10px;
}

.help-steps {
    padding-left: 20px;
    color: #ccc;
    font-size: 0.9rem;
    line-height: 1.8;
}

.help-item {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    align-items: flex-start;
}

.help-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    background: #2a2a4a;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #667eea;
}

.help-item strong {
    color: #fff;
    font-size: 0.9rem;
}

.help-item p {
    color: #aaa;
    font-size: 0.85rem;
    margin-top: 2px;
    line-height: 1.5;
}

.help-shortcuts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.shortcut {
    color: #aaa;
    font-size: 0.85rem;
}

.shortcut kbd {
    display: inline-block;
    padding: 2px 8px;
    background: #2a2a4a;
    border: 1px solid #444;
    border-radius: 4px;
    color: #ddd;
    font-family: inherit;
    font-size: 0.8rem;
    margin-right: 4px;
}

/* Responsive */
@media (max-width: 768px) {
    #app {
        padding: 12px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .dropzone {
        padding: 40px 16px;
    }

    #toolbar {
        gap: 4px;
        padding: 8px;
    }

    .tool-group {
        padding: 0 4px;
    }

    .tool-btn span {
        display: none;
    }

    .tool-btn {
        padding: 8px;
    }

    .primary-btn {
        padding: 10px 24px;
        font-size: 0.9rem;
    }

    #result-actions {
        flex-direction: column;
        align-items: center;
    }

    #compress-panel {
        padding: 16px;
    }

    .compress-info {
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    .dropzone {
        padding: 30px 12px;
    }

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

    .dropzone p {
        font-size: 0.95rem;
    }
}
