/**
 * Scroll-to-Top Button
 *
 * Fixed bottom-right control, hidden until JS adds .is-visible (set once the
 * page is scrolled past one viewport height). Depends on design-tokens.css.
 *
 * Visibility model: when not visible the button is removed from layout via
 * visibility:hidden + the [inert] attribute (JS-toggled). We animate opacity
 * and transform only; visibility flips at the end of the transition so the
 * fade-out is seen but the control still leaves the a11y tree / tab order.
 *
 * Scoping note: this is a standalone EPSD control rendered outside the
 * .epsd-nav-wrap / .epsd-drawer / .epsd-zone-8 bleed-reset scopes, so its
 * button styling is asserted here directly with enough specificity to win
 * over Astra's bare `button { … }` inline rules. See ARCHITECTURE.md
 * "Astra Bleed Resets" for the broader pattern.
 */

.epsd-scroll-top {
  position: fixed;
  right: var(--epsd-space-lg);
  bottom: var(--epsd-space-lg);
  z-index: 9000; /* below skip links (10001), above page content */

  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  margin: 0;
  padding: 0;

  color: var(--epsd-interactive-primary-text);
  background-color: var(--epsd-interactive-primary);
  border: 2px solid transparent;
  border-radius: var(--epsd-radius-full);
  box-shadow: var(--epsd-shadow-lg);
  cursor: pointer;

  /* Hidden resting state */
  opacity: 0;
  visibility: hidden;
  transform: translateY(0.75rem);

  transition:
    opacity var(--epsd-transition-normal),
    transform var(--epsd-transition-normal),
    visibility 0s linear var(--epsd-transition-normal),
    background-color var(--epsd-transition-fast);
}

.epsd-scroll-top.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  /* No visibility delay when appearing */
  transition:
    opacity var(--epsd-transition-normal),
    transform var(--epsd-transition-normal),
    visibility 0s,
    background-color var(--epsd-transition-fast);
}

.epsd-scroll-top:hover {
  background-color: var(--epsd-interactive-primary-hover);
  transform: translateY(-2px);
}

.epsd-scroll-top:active {
  background-color: var(--epsd-interactive-primary-active);
  transform: translateY(0);
}

/* Focus ring is provided globally by :focus-visible in design-tokens.css.
   Pair plain :focus with :focus-visible so a click doesn't paint the ring
   but the gold offset ring still needs room around a round button. */
.epsd-scroll-top:focus-visible {
  outline-offset: var(--epsd-focus-ring-offset);
}

.epsd-scroll-top__icon {
  display: block;
  width: 1.5rem;
  height: 1.5rem;
}

/* Small screens: tuck in a little tighter and shrink slightly. */
@media (max-width: 768px) {
  .epsd-scroll-top {
    right: var(--epsd-space-md);
    bottom: var(--epsd-space-md);
    width: 2.75rem;
    height: 2.75rem;
  }
}

/* WCAG 2.3.3 — honor reduced-motion: no slide/fade transition, no hover lift.
   (Smooth scroll itself is disabled in JS by reading the same media query.) */
@media (prefers-reduced-motion: reduce) {
  .epsd-scroll-top,
  .epsd-scroll-top.is-visible {
    transition: visibility 0s, background-color var(--epsd-transition-fast);
    transform: none;
  }

  .epsd-scroll-top:hover,
  .epsd-scroll-top:active {
    transform: none;
  }
}
