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

        body {
            font-family: 'Inter', sans-serif;
            background-color: #f9fafb;
            color: #1f2937;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }

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

        h1 {
            text-align: center;
            margin-bottom: 8px;
            font-weight: 700;
            font-size: 1.875rem;
            background: linear-gradient(to right, #3b82f6, #2563eb);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        @media (min-width: 768px) {
            h1 {
                font-size: 3rem;
            }
        }

        .subtitle {
            text-align: center;
            color: #6b7280;
            font-size: 0.875rem;
            margin-bottom: 24px;
        }

        .main-layout {
            display: grid;
            grid-template-columns: 1fr 360px;
            gap: 24px;
            margin-bottom: 40px;
        }

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

        .canvas-section {
            background: #fff;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
            display: flex;
            flex-direction: column;
        }

        .canvas-container {
            position: relative;
            width: 100%;
            background: #f1f5f9;
            border-radius: 8px;
            overflow: hidden;
            flex: 1;
            min-height: 400px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 1px solid #e2e8f0;
            margin-bottom: 16px;
        }

        /* Checkboard pattern for transparency */
        .canvas-bg-pattern {
            background-image: linear-gradient(45deg, #e2e8f0 25%, transparent 25%),
                linear-gradient(-45deg, #e2e8f0 25%, transparent 25%),
                linear-gradient(45deg, transparent 75%, #e2e8f0 75%),
                linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
            background-size: 20px 20px;
            background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
        }

        #mainCanvas {
            max-width: 100%;
            max-height: 70vh;
            cursor: crosshair;
            display: block;
        }

        #selectionCanvas {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
        }

        #edgeCanvas {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            opacity: 0.4;
        }

        .canvas-transform-wrapper {
            transform-origin: 0 0;
            position: relative;
            display: inline-block;
        }

        .canvas-container.panning {
            cursor: grabbing !important;
        }

        .canvas-container.panning * {
            cursor: grabbing !important;
        }

        .upload-prompt {
            text-align: center;
            color: #64748b;
        }

        .upload-prompt label {
            display: inline-block;
            padding: 16px 32px;
            background: #fff;
            border: 2px dashed #cbd5e1;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.2s;
            color: #475569;
        }

        .upload-prompt label:hover {
            border-color: #6366f1;
            color: #6366f1;
        }

        #imageInput {
            display: none;
        }

        /* Modern Toolbar */
        .toolbar-modern {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 12px;
            background: rgba(230, 230, 230, 0.50);
            backdrop-filter: blur(10px);
            border-radius: 12px;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            margin-bottom: 12px;
            flex-wrap: wrap;
        }

        .toolbar-group {
            display: contents;
        }

        .toolbar-separator {
            display: none;
        }

        /* Mode buttons - toggle state */
        .btn-mode {
            background: #f1f5f9;
            color: #475569;
            border: 1px solid #e2e8f0;
            transition: all 0.2s;
        }

        .btn-mode:hover:not(:disabled) {
            background: #e2e8f0;
        }

        .btn-mode.active {
            background: #3b82f6;
            color: white;
            border-color: #3b82f6;
        }

        .btn-mode.active:hover:not(:disabled) {
            background: #2563eb;
            border-color: #2563eb;
        }

        /* SVG icons inherit button color */
        .btn svg {
            display: block;
        }

        /* Mobile: Stack into two rows if needed */
        @media (max-width: 640px) {
            .toolbar-modern {
                justify-content: center;
            }

            .toolbar-separator {
                display: none;
            }
        }

        .btn {
            padding: 8px 16px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 13px;
            font-weight: 500;
            transition: all 0.2s;
        }

        .btn-primary {
            background: #22c55e;
            color: white;
        }

        .btn-primary:hover {
            background: #16a34a;
        }

        .btn-secondary {
            background: #f1f5f9;
            color: #475569;
            border: 1px solid #e2e8f0;
        }

        .btn-secondary:hover {
            background: #e2e8f0;
        }

        .btn:disabled {
            opacity: 0.5;
            cursor: not-allowed;
        }

        #commitBtn:not(:disabled) {
            background: #6366f1;
            color: white;
            border-color: #6366f1;
        }

        #commitBtn:not(:disabled):hover {
            background: #4f46e5;
            border-color: #4f46e5;
        }

        .btn-icon {
            padding: 7px 11px;
            font-size: 18px;
            line-height: 1;
        }

        .btn-icon svg {
            width: 26px;
            height: 26px;
            display: block;
        }

        #downloadBtn {
            font-size: 100%;
            padding: 10px 18px;
        }

        .info-text {
            font-size: 12px;
            color: #94a3b8;
            margin-top: 12px;
            line-height: 1.5;
        }

        .controls-panel {
            background: #fff;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
            display: flex;
            flex-direction: column;
            gap: 20px;
            height: fit-content;
            max-height: 90vh;
        }

        .panel-section {
            border-bottom: 1px solid #f1f5f9;
            padding-bottom: 16px;
        }

        .panel-section:last-child {
            border-bottom: none;
            padding-bottom: 0;
        }

        .section-title {
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: #94a3b8;
            margin-bottom: 12px;
            font-weight: 600;
        }

        .toggle-row {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 10px;
        }

        .toggle-label {
            font-size: 14px;
            color: #475569;
        }

        .toggle-switch {
            position: relative;
            width: 44px;
            height: 24px;
        }

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

        .toggle-slider {
            position: absolute;
            cursor: pointer;
            inset: 0;
            background: #e2e8f0;
            border-radius: 24px;
            transition: 0.2s;
        }

        .toggle-slider::before {
            content: '';
            position: absolute;
            height: 18px;
            width: 18px;
            left: 3px;
            bottom: 3px;
            background: white;
            border-radius: 50%;
            transition: 0.2s;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
        }

        .toggle-switch input:checked+.toggle-slider {
            background: #6366f1;
        }

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

        .toggle-switch input:disabled+.toggle-slider {
            opacity: 0.5;
            cursor: not-allowed;
        }

        .shared-control {
            margin-top: 12px;
            padding: 12px;
            background: #f8fafc;
            border-radius: 8px;
            display: none;
            border: 1px solid #e2e8f0;
        }

        .shared-control.visible {
            display: block;
        }

        .shared-control>label {
            display: block;
            font-size: 12px;
            color: #64748b;
            margin-bottom: 8px;
        }

        .intensity-control {
            margin-top: 4px;
            margin-bottom: 10px;
            padding: 10px 12px;
            background: #f8fafc;
            border-radius: 8px;
            border: 1px solid #e2e8f0;
            display: none;
        }

        .intensity-control.visible {
            display: block;
        }

        .intensity-row {
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .intensity-label {
            font-size: 13px;
            color: #475569;
            min-width: 60px;
        }

        .intensity-slider {
            flex: 1;
            height: 6px;
            -webkit-appearance: none;
            appearance: none;
            background: linear-gradient(to right, #94a3b8 0%, #94a3b8 50%, #6366f1 50%, #6366f1 100%);
            border-radius: 3px;
            outline: none;
        }

        .intensity-slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 16px;
            height: 16px;
            background: #6366f1;
            border-radius: 50%;
            cursor: pointer;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
        }

        .intensity-slider::-moz-range-thumb {
            width: 16px;
            height: 16px;
            background: #6366f1;
            border-radius: 50%;
            cursor: pointer;
            border: none;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
        }

        .intensity-value {
            font-size: 13px;
            font-weight: 500;
            color: #334155;
            min-width: 30px;
            text-align: right;
        }

        .color-pairs {
            display: flex;
            flex-direction: column;
            gap: 12px;
            overflow-y: auto;
            flex: 1;
            padding-right: 4px;
        }

        .color-pair {
            background: #f8fafc;
            border-radius: 8px;
            padding: 12px;
            border: 1px solid #e2e8f0;
            transition: border-color 0.2s;
        }

        .color-pair:hover {
            border-color: #cbd5e1;
        }

        .color-pair-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 10px;
        }

        .color-pair-number {
            font-size: 12px;
            color: #94a3b8;
            font-weight: 500;
        }

        .remove-pair {
            background: none;
            border: none;
            color: #cbd5e1;
            cursor: pointer;
            font-size: 18px;
            line-height: 1;
            padding: 4px;
            transition: color 0.2s;
        }

        .remove-pair:hover {
            color: #ef4444;
        }

        .color-row {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-bottom: 8px;
        }

        .color-row-label {
            font-size: 12px;
            color: #64748b;
            width: 32px;
        }

        .color-input-group {
            display: flex;
            align-items: center;
            gap: 6px;
            flex: 1;
        }

        .color-input-group input:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            background-color: #f8fafc;
        }

        .color-picker {
            width: 28px;
            height: 28px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            padding: 0;
            background: none;
        }

        .color-picker::-webkit-color-swatch-wrapper {
            padding: 0;
        }

        .color-picker::-webkit-color-swatch {
            border: 2px solid #e2e8f0;
            border-radius: 6px;
        }

        .color-picker.unset::-webkit-color-swatch {
            background: linear-gradient(45deg, #f1f5f9 25%, #e2e8f0 25%, #e2e8f0 50%, #f1f5f9 50%, #f1f5f9 75%, #e2e8f0 75%);
            background-size: 8px 8px;
        }

        .color-picker.transparent-swatch::-webkit-color-swatch {
            background: linear-gradient(45deg, #e2e8f0 25%, #cbd5e1 25%, #cbd5e1 50%, #e2e8f0 50%, #e2e8f0 75%, #cbd5e1 75%);
            background-size: 8px 8px;
        }

        .color-picker.transparent-swatch::-moz-color-swatch {
            background: linear-gradient(45deg, #e2e8f0 25%, #cbd5e1 25%, #cbd5e1 50%, #e2e8f0 50%, #e2e8f0 75%, #cbd5e1 75%);
            background-size: 8px 8px;
        }

        .color-text {
            flex: 1;
            padding: 4px 8px;
            border: 1px solid #e2e8f0;
            border-radius: 6px;
            background: #fff;
            color: #334155;
            font-family: 'SF Mono', Monaco, monospace;
            font-size: 11px;
            width: 0;
            /* allows shrinking */
        }

        .color-text:focus {
            outline: none;
            border-color: #6366f1;
        }

        /* 3-Channel Tolerance Styles */
        .tolerance-grid {
            display: grid;
            grid-template-columns: auto 1fr auto;
            gap: 8px 8px;
            background: #fff;
            padding: 8px;
            border-radius: 6px;
            border: 1px solid #e2e8f0;
            margin-top: 8px;
        }

        .tol-label {
            font-size: 11px;
            color: #64748b;
            font-weight: 600;
            width: 12px;
            padding-top: 2px;
        }

        .tol-slider {
            width: 100%;
            height: 4px;
            -webkit-appearance: none;
            background: #e2e8f0;
            border-radius: 2px;
            outline: none;
            align-self: center;
        }

        .tol-slider::-webkit-slider-thumb {
            -webkit-appearance: none;
            width: 12px;
            height: 12px;
            background: #6366f1;
            border-radius: 50%;
            cursor: pointer;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
        }

        /* Different colors for H, S, V thumbs for visual distinction */
        .tol-slider.hue::-webkit-slider-thumb {
            background: #ec4899;
        }

        .tol-slider.sat::-webkit-slider-thumb {
            background: #f59e0b;
        }

        .tol-slider.val::-webkit-slider-thumb {
            background: #3b82f6;
        }

        .tol-value {
            font-size: 11px;
            color: #475569;
            width: 24px;
            text-align: right;
            font-family: monospace;
        }

        .add-pair-btn {
            width: 100%;
            padding: 10px;
            background: #fff;
            border: 1px dashed #cbd5e1;
            border-radius: 8px;
            color: #64748b;
            cursor: pointer;
            transition: all 0.2s;
            font-size: 13px;
            margin-top: 10px;
        }

        .add-pair-btn:hover {
            border-color: #6366f1;
            color: #6366f1;
        }

        .region-controls {
            padding: 12px;
            background: #f8fafc;
            border: 1px solid #e2e8f0;
            border-radius: 8px;
        }

        .region-controls h3 {
            font-size: 11px;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            color: #6366f1;
            margin-bottom: 8px;
            font-weight: 600;
        }

        .selection-row {
            display: flex;
            align-items: center;
            gap: 8px;
            flex-wrap: wrap;
        }

        .selection-label {
            font-size: 12px;
            color: #64748b;
        }

        .selection-badge {
            padding: 4px 10px;
            background: #fff;
            border: 1px solid #cbd5e1;
            border-radius: 6px;
            font-size: 12px;
            color: #475569;
            font-weight: 500;
        }

        .selection-buttons {
            display: flex;
            gap: 6px;
            margin-left: auto;
        }

        .btn-small {
            padding: 6px 12px;
            font-size: 12px;
        }

        .hidden {
            display: none !important;
        }

        .processing-indicator {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: rgba(0, 0, 0, 0.7);
            color: white;
            padding: 10px 20px;
            border-radius: 20px;
            font-size: 14px;
            display: none;
            z-index: 10;
        }

        .processing-indicator.active {
            display: block;
        }

        /* Documentation/SEO Content Styles */
        .doc-section {
            background: #fff;
            border-radius: 12px;
            padding: 32px;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
            color: #475569;
            line-height: 1.6;
            margin-bottom: 24px;
        }

        .doc-section h2 {
            color: #1a202c;
            font-size: 1.5rem;
            margin-bottom: 16px;
            font-weight: 500;
            border-bottom: 2px solid #f1f5f9;
            padding-bottom: 8px;
        }

        .doc-section h3 {
            color: #2d3748;
            font-size: 1.1rem;
            margin: 24px 0 12px;
            font-weight: 600;
        }

        .doc-section p {
            margin-bottom: 16px;
        }

        .doc-section ul {
            margin-left: 20px;
            margin-bottom: 16px;
        }

        .doc-section li {
            margin-bottom: 8px;
        }

        .canvas-container.drag-active {
            border-color: #6366f1;
            background-color: #e0e7ff;
            box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.2);
        }

        /* Toast notification */
        .toast {
            position: fixed;
            top: 80px;
            left: 50%;
            transform: translateX(-50%) translateY(-100px);
            background: #334155;
            color: #f1f5f9;
            padding: 12px 20px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            z-index: 1000;
            opacity: 0;
            transition: transform 0.3s ease, opacity 0.3s ease;
            max-width: 400px;
            font-size: 14px;
            line-height: 1.4;
        }
        
        .toast.show {
            transform: translateX(-50%) translateY(0);
            opacity: 1;
        }
        
        .toast .toast-dismiss {
            margin-left: 12px;
            color: #94a3b8;
            cursor: pointer;
            font-weight: bold;
        }
        
        .toast .toast-dismiss:hover {
            color: #f1f5f9;
        }

        /* Download dropdown */
        .download-dropdown {
            position: relative;
            display: inline-block;
        }
        
        .download-menu {
            position: absolute;
            bottom: 100%;
            right: 0;
            background: white;
            border: 1px solid #e2e8f0;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            margin-bottom: 4px;
            display: none;
            min-width: 200px;
            overflow: hidden;
        }
        
        .download-dropdown.open .download-menu {
            display: block;
        }
        
        .download-option {
            display: block;
            width: 100%;
            padding: 10px 16px;
            text-align: left;
            background: none;
            border: none;
            cursor: pointer;
            font-size: 14px;
            color: #334155;
        }
        
        .download-option:hover {
            background: #f1f5f9;
        }
        
        .download-option:first-child {
            border-bottom: 1px solid #e2e8f0;
        }
        
        .download-option .download-size {
            color: #64748b;
            font-size: 12px;
        }
