/*
 * Promote card on Infima tokens. Layout: content on top, one action row below.
 * The call to action sits bottom-left; pager and pause share that row at the
 * bottom-right. Dismiss is a corner mark. Portrait phones keep only a thumbnail
 * beside the title; short landscape viewports drop the thumbnail for a thin strip.
 */

.hagilight-promoto {
  --hagilight-promoto-cta-text: var(--ifm-color-white);
  --promoto-control-size: 1.75rem;
  --promoto-cta-height: 2.25rem;
  --promoto-pad: 0.875rem;
  --promoto-pager-width: calc(3 * var(--promoto-control-size) + 2.25rem + 0.375rem);
  --promoto-muted: var(--ifm-color-emphasis-700);
  /* Motion: a damped spring where linear() exists, a long ease-out elsewhere. */
  --promoto-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --promoto-rotation: 8000ms;
  --promoto-shift: 1rem;
  display: block;
}

@supports (transition-timing-function: linear(0, 1)) {
  .hagilight-promoto {
    --promoto-ease: linear(0, 0.066, 0.22, 0.409, 0.597, 0.761, 0.89, 0.983, 1.042, 1.073, 1.083, 1.079, 1.067, 1.052, 1.036, 1.022, 1.011, 1.002, 0.997, 0.994, 0.993, 0.993, 1);
  }
}

.hagilight-promoto[data-dir='prev'] {
  --promoto-shift: -1rem;
}

.hagilight-promoto[hidden],
.hagilight-promoto__shell[hidden],
.hagilight-promoto__controls[hidden] {
  display: none !important;
}

.hagilight-promoto__shell {
  position: fixed;
  z-index: 40;
  /* Centered in the content area: a theme narrows it by setting these two insets on :root. */
  inset-inline-start: var(--hagilight-promoto-inset-start, 0px);
  inset-inline-end: var(--hagilight-promoto-inset-end, 0px);
  bottom: max(1rem, env(safe-area-inset-bottom));
  width: min(42rem, calc(100% - var(--hagilight-promoto-inset-start, 0px) - var(--hagilight-promoto-inset-end, 0px) - 1rem - 2 * max(env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px))));
  margin-inline: auto;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--ifm-color-primary) 24%, var(--ifm-color-emphasis-300));
  border-radius: 1rem;
  background: color-mix(in srgb, var(--ifm-background-surface-color, var(--ifm-color-white)) 96%, var(--ifm-color-primary) 4%);
  box-shadow: 0 12px 32px color-mix(in srgb, #000 14%, transparent);
  color: var(--ifm-font-color-base);
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.24s ease, transform 0.62s var(--promoto-ease), visibility 0s linear;
}

/* Rises into place on first render and whenever it returns from the footer or the consent panel. */
.hagilight-promoto[data-state='ready'] .hagilight-promoto__shell {
  animation: hagilight-promoto-rise 0.62s var(--promoto-ease) backwards;
}

@keyframes hagilight-promoto-rise {
  from { opacity: 0; transform: translateY(1.25rem) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.hagilight-promoto[data-state='footer-hidden'] .hagilight-promoto__shell,
.hagilight-promoto[data-state='consent-hidden'] .hagilight-promoto__shell {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(1.25rem) scale(0.97);
  /* Leaving is quick and does not bounce. */
  transition: opacity 0.2s ease, transform 0.24s ease-in, visibility 0s linear 0.24s;
}

/* Time until the next card, drawn along the bottom edge; hovering the card or tabbing into it holds it. */
.hagilight-promoto__progress {
  position: absolute;
  inset-block-end: 0;
  inset-inline: 0;
  block-size: 2px;
  background: var(--ifm-color-primary);
  opacity: 0;
  pointer-events: none;
  transform: scaleX(0);
  transform-origin: left center;
}

.hagilight-promoto__progress:dir(rtl) {
  transform-origin: right center;
}

.hagilight-promoto[data-rotating] .hagilight-promoto__progress {
  opacity: 0.55;
  animation-duration: var(--promoto-rotation);
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

/* Two names for one keyframe set: flipping between them restarts the fill without a forced reflow. */
.hagilight-promoto[data-rotating][data-tick='0'] .hagilight-promoto__progress {
  animation-name: hagilight-promoto-fill-a;
}

.hagilight-promoto[data-rotating][data-tick='1'] .hagilight-promoto__progress {
  animation-name: hagilight-promoto-fill-b;
}

.hagilight-promoto[data-paused] .hagilight-promoto__progress,
.hagilight-promoto__shell:hover .hagilight-promoto__progress,
.hagilight-promoto__shell:has(:focus-visible) .hagilight-promoto__progress {
  animation-play-state: paused;
}

@keyframes hagilight-promoto-fill-a {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes hagilight-promoto-fill-b {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.hagilight-promoto__viewport {
  overflow: hidden;
}

.hagilight-promoto__track {
  display: flex;
  align-items: stretch;
  width: 100%;
  transition: transform 0.5s var(--promoto-ease);
}

/*
 * Content settles after the track: the card being left fades out at once, the card
 * arriving lands copy, then the action, each a beat behind the last. Pushes toward
 * the direction of travel (--promoto-shift flips for Previous).
 */
.hagilight-promoto__slide > * {
  transition: opacity 0.32s ease, transform 0.55s var(--promoto-ease);
}

.hagilight-promoto__slide[aria-hidden='true'] > * {
  opacity: 0;
  transform: translateX(var(--promoto-shift));
  transition-duration: 0.18s, 0.18s;
}

.hagilight-promoto__slide[aria-hidden='false'] > .hagilight-promoto__copy {
  transition-delay: 0.08s;
}

.hagilight-promoto__slide[aria-hidden='false'] > .hagilight-promoto__cta {
  transition-delay: 0.14s;
}

.hagilight-promoto__slide {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    'media copy'
    'media cta';
  align-items: start;
  column-gap: 1rem;
  row-gap: 0.75rem;
  width: 100%;
  min-width: 100%;
  padding: var(--promoto-pad);
}

.hagilight-promoto__slide:not([data-has-image='true']) {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    'copy'
    'cta';
  padding-inline-start: 1.25rem;
}

.hagilight-promoto__slide[aria-hidden='true'] {
  pointer-events: none;
}

.hagilight-promoto__copy {
  grid-area: copy;
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.hagilight-promoto__title,
.hagilight-promoto__description {
  display: -webkit-box;
  overflow: hidden;
  margin: 0;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.hagilight-promoto__title {
  padding-inline-end: 2rem;
  color: var(--ifm-heading-color);
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  text-wrap: balance;
}

.hagilight-promoto__description {
  color: var(--promoto-muted);
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1.4;
}

.hagilight-promoto__media {
  grid-area: media;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4.5rem;
  min-width: 4.5rem;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--ifm-color-primary-dark) 18%, var(--ifm-color-emphasis-300));
  border-radius: 0.75rem;
  background: var(--ifm-color-emphasis-100);
}

.hagilight-promoto__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hagilight-promoto__media picture {
  display: contents;
}

.hagilight-promoto__cta {
  grid-area: cta;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  justify-self: start;
  max-width: min(100%, 16rem);
  min-height: var(--promoto-cta-height);
  padding: 0.4rem 1rem;
  border: 1px solid color-mix(in srgb, var(--ifm-color-primary-dark) 30%, transparent);
  border-radius: 999px;
  background: var(--ifm-color-primary);
  color: var(--hagilight-promoto-cta-text);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
}

.hagilight-promoto[data-multiple] .hagilight-promoto__cta {
  max-width: min(16rem, calc(100% - var(--promoto-pager-width)));
}

.hagilight-promoto__cta:hover,
.hagilight-promoto__cta:focus-visible {
  background: var(--ifm-color-primary-dark);
}

/* Pager and pause sit on the call-to-action row, bottom-right. */
.hagilight-promoto__controls {
  position: absolute;
  inset-block-end: var(--promoto-pad);
  inset-inline-end: 0.5rem;
  display: flex;
  align-items: center;
  height: var(--promoto-cta-height);
  gap: 0.125rem;
}

.hagilight-promoto__dismiss,
.hagilight-promoto__control {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--promoto-control-size);
  height: var(--promoto-control-size);
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--promoto-muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* Keep the tap target larger than the visible mark. */
.hagilight-promoto__dismiss::before,
.hagilight-promoto__control::before {
  content: '';
  position: absolute;
  inset-block: -0.375rem;
  inset-inline: 0;
}

.hagilight-promoto__dismiss {
  position: absolute;
  inset-block-start: 0.375rem;
  inset-inline-end: 0.375rem;
}

.hagilight-promoto__dismiss::before {
  inset-inline: -0.25rem;
}

.hagilight-promoto__icon {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.hagilight-promoto__icon--play {
  display: none;
  fill: currentColor;
}

.hagilight-promoto__control[aria-pressed='true'] .hagilight-promoto__icon--pause {
  display: none;
}

.hagilight-promoto__control[aria-pressed='true'] .hagilight-promoto__icon--play {
  display: block;
}

.hagilight-promoto__count {
  min-width: 2.25rem;
  color: var(--promoto-muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
}

.hagilight-promoto__control:disabled {
  cursor: default;
  opacity: 0.45;
}

.hagilight-promoto__status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (hover: hover) {
  .hagilight-promoto__dismiss:hover,
  .hagilight-promoto__control:hover:not(:disabled) {
    background: color-mix(in srgb, var(--ifm-color-primary) 12%, transparent);
    color: var(--ifm-heading-color);
  }
}

.hagilight-promoto__dismiss:focus-visible,
.hagilight-promoto__control:focus-visible,
.hagilight-promoto__cta:focus-visible {
  outline: 2px solid var(--ifm-color-primary);
  outline-offset: 2px;
}

@media (pointer: coarse) {
  .hagilight-promoto {
    --promoto-control-size: 2rem;
  }
}

/* Portrait phones: thumbnail beside the title only; description and action row take the full width. */
@media (max-width: 36rem) and (min-height: 30rem) {
  .hagilight-promoto {
    --promoto-control-size: 2rem;
    --promoto-pad: 0.75rem;
  }

  .hagilight-promoto__shell {
    bottom: calc(env(safe-area-inset-bottom) + 0.5rem);
    width: min(calc(100vw - 1rem - 2 * max(env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px))), 28rem);
    border-radius: 0.875rem;
  }

  .hagilight-promoto__slide[data-has-image] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'title' 'desc' 'cta';
    gap: 0.375rem;
    padding: var(--promoto-pad);
  }

  .hagilight-promoto__slide[data-has-image='true'] {
    grid-template-columns: 3rem minmax(0, 1fr);
    grid-template-areas: 'media title' 'desc desc' 'cta cta';
    column-gap: 0.625rem;
  }

  /* Flatten copy so the thumbnail sits beside the title only. */
  .hagilight-promoto__copy {
    display: contents;
  }

  .hagilight-promoto__title {
    grid-area: title;
    align-self: center;
    font-size: 0.95rem;
  }

  .hagilight-promoto__description {
    grid-area: desc;
    font-size: 0.85rem;
    line-height: 1.35;
  }

  .hagilight-promoto__media {
    width: 3rem;
    min-width: 3rem;
    border-radius: 0.625rem;
  }

  .hagilight-promoto__cta {
    margin-block-start: 0.25rem;
    padding-inline: 0.875rem;
  }
}

@media (max-width: 22.5rem) and (min-height: 30rem) {
  .hagilight-promoto {
    --promoto-pager-width: 6rem;
  }

  .hagilight-promoto__count {
    display: none;
  }

  .hagilight-promoto__cta {
    padding-inline: 0.625rem;
  }
}

/* Short landscape viewports: thin strip, no thumbnail, one-line description. */
@media (max-height: 30rem) {
  .hagilight-promoto {
    --promoto-cta-height: 2rem;
    --promoto-pad: 0.5rem;
  }

  .hagilight-promoto__shell {
    bottom: max(0.5rem, env(safe-area-inset-bottom));
  }

  .hagilight-promoto__media {
    display: none;
  }

  .hagilight-promoto__slide[data-has-image] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: 'copy' 'cta';
    row-gap: 0.375rem;
    padding: 0.5rem 0.75rem 0.5rem 1rem;
  }

  .hagilight-promoto__description {
    -webkit-line-clamp: 1;
  }

  .hagilight-promoto__dismiss {
    inset-block-start: 0.25rem;
    inset-inline-end: 0.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hagilight-promoto__shell,
  .hagilight-promoto__track,
  .hagilight-promoto__slide > *,
  .hagilight-promoto__dismiss,
  .hagilight-promoto__control {
    transition: none;
  }

  .hagilight-promoto__shell {
    transform: none !important;
    animation: none !important;
  }

  .hagilight-promoto__progress {
    display: none;
  }
}
