/* MOBILE PERFORMANCE OPTIMIZATIONS - Add to assets/seo-pages.css */

/* ============================================
   PRIORITY 1: REDUCE RENDERING TIME ON MOBILE
   ============================================ */

@media (max-width: 768px) {
  /* Simplify fonts on mobile for faster rendering */
  body {
    font-size: 14px;
    -webkit-font-smoothing: auto; /* Faster text rendering on mobile Safari */
  }

  h1 {
    font-size: 24px;
    line-height: 1.3;
  }

  h2 {
    font-size: 18px;
    line-height: 1.4;
  }

  h3 {
    font-size: 16px;
  }

  /* Remove expensive shadows on mobile for faster rendering */
  .paper-card {
    box-shadow: none;
    border: 1px solid var(--border-color);
    margin-bottom: 12px;
  }

  .panel {
    box-shadow: none;
    border: 1px solid var(--border-color);
  }

  header {
    box-shadow: none;
    border-bottom: 1px solid var(--border-color);
  }

  /* Reduce grid complexity on mobile */
  .grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .grid.stats {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Hide extended paper info on mobile (show on hover/click instead) */
  .paper-card-meta > span:nth-child(n+3) {
    display: none;
  }

  /* Simplify buttons for mobile */
  .btn {
    padding: 10px 12px;
    font-size: 14px;
    border-radius: 4px;
  }

  /* Reduce padding for mobile to fit more content */
  .shell {
    padding: 16px 12px 32px;
  }

  /* Hide decorative elements on mobile */
  .brand-row {
    margin-bottom: 12px;
  }

  /* Reduce animation complexity on low-end devices */
  @media (prefers-reduced-motion: reduce) {
    * {
      animation: none !important;
      transition: none !important;
    }
  }
}

/* ============================================
   PRIORITY 2: LAZY LOADING STYLES
   ============================================ */

.paper-card {
  transition: opacity 0.2s ease;
}

.paper-card.loading {
  opacity: 0.7;
  pointer-events: none;
}

/* Skeleton loader for lazy-loaded content */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-light) 25%,
    #f0f0f0 50%,
    var(--bg-light) 75%
  );
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ============================================
   PRIORITY 3: REDUCE LAYOUT SHIFT
   ============================================ */

.paper-card {
  min-height: 100px; /* Reserve space to prevent layout shift */
}

.stat {
  min-height: 80px;
}

/* ============================================
   PRIORITY 4: OPTIMIZE FONT LOADING
   ============================================ */

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", sans-serif;
  /* Fallback to system fonts first, then load custom fonts */
}

body {
  font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Reduce web font weight on mobile (only load 600 instead of 500,600,700,800) */
@media (max-width: 768px) {
  body {
    font-weight: 400; /* Use lighter weight on mobile */
  }

  strong {
    font-weight: 600;
  }

  h1, h2, h3 {
    font-weight: 600; /* Don't load 700/800 on mobile */
  }
}

/* ============================================
   PRIORITY 5: REDUCE JAVASCRIPT EXECUTION TIME
   ============================================ */

/* Prevent layout shift during search */
#paperSearch {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 14px;
}

/* Optimize list rendering with will-change (use sparingly) */
@media (max-width: 768px) {
  .paper-list {
    will-change: contents; /* Let browser optimize rendering */
  }
}

/* ============================================
   PRIORITY 6: MOBILE-SPECIFIC IMPROVEMENTS
   ============================================ */

@media (max-width: 480px) {
  /* Extra small phones - further reduce complexity */
  .shell {
    padding: 12px 8px 24px;
  }

  .btn-row {
    flex-direction: column;
    gap: 8px;
  }

  .btn {
    padding: 12px 10px;
    font-size: 13px;
  }

  .nav-links {
    gap: 4px;
  }

  .nav-link {
    padding: 6px 10px;
    font-size: 12px;
  }

  .chips {
    gap: 6px;
  }

  .chip {
    padding: 4px 8px;
    font-size: 12px;
  }

  /* Stack stats vertically on extra small phones */
  .grid.stats {
    grid-template-columns: 1fr;
  }
}

/* ============================================
   NETWORK THROTTLING OPTIMIZATIONS
   ============================================ */

/* Show loading state for slower connections */
@media (max-width: 768px) and (prefers-color-scheme: light) {
  /* Reduce color complexity for slower rendering */
  .paper-card {
    color: #202124;
    background: #fff;
  }

  .panel {
    background: #fff;
  }
}

/* Optimize images for mobile (if any) */
img {
  max-width: 100%;
  height: auto;
  display: block;
}

@media (max-width: 768px) {
  img {
    /* Reduce image quality load for mobile */
    image-rendering: -webkit-optimize-contrast;
  }
}

/* ============================================
   PERFORMANCE METRICS OPTIMIZATION
   ============================================ */

/* Reduce Largest Contentful Paint (LCP) */
h1 {
  font-size: clamp(20px, 5vw, 32px); /* Scale smoothly, no reflow */
}

/* Improve Interaction to Next Paint (INP) */
button,
a {
  min-height: 44px; /* Larger touch targets on mobile */
  min-width: 44px;
}

@media (min-width: 769px) {
  button,
  a {
    min-height: auto;
    min-width: auto;
  }
}

/* Reduce Cumulative Layout Shift (CLS) */
.paper-list {
  display: grid;
  gap: 16px;
  /* Pre-allocate space to prevent jumps */
}

/* Load More button spacing */
#loadMore {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 12px;
  text-align: center;
}

#loadMore:disabled {
  opacity: 0.5;
  pointer-events: none;
  display: none;
}

/* Keep the redesigned exam hub professional on mobile too. */
@media (max-width: 768px) {
  .shell {
    width: min(100% - 24px, 1088px);
    padding: 16px 0 36px;
  }

  .panel {
    border-radius: 10px;
    border-color: #d9e1ec;
    background: #ffffff;
  }

  .paper-card {
    min-height: 0;
    margin-bottom: 0;
    border-color: #dce5f0;
    border-radius: 10px;
    background: #ffffff;
  }

  .btn {
    border-radius: 8px;
  }

  #paperSearch {
    min-height: 48px;
    padding: 0 16px;
    border-radius: 8px;
    border-color: #cfd9e7;
    font-size: 15px;
  }

  .paper-card-meta > span:nth-child(n+3) {
    display: inline-flex;
  }

  .question-card {
    min-height: 0;
    padding: 18px;
    border-color: #d9e4f2;
    border-radius: 12px;
    background: #ffffff;
  }

  .question-head {
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 1px solid #edf2f7;
  }

  .option-item {
    border-radius: 10px;
    border-color: #dbe4f0;
  }

  .option-item.correct {
    border-color: #8dd3ad;
    background: #f3fbf6;
  }

  .explanation-box {
    border-radius: 10px;
    background: #f7fbff;
  }
}
