/*
 * The opening animation (OpeningAnimation.jsx), about 3.5 s:
 *
 *   0.0 - 1.0  service tiles float in from off-screen, tumbling, and scatter
 *   1.0 - 2.0  they drift to the centre and fade while the two halves of the H
 *              slide in from the sides and meet: the two hands
 *   2.0 - 2.7  the hands shake: a small rock and bounce, then settle
 *   2.7 - 3.5  the H zooms toward the camera and the screen fades to the site
 *
 * Only transform and opacity animate, so phones composite it on the GPU
 * without re-laying out the page underneath.
 *
 * One file for both places it plays: the app (OpeningAnimation.jsx, linked
 * from index.html) and the pre-launch page /join (join.html, join-intro.js).
 * The app supplies its theme tokens (--bg, --surface, --line, --muted); /join
 * has none, so the fallbacks are its own navy colours.
 */

.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg, #0b1829);
  overflow: hidden;
  display: grid;
  place-items: center;
  animation: intro-fade 0.65s ease-in 2.85s forwards;
}

.intro-tiles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.intro-tile {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(13vmin, 64px);
  height: min(13vmin, 64px);
  margin: calc(min(13vmin, 64px) / -2) 0 0 calc(min(13vmin, 64px) / -2);
  border-radius: 28%;
  background: var(--surface, #12233a);
  border: 1px solid var(--line, #2a3b55);
  box-shadow: 0 6px 18px rgb(15 32 56 / 0.12);
  display: grid;
  place-items: center;
  font-size: min(6.5vmin, 32px);
  line-height: 1;
  opacity: 0;
  will-change: transform, opacity;
  animation: intro-tile 2s cubic-bezier(0.45, 0, 0.3, 1) var(--delay) forwards;
}

@keyframes intro-tile {
  0% {
    transform: translate(var(--from-x), var(--from-y)) rotate(var(--spin)) scale(0.8);
    opacity: 0;
  }
  18% {
    opacity: 1;
  }
  50% {
    transform: translate(var(--x), var(--y)) rotate(calc(var(--spin) / -3)) scale(1);
    opacity: 1;
  }
  85% {
    opacity: 0.9;
  }
  100% {
    transform: translate(0, 0) rotate(0deg) scale(0.25);
    opacity: 0;
  }
}

/* The mark: zoom wraps shake wraps the disc and the two halves. */
.intro-zoom {
  position: relative;
  width: min(56vmin, 260px);
  height: min(56vmin, 260px);
  will-change: transform, opacity;
  animation: intro-zoom 0.8s cubic-bezier(0.55, 0, 0.85, 0.35) 2.7s forwards;
}

.intro-shake {
  position: absolute;
  inset: 0;
  animation: intro-shake 0.7s ease-in-out 2s both;
}

/* The H artwork is navy and gold on white, so it sits on a white disc in both
   themes, the way the header logo sits on a white chip in dark mode. */
.intro-disc {
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 10px 40px rgb(15 32 56 / 0.18);
  opacity: 0;
  animation: intro-disc 0.6s ease-out 1s forwards;
}

.intro-half {
  position: absolute;
  inset: 14%;
  width: 72%;
  height: 72%;
  object-fit: contain;
  opacity: 0;
  will-change: transform, opacity;
}
.intro-half.left {
  clip-path: inset(0 50% 0 0);
  animation: intro-left 1s cubic-bezier(0.2, 0.8, 0.25, 1) 1s forwards;
}
.intro-half.right {
  clip-path: inset(0 0 0 50%);
  animation: intro-right 1s cubic-bezier(0.2, 0.8, 0.25, 1) 1s forwards;
}

@keyframes intro-disc {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes intro-left {
  from { transform: translateX(-70%) rotate(-14deg); opacity: 0; }
  35% { opacity: 1; }
  to { transform: translateX(0) rotate(0deg); opacity: 1; }
}
@keyframes intro-right {
  from { transform: translateX(70%) rotate(14deg); opacity: 0; }
  35% { opacity: 1; }
  to { transform: translateX(0) rotate(0deg); opacity: 1; }
}

/* A handshake: down, up, down a little less, settle. */
@keyframes intro-shake {
  0% { transform: translateY(0) rotate(0deg); }
  20% { transform: translateY(5%) rotate(-4deg); }
  40% { transform: translateY(-4%) rotate(3deg); }
  60% { transform: translateY(3%) rotate(-2deg); }
  80% { transform: translateY(-1%) rotate(1deg); }
  100% { transform: translateY(0) rotate(0deg); }
}

@keyframes intro-zoom {
  0% { transform: scale(1); opacity: 1; }
  60% { opacity: 1; }
  100% { transform: scale(9); opacity: 0; }
}

@keyframes intro-fade {
  to { opacity: 0; visibility: hidden; }
}

/* Explicit size and spacing: /join styles every button full-width and gold. */
.intro-skip {
  position: absolute;
  width: auto;
  margin: 0;
  cursor: pointer;
  line-height: 1.2;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  z-index: 1;
  font-family: var(--font-display, inherit);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted, #c5cdd8);
  background: var(--surface, #12233a);
  border: 1px solid var(--line, #2a3b55);
  border-radius: 999px;
  padding: 6px 14px;
}

/* Belt and braces: the component already checks this before playing. */
@media (prefers-reduced-motion: reduce) {
  .intro-overlay {
    display: none;
  }
}

/*
 * /join only: join-intro.js sets this on <html> before the page paints, so the
 * buttons are never seen and then covered. It is a plain cover, not the page
 * hidden: it switches itself off after 4.5 s by CSS alone, and the script
 * removes it as soon as the animation ends or is skipped, so the buttons can
 * never be left hidden.
 */
html.intro-cover::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 99;
  background: var(--bg, #0b1829);
  animation: intro-cover-off 0s linear 4.5s forwards;
}
@keyframes intro-cover-off {
  to { visibility: hidden; }
}
@media (prefers-reduced-motion: reduce) {
  html.intro-cover::after { display: none; }
}
