:root {
  --bg: #0f1115;
  --secondary-bg: #171a21;
  --text: #f2f3f5;
  --hint: #8b93a1;
  --link: #4fa3ff;
  --button: #2ea6ff;
  --button-text: #ffffff;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --secondary-bg: #ffffff;
    --text: #14161a;
    --hint: #6b7280;
    --link: #1d7ce0;
    --button: #1d7ce0;
    --button-text: #ffffff;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 24px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--secondary-bg);
  border-bottom: 1px solid rgba(139, 147, 161, 0.2);
}

.brand {
  max-width: 220px;
  text-align: center;
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.subtitle {
  margin: 1px 0 0;
  font-size: 11px;
  line-height: 1.2;
  color: var(--hint);
}

.toggles {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.toggle-group {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: 8px;
  padding: 3px;
}

.toggle-group button {
  border: none;
  background: transparent;
  color: var(--hint);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.toggle-group button.active {
  background: var(--button);
  color: var(--button-text);
}

.hero {
  padding: 8px 16px 0;
}

.hero-banner {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  border-radius: 14px;
}

/* 6 клонов одной машины, каждый едет и исчезает/появляется в свою очередь (сдвиг по фазе на
   1/6 цикла), поэтому видна всегда только одна — но при каждом новом появлении другого цвета. */
.hero-car-move {
  opacity: 0;
  animation: hero-drive-cycle 30s ease-in-out infinite both;
}

.hero-car-1 { animation-delay: 0s; }
.hero-car-2 { animation-delay: 5s; }
.hero-car-3 { animation-delay: 10s; }
.hero-car-4 { animation-delay: 15s; }
.hero-car-5 { animation-delay: 20s; }
.hero-car-6 { animation-delay: 25s; }

.hero-car-1 .hero-car-body { fill: #eaf4ff; }
.hero-car-2 .hero-car-body { fill: #ff6b6b; }
.hero-car-3 .hero-car-body { fill: #ffd166; }
.hero-car-4 .hero-car-body { fill: #06d6a0; }
.hero-car-5 .hero-car-body { fill: #4fa3ff; }
.hero-car-6 .hero-car-body { fill: #b892ff; }

@keyframes hero-drive-cycle {
  0% {
    opacity: 0;
    transform: translateX(0);
  }
  3% {
    opacity: 1;
    transform: translateX(0);
  }
  13% {
    opacity: 1;
    transform: translateX(-240px);
  }
  16% {
    opacity: 0;
    transform: translateX(-240px);
  }
  16.5% {
    opacity: 0;
    transform: translateX(0);
  }
  100% {
    opacity: 0;
    transform: translateX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .hero-car-move {
    animation: none;
    opacity: 0;
  }
  .hero-car-1 {
    opacity: 1;
  }
}

.hero-features {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.hero-feature {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--secondary-bg);
  border: 1px solid rgba(139, 147, 161, 0.15);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.hero-feature-icon {
  font-size: 16px;
  line-height: 1;
}

.filters {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 12px 16px;
}

/* Пятый фильтр (Сортировка) — нечётный, растягиваем на всю ширину, чтобы не висел одиноко. */
.filter:last-child {
  grid-column: 1 / -1;
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.filter label {
  font-size: 11px;
  color: var(--hint);
}

.filter select {
  width: 100%;
  background: var(--secondary-bg);
  color: var(--text);
  border: 1px solid rgba(139, 147, 161, 0.3);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 42px;
  font-size: 13px;
  transition: border-color 0.15s ease;
}

.filter select:focus {
  outline: none;
  border-color: var(--button);
}

@media (min-width: 420px) {
  .filters {
    grid-template-columns: repeat(3, 1fr);
  }

  .filter:last-child {
    grid-column: auto;
  }
}

.car-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  padding: 4px 12px 16px;
}

.loading,
.no-results {
  color: var(--hint);
  padding: 24px 4px;
  text-align: center;
  grid-column: 1 / -1;
}

.car-card {
  background: var(--secondary-bg);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(139, 147, 161, 0.15);
}

.car-photo {
  height: 110px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 34px;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(46, 166, 255, 0.25), rgba(46, 166, 255, 0.05));
}

.car-photo span {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.car-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.car-photo.large {
  height: 200px;
  border-radius: 12px;
  margin-bottom: 8px;
  position: relative;
}

.car-photo.gallery .gallery-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.car-photo.gallery .gallery-img.active {
  opacity: 1;
}

.gallery-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-nav.prev {
  left: 8px;
}

.gallery-nav.next {
  right: 8px;
}

.gallery-counter {
  position: absolute;
  bottom: 8px;
  right: 10px;
  background: rgba(0, 0, 0, 0.5);
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
}

.car-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.car-body h3 {
  margin: 0;
  font-size: 16px;
}

.trim {
  margin: 0;
  color: var(--hint);
  font-size: 13px;
}

.meta {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--hint);
}

.price {
  margin: 6px 0 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--link);
}

.price.big {
  font-size: 22px;
}

.price-note {
  margin: 2px 0 0;
  font-size: 11px;
  color: #e5484d;
}

.route {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text);
}

.route .label {
  color: var(--hint);
}

.stage {
  margin: 6px 0 0;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.stage .dots {
  letter-spacing: 2px;
  color: var(--button);
}

.details-btn,
.buy-btn,
.submit-btn,
.calc-btn {
  margin-top: 10px;
  border: none;
  background: var(--button);
  color: var(--button-text);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
}

.details-btn:disabled,
.buy-btn:disabled,
.submit-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.card-actions {
  display: flex;
  gap: 6px;
}

.card-actions .details-btn,
.card-actions .buy-btn {
  flex: 1 1 50%;
  min-width: 0;
  margin-top: 10px;
  padding: 8px 6px;
  font-size: 11px;
}

.buy-btn {
  background: #15803d;
  color: #fff;
  font-weight: 700;
}

.calc-btn {
  width: 100%;
  background: var(--secondary-bg);
  color: var(--text);
  border: 1px solid rgba(139, 147, 161, 0.3);
}

.order-btn {
  width: 100%;
}

.calc-result {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--secondary-bg);
  border: 1px solid rgba(139, 147, 161, 0.2);
}

.calc-result p {
  margin: 4px 0;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
}

.calc-result .calc-total {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(139, 147, 161, 0.25);
  font-weight: 700;
  font-size: 15px;
}

.calc-result .calc-note {
  display: block;
  margin-top: 8px;
  font-size: 11px;
  color: var(--hint);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.modal-overlay-hint {
  position: absolute;
  top: 16px;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.modal-overlay-hint span {
  display: inline-block;
  padding: 6px 14px;
  border: 1px solid #ffffff;
  border-radius: 20px;
}

.modal {
  background: var(--secondary-bg);
  color: var(--text);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 16px 18px 24px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: transparent;
  color: var(--hint);
  font-size: 18px;
  cursor: pointer;
}

.modal h2 {
  margin: 4px 0 0;
  font-size: 18px;
}

.modal h3 {
  margin: 14px 0 8px;
  font-size: 15px;
}

.modal hr {
  border: none;
  border-top: 1px solid rgba(139, 147, 161, 0.2);
  margin: 14px 0 0;
}

.form-status {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--link);
  min-height: 16px;
}

.form-status.error {
  color: #ff6b6b;
}

.scroll-top-btn {
  position: fixed;
  right: 16px;
  bottom: 20px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  z-index: 40;
}
