/* Pintaz Draf — community designs carousel.
 * Owns #carousel-root (class .carousel is added by /static/js/carousel.js).
 * Every slot position is a custom property so the three responsive layouts
 * (4 cards · 2.5 cards · 2 cards) reuse one set of rules.
 */

.carousel {
  position: relative;
  width: 100%;
  padding-block: 2.75rem 1.25rem;

  /* Card sizing — mobile/tablet default, widened at >=1024px. */
  --card-w: clamp(12.25rem, 27vw, 15rem);
  --card-h: calc(var(--card-w) * 1.25 + 4.25rem);

  /* Slot x offsets, as a percentage of card width from stage centre. */
  --x-exit-left: -235%;
  --x-left-back: -150%;
  --x-left-front: -56%;
  --x-right-front: 56%;
  --x-right-back: 150%;
  --x-exit-right: 235%;
  --x-enter: 192%;        /* rightBack +42% — the incoming-card keyframe */
  --x-enter-left: -192%;  /* mirror, used by the back arrow */

  /* Shared back-slot styling. */
  --y-back: 3rem;
  --scale-back: 0.92;
  --opacity-back: 0.92;

  /* Exiting cards must not create horizontal scroll, but the soft card
   * shadows still need to breathe above and below the stage. */
  overflow-x: hidden;
}

@supports (overflow-x: clip) {
  .carousel {
    overflow-x: clip;
    overflow-y: visible;
    overflow-clip-margin: 4rem;
  }
}

/* ------------------------------------------------------------------ stage -- */

.carousel__stage {
  position: relative;
  margin: 0 auto;
  max-width: 1120px;
  height: calc(var(--card-h) + var(--y-back) + 1.25rem);
}

/* ------------------------------------------------------------------- card -- */

.carousel__card {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  width: var(--card-w);
  margin: 0;
  background: var(--bg-card, #FFFEF9);
  border: 1px solid var(--line, #E7E1D4);
  border-radius: var(--radius-card, 20px);
  box-shadow: var(--shadow-card, 0 18px 40px -18px rgba(28, 25, 19, 0.28));
  overflow: hidden;
  will-change: transform, opacity;
  transform:
    translate(-50%, 0)
    translate(var(--slot-x, var(--x-enter)), var(--slot-y, var(--y-back)))
    scale(var(--slot-scale, 0.92));
  opacity: var(--slot-opacity, 0);
  z-index: var(--slot-z, 0);
  transition:
    transform 760ms var(--ease-carousel, cubic-bezier(0.2, 0.86, 0.24, 1)),
    opacity 760ms ease;
}

/* Applied by JS while a card is being repositioned off-stage. */
.carousel__card.is-static {
  transition: none;
}

/* ------------------------------------------------------------------ slots -- */

.carousel__card[data-slot='leftBack'],
.carousel__card[data-slot='rightBack'] {
  --slot-y: var(--y-back);
  --slot-scale: var(--scale-back);
  --slot-opacity: var(--opacity-back);
  --slot-z: 10;
}

.carousel__card[data-slot='leftFront'],
.carousel__card[data-slot='rightFront'] {
  --slot-y: 0px;
  --slot-scale: 1;
  --slot-opacity: 1;
  --slot-z: 30;
}

.carousel__card[data-slot='leftBack']    { --slot-x: var(--x-left-back); }
.carousel__card[data-slot='leftFront']   { --slot-x: var(--x-left-front); }
.carousel__card[data-slot='rightFront']  { --slot-x: var(--x-right-front); }
.carousel__card[data-slot='rightBack']   { --slot-x: var(--x-right-back); }

.carousel__card[data-slot='exitLeft'],
.carousel__card[data-slot='exitRight'] {
  --slot-y: 0px;
  --slot-scale: 0.72;
  --slot-opacity: 0;
  --slot-z: 0;
  pointer-events: none;
}

.carousel__card[data-slot='exitLeft']  { --slot-x: var(--x-exit-left); }
.carousel__card[data-slot='exitRight'] { --slot-x: var(--x-exit-right); }

.carousel__card[data-slot='enter'],
.carousel__card[data-slot='enterLeft'],
.carousel__card[data-slot='parked'] {
  --slot-y: var(--y-back);
  --slot-scale: var(--scale-back);
  --slot-opacity: 0;
  --slot-z: 0;
  pointer-events: none;
}

.carousel__card[data-slot='enter']     { --slot-x: var(--x-enter); }
.carousel__card[data-slot='enterLeft'] { --slot-x: var(--x-enter-left); }
.carousel__card[data-slot='parked']    { --slot-x: var(--x-enter); }

/* --------------------------------------------------------------- artwork -- */

.carousel__art {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: #F2ECE0;
  border-radius: calc(var(--radius-card, 20px) - 1px) calc(var(--radius-card, 20px) - 1px) 0 0;
  user-select: none;
  -webkit-user-drag: none;
}

/* ------------------------------------------------------------------ meta -- */

.carousel__meta {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.75rem 0.85rem 0.9rem;
}

.carousel__avatar {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill, 999px);
  background: var(--tint, #EBD9BE);
  color: var(--ink, #1C1913);
  font-size: 12px;
  font-weight: 700;
  line-height: 28px;
  text-align: center;
}

.carousel__body {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 0.3rem;
  row-gap: 1px;
  min-width: 0;
  padding-top: 1px;
}

.carousel__title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.012em;
  color: var(--ink, #1C1913);
}

.carousel__time {
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--muted, #8A8274);
  white-space: nowrap;
}

/* Author name — announced by screen readers, not shown (the avatar carries it). */
.carousel__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  white-space: nowrap;
  border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
}

/* -------------------------------------------------------------- controls -- */

.carousel__controls {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  margin-top: 1.5rem;
}

.carousel__arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line, #E7E1D4);
  border-radius: var(--radius-pill, 999px);
  background: var(--bg-card, #FFFEF9);
  color: var(--ink, #1C1913);
  font: inherit;
  cursor: pointer;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease;
}

.carousel__arrow svg {
  width: 15px;
  height: 15px;
}

.carousel__arrow:hover {
  transform: translateY(-1px);
  border-color: #D8D0BE;
  box-shadow: 0 8px 18px -10px rgba(28, 25, 19, 0.35);
}

.carousel__arrow:active {
  transform: translateY(0);
}

.carousel__arrow:focus-visible {
  outline: 2px solid var(--ink, #1C1913);
  outline-offset: 2px;
}

/* ------------------------------------------------------------ responsive -- */

/* Desktop — all four slots visible. */
@media (min-width: 1024px) {
  .carousel {
    --card-w: clamp(14.5rem, 18vw, 17rem);
    padding-block: 3.5rem 1.5rem;
  }
}

/* Tablet — 2.5-card feel: rightFront demotes to back styling, rightBack hides. */
@media (min-width: 760px) and (max-width: 1023.98px) {
  .carousel {
    --x-exit-left: -215%;
    --x-left-back: -118%;
    --x-left-front: -24%;
    --x-right-front: 82%;
    --x-right-back: 158%;
    --x-enter: 200%;
  }

  .carousel__card[data-slot='rightFront'] {
    --slot-y: var(--y-back);
    --slot-scale: var(--scale-back);
    --slot-opacity: var(--opacity-back);
    --slot-z: 10;
  }

  .carousel__card[data-slot='rightBack'] {
    --slot-opacity: 0;
    --slot-z: 0;
    pointer-events: none;
  }
}

/* Mobile — two cards, the leftFront + rightFront pair. */
@media (max-width: 759.98px) {
  .carousel {
    --x-exit-left: -175%;
    --x-left-back: -152%;
    --x-left-front: -56%;
    --x-right-front: 56%;
    --x-right-back: 152%;
    --x-enter: 194%;
    --y-back: 2.25rem;
    padding-block: 2.25rem 1rem;
  }

  .carousel__card[data-slot='leftBack'],
  .carousel__card[data-slot='rightBack'] {
    --slot-opacity: 0;
    --slot-z: 0;
    pointer-events: none;
  }
}

@media (max-width: 479.98px) {
  .carousel__controls {
    display: none;
  }
}

/* ------------------------------------------------- reduced motion (a11y) -- */
/* JS also stops auto-advance; here we drop movement to a plain opacity fade. */
@media (prefers-reduced-motion: reduce) {
  .carousel__card {
    transition: opacity 200ms linear;
    will-change: auto;
  }

  .carousel__card.is-static {
    transition: none;
  }

  .carousel__arrow,
  .carousel__arrow:hover,
  .carousel__arrow:active {
    transform: none;
    transition: none;
  }
}
