/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, 'Segoe UI', system-ui, sans-serif;
    background: #0a0a0f;
    color: #e2e8f0;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* ===== ANIMATED BACKGROUND ===== */
.bg-particles {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
}
.bg-particles span {
    position: absolute;
    width: 4px;
    height: 4px;
    background: rgba(99, 102, 241, 0.12);
    border-radius: 50%;
    animation: float-particle linear infinite;
}
@keyframes float-particle {
    0% { transform: translateY(100vh) scale(0); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translateY(-10vh) scale(1); opacity: 0; }
}

.glow {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(ellipse at 30% 50%, rgba(99, 102, 241, 0.08), transparent 60%);
    z-index: 0;
    pointer-events: none;
}

/* ===== HEADER ===== */
.header {
    position: relative;
    z-index: 1;
    padding: 24px 16px 16px;
    text-align: center;
    background: linear-gradient(180deg, rgba(10, 10, 15, 0.9) 0%, transparent 100%);
}
.header .logo {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-size: clamp(28px, 7vw, 48px);
    font-weight: 800;
    letter-spacing: -1.5px;
    background: linear-gradient(135deg, #818cf8, #a78bfa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-shadow: 0 0 60px rgba(129, 140, 248, 0.2);
}
.header .logo .icon {
    font-size: clamp(32px, 7vw, 52px);
    -webkit-text-fill-color: initial;
    background: none;
    filter: drop-shadow(0 0 20px rgba(129, 140, 248, 0.3));
}
.header .tagline {
    color: #64748b;
    font-size: clamp(13px, 2.5vw, 18px);
    margin-top: 4px;
    font-weight: 300;
    letter-spacing: 0.3px;
}
.header .tagline span {
    color: #a78bfa;
    font-weight: 500;
}

/* ===== VERSION BADGE ===== */
.version-badge {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0;
    padding: 3px 10px;
    border-radius: 20px;
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.2);
    -webkit-text-fill-color: #10b981;
    background-clip: initial;
    text-shadow: none;
    vertical-align: middle;
    margin-left: 4px;
    position: relative;
    top: -4px;
}

/* ===== CONTAINER ===== */
.container {
    position: relative;
    z-index: 1;
    max-width: 1300px;
    margin: 0 auto;
    padding: 0 12px 20px;
}

/* ===== PRESETS ===== */
.presets-container {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 16px 18px;
    margin-bottom: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.presets-container .presets-header,
.saved-palettes-container .presets-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}
.presets-container .presets-header h4,
.saved-palettes-container .presets-header h4 {
    font-size: 14px;
    font-weight: 600;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 8px;
}
.presets-container .presets-header .preset-hint,
.saved-palettes-container .presets-header .preset-hint {
    font-size: 12px;
    color: #64748b;
}
.presets-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 10px;
}
.preset-btn {
    padding: 10px 8px;
    border: 2px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    color: #e2e8f0;
    cursor: pointer;
    transition: all 0.25s ease;
    font-size: 22px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: relative;
}
.preset-btn:active {
    transform: scale(0.92);
}
.preset-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(129, 140, 248, 0.2);
    transform: translateY(-2px);
}
.preset-btn .preview-colors {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
}
.preset-btn .preview-colors span {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: transform 0.2s;
}
.preset-btn:hover .preview-colors span {
    transform: scale(1.05);
}
.preset-btn .preset-icon {
    font-size: 22px;
    line-height: 1;
}
.preset-btn .preset-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) scale(0.8);
    background: rgba(15, 15, 23, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 4px 12px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 500;
    color: #e2e8f0;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.preset-btn:hover .preset-tooltip,
.preset-btn:active .preset-tooltip {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}
.preset-btn .preset-tooltip .tooltip-count {
    color: #64748b;
    font-weight: 400;
    margin-left: 4px;
}
.preset-btn.active {
    background: rgba(129, 140, 248, 0.12);
    border-color: rgba(129, 140, 248, 0.3);
    box-shadow: 0 0 30px rgba(129, 140, 248, 0.1);
}
.preset-btn.active::after {
    content: 'вњ“';
    position: absolute;
    top: -6px;
    right: -6px;
    background: linear-gradient(135deg, #818cf8, #7c3aed);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 0 20px rgba(129, 140, 248, 0.4);
    border: 2px solid rgba(10, 10, 15, 0.8);
}

/* ===== SAVED PALETTES ===== */
.saved-palettes-container {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 16px 18px;
    margin-bottom: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.saved-palettes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}
.saved-palette-btn {
    position: relative;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    color: #e2e8f0;
    font-family: inherit;
    display: flex;
    flex-direction: column;
    gap: 6px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}
.saved-palette-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(129, 140, 248, 0.25);
    transform: translateY(-2px);
}
.saved-palette-btn:active {
    transform: scale(0.97);
}
.saved-palette-name {
    font-size: 13px;
    font-weight: 600;
    color: #e2e8f0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 20px;
}
.saved-palette-preview {
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
}
.saved-palette-preview span {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.saved-palette-count {
    font-size: 11px;
    color: #64748b;
}
.saved-palette-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    font-size: 11px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid rgba(239, 68, 68, 0.15);
}
.saved-palette-delete:hover {
    background: rgba(239, 68, 68, 0.3);
    transform: scale(1.1);
}

/* ===== PRIORITY SLIDERS ===== */
.priority-container {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 16px 18px;
    margin-bottom: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.priority-container .priority-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}
.priority-container .priority-header h4 {
    font-size: 14px;
    font-weight: 600;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 8px;
}
.priority-container .priority-header .priority-hint {
    font-size: 12px;
    color: #64748b;
}
.priority-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}
.priority-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: rgba(255, 255, 255, 0.03);
    padding: 8px 12px 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}
.priority-item .priority-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 500;
    color: #94a3b8;
}
.priority-item .priority-label .color-dot {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
    margin-right: 6px;
}
.priority-item .priority-label .label-text {
    display: flex;
    align-items: center;
    gap: 4px;
}
.priority-item .priority-label .priority-value {
    font-weight: 700;
    color: #e2e8f0;
    font-size: 13px;
    min-width: 28px;
    text-align: right;
}
.priority-item input[type="range"] {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(90deg, #4f46e5, #a78bfa);
    border-radius: 2px;
    outline: none;
}
.priority-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: radial-gradient(circle, #818cf8, #4f46e5);
    cursor: pointer;
    box-shadow: 0 0 16px rgba(129, 140, 248, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
}
.priority-item input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: radial-gradient(circle, #818cf8, #4f46e5);
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

/* ===== CONTROLS ===== */
.controls {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 16px 18px;
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.controls .group {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.04);
    padding: 4px 12px 4px 16px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    flex: 0 1 auto;
    min-width: 0;
}
.controls label {
    font-size: 12px;
    font-weight: 500;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.controls label .emoji {
    font-size: 14px;
}
.controls input[type="range"] {
    width: 90px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(90deg, #4f46e5, #a78bfa);
    border-radius: 2px;
    outline: none;
    flex-shrink: 0;
}
.controls input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: radial-gradient(circle, #818cf8, #4f46e5);
    cursor: pointer;
    box-shadow: 0 0 20px rgba(129, 140, 248, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.2s;
}
.controls input[type="range"]::-webkit-slider-thumb:active {
    transform: scale(1.2);
}
.controls input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: radial-gradient(circle, #818cf8, #4f46e5);
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.1);
}
.controls .value-badge {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    padding: 2px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 700;
    min-width: 28px;
    text-align: center;
    box-shadow: 0 0 20px rgba(79, 70, 229, 0.25);
    flex-shrink: 0;
}

.controls .btn {
    padding: 10px 18px;
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    flex: 0 1 auto;
}
.controls .btn:active {
    transform: scale(0.95);
}
.controls .btn-primary {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    box-shadow: 0 4px 20px rgba(79, 70, 229, 0.3);
}
.controls .btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}
.controls .btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    color: #e2e8f0;
    border: 1px solid rgba(255, 255, 255, 0.06);
}
.controls .btn-secondary:active {
    background: rgba(255, 255, 255, 0.12);
}
.controls .btn-success {
    background: linear-gradient(135deg, #059669, #10b981);
    color: white;
    box-shadow: 0 4px 20px rgba(5, 150, 105, 0.25);
}

/* ===== DITHERING SWITCH ===== */
.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}
.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.switch .slider-switch {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    transition: 0.3s;
}
.switch .slider-switch:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background: #64748b;
    border-radius: 50%;
    transition: 0.3s;
}
.switch input:checked + .slider-switch {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    border-color: rgba(129, 140, 248, 0.4);
    box-shadow: 0 0 16px rgba(129, 140, 248, 0.25);
}
.switch input:checked + .slider-switch:before {
    transform: translateX(18px);
    background: #fff;
}

.file-input-wrapper {
    position: relative;
    overflow: hidden;
    display: inline-flex;
    flex-shrink: 0;
}
.file-input-wrapper input[type="file"] {
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}
.file-input-wrapper .fake-btn {
    padding: 10px 18px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    color: #e2e8f0;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}
.file-input-wrapper .fake-btn:active {
    background: rgba(255, 255, 255, 0.12);
    transform: scale(0.95);
}

/* ===== PROGRESS ===== */
.progress-container {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    padding: 16px 18px;
    margin-bottom: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
}
.progress-header .status-text {
    font-weight: 500;
    font-size: clamp(13px, 2vw, 15px);
    color: #e2e8f0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}
.progress-header .status-text .spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(129, 140, 248, 0.2);
    border-top-color: #818cf8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}
.progress-header .status-text .spinner.active {
    display: inline-block;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
.progress-header .percentage-text {
    font-weight: 700;
    font-size: clamp(18px, 4vw, 24px);
    background: linear-gradient(135deg, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    flex-shrink: 0;
}
.progress-bar-track {
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    overflow: hidden;
}
.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #4f46e5, #a78bfa, #c084fc);
    border-radius: 10px;
    width: 0%;
    transition: width 0.4s ease;
    position: relative;
}
.progress-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: shimmer 1.8s infinite;
}
@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}
.progress-steps {
    display: flex;
    gap: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
    justify-content: center;
}
.progress-steps .step {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: clamp(11px, 1.8vw, 13px);
    color: #475569;
    transition: color 0.3s;
}
.progress-steps .step .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    transition: all 0.3s;
    border: 2px solid transparent;
    flex-shrink: 0;
}
.progress-steps .step .dot.active {
    background: #818cf8;
    border-color: rgba(129, 140, 248, 0.3);
    box-shadow: 0 0 16px rgba(129, 140, 248, 0.25);
}
.progress-steps .step .dot.done {
    background: #10b981;
    border-color: rgba(16, 185, 129, 0.2);
}
.progress-steps .step .label {
    font-weight: 500;
    transition: color 0.3s;
    white-space: nowrap;
}
.progress-steps .step .label.active {
    color: #a78bfa;
}
.progress-steps .step .label.done {
    color: #10b981;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}
@media (max-width: 700px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 14px;
    }
}

.image-box {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.image-box .box-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding: 0 2px;
}
.image-box .box-header h3 {
    font-size: clamp(14px, 2.5vw, 16px);
    font-weight: 600;
    color: #e2e8f0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.image-box .box-header .badge {
    font-size: 10px;
    font-weight: 500;
    padding: 2px 10px;
    border-radius: 20px;
    background: rgba(129, 140, 248, 0.12);
    color: #a78bfa;
    border: 1px solid rgba(129, 140, 248, 0.06);
    white-space: nowrap;
}
.image-box .box-content {
    border-radius: 10px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.3);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.image-box .box-content img,
.image-box .box-content canvas {
    width: 100%;
    display: block;
    border-radius: 10px;
}
.image-box .box-content .placeholder {
    color: #64748b;
    font-size: clamp(13px, 2vw, 15px);
    padding: 40px 16px;
    text-align: center;
}
.image-box .box-content .placeholder .big-icon {
    font-size: 36px;
    display: block;
    margin-bottom: 12px;
    opacity: 0.5;
}
.image-box .box-content .placeholder .sub {
    font-size: 12px;
    color: #475569;
    margin-top: 6px;
}

/* ===== PALETTE ===== */
.palette-editor {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    padding: 18px 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.palette-editor .palette-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}
.palette-editor .palette-header h3 {
    font-size: clamp(15px, 2.5vw, 17px);
    font-weight: 600;
    color: #e2e8f0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.palette-editor .palette-header .hint {
    font-size: clamp(11px, 1.6vw, 13px);
    color: #64748b;
    font-weight: 400;
}
.palette-editor .palette-header .hint strong {
    color: #a78bfa;
}
.palette-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.palette-stats-text {
    font-size: clamp(12px, 1.8vw, 14px);
    color: #64748b;
}
.btn-small {
    padding: 7px 12px !important;
    font-size: 12px !important;
}
.btn-small .btn-label {
    font-weight: 500;
}
@media (max-width: 600px) {
    .btn-small .btn-label {
        display: none;
    }
    .btn-small {
        padding: 7px 10px !important;
        font-size: 14px !important;
    }
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}
@media (max-width: 480px) {
    .palette-grid {
        grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
        gap: 10px;
    }
}
.palette-item {
    aspect-ratio: 1;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.06);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    gap: 3px;
    padding: 6px;
    transition: all 0.25s ease;
    cursor: pointer;
    position: relative;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    min-height: 60px;
}
.palette-item:active {
    transform: scale(0.92);
}
.palette-item .percent {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 2px 8px;
    border-radius: 16px;
    font-size: 10px;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.06);
    pointer-events: none;
}
.palette-item .index-label {
    font-size: 9px;
    opacity: 0.5;
    font-weight: 400;
    pointer-events: none;
}
.palette-item .replace-hint {
    position: absolute;
    bottom: 4px;
    right: 4px;
    font-size: 10px;
    opacity: 0.5;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 50%;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    transition: opacity 0.3s;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.palette-item .empty-badge {
    position: absolute;
    top: 3px;
    left: 3px;
    font-size: 8px;
    background: rgba(0, 0, 0, 0.5);
    padding: 1px 6px;
    border-radius: 8px;
    color: #64748b;
    pointer-events: none;
}

.stats-text {
    background: rgba(0, 0, 0, 0.2);
    padding: 12px 14px;
    border-radius: 10px;
    font-size: clamp(12px, 1.6vw, 13px);
    color: #94a3b8;
    max-height: 120px;
    overflow-y: auto;
    font-family: 'SF Mono', 'Fira Code', monospace;
    border: 1px solid rgba(255, 255, 255, 0.04);
}
.stats-text::-webkit-scrollbar {
    width: 3px;
}
.stats-text::-webkit-scrollbar-track {
    background: transparent;
}
.stats-text::-webkit-scrollbar-thumb {
    background: rgba(129, 140, 248, 0.2);
    border-radius: 10px;
}
.stats-text div {
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.stats-text div:last-child { border-bottom: none; }
.stats-text .color-preview {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    vertical-align: middle;
    margin-right: 8px;
    flex-shrink: 0;
}
.stats-text .color-hex {
    font-weight: 500;
    color: #e2e8f0;
    font-size: 12px;
}
.stats-text .color-count {
    color: #475569;
    font-size: 11px;
    flex-shrink: 0;
}

/* ===== TOAST ===== */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    width: 90%;
    max-width: 400px;
}
.toast {
    background: rgba(15, 15, 23, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 14px 18px;
    border-radius: 14px;
    font-size: clamp(13px, 2vw, 14px);
    color: #e2e8f0;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}
.toast.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.toast .toast-icon {
    font-size: 18px;
    flex-shrink: 0;
}
.toast .toast-close {
    background: none;
    border: none;
    color: #475569;
    cursor: pointer;
    font-size: 16px;
    padding: 0 4px;
    transition: color 0.3s;
    flex-shrink: 0;
    touch-action: manipulation;
}
.toast .toast-close:active {
    color: #94a3b8;
}

/* ===== OVERLAY ===== */
.processing-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 50;
    align-items: center;
    justify-content: center;
}
.processing-overlay.show {
    display: flex;
}
.processing-overlay .loader {
    text-align: center;
    padding: 20px;
}
.processing-overlay .loader .spinner-big {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(129, 140, 248, 0.15);
    border-top-color: #818cf8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}
.processing-overlay .loader .label {
    color: #94a3b8;
    font-size: clamp(14px, 2.5vw, 16px);
    font-weight: 500;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
    .controls {
        padding: 12px 14px;
        gap: 10px;
        border-radius: 14px;
    }
    .controls .group {
        padding: 3px 10px 3px 12px;
        gap: 6px;
        flex: 1 1 auto;
        min-width: 0;
    }
    .controls input[type="range"] {
        width: 60px;
        flex: 1;
        min-width: 40px;
        max-width: 120px;
    }
    .controls .btn,
    .file-input-wrapper .fake-btn {
        padding: 10px 14px;
        font-size: 13px;
        flex: 1 1 auto;
        justify-content: center;
        min-width: 44px;
    }
    .controls .btn .btn-label {
        display: none;
    }
    .controls .btn-primary .btn-label {
        display: inline;
    }
    .controls .btn-secondary .btn-label {
        display: inline;
    }
    .controls .btn-success .btn-label {
        display: inline;
    }
    .progress-steps {
        gap: 8px;
    }
    .progress-steps .step .label {
        font-size: 10px;
    }
    .progress-steps .step .dot {
        width: 6px;
        height: 6px;
    }
    .palette-item .replace-hint {
        opacity: 0.5;
        width: 20px;
        height: 20px;
        font-size: 8px;
    }
    .stats-text {
        font-size: 11px;
        padding: 10px 12px;
        max-height: 100px;
    }
    .image-box {
        padding: 10px;
    }
    .image-box .box-content {
        min-height: 150px;
    }
    .presets-grid {
        grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
        gap: 8px;
    }
    .preset-btn {
        min-height: 52px;
        font-size: 18px;
        padding: 8px 6px;
    }
    .preset-btn .preview-colors span {
        width: 12px;
        height: 12px;
    }
    .preset-btn .preset-icon {
        font-size: 18px;
    }
    .preset-btn .preset-tooltip {
        font-size: 10px;
        padding: 3px 10px;
    }
    .priority-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .priority-item {
        padding: 6px 10px 8px;
    }
    .priority-item .priority-label {
        font-size: 11px;
    }
    .saved-palettes-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 8px;
    }
}

@media (max-width: 400px) {
    .controls .group label .emoji {
        display: none;
    }
    .controls .group label {
        font-size: 11px;
    }
    .palette-grid {
        grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
        gap: 8px;
    }
    .palette-item .percent {
        font-size: 8px;
        padding: 1px 6px;
    }
    .palette-item .index-label {
        font-size: 7px;
    }
    .presets-grid {
        grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
        gap: 6px;
    }
    .preset-btn {
        min-height: 44px;
        font-size: 16px;
        padding: 6px 4px;
        border-radius: 10px;
    }
    .preset-btn .preview-colors span {
        width: 10px;
        height: 10px;
    }
    .preset-btn .preset-icon {
        font-size: 16px;
    }
    .priority-grid {
        grid-template-columns: 1fr;
    }
    .saved-palettes-grid {
        grid-template-columns: 1fr;
    }
}

@media (pointer: coarse) {
    .palette-item .replace-hint {
        opacity: 0.4;
    }
}

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.modal-overlay.show {
    display: flex;
    opacity: 1;
}
.modal-content {
    background: rgba(15, 15, 23, 0.98);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 80px rgba(129, 140, 248, 0.08);
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
}
.modal-overlay.show .modal-content {
    transform: scale(1);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.modal-header h3 {
    font-size: 17px;
    font-weight: 700;
    background: linear-gradient(135deg, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: #94a3b8;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    touch-action: manipulation;
    font-family: inherit;
}
.modal-close:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.2);
    transform: rotate(90deg);
}
.modal-body {
    padding: 22px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}
.modal-footer {
    display: flex;
    gap: 8px;
    padding: 16px 22px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-wrap: wrap;
    justify-content: flex-end;
}
.modal-footer .btn {
    padding: 10px 18px;
    font-size: 13px;
    flex: 1 1 auto;
    justify-content: center;
    min-width: 0;
}

/* ===== COLOR EDIT SPECIFIC ===== */
.color-edit-content {
    max-width: 440px;
}
.color-edit-preview {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 12px;
    align-items: center;
    margin-bottom: 22px;
}
.color-preview-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}
.color-preview-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
}
.color-preview-swatch {
    width: 100%;
    aspect-ratio: 1.6;
    border-radius: 12px;
    border: 2px solid rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 0 30px rgba(0,0,0,0.2), 0 4px 16px rgba(0, 0, 0, 0.3);
    transition: background 0.15s ease;
}
.color-preview-hex {
    font-size: 12px;
    font-weight: 600;
    color: #e2e8f0;
    font-family: 'SF Mono', 'Fira Code', monospace;
    letter-spacing: 0.3px;
}
.color-preview-arrow {
    font-size: 22px;
    color: #a78bfa;
    font-weight: 700;
    filter: drop-shadow(0 0 8px rgba(167, 139, 250, 0.4));
}
.color-edit-picker-btn {
    width: 100%;
    justify-content: center;
    padding: 14px 20px !important;
    font-size: 14px !important;
    margin-bottom: 14px;
}
.color-edit-hint {
    font-size: 12px;
    color: #64748b;
    line-height: 1.5;
    padding: 10px 14px;
    background: rgba(129, 140, 248, 0.06);
    border-radius: 10px;
    border: 1px solid rgba(129, 140, 248, 0.1);
    text-align: center;
}

@media (max-width: 500px) {
    .color-edit-preview {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .color-preview-arrow {
        transform: rotate(90deg);
        font-size: 18px;
    }
    .color-preview-swatch {
        aspect-ratio: 3;
    }
    .modal-content {
        max-width: 100%;
        border-radius: 16px;
    }
    .modal-header {
        padding: 14px 16px;
    }
    .modal-header h3 {
        font-size: 15px;
    }
    .modal-body {
        padding: 16px;
    }
    .modal-footer {
        padding: 12px 16px;
    }
    .modal-footer .btn {
        padding: 10px 12px;
        font-size: 12px;
    }
}
/* ============================================================
   DITHER ALGORITHM SELECT
   ============================================================ */

.dither-group {
    padding: 4px 10px 4px 16px !important;
}

.dither-select {
    padding: 6px 28px 6px 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: #e2e8f0;
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23a78bfa'%3e%3cpath d='M4 6l4 4 4-4' stroke='%23a78bfa' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 12px;
    min-width: 150px;
    touch-action: manipulation;
}

.dither-select:hover {
    background-color: rgba(255, 255, 255, 0.09);
    border-color: rgba(129, 140, 248, 0.3);
}

.dither-select:focus {
    border-color: rgba(129, 140, 248, 0.5);
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.12);
    background-color: rgba(129, 140, 248, 0.06);
}

.dither-select option {
    background: #0f0f17;
    color: #e2e8f0;
    padding: 8px;
    font-size: 13px;
}

/* Мобильная версия — компактнее */
@media (max-width: 600px) {
    .dither-group {
        padding: 3px 8px 3px 12px !important;
    }
    .dither-select {
        padding: 6px 24px 6px 8px;
        font-size: 11px;
        min-width: 120px;
        background-position: right 6px center;
        background-size: 10px;
    }
}

@media (max-width: 400px) {
    .dither-select {
        font-size: 10px;
        min-width: 100px;
        padding: 5px 20px 5px 6px;
    }
}
/* ============================================================
   DITHER STRENGTH SLIDER
   ============================================================ */

.dither-strength-slider {
    width: 60px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(90deg, #4f46e5, #a78bfa);
    border-radius: 2px;
    outline: none;
    flex-shrink: 0;
    cursor: pointer;
    transition: opacity 0.2s;
}

.dither-strength-slider:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.dither-strength-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: radial-gradient(circle, #818cf8, #4f46e5);
    cursor: pointer;
    box-shadow: 0 0 12px rgba(129, 140, 248, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.1);
    transition: transform 0.15s;
}

.dither-strength-slider::-webkit-slider-thumb:active {
    transform: scale(1.2);
}

.dither-strength-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: radial-gradient(circle, #818cf8, #4f46e5);
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

/* Бейдж со значением — меньше, чем обычный */
.dither-group #ditherStrengthDisplay {
    min-width: 24px;
    padding: 2px 8px;
    font-size: 11px;
    background: linear-gradient(135deg, #64748b, #475569);
    box-shadow: none;
}

/* Мобильная версия */
@media (max-width: 600px) {
    .dither-strength-slider {
        width: 50px;
    }
    .dither-group #ditherStrengthDisplay {
        min-width: 22px;
        padding: 1px 6px;
        font-size: 10px;
    }
}

/* При выключенном дизеринге слайдер визуально приглушается */
.dither-group.dither-off .dither-strength-slider {
    opacity: 0.35;
    pointer-events: none;
}
.dither-group.dither-off #ditherStrengthDisplay {
    opacity: 0.5;
}