Native CSS Nesting and Cascade Layers, from specificity risk to scoped component control.
This showcase documents the complete assignment from raw semantic HTML through prompt
engineering, human auditing, and a verified flight booking card that avoids specificity wars.
01Problem
02CSS Concepts
03Raw HTML
04AI Prompt
05Audit
06Final Result
07Verification
01
Why specificity wars make component CSS fragile
Large stylesheets need predictable precedence, clean component scope, and overrides that do not depend on selector escalation.
Before
A global button rule and a card-specific button rule can collide when both buttons share
the same generic .btn class. Without an architecture, developers often reach for
longer selectors, IDs, or !important just to make the component win.
Modern approach
Cascade Layers define which category of styles wins, while native CSS Nesting keeps the
flight card’s sub-elements visually and mechanically connected to the .booking-card
wrapper. The AI drafts the CSS, but a human audit confirms that no unlayered overrides or
flat repeated selectors slipped in.
Act as a senior CSS systems engineer. Generate a production-ready stylesheet for the supplied semantic flight-booking HTML without replacing its structural class system.
Architecture requirements:
1. Declare the cascade layer order at the very top of the stylesheet with @layer reset, base, components; exactly in that order.
2. Put only box sizing and basic margin cleanup in the reset layer. Use box-sizing: border-box for all elements and pseudo-elements.
3. Put page-level typography, global headings, the global header, default document spacing, and the generic .btn button style in the base layer.
4. Put every .booking-card rule and every flight-card sub-element rule in the components layer so component styles outrank base styles through layer order instead of specificity escalation.
5. Use native CSS Nesting inside the .booking-card wrapper. Nest sub-elements such as .booking-card__title, .booking-card__badge, .booking-card__route, .route-node, .connector-line, .connector-duration, and the card-scoped .btn directly inside .booking-card.
6. Use the & nesting selector for hover, active, focus-within, and card-scoped descendant rules. Do not write flat repeated selectors such as .booking-card .booking-card__title.
7. Preserve the fact that both buttons share the generic .btn class. The header button must keep the base .btn styling while the Manage Booking button receives the card-scoped component styling.
8. Do not use ID selectors, inline styles, unlayered overrides, preprocessors, JavaScript, frameworks, or !important.
9. Keep the component responsive with flexible route spacing, wrapping behavior, logical sizing, readable contrast, visible keyboard focus, and usable button target sizes.
10. Add concise comments only where they clarify the layer architecture, nesting scope, or specificity override test.
Return only the complete CSS stylesheet.
05
Auditing the generated nesting and layer system
The draft only becomes trustworthy after selector structure, layer precedence, and button behavior are inspected.