/*
  Interactive widgets for the "How Parallax Animation Works" post.
  Standalone, prefixed styles (.pxw = depth studio, .gapw = the gap demo).
  Brand tokens (--red, --ink, --line, --card ...) come from /blog/theme.css,
  which this post links alongside this file.
*/

/* Shared embed shell -------------------------------------------------------- */
.px-embed {
  margin: 2.6rem 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--white);
  box-shadow: 0 1px 2px rgba(23, 23, 31, 0.04);
  overflow: hidden;
}
.px-embed .px-fallback {
  margin: 0;
  display: block;
}
.px-embed .px-fallback img {
  display: block;
  width: 100%;
  height: auto;
  border: 0;
  border-radius: 0;
}
.px-embed.is-ready .px-fallback { display: none; }

.px-embed-head {
  padding: 16px 18px 0;
}
.px-embed-eyebrow {
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--red);
  margin: 0 0 4px;
}
.px-embed-note {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--body);
  margin: 0;
}

/* The picture stage --------------------------------------------------------- */
.px-stage {
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 16px auto;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  overflow: hidden;
  background: #0e0e13;
  touch-action: pan-y;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.px-stage:active { cursor: grabbing; }

.px-stage.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(14, 14, 19, 0.55);
  backdrop-filter: blur(1px);
  z-index: 50;
  transition: opacity 0.25s ease;
}

/* Parallax plane group (combined view) */
.pxw-planes {
  position: absolute;
  inset: 0;
  will-change: transform;
}
.pxw-plane {
  position: absolute;
  inset: 0;
  will-change: transform;
  transform: translate3d(
    calc(var(--mx) * var(--amp) * var(--d) * var(--strength)),
    calc(var(--my) * var(--amp) * var(--d) * var(--strength) * 0.55),
    0
  );
}
.pxw-plane img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.14);
  display: block;
  border: 0;
  border-radius: 0;
  pointer-events: none;
}

/* Separated view: the complete layers laid out as a grid -------------------- */
/* The planes are full-canvas, position-preserving cut-outs, so fanning them in
   3D just recombines them into the composite. To actually show each layer's
   content we lay them out as discrete tiles on a transparency checker. */
.pxw-grid {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px auto;
  max-width: 560px;
}
.px-embed.is-split .px-stage { display: none; }
.px-embed.is-split .pxw-grid { display: grid; }
.pxw-grid-caption {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--body);
}
.pxw-grid-caption b { color: var(--ink-2); font-weight: 700; }
.pxw-tile {
  position: relative;
  aspect-ratio: var(--ar, 1 / 1);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  /* checkerboard so each layer's transparent (empty) area is visible */
  background-color: #f3f1f1;
  background-image:
    linear-gradient(45deg, #e4e0e0 25%, transparent 25%, transparent 75%, #e4e0e0 75%),
    linear-gradient(45deg, #e4e0e0 25%, transparent 25%, transparent 75%, #e4e0e0 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.22, 0.61, 0.36, 1);
  transition-delay: calc(var(--ti, 0) * 55ms);
}
.pxw-grid.is-shown .pxw-tile { opacity: 1; transform: none; }
.pxw-tile img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  border: 0;
  border-radius: 0;
  pointer-events: none;
}
.pxw-tile-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 0.66rem;
  font-weight: 800;
  color: #fff;
  background: var(--red);
  border-radius: 999px;
}
.pxw-tile-label {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  font-family: var(--font-display);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(14, 14, 19, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 7px;
  padding: 4px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (prefers-reduced-motion: reduce) {
  .pxw-tile { transition: none; }
}

/* Controls ------------------------------------------------------------------ */
.px-controls {
  padding: 4px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.px-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.px-row-label {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  flex: 0 0 auto;
  min-width: 108px;
}
.px-slider {
  flex: 1 1 160px;
  min-width: 140px;
  accent-color: var(--red);
  height: 4px;
}
.px-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.px-pill {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-2);
  background: var(--white);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 7px 15px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.px-pill:hover { border-color: var(--red); color: var(--red); }
.px-pill.is-active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.px-pill--wide { padding: 9px 18px; }
.px-hint {
  font-size: 0.86rem;
  color: var(--muted);
  margin: 0;
  flex: 1 1 auto;
}
.px-hint b { color: var(--body); font-weight: 600; }

/* Segmented control (clean / naive) */
.px-seg {
  display: inline-flex;
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  background: var(--card);
}
.px-seg button {
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-2);
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 7px 16px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.px-seg button.is-active {
  background: var(--white);
  color: var(--red);
  box-shadow: 0 1px 3px rgba(23, 23, 31, 0.12);
}

/* The gap demo -------------------------------------------------------------- */
.gapw-behind,
.gapw-hole,
.gapw-subject {
  position: absolute;
  inset: 0;
}
.gapw-behind img,
.gapw-subject img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border: 0;
  border-radius: 0;
  pointer-events: none;
}
.gapw-subject {
  transition: transform 0.08s linear;
  cursor: grab;
  z-index: 3;
}
.gapw-subject:active { cursor: grabbing; }
/* The "missing pixels" hole: a checker punched to the subject's silhouette,
   pinned where the subject originally sat. Shown only in naive mode. */
.gapw-hole {
  z-index: 2;
  opacity: 0;
  transition: opacity 0.25s ease;
  background-color: #14141a;
  background-image:
    linear-gradient(45deg, rgba(183, 90, 90, 0.5) 25%, transparent 25%, transparent 75%, rgba(183, 90, 90, 0.5) 75%),
    linear-gradient(45deg, rgba(183, 90, 90, 0.5) 25%, transparent 25%, transparent 75%, rgba(183, 90, 90, 0.5) 75%);
  background-size: 26px 26px;
  background-position: 0 0, 13px 13px;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-mode: alpha;
  mask-mode: alpha;
}
.gapw.is-naive .gapw-hole { opacity: 1; }

@media (max-width: 520px) {
  .px-row-label { min-width: 0; flex-basis: 100%; }
  .pxw-grid { grid-template-columns: repeat(2, 1fr); }
}
