/* v15-mobile-polish — 2026-05-11
 *
 * Final polish pass from 5 specialized audit agents. Fixes:
 *
 *   1. Theme toggle touch target regression (v13 set 40px, restore 44px)
 *   2. iOS zoom prevention (inputs < 16px trigger auto-zoom)
 *   3. Touch targets < 44px across interactive elements
 *   4. Library flagship-card excessive padding
 *   5. Container padding reduction on mobile
 *   6. Shop filter row horizontal scroll
 *   7. Kit page cover image overflow
 *   8. Desk tooltip white-space overflow
 *   9. Spiraling badge hide on virtual keyboard
 *  10. Misc overflow and alignment fixes
 *
 * ~3KB. Loaded last after v14.
 */

/* ═══════════════════════════════════════════════════════════════════
   1. THEME TOGGLE — restore 44px (v13 regressed to 40px)
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 760px) {
  .dr-theme-toggle {
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 8px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   2. iOS ZOOM PREVENTION — all inputs/selects/textareas ≥ 16px
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 760px) {
  input,
  select,
  textarea,
  .squeeze-email,
  .shop-search,
  .ai-tool-input,
  .today-input,
  [type="email"],
  [type="text"],
  [type="search"] {
    font-size: 16px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   3. TOUCH TARGETS — 44px minimum (WCAG 2.5.5)
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 760px) {
  /* Decode copy button */
  .decode-copy,
  .decode-copy-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 10px !important;
  }

  /* Timer control buttons */
  .fs-timer-btn,
  .timer-btn,
  .fs-timer-actions button {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 10px 14px !important;
  }

  /* Time estimation game buttons */
  .time-game-btn,
  .game-btn,
  .estimation-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 10px 16px !important;
  }

  /* Spiraling audio/control buttons */
  .spiraling-btn,
  .spiraling-audio-btn,
  .spiral-control {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  /* Crisis resource links — critical for accessibility */
  .crisis-link,
  .crisis-resource a,
  .crisis-resources a {
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center !important;
    padding: 8px 4px !important;
  }

  /* Today form button */
  .today-submit,
  .today-form button,
  .today-btn {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 10px 18px !important;
  }

  /* Desk skip-nav links */
  .desk-skip-nav a,
  .skip-nav a,
  .skip-link {
    min-height: 44px !important;
    padding: 10px 16px !important;
  }

  /* AI tool submit buttons */
  .ai-tool-submit,
  .ai-submit,
  .tool-submit {
    min-width: 44px !important;
    min-height: 44px !important;
    padding: 10px 18px !important;
  }

  /* Generic small buttons that might be under 44px */
  .btn-sm,
  .btn-xs,
  .btn-icon {
    min-width: 44px !important;
    min-height: 44px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   4. LIBRARY — flagship card excessive padding
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .flagship-card {
    padding: 18px !important;
  }
  .flagship-card h3 {
    font-size: 18px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   5. CONTAINER — reduce excessive 48px padding on mobile
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  .container {
    padding-left: 16px !important;
    padding-right: 16px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   6. SHOP — filter row scroll + sticky controls height
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .shop-filters,
  .filter-row {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    padding-bottom: 6px !important;
  }
  .shop-filters button,
  .filter-row button {
    flex-shrink: 0 !important;
    white-space: nowrap !important;
    font-size: 13px !important;
    padding: 8px 12px !important;
  }

  /* Reduce sticky controls viewport consumption */
  .shop-sticky,
  .shop-controls-sticky {
    padding: 8px 12px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   7. KIT PAGE — cover image overflow prevention
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 760px) {
  .kit-cover,
  .kit-cover-img,
  .kit-hero img,
  .product-cover img {
    max-width: 100% !important;
    height: auto !important;
    border-radius: 12px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   8. DESK TOOLTIPS — prevent white-space overflow
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 760px) {
  .desk-tooltip,
  .tooltip,
  [data-tooltip]::after {
    white-space: normal !important;
    max-width: 200px !important;
    word-wrap: break-word !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   9. SPIRALING BADGE — hide when virtual keyboard is open
   ═══════════════════════════════════════════════════════════════════ */
@media (max-height: 500px) and (max-width: 760px) {
  .spiraling-badge-link,
  .spiraling-badge {
    display: none !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   10. MISC OVERFLOW & ALIGNMENT
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 760px) {
  /* Prevent any horizontal overflow from wide elements (skip desk page) */
  html:not(:has(.stage)), body:not(:has(.stage)) {
    overflow-x: hidden !important;
  }

  /* Tables: scrollable wrapper */
  table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    max-width: 100% !important;
  }

  /* Pre/code blocks: scrollable */
  pre, code {
    max-width: 100% !important;
    overflow-x: auto !important;
    word-break: break-all !important;
  }

  /* Iframes (embedded content) */
  iframe {
    max-width: 100% !important;
  }

  /* SVGs that might overflow */
  svg:not(.icon):not([width="16"]):not([width="20"]):not([width="24"]) {
    max-width: 100%;
    height: auto;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   11. SQUEEZE/LANDING PAGES — form layout on mobile
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .squeeze-form,
  .landing-form,
  .email-capture {
    flex-direction: column !important;
    gap: 10px !important;
  }
  .squeeze-form input,
  .landing-form input,
  .email-capture input {
    width: 100% !important;
  }
  .squeeze-form button,
  .landing-form button,
  .email-capture button {
    width: 100% !important;
    justify-content: center !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   12. BLOG/ARTICLE — image captions and figures
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  figure {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  figcaption {
    font-size: 13px !important;
    padding: 6px 0 !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   13. SAFE AREA INSETS — notched devices (iPhone X+)
   ═══════════════════════════════════════════════════════════════════ */
@supports (padding: env(safe-area-inset-bottom)) {
  @media (max-width: 760px) {
    .home-sticky-buy,
    .sbb-inner,
    .sticky-buy-bar {
      padding-bottom: calc(8px + env(safe-area-inset-bottom)) !important;
    }
    .dr-canon-nav .inner {
      padding-left: calc(12px + env(safe-area-inset-left)) !important;
      padding-right: calc(12px + env(safe-area-inset-right)) !important;
    }
  }
}

/* ═══════════════════════════════════════════════════════════════════
   14. DESK PAGE — welcome banner + HUD collision fix
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 760px) {
  .dr-welcome-back {
    top: calc(10px + env(safe-area-inset-top, 0px)) !important;
    font-size: 11px !important;
    padding: 6px 12px !important;
    z-index: 11 !important;
  }

  /* Desk page HUD pills — push down to avoid welcome banner */
  body:has(.dr-welcome-back) .hud {
    top: 50px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   15. KIT HERO — compact product card on mobile
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  /* Limit the aurora/geometric hero height */
  .hero-vp {
    max-height: none !important;
    padding-top: 20px !important;
    padding-bottom: 24px !important;
  }

  /* Product card: more compact */
  .hero-product-card {
    padding: 16px !important;
  }
  .hero-product-card h3 {
    font-size: 16px !important;
    margin-bottom: 8px !important;
  }
  .hero-product-card .hpc-desc {
    font-size: 13px !important;
    line-height: 1.4 !important;
  }

  /* Cover image — smaller on mobile */
  .dr-cover-wrap {
    gap: 12px !important;
  }
  .dr-kit-cover {
    max-width: 120px !important;
    height: auto !important;
  }

  /* Compact the price + actions area */
  .hpc-price {
    font-size: 13px !important;
    margin: 8px 0 !important;
  }
  .hpc-actions {
    gap: 8px !important;
  }
  .hpc-actions .hero-action {
    font-size: 13px !important;
    padding: 10px 14px !important;
  }
  .hpc-microtrust {
    font-size: 11px !important;
    margin-top: 8px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   16. SHARE BUTTON — shift up when sticky buy bar is visible
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 760px) {
  /* When sticky bar is showing, push the share button above it */
  .sticky-buy-bar.is-visible ~ #dr-share-btn,
  body:has(.sticky-buy-bar.is-visible) #dr-share-btn {
    bottom: 68px !important;
  }

  /* Also handle the home sticky buy variant */
  .home-sticky-buy.is-visible ~ #dr-share-btn,
  body:has(.home-sticky-buy.is-visible) #dr-share-btn {
    bottom: 68px !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════
   17. STICKY BUY BAR — cleaner layout on narrow screens
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 420px) {
  .sbb-inner {
    flex-direction: column !important;
    gap: 6px !important;
    padding: 10px 14px !important;
    text-align: center !important;
  }
  .sbb-text {
    width: 100% !important;
  }
  .sbb-text strong {
    font-size: 12px !important;
    display: block !important;
  }
  .sbb-price {
    font-size: 10px !important;
  }
  .sbb-actions {
    width: 100% !important;
  }
  .sbb-actions .hero-action.primary {
    width: 100% !important;
    text-align: center !important;
    justify-content: center !important;
    font-size: 13px !important;
    padding: 10px 16px !important;
  }
}
