/* ==========================================================================
   Conheça a BAIC (linha do tempo)
   Uma estrada reta no centro: à frente do carro ela é cinza-clara; atrás dele
   fica o rastro grafite com a faixa branca tracejada. Os marcos alternam
   imagem e texto entre os lados (no celular, a estrada vai para a esquerda).
   Sem JS/GSAP ou com movimento reduzido, tudo aparece estático: estrada
   completa e carro estacionado no fim. O js/history.js liga a animação
   adicionando .is-animated.
   Com a seção de números logo abaixo, .is-continued estica a estrada até a
   borda de baixo: ela segue, sem emenda, pela seção seguinte.
   Pouco depois de o usuário chegar na seção, o js/history.js adiciona
   .is-dark: o fundo passa para um grafite escuro e o que era escuro (textos, rastro,
   pontos, conectores) clareia, numa transição só de cores.
   ========================================================================== */
.history {
  --rail: clamp(104px, 11vw, 176px); /* coluna central, onde passa a estrada */
  --road-w: 10px;
  --car-w: 34px;
  --dot: 18px;
  --radius: 12px;
  --pad-bottom: clamp(72px, 9vw, 144px);

  /* cores (a versão escura fica em .history.is-dark) */
  --h-bg: var(--bg-light);
  --h-ink: var(--color-black);          /* título, anos, destaques */
  --h-text: var(--color-graphite);      /* texto corrido */
  --h-road: var(--color-gray);          /* estrada à frente do carro */
  --h-trail: var(--color-graphite);     /* rastro atrás do carro */
  --h-lane: rgba(255, 255, 255, 0.85);  /* faixa tracejada do rastro */
  --h-dot-ring: var(--color-graphite);
  --h-dot-fill: var(--bg-light);
  --h-dot-halo: rgba(59, 63, 68, 0.12);
  --h-connector: rgba(59, 63, 68, 0.5);
  --h-media-bg: var(--color-gray);
  --h-media-line: rgba(29, 29, 27, 0.08);
  --h-fade: 1.4s ease; /* duração da troca de cores */

  position: relative;
  overflow: hidden; /* imagens e textos entram deslizando pelas laterais */
  padding: clamp(96px, 11vw, 168px) var(--gutter) var(--pad-bottom);
  background-color: var(--h-bg);
  color: var(--h-ink);
  transition: background-color var(--h-fade), color var(--h-fade);
}

.history.is-dark {
  --h-bg: var(--bg-dark);
  --h-ink: var(--color-white);
  --h-text: var(--color-gray);
  --h-road: #43474C;
  --h-trail: var(--color-gray);
  --h-lane: var(--bg-dark);
  --h-dot-ring: var(--color-gray);
  --h-dot-fill: var(--bg-dark);
  --h-dot-halo: rgba(217, 217, 217, 0.16);
  --h-connector: rgba(217, 217, 217, 0.5);
  --h-media-bg: #43474C;
  --h-media-line: rgba(255, 255, 255, 0.1);
}

.history__title {
  margin: 0 0 clamp(8px, 2vw, 24px);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(26px, 8vw, 80px); /* no celular "Conheça a BAIC" (≈10.4em) ocupa a largura toda */
  line-height: 1;
  letter-spacing: -0.005em;
  text-align: center;
}

/* o logo ocupa exatamente a altura das maiúsculas da Eurostile, apoiado na linha de base */
.history__title-logo {
  display: inline-block;
  width: auto;
  height: 0.7em;
  margin-left: 0.14em;
  vertical-align: baseline;
}

/* --------------------------------------------------------------------------
   Estrada, rastro e carro
   -------------------------------------------------------------------------- */
.history__timeline {
  position: relative;
  max-width: 1200px;
  margin: 0 auto;
}

.history__road {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: var(--road-w);
  margin-left: calc(var(--road-w) / -2);
  overflow: hidden;
  border-radius: var(--road-w);
  background-color: var(--h-road);
  transition: background-color var(--h-fade);
}

/* a estrada continua na seção "BAIC em números": vai até a borda de baixo, sem arremate */
.history.is-continued .history__road {
  bottom: calc(var(--pad-bottom) * -1);
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

/* o JS recorta o rastro (clip-path) até o meio do carro */
.history__trail {
  position: absolute;
  inset: 0;
  background-color: var(--h-trail);
  transition: background-color var(--h-fade);
}

/* faixa tracejada: cor sólida recortada por máscara (assim a cor pode transicionar) */
.history__trail::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background-color: var(--h-lane);
  -webkit-mask-image: repeating-linear-gradient(to bottom, #000 0 12px, transparent 12px 26px);
  mask-image: repeating-linear-gradient(to bottom, #000 0 12px, transparent 12px 26px);
  transition: background-color var(--h-fade);
}

.history__car {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: 0; /* sem animação: estacionado no fim da estrada */
  width: var(--car-w);
  height: auto;
  margin-left: calc(var(--car-w) / -2);
  filter: drop-shadow(0 8px 10px rgba(29, 29, 27, 0.25));
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.history.is-animated .history__car {
  top: 0;
  bottom: auto;
  will-change: transform;
}

/* --------------------------------------------------------------------------
   Marcos
   -------------------------------------------------------------------------- */
.history__list {
  position: relative;
  z-index: 1;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history__item {
  display: grid;
  grid-template-columns: 1fr var(--rail) 1fr;
  align-items: center;
  padding: clamp(40px, 5vw, 72px) 0;
}

/* a estrada começa antes do primeiro marco e termina depois do último */
.history__item:first-child {
  padding-top: clamp(120px, 13vw, 200px);
}

.history__item:last-child {
  padding-bottom: clamp(120px, 13vw, 200px);
}

.history__media {
  position: relative;
  grid-column: 1;
  grid-row: 1;
  margin: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background-color: var(--h-media-bg);
  transition: background-color var(--h-fade);
}

/* contorno fino por dentro: separa do fundo as imagens claras */
.history__media::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px var(--h-media-line);
  transition: box-shadow var(--h-fade);
  pointer-events: none;
}

.history__media img {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

/* o card do logo continua branco nas duas versões */
.history__media--logo {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 9;
  background-color: var(--color-white);
}

.history__media--logo img {
  width: 56%;
  aspect-ratio: auto;
  object-fit: contain;
}

/* ponto na estrada + conector tracejado até a imagem */
.history__marker {
  position: relative;
  grid-column: 2;
  grid-row: 1;
  height: var(--dot);
}

.history__dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--dot);
  height: var(--dot);
  margin: calc(var(--dot) / -2) 0 0 calc(var(--dot) / -2);
  border: 4px solid var(--h-dot-ring);
  border-radius: 50%;
  background-color: var(--h-dot-fill);
  box-shadow: 0 0 0 8px var(--h-dot-halo);
  transition: border-color var(--h-fade), background-color var(--h-fade), box-shadow var(--h-fade);
}

.history__connector {
  position: absolute;
  top: 50%;
  left: 0;
  right: 50%;
  border-top: 1.5px dashed var(--h-connector);
  transform-origin: right center; /* nasce no ponto e cresce até a imagem */
  transition: border-color var(--h-fade);
}

.history__body {
  grid-column: 3;
  grid-row: 1;
  max-width: 420px;
}

.history__year {
  margin: 0 0 14px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(40px, 4.6vw, 72px);
  line-height: 1;
  letter-spacing: -0.01em;
}

.history__text {
  margin: 0;
  font-size: clamp(16px, 1.2vw, 18px);
  line-height: 1.55;
  color: var(--h-text);
  transition: color var(--h-fade);
}

.history__text strong {
  font-weight: 700;
  color: var(--h-ink);
  transition: color var(--h-fade);
}

/* marcos pares: imagem à direita, texto à esquerda (alinhado à estrada) */
.history__item:nth-child(even) .history__media {
  grid-column: 3;
}

.history__item:nth-child(even) .history__connector {
  left: 50%;
  right: 0;
  transform-origin: left center;
}

.history__item:nth-child(even) .history__body {
  grid-column: 1;
  justify-self: end;
  text-align: right;
}

/* --------------------------------------------------------------------------
   Celular: estrada à esquerda, imagem e texto empilhados à direita
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .history {
    --rail: 52px;
    --road-w: 8px;
    --car-w: 26px;
    --dot: 16px;
    --radius: 10px;
  }

  /* respiro entre o título e o início da estrada (onde o carro parte) */
  .history__title {
    margin-bottom: 40px;
  }

  .history__road,
  .history__car {
    left: calc(var(--rail) / 2);
  }

  .history__item,
  .history__item:nth-child(even) {
    grid-template-columns: var(--rail) 1fr;
    padding: 36px 0;
  }

  .history__item:first-child {
    padding-top: 96px;
  }

  .history__item:last-child {
    padding-bottom: 96px;
  }

  .history__item .history__media,
  .history__item:nth-child(even) .history__media {
    grid-column: 2;
    grid-row: 1;
  }

  .history__item .history__marker,
  .history__item:nth-child(even) .history__marker {
    grid-column: 1;
    grid-row: 1;
  }

  .history__item .history__connector,
  .history__item:nth-child(even) .history__connector {
    left: 50%;
    right: 0;
    transform-origin: left center;
  }

  .history__item .history__body,
  .history__item:nth-child(even) .history__body {
    grid-column: 2;
    grid-row: 2;
    justify-self: start;
    max-width: none;
    margin-top: 20px;
    text-align: left;
  }

  .history__year {
    margin-bottom: 10px;
    font-size: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .history {
    --h-fade: 0s;
  }
}
