Skip to content

A lightweight Clip Studio Paint alternative with real-time multiplayer collaborative drawing. Built with Tauri and React.

27.8 KB
Raw Blame
import React, { useState, useRef } from 'react';
import { Droplets, Download, Upload, RotateCcw, Copy, Save } from 'lucide-react';
import type {
  BrushCategory,
  BrushDynamics,
  BrushSettings,
  CspSensorConfig,
  ImpastoSettings,
  NaturalMixingMode,
  NaturalPaintSettings,
} from '../../types/editor';
import {
  DEFAULT_BRUSH_DYNAMICS,
  DEFAULT_IMPASTO_SETTINGS,
  DEFAULT_NATURAL_PAINT_SETTINGS,
} from '../../types/editor';
import { cleanNativeDirtyBrush as cleanDirtyBrush } from '../../utils/nativeEngineBridge';
import { useToolStore } from '../../stores';
import { LightSourceWidget } from '../LightSourceWidget';
import { PigmentBlendControl } from '../PigmentBlendControl';
import { PressureCurveEditor } from '../PressureCurveEditor';
import {
  StudioSection,
  StudioSegmented,
  StudioSlider,
  StudioToggle,
} from './BrushStudioControls';
import type { BrushStudioTabProps } from './BrushStudioTabsPrimary';
import { useI18n } from '../../i18n';

export const NaturalPaintMixingTab: React.FC<BrushStudioTabProps> = ({ bs, onPatch }) => {
  const { t, tc } = useI18n();
  const primaryColor = useToolStore((s) => s.primaryColor);
  const secondaryColor = useToolStore((s) => s.secondaryColor);
  const np: NaturalPaintSettings = {
    ...DEFAULT_NATURAL_PAINT_SETTINGS,
    ...(bs.naturalPaint || {}),
  };

  const patchNp = (p: Partial<NaturalPaintSettings>) => {
    onPatch({
      naturalPaint: { ...np, ...p },
      colorMixing: p.enabled !== undefined ? p.enabled : bs.colorMixing,
    });
  };

  const isMixingEnabled = Boolean(np.enabled || bs.colorMixing);

  return (
    <div className="divide-y divide-ui-subtle">
      <StudioSection
        title={t('Natural Paint Engine')}
        summary={isMixingEnabled ? t('Active') : t('Off')}
        summaryTone={isMixingEnabled ? 'accent' : 'muted'}
        divider={false}
        defaultOpen
      >
        <StudioToggle
          label={t('Enable Natural Paint & Wet Mixing')}
          description={t('Per-bristle pigment mixing, load capacity & dry-brush')}
          checked={isMixingEnabled}
          onChange={(v) =>
            onPatch({
              colorMixing: v,
              naturalPaint: { ...np, enabled: v },
              renderMode: v && (bs.renderMode ?? 'stamp') === 'stamp' ? 'bristle-ribbon' : bs.renderMode,
            })
          }
        />

        <StudioSegmented<NaturalMixingMode>
          label={t('Mixing Mode')}
          value={bs.mixingMode ?? 'impasto_mix'}
          options={[
            { id: 'blend', label: tc('mixingMode', 'Blend') },
            { id: 'running_color', label: tc('mixingMode', 'Running') },
            { id: 'smear', label: tc('mixingMode', 'Smear') },
            { id: 'impasto_mix', label: tc('mixingMode', 'Impasto') },
          ]}
          onChange={(m) => onPatch({ mixingMode: m })}
        />

        <StudioToggle
          label={t('Per-Bristle Spatial Mixing')}
          description={t('Each bristle picks up & drags local canvas color streaks')}
          checked={np.spatialMixing}
          onChange={(v) => patchNp({ spatialMixing: v })}
        />
      </StudioSection>

      <StudioSection
        title={t('Pigment & Reservoir Physics')}
        summary={t('{pct}% load', { pct: Math.round(np.paintLoad * 100) })}
        defaultOpen
        divider={false}
      >
        <PigmentBlendControl
          variant="studio"
          label="Color Blending"
          strengthLabel="Pigment Strength"
          enabled={bs.perceptualMixing !== false}
          onEnabledChange={(enabled) => onPatch({ perceptualMixing: enabled })}
          strength={np.pigmentMixingStrength}
          onStrengthChange={(s) =>
            onPatch({
              perceptualMixing: true,
              naturalPaint: { ...np, pigmentMixingStrength: s },
            })
          }
          primaryColor={primaryColor}
          secondaryColor={secondaryColor}
        />
        <StudioSlider
          label={t('Paint Load')}
          value={Math.round(np.paintLoad * 100)}
          min={0}
          max={100}
          defaultValue={Math.round(DEFAULT_NATURAL_PAINT_SETTINGS.paintLoad * 100)}
          valueLabel={`${Math.round(np.paintLoad * 100)}%`}
          onChange={(v) =>
            onPatch({
              amountOfPaint: v / 100,
              naturalPaint: { ...np, paintLoad: v / 100 },
            })
          }
        />
        <StudioSlider
          label={t('Depletion Rate')}
          value={Math.round(np.depletionRate * 100)}
          min={0}
          max={100}
          defaultValue={Math.round(DEFAULT_NATURAL_PAINT_SETTINGS.depletionRate * 100)}
          valueLabel={`${Math.round(np.depletionRate * 100)}%`}
          onChange={(v) => patchNp({ depletionRate: v / 100 })}
        />
        <StudioSlider
          label={t('Wetness / Pickup')}
          value={Math.round(np.wetness * 100)}
          min={0}
          max={100}
          defaultValue={Math.round(DEFAULT_NATURAL_PAINT_SETTINGS.wetness * 100)}
          valueLabel={`${Math.round(np.wetness * 100)}%`}
          onChange={(v) => patchNp({ wetness: v / 100 })}
        />
        <StudioSlider
          label={t('Viscosity')}
          value={Math.round(np.viscosity * 100)}
          min={0}
          max={100}
          defaultValue={Math.round(DEFAULT_NATURAL_PAINT_SETTINGS.viscosity * 100)}
          valueLabel={`${Math.round(np.viscosity * 100)}%`}
          onChange={(v) => patchNp({ viscosity: v / 100 })}
        />
        <StudioSlider
          label={t('Color Stretch')}
          value={Math.round((bs.colorStretch ?? 0.65) * 100)}
          min={0}
          max={100}
          defaultValue={65}
          valueLabel={`${Math.round((bs.colorStretch ?? 0.65) * 100)}%`}
          onChange={(v) => onPatch({ colorStretch: v / 100 })}
        />
        <StudioToggle
          label={t('Optical Blend Blur')}
          description={t('Isotropic smoothing on picked-up canvas color')}
          checked={Boolean(bs.useBlur)}
          onChange={(v) =>
            onPatch({
              useBlur: v,
              blurStrength: v ? bs.blurStrength ?? 0.35 : bs.blurStrength,
            })
          }
        />
        {bs.useBlur && (
          <StudioSlider
            label={t('Blur Strength')}
            value={Math.round((bs.blurStrength ?? 0.35) * 100)}
            min={5}
            max={100}
            defaultValue={35}
            valueLabel={`${Math.round((bs.blurStrength ?? 0.35) * 100)}%`}
            onChange={(v) => onPatch({ blurStrength: v / 100 })}
          />
        )}
        <StudioSlider
          label={t('Charge per Pressure')}
          value={Math.round(np.chargePerPressure * 100)}
          min={0}
          max={100}
          defaultValue={Math.round(DEFAULT_NATURAL_PAINT_SETTINGS.chargePerPressure * 100)}
          valueLabel={`${Math.round(np.chargePerPressure * 100)}%`}
          onChange={(v) => patchNp({ chargePerPressure: v / 100 })}
        />

        <div className="pt-2 border-t border-ui-subtle flex items-center justify-between gap-2">
          <div className="flex-1 min-w-0">
            <StudioToggle
              label={t('Auto-Clean After Stroke')}
              description={t('Off keeps picked-up pigment on bristles across strokes')}
              checked={np.autoClean}
              onChange={(v) => patchNp({ autoClean: v })}
            />
          </div>
          {!np.autoClean && (
            <button
              type="button"
              onClick={() => cleanDirtyBrush(bs.preset)}
              className="h-6 px-2 rounded-ui-xs bg-ui-control hover:bg-ui-control-hover border border-ui-default text-[10px] text-ui-accent flex items-center gap-1 cursor-pointer shrink-0 transition-colors"
            >
              <Droplets className="w-3 h-3" />
              <span>{t('Clean')}</span>
            </button>
          )}
        </div>
      </StudioSection>
    </div>
  );
};

export const ImpastoWetEdgeTab: React.FC<BrushStudioTabProps> = ({ bs, onPatch }) => {
  const { t } = useI18n();
  const imp: ImpastoSettings = { ...DEFAULT_IMPASTO_SETTINGS, ...(bs.impasto || {}) };
  const np: NaturalPaintSettings = {
    ...DEFAULT_NATURAL_PAINT_SETTINGS,
    ...(bs.naturalPaint || {}),
  };

  const patchImp = (p: Partial<ImpastoSettings>) => {
    onPatch({ impasto: { ...imp, ...p } });
  };

  const wetPct = Math.round((bs.wetEdge ?? 0) * 100);

  return (
    <div className="divide-y divide-ui-subtle">
      <StudioSection
        title={t('3D Impasto Relief')}
        summary={imp.enabled ? `${Math.round(imp.depth * 100)}%` : t('Off')}
        summaryTone={imp.enabled ? 'accent' : 'muted'}
        divider={false}
        defaultOpen
      >
        <StudioToggle
          label={t('Enable 3D Impasto Relief')}
          description={t('Real-time paint heightmap with directional lighting & sheen')}
          checked={imp.enabled}
          onChange={(v) => patchImp({ enabled: v })}
        />

        <StudioSlider
          label={t('Impasto Depth')}
          value={Math.round(imp.depth * 100)}
          min={0}
          max={100}
          defaultValue={Math.round(DEFAULT_IMPASTO_SETTINGS.depth * 100)}
          valueLabel={`${Math.round(imp.depth * 100)}%`}
          onChange={(v) => patchImp({ depth: v / 100 })}
        />
        <StudioSlider
          label={t('Bristle Groove Relief')}
          value={Math.round(imp.bristleRelief * 100)}
          min={0}
          max={100}
          defaultValue={Math.round(DEFAULT_IMPASTO_SETTINGS.bristleRelief * 100)}
          valueLabel={`${Math.round(imp.bristleRelief * 100)}%`}
          onChange={(v) => patchImp({ bristleRelief: v / 100 })}
        />
        <StudioSlider
          label={t('Gloss / Oil Sheen')}
          value={Math.round(imp.gloss * 100)}
          min={0}
          max={100}
          defaultValue={Math.round(DEFAULT_IMPASTO_SETTINGS.gloss * 100)}
          valueLabel={`${Math.round(imp.gloss * 100)}%`}
          onChange={(v) => patchImp({ gloss: v / 100 })}
        />
        <StudioSlider
          label={t('Relief Lighting Contrast')}
          value={Math.round(imp.reliefContrast * 100)}
          min={0}
          max={100}
          defaultValue={Math.round(DEFAULT_IMPASTO_SETTINGS.reliefContrast * 100)}
          valueLabel={`${Math.round(imp.reliefContrast * 100)}%`}
          onChange={(v) => patchImp({ reliefContrast: v / 100 })}
        />
      </StudioSection>

      {/* Directional Light Gizmo (Reuses InkStudio LightSourceWidget) */}
      <StudioSection
        title={t('Directional Light')}
        summary={`${Math.round(imp.lightAzimuth)}° / ${Math.round(imp.lightElevation)}°`}
        defaultOpen={imp.enabled}
        divider={false}
      >
        <LightSourceWidget
          embedded
          settings={{
            azimuth: imp.lightAzimuth,
            elevation: imp.lightElevation,
            intensity: 1.2,
            ambientIntensity: 0.7,
            color: '#ffffff',
            isBacklit: false,
          }}
          onChange={(next) =>
            patchImp({
              lightAzimuth: Math.max(0, Math.min(360, next.azimuth)),
              lightElevation: Math.max(5, Math.min(85, next.elevation)),
            })
          }
          onReset={() => patchImp({ lightAzimuth: 315, lightElevation: 42 })}
        />
      </StudioSection>

      {/* Watercolor Wet Edge & Paper-Valley Granulation */}
      <StudioSection
        title={t('Watercolor Wet Edge & Granulation')}
        summary={wetPct > 0 ? `${wetPct}%` : t('Off')}
        summaryTone={wetPct > 0 ? 'accent' : 'muted'}
        defaultOpen
        divider={false}
      >
        <StudioSlider
          label={t('Wet Edge Strength')}
          value={wetPct}
          min={0}
          max={100}
          defaultValue={0}
          valueLabel={`${wetPct}%`}
          onChange={(v) => onPatch({ wetEdge: v / 100 })}
        />
        <StudioSlider
          label={t('Wet Edge Radius')}
          value={Number((bs.wetEdgeRadius ?? 3.0).toFixed(1))}
          min={1}
          max={8}
          step={0.5}
          defaultValue={3.0}
          valueLabel={`${(bs.wetEdgeRadius ?? 3.0).toFixed(1)}px`}
          onChange={(v) => onPatch({ wetEdgeRadius: v })}
        />
        <StudioSlider
          label={t('Paper-Valley Granulation')}
          value={Math.round((np.granulation ?? 0) * 100)}
          min={0}
          max={100}
          defaultValue={0}
          valueLabel={`${Math.round((np.granulation ?? 0) * 100)}%`}
          onChange={(v) => onPatch({ naturalPaint: { ...np, granulation: v / 100 } })}
        />
      </StudioSection>
    </div>
  );
};

type SensorTargetKey =
  | 'sizeSensor'
  | 'opacitySensor'
  | 'densitySensor'
  | 'bristleSplaySensor'
  | 'paintLoadSensor'
  | 'grainPenetrationSensor'
  | 'angleSensor'
  | 'scatterSensor';

const SENSOR_TARGETS: Array<{ key: SensorTargetKey; label: string }> = [
  { key: 'sizeSensor', label: 'Size' },
  { key: 'opacitySensor', label: 'Opacity' },
  { key: 'densitySensor', label: 'Flow / Density' },
  { key: 'bristleSplaySensor', label: 'Bristle Splay' },
  { key: 'paintLoadSensor', label: 'Paint Load' },
  { key: 'grainPenetrationSensor', label: 'Grain Depth' },
  { key: 'angleSensor', label: 'Angle' },
  { key: 'scatterSensor', label: 'Scatter' },
];

export const DynamicsSensorMatrixTab: React.FC<BrushStudioTabProps> = ({ bs, onPatch }) => {
  const { t } = useI18n();
  const [selectedTarget, setSelectedTarget] = useState<SensorTargetKey>('sizeSensor');
  const dyn: BrushDynamics = { ...DEFAULT_BRUSH_DYNAMICS, ...(bs.dynamics || {}) };
  const sensor: CspSensorConfig = bs[selectedTarget] || {};

  const patchSensor = (p: Partial<CspSensorConfig>) => {
    onPatch({ [selectedTarget]: { ...sensor, ...p } } as Partial<BrushSettings>);
  };

  const patchDyn = (p: Partial<BrushDynamics>) => {
    onPatch({ dynamics: { ...dyn, ...p } });
  };

  const selectedTargetLabel = t(
    SENSOR_TARGETS.find((target) => target.key === selectedTarget)?.label ?? 'Size'
  );

  return (
    <div className="divide-y divide-ui-subtle">
      {/* Unified Sensor Matrix Target Selector */}
      <StudioSection
        title={t('Sensor-to-Property Matrix')}
        summary={selectedTargetLabel}
        summaryTone="accent"
        divider={false}
        defaultOpen
      >
        <div className="grid grid-cols-2 gap-1">
          {SENSOR_TARGETS.map((target) => {
            const cfg = bs[target.key];
            const activeCount = cfg
              ? [
                  cfg.usePressure,
                  cfg.useTilt,
                  cfg.useBarrelTwist,
                  cfg.useVelocity,
                  cfg.useDistance,
                  cfg.useRandom,
                ].filter(Boolean).length
              : 0;
            const isSelected = selectedTarget === target.key;
            return (
              <button
                key={target.key}
                type="button"
                onClick={() => setSelectedTarget(target.key)}
                className={`px-2 py-1 rounded-ui-xs text-[10.5px] flex items-center justify-between gap-1 cursor-pointer border transition-colors ${
                  isSelected
                    ? 'bg-ui-accent-subtle text-ui-primary font-medium border-ui-accent-border'
                    : 'bg-ui-input text-ui-secondary border-ui-subtle hover:text-ui-primary hover:bg-ui-control-hover'
                }`}
              >
                <span className="truncate">{t(target.label)}</span>
                {activeCount > 0 && (
                  <span className="px-1 rounded-ui-xs bg-ui-panel text-[9px] font-ui-mono tabular-nums text-ui-accent border border-ui-subtle shrink-0">
                    {activeCount}
                  </span>
                )}
              </button>
            );
          })}
        </div>

        <div className="pt-2 border-t border-ui-subtle space-y-1.5">
          <StudioToggle
            label={t('Stylus Pressure')}
            checked={Boolean(sensor.usePressure)}
            onChange={(v) => patchSensor({ usePressure: v })}
          />
          {sensor.usePressure && (
            <StudioSlider
              label={t('Minimum at Zero Pressure')}
              value={Math.round((sensor.pressureMin ?? 0) * 100)}
              min={0}
              max={100}
              defaultValue={0}
              valueLabel={`${Math.round((sensor.pressureMin ?? 0) * 100)}%`}
              onChange={(v) => patchSensor({ pressureMin: v / 100 })}
            />
          )}

          <StudioToggle
            label={t('Tilt Altitude')}
            checked={Boolean(sensor.useTilt)}
            onChange={(v) => {
              patchSensor({ useTilt: v });
              if (v && !bs.useTilt) onPatch({ useTilt: true });
            }}
          />
          <StudioToggle
            label={t('Tilt Azimuth')}
            checked={Boolean(sensor.useTiltAzimuth)}
            onChange={(v) => patchSensor({ useTiltAzimuth: v })}
          />
          <StudioToggle
            label={t('Barrel Twist')}
            checked={Boolean(sensor.useBarrelTwist)}
            onChange={(v) => patchSensor({ useBarrelTwist: v })}
          />
          <StudioToggle
            label={t('Stroke Velocity')}
            checked={Boolean(sensor.useVelocity)}
            onChange={(v) => patchSensor({ useVelocity: v })}
          />
          <StudioToggle
            label={t('Stroke Distance')}
            checked={Boolean(sensor.useDistance)}
            onChange={(v) => patchSensor({ useDistance: v })}
          />
          <StudioToggle
            label={t('Random Variance')}
            checked={Boolean(sensor.useRandom)}
            onChange={(v) => patchSensor({ useRandom: v })}
          />
        </div>

        <div className="pt-2 border-t border-ui-subtle">
          <div className="text-[10px] text-ui-muted mb-1.5">{t('Response Curve')}</div>
          <PressureCurveEditor
            value={{
              enabled: true,
              preset: 'custom',
              points: sensor.pressureCurve ?? bs.pressureCurve ?? [
                [0, 0],
                [1, 1],
              ],
            }}
            onChange={(next) => {
              patchSensor({ pressureCurve: next.points });
              if (selectedTarget === 'sizeSensor') {
                onPatch({ pressureCurve: next.points });
              }
            }}
          />
        </div>
      </StudioSection>

      {/* Jitter & Color Dynamics */}
      <StudioSection
        title={t('Stamp & Color Jitter')}
        summary={dyn.colorJitterEnabled ? t('Color On') : t('Stamp')}
        summaryTone={dyn.colorJitterEnabled ? 'accent' : 'muted'}
        defaultOpen
        divider={false}
      >
        <StudioSlider
          label={t('Size Jitter')}
          value={Math.round(dyn.sizeJitter * 100)}
          min={0}
          max={100}
          defaultValue={0}
          valueLabel={`${Math.round(dyn.sizeJitter * 100)}%`}
          onChange={(v) => patchDyn({ sizeJitter: v / 100 })}
        />
        <StudioSlider
          label={t('Angle Jitter')}
          value={Math.round(dyn.angleJitter * 100)}
          min={0}
          max={100}
          defaultValue={0}
          valueLabel={`${Math.round(dyn.angleJitter * 100)}%`}
          onChange={(v) => patchDyn({ angleJitter: v / 100 })}
        />
        <StudioSlider
          label={t('Scatter')}
          value={Math.round(dyn.scatter * 100)}
          min={0}
          max={250}
          defaultValue={0}
          valueLabel={`${Math.round(dyn.scatter * 100)}%`}
          onChange={(v) => patchDyn({ scatter: v / 100 })}
        />
        <StudioToggle
          label={t('Enable Color Dynamics')}
          checked={dyn.colorJitterEnabled}
          onChange={(v) => patchDyn({ colorJitterEnabled: v })}
        />
        {dyn.colorJitterEnabled && (
          <>
            <StudioSlider
              label={t('Hue Jitter')}
              value={Math.round(dyn.hueJitter * 100)}
              min={0}
              max={100}
              defaultValue={0}
              valueLabel={`${Math.round(dyn.hueJitter * 100)}%`}
              onChange={(v) => patchDyn({ hueJitter: v / 100 })}
            />
            <StudioSlider
              label={t('Saturation Jitter')}
              value={Math.round(dyn.saturationJitter * 100)}
              min={0}
              max={100}
              defaultValue={0}
              valueLabel={`${Math.round(dyn.saturationJitter * 100)}%`}
              onChange={(v) => patchDyn({ saturationJitter: v / 100 })}
            />
            <StudioSlider
              label={t('Lightness Jitter')}
              value={Math.round(dyn.brightnessJitter * 100)}
              min={0}
              max={100}
              defaultValue={0}
              valueLabel={`${Math.round(dyn.brightnessJitter * 100)}%`}
              onChange={(v) => patchDyn({ brightnessJitter: v / 100 })}
            />
            <StudioSlider
              label={t('Temperature Jitter')}
              value={Math.round((dyn.temperatureJitter ?? 0) * 100)}
              min={0}
              max={100}
              defaultValue={0}
              valueLabel={`${Math.round((dyn.temperatureJitter ?? 0) * 100)}%`}
              onChange={(v) => patchDyn({ temperatureJitter: v / 100 })}
            />
            <StudioSlider
              label={t('FG / BG Mix')}
              value={Math.round(dyn.foregroundBackgroundJitter * 100)}
              min={0}
              max={100}
              defaultValue={0}
              valueLabel={`${Math.round(dyn.foregroundBackgroundJitter * 100)}%`}
              onChange={(v) => patchDyn({ foregroundBackgroundJitter: v / 100 })}
            />
          </>
        )}
      </StudioSection>
    </div>
  );
};

export interface AboutPresetsTabProps extends BrushStudioTabProps {
  brushName: string;
  onBrushNameChange: (name: string) => void;
  category: BrushCategory | 'custom';
  onCategoryChange: (cat: BrushCategory | 'custom') => void;
  description: string;
  onDescriptionChange: (desc: string) => void;
  onResetDefault: () => void;
  onSaveAsNewPreset: () => void;
  onDuplicateBrush: () => void;
  onExportInkb: () => void;
  onImportInkb: (file: File) => void;
}

export const AboutPresetsTab: React.FC<AboutPresetsTabProps> = ({
  bs,
  brushName,
  onBrushNameChange,
  category,
  onCategoryChange,
  description,
  onDescriptionChange,
  onResetDefault,
  onSaveAsNewPreset,
  onDuplicateBrush,
  onExportInkb,
  onImportInkb,
}) => {
  const { t, td } = useI18n();
  const importRef = useRef<HTMLInputElement>(null);

  return (
    <div className="divide-y divide-ui-subtle">
      {bs.importWarnings && bs.importWarnings.length > 0 && (
        <div className="p-2.5 bg-ui-warning/10 border-b border-ui-warning/30 space-y-1.5">
          <div className="text-[11px] font-medium text-ui-warning tabular-nums">
            {t('CSP Import Notices ({count})', { count: bs.importWarnings.length })}
          </div>
          <ul className="pl-4 list-disc space-y-1 text-[10.5px] leading-snug text-ui-primary">
            {bs.importWarnings.map((w, idx) => (
              <li key={idx}>{w}</li>
            ))}
          </ul>
        </div>
      )}

      <StudioSection
        title={t('Brush Identity')}
        summary={td(category, 'brushCategory')}
        divider={false}
        defaultOpen
      >
        <div className="space-y-1">
          <label className="text-[10.5px] text-ui-secondary">{t('Brush Name')}</label>
          <input
            type="text"
            value={brushName}
            onChange={(e) => onBrushNameChange(e.target.value)}
            className="w-full h-[var(--ui-control-height)] px-2.5 rounded-ui-sm bg-ui-input border border-ui-subtle hover:border-ui-default focus:border-ui-focus text-[11.5px] text-ui-primary transition-colors"
          />
        </div>

        <div className="space-y-1">
          <label className="text-[10.5px] text-ui-secondary">{t('Category')}</label>
          <select
            value={category}
            onChange={(e) => onCategoryChange(e.target.value as BrushCategory | 'custom')}
            className="w-full h-[var(--ui-control-height)] px-2 rounded-ui-sm bg-ui-input border border-ui-subtle hover:border-ui-default text-[11.5px] text-ui-primary transition-colors"
          >
            <option value="pen">{t('Pen')}</option>
            <option value="sketch">{t('Sketch')}</option>
            <option value="brush">{t('Brush')}</option>
            <option value="blend">{t('Blend')}</option>
            <option value="natural-paint">{t('Natural Paint')}</option>
            <option value="texture-fx">{t('Texture & FX')}</option>
            <option value="custom">{t('Custom')}</option>
          </select>
        </div>

        <div className="space-y-1">
          <label className="text-[10.5px] text-ui-secondary">{t('Description')}</label>
          <textarea
            rows={3}
            value={description}
            onChange={(e) => onDescriptionChange(e.target.value)}
            placeholder={t(
              "Describe this brush's physical feel, bristle setup, or surface interaction..."
            )}
            className="w-full px-2.5 py-1.5 rounded-ui-sm bg-ui-input border border-ui-subtle hover:border-ui-default focus:border-ui-focus text-[11px] text-ui-primary placeholder:text-ui-muted/60 resize-none transition-colors"
          />
        </div>
      </StudioSection>

      <StudioSection title={t('Preset & File Actions')} defaultOpen divider={false}>
        <div className="grid grid-cols-2 gap-1.5">
          <button
            type="button"
            onClick={onSaveAsNewPreset}
            className="h-[var(--ui-control-height)] px-2.5 rounded-ui-sm bg-ui-accent text-ui-accent-contrast hover:opacity-90 text-[11px] font-medium flex items-center justify-center gap-1.5 cursor-pointer transition-opacity"
          >
            <Save className="w-3.5 h-3.5 shrink-0" />
            <span className="truncate">{t('Save New')}</span>
          </button>
          <button
            type="button"
            onClick={onDuplicateBrush}
            className="h-[var(--ui-control-height)] px-2.5 rounded-ui-sm bg-ui-control hover:bg-ui-control-hover border border-ui-default text-[11px] text-ui-primary flex items-center justify-center gap-1.5 cursor-pointer transition-colors"
          >
            <Copy className="w-3.5 h-3.5 shrink-0" />
            <span className="truncate">{t('Duplicate')}</span>
          </button>
          <button
            type="button"
            onClick={onExportInkb}
            className="h-[var(--ui-control-height)] px-2.5 rounded-ui-sm bg-ui-control hover:bg-ui-control-hover border border-ui-default text-[11px] text-ui-primary flex items-center justify-center gap-1.5 cursor-pointer transition-colors"
          >
            <Download className="w-3.5 h-3.5 shrink-0" />
            <span className="truncate">{t('Export .inkb')}</span>
          </button>
          <button
            type="button"
            onClick={() => importRef.current?.click()}
            className="h-[var(--ui-control-height)] px-2.5 rounded-ui-sm bg-ui-control hover:bg-ui-control-hover border border-ui-default text-[11px] text-ui-primary flex items-center justify-center gap-1.5 cursor-pointer transition-colors"
          >
            <Upload className="w-3.5 h-3.5 shrink-0" />
            <span className="truncate">{t('Import Brush')}</span>
          </button>
          <input
            ref={importRef}
            type="file"
            accept=".inkb,.sut"
            className="hidden"
            onChange={(e) => {
              const f = e.target.files?.[0];
              if (f) onImportInkb(f);
              e.target.value = '';
            }}
          />
        </div>
        <button
          type="button"
          onClick={onResetDefault}
          className="w-full h-[var(--ui-control-height)] px-2.5 rounded-ui-sm bg-ui-control hover:bg-ui-danger/15 border border-ui-subtle hover:border-ui-danger/40 text-[11px] text-ui-secondary hover:text-ui-danger flex items-center justify-center gap-1.5 cursor-pointer transition-colors"
        >
          <RotateCcw className="w-3.5 h-3.5 shrink-0" />
          <span>{t('Reset Active Brush to Default')}</span>
        </button>
      </StudioSection>
    </div>
  );
};