/* Cosmos R1 — the listening sky and the interaction polish that goes with it (18 November 2026).
   Founder request: "an animated background that's playful and fun, sort of space-ish … focus
   mode to really create a sense of zen and background animation effects should reciprocate."
   cosmos.js draws the stars and publishes five attributes on <html>:
     data-cosmos=on|off · data-cosmos-motion=on|off · data-cosmos-mood=home|quiet|listen|zen ·
     data-cosmos-playing=true|false · data-cosmos-puck=true|false (the player's puck is on screen)
   Everything here is additive. Gold Halo, Living Halo, the exact R4 artwork, the header and the
   player contracts are untouched; movement is transform/opacity only. The existing switch
   (Settings → Animate backgrounds and decorative effects) and the device's reduced-motion
   setting stop all of it. High Contrast and forced colours never show it. */
:root { --cosmos-ease:cubic-bezier(.2,.8,.2,1); --cosmos-spring:cubic-bezier(.3,1.5,.5,1); --cosmos-breath:11s; }

/* ---------- The sky layer ---------- */
.cosmos { position:fixed; inset:0; z-index:-1; display:none; overflow:hidden; pointer-events:none; contain:strict; }
:root[data-cosmos=on] .cosmos { display:block; }
.cosmos > *, .cosmos-nebula i, .cosmos-aurora i { position:absolute; pointer-events:none; }
.cosmos-stars, .cosmos-veil, .cosmos-night, .cosmos-nebula, .cosmos-aurora { inset:0; width:100%; height:100%; }
/* The player's own backdrop, drawn here so the stars can sit in front of it. */
.cosmos-veil { opacity:0; background:radial-gradient(130% 70% at 50% 24%, var(--soft) 0%, var(--bg) 64%), var(--bg); }
.cosmos-night { opacity:0; background:linear-gradient(#050a18, #0b1230 54%, #1b1a3a 82%, #2a2440); transition:opacity .7s ease; }
body.player-open > .cosmos, body.focus-open > .cosmos { z-index:44; background:var(--bg); }
body.player-open > .cosmos .cosmos-veil, body.focus-open > .cosmos .cosmos-veil { opacity:1; }
body.focus-open > .cosmos .cosmos-night { opacity:1; transition-duration:1.5s; }
:root[data-cosmos=on] body.player-open #player:not(.minimised),
:root[data-cosmos=on] body.focus-open #player.focus { background:transparent; }

/* Reading pages (About, Help, Settings, Library) keep the sky far in the background. */
.cosmos-stars { transition:opacity .5s ease; }
body.page-open > .cosmos .cosmos-stars { opacity:.38; }

/* Colour clouds. Soft-edged gradients, so nothing here needs a blur filter. */
.cosmos-nebula { opacity:1; transition:opacity 1.2s ease; }
.cosmos-nebula i { width:120vmax; height:90vmax; border-radius:50%; }
.cosmos-nebula i:first-child { left:-46vmax; top:-8vmax; background:radial-gradient(closest-side, #3a8fc44d, #1c689922 52%, transparent 74%); }
.cosmos-nebula i:last-child { right:-52vmax; top:34vmax; background:radial-gradient(closest-side, #8a6ccc47, #71629b1f 50%, transparent 72%); }
:root[data-theme=plum] .cosmos-nebula i:first-child { background:radial-gradient(closest-side, #b56aa62b, #7a4c8e14 52%, transparent 74%); }
:root:is([data-theme=ivory],[data-theme=sage],[data-theme=sky]) .cosmos-nebula i:first-child { background:radial-gradient(closest-side, color-mix(in srgb,var(--accent) 13%,transparent), transparent 70%); }
:root:is([data-theme=ivory],[data-theme=sage],[data-theme=sky]) .cosmos-nebula i:last-child { background:radial-gradient(closest-side, color-mix(in srgb,var(--line) 20%,transparent), transparent 70%); }
:root[data-cosmos-mood=quiet] .cosmos-nebula { opacity:.55; }
/* The player and focus have their own backdrops, so the clouds are switched off there, not just hidden. */
:root:is([data-cosmos-mood=listen],[data-cosmos-mood=zen]) .cosmos-nebula { display:none; }

/* Focus only: two slow ribbons of light that breathe with the recording. */
.cosmos-aurora { opacity:0; transition:opacity .8s ease; }
:root[data-cosmos-mood=zen] .cosmos-aurora { opacity:1; transition-duration:2.4s; }
.cosmos-aurora i { left:-35%; width:170%; height:44%; border-radius:50%; }
.cosmos-aurora i:first-child { top:2%; background:radial-gradient(closest-side, #4fb3c44a, #2c5f8a26 46%, transparent 72%); transform:rotate(-9deg); }
.cosmos-aurora i:last-child { top:30%; background:radial-gradient(closest-side, #8f72d444, #4a3c8a22 50%, transparent 74%); transform:rotate(7deg); }

/* The light around the puck in the player and in focus. cosmos.js only says where the puck is
   (--puck-x, --puck-y, --puck-r); the glow and the waves are moved by the compositor. */
.cosmos-puck { left:var(--puck-x,50%); top:var(--puck-y,30%); width:0; height:0; opacity:0; transition:opacity .5s ease; }
:root[data-cosmos-puck=true] .cosmos-puck { opacity:1; }
.cosmos-aura, .cosmos-wave { position:absolute; left:calc(var(--size) / -2); top:calc(var(--size) / -2); width:var(--size); height:var(--size); border-radius:50%; pointer-events:none; }
.cosmos-aura { --size:calc(var(--puck-r,120px) * 3.6); opacity:.32; transition:opacity 1.2s ease;
  background:radial-gradient(closest-side, rgba(242,196,116,.5) 24%, rgba(242,196,116,.27) 44%, rgba(242,196,116,.09) 70%, transparent); }
:root[data-cosmos-playing=true] .cosmos-aura { opacity:.6; }
:root[data-cosmos-mood=zen] .cosmos-aura { opacity:.46; }
.cosmos-wave { --size:calc(var(--puck-r,120px) * 2.5); opacity:0;
  background:radial-gradient(closest-side, transparent 84%, rgba(242,196,116,.6) 91%, transparent 98%); }
/* At home the puck that is playing sends out its own small ring. */
.bani-disc--illustrated::before { content:""; position:absolute; left:0; top:0; width:100%; aspect-ratio:1; border-radius:50%; pointer-events:none; opacity:0;
  background:radial-gradient(closest-side, transparent 86%, rgba(242,196,116,.7) 93%, transparent 99%); }

/* Living Halo's six fixed dots give way to the star field; its tap echo stays. */
:root[data-cosmos=on] .living-lightfield { display:none; }
/* The navy header melts into the sky instead of ending on a hard edge. */
:root[data-cosmos=on]:is([data-theme=royal],:not([data-theme])) body[data-home=true] #site-header::after {
  content:""; position:absolute; left:0; right:0; top:100%; height:56px; pointer-events:none;
  background:linear-gradient(#061a35, #061a35b8 30%, transparent);
}

/* ---------- Focus: a quiet room under the night sky ---------- */
/* The glow behind the puck is the sky's own (.cosmos-aura), so the puck's shadow stays small and still. */
:root[data-cosmos=on] #player.focus .puck-face { box-shadow:0 0 0 1px rgba(232,196,127,.5), 0 18px 44px rgba(0,0,0,.45); }
:root[data-cosmos=on] #player.focus > .focus-scene { background:transparent; }
:root[data-cosmos=on] #player.focus .sky-stars, :root[data-cosmos=on] #player.focus .sky-glow { display:none; }
:root[data-cosmos=on] #player.focus .sky-horizon { background:linear-gradient(#0a1128, #060b1c 40%); border-top-color:#e8c47f5c; box-shadow:0 -14px 80px #b99b6524, 0 -2px 22px #e8c47f1f; }
:root[data-cosmos=on] #player.focus .sky-orbit { border-color:#e8c47f1c; }
#player.focus .player-view-controls, #player.focus .focus-caption, #player.focus .player-extra,
#player.focus .playback, #player.focus #now-artist, #player.focus #source-link { transition:opacity .28s ease; }
/* While a recording plays and nothing is touched, the controls step back. Any touch, pointer
   move or key brings them straight back; keyboard focus keeps them at full strength. */
#player.focus.zen-rest :is(.player-view-controls,.focus-caption,.player-extra) { opacity:.16; transition:opacity 2.2s ease; }
#player.focus.zen-rest .playback { opacity:.38; transition:opacity 2.2s ease; }
#player.focus.zen-rest :is(#now-artist,#source-link) { opacity:.55; transition:opacity 2.2s ease; }
#player.focus.zen-rest :is(.player-view-controls,.focus-caption,.player-extra,.playback):focus-within { opacity:1; }
/* The way into focus: a small crescent on the button. */
#player:not(.focus) #focus-button::before { content:""; flex:none; width:12px; height:12px; border-radius:50%; box-shadow:inset 3.5px -1.5px 0 0 currentColor; transform:rotate(-18deg); }
#player:not(.focus):not(.minimised) #focus-button { border:1px solid color-mix(in srgb,var(--accent) 42%,transparent); color:var(--accent); }

/* ---------- Clear, still feedback (kept when motion is off) ---------- */
/* Words stay easy to read with stars behind them. */
:root[data-cosmos=on] body[data-home=true] #collection-top .play-all { background:color-mix(in srgb, var(--accent) 10%, var(--bg)); }
:root[data-cosmos=on] body[data-home=true] #collection-top .play-all:hover { background:color-mix(in srgb, var(--accent) 18%, var(--bg)); }
:root[data-cosmos=on] .bani-disc--illustrated .bani-disc-name { text-shadow:0 0 10px var(--bg), 0 0 3px var(--bg); }
#player .play-button { position:relative; }
#player.minimised:not(.focus)[data-playing=true] { border-color:color-mix(in srgb,var(--accent) 52%,var(--line)); box-shadow:0 12px 34px rgba(0,0,0,.34), 0 -8px 30px color-mix(in srgb,var(--accent) 9%,transparent); }
.bani-disc.is-current .bani-halo::before, .bani-disc.is-current .bani-halo::after { opacity:.5; }
.bani-disc.is-playing .bani-halo::before, .bani-disc.is-playing .bani-halo::after, .bani-disc.is-playing .halo-sparks { opacity:1; }
body[data-home=true] #collection-top .play-all { position:relative; overflow:hidden; }
body[data-home=true] #collection-top .play-all > span[aria-hidden] { display:inline-block; }
#site-header .menu-button:hover, #site-header .language-toggle:hover, #site-menu[data-open=true] .menu-button { box-shadow:0 0 0 4px rgba(232,196,127,.1); }

/* ---------- Movement ---------- */
@media (prefers-reduced-motion:no-preference) {
  :root[data-cosmos-motion=on] .cosmos-nebula i:first-child { animation:cosmos-cloud-a 70s ease-in-out infinite alternate; }
  :root[data-cosmos-motion=on] .cosmos-nebula i:last-child { animation:cosmos-cloud-b 90s ease-in-out infinite alternate; }
  :root[data-cosmos-motion=on][data-cosmos-mood=zen] .cosmos-aurora i:first-child { animation:cosmos-ribbon-a 58s ease-in-out infinite alternate; }
  :root[data-cosmos-motion=on][data-cosmos-mood=zen] .cosmos-aurora i:last-child { animation:cosmos-ribbon-b 74s ease-in-out infinite alternate; }
  :root[data-cosmos-motion=on][data-cosmos-mood=zen][data-cosmos-playing=true] .cosmos-aurora { animation:cosmos-air var(--cosmos-breath) cubic-bezier(.4,0,.4,1) infinite; }

  /* Focus: one breath every eleven seconds — in for about four and a half, out for six and a half.
     The puck, the glow behind it, the waves, the ribbons and the horizon all share it. */
  :root[data-cosmos-motion=on] #player.focus[data-playing=true] .puck-face { animation:cosmos-breath var(--cosmos-breath) cubic-bezier(.4,0,.4,1) infinite; }
  :root[data-cosmos-motion=on] #player.focus[data-playing=true] .sky-horizon { animation:cosmos-horizon var(--cosmos-breath) cubic-bezier(.4,0,.4,1) infinite; }
  :root[data-cosmos-motion=on][data-cosmos-mood=zen][data-cosmos-playing=true] .cosmos-aura { animation:cosmos-aura-breath var(--cosmos-breath) cubic-bezier(.4,0,.4,1) infinite; }
  :root[data-cosmos-motion=on][data-cosmos-mood=zen][data-cosmos-playing=true] .cosmos-wave { animation:cosmos-wave-breath var(--cosmos-breath) linear infinite; }
  :root[data-cosmos-motion=on][data-cosmos-mood=zen][data-cosmos-playing=true] .cosmos-wave + .cosmos-wave { animation-name:cosmos-wave-breath-far; }
  /* The puck's two gold arcs hold still in focus: fewer moving things. */
  :root[data-cosmos-motion=on] #player.focus .puck-stage::before,
  :root[data-cosmos-motion=on] #player.focus .puck-stage::after { animation-play-state:paused; }
  :root[data-cosmos-motion=on] #player.focus .puck-stage { animation:cosmos-appear 1.1s ease backwards; }
  :root[data-cosmos-motion=on] #player.focus .player-top { animation:cosmos-settle 1.1s var(--cosmos-ease) backwards; }
  :root[data-cosmos-motion=on] #player.focus .playback,
  :root[data-cosmos-motion=on] #player.focus .player-extra { animation:cosmos-settle 1.1s var(--cosmos-ease) .12s backwards; }

  /* In the player the glow is the sky's own, so the puck's large shadow no longer animates.
     The glow swells slowly and a wave leaves the puck every few seconds while it plays. */
  :root[data-cosmos-motion=on] #player[data-playing=true]:not(.minimised):not(.focus) .puck-face { animation:none; }
  :root[data-cosmos-motion=on][data-cosmos-mood=listen][data-cosmos-playing=true] .cosmos-aura { animation:cosmos-aura-pulse 6s ease-in-out infinite; }
  :root[data-cosmos-motion=on][data-cosmos-mood=listen][data-cosmos-playing=true] .cosmos-wave { animation:cosmos-wave 3.6s ease-out infinite; }
  :root[data-cosmos-motion=on][data-cosmos-mood=listen][data-cosmos-playing=true] .cosmos-wave + .cosmos-wave { animation-delay:1.8s; }
  :root[data-cosmos-motion=on] .bani-disc--illustrated.is-playing::before { animation:cosmos-disc-ring 2.8s ease-out infinite; }

  /* The play button sends out a slow ring while a recording plays. */
  :root[data-cosmos-motion=on] #player[data-playing=true] .play-button::after {
    content:""; position:absolute; inset:0; border-radius:50%; border:1.5px solid var(--accent); pointer-events:none;
    animation:cosmos-sonar 2.8s ease-out infinite;
  }
  :root[data-cosmos-motion=on] #player.focus[data-playing=true] .play-button::after { animation-duration:5.5s; }
  :root[data-cosmos-motion=on] #player.minimised:not(.focus)[data-playing=true] .play-button::after { animation-name:cosmos-sonar-small; }
  :root[data-cosmos-motion=on] #player .play-button svg { animation:cosmos-pop .3s var(--cosmos-spring) both; }
  :root[data-cosmos-motion=on] #player .extra-button { transition:scale .2s var(--cosmos-spring), background-color .2s ease, color .2s ease; }
  :root[data-cosmos-motion=on] #player .extra-button:active { scale:.93; }
  :root[data-cosmos-motion=on] #player .repeat-button[aria-pressed=true] svg { animation:cosmos-pop .34s var(--cosmos-spring) both; }
  :root[data-cosmos-motion=on] #player .timeline input::-webkit-slider-thumb { transition:transform .18s var(--cosmos-spring), box-shadow .18s ease; }
  :root[data-cosmos-motion=on] #player .timeline input:active::-webkit-slider-thumb { transform:scale(1.16); box-shadow:0 0 0 2px var(--seek-accent), 0 0 20px color-mix(in srgb,var(--seek-accent) 55%,transparent); }
  :root[data-cosmos-motion=on] #player .player-view-controls button { transition:scale .2s var(--cosmos-spring), background-color .2s ease, opacity .28s ease; }
  :root[data-cosmos-motion=on] #player .player-view-controls button:active { scale:.94; }
  :root[data-cosmos-motion=on] #player.minimised:not(.focus)[data-playing=true] .mini-puck { animation:cosmos-mini 3.6s ease-in-out infinite; }

  /* The puck that is playing keeps its halo turning. */
  :root[data-cosmos-motion=on] .bani-disc.is-playing .bani-halo::before,
  :root[data-cosmos-motion=on] .bani-disc.is-playing .bani-halo::after,
  :root[data-cosmos-motion=on] .bani-disc.is-playing .halo-sparks { animation-play-state:running; }

  /* Header and buttons: a small, springy answer to every press. */
  :root[data-cosmos-motion=on] #site-header :is(.menu-button,.language-toggle,.header-resume) { transition:scale .22s var(--cosmos-spring), background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease; }
  :root[data-cosmos-motion=on] #site-header :is(.menu-button,.language-toggle,.header-resume):active { scale:.95; }
  :root[data-cosmos-motion=on] :is(.primary,.outline):not(:disabled) { transition:scale .2s var(--cosmos-spring), transform .22s var(--cosmos-ease), background-color .2s ease, border-color .2s ease, box-shadow .2s ease; }
  :root[data-cosmos-motion=on] :is(.primary,.outline):not(:disabled):active { scale:.97; }
  :root[data-cosmos-motion=on] .theme-option[aria-pressed=true] .theme-check { animation:cosmos-pop .34s var(--cosmos-spring) both; }
  :root[data-cosmos-motion=on] body[data-home=true] #collection-top .play-all > span[aria-hidden] { transition:transform .25s var(--cosmos-spring); }
  :root[data-cosmos-motion=on] body[data-home=true] #collection-top .play-all::after {
    content:""; position:absolute; top:0; bottom:0; left:-60%; width:46%; pointer-events:none; opacity:0;
    background:linear-gradient(100deg, transparent, color-mix(in srgb,var(--accent) 32%,transparent), transparent);
  }
  :root[data-cosmos-motion=on] body[data-home=true] #collection-top .play-all:active::after { animation:cosmos-sheen .7s ease-out; }

  /* Messages and pages arrive rather than appear. */
  :root[data-cosmos-motion=on] #toast:not([hidden]) { animation:cosmos-toast .44s var(--cosmos-spring) both; }
  :root[data-cosmos-motion=on] #dialog[open] { animation:cosmos-rise .38s var(--cosmos-ease) backwards; }

  @media (hover:hover) and (pointer:fine) {
    /* A puck leans towards the pointer. cosmos.js supplies the two angles. */
    :root[data-cosmos-motion=on] .bani-disc--illustrated .bani-disc-button:hover .bani-halo {
      transform:perspective(720px) rotateX(var(--tilt-x,0deg)) rotateY(var(--tilt-y,0deg)) translateY(-6px) scale(1.035);
      filter:drop-shadow(0 0 18px #f2c4748c); transition-duration:.2s;
    }
    :root[data-cosmos-motion=on] body[data-home=true] #collection-top .play-all:hover { box-shadow:0 0 0 4px color-mix(in srgb,var(--accent) 12%,transparent), 0 10px 30px color-mix(in srgb,var(--accent) 16%,transparent); }
    :root[data-cosmos-motion=on] body[data-home=true] #collection-top .play-all:hover > span[aria-hidden] { transform:translateX(2px) scale(1.12); }
    :root[data-cosmos-motion=on] body[data-home=true] #collection-top .play-all:hover::after { animation:cosmos-sheen .9s ease-out; }
    :root[data-cosmos-motion=on] #player .extra-button:hover { scale:1.04; }
  }
}

/* Still scenery, hidden tabs and reduced motion: everything above holds still. */
:root[data-cosmos-motion=off] :is(.cosmos-nebula i, .cosmos-aurora, .cosmos-aurora i, .cosmos-aura, .cosmos-wave) { animation:none!important; }
:root[data-theme=contrast] .cosmos { display:none!important; }
@media (forced-colors:active) { .cosmos { display:none!important; } }
@media (prefers-reduced-motion:reduce) {
  .cosmos-nebula i, .cosmos-aurora, .cosmos-aurora i, .cosmos-aura, .cosmos-wave, .bani-disc--illustrated::before { animation:none!important; }
  #player.focus.zen-rest :is(.player-view-controls,.focus-caption,.player-extra,.playback,#now-artist,#source-link) { transition:none; }
}

@keyframes cosmos-cloud-a { from { transform:translate(0,0) scale(1); } to { transform:translate(9vmax,6vmax) scale(1.12); } }
@keyframes cosmos-cloud-b { from { transform:translate(0,0) scale(1.08); } to { transform:translate(-8vmax,-7vmax) scale(.96); } }
@keyframes cosmos-ribbon-a { from { transform:rotate(-9deg) translateX(-5%) scaleY(1); } to { transform:rotate(-5deg) translateX(6%) scaleY(1.18); } }
@keyframes cosmos-ribbon-b { from { transform:rotate(7deg) translateX(5%) scaleY(1.1); } to { transform:rotate(3deg) translateX(-6%) scaleY(.9); } }
@keyframes cosmos-air { 0%,100% { opacity:.72; } 42% { opacity:1; } }
@keyframes cosmos-breath { 0%,100% { scale:1; } 42% { scale:1.035; } }
@keyframes cosmos-aura-breath { 0%,100% { opacity:.46; transform:scale(1); } 42% { opacity:.95; transform:scale(1.24); } }
@keyframes cosmos-aura-pulse { 0%,100% { opacity:.5; transform:scale(1); } 50% { opacity:.8; transform:scale(1.07); } }
/* A wave leaves the puck at the top of each breath and fades as it travels. */
@keyframes cosmos-wave-breath { 0%,40% { opacity:0; transform:scale(.9); } 46% { opacity:.5; } 100% { opacity:0; transform:scale(4.4); } }
@keyframes cosmos-wave-breath-far { 0%,47% { opacity:0; transform:scale(.9); } 54% { opacity:.3; } 100% { opacity:0; transform:scale(3); } }
@keyframes cosmos-wave { 0% { opacity:0; transform:scale(.88); } 14% { opacity:.5; } 100% { opacity:0; transform:scale(1.8); } }
@keyframes cosmos-disc-ring { 0% { opacity:0; transform:scale(.98); } 16% { opacity:.6; } 100% { opacity:0; transform:scale(1.3); } }
@keyframes cosmos-appear { from { opacity:0; } }
@keyframes cosmos-horizon { 0%,100% { opacity:.72; transform:translateY(8px); } 42% { opacity:1; transform:translateY(0); } }
@keyframes cosmos-settle { from { opacity:0; translate:0 14px; } }
@keyframes cosmos-sonar { from { transform:scale(1); opacity:.5; } to { transform:scale(1.6); opacity:0; } }
@keyframes cosmos-sonar-small { from { transform:scale(1); opacity:.45; } to { transform:scale(1.32); opacity:0; } }
@keyframes cosmos-pop { from { scale:.6; opacity:.2; } to { scale:1; opacity:1; } }
@keyframes cosmos-mini { 0%,100% { box-shadow:0 0 0 1px rgba(232,196,127,.5); } 50% { box-shadow:0 0 0 1px rgba(232,196,127,.85), 0 0 16px rgba(232,196,127,.4); } }
@keyframes cosmos-sheen { from { transform:translateX(0); opacity:1; } to { transform:translateX(400%); opacity:1; } }
@keyframes cosmos-toast { from { opacity:0; translate:0 16px; scale:.95; } to { opacity:1; translate:0 0; scale:1; } }
@keyframes cosmos-rise { from { opacity:0; translate:0 14px; } }
