/* Enhanced View Transitions CSS - Based on piccalil.li practical examples */

/* ==========================================================================
   Base Transition Setup
   ========================================================================== */

/* Prevent white flash - set dark background on transition layer */
::view-transition {
    background: #0a0a0a;
}

/* Default cross-fade for root - fallback for non-directional */
::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 0.4s;
    animation-timing-function: cubic-bezier(0.65, 0, 0.35, 1);
    overflow: hidden;
}

::view-transition-old(root) {
    animation-name: fade-out;
}

::view-transition-new(root) {
    animation-name: fade-in;
}

@keyframes fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==========================================================================
   Directional Slide Transitions
   Uses CSS custom property --nav-direction set by JavaScript
   ========================================================================== */

/* Default root transition - crossfade with slight slide */
::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: 0.5s;
    animation-timing-function: cubic-bezier(0.65, 0, 0.35, 1);
    overflow: hidden;
}

::view-transition-old(root) {
    animation-name: root-fade-out;
}

::view-transition-new(root) {
    animation-name: root-fade-in;
}

/* Crossfade animations */
@keyframes root-fade-out {
    from { 
        opacity: 1; 
        transform: translateX(0);
    }
    to { 
        opacity: 0; 
        transform: translateX(-15px);
    }
}

@keyframes root-fade-in {
    from { 
        opacity: 0; 
        transform: translateX(15px);
    }
    to { 
        opacity: 1; 
        transform: translateX(0);
    }
}

/* Backward navigation override - swap directions */
html[data-nav-direction="backward"] ::view-transition-old(root) {
    animation-name: root-fade-out-backward;
}

html[data-nav-direction="backward"] ::view-transition-new(root) {
    animation-name: root-fade-in-backward;
}

@keyframes root-fade-out-backward {
    from { 
        opacity: 1; 
        transform: translateX(0);
    }
    to { 
        opacity: 0; 
        transform: translateX(15px);
    }
}

@keyframes root-fade-in-backward {
    from { 
        opacity: 0; 
        transform: translateX(-15px);
    }
    to { 
        opacity: 1; 
        transform: translateX(0);
    }
}

/* ==========================================================================
   Shared Element Transition - Background Image
   ========================================================================== */

.page-background,
.fake3d-container {
    view-transition-name: page-bg;
}

::view-transition-old(page-bg),
::view-transition-new(page-bg) {
    animation-duration: 0.6s;
    animation-timing-function: cubic-bezier(0.65, 0, 0.35, 1);
    overflow: hidden;
}

/* Background cross-fade with slight scale for depth effect */
::view-transition-old(page-bg) {
    animation-name: bg-fade-out;
    z-index: 2;
}

::view-transition-new(page-bg) {
    animation-name: bg-fade-in;
    z-index: 1;
}

@keyframes bg-fade-out {
    from {
        opacity: 1;
        transform: scale(1);
        filter: brightness(1);
    }
    to {
        opacity: 0;
        transform: scale(1.02);
        filter: brightness(0.8);
    }
}

@keyframes bg-fade-in {
    from {
        opacity: 0;
        transform: scale(1.05);
        filter: brightness(1.2);
    }
    to {
        opacity: 1;
        transform: scale(1);
        filter: brightness(1);
    }
}

/* ==========================================================================
   Content Card Transition - Slide and Fade
   ========================================================================== */

.content-card {
    view-transition-name: content;
}

::view-transition-old(content),
::view-transition-new(content) {
    animation-duration: 0.5s;
    animation-timing-function: cubic-bezier(0.65, 0, 0.35, 1);
}

::view-transition-old(content) {
    animation-name: content-slide-out;
}

::view-transition-new(content) {
    animation-name: content-slide-in;
}

@keyframes content-slide-out {
    from {
        opacity: 1;
        transform: translateX(0) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-20px) translateY(10px);
    }
}

@keyframes content-slide-in {
    from {
        opacity: 0;
        transform: translateX(20px) translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateX(0) translateY(0);
    }
}

/* ==========================================================================
   Navigation Transition - Quick Fade
   ========================================================================== */

.page-nav {
    view-transition-name: nav;
}

::view-transition-old(nav),
::view-transition-new(nav) {
    animation-duration: 0.35s;
    animation-timing-function: cubic-bezier(0.65, 0, 0.35, 1);
}

::view-transition-old(nav) {
    animation-name: nav-fade-out;
}

::view-transition-new(nav) {
    animation-name: nav-fade-in;
}

@keyframes nav-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes nav-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==========================================================================
   Bottom Navigation Transition
   ========================================================================== */

.page-nav-bottom {
    view-transition-name: nav-bottom;
}

::view-transition-old(nav-bottom),
::view-transition-new(nav-bottom) {
    animation-duration: 0.4s;
    animation-timing-function: cubic-bezier(0.65, 0, 0.35, 1);
}

::view-transition-old(nav-bottom) {
    animation-name: nav-bottom-out;
}

::view-transition-new(nav-bottom) {
    animation-name: nav-bottom-in;
}

@keyframes nav-bottom-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(15px);
    }
}

@keyframes nav-bottom-in {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   Menu Page Transitions
   ========================================================================== */

.menu-container {
    view-transition-name: menu;
}

::view-transition-old(menu),
::view-transition-new(menu) {
    animation-duration: 0.5s;
    animation-timing-function: cubic-bezier(0.65, 0, 0.35, 1);
}

::view-transition-old(menu) {
    animation-name: menu-scale-out;
}

::view-transition-new(menu) {
    animation-name: menu-scale-in;
}

@keyframes menu-scale-out {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.96);
    }
}

@keyframes menu-scale-in {
    from {
        opacity: 0;
        transform: scale(0.96);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Menu items - staggered animation */
.menu-item {
    view-transition-name: menu-item;
}

::view-transition-old(menu-item),
::view-transition-new(menu-item) {
    animation-duration: 0.4s;
    animation-timing-function: cubic-bezier(0.65, 0, 0.35, 1);
}

/* ==========================================================================
   Page Entrance Animations (Non-View Transitions API)
   ========================================================================== */

/* Entrance animation classes */
html.page-enter {
    animation: page-enter 0.5s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

html.page-enter-active {
    animation: page-enter-active 0.5s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

@keyframes page-enter {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes page-enter-active {
    from {
        opacity: 1;
    }
    to {
        opacity: 1;
    }
}

/* Content card entrance */
.content-card {
    opacity: 0;
    transform: translateY(20px);
    animation: content-entrance 0.6s cubic-bezier(0.65, 0, 0.35, 1) 0.1s forwards;
}

@keyframes content-entrance {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Navigation entrance */
.page-nav,
.page-nav-bottom {
    opacity: 0;
    animation: nav-entrance 0.4s cubic-bezier(0.65, 0, 0.35, 1) 0.2s forwards;
}

@keyframes nav-entrance {
    to {
        opacity: 1;
    }
}

/* Menu items staggered entrance */
.menu-item {
    opacity: 0;
    transform: translateX(-20px);
    animation: menu-item-entrance 0.5s cubic-bezier(0.65, 0, 0.35, 1) forwards;
}

.menu-item:nth-child(1) { animation-delay: 0.05s; }
.menu-item:nth-child(2) { animation-delay: 0.1s; }
.menu-item:nth-child(3) { animation-delay: 0.15s; }
.menu-item:nth-child(4) { animation-delay: 0.2s; }
.menu-item:nth-child(5) { animation-delay: 0.25s; }
.menu-item:nth-child(6) { animation-delay: 0.3s; }
.menu-item:nth-child(7) { animation-delay: 0.35s; }
.menu-item:nth-child(8) { animation-delay: 0.4s; }
.menu-item:nth-child(9) { animation-delay: 0.45s; }
.menu-item:nth-child(10) { animation-delay: 0.5s; }
.menu-item:nth-child(11) { animation-delay: 0.55s; }
.menu-item:nth-child(12) { animation-delay: 0.6s; }
.menu-item:nth-child(13) { animation-delay: 0.65s; }
.menu-item:nth-child(14) { animation-delay: 0.7s; }

@keyframes menu-item-entrance {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ==========================================================================
   Loading State Styles
   ========================================================================== */

.page-loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0a0a0a;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s cubic-bezier(0.65, 0, 0.35, 1);
}

.page-loading.loaded {
    opacity: 0;
    pointer-events: none;
}

.page-loading-spinner {
    width: 40px;
    height: 40px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top-color: #c9a962;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   Hover Effects for Enhanced UX
   ========================================================================== */

/* Navigation link hover effects */
.nav-prev,
.nav-next {
    transition: transform 0.3s cubic-bezier(0.65, 0, 0.35, 1),
                opacity 0.3s ease;
}

.nav-prev:hover,
.nav-next:hover {
    transform: scale(1.02);
}

/* Menu link hover effects */
.menu-link {
    transition: transform 0.3s cubic-bezier(0.65, 0, 0.35, 1),
                background-color 0.3s ease,
                padding-left 0.3s cubic-bezier(0.65, 0, 0.35, 1);
}

.menu-link:hover {
    transform: translateX(8px);
    padding-left: 1.5rem;
}

.menu-link:hover .menu-arrow {
    transform: translateX(4px);
    opacity: 1;
}

.menu-arrow {
    transition: transform 0.3s cubic-bezier(0.65, 0, 0.35, 1),
                opacity 0.3s ease;
}

/* Home navigation hover */
.nav-home {
    transition: transform 0.3s cubic-bezier(0.65, 0, 0.35, 1),
                background-color 0.3s ease;
}

.nav-home:hover {
    transform: scale(1.05);
}

/* ==========================================================================
   Fallback for browsers without View Transitions API
   ========================================================================== */

@supports not (view-transition-name: none) {
    .page-view,
    .menu-page {
        animation: fadeIn 0.4s cubic-bezier(0.65, 0, 0.35, 1);
    }
    
    .content-card {
        animation: content-entrance-fallback 0.5s cubic-bezier(0.65, 0, 0.35, 1);
    }
    
    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    @keyframes content-entrance-fallback {
        from {
            opacity: 0;
            transform: translateY(20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

/* ==========================================================================
   Reduced Motion Support
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    ::view-transition-old(root),
    ::view-transition-new(root),
    ::view-transition-old(page-bg),
    ::view-transition-new(page-bg),
    ::view-transition-old(content),
    ::view-transition-new(content),
    ::view-transition-old(nav),
    ::view-transition-new(nav),
    ::view-transition-old(nav-bottom),
    ::view-transition-new(nav-bottom),
    ::view-transition-old(menu),
    ::view-transition-new(menu) {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
    
    .content-card,
    .page-nav,
    .page-nav-bottom,
    .menu-item {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    
    .menu-link,
    .nav-prev,
    .nav-next,
    .nav-home {
        transition: none !important;
    }
}
