/* Basketball League - Mobile Responsive Design */
/* Clean rewrite based on desktop design with Safari compatibility */

/* Prevent initial scroll positioning issues */
html {
    scroll-behavior: auto !important;
}

body {
    scroll-behavior: auto !important;
}

/* Force page to start at top on mobile */
@media (max-width: 767px) {
    html, body {
        scroll-behavior: auto !important;
        overflow-anchor: none; /* Prevent scroll anchoring */
        scroll-padding-top: 0 !important;
    }
    
    /* Prevent any elements from causing initial scroll */
    * {
        scroll-margin-top: 0 !important;
        scroll-snap-margin-top: 0 !important;
        scroll-padding-top: 0 !important;
    }
    
    /* Ensure the app container starts at top */
    #app {
        margin-top: 0 !important;
        padding-top: 0 !important;
        scroll-margin-top: 0 !important;
    }
    
    /* Force main sections to not auto-scroll */
    #main-section,
    #challenge-section {
        scroll-margin-top: 0 !important;
        scroll-snap-margin-top: 0 !important;
    }
}

/* Safari-specific viewport and scrolling fixes */
@supports (-webkit-appearance: none) {
    html {
        height: -webkit-fill-available;
        -webkit-text-size-adjust: 100%;
    }
    
    body {
        min-height: -webkit-fill-available;
        -webkit-overflow-scrolling: touch;
        -webkit-font-smoothing: antialiased;
    }
    
    /* Fix Safari flexbox issues */
    .main-content {
        -webkit-flex-shrink: 0;
        flex-shrink: 0;
    }
    
    /* Fix Safari position fixed issues */
    .main-nav {
        -webkit-transform: translate3d(0, 0, 0);
        transform: translate3d(0, 0, 0);
    }
}

/* Additional Safari mobile fixes */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
    @media (max-width: 767px) {
        /* Force Safari to respect viewport */
        html {
            -webkit-text-size-adjust: none;
        }
        
        body {
            -webkit-transform: translateZ(0);
            transform: translateZ(0);
        }
        
        /* Fix Safari flexbox rendering */
        .main-content,
        .champion-side,
        .versus-side {
            -webkit-backface-visibility: hidden;
            backface-visibility: hidden;
        }
        
        /* Fix Safari position fixed with keyboard */
        .main-nav {
            position: -webkit-sticky;
            position: sticky;
            bottom: 0;
        }
    }
}

/* ===== MOBILE RESPONSIVE DESIGN ===== */
@media (max-width: 767px) {
    
    /* === MOBILE BODY SPACING === */
    body {
        padding-bottom: 120px; /* Ensure all content has space for floating elements */
    }
    
    /* === MAIN LAYOUT === */
    .main-display {
        height: auto !important;
        min-height: 100vh;
        min-height: -webkit-fill-available; /* Safari fix */
        min-height: calc(var(--vh, 1vh) * 100); /* Safari viewport fix */
        overflow: visible !important;
        position: relative !important;
        /* Safari-specific fixes */
        -webkit-overflow-scrolling: touch;
        -webkit-transform: translateZ(0); /* Force hardware acceleration */
        transform: translateZ(0);
        /* Additional Safari fixes */
        width: 100%;
        max-width: 100vw;
        /* Ensure this section is always at the top */
        scroll-margin-top: 0 !important;
        scroll-snap-margin-top: 0 !important;
        /* Force this to be the first visible section */
        margin-top: 0 !important;
        padding-top: 0 !important;
    }
    
    .main-content {
        display: -webkit-flex !important; /* Safari prefix */
        display: flex !important;
        -webkit-flex-direction: column !important; /* Safari prefix */
        flex-direction: column !important;
        height: auto !important;
        position: relative !important;
        padding-bottom: 120px; /* Space for floating WhatsApp and logo elements */
        /* Safari-specific fixes */
        -webkit-transform: translateZ(0); /* Force hardware acceleration */
        transform: translateZ(0);
    }
    
    /* === CHAMPION SECTION === */
    .champion-side {
        width: 100% !important;
        -webkit-flex: none !important; /* Safari prefix */
        flex: none !important;
        padding: 1rem !important;
        -webkit-order: 1 !important; /* Safari prefix */
        order: 1 !important;
        display: -webkit-flex !important; /* Safari prefix */
        display: flex !important;
        -webkit-flex-direction: column !important; /* Safari prefix */
        flex-direction: column !important;
        -webkit-justify-content: flex-start !important; /* Safari prefix */
        justify-content: flex-start !important;
        -webkit-align-items: center !important; /* Safari prefix */
        align-items: center !important;
        /* Safari-specific fixes */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    .team-info {
        max-width: 100%;
        width: 100%;
        margin-bottom: 1rem;
        padding: 1.5rem;
        border-radius: 15px;
        min-height: auto;
        text-align: center;
        /* Keep desktop animations but make them visible immediately on mobile */
        transform: none;
        opacity: 1;
        animation: none;
    }
    
    .team-content {
        transform: none;
        opacity: 1;
        max-height: none;
        display: flex;
        flex-direction: column;
    }
    
    /* Hide mobile team photo - use standard layout instead */
    .mobile-team-photo {
        display: none;
    }
    
    .mobile-team-img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        object-position: center;
        transition: all 0.3s ease;
        border-radius: 20px;
    }
    
    .mobile-team-img:hover,
    .mobile-team-img:active {
        transform: scale(1.05);
    }
    
    /* Mobile team photo overlay removed - using standard layout */
    
    /* Mobile team overlay removed - using standard layout */
    
    /* Hide desktop floating logo on mobile */
    .floating-logo {
        display: none;
    }
    
    .floating-logo-image-mobile {
        height: 80px;
        width: auto;
        max-width: 200px;
        object-fit: contain;
        filter: 
            drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.8))
            drop-shadow(0 0 15px rgba(212, 175, 55, 0.6));
        animation: logoGlow 3s ease-in-out infinite alternate;
        transition: all 0.3s ease;
        cursor: pointer;
        border-radius: 8px;
    }
    
    .floating-logo-image-mobile:hover {
        transform: scale(1.1);
        filter: 
            drop-shadow(2px 2px 6px rgba(0, 0, 0, 0.9))
            drop-shadow(0 0 20px rgba(212, 175, 55, 0.8))
            drop-shadow(0 0 30px rgba(255, 107, 53, 0.6));
    }
    
    /* Mobile logo animations */
    @keyframes logoFloat {
        0% {
            opacity: 0;
            transform: translateY(20px) scale(0.9);
        }
        100% {
            opacity: 1;
            transform: translateY(0) scale(1);
        }
    }
    
    @keyframes logoGlow {
        0% {
            filter: 
                drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.8))
                drop-shadow(0 0 15px rgba(212, 175, 55, 0.6));
            transform: scale(1);
        }
        100% {
            filter: 
                drop-shadow(2px 2px 6px rgba(0, 0, 0, 0.9))
                drop-shadow(0 0 20px rgba(212, 175, 55, 0.8))
                drop-shadow(0 0 25px rgba(255, 107, 53, 0.6));
            transform: scale(1.02);
        }
    }
    
    /* === VERSUS SECTION === */
    .versus-side {
        width: 100% !important;
        -webkit-flex: none !important; /* Safari prefix */
        flex: none !important;
        padding: 1rem !important;
        -webkit-order: 2 !important; /* Safari prefix */
        order: 2 !important;
        border-left: none !important;
        border-top: 2px solid rgba(212, 175, 55, 0.3) !important;
        display: -webkit-flex !important; /* Safari prefix */
        display: flex !important;
        -webkit-flex-direction: column !important; /* Changed to column for mobile */
        flex-direction: column !important;
        -webkit-align-items: center !important; /* Safari prefix */
        align-items: center !important;
        -webkit-justify-content: center !important; /* Safari prefix */
        justify-content: center !important;
        /* Vertical centering for the entire VS section */
        min-height: 50vh; /* Minimum height to allow centering */
        /* Safari-specific fixes */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    .versus-container {
        display: -webkit-flex !important; /* Safari prefix */
        display: flex !important;
        -webkit-flex-direction: row !important; /* Safari prefix */
        flex-direction: row !important;
        -webkit-align-items: center !important; /* Safari prefix */
        align-items: center !important;
        -webkit-justify-content: space-between !important; /* Safari prefix */
        justify-content: space-between !important;
        /* Safari doesn't support gap well, use margin instead */
        width: 100% !important;
        max-width: 100% !important;
        padding: 1rem !important;
        /* Remove desktop animations for mobile */
        -webkit-transform: none !important;
        transform: none !important;
        opacity: 1 !important;
        animation: none !important;
        position: static !important;
        /* Safari-specific fixes */
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        margin-bottom: 1rem; /* Space for match info below */
    }
    
    .team-logo {
        -webkit-flex: 1; /* Safari prefix */
        flex: 1;
        max-width: 40%; /* Increased from 30% to 40% for larger logos */
        padding: 1rem 0.5rem; /* Increased padding */
        border-radius: 12px;
        min-height: 140px; /* Increased from 120px to 140px */
        display: -webkit-flex; /* Safari prefix */
        display: flex;
        -webkit-flex-direction: column; /* Safari prefix */
        flex-direction: column;
        -webkit-justify-content: center; /* Safari prefix */
        justify-content: center;
        -webkit-align-items: center; /* Safari prefix */
        align-items: center;
        text-align: center;
        /* Safari gap fallback */
        margin: 0 0.25rem;
    }
    
    .team-logo img {
        width: 80px; /* Increased from 60px to 80px */
        height: 80px; /* Increased from 60px to 80px */
        margin-bottom: 0.8rem; /* Increased margin */
        object-fit: contain;
    }
    
    .team-label {
        font-size: 0.8rem;
        letter-spacing: 0.5px;
        text-align: center;
    }
    
    .status-text {
        font-size: 0.7rem;
        margin-bottom: 0.3rem;
        text-align: center;
    }
    
    .pulse-dot {
        width: 4px;
        height: 4px;
    }
    
    .vs-element {
        -webkit-flex: 0 0 auto; /* Safari prefix */
        flex: 0 0 auto;
        width: auto;
        height: 120px; /* Increased height to match larger logos */
        display: -webkit-flex; /* Safari prefix */
        display: flex;
        -webkit-flex-direction: column; /* Safari prefix */
        flex-direction: column;
        -webkit-align-items: center; /* Safari prefix */
        align-items: center;
        -webkit-justify-content: center; /* Safari prefix */
        justify-content: center;
        -webkit-order: 2; /* Safari prefix */
        order: 2;
        /* Safari gap fallback */
        margin: 0 0.25rem;
    }
    
    .vs-logo {
        width: 70px; /* Increased from 60px to 70px */
        height: 47px; /* Increased proportionally */
        object-fit: contain;
    }
    
    .match-info {
        /* Match info is now always outside VS container - 60% width (20% increase from 50%) */
        position: relative;
        width: 60%;
        max-width: 60%;
        margin: 1rem auto 0;
        padding: 0.96rem; /* 20% increase from 0.8rem */
        font-size: 0.9rem; /* 20% increase from 0.75rem */
        text-align: center;
        line-height: 1.4;
        background: rgba(0, 0, 0, 0.4);
        border-radius: 12px;
        border: 1px solid rgba(212, 175, 55, 0.3);
        display: block;
        order: 3; /* Place after VS container */
    }
    
    .match-detail {
        margin-bottom: 0.5rem; /* Increased spacing */
        font-size: 0.96rem; /* 20% increase from 0.8rem */
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .match-label {
        font-size: 0.96rem; /* 20% increase from 0.8rem */
        min-width: 72px; /* 20% increase from 60px */
        font-weight: bold;
        color: #ffd700;
    }
    
    .match-value {
        font-size: 0.96rem; /* 20% increase from 0.8rem */
        color: #ffffff;
    }
    
    .champion-logo {
        order: 1;
    }
    
    .challenger-logo {
        order: 3;
    }
    
    /* === CHALLENGE FORM SECTION === */
    .challenge-form-section {
        padding: 2rem 1rem;
        padding-bottom: 120px; /* Extra space for floating elements */
        order: 3;
        /* Prevent this section from being scroll target */
        scroll-margin-top: 0 !important;
        scroll-snap-margin-top: 0 !important;
    }
    
    .form-container {
        padding: 1.5rem; /* Match team-info padding */
        margin: 0;
        border-radius: 15px;
    }
    
    /* Ensure form header aligns exactly with team content */
    .challenge-form-section .form-container {
        padding-left: 1.5rem; /* Match team-info padding exactly */
        padding-right: 1.5rem;
    }
    
    .challenge-form-section .form-header {
        justify-content: center; /* Center the header content */
        text-align: center;
        margin: 0;
        padding: 0;
    }
    
    .challenge-form-section .form-container h2 {
        text-align: center; /* Center the heading text */
        margin: 0;
        padding: 0;
        position: relative;
        left: 0;
    }
    
    .form-header {
        flex-direction: row;
        align-items: center;
        justify-content: center; /* Center the content */
        gap: 1rem;
        text-align: center; /* Center align text */
        padding: 0; /* Remove padding */
        margin: 0; /* Remove margin */
    }
    
    .form-container h2 {
        font-size: 1.5rem;
        margin: 0; /* Remove all margins */
        padding: 0; /* Remove all padding */
        text-align: center; /* Center align text */
        flex: 1; /* Take available space */
    }
    
    /* WhatsApp inquiry removed from form header */
    
    .whatsapp-icon {
        width: 20px; /* Adjusted to match smaller container */
        height: 20px;
    }
    
    /* === MOBILE HAMBURGER MENU === */
    .hamburger-menu {
        display: flex !important; /* Show on mobile */
        top: 1rem;
        left: 1rem;
        width: 45px;
        height: 45px;
        padding: 5px;
        background: linear-gradient(135deg, #d4af37 0%, #f4d03f 100%);
        border: none;
        border-radius: 12px;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        transition: all 0.3s ease;
        box-shadow: 0 4px 15px rgba(212, 175, 55, 0.4);
        z-index: 1002;
        position: fixed;
    }
    
    /* Hamburger Lines Styling */
    .hamburger-lines {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        width: 20px;
        height: 18px; /* Increased height for better spacing */
        transition: all 0.3s ease;
    }
    
    .hamburger-lines .line {
        display: block;
        width: 100%;
        height: 3px; /* Slightly thicker for better visibility */
        background: #1a1a1a; /* Darker for better contrast */
        border-radius: 1px;
        transition: all 0.3s ease;
        box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2); /* Add subtle shadow */
    }
    
    /* Logo styling (hidden by default) */
    .hamburger-logo {
        width: 100%;
        height: 100%;
        object-fit: contain;
        border-radius: 4px;
        transition: all 0.3s ease;
    }
    
    .hamburger-logo.hidden {
        display: none;
    }
    
    /* Active state - hide lines, show logo */
    .hamburger-menu.active .hamburger-lines {
        display: none;
    }
    
    .hamburger-menu.active .hamburger-logo {
        display: block;
    }
    
    /* Hover effects */
    .hamburger-menu:hover {
        transform: scale(1.1);
        box-shadow: 0 6px 20px rgba(212, 175, 55, 0.6);
    }
    
    /* === MOBILE HAMBURGER NAVIGATION === */
    .hamburger-nav {
        display: block !important; /* Show on mobile */
    }
    
    .floating-whatsapp {
        bottom: 1rem;
        left: 1rem;
        width: 55px;
        height: 55px;
        animation: whatsappFloat 0.8s ease-out 0s both, whatsappPulse 2s infinite 0.8s;
    }
    
    .floating-whatsapp img {
        width: 28px;
        height: 28px;
    }
    
    .nav-menu {
        width: 280px;
    }
    
    .nav-header {
        padding: 1.5rem;
    }
    
    .nav-header h3 {
        font-size: 1.3rem;
    }
    
    .nav-links a {
        padding: 0.8rem 1.5rem;
        font-size: 1rem;
    }
    
    .dropdown-submenu a {
        padding: 0.6rem 2.5rem;
        font-size: 0.9rem;
    }
    

    
    /* === MINIMIZE BUTTON === */
    .minimize-btn {
        width: 35px;
        height: 35px;
        font-size: 1.3rem;
        top: 0.5rem;
        left: 0.5rem;
    }
    
    .team-info.minimized .minimize-btn {
        width: 35px;
        height: 35px;
        font-size: 1.3rem;
        top: 0.5rem;
        left: 0.5rem;
    }
    
    /* Show team name and logo before description on mobile */
    .team-name {
        display: block;
        font-size: 2rem;
        text-align: center;
        margin-bottom: 1rem;
        order: 1;
    }
    
    .team-logo-display {
        display: flex;
        justify-content: center;
        margin: 1rem 0;
        order: 2;
    }
    
    .team-logo-img {
        width: 80px;
        height: 80px;
    }
    
    .team-description {
        font-size: 1rem;
        margin-bottom: 1rem;
        text-align: center;
        line-height: 1.6;
        order: 3;
    }
    
    .streak-counter {
        max-width: 300px;
        margin: 0 auto;
        padding: 0.8rem 1.5rem;
        width: 100%;
        order: 4;
    }
    
    .streak-label {
        font-size: 0.9rem;
        text-align: center;
    }
    
    .streak-number {
        font-size: 2rem;
    }
    
    /* === PLAYER CAROUSEL === */
    .player-carousel {
        width: 100%;
        margin-top: 1rem;
        max-width: 100%;
        order: 5;
    }
}

    /* Ensure floating elements are always visible and floating on mobile */
    .floating-whatsapp,
    .floating-logo-mobile {
        display: block !important;
        position: fixed !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }

/* === SMALL MOBILE (480px and below) === */
@media (max-width: 480px) {
    /* Extra spacing for small mobile */
    body {
        padding-bottom: 140px; /* More space on smaller screens */
    }
    
    .champion-side,
    .versus-side {
        padding: 0.8rem;
    }
    
    .team-info {
        padding: 1rem;
        margin-bottom: 0.8rem;
    }
    
    .team-name {
        font-size: 1.8rem;
    }
    
    .team-logo-img {
        width: 70px;
        height: 70px;
    }
    
    /* Mobile team photo hidden - using standard layout */
    
    .mobile-team-name {
        font-size: 1.8rem; /* Smaller font for small screens */
    }
    
    .mobile-team-logo {
        width: 60px;
        height: 60px;
    }
    
    /* Smaller floating logo for small mobile */
    .floating-logo-image-mobile {
        height: 60px;
        max-width: 150px;
    }
    
    .team-description {
        font-size: 0.9rem;
    }
    
    .streak-counter {
        padding: 0.6rem 1rem;
        max-width: 100%;
    }
    
    .streak-label {
        font-size: 0.8rem;
    }
    
    .streak-number {
        font-size: 1.8rem;
    }
    
    .versus-container {
        padding: 0.8rem;
        margin-bottom: 0.8rem; /* Space for match info */
    }
    
    .vs-logo {
        width: 60px; /* Increased from 50px */
        height: 40px; /* Increased from 33px */
    }
    
    .match-info {
        padding: 0.72rem; /* 20% increase from 0.6rem */
        font-size: 0.78rem; /* 20% increase from 0.65rem */
        margin-top: 0.8rem;
        width: 60%; /* 20% increase from 50% */
        max-width: 60%; /* 20% increase from 50% */
    }
    
    .match-detail,
    .match-label,
    .match-value {
        font-size: 0.84rem; /* 20% increase from 0.7rem */
    }
    
    .team-logo {
        padding: 0.8rem; /* Increased from 0.4rem */
        min-height: 120px; /* Increased from 100px */
        max-width: 40%; /* Increased for larger logos */
    }
    
    .team-logo img {
        width: 70px; /* Increased from 50px */
        height: 70px; /* Increased from 50px */
    }
    
    .team-label {
        font-size: 0.7rem;
    }
    

    
    .player-card {
        flex: 0 0 90px;
        padding: 0.5rem;
        min-width: 90px;
    }
    
    .player-photo {
        width: 60px;
        height: 60px;
    }
    
    .player-name {
        font-size: 0.75rem;
    }
    
    .player-position {
        font-size: 0.65rem;
    }
    
    .minimize-btn {
        width: 32px;
        height: 32px;
        font-size: 1.1rem;
    }
    
    .team-info.minimized .minimize-btn {
        width: 32px;
        height: 32px;
        font-size: 1.1rem;
    }
    
    /* Form header adjustments for small mobile */
    .form-container h2 {
        font-size: 1.3rem; /* Slightly smaller for small screens */
        margin: 0; /* Remove all margins */
        padding: 0; /* Remove all padding */
        text-align: center; /* Center align on small screens */
    }
    
    /* Ensure consistent alignment on small mobile */
    .challenge-form-section .form-container {
        padding-left: 1rem; /* Match smaller team-info padding on small mobile */
        padding-right: 1rem;
    }
    
    /* WhatsApp inquiry removed from form header */
    
    /* Hide social sharing buttons on mobile - only show logo.gif */
    .social-share-container,
    button[title*="分享到"],
    .social-share-container * {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
        position: absolute !important;
        left: -9999px !important;
        top: -9999px !important;
    }
}

/* === LANDSCAPE MOBILE === */
@media (max-width: 767px) and (orientation: landscape) and (max-height: 500px) {
    .main-content {
        flex-direction: row;
        padding-bottom: 100px; /* Space for floating elements in landscape */
    }
    
    .champion-side {
        flex: 1;
        order: 1;
        padding: 0.8rem;
    }
    
    .versus-side {
        flex: 0 0 300px;
        order: 2;
        padding: 0.8rem;
        border-top: none;
        border-left: 2px solid rgba(212, 175, 55, 0.3);
    }
    
    .team-info {
        margin-bottom: 0.5rem;
        padding: 1rem;
        min-height: auto;
    }
    
    /* Mobile team photo removed - using standard layout */
    
    .mobile-team-logo {
        width: 50px;
        height: 50px;
    }
    
    .team-name {
        font-size: 1.6rem;
        margin-bottom: 0.5rem;
    }
    
    .team-description {
        font-size: 0.9rem;
        margin-bottom: 0.8rem;
    }
    
    .streak-counter {
        padding: 0.4rem 0.8rem;
        max-width: 200px;
    }
    
    .player-carousel {
        margin-top: 0.5rem;
    }
    
    .versus-container {
        flex-direction: column;
        gap: 0.5rem;
        height: 100%;
        justify-content: space-around;
        padding: 0.5rem;
    }
    
    .team-logo {
        max-width: 100%;
        min-height: 60px;
        padding: 0.5rem;
    }
    
    .team-logo img {
        width: 40px;
        height: 40px;
    }
    
    .vs-element {
        height: 50px;
        order: 2;
    }
    
    .vs-logo {
        width: 40px;
        height: 27px;
    }
    
    .champion-logo {
        order: 1;
    }
    
    .challenger-logo {
        order: 3;
    }
    
    /* Keep navigation at bottom even in landscape */
    .main-nav {
        padding: 0.3rem;
    }
    
    .main-nav ul {
        padding: 0.3rem;
    }
    
    .main-nav a {
        padding: 0.3rem 0.5rem;
        font-size: 0.65rem;
        min-height: 40px;
    }
}



/* === ACCESSIBILITY === */
@media (max-width: 767px) {
    /* Focus indicators */
    .main-nav a:focus,
    .carousel-btn:focus,
    .nav-btn:focus,
    .submit-btn:focus {
        outline: 3px solid rgba(212, 175, 55, 0.8);
        outline-offset: 2px;
    }
    
    /* Reduced motion support */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
}