/*
 * Polaroid kit: watercolor polaroids that fall gently into place.
 * Pair with polaroid.js. Customize with the variables on .polaroids.
 */
.polaroids {
  --polaroid-width: 440px;       /* a single photo */
  --polaroid-pile-width: 250px;  /* each photo when there are several */
  --polaroid-paper: #fdfcf9;
  --polaroid-caption: #6b665e;
  --polaroid-caption-font: "Fraunces", Georgia, serif;
  --polaroid-tape: rgba(233, 190, 160, 0.55);
  --polaroid-stagger: 0.35s;     /* delay between photos landing */

  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin: 40px 0 16px;
  padding-top: 12px;
}

.polaroid {
  --r: -2deg; /* resting tilt; polaroid.js sets one per photo */
  position: relative;
  width: min(100%, var(--polaroid-width));
  margin: 0;
  padding: 12px 12px 0;
  background: var(--polaroid-paper);
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.12);
  transform: rotate(var(--r));
  transition: transform 0.4s ease, box-shadow 0.4s ease;
}

.polaroid:hover {
  z-index: 1;
  transform: rotate(0deg) translateY(-3px) scale(1.02);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08), 0 14px 32px rgba(0, 0, 0, 0.16);
}

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

.polaroid figcaption {
  padding: 12px 0 14px;
  color: var(--polaroid-caption);
  font-family: var(--polaroid-caption-font);
  font-size: 17px;
  font-style: italic;
  text-align: center;
}

/* Several photos: smaller, overlapping, scattered. */
.polaroids.is-pile .polaroid { width: var(--polaroid-pile-width); margin: 0 -14px 24px; }
.polaroids.is-pile .polaroid:nth-child(even) { margin-top: 22px; }
.polaroids.is-pile .polaroid figcaption { padding: 8px 0 10px; font-size: 15px; }

@media (max-width: 600px) {
  .polaroids.is-pile { flex-direction: column; }
  .polaroids.is-pile .polaroid { width: 78%; margin: 0 0 -4px; }
  .polaroids.is-pile .polaroid:nth-child(odd) { margin-right: auto; }
  .polaroids.is-pile .polaroid:nth-child(even) { margin-top: 0; margin-left: auto; }
  .polaroids.is-pile .polaroid:last-child { margin-bottom: 16px; }
}

/* A strip of tape pressed on once each photo lands. */
.polaroid::before {
  content: "";
  position: absolute;
  top: -12px;
  left: 50%;
  width: 28%;
  min-width: 64px;
  height: 24px;
  background: var(--polaroid-tape);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  transform: translateX(-50%) rotate(3deg);
}

/* Hidden only once polaroid.js is running, so photos still show without JS. */
.polaroids.is-ready .polaroid:not(.is-landed),
.polaroids.is-ready .polaroid:not(.is-landed)::before { opacity: 0; }

.polaroid.is-landed {
  animation: polaroid-drop 1.5s cubic-bezier(0.22, 0.7, 0.3, 1) calc(var(--i, 0) * var(--polaroid-stagger)) both;
}

.polaroid.is-landed::before {
  animation: polaroid-tape 0.35s ease-out calc(var(--i, 0) * var(--polaroid-stagger) + 1.25s) both;
}

/* After landing, drop the animation so the hover tilt can take over. */
.polaroid.is-settled { animation: none; }

/* Drifts down with a slight sway, overshoots a touch, and settles at its resting tilt.
   The shadow starts soft and wide (far from the page) and tightens as it lands. */
@keyframes polaroid-drop {
  0% {
    opacity: 0;
    transform: translateY(-140px) rotate(calc(var(--r) - 10deg)) scale(1.08);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.04);
  }
  15% { opacity: 1; }
  55% {
    transform: translateY(10px) rotate(calc(var(--r) + 4.5deg)) scale(1.01);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14);
  }
  78% { transform: translateY(-4px) rotate(calc(var(--r) - 1deg)) scale(1); }
  100% {
    opacity: 1;
    transform: rotate(var(--r));
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.12);
  }
}

@keyframes polaroid-tape {
  from { opacity: 0; transform: translateX(-50%) rotate(3deg) scale(1.3); }
  to { opacity: 1; transform: translateX(-50%) rotate(3deg) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .polaroids.is-ready .polaroid:not(.is-landed),
  .polaroids.is-ready .polaroid:not(.is-landed)::before { opacity: 1; }
  .polaroid.is-landed,
  .polaroid.is-landed::before { animation: none; }
}
