/**
 * bd-cursor — custom cursor system (native / label / badge / graphic / halo)
 * Version: 5.0.0
 * Updated: June 24, 2026
 * Model: ONE overlay element (.cursor-overlay) becomes the LABEL box, the BADGE
 *        circle, or the bare GRAPHIC by composing a shape class (.is-circle /
 *        .is-graphic / none = label box) with the root .bd-cursor-replacing flag
 *        (native hidden + halo off + larger "riding" size). Authored via
 *        data-cursor-label / -icon / -icon-end / -badge / -graphic, the
 *        data-cursor-replace boolean (hide native, the atom rides the pointer),
 *        and data-cursor-native (carve-out: restore the OS pointer inside a
 *        replace region). All glyphs are SVG <use> refs into _sprite.svg — no PNG.
 * History: v4.x used .cursor-label + data-cursor-solo/-hide + .is-icon-only/.is-solo.
 *          v5 renames the surface to .cursor-overlay, splits shape (.is-circle) from
 *          riding state (.bd-cursor-replacing), adds the bare .is-graphic, renames
 *          the carve-out to a self-sufficient data-cursor-native, and the slot flag
 *          .is-active → .has-glyph.
 */

/* Hidden by default on touch/tablet/narrow viewports — chrome injects these
   elements on every page, so without this they fall back to block-level
   defaults below the footer and break layout. Desktop pointer query below
   opts them back in. */
.cursor-overlay,
.cursor-halo {
  display: none;
}

/* Desktop pointer-only — additive overlay on top of the native cursor */
@media (min-width: 991px) and (hover: hover) and (pointer: fine) {
  :root {
    --cursor--color: var(--text-accent);
    --cursor-5:  color-mix(in srgb, var(--cursor--color), var(--alpha-5));
    --cursor-10: color-mix(in srgb, var(--cursor--color), var(--alpha-10));
    --cursor-20: color-mix(in srgb, var(--cursor--color), var(--alpha-20));
    --cursor-50: color-mix(in srgb, var(--cursor--color), var(--alpha-50));
    --cursor-90: color-mix(in srgb, var(--cursor--color), var(--alpha-90));
  }

  /* Overlay — invisible at rest; .is-visible toggles fade-in. Position is set by
     JS via translate3d every frame (below the pointer in float modes; centred on
     it under .bd-cursor-replacing). Default look = the LABEL box: accent fill,
     inverted text, square corners. Shape classes below switch it to a badge circle
     or a bare graphic. */
  .cursor-overlay {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 10001;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 0;
    background: var(--cursor--color);
    /* Mode-aware text on the accent fill — off-white on the light-mode blue,
       near-black on the dark-mode yellow. Same token the filled buttons use.
       The icon follows via currentColor. */
    color: var(--text-inverted);
    font-family: inherit;
    font-size: 15px;
    line-height: 1;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transform: translate3d(0, 0, 0);
    will-change: transform, opacity;
    transition: opacity var(--duration-2xs) var(--ease-out);
  }

  /* REPLACE — an element flagged data-cursor-replace hides the native cursor over
     itself (and its children) and lets the atom (badge / graphic / label) ride
     the pointer. Gated behind .bd-cursor-ready, which JS adds only once the cursor
     is confirmed live (desktop, not reduced-motion, DOM present), so no-JS /
     reduced-motion / init-failure never hide the cursor with nothing to replace
     it. The descendant rule is required because children set their own cursor
     (e.g. cursor:pointer on links). When Barba removes the element on navigation,
     the rule stops matching and the native cursor self-heals — no JS needed for
     the hide half. */
  .bd-cursor-ready [data-cursor-replace],
  .bd-cursor-ready [data-cursor-replace] *,
  /* GRAPHIC always replaces the OS pointer (it IS a cursor graphic), so hide the
     native cursor over [data-cursor-graphic] too — matching the engine, which
     forces replace for graphics even without the explicit attribute. */
  .bd-cursor-ready [data-cursor-graphic],
  .bd-cursor-ready [data-cursor-graphic] * {
    cursor: none;
  }

  /* NATIVE carve-out — restores the real OS pointer inside a replace region (the
     keystone a11y atom: a precise control, e.g. the video scrubber, opts back to
     the native pointer). Self-sufficient: it emits its OWN cursor:auto, placed
     AFTER the replace rule so it wins at equal specificity — the carve-out works
     even if the consumer writes no CSS. A consumer may still set a more specific
     cursor (e.g. .bd-video-scrubber{cursor:pointer}) which wins by source order. */
  .bd-cursor-ready [data-cursor-native],
  .bd-cursor-ready [data-cursor-native] * {
    cursor: auto;
  }

  /* While a badge/graphic rides the pointer the click halo would bloom underneath
     it and read as noise. Hide it while replacing. */
  .bd-cursor-replacing .cursor-halo {
    display: none;
  }

  .cursor-overlay.is-visible {
    opacity: 1;
  }

  /* BADGE (.is-circle) — icon in an accent circle. Inherits the accent fill +
     inverted glyph from the base. 40px floating beside the native pointer; 56px
     when it rides the pointer (.bd-cursor-replacing) — the home-hero look. */
  .cursor-overlay.is-circle {
    padding: 6px;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    justify-content: center;
  }

  .cursor-overlay.is-circle .cursor-overlay-icon {
    width: 1em;
    height: 1em;
  }

  .bd-cursor-replacing .cursor-overlay.is-circle {
    width: 56px;
    height: 56px;
    font-size: 22px;
  }

  /* GRAPHIC (.is-graphic) — a cursor graphic from the cursor sprite (an exaggerated
     OS cursor), NO box / background. Two-tone cursors carry their OWN #fff/#000 fills
     (presentation attrs beat inherited fill), so `color` never reaches them. A graphic
     authored with fill="currentColor" (e.g. the By Default logo) DOES follow this
     `color` — set to --text-primary so it inherits the theme and stays visible in both
     light and dark. Graphic always replaces the pointer, so the "replacing" size is the
     one that shows; the smaller rule is a dead fallback. */
  .cursor-overlay.is-graphic {
    padding: 0;
    border-radius: 0;
    width: auto;
    height: auto;
    background: transparent;
    color: var(--text-primary);
    justify-content: center;
  }

  .cursor-overlay.is-graphic .cursor-overlay-icon {
    width: 32px;
    height: 32px;
  }

  .bd-cursor-replacing .cursor-overlay.is-graphic .cursor-overlay-icon {
    width: 100px;
    height: 100px;
  }

  /* Icon slots — both leading and trailing default to hidden. JS toggles
     .has-glyph on the slots that are populated for the current target. */
  .cursor-overlay-icon {
    width: 14px;
    height: 14px;
    flex: 0 0 auto;
    display: none;
    align-items: center;
    justify-content: center;
  }

  .cursor-overlay-icon.has-glyph {
    display: inline-flex;
  }

  .cursor-overlay-icon svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
  }

  /* Text — collapses when empty so icon-only / icon+icon layouts stay tight. */
  .cursor-overlay-text:empty {
    display: none;
  }

  /* Halo — invisible at rest; click feedback only via .cursor-pressed (90px). */
  .cursor-halo {
    display: block;
    width: 0;
    height: 0;
    border-radius: 100%;
    background-color: var(--cursor-5);
    border: 2px solid var(--cursor-5);
    position: fixed;
    left: 0;
    top: 0;
    transform: translate(-50%, -50%) scale(1);
    transform-origin: center center;
    pointer-events: none;
    z-index: 10000;
    will-change: transform;
    transition: width var(--duration-xs) var(--ease-out), height var(--duration-xs) var(--ease-out), background-color var(--duration-xs);
  }

  .cursor-pressed {
    width: 90px;
    height: 90px;
    background-color: var(--cursor-20);
    border-color: var(--cursor-10);
  }
}
