Part of [Design system](https://docs.mapcairn.com/design.md), which is built from [DESIGN.md](https://github.com/MapCairn/mapcairn/blob/main/DESIGN.md) in the repository, where it is edited.

- **Light DOM, no `static styles`.** `PrivateElement` draws into itself, so the vanilla-extract stylesheet, the tokens and the page's focus handling reach it. No template binds `style`; a computed style is set with `element.style.setProperty`.
- **Loading.** Lit's browser build extends `HTMLElement` as it is evaluated, which a server bundle that takes the `browser` condition cannot do, so nothing imports Lit statically from the package's entry. `privateElements` loads it with a dynamic `import()`, once for the page, in a chunk of its own.
- **The map view waits for it.** The element draws only in a browser. The map view it mounts renders nothing until the chunk has arrived, and neither its chrome nor its children are mounted, so every part of the interface finds its private elements defined in its first render: nothing below it loads anything or waits, and a parent's mount effect that moves focus into one finds it drawn. The reference host keeps its placeholder, the server's skeleton, up until the element has drawn, and its server render of `/map` preloads the chunk.
- **A server sends the skeleton only.** No part of the interface is drawn on a server, so a view is never hydrated from a server's markup. The code that keeps a server-drawn view (`useDrawnByAServer` and the branches that read it) has no way in from the public API and goes with the rewrite (#1127). Outside any map view (the component-states fixture's controls, say), a private element's React part asks for the load itself, is absent until the chunk has arrived and then appears. A tool that moves focus on opening has a button to give it to until then.
- **A load that fails.** It stays failed until the page is reloaded. The map view then shows no map, because a map is not drawn without its controls and credits. In the map's place is a region named as the map is, with `data-state="error"`, that holds "The map could not start. Reload the page to try again." (`app.banner.engineFailed`) and can take focus from a skip link. The notice is announced once, assertively, and the element sends one `mapcairn-error` with an `interface-load-failed` error, so `mountMap`'s `ready` rejects. The reason is its own, not `load-failed`, because no basemap is at fault. The call comes from a layout effect as the notice mounts: the reference host removes its placeholder there, and makes the wrapper around the view the page's `main`, because no chrome is drawn to hold one.
- **A load that stalls.** A map view that is holding itself back has nothing on screen to keep, so after `ELEMENTS_LOAD_TIMEOUT_MS` (30 seconds) it treats the load as failed, and says so even if the chunk arrives later.
- **As React commits.** `PrivatePart` (`packages/map/src/lit`) draws the element, sets its properties in a layout effect and calls `flush`, so a parent's effect finds what the element draws. A part that is one element and nothing else is a `LeafPart` (`lit/leafPart.ts`): the element's name, its box class and a plain `configure(element, props)` function, which an owner that is not React will be able to call too. `configure` takes the class of the element the part's key names, so a part cannot set another element's properties. `Leaf` draws one under React once the elements have loaded. The credits, the status message, the map key, the readout, the map overlays, the measure and draw toolbars, the search pill, the end stack, the sheet and the tour card are leaf parts (`attributionPart`, `statusMessagePart`, `mapKeyPart`, `readoutPart`, `toolOverlaysPart`, `measureToolbarPart`, `drawToolbarPart`, `searchPillPart`, `endStackPart`, `sheetPart` and `tourCardPart`).
- **A native control stays controlled.** The browser turns a checkbox or moves a range input before the callback runs, so the element draws the property with `live()` and calls `requestUpdate()` after reporting, and a parent that keeps the old value sees the control go back to it. So a `setChecked` or `setValue` handler must hand the parent's new value over in the same call, as a state setter or a store's `set` does; a handler that updates it later leaves the control showing the old value until then. The slider's `formatValue` is a plain field read at render, like a callback, because a React parent hands it a new arrow function on every commit and that must not draw the slider again; its text follows the next render that a label, range or value brings.
- **A private element reports with a callback property.** To tell its parent what a person did, an element calls a function the parent has set (`choose` on the segmented control, `setChecked` on the switch and `setValue` on the slider): a plain field, left out of `static properties` so that setting it never renders, called with a plain value and never wrapped or replaced by the element. It dispatches no event. A bubbling event from an element in the light DOM reaches the page's own listeners and becomes part of the public contract by accident, while a function is typed, is checked in a test with a mock, and is passed from a Lit template with a property binding. Only the public `<mapcairn-map>` reports with events (`mapcairn-*`), because a host is its parent.
- **Only a parent that is not Lit forces a render.** `flush()` on `PrivateElement` calls `performUpdate()` and has one caller: a React part, after it sets properties in a layout effect. An element never forces its own render. A change to its own state sets a reactive property or calls `requestUpdate()`, and the render runs in a microtask, before the next event a person can cause; a test waits on `updateComplete`. A Lit parent sets properties and awaits `updateComplete` when it must read what the child drew. Lit's documentation calls `performUpdate()` a rare case, and `flush()` goes with the last React part. The segmented control follows both conventions, so a later element copies it.
- **A panel section is an element, its words and rules are plain modules.** Each section is one element (`HelpSectionElement`, `ExportSectionElement`) that holds no copy and calls no catalogue: plain modules with their own tests (`helpContent`, `exportContent`) decide what it says. A **binding** beside it (`helpBinding`, `exportBinding`) hands it that content, memoised on its inputs (`memoLast`) because a new object would draw the section again, and keeps what the section does: Save image asks the map for the image, announces the result and keeps whether a save is under way or the last one failed, which reaches the element as `busy`, `failed` and `save`. The element never makes the image, and the pure steps (`imageOptions`, `filenameFor`, `saveBlob`) are plain modules too. The element's host (`elementHost` in `Section.css`) is `display: contents`, so its `section` is laid out as a child of the sheet's content. Its element extends `SectionElement` (`panels/Section`: `headingId`, `headingLevel` and the `heading` getter). The Pin section draws its own card, so `focusCard` finds it once the section has drawn (`pin-section.spec.ts`).
- **The sheet's content is one element** (`SheetContentElement`). It draws each part its parent hands it in `parts`, in one order, and holds no rule about which sheet is open. A plain function beside each part (`helpPart`) assembles what the part is drawn from, with what it takes from the services (`useSheetPartServices` reads them once and is given the map's engine, as the Directions panel's `useDirectionsServices` is given the engine and the view, so neither reads the map context); the Layers and Shapes parts are plain functions (`layersPart`, `shapesPart`) that `MountedSheet` gives the services' values the mount settled (`SheetServices`) and what the chrome measured (the session's state, through `sheetGeometryOf`, which adds the reading direction and the map key's clearance to `chromeGeometryOf`); and `sheetContentParts`, a plain function, picks the parts of the group the section names, so one content element stays as the sheet moves between its groups. The sheet element calls `arrive()` after each draw and passes a section only when it changes, and forgets it when the sheet holds nothing. The last one passed has its heading take focus once all it composes has drawn, unless focus has moved since the call (a control that left the page does not count as moving it), so the sheet's title keeps focus as the sheet opens; the heading scrolls to the top either way. After that the Layers section answers a tap on the map, so its card takes focus last. `focusCard()` waits the same way, behind a move already asked for.
- **The sheet is one element** (`SheetElement`, host `display: contents`, pinned in `sheet-host.spec.ts`) that composes only private elements: the content or the Directions panel, whichever `body` holds. The React `Sheet` takes the layout, the chrome's height and where to publish its edges as properties (`MountedSheet` hands it `sheetFeedOf` of the session and its state), takes the catalogue, the announcer and the motion preference as properties too (`MountedChrome` hands them on through `MountedSheet`) and hands them over with a callback for each report; `MountedSheet` calls the hooks of the body, and is given the chrome's state and the reading direction for them. The element owns what the sheet does: it asks the content for a section, then moves focus to the title as the sheet opens, and calls `restoreFocus` in a microtask after it closes, once a control that came back with the closing is on the page. It owns Escape, the Tab loop and its sentinels at full, dragging with its detents and announcements, the top edge and detent it publishes, the panel's far edge and the host's brand container, which it places in a row while the container holds something to see. A publication, the animation frame and each observer are let go when the element leaves the page and when the node they watch is replaced, and taken up when it returns.
- **A section that holds other private elements** (`SettingsSectionElement`, which draws four segmented controls and the switch). A template cannot bind a tag name, and the harmony scanner refuses `unsafeStatic`, so the section makes each control once, by the name `defineSegmentedControl()` or `defineSwitch()` gave this copy of the package, and draws the node: it is the same node on every render, so a control keeps its focus. The section sets the controls' properties as it renders, never calls `flush()` on them, and overrides `getUpdateComplete` to wait for the controls it is drawing, so its `updateComplete` means the whole section has drawn. `flush()` renders only the section's own nodes (its heading, say): the controls draw a microtask later, so a parent must not reach one synchronously, and a React test lets them draw before it queries; a control it is not drawing (the Language field of a host with one language) is never waited for, because an element that was never connected never completes. What it decides is in plain modules with their own tests: `settingsContent` (the words, which fields and parts exist, and which privacy address may be a link), `languageControl` (the choices, what is selected while a load has failed, and whether a pick stores the language or retries it) and `FocusClaim` (`lit`: focus goes to the selected language when Try again goes because the language loaded, and only if it had focus and nobody has moved it). A browser blurs the focused control as a render removes it, while it is still on the page, so `isConnected` cannot tell that blur from a person moving on: the element wraps its own `update` in `FocusClaim.during`, which takes the blur that comes inside it as the control leaving. `settingsBinding` makes the announcements (the map shape change, the language failure) and hands the element data and callback properties. `privacyNote` is plain text (`string | null`) because its only source is catalogue text; it was a React node before this section moved.
- **The readout and the credits** (`ReadoutElement`, `CreditsElement`) take words and links from `readoutContent` and `creditsContent`, and map facts as properties. The React `MapReadout` takes the catalogue, its landmark's name, the map's adapter, view and host and the motion preference as properties (`MountedChrome` passes them on and adds what the chrome's layout decides, through `readoutFor`), so it reads no context. The credits keep their state in `creditsSession`, which has no DOM. What a timer or a measurement changes alone (`data-idle`, the scale line's custom properties, `data-placement`, `data-readout-clear`, `data-settled`) is written straight to the node, never bound in a template. The credits' `elementHost` comes last in `Attribution.css`, because the server skeleton shares the class names generated before it. React's enter and leave events name the nearest element React drew as `relatedTarget`, so a React handler that looks inside a private element reads `nativeEvent.relatedTarget` (`usePointerPosition`).
- **The end stack is a leaf in its slot.** `EndStackElement` (host `display: contents`) draws the landmark, the compass and both groups from `endStackContent` and flat properties, and reports each press with a callback. The React `EndStack` decides whether the zoom group shows and registers the element's buttons as focus targets. The focus targets (`createFocusTargets`, which remembers the controls that open surfaces so closing one can put focus back) are a plain object the chrome makes once (`useFocusTargets`) and hands to each part that registers a control or returns focus (the end stack, the search pill, the draw toolbar and the tour card) as the property `focus`; no context carries them. The element writes the bearing and `data-scroll-more` straight to the landmark, and watches the column and the groups drawn in it afresh when a group comes or goes.
- **Shapes draws its own `ul`.** Each row is a `li` made by `listRowTemplate` (`ui/ListRow`), directly in the `ul`: an element between them breaks list semantics. `shapesContent` and `shapeRows` (two exports of one plain module) decide the words and rows. The host is `display: contents` (`shapes-section.spec.ts`).
- **The basemap picker is a leaf inside the Basemap section**, which `SheetContentElement` draws. `BasemapPickerElement` draws the radio group and the "Try again" button, and its host is also `display: contents` (pinned in `basemap-picker-host.spec.ts`), so the group is laid out as a child of that section. `basemapPickerContent` (a plain module with its own test) decides every word and tile, `basemapBinding` memoises it and announces a choice, and the element reports with `choose`, `keep` and `retry` callbacks. The preview's own load failure is the element's state, not the parent's.
- **The measure toolbar is a leaf in the bottom-centre slot.** `MeasureToolbarElement` draws the landmark, the toolbar, the mode switch (a segmented control it makes once, as Settings does), the total, the buttons and the hint; its host is `display: contents` (pinned in `measure-host.spec.ts`). `measureToolbarContent` decides every word, and the React `MeasureToolbar` takes its words (`measureToolbarContent`, with the landmark's name) and the page's reading direction as properties, as `DrawToolbar`, `MapKey` (its words and an id prefix) and `IdentifyStatus` (its line) do, because `MountedChrome` words them as it words the end stack and the credits, so none of them reads the catalogue or the page itself; it reads the measurement state (`useMeasureOf`, shared with the map overlay, over the `createMeasureSession` the mount makes, which holds the points, the mode and the wait before the total is announced with no React) and passes callbacks. The element moves focus to its first button once the switch has drawn, unless focus has moved since the element joined the page, because a parent that returns focus to the opener must win. The tour card is a leaf in the tour slot the same way (`TourCardElement`, host pinned in `tour-host.spec.ts`), and the React `TourCard` is given the controller's tour view and actions, the catalogue, the announcer and the motion preference as properties (`useMountedTour` takes the last three from `MountedChrome`), and reads nothing from context.
- **The search pill is one leaf element in the top-start slot** (`SearchPillElement`, host `display: contents`, pinned in `search-host.spec.ts`). The combobox, its listbox and every option are in one light-DOM tree, so `aria-controls` and `aria-activedescendant` name nodes that resolve in it. The element owns the search and suggestions sessions and the open list, active option and focus state, and one delegated `mousedown` keeps focus in the box when a button or an option is pressed; the React `SearchPill` takes `searchPillContent` (with the landmark's name), the two providers, the catalogue and the announcer as properties from `MountedChrome`, hands them to it, and registers the input, not the host, as the search focus target. An element may hold a framework-free session (`getSnapshot`, `subscribe`) when its state is local to it and nothing else reads it. It takes the narrow ports as properties (a provider, the catalogue, the announcer), never `Services` whole and never from context, and state that components share stays in the controller.
- **The draw toolbar is a leaf in the same slot.** `DrawToolbarElement` draws the landmark, the toolbar and the selected shape's group, and its host is `display: contents` (pinned in `draw-host.spec.ts`). `drawToolbarContent` decides every word and the group's name, and the React `DrawToolbar` takes the drawing state (`useDrawOf`, over the mount's `createDrawSession`; `bindDrawToAdapter` gives the map the selected shape's handles and passes its handle presses back, with no React), registers the Shapes button as the control focus returns to and passes callbacks. The element follows the scroller's edges itself (`watchScrollEdges`) and moves focus to the chosen shape type, unless focus has moved since it joined the page.
- **A status message is a leaf in the bottom-centre slot.** `StatusMessageElement` (host `display: contents`, pinned in `status-host.spec.ts`) draws one box that carries `data-status-message`, `data-testid` and the parent's class, and `MapChrome` reads that box, not the host, for the height a message takes. The element holds the live region (drawn empty and filled two frames after it joins the page, so the browser has laid out the empty one first), the countdown and the hand-back of focus (a browser reports the blur of a focused control being removed just before the element goes, so a blur with no related target counts as the message's for the rest of that turn), and keeps no timer or frame while it is off the page; the React `StatusMessage` takes the Dismiss name and the stop focus falls back to (`focusFallback`) as properties, as the banners and the identify line are given them by `MountedChrome`, and hands the element those, the text and the callbacks; it reads no context.
- **The chrome's layout has no framework.** `createChromeSession` (`chrome/MapChrome/chromeSession.ts`) measures the container and the slots, settles where the bottom slots, the end stack, the tour card and the map key rest (`settleChrome`, a pure function, and `measure`, which reads the slots' boxes), and writes the results as `chromeVars` through CSSOM. It is the only writer of `--chrome-bottom-end-rise`, from the observer's own callback and at the lifts the last settling chose, and it measures again when a lift, the key's tour edge or the readout's shift moves something no observer reports. `MountedMap` makes the session for each map, with the sheet's modality as it starts, and reads it once with `useChromeState` (in `chrome/MapChrome`), which copies its state into React state, tells the session each state it drew (`drawn`) and whether the sheet is modal (`setModal`), and hands session and state down, so every part that needs what the chrome measured is given it as properties and reads no context: pure selectors over the state (`chromeGeometryOf`, `endStackHeightOf`, `readoutFor` and `sheetFeedOf`, in `chrome/MapChrome/chromeSelectors.ts`) say where the chrome leaves the map free, how tall the end stack may be, what the readout shows and what the sheet is fed, and `MountedMap`, `MountedChrome` and `MountedSheet` hand those to the overlays, the directions on the map, the end stack, the map key, the readout, the tour card and the sheet. The React `MapChrome` is given the session and the state, keeps the slots and their markup, hands the session each slot and the container it measures (`attach`), measures again when the layout changes or a slot comes or goes, and still feeds `useChromeLayout` and the surface context from the state it is given, which only the test support reads now. The state is not `useSyncExternalStore`, whose render is synchronous: a change from the observer would render inside the observer's loop, with any other update pending (the readout losing its cursor coordinates), and a slot that render resized would be measured a frame late, after a frame with the map key where it was. React state set from the observer renders after the frame; set from a layout effect, before paint. So that a frame never pairs one state's attributes with another's properties, the session writes what goes with a new state (the width, the search pill's edge, the end stack's cap and width, the bottom-end rooms, the bottom row's lift and shift) once `useChromeState` says it has drawn that state (`drawn`), in the same commit as `data-layout`, `data-hide-bottom` and the crowded slots; a change that keeps the drawn state, and every change while nothing listens, is written at once. The raises, the rises and the map key's room, lift and tour edge are measurements, written from the observer's own callback, so the key can move a render before the tour card hides for it.
- **The map key is a leaf in the map-key slot.** `MapKeyElement` (host `display: contents`) draws the panel from `mapKeyContent` (words and rows, plain), the chrome's viewport, the host's `defaultMinimised` and an id prefix. Whether it is minimised is its own state (`mapKeyStart` decides how it starts). The tab stop and name of a body that scrolls are written straight to the node by `watchOverflow`, which is held only while the body is open and on the page.
- **The Directions panel is one element** (`DirectionsPanelElement`, host `display: contents`) that composes the stops, the place search, the result card and the travel mode switch. `directionsPart` assembles what the panel is drawn from (`useDirectionsServices` reads the services and the map), `directionsPanelBinding`, which has no React, memoises the words (`panelContent`, `panelStatus`) and sets the callbacks, and the React `DirectionsPanel` only draws the element. The element brings a result or a failure into view once all it composes has drawn (every host is pinned in `directions.spec.ts`).
- **The directions result card is a leaf in the panel's status block.** `DirectionsResultElement` draws the figures of a route or an area and its legs, from `resultContent` (words and slots, a plain module), which follows the units and the language, and its host is `display: contents`. It holds no state and reports nothing. Each figure is in `isolateTemplate` (`ui/Isolate`), and `slotParts` (a plain splitter) drops the isolate controls a right-to-left catalogue writes around a slot.
- **Templates for what the elements share.** A Lit template function sits beside the React primitive it replaces and uses the same vanilla-extract classes, so the two look alike while callers move over one at a time: `sectionTemplate`, `subheadingTemplate` and `sectionHeading` (`panels/Section`, a heading level picks one of five fixed tag literals, and `sectionHeading` finds the heading an element drew by its id), `listRowTemplate` (`ui/ListRow`) and `buttonTemplate` (`ui/Button`, with an optional icon, `mirrorInRtl`, `busy`, `disabled`, `pressed`, `describedBy`, test id, `className`, `ariaLabel` and a template as `label` in its one options object, which a later need joins rather than forking the template) and `iconButtonTemplate` (`ui/IconButton`, a compact or control size, `mirrorInRtl`, `disabled`, `busy`, `pressed`, `expanded`, `controls`, `className`, test id and `focusTarget`), `controlGroupTemplate` (`ui/ControlGroup`) and `iconTemplate` (`ui/Icon`, an icon alone, with `mirrorInRtl` and a class). The button templates draw `aria-busy` and `aria-disabled` only when set, the button stays focusable, a click does nothing while either is set, and a busy button swaps its icon for the spinning loader. A React primitive is deleted with its last React caller. The icon guide reads Lit icon constants too, and `iconMirroring.test.ts` fails a `mirrors` icon drawn without `mirrorInRtl`. Plain modules, such as `headingLevel`, hold what both sides use, so `HelpSectionElement` and the templates import nothing from React.
- **A leaf element under a section follows the same shape.** Its host is `display: contents`, a plain view module looks up every word, its parent keeps the announcements, the services and the file saver, and the element reports with callbacks. A row of a list keeps its `li` in the parent, so nothing sits between the list's `ul` and the row. An element that draws other private elements (a switch, the date and time control) makes each once (`ComposedElements`, which needs a template that `repeat` draws to be built before `repeat` runs), so the node is the same across renders and the focus left on it stays, and a control it stops drawing is made afresh when it returns. A view that reads the clock is keyed on what changed (`clockKey`), so a ticking clock does not rebuild it and a relative time is as of the last change. Glyphs are drawn through `glyphTemplate` (one `glyphGeometry` and `glyphSpec` under both the React and the Lit glyphs; `hatchPrefix` makes each pattern id unique), and a provider link is checked with `safeLink`. A view is rebuilt only when what it reads changes, so a card left open shows a relative time as of then. A blur the draw causes is the button leaving, which `FocusClaim` (`lit`, shared with Settings) tells apart from a person moving on. An input that reports on `input` shows a draft with `live()`; a select is set after each render, because a binding on it runs before its options exist.
- **Addresses are checked where the template writes them.** `linkAddresses.test.ts` reads `html` templates as it reads JSX: an `href`, `src` or other address attribute bound with `${}` must be named by an `isWebAddress`, `isSitePath`, `acceptedAddress` or `safeLink` check in the same function, so the check stays in the file that draws the link.
- **Two copies on a page.** Element names are global, so each copy defines its elements under the first free numbered name (`mapcairn-segmented-1`, then `-2`) and creates them by that name, so neither runs the other's class. The names are not part of any contract: select by role, name or `data-testid`.
- **One document.** A React tree portalled into another document is unsupported, because the elements are defined in the page's own.

Gesture equivalents: tapping a data point, polygon or line has the layer's list and its "Show on map" rows, and a tap that finds several features has the I key, which also asks the raster layers that answer a tap. Escape, on the map or from elsewhere on the page, ends such a lookup while it waits and does not also close the open surface; a second press closes it. Saving an image is a button, and importing shapes is a button that opens the browser's own file picker, with no drag and drop to need an equivalent. Drawing has Add point at map centre and the Space key. Selecting a point has Previous point, Next point and the bracket keys. Dragging a point has the arrow keys (Shift for more) and Move point to map centre. Tapping a midpoint handle to add a vertex has Add point after this one at map centre, and dragging a circle's radius handle has the radius buttons. Finish has Enter, Cancel has Escape and Remove point has Delete or Backspace. Long-press pin has "Drop pin at map centre" and the P key. Pinch and double-tap have the zoom buttons and +/-. Rotation has Shift with left and right arrows and the compass. Sheet drag has the handle button. Measure taps have "Add point at map centre". Directions stop taps have "Add stop at map centre", "Add dropped pin" and a place search, and any drag of a stop has the Move and Remove buttons.

## Overriding a primitive

The primitives are private to the element: a host cannot pass them a `className`, and this section is for contributors and for how a page's own rules meet the layer. The recipes of `Surface`, `Button` and `IconButton`, whose classes a component can pass on, are built with `primitiveRecipe` (`packages/map/src/ui/primitiveRecipe.ts`), as does the `ListRow` recipe, used by a template with no `className`. It puts every rule of the recipe, with its selectors and media queries, in one cascade layer (`primitives`, declared in `primitives.css.ts`). A style outside any layer beats a layered one whatever its specificity or the order the stylesheets load in, so a component restyles a primitive with a plain class passed as `className`: a background, a radius, a shadow, a border colour. Never double a selector (`&&`) to win, and never rely on the stylesheet order. A new primitive that takes a `className` uses `primitiveRecipe`; a recipe that is a component's own style (such as `StatusMessage`'s) stays a plain `recipe`.

What the layer changes:

- A component's plain rule also beats the recipe's state rules (hover, active, focus, pressed). A component that sets its own background therefore sets its own hover and focus styles, as the credits button does.
- Unlayered rules beat the primitives, in this repository and in an adopter's app. The host's default focus outline (`:where(:focus-visible)`, in `packages/web/src/global.css.ts`) outranks the recipes' own outline, so the two keep the same `outline` and `outlineOffset` (both come from `focusRing`; a test pins them). Do not add an unlayered rule for `button` or another element a primitive renders unless it is meant to win.
- Known trade-off for adopters: an unlayered element rule in an app (`button { background: transparent; border: 0; padding: 0 }`, say, or `:focus-visible { outline: none }`) now beats every primitive whatever its specificity or the stylesheet order. Before the layer, the primitive's class beat an element selector. An app's base styles and resets therefore go in an `@layer` that is declared before `@mapcairn/map/styles.css` is imported, because a layer declared earlier ranks lower, so the primitives outrank it. The layer name stays generated and private, so an app cannot order it by name. An adopter who hits a problem with this can open an issue.
- The built `styles.css` uses one layer with a generated name. Each file that holds primitive rules repeats the one-line statement `@layer <name>;` before its blocks, so the name is declared several times, in the middle of the file and not first; with one layer the repeats change nothing, and the first sits ahead of every block that uses it. `npm run consumer:check` builds a throwaway app with a layered reset imported before `styles.css` and checks a primitive keeps its background, padding and border.
- The browser bundle of `@mapcairn/sdk/browser` (a page with no build and no layered reset of its own) is the other case: its `browser.css` takes the layer apart (`withoutLayers` in `scripts/bundleOutput.mjs`), putting the primitives' rules first and in no layer, and starts with a reset (`pageReset`: `all: revert` for every element under the map but drawings, `box-sizing: border-box`, the default focus ring, an icon's fill and stroke, and the container's text from the tokens), so a page's rules that name elements (`button`, `*`, `svg`) do not reach the interface. Attribute selectors, and any rule of equal or higher specificity loaded later, still do, as does a rule on the container by id, and inherited properties that no component sets (`text-transform`, `letter-spacing`, `text-align`, `color` on the container) leak. The consumer check's hostile and leaks pages hold that distance (`docs/guides/releasing.md`). With no layer, a primitive's state rules now rank above a component's plain class by specificity, where in the host the component wins; the computed style of every interactive element in the bundle's composition, at rest, hovered, pressed, focused and open, is the same with and without the layer, and a component that sets its own background still sets its own hover and focus styles, as above.
- Forced colours and `prefers-contrast: more` still apply: they come from the tokens, which are not layered, and from the same layered rules.

`e2e/primitive-override.spec.ts` moves the recipe's rules to a stylesheet added last and checks the credits button keeps its surface, radius and shadow (its hover case passes without the layer and only guards the hover rule); `packages/core/src/lint/sdkDist.test.ts` checks the built `styles.css` and that every primitive recipe uses `primitiveRecipe`.
