/**
 * MOBILE OPTIMIZATION - ESL Fun Online
 * Comprehensive mobile menu and layout fixes for ALL pages
 * This file ensures consistent mobile behavior across the entire site
 */

/* ==============================================
   MOBILE HEADER & NAVIGATION - UNIVERSAL
   ============================================== */

@media (max-width: 768px) {
  /* Force proper header display and positioning */
  header {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 1000 !important;
    background: rgba(255, 255, 255, 0.98) !important;
    backdrop-filter: blur(20px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08) !important;
    border-bottom: 1px solid var(--border-color, #e5e7eb) !important;
  }

  .dark-mode header {
    background: rgba(31, 41, 55, 0.98) !important;
    border-bottom-color: rgba(55, 65, 81, 0.5) !important;
  }

  /* Navbar container */
  .navbar {
    height: 70px !important;
    padding: 0.5rem 1rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
  }

  .navbar .container {
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
  }

  /* Logo optimization */
  .logo-container {
    padding: 0.25rem !important;
    gap: 0.5rem !important;
    display: flex !important;
    align-items: center !important;
  }

  .logo-image {
    width: 36px !important;
    height: 36px !important;
  }

  .logo-text {
    font-size: 1.25rem !important;
    font-weight: 700 !important;
  }

  /* Controls layout */
  .controls {
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
  }

  .control-btn {
    padding: 0.5rem !important;
    min-width: 44px !important;
    min-height: 44px !important;
    border-radius: 8px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .control-btn i {
    font-size: 1.1rem !important;
  }

  .control-btn span {
    display: none !important;
  }

  /* FORCE mobile toggle visibility */
  .mobile-toggle,
  #mobileToggle,
  button.mobile-toggle,
  .control-btn.mobile-toggle {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    background: var(--primary-color, #46bbe5) !important;
    color: white !important;
    border: none !important;
  }

  .mobile-toggle:hover,
  .mobile-toggle:active {
    background: var(--primary-hover, #05425c) !important;
    transform: scale(0.95) !important;
  }

  /* FORCE mobile navigation menu */
  .nav-links,
  #navLinks,
  ul.nav-links {
    position: fixed !important;
    top: 70px !important;
    left: 0 !important;
    right: 0 !important;
    background: var(--bg-primary, #ffffff) !important;
    border-bottom: 1px solid var(--border-color, #e5e7eb) !important;
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 1rem !important;
    gap: 0 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    transform: translateY(-20px) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    max-height: 0 !important;
    overflow: hidden !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15) !important;
    z-index: 999 !important;
    list-style: none !important;
    margin: 0 !important;
  }

  .dark-mode .nav-links,
  .dark-mode #navLinks {
    background: var(--bg-secondary, #1f2937) !important;
  }

  /* Active menu state */
  .nav-links.active,
  #navLinks.active,
  ul.nav-links.active {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) !important;
    max-height: calc(100vh - 70px) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Scrollbar styling */
  .nav-links::-webkit-scrollbar,
  #navLinks::-webkit-scrollbar {
    width: 6px !important;
  }

  .nav-links::-webkit-scrollbar-track,
  #navLinks::-webkit-scrollbar-track {
    background: transparent !important;
  }

  .nav-links::-webkit-scrollbar-thumb,
  #navLinks::-webkit-scrollbar-thumb {
    background: var(--border-color, #e5e7eb) !important;
    border-radius: 3px !important;
  }

  /* Nav items */
  .nav-item,
  .nav-links > li {
    width: 100% !important;
    margin-bottom: 0.5rem !important;
    position: relative !important;
    list-style: none !important;
  }

  .nav-item:last-child {
    margin-bottom: 0 !important;
  }

  /* Nav links styling */
  .nav-link,
  .nav-item > a {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 1rem !important;
    border-radius: 10px !important;
    background: var(--bg-secondary, #f9fafb) !important;
    width: 100% !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    border: 2px solid transparent !important;
    transition: all 0.2s ease !important;
    color: var(--text-primary, #1f2937) !important;
    text-decoration: none !important;
    gap: 0.75rem !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
  }

  .dark-mode .nav-link,
  .dark-mode .nav-item > a {
    background: var(--bg-tertiary, #374151) !important;
    color: var(--text-primary, #f9fafb) !important;
  }

  .nav-link i:first-child,
  .nav-item > a i:first-child {
    font-size: 1.1rem !important;
    width: 24px !important;
    text-align: center !important;
  }

  .nav-link:hover,
  .nav-link:active,
  .nav-link:focus {
    background: var(--primary-light, rgba(70, 187, 229, 0.1)) !important;
    border-color: var(--primary-color, #46bbe5) !important;
    color: var(--primary-color, #46bbe5) !important;
    transform: translateX(2px) !important;
    box-shadow: 0 2px 8px rgba(70, 187, 229, 0.2) !important;
  }

  /* Current page indicator */
  .nav-item.current .nav-link,
  .nav-item.current > a {
    background: var(--primary-color, #46bbe5) !important;
    color: white !important;
    border-color: var(--primary-color, #46bbe5) !important;
    font-weight: 700 !important;
  }

  /* Remove desktop hover effects */
  .nav-link::before {
    display: none !important;
  }

  /* Dropdowns */
  .dropdown {
    position: static !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    box-shadow: none !important;
    border: none !important;
    background: rgba(0, 0, 0, 0.02) !important;
    border-radius: 8px !important;
    margin-top: 0.5rem !important;
    max-height: 0 !important;
    overflow: hidden !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    width: 100% !important;
    min-width: unset !important;
    left: unset !important;
    right: unset !important;
  }

  .dark-mode .dropdown {
    background: rgba(255, 255, 255, 0.03) !important;
  }

  .dropdown::before,
  .dropdown::after {
    display: none !important;
  }

  /* Open dropdown state */
  .nav-item.mobile-dropdown-open .dropdown,
  .nav-item.mobile-open .dropdown {
    max-height: 500px !important;
    padding: 0.5rem 0 !important;
    border: 1px solid var(--border-color, #e5e7eb) !important;
    border-radius: 8px !important;
    background: rgba(0, 0, 0, 0.02) !important;
    margin-top: 0.5rem !important;
  }

  .dark-mode .nav-item.mobile-open .dropdown {
    background: rgba(255, 255, 255, 0.03) !important;
  }

  /* Disable hover on mobile */
  .nav-item:hover .dropdown,
  .nav-item:focus-within .dropdown {
    max-height: 0 !important;
    padding: 0 !important;
    border: none !important;
  }

  /* Dropdown items */
  .dropdown-item,
  .dropdown > a {
    padding: 0.875rem 1rem !important;
    font-size: 0.95rem !important;
    border-radius: 6px !important;
    margin: 0.25rem 0.5rem !important;
    background: var(--bg-primary, #ffffff) !important;
    border: 1px solid transparent !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.75rem !important;
    color: var(--text-secondary, #6b7280) !important;
    text-decoration: none !important;
    font-weight: 500 !important;
  }

  .dropdown-item i,
  .dropdown > a i {
    font-size: 1rem !important;
    width: 20px !important;
    text-align: center !important;
  }

  .dropdown-item:hover,
  .dropdown-item:active,
  .dropdown > a:hover,
  .dropdown > a:active {
    transform: translateX(4px) !important;
    background: var(--primary-light, rgba(70, 187, 229, 0.1)) !important;
    border-color: var(--primary-color, #46bbe5) !important;
    color: var(--primary-color, #46bbe5) !important;
    box-shadow: 0 1px 4px rgba(70, 187, 229, 0.15) !important;
  }

  /* Parent state when dropdown open */
  .nav-item.mobile-dropdown-open > .nav-link,
  .nav-item.mobile-open > .nav-link,
  .nav-item.mobile-open > a {
    background: var(--primary-light, rgba(70, 187, 229, 0.1)) !important;
    color: var(--primary-color, #46bbe5) !important;
    border-color: var(--primary-color, #46bbe5) !important;
  }

  /* Chevron rotation */
  .nav-item.mobile-dropdown-open .fa-chevron-down,
  .nav-item.mobile-open .fa-chevron-down {
    transform: rotate(180deg) !important;
  }

  .nav-link .fa-chevron-down,
  .nav-item > a .fa-chevron-down {
    transition: transform 0.3s ease !important;
    font-size: 0.875rem !important;
  }

  /* Body scroll lock */
  body.mobile-menu-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
  }

  /* Container fixes */
  .container {
    padding: 0 1rem !important;
    margin: 0 auto !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Backdrop overlay */
  .nav-links.active::before,
  #navLinks.active::before {
    content: "";
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(2px);
    z-index: -1;
  }

  /* Page header spacing */
  .page-header,
  .hero,
  main {
    padding-top: calc(70px + 2rem) !important;
  }

  /* Content sections */
  section {
    padding: 3rem 1rem !important;
  }

  /* Page titles */
  .page-header h1,
  .hero h1,
  h1 {
    font-size: clamp(1.75rem, 5vw, 2.5rem) !important;
    line-height: 1.2 !important;
  }
}

/* ==============================================
   SMALL MOBILE SCREENS (≤480px)
   ============================================== */

@media (max-width: 480px) {
  /* Compact header */
  header {
    height: 60px !important;
  }

  .navbar {
    height: 60px !important;
    padding: 0.5rem 0.75rem !important;
  }

  .container {
    padding: 0 0.75rem !important;
  }

  /* Smaller logo */
  .logo-container {
    gap: 0.4rem !important;
  }

  .logo-text {
    font-size: 1.1rem !important;
  }

  .logo-image {
    width: 32px !important;
    height: 32px !important;
  }

  /* Compact controls */
  .controls {
    gap: 0.4rem !important;
  }

  .control-btn {
    min-width: 40px !important;
    min-height: 40px !important;
    padding: 0.4rem !important;
  }

  .control-btn i {
    font-size: 1rem !important;
  }

  /* Menu adjustments */
  .nav-links,
  #navLinks {
    padding: 0.75rem !important;
    top: 60px !important;
  }

  .nav-item {
    margin-bottom: 0.4rem !important;
  }

  .nav-link,
  .nav-item > a {
    padding: 0.875rem !important;
    font-size: 0.95rem !important;
    border-radius: 8px !important;
  }

  .nav-link i:first-child {
    font-size: 1rem !important;
    width: 20px !important;
  }

  .nav-link .fa-chevron-down {
    font-size: 0.8rem !important;
  }

  .dropdown-item {
    padding: 0.75rem 0.875rem !important;
    font-size: 0.9rem !important;
    margin: 0.2rem 0.4rem !important;
  }

  .dropdown-item i {
    width: 18px !important;
    font-size: 0.9rem !important;
  }

  /* Page spacing */
  .page-header,
  .hero,
  main {
    padding-top: calc(60px + 1.5rem) !important;
  }

  section {
    padding: 2rem 0.75rem !important;
  }

  h1 {
    font-size: 1.5rem !important;
  }

  h2 {
    font-size: 1.25rem !important;
  }
}

/* ==============================================
   ACCESSIBILITY & TOUCH OPTIMIZATION
   ============================================== */

@media (max-width: 768px) {
  /* Remove tap highlight */
  * {
    -webkit-tap-highlight-color: transparent !important;
  }

  /* Better touch targets */
  a,
  button,
  input,
  select,
  textarea {
    min-height: 44px !important;
  }

  /* Prevent text size adjustment */
  * {
    -webkit-text-size-adjust: 100% !important;
    text-size-adjust: 100% !important;
  }
}

/* ==============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================== */

@media (max-width: 768px) {
  /* Reduce motion for better performance */
  @media (prefers-reduced-motion: reduce) {
    * {
      animation: none !important;
      transition: none !important;
    }
  }

  /* GPU acceleration for smooth animations */
  .nav-links,
  #navLinks,
  .dropdown,
  .nav-link,
  .mobile-toggle {
    will-change: transform, opacity !important;
  }
}
