/* Shared by the front end and editor; native scrolling is the no-JavaScript fallback. */
.wp-block-post-template.is-style-racemate-event-rows {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 0;
  list-style: none;
}
.is-style-racemate-event-rows > li { margin: 0; min-width: 0; }
.wp-block-group.racemate-event-row {
  display: grid;
  grid-template-columns: 3.5rem minmax(0, 1fr) 6rem 6rem auto;
  align-items: center;
  gap: 1.5rem;
  padding-block: 1.5rem;
  border-bottom: 1px solid var(--wp--preset--color--border-light, #ddd);
}
.racemate-event-row > * { margin: 0; min-width: 0; }
.racemate-event-row__identity h3 { margin: 0; font-size: 1.25rem; overflow-wrap: anywhere; }
.racemate-event-row__identity p { margin: .35rem 0 0; color: #6b7280; }
.racemate-event-row__distance, .racemate-event-row__elevation { text-align: center; font-weight: 600; }
.racemate-event-row .wp-block-buttons { justify-content: flex-end; }
@media (width < 782px) {
  .wp-block-group.racemate-event-row { grid-template-columns: 3rem minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; }
  .racemate-event-row__identity { grid-column: 2 / -1; }
  .racemate-event-row__distance { grid-column: 2; text-align: start; }
  .racemate-event-row__elevation { grid-column: 3; text-align: start; }
  .racemate-event-row .wp-block-buttons { grid-column: 2 / -1; justify-content: flex-start; }
}

.racemate-event-card > .wp-block-columns > .wp-block-column:first-child:not(:has(*)) {
  /* WordPress omits the image block when no featured image is available. */
  display: none;
}

.racemate-event-card > .wp-block-columns > .wp-block-column:first-child:not(:has(*)) + .wp-block-column {
  flex-grow: 1;
}

/* Visible stats share equal columns, including when the middle value is missing. */
.racemate-event-stats:not([data-block]) {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  justify-items: center;
}

/* Collapse empty data in rendered cards; keep every block editable in the editor. */
.racemate-event-stats:not([data-block]) > .wp-block-group:has(> p:last-child:empty),
.racemate-event-stats:not([data-block]):not(:has(> .wp-block-group > p:last-child:not(:empty))) {
  display: none;
}

.wp-block-post-template.is-style-racemate-event-cards {
  --racemate-card-gap: 1.5rem;
  --racemate-card-gutter: .25rem;
  /* One full card, one gap and one fifth of the next card. */
  --racemate-card-width: calc((100% + var(--racemate-card-gutter) - var(--racemate-card-gap)) / 1.2);
  /* Contain absolute screen-reader text from links in off-screen cards. */
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  gap: var(--racemate-card-gap);
  scrollbar-width: none;
  padding: .25rem var(--racemate-card-gutter) 1rem;
  list-style: none;
}

.wp-block-post-template.is-style-racemate-event-cards:not(.racemate-carousel__track) {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scroll-padding-inline: var(--racemate-card-gutter);
}

.wp-block-post-template.is-style-racemate-event-cards::-webkit-scrollbar {
  display: none;
}

.wp-block-post-template.is-style-racemate-event-cards > li {
  flex: 0 0 var(--racemate-card-width);
  min-width: 0;
  margin-block: 0;
  scroll-snap-align: start;
}

@media (width < 782px) {
  /* Let this carousel cross the page gutter; keep spacing inside the scrolling list. */
  .has-global-padding > .wp-block-query.racemate-upcoming-events:has(> .wp-block-post-template.is-style-racemate-event-cards) {
    max-width: none;
    margin-left: calc(-1 * var(--wp--style--root--padding-left, 0px)) !important;
    margin-right: calc(-1 * var(--wp--style--root--padding-right, 0px)) !important;
  }

  .has-global-padding > .wp-block-query.racemate-upcoming-events > .wp-block-post-template.is-style-racemate-event-cards {
    --racemate-card-gutter: 1rem;
  }
}

@media (min-width: 782px) {
  .wp-block-post-template.is-style-racemate-event-cards {
    /* The native maximum column count, followed by one quarter of a card. */
    --racemate-card-width: calc((100% + var(--racemate-card-gutter) - var(--racemate-card-columns, 1) * var(--racemate-card-gap)) / (var(--racemate-card-columns, 1) + .25));
  }
}

/* Share image/header/body/stats/actions rows without measuring content in JavaScript.
   Gutenberg keeps its native editing layout, including selectable empty blocks. */
.wp-block-query .wp-block-post-template.is-style-racemate-event-cards:not([data-block]) {
  --racemate-card-rows: subgrid;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: var(--racemate-card-width);
  grid-template-columns: none;
  grid-template-rows: auto auto 1fr auto auto;
  row-gap: 0;
}

.wp-block-post-template.is-style-racemate-event-cards:not([data-block]) > li,
.racemate-event-card:not([data-block]),
.racemate-event-card:not([data-block]) > .wp-block-columns,
.racemate-event-card:not([data-block]) > .wp-block-columns > .wp-block-column:last-child {
  display: grid;
  grid-row: 1 / -1;
  grid-template-rows: subgrid;
  row-gap: 0;
}

.racemate-event-card:not([data-block]) {
  grid-template-rows: var(--racemate-card-rows, auto auto 1fr auto auto);
}

.racemate-event-card:not([data-block]) > .wp-block-columns {
  grid-template-columns: minmax(0, 1fr);
}

.racemate-event-card:not([data-block]) > .wp-block-columns > .wp-block-column:first-child {
  grid-row: 1;
  grid-column: 1;
  min-height: 0;
}

.racemate-event-card:not([data-block]) > .wp-block-columns > .wp-block-column:last-child {
  grid-row: 2 / -1;
  grid-column: -2 / -1;
  min-width: 0;
}

.racemate-event-card:not([data-block]) .racemate-event-card-header { grid-row: 1; }
.racemate-event-card:not([data-block]) .wp-block-post-excerpt { grid-row: 2; }
.racemate-event-card:not([data-block]) .racemate-event-stats { grid-row: 3; }
.racemate-event-card:not([data-block]) .wp-block-buttons { grid-row: 4; }

@media (min-width: 782px) {
  .racemate-event-card:not([data-block]) {
    grid-template-rows: var(--racemate-card-rows, auto 1fr auto auto);
  }

  .wp-block-post-template.is-style-racemate-event-cards:not([data-block]) {
    grid-template-rows: auto 1fr auto auto;
  }

  .racemate-event-card:not([data-block]) > .wp-block-columns:has(.wp-block-post-featured-image) {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  }

  .racemate-event-card:not([data-block]) > .wp-block-columns > .wp-block-column:first-child,
  .racemate-event-card:not([data-block]) > .wp-block-columns > .wp-block-column:last-child {
    grid-row: 1 / -1;
  }
}

.wp-block-racemate-event-date.racemate-event-date--badge {
  display: flex;
  flex: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 2.75rem;
  margin: 0;
  line-height: 1;
  text-align: center;
}

.racemate-event-date__day {
  font-size: 1.8em;
  font-weight: 700;
}

.racemate-event-date__month {
  margin-top: .25em;
  font-size: .85em;
  text-transform: uppercase;
}

.wp-block-racemate-event-location {
  display: flex;
  align-items: baseline;
  gap: .4em;
}

.wp-block-racemate-event-location::before {
  content: '';
  flex: 0 0 1em;
  height: 1em;
  align-self: center;
  background-color: currentColor;
  mask: url('../images/location-pin.svg') center / contain no-repeat;
}

