/**
 * LUMAVINE.AI - RESPONSIVE DESIGN FIXES
 * Comprehensive responsive design improvements across all breakpoints
 * Breakpoints: 480px (xs), 640px (sm), 768px (md), 1024px (lg), 1280px (xl), 1536px (2xl)
 */

/* =====================================================
   MOBILE FIRST BASE STYLES
   ===================================================== */

/* Ensure touch targets are minimum 44x44px */
button,
a[role="button"],
input[type="button"],
input[type="submit"],
.btn,
.clickable {
  min-height: 44px;
  min-width: 44px;
  padding: 12px 16px;
}

/* Prevent horizontal scroll */
html,
body {
  overflow-x: hidden;
  max-width: 100%;
}

/* Improve tap target spacing on mobile */
@media (max-width: 768px) {
  button + button,
  .btn + .btn,
  a + a {
    margin-left: 12px;
  }
}

/* =====================================================
   EXTRA SMALL DEVICES (320px - 479px)
   ===================================================== */

@media (max-width: 479px) {
  /* Typography scaling */
  h1,
  .text-6xl {
    font-size: 2rem !important;
    line-height: 1.2;
  }

  h2,
  .text-5xl {
    font-size: 1.75rem !important;
    line-height: 1.2;
  }

  h3,
  .text-4xl {
    font-size: 1.5rem !important;
    line-height: 1.3;
  }

  /* Container padding */
  .container,
  .section {
    padding-left: 16px;
    padding-right: 16px;
  }

  /* Button sizing */
  button,
  .btn {
    font-size: 14px;
    padding: 10px 14px;
  }

  /* Grid layouts */
  .grid,
  [class*="grid-cols"] {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* Language switcher */
  .language-switcher-widget {
    bottom: 70px;
    right: 12px;
  }

  .language-switcher-dropdown {
    width: calc(100vw - 24px);
    max-width: 300px;
  }

  /* Modal sizing */
  .modal-content {
    width: calc(100vw - 24px);
    margin: 12px;
    border-radius: 12px;
  }
}

/* =====================================================
   SMALL DEVICES (480px - 639px)
   ===================================================== */

@media (min-width: 480px) and (max-width: 639px) {
  /* Two column layouts where appropriate */
  .grid-auto-fit {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Container padding */
  .container {
    padding-left: 20px;
    padding-right: 20px;
  }
}

/* =====================================================
   MEDIUM DEVICES - TABLETS (640px - 767px)
   ===================================================== */

@media (min-width: 640px) and (max-width: 767px) {
  /* Navigation */
  .nav-links {
    gap: 20px;
  }

  /* Card grid */
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
  }

  /* Typography */
  h1 {
    font-size: 3rem;
  }

  h2 {
    font-size: 2.25rem;
  }
}

/* =====================================================
   MEDIUM DEVICES - TABLETS LANDSCAPE (768px - 1023px)
   ===================================================== */

@media (min-width: 768px) and (max-width: 1023px) {
  /* Three column layouts */
  .grid-3-col {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Side panels */
  .sidebar {
    width: 240px;
  }

  /* Modal sizing */
  .modal-content {
    max-width: 600px;
  }
}

/* =====================================================
   LARGE DEVICES - DESKTOP (1024px - 1279px)
   ===================================================== */

@media (min-width: 1024px) and (max-width: 1279px) {
  .container {
    max-width: 960px;
  }

  /* Four column layouts */
  .grid-4-col {
    grid-template-columns: repeat(4, 1fr);
  }

  /* Navigation */
  .nav-links {
    gap: 32px;
  }
}

/* =====================================================
   EXTRA LARGE DEVICES (1280px+)
   ===================================================== */

@media (min-width: 1280px) {
  .container {
    max-width: 1200px;
    margin: 0 auto;
  }

  /* Full width sections */
  .section-full {
    width: 100%;
    max-width: 1536px;
    margin: 0 auto;
  }
}

/* =====================================================
   GAME-SPECIFIC RESPONSIVE FIXES
   ===================================================== */

/* Game container adjustments */
@media (max-width: 900px) {
  .game-container {
    flex-direction: column;
    align-items: center;
    padding: 10px;
  }

  .side-panel {
    width: 100%;
    max-width: 550px;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .side-panel .panel {
    flex: 1;
    min-width: 140px;
  }

  /* Game canvas */
  #gameCanvas,
  canvas {
    max-width: 100%;
    height: auto;
  }
}

/* Mobile game controls */
@media (max-width: 768px) {
  .mobile-controls {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 15px;
    background: rgba(0, 0, 0, 0.8);
    z-index: 200;
  }

  body {
    padding-bottom: 120px;
  }

  /* Game text scaling */
  .logo {
    font-size: 2rem;
    letter-spacing: 6px;
  }

  .score-display {
    font-size: 2rem;
  }
}

/* =====================================================
   ORIENTATION-SPECIFIC STYLES
   ===================================================== */

@media (orientation: landscape) and (max-height: 600px) {
  /* Reduce vertical padding in landscape mode */
  .section {
    padding-top: 40px;
    padding-bottom: 40px;
  }

  /* Adjust modals */
  .modal-content {
    max-height: 90vh;
    overflow-y: auto;
  }
}

/* =====================================================
   LAYOUT STABILITY (PREVENT CLS)
   ===================================================== */

/* Reserve space for images */
img[width][height] {
  height: auto;
}

img {
  max-width: 100%;
  height: auto;
}

/* Skeleton loaders match final dimensions */
.skeleton {
  min-height: 200px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.05) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

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

/* =====================================================
   ACCESSIBILITY - FOCUS INDICATORS
   ===================================================== */

@media (max-width: 768px) {
  /* Larger focus indicators on touch devices */
  *:focus-visible {
    outline-width: 3px;
    outline-offset: 3px;
  }
}

/* =====================================================
   PRINT STYLES
   ===================================================== */

@media print {
  /* Hide interactive elements */
  .language-switcher-widget,
  button,
  .mobile-controls,
  nav,
  .skip-link {
    display: none !important;
  }

  /* Ensure content is visible */
  * {
    background: white !important;
    color: black !important;
  }

  /* Page breaks */
  h1,
  h2,
  h3 {
    page-break-after: avoid;
  }

  .section {
    page-break-inside: avoid;
  }
}

/* =====================================================
   FLEXIBLE CONTAINERS
   ===================================================== */

.flex-mobile-col {
  display: flex;
}

@media (max-width: 768px) {
  .flex-mobile-col {
    flex-direction: column;
  }
}

.flex-tablet-col {
  display: flex;
}

@media (max-width: 1024px) {
  .flex-tablet-col {
    flex-direction: column;
  }
}

/* =====================================================
   UTILITIES
   ===================================================== */

/* Hide on specific breakpoints */
.hide-mobile {
  display: block;
}

@media (max-width: 768px) {
  .hide-mobile {
    display: none !important;
  }
}

.hide-tablet {
  display: block;
}

@media (max-width: 1024px) {
  .hide-tablet {
    display: none !important;
  }
}

.hide-desktop {
  display: none;
}

@media (max-width: 1024px) {
  .hide-desktop {
    display: block !important;
  }
}

/* Show only on specific breakpoints */
.show-mobile {
  display: none;
}

@media (max-width: 768px) {
  .show-mobile {
    display: block !important;
  }
}

/* =====================================================
   PERFORMANCE OPTIMIZATIONS
   ===================================================== */

@media (max-width: 768px) {
  /* Reduce animations on mobile for performance */
  @media (prefers-reduced-motion: no-preference) {
    * {
      animation-duration: 0.3s !important;
    }
  }

  /* Disable parallax effects on mobile */
  [data-parallax] {
    transform: none !important;
  }
}

/* =====================================================
   MOBILE HEADER & NAVIGATION FIXES
   ===================================================== */

/* Make header navigation wrap on smaller screens */
@media (max-width: 768px) {
  .lumacore-header {
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 16px !important;
  }

  .logo-section {
    flex: 1;
    min-width: 0;
  }

  .header-actions {
    flex-wrap: wrap;
    gap: 8px !important;
    justify-content: flex-end;
  }

  /* Make nav buttons smaller on mobile */
  .header-nav-btn {
    padding: 8px 12px !important;
    font-size: 0.8rem !important;
    margin-right: 0 !important;
  }
}

/* Extra small screens - stack navigation vertically */
@media (max-width: 480px) {
  .lumacore-header {
    padding: 10px 12px !important;
  }

  .header-actions {
    width: 100%;
    justify-content: center;
    order: 3;
    margin-top: 8px;
  }

  .header-nav-btn {
    flex: 1;
    text-align: center;
    min-width: 0;
    padding: 10px 8px !important;
    font-size: 0.75rem !important;
  }

  /* Ensure hamburger menu button is visible and accessible */
  .mobile-menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
  }

  .logo-text {
    display: none;
  }

  .logo-section {
    gap: 8px;
  }
}

/* =====================================================
   MOBILE CHAT INPUT VISIBILITY
   ===================================================== */

@media (max-width: 768px) {
  /* Ensure input area stays visible at bottom */
  .input-area {
    position: sticky;
    bottom: 0;
    z-index: 100;
    background: var(--surface-mid, #1A1A24);
    padding: 12px 16px !important;
  }

  .input-wrapper {
    padding: 10px 12px;
  }

  .message-input {
    font-size: 16px !important; /* Prevents iOS zoom on focus */
    min-height: 44px;
  }

  /* Make input actions accessible on touch */
  .input-actions {
    gap: 4px;
  }

  .input-action-btn {
    min-width: 40px;
    min-height: 40px;
  }
}

/* =====================================================
   MOBILE SIDEBAR & MENU FIXES
   ===================================================== */

@media (max-width: 767px) {
  /* Ensure sidebar opens properly when toggled */
  .lumacore-sidebar.open,
  .lumavine-sidebar.mobile-open {
    transform: translateX(0) !important;
    display: flex !important;
  }

  /* Make sidebar overlay cover full screen */
  .sidebar-overlay.active {
    position: fixed;
    inset: 0;
    z-index: 999;
    display: block !important;
  }
}
