:root {
    --app-aspect-w: 470;
    --app-aspect-h: 920;
    --app-frame-max-width: 470px;
    --app-frame-vertical-gap-max: 24px;
    --app-radius: 48px;

    --app-motion-duration: 280ms;
    --app-motion-ease: cubic-bezier(0.2, 0.8, 0.2, 1);

    --app-surface: #131514;
    --app-backdrop: #0b0c0b;
    --app-backdrop-glow: rgba(255, 255, 255, 0.05);
    --app-frame-edge: rgba(255, 255, 255, 0.08);
    --app-frame-shadow: 0 24px 70px -12px rgba(0, 0, 0, 0.75);
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background-color: var(--app-backdrop);
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
    background-image: radial-gradient(120% 80% at 50% 0%, var(--app-backdrop-glow), transparent 70%);
}

#app-root {
    position: relative;
    flex: 0 0 auto;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--app-surface);
    transform: none;
    filter: none;
    perspective: none;
}

html[data-app-host="desktop"] #app-root {
    --frame-w: min(
        var(--app-frame-max-width),
        var(--app-vw, 100dvw)
    );

    --frame-gap: clamp(
        0px,
        calc((var(--app-vw, 100dvw) - var(--app-frame-max-width)) / 2),
        var(--app-frame-vertical-gap-max)
    );

    width: var(--frame-w);
    aspect-ratio: var(--app-aspect-w) / var(--app-aspect-h);
    height: auto;
    max-height: calc(var(--app-vh, 100dvh) - 2 * var(--frame-gap));

}

html[data-app-host="desktop"][data-tma-mode="desktop"] #app-root {
    border-radius: var(--app-radius);
    box-shadow: 0 0 0 1px var(--app-frame-edge), var(--app-frame-shadow);

    transition:
        border-radius var(--app-motion-duration) var(--app-motion-ease),
        box-shadow var(--app-motion-duration) var(--app-motion-ease);
}

html[data-app-host="mobile"] body {
    background-color: var(--app-surface);
    background-image: none;
}

html[data-app-host="mobile"] #app-root {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    max-height: none;
    aspect-ratio: auto;
    border-radius: 0;
    box-shadow: none;
}

html[data-window-resizing] #app-root {
    transition: none;
}

@media (prefers-reduced-motion: reduce) {
    #app-root,
    html[data-app-host="desktop"] #app-root,
    html[data-app-host="desktop"][data-tma-mode="desktop"] #app-root {
        transition: none;
    }
}

#app-canvas {
    position: absolute;
    inset: 0;
}

#app-canvas > div {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* visibility: hidden — слот, который Compose ещё не показал или целиком обрезал. */
#app-canvas [data-webview-frame]:not([style*="visibility: hidden"]):not([style*="visibility:hidden"]) {
    bottom: 0 !important;
    width: 100% !important;
    height: auto !important;
}

#app-canvas [data-webview-frame]:is([style*="visibility: hidden"], [style*="visibility:hidden"]) {
    display: none !important;
}

#app-canvas [data-webview-frame] > iframe {
    width: 100% !important;
    height: 100% !important;
}

#app-canvas [data-webview-chrome] {
    width: 100% !important;
}

#app-splash {
    --app-splash-exit-duration: 200ms;
    --app-splash-logo-exit-duration: 180ms;

    position: absolute;
    inset: 0;
    z-index: 2147483647;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--app-surface);
    color: var(--app-splash-accent, #1FECA2);
    opacity: 1;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    cursor: default;
}

#app-splash.app-splash--hiding {
    animation: none;
    opacity: 0;
    transition: opacity var(--app-splash-exit-duration) var(--app-motion-ease);
    pointer-events: none;
}

#app-splash.app-splash--hiding #app-splash-logo {
    animation: none;
    opacity: 0;
    transform: scale(0.92);
    transition:
        opacity var(--app-splash-logo-exit-duration) var(--app-motion-ease),
        transform var(--app-splash-logo-exit-duration) var(--app-motion-ease);
}

#app-splash-logo {
    width: 108px;
    height: 108px;
    color: var(--app-splash-accent, #1FECA2);
}

#app-splash.app-splash--covered {
    z-index: 0;
}

#app-boot-error[hidden] {
    display: none !important;
}

#app-boot-error {
    position: absolute;
    inset: 0;
    z-index: 2147483647;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    background-color: var(--app-surface);
    color: #fff;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.app-boot-error-copy {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 8px;
}

.app-boot-error-title,
.app-boot-error-subtitle {
    margin: 0;
}

.app-boot-error-title {
    font-size: 20px;
    font-weight: 600;
    line-height: 1.3;
}

.app-boot-error-subtitle {
    max-width: 320px;
    font-size: 16px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.7);
}

#app-boot-reload {
    width: 100%;
    min-height: 48px;
    border: 0;
    border-radius: 16px;
    background: #fff;
    color: var(--app-surface);
    font: 600 16px/1.2 system-ui, -apple-system, "Segoe UI", sans-serif;
    cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
    #app-splash.app-splash--hiding,
    #app-splash.app-splash--hiding #app-splash-logo {
        transition: none;
    }
}
