/* Phone portrait and short landscape windows share the same gallery controls. */
@media (max-width: 640px), (min-width: 641px) and (max-width: 1023px) and (max-height: 599px) {
  body.listing-mobile-gallery .main.main--catalog { padding-top: 0; }
  body.listing-mobile-gallery #listing-content > .gallery {
    width: calc(100% + 32px);
    margin-inline: -16px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  body.listing-mobile-gallery #listing-content .gallery__main {
    aspect-ratio: 4 / 5;
    border-radius: 0;
    box-shadow: none;
  }
  body.listing-mobile-gallery #listing-content .gallery__inline-nav { display: none !important; }
  body.listing-mobile-gallery #listing-content .gallery__main--track {
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
  }
  body.listing-mobile-gallery #listing-content .gallery__main img {
    width: 100%;
    max-width: none;
    height: 100%;
    flex: 0 0 100%;
    aspect-ratio: 4 / 5;
    border-radius: 0;
    object-fit: cover;
    object-position: center;
  }
  .listing-mobile-gallery__controls {
    position: absolute;
    top: calc(6px + env(safe-area-inset-top, 0px));
    left: max(6px, env(safe-area-inset-left, 0px));
    right: max(6px, env(safe-area-inset-right, 0px));
    z-index: 3;
    display: flex;
    gap: 0;
    pointer-events: none;
  }
  body.listing-mobile-gallery .gallery .listing-mobile-gallery__control {
    position: static;
    display: grid;
    place-items: center;
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: #fff;
    transform: none;
    pointer-events: auto;
    touch-action: manipulation;
  }
  body.listing-mobile-gallery .gallery #back-btn { margin-right: auto; }
  body.listing-mobile-gallery .gallery .listing-mobile-gallery__control svg {
    width: 24px;
    height: 24px;
    flex: none;
    stroke-width: 2;
    filter: drop-shadow(0 1px 2px rgb(0 0 0 / 60%)) drop-shadow(0 0 1px rgb(0 0 0 / 50%));
  }
  body.listing-mobile-gallery .gallery #back-btn span,
  body.listing-mobile-gallery .gallery #share-open span { display: none; }
  body.listing-mobile-gallery .gallery--empty .listing-mobile-gallery__control { color: #171717; }
  body.listing-mobile-gallery .gallery--empty .listing-mobile-gallery__control svg { filter: none; }
  body.listing-mobile-gallery .gallery .listing-mobile-gallery__control:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: -4px;
  }
  body.listing-mobile-gallery #listing-content .gallery__dots { bottom: 8px; gap: 2px; }
  body.listing-mobile-gallery #listing-content .gallery__dot {
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 0;
    padding: 0;
    background: transparent;
  }
  body.listing-mobile-gallery #listing-content .gallery__dot::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgb(255 255 255 / 60%);
    box-shadow: 0 0 2px rgb(0 0 0 / 40%);
  }
  body.listing-mobile-gallery #listing-content .gallery__dot.active::before { background: #fff; }
  body.listing-mobile-gallery #listing-content .listing-detail__quick-actions #contacts-open { flex: 1 1 100%; width: 100%; }
}

/* Phone rotation must not expose the legacy wide card or desktop header. */
@media (min-width:641px) and (max-width:1023px) and (max-height:599px){
  body:has(#listing-content)> .header{display:none}
  body:has(#listing-content) .main.main--catalog{padding-top:0}
  body:has(#listing-content) .listing-page{width:min(640px,calc(100% - 32px - env(safe-area-inset-left,0px) - env(safe-area-inset-right,0px)));margin-inline:auto}
  body:has(#listing-content) #listing-content{padding:0;border:0;border-radius:0;box-shadow:none;background:transparent}
  body.listing-mobile-gallery #listing-content>.gallery{width:100%;margin:0}
  body.listing-mobile-gallery #listing-content .gallery__main{height:70svh;max-height:360px;aspect-ratio:auto;background:#f3f4f5;border-radius:12px}
  body.listing-mobile-gallery #listing-content .gallery__main--track{display:flex;scroll-snap-type:x mandatory;overscroll-behavior-inline:contain;scrollbar-width:none}
  body.listing-mobile-gallery #listing-content .gallery__main--track::-webkit-scrollbar{display:none}
  body.listing-mobile-gallery #listing-content .gallery__main img{object-fit:contain;scroll-snap-align:start;scroll-snap-stop:always}
  body.listing-mobile-gallery #listing-content .gallery__dots{display:flex}
  body.listing-mobile-gallery #listing-content .listing-detail__header{margin:17px 0 12px}
  body.listing-mobile-gallery #listing-content .listing-detail__title{font-size:21px;line-height:1.25;overflow-wrap:anywhere}
  body.listing-mobile-gallery #listing-content .listing-detail__description{overflow-wrap:anywhere}
}
