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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

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

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow);
}

/* Upload Section */
.drop-zone {
    border: 3px dashed var(--border-color);
    border-radius: 12px;
    padding: 4rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-color);
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary-color);
    background: #f0f9ff;
}

.drop-zone-content svg {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.drop-zone-content p {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.drop-zone-content .hint {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Loading */
.loading {
    text-align: center;
    padding: 3rem;
}

.spinner {
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Editor Layout */
.editor-layout {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 2rem;
    min-height: 600px;
}

/* Controls Panel */
.controls-panel {
    border-right: 1px solid var(--border-color);
    padding-right: 2rem;
    overflow-y: auto;
    max-height: 85vh;
}

.controls-panel h3 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.divider {
    height: 1px;
    background: var(--border-color);
    margin: 2rem 0;
}

/* Masks List */
.masks-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.mask-chip {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--card-bg);
    font-size: 0.9rem;
}

.mask-chip:hover {
    border-color: var(--primary-color);
    background: #f0f9ff;
}

.mask-chip.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.mask-chip .percentage {
    font-size: 0.8rem;
    opacity: 0.7;
    margin-left: 0.3rem;
}

/* Controls */
.controls-group {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.control {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.control-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

.control-header input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.control-header span:first-of-type {
    flex: 1;
}

.control > label {
    display: flex;
    flex-direction: column;
    font-weight: 600;
    color: var(--text-primary);
}

.control-hint {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-secondary);
    font-style: italic;
}

.slider-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg-color);
    border-radius: 8px;
}

.slider-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.slider-label span {
    min-width: 40px;
    text-align: right;
    font-weight: 600;
    color: var(--text-primary);
}

input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-hover);
    transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
}

.info-box {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.85rem;
    color: #166534;
}

.info-box strong {
    display: block;
    margin-bottom: 0.5rem;
}

.info-box ul {
    margin-left: 1.5rem;
}

.info-box li {
    margin-bottom: 0.25rem;
}

/* Preview Panel */
.preview-panel {
    display: flex;
    flex-direction: column;
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.preview-header h3 {
    font-size: 1.2rem;
}

/* Toggle Switch */
.toggle-switch {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toggle-input {
    display: none;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
}

.toggle-text {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.toggle-slider {
    position: relative;
    width: 48px;
    height: 24px;
    background: var(--border-color);
    border-radius: 24px;
    transition: background 0.3s ease;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
    box-shadow: var(--shadow);
}

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

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

/* Canvas Container */
.canvas-container {
    flex: 1;
    position: relative;
    background: var(--bg-color);
    border-radius: 8px;
    overflow: hidden;
    min-height: 500px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#preview-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: opacity 0.3s ease;
}

.canvas-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Preview Actions */
.preview-actions {
    margin-top: 1.5rem;
    display: flex;
    gap: 1rem;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: white;
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
}

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

/* Responsive */
@media (max-width: 1200px) {
    .editor-layout {
        grid-template-columns: 350px 1fr;
    }
}

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

    .controls-panel {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding-right: 0;
        padding-bottom: 2rem;
        max-height: none;
    }
}

/* Hide/Show sections */
.section.active {
    display: block;
}

.section:not(.active) {
    display: none;
}

