/* === COMPREHENSIVE MOBILE & TABLET RESPONSIVENESS === */

/* --- Base Mobile Optimizations --- */
* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* --- DESKTOP NAVIGATION STYLES --- */
@media (min-width: 769px) {
  .mobile-menu-btn {
    display: none !important;
  }
  
  .mobile-nav {
    display: none !important;
  }
  
  .desktop-nav {
    display: flex !important;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
  }
  
  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
  }
  
  .header-btn {
    white-space: nowrap;
    flex-shrink: 0;
  }
}

/* --- TABLET STYLES (768px - 1024px) --- */
@media (max-width: 1024px) and (min-width: 769px) {
  .header, .game-header {
    padding: 10px 20px;
    min-height: 70px;
  }
  
  .header-btn {
    font-size: 0.9rem;
    padding: 6px 12px;
  }
  
  .games-grid, .leaderboard-grid {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
    padding: 0 20px;
  }
  
  .hero {
    padding: 60px 30px;
  }
  
  .features-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
  }
}

/* --- MOBILE STYLES (up to 768px) --- */
@media (max-width: 768px) {
  body {
    padding: 0;
    margin: 0;
    overflow-x: hidden;
  }
  
  /* Fixed Header for Mobile */
  .header, .game-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    min-height: 60px;
    padding: 8px 15px;
    margin: 0;
    border-radius: 0;
    z-index: 1001;
    backdrop-filter: blur(20px);
    background: rgba(10, 10, 35, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  
  /* Add top padding to body to account for fixed header */
  body {
    padding-top: 70px;
  }
  
  /* Logo and Brand Adjustments */
  .logo-circle {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
  }
  
  .brand {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
  }
  
  .brand img {
    width: 35px;
    height: 35px;
  }
  
  .brand span {
    font-size: 1rem;
    font-weight: 600;
  }
  
  /* Hide main navigation on mobile, show hamburger instead */
  .header nav {
    display: none;
  }
  
  /* Show mobile menu button */
  .header .mobile-menu-btn {
    display: flex;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-size: 1.2rem;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
  }
  
  .header .mobile-menu-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
  }
  
  /* Mobile dropdown menu */
  .header .mobile-nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(10, 10, 35, 0.98);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: none;
    flex-direction: column;
    padding: 10px 0;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  }
  
  .header .mobile-nav.show {
    display: flex;
  }
  
  .header .mobile-nav .header-btn {
    width: 100%;
    text-align: left;
    padding: 12px 20px;
    margin: 0;
    background: none;
    border: none;
    color: white;
    font-size: 1rem;
    border-radius: 0;
    transition: background 0.3s ease;
  }
  
  .header .mobile-nav .header-btn:hover {
    background: rgba(255, 255, 255, 0.1);
  }
  
  /* Game Header Menu Button */
  .game-header .menu-btn {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
  }
  
  .game-header .menu-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
  }
  
  /* Game Header Dropdown - Fix transparency issue */
  .game-header .menu-dropdown {
    position: absolute;
    top: 100%;
    right: 15px;
    background: rgba(10, 10, 35, 0.98) !important;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    z-index: 1002;
    min-width: 200px;
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: none;
  }
  
  .game-header .menu-dropdown.show {
    display: block;
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  
  .game-header .menu-dropdown button {
    width: 100%;
    background: none !important;
    border: none;
    color: white !important;
    padding: 14px 18px;
    text-align: left;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
  }
  
  .game-header .menu-dropdown button::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
  }
  
  .game-header .menu-dropdown button:hover::before {
    width: 4px;
  }
  
  .game-header .menu-dropdown button:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    padding-left: 22px;
  }
  
  /* Hero Section Mobile */
  .hero {
    padding: 30px 15px;
    margin: 10px;
    border-radius: 12px;
  }
  
  .hero-content {
    grid-template-columns: 1fr;
    gap: 30px;
    text-align: center;
  }
  
  .hero h1, .hero-text h1 {
    font-size: 1.8rem;
    line-height: 1.3;
    margin-bottom: 16px;
  }
  
  .hero p, .hero-text p {
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 24px;
  }
  
  .hero-buttons {
    flex-direction: column;
    gap: 12px;
    align-items: center;
  }
  
  .play-btn, .stats-btn {
    width: 100%;
    max-width: 280px;
    padding: 14px 24px;
    font-size: 1rem;
    justify-content: center;
  }
  
  /* Floating Icons - Hide on Mobile */
  .hero-visual, .floating-icons {
    display: none;
  }
  
  /* Games and Leaderboard Grids */
  .games-grid, .leaderboard-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 0 15px;
    margin-bottom: 20px;
  }
  
  .game-tile, .leaderboard-tile {
    padding: 20px 16px;
    min-height: 200px;
    margin: 0;
  }
  
  .game-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
  }
  
  .logo-icon {
    font-size: 2.5rem;
  }
  
  .game-name {
    font-size: 1.1rem;
    margin-bottom: 12px;
  }
  
  .game-description {
    font-size: 0.9rem;
    line-height: 1.4;
  }
  
  /* Features Section */
  .features {
    padding: 40px 15px;
  }
  
  .features h2 {
    font-size: 1.8rem;
    margin-bottom: 30px;
  }
  
  .features-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
  
  .feature-card {
    padding: 24px 20px;
    text-align: center;
  }
  
  .feature-icon {
    font-size: 2.5rem;
    margin-bottom: 16px;
  }
  
  /* About Section */
  .about {
    padding: 40px 15px;
  }
  
  .about h2 {
    font-size: 1.8rem;
    margin-bottom: 20px;
  }
  
  .about p {
    font-size: 1rem;
    line-height: 1.6;
  }
  
  /* Footer */
  footer {
    padding: 20px 15px;
    font-size: 0.9rem;
  }
}

/* --- GAME-SPECIFIC MOBILE STYLES --- */
@media (max-width: 768px) {
  /* Game Main Container */
  .game-main, .games-container, .leaderboard-container {
    padding: 15px 10px;
    margin-top: 0;
  }
  
  /* Game Info and Stats */
  .game-info {
    margin-bottom: 20px;
    padding: 15px;
    border-radius: 12px;
  }
  
  .stats {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: space-around;
  }
  
  .stat {
    flex: 1;
    min-width: 80px;
    max-width: 120px;
    padding: 12px 8px;
    text-align: center;
  }
  
  .stat-label {
    font-size: 0.8rem;
    margin-bottom: 4px;
  }
  
  .stat-value {
    font-size: 1.2rem;
    font-weight: bold;
  }
  
  /* Canvas and Game Areas */
  canvas {
    max-width: 100%;
    max-height: 60vh;
    width: auto;
    height: auto;
    border-radius: 8px;
  }
  
  .game-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px 0;
  }
  
  /* Game Controls */
  .game-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    padding: 15px;
  }
  
  .control-btn {
    padding: 12px 20px;
    font-size: 0.9rem;
    min-width: 120px;
    touch-action: manipulation;
  }
  
  /* Mobile Controls */
  .mobile-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 20px 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    margin: 15px 10px;
  }
  
  .control-row {
    display: flex;
    gap: 12px;
    justify-content: center;
  }
  
  .direction-btn {
    width: 50px;
    height: 50px;
    font-size: 1.2rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
  }
  
  .direction-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.2);
  }
  
  /* Mode Selection Screens */
  .mode-selection, .difficulty-selection {
    padding: 20px 15px;
    min-height: calc(100vh - 70px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  
  .mode-container, .difficulty-container {
    width: 100%;
    max-width: 400px;
    text-align: center;
  }
  
  .mode-container h2, .difficulty-container h2 {
    font-size: 1.8rem;
    margin-bottom: 30px;
  }
  
  .mode-buttons, .difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
  }
  
  .mode-btn, .difficulty-btn {
    padding: 16px 20px;
    font-size: 1.1rem;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    touch-action: manipulation;
    width: 100%;
  }
  
  .mode-btn:active, .difficulty-btn:active {
    transform: scale(0.98);
  }
  
  /* Modals */
  .modal-overlay {
    padding: 20px;
  }
  
  .modal-content {
    width: 95%;
    max-width: 400px;
    max-height: 80vh;
    padding: 20px;
    border-radius: 12px;
    overflow-y: auto;
  }
  
  .modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 20px;
  }
  
  .modal-buttons button {
    padding: 12px 20px;
    font-size: 1rem;
    border-radius: 8px;
    width: 100%;
  }
}

/* --- SMALL MOBILE STYLES (up to 480px) --- */
@media (max-width: 480px) {
  .header, .game-header {
    padding: 6px 12px;
    min-height: 55px;
  }
  
  body {
    padding-top: 65px;
  }
  
  .logo-circle {
    width: 35px;
    height: 35px;
  }
  
  .brand img {
    width: 30px;
    height: 30px;
  }
  
  .brand span {
    font-size: 0.9rem;
  }
  
  .menu-btn {
    width: 35px;
    height: 35px;
    font-size: 1.1rem;
  }
  
  .hero {
    padding: 20px 12px;
    margin: 8px;
  }
  
  .hero h1 {
    font-size: 1.5rem;
  }
  
  .hero p {
    font-size: 0.9rem;
  }
  
  .games-grid, .leaderboard-grid {
    padding: 0 12px;
    gap: 12px;
  }
  
  .game-tile, .leaderboard-tile {
    padding: 16px 12px;
    min-height: 180px;
  }
  
  .game-logo {
    width: 70px;
    height: 70px;
    margin-bottom: 12px;
  }
  
  .logo-icon {
    font-size: 2rem;
  }
  
  .game-name {
    font-size: 1rem;
  }
  
  .game-description {
    font-size: 0.85rem;
  }
  
  .features, .about {
    padding: 30px 12px;
  }
  
  .stat {
    min-width: 70px;
    padding: 10px 6px;
  }
  
  .stat-value {
    font-size: 1.1rem;
  }
  
  .direction-btn {
    width: 45px;
    height: 45px;
    font-size: 1.1rem;
  }
  
  .mobile-controls {
    margin: 10px 8px;
    padding: 15px 10px;
  }
}

/* --- LANDSCAPE ORIENTATION FIXES --- */
@media (max-width: 768px) and (orientation: landscape) {
  .header, .game-header {
    min-height: 50px;
    padding: 5px 15px;
  }
  
  body {
    padding-top: 60px;
  }
  
  .hero {
    padding: 20px 15px;
  }
  
  .mode-selection, .difficulty-selection {
    min-height: calc(100vh - 60px);
    padding: 15px;
  }
  
  .mode-buttons, .difficulty-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
  }
  
  .mode-btn, .difficulty-btn {
    flex: 1;
    min-width: 140px;
  }
}

/* --- TOUCH IMPROVEMENTS --- */
@media (hover: none) and (pointer: coarse) {
  .game-tile:hover, .leaderboard-tile:hover {
    transform: none;
  }
  
  .game-tile:active, .leaderboard-tile:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
  
  button:hover {
    transform: none;
  }
  
  button:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
  }
}

/* --- ACCESSIBILITY IMPROVEMENTS --- */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- HIGH DPI DISPLAYS --- */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .logo-circle img, .brand img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}