:root {
  color-scheme: light;
}

html {
  overflow-x: clip;
  scroll-padding-top: 16px;
}

body {
  overflow-x: hidden;
  text-rendering: optimizeLegibility;
}

button,
a,
input,
select,
.car-card {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.car-card {
  content-visibility: auto;
  contain: layout paint style;
  contain-intrinsic-size: 430px;
}

.car-image img {
  transition: transform .28s ease, opacity .18s ease;
}

.photo-count,
.detail-dialog::backdrop {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.image-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #e6e9ed, #f3f4f6);
}

.detail-arrow {
  flex: 0 0 auto;
}

.detail-dialog {
  overscroll-behavior: contain;
  overflow: hidden;
}

.detail-layout {
  max-height: calc(100dvh - 36px);
}

.gallery,
.detail-info {
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.gallery {
  overflow-y: auto;
}

.gallery-stage {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border-radius: 14px;
  background: #dfe3de;
  touch-action: pan-y;
}

.gallery-main {
  position: relative;
  z-index: 1;
  border-radius: 14px;
  transition: opacity .16s ease;
}

.gallery-loader {
  position: absolute;
  z-index: 2;
  inset: 50% auto auto 50%;
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, .58);
  border-top-color: var(--green);
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.gallery-stage.is-loading .gallery-main {
  opacity: .68;
}

.gallery-stage.is-loading .gallery-loader {
  opacity: 1;
  animation: gallery-spin .7s linear infinite;
}

@keyframes gallery-spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.gallery-nav {
  position: absolute;
  z-index: 3;
  top: 50%;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 8px 24px rgba(12, 21, 44, .18);
  font-size: 31px;
  line-height: 1;
  transform: translateY(-50%);
}

.gallery-prev { left: 14px; }
.gallery-next { right: 14px; }

.gallery-position {
  position: absolute;
  z-index: 3;
  right: 14px;
  bottom: 12px;
  padding: 7px 10px;
  color: #fff;
  background: rgba(12, 21, 44, .8);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.thumb {
  min-width: 0;
  transition: border-color .15s ease, transform .15s ease;
}

.thumb img {
  transform: translateZ(0);
}

body.dialog-open {
  overflow: hidden;
}

@media (hover: hover) and (pointer: fine) {
  .gallery-nav:hover {
    color: #fff;
    background: var(--green);
  }

  .thumb:hover {
    transform: translateY(-2px);
  }
}

@media (hover: none) {
  .car-card:hover {
    transform: none;
    box-shadow: 0 3px 10px rgba(23, 33, 28, .025);
  }

  .car-card:hover .car-image img {
    transform: none;
  }
}

@media (max-width: 900px) {
  .detail-dialog {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .detail-layout {
    max-height: none;
  }

  .gallery {
    overflow: visible;
  }

  .thumbs {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  html {
    scroll-padding-top: 76px;
  }

  .site-header {
    height: 68px;
    padding: 0 15px;
    gap: 12px;
    position: relative;
    z-index: 10;
  }

  .brand img {
    width: min(156px, 48vw);
  }

  .header-phone {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    border: 1px solid rgba(255, 255, 255, .16);
    border-radius: 50%;
    text-align: center;
  }

  .header-phone small {
    display: none;
  }

  .header-phone strong {
    margin: 0;
    font-size: 0;
  }

  .header-phone strong::before {
    content: "☎";
    font-size: 19px;
  }

  .hero {
    min-height: auto;
    padding: 34px 15px 10px;
    gap: 8px;
    background: linear-gradient(160deg, #fff 0 62%, #e5e8ed 62%);
  }

  .eyebrow {
    margin-bottom: 12px;
    font-size: 10px;
    letter-spacing: 1.45px;
  }

  .hero h1 {
    max-width: 100%;
    font-size: clamp(32px, 9.7vw, 40px);
    line-height: 1.07;
    letter-spacing: -1.8px;
  }

  .hero-text {
    margin-top: 17px;
    font-size: 13px;
    line-height: 1.58;
  }

  .hero-button {
    width: 100%;
    min-height: 50px;
    margin-top: 21px;
    justify-content: space-between;
  }

  .hero-visual {
    min-height: 235px;
  }

  .hero-visual > img {
    width: 118%;
    max-width: none;
    max-height: 250px;
    object-fit: contain;
    filter: drop-shadow(0 16px 18px rgba(12, 21, 44, .18));
  }

  .hero-stamp {
    width: 82px;
    height: 82px;
    top: 2px;
    right: 0;
    gap: 5px;
  }

  .hero-stamp strong { font-size: 23px; }
  .hero-stamp span { font-size: 7px; }

  .advantages {
    padding: 10px 15px;
  }

  .advantages div {
    min-height: 62px;
    padding: 14px 5px;
  }

  .catalog {
    padding: 38px 15px 54px;
  }

  .section-intro {
    margin-bottom: 24px;
  }

  .section-intro h2 {
    font-size: 28px;
    line-height: 1.13;
    letter-spacing: -1px;
  }

  .section-intro p {
    font-size: 12px;
    line-height: 1.55;
  }

  .toolbar {
    gap: 9px;
    margin-bottom: 28px;
  }

  .search,
  .select-wrap select {
    height: 52px;
    border-radius: 11px;
    font-size: 16px;
  }

  .catalog-head {
    gap: 12px;
    margin-bottom: 17px;
  }

  .catalog-head h3 {
    font-size: 19px;
  }

  .catalog-head span {
    display: block;
    flex: 0 0 auto;
    font-size: 11px;
  }

  .car-grid {
    gap: 16px;
  }

  .car-card {
    contain-intrinsic-size: 410px;
    border-radius: 15px;
  }

  .card-body {
    padding: 17px;
  }

  .car-title {
    min-height: 0;
    font-size: 18px;
  }

  .card-specs {
    margin: 14px 0;
  }

  .price strong {
    font-size: 21px;
  }

  footer {
    min-height: 0;
    padding: 34px 20px calc(34px + env(safe-area-inset-bottom));
    gap: 16px;
  }

  footer p {
    margin: 0;
    line-height: 1.55;
  }

  .detail-dialog {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }

  .detail-dialog::backdrop {
    background: rgba(12, 21, 44, .82);
  }

  .dialog-close {
    top: max(10px, env(safe-area-inset-top));
    right: 10px;
    width: 44px;
    height: 44px;
    color: #fff;
    background: rgba(12, 21, 44, .88);
  }

  .detail-layout {
    min-height: 100%;
  }

  .gallery {
    padding: 0 0 10px;
  }

  .gallery-stage {
    border-radius: 0;
  }

  .gallery-main {
    aspect-ratio: 4 / 3;
    border-radius: 0;
  }

  .gallery-nav {
    width: 42px;
    height: 42px;
    font-size: 28px;
  }

  .gallery-prev { left: 8px; }
  .gallery-next { right: 8px; }

  .gallery-position {
    right: 9px;
    bottom: 9px;
  }

  .thumbs {
    display: flex;
    gap: 7px;
    margin-top: 0;
    padding: 10px 10px 2px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .thumbs::-webkit-scrollbar {
    display: none;
  }

  .thumb {
    width: 78px;
    min-width: 78px;
    scroll-snap-align: center;
    border-radius: 7px;
  }

  .detail-info {
    padding: 24px 16px calc(42px + env(safe-area-inset-bottom));
  }

  .detail-info h2 {
    margin-top: 13px;
    font-size: 24px;
    letter-spacing: -.7px;
  }

  .detail-model {
    margin-bottom: 18px;
    font-size: 13px;
  }

  .detail-price {
    margin-bottom: 22px;
    font-size: 27px;
    line-height: 1.2;
  }

  .detail-price small {
    display: block;
    margin-top: 5px;
  }

  .quick-specs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    margin-bottom: 24px;
  }

  .quick-spec {
    min-width: 0;
    padding: 12px 9px;
  }

  .quick-spec strong {
    overflow-wrap: anywhere;
    font-size: 11px;
  }

  .vin {
    align-items: center;
  }

  .vin strong {
    max-width: 72%;
    overflow-wrap: anywhere;
    text-align: right;
  }

  .detail-section {
    margin-top: 24px;
  }

  .spec-row {
    align-items: flex-start;
  }

  .spec-row strong {
    max-width: 56%;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 380px) {
  .hero h1 {
    font-size: 31px;
  }

  .hero-visual {
    min-height: 210px;
  }

  .hero-visual > img {
    max-height: 220px;
  }

  .quick-specs {
    grid-template-columns: 1fr;
  }

  .quick-spec {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .quick-spec strong {
    margin-top: 0;
    text-align: right;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
