/* ==========================================================================
   responsive.css — Afaq Platform Cross-Device Layout & Touch Optimization
   Breakpoints: Mobile (<= 640px), Tablet (641px - 1023px), Desktop (>= 1024px)
   ========================================================================== */

/* 1. Global Box Sizing & Fluid Overflow Protection */
*, *::before, *::after {
  box-sizing: border-box;
}

#main-content {
  min-width: 0;
  width: 100%;
}

#main-content :where(h1, h2, h3, h4, h5, h6, p, label, dd, dt, a, span) {
  overflow-wrap: anywhere;
  word-break: break-word;
}

#main-content :where(input, select, textarea, fieldset, button) {
  min-width: 0;
  max-width: 100%;
}

#main-content :where(.grid, .flex) > * {
  min-width: 0;
}

img, video, svg, canvas, iframe {
  max-width: 100%;
  height: auto;
}

/* 2. Responsive Tables & Overflow Handling */
#main-content .overflow-x-auto,
.table-responsive-wrapper {
  max-width: 100%;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

#main-content .overflow-x-auto:focus-visible,
.table-responsive-wrapper:focus-visible {
  outline: 3px solid #0D9A9B;
  outline-offset: 2px;
}

header form {
  min-width: 0;
}

.activity-layout > *,
.activity-stack,
.activity-panel,
.game-card {
  min-width: 0;
}

.game-options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.game-option {
  overflow-wrap: anywhere;
  min-width: 0;
}

/* 3. Desktop Ergonomics (>= 1024px) */
@media (min-width: 1024px) {
  #sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    height: 100dvh;
    flex-shrink: 0;
  }
}

/* 4. Tablet Landscape & Portrait (641px - 1023px) */
@media (min-width: 641px) and (max-width: 1023px) {
  .grid-cols-4,
  .grid-cols-5,
  .grid-cols-6 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .grid-cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  #main-content {
    padding: 1.25rem;
  }

  /* Activity layout stacks on tablets if space is tight */
  .activity-layout {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }
}

/* 5. Mobile Ergonomics (<= 640px) */
@media (max-width: 640px) {
  /* Prevent iOS Safari auto-zoom on input focus */
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea,
  input.nu-field,
  .field {
    font-size: 16px !important;
  }

  /* Touch Target Standard: 44px minimum touch height */
  .btn,
  button:not(.act):not(.toast-close-btn),
  a.btn {
    white-space: normal;
    min-height: 44px;
    max-width: 100%;
  }

  .act {
    width: 44px;
    height: 44px;
  }

  #menu-btn,
  #sidebar-close,
  header a[title] {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Responsive Grid Adjustments for Mobile */
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4,
  .grid-cols-5,
  .grid-cols-6 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  /* Narrow mobile: single column when needed */
  @media (max-width: 380px) {
    .grid-cols-2 {
      grid-template-columns: minmax(0, 1fr);
    }
  }

  /* Page title and actions header wrapping */
  #main-content > div.flex.flex-wrap.items-start.justify-between {
    flex-direction: column;
    gap: 1rem;
  }

  #main-content > div.flex.flex-wrap.items-start.justify-between > div.flex {
    width: 100%;
    justify-content: flex-start;
  }

  #main-content > div.flex.flex-wrap.items-start.justify-between > div.flex > * {
    flex: 1 1 auto;
  }

  /* Activity & Game elements */
  .activity-panel,
  .game-card {
    padding: 16px;
    border-radius: 14px;
  }

  .activity-hero {
    padding: 18px;
    border-radius: 18px;
  }

  .game-options {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 8px;
  }

  .activity-title {
    overflow-wrap: anywhere;
    font-size: 1.35rem;
  }

  /* Login Card Responsiveness */
  .auth-card {
    border-radius: 16px;
    margin: 1rem 0;
  }

  .auth-card .grid {
    grid-template-columns: 1fr;
  }

  .auth-art {
    display: none; /* Hide visual art banner on mobile to keep login fast and centered */
  }

  /* Mobile sidebar drawer */
  #sidebar {
    max-width: min(84vw, 300px);
    height: 100vh;
    height: 100dvh;
    box-shadow: -8px 0 24px rgba(7, 52, 90, 0.25);
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* Smooth backdrop blur when drawer is open */
  #overlay:not(.hidden) {
    display: block;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  /* Mobile header padding */
  header.h-\[68px\] {
    padding-inline: 0.75rem;
  }

  /* Mobile Stepper in Lessons */
  .lesson-steps {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .lesson-steps a {
    padding: 10px 14px;
  }
}

/* 6. Public Footer Grid */
.footer-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px 16px;
  padding: 28px 20px;
}

.footer-grid > * {
  min-width: 0;
}

.footer-brand {
  grid-column: 1 / -1;
  padding-bottom: 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.site-footer p,
.site-footer a {
  overflow-wrap: anywhere;
}

.footer-brand > p {
  max-width: 38rem;
  line-height: 1.9;
}

.footer-links a {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 0;
  font-size: 14px;
  line-height: 1.6;
}

.footer-links a:focus-visible {
  outline: 2px solid #FDB833;
  outline-offset: 3px;
  border-radius: 4px;
}

.footer-grid h3 {
  margin-bottom: 8px;
}

@media (min-width: 768px) {
  .footer-grid {
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 40px;
    padding: 48px 24px;
  }

  .footer-brand {
    grid-column: auto;
    padding-bottom: 0;
    border-bottom: 0;
  }

  .footer-grid h3 {
    margin-bottom: 16px;
  }
}

/* 7. Print Responsiveness */
@media print {
  #sidebar,
  #overlay,
  #sidebar-close {
    display: none !important;
  }

  .overflow-x-auto {
    overflow: visible !important;
  }
}
