.scroll-top-button {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 120;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid color-mix(in oklab, var(--color-border), transparent 5%);
  border-radius: 12px;
  background: color-mix(in oklab, var(--color-surface), white 8%);
  color: color-mix(in oklab, var(--color-muted), #536073 25%);
  box-shadow: 0 7px 20px rgba(31, 35, 40, 0.14);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease,
    background 0.2s ease,
    box-shadow 0.2s ease;
}

.scroll-top-button[hidden] {
  display: inline-flex !important;
}

.scroll-top-button svg {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.scroll-top-button.is-visible {
  opacity: 0.86;
  transform: translateY(0);
  pointer-events: auto;
}

.scroll-top-button:hover,
.scroll-top-button:focus-visible {
  border-color: color-mix(in oklab, var(--color-primary), transparent 40%);
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: 0 9px 24px rgba(31, 35, 40, 0.18);
  opacity: 1;
}

/* Preserve the compact backup dimensions against legacy page button rules. */
button.scroll-top-button {
  min-width: 30px;
  min-height: 30px;
  max-width: 30px;
  max-height: 30px;
  box-sizing: border-box;
}

@media (max-width: 1024px) {
  body:has(.mobile-bottom-nav) .scroll-top-button {
    bottom: calc(var(--mobile-bottom-nav-height, 68px) + 14px + env(safe-area-inset-bottom, 0px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .scroll-top-button {
    transition: none;
  }
}
