/* Effects layer: everything here is decoration. Remove this file and effects.js and the page works the same. */

/* The court at night: a soft light over it that follows the pointer on desktop. */
.masthead::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    380px circle at var(--mx, 84%) var(--my, 72%),
    color-mix(in srgb, var(--court) 34%, transparent),
    transparent 70%
  );
}

/* Lines keep their faintness; the ball does not inherit it. */
.court { opacity: 1; --court-ink: 0.38; overflow: visible; }
.court rect, .court line { stroke-opacity: var(--court-ink); }
.court .net { stroke-opacity: 0.6; }
@media (max-width: 560px) { .court { --court-ink: 0.2; } .court .net { stroke-opacity: 0.3; } }

/* The ball rests where the last point left it. */
.rally { transform: translate(140px, 30px); }
.rally .ball { fill: var(--ball); stroke: none; transform-box: fill-box; transform-origin: center; }
@media (max-width: 560px) { .rally { opacity: 0.55; } }

/* Tabs: one underline that travels, instead of one per link. */
.sections.has-ink a.active { border-color: transparent; }
.tab-ink {
  position: absolute;
  left: 0; top: 0;
  width: var(--w, 0);
  height: 2px;
  background: var(--ink);
  transform: translate(var(--x, 0), var(--y, 0));
  pointer-events: none;
}

/* Segmented switches: one pill under the chosen option (effects.js), instead of each button painting its own. */
.segment.has-thumb { position: relative; isolation: isolate; }
.segment.has-thumb button[aria-checked="true"] { background: transparent; }
.segment-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 0;
  z-index: -1;
  width: var(--w, 0);
  transform: translateX(var(--x, 0));
  border-radius: 999px;
  background: var(--paper);
  pointer-events: none;
}
.segment.on-page .segment-thumb { background: var(--ink); }

@media (hover: hover) {
  tbody tr:not(.me):hover td { background: var(--paper-2); }
}

@media (prefers-reduced-motion: no-preference) {
  .masthead::before { transition: opacity 400ms ease; }
  .tab-ink.ready { transition: transform 320ms cubic-bezier(0.3, 0.8, 0.2, 1), width 320ms cubic-bezier(0.3, 0.8, 0.2, 1); }
  tbody tr td { transition: background-color 140ms ease; }

  /* The court draws itself, then a short point is played. Once per page load. */
  .court.play rect, .court.play line:not(.net) {
    stroke-dasharray: 1;
    animation: draw 900ms cubic-bezier(0.4, 0, 0.2, 1) both;
  }
  .court.play line:nth-of-type(1) { animation-delay: 150ms; }
  .court.play line:nth-of-type(2) { animation-delay: 250ms; }
  .court.play line:nth-of-type(3) { animation-delay: 400ms; }
  .court.play .net { animation: fade 500ms 500ms ease-out both; }
  @keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }

  .court.play .rally { animation: rally 4200ms 900ms linear both; }
  .court.play .ball { animation: lob 840ms 900ms ease-in-out 5 both; }
  @keyframes rally {
    0% { transform: translate(24px, 70px); opacity: 0; }
    3% { opacity: 1; }
    20% { transform: translate(170px, 34px); }
    40% { transform: translate(28px, 26px); }
    60% { transform: translate(166px, 70px); }
    80% { transform: translate(34px, 56px); }
    100% { transform: translate(140px, 30px); opacity: 1; }
  }
  /* Seen from above, height is size: the ball swells at the top of each shot. */
  @keyframes lob { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.9); } }

  /* The ball after the title drops in and bounces, once, when the page loads. A new group only makes it
     hop, and if the group is slow to load it keeps a small bounce going meanwhile. */
  .masthead-team.hop::after { animation: hop 380ms cubic-bezier(0.3, 0, 0.5, 1); }
  @keyframes hop { 45% { transform: translateY(-0.22em); } }
  body.loading .masthead-team::after { animation: dribble 420ms 400ms cubic-bezier(0.2, 0.6, 0.4, 1) infinite alternate; }
  @keyframes dribble { to { transform: translateY(-0.22em); } }
  .masthead-team.drop::after { animation: drop 780ms cubic-bezier(0.3, 0, 0.6, 1) both; }
  @keyframes drop {
    0% { transform: translateY(-1.6em); opacity: 0; }
    15% { opacity: 1; }
    45% { transform: translateY(0); animation-timing-function: cubic-bezier(0.2, 0.6, 0.4, 1); }
    62% { transform: translateY(-0.42em); animation-timing-function: cubic-bezier(0.6, 0, 0.8, 0.4); }
    78% { transform: translateY(0); animation-timing-function: cubic-bezier(0.2, 0.6, 0.4, 1); }
    89% { transform: translateY(-0.12em); animation-timing-function: cubic-bezier(0.6, 0, 0.8, 0.4); }
    100% { transform: translateY(0); }
  }

  /* A tab opens row by row instead of all at once. Browsers without sibling-index() bring the rows in together. */
  .tab.refresh { animation: none; }
  .tab.refresh :is(tbody tr, .round, .rival) { animation: row-in 420ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  .tab.refresh :is(tbody tr, .round, .rival) { animation-delay: calc(min(sibling-index(), 16) * 24ms); }
  @keyframes row-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

  /* Opening a match: the pairs come down one after another and each set lands like a scoreboard digit. */
  .match[open] .pair { animation: pair-in 320ms cubic-bezier(0.2, 0.7, 0.2, 1) both; }
  .match[open] .pair:nth-child(2) { animation-delay: 70ms; }
  .match[open] .pair:nth-child(3) { animation-delay: 140ms; }
  @keyframes pair-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
  .match[open] .set { animation: set-in 360ms cubic-bezier(0.3, 1.5, 0.5, 1) both; animation-delay: 120ms; }
  .match[open] .set:nth-child(2) { animation-delay: 190ms; }
  .match[open] .set:nth-child(3) { animation-delay: 260ms; }
  .match[open] .pair:nth-child(2) .set { animation-delay: 190ms; }
  .match[open] .pair:nth-child(2) .set:nth-child(2) { animation-delay: 260ms; }
  .match[open] .pair:nth-child(2) .set:nth-child(3) { animation-delay: 330ms; }
  .match[open] .pair:nth-child(3) .set { animation-delay: 260ms; }
  .match[open] .pair:nth-child(3) .set:nth-child(2) { animation-delay: 330ms; }
  .match[open] .pair:nth-child(3) .set:nth-child(3) { animation-delay: 400ms; }
  @keyframes set-in { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: none; } }

  /* The three dots under a score pop in order. */
  .tab.refresh .dots i, .round[open] .dots i { animation: set-in 320ms cubic-bezier(0.3, 1.5, 0.5, 1) both; animation-delay: 200ms; }
  .tab.refresh .dots i:nth-child(2), .round[open] .dots i:nth-child(2) { animation-delay: 270ms; }
  .tab.refresh .dots i:nth-child(3), .round[open] .dots i:nth-child(3) { animation-delay: 340ms; }

  /* Win-rate bars fill from empty. */
  .tab.refresh .bar i { animation: fill 700ms 200ms cubic-bezier(0.2, 0.7, 0.2, 1) both; transform-origin: left; }
  @keyframes fill { from { transform: scaleX(0); } to { transform: none; } }

  /* The evolution chart draws each team's path from the first round to the last. */
  .tab.refresh .evolution-chart .trace { stroke-dasharray: 1; animation: draw 900ms 150ms cubic-bezier(0.4, 0, 0.2, 1) both; }

  /* Sun to moon and back: the disc and the bite move with a little overshoot, the rays spin in after. */
  .theme-toggle .orb, .theme-toggle .bite { transition: transform 620ms cubic-bezier(0.5, 1.5, 0.4, 1); }
  .theme-toggle .rays { transition: transform 620ms cubic-bezier(0.5, 1.5, 0.4, 1), opacity 260ms ease; }
  :root[data-theme="dark"] .theme-toggle .rays { transition-delay: 140ms; }
  .theme-toggle:hover .rays { transform: rotate(45deg); }
  .theme-toggle:active svg { transform: scale(0.85); }
  .theme-toggle svg { transition: transform 160ms ease; }

  /* The pill slides to the new choice and settles with a small bounce; the pressed option gives a little. */
  .segment-thumb.ready { transition: transform 380ms cubic-bezier(0.34, 1.45, 0.64, 1), width 380ms cubic-bezier(0.34, 1.45, 0.64, 1); }
  .segment button { transition: background-color 160ms ease, color 200ms ease, transform 140ms ease; }
  .segment button:active { transform: scale(0.94); }

  /* Changing theme: the new one opens as a circle from the button that was pressed (see theme.js). */
  :root.theme-flip::view-transition-old(root) { animation: none; mix-blend-mode: normal; z-index: 0; }
  :root.theme-flip::view-transition-new(root) { animation: theme-reveal 700ms cubic-bezier(0.45, 0, 0.2, 1) both; mix-blend-mode: normal; z-index: 1; }
  @keyframes theme-reveal {
    from { clip-path: circle(0 at var(--flip-x) var(--flip-y)); }
    to { clip-path: circle(var(--flip-r) at var(--flip-x) var(--flip-y)); }
  }

  /* Saving a favourite. */
  .fav[aria-pressed="true"] svg { animation: star 700ms cubic-bezier(0.3, 0.7, 0.3, 1); }
  @keyframes star {
    0% { transform: scale(0.3) rotate(-216deg); }
    55% { transform: scale(1.45) rotate(18deg); }
    78% { transform: scale(0.92) rotate(-6deg); }
    100% { transform: none; }
  }

  /* A line of the index unfolds, where the browser can animate to a height it does not know beforehand. */
  .division-index { interpolate-size: allow-keywords; }
  .division::details-content { block-size: 0; overflow: clip; transition: block-size 300ms cubic-bezier(0.3, 0.7, 0.3, 1), content-visibility 300ms allow-discrete; }
  .division[open]::details-content { block-size: auto; }

  /* Scrolling away, the court drifts a little slower than the page. */
  @supports (animation-timeline: scroll()) {
    .court { animation: drift linear both; animation-timeline: scroll(root); animation-range: 0 480px; }
    @keyframes drift { to { transform: translateY(42px) scale(1.05); } }
  }
}
