/* Enhanced Mobile Optimizations */
/* Following MDN Mobile Web Development Best Practices */

/* Improved Touch Targets - 48x48px minimum as per WCAG guidelines */
button, 
a, 
input, 
textarea, 
select,
.cta-button,
.project-card,
.contact-card,
.feature-card,
.mobile-menu-toggle,
#theme-toggle {
  min-height: 48px;
  min-width: 48px;
  position: relative;
}

/* Enhanced touch feedback */
button:active,
.cta-button:active,
a:active,
.project-card:active {
  transform: scale(0.98);
  opacity: 0.8;
  transition: transform 0.1s ease, opacity 0.1s ease;
}

/* Better spacing between touch targets */
.nav-links li {
  margin: 8px 16px 8px 0;
}

.mobile-nav ul li a {
  padding: 16px 5%;
  min-height: 56px; /* Larger touch targets in mobile menu */
  display: flex;
  align-items: center;
}

/* Enhanced Mobile Navigation */
.mobile-menu-toggle {
  font-size: 1.5rem;
  padding: 12px;
  border: none;
  background: none;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: 4px;
  transition: background-color 0.3s ease;
}

.mobile-menu-toggle:hover,
.mobile-menu-toggle:focus {
  background-color: var(--button-hover-bg);
  outline: 2px solid var(--text-primary);
  outline-offset: 2px;
}

.mobile-nav {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--secondary-bg);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  transform: translateY(-100%);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.mobile-nav.show {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}

/* Better Mobile Typography Scaling */
html {
  font-size: 16px; /* Base font size to prevent iOS zoom */
}

.welcome-title {
  font-size: clamp(1.8rem, 6vw, 3rem);
  line-height: 1.2;
}

.welcome-subtitle {
  font-size: clamp(1rem, 3vw, 1.2rem);
  line-height: 1.4;
}

.projects-title {
  font-size: clamp(2rem, 5vw, 2.5rem);
  line-height: 1.1;
}

.about-title {
  font-size: clamp(1.4rem, 4vw, 2rem);
  line-height: 1.2;
}

/* Improved Mobile Responsive Breakpoints */
@media (max-width: 480px) {
  /* Extra small phones */
  .container,
  .welcome-container,
  .about-container,
  .contact-container,
  .projects-container {
    padding-left: 1rem;
    padding-right: 1rem;
  }
  
  .cta-buttons {
    flex-direction: column;
    gap: 1rem;
    width: 100%;
  }
  
  .cta-button {
    width: 100%;
    text-align: center;
  }
  
  .contact-grid {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
  
  .feature-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .projects-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
  
  .project-card-image {
    height: 180px;
  }
}

@media (max-width: 600px) {
  header {
    padding: 1rem 4%;
  }
  
  .mobile-nav ul li a {
    font-size: 0.9rem;
    padding: 14px 4%;
  }
  
  /* Improve form usability on mobile */
  .form-group input,
  .form-group textarea {
    font-size: 16px; /* Prevent iOS zoom */
    padding: 12px;
    border-radius: 6px;
  }
  
  .form-group textarea {
    min-height: 120px;
    resize: vertical;
  }
  
  .submit-button {
    padding: 14px;
    font-size: 1rem;
    border-radius: 6px;
  }
}

@media (max-width: 768px) {
  /* Standard mobile breakpoint */
  .desktop-nav {
    display: none;
  }
  
  .mobile-menu-toggle {
    display: block;
  }
  
  .header-controls {
    gap: 0.5rem;
  }
  
  #theme-toggle {
    padding: 8px 12px;
    font-size: 0.75rem;
  }
  
  /* Reduce section spacing on mobile */
  .about-section {
    margin-bottom: 2rem;
  }
  
  .projects-container,
  .about-container,
  .contact-container {
    padding-top: 2rem;
    padding-bottom: 2rem;
  }
  
  /* Better mobile chat interface */
  .chat-container {
    margin: 1rem;
    border-radius: 12px;
  }
  
  .model-selector {
    flex-direction: column;
    padding-right: 0;
    padding-bottom: 50px;
  }
  
  .model-button {
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px;
    font-size: 0.8rem;
  }
  
  .model-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 50px;
    border-left: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }
  
  #chat-messages {
    height: 300px;
    padding: 1rem;
  }
  
  #user-input {
    font-size: 16px; /* Prevent iOS zoom */
    padding: 12px;
  }
  
  #send-button {
    padding: 0 16px;
    font-size: 0.8rem;
  }
}

/* Landscape orientation optimizations */
@media (max-height: 500px) and (orientation: landscape) {
  .welcome-container {
    padding: 1rem 2rem;
  }
  
  .chat-container {
    max-height: 80vh;
  }
  
  #chat-messages {
    height: 200px;
  }
}

/* Large mobile devices and small tablets */
@media (min-width: 481px) and (max-width: 768px) {
  .projects-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
  }
  
  .feature-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .contact-grid {
    grid-template-columns: 1fr;
    gap: 2rem;
  }
}

/* Tablet optimizations */
@media (min-width: 769px) and (max-width: 1024px) {
  .projects-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 2rem;
  }
  
  .feature-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .contact-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  /* Ensure images look crisp on high DPI displays */
  .project-card-image {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
  }
}

/* iOS Safari specific fixes */
@supports (-webkit-appearance: none) {
  /* Fix the infamous iOS Safari 100vh issue */
  body {
    min-height: -webkit-fill-available;
  }
  
  .welcome-container,
  .about-container,
  .projects-container,
  .contact-container {
    min-height: -webkit-fill-available;
  }
  
  /* Fix iOS input styling */
  input, textarea, select {
    border-radius: 6px;
    -webkit-appearance: none;
  }
  
  /* Improve iOS scroll performance */
  .chat-messages {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
  }
}

/* Android Chrome specific optimizations */
@media screen and (max-width: 768px) {
  /* Improve text rendering on Android */
  body {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  
  /* Better button styling for Android */
  button, .cta-button {
    -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
    tap-highlight-color: rgba(255, 255, 255, 0.1);
  }
}

/* Accessibility improvements for mobile */
@media (max-width: 768px) {
  /* Larger focus indicators on mobile */
  button:focus,
  a:focus,
  input:focus,
  textarea:focus {
    outline: 3px solid var(--space-blue);
    outline-offset: 2px;
  }
  
  /* Better contrast for mobile viewing */
  .project-description,
  .about-content,
  .contact-text {
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1.6;
  }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  .mobile-nav {
    transition: none;
  }
  
  .project-card:hover,
  .cta-button:hover {
    transform: none;
  }
  
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Dark mode adjustments for mobile */
@media (max-width: 768px) {
  body.light-mode .mobile-nav {
    background: var(--secondary-bg);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  }
}

/* Better mobile form validation display */
.form-group {
  position: relative;
}

.form-group.error input,
.form-group.error textarea {
  border-color: var(--space-red);
  box-shadow: 0 0 5px rgba(204, 0, 0, 0.3);
}

.form-group.success input,
.form-group.success textarea {
  border-color: #00cc00;
  box-shadow: 0 0 5px rgba(0, 204, 0, 0.3);
}