/*
  Stickers on the corners of an image.

  Each sticker hangs over the edge of the image. The rotation, nudge and size
  variation come from the template as custom properties, so they look hand
  placed but stay the same on every page load.

  To keep them from covering any text:
  - space is reserved above or below the image for stickers hanging over the
    top or bottom edge,
  - they only hang over the sides on wide screens, and never on the side next
    to a media with text or banner highlight paragraph's text,
  - they never take clicks.
*/
.has-stickers {
  --sticker-size: clamp(4.5rem, 12vw, 8.5rem);
  --sticker-overhang-y: calc(var(--sticker-size) * -0.3);
  --sticker-overhang-x: 0.5rem;
  position: relative;
}

/*
  Reserve space for stickers hanging over the top or bottom edge, plus a
  little extra for their rotation, nudge and scale. Stickers that have slid
  down a side don't hang over either edge. Small screens only show the first
  sticker, so only reserve space for that one.
*/
.has-stickers:has(.sticker:first-child:not(.sticker--on-side):is(.sticker--top-left, .sticker--top-right)) {
  margin-top: calc(var(--sticker-overhang-y) * -1 + 1rem);
}

.has-stickers:has(.sticker:first-child:not(.sticker--on-side):is(.sticker--bottom-left, .sticker--bottom-right)) {
  margin-bottom: calc(var(--sticker-overhang-y) * -1 + 1rem);
}

@media (min-width: 768px) {
  .has-stickers:has(.sticker:not(.sticker--on-side):is(.sticker--top-left, .sticker--top-right)) {
    margin-top: calc(var(--sticker-overhang-y) * -1 + 1rem);
  }

  .has-stickers:has(.sticker:not(.sticker--on-side):is(.sticker--bottom-left, .sticker--bottom-right)) {
    margin-bottom: calc(var(--sticker-overhang-y) * -1 + 1rem);
  }
}

.stickers {
  margin: 0;
  padding: 0;
  list-style: none;
}

.sticker {
  position: absolute;
  z-index: 1;
  width: var(--sticker-size);
  margin: 0;
  pointer-events: none;
  transform:
    translate(var(--sticker-x, 0), var(--sticker-y, 0))
    rotate(var(--sticker-rotate, 0deg))
    scale(var(--sticker-scale, 1));
}

.sticker img {
  display: block;
  width: 100%;
  height: auto;
}

/*
  Each sticker starts at its corner and slides some way along one edge, by
  --sticker-along-x (top or bottom edge) or --sticker-along-y (the side).
*/
.sticker--top-left {
  top: calc(var(--sticker-overhang-y) + var(--sticker-along-y, 0%));
  left: calc(var(--sticker-overhang-x-left, var(--sticker-overhang-x)) + var(--sticker-along-x, 0%));
}

.sticker--top-right {
  top: calc(var(--sticker-overhang-y) + var(--sticker-along-y, 0%));
  right: calc(var(--sticker-overhang-x-right, var(--sticker-overhang-x)) + var(--sticker-along-x, 0%));
}

.sticker--bottom-right {
  bottom: calc(var(--sticker-overhang-y) + var(--sticker-along-y, 0%));
  right: calc(var(--sticker-overhang-x-right, var(--sticker-overhang-x)) + var(--sticker-along-x, 0%));
}

.sticker--bottom-left {
  bottom: calc(var(--sticker-overhang-y) + var(--sticker-along-y, 0%));
  left: calc(var(--sticker-overhang-x-left, var(--sticker-overhang-x)) + var(--sticker-along-x, 0%));
}

/* Small screens: one sticker only, kept inside the sides of the image. */
/* @media (max-width: 767px) {
  .sticker:nth-child(n + 2) {
    display: none;
  }
} */

/* Wider screens: hang over the sides too, except towards the text. */
@media (min-width: 768px) {
  .has-stickers {
    --sticker-overhang-x: calc(var(--sticker-size) * -0.2);
  }

  .media-with-text--media-left .has-stickers {
    --sticker-overhang-x-right: 0.5rem;
  }

  .media-with-text--media-right .has-stickers,
  .banner-highlight .has-stickers {
    --sticker-overhang-x-left: 0.5rem;
  }
}

@media print {
  .stickers {
    display: none;
  }
}
