/* Shared aurora canvas stays within the viewport, including long chats. */
.infinet-bg,
.particles-container.infinet-aurora-home {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}
.infinet-bg canvas,
.infinet-aurora-home canvas {
    width: 100%;
    height: 100%;
    display: block;
}
body.has-infinet-bg .main-content,
body.has-infinet-bg .page-content {
    background: transparent !important;
}
body.has-infinet-bg .main-content,
body.has-infinet-bg .reset-container {
    position: relative;
}

/* Continue the aurora behind the home page footer in both themes. */
body .chat-footer {
    background: transparent !important;
}

/* Opaque matching aurora starts halfway down the composer, in both layouts. */
.chat-input-area.infinet-composer-layer { isolation: isolate; }
.chat-input-area > .infinet-composer-aurora {
    display: block;
    position: absolute;
    top: var(--infinet-backdrop-top, 0px);
    left: 0;
    width: 100%;
    height: max(0px, calc(100% - var(--infinet-backdrop-top, 0px) + 32px));
    z-index: -1;
    pointer-events: none;
    background: #000000;
}
body.light-mode .chat-input-area > .infinet-composer-aurora {
    background: #ffffff;
}
@media (min-width: 769px) {
    #chat-messages {
        isolation: isolate;
        /* Preserve the backdrop position and keep the final reply above the composer. */
        margin-bottom: calc(-1 * var(--infinet-composer-overlap, 0px));
        padding-bottom: max(2rem, var(--infinet-reply-bottom-padding, 0px)) !important;
    }
}
.chat-scroll-track,
.chat-visible-window {
    display: contents;
}
@media (max-width: 768px) {
    #chat-messages.infinet-mobile-chat-spacing {
        padding-bottom: max(200px, var(--infinet-chat-bottom-space, 200px)) !important;
    }
    html body.mobile-chat-layout #chat-header.chat-header {
        background: #121212 !important;
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
        top: 0 !important;
    }
    html body.light-mode.mobile-chat-layout #chat-header.chat-header {
        background: #fff !important;
    }
    body.mobile-chat-layout.studio-open #chat-messages {
        visibility: hidden;
    }
    body.mobile-chat-layout .chat-input-area {
        bottom: var(--mobile-chat-bottom, 0px) !important;
    }
    body.mobile-chat-typing #chat-header,
    body.mobile-chat-typing .chat-input-area {
        translate: 0 var(--mobile-keyboard-pan, 0px);
    }
    body.mobile-chat-typing .scroll-to-bottom-btn {
        bottom: calc(var(--mobile-chat-composer-inset, 0px) - var(--mobile-keyboard-pan, 0px) + 1rem);
    }
    body.mobile-chat-typing .chat-footer {
        display: none !important;
    }
    body.mobile-chat-typing .input-container {
        margin-bottom: 0 !important;
    }
    body.mobile-chat-layout #chat-messages {
        isolation: isolate;
        overflow: visible;
        padding-bottom: var(--mobile-chat-scroll-padding, 200px) !important;
    }
    @supports (animation-timeline: scroll(root block)) {
        body.mobile-chat-layout:not(.mobile-chat-welcome-layout, .mobile-chat-typing) .chat-scroll-track {
            display: block;
            height: var(--chat-track-height, auto);
        }
        body.mobile-chat-layout:not(.mobile-chat-welcome-layout, .mobile-chat-typing) .chat-visible-window {
            display: block;
            position: fixed;
            inset: var(--chat-window-top, 0px) 0 var(--chat-window-bottom, 0px);
            clip-path: inset(0);
            z-index: 1;
        }
        body.mobile-chat-layout:not(.mobile-chat-welcome-layout, .mobile-chat-typing) #chat-messages {
            position: absolute;
            inset: var(--chat-track-offset, 0px) 0 auto;
            animation: mobile-chat-scroll linear both;
            animation-timeline: scroll(root block);
        }
        body.mobile-chat-typing #chat-messages {
            animation: mobile-chat-typing-clip linear both;
            animation-timeline: scroll(root block);
        }
        @keyframes mobile-chat-typing-clip {
            from { clip-path: inset(var(--typing-chat-clip-top, 0px) 0 var(--typing-chat-clip-bottom, 0px)); }
            to {
                clip-path: inset(calc(var(--typing-chat-clip-top, 0px) + var(--typing-chat-scroll-distance, 0px))
                    0 calc(var(--typing-chat-clip-bottom, 0px) - var(--typing-chat-scroll-distance, 0px)));
            }
        }
        @keyframes mobile-chat-scroll {
            to { transform: translateY(calc(-1 * var(--chat-scroll-distance, 0px))); }
        }
    }
    body.mobile-chat-layout:not(.mobile-chat-welcome-layout)::after { display: none; }
    body.mobile-chat-welcome-layout #chat-messages {
        min-height: max(0px, calc(100dvh - 70px));
    }
    body.mobile-chat-welcome-layout #welcome-screen:not(.hidden) {
        position: fixed;
        top: var(--mobile-welcome-top, 70px);
        inset-inline: 0;
        margin-top: 0 !important;
        transform: none;
        height: auto;
        padding-top: 12px !important;
        pointer-events: none;
    }
    /* Use the same viewport shift as the header when Safari opens the keyboard. */
    body.mobile-chat-welcome-layout:has(#message-input:focus) #welcome-screen:not(.hidden) {
        translate: 0 var(--mobile-keyboard-pan, 0px);
        max-height: var(--mobile-welcome-available, 100%);
        justify-content: flex-start;
        overflow: clip;
        padding-bottom: 0;
    }
    body.mobile-chat-welcome-layout:has(#message-input:focus) .welcome-logo {
        display: none;
    }
    body.mobile-chat-welcome-layout:has(#message-input:focus) #welcome-screen h2 {
        font-size: clamp(1.15rem, 5.5vw, 1.55rem);
        margin-bottom: 0.5rem;
    }
    body.mobile-chat-welcome-layout:has(#message-input:focus) #welcome-screen p {
        font-size: 0.95rem;
    }
}

/* Safari samples fixed surfaces at the viewport edges for its mobile browser bars. */
@supports (-webkit-touch-callout: none) {
    @media (hover: none) and (pointer: coarse) {
        html::before, html::after {
            content: "";
            position: fixed;
            inset-inline: 0;
            height: 12px;
            background-color: #000;
            -webkit-background-clip: text;
            background-clip: text;
            pointer-events: none;
            z-index: 2147483647;
        }
        html::before { top: 0; }
        html::after { bottom: 0; }
        html:has(body.light-mode)::before, html:has(body.light-mode)::after {
            background-color: #fff;
            height: 13px;
        }
    }
}

/* Shared glass surfaces for every aurora-enabled application page.
   Explicit component selectors preserve action colors, overlays and footer shielding. */
body {
    --infinet-glass-surface: rgba(17, 17, 17, .78);
    --infinet-glass-panel: rgba(17, 17, 17, .88);
    --infinet-glass-input: rgba(0, 0, 0, .30);
}
body.light-mode {
    --infinet-glass-surface: rgba(255, 255, 255, .78);
    --infinet-glass-panel: rgba(255, 255, 255, .90);
    --infinet-glass-input: rgba(255, 255, 255, .40);
}
html body :is(.plan, .topup-strip, .contact-payment-pill,
.profile-section, .appearance-section, .feature-card, .model-card, .stat-card,
.info-box, .warning-box, .feature-item, .coming-soon-pill, .reset-container,
.message-content, .message.user .message-content, .input-container, .chat-header,
.sidebar, .info-card, .info-card-expanded, .su-row, .su-menu, .new-chat-menu,
.conv-select-bar, .conv-toast, .agent-menu, .pricing-dropdown-menu,
.auth-modal-content, .install-modal-content, .token-limit-modal-content,
.sensitive-content-modal-content, .infra-upgrade-modal-content,
.phone-verification-modal-content, .verification-code-alert,
.spectre-banner-box, .infisec-banner-inner, .attach-card, .attach-note,
.attach-tile, .attach-empty-icon, .venice-file-card, .venice-attach-file,
.img2img-unavailable-popup, .temp-chat-banner, .agent-video-confirm,
.code-file-card, .reply-file-card, .reply-pdf-chip, .code-block-container, .code-block,
.studio-view, .studio-topbar, .studio-panel, .studio-gallery, .studio-card,
.studio-card-caption, .studio-notice, .studio-drop,
.iem-card, .cdm-card, .bc-card, .bc-toast,
#ics-modal .ics-card, #ips-modal .ips-card, #infinet-pay-choice .infinet-pay-card,
.billing-toggle, .studio-tabs, .studio-subtoggle, .attach-tabs,
.chat-pill, .agent-select-btn, .tokens-badge, .header-btn:not(.primary),
.theme-toggle, .footer-link, .theme-button:not(.active),
.message-content blockquote, .message-content .thinking-content,
.message-content .thinking-block.is-live) {
    background: var(--infinet-glass-surface) !important;
    -webkit-backdrop-filter: blur(14px) !important;
    backdrop-filter: blur(14px) !important;
}
html body :is(.sidebar, .su-menu, .new-chat-menu, .info-card-expanded, .agent-menu,
.pricing-dropdown-menu, .auth-modal-content, .install-modal-content,
.token-limit-modal-content, .sensitive-content-modal-content, .infra-upgrade-modal-content,
.phone-verification-modal-content, .spectre-banner-box, .attach-card, .iem-card, .cdm-card,
.bc-card, #ics-modal .ics-card, #ips-modal .ips-card, #infinet-pay-choice .infinet-pay-card,
.studio-view) {
    background: var(--infinet-glass-panel) !important;
}
html body :is(.chat-input, .chat-search-input, .conv-rename-input, .studio-textarea,
.studio-select, .theme-select-simple, .auth-form-group input, .form-group input,
.form-group select, .bc-input-wrap, .bc-pick:not(.is-active)) {
    background: var(--infinet-glass-input) !important;
}
/* Preserve dark code syntax panels and theme-aware toolbar text. */
html body .message-content pre,
html body.light-mode .message-content :is(pre, pre.hljs) {
    background: rgba(5, 5, 5, .88) !important;
    -webkit-backdrop-filter: blur(14px) !important;
    backdrop-filter: blur(14px) !important;
}
html body .code-block-content,
html body .message-content pre code,
html body.light-mode .message-content pre code.hljs {
    background: transparent !important;
}
html body .code-block-header { background: var(--infinet-glass-input) !important; }

/* Keep the animated pixels and readability treatment in one composited surface.
   An overlapping full-screen backdrop filter can leave Safari showing stale frames. */
.infinet-bg.infinet-readable-bg,
.particles-container.infinet-aurora-home.infinet-readable-bg {
    background: #000;
}
body.light-mode .infinet-bg.infinet-readable-bg,
body.light-mode .particles-container.infinet-aurora-home.infinet-readable-bg {
    background: #fff;
}
.infinet-readable-bg > canvas,
.infinet-composer-aurora > canvas {
    filter: blur(10px);
    transform: translateZ(0);
}
.page-readability-layer {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: rgba(0, 0, 0, .24);
    pointer-events: none;
}
body.light-mode .page-readability-layer {
    background: rgba(255, 255, 255, .32);
}
@media (max-width: 768px) {
    /* Cover Safari's changing toolbar viewport and rubber-band overscroll without
       stretching an independent blur layer or exposing an unfiltered ribbon edge. */
    .infinet-bg.infinet-readable-bg,
    .particles-container.infinet-aurora-home.infinet-readable-bg {
        top: -160px;
        bottom: -160px;
        height: calc(100% + 320px);
    }
}
