/* ==========================================================================
   EMOTIA 3D — Native Fullscreen Telegram Mini App Shell
   Handles Bot API 8.0+ Fullscreen, Dynamic Island / Notch / Telegram Pills
   safe areas, edge-to-edge 100dvh WebGL viewport, and native Exit Sheet.
   ========================================================================== */

:root {
    --js-tg-safe-top: 0px;
    --js-tg-safe-bottom: 0px;
    --js-tg-safe-left: 0px;
    --js-tg-safe-right: 0px;
    --js-tg-content-top: 0px;
    --js-tg-content-bottom: 0px;

    --emotia-safe-top: max(var(--tg-safe-area-inset-top, 0px), env(safe-area-inset-top, 0px), var(--js-tg-safe-top, 0px));
    --emotia-safe-bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px), var(--js-tg-safe-bottom, 0px));
    --emotia-safe-left: max(var(--tg-safe-area-inset-left, 0px), env(safe-area-inset-left, 0px), var(--js-tg-safe-left, 0px));
    --emotia-safe-right: max(var(--tg-safe-area-inset-right, 0px), env(safe-area-inset-right, 0px), var(--js-tg-safe-right, 0px));

    --emotia-content-top: max(var(--tg-content-safe-area-inset-top, 0px), var(--js-tg-content-top, 0px));
    --emotia-content-bottom: max(var(--tg-content-safe-area-inset-bottom, 0px), var(--js-tg-content-bottom, 0px));

    --emotia-top-inset: calc(var(--emotia-safe-top) + var(--emotia-content-top));
    --emotia-bottom-inset: calc(var(--emotia-safe-bottom) + var(--emotia-content-bottom));
}

html,
body {
    overscroll-behavior: none !important;
    -webkit-tap-highlight-color: transparent;
}

body :is(button, a, label, header, nav) {
    -webkit-touch-callout: none;
    user-select: none;
}

body :is(input, textarea, [contenteditable="true"]) {
    user-select: text;
    -webkit-user-select: text;
}

/* Edge-to-edge 100dvh 3D viewport */
#section-surprise-world,
#view-museum,
.emotia-fullscreen-stage {
    height: 100vh;
    height: 100dvh !important;
    min-height: 100dvh;
}

/* Subtle top atmospheric vignette behind iOS status bar & Telegram floating pills */
.emotia-status-scrim {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--emotia-top-inset) + 28px);
    background: linear-gradient(
        180deg,
        rgba(10, 7, 14, 0.78) 0%,
        rgba(10, 7, 14, 0.36) 62%,
        rgba(10, 7, 14, 0) 100%
    );
    pointer-events: none;
    z-index: 28;
    opacity: 0;
    transition: opacity 220ms ease;
}

html.tg-fullscreen .emotia-status-scrim,
html.emotia-has-top-inset .emotia-status-scrim {
    opacity: 1;
}

/* Floating Native App Capsule Header (index.html & view.html) */
header.palace-header,
header.emotia-floating-header {
    top: calc(var(--emotia-top-inset) + 6px) !important;
    left: max(8px, calc(var(--emotia-safe-left) + 8px)) !important;
    right: max(8px, calc(var(--emotia-safe-right) + 8px)) !important;
    max-width: 560px;
    margin-inline: auto;
    border-radius: 18px;
    border: 1px solid rgba(231, 207, 172, 0.22) !important;
    background: rgba(30, 24, 20, 0.86) !important;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 245, 230, 0.08);
    transition: top 180ms ease;
}

/* Secondary floating overlays positioned below header */
#inWorldVoiceBar {
    top: calc(var(--emotia-top-inset) + 68px) !important;
}

#frameAdjusterBar {
    top: calc(var(--emotia-top-inset) + 68px) !important;
}

#section-invitation,
#section-admin {
    padding-top: calc(var(--emotia-top-inset) + 72px) !important;
    padding-bottom: calc(var(--emotia-bottom-inset) + 72px) !important;
}

/* Bottom HUD & Home-Indicator Safe Dock */
#bottomWorldHud,
.emotia-bottom-safe-hud {
    padding-bottom: calc(max(var(--emotia-bottom-inset), 8px) + 4px) !important;
    padding-left: max(12px, calc(var(--emotia-safe-left) + 12px)) !important;
    padding-right: max(12px, calc(var(--emotia-safe-right) + 12px)) !important;
}

/* Settings & Checkout Bottom Sheets Safe-Area Support */
#settingsSheet.apple-sheet {
    height: min(calc(56dvh + var(--emotia-bottom-inset)), 590px);
    padding-bottom: var(--emotia-bottom-inset);
}

.checkout-sheet {
    max-height: calc(100dvh - var(--emotia-top-inset) - 12px) !important;
    padding-bottom: calc(max(var(--emotia-bottom-inset), 16px) + 6px) !important;
}

#myProjectsModal > div {
    max-height: calc(100dvh - var(--emotia-top-inset) - 16px) !important;
    padding-bottom: calc(max(var(--emotia-bottom-inset), 16px) + 6px) !important;
}

/* Upgraded Native Luxury Launch Splash */
.emotia-startup {
    padding-top: var(--emotia-top-inset);
    padding-bottom: var(--emotia-bottom-inset);
    background:
        radial-gradient(circle at 50% 34%, rgba(214, 174, 118, 0.16), transparent 46%),
        radial-gradient(ellipse at 50% 36%, #3f3126, #191310 74%) !important;
    transition: opacity 280ms cubic-bezier(.22, 1, .36, 1), transform 280ms cubic-bezier(.22, 1, .36, 1) !important;
}

.emotia-startup.is-ready {
    opacity: 0;
    transform: scale(1.035);
    pointer-events: none;
}

.emotia-startup-mark {
    width: 64px !important;
    height: 64px !important;
    border-radius: 20px !important;
    background: linear-gradient(145deg, rgba(231, 207, 172, 0.16), rgba(44, 33, 25, 0.85));
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55), 0 0 28px rgba(230, 203, 161, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.emotia-startup-bar {
    width: 132px;
    height: 3px;
    border-radius: 999px;
    background: rgba(231, 207, 172, 0.16);
    overflow: hidden;
    justify-self: center;
}

.emotia-startup-bar::after {
    content: "";
    display: block;
    width: 48%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, transparent, #e7cfac, #fff4df, transparent);
    animation: emotia-loader-glide 1.15s ease-in-out infinite;
}

@keyframes emotia-loader-glide {
    0% { transform: translateX(-110%); }
    100% { transform: translateX(220%); }
}

/* ==========================================================================
   Native iOS / Telegram Exit Confirmation Sheet
   ("Orqaga" -> "Chiqish" flow)
   ========================================================================== */
.emotia-exit-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100050;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 12px max(12px, var(--emotia-safe-right)) calc(max(var(--emotia-bottom-inset), 12px) + 4px) max(12px, var(--emotia-safe-left));
    background: rgba(6, 5, 10, 0.56);
    backdrop-filter: blur(18px) saturate(165%);
    -webkit-backdrop-filter: blur(18px) saturate(165%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Plus Jakarta Sans", system-ui, sans-serif;
}

.emotia-exit-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}

@media (min-width: 640px) {
    .emotia-exit-backdrop {
        align-items: center;
    }
}

.emotia-exit-sheet {
    width: 100%;
    max-width: 386px;
    border-radius: 30px;
    padding: 18px 18px 18px;
    background: linear-gradient(165deg, rgba(40, 33, 30, 0.72) 0%, rgba(16, 13, 15, 0.84) 100%);
    backdrop-filter: blur(36px) saturate(210%);
    -webkit-backdrop-filter: blur(36px) saturate(210%);
    border: 1px solid rgba(255, 248, 238, 0.24);
    box-shadow:
        0 28px 80px rgba(0, 0, 0, 0.68),
        inset 0 1px 0 rgba(255, 255, 255, 0.36),
        inset 0 -1px 0 rgba(255, 255, 255, 0.06);
    color: #fffaf4;
    text-align: center;
    transform: translateY(24px) scale(0.96);
    transition: transform 250ms cubic-bezier(.22, 1.06, .36, 1);
}

.emotia-exit-backdrop.is-open .emotia-exit-sheet {
    transform: translateY(0) scale(1);
}

.emotia-exit-handle {
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.28);
    margin: 0 auto 14px;
}

.emotia-exit-badge {
    width: 48px;
    height: 48px;
    margin: 0 auto 10px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    background: linear-gradient(160deg, rgba(255, 250, 242, 0.24), rgba(243, 214, 173, 0.08));
    border: 1px solid rgba(255, 248, 236, 0.32);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.48);
    color: #fae0b8;
    font: 700 22px Georgia, serif;
}

.emotia-exit-title {
    margin: 0;
    font-size: 17.5px;
    font-weight: 760;
    letter-spacing: -0.022em;
    color: #fffaf4;
}

.emotia-exit-desc {
    margin: 6px 0 18px;
    font-size: 12.5px;
    line-height: 1.48;
    color: rgba(240, 228, 215, 0.72);
}

.emotia-exit-actions {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.emotia-exit-btn {
    width: 100%;
    min-height: 48px;
    padding: 11px 16px;
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 700;
    letter-spacing: -0.01em;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    transition: transform 150ms cubic-bezier(.22, 1, .36, 1), background 160ms ease, border-color 160ms ease, filter 160ms ease;
}

.emotia-exit-btn:active {
    transform: scale(0.965);
}

.emotia-exit-btn-stay {
    background: linear-gradient(180deg, rgba(255, 250, 242, 0.94) 0%, rgba(238, 212, 176, 0.88) 100%);
    border-color: rgba(255, 255, 255, 0.85);
    color: #1c1510;
    box-shadow: 0 8px 24px rgba(243, 214, 173, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.96);
}

.emotia-exit-btn-save {
    background: linear-gradient(180deg, rgba(52, 211, 153, 0.24) 0%, rgba(16, 185, 129, 0.12) 100%);
    border-color: rgba(110, 231, 183, 0.38);
    color: #ecfdf5;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.30);
}

.emotia-exit-btn-leave {
    background: linear-gradient(180deg, rgba(244, 63, 94, 0.22) 0%, rgba(190, 18, 60, 0.12) 100%);
    border-color: rgba(253, 164, 175, 0.36);
    color: #ffe4e6;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.26);
}

/* Auxiliary Mini App pages (invitation-builder.html, invitation.html, view.html) */
.emotia-sticky-safe-header {
    padding-top: calc(var(--emotia-top-inset) + 12px) !important;
    padding-left: max(16px, calc(var(--emotia-safe-left) + 16px)) !important;
    padding-right: max(16px, calc(var(--emotia-safe-right) + 16px)) !important;
}

.emotia-top-safe-overlay {
    padding-top: calc(var(--emotia-top-inset) + 10px) !important;
    padding-left: max(12px, calc(var(--emotia-safe-left) + 12px)) !important;
    padding-right: max(12px, calc(var(--emotia-safe-right) + 12px)) !important;
}

.emotia-view-subhud {
    top: calc(var(--emotia-top-inset) + 68px) !important;
}

#recVoiceBar {
    top: calc(var(--emotia-top-inset) + 122px) !important;
}

#toastBox {
    top: calc(var(--emotia-top-inset) + 68px) !important;
}
