/* AstroGames Responsive Design and Mobile Optimization */
/* Early 2000s Compatible Mobile Enhancements */

/* Mobile-First Responsive Breakpoints */
/* Following early 2000s design principles with modern mobile support */

/* Base Mobile Styles (320px and up) */
@media screen and (max-width: 767px) {
  /* Container and Layout Adjustments */
  .container {
    max-width: 100%;
    padding: 0 var(--space-3);
  }
  
  .main-content {
    padding: var(--space-3) 0;
  }
  
  /* Header Mobile Optimization */
  .nav-container {
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
  }
  
  .logo-container {
    width: 100%;
    justify-content: center;
    margin-bottom: var(--space-2);
  }
  
  .logo-image {
    height: 32px;
  }
  
  .logo-text {
    font-size: 20px;
  }
  
  /* Mobile Navigation */
  .nav-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #FFFFFF;
    border: 1px solid #CCCCCC;
    border-top: none;
    flex-direction: column;
    gap: 0;
    z-index: 100;
  }
  
  .nav-menu.active {
    display: flex;
  }
  
  .nav-menu li {
    width: 100%;
    border-bottom: 1px solid #E0E0E0;
  }
  
  .nav-menu li:last-child {
    border-bottom: none;
  }
  
  .nav-link {
    display: block;
    width: 100%;
    padding: var(--space-3) var(--space-4);
    text-align: left;
    border: none;
    background: #FFFFFF;
  }
  
  .nav-link:hover {
    background: #F0F0F0;
  }
  
  .nav-link.active {
    background: #E8E8E8;
    border: none;
  }
  
  /* Mobile Menu Toggle */
  .mobile-menu-toggle {
    display: flex;
    background: #E0E0E0;
    border: 1px outset #CCCCCC;
    padding: var(--space-2);
    cursor: pointer;
    flex-direction: column;
    gap: 3px;
    width: 40px;
    height: 32px;
    justify-content: center;
    align-items: center;
  }
  
  .mobile-menu-toggle span {
    display: block;
    width: 20px;
    height: 2px;
    background: #333333;
  }
  
  .mobile-menu-toggle:hover {
    background: #D0D0D0;
  }
  
  .mobile-menu-toggle:active {
    border: 1px inset #CCCCCC;
  }
  
  /* User Area Mobile */
  .user-area {
    gap: var(--space-2);
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .user-btn {
    padding: var(--space-2) var(--space-3) !important;
    font-size: var(--text-sm) !important;
    min-width: 80px;
  }
  
  /* Game Grid Mobile Optimization */
  .games-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-3);
    padding: var(--space-3) 0;
  }
  
  .game-card {
    padding: var(--space-3);
    margin-bottom: var(--space-3);
  }
  
  .game-thumbnail {
    height: 120px;
    margin-bottom: var(--space-2);
  }
  
  .game-info h3 {
    font-size: var(--text-base);
    margin-bottom: var(--space-1);
  }
  
  .game-info p {
    font-size: var(--text-sm);
    line-height: 1.3;
    margin-bottom: var(--space-2);
    /* Limit description to 2 lines on mobile */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  
  .game-meta {
    font-size: var(--text-xs);
    margin-bottom: var(--space-2);
  }
  
  .game-tags {
    display: none; /* Hide tags on mobile to save space */
  }
  
  .game-actions {
    display: flex;
    gap: var(--space-2);
    align-items: center;
  }
  
  .btn-play {
    flex: 1;
    text-align: center;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
  }
  
  .btn-favorite {
    padding: var(--space-2);
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Touch-Optimized Game Overlay */
  .game-overlay {
    opacity: 1; /* Always visible on mobile */
    background: rgba(0, 0, 0, 0.7);
  }
  
  .game-play-btn {
    width: 48px;
    height: 48px;
    font-size: 20px;
    border: 2px solid #FFFFFF;
    background: #0066CC;
    color: #FFFFFF;
  }
  
  /* Categories Grid Mobile */
  .categories-grid {
    grid-template-columns: 1fr;
    gap: var(--space-3);
  }
  
  .category-card {
    padding: var(--space-4);
  }
  
  .category-card h3 {
    font-size: var(--text-lg);
  }
  
  .category-card p {
    font-size: var(--text-sm);
  }
  
  /* Search and Filter Mobile */
  .search-container {
    flex-direction: column;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
  }
  
  .search-input-group {
    width: 100%;
  }
  
  .search-input {
    width: 100%;
    padding: var(--space-3);
    font-size: var(--text-base);
    border: 1px solid #CCCCCC;
    background: #FFFFFF;
  }
  
  .search-btn {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-base);
    min-width: 80px;
  }
  
  .filter-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    justify-content: center;
  }
  
  .filter-btn {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    min-width: 80px;
    text-align: center;
  }
  
  /* Hero Section Mobile */
  .hero-section {
    padding: var(--space-4);
    margin-bottom: var(--space-4);
  }
  
  .hero-content h1 {
    font-size: var(--text-2xl);
    margin-bottom: var(--space-3);
  }
  
  .hero-content p {
    font-size: var(--text-base);
    margin-bottom: var(--space-4);
  }
  
  /* Footer Mobile */
  .footer-content {
    grid-template-columns: 1fr;
    gap: var(--space-4);
    padding: var(--space-4) var(--space-3) 0;
    text-align: center;
  }
  
  .footer-section h3,
  .footer-section h4 {
    margin-bottom: var(--space-2);
  }
  
  .footer-bottom {
    padding: var(--space-3);
    margin-top: var(--space-3);
  }
  
  /* Form Mobile Optimization */
  .form-layout {
    max-width: 100%;
    padding: 0 var(--space-3);
  }
  
  .form-input,
  .form-textarea,
  .form-select {
    padding: var(--space-3);
    font-size: var(--text-base);
  }
  
  .form-actions {
    flex-direction: column;
    gap: var(--space-3);
  }
  
  /* Button mobile styles handled in buttons.css */
  
  /* Mobile-Specific Utilities */
  .mobile-only {
    display: block;
  }
  
  .desktop-only {
    display: none;
  }
  
  .mobile-center {
    text-align: center;
  }
  
  .mobile-full-width {
    width: 100%;
  }
  
  /* Touch-Friendly Spacing */
  .touch-target {
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Tablet Styles (768px to 1023px) */
@media screen and (min-width: 768px) and (max-width: 1023px) {
  .container {
    max-width: 100%;
    padding: 0 var(--space-4);
  }
  
  /* Tablet Navigation */
  .nav-container {
    padding: 0 var(--space-4);
  }
  
  .mobile-menu-toggle {
    display: none;
  }
  
  .nav-menu {
    display: flex;
    position: static;
    background: transparent;
    border: none;
    flex-direction: row;
    gap: var(--space-3);
  }
  
  /* Tablet Game Grid */
  .games-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-4);
  }
  
  .game-thumbnail {
    height: 140px;
  }
  
  .game-tags {
    display: block; /* Show tags on tablet */
  }
  
  /* Tablet Categories */
  .categories-grid {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-4);
  }
  
  /* Tablet Search */
  .search-container {
    flex-direction: row;
    align-items: center;
    gap: var(--space-4);
  }
  
  .search-input-group {
    flex: 1;
    max-width: 400px;
  }
  
  .filter-buttons {
    justify-content: flex-start;
  }
  
  /* Tablet Footer */
  .footer-content {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-5);
    text-align: left;
  }
  
  /* Tablet-Specific Utilities */
  .tablet-hide {
    display: none;
  }
  
  .tablet-show {
    display: block;
  }
}

/* Desktop Styles (1024px and up) */
@media screen and (min-width: 1024px) {
  /* Desktop Game Grid */
  .games-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-4);
  }
  
  .game-thumbnail {
    height: 150px;
  }
  
  /* Desktop Categories */
  .categories-grid {
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: var(--space-5);
  }
  
  /* Desktop-Specific Utilities */
  .desktop-only {
    display: block;
  }
  
  .mobile-only {
    display: none;
  }
  
  .desktop-hide {
    display: none;
  }
}

/* Large Desktop Styles (1200px and up) */
@media screen and (min-width: 1200px) {
  .games-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: var(--space-5);
  }
  
  .game-thumbnail {
    height: 160px;
  }
}

/* Extra Small Mobile (320px and below) */
@media screen and (max-width: 320px) {
  .container {
    padding: 0 var(--space-2);
  }
  
  .games-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--space-2);
  }
  
  .game-card {
    padding: var(--space-2);
  }
  
  .game-thumbnail {
    height: 100px;
  }
  
  .game-info h3 {
    font-size: var(--text-sm);
  }
  
  .game-info p {
    font-size: var(--text-xs);
    -webkit-line-clamp: 1; /* Single line on very small screens */
  }
  
  .btn-play {
    padding: var(--space-2);
    font-size: var(--text-xs);
  }
  
  .hero-content h1 {
    font-size: var(--text-xl);
  }
  
  .hero-content p {
    font-size: var(--text-sm);
  }
}

/* Landscape Mobile Optimization */
@media screen and (max-height: 500px) and (orientation: landscape) {
  .hero-section {
    padding: var(--space-3);
  }
  
  .hero-content h1 {
    font-size: var(--text-xl);
    margin-bottom: var(--space-2);
  }
  
  .hero-content p {
    margin-bottom: var(--space-3);
  }
  
  .main-content {
    padding: var(--space-2) 0;
  }
  
  .games-grid {
    padding: var(--space-2) 0;
  }
}

/* High DPI / Retina Display Support */
@media screen and (-webkit-min-device-pixel-ratio: 2),
       screen and (min-resolution: 192dpi) {
  .game-thumbnail,
  .logo-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch devices */
  .game-card:hover {
    border-color: #CCCCCC;
    background-color: #FFFFFF;
  }
  
  .nav-link:hover {
    background: #E0E0E0;
    color: #333333;
  }
  
  /* Button hover styles handled in buttons.css */
  
  /* Always show game overlay on touch devices */
  .game-overlay {
    opacity: 0.8;
  }
  
  /* Larger touch targets */
  .btn,
  .nav-link,
  .filter-btn,
  .game-play-btn {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Touch-friendly spacing */
  .game-actions {
    gap: var(--space-3);
  }
  
  .filter-buttons {
    gap: var(--space-3);
  }
}

/* Accessibility Improvements for Mobile */
@media screen and (max-width: 767px) {
  /* Focus indicators for keyboard navigation */
  *:focus {
    outline: 3px solid #0066CC;
    outline-offset: 2px;
  }
  
  /* Skip link for mobile */
  .skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #0066CC;
    color: white;
    padding: 8px;
    text-decoration: none;
    z-index: 1000;
  }
  
  .skip-link:focus {
    top: 6px;
  }
  
  /* Screen reader improvements */
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  
  /* Mobile-specific ARIA labels */
  .mobile-menu-toggle[aria-expanded="true"] span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
  }
  
  .mobile-menu-toggle[aria-expanded="true"] span:nth-child(2) {
    opacity: 0;
  }
  
  .mobile-menu-toggle[aria-expanded="true"] span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -6px);
  }
}

/* Print Styles for Mobile */
@media print {
  .mobile-menu-toggle,
  .nav-menu,
  .user-area,
  .game-overlay,
  .btn-favorite {
    display: none !important;
  }
  
  .games-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--space-2) !important;
  }
  
  .game-card {
    break-inside: avoid;
    margin-bottom: var(--space-3) !important;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .mobile-menu-toggle span {
    transition: none;
  }
  
  .game-card,
  .btn,
  .nav-link {
    transition: none;
  }
  
  /* Disable any JavaScript animations on mobile */
  .loading-progress-bar {
    animation: none;
  }
}

/* Dark Mode Support (System Preference) */
@media (prefers-color-scheme: dark) and (max-width: 767px) {
  /* Keep the early 2000s light theme regardless of system preference */
  /* This maintains the authentic retro aesthetic */
  .nav-menu {
    background: #FFFFFF;
    border-color: #CCCCCC;
  }
  
  .nav-link {
    background: #FFFFFF;
    color: #333333;
  }
  
  .mobile-menu-toggle {
    background: #E0E0E0;
    border-color: #CCCCCC;
  }
}

/* Mobile-Specific Loading States */
@media screen and (max-width: 767px) {
  .loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    font-family: Arial, Helvetica, sans-serif;
    font-size: var(--text-base);
    color: #333333;
  }
  
  .loading-spinner {
    border: 3px solid #E0E0E0;
    border-top: 3px solid #0066CC;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin-right: var(--space-3);
  }
  
  @keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
  }
}

/* Mobile Performance Optimizations */
@media screen and (max-width: 767px) {
  /* Optimize images for mobile */
  .game-thumbnail {
    image-rendering: auto;
    image-rendering: optimizeSpeed;
  }
  
  /* Reduce complexity for better performance */
  .game-card {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  }
  
  /* Simplify borders for better rendering */
  .btn,
  .nav-link,
  .form-input {
    border-radius: 2px;
  }
}