/*
 * Everything that moves on the home page, only for those who accept it: without this file, the page is complete.
 */

/* ---------- Movement, for those who accept it: nothing above depends on it ---------- */

@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .game:hover {
    z-index: 1;
    rotate: 0deg;
    translate: 0 -0.25rem;
  }
}

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }

  .dot {
    animation: dot 2s var(--bf-ease-in-out) infinite;
  }

  .waves i {
    animation: wave 7s linear infinite;
  }
  .waves i:nth-child(2) {
    animation-delay: -1.75s;
  }
  .waves i:nth-child(3) {
    animation-delay: -3.5s;
  }
  .waves i:nth-child(4) {
    animation-delay: -5.25s;
  }

  .ticker-track {
    animation: ticker 48s linear infinite;
  }

  /*
   * One loop of 18 s tells the game's promise: the Tribunal elects Léa, another round goes by, then the game
   * remembers her. The phone's shake is the application's heavy-light-heavy vibration.
   */
  .table {
    --loop: 18s;
  }

  .scene,
  .phone,
  .seat,
  .seat-token,
  .vote,
  .flame-sweep,
  .flame-title,
  .typed::after {
    animation-duration: var(--loop);
    animation-iteration-count: infinite;
  }

  .scene-vote {
    animation-name: scene-vote;
  }
  .scene-play {
    animation-name: scene-play;
  }
  .scene-flame {
    animation-name: scene-flame;
    opacity: 0;
  }
  .scene-press {
    animation-name: scene-press;
  }

  .phone {
    animation-name: shake;
  }

  .seat {
    animation-name: seat-dim;
  }
  .seat-lea {
    animation-name: none;
  }
  .seat-lea .seat-token {
    animation-name: seat-called;
  }
  .seat-lea .seat-token::after {
    animation: seat-ring var(--loop) infinite;
  }

  .vote {
    animation-name: vote-dim;
  }
  .vote-lea {
    animation-name: vote-picked;
  }

  .flame-sweep {
    animation-name: sweep;
    animation-timing-function: linear;
  }

  .flame-title {
    animation-name: glitch;
  }

  /* The title types itself: a cover the colour of the screen withdraws by steps, line after line. */
  .typed::after {
    position: absolute;
    inset: -14% -3% -2%;
    background: var(--bf-bg);
    content: '';
    transform-origin: right;
  }

  .typed-1::after {
    animation-name: type-1;
  }

  .typed-2::after {
    animation-name: type-2;
  }

  .typed-3::after {
    animation-name: type-3;
  }

  /* The label that lets anyone stop the movement (WCAG 2.2.2): no script needed for a checkbox. */
  .motion {
    display: inline-flex;
    align-items: center;
    gap: var(--bf-space-2);
    min-height: 3rem;
    padding-inline: var(--bf-space-3);
    border-radius: var(--bf-radius-chip);
    background: var(--bf-surface-1);
    color: var(--bf-text-muted);
    cursor: pointer;
    font-size: var(--bf-font-label);
    font-weight: var(--bf-weight-medium);
  }

  .motion:hover {
    color: var(--bf-text);
  }

  .motion:has(input:focus-visible) {
    outline: 3px solid var(--bf-focus);
    outline-offset: 3px;
  }

  .motion input {
    position: absolute;
    opacity: 0;
    inset: 0;
    margin: 0;
    cursor: pointer;
  }

  .motion-box {
    display: grid;
    place-items: center;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid currentcolor;
    border-radius: 0.3rem;
    color: var(--bf-text-muted);
  }

  .motion-box svg {
    width: 0.85rem;
    height: 0.85rem;
    fill: var(--bf-on-accent);
    opacity: 0;
  }

  .motion input:checked + .motion-box {
    border-color: var(--bf-accent);
    background: var(--bf-accent);
  }

  .motion input:checked + .motion-box svg {
    opacity: 1;
  }

  /* Only what plays by itself stops: the reveals below follow the visitor's own scrolling. */
  html:has(.motion input:checked) .ticker-track,
  html:has(.motion input:checked) .dot,
  html:has(.motion input:checked) .table *,
  html:has(.motion input:checked) .seat-lea .seat-token::after,
  html:has(.motion input:checked) .typed::after {
    animation-play-state: paused;
  }

  @supports (animation-timeline: view()) {
    .game,
    .beat,
    .poster-sheet,
    .party {
      animation: reveal linear both;
      animation-range: entry 0% entry 55%;
      animation-timeline: view();
    }

    .game:nth-child(even) {
      animation-name: reveal-right;
    }

    .game:nth-child(odd) {
      animation-name: reveal-left;
    }
  }
}

@keyframes dot {
  50% {
    opacity: 0.35;
    transform: scale(0.8);
  }
}

@keyframes wave {
  0% {
    opacity: 0;
    transform: scale(0.45);
  }
  20% {
    opacity: 0.45;
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}

@keyframes ticker {
  to {
    transform: translateX(-50%);
  }
}

@keyframes scene-vote {
  0%,
  26% {
    opacity: 1;
    transform: none;
  }
  28%,
  98% {
    opacity: 0;
    transform: translateY(-3%);
  }
  100% {
    opacity: 1;
    transform: none;
  }
}

@keyframes scene-play {
  0%,
  26% {
    opacity: 0;
    transform: translateY(5%);
  }
  29%,
  44% {
    opacity: 1;
    transform: none;
  }
  46%,
  100% {
    opacity: 0;
    transform: none;
  }
}

@keyframes scene-flame {
  0%,
  45% {
    opacity: 0;
  }
  46%,
  70% {
    opacity: 1;
  }
  72%,
  100% {
    opacity: 0;
  }
}

@keyframes scene-press {
  0%,
  70% {
    opacity: 0;
    transform: scale(0.96);
  }
  73%,
  97% {
    opacity: 1;
    transform: none;
  }
  99%,
  100% {
    opacity: 0;
    transform: none;
  }
}

@keyframes shake {
  0%,
  46%,
  48.4%,
  100% {
    transform: none;
  }
  46.6% {
    transform: translateX(-2%);
  }
  47.2% {
    transform: translateX(1%);
  }
  47.8% {
    transform: translateX(-2%);
  }
}

@keyframes seat-dim {
  0%,
  10%,
  28%,
  46% {
    opacity: 1;
  }
  12%,
  26%,
  48%,
  97% {
    opacity: 0.35;
  }
  100% {
    opacity: 1;
  }
}

@keyframes seat-called {
  0%,
  10%,
  28%,
  46% {
    transform: none;
  }
  12%,
  26% {
    transform: scale(1.14);
  }
  48%,
  97% {
    transform: scale(1.3);
  }
  100% {
    transform: none;
  }
}

@keyframes seat-ring {
  0%,
  46%,
  99%,
  100% {
    opacity: 0;
  }
  48%,
  97% {
    opacity: 1;
  }
}

@keyframes vote-dim {
  0%,
  10% {
    opacity: 1;
  }
  12%,
  100% {
    opacity: 0.35;
  }
}

@keyframes vote-picked {
  0%,
  10%,
  14%,
  100% {
    transform: none;
  }
  12% {
    transform: scale(1.07);
  }
}

@keyframes sweep {
  0%,
  46% {
    opacity: 0;
    transform: translateY(-100%);
  }
  46.5% {
    opacity: 0.9;
  }
  52% {
    opacity: 0.9;
    transform: translateY(1400%);
  }
  52.5%,
  100% {
    opacity: 0;
    transform: translateY(1400%);
  }
}

@keyframes glitch {
  0%,
  47%,
  49%,
  50.4%,
  100% {
    transform: none;
  }
  47.6% {
    transform: translateX(-2.5%);
  }
  48.2% {
    transform: translateX(2%);
  }
  49.8% {
    transform: translateX(-1%);
  }
}

@keyframes type-1 {
  0%,
  47% {
    transform: scaleX(1);
    animation-timing-function: steps(5);
  }
  49%,
  100% {
    transform: scaleX(0);
  }
}

@keyframes type-2 {
  0%,
  49% {
    transform: scaleX(1);
    animation-timing-function: steps(9);
  }
  53%,
  100% {
    transform: scaleX(0);
  }
}

@keyframes type-3 {
  0%,
  53% {
    transform: scaleX(1);
    animation-timing-function: steps(5);
  }
  55.5%,
  100% {
    transform: scaleX(0);
  }
}

@keyframes reveal {
  from {
    opacity: 0;
    translate: 0 2.5rem;
  }
}

@keyframes reveal-left {
  from {
    opacity: 0;
    translate: -3rem 0;
  }
}

@keyframes reveal-right {
  from {
    opacity: 0;
    translate: 3rem 0;
  }
}
