/* ============================================================
   Samarth eGov · Back-to-top / reading progress
   A ring that fills with scroll position, wrapped around an up arrow. The
   inner disc is left transparent (only blurred) so the control sits over the
   page rather than on it; the ring itself carries all the weight.
   Markup: views/layouts/samarth4/include/guest-totop.php
   Progress comes from --g-totop-p, written by initToTop() in guest.js.
   ============================================================ */

.g-totop {
    /* Circumference of r=20, i.e. 2 * PI * 20. The dash length has to be a
       real number for the offset maths below; pathLength="100" would read
       nicer but is unreliable on <circle> in older Safari. */
    --g-totop-c: 125.664;
    --g-totop-size: 2.4rem;

    /* Under the mega menu (1070) and palette (1080) so either overlay covers
       it, but above page content. */
    position: fixed;
    z-index: 1035;
    right: clamp(1rem, 3vw, 2rem);
    bottom: clamp(1rem, 3vw, 2rem);

    display: grid;
    place-items: center;
    width: var(--g-totop-size);
    height: var(--g-totop-size);
    padding: 0;
    border: 0;
    border-radius: 50%;
    /* Transparent disc: the blur alone keeps the arrow legible over imagery
       without painting a filled button. */
    background: transparent;
    backdrop-filter: blur(8px) saturate(1.2);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;

    /* Hidden state. visibility (not just opacity) so the control leaves the
       tab order while off-screen — otherwise it stays focusable with nothing
       visible to show for it. */
    visibility: hidden;
    opacity: 0;
    transform: translateY(.5rem) scale(.9);
    transition:
        opacity .24s var(--g-ease),
        transform .24s var(--g-ease),
        visibility .24s linear;
}

.g-totop.is-visible {
    visibility: visible;
    opacity: 1;
    transform: none;
}

.g-totop:hover { transform: translateY(-2px); }
.g-totop:active { transform: translateY(0) scale(.95); }
.g-totop:focus-visible {
    outline: 2px solid var(--g-accent);
    outline-offset: 3px;
}

/* Both circles share the box; rotating the SVG puts the dash start at 12
   o'clock instead of 3. */
.g-totop__ring {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
    overflow: visible;
    fill: none;
}

.g-totop__track {
    stroke: var(--g-border-strong);
    stroke-width: 2;
    transition: stroke .2s var(--g-ease);
}

.g-totop__bar {
    stroke: var(--g-text);
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-dasharray: var(--g-totop-c);
    /* p = 0 leaves the whole dash offset (empty ring); p = 1 closes it. No
       transition on the offset: guest.js already updates it once per animation
       frame, and easing on top of that reads as lag. Only the colour eases,
       for the light/dark flip below. */
    stroke-dashoffset: calc(var(--g-totop-c) * (1 - var(--g-totop-p, 0)));
    transition: stroke .2s var(--g-ease);
}

.g-totop__arrow {
    position: relative;
    width: .9rem;
    height: .9rem;
    fill: none;
    stroke: var(--g-text);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform .2s var(--g-ease), stroke .2s var(--g-ease);
}
.g-totop:hover .g-totop__arrow { transform: translateY(-1px); }

/* Over a dark panel the near-black ring and arrow all but vanish. This cannot
   be keyed off [data-guest-theme]: the footer, the CTA band and the dark cards
   are navy in the *light* theme too, and the footer sits on every page. So
   initToTop() measures which surface the control is actually over and sets
   .is-on-dark, and the whole thing flips to white. */
.g-totop.is-on-dark .g-totop__track { stroke: rgba(255, 255, 255, .28); }
.g-totop.is-on-dark .g-totop__bar { stroke: #fff; }
.g-totop.is-on-dark .g-totop__arrow { stroke: #fff; }
.g-totop.is-on-dark:focus-visible { outline-color: #fff; }

/* The mobile action bar owns the bottom of the viewport, so sit above it. */
@media (max-width: 767.98px) {
    .g-totop {
        bottom: calc(var(--g-bbar-h, 4rem) + env(safe-area-inset-bottom, 0px) + .75rem);
        --g-totop-size: 2.25rem;
    }
}

/* The global reduced-motion rule already collapses the transitions; the scroll
   itself is switched to an instant jump in guest.js. */
