/* ===== Stats & Facts Section ===== */
.stats-section {
  background: #3e3e40;
  padding: 0;
  font-family: var(--font, 'General Sans', -apple-system, BlinkMacSystemFont, sans-serif);
  border-radius: 2rem;
  position: relative;
  z-index: 7;
  margin: -2rem 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}


.stats-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 2;
}

/* Header */
.stats-header {
  position: relative;
  text-align: center;
  padding: 6rem 2.5rem 5rem;
  overflow: hidden;
}

/* Subtle noise in header so it matches the image area */
.stats-header::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='256' height='256'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='256' height='256' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
  opacity: 0.16;
}

.stats-title {
  font-family: var(--font-display, 'Apfel Grotezk', sans-serif);
  font-size: clamp(4rem, 9vw, 120px);
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 1rem;
  line-height: 1;
  letter-spacing: -0.02em;
}

.stats-subtitle {
  font-size: 1.0625rem;
  line-height: 1.65;
  color: rgba(255, 255, 255, 0.5);
  max-width: 400px;
  margin: 0 auto;
}

/* Image wrap — mountain image sits under the same #3e3e40 tone */
.stats-image-wrap {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Solid base colour behind the mountain image */
  background: #303030;
}

/* Mountain background image */
.stats-image-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, rgba(48, 48, 48, 0.85) 0%, rgba(48, 48, 48, 0.4) 60%, rgba(48, 48, 48, 1) 100%),
    url('https://framerusercontent.com/images/KCORnc7dW4IY6C30ZKFlmMg2PuY.png');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  z-index: 0;
}

/* Overlay — dark tint + top gradient fading into section colour */
.stats-image-wrap::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, #3e3e40 0%, #3e3e40 20%, rgba(62, 62, 64, 0.1) 60%, rgba(62, 62, 64, 0.5) 100%),
    rgba(62, 62, 64, 0.3);
  z-index: 1;
}

/* Noise texture — sits above overlay and grid lines so it's visible over the image */
.stats-image-wrap .stats-noise {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='256' height='256'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='256' height='256' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
  opacity: 0.22;
}

/* Grid lines: verticals only.
   Horizontal row divider comes from .stats-card border-bottom — a 50% overlay line doubled it. */
.stats-image-wrap .stats-grid-lines {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 25% 50%;
  background-repeat: repeat;
}

/* Stats grid — 4×2, fills the image area */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  flex: 1;
  min-height: 100vh;
  position: relative;
  z-index: 3;
  padding-bottom: clamp(15rem, 28vmin, 24rem); /* clears bottom ticker band + breathing room */
}

.stats-card {
  padding: 3rem 2.5rem;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
}

.stats-card:nth-child(4n) {
  border-right: none;
}

.stats-card:nth-child(5),
.stats-card:nth-child(6),
.stats-card:nth-child(7),
.stats-card:nth-child(8) {
  border-bottom: none;
}

/* Bottom logo ticker — tall enough for Oswald size; centered; soft side fades (no harsh clip) */
.stats-ticker {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: clamp(11.5rem, 20vmin, 17rem);
  padding-block: clamp(0.85rem, 2.2vmin, 1.5rem);
  padding-inline: 0;
  overflow: hidden;
  z-index: 5;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  background: linear-gradient(
    to top,
    rgba(48, 48, 48, 1) 0%,
    rgba(48, 48, 48, 0.88) 35%,
    rgba(48, 48, 48, 0.35) 100%
  );
  mask-image: linear-gradient(
    to right,
    transparent 0%,
    #000 5%,
    #000 95%,
    transparent 100%
  );
  -webkit-mask-image: linear-gradient(
    to right,
    transparent 0%,
    #000 5%,
    #000 95%,
    transparent 100%
  );
}

.stats-ticker-track {
  display: flex;
  align-items: center;
  gap: clamp(2.5rem, 5vw, 4rem);
  white-space: nowrap;
  animation: statsTickerScroll 52s linear infinite;
  will-change: transform;
}

.stats-ticker-item {
  font-family: var(--font-oswald, var(--font-system));
  font-weight: 700;
  font-size: clamp(4.25rem, 8vw, 7.25rem);
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: none;
  color: rgba(255, 255, 255, 0.48);
  opacity: 1;
  position: relative;
  flex-shrink: 0;
}

/* Small ™ sitting on the top-right of imTheo */
.stats-ticker-item::after {
  content: '™';
  position: absolute;
  top: 0.04em;
  right: -0.42em;
  font-size: 0.28em;
  letter-spacing: 0;
  line-height: 1;
}

@keyframes statsTickerScroll {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

.stats-value {
  font-family: var(--font-oswald, var(--font-system));
  font-size: clamp(3rem, 6vw, 90px);
  font-weight: 700;
  color: #ffffff;
  line-height: 1;
  margin-bottom: 1rem;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stats-label {
  font-family: var(--font-display, 'Apfel Grotezk', sans-serif);
  font-size: 1.0625rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats-desc {
  font-size: 0.9375rem;
  line-height: 1.65;
  color: rgba(255, 255, 255, 0.4);
  max-width: 380px;
}

/* Scroll-in + count-up (stats-animate.js sets data-stats-anim; no JS = no attr = no hiding) */
.stats-section[data-stats-anim='on']
  .stats-card:not(.stats-card--inview):not(.stats-card-empty)
  .stats-value,
.stats-section[data-stats-anim='on']
  .stats-card:not(.stats-card--inview):not(.stats-card-empty)
  .stats-label,
.stats-section[data-stats-anim='on']
  .stats-card:not(.stats-card--inview):not(.stats-card-empty)
  .stats-desc {
  opacity: 0;
  transform: translate3d(0, 22px, 0);
  transition:
    opacity 0.62s var(--ease-smooth-opacity, cubic-bezier(0.33, 1, 0.68, 1)),
    transform 0.7s var(--ease-smooth-transform, cubic-bezier(0.22, 1, 0.42, 1));
  transition-delay: 0ms;
}

.stats-card--inview .stats-value {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  transition:
    opacity 0.74s var(--ease-smooth-opacity, cubic-bezier(0.33, 1, 0.68, 1)),
    transform 0.82s var(--ease-smooth-transform, cubic-bezier(0.22, 1, 0.42, 1));
  transition-delay: 0ms;
}

.stats-card--inview .stats-label {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  transition:
    opacity 0.7s var(--ease-smooth-opacity, cubic-bezier(0.33, 1, 0.68, 1)),
    transform 0.76s var(--ease-smooth-transform, cubic-bezier(0.22, 1, 0.42, 1));
  transition-delay: 0.06s;
}

.stats-card--inview .stats-desc {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  transition:
    opacity 0.7s var(--ease-smooth-opacity, cubic-bezier(0.33, 1, 0.68, 1)),
    transform 0.76s var(--ease-smooth-transform, cubic-bezier(0.22, 1, 0.42, 1));
  transition-delay: 0.11s;
}

@media (prefers-reduced-motion: reduce) {
  .stats-section[data-stats-anim='on']
    .stats-card:not(.stats-card--inview):not(.stats-card-empty)
    .stats-value,
  .stats-section[data-stats-anim='on']
    .stats-card:not(.stats-card--inview):not(.stats-card-empty)
    .stats-label,
  .stats-section[data-stats-anim='on']
    .stats-card:not(.stats-card--inview):not(.stats-card-empty)
    .stats-desc {
    opacity: 1;
    transform: none;
  }

  .stats-card--inview .stats-value,
  .stats-card--inview .stats-label,
  .stats-card--inview .stats-desc {
    transition: none;
  }

  .stats-ticker-track {
    animation: none;
    transform: none;
  }
}

/* Tablet / phone: remove stagger “holes”, single column, readable type */
@media (max-width: 900px) {
  .stats-section {
    border-radius: 1.25rem;
    margin: -1rem 0;
  }

  .stats-header {
    padding: clamp(3rem, 9vw, 4.5rem) clamp(1rem, 4vw, 1.5rem) clamp(2.25rem, 6vw, 3.25rem);
  }

  .stats-title {
    font-size: clamp(2.35rem, 10vw, 3.75rem);
    line-height: 1.02;
  }

  .stats-subtitle {
    font-size: clamp(0.9rem, 3.1vw, 1.02rem);
    max-width: 22rem;
    line-height: 1.6;
  }

  .stats-image-wrap {
    min-height: auto;
  }

  /* Softer grid: verticals only (stacked cards — skip mid horizontal) */
  .stats-image-wrap .stats-grid-lines {
    background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
    background-size: 50% 40%;
    background-repeat: repeat;
    opacity: 0.45;
  }

  /* Spacer cells only exist for desktop stagger — hide so layout doesn’t break */
  .stats-card-empty {
    display: none !important;
  }

  .stats-grid {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    min-height: auto;
    padding: clamp(1.25rem, 3vw, 1.75rem) clamp(1rem, 4vw, 1.5rem);
    padding-bottom: clamp(7.25rem, 32vw, 10rem); /* above ticker band */
    gap: 0;
  }

  /* Reading order: years → projects → customers → awards */
  .stats-grid > .stats-card:nth-child(1) {
    order: 1;
  }

  .stats-grid > .stats-card:nth-child(6) {
    order: 2;
  }

  .stats-grid > .stats-card:nth-child(3) {
    order: 3;
  }

  .stats-grid > .stats-card:nth-child(8) {
    order: 4;
  }

  .stats-card:not(.stats-card-empty) {
    border-right: none;
    border-top: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding: clamp(1.65rem, 4.5vw, 2.15rem) 0;
    align-items: flex-start;
    text-align: left;
    width: 100%;
    max-width: min(36rem, 100%);
    margin-inline: auto;
    justify-content: flex-start;
  }

  /* Last stat: no divider below */
  .stats-grid > .stats-card:nth-child(8) {
    border-bottom: none;
  }

  .stats-value {
    font-size: clamp(2.35rem, 11vw, 3.5rem);
    margin-bottom: 0.65rem;
  }

  .stats-label {
    font-size: clamp(0.8125rem, 2.4vw, 0.9375rem);
    margin-bottom: 0.5rem;
  }

  .stats-desc {
    font-size: clamp(0.875rem, 2.6vw, 0.9375rem);
    line-height: 1.62;
    max-width: 100%;
    color: rgba(255, 255, 255, 0.48);
  }

  .stats-ticker {
    height: auto;
    min-height: clamp(5.75rem, 22vw, 8rem);
    padding-block: clamp(0.65rem, 2.5vw, 1.1rem);
    align-items: center;
    background: linear-gradient(
      to top,
      rgba(48, 48, 48, 1) 0%,
      rgba(48, 48, 48, 0.9) 40%,
      rgba(48, 48, 48, 0.35) 100%
    );
  }

  .stats-ticker-track {
    gap: clamp(1.5rem, 6vw, 2.5rem);
  }

  .stats-ticker-item {
    font-size: clamp(2.35rem, 11vw, 3.65rem);
    letter-spacing: 0.055em;
    line-height: 1;
  }
}

@media (max-width: 900px) and (prefers-reduced-motion: reduce) {
  .stats-ticker-track {
    animation: none;
    transform: none;
  }
}

@media (max-width: 380px) {
  .stats-grid {
    padding-left: 0.875rem;
    padding-right: 0.875rem;
  }

  .stats-value {
    font-size: clamp(2rem, 12vw, 2.65rem);
  }
}
