/**
 * Sundahls Mascus carousel.
 *
 * Styled after sundahls.se: square corners, hard offset shadows, Lato bold
 * italic titles, navy text and the red accent. Fonts are the site's own
 * (Lato and Noto Sans JP are already loaded by Divi).
 *
 * Everything is scoped under .sm-carousel so nothing leaks into Divi.
 * Override the custom properties below from the child theme, e.g.
 *   .sm-carousel { --sm-accent: #e02a20; --sm-speed: 60s; }
 */

.sm-carousel {
  --sm-card-bg: #fff;
  --sm-card-color: #173140; /* the card owns its background, so it owns its text color too */
  --sm-accent: #e02a20;     /* title on hover, focus outline */
  --sm-muted: #5d6f78;
  --sm-shadow: #c1c5c7;     /* hard offset shadow, as on sundahls.se */
  --sm-title-font: Lato, "Noto Sans JP", Helvetica, Arial, sans-serif;
  --sm-placeholder: #e1e5e7;
  --sm-card-width: 22rem;
  --sm-speed: 75s;
  --sm-gap: 1rem;
  --sm-fade: 8%;

  width: 100%;
  /* hidden is the fallback for Safari < 16, which ignores clip. */
  overflow-x: hidden;
  overflow-x: clip;
  /* mask-image clips painting to this box, so leave room for the offset
     shadow (10px below the card on hover). */
  padding-block: 0.5rem 1.5rem;
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 var(--sm-fade), #000 calc(100% - var(--sm-fade)), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 var(--sm-fade), #000 calc(100% - var(--sm-fade)), transparent 100%);
}

@media (min-width: 768px) {
  .sm-carousel {
    --sm-card-width: 35rem;
    --sm-gap: 1.5rem;
  }
}

/*
 * Near full width: break out of the (centered) Divi column to the viewport,
 * minus a gutter on each side. The gutter is wider than a desktop scrollbar,
 * so 100vw including the scrollbar never causes horizontal page scroll.
 * Positioned with `left` rather than margins, because themes force
 * `margin-inline: auto !important` on content children (block themes do).
 */
.sm-carousel.sm-carousel--bleed {
  --sm-bleed-gutter: 1rem;
  position: relative;
  left: calc(50% - 50vw + var(--sm-bleed-gutter));
  width: calc(100vw - 2 * var(--sm-bleed-gutter));
  max-width: none;
  margin-left: 0;
  margin-right: 0;
}

@media (min-width: 768px) {
  .sm-carousel.sm-carousel--bleed {
    --sm-bleed-gutter: 2rem;
  }
}

@media (min-width: 1024px) {
  .sm-carousel {
    --sm-speed: 90s;
    --sm-fade: 4%;
  }
}

.sm-carousel .sm-carousel__track {
  display: flex;
  align-items: stretch;
  gap: var(--sm-gap);
  width: max-content;
  padding-right: var(--sm-gap); /* trailing gap so the three copies are evenly spaced */
  animation: sm-marquee var(--sm-speed) linear infinite;
}

.sm-carousel:hover .sm-carousel__track,
.sm-carousel:focus-within .sm-carousel__track {
  animation-play-state: paused;
}

@keyframes sm-marquee {
  from { transform: translateX(0); }
  to { transform: translateX(calc(-100% / 3)); } /* one copy of three */
}

.sm-carousel .sm-carousel__item {
  flex-shrink: 0;
  display: flex;
}

/* Few items: no loop, just a centered row. */
.sm-carousel.sm-carousel--static {
  -webkit-mask-image: none;
  mask-image: none;
}

.sm-carousel--static .sm-carousel__track {
  animation: none;
  width: auto;
  flex-wrap: wrap;
  justify-content: center;
  padding-right: 0;
}

.sm-carousel--static .sm-carousel__item,
.sm-carousel--static .sm-card {
  max-width: 100%; /* never wider than the Divi column */
}

/* Card */

.sm-carousel .sm-card {
  display: flex;
  width: var(--sm-card-width);
  max-width: calc(100vw - 2.5rem);
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  color: var(--sm-card-color);
  text-decoration: none;
  background: var(--sm-card-bg);
  border-radius: 0;
  box-shadow: 8px 8px 0 var(--sm-shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.sm-carousel .sm-card:hover {
  transform: translate(-2px, -2px);
  box-shadow: 10px 10px 0 var(--sm-shadow);
}

.sm-carousel .sm-card:focus-visible {
  outline: 2px solid var(--sm-accent);
  outline-offset: 2px;
}

.sm-carousel .sm-card__media {
  position: relative;
  flex-shrink: 0;
  width: 40%;
  aspect-ratio: 5 / 3; /* minimum height; stretches when the text column is taller */
  align-self: stretch;
  background: var(--sm-placeholder);
}

.sm-carousel .sm-card__img,
.sm-carousel .sm-card__placeholder {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  margin: 0;
  object-fit: cover;
  border: 0;
  border-radius: 0;
}

.sm-carousel .sm-card__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
}

/* Defensive resets: Divi styles h3/p globally. */
.sm-carousel .sm-card h3,
.sm-carousel .sm-card p {
  margin: 0;
  padding: 0;
  color: inherit;
  font-family: inherit;
  letter-spacing: normal;
  text-transform: none;
  text-decoration: none;
}

.sm-carousel .sm-card .sm-card__title {
  overflow: hidden;
  font-family: var(--sm-title-font);
  font-size: 1rem;
  font-style: italic;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.2s ease;
}

.sm-carousel .sm-card:hover .sm-card__title {
  color: var(--sm-accent);
}

.sm-carousel .sm-card .sm-card__subtitle {
  overflow: hidden;
  color: var(--sm-muted);
  font-size: 0.75rem;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sm-carousel .sm-card__meta {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.75rem;
}

.sm-carousel .sm-card__year {
  text-align: right;
}

.sm-carousel .sm-card .sm-card__label {
  color: var(--sm-muted);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.3;
}

.sm-carousel .sm-card .sm-card__value {
  margin-top: 0.25rem;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
}

.sm-carousel .sm-card .sm-card__hours {
  color: var(--sm-muted);
  font-size: 0.75rem;
  line-height: 1.3;
  white-space: nowrap;
}

@media (min-width: 768px) {
  .sm-carousel .sm-card__body {
    padding: 1.25rem;
  }

  .sm-carousel .sm-card .sm-card__title {
    font-size: 1.25rem;
  }

  .sm-carousel .sm-card .sm-card__subtitle {
    margin-top: 0.25rem;
    font-size: 1rem;
  }

  .sm-carousel .sm-card .sm-card__label {
    font-size: 0.875rem;
  }

  .sm-carousel .sm-card .sm-card__value {
    font-size: 1.125rem;
  }

  .sm-carousel .sm-card .sm-card__hours {
    font-size: 0.875rem;
  }
}

/* Reduced motion: no loop, single copy, swipe/scroll by hand. */
@media (prefers-reduced-motion: reduce) {
  .sm-carousel {
    overflow-x: auto;
    -webkit-mask-image: none;
    mask-image: none;
    scroll-snap-type: x proximity;
  }

  .sm-carousel .sm-carousel__track {
    animation: none;
  }

  .sm-carousel .sm-carousel__item--clone {
    display: none;
  }

  .sm-carousel .sm-carousel__item {
    scroll-snap-align: start;
  }

  .sm-carousel .sm-card,
  .sm-carousel .sm-card:hover {
    transform: none;
    transition: none;
  }
}
