/**
 * Unified Floating Widget Stack
 * Container for all floating widgets: admin toolbar, cart button, back-to-top
 *
 * Priority order (bottom to top): Admin > Cart > Back-to-Top
 * This ensures proper stacking without overlap or click interception
 */

/* ============================================================================
   MAIN STACK CONTAINER
   ============================================================================ */
.floating-stack {
    position: fixed;
    bottom: 16px;
    right: 16px;
    display: flex;
    flex-direction: column-reverse; /* Items stack from bottom up */
    align-items: flex-end;
    gap: 12px;
    z-index: 9000; /* Base z-index for the container */
    pointer-events: none; /* Container doesn't block clicks */
}

/* All direct children receive pointer events */
.floating-stack > * {
    pointer-events: auto;
}

/* ============================================================================
   STACK ITEMS - Base styles for all floating widgets in the stack
   ============================================================================ */
.floating-stack-item {
    /* Reset any conflicting fixed positioning from child components */
    position: relative !important;
    bottom: auto !important;
    right: auto !important;

    /* Ensure proper stacking context */
    isolation: isolate;
}

/* ============================================================================
   ADMIN TOOLBAR WRAPPER
   Admin toolbar has its own internal structure, so we just wrap it
   ============================================================================ */
.floating-stack .pg-admin-toolbar {
    position: relative;
    bottom: auto;
    right: auto;
    z-index: 3; /* Highest priority in stack */
}

/* ============================================================================
   CART BUTTON IN STACK
   ============================================================================ */
.floating-stack .floating-cart-btn {
    position: relative;
    bottom: auto;
    right: auto;
    z-index: 2; /* Middle priority */
}

/* ============================================================================
   BACK-TO-TOP BUTTON IN STACK
   ============================================================================ */
.floating-stack .back-to-top-btn {
    position: relative;
    bottom: auto;
    right: auto;
    z-index: 1; /* Lowest priority (appears at bottom of stack) */
    display: none; /* Hidden by default, shown via JS */
}

/* When visible class is added by JS, show and animate */
.floating-stack .back-to-top-btn.visible {
    display: flex;
    animation: slideUp 0.3s ease forwards;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* (Book music button removed -- music now accessed via brain menu) */

/* ============================================================================
   BOOK MODAL BUTTON IN STACK
   ============================================================================ */
.floating-stack .book-modal-btn {
    position: relative;
    bottom: auto;
    right: auto;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), inset 0 1px 1px rgba(255, 255, 255, 0.4);
    padding: 0;
}

.book-modal-btn-emoji {
    font-size: 1.35rem;
    line-height: 1;
}

.floating-stack .book-modal-btn:hover {
    background: rgba(255, 255, 255, 0.55);
    transform: scale(1.05);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2), inset 0 1px 1px rgba(255, 255, 255, 0.5);
}

.floating-stack .book-modal-btn:active {
    transform: scale(0.95);
}

[data-theme="dark"] .floating-stack .book-modal-btn {
    background: rgba(50, 50, 70, 0.4);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3), inset 0 1px 1px rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .floating-stack .book-modal-btn:hover {
    background: rgba(70, 70, 100, 0.5);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4), inset 0 1px 1px rgba(255, 255, 255, 0.15);
}

/* ============================================================================
   BIBLE LOOKUP BUTTON IN STACK
   ============================================================================ */
.floating-stack .bible-lookup-btn {
    position: relative;
    bottom: auto;
    right: auto;
    z-index: 1;
    width: 48px;
    height: 48px;
    /* Display is controlled by media query, but visibility by JS */
}

/* In stack, visible class controls opacity/visibility */
.floating-stack .bible-lookup-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: none;
}

/* ============================================================================
   RESPONSIVE ADJUSTMENTS
   ============================================================================ */

/* Tablet and up - slightly more spacing */
@media (min-width: 576px) {
    .floating-stack {
        bottom: 20px;
        right: 20px;
        gap: 14px;
    }
}

/* Desktop - more spacing, adjust for larger buttons */
@media (min-width: 768px) {
    .floating-stack {
        bottom: 24px;
        right: 24px;
        gap: 16px;
    }
}

/* ============================================================================
   LANDSCAPE ORIENTATION ADJUSTMENTS
   Reduce vertical spacing in landscape to prevent stack overflow
   ============================================================================ */
@media (orientation: landscape) and (max-height: 500px) {
    .floating-stack {
        bottom: 12px;
        right: 12px;
        gap: 8px;
    }

    /* Smaller buttons in cramped landscape */
    .floating-stack .floating-cart-btn {
        width: 44px;
        height: 44px;
    }

    .floating-stack .back-to-top-btn {
        width: 42px;
        height: 42px;
    }

    .floating-stack .book-modal-btn {
        width: 42px;
        height: 42px;
    }

    .floating-stack .book-modal-btn .book-modal-btn-emoji {
        font-size: 1.15rem;
    }

    .floating-stack .bible-lookup-btn {
        width: 42px;
        height: 42px;
    }

    .floating-stack .pg-admin-toggle {
        width: 46px;
        height: 46px;
        font-size: 1.2rem;
    }
}

/* ============================================================================
   SAFE AREA INSETS (for notched devices like iPhone)
   ============================================================================ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .floating-stack {
        bottom: calc(16px + env(safe-area-inset-bottom));
        right: calc(16px + env(safe-area-inset-right));
    }

    @media (min-width: 768px) {
        .floating-stack {
            bottom: calc(24px + env(safe-area-inset-bottom));
            right: calc(24px + env(safe-area-inset-right));
        }
    }
}

/* ============================================================================
   BRAIN MENU WRAP
   ============================================================================ */
.brain-menu-wrap {
    position: relative !important;
    bottom: auto !important;
    right: auto !important;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ============================================================================
   BRAIN DROPDOWN MENU
   ============================================================================ */
.brain-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
    opacity: 0;
    transform: translateY(10px) scale(0.9);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
}

.brain-menu.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.brain-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    cursor: pointer;
    font-size: 0.85rem;
    color: #333;
    white-space: nowrap;
    transition: all 0.15s ease;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

.brain-menu-item:hover {
    background: rgba(255, 255, 255, 0.95);
    transform: scale(1.04);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.brain-menu-icon {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

.brain-menu-label {
    font-weight: 500;
}

[data-theme="dark"] .brain-menu-item {
    background: rgba(40, 40, 60, 0.85);
    border-color: rgba(255, 255, 255, 0.15);
    color: #e0e0e0;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .brain-menu-item:hover {
    background: rgba(60, 60, 85, 0.95);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* ============================================================================
   BRAIN BUTTON -- MENU OPEN STATE
   ============================================================================ */
.book-modal-btn.menu-open {
    background: rgba(139, 92, 246, 0.15);
    border-color: rgba(139, 92, 246, 0.3);
}

[data-theme="dark"] .book-modal-btn.menu-open {
    background: rgba(139, 92, 246, 0.25);
    border-color: rgba(139, 92, 246, 0.4);
}

/* ============================================================================
   NOW PLAYING INDICATOR
   ============================================================================ */
.brain-now-playing {
    position: absolute;
    bottom: -2px;
    right: 56px;
    white-space: nowrap;
    font-size: 0.7rem;
    color: #7c3aed;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 12px;
    padding: 2px 10px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    animation: nowPlayingPulse 2s ease-in-out infinite;
    pointer-events: none;
}

[data-theme="dark"] .brain-now-playing {
    background: rgba(40, 40, 60, 0.85);
    color: #a78bfa;
    border-color: rgba(139, 92, 246, 0.3);
}

@keyframes nowPlayingPulse {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

/* ============================================================================
   BRAIN BUTTON BOUNCE (when music is playing)
   ============================================================================ */
.book-modal-btn.brain-btn-bounce {
    animation: brainBounce 2s ease-in-out infinite;
}

@keyframes brainBounce {
    0%, 100% { transform: translateY(0); }
    25% { transform: translateY(-3px); }
    50% { transform: translateY(0); }
    75% { transform: translateY(-2px); }
}

/* ============================================================================
   MUSIC NOTE PARTICLES
   ============================================================================ */
.music-note-particle {
    position: absolute;
    bottom: 48px;
    font-size: 1rem;
    color: #7c3aed;
    pointer-events: none;
    animation: noteFloat 2s ease-out forwards;
    opacity: 0;
    z-index: -1;
}

[data-theme="dark"] .music-note-particle {
    color: #a78bfa;
}

@keyframes noteFloat {
    0% {
        opacity: 0.8;
        transform: translateY(0) rotate(0deg);
    }
    50% {
        opacity: 0.6;
    }
    100% {
        opacity: 0;
        transform: translateY(-60px) rotate(15deg);
    }
}

/* ============================================================================
   MUSIC PLAYING STATE ON BRAIN BUTTON
   ============================================================================ */
.book-modal-btn.music-playing {
    border-color: rgba(139, 92, 246, 0.4);
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.2), inset 0 1px 1px rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .book-modal-btn.music-playing {
    border-color: rgba(139, 92, 246, 0.5);
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.3), inset 0 1px 1px rgba(255, 255, 255, 0.1);
}

/* ============================================================================
   ACCESSIBILITY: REDUCE MOTION
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
    .floating-stack,
    .floating-stack > * {
        transition: none;
    }
    .book-modal-btn.brain-btn-bounce,
    .music-note-particle {
        animation: none;
    }
}

/* ============================================================================
   PRINT STYLES - Hide floating widgets when printing
   ============================================================================ */
@media print {
    .floating-stack {
        display: none !important;
    }
}
