/* ==========================================================================
   the goo collection — the goo games

   Opened from the controller beside the music note, on every page, by
   js/games.js. Both are linked in every page's <head>, so the controller is
   styled from the first paint. Three pieces:

   1. the controller itself, styled to sit beside the note in the bar;
   2. the picker, a little shelf of games that drops out of the controller;
   3. the layer — a cream veil, the goo field and the readout — poured over
      the whole page for the length of a round.
   ========================================================================== */

/* ---- Per-round goo palette ----------------------------------------------
   Each game borrows one brand group for the round, set on the layer by
   js/games.js so both the filtered field and the unfiltered ripple layer
   retint together. Pink leads with its coral rather than its primary:
   #ebd0fb over cream at droplet scale is a smudge, not a colour (same call
   as the nav wordmark). */

.goo-games {
  --drop-a: #ffce57;
  --drop-b: #b4ccd6;
  --group-glow: rgba(80, 52, 30, 0.4);
}

.goo--yellow {
  --drop-a: #ffce57;
  --drop-b: #b4ccd6;
  --group-glow: rgba(80, 52, 30, 0.4);
}

.goo--pink {
  --drop-a: #ff9e8e;
  --drop-b: #ebd0fb;
  --group-glow: rgba(255, 158, 142, 0.55);
}

.goo--green {
  --drop-a: #95d46c;
  --drop-b: #f39067;
  --group-glow: rgba(89, 127, 47, 0.45);
}

/* ==========================================================================
   1. The controller — the note's twin
   ========================================================================== */

.games {
  position: relative;
  display: inline-flex;
}

.site-nav .games-toggle {
  position: relative;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--ink);
  background: rgba(80, 52, 30, 0.06);
  transition:
    transform 0.35s var(--ease-spring),
    background 0.35s var(--ease-smooth);
}

.site-nav .games-toggle .site-nav__icon {
  width: 22px;
  height: 22px;
}

.site-nav .games-toggle:hover,
.site-nav .games-toggle:focus-visible {
  transform: scale(1.08);
  background: rgba(80, 52, 30, 0.12);
}

.site-nav .games-toggle:active {
  transform: scale(1);
}

/* Open → lit, the same yellow the note wears while it sounds. */
.games.is-open .games-toggle {
  background: var(--yellow);
  box-shadow: 0 8px 22px -10px rgba(255, 206, 87, 0.95);
}

/* ==========================================================================
   2. The picker — a shelf of goo hanging off the controller
   ========================================================================== */

.goo-games__picker {
  position: absolute;
  top: calc(100% + 0.9rem);
  left: 50%;
  z-index: 2;
  width: max-content;
  max-width: calc(100vw - 2 * var(--space-2));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--cream);
  box-shadow:
    0 30px 60px -30px rgba(80, 52, 30, 0.45),
    0 10px 22px -14px rgba(255, 206, 87, 0.7),
    0 0 0 1.5px rgba(255, 206, 87, 0.55);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -0.6rem) scale(0.94);
  transform-origin: top center;
  /* On the way out, visibility waits for the fade so nothing inside stays
     focusable once it is gone. */
  transition:
    opacity 0.24s var(--ease-smooth),
    transform 0.5s var(--ease-spring),
    visibility 0s linear 0.24s;
}

/* The same drop the note's bubble hangs from: the shelf reads as goo that came off
   the button, not as a menu. */
.goo-games__picker::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 0.2rem);
  left: 50%;
  width: 0.5rem;
  height: 0.5rem;
  margin-left: -0.25rem;
  border-radius: 50%;
  background: var(--yellow);
}

.games.is-open .goo-games__picker {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0) scale(1);
  transition:
    opacity 0.24s var(--ease-smooth),
    transform 0.5s var(--ease-spring);
}

.goo-games__picker-line {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.95rem;
  text-transform: lowercase;
  text-align: center;
  color: var(--ink);
  opacity: 0.72;
}

.goo-games__list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

/* ---- A game --------------------------------------------------------------
   One frame, three colours: the blob is the only thing that changes between
   them, so they read as a set of one kind of thing. */

.goo-games__start {
  display: flex;
  align-items: center;
  gap: 0.7em;
  padding: 0.78em 1.4em;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.95rem;
  text-transform: lowercase;
  letter-spacing: -0.01em;
  color: var(--ink);
  background: var(--white);
  box-shadow:
    inset 0 0 0 1.5px rgba(80, 52, 30, 0.14),
    0 8px 18px -12px rgba(80, 52, 30, 0.45);
  transition:
    transform 0.35s var(--ease-spring),
    box-shadow 0.35s var(--ease-smooth);
}

.goo-games__start:hover,
.goo-games__start:focus-visible {
  transform: translateY(-2px);
  box-shadow:
    inset 0 0 0 1.5px var(--blob),
    0 12px 22px -12px var(--blob);
}

.goo-games__start:active {
  transform: translateY(0);
}

/* A droplet on the button, churning like the goo it is about to release —
   and out of step with its neighbours, so the shelf never pulses in unison. */
.goo-games__start-blob {
  width: 0.95em;
  height: 0.95em;
  flex-shrink: 0;
  background: var(--blob);
  border-radius: 38% 62% 64% 36% / 58% 41% 59% 42%;
  animation: gooGamesChurn var(--churn, 6s) ease-in-out infinite;
}

.goo-games__start--yellow { --blob: var(--yellow); --churn: 6s; }
.goo-games__start--pink   { --blob: var(--pink-accent2); --churn: 7.4s; }
.goo-games__start--green  { --blob: var(--green); --churn: 8.6s; }

/* Gather is a drag: it wants a pointer travelling across the goo, and on a
   phone it is the one of the three that competes with a finger. It goes; the
   line above never names a number, so nothing else has to change. */
@media (max-width: 640px) {
  .goo-games__start[data-game="gather"] {
    display: none;
  }
}

/* Under the burger breakpoint the controller sits near the right edge, and a
   shelf centred on it would run off the screen. Pin it to the gutter instead,
   and let the drop stay with the button rather than with the shelf. */
@media (max-width: 1080px) {
  .goo-games__picker {
    position: fixed;
    top: calc(var(--nav-h, 84px) - 0.25rem);
    left: auto;
    right: var(--space-2);
    transform: translateY(-0.6rem) scale(0.94);
    transform-origin: top right;
  }

  .games.is-open .goo-games__picker {
    transform: none;
  }

  .goo-games__picker::before {
    display: none;
  }
}

/* ==========================================================================
   3. The layer — poured over the page for the length of a round
   ========================================================================== */

.goo-games {
  position: fixed;
  inset: 0;
  z-index: 110; /* over the bar (100): a round is the whole screen */
  pointer-events: none;
}

.goo-games__defs {
  position: absolute;
  width: 0;
  height: 0;
}

/* Cream poured over the page so the goo reads on any page underneath —
   photos, coloured bands, the story's portraits. It is also the round's
   hit area: it takes every press, so nothing under it is clicked, dragged,
   selected or scrolled by accident. */
.goo-games__veil {
  position: absolute;
  inset: 0;
  background: rgba(255, 254, 251, 0.86);
  opacity: 0;
  transition: opacity 0.9s var(--ease-smooth);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.goo-games.is-round .goo-games__veil {
  opacity: 1;
  pointer-events: auto;
}

/* The page under a round stays put: no scrollbar to drag, no wheel scroll
   moving it out from under the veil. */
html.goo-games-on,
html.goo-games-on body {
  overflow: hidden;
}

/* ---- The goo field ------------------------------------------------------
   Droplets and the pointer-led blob, all fused by the #gooGamesField metaball
   filter so they reach for each other before they touch. The rings sit
   outside that filter, because a ring pushed through the alpha ramp would
   dissolve. */

.goo-games__field,
.goo-games__rings {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.goo-games__field {
  filter: url(#gooGamesField);
  opacity: 0;
  transition: opacity 1.1s var(--ease-smooth);
}

.goo-games.is-round .goo-games__field {
  opacity: 0.9;
}

/* Parked whenever the tab is hidden — a full-viewport SVG filter is not
   something to keep re-running in the background. */
.goo-games__field.is-idle {
  visibility: hidden;
}

/* Each blob is two elements: the outer one is positioned and scaled every
   frame, the inner "skin" carries the churn. Splitting them keeps the two
   transforms from overwriting each other. */
.goo-games__drop,
.goo-games__cursor {
  position: absolute;
  top: 0;
  left: 0;
  will-change: transform;
}

.goo-games__skin {
  display: block;
  width: 100%;
  height: 100%;
  /* Alpha stays high across the body of the blob so the metaball ramp has a
     surface to threshold; the falloff only softens the rim. */
  background: radial-gradient(
    circle at 38% 34%,
    var(--c) 0%,
    var(--c) 64%,
    rgba(255, 254, 251, 0) 100%
  );
  /* Lopsided radii turned slowly against an uneven squash — a perfect circle
     reads as a dot, this reads as something soft that hasn't settled. */
  border-radius: 38% 62% 64% 36% / 58% 41% 59% 42%;
  animation: gooGamesChurn var(--churn, 13s) ease-in-out infinite;
  animation-delay: var(--churn-delay, 0s);
}

@keyframes gooGamesChurn {
  0%, 100% { border-radius: 38% 62% 64% 36% / 58% 41% 59% 42%; transform: rotate(0deg)   scale(1, 1); }
  25%      { border-radius: 63% 37% 39% 61% / 41% 64% 36% 59%; transform: rotate(90deg)  scale(1.1, 0.9); }
  50%      { border-radius: 56% 44% 34% 66% / 67% 37% 63% 33%; transform: rotate(180deg) scale(0.92, 1.09); }
  75%      { border-radius: 35% 65% 59% 41% / 44% 60% 40% 56%; transform: rotate(270deg) scale(1.07, 0.94); }
}

.goo-games__cursor {
  --c: var(--drop-a);
  opacity: 0;
  transition: opacity 0.55s var(--ease-smooth);
}

.goo-games__cursor .goo-games__skin {
  --churn: 7s;
}

.goo-games__cursor.is-live {
  opacity: 1;
}

/* Absorption ripple — one ring per droplet gathered, removed on animationend. */
.goo-games__ring {
  position: absolute;
  top: 0;
  left: 0;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  border: 2px solid var(--group-glow);
  animation: gooGamesRing 0.7s var(--ease-smooth) forwards;
}

@keyframes gooGamesRing {
  from { transform: translate3d(var(--x), var(--y), 0) scale(1); opacity: 0.9; }
  to   { transform: translate3d(var(--x), var(--y), 0) scale(9); opacity: 0; }
}

/* A blob grown past its limit throws a wider, faster ring than a gathered
   droplet does — a burst should read as a burst from across the page. */
.goo-games__ring--burst {
  border-width: 3px;
  border-color: var(--drop-a);
  animation-name: gooGamesBurst;
  animation-duration: 0.55s;
}

@keyframes gooGamesBurst {
  from { transform: translate3d(var(--x), var(--y), 0) scale(2); opacity: 1; }
  to   { transform: translate3d(var(--x), var(--y), 0) scale(22); opacity: 0; }
}

/* ---- Readout ------------------------------------------------------------
   The count, and the way back out, floating at the foot of the screen. A
   round you cannot leave is a trap, and stop is also the only way out
   without a pointer or an Esc key. The count and the finished line share one
   cell, so swapping them never jolts the pill. */

.goo-games__readout {
  position: absolute;
  left: 50%;
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 0 var(--space-2);
  padding: 0.7em 0.7em 0.7em 1.4em;
  border-radius: var(--radius-pill);
  background: var(--white);
  box-shadow:
    0 22px 40px -22px rgba(80, 52, 30, 0.5),
    0 0 0 1.5px var(--group-glow);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 1rem);
  transition:
    opacity 0.4s var(--ease-smooth),
    transform 0.6s var(--ease-spring),
    visibility 0s linear 0.4s;
}

.goo-games.is-round .goo-games__readout {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate(-50%, 0);
  transition:
    opacity 0.4s var(--ease-smooth) 0.2s,
    transform 0.6s var(--ease-spring) 0.2s;
}

.goo-games__score {
  grid-area: 1 / 1;
  font-family: var(--font-display);
  font-weight: 500;
  text-transform: lowercase;
  font-size: 0.92rem;
  letter-spacing: 0.01em;
  color: var(--ink);
  white-space: nowrap;
  transition: opacity 0.35s var(--ease-smooth);
}

.goo-games__done {
  opacity: 0;
}

.goo-games__readout.is-done .goo-games__score:not(.goo-games__done) {
  opacity: 0;
}

.goo-games__readout.is-done .goo-games__done {
  opacity: 1;
}

.goo-games__stop {
  grid-area: 1 / 2;
  padding: 0.5em 1.1em;
  border-radius: var(--radius-pill);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.85rem;
  text-transform: lowercase;
  color: var(--cream);
  background: var(--ink);
  transition:
    transform 0.3s var(--ease-spring),
    opacity 0.3s var(--ease-smooth);
}

.goo-games__stop:hover,
.goo-games__stop:focus-visible {
  transform: scale(1.06);
}

.goo-games__stop:active {
  transform: scale(0.97);
}

.goo-games__readout.is-done .goo-games__stop {
  opacity: 0;
  pointer-events: none;
}

/* On a narrow phone the hint is the longest line in the pill; let it wrap
   rather than push the pill past the gutters. */
@media (max-width: 480px) {
  .goo-games__readout {
    width: max-content;
    max-width: calc(100vw - 2 * var(--space-2));
  }

  .goo-games__score {
    white-space: normal;
  }
}

/* ---- Reduced motion -----------------------------------------------------
   The goo still arrives and leaves — it is the game — but nothing churns,
   springs or ripples. */
@media (prefers-reduced-motion: reduce) {
  .goo-games__skin,
  .goo-games__start-blob {
    animation: none;
  }

  .goo-games__ring {
    display: none;
  }

  .goo-games__picker,
  .games.is-open .goo-games__picker {
    transform: translate(-50%, 0);
  }

  .goo-games__readout,
  .goo-games.is-round .goo-games__readout {
    transform: translate(-50%, 0);
  }
}

@media (prefers-reduced-motion: reduce) and (max-width: 1080px) {
  .goo-games__picker,
  .games.is-open .goo-games__picker {
    transform: none;
  }
}
