/* ========================================
   PHASE 1 WEEK 4: ENHANCED MOBILE OPTIMIZATION
   Modern responsive design with precise breakpoints
   ======================================== */

/* ========== BREAKPOINT SYSTEM ========== */
/* 
  Mobile (Portrait):  < 375px (Small phones)
  Mobile (Standard):  375px - 767px (Most phones)
  Tablet (Portrait):  768px - 1023px (Tablets)
  Desktop (Small):    1024px - 1279px (Laptops)
  Desktop (Large):    >= 1280px (Desktops)
*/

/* ========== SMALL MOBILE (< 375px) ========== */
@media (max-width: 374px) {
  /* Ultra-compact for small devices (iPhone SE, etc.) */
  
  header h1 {
    font-size: 1rem !important;
  }
  
  nav button {
    font-size: 0.6875rem !important;
    padding: 0.375rem 0.5rem !important;
  }
  
  .card {
    padding: 0.75rem !important;
  }
  
  h2 {
    font-size: 1.25rem !important;
  }
  
  /* Reduce spacing */
  .space-y-4 > * + * {
    margin-top: 0.5rem !important;
  }
}

/* ========== STANDARD MOBILE (375px - 767px) ========== */
/* Already covered by responsive.css base mobile styles */

/* ========== TOUCH ENHANCEMENTS ========== */
@media (max-width: 1023px) {
  
  /* ===== ENHANCED TOUCH TARGETS ===== */
  
  /* Primary actions - 48x48px (Material Design) */
  .btn-primary,
  .nav-tab,
  .quest-card button,
  .tool-card button {
    min-height: 48px !important;
    min-width: 48px !important;
  }
  
  /* Secondary actions - 44x44px (Apple HIG) */
  button {
    min-height: 44px !important;
  }
  
  /* Interactive cards - increase tap area */
  .quest-card,
  .tool-card,
  .user-card,
  .leaderboard-item {
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(59, 130, 246, 0.1);
  }
  
  /* Tap feedback */
  .quest-card:active,
  .tool-card:active,
  .user-card:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
  
  /* ===== IMPROVED SCROLLING ===== */
  
  /* Smooth momentum scrolling */
  .overflow-auto,
  .overflow-x-auto,
  .overflow-y-auto {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
  
  /* Scroll indicators */
  .overflow-x-auto {
    scroll-snap-type: x proximity;
  }
  
  .overflow-x-auto > * {
    scroll-snap-align: start;
  }
  
  /* ===== FORM IMPROVEMENTS ===== */
  
  /* Prevent zoom on focus (iOS) */
  input,
  select,
  textarea {
    font-size: 16px !important;
  }
  
  /* Larger checkboxes and radio buttons */
  input[type="checkbox"],
  input[type="radio"] {
    width: 24px !important;
    height: 24px !important;
    min-width: 24px !important;
    min-height: 24px !important;
  }
  
  /* Better date/time pickers on mobile */
  input[type="date"],
  input[type="time"],
  input[type="datetime-local"] {
    min-height: 44px !important;
  }
  
  /* ===== NAVIGATION IMPROVEMENTS ===== */
  
  /* Sticky navigation hint */
  nav {
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  }
  
  /* Scroll snap for horizontal nav */
  nav .container {
    scroll-snap-type: x mandatory;
  }
  
  nav button {
    scroll-snap-align: start;
  }
  
  /* Show scroll indicator for nav */
  nav::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 30px;
    background: linear-gradient(to left, rgba(15, 23, 42, 0.8), transparent);
    pointer-events: none;
  }
  
  /* ===== IMPROVED SPACING ===== */
  
  /* Breathing room for touch */
  .space-y-2 > * + * {
    margin-top: 0.75rem !important;
  }
  
  /* Card gaps for easy tapping */
  .grid {
    gap: 1rem !important;
  }
  
  /* ===== TEXT READABILITY ===== */
  
  /* Optimal line length for mobile (45-75 characters) */
  p, li {
    max-width: 65ch;
  }
  
  /* Improved line height for readability */
  p {
    line-height: 1.6 !important;
  }
  
  /* ===== PERFORMANCE OPTIMIZATIONS ===== */
  
  /* GPU acceleration for smoother animations */
  .animate-slide-in,
  .quest-card,
  .tool-card {
    will-change: transform;
    transform: translateZ(0);
  }
  
  /* Reduce motion for accessibility */
  @media (prefers-reduced-motion: reduce) {
    * {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
    }
  }
}

/* ========== TABLET ENHANCEMENTS (768px - 1023px) ========== */
@media (min-width: 768px) and (max-width: 1023px) {
  
  /* ===== OPTIMAL GRID LAYOUTS ===== */
  
  /* 2 columns for most content */
  .grid.grid-cols-1.md\:grid-cols-2 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* 3 columns become 2 on tablet */
  .grid.grid-cols-1.md\:grid-cols-3,
  .grid.grid-cols-1.lg\:grid-cols-3 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* Quest cards - 2 columns */
  .quest-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* ===== TYPOGRAPHY SCALING ===== */
  
  h1 {
    font-size: 2rem !important;
  }
  
  h2 {
    font-size: 1.75rem !important;
  }
  
  h3 {
    font-size: 1.25rem !important;
  }
  
  /* ===== SPACING ADJUSTMENTS ===== */
  
  .card {
    padding: 1.5rem !important;
  }
  
  main.container {
    padding: 1.5rem !important;
  }
}

/* ========== DESKTOP OPTIMIZATIONS (1024px+) ========== */
@media (min-width: 1024px) {
  
  /* ===== HOVER STATES (DESKTOP ONLY) ===== */
  
  .quest-card:hover,
  .tool-card:hover,
  .user-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease;
  }
  
  button:hover:not(:disabled) {
    transform: scale(1.02);
    transition: transform 0.1s ease;
  }
  
  /* ===== OPTIMAL LAYOUT ===== */
  
  /* 3 columns for content grids */
  .grid.grid-cols-1.lg\:grid-cols-3 {
    grid-template-columns: repeat(3, 1fr) !important;
  }
  
  /* Max width for readability */
  main.container {
    max-width: 1280px;
    margin: 0 auto;
  }
}

/* ========== LANDSCAPE MODE OPTIMIZATIONS ========== */
@media (max-width: 767px) and (orientation: landscape) {
  
  /* ===== SPACE-EFFICIENT LAYOUT ===== */
  
  /* Compact header */
  header {
    padding: 0.5rem !important;
  }
  
  header .container {
    flex-direction: row !important;
    align-items: center;
    gap: 0.5rem !important;
  }
  
  header h1 {
    font-size: 0.875rem !important;
    width: auto !important;
  }
  
  /* Side-by-side layout for cards */
  .grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  /* Reduce vertical spacing */
  .space-y-4 > * + * {
    margin-top: 0.5rem !important;
  }
  
  h2 {
    font-size: 1.25rem !important;
    margin-bottom: 0.5rem !important;
  }
  
  /* Compact navigation */
  nav .container {
    padding: 0.25rem !important;
  }
  
  nav button {
    padding: 0.25rem 0.5rem !important;
    font-size: 0.75rem !important;
  }
}

/* ========== ACCESSIBILITY ENHANCEMENTS ========== */

/* High contrast mode support */
@media (prefers-contrast: high) {
  .card {
    border: 2px solid currentColor !important;
  }
  
  button {
    border: 2px solid currentColor !important;
  }
}

/* Dark mode optimizations (already using dark theme) */
@media (prefers-color-scheme: dark) {
  /* Ensure proper contrast */
  body {
    color: #e5e7eb;
  }
  
  .card {
    background: rgba(31, 41, 55, 0.95) !important;
  }
}

/* ========== FOCUS INDICATORS ========== */

/* Visible focus for keyboard navigation */
*:focus-visible {
  outline: 2px solid #3b82f6 !important;
  outline-offset: 2px !important;
}

button:focus-visible,
a:focus-visible,
input:focus-visible {
  outline: 2px solid #3b82f6 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2) !important;
}

/* Remove outline for mouse users */
*:focus:not(:focus-visible) {
  outline: none !important;
}

/* ========== PRINT OPTIMIZATIONS ========== */
@media print {
  /* Hide navigation and controls */
  nav,
  header button,
  .modal,
  button:not(.print-show) {
    display: none !important;
  }
  
  /* Optimize layout for print */
  main {
    padding: 0 !important;
  }
  
  .card {
    break-inside: avoid;
    border: 1px solid #000 !important;
    margin-bottom: 1rem;
  }
  
  /* Black text on white background */
  * {
    background: white !important;
    color: black !important;
  }
}

/* ========== LOADING STATES ========== */

/* Skeleton loading for better perceived performance */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.1) 25%,
    rgba(255, 255, 255, 0.2) 50%,
    rgba(255, 255, 255, 0.1) 75%
  );
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ========== UTILITY CLASSES ========== */

/* Mobile-specific utilities */
@media (max-width: 767px) {
  .mobile-hidden {
    display: none !important;
  }
  
  .mobile-full-width {
    width: 100% !important;
  }
  
  .mobile-text-center {
    text-align: center !important;
  }
  
  .mobile-stack {
    flex-direction: column !important;
  }
}

/* Tablet-specific utilities */
@media (min-width: 768px) and (max-width: 1023px) {
  .tablet-hidden {
    display: none !important;
  }
  
  .tablet-grid-2 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* Desktop-specific utilities */
@media (min-width: 1024px) {
  .desktop-hidden {
    display: none !important;
  }
  
  .desktop-grid-3 {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}
