/* =========================================
   HERO — 8-BIT MODE
   Every 2 seconds the ID photo flickers to a pixel avatar and back.
   Design + development pieces come out from behind the card with it.
========================================= */

/* Wrapper that swings, so the photo, avatar and card move together */
.id-card {
  position: relative;
  z-index: 1;
  width: 100%;
  aspect-ratio: 1050 / 1414;

  transform-origin: 40% 3%;
  animation: card-swing 3s ease-in-out infinite alternate;
}

.hero-visual .id-card img {
  width: 100%;
  height: 100%;
}

/* Overlay shares the card image's 1050 × 1414 coordinate space */
.id-card-avatar {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  visibility: hidden;
}

.hero.is-showing-pixel .id-card-avatar {
  visibility: visible;
}

.id-card-avatar image {
  image-rendering: pixelated;
}

/* Brief jolt on every swap */
.hero.is-glitching .id-card-avatar {
  visibility: visible;
  animation: pixel-glitch 0.18s steps(1) infinite;
}

.hero.is-glitching:not(.is-showing-pixel) .id-card-avatar {
  opacity: 0.35;
}

@keyframes pixel-glitch {
  0%   { transform: translate(0, 0);     clip-path: inset(0); }
  33%  { transform: translate(-8px, 0);  clip-path: inset(52% 0 33% 0); }
  66%  { transform: translate(7px, 0);   clip-path: inset(62% 0 30% 0); }
}


/* ---------- Floating pieces ---------- */

.pixel-bits {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.pixel-bit {
  /* --x / --y: resting spot as % of the hero. Pieces start behind the card
     (the card's centre sits 274px across and 442px down). */
  position: absolute;
  left: 274px;
  top: 442px;

  translate: -50% -50%;
  scale: 0.3;
  rotate: 0deg;
  opacity: 0;
  visibility: hidden;

  transition:
    left 0.35s steps(6),
    top 0.35s steps(6),
    scale 0.35s steps(6),
    rotate 0.35s steps(6),
    opacity 0.35s steps(4),
    visibility 0s 0.35s;
}

.hero.is-pixel-mode .pixel-bit {
  /* clamp keeps edge pieces from running off narrow screens */
  left: clamp(64px, var(--x), 100% - 64px);
  top: var(--y);
  scale: 1;
  rotate: var(--r, 0deg);
  opacity: 1;
  visibility: visible;

  transition:
    left 0.6s steps(9) var(--delay, 0s),
    top 0.6s steps(9) var(--delay, 0s),
    scale 0.6s steps(9) var(--delay, 0s),
    rotate 0.6s steps(9) var(--delay, 0s),
    opacity 0.2s steps(3) var(--delay, 0s),
    visibility 0s var(--delay, 0s);
}

/* Inner element carries the look and the idle bobbing */
.pixel-bit > span {
  display: flex;
  align-items: center;
  gap: 8px;

  padding: 8px 12px;
  background: var(--color-foundation-white);
  color: var(--color-foundation-black);
  border: 2px solid var(--color-foundation-black);
  box-shadow: 4px 4px 0 var(--color-foundation-black);

  font: 500 14px/1.2 "Pixelify Sans", monospace;
  white-space: nowrap;
}

.hero.is-pixel-mode .pixel-bit > span {
  animation: pixel-bob 1.6s steps(4) infinite alternate;
  animation-delay: calc(var(--delay, 0s) * -6);
}

@keyframes pixel-bob {
  from { transform: translateY(-4px); }
  to   { transform: translateY(4px); }
}

.pixel-bit > .bit-code {
  background: var(--color-foundation-black);
  color: var(--color-green-500);
  box-shadow: 4px 4px 0 var(--color-green-500);
}

.pixel-bit > .bit-green {
  background: var(--color-green-500);
}

.pixel-bit > .bit-blue {
  background: var(--color-blue-500);
  color: var(--color-foundation-white);
}

/* Colour swatches */
.pixel-bit > .bit-swatches {
  gap: 0;
  padding: 4px;
}

.bit-swatches i {
  width: 22px;
  height: 22px;
  background: var(--swatch);
}

/* Selected design frame with resize handles */
.pixel-bit > .bit-frame {
  position: relative;
  padding: 10px 18px;
  border-color: var(--color-blue-500);
  box-shadow: none;
  font-size: 32px;
}

.bit-frame::before {
  content: "";
  position: absolute;
  inset: -6px;
  --handle: linear-gradient(var(--color-blue-500) 0 0);
  background:
    var(--handle) top left,
    var(--handle) top right,
    var(--handle) bottom left,
    var(--handle) bottom right;
  background-size: 10px 10px;
  background-repeat: no-repeat;
}

/* Pen tool path */
.pixel-bit > .bit-icon {
  padding: 6px;
}

.bit-icon svg {
  display: block;
  width: 56px;
  height: 40px;
}


/* ---------- Responsive ---------- */

/* Stacked layout: pieces surround the card only, above the text */
@media (max-width: 1080px) {
  .pixel-bits {
    --card-width: min(90vw, 525px);
    top: -130px;
    bottom: auto;
    height: calc(var(--card-width) * 707 / 525);
  }

  .pixel-bit {
    left: calc(50% + var(--card-width) * 0.06);
    top: 64%;
  }

  .hero.is-pixel-mode .pixel-bit {
    left: clamp(54px, var(--mx), 100% - 54px);
    top: var(--my);
  }
}

@media (max-width: 500px) {
  /* The hero gains 110px of top padding here */
  .pixel-bits {
    top: -20px;
  }
}

@media (max-width: 600px) {
  .pixel-bit > span {
    padding: 5px 8px;
    font-size: 11px;
    box-shadow: 3px 3px 0 var(--color-foundation-black);
  }

  .pixel-bit > .bit-code {
    box-shadow: 3px 3px 0 var(--color-green-500);
  }

  .pixel-bit > .bit-swatches {
    padding: 3px;
  }

  .bit-swatches i {
    width: 14px;
    height: 14px;
  }

  .pixel-bit > .bit-frame {
    padding: 6px 10px;
    font-size: 20px;
    box-shadow: none;
  }

  .bit-icon svg {
    width: 40px;
    height: 28px;
  }

  /* Fewer pieces on phones */
  .pixel-bit--wide {
    display: none;
  }
}


/* ---------- Reduced motion ---------- */

/* The photo stays put: js/hero-pixel.js does not start the loop */
@media (prefers-reduced-motion: reduce) {
  .id-card {
    animation: none;
  }
}
