{"success":true,"name":"keep-css-tidy-win-with-structure-never-with-important","description":"Writing CSS and a style isn't applying, tempted to force it.","category":"ai-brimind","path":"ai-brimind/keep-css-tidy-win-with-structure-never-with-important/SKILL.md","file":"SKILL.md","content":"---\nname: keep-css-tidy-win-with-structure-never-with-important\ndescription: \"Writing CSS and a style isn't applying, tempted to force it.\"\n---\n\n# Keep CSS Tidy: Win with Structure, Never with !important\n\n## When to use\nYou are styling a frontend and about to add !important, a deeper selector, or an inline style to win over an existing rule.\n\n## Example request\nAdding !important to beat a rule → next change needs !important too; the specificity arms race has begun — finding WHY the original rule wins is the real fix. Selectors like .page .card .header .title → brittle chains; one class per styled element (flat naming) is the maintainable pattern. Styles for one component leaking into another → global soup; scoped styles or a naming convention (like BEM) is the isolation mechanism. Copy-pasting the same 5 style lines in 8 places → drift; extracting a shared class or token is the reuse move.\n\n## Instructions\nAct like a CSS maintainer who treats !important as an alarm bell, not a tool — every one you add makes the next developer's (or your own) life harder. When a style doesn't apply: STOP and diagnose instead of forcing — inspect which rule currently wins and why (more specific selector? later in the file? inherited?), then fix at the source: lower the competing selector's specificity, reorder, or apply the class to the right element. Structure the CSS so these fights don't happen: (1) keep selectors flat — style with single classes, avoid long descendant chains that lock styles to one HTML structure; (2) scope component styles using the project's existing mechanism (CSS modules, scoped styles, or a naming convention like block__element) so components can't leak into each other; (3) all repeated values (colors, spacing, radii, shadows) come from the design tokens — a raw hex or magic pixel in a component file is a smell; (4) before writing new CSS, check whether a utility class or existing component style already does it — duplicated style blocks drift apart and cause the 'why does this card look different' bug. Inline styles are reserved for truly dynamic values computed at runtime, nothing else. If a third-party style must be overridden, isolate the override in one clearly-commented place. Finish by explaining why the style now applies through structure — proving the cascade is understood, not bullied.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #413\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}