/*
  The landing page's hero: the logo ball opens once when the page loads, then example
  challenges pop out of it, one a second, each bumping the last out of the way. After the
  tenth the first comes round again, and so on.

  The opening follows the app's own reveal (ChallengeSphere/Features/Inbox/Reveal and
  ChallengeCore's SphereRevealTimeline.standard): the shut ball shakes for 0.45s, the halves
  swing 30 degrees apart over 0.55s and a beam comes on. The ball then stays open.

  CSS only, no scripts. Each card carries its place in the queue as --i (0 to 9) in the HTML,
  and its start time is worked out from that. The card keyframes are written for ten cards a
  second apart (a 10 second lap); with a different number, set --cards and rework their
  percentages (seconds / lap * 100).
*/

.hero {
  position: relative;
  /* When the halves start to part, and when the first challenge starts to climb. */
  --opens-at: 0.95s;
  --first-rise: 1.15s;
  /* How many example cards there are, and how long each has before the next arrives. */
  --cards: 10;
  --step: 1s;
  /* One lap of the queue: every card has had its turn. */
  --lap: calc(var(--cards) * var(--step));
  --sphere-size: clamp(8rem, 38vw, 12rem);
  /* Room above the ball for the tallest card. */
  --slot-height: 12.5rem;
  --slot-gap: 0.25rem;
  /* From the middle of the ball up to the middle of that room. */
  --climb: calc(var(--slot-height) / 2 + var(--slot-gap) + var(--sphere-size) / 2);
  --glow: 255 217 59;
}

.reveal {
  position: relative;
  isolation: isolate;
  display: grid;
  justify-items: center;
  width: 100%;
  max-width: 20rem;
  text-align: left;
}

/* ---------- The ball ---------- */

.reveal-sphere {
  position: relative;
  z-index: 3;
  width: var(--sphere-size);
  height: var(--sphere-size);
  margin-top: var(--slot-gap);
  transform-origin: 50% 100%;
  animation: reveal-shake var(--opens-at) ease-in-out 1 both;
}

/* Each half is hinged at the foot of the ball, so the top opens like a pair of jaws. */
.reveal-half {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  transform-origin: 50% 100%;
  animation-duration: 0.55s;
  animation-delay: var(--opens-at);
  animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
  animation-iteration-count: 1;
  animation-fill-mode: both;
}

.reveal-half-left {
  animation-name: reveal-open-left;
}

.reveal-half-right {
  animation-name: reveal-open-right;
}

/* The light between the halves. It sits behind them, so it only shows once they part. */
.reveal-glow {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: radial-gradient(circle, #ffffff 10%, rgb(var(--glow)) 40%, rgb(var(--glow) / 0) 70%);
  opacity: 0;
  animation: reveal-light var(--step) var(--first-rise) infinite;
}

/* ---------- The beam ---------- */

/* Narrow where it leaves the ball, wide where the challenge comes to rest. */
.reveal-beam {
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  top: 0;
  bottom: calc(var(--sphere-size) / 2);
  transform-origin: 50% 100%;
  /* The blur is here, on the parent, so the cone's cut edges soften with it. */
  filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  animation: reveal-beam 0.15s var(--opens-at) 1 both;
}

.reveal-beam::before {
  content: "";
  position: absolute;
  inset: 0;
  clip-path: polygon(0 0, 100% 0, 62% 100%, 38% 100%);
  background: linear-gradient(to top, rgb(var(--glow) / 0.7), rgb(var(--glow) / 0.3) 60%, rgb(var(--glow) / 0));
}

/* ---------- The challenge cards ---------- */

/* Every card sits in the same place, centred in the room above the ball. */
.reveal-slot {
  position: relative;
  z-index: 2;
  display: grid;
  width: 100%;
  height: var(--slot-height);
}

/*
  The app's ChallengeHeroCard: a yellow card with a darker edge underneath.
  Each new card comes up from below, covers the one before it and knocks it up and out of
  the way. Which card is on top is part of the animation (reveal-card-order), so that the
  first card can cover the last when the queue comes round again.
*/
.reveal-card {
  grid-area: 1 / 1;
  align-self: center;
  border-radius: 24px;
  background: var(--yellow);
  /* The darker edge underneath, and a thin rim so one yellow card shows against another. */
  box-shadow: 0 4px 0 var(--yellow-edge), 0 0 0 1.5px var(--yellow-edge);
  padding: 1rem;
  color: var(--ink);
  opacity: 0;
  /* Which way it tips as it is knocked away. */
  --tilt: -7deg;
  animation:
    reveal-card-move var(--lap) infinite backwards,
    reveal-card-show var(--lap) infinite backwards,
    reveal-card-order var(--lap) infinite backwards;
  animation-delay: calc(var(--first-rise) + var(--i) * var(--step));
}

.reveal-card:nth-child(even) {
  --tilt: 7deg;
}

.reveal-title {
  font-size: 1.25rem;
  font-weight: 900;
  line-height: 1.2;
}

.reveal-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 0.75rem;
}

.reveal-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 10px;
  background: #ffffff;
  padding: 4px 12px;
  font-size: 0.8125rem;
  font-weight: 800;
  line-height: 1.2;
}

/* A category's colour is its place in the list, as in the app. */
.reveal-pill.is-green { background: var(--green); }
.reveal-pill.is-pink { background: var(--pink); }
.reveal-pill.is-blue { background: var(--blue); }
.reveal-pill.is-orange { background: #ffa43a; }
.reveal-pill.is-purple { background: #b79cff; }
.reveal-pill.is-teal { background: var(--teal); }
.reveal-pill.is-coral { background: var(--coral); }

/* ---------- Pause ---------- */

/* A real checkbox, hidden but still reachable by keyboard. Its label draws the box. */
.reveal-pause {
  position: absolute;
  left: calc(50% - 0.625rem);
  bottom: 2.5rem;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  opacity: 0;
}

.reveal-pause-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 800;
  cursor: pointer;
}

.reveal-pause-label::before {
  content: "";
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: #ffffff;
}

.reveal-pause:checked ~ .reveal-pause-label::before {
  background: var(--violet);
  box-shadow: inset 0 0 0 3px #ffffff;
}

.reveal-pause:focus-visible ~ .reveal-pause-label {
  outline: 3px solid var(--violet);
  outline-offset: 3px;
  border-radius: 6px;
}

.reveal-pause:checked ~ .reveal *,
.reveal-pause:checked ~ .reveal *::before {
  animation-play-state: paused;
}

/* ---------- The ball opening, once ---------- */

/* A slow swell while it waits, then a shake that starts and ends level (0.5s, then 0.45s). */
@keyframes reveal-shake {
  0% { transform: scale(1) rotate(0deg); }
  26% { transform: scale(1.03) rotate(0deg); }
  52.6% { transform: scale(1) rotate(0deg); }
  58.5% { transform: scale(1) rotate(3.8deg); }
  70.4% { transform: scale(1) rotate(-9.2deg); }
  82.2% { transform: scale(1) rotate(9.2deg); }
  94.1% { transform: scale(1) rotate(-3.8deg); }
  100% { transform: scale(1) rotate(0deg); }
}

@keyframes reveal-open-left {
  from { transform: translateX(0) rotate(0deg); }
  to { transform: translateX(-10%) rotate(-30deg); }
}

@keyframes reveal-open-right {
  from { transform: translateX(0) rotate(0deg); }
  to { transform: translateX(10%) rotate(30deg); }
}

/* ---------- Light ---------- */

/* The light inside the ball flares as each challenge leaves it. */
@keyframes reveal-light {
  0% { opacity: 1; }
  60% { opacity: 0.55; }
  100% { opacity: 1; }
}

/* Comes on as the halves part and stays on. It widens as it brightens. */
@keyframes reveal-beam {
  from { opacity: 0; transform: scaleX(0.5); }
  to { opacity: 1; transform: scaleX(1); }
}

/* ---------- One card's turn, on the 10 second lap ---------- */

/*
  Seconds into its turn: 0 starts to climb out of the ball (quick, then easing to a stop),
  0.5 at rest, 1.15 the next card reaches it from below and knocks it up and away, 1.6 gone.
  It then waits out of sight for the rest of the lap.
*/
@keyframes reveal-card-move {
  0% {
    transform: translateY(var(--climb)) scale(0.15);
    animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
  }
  5%, 11.5% {
    transform: translateY(0) scale(1);
    animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
  }
  16%, 100% { transform: translateY(-3.5rem) rotate(var(--tilt)) scale(0.94); }
}

@keyframes reveal-card-show {
  0% { opacity: 0; }
  0.6%, 13.5% { opacity: 1; }
  16%, 100% { opacity: 0; }
}

/* On top for its first second; then the next card, which starts a second later, covers it. */
@keyframes reveal-card-order {
  0%, 9.9% { z-index: 2; }
  10%, 100% { z-index: 1; }
}

/* ---------- No motion: the open ball with one challenge above it ---------- */

@media (prefers-reduced-motion: reduce) {
  .reveal-sphere,
  .reveal-half,
  .reveal-glow,
  .reveal-beam,
  .reveal-card {
    animation: none;
  }

  .reveal-half-left {
    transform: translateX(-10%) rotate(-30deg);
  }

  .reveal-half-right {
    transform: translateX(10%) rotate(30deg);
  }

  .reveal-glow {
    opacity: 0.35;
  }

  .reveal-card:first-child {
    opacity: 1;
  }

  .reveal-pause,
  .reveal-pause-label {
    display: none;
  }
}

.hero-categories {
  max-width: 30rem;
  color: var(--muted);
  font-weight: 700;
}
