/* BSA buttons: the shared button layer for every BSA page (gallery1486, projects, account, landing).

   "Calm ink": commands are 6px-radius rectangles, states (chips, segments) are capsules. One height ladder, one
   hierarchy, 44px touch targets, a two-tone focus ring and a 1px press. Opaque fills only: no blur, no translucent
   glass, no sheen, no gradient.

   Load it after the page stylesheets. Class API (guide and mapping of the old classes: docs/design/buttons.md):
     .bsa-btn                     secondary button: paper fill, 3:1 grey edge, top highlight (default)
       --primary | --ink          solid fill (accent orange, once per view | navy, for repeated main actions)
       --tertiary                 text button with a permanent hairline underline; a light fill appears on hover
       --danger                   destructive: red text button (solid together with --primary)
       --xs | --sm | --lg | --xl  28 / 32 / 40 / 48px (default 36px); coarse pointers always get 44px
       --chip                     state capsule, 32px
       --icon                     square icon-only button; needs aria-label
       --pill                     capsule shape
     .bsa-badge                   count badge inside a button (always ink, never orange)
     .bsa-toolbar                 group of buttons; its buttons are plain unless they name a variant
     .bsa-segmented               segmented control (children: .bsa-btn with aria-pressed or aria-selected)
   Context classes swap the tokens for everything inside: .bsa-on-dark (navy rail, AI panel head, camera dark mode, the
   dark reader stage) and .bsa-on-media (over photos, video and the camera: opaque dark fill, white edge).
   States, each with its own signal: hover = ink edge + cool fill; pressed = 1px down + darker fill + inner shade;
   selected = 2px ring + cool fill + tick (white raised key in a segmented control); disabled = flat paper fill + dashed
   edge (no opacity); busy = label kept + spinner + bottom line. Hover only where some pointer can hover.
   Current navigation item: [aria-current=page]. */

:root {
  --bsa-tick: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5l10-10'/%3E%3C/svg%3E");
}
/* The colour tokens this layer reads (--bsa-btn-fg, --bsa-fill, ..., standard values and every other skin's) are in bsa-skins.css. */

/* Navy rail, AI panel head, camera dark mode, the dark reader stage. Every fill is solid: it suits every dark ground
   without letting the ground show through. */
.bsa-on-dark {
  --bsa-btn-fg: #ffffff;
  --bsa-fg-hover: #ffffff;
  --bsa-fill: #0b2a52;
  --bsa-fill-hover: #16396b;
  --bsa-fill-press: #1d4478;
  --bsa-edge: #6f86a8;
  --bsa-edge-hover: #cfe0f5;
  --bsa-drop: 0 0 #0000;
  --bsa-press-shade: inset 0 2px 3px rgba(0, 0, 0, .35);
  --bsa-material: #0b2a52;
  --bsa-line: #2f4461;
  --bsa-lift: 0 1px 2px rgba(0, 0, 0, .35);
  --bsa-tertiary-fg: #c0d2e7;
  --bsa-tertiary-fg-hover: #ffffff;
  --bsa-tertiary-underline: #46607f;
  --bsa-hover-tint: #123760;
  --bsa-tertiary-press: #1a447a;
  --bsa-track-fill: #011530;
  --bsa-track-hover: #123760;
  --bsa-track-press: #1a447a;
  --bsa-seg-fg: #c0d2e7;
  --bsa-selected-bg: #1d4478;
  --bsa-selected-bg-hover: #255388;
  --bsa-selected-fg: #ffffff;
  --bsa-selected-edge: #ffffff;
  --bsa-current-edge: #344965;
  /* A navy button would vanish on the navy rail: on dark grounds the repeated main action is light with navy text. */
  --bsa-ink: #eef3f9;
  --bsa-ink-hover: #ffffff;
  --bsa-ink-press: #dbe4f0;
  --bsa-on-ink: #011b3e;
  --bsa-danger-fg: #ffb4a2;
  --bsa-danger-fg-hover: #ffd2c6;
  --bsa-danger-underline: #7f4a42;
  --bsa-danger-tint: #4a2a2c;
  --bsa-danger-press: #5a3232;
  --bsa-dis-bg: #0e2547;
  --bsa-dis-edge: #4d6585;
  --bsa-dis-fg: #9db1cc;
  --bsa-focus-ring: #ffb48a;
  --bsa-focus-gap: #011b3e;
  --bsa-badge-bg: #dbe4f0;
  --bsa-badge-fg: #011b3e;
  --bsa-badge-ring: #011b3e;
}

/* Over photos, video and the camera, whose pixels can be anything from white to black. The dark fill is opaque, and
   so is every state of it: a white edge separates it from white pixels, a dark one from black. No alpha anywhere. */
.bsa-on-media {
  --bsa-btn-fg: #ffffff;
  --bsa-fg-hover: #011b3e;
  --bsa-fill: #0e1a2a;
  --bsa-fill-hover: #dbe4f0;
  --bsa-fill-press: #b8c6d8;
  --bsa-edge: #ffffff;
  --bsa-edge-hover: #ffffff;
  --bsa-drop: 0 0 #0000;
  --bsa-press-shade: 0 0 #0000;
  --bsa-material: #0e1a2a;
  --bsa-line: #3d4d63;
  --bsa-lift: 0 1px 2px rgba(0, 0, 0, .35);
  --bsa-tertiary-bg: #0e1a2a;
  --bsa-tertiary-fg: #ffffff;
  --bsa-tertiary-fg-hover: #011b3e;
  --bsa-tertiary-edge: #3d4d63;
  --bsa-tertiary-underline: #ffffff;
  --bsa-hover-tint: #dbe4f0;
  --bsa-tertiary-press: #b8c6d8;
  --bsa-track-fill: #1f2f45;
  --bsa-track-hover: #33496a;
  --bsa-track-press: #455f86;
  --bsa-seg-fg: #ffffff;
  --bsa-selected-bg: #ffffff;
  --bsa-selected-bg-hover: #eef3f9;
  --bsa-selected-fg: #011b3e;
  --bsa-selected-edge: #ffffff;
  --bsa-current-bg: #ffffff;
  --bsa-current-bg-hover: #eef3f9;
  --bsa-current-edge: #ffffff;
  --bsa-accent-edge: #ffffff;
  --bsa-accent-edge-hover: #ffffff;
  --bsa-ink: #ffffff;
  --bsa-ink-hover: #dbe4f0;
  --bsa-ink-press: #b8c6d8;
  --bsa-on-ink: #011b3e;
  --bsa-danger-fg: #ffb4a2;
  --bsa-danger-fg-hover: #7a2d1a;
  --bsa-danger-underline: #ffb4a2;
  --bsa-danger-tint: #dbe4f0;
  --bsa-danger-press: #b8c6d8;
  --bsa-dis-bg: #1b2a3d;
  --bsa-dis-edge: #7d8da3;
  --bsa-dis-fg: #c9d5e4;
  --bsa-focus-ring: #ffffff;
  --bsa-focus-gap: #011b3e;
  --bsa-badge-bg: #dbe4f0;
  --bsa-badge-fg: #011b3e;
  --bsa-badge-ring: #0e1a2a;
}

/* ── Button ─────────────────────────────────────────────────────────────────────────────────────────────────────
   Every colour reads a private --_ variable; variants and states only swap those variables. Layout (display, position,
   alignment, margin) sits at zero specificity, so a page rule such as `.x { display: none }`, a nav row's
   `justify-content` or a control's own margin still wins; size and type
   at (0,2,0) yield to a page's own rule for a specific control; the colours at (0,3,0) outrank the old page defaults
   (`.bsa-cloud button[aria-pressed=true]`, `.bsa-cloud button:hover`). */
:where(.bsa-btn) { position: relative; display: inline-flex; align-items: center; justify-content: center; box-sizing: border-box; margin: 0 }
:where(.bsa-toolbar, .bsa-segmented) { display: inline-flex }
:root :is(.bsa-btn, .bsa-toolbar, .bsa-segmented)[hidden] { display: none }
:root .bsa-btn {
  --_bg: var(--bsa-fill);
  --_bg-hover: var(--bsa-fill-hover);
  --_bg-press: var(--bsa-fill-press);
  --_fg: var(--bsa-btn-fg);
  --_fg-hover: var(--bsa-fg-hover);
  --_edge: var(--bsa-edge);
  --_edge-hover: var(--bsa-edge-hover);
  --_drop: var(--bsa-drop);
  --_press: var(--bsa-press-shade);
  --_h: 36px;
  gap: 8px;
  min-height: var(--_h);
  padding: 6px 14px;
  border-width: 1px;
  border-style: solid;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0;
  text-align: center;
  text-decoration: none;
  /* Labels wrap instead of being cut: Chinese and English both stay whole at any width. */
  white-space: normal;
  overflow-wrap: break-word;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: background-color .14s cubic-bezier(.4, 0, .2, 1), border-color .14s cubic-bezier(.4, 0, .2, 1), color .14s cubic-bezier(.4, 0, .2, 1), box-shadow .14s cubic-bezier(.4, 0, .2, 1), transform .07s cubic-bezier(.4, 0, .2, 1);
}
:root .bsa-btn.bsa-btn {
  border-color: var(--_edge);
  background-color: var(--_bg);
  color: var(--_fg);
  box-shadow: var(--_drop);
}
:root .bsa-btn svg { flex: none }
/* Height ladder: 28 / 32 / 36 / 40 / 48. --sm is 32 (it was 34); --xs is new; --xl is for the landing hero. */
:root .bsa-btn--xs { --_h: 28px; gap: 6px; padding: 4px 10px; font-size: 12px }
:root .bsa-btn--sm { --_h: 32px; gap: 6px; padding: 5px 12px; font-size: 13px }
:root .bsa-btn--lg { --_h: 40px; gap: 8px; padding: 8px 18px; font-size: 15px }
:root .bsa-btn--xl { --_h: 48px; gap: 10px; padding: 8px 24px; font-size: 16px }
:root .bsa-btn--chip { --_h: 32px; gap: 6px; padding: 5px 14px; border-radius: 999px; font-size: 13px }
:root .bsa-btn--pill { border-radius: 999px }
:root .bsa-btn--icon { width: var(--_h); min-width: var(--_h); padding: 0 }
:root .bsa-btn--icon.bsa-btn--pill { border-radius: 50% }

/* Toolbars give their children the plain look; an explicit variant still wins (declared below). */
:root :where(.bsa-toolbar) .bsa-btn {
  --_bg: var(--bsa-tertiary-bg);
  --_bg-hover: var(--bsa-hover-tint);
  --_bg-press: var(--bsa-tertiary-press);
  --_edge: transparent;
  --_edge-hover: transparent;
  --_drop: 0 0 #0000;
}

:root .bsa-btn--secondary {
  --_bg: var(--bsa-fill);
  --_bg-hover: var(--bsa-fill-hover);
  --_bg-press: var(--bsa-fill-press);
  --_edge: var(--bsa-edge);
  --_edge-hover: var(--bsa-edge-hover);
  --_drop: var(--bsa-drop);
}
:root .bsa-btn--primary {
  --_bg: var(--bsa-accent);
  --_bg-hover: var(--bsa-accent-hover);
  --_bg-press: var(--bsa-accent-press);
  --_fg: var(--bsa-on-accent);
  --_fg-hover: var(--bsa-on-accent);
  --_edge: var(--bsa-accent-edge);
  --_edge-hover: var(--bsa-accent-edge-hover);
  --_drop: 0 0 #0000;
  --_press: inset 0 2px 3px rgba(120, 40, 0, .3);
}
:root .bsa-btn--ink {
  --_bg: var(--bsa-ink);
  --_bg-hover: var(--bsa-ink-hover);
  --_bg-press: var(--bsa-ink-press);
  --_fg: var(--bsa-on-ink);
  --_fg-hover: var(--bsa-on-ink);
  --_edge: var(--bsa-ink);
  --_edge-hover: var(--bsa-ink-hover);
  --_drop: 0 0 #0000;
}
:root .bsa-btn--tertiary {
  --_fg: var(--bsa-tertiary-fg);
  --_fg-hover: var(--bsa-tertiary-fg-hover);
  --_bg: var(--bsa-tertiary-bg);
  --_bg-hover: var(--bsa-hover-tint);
  --_bg-press: var(--bsa-tertiary-press);
  --_edge: var(--bsa-tertiary-edge);
  --_edge-hover: var(--bsa-tertiary-edge);
  --_drop: 0 0 #0000;
  font-weight: 500;
}
/* A text button keeps a hairline underline, so it still reads as clickable at rest. */
:root .bsa-btn--tertiary:not(.bsa-btn--icon),
:root .bsa-btn--danger:not(.bsa-btn--icon):not(.bsa-btn--primary) {
  text-decoration: underline;
  text-decoration-color: var(--bsa-tertiary-underline);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}
:root .bsa-btn--danger {
  --_fg: var(--bsa-danger-fg);
  --_fg-hover: var(--bsa-danger-fg-hover);
  --_bg: var(--bsa-tertiary-bg);
  --_bg-hover: var(--bsa-danger-tint);
  --_bg-press: var(--bsa-danger-press);
  --_edge: var(--bsa-tertiary-edge);
  --_edge-hover: var(--bsa-tertiary-edge);
  --_drop: 0 0 #0000;
  font-weight: 500;
}
:root .bsa-btn--danger:not(.bsa-btn--icon):not(.bsa-btn--primary) { text-decoration-color: var(--bsa-danger-underline) }
:root .bsa-btn--danger.bsa-btn--primary {
  --_bg: var(--bsa-danger-solid);
  --_bg-hover: var(--bsa-danger-solid-hover);
  --_bg-press: var(--bsa-danger-solid);
  --_fg: #ffffff;
  --_fg-hover: #ffffff;
  --_edge: var(--bsa-danger-solid);
  --_edge-hover: var(--bsa-danger-solid-hover);
  font-weight: 600;
}

/* Hover only where some pointer can hover (a mouse, or an iPad's trackpad); a finger-only screen never shows it, and
   nothing depends on it. The edge turns ink and the fill goes cool. */
@media (any-hover: hover) {
  :root .bsa-btn:hover:not(:disabled):not([aria-disabled=true]) { --_bg: var(--_bg-hover); color: var(--_fg-hover); border-color: var(--_edge-hover) }
  :root .bsa-btn--tertiary:hover:not(.bsa-btn--icon):not(:disabled):not([aria-disabled=true]),
  :root .bsa-btn--danger:hover:not(.bsa-btn--icon):not(.bsa-btn--primary):not(:disabled):not([aria-disabled=true]) { text-decoration-color: currentColor }
}

/* Selected: a 2px ring (border + inner line) and a cool fill, plus a tick on chips only (a tick on other buttons would
   make them wider when switched on); primary buttons stay orange. Distinct from hover
   (ink edge, lighter fill) and from pressed (1px down, darker fill, inner shade). */
:root .bsa-btn:is([aria-pressed=true], [aria-selected=true], .is-selected):not(.bsa-btn--primary) {
  --_bg: var(--bsa-selected-bg);
  --_bg-hover: var(--bsa-selected-bg-hover);
  --_bg-press: var(--bsa-selected-bg-hover);
  --_fg: var(--bsa-selected-fg);
  --_fg-hover: var(--bsa-selected-fg);
  --_edge: var(--bsa-selected-edge);
  --_edge-hover: var(--bsa-selected-edge);
  --_drop: inset 0 0 0 1px var(--bsa-selected-edge);
  --_press: inset 0 0 0 1px var(--bsa-selected-edge), var(--bsa-press-shade);
  font-weight: 600;
}
:root .bsa-btn--primary:is([aria-pressed=true], .is-selected) { --_edge: var(--bsa-selected-edge); --_edge-hover: var(--bsa-selected-edge) }
:root .bsa-btn:is([aria-pressed=true], .is-selected):is(.bsa-btn--tertiary, .bsa-btn--danger):not(.bsa-btn--icon) { text-decoration-color: currentColor }
:root .bsa-btn--chip:is([aria-pressed=true], [aria-selected=true], .is-selected):not([aria-current])::before {
  content: "";
  width: 14px;
  height: 14px;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--bsa-tick) center / 14px no-repeat;
  mask: var(--bsa-tick) center / 14px no-repeat;
}
/* The current item of a navigation list: a light chip with the one orange edge; position is what orange means. */
:root .bsa-btn:is([aria-current=page], [aria-current=true]) {
  --_bg: var(--bsa-current-bg);
  --_bg-hover: var(--bsa-current-bg-hover);
  --_bg-press: var(--bsa-current-bg-hover);
  --_fg: var(--bsa-current-fg);
  --_fg-hover: var(--bsa-current-fg);
  --_edge: var(--bsa-current-edge);
  --_edge-hover: var(--bsa-current-edge);
  --_drop: inset 3px 0 0 var(--bsa-accent);
  --_press: inset 3px 0 0 var(--bsa-accent);
  text-decoration: none;
  font-weight: 600;
}
/* A current item that is also on keeps its orange edge: position still reads. */
:root .bsa-btn:is([aria-current=page], [aria-current=true]):is([aria-pressed=true], [aria-selected=true], .is-selected) {
  --_drop: inset 3px 0 0 var(--bsa-accent);
  --_press: inset 3px 0 0 var(--bsa-accent);
}

/* Pressed: 1px down, a darker fill and an inner shade, at once on touch too (iOS applies :active only while a touch
   listener exists: bsa-buttons.mjs adds a passive one; the grey tap flash is off). No bounce. */
:root .bsa-btn.bsa-btn:active:not(:disabled):not([aria-disabled=true]) {
  --_bg: var(--_bg-press);
  color: var(--_fg-hover);
  border-color: var(--_edge-hover);
  transform: translateY(1px);
  box-shadow: var(--_press);
  transition-duration: .07s;
}

/* Keyboard focus: a two-tone ring (3px gap + 2px ring) so one of the two always contrasts with whatever is behind it. */
:root .bsa-btn.bsa-btn:focus-visible {
  outline: 2px solid var(--bsa-focus-ring);
  outline-offset: 3px;
  box-shadow: 0 0 0 3px var(--bsa-focus-gap), var(--_drop);
}
:root .bsa-btn:focus:not(:focus-visible) { outline: none }

/* Disabled is flat, not faded: paper fill, dashed edge, no underline. Busy buttons keep their own colours. */
:root .bsa-btn:is(:disabled, [aria-disabled=true]):not([aria-busy=true], .is-loading) {
  --_bg: var(--bsa-dis-bg);
  --_bg-hover: var(--bsa-dis-bg);
  --_bg-press: var(--bsa-dis-bg);
  --_fg: var(--bsa-dis-fg);
  --_fg-hover: var(--bsa-dis-fg);
  --_edge: var(--bsa-dis-edge);
  --_edge-hover: var(--bsa-dis-edge);
  --_drop: 0 0 #0000;
  border-style: dashed;
  cursor: not-allowed;
  text-decoration: none;
  transform: none;
}

/* Busy: the label stays (a count can ride in it), a spinner leads it and a thin line runs along the bottom edge. The
   accessible name does not change. */
:root .bsa-btn.bsa-btn:is([aria-busy=true], .is-loading) { pointer-events: none; cursor: progress; overflow: hidden }
:root .bsa-btn:is([aria-busy=true], .is-loading) > svg:first-child { display: none }
:root .bsa-btn.bsa-btn:is([aria-busy=true], .is-loading)::before {
  content: "";
  width: 14px;
  height: 14px;
  flex: none;
  box-sizing: border-box;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  background: none;
  -webkit-mask: none;
  mask: none;
  animation: bsa-btn-spin .7s linear infinite;
}
:root .bsa-btn:is([aria-busy=true], .is-loading)::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 34%;
  height: 3px;
  background: currentColor;
  animation: bsa-btn-scan 1.2s linear infinite;
}
@keyframes bsa-btn-spin { to { transform: rotate(360deg) } }
@keyframes bsa-btn-scan { from { transform: translateX(-100%) } to { transform: translateX(300%) } }

/* Count badge: <span class="bsa-badge" aria-hidden="true">3</span>; the count also goes in the accessible name. Ink,
   never orange: orange is for the one main action and the current position. */
:root .bsa-badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--bsa-badge-bg);
  color: var(--bsa-badge-fg);
  box-shadow: 0 0 0 2px var(--bsa-badge-ring);
  font: 600 11px/1 'IBM Plex Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  text-decoration: none;
  pointer-events: none;
}
:root .bsa-btn--icon .bsa-badge { position: absolute; top: -5px; inset-inline-end: -5px }

/* ── Toolbar group ──────────────────────────────────────────────────────────────────────────────────────────────── */
:root .bsa-toolbar {
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--bsa-line);
  border-radius: 10px;
  background-color: var(--bsa-material);
  color: var(--bsa-btn-fg);
  box-shadow: var(--bsa-lift);
}
:root .bsa-toolbar--pill { border-radius: 999px }
:root .bsa-toolbar__sep { flex: none; align-self: stretch; width: 1px; margin: 6px 2px; background: var(--bsa-line) }

/* ── Segmented control: a recessed track and a raised white key ───────────────────────────────────────────────── */
:root .bsa-segmented {
  flex-wrap: wrap;
  align-items: stretch;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--bsa-track-fill);
  box-shadow: inset 0 1px 2px rgba(1, 27, 62, .14);
}
/* Only .bsa-btn children: a container that borrows .bsa-segmented keeps its own pills and chips as they are. */
:root .bsa-segmented > .bsa-btn {
  --_bg: transparent;
  --_bg-hover: var(--bsa-track-hover);
  --_bg-press: var(--bsa-track-press);
  --_fg: var(--bsa-seg-fg);
  --_fg-hover: var(--bsa-btn-fg);
  --_edge: transparent;
  --_edge-hover: transparent;
  --_drop: 0 0 #0000;
  --_press: 0 0 #0000;
  --_h: 30px;
  padding: 4px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
}
:root .bsa-segmented > .bsa-btn:is([aria-pressed=true], [aria-selected=true], [aria-checked=true], .is-selected) {
  --_bg: var(--bsa-thumb-fill);
  --_bg-hover: var(--bsa-thumb-fill);
  --_bg-press: var(--bsa-thumb-fill);
  --_fg: var(--bsa-thumb-fg);
  --_fg-hover: var(--bsa-thumb-fg);
  --_edge: transparent;
  --_edge-hover: transparent;
  --_drop: 0 1px 2px rgba(1, 27, 62, .22), 0 0 0 1px rgba(1, 27, 62, .06);
  --_press: 0 1px 2px rgba(1, 27, 62, .22), 0 0 0 1px rgba(1, 27, 62, .06);
  font-weight: 600;
}
:root .bsa-segmented > .bsa-btn.bsa-btn.bsa-btn:is([aria-pressed], [aria-selected], .is-selected)::before { content: none }
:root .bsa-segmented > .bsa-btn.bsa-btn:active:not(:disabled):not([aria-disabled=true]) { transform: none }

/* Inside a track the ring stays inside it (1px gap + 2px ring over the 3px padding): a 3px gap would push the ring out
   onto whatever is around the track, where it can be the same colour as the ring. */
:root .bsa-segmented > .bsa-btn.bsa-btn:focus-visible { outline-offset: 1px; box-shadow: 0 0 0 1px var(--bsa-focus-gap), var(--_drop) }

/* ── Coarse pointers: every control is at least 44 × 44 ───────────────────────────────────────────────────────── */
@media (pointer: coarse) {
  :root .bsa-btn { min-height: max(44px, var(--_h)) }
  :root .bsa-segmented > .bsa-btn { min-width: 44px }
  :root .bsa-btn--icon { width: max(44px, var(--_h)); min-width: max(44px, var(--_h)) }
}

/* ── Preferences and fallbacks ──────────────────────────────────────────────────────────────────────────────────── */
/* Every fill above is opaque in every context, so reduced transparency needs no second set of values. */

/* Higher contrast requested: a visible edge on every button. */
@media (prefers-contrast: more) {
  :root { --bsa-dis-fg: var(--ink-2) }
  :root .bsa-btn { --_edge: currentColor; --_edge-hover: currentColor }
  :root .bsa-btn:is(.bsa-btn--primary, .bsa-btn--ink) { --_edge: var(--bar); --_edge-hover: var(--bar) }
}

/* Reduced motion, from the system or the account preference (html[data-bsa-motion=reduce]): no pressing down, no
   spinning, no scanning; presses still show through the fill, and a busy button shows a still, half-strength line. */
@media (prefers-reduced-motion: reduce) {
  :root .bsa-btn { transition: none }
  :root .bsa-btn.bsa-btn:active:not(:disabled):not([aria-disabled=true]) { transform: none }
  :root .bsa-btn.bsa-btn:is([aria-busy=true], .is-loading)::before { animation: none; border-right-color: currentColor; border-style: dotted }
  :root .bsa-btn.bsa-btn:is([aria-busy=true], .is-loading)::after { animation: none; width: 100%; opacity: .35 }
}
:root[data-bsa-motion=reduce] .bsa-btn { transition: none }
:root[data-bsa-motion=reduce] .bsa-btn.bsa-btn:active:not(:disabled):not([aria-disabled=true]) { transform: none }
:root[data-bsa-motion=reduce] .bsa-btn.bsa-btn:is([aria-busy=true], .is-loading)::before { animation: none; border-right-color: currentColor; border-style: dotted }
:root[data-bsa-motion=reduce] .bsa-btn.bsa-btn:is([aria-busy=true], .is-loading)::after { animation: none; width: 100%; opacity: .35 }

/* Windows high contrast and other forced colours: system colours, real borders, a Highlight focus ring. */
@media (forced-colors: active) {
  :root .bsa-btn.bsa-btn {
    border: 1px solid ButtonText;
    background: ButtonFace;
    color: ButtonText;
    box-shadow: none;
    transform: none;
  }
  :root .bsa-btn.bsa-btn:is([aria-pressed=true], [aria-selected=true], [aria-current=page], .is-selected),
  :root .bsa-segmented > .bsa-btn:is([aria-pressed=true], [aria-selected=true], [aria-checked=true], .is-selected) {
    forced-color-adjust: none;
    border-color: Highlight;
    background: Highlight;
    color: HighlightText;
  }
  :root .bsa-btn.bsa-btn:focus-visible { outline: 3px solid Highlight; outline-offset: 2px; box-shadow: none }
  :root .bsa-btn.bsa-btn:is(:disabled, [aria-disabled=true]):not([aria-busy=true], .is-loading) { border-style: dashed; border-color: GrayText; color: GrayText }
  :root .bsa-btn::before, :root .bsa-btn::after { forced-color-adjust: none }
  :root .bsa-btn:is([aria-busy=true], .is-loading)::after { background: ButtonText }
  :root .bsa-btn:is([aria-busy=true], .is-loading)::before { border-color: ButtonText; border-top-color: transparent }
  :root .bsa-toolbar, :root .bsa-segmented { border: 1px solid CanvasText; background: Canvas; box-shadow: none }
  :root .bsa-badge { forced-color-adjust: none; background: Highlight; color: HighlightText; box-shadow: none }
}
