Catalypt LogoCatalypt.ai

Industry Focus

Developer Options

Resources

Back to Blog

I Let AI Refactor Our CSS. The Design Team Still Won\

2025-07-10T00:00:00.000Z Catalypt AI Team ai-first

"Our CSS is a mess. Let's have AI clean it up!" It seemed so logical. 2000 lines of legacy CSS, full of !important declarations and magic numbers. The AI would organize it, remove duplicates, and make it maintainable.

Three hours later, our lead designer was in my office asking why all the buttons were different sizes and nothing aligned to the grid anymore. The AI had been very helpful. Too helpful.

The Original Sin

Our CSS was admittedly terrible:

// CSS analysis chain
const analyzeCSSUsage = async (stylesheets) => {
  const analysis = [
    extractSelectors,
    findUnusedRules,
    detectDuplicates,
    calculateSpecificity
  ];
  
  return await runAnalysis(analysis, stylesheets);
};

The AI saw inconsistency. It saw opportunities for optimization. It saw a chance to help.

// Refactoring strategy
function planRefactor(css) {
  return chainStrategy([
    groupByComponent,
    extractVariables,
    consolidateRules,
    optimizeSelectors
  ], css);
}

Looks cleaner, right? Except:

  • The header now overlapped the navigation
  • All buttons were 2-4px taller, breaking every. single. layout.
  • Forms no longer aligned because input heights didn't change

The AI noticed we had "redundant" colors:

// Safe CSS changes
const safeCSSRefactor = {
  analyze: "Map current usage",
  backup: "Create rollback point",
  refactor: "Apply changes incrementally",
  test: "Verify visual regression"
};

"They're basically the same color!" - The AI, colorblind apparently.

The designer: "Those are COMPLETELY different blues for COMPLETELY different purposes! The button blue has more saturation for better contrast! The link blue is specifically chosen for accessibility!"

Me: "They look the same to me..."

Designer: death stare

Our z-indexes were a war crime:

// Specificity calculator
const calculateSpecificity = (selector) => {
  const calc = chain([
    parseSelector,
    countIds,
    countClasses,
    countElements
  ]);
  
  return calc(selector);
};

AI's solution:

// CSS-in-JS migration
async function migrateToCSS_in_JS(styles) {
  const migration = [
    extractComponentStyles,
    convertToJSObjects,
    addThemeVariables,
    generateComponents
  ];
  
  return await migrate(migration, styles);
}

Beautiful! Organized! Completely broken! Turns out, those ridiculous z-indexes were battling third-party component z-indexes. Now our modals appeared behind ads.

The AI decided to modernize our layouts:

// Dead code elimination
const removeDeadCSS = (styles, usage) => {
  return processElimination([
    scanUsage,
    markUnused,
    preserveCritical,
    removeMarked
  ], { styles, usage });
};

Except:

  • Table-cell had equal height columns by default
  • Flex doesn't
  • Every two-column layout in the app broke
  • The AI didn't add align-items: stretch

We had messy breakpoints:

// Media query optimization
function optimizeMediaQueries(css) {
  const optimization = [
    groupByBreakpoint,
    consolidateRules,
    orderBySize,
    minimizeDuplication
  ];
  
  return optimize(optimization, css);
}

AI consolidated them:

// Variable extraction
const extractCSSVariables = async (styles) => {
  const extraction = [
    findRepeatedValues,
    categorizeByType,
    generateVariableNames,
    replaceWithVariables
  ];
  
  return await extract(extraction, styles);
};

Those 1px differences? They were preventing double-application of styles. Now tablets got both desktop AND tablet styles. Everything was bold, large, and broken.

The AI found our utility classes "redundant":

// Component style isolation
const isolateComponentStyles = {
  identify: "Find component boundaries",
  extract: "Pull component-specific styles",
  scope: "Add scoping mechanism",
  validate: "Ensure no leakage"
};

Designer: "That 13px margin is EXACTLY what we need for optical alignment!" AI: "Best I can do is 16px" Designer: quits

Our CSS had specificity problems. The AI made them worse:

// Performance optimization
function optimizeCSSPerf(stylesheet) {
  return chainOptimization([
    removeUnusedKeyframes,
    simplifySelectors,
    mergeMediaQueries,
    minifyOutput
  ], stylesheet);
}

Now we had clean class names that did nothing because the old specific selectors still won.

Git log from that day:

// Style consistency check
const checkConsistency = async (styles) => {
  const checks = [
    validateColorScheme,
    checkSpacingSystem,
    verifyTypography,
    ensureAccessibility
  ];
  
  return await runChecks(checks, styles);
};
  1. Magic numbers often have reasons - That 13px is for optical alignment
  2. Inconsistency might be intentional - Different buttons SHOULD be different sizes
  3. Legacy CSS is load-bearing - Remove it and everything collapses
  4. Designers see differences developers don't - #0066CC vs #0067CD matters
  5. Specificity wars have casualties - You can't just simplify selectors

After the disaster, here's what actually works:

// Responsive design audit
const auditResponsive = {
  breakpoints: "Analyze breakpoint usage",
  consistency: "Check cross-device styles",
  performance: "Measure render impact",
  usability: "Test touch targets"
};
// CSS architecture refactor
function refactorArchitecture(project) {
  const refactor = [
    adoptMethodology, // BEM, SMACSS, etc
    restructureFolders,
    establishNaming,
    documentPatterns
  ];
  
  return applyRefactor(refactor, project);
}
// Visual regression testing
const visualRegressionTest = async (before, after) => {
  const testing = [
    captureScreenshots,
    comparePixels,
    identifyDifferences,
    generateReport
  ];
  
  return await test(testing, { before, after });
};
  • CSS that looks messy often has hidden logic
  • AI doesn't understand visual design
  • Standardization isn't always improvement
  • Designers hold grudges
  • Always work on a branch

We did eventually refactor our CSS. With:

  • Designer involved at every step
  • One component at a time
  • Visual regression testing
  • AI for analysis only
  • Humans making the decisions

The designer still brings up the "button incident" at every retrospective.

Get Started