/* ================================================
   App Switcher — iOS-style multitasking view
   Phone frame: 300 × 650 CSS px
   Card: 240 × (32+8+520) = 560px
   Thumbnail inner: 300×650 scaled to 0.8 = 240×520
   ================================================ */

#app-switcher {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 1990; /* below status-bar (2000) and dynamic-island (2500) */
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    overflow: hidden;
    border-radius: 44px;
    /* No opacity transition on the root — bg is instant, stage fades in */
}

#app-switcher.switcher-visible {
    pointer-events: all;
}

#app-switcher.switcher-closeall-exit {
    pointer-events: none;
}

/* Stage, button and pill all fade together; bg is already fully visible */
#app-switcher .switcher-stage,
#app-switcher .switcher-no-apps,
#app-switcher .switcher-close-all-btn,
#app-switcher .switcher-home-pill {
    opacity: 0;
    transition: opacity 0.22s ease;
}
#app-switcher.switcher-visible .switcher-stage,
#app-switcher.switcher-visible .switcher-no-apps,
#app-switcher.switcher-visible .switcher-close-all-btn,
#app-switcher.switcher-visible .switcher-home-pill {
    opacity: 1;
}

/* Close-all uses a short, soft exit so returning home does not feel abrupt. */
#app-switcher.switcher-closeall-exit .switcher-stage,
#app-switcher.switcher-closeall-exit .switcher-no-apps,
#app-switcher.switcher-closeall-exit .switcher-close-all-btn,
#app-switcher.switcher-closeall-exit .switcher-home-pill {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
    transition: opacity 0.14s ease, transform 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Blurred backdrop — fades out when switcher closes, but is instant on open */
.switcher-bg {
    position: absolute;
    inset: 0;
    background: rgba(40, 40, 40, 0.60);
    backdrop-filter: blur(6px);
    border-radius: 44px;
    transition: opacity 0.28s ease;
    opacity: 1;
}

/* When switcher is closing (visible class removed), bg fades out too */
#app-switcher:not(.switcher-visible) .switcher-bg {
    opacity: 0;
}

#app-switcher.switcher-closeall-exit .switcher-bg {
    opacity: 0;
    transition: opacity 0.16s ease;
}

/* Title removed */

/* Stage: clipping area for the horizontal carousel */
.switcher-stage {
    position: relative;
    z-index: 1;
    width: 100%;
    flex: 1;
    overflow: hidden;
    display: flex;
    align-items: center;      /* vertically centre the track */
    padding-top: 30px;     /* nudge above home pill */
    box-sizing: border-box;
}

/* Moving track — JS sets translateX; left edge anchored at 0 */
.switcher-track {
    position: absolute;
    left: 0;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    flex-shrink: 0;
    will-change: transform;
}

/* Individual card */
.switcher-card {
    flex-shrink: 0;
    width: 204px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 7px;
    position: relative;
    user-select: none;
}

/* Fly-up dismiss animation */
.switcher-card.card-dismissing {
    transition: transform 0.22s cubic-bezier(0.4, 0, 1, 1),
                opacity   0.22s ease !important;
    transform: translateY(-140%) !important;
    opacity: 0 !important;
    pointer-events: none;
}

/* Header: icon + app name */
.switcher-card-header {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    padding: 0 10px;
    box-sizing: border-box;
}

.switcher-card-icon {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    object-fit: contain;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.08);
}

.switcher-card-name {
    color: rgba(255, 255, 255, 0.92);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

/*
 * Thumbnail container.
 * Clips the scaled 300×650 inner down to 204×442 (scale 0.68).
 */
.switcher-card-thumbnail {
    width: 204px;
    height: 442px;
    border-radius: 19px;
    overflow: hidden;
    clip-path: inset(0 round 19px);
    -webkit-clip-path: inset(0 round 19px);
    position: relative;
    flex-shrink: 0;
    background: transparent;
    cursor: pointer;
    /* Force GPU compositing for sharp anti-aliased corner clipping */
    transform: translateZ(0);
    will-change: transform;
    isolation: isolate;
}

/*
 * Inner wrapper: holds the full 300×650 app DOM.
 * scale(0.68) with transform-origin top-left → visually 204×442.
 */
.switcher-card-thumbnail-inner {
    position: relative;
    width: 300px;
    height: 650px;
    transform: scale(0.68);
    transform-origin: top left;
    pointer-events: none;
    overflow: hidden;
}

/* Cloned app-wrapper: reset any mid-animation state.
 * border-radius: 0 — container thumbnail already clips rounded;
 * keeping 44px here would show the #111113 background in the corners. */
.switcher-card-thumbnail-inner > .app-wrapper {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    opacity: 1 !important;
    transform: scale(1) !important;
    transition: none !important;
    animation: none !important;
    border-radius: 0 !important;
    overflow: hidden;
}

/* Fallback when no DOM snapshot available */
.switcher-card-empty-thumb {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1c1c1e;
    border-radius: 19px;
}

.switcher-empty-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    object-fit: contain;
    opacity: 0.3;
}

/* No apps hint */
.switcher-no-apps {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 10px;
    padding-bottom: 40px;
}

.switcher-no-apps-text {
    color: rgba(255, 255, 255, 0.35);
    font-size: 13px;
    font-weight: 500;
}

/* Home pill at bottom */
/* ---- Close-all button — matches .button glass design from ui_overview ---- */
.switcher-close-all-btn {
    position: relative;
    z-index: 2;
    flex-shrink: 0;
    margin-bottom: 42px;
    padding: 0 28px;
    height: 38px;
    border: none;
    border-radius: 99em;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: rgba(255, 255, 255, 0.92);

    background-color: rgba(187, 187, 188, 0.14);
    backdrop-filter: blur(8px) saturate(150%);
    -webkit-backdrop-filter: blur(8px) saturate(150%);

    box-shadow:
        inset 0 0 0 1px        rgba(255, 255, 255, 0.14),
        inset 1px 2px 0 -1px   rgba(255, 255, 255, 0.295),
        inset -1px -1px 0 -1px rgba(255, 255, 255, 0.50),
        inset 0 -1px 4px 0     rgba(0, 0, 0, 0.10),
        0 2px 8px 0            rgba(0, 0, 0, 0.10),
        0 6px 20px 0           rgba(0, 0, 0, 0.06);

    transition:
        background-color 200ms cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow       200ms cubic-bezier(0.4, 0, 0.2, 1),
        scale            160ms cubic-bezier(0.5, 0, 0, 1);

    -webkit-tap-highlight-color: transparent;
    outline: none;
    user-select: none;
    -webkit-user-select: none;
}

.switcher-close-all-btn:hover {
    background-color: rgba(187, 187, 188, 0.22);
    box-shadow:
        inset 0 0 0 1px        rgba(255, 255, 255, 0.22),
        inset 1px 2px 0 -1px   rgba(255, 255, 255, 0.85),
        inset -1px -1px 0 -1px rgba(255, 255, 255, 0.55),
        inset 0 -1px 4px 0     rgba(0, 0, 0, 0.10),
        0 2px 10px 0           rgba(0, 0, 0, 0.12),
        0 6px 20px 0           rgba(0, 0, 0, 0.08);
}

.switcher-close-all-btn:active {
    scale: 0.97;
    box-shadow:
        inset 0 0 0 1px   rgba(255, 255, 255, 0.10),
        inset 0 2px 6px 0 rgba(0, 0, 0, 0.14),
        0 1px 4px 0       rgba(0, 0, 0, 0.06);
}

.switcher-home-pill {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 5px;
    background: rgba(255, 255, 255, 0.35);
    border-radius: 3px;
    z-index: 2;
    cursor: pointer;
    transition: background 0.2s ease;
}

.switcher-home-pill:hover {
    background: rgba(255, 255, 255, 0.75);
}
