/*
 * Mobile-First Gaming Theme CSS
 * Special enhancements for mobile compatibility
 */

/* Critical CSS Variables for Mobile */
:root {
  --mobile-padding: min(16px, 4vw);
  --mobile-gap: min(16px, 3vw);
  --touch-target: 44px;
  --mobile-text: clamp(0.8rem, 2.5vw, 1rem);
  --mobile-heading: clamp(1.1rem, 4vw, 1.8rem);
  --mobile-container: min(100vw - 32px, 1200px);
}

/* Mobile Container System */
.mobile-container {
  width: 100%;
  max-width: var(--mobile-container);
  margin: 0 auto;
  padding: 0 var(--mobile-padding);
}

/* Enhanced Mobile Navigation */
@media (max-width: 768px) {
  .site-header {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  
  .mobile-nav-toggle {
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex !important;
    align-items: center;
    justify-content: center;
  }
  
  .main-nav {
    position: fixed !important;
    top: 100% !important;
    left: 0 !important;
    right: 0 !important;
    background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 100%) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transform: translateY(-100%);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 70vh;
    overflow-y: auto;
  }
  
  .main-nav.active {
    transform: translateY(-100%);
    display: flex !important;
  }
}

/* Mobile Game Grid System */
.games-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)) !important;
  gap: var(--mobile-gap) !important;
  padding: 0 !important;
}

@media (max-width: 600px) {
  .games-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr)) !important;
    gap: 12px !important;
  }
}

@media (max-width: 480px) {
  .games-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
}

/* Mobile Game Card Enhancements */
.game-card {
  background: var(--bg-card, #181828) !important;
  border-radius: 16px !important;
  overflow: hidden !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12) !important;
  height: auto !important;
  display: flex !important;
  flex-direction: column !important;
}

/* Optimize game card layout for mobile */
@media (max-width: 768px) {
  .game-card {
    max-height: 420px !important;
  }
  
  .game-card .game-info {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    padding: 14px !important;
    gap: 8px !important;
  }
  
  .game-card .game-content {
    flex: 1 !important;
  }
  
  .game-card .play-button-container {
    margin-top: 8px !important;
  }
  
  .game-card .play-btn {
    padding: 10px 20px !important;
    font-size: 0.85rem !important;
    border-radius: 20px !important;
    min-width: 90px !important;
  }
}

@media (max-width: 480px) {
  .game-card {
    max-height: 380px !important;
  }
  
  .game-card .game-info {
    padding: 12px !important;
    gap: 6px !important;
  }
  
  .game-card .game-content {
    flex: 1 !important;
  }
  
  .game-card .play-button-container {
    margin-top: 6px !important;
  }
  
  .game-card .play-btn {
    padding: 8px 18px !important;
    font-size: 0.8rem !important;
    border-radius: 18px !important;
    min-width: 80px !important;
  }
}

/* Additional mobile optimizations */
@media (max-width: 768px) {
  /* Compact game cards */
  .game-card {
    margin-bottom: 16px !important;
  }
  
  /* Reduce category margins */
  .game-card div[style*="margin-bottom:12px"] {
    margin-bottom: 8px !important;
  }
  
  /* Compact rating section */
  .game-card .game-stats {
    margin-bottom: 8px !important;
  }
}

@media (max-width: 480px) {
  /* Very compact design for small screens */
  .game-card {
    margin-bottom: 12px !important;
    max-height: 350px !important;
  }
  
  .game-card .game-info {
    padding: 10px !important;
    gap: 6px !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
  }
  
  .game-card .play-btn {
    padding: 8px 16px !important;
    font-size: 0.75rem !important;
    border-radius: 16px !important;
    min-width: 80px !important;
  }
  
  /* Minimize all margins */
  .game-card div[style*="margin-bottom:12px"] {
    margin-bottom: 6px !important;
  }
  
  .game-card .game-stats {
    margin-bottom: 6px !important;
  }
}


/* Mobile Game Player Optimizations */
@media (max-width: 768px) {
  .game-content {
    margin: 16px auto !important;
    padding: 0 var(--mobile-padding) !important;
  }
  
  #game-loader {
    min-height: 50vh !important;
    padding: 20px !important;
    border-radius: 12px !important;
  }
  
  #start-game-btn {
    min-height: var(--touch-target);
    padding: 14px 32px !important;
    font-size: 1rem !important;
    border-radius: 22px !important;
  }
  
  .game-container {
    border-radius: 8px !important;
    margin: 0 !important;
  }
  
  .game-controls {
    top: 8px !important;
    right: 8px !important;
  }
  
  .game-controls button {
    min-height: 36px;
    padding: 6px 10px !important;
    font-size: 0.8rem !important;
  }
}

@media (max-width: 480px) {
  .game-content {
    margin: 12px auto !important;
    padding: 0 8px !important;
  }
  
  #game-loader {
    min-height: 45vh !important;
    padding: 16px !important;
  }
  
  #start-game-btn {
    padding: 12px 28px !important;
    font-size: 0.9rem !important;
    min-width: 140px;
  }
  
  .game-header h1 {
    font-size: 1.6rem !important;
    margin-bottom: 12px !important;
  }
}

/* Touch-Optimized Interactions */
@media (hover: none) and (pointer: coarse) {
  .game-card:active {
    transform: scale(0.98) !important;
    transition: transform 0.1s ease !important;
  }
  
  .play-btn:active,
  button:active,
  .filter-btn:active {
    transform: scale(0.95) !important;
    transition: transform 0.1s ease !important;
  }
  
  /* Disable hover effects on touch devices */
  .game-card:hover {
    transform: none !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12) !important;
  }
}

/* Improved Typography for Mobile */
@media (max-width: 768px) {
  body {
    font-size: var(--mobile-text);
    line-height: 1.5;
  }
  
  h1, h2, h3, h4, h5, h6 {
    line-height: 1.2;
    word-wrap: break-word;
    hyphens: auto;
  }
  
  p, span, div {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
}

/* Mobile Pagination Enhancements */
@media (max-width: 768px) {
  .pagination-wrapper {
    padding: 12px !important;
    gap: 6px !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    margin: 32px 0 !important;
  }
  
  .pagination-wrapper a,
  .pagination-wrapper span {
    min-width: 36px !important;
    min-height: 36px !important;
    font-size: 0.85rem !important;
    padding: 8px 12px !important;
  }
  
  .pagination-wrapper a[style*="padding:12px 20px"],
  .pagination-wrapper span[style*="padding:12px 20px"] {
    padding: 8px 16px !important;
    font-size: 0.8rem !important;
  }
  
  /* Hide some page numbers on very small screens */
  .pagination-wrapper a:nth-child(n+6):nth-last-child(n+6) {
    display: none;
  }
  
  /* Keep only prev/next and current page visible on mobile */
  .pagination-wrapper a:not([href*="Previous"]):not([href*="Next"]):not(.current) {
    display: none;
  }
  
  .pagination-wrapper span:not([style*="linear-gradient"]) {
    display: none;
  }
}

@media (max-width: 480px) {
  .pagination-wrapper {
    padding: 10px !important;
    gap: 4px !important;
    margin: 24px 0 !important;
  }
  
  .pagination-wrapper a,
  .pagination-wrapper span {
    min-width: 32px !important;
    min-height: 32px !important;
    font-size: 0.8rem !important;
    padding: 6px 10px !important;
  }
  
  .pagination-wrapper a[style*="padding"] {
    padding: 6px 12px !important;
    font-size: 0.75rem !important;
  }
  
  /* Show only essential pagination elements on small screens */
  .pagination-wrapper svg {
    width: 12px !important;
    height: 12px !important;
  }
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-dark: #0a0a0a;
    --bg-card: #111111;
    --text-light: #ffffff;
    --text-muted: #999999;
  }
}

/* High DPI Display Optimization */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .game-card img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Landscape Orientation Fixes */
@media screen and (orientation: landscape) and (max-height: 500px) {
  .site-header {
    padding: 8px 0 !important;
  }
  
  .game-content {
    margin: 8px auto !important;
  }
  
  #game-loader {
    min-height: 35vh !important;
  }
}

/* Internet Explorer and Old Browser Support */
@supports not (display: grid) {
  .games-grid {
    display: flex !important;
    flex-wrap: wrap !important;
  }
  
  .game-card {
    flex: 1 1 280px !important;
    margin: 8px !important;
  }
}

/* Print Styles */
@media print {
  .site-header,
  .pagination-wrapper,
  .game-controls,
  #start-game-btn {
    display: none !important;
  }
  
  .game-card {
    break-inside: avoid !important;
  }
}

/* Loading States */
.loading {
  opacity: 0.7;
  pointer-events: none;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid transparent;
  border-top: 2px solid var(--primary-color, #6C5CE7);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Focus Styles for Accessibility */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--primary-color, #6C5CE7) !important;
  outline-offset: 2px !important;
}

/* Mobile Safari Fixes */
@supports (-webkit-touch-callout: none) {
  input[type="search"] {
    -webkit-appearance: none;
    appearance: none;
    border-radius: 20px;
  }
  
  iframe {
    -webkit-overflow-scrolling: touch;
  }
}
