/*
 * Responsive audit — a late-loading guardrail for tablet and phone layouts.
 * Desktop rails remain defined by each page stylesheet; these rules intervene
 * only once a multi-column composition no longer has enough breathing room.
 */

html { overflow-x: clip; }

img,
svg,
iframe { max-width: 100%; }

/* Tablet navigation: switch before the logo, account/cart controls, and four
 * desktop menu groups have to compete for one line. */
@media (max-width: 1120px) {
  .mast { padding-left: 24px !important; padding-right: 24px !important; }
  .primary-nav,
  .nav-actions,
  .mega { display: none !important; }
  .menu { display: block !important; margin-left: auto; }

  /* The homepage's "how it works" composition stays editorial at tablet:
   * copy/image above the three short steps rather than three narrow columns. */
  .how-prototype {
    grid-template-columns: minmax(0, 1fr) 340px;
    min-height: 0;
  }
  .how-intro { padding: 78px 48px 64px; }
  .how-steps {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    padding: 32px 48px 46px;
  }
  .how-steps > div { border-bottom: 0; border-top: 1px solid var(--hair); }

  /* Commerce cards retain useful line length instead of becoming cramped
   * three-up tiles between laptop and iPad widths. */
  .catalog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .affiliate-stats > .affiliate-wrap,
  .affiliate-steps,
  .affiliate-audience,
  .wholesale-stats > .wholesale-wrap,
  .wholesale-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Portrait tablet and small landscape tablet. */
@media (max-width: 1080px) {
  /* The blue bioavailability block is deliberately vertical here. Its data
   * message then has full width rather than being squeezed beside its copy. */
  .absorption {
    grid-template-columns: 1fr;
    gap: 36px;
    padding-top: 84px;
    padding-bottom: 84px;
  }
  .absorb-stat {
    border-top: 1px solid rgba(255, 255, 255, .35);
    border-left: 0;
    padding: 30px 0 0;
  }

  /* Product, cart, and checkout flows become single-column before their
   * purchase controls or order summaries get visually compressed. */
  .pdp-top {
    grid-template-columns: 1fr;
    gap: 34px;
    padding-left: 32px;
    padding-right: 32px;
  }
  .pdp-buy { position: static; }

  .cart-grid,
  .melts-checkout-grid { grid-template-columns: 1fr; }
  .cart-summary,
  .melts-checkout-review { position: static; order: -1; }
  .cart-main { display: contents; }
  .cart-gift-progress { order: -2; }
  .cart-upsells { order: 2; }

  .science-hero-grid,
  .science-proof-grid,
  .science-format-grid,
  .science-faq-grid { gap: 36px; }
  .science-hero-grid > div:first-child,
  .science-proof-grid > div:first-child { flex-basis: 390px; }
}

/* Phone rules concentrate on readable type, explicit one-column flow, and
 * touch targets without changing desktop page composition. */
@media (max-width: 760px) {
  .mast { padding-left: 20px !important; padding-right: 20px !important; }

  .how-prototype { grid-template-columns: 1fr; }
  .how-intro { padding: 64px 20px 42px; }
  .how-steps { grid-template-columns: 1fr; gap: 0; padding: 28px 20px 42px; }
  .how-steps > div { padding: 16px 0; }
  .how-photo { height: min(100vw, 480px); }

  .absorption { gap: 28px; padding-top: 68px; padding-bottom: 68px; }
  .absorption h2 { font-size: clamp(56px, 19vw, 88px); }
  .absorb-stat b { font-size: clamp(74px, 25vw, 118px); }

  .pdp-top { gap: 28px; padding: 4px 20px 56px; }
  .pdp-gallery { width: 100%; }
  .pdp-details { grid-template-columns: 1fr; gap: 24px; padding: 52px 20px; }
  .pdp-action { align-items: stretch; }
  .pdp-add { min-width: 0; }

  .catalog-grid { grid-template-columns: 1fr; }
  .catalog-controls { gap: 14px 20px; }

  .cart-gift-progress { padding: 21px; gap: 18px; }
  .cart-steps { min-width: 0; }
  .cart-line-controls { flex-wrap: wrap; }

  .science-hero-grid > div:first-child,
  .science-proof-grid > div:first-child,
  .science-format-grid > div:first-child,
  .science-faq-grid > div:first-child { flex-basis: 100%; }
  .science-stats { grid-template-columns: 1fr; }
  .science-meter-row { align-items: flex-start; flex-direction: column; gap: 7px; }
  .science-meter-row span { width: auto; max-width: none; }
  /* In a vertical flex row, the desktop `flex: 1` bar has no available
   * vertical space to grow into. Give it an explicit full-width track so the
   * comparison still reads as a graphic, not a list of labels. */
  .science-meter-bar { flex: 0 0 15px; width: 100%; min-height: 15px; }
  .science-meter-row span { order: -1; }

  /* Keep the route diagram meaningful even if an intersection callback is
   * delayed or skipped by a mobile browser. Desktop retains its animation. */
  .science-trip .science-bars i { transform: scaleY(1); }

  .affiliate-stats > .affiliate-wrap,
  .affiliate-steps,
  .affiliate-audience,
  .wholesale-stats > .wholesale-wrap,
  .wholesale-steps { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .pdp-action { gap: 7px; }
  .pdp-quantity { grid-template-columns: 34px 31px 34px; }
  .pdp-quantity button { height: 46px; }
  .pdp-gift-list article { grid-template-columns: 58px minmax(0, 1fr) auto 16px; gap: 6px; }
  .pdp-gift-list em,
  .pdp-gift-list b { font-size: 9px; }

  #melts-sidecart { max-width: 100%; }
  .msc-steps { gap: 6px; }
  .msc-step { gap: 5px; font-size: 9px; }
  .msc-step:before { display: none; }
  .msc-foot { padding-left: 16px; padding-right: 16px; }
  .msc-items { padding-left: 16px; padding-right: 16px; }
  .msc-head,
  .msc-progress { padding-left: 16px; padding-right: 16px; }
}

/* Homepage mobile polish. These sit late in the cascade so they safely
 * supersede older prototype rules without changing the approved desktop UI. */
@media (max-width: 900px) {
  body { padding-bottom: 0 !important; }
  /* Sticky children need a non-clipping ancestor on iOS Safari. Horizontal
   * clipping is handled on the document instead, above. */
  .melts-site { overflow: visible; }

  /* Individual templates sometimes set their mast to `relative`, which lets
   * it scroll away permanently. Every mobile template uses the same sticky
   * header contract so the shared scroll-up handler can reveal it again. */
  .mast {
    position: sticky !important;
    top: 36px;
    z-index: 190;
    transition: transform .22s ease;
    will-change: transform;
  }
  .mast.mast-is-hidden { transform: translateY(-82px); }
  .melts-site > .mast { position: fixed !important; top: 36px; }

  .melts-site > .offer {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 200;
    display: flex !important;
    min-height: 36px;
    padding: 8px 14px;
    justify-content: center;
    gap: 7px;
    font-size: 10px;
    white-space: nowrap;
  }
  .melts-site > .offer > span { display: inline !important; margin: 0 !important; opacity: 1; }
  .melts-site > .offer > span:last-child,
  .melts-site > .offer > i:last-of-type { display: none !important; }
  .melts-site > .offer > i { display: inline !important; margin: 0 1px; }
  .melts-site {
    padding-top: 100px;
  }
  .melts-site > .mast {
    position: fixed;
    top: 36px;
    right: 0;
    left: 0;
    z-index: 190;
  }

  /* The original mobile stylesheet hides offer spans wholesale. Restore the
   * compact, legible two-message version on every template. */
  .offer {
    position: sticky;
    top: 0;
    z-index: 200;
    display: flex !important;
    min-height: 36px;
    padding: 8px 12px;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: #fff !important;
    background: #2456d9;
    font: 500 10px/1.2 var(--body);
    white-space: nowrap;
  }
  .offer > span { display: inline !important; margin: 0 !important; color: #fff !important; opacity: 1 !important; }
  .offer > i { display: inline !important; margin: 0 !important; color: rgba(255,255,255,.72) !important; }
  .offer > span:last-child,
  .offer > i:last-of-type { display: none !important; }

  /* Shared promo ribbon treatment for catalog and supporting-page headers. */
  .site-offer,
  .catalog-page > .offer,
  .cart-offer,
  .affiliate-offer,
  .wholesale-offer {
    position: sticky;
    top: 0;
    z-index: 200;
  }
  .site-offer {
    display: flex !important;
    min-height: 36px;
    padding: 8px 14px;
    align-items: center;
    justify-content: center;
    gap: 7px;
    color: #fff;
    background: #2456d9;
    font: 600 10px/1.2 var(--font-mono, monospace);
    letter-spacing: .025em;
    white-space: nowrap;
  }
  .catalog-page > .offer + .mast,
  .site-offer + .mast,
  .cart-offer + .mast,
  .affiliate-offer + .mast,
  .wholesale-offer + .mast { top: 36px; }

  /* Lead with product identity, then show the visual/review proof, followed
   * by variant, offer and purchase controls. */
  .stacks .stack-grid { display: flex; flex-direction: column; gap: 0; }
  .stacks .stack-copy { display: contents; }
  .stacks #stack-kicker { order: 1; margin: 0 0 8px; }
  .stacks #stack-title { order: 2; }
  .stacks #stack-description { order: 3; margin: 12px 0 22px; }
  .stacks .stack-gallery { order: 4; margin: 0 0 26px; }
  .stacks .stack-accordions { order: 5; }
  .stacks .stack-choice { order: 6; }
  .stacks .stack-gifts { order: 7; }
  .stacks .buy-action-row { order: 8; }
  .stacks .stack-copy > small:last-child { order: 9; }

  .buy-action-row { align-items: stretch !important; min-height: 50px; }
  .buy-action-row .quantity-picker { align-self: stretch; height: 50px !important; margin: 0 !important; }
  .buy-action-row .quantity-picker button { height: 48px; }
  .buy-action-row .quantity-picker span { line-height: 48px; }
  .buy-action-row > a,
  .buy-action-row > .button {
    align-self: stretch;
    display: flex !important;
    align-items: center;
    justify-content: center;
    height: 50px !important;
    min-height: 50px !important;
    margin: 0 !important;
  }

  .absorb-stat { padding: 26px !important; }
  .absorb-stat > div { margin: 0 !important; }
  .absorb-stat > div + div { margin-top: 23px !important; }
  .absorb-stat p { gap: 12px; margin: 0 0 9px !important; }
  .absorb-stat i { height: 34px !important; }
  .absorb-stat > small { margin-top: 14px; }
  .absorb-disclaimer { margin-top: 16px !important; }

  .shop .prototype-picker {
    padding-left: 24px !important;
    padding-right: 24px !important;
    scroll-padding-left: 24px;
  }
  .shop .prototype-picker button { box-sizing: border-box; }
  .shop .prototype-picker img {
    display: block;
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 1 / 1 !important;
    object-fit: cover;
  }

  .gift-progress-bar { display: none !important; }

  .melts-footer {
    grid-template-columns: 1fr !important;
    gap: 28px !important;
    padding: 48px 20px 32px !important;
  }
  .melts-footer .footer-disclaimer { grid-column: auto; margin-top: 0; }

  .mobile-nav { z-index: 300; }
  .mobile-nav-header { margin-bottom: 34px; }
  .mobile-nav-brand { display: inline-flex !important; align-items: center; border: 0 !important; padding: 0 !important; }
  .mobile-nav-brand img { display: block; width: 58px; height: 48px; object-fit: contain; }
}

/* Mobile catalog: choose one line in a selector, then read and buy each card
 * as a deliberate, full-width product unit. */
.site-offer { display: none; }
.catalog-line-select { display: none; }
@media (max-width: 900px) {
  .catalog-controls {
    display: flex !important;
    align-items: center;
    justify-content: space-between !important;
    gap: 10px;
    overflow: visible !important;
    padding-bottom: 20px !important;
  }
  .catalog-line-switch { order: 2; width: auto; flex: 0 0 auto; }
  .catalog-product-filters { order: 1; width: auto; min-width: 0; flex: 1 1 auto; gap: 2px; }
  .catalog-line-switch > a { display: none; }
  .catalog-line-select { display: block; width: auto; }
  .catalog-line-select > span { display: none; }
  .catalog-line-select select {
    width: 124px;
    min-height: 38px;
    padding: 0 9px;
    border: 1px solid #cfd7e4;
    border-radius: 999px;
    background: #fff;
    color: #0b0e14;
    font: 700 13px var(--body);
  }
  .catalog-product-filters .catalog-filter { padding: 8px 9px; font-size: 12px; }
  .catalog-grid { gap: 16px; padding-top: 24px; }
  .catalog-card { padding: 18px; }
  .catalog-image { width: 100%; max-height: none !important; aspect-ratio: 1 / 1; }
  .catalog-image img { display: block; width: 100%; height: 100%; object-fit: cover; }
  .catalog-card h2 { margin-top: 18px; font-size: 28px; }
  .catalog-goal { font-size: 12px; }
  .catalog-copy { min-height: 0; margin: 11px 0 18px; font-size: 16px; line-height: 1.45; }
  .catalog-mode { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
  .catalog-mode label {
    min-height: 46px;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border: 1px solid #d9dfe8;
    border-radius: 8px;
    color: #657181;
    font-size: 14px;
    line-height: 1.2;
  }
  .catalog-mode label.is-active { border-color: var(--catalog-accent); background: color-mix(in srgb, var(--catalog-accent) 8%, white); color: #0b0e14; }
  .catalog-mode input { width: 16px; height: 16px; flex: 0 0 16px; }
  .catalog-bottom { display: grid !important; grid-template-columns: auto minmax(150px, 1fr); align-items: center; gap: 14px; }
  .catalog-price { display: flex; flex-direction: column; gap: 2px; font-size: 16px; }
  .catalog-price b { font: 800 24px var(--display); letter-spacing: -.03em; }
  .catalog-add { display: flex; min-height: 52px; align-items: center; justify-content: center; margin: 0 !important; border-radius: 8px; font-size: 16px; }
}
@media (max-width: 400px) {
  .catalog-line-select select { width: 110px; }
  .catalog-product-filters .catalog-filter { padding-right: 7px; padding-left: 7px; font-size: 11px; }
  .catalog-mode { grid-template-columns: 1fr; }
  .catalog-bottom { grid-template-columns: 1fr; gap: 12px; }
  .catalog-price { flex-direction: row; align-items: baseline; gap: 8px; }
}

/* Native scrolling is substantially more stable than a transformed flex row
 * during touch gestures. Arrow controls still target the same slide index. */
.carousel-track {
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  transform: none !important;
}
.carousel-track::-webkit-scrollbar { display: none; }
.carousel-track > img { scroll-snap-align: start; }

/* Product galleries are square at every width. The square belongs on the
 * viewport only: putting it on the flex track and every slide makes each
 * slide calculate from the three-slide track, which produces a 3× crop. */
.pdp-gallery { width: 100% !important; height: auto !important; aspect-ratio: 1 / 1 !important; }
.pdp-gallery-track { width: 100% !important; height: 100% !important; aspect-ratio: auto !important; }
.pdp-gallery figure { flex: 0 0 100% !important; width: 100% !important; height: 100% !important; aspect-ratio: auto !important; }
.pdp-gallery img { display: block; width: 100% !important; height: 100% !important; aspect-ratio: auto !important; object-fit: contain !important; }

/* PDP mobile refinement: show the entire portrait product artwork within the
 * square gallery rather than cropping it into an oversized close-up. Reviews
 * remain available on desktop and are intentionally removed from the mobile
 * purchase flow. */
@media (max-width: 900px) {
  .pdp-gallery figure { background: #fff; }
  .pdp-review,
  .pdp-reviews-placeholder { display: none !important; }

  .pdp-gifts { padding: 15px; }
  .pdp-gifts-head { margin-bottom: 12px; }
  .pdp-gifts-head b { font-size: 11px; }
  .pdp-gifts-head small,
  .pdp-gifts > small { font-size: 11px; }
  .pdp-gift-list { gap: 8px; }
  .pdp-gift-list article,
  .pdp-gift-list article.is-earned {
    grid-template-columns: minmax(0, 1fr) auto 20px !important;
    gap: 9px !important;
    min-height: 46px;
    padding: 10px 11px;
    opacity: 1;
  }
  .pdp-gift-list em { display: none !important; }
  .pdp-gift-list b { font-size: 14px !important; line-height: 1.2; }
  .pdp-gift-list span { font-size: 13px !important; }
  .pdp-gift-list i { font-size: 16px; }

  .melts-footer > div:first-child img {
    width: 116px;
    height: 56px;
    margin-left: -20px;
  }
}

/* Collection purchase options are intentionally large enough to scan at a
 * glance on desktop as well as touch comfortably on smaller screens. */
.catalog-mode { gap: 8px 16px; }
.catalog-mode label { gap: 7px; font-size: 13px; line-height: 1.25; }
.catalog-mode input { width: 15px; height: 15px; }

/* PDP gift cards carry an important offer; keep the desktop version equally
 * easy to read rather than reserving the accessible sizing for phones. */
.pdp-gifts { padding: 15px; }
.pdp-gifts-head { margin-bottom: 12px; }
.pdp-gifts-head b { font-size: 11px; }
.pdp-gifts-head small,
.pdp-gifts > small { font-size: 11px; }
.pdp-gift-list { gap: 8px; }
.pdp-gift-list article { min-height: 44px; padding: 9px 11px; }
.pdp-gift-list em { font-size: 9px; }
.pdp-gift-list b { font-size: 13px; }
.pdp-gift-list span { font-size: 13px; }
.pdp-gift-list i { font-size: 15px; }

/* Header cart: icon-first everywhere, with a count badge only when the cart
 * contains paid items. On mobile it remains beside the menu trigger. */
.nav-actions .cart-link {
  position: relative;
  display: inline-grid;
  width: 42px;
  height: 42px;
  padding: 0 !important;
  place-items: center;
  border-radius: 50%;
  background: transparent !important;
  color: #0b0e14 !important;
  font-size: 0 !important;
}
.nav-actions .cart-link::before {
  width: 20px;
  height: 20px;
  background: center / contain no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 3h2l2.2 11.2a2 2 0 0 0 2 1.6h8.8a2 2 0 0 0 2-1.6L21 7H6'/%3E%3Ccircle cx='10' cy='20' r='1'/%3E%3Ccircle cx='18' cy='20' r='1'/%3E%3C/svg%3E");
  filter: invert(1);
  content: '';
}
.nav-actions .cart-link .melts-cart-count {
  position: absolute;
  top: -6px;
  right: -6px;
  display: none;
  min-width: 19px;
  height: 19px;
  padding: 0 4px;
  border: 2px solid #fff;
  border-radius: 99px;
  background: #2456d9;
  color: #fff;
  font: 700 10px/15px var(--body);
  text-align: center;
}
.nav-actions .cart-link.has-items .melts-cart-count { display: block; }
@media (min-width: 1121px) {
  .nav-actions .cart-link {
    display: inline-flex;
    width: auto;
    height: auto;
    padding: 10px 20px !important;
    border-radius: 8px;
    background: #0b0e14 !important;
    color: #fff !important;
    font: 600 14px var(--body) !important;
  }
  .nav-actions .cart-link::before { display: none; }
  .nav-actions .cart-link .melts-cart-count {
    position: static;
    display: inline;
    min-width: 0;
    width: auto;
    height: auto;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    line-height: inherit;
  }
}
@media (max-width: 1120px) {
  .nav-actions { display: flex !important; flex: 0 0 auto; align-items: center !important; margin-left: auto; gap: 0 !important; }
  .nav-actions > a:first-child { display: none !important; }
  .nav-actions .cart-link { align-self: center; margin: 0; transform: translateY(2px); }
  .nav-actions .cart-link .melts-cart-count { top: 0; right: -3px; }
  .menu { margin-left: 12px !important; }
}
@media (max-width: 900px) {
  .mobile-nav .mobile-cart-count { display: inline; margin-left: 4px; }
}
