/* Webworks back to top: a round button fixed to a screen edge whose ring fills as the page scrolls.
   Colours come from the theme through the UIkit class chosen in the element (card, tile or icon button);
   size, position and distance from the edges come from its settings as custom properties.
   The doubled class outranks the theme's own sizing of those classes (e.g. uk-icon-button is 36px).
   Only opacity and transforms (scale, translate) animate. */
.ww-totop.ww-totop {
    position: fixed;
    z-index: 970;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: var(--ww-totop-size, 48px);
    height: var(--ww-totop-size, 48px);
    margin: 0 !important; /* the builder's margin classes don't apply to a fixed button */
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
    /* hidden state: shrunk, faded, not clickable or focusable */
    opacity: 0;
    visibility: hidden;
    scale: 0.6;
    transition: opacity 0.3s ease, scale 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), translate 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.4s, background-color 0.2s ease;
}
:where(.ww-totop) { border: 0; }
/* Elevation. Card, tile and icon-button styles are made for boxes that sit on their section, and their borders and
   shadows differ between styles and between light and dark, so the button's shadow is always ours (--ww-totop-shadow
   changes it). Tripling the class outranks their shadows, including a hover or focus state (0,2,0).
   Two dark layers (a close one for the edge, a wide soft one for the lift) separate the button from light pages and
   images. A black shadow does little on a dark page, so a 10% white 1px edge, which a light page simply doesn't show,
   keeps the outline there without reading the theme's scheme. */
.ww-totop.ww-totop.ww-totop { box-shadow: var(--ww-totop-shadow, 0 1px 3px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.1)); }
.ww-totop.is-visible {
    opacity: 1;
    visibility: visible;
    scale: 1;
    transition: opacity 0.3s ease, scale 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), translate 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s, background-color 0.2s ease;
}

/* Position: offset from the edges plus any safe area (notches, home indicator).
   Right and left are the inline end and start, so they swap on right-to-left pages. */
.ww-totop { --ww-o: var(--ww-totop-offset, 16px); --ww-safe-end: env(safe-area-inset-right, 0px); --ww-safe-start: env(safe-area-inset-left, 0px); }
.ww-totop:dir(rtl) { --ww-safe-end: env(safe-area-inset-left, 0px); --ww-safe-start: env(safe-area-inset-right, 0px); }
/* The width blocks below and further down are for UIkit's default breakpoints. When the site's style changes one, Breakpoints::rewriteAll writes them again at the style's widths and the element gets ww-totop-bp, which the :where(:not(.ww-totop-bp)) in each selector skips (:where keeps their weight). */
@media (min-width: 960px) { .ww-totop:where(:not(.ww-totop-bp)) { --ww-o: var(--ww-totop-offset-l, 24px); } }
.ww-totop-bottom-right, .ww-totop-middle-right, .ww-totop-top-right { inset-inline-end: calc(var(--ww-o) + var(--ww-safe-end)); }
.ww-totop-bottom-left, .ww-totop-middle-left, .ww-totop-top-left { inset-inline-start: calc(var(--ww-o) + var(--ww-safe-start)); }
.ww-totop-bottom-right, .ww-totop-bottom-left {
    bottom: calc(var(--ww-o) + env(safe-area-inset-bottom, 0px));
    /* Lifted above the mobile action bar while it shows (its height already includes the safe area) */
    translate: 0 calc(-1 * max(0px, var(--ww-actionbar-h, 0px) - env(safe-area-inset-bottom, 0px)));
}
.ww-totop-top-right, .ww-totop-top-left { top: calc(var(--ww-o) + env(safe-area-inset-top, 0px)); }
.ww-totop-middle-right, .ww-totop-middle-left { top: 50%; translate: 0 -50%; }

/* The ring's colour and width are the theme's (or the browser's); only the gap is ours */
.ww-totop:focus-visible { outline-offset: 3px; }

/* Ring: progress in a theme colour (uk-link / uk-text-* on the circle) or a custom one */
.ww-totop-ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); pointer-events: none; fill: none; }
.ww-totop-track { stroke: var(--ww-totop-track, currentColor); opacity: 0.15; }
.ww-totop-has-track .ww-totop-track { opacity: 1; }
.ww-totop-progress { stroke: var(--ww-totop-ring, currentColor); stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; }

.ww-totop-icon { position: relative; transition: transform 0.2s ease; }
.ww-totop:hover .ww-totop-icon { transform: translateY(-2px); }

/* The main content, focused after going back to the top on a page with no H1 */
.ww-totop-target:focus { outline: none; }

/* In the builder: where it's placed, shown, so it can be selected */
.ww-totop.ww-totop-preview { position: relative; inset: auto; translate: none; }

@media (prefers-reduced-motion: reduce) {
    .ww-totop.ww-totop, .ww-totop.is-visible, .ww-totop-icon { transition: none; }
}
