/* Counter Scroll — block styles */

.counter-scroll {
  position: relative;
  /* Width + margin are set at runtime in JS (full-bleed by measuring the
     block's actual left offset and pulling it back to the viewport edge).
     CSS just provides safe defaults for first paint before JS runs. */
  /* Full-bleed at first paint. The JS below re-measures and corrects for
     asymmetric containers, but in a centred one (Dawn's page-width wrapper)
     this already matches what the JS computes, so nothing shifts. Leaving it
     at width:100% meant every block rendered inset until its script finished
     downloading — a visible gap on every load. */
  width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  padding: var(--cs-padding-y, 40px) 1.5rem;
  background-color: var(--cs-bg-color, #333333);
  color: var(--cs-text-color, #ffffff);
  overflow: hidden;
  isolation: isolate;
  box-sizing: border-box;
}

.counter-scroll--bg-image .counter-scroll__bg {
  position: absolute;
  inset: 0;
  z-index: 0;
}
/* Explicit position + z-index so themes that inject `img { position:
   relative }` or a stacking context can't accidentally paint the image
   above our overlay. */
.counter-scroll__bg-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 0;
}
.counter-scroll__overlay {
  /* Dawn ships a rule (roughly `.color-* :empty:not([class])`) that
     collapses empty leaf elements, and it wins normal specificity
     against our block-scoped class. !important is the reliable fix. */
  display: block !important;
  position: absolute;
  inset: 0;
  background-color: rgba(0, 0, 0, var(--cs-overlay-alpha, 0.35));
  pointer-events: none;
  z-index: 1;
}

.counter-scroll__content {
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
}

/* Heading + supporting text inherit their size from the theme's h2 / p
   styles — we intentionally don't declare font-size here so the block
   matches the merchant's storefront typography scale. Value font-size
   is a separate, animated concern (see .counter-scroll__number). */
.counter-scroll__title {
  margin: 0 0 0.75rem;
  line-height: 1.2;
  color: var(--cs-text-color, #fff);
}

.counter-scroll__intro {
  margin: 0 auto 2.75rem;
  max-width: 720px;
  /* Follow the theme's body font-size (1em = parent's computed size,
     which walks up to body), floored at 1rem so themes with tiny p
     defaults (like Horizon) don't render this too small. Works for
     both Dawn (large body) and Horizon (small body). */
  font-size: max(1rem, 1em);
  line-height: 1.55;
  opacity: 0.85;
}
.counter-scroll__intro p { margin: 0 0 0.5rem; }
.counter-scroll__intro p:last-child { margin-bottom: 0; }

/* Grid: 4 cols → 2 cols (≤900px) → 1 col (≤600px).
   If the merchant only filled in 3 counters, force 3-up on desktop too. */
.counter-scroll__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(1.5rem, 3vw, 2.5rem);
  align-items: start;
}
.counter-scroll--count-1 .counter-scroll__grid { grid-template-columns: minmax(0, 1fr); max-width: 320px; margin: 0 auto; }
.counter-scroll--count-2 .counter-scroll__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 720px; margin: 0 auto; }
.counter-scroll--count-3 .counter-scroll__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

@media (max-width: 900px) {
  .counter-scroll__grid,
  .counter-scroll--count-3 .counter-scroll__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 600px) {
  .counter-scroll__grid,
  .counter-scroll--count-3 .counter-scroll__grid,
  .counter-scroll--count-2 .counter-scroll__grid {
    grid-template-columns: minmax(0, 1fr);
    max-width: 320px;
    margin: 0 auto;
  }
}

.counter-scroll__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  min-width: 0;         /* grid items shrink below content size when needed */
  overflow: hidden;     /* clip anything that still overflows into the next column */
}

.counter-scroll__number {
  font-family: var(--cs-font-family, "Helvetica Neue", Arial, sans-serif);
  font-style: var(--cs-font-style, normal);
  font-weight: var(--cs-font-weight, 800);
  /* Cap the max at 4rem so 8-char fat-font values don't overrun the column. */
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
  /* Neutral letter-spacing so wide "display" fonts don't visually collide. */
  letter-spacing: 0;
  /* Never wrap: keep values with hyphens (e.g. "2-day") on a single line. */
  white-space: nowrap;
  color: var(--cs-number-color, #ff8820);
  font-variant-numeric: tabular-nums; /* stops digits shifting horizontally as they count up */
  will-change: contents;
}

.counter-scroll__desc {
  margin: 0;
  font-size: max(1rem, 1em);
  line-height: 1.4;
  max-width: 24ch;
  opacity: 0.9;
}

/* Reduced motion: render the final value immediately, no count-up */
@media (prefers-reduced-motion: reduce) {
  .counter-scroll__number {
    will-change: auto;
  }
}
