/*
 * QPG Pro — Responsive Stylesheet v1.2.0
 * Mobile-first media queries
 * Breakpoints: XL 1100+, LG 900-1099, MD 768-899, SM 480-767, XS <480
 */

/* ============================================================
   TABLET (≤ 900px)
   ============================================================ */
@media (max-width: 900px) {
  .qpg-wrap { margin: 16px; padding: 14px; }

  .qpg-hero { padding: 22px 20px; gap: 14px; }
  .qpg-hero-text h1 { font-size: 18px; }
  .qpg-hero-text p  { font-size: 13px; }

  /* Shrink illustration a bit */
  .qpg-hero-illustration { width: 140px; height: 140px; }
  .qpg-hero-svg, .qpg-hero-img { width: 140px; height: 140px; }

  .qpg-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
  .qpg-card { padding: 16px; }
  .qpg-btn { min-width: 110px; padding: 9px 16px; font-size: 13px; }
}

/* ============================================================
   MOBILE LANDSCAPE (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
  .qpg-wrap { margin: 10px; padding: 12px; border-radius: 10px; }

  /* Topbar: keep hero + toggle in a row */
  .qpg-topbar { flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
  .qpg-hero { flex: 1; min-width: 0; }
  .qpg-theme-toggle { align-self: flex-start; width: 42px; height: 42px; font-size: 16px; margin-top: 2px; }

  /* Hero: stack illustration below text on small screens */
  .qpg-hero { flex-direction: column; align-items: flex-start; padding: 20px 16px; gap: 16px; }
  .qpg-hero-illustration { width: 100%; height: auto; justify-content: center; }
  .qpg-hero-svg, .qpg-hero-img { width: 130px; height: 130px; }

  /* Keep hero two-column if there's enough space */
  @supports (min-width: 480px) {
    /* override below for larger phones */
  }

  .qpg-card  { padding: 14px; margin-bottom: 10px; border-radius: 10px; }
  .qpg-card h3 { font-size: 14px; margin-bottom: 10px; padding-bottom: 8px; }

  .qpg-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .qpg-grid input, .qpg-grid select { padding: 10px 12px; font-size: 14px; }

  /* Add bar: horizontal scroll */
  .qpg-add-bar { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding: 12px; }
  .qpg-add-bar::-webkit-scrollbar { display: none; }
  .qpg-add-bar strong { white-space: nowrap; flex-shrink: 0; }
  .qpg-add { white-space: nowrap; flex-shrink: 0; padding: 9px 14px; font-size: 12.5px; }

  /* Question head: two rows */
  .qpg-q-head { flex-direction: column; align-items: flex-start; padding-bottom: 8px; }
  .qpg-q-del, .qpg-q-mv, .qpg-q-ai { padding: 6px 10px; font-size: 12px; }

  /* Toolbar: horizontal scroll */
  .qpg-toolbar { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .qpg-toolbar::-webkit-scrollbar { display: none; }
  .qpg-toolbar button, .qpg-toolbar select { flex-shrink: 0; min-height: 32px; }

  .qpg-match-grid { grid-template-columns: 1fr; gap: 10px; }

  /* Action bar: wrap buttons, equal size */
  .qpg-actions { flex-wrap: wrap; padding: 12px; gap: 8px; margin-top: 10px; }
  .qpg-btn { flex: 1 1 calc(50% - 4px); min-width: 110px; justify-content: center; padding: 11px 10px; font-size: 13px; }

  /* Paper preview */
  #qpg-preview-wrap { padding: 12px; margin-top: 14px; }
  .qpg-paper { width: 100%; padding: 24px 18px; font-size: 13px; }
  .qpg-paper.cols-2 .qpg-paper-questions { column-count: 1; }
  .qpg-paper-head h2 { font-size: 17px; }

  /* AI modal */
  .qpg-ai-modal { padding: 12px; align-items: flex-end; }
  .qpg-ai-box { border-radius: 16px 16px 10px 10px; padding: 20px 16px; max-height: 80vh; }
  .qpg-ai-box h3 { font-size: 16px; }
  .qpg-ai-box .qpg-ai-actions { flex-wrap: wrap; }
  .qpg-ai-box .qpg-btn { flex: 1; justify-content: center; }
}

/* ============================================================
   LARGE PHONE: hero stays two-column (480px–768px)
   ============================================================ */
@media (min-width: 480px) and (max-width: 768px) {
  .qpg-hero {
    flex-direction: row;
    align-items: center;
    padding: 20px 18px;
  }
  .qpg-hero-illustration {
    width: 120px;
    height: 120px;
    flex-shrink: 0;
  }
  .qpg-hero-svg, .qpg-hero-img { width: 120px; height: 120px; }
}

/* ============================================================
   SMALL MOBILE (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
  .qpg-wrap { margin: 6px; padding: 10px; border-radius: 8px; }

  /* Hero stacked on tiny screens */
  .qpg-hero { flex-direction: column; align-items: flex-start; padding: 16px 14px; gap: 12px; }
  .qpg-hero-text h1 { font-size: 16px; }
  .qpg-hero-text p  { font-size: 12px; }
  .qpg-hero-illustration { width: 100%; height: auto; align-items: center; justify-content: center; }
  .qpg-hero-svg, .qpg-hero-img { width: 100px; height: 100px; }

  .qpg-grid { grid-template-columns: 1fr; gap: 8px; }
  .qpg-grid label, .qpg-grid > div { font-size: 11px; }

  .qpg-card { padding: 12px; margin-bottom: 8px; }
  .qpg-card h3 { font-size: 13.5px; }

  /* Buttons: 2 per row */
  .qpg-actions { padding: 10px; gap: 6px; }
  .qpg-btn { flex: 1 1 calc(50% - 3px); padding: 12px 8px; font-size: 12.5px; }

  /* Paper */
  .qpg-paper { padding: 18px 12px; font-size: 12px; }

  /* AI modal: bottom sheet */
  .qpg-ai-modal { padding: 0; align-items: flex-end; }
  .qpg-ai-box { max-width: 100%; width: 100%; border-radius: 20px 20px 0 0; max-height: 90vh; padding: 20px 14px 24px; }

  .qpg-instr .qpg-bullet { display: none; }
}

/* ============================================================
   TOUCH OPTIMIZATIONS
   ============================================================ */
@media (hover: none) and (pointer: coarse) {
  .qpg-add { min-height: 44px; display: inline-flex; align-items: center; }
  .qpg-btn { min-height: 44px; }
  .qpg-q-del, .qpg-q-mv, .qpg-q-ai { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; }
  .qpg-x { width: 34px; height: 34px; }
  /* Suppress hover animations on touch */
  .qpg-q:hover::before        { opacity: 0; }
  .qpg-theme-toggle:hover     { transform: none; }
  .qpg-btn:hover              { transform: none; }
  .qpg-add:hover              { transform: none; }
  .qpg-btn-sm:hover           { transform: none; }
  .qpg-q-ai:hover             { transform: none; }
  .qpg-hero-svg               { animation: none; }
  .qpg-hero-img               { animation: none; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  .qpg-actions, .qpg-topbar, .qpg-card, .qpg-add-bar, .qpg-theme-toggle { display: none !important; }
  #qpg-preview-wrap { background: none !important; padding: 0 !important; box-shadow: none !important; }
  .qpg-paper { box-shadow: none !important; width: 100% !important; padding: 0 !important; }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  .qpg-wrap *, .qpg-wrap *::before, .qpg-wrap *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
