/* Special-effect stamps. Shared by the extension and the public pages (served at /static/fx.css).
   Each effect is a layer on top of the stamp image, cut to the stamp's notched outline. */

.fx {
  position: relative;
  display: block;
  line-height: 0;
}

/* ---------- gold: an animated shining border along the notched edge ---------- */

.fx-gold-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.fx-gold-frame path {
  fill: none;
  /* The stroke (the gold gradient for this stamp size) is set in fx.js. */
  /* Clipped to the inside of the outline, so 4px of this shows. */
  stroke-width: 8;
  filter: drop-shadow(0 0 1px rgba(90, 60, 0, .6));
}

/* ---------- hologram: rainbow foil across the whole stamp, with a moving shine ---------- */

.fx-holo-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  -webkit-mask: var(--stamp-mask) 0 0 / 100% 100% no-repeat;
  mask: var(--stamp-mask) 0 0 / 100% 100% no-repeat;
  mix-blend-mode: hard-light;
  opacity: .55;
}

/* The foil: a large striped sheet, tilted, sliding exactly one rainbow period (120px) per loop,
   so it never shows a seam or a jump. Fine lines on top give it a foil grain. */
.fx-holo-layer::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  /* Big enough to cover a 2x2 stamp while tilted and sliding. */
  width: 900px;
  height: 900px;
  margin: -450px 0 0 -450px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .22) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(
      90deg,
      hsl(330 100% 70%) 0px,
      hsl(40 100% 65%) 20px,
      hsl(90 100% 65%) 40px,
      hsl(170 100% 65%) 60px,
      hsl(220 100% 70%) 80px,
      hsl(280 100% 72%) 100px,
      hsl(330 100% 70%) 120px
    );
  transform: rotate(35deg);
  animation: fx-holo-foil 14s linear infinite;
}

/* The shine: a bright band that sweeps across, then waits off the stamp before the next pass. */
.fx-holo-layer::after {
  content: "";
  position: absolute;
  inset: -60%;
  background: linear-gradient(115deg, transparent 42%, rgba(255, 255, 255, .8) 50%, transparent 58%);
  mix-blend-mode: overlay;
  transform: translateX(-100%);
  animation: fx-holo-shine 8s ease-in-out infinite;
}

.fx-hologram:hover .fx-holo-layer { opacity: .7; }

@keyframes fx-holo-foil {
  from { transform: rotate(35deg) translateX(0); }
  to { transform: rotate(35deg) translateX(-120px); }
}

@keyframes fx-holo-shine {
  0% { transform: translateX(-100%); }
  35%, 100% { transform: translateX(100%); }
}

@media (prefers-reduced-motion: reduce) {
  .fx-holo-layer::before, .fx-holo-layer::after, .fx-floating, .fx.fx-floating img { animation: none; }
  .fx-spark { animation: none; opacity: .9; transform: scale(var(--still)) rotate(20deg); }
}

/* ---------- sparkle: little stars twinkling on and around the stamp ----------
   Positions and timing per star are set in fx.js. */

.fx-sparkle-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.fx-spark {
  position: absolute;
  width: var(--s);
  height: var(--s);
  margin: calc(var(--s) / -2) 0 0 calc(var(--s) / -2);
  line-height: 0;
  opacity: 0;
  transform: scale(0);
  filter: drop-shadow(0 0 2px #fff) drop-shadow(0 0 6px rgba(255, 220, 130, .95)) drop-shadow(0 0 12px rgba(255, 200, 90, .6));
  animation: fx-twinkle var(--d) ease-in-out var(--delay) infinite;
}

.fx-spark svg { width: 100%; height: 100%; fill: #fffdf5; }

/* On rainbow foil, white stars get lost: a thin dark edge and a stronger glow make them pop. */
.fx-hologram .fx-spark {
  filter: drop-shadow(0 0 1px rgba(40, 20, 60, .7)) drop-shadow(0 0 4px #fff) drop-shadow(0 0 10px rgba(255, 230, 160, .95));
}
.fx-hologram .fx-spark svg { fill: #fff; }

/* A glint, then dark for a while, so about half the stars shine at once. */
@keyframes fx-twinkle {
  0%, 40%, 100% { opacity: 0; transform: scale(0) rotate(0deg); }
  58% { opacity: 1; transform: scale(1.1) rotate(45deg); }
  70% { opacity: 1; transform: scale(.8) rotate(70deg); }
  86% { opacity: .8; transform: scale(.25) rotate(100deg); }
}

/* ---------- floating: lifted off the page towards you, drifting gently ----------
   The stamp stays in its row and rises on the z axis (3D depth), so it looks closer
   and its shadow spreads further below it. */

.fx-floating {
  z-index: 1;
  transform: perspective(600px) translateZ(20px);
  animation: fx-float 6s ease-in-out infinite;
}

/* A deep, soft shadow that spreads and fades as the stamp rises. */
.fx.fx-floating img {
  filter: drop-shadow(0 3px 3px rgba(60, 40, 20, .2)) drop-shadow(0 14px 14px rgba(60, 40, 20, .28));
  animation: fx-float-shadow 6s ease-in-out infinite;
}

@keyframes fx-float {
  0%, 100% { transform: perspective(600px) translateZ(16px) rotateX(2deg) rotateY(-3deg) rotate(-1.2deg); }
  50% { transform: perspective(600px) translateZ(32px) rotateX(-2deg) rotateY(3deg) rotate(1.2deg); }
}

@keyframes fx-float-shadow {
  0%, 100% { filter: drop-shadow(0 3px 3px rgba(60, 40, 20, .22)) drop-shadow(0 12px 12px rgba(60, 40, 20, .3)); }
  50% { filter: drop-shadow(0 5px 5px rgba(60, 40, 20, .16)) drop-shadow(0 24px 22px rgba(60, 40, 20, .2)); }
}

/* ---------- tilted and upside-down: the whole stamp turned ----------
   The rotate property adds to any transform another effect uses (floating, crumpled). */

.fx-tilted { rotate: 3deg; z-index: 1; }
.fx-upside-down { rotate: 180deg; }
.fx-tilted.fx-upside-down { rotate: 183deg; }
/* Turned over, the shadow would fall upwards: flip it so it still falls down the page. */
body:not(.no-fx):not(.no-shadow) .fx-upside-down:not(.fx-floating) img {
  filter: drop-shadow(0 -1px 1px rgba(60, 40, 20, .25)) drop-shadow(0 -4px 6px rgba(60, 40, 20, .18));
}

/* ---------- crumpled: for stamps that look like cheats ----------
   The whole stamp is warped by an SVG filter (set per stamp in fx.js), with crease lines,
   faded colours and a tilt. It is a penalty, not decoration, so the Effects setting
   doesn't hide it. */

.fx-crumpled {
  transform: rotate(var(--fx-tilt, -2deg));
}

.fx.fx-crumpled img {
  filter: grayscale(.45) sepia(.25) contrast(.9) brightness(.96)
    drop-shadow(0 1px 1px rgba(60, 40, 20, .25)) drop-shadow(0 4px 6px rgba(60, 40, 20, .18));
}

.no-shadow .fx.fx-crumpled img {
  filter: grayscale(.45) sepia(.25) contrast(.9) brightness(.96);
}

.fx-crumple-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  -webkit-mask: var(--stamp-mask) 0 0 / 100% 100% no-repeat;
  mask: var(--stamp-mask) 0 0 / 100% 100% no-repeat;
  /* Creases: a dark fold next to a light ridge, at a few angles, plus some shading. */
  background:
    linear-gradient(var(--fx-crease-1), transparent 46%, rgba(0, 0, 0, .28) 49%, rgba(255, 255, 255, .45) 50.5%, transparent 54%),
    linear-gradient(var(--fx-crease-2), transparent 27%, rgba(0, 0, 0, .22) 30%, rgba(255, 255, 255, .38) 31.5%, transparent 35%),
    linear-gradient(var(--fx-crease-3), transparent 62%, rgba(0, 0, 0, .2) 65%, rgba(255, 255, 255, .34) 66.5%, transparent 70%),
    linear-gradient(var(--fx-crease-4), transparent 16%, rgba(0, 0, 0, .16) 19%, rgba(255, 255, 255, .3) 20.5%, transparent 24%),
    radial-gradient(ellipse at 28% 72%, rgba(0, 0, 0, .18), transparent 45%),
    radial-gradient(ellipse at 75% 25%, rgba(0, 0, 0, .14), transparent 40%),
    radial-gradient(ellipse at 60% 60%, rgba(255, 255, 255, .2), transparent 35%);
  mix-blend-mode: hard-light;
}

/* ---------- trimmed: a grid stamp with some of its stamps removed ----------
   The removed ones are cut out of the picture. The shadow moves from the picture to the stamp,
   so the cut doesn't take it away. */

.fx-trimmed img {
  -webkit-mask: var(--trim-mask) 0 0 / 100% 100% no-repeat;
  mask: var(--trim-mask) 0 0 / 100% 100% no-repeat;
  filter: none !important;
  animation: none !important;
}

.fx-trimmed {
  filter: drop-shadow(0 1px 1px rgba(60, 40, 20, .25)) drop-shadow(0 4px 6px rgba(60, 40, 20, .18));
}

.no-shadow .fx-trimmed { filter: none; }

/* Other stamps can sit in the removed stamps' slots: only the stamps that are left take clicks.
   (Not on profile covers, which are shown smaller and are one link anyway.) */
.fx-trimmed:not(.cover-img) { pointer-events: none; }
.fx-trimmed:not(.cover-img) img { pointer-events: auto; clip-path: var(--trim-clip); }

/* ---------- viewer settings ---------- */

/* Effects off: special stamps look like normal stamps. */
.no-fx .fx-gold-frame,
.no-fx .fx-holo-layer,
.no-fx .fx-sparkle-layer { display: none; }
.no-fx .fx-floating { transform: none; animation: none; }
.no-fx .fx-tilted, .no-fx .fx-upside-down { rotate: none; }
.no-fx .fx.fx-floating img {
  animation: none;
  filter: drop-shadow(0 1px 1px rgba(60, 40, 20, .25)) drop-shadow(0 4px 6px rgba(60, 40, 20, .18));
}

/* Shadow off: no shadow under floating stamps either. */
.no-shadow .fx.fx-floating img { filter: none; animation: none; }

/* Animation off (or reduced motion): effects stay, nothing moves. */
.fx-still .fx-holo-layer::before,
.fx-still .fx-holo-layer::after,
.fx-still .fx-floating,
.fx-still .fx.fx-floating img { animation: none; }

/* Still sparkles: every star shows, frozen at its own size. */
.fx-still .fx-spark { animation: none; opacity: .9; transform: scale(var(--still)) rotate(20deg); }
