/* The falling notes of the site (task W): the widget of web/keyfall/keyfall.js, its controls, its
   counters and its end. docs/DESIGN.md « Site web », « Le keyfall du site ». Without the script, or
   without WebGL, the element keeps what it holds (a video, an audio player) and none of this applies:
   every rule below needs .is-live, set by the script once it draws. */

/* The space around the player, the same on every page that shows it (1.0.1, « Lecteur du site,
   seconde passe »; DESIGN « Formes et espacements »): between it and what is just above and just
   below it in its card or frame (its title, its caption), --kf-space, the screen margins of DESIGN
   (24 px, 16 px on a phone); between its card or frame and the rest of the page, --kf-around, as
   much below as above. */
:root {
  --kf-space: 24px;
  --kf-around: 40px;
}

@media (max-width: 700px) {
  :root {
    --kf-space: 16px;
  }
}

.keyfall {
  position: relative;
}

.keyfall.is-live {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 14px;
  background:
    radial-gradient(ellipse 60% 55% at 12% 0%, rgba(92, 225, 255, 0.10), transparent 70%),
    radial-gradient(ellipse 50% 60% at 100% 30%, rgba(178, 141, 255, 0.10), transparent 70%),
    linear-gradient(to bottom, #0B0A16, #0A0A12 60%, #120F1C);
  color: var(--text-primary);
  font-family: var(--font-ui);
  isolation: isolate;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

.keyfall.is-live:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Taller where the screen is narrow: room for the notes to fall. */
@media (max-width: 700px) {
  .keyfall.is-live {
    aspect-ratio: 4 / 5;
  }

  .demo .keyfall.is-live {
    aspect-ratio: 1 / 1;
  }
}

.demo .keyfall.is-live {
  border-radius: 11px;
}

.keyfall.is-live:fullscreen {
  aspect-ratio: auto;
  width: 100%;
  height: 100%;
  border-radius: 0;
}

.keyfall.is-live:-webkit-full-screen {
  aspect-ratio: auto;
  width: 100%;
  height: 100%;
  border-radius: 0;
}

.kf-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

/* The poster of a song page (data-mount="tap", task « Référencement des pages de morceaux »): the
   first frame of the widget drawn by the page in SVG, the size of the widget, shown with the page;
   the widget replaces it at « Écouter » (a link to the audio excerpt without the script). */
.keyfall.kf-poster-host {
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 14px;
  background:
    radial-gradient(ellipse 60% 55% at 12% 0%, rgba(92, 225, 255, 0.10), transparent 70%),
    radial-gradient(ellipse 50% 60% at 100% 30%, rgba(178, 141, 255, 0.10), transparent 70%),
    linear-gradient(to bottom, #0B0A16, #0A0A12 60%, #120F1C);
}

@media (max-width: 700px) {
  .keyfall.kf-poster-host {
    aspect-ratio: 4 / 5;
  }
}

.kf-poster {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.kf-poster .kf-pr { fill: url(#kf-gr); }
.kf-poster .kf-pl { fill: url(#kf-gl); }
.kf-poster .kf-pstar { fill: #F2F0FA; fill-opacity: 0.35; }
.kf-poster .kf-pu { fill: #A9A6C0; fill-opacity: 0.7; }
.kf-poster .kf-pb { fill-opacity: 0.95; }
.kf-poster .kf-pline { fill: #FFC46B; fill-opacity: 0.55; }
.kf-poster .kf-pkeys { fill: #E6E3EE; }
.kf-poster .kf-pgap { fill: #0E0D14; fill-opacity: 0.45; }
.kf-poster .kf-pblack { fill: #17151F; }

.kf-poster-go {
  text-decoration: none;
}

.keyfall.kf-poster-host ~ .hint-keyfall {
  display: block;
}

/* The fallback (video, audio player) set aside while the widget plays; the hints that go with each. */
.keyfall.is-live ~ .hint-audio,
.keyfall:not(.is-live) ~ .hint-keyfall {
  display: none;
}

/* ------------------------------------------------------------------ The title, at the start */

.kf-title {
  position: absolute;
  top: 16px;
  left: 18px;
  right: 18px;
  display: grid;
  gap: 2px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 700ms var(--ease), transform 700ms var(--ease);
  text-shadow: 0 1px 12px rgba(10, 10, 18, 0.9);
  /* Its own stack: the veil below lies under the words, over the notes. */
  isolation: isolate;
}

/* A veil of night behind the title, so that it reads over the notes: dark down to its last line,
   then fading out (the notes falling behind it stay a glimmer). */
.kf-title::before {
  content: "";
  position: absolute;
  inset: -16px -18px -40px;
  z-index: -1;
  background: linear-gradient(
    to bottom,
    rgba(10, 10, 18, 0.9),
    rgba(10, 10, 18, 0.84) calc(100% - 56px),
    rgba(10, 10, 18, 0.5) calc(100% - 28px),
    rgba(10, 10, 18, 0)
  );
}

.kf-title.is-shown {
  opacity: 1;
  transform: none;
}

.kf-composer {
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.kf-name {
  font-family: var(--font-title);
  font-weight: 300;
  font-size: clamp(20px, 3vw, 30px);
  line-height: 1.15;
}

.kf-by {
  color: var(--text-secondary);
  font-size: 13px;
}

/* ------------------------------------------------------------------ The counters of a challenge */

.kf-hud {
  position: absolute;
  top: 14px;
  right: 16px;
  display: grid;
  justify-items: end;
  gap: 2px;
  pointer-events: none;
  text-shadow: 0 1px 10px rgba(10, 10, 18, 0.95);
}

.kf-score {
  font-family: var(--font-title);
  font-weight: 300;
  font-size: clamp(22px, 3.4vw, 34px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.kf-combo {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
  color: var(--text-secondary);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 250ms var(--ease);
}

.kf-combo.is-shown {
  opacity: 1;
}

.kf-mult {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid rgba(255, 196, 107, 0.6);
  border-radius: 999px;
  background: rgba(255, 196, 107, 0.16);
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
}

.kf-mult.is-step {
  animation: kf-pop 520ms var(--ease);
}

@keyframes kf-pop {
  0% { transform: scale(1); box-shadow: 0 0 0 rgba(255, 196, 107, 0); }
  35% { transform: scale(1.35); box-shadow: 0 0 22px rgba(255, 196, 107, 0.8); }
  100% { transform: scale(1); box-shadow: 0 0 0 rgba(255, 196, 107, 0); }
}

/* The judgements, floating above their key. */
.kf-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.kf-label {
  position: absolute;
  top: 0;
  left: 0;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: clamp(12px, 1.5vw, 15px);
  letter-spacing: 0.02em;
  white-space: nowrap;
  opacity: 0;
  text-shadow: 0 0 10px currentColor, 0 1px 6px rgba(10, 10, 18, 0.9);
  will-change: transform, opacity;
}

.kf-label.is-on {
  animation: kf-label 900ms var(--ease) forwards;
}

@keyframes kf-label {
  0% { opacity: 0; transform: translate(var(--x), var(--y)) translate(-50%, 6px) scale(0.8); }
  18% { opacity: 1; transform: translate(var(--x), var(--y)) translate(-50%, -6px) scale(1.06); }
  70% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--x), var(--y)) translate(-50%, -30px) scale(1); }
}

/* ------------------------------------------------------------------ The big start key */

.kf-start {
  position: absolute;
  left: 50%;
  top: 44%;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 0 26px 0 20px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(to bottom, #FFDDA0, #F3A955);
  box-shadow:
    0 5px 0 #B86E28,
    0 8px 22px rgba(0, 0, 0, 0.45),
    0 0 40px rgba(255, 196, 107, 0.45);
  color: #2A1A08;
  font: 500 17px var(--font-ui);
  cursor: pointer;
  transform: translate(-50%, -50%);
  transition: transform 160ms var(--ease), box-shadow 160ms var(--ease), opacity 300ms var(--ease);
  animation: kf-breathe 3.2s ease-in-out infinite;
}

.kf-start:active {
  transform: translate(-50%, calc(-50% + 4px));
  box-shadow: 0 1px 0 #B86E28, 0 4px 12px rgba(0, 0, 0, 0.45), 0 0 50px rgba(255, 196, 107, 0.6);
}

.kf-start:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

.kf-start svg {
  width: 22px;
  height: 22px;
}

.kf-start[hidden] {
  display: none;
}

@keyframes kf-breathe {
  0%, 100% { box-shadow: 0 5px 0 #B86E28, 0 8px 22px rgba(0, 0, 0, 0.45), 0 0 30px rgba(255, 196, 107, 0.35); }
  50% { box-shadow: 0 5px 0 #B86E28, 0 8px 22px rgba(0, 0, 0, 0.45), 0 0 56px rgba(255, 196, 107, 0.6); }
}

/* « Écouter » where the music starts without sound (the home page): a small amber key in the top
   right corner, from the first seconds, while the controls rest too, until it is touched. The
   title keeps clear of it. */
.kf-listen {
  position: absolute;
  top: 12px;
  right: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px 0 14px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(to bottom, #FFDDA0, #F3A955);
  box-shadow:
    0 3px 0 #B86E28,
    0 6px 16px rgba(0, 0, 0, 0.45),
    0 0 26px rgba(255, 196, 107, 0.4);
  color: #2A1A08;
  font: 500 15px var(--font-ui);
  cursor: pointer;
  animation:
    kf-listen-in 500ms var(--ease) backwards,
    kf-listen-breathe 3s ease-in-out 600ms infinite;
  transition: transform 140ms var(--ease), box-shadow 140ms var(--ease);
}

.kf-listen svg {
  width: 20px;
  height: 20px;
}

.kf-listen:active {
  transform: translateY(2px);
  box-shadow:
    0 1px 0 #B86E28,
    0 3px 10px rgba(0, 0, 0, 0.45),
    0 0 34px rgba(255, 196, 107, 0.55);
}

.kf-listen:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.kf-listen[hidden] {
  display: none;
}

.keyfall.is-inviting .kf-title {
  right: 150px;
}

@keyframes kf-listen-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

@keyframes kf-listen-breathe {
  0%, 100% { box-shadow: 0 3px 0 #B86E28, 0 6px 16px rgba(0, 0, 0, 0.45), 0 0 18px rgba(255, 196, 107, 0.3); }
  50% { box-shadow: 0 3px 0 #B86E28, 0 6px 16px rgba(0, 0, 0, 0.45), 0 0 40px rgba(255, 196, 107, 0.7); }
}

@media (max-width: 520px) {
  .kf-listen {
    top: 10px;
    right: 10px;
    padding: 0 14px 0 12px;
    font-size: 14px;
  }

  .keyfall.is-inviting .kf-title {
    right: 130px;
  }
}

/* ------------------------------------------------------------------ The controls */

.kf-bar {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(var(--kf-keys, 0px) + 10px);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(255, 196, 107, 0.22);
  border-radius: 999px;
  background: rgba(18, 17, 32, 0.78);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  transition: opacity 300ms var(--ease), transform 300ms var(--ease);
}

.keyfall.is-quiet .kf-bar {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

/* Resting, the pointer hides too; a control reached by the keyboard always shows. */
.keyfall.is-quiet {
  cursor: none;
}

.keyfall.is-quiet .kf-bar:has(:focus-visible) {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.kf-key {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 160ms, border-color 160ms, color 160ms;
}

.kf-key:hover {
  background: rgba(255, 255, 255, 0.06);
}

.kf-key:focus-visible,
.kf-seek:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.kf-key svg {
  width: 20px;
  height: 20px;
}

.kf-key [data-on],
.kf-key[aria-pressed="true"] [data-off] {
  display: none;
}

.kf-key[aria-pressed="true"] [data-on] {
  display: block;
}

/* « Écouter »: a pill that glows until it is touched. */
.kf-key.kf-sound {
  width: auto;
  gap: 8px;
  grid-auto-flow: column;
  padding: 0 14px 0 12px;
  border-color: rgba(255, 196, 107, 0.55);
  background: rgba(255, 196, 107, 0.12);
  color: var(--accent);
  font: 500 14px var(--font-ui);
}

.kf-key.kf-sound[aria-pressed="false"] {
  animation: kf-invite 2.6s ease-in-out infinite;
}

.kf-key.kf-sound[aria-pressed="true"] {
  border-color: rgba(255, 255, 255, 0.14);
  background: transparent;
  color: var(--text-primary);
}

.kf-key.kf-sound.is-loading svg {
  animation: kf-spin 1s linear infinite;
}

@keyframes kf-invite {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 196, 107, 0); }
  50% { box-shadow: 0 0 18px rgba(255, 196, 107, 0.45); }
}

@keyframes kf-spin {
  to { transform: rotate(360deg); }
}

.kf-seek {
  flex: 1;
  min-width: 40px;
  height: 44px;
  margin: 0 4px;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.kf-seek::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--done, 0%), rgba(255, 255, 255, 0.16) var(--done, 0%));
}

.kf-seek::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.16);
}

.kf-seek::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

.kf-seek::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: 2px solid #FFE2A8;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(255, 196, 107, 0.7);
  -webkit-appearance: none;
  appearance: none;
}

.kf-seek::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 2px solid #FFE2A8;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(255, 196, 107, 0.7);
}

.kf-time {
  flex: none;
  min-width: 74px;
  color: var(--text-secondary);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

@media (max-width: 520px) {
  .kf-time,
  .kf-restart {
    display: none;
  }

  .kf-key.kf-sound span {
    display: none;
  }

  .kf-key.kf-sound {
    width: 44px;
    padding: 0;
  }
}

/* ------------------------------------------------------------------ The end */

.kf-end {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px 16px calc(var(--kf-keys, 0px) + 66px);
  background: radial-gradient(ellipse at 50% 45%, rgba(18, 17, 32, 0.4), rgba(10, 10, 18, 0.8));
  opacity: 0;
  transition: opacity 600ms var(--ease);
}

.kf-end.is-shown {
  opacity: 1;
}

.kf-end[hidden] {
  display: none;
}

.kf-end-panel {
  display: grid;
  justify-items: center;
  gap: 10px;
  max-width: 420px;
  padding: 22px 26px;
  border: 1px solid rgba(255, 196, 107, 0.35);
  border-radius: 20px;
  background: linear-gradient(to bottom, rgba(34, 31, 52, 0.94), rgba(18, 17, 32, 0.94));
  box-shadow: 0 0 60px rgba(92, 225, 255, 0.12), 0 24px 60px rgba(0, 0, 0, 0.55);
  text-align: center;
  transform: translateY(10px) scale(0.98);
  transition: transform 600ms var(--ease);
}

.kf-end.is-shown .kf-end-panel {
  transform: none;
}

.kf-end-title {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 300;
  font-size: clamp(22px, 3.2vw, 30px);
  line-height: 1.2;
}

.kf-end-facts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
  margin: 0;
  padding: 0;
  color: var(--text-secondary);
  font-size: 14px;
  list-style: none;
}

.kf-end-facts strong {
  color: var(--text-primary);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.kf-end-call {
  margin: 4px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.kf-end-keys {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 6px;
}

.kf-end-keys .key {
  min-width: 0;
}

@media (max-width: 520px) {
  .kf-end {
    padding: 10px 10px calc(var(--kf-keys, 0px) + 62px);
  }

  .kf-end-panel {
    gap: 6px;
    padding: 14px 14px 16px;
  }

  .kf-end-title {
    font-size: 21px;
  }

  .kf-end-facts,
  .kf-end-call {
    font-size: 13px;
  }

  .kf-end-keys {
    gap: 8px;
  }
}

/* A song page: its title, the falling notes, their caption, as much space above the notes as
   below them; the card as far from what follows as from the head of the page (40 px). On a phone,
   the falling notes take the width of the card. */
.listen-stage {
  margin-bottom: var(--kf-around);
}

.catalog .listen-stage h2 {
  margin-bottom: var(--kf-space);
}

.listen-stage .keyfall.is-live ~ .hint-keyfall {
  margin-top: var(--kf-space);
}

@media (max-width: 520px) {
  .listen-stage {
    padding: 16px 12px;
  }

  .listen-stage h2 {
    margin-left: 6px;
  }
}

/* The stars of a challenge (DESIGN « Étoiles de récompense »): gold in relief, or a night setting
   rimmed with gold; each rises in turn from its setting. */
.kf-stars {
  display: flex;
  gap: 6px;
  margin: 2px 0 2px;
}

.kf-star {
  position: relative;
  width: clamp(44px, 7vw, 64px);
  height: clamp(44px, 7vw, 64px);
}

.kf-star svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.kf-star .kf-gold {
  opacity: 0;
  transform: scale(0.4);
  transform-origin: 50% 55%;
  filter: drop-shadow(0 0 9px rgba(255, 196, 107, 0.42)) drop-shadow(0 3px 3px rgba(0, 0, 0, 0.5));
}

.kf-star.is-lit .kf-gold {
  animation: kf-star 700ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.kf-star .kf-glint {
  opacity: 0;
  transform-origin: 50% 52%;
}

.kf-star.is-lit .kf-glint {
  animation: kf-glint 700ms var(--ease) 120ms forwards;
}

@keyframes kf-star {
  from { opacity: 0.2; transform: scale(0.4); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes kf-glint {
  0% { opacity: 0; transform: scale(0.2) rotate(0deg); }
  40% { opacity: 1; transform: scale(1.1) rotate(25deg); }
  100% { opacity: 0; transform: scale(0.6) rotate(45deg); }
}

/* The calm version: nothing breathes nor floats; the notes still fall. */
@media (prefers-reduced-motion: reduce) {
  .kf-start,
  .kf-listen,
  .kf-key.kf-sound[aria-pressed="false"],
  .kf-mult.is-step {
    animation: none;
  }

  .kf-star.is-lit .kf-gold {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .kf-star.is-lit .kf-glint,
  .kf-label.is-on {
    animation: none;
  }

  .kf-title,
  .kf-end,
  .kf-end-panel,
  .kf-bar {
    transition: none;
  }
}

.kf-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* web/keyfall/demo.html, the page of reference: the same space around each player. */
.keyfall-demo {
  display: grid;
  gap: 14px;
  max-width: 1100px;
  margin: 0 auto;
}

.keyfall-demo > .keyfall.is-live {
  margin: calc(var(--kf-space) - 14px) 0;
}

.keyfall-demo h2 {
  margin: 28px 0 0;
}

/* The home page: the caption of the falling notes once they play, the caption of the video else;
   a guest performer's when theirs is featured (accueil.js sets .is-featured). */
.demo .hint-keyfall,
.demo .hint-featured {
  display: none;
}

.demo.is-featured:has(.keyfall.is-live) .hint-featured {
  display: inline;
}

.demo.is-featured:has(.keyfall.is-live) .hint-keyfall {
  display: none;
}

.hint-featured a {
  color: var(--accent);
}

.demo:has(.keyfall.is-live) .hint-audio {
  display: none;
}

.demo:has(.keyfall.is-live) .hint-keyfall {
  display: inline;
}
