/* gbr-reviews — Google Business Reviews component (aether.dev)
 * Pure progressive enhancement: style the server-rendered (baked) markup;
 * gbr-reviews.js only refreshes numbers/dates/cards from the sync endpoint.
 *
 * Layouts (modifier on the .gbr root):
 *   .gbr--marquee — two horizontally infinite-scrolling rows in a rounded
 *                   container (default for new sites)
 *   .gbr--grid    — the previous static 3/2/1-column grid
 * Bare .gbr behaves as .gbr--grid (back-compat with earlier embeds).
 *
 * Theme via CSS custom properties (see README.md theming table). */

.gbr {
  --gbr-bg: transparent;
  --gbr-card: rgba(128, 128, 128, 0.07);
  --gbr-card-border: rgba(128, 128, 128, 0.22);
  --gbr-card-border-hover: rgba(128, 128, 128, 0.42);
  --gbr-text: inherit;
  /* Muted text (dates, "based on N reviews") is a translucent tint of the
     surrounding text colour, NOT a fixed mid-grey. A fixed grey only ever hits
     ~3.9:1 on a light card (WCAG AA body text needs 4.5:1); keying it to
     currentColor stays legible on light and dark skins alike. */
  --gbr-muted: color-mix(in srgb, currentColor 72%, transparent);
  --gbr-accent: #2563eb;
  /* Brand accents are fine as a fill/border/ring (3:1 threshold) but routinely
     fail the 4.5:1 body-text threshold when they colour TEXT on a background.
     --gbr-accent-text is the accent used for text only; it defaults to the
     brand accent so nothing changes for existing skins, and a skin whose
     accent-as-text fails contrast overrides just this one token. */
  --gbr-accent-text: var(--gbr-accent);
  --gbr-star: #fbbf24;
  --gbr-star-off: rgba(128, 128, 128, 0.3);
  --gbr-radius: 14px;
  --gbr-font: inherit;
  --gbr-shell: rgba(128, 128, 128, 0.05);       /* marquee container bg */
  --gbr-shell-border: var(--gbr-card-border);   /* marquee container border */
  --gbr-shell-radius: 18px;                     /* marquee container radius */

  background: var(--gbr-bg);
  color: var(--gbr-text);
  font-family: var(--gbr-font);
}

/* ---- summary panel ---- */
.gbr-summary {
  display: flex;
  align-items: center;
  gap: 28px;
  flex-wrap: wrap;
  margin-bottom: 40px;
}
.gbr-rating {
  font-size: 72px;
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: -0.04em;
  color: var(--gbr-text);
  font-variant-numeric: tabular-nums;
}
.gbr-summary-meta {
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.gbr-basis {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 14.5px;
  color: var(--gbr-muted);
}
.gbr-glogo {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: inline-block;
}
.gbr-cta {
  font-size: 14px;
  font-weight: 700;
  /* accent-as-TEXT (needs 4.5:1) — not the fill/ring token */
  color: var(--gbr-accent-text, var(--gbr-accent));
  text-decoration: none;
  width: fit-content;
}
.gbr-cta:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---- star rows (base row + width-clipped filled overlay: handles 4.7 etc.) ---- */
.gbr-stars {
  position: relative;
  display: inline-flex;
  line-height: 0;
  color: var(--gbr-star-off);
}
.gbr-stars-row {
  display: inline-flex;
  gap: 2px;
  white-space: nowrap;
}
.gbr-stars-row svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}
.gbr-stars-on {
  position: absolute;
  top: 0;
  left: 0;
  overflow: hidden;
  width: var(--gbr-fill, 100%);
  color: var(--gbr-star);
}
.gbr-card .gbr-stars-row svg {
  width: 15px;
  height: 15px;
}

/* ---- cards (shared) ---- */
.gbr-card {
  display: flex;
  flex-direction: column;
  gap: 13px;
  background: var(--gbr-card);
  border: 1px solid var(--gbr-card-border);
  border-radius: var(--gbr-radius);
  padding: 24px 22px 20px;
}
.gbr-card:hover {
  border-color: var(--gbr-card-border-hover);
}
/* keyboard: unique marquee cards are tabbable (tabindex="0") so :focus-within
   can pause the loop; visible ring for keyboard users only */
.gbr-card:focus-visible {
  outline: 2px solid var(--gbr-accent);
  outline-offset: 2px;
}

.gbr-text {
  margin: 0;
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--gbr-text);
  /* clamp long reviews; JS adds .gbr-fade when actually clamped */
  display: -webkit-box;
  -webkit-line-clamp: 6;
  line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.gbr-text.gbr-fade {
  -webkit-mask-image: linear-gradient(180deg, #000 62%, transparent 97%);
  mask-image: linear-gradient(180deg, #000 62%, transparent 97%);
}

.gbr-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}
.gbr-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  /* neutral until gbr-reviews.js assigns the deterministic pastel hue */
  background: rgba(128, 128, 128, 0.25);
  color: var(--gbr-text);
  user-select: none;
}
.gbr-author {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--gbr-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gbr-date {
  font-size: 12.5px;
  color: var(--gbr-muted);
  white-space: nowrap;
  margin-left: auto;
  padding-left: 8px;
}

/* =========================================================================
   .gbr--grid — static responsive grid (previous default; bare .gbr = grid)
   ========================================================================= */
.gbr-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
@media (max-width: 1024px) {
  .gbr-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .gbr-grid { grid-template-columns: 1fr; }
}

/* =========================================================================
   .gbr--marquee — two counter-scrolling rows in a rounded shell
   Markup: .gbr-carousel > .gbr-row[.gbr-row--reverse] > .gbr-track >
           .gbr-track-seg + .gbr-track-seg[aria-hidden] (identical copies).
   The CSS animation needs no JS; JS only rebuilds rows from live data.
   ========================================================================= */
.gbr-carousel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 0;
  background: var(--gbr-shell);
  border: 1px solid var(--gbr-shell-border);
  border-radius: var(--gbr-shell-radius);
  overflow: hidden;
}
/* base = reduced-motion / no-animation fallback: swipeable static rows */
.gbr--marquee .gbr-row {
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
  padding: 0 16px;
}
.gbr--marquee .gbr-track {
  display: flex;
  width: max-content;
}
.gbr-track-seg {
  display: flex;
  flex-shrink: 0;
}
/* width-fill repeats: visual only, never in the accessibility tree */
.gbr-track-fill {
  display: flex;
  flex-shrink: 0;
}
.gbr--marquee .gbr-card {
  width: 340px;
  flex-shrink: 0;
  margin-right: 14px;
  scroll-snap-align: start;
}
.gbr--marquee .gbr-text {
  -webkit-line-clamp: 4;
  line-clamp: 4;
  font-size: 15px;
}
@media (max-width: 640px) {
  .gbr--marquee .gbr-card { width: 280px; }
}
@media (prefers-reduced-motion: reduce) {
  /* static mode: each review appears once; duplicates are for the loop only */
  .gbr-track-seg[aria-hidden="true"],
  .gbr-track-fill { display: none; }
}

/* ---- motion ---- */
@media (prefers-reduced-motion: no-preference) {
  /* marquee: two slow counter-directional loops; seamless via -50% on the
     doubled track (each seg carries the trailing 14px gap as margin-right,
     so half the track width lands exactly on the second copy's start) */
  .gbr--marquee .gbr-row {
    overflow: hidden;
    scroll-snap-type: none;
    padding: 0;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 52px, #000 calc(100% - 52px), transparent);
    mask-image: linear-gradient(90deg, transparent, #000 52px, #000 calc(100% - 52px), transparent);
  }
  .gbr--marquee .gbr-track {
    animation: gbr-marquee 70s linear infinite;
  }
  .gbr--marquee .gbr-row--reverse .gbr-track {
    animation-direction: reverse;
    animation-duration: 85s;
  }
  .gbr-carousel:hover .gbr-track,
  .gbr-carousel:focus-within .gbr-track {
    animation-play-state: paused;
  }
  @keyframes gbr-marquee {
    from { transform: translateX(0); }
    to   { transform: translateX(-50%); }
  }

  .gbr-card {
    transition: border-color 0.3s ease;
  }
  /* scroll-in reveal — grid: per-card stagger; marquee: the shell as one */
  .gbr.gbr-js:not(.gbr--marquee) .gbr-card {
    opacity: 0;
    transform: translateY(8px);
    transition:
      opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
      transform 0.5s cubic-bezier(0.16, 1, 0.3, 1),
      border-color 0.3s ease;
  }
  .gbr.gbr-js:not(.gbr--marquee) .gbr-card.gbr-in {
    opacity: 1;
    transform: none;
  }
  .gbr--marquee.gbr-js .gbr-carousel {
    opacity: 0;
    transform: translateY(8px);
    transition:
      opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
      transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .gbr--marquee.gbr-js .gbr-carousel.gbr-in {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 640px) {
  .gbr-rating { font-size: 56px; }
  .gbr-summary { gap: 20px; margin-bottom: 30px; }
}
