/* ============================================================================
   MOBILE FIXES & RESPONSIVE STYLES
   ============================================================================
   
   TABLE OF CONTENTS:
   1. Overflow & Scroll Prevention
   2. Container Fixes
   3. Mobile Navigation
   4. Mobile Features Grid (Horizontal Scroll - DISABLED)
   5. Mobile Typography
   6. Mobile Spacing
   7. Mobile Components
   
   ============================================================================ */

/* ============================================================================
   1. OVERFLOW & SCROLL PREVENTION
   ============================================================================
   All overflow-x settings are centralized here.
   ============================================================================ */

/* Prevent horizontal scroll — MOBILE ONLY */
@media (max-width: 768px) {
  html {
      overflow-x: hidden;
      overflow-y: auto;
      width: 100%;
  }
  body {
      overflow-x: hidden;
      overflow-y: auto;
      width: 100%;
      position: relative;
  }
  .container {
      width: 100%;
      max-width: var(--container-width);
      padding-left: 0;
      padding-right: 0;
      overflow-x: hidden;
      overflow-y: visible;
  }
}

/* Desktop: clip prevents scrollbar but allows visual overflow for hover effects */
@media (min-width: 769px) {
  html, body {
      overflow-x: clip;
  }
}

/* Ensure all images are responsive */
img {
    max-width: 100%;
    height: auto;
}

/* Mobile Header Fixes — robust 2-row grid layout */
@media (max-width: 768px) {
    .site-header .header-content {
        display: grid !important;
        grid-template-columns: auto 1fr auto;
        grid-template-rows: auto auto;
        align-items: center;
        gap: 0;
        position: relative;
    }

    .site-header .logo {
        grid-column: 1;
        grid-row: 1;
    }

    .logo img {
        height: 36px !important;
        max-height: 36px;
    }

    /* Nav hidden on mobile (shown via hamburger) */
    .site-header .main-nav {
        display: none;
        grid-column: 1 / -1;
        grid-row: 3;
    }

    /* Auth buttons (guest) — right side of row 1 */
    .header-auth {
        grid-column: 3;
        grid-row: 1;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        gap: 6px !important;
        overflow: visible;
    }

    /* Authenticated user menu — right side of row 1 */
    .header-actions {
        grid-column: 3;
        grid-row: 1;
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }

    .header-auth .btn {
        flex: 0 0 auto;
        padding: 0.45rem 0.75rem !important;
        font-size: 0.8rem !important;
        white-space: nowrap;
        min-width: 0;
    }

    /* User name: truncate on small screens */
    .user-name {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .language-switcher {
        display: none;
    }

    /* Burger: row 2, left-aligned, full width */
    .mobile-menu-toggle {
        grid-column: 1 / -1;
        grid-row: 2;
        justify-self: start;
        margin: 4px 0 0 0;
    }
}

/* Mobile Menu — open state */
@media (max-width: 768px) {
    .main-nav.nav-open {
        display: flex !important;
        flex-direction: column;
        position: fixed;
        top: var(--menu-top, 68px);
        left: 0;
        right: 0;
        background: rgba(15, 20, 25, 0.97);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid rgba(0, 217, 126, 0.3);
        border-bottom: 1px solid rgba(0, 217, 126, 0.3);
        z-index: 9998;
        padding: 1rem 0;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    }

    .main-nav.nav-open ul {
        flex-direction: column;
        gap: 0;
        padding: 0;
        margin: 0;
        list-style: none;
    }

    .main-nav.nav-open ul li a {
        display: block;
        padding: 0.875rem 1.5rem;
        font-size: 1.05rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        transition: background 0.2s, color 0.2s;
    }

    .main-nav.nav-open ul li:last-child a {
        border-bottom: none;
    }

    .main-nav.nav-open ul li a:hover {
        background: rgba(0, 217, 126, 0.08);
        color: var(--primary);
    }

    /* Active link in mobile menu — green glow effect (replaces canvas fire) */
    .main-nav.nav-open ul li a.active {
        color: #00D97E !important;
        background: linear-gradient(90deg, rgba(0, 217, 126, 0.12) 0%, rgba(0, 217, 126, 0.04) 100%) !important;
        border-left: 3px solid #00D97E;
        box-shadow: inset 0 0 20px rgba(0, 217, 126, 0.08), 0 0 15px rgba(0, 217, 126, 0.1);
        text-shadow: 0 0 12px rgba(0, 217, 126, 0.6), 0 0 24px rgba(0, 217, 126, 0.3);
        position: relative;
        overflow: hidden;
    }

    /* Animated shimmer on active link */
    .main-nav.nav-open ul li a.active::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(0, 217, 126, 0.15), transparent);
        animation: menuFireShimmer 2s ease-in-out infinite;
        pointer-events: none;
    }

    @keyframes menuFireShimmer {
        0% { left: -100%; }
        50% { left: 100%; }
        100% { left: 100%; }
    }

    /* Hamburger → X animation */
    .mobile-menu-toggle.is-active span:nth-child(1) {
        transform: translateY(6px) rotate(45deg);
    }

    .mobile-menu-toggle.is-active span:nth-child(2) {
        opacity: 0;
        transform: scaleX(0);
    }

    .mobile-menu-toggle.is-active span:nth-child(3) {
        transform: translateY(-6px) rotate(-45deg);
    }

    .mobile-menu-toggle span {
        transition: transform 0.3s ease, opacity 0.3s ease;
        display: block;
    }

    /* Prevent body scroll when menu open */
    body.menu-open {
        overflow: hidden;
    }
}

/* Mobile Header Fixes */
@media (max-width: 768px) {
    /* Fixed header on mobile is ~120px (2-row), compensate */
    body {
        padding-top: 120px !important;
    }

    /* Auth pages: fixed header ~56px, compensate */
    body.auth-page {
        padding-top: 56px !important;
    }

    .hero {
        padding: 60px 0 40px;
    }
    
    .hero-title {
        font-size: 1.75rem;
        line-height: 1.2;
        padding: 0 1rem;
    }
    
    .lang-zh .hero-title {
        font-size: 1.6rem;
    }
    
    .hero-subtitle {
        font-size: 1rem;
        padding: 0 1rem;
        margin-bottom: 2rem;
    }
    
    /* FIX: Hero CTA buttons had calc(8rem + 60px) margin — way too much on mobile */
    .hero-cta,
    .hero-buttons {
        margin-top: 2rem !important;
        padding: 0 1rem;
        gap: 1rem;
    }
    
    .hero-cta .btn {
        width: 100%;
        max-width: 300px;
    }
}

/* Mobile Features Grid Fixes */
@media (max-width: 768px) {
    .features {
        padding: 40px 0 60px;
    }
    
    .section-title {
        font-size: 1.75rem;
        margin-bottom: 2rem;
        padding: 0 1rem;
        text-align: center !important;
    }
    
    .lang-zh .section-title {
        font-size: 1.6rem;
    }
    
    /* Features grid — simple vertical stack on mobile (no carousel) */
    .features-grid,
    .feature-grid,
    .desktop-only-grid {
        display: none !important;
    }

    .mobile-features-cards {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 0.5rem;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    .features .container {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    .features {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .mobile-feature-card {
        display: block;
        background: rgba(45, 55, 65, 0.55);
        border: 1px solid rgba(0, 217, 126, 0.15);
        border-radius: 10px;
        padding: 1rem 0.5rem;
        text-decoration: none;
        color: inherit;
        text-align: center;
        min-width: 0;
        overflow: hidden;
    }

    .mobile-feature-card .feature-icon {
        margin-bottom: 10px;
        display: flex;
        justify-content: center;
    }

    .mobile-feature-card .feature-icon img {
        width: 177px;
        height: 177px;
        object-fit: contain;
    }

    .mobile-feature-card h3 {
        font-size: 1.15rem;
        font-weight: 600;
        color: #fff;
        margin-bottom: 6px;
    }

    .mobile-feature-card p {
        color: rgba(255,255,255,0.6);
        font-size: 0.75rem;
        margin: 0;
    }

    .features-grid::-webkit-scrollbar,
    .feature-grid::-webkit-scrollbar {
        display: none;
    }
    
    /* Feature cards — full width on mobile */
    .feature-block,
    .feature-card {
        width: 100% !important;
        min-width: unset !important;
        max-width: unset !important;
        padding: 1.5rem;
        /* Disable hover effects on mobile to prevent jitter */
        pointer-events: auto;
        user-select: none;
        -webkit-user-select: none;
        /* Force visible — reveal animations break on mobile */
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
    }
    
    /* Disable hover effects on mobile */
    .feature-block:hover,
    .feature-card:hover {
        transform: none !important;
        box-shadow: var(--shadow-md) !important;
    }
    
    /* Disable link hover effects on mobile */
    a.feature-link:hover .feature-icon {
        transform: none !important;
    }
    
    .feature-icon {
        font-size: 2.5rem;
        transition: none !important;
    }
    
    .feature-block h3,
    .feature-card h3 {
        font-size: 1.25rem;
        transition: none !important;
    }
    
    /* Scroll indicator removed — was leaking outside container on mobile */
}

/* Mobile Feature Content Fixes */
@media (max-width: 768px) {
    .feature-hero {
        padding: 2rem 1rem;
        margin-bottom: 0;
    }
    
    .feature-hero .emoji {
        font-size: 3.5rem;
    }
    
    .feature-image {
        padding: 0 1rem;
        margin-bottom: 2rem;
    }
    
    .feature-content {
        padding: 1.5rem;
        margin: 1rem;
        border-radius: 8px;
    }
    
    .feature-content h1 {
        font-size: 1.75rem;
        margin-bottom: 1rem;
    }
    
    .feature-content h2 {
        font-size: 1.5rem;
        margin-top: 2rem;
        margin-bottom: 1rem;
    }
    
    .feature-content h3 {
        font-size: 1.125rem;
        margin-top: 1.5rem;
    }
    
    .feature-content table {
        font-size: 0.875rem;
        display: block;
        overflow-x: hidden;
        white-space: nowrap;
    }
    
    .feature-content th,
    .feature-content td {
        padding: 0.75rem 0.5rem;
    }
}

/* Mobile Steps/How It Works Fixes */
@media (max-width: 768px) {
    .how-it-works {
        padding: 60px 0;
    }
    
    .steps {
        grid-template-columns: 1fr;
        gap: 2rem;
        padding: 0 1rem;
    }
    
    .step-number {
        width: 50px;
        height: 50px;
        font-size: 1.25rem;
    }
    
    .step h3 {
        font-size: 1.25rem;
    }
}

/* Mobile Statistics Fixes */
@media (max-width: 768px) {
    .statistics {
        padding: 60px 0;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
        padding: 0 1rem;
    }
    
    .stat-number {
        font-size: 2rem;
    }
    
    .stat-label {
        font-size: 0.95rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Mobile Testimonials Fixes */
@media (max-width: 768px) {
    .testimonials {
        padding: 60px 0;
    }
    
    .testimonials-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        padding: 0 1rem;
    }
    
    .testimonial {
        padding: 1.5rem;
    }
    
    .testimonial-quote {
        font-size: 1rem;
    }
}

/* Mobile FAQ Fixes */
@media (max-width: 768px) {
    .faq {
        padding: 60px 0;
    }
    
    .faq-list {
        padding: 0 1rem;
    }
    
    .faq-item {
        padding: 1.25rem;
    }
    
    .faq-question {
        font-size: 1.05rem;
    }
}

/* Mobile Final CTA Fixes */
@media (max-width: 768px) {
    .final-cta {
        padding: 40px 1rem 0.25rem;
    }

    .cta-extra {
        display: flex !important;
        flex-direction: column !important;
        align-items: center;
        gap: 1rem;
        white-space: normal !important;
        font-size: 1.15rem !important;
        line-height: 1.5 !important;
        text-align: center;
        margin-top: 1.5rem;
    }

    .cta-extra .cta-item {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        white-space: nowrap;
        font-size: 1.1rem;
    }

    /* dl-free-note тоже использует cta-extra теперь */
    .dl-free-note {
        white-space: normal !important;
    }

    /* Кнопки по центру */
    .cta-buttons {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        width: 100% !important;
    }
    
    .final-cta h2 {
        font-size: 1.75rem;
        margin-bottom: 1rem;
    }
    
    .lang-zh .final-cta h2 {
        font-size: 1.6rem;
    }
    
    .final-cta p {
        font-size: 1.05rem;
        margin-bottom: 2rem;
    }
    
    .cta-buttons {
        padding: 0 1rem;
    }
    
    .cta-buttons .btn {
        width: 100%;
        max-width: 300px;
    }
}

/* Mobile Footer Fixes */
@media (max-width: 768px) {
    .site-footer {
        padding: 3rem 0 2rem;
    }
    
    .footer-grid {
        grid-template-columns: 1fr;
        gap: 2rem;
        padding: 0 1rem;
    }
    
    .footer-col {
        text-align: center;
    }
    
    .social-links {
        justify-content: center;
    }
    
    .footer-bottom {
        padding: 1.5rem 1rem 0;
    }
}

/* Fix for very small screens */
@media (max-width: 360px) {
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    
    .hero-title {
        font-size: 1.5rem;
    }
    
    .lang-zh .hero-title {
        font-size: 1.4rem;
    }
    
    .section-title {
        font-size: 1.5rem;
    }
    
    .lang-zh .section-title {
        font-size: 1.4rem;
    }
    
    .btn {
        padding: 0.625rem 1.25rem;
        font-size: 0.875rem;
    }
}

/* Ensure buttons don't overflow */
.btn {
    max-width: 100%;
    word-wrap: break-word;
}

/* Fix for long text in feature cards */
.feature-block h3,
.feature-card h3 {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Prevent code blocks from overflowing */
pre, code {
    max-width: 100%;
    overflow-x: hidden;
    word-wrap: break-word;
}

/* Fix for embedded content */
iframe, embed, object {
    max-width: 100%;
}

/* Footer Accordion — collapsed by default (all screen sizes) */
.footer-accordion-body {
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease;
    list-style: none;
    margin: 0;
    max-height: 0;
}

/* Desktop: always visible, no collapse */
@media (min-width: 769px) {
    .footer-accordion-body {
        max-height: none !important;
        padding: 0;
        overflow: visible;
    }

    .footer-accordion-icon {
        display: none;
    }
}

/* Mobile Footer Accordion */
@media (max-width: 768px) {
    .footer-accordion-body {
        max-height: 0;
        padding: 0 1rem;
    }

    .footer-accordion-body.open {
        max-height: 300px;
        padding: 0 1rem 0.875rem;
    }

    .site-footer {
        padding: 1.5rem 0 1rem;
    }

    .footer-grid {
        grid-template-columns: 1fr !important;
        gap: 0 !important;
        padding: 0 !important;
    }

    .footer-col {
        text-align: left !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    }

    .footer-accordion-toggle {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.875rem 1rem;
        margin: 0;
        font-size: 0.95rem;
        font-weight: 600;
        color: #e5e7eb;
        user-select: none;
        -webkit-user-select: none;
    }

    .footer-accordion-icon {
        font-size: 1.25rem;
        line-height: 1;
        color: var(--primary, #00D97E);
        font-weight: 400;
        transition: transform 0.2s ease;
    }

    .footer-accordion-body li {
        padding: 0.3rem 0;
        font-size: 0.9rem;
        color: #9ca3af;
    }

    .footer-accordion-body li a {
        color: #9ca3af;
    }

    .footer-accordion-body li a:hover {
        color: var(--primary, #00D97E);
    }

    .footer-bottom {
        padding: 1rem 1rem 0;
        text-align: center;
    }

    .footer-bottom p {
        font-size: 0.8rem;
        color: #6b7280;
    }
}

/* ============================================================================
   TESTIMONIALS MOBILE CAROUSEL
   JS (testimonials-carousel.js) owns the layout — CSS just resets defaults.
   ============================================================================ */
@media (max-width: 768px) {
    /* Let JS wrap the grid in its own viewport div */
    .testimonials .container {
        overflow: visible;
        padding: 0;
    }

    /* Reset grid to block so JS can convert it to flex row */
    .testimonials-grid {
        display: block;
        grid-template-columns: unset !important;
        overflow: visible !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* Disable hover lift on touch */
    .testimonials-grid .testimonial:hover,
    .testimonials-grid .testimonial-card:hover {
        transform: none !important;
    }
}


/* ============================================================================
   CAROUSEL SCROLL INDICATOR — shows user can swipe horizontally
   ============================================================================ */
@media (max-width: 768px) {
    /* Gradient fade on right edge to hint at more content */
    .features-grid::after,
    .feature-grid::after,
    .dl-cards-grid::after,
    .plans-grid::after {
        content: '';
        position: sticky;
        right: 0;
        top: 0;
        flex-shrink: 0;
        width: 24px;
        min-height: 100%;
        background: linear-gradient(to left, var(--bg-primary, #0F1419) 0%, transparent 100%);
        pointer-events: none;
        z-index: 5;
    }

    /* Disable ALL hover transforms on touch devices globally */
    .feature-block:hover,
    .feature-card:hover,
    .step:hover,
    .stat:hover,
    .faq-item:hover {
        transform: none !important;
    }

    /* Force all reveal elements inside horizontal scroll containers to be visible.
       IntersectionObserver doesn't work for off-screen items in overflow-x containers */
    .features-grid .reveal,
    .feature-grid .reveal,
    .plans-grid .reveal,
    .dl-cards-grid .reveal,
    .features-grid .reveal-scale,
    .features-grid .reveal-fade,
    .features-grid .reveal-fade-up,
    .plans-grid .reveal-scale,
    .plans-grid .reveal-fade {
        opacity: 1 !important;
        transform: none !important;
        transition: none !important;
        animation: none !important;
    }

    /* Disable hover animations that cause jank on mobile */
    .stat:hover {
        animation: none !important;
    }

    .step:hover .step-number::after {
        animation: none !important;
        opacity: 0 !important;
    }
}

/* ============================================================================
   iOS SAFE AREA — respect notch and home indicator
   ============================================================================ */
@supports (padding: env(safe-area-inset-bottom)) {
    .site-footer {
        padding-bottom: calc(2rem + env(safe-area-inset-bottom));
    }

    .final-cta,
    .cta {
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    }
}

/* ============================================================================
   TOUCH-FRIENDLY TAP TARGETS — minimum 44px per Apple/Google guidelines
   ============================================================================ */
@media (max-width: 768px) {
    .main-nav.nav-open ul li a {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .faq-question {
        min-height: 44px;
        padding: 12px 0;
    }

    .footer-accordion-toggle {
        min-height: 44px;
    }

    /* Social links in footer */
    .social-links a {
        min-width: 44px;
        min-height: 44px;
    }
}


/* Desktop: hide mobile feature cards, show desktop grid */
@media (min-width: 769px) {
    .mobile-features-cards {
        display: none !important;
    }
    .desktop-only-grid {
        display: grid !important;
    }
}
