@font-face {
  font-family: "ITC Avant Garde Gothic";
  src: url("assets/fonts/itc-avant-garde-gothic-medium.otf") format("opentype");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "ITC Avant Garde Gothic";
  src: url("assets/fonts/itc-avant-garde-gothic-bold.otf") format("opentype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --red: #d21807;
  --ink: #000;
  --pad: clamp(1.25rem, 3vw, 2rem);
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --mx: 0;
  --my: 0;
}

body.is-404 {
  margin: 0;
  min-height: 100dvh;
  background: var(--red);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  background: var(--red);
  color: var(--ink);
  overflow: hidden;
}

body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--red);
  color: var(--ink);
  font-family: "ITC Avant Garde Gothic", sans-serif;
  font-weight: 500;
}

::selection {
  background: var(--ink);
  color: var(--red);
}

.wash {
  display: none;
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0;
  background:
    radial-gradient(
      55rem 42rem at
        calc(50% + var(--mx) * 34%)
        calc(50% + var(--my) * 30%),
      rgb(255 60 40 / 0.28) 0%,
      transparent 62%
    ),
    radial-gradient(
      120% 90% at
        calc(50% - var(--mx) * 22%)
        calc(50% - var(--my) * 20%),
      transparent 40%,
      rgb(0 0 0 / 0.22) 100%
    );
  transition: opacity 480ms var(--ease-out);
}

body.is-ready .wash {
  opacity: 1;
}

main {
  position: relative;
  z-index: 1;
  height: 100dvh;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding:
    calc(var(--pad) + 1.5rem)
    calc(var(--pad) + 1.25rem)
    calc(var(--pad) + 2rem);
}

.lockup {
  position: relative;
  z-index: 2;
  width: clamp(17.5rem, 40vw, 27rem);
}

.logo,
.smile {
  display: block;
  height: auto;
}

.logo {
  width: 100%;
  will-change: transform, opacity;
}

.smile-hit {
  display: block;
  width: clamp(2.2rem, 4vw, 3.1rem);
  margin: 1rem auto 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  transform-origin: 50% 35%;
  will-change: transform, opacity;
  -webkit-tap-highlight-color: transparent;
}

.smile-hit:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 6px;
}

.smile {
  width: 100%;
  transform-origin: 50% 70%;
  will-change: transform;
  pointer-events: none;
  user-select: none;
}

h1 {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28em;
  margin: 0.85rem 0 0;
  font-family: "ITC Avant Garde Gothic", sans-serif;
  font-size: clamp(0.98rem, 1.25vw, 1.22rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.15;
}

h1 .word {
  display: inline-block;
  will-change: transform, opacity;
}

.meta {
  position: absolute;
  z-index: 3;
  left: calc(var(--pad) + 1.5rem + env(safe-area-inset-left));
  right: calc(var(--pad) + 1.5rem + env(safe-area-inset-right));
  top: calc(var(--pad) - 0.35rem + env(safe-area-inset-top));
  bottom: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 0;
  font-family: "ITC Avant Garde Gothic", sans-serif;
  font-size: clamp(1.05rem, 1.45vw, 1.25rem);
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1;
}

.credit {
  position: absolute;
  z-index: 3;
  right: calc(var(--pad) + 1.5rem + env(safe-area-inset-right));
  bottom: calc(var(--pad) - 0.2rem + env(safe-area-inset-bottom));
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
  will-change: transform, opacity;
}

.credit-by {
  font-family: "ITC Avant Garde Gothic", sans-serif;
  font-size: clamp(0.58rem, 0.8vw, 0.68rem);
  font-weight: 500;
  letter-spacing: 0.04em;
  line-height: 1;
  opacity: 0.72;
}

.credit-logo {
  display: block;
  width: clamp(2.85rem, 4.2vw, 3.5rem);
  height: auto;
  pointer-events: none;
  user-select: none;
}

.credit:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 6px;
}

.meta a,
.meta .year {
  will-change: transform, opacity;
}

.meta a {
  color: var(--ink);
  text-decoration: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  background-image: linear-gradient(var(--ink), var(--ink));
  background-repeat: no-repeat;
  background-size: 0 2px;
  background-position: 0 100%;
  transition: background-size 180ms ease;
}

.meta a:hover,
.meta a:focus-visible {
  background-size: 100% 2px;
}

.meta a:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 6px;
}

.meta .year {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

/* Inverted deconstruct: pieces fly in from scatter → lock */
.piece {
  --fx: 0;
  --fy: 0;
  --fr: 0deg;
  --fs: 0.92;
  --d: 0ms;
  opacity: 0;
  transform:
    translate3d(var(--fx), var(--fy), 0)
    rotate(var(--fr))
    scale(var(--fs));
}

.piece-logo { --fx: -4.5rem; --fy: -3.2rem; --fr: -9deg; --fs: 0.88; --d: 0ms; }
.piece-w1 { --fx: 3.5rem; --fy: -2.4rem; --fr: 7deg; --fs: 0.9; --d: 70ms; }
.piece-w2 { --fx: -2.8rem; --fy: 1.6rem; --fr: -5deg; --fs: 0.9; --d: 120ms; }
.piece-w3 { --fx: 2.2rem; --fy: 2.8rem; --fr: 8deg; --fs: 0.9; --d: 170ms; }
.piece-smile { --fx: 1.5rem; --fy: 4.5rem; --fr: 18deg; --fs: 0.7; --d: 230ms; }
.piece-ig { --fx: -5rem; --fy: -2rem; --fr: -6deg; --fs: 0.92; --d: 300ms; }
.piece-year { --fx: 5rem; --fy: -2rem; --fr: 6deg; --fs: 0.92; --d: 340ms; }
.piece-credit { --fx: 3.5rem; --fy: 2.4rem; --fr: 4deg; --fs: 0.9; --d: 390ms; }

body.is-assembling .piece {
  animation: reconstruct 820ms var(--ease-out) var(--d) both;
}

body.is-ready .piece {
  opacity: 1;
  transform: none;
  animation: none;
}

@keyframes reconstruct {
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(0deg) scale(1);
  }
}

@media (hover: hover) and (pointer: fine) {
  .wash {
    display: block;
  }

  body.is-ready.is-tracking .logo {
    transform: translate3d(
      calc(var(--mx) * 14px),
      calc(var(--my) * 10px),
      0
    );
  }

  body.is-ready.is-tracking h1 .word:nth-child(1) {
    transform: translate3d(
      calc(var(--mx) * 18px),
      calc(var(--my) * 12px),
      0
    );
  }

  body.is-ready.is-tracking h1 .word:nth-child(2) {
    transform: translate3d(
      calc(var(--mx) * 22px),
      calc(var(--my) * 15px),
      0
    );
  }

  body.is-ready.is-tracking h1 .word:nth-child(3) {
    transform: translate3d(
      calc(var(--mx) * 26px),
      calc(var(--my) * 18px),
      0
    );
  }

  body.is-ready.is-tracking .smile-hit {
    transform:
      translate3d(
        calc(var(--mx) * 30px),
        calc(var(--my) * 22px),
        0
      )
      rotate(calc(var(--mx) * 18deg));
  }

  body.is-ready.is-tracking .meta a {
    transform: translate3d(
      calc(var(--mx) * -9px),
      calc(var(--my) * 6px),
      0
    );
  }

  body.is-ready.is-tracking .meta .year {
    transform: translate3d(
      calc(var(--mx) * 9px),
      calc(var(--my) * 6px),
      0
    );
  }

  body.is-ready.is-tracking .credit {
    transform: translate3d(
      calc(var(--mx) * 7px),
      calc(var(--my) * -4px),
      0
    );
  }
}

@media (prefers-reduced-motion: reduce) {
  .wash {
    display: none;
  }

  body.is-assembling .piece {
    animation: none;
    opacity: 1;
    transform: none;
  }

  body.is-ready.is-tracking .logo,
  body.is-ready.is-tracking h1 .word,
  body.is-ready.is-tracking .smile-hit,
  body.is-ready.is-tracking .meta a,
  body.is-ready.is-tracking .meta .year,
  body.is-ready.is-tracking .credit {
    transform: none;
  }
}
