/*
 * styles.css - layout, scatter/assemble motion and the header/tagline reveal.
 * Author: Trivikram Shenoy, RedX Creatives (https://redxcreatives.com/)
 *
 * Pieces sit at their home spot (in % of the stage) and are pushed away with a
 * transform. Assembling = clearing the transform, so the browser animates it.
 */
:root {
  --red: #d33a3a;
  --navy: #2b3f8f;
  --ink: #1d2340;
  --muted: #6b7088;
  --bg: #ffffff;
  --snap: cubic-bezier(.34, 1.45, .55, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden; /* scattered pieces may hang off-screen edges */
}

body {
  font-family: "Montserrat", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% 45%, #f4f6fc 0%, transparent 70%),
    var(--bg);
}

.scene {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vh, 32px);
  padding: 24px;
}

.stage {
  position: relative;
  width: min(86vw, 860px, 170vh);
  aspect-ratio: 389 / 150; /* overwritten from pieces.json */
}

.piece {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  transition: transform 1.1s var(--snap);
  will-change: transform;
}

.piece img {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

/* Gentle drift while scattered, on the inner image so it never fights the outer transform. */
.is-scattered .piece:not(.piece--five) img {
  animation: drift var(--drift, 5s) ease-in-out infinite alternate;
}

@keyframes drift {
  from { transform: translateY(-4px) rotate(-2deg); }
  to   { transform: translateY(4px) rotate(2deg); }
}

/* The 5: the only thing you can click. */
.piece--five {
  cursor: pointer;
  z-index: 2;
  border-radius: 12px;
}
.piece--five:focus-visible { outline: 3px solid var(--navy); outline-offset: 6px; }
.is-assembling .piece--five, .is-assembled .piece--five { outline: none; cursor: default; }

.is-scattered .piece--five img {
  animation: pulse 1.8s ease-in-out infinite;
  filter: drop-shadow(0 6px 14px rgba(43, 63, 143, .25));
}
.is-scattered .piece--five:hover img { animation-play-state: paused; transform: scale(1.08); }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.06); }
}

.hint {
  position: absolute;
  left: 50%;
  top: 100%;
  margin-top: 10px;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: clamp(12px, 1.6vw, 15px);
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--red);
  pointer-events: none;
  transition: opacity .3s;
}
.hint::before { content: "\2191\00a0"; }
.is-assembling .hint, .is-assembled .hint { opacity: 0; }

/* Assembled: a single light sweep across the finished logo. */
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,.75) 50%, transparent 65%);
  background-size: 250% 100%;
  background-position: 150% 0;
  mix-blend-mode: overlay;
  opacity: 0;
}
.is-assembled .stage::after { animation: sheen 1.2s ease-out .1s 1 both; }
@keyframes sheen {
  0%   { opacity: 1; background-position: 150% 0; }
  100% { opacity: 0; background-position: -50% 0; }
}

/* Header + tagline stay invisible (but keep their space) until assembled. */
.reveal {
  margin: 0;
  text-align: center;
  opacity: 0;
  transition: opacity .7s ease, transform .7s var(--snap);
}
.reveal--header {
  font-size: clamp(24px, 4.4vw, 52px);
  font-weight: 800;
  font-style: italic;
  line-height: 1.1;
  color: var(--navy);
  transform: translateY(-18px);
}
.reveal--tagline {
  font-size: clamp(15px, 2vw, 22px);
  font-weight: 500;
  color: var(--muted);
  transform: translateY(18px);
  max-width: 40ch;
}
.is-assembled .reveal { opacity: 1; transform: none; }
.is-assembled .reveal--tagline { transition-delay: .25s; }

.replay {
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  padding: 10px 20px;
  border-radius: 999px;
  border: 2px solid var(--navy);
  background: transparent;
  color: var(--navy);
  cursor: pointer;
  opacity: 0;
  visibility: hidden; /* keeps its space so the logo never jumps */
  transition: opacity .5s ease .6s, visibility 0s .6s, background .2s, color .2s;
}
.replay:hover { background: var(--navy); color: #fff; }
.is-assembled .replay { opacity: 1; visibility: visible; }

.credit {
  position: fixed;
  bottom: 10px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}
.credit a { color: inherit; }

@media (prefers-reduced-motion: reduce) {
  .piece { transition-duration: .01s; }
  .piece img, .stage::after { animation: none !important; }
  .reveal { transition-duration: .2s; }
}
