/* 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.
 */

:is(html, body) { background-color: #f3f2ef; }
html[data-host-theme="dark"] :is(html, body) { background-color: #191919; }

.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;
  }
}

/* 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.
 * State comes from aria-pressed, which the hosting shims set from the value
 * actually applied — never from the catalog's painted colour, which no longer
 * carries the meaning.
 *
 * 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). */
html[data-host-theme="dark"] [data-kl-root] [data-lib] > div:first-child button[aria-pressed="true"] {
  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[aria-pressed="false"]: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; }
