/* Hosting shim: make the whole showcase, not just the specimens, follow the
 * catalog's own Light/Dark choice.
 *
 * The approved catalog scopes its palette to [data-lt][data-theme] specimens;
 * its page chrome (--pg* literals, the sticky header's rgba fill, the light
 * shell background) was authored light-only. This file overrides only those
 * shell surfaces when <html data-host-theme="dark">, so the authority stays the
 * shipped build and no catalogue byte is edited.
 */

/* One background literal for the page, in both themes, on both elements.
 *
 * The catalogue's own `body{background-color:hsl(var(--background))}` is
 * rgb(246,243,238) and loads after this file, so a plain `body` rule here lost
 * the cascade and the page repainted from one off-white to the other once during
 * load. The `html body` selector wins that comparison without !important. And
 * <html> itself stays the *light* literal in dark unless it is set here too,
 * which is what the overscroll gutter paints — it flashed light on a rubber-band
 * scroll. color-scheme keeps the scrollbar and the gutter in the same theme.
 *
 * !important is required, not stylistic: the build pins the shell with
 * `:is(html, body, #app, #root):has([data-kl-root]) { background:#f3f2ef }`,
 * which carries an id's specificity and therefore beats any `html[...]` rule —
 * measured as a light <html> under a dark body, i.e. a light overscroll gutter
 * and a light first paint on a phone. Every other dark override in this file
 * already uses !important for the same reason. */
html, html body { background-color: #f3f2ef !important; color-scheme: light; }
html[data-host-theme="dark"], html[data-host-theme="dark"] body {
  background-color: #191919 !important;
  color-scheme: dark;
}

.catalog-loading {
  --placeholder-ink: #e3e1dc;
  min-height: 100vh;
  background: #f3f2ef;
  color: #2b2a27;
}
html[data-host-theme="dark"] .catalog-loading {
  --placeholder-ink: #303030;
  background: #191919;
  color: #e6e6e4;
}
@media (prefers-color-scheme: dark) {
  html:not([data-host-theme]) .catalog-loading {
    --placeholder-ink: #303030;
    background: #191919;
    color: #e6e6e4;
  }
}
.catalog-placeholder { display: none; }
.catalog-js .catalog-loading:not(.catalog-loading-slow) .catalog-placeholder { display: block; }
.catalog-js .catalog-loading:not(.catalog-loading-slow) .catalog-loading-copy { display: none; }
.catalog-placeholder i {
  display: block;
  height: 16px;
  border-radius: 8px;
  background: var(--placeholder-ink);
}
.catalog-placeholder-bar, .catalog-placeholder-content, .catalog-loading-copy {
  box-sizing: border-box;
  max-width: 1320px;
  margin-inline: auto;
  padding-inline: clamp(20px, 4vw, 32px);
}
.catalog-placeholder-bar {
  min-height: 65px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  column-gap: 16px;
  border-bottom: 1px solid var(--placeholder-ink);
}
.catalog-placeholder-bar i:first-child { width: 140px; }
.catalog-placeholder-bar i:last-child { width: min(100%, 400px); height: 36px; }
.catalog-placeholder-content { padding-top: 48px; }
.catalog-placeholder-content i { margin-bottom: 16px; width: min(100%, 570px); }
.catalog-placeholder-content i:first-child { height: 44px; width: min(75%, 380px); }
.catalog-placeholder-content i:nth-child(3) { width: min(65%, 420px); }
.catalog-placeholder-content i:last-child { width: 100%; height: 180px; margin-top: 44px; border-radius: 14px; }
.catalog-loading-copy { padding-block: 24px; }
.catalog-loading-copy a { color: inherit; }
.catalog-loading-slow .catalog-placeholder { display: none; }
@media (max-width: 599px) {
  .catalog-placeholder-bar { min-height: 110px; }
}

@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }

  ::view-transition-old(root), ::view-transition-new(root) {
    animation-duration: 160ms;
  }

  /* The two bars that must not move: the section bar and the page header.
   *
   * A named element is lifted out of the root cross-fade, so the 160 ms fade
   * no longer blends them with the arriving page — that fade is what made
   * both bars flicker on every route change, because the outgoing and
   * incoming frames are different documents with different mount states.
   *
   * Their groups get no animation at all: the bar is static HTML and the
   * header is prerendered before paint, so the two snapshots are the same
   * pixels and the only thing that can differ is the selected pill — and a
   * step, not a fade, is the honest way to show it. The old image is hidden
   * outright (the new frame alone is the truth; a stacked old frame would
   * ghost through the header's 96% fill), and the groups carry the page's
   * own background so that translucent fill composites over paper exactly
   * as it does at rest, whatever the root cross-fade paints in that region.
   *
   * Reduced motion stands down twice: the whole block is inside
   * no-preference, so a reduced-motion visitor gets no cross-document
   * transition and these rules never act. No pill slide is animated on
   * purpose — the selection is a step, the way the drawing reads it. */
  .sn { view-transition-name: kira-section-bar; }
  #root [data-lib] > div:first-child { view-transition-name: kira-page-header; }
  ::view-transition-group(kira-section-bar),
  ::view-transition-image-pair(kira-section-bar),
  ::view-transition-old(kira-section-bar),
  ::view-transition-new(kira-section-bar),
  ::view-transition-group(kira-page-header),
  ::view-transition-image-pair(kira-page-header),
  ::view-transition-old(kira-page-header),
  ::view-transition-new(kira-page-header) {
    animation: none !important;
  }
  /* The section bar's old image is dropped: the selected pill genuinely moves,
   * and two stacked bars would show two pills pressed at once.
   *
   * The page header does the opposite and keeps only its OLD image. Its old and
   * new snapshots are the same pixels on every section route (the header is
   * static markup), so either one is the truth — but Chromium intermittently
   * captured the NEW one as empty, which left a bare page-coloured band. And
   * stacking both is not an option either: the header's fill is 96% opaque, so
   * two copies over each other tint the mark and the wordmark by two levels.
   * The outgoing snapshot has been reliable in every run, so it is the one the
   * visitor keeps seeing. */
  ::view-transition-old(kira-section-bar),
  ::view-transition-new(kira-page-header) { opacity: 0; }
  /* The page's own chrome colour, so a translucent header composites exactly as
   * it does at rest whatever the root cross-fade paints beneath it. These two
   * literals are the one thing here with no token to point at: --pg and --sn-bg
   * carry these same values, but both are declared on descendants
   * ([data-kl-root] [data-lib], .sn) and the view-transition pseudo tree hangs
   * off html, so neither resolves here in light. Replace them with the token the
   * day the page background is hoisted to html. */
  ::view-transition-group(kira-section-bar),
  ::view-transition-group(kira-page-header) { background: #f3f2ef; }
  html[data-host-theme="dark"]::view-transition-group(kira-section-bar),
  html[data-host-theme="dark"]::view-transition-group(kira-page-header) { background: #191919; }
}

/* Theme change cross-fade.
 *
 * Scoped to the root snapshot only, and only while <html data-theme-tween> is
 * set — which theme-sync.js adds for one transition, from a deliberate pill
 * click, and removes when it finishes. Restoring a preference, a width change
 * and a first visit never set it, so nothing fades at startup. The navigation
 * fade below is untouched and still applies to real page loads.
 *
 * No `mix-blend-mode`, no `clip-path`, no per-element layers: one root
 * cross-fade, transform/opacity only, and no cost at rest. Browsers without
 * same-document view transitions never see these rules act (the JS falls back
 * to an instant apply), and reduced motion is honoured twice — the JS never
 * starts a transition, and this rule stands down as well. */
html[data-theme-tween]::view-transition-new(root) {
  animation: theme-fade-in 240ms cubic-bezier(0.2, 0, 0, 1);
}
/* The old frame stays opaque underneath: a symmetric cross-fade would show the
 * page backdrop through both snapshots at the midpoint and flash the mid-grey. */
@keyframes theme-fade-in { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  html[data-theme-tween]::view-transition-new(root) { animation: none !important; }
}

/* Shell background the build pins with :has([data-kl-root]). */
:is(html, body, #app, #root):has([data-kl-root]) { background-color: #f3f2ef; }
html[data-host-theme="dark"] :is(html, body, #app, #root):has([data-kl-root]) {
  background-color: #191919;
}

/* Page-chrome roles. Light values are the build's own; dark values mirror the
 * specimen dark palette so text keeps the same contrast. */
html[data-host-theme="dark"] [data-kl-root] [data-lib] {
  --pg: #191919;
  --pgcard: #202020;
  --pgline: #2e2e2e;
  --pgink: #e6e6e4;
  --pgink2: #a3a29e;
  --pgink3: #8c8b87;
}
html[data-host-theme="dark"] [data-kl-root] a { color: #e6e6e4; }

/* The sticky header paints a literal light rgba, not --pg. */
html[data-host-theme="dark"] [data-kl-root] [data-lib] > div:first-child {
  background: rgba(25, 25, 25, 0.96) !important;
  border-bottom-color: #2e2e2e !important;
}

/* The filter/theme pill trays likewise carry a literal light fill. Keeping them
 * light under a dark page would leave the (now light) inactive labels on a light
 * chip. The active pill keeps its dark fill and near-white label — the catalog's
 * intentional divergence — which still reads against a darker tray. */
html[data-host-theme="dark"] [data-kl-root] [data-lib] div[style*="rgb(229, 227, 222)"] {
  background: #262626 !important;
}

/* Selected pill in the dark shell.
 *
 * The shipped build marks the chosen pill with a dark fill (rgb(43,42,39)). On
 * a dark tray that fill is all but invisible — the same value, one step apart —
 * so "which one is on?" could not be answered by looking. The choice has to be
 * legible, and it has to be legible without relying on the fill alone.
 *
 * So the chosen pill is *raised* out of the sunken tray: a lighter fill, a 2px
 * inset ring that contrasts against the tray around it, and a heavier label.
 *
 * The selector reads the catalogue's own painted state — the inline
 * `rgb(43, 42, 39)` fill it puts on exactly one pill — and not aria-pressed.
 * The shipped build gives its filter tray no ARIA, and React re-renders these
 * buttons on mount and on every filter click without it: a rule keyed on
 * aria-pressed therefore matched the prerendered header (which the boot script
 * stamps) and stopped matching the moment React took over, so the chosen pill
 * visibly dropped from the ringed dark treatment back to the near-invisible
 * shipped fill — a flash on the first frame and on every route change, in every
 * engine that renders the header. ARIA is still published for assistive tech
 * (catalog-nav.js), but it is no longer what the paint depends on: the inline
 * fill is on both sides of the swap and cannot go missing.
 *
 * Scoped to the header trays, so no inspected specimen ([data-lt]) is touched,
 * and it applies only under the dark shell: the light design is unchanged.
 *
 * Measured: ring #7a7873 against tray #262626 = 3.5:1 (cue ≥ 3:1);
 *         label #fbfbfa on fill #3a3936 = 11.0:1 (label ≥ 4.5:1).
 *
 * shortcut: the inline `rgb(43, 42, 39)` literal is a paint detail, not an
 * API — it breaks if the catalogue restyles its selected pill; upgrade to the
 * published selected state (a data-attribute) when the page moves to
 * components (P3/P4), which retires this shim. */
html[data-host-theme="dark"] [data-kl-root] [data-lib] > div:first-child button[style*="rgb(43, 42, 39)"] {
  background: #3a3936 !important;
  color: #fbfbfa !important;
  font-weight: 650 !important;
  box-shadow: inset 0 0 0 2px #7a7873 !important;
}
/* Hovering an unselected pill must not be confused with the selection. */
html[data-host-theme="dark"] [data-kl-root] [data-lib] > div:first-child button:not([style*="rgb(43, 42, 39)"]):hover {
  background: #2f2f2d !important;
  box-shadow: inset 0 0 0 1px #4a4a46 !important;
}

/* Page prose carries literal light inks that would vanish on the darkened page.
 * A blanket remap is wrong: some of that prose sits on light "paper" cards that
 * legitimately stay light. theme-sync.js measures each chrome text node's real
 * contrast against its effective background and tags it:
 *   strong — light ink that still fails on a dark surface -> near-white
 *   muted  — mid ink on a dark surface                   -> secondary light
 *   dark   — text that went light-on-light (inherited)   -> dark ink
 * Specimens ([data-lt]) are never tagged, so the catalog's own palette stays
 * authoritative inside them. */
html[data-host-theme="dark"] [data-host-ink="strong"] { color: #e6e6e4 !important; }
html[data-host-theme="dark"] [data-host-ink="muted"] { color: #a3a29e !important; }
html[data-host-theme="dark"] [data-host-ink="dark"] { color: #37352f !important; }

/* Wrapper chrome (/devices/). Same roles, same dark values. The wrapper reads
 * its own light --pg* custom properties, so remap those first and let its rules
 * follow — only the two literal fills below need to be overridden directly. */
html[data-host-theme="dark"] {
  --pg: #191919;
  --pgcard: #202020;
  --pgline: #2e2e2e;
  --pgink: #e6e6e4;
  --pgink2: #a3a29e;
  --pgink3: #8c8b87;
}
html[data-host-theme="dark"] .bar {
  background: rgba(25, 25, 25, 0.96) !important;
  border-bottom-color: #2e2e2e !important;
}
html[data-host-theme="dark"] .seg { background: #262626 !important; }
html[data-host-theme="dark"] .seg button { color: #e6e6e4; }
html[data-host-theme="dark"] .seg button[aria-pressed="true"] {
  background: #202020;
  color: #fbfbfa;
}
html[data-host-theme="dark"] .stage { background: #191919; }
html[data-host-theme="dark"] .frame {
  background: #202020;
  box-shadow: 0 18px 40px -28px rgb(0 0 0 / 75%);
}

/* Header trays: hold their geometry across the webfont swap.
 *
 * The catalogue's pills size to their text, so when Hanken Grotesk replaces the
 * fallback the label re-measures and the button grows by ~2px — which moved the
 * whole page down (0.15 CLS on a phone, measured). A floor on the height and a
 * nowrap stops the reflow; the pill keeps its own padding and font, and the
 * widths it needs. Hosting-only: the export is untouched. */
[data-kl-root] [data-lib] > div:first-child button {
  white-space: nowrap;
  min-height: 34px;
}
html[data-host-theme="dark"] [data-kl-root] [data-lib] > div:first-child button {
  min-height: 34px;
}

/* The export's mark grid paints its construction grid as a background-image
 * data URL that its template spread across attributes, so the declaration the
 * browser receives is url("data:image/svg+xml") with no payload. It still tries
 * to load it — net::ERR_INVALID_URL in Chromium, "Data URL decoding failed" in
 * WebKit — and that console error is a Lighthouse best-practices failure on
 * /mark-motion/ and on /all/.
 *
 * Clearing it changes no pixels: a URL that cannot load paints nothing, so the
 * grid was never drawn (measured: 0 differing pixels in WebKit, 31 subpixel
 * pixels at channel delta 1 out of 3.16 M in Chromium, i.e. antialiasing
 * noise). Nothing is lost — nothing was ever shown.
 *
 * The [d] guard keeps this to exactly those 36 spans: it requires the `d`
 * attribute the attribute-spread created, so a legitimate svg+xml data URL
 * elsewhere in the catalogue is never touched. Hosted-only: the export's bytes,
 * and /all/, are unchanged. */
[style*="data:image/svg+xml"][d] { background-image: none !important; }

/* The catalogue adapter's spare canvas.
 *
 * The export's React adapter replaces every `<kira-mark size=N>` with its own
 * `ev()` component: a `display:block` span that always holds TWO canvases — a
 * blank one, then the painted one. Nothing clips the pair, so the span is twice
 * the mark's height and every mark sits half a mark below its baseline.
 *
 * Surveyed all 6 section routes plus /kit/ at 1440, both engines, light: the
 * shape exists only in the toast row (3 elements; span 32px in a 44px row, so
 * the visible mark sat 8px below the label and the dismiss X). The Mark motion
 * page's 37 canvases are single-canvas `kira-mark`s that paint and animate — it
 * never matches this selector, verified 0 hits there and 0 on /icons/,
 * /state/, /foundations/, /rule-book/.
 *
 * The first canvas is never painted (0 non-transparent pixels at alpha>8; the
 * painted second one has 159), so hiding it loses nothing and leaves one box of
 * the mark's own height, which the row's `align-items:center` then puts exactly
 * on the label's centre. Measured after, at 1440 and 390, both themes, both
 * engines: span 32 -> 16, markCY - labelCY +8.00 -> 0.00, dismissCY - labelCY
 * 0.00, row heights unchanged (44/46/46), CLS 0.00.
 *
 * `data-kl-live` is the adapter's own marker, so this reaches catalogue output
 * and nothing else — /all/ keeps the export's bytes and loads no shim.
 * `!important` because the adapter writes the canvases' `display:block` as an
 * inline style on the element itself. */
[data-lib] [data-kl-live] > span[aria-hidden="true"] > canvas:first-child:not(:last-child) {
  display: none !important;
}

/* The mono <code> in the Components intro, and the 1px shift it caused.
 *
 * `<code>data-theme</code>` is IBM Plex Mono at 13px inside a 1.55 line box.
 * The export gives Plex `font-display:swap`, so the fallback paints first and
 * the real face replaces it: measured ascent/descent 12/3 px (fallback) vs
 * 13/4 px (Plex) at 13px, so the inline box grows by 2px and everything below
 * moved up 1px — 603.2 -> 602.2, CLS 0.000066 on /components/ at 1440 in
 * Chromium (0 at 390, 0 in WebKit).
 *
 * A metric-matched local fallback fixes it without touching the route head or
 * the export's font rules: overrides set to Plex's own 13/4 at 13px
 * (ascent 100%, descent 30.77%, line-gap 0), so the swap changes no geometry.
 * Measured after: CLS 0.000000 at 1440 and 390 in Chromium and WebKit. The
 * real face is still first in the stack, so Plex still paints once it loads —
 * this only matches the fallback's box to it. If a browser has none of these
 * local monos it keeps the old stack and the old 1px. */
@font-face {
  font-family: "Kira Mono Fallback";
  src: local("DejaVu Sans Mono"), local("Liberation Mono"), local("Menlo"),
    local("Courier New");
  ascent-override: 100%;
  descent-override: 30.77%;
  line-gap-override: 0%;
}
/* !important, not stylistic: the export writes font-family as an inline style
 * on each <code>, so a plain rule loses the cascade. */
code {
  font-family: "IBM Plex Mono", "Kira Mono Fallback", ui-monospace, monospace !important;
}
