/* Shared shape and glyph. The active theme supplies the paper, outline and ink. */
:root {
    --back-top-right: clamp(14px, 2vw, 28px);
    --back-top-bottom: clamp(16px, 2vw, 28px);
    --back-top-surface: var(--air-surface-solid, #fff);
    --back-top-icon: var(--air-primary, #365678);
    --back-top-border: var(--air-line, #d6dfe9);
}
html[data-blog-theme="dark"] {
    --back-top-surface: var(--air-surface-solid, #1b2735);
    --back-top-icon: var(--air-primary, #bad3f1);
    --back-top-border: var(--air-line, #4a5b70);
}

/* Older themes style these IDs with !important, including standalone article and guestbook pages. */
body :is(.back-to-top, #back-to-top, #backToTop, #scroll-to-top-btn, #air-global-back-to-top) {
    --return-target: clamp(44px, 3.4vw, 48px);
    box-sizing: border-box !important;
    display: grid !important;
    place-items: center !important;
    width: var(--return-target) !important;
    min-width: var(--return-target) !important;
    height: var(--return-target) !important;
    min-height: var(--return-target) !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 1px solid var(--back-top-border) !important;
    border-radius: 50% !important;
    background: var(--back-top-surface) !important;
    color: var(--back-top-icon) !important;
    box-shadow: 0 2px 7px rgb(18 32 48 / 10%) !important;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
body :is(.back-to-top, #back-to-top, #backToTop, #scroll-to-top-btn, #air-global-back-to-top) {
    position: fixed !important;
    top: auto !important;
    left: auto !important;
    right: max(var(--back-top-right), env(safe-area-inset-right)) !important;
    bottom: max(var(--back-top-bottom), calc(env(safe-area-inset-bottom) + 12px)) !important;
    z-index: 10000 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transform: translateY(5px) !important;
    transition: opacity .16s ease, visibility .16s ease, transform .16s ease !important;
}
body :is(.back-to-top, #back-to-top, #backToTop, #scroll-to-top-btn, #air-global-back-to-top).visible {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    transform: none !important;
}
body :is(.back-to-top, #back-to-top, #backToTop, #scroll-to-top-btn, #air-global-back-to-top)::before,
body :is(.back-to-top, #back-to-top, #backToTop, #scroll-to-top-btn, #air-global-back-to-top)::after {
    content: none !important;
    display: none !important;
}
/* Align the two controls on one vertical axis. */
body.article-tools-page {
    --article-tools-right: max(36px, env(safe-area-inset-right));
    --article-tools-bottom: calc(28px + env(safe-area-inset-bottom));
    --article-assistant-size: 44px;
    --back-top-bottom: calc(var(--article-tools-bottom) + var(--article-assistant-size) + 8px);
}
body.article-tools-page #scroll-to-top-btn {
    right: calc(var(--article-tools-right) + (var(--article-assistant-size) - var(--return-target)) / 2) !important;
}
body.article-tools-page #aiChatWidget {
    right: var(--article-tools-right) !important;
    bottom: var(--article-tools-bottom) !important;
}
body.article-tools-page #aiChatToggle {
    box-sizing: border-box;
    width: var(--article-assistant-size);
    height: var(--article-assistant-size);
    padding: 0;
    border: 1px solid var(--back-top-border);
    border-radius: 13px;
    background: var(--back-top-surface);
    box-shadow: 0 8px 22px rgb(23 32 51 / 10%);
    transform: none;
}
body.article-tools-page #aiChatToggle .ai-chat-toggle-inner { display: none; }
body.article-tools-page #aiChatToggle img { display: block !important; width: 27px; height: 27px; transform: none; }
body.article-tools-page #aiChatToggle:focus-visible { outline: 2px solid var(--back-top-icon); outline-offset: 3px; }
body.article-tools-page #blog-theme-toggle { display: none !important; }
body.article-tools-page.air-modal-open #aiChatToggle,
body.article-tools-page.comment-sticker-open #aiChatToggle,
html.blog-nav-open body.article-tools-page #aiChatToggle { visibility: hidden; pointer-events: none; }
@media (min-width: 768px) {
    body.article-tools-page #aiChatWindow { left: auto; right: 0; }
}
@media (max-width: 767px), (max-width: 1023px) and (hover: none) and (pointer: coarse) {
    body.article-tools-page {
        --article-tools-right: calc(14px + env(safe-area-inset-right, 0px));
    }
}
@media (max-width: 767px) {
    body.article-tools-page {
        --article-tools-bottom: calc(18px + env(safe-area-inset-bottom));
    }
    body.bt-page.article-tools-page { --article-tools-bottom: calc(88px + env(safe-area-inset-bottom)); }
}

/* Standalone pages keep their own scroll handler and the older icon element. */
.back-to-top > i.fa-chevron-up::before { content: none; }
.back-top-glyph,
.back-to-top > i.fa-chevron-up {
    display: block;
    width: 20px;
    height: 20px;
    background-color: currentColor;
    --return-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 4.5h14M12 20V9m-5 5 5-5 5 5'/%3E%3C/svg%3E");
    -webkit-mask: var(--return-arrow) center / contain no-repeat;
    mask: var(--return-arrow) center / contain no-repeat;
}
body :is(.back-to-top, #back-to-top, #backToTop, #scroll-to-top-btn, #air-global-back-to-top):focus-visible {
    outline: 2px solid currentColor !important;
    outline-offset: 3px !important;
}
body.air-modal-open :is(.back-to-top, #back-to-top, #backToTop, #scroll-to-top-btn, #air-global-back-to-top),
body.air-modal-open :is(.back-to-top, #back-to-top, #backToTop, #scroll-to-top-btn, #air-global-back-to-top).visible {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}
@media (prefers-reduced-motion: reduce) {
    body :is(.back-to-top, #back-to-top, #backToTop, #scroll-to-top-btn, #air-global-back-to-top) {
        transition: none !important;
    }
}
@media (prefers-reduced-transparency: reduce) {
    body :is(.back-to-top, #back-to-top, #backToTop, #scroll-to-top-btn, #air-global-back-to-top) {
        background: var(--air-surface-solid, Canvas) !important;
    }
}
@media (forced-colors: active) {
    .back-top-glyph, .back-to-top > i.fa-chevron-up { background: ButtonText; forced-color-adjust: none; }
}
