/* COSMOS launcher: the floating button, the transition layer shell (#wow), the reveal ring and the failure toast.
   Always loaded (small); the layer must clip correctly on the very first click.
   Internal hooks kept from the original controller (cosmos.css and cosmos.js rely on them):
   #wow, #wow-ring, #wow-toast, .wow-fab, .wow-loader, html.wow-lock, html.wow-covered, html[data-mode="wow"],
   html[data-wow-look="c"], #wow[data-look="c"]. */
:root {
  --wow-bg: #0A0A0B;
  --wow-ink: #F2EFE8;
}

#wow {
  position: fixed;
  inset: 0;
  z-index: 9990;
  --wow-r: 0px;
  --wow-x: 50vw;
  --wow-y: 50vh;
  background: var(--wow-bg);
  color: var(--wow-ink);
  clip-path: circle(var(--wow-r) at var(--wow-x) var(--wow-y));
}
#wow[data-look="c"] { --wow-bg: #05060B; --wow-ink: #EEF1FF; }
html[data-mode="wow"] #wow { clip-path: none; }
#wow:focus { outline: none; }
html.wow-lock { overflow: hidden; scrollbar-gutter: stable; }

/* Task 10 (Bo Ali #4): the covered page also leaves the rendering pipeline (no style/paint/layer work, the hero blobs
   stop). `auto` must be set while the page is rendered so each block remembers its size: without it the document would
   collapse while covered and the page would come back at scrollY 0. No effect on the normal page (no size containment). */
body > :not(#wow, #wow-ring, .wow-fab, #wow-toast) { contain-intrinsic-size: auto none; }
html.wow-covered body > :not(#wow, #wow-ring, .wow-fab, #wow-toast) { visibility: hidden; content-visibility: hidden; }

/* thin bar shown only if the circle finished growing before the COSMOS files arrived */
.wow-loader {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
  width: 40%;
  height: 1px;
  background: #7FE3FF;
  animation: wow-loading 1.1s cubic-bezier(.65, 0, .35, 1) infinite;
}

@keyframes wow-loading {
  from { transform: translateX(-100%) scaleX(.4); }
  to { transform: translateX(250%) scaleX(1); }
}

/* the 2 px edge of the growing circle */
#wow-ring {
  position: fixed;
  inset: 0;
  z-index: 9989;
  background: linear-gradient(135deg, #7FE3FF, #A98BFF 50%, #FF6FB5);
  pointer-events: none;
  clip-path: circle(0px at 0 0);
}
#wow-ring[hidden] { display: none; }

/* #cosmos-toggle: navy disc with a 1.5 px conic cyan -> violet -> pink ring, bottom-right;
   static glow on hover (no animation loop); the planet icon turns into a close icon while COSMOS is open */
.wow-fab {
  position: fixed;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 9999;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: transform .25s var(--ease-out, cubic-bezier(.16, 1, .3, 1)), translate .35s var(--ease-out, cubic-bezier(.16, 1, .3, 1));
}
.wow-fab:hover { transform: scale(1.06); }
.wow-fab[hidden] { display: none; }
.wow-fab:focus-visible {
  outline: 3px solid var(--wow-ink);
  outline-offset: 3px;
}
.wow-fab.is-shaking { animation: wow-shake .4s; }

.wow-fab svg {
  grid-area: 1 / 1;
  transition: transform .45s var(--ease-out, cubic-bezier(.16, 1, .3, 1)), opacity .25s;
}
.wow-fab .wow-icon-close { opacity: 0; transform: rotate(-90deg) scale(.4); }
.wow-fab[aria-pressed="true"] > svg:first-child { opacity: 0; transform: rotate(90deg) scale(.4); }
.wow-fab[aria-pressed="true"] .wow-icon-close { opacity: 1; transform: none; }

#cosmos-toggle {
  box-sizing: border-box;
  border: 1.5px solid transparent;
  background: linear-gradient(#0B1030, #0B1030) padding-box, conic-gradient(from 200deg, #7FE3FF, #A98BFF, #FF6FB5, #A98BFF, #7FE3FF) border-box;
  color: #EEF1FF;
  box-shadow: 0 8px 24px rgba(11, 16, 48, .35);
}
#cosmos-toggle:hover { box-shadow: 0 0 16px rgba(127, 227, 255, .35), 0 8px 24px rgba(11, 16, 48, .35); }
#cosmos-toggle:focus-visible {
  outline-color: #7FE3FF;
  box-shadow: 0 0 0 9px #05060B;
}

#wow-toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(24px, env(safe-area-inset-bottom)) + 68px);
  z-index: 9999;
  width: max-content;
  max-width: min(36rem, calc(100vw - 32px));
  padding: .7rem 1.1rem;
  border: 1px solid rgba(242, 239, 232, .12);
  border-radius: 1.2rem;
  text-align: center;
  background: var(--wow-bg);
  color: var(--wow-ink);
  font: 500 .875rem/1.3 Inter, system-ui, sans-serif;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity .25s, transform .25s var(--ease-out, cubic-bezier(.16, 1, .3, 1));
}
#wow-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* (translate, not transform: a shake while the hover portal is up keeps the portal's transform) */
@keyframes wow-shake {
  20% { translate: -6px 0; }
  40% { translate: 6px 0; }
  60% { translate: -4px 0; }
  80% { translate: 4px 0; }
}

/* ---------- hover portal (Task 3c) ----------
   Hover / keyboard focus on #cosmos-toggle, only while COSMOS is closed (no html.wow-lock), morphs the disc into a
   small black hole: the button shifts up-left so the 152 px portal stays on screen (the portal centre IS the button
   centre, so the circle reveal starts there), the decorative .cosmos-portal grows from 56 px, the guide peeks out from
   behind it and the pill says the line. After COSMOS closes it stays down for the resting cursor / returned focus
   (.is-back / .is-back-focus, set by the launcher). The one state rule below only sets --cp-* properties that the
   children read. Transform/opacity only; the loops (disc spin, falling stars, wave) exist only in this state. */
#cosmos-toggle { transition: transform .22s cubic-bezier(.4, 0, .2, 1), translate .35s var(--ease-out, cubic-bezier(.16, 1, .3, 1)); }
html:not(.wow-lock) #cosmos-toggle:not(.is-back):is(:hover, :focus-visible:not(.is-back-focus)) {
  --cp-v: visible; --cp-o: 1; --cp-io: 0; --cp-icon: scale(.4); --cp-pt: none; --cp-gt: rotate(-26deg); --cp-lt: none;
  --cp-ptr: transform .32s cubic-bezier(.16, 1, .3, 1), opacity .06s linear, visibility 0s;
  --cp-gtr: transform .46s cubic-bezier(.34, 1.4, .64, 1) .12s, opacity .16s linear .12s;
  --cp-ltr: opacity .2s linear .1s, transform .32s cubic-bezier(.16, 1, .3, 1) .1s, visibility 0s;
  --cp-wc: transform, opacity; --cp-spin: cp-spin 7s linear infinite; --cp-wave: cp-wave 1.1s ease-in-out .6s infinite alternate;
  --cp-fall: cp-fall 2.4s cubic-bezier(.55, 0, .9, .5) infinite;
  --cp-grow: cp-grow 1.6s cubic-bezier(.3, 0, .2, 1) .2s both; --cp-grow-halo: cp-grow-halo 1.6s cubic-bezier(.3, 0, .2, 1) .2s both;
  transform: translate(-42px, -36px);
  outline-offset: 50px;
  transition: transform .32s cubic-bezier(.16, 1, .3, 1), translate .35s var(--ease-out, cubic-bezier(.16, 1, .3, 1));
}
.wow-icon-planet { opacity: var(--cp-io, 1); transform: var(--cp-icon, none); }
.cosmos-portal, .cosmos-portal span, .cosmos-portal i, .cosmos-pill { position: absolute; display: block; }
.cosmos-portal, .cp-stars i, .cp-disc, .cp-halo, .cp-hole { left: 50%; top: 50%; }
.cosmos-portal, .cp-space, .cp-disc span, .cp-halo, .cp-hole, .cosmos-portal::before { border-radius: 50%; }
.cosmos-portal, .cosmos-pill { visibility: var(--cp-v, hidden); opacity: var(--cp-o, 0); }
.cosmos-portal {
  width: 152px; height: 152px; margin: -76px;
  transform: var(--cp-pt, scale(.37));
  will-change: var(--cp-wc, auto);
  transition: var(--cp-ptr, transform .22s cubic-bezier(.4, 0, .2, 1), opacity .12s linear .1s, visibility 0s .22s);
}
.cosmos-portal::before { content: ""; position: absolute; inset: -10px; }
.cp-space {
  inset: 0;
  background: radial-gradient(1px 1px at 24% 30%, #EEF1FF 50%, transparent), radial-gradient(1px 1px at 78% 22%, #A7B0D8 50%, transparent),
    radial-gradient(1.4px 1.4px at 84% 70%, #EEF1FF 50%, transparent), radial-gradient(1px 1px at 18% 74%, #A7B0D8 50%, transparent),
    radial-gradient(circle, rgba(169, 139, 255, .28) 18%, rgba(255, 111, 181, .1) 34%, transparent 52%),
    radial-gradient(circle, #000 0 30%, #0A0920 52%, #120F35 78%, #241A4E);
  box-shadow: 0 0 0 1px rgba(169, 139, 255, .55), 0 0 24px 3px rgba(255, 111, 181, .3), 0 12px 30px rgba(5, 6, 11, .4);
}
.cp-stars { inset: 0; }
.cp-stars i { transform: rotate(var(--a)) scale(var(--k)); }
.cp-stars i::before {
  content: ""; position: absolute; left: -1px; top: -1px; width: 2px; height: 2px; border-radius: 50%; background: #EEF1FF; opacity: 0;
  animation: var(--cp-fall, none); animation-delay: var(--t);
}
/* accretion disc: a conic ring flattened + tilted by its wrapper, spun inside it; .cp-front is its near half, over the hole */
.cp-disc { width: 184px; height: 184px; margin: -92px; transform: rotate(-12deg) scaleY(.22); }
.cp-front { clip-path: inset(50% 0 0 0); }
.cp-disc span {
  inset: 0;
  background: conic-gradient(#FFE6F2, #FF6FB5 12%, #A98BFF 30%, #7FE3FF 40%, rgba(169, 139, 255, .5) 50%, rgba(255, 111, 181, .25) 62%, #FF6FB5 80%, #FFE6F2);
  -webkit-mask: radial-gradient(closest-side, transparent 30%, #000 36%, #000 58%, transparent);
  mask: radial-gradient(closest-side, transparent 30%, #000 36%, #000 58%, transparent);
  animation: var(--cp-spin, none);
}
/* lensed far side of the disc: a static ring around the hole, brightest on top */
.cp-halo {
  width: 104px; height: 104px; margin: -52px;
  background: conic-gradient(#FFF1F8, #FFC2E0 10%, #FF6FB5 24%, #A98BFF 40%, #7A6BD8 50%, #A98BFF 60%, #FF6FB5 76%, #FFC2E0 90%, #FFF1F8);
  -webkit-mask: radial-gradient(closest-side, transparent 44%, #000 47%, #000 62%, transparent 86%);
  mask: radial-gradient(closest-side, transparent 44%, #000 47%, #000 62%, transparent 86%);
}
.cp-hole { width: 46px; height: 46px; margin: -23px; background: #000; box-shadow: 0 0 0 1.5px #FFF1F8, 0 0 7px 2px rgba(255, 111, 181, .8); }
/* the guide sits behind the portal (first child) and leans out over its upper-left rim */
.cp-guide {
  left: 0; top: -54px; width: 90px; height: 92px;
  transform-origin: 50% 100%;
  opacity: var(--cp-o, 0);
  transform: var(--cp-gt, rotate(-26deg) translateY(46px) scale(.7));
  transition: var(--cp-gtr, transform .18s cubic-bezier(.4, 0, .2, 1), opacity .14s linear);
}
.cp-guide img { display: block; width: 90px; height: 92px; transform-origin: 50% 96%; animation: var(--cp-wave, none); }
.cp-guide img:not([src]) { visibility: hidden; }
/* the pill is a zero-size anchor at the bubble's right edge (owns the tail + the hover bridge to the portal); the bubble
   hangs left of it by its own width (transform), so the Instrument Serif swap changes only its width: no layout shift */
.cosmos-pill { left: -62px; top: 50%; width: 0; height: 0; transform: var(--cp-lt, translateX(10px)); transition: var(--cp-ltr, opacity .15s linear, transform .2s cubic-bezier(.4, 0, .2, 1), visibility 0s .2s); }
.cosmos-pill::before { content: ""; position: absolute; left: 0; top: -30px; width: 24px; height: 60px; }
.cosmos-pill::after {
  content: ""; position: absolute; left: -4px; top: -5px; width: 10px; height: 10px; z-index: 1;
  border: solid rgba(127, 227, 255, .35); border-width: 1px 1px 0 0; background: #0E1430; transform: rotate(45deg);
}
.cp-bubble {
  position: absolute; left: 0; top: 0;
  padding: 9px 16px 10px 15px;
  border: 1px solid rgba(127, 227, 255, .35);
  border-radius: 14px;
  background: #0E1430;
  color: #EEF1FF;
  text-align: left;
  white-space: nowrap;
  box-shadow: 0 10px 28px rgba(5, 6, 11, .3);
  transform: translate(-100%, -50%);
}
.cp-line { display: block; font: italic 400 20px/1.15 "Instrument Serif", Georgia, "Times New Roman", serif; }
.cp-cap { display: block; margin-top: 4px; color: #7FE3FF; font: 600 10.5px/1 "Chakra Petch", ui-monospace, Menlo, monospace; letter-spacing: .18em; }
.cp-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@keyframes cp-spin { to { transform: rotate(1turn); } }
@keyframes cp-wave { to { transform: rotate(7deg); } }
@keyframes cp-fall {
  0% { transform: rotate(0) translateX(70px); opacity: 0; }
  20% { opacity: 1; }
  to { transform: rotate(75deg) translateX(12px) scale(.4); opacity: 0; }
}

/* ---------- Task 14: black-hole portal transitions (driven by cosmos-launcher.js, WAAPI on transform/opacity/clip-path) ----------
   HOVER: .cosmos-fx, a fixed, click-through layer under the COSMOS layer, created on the first hover: a violet veil centred
   on the portal (a lensing ring just outside it, the page darkening toward its edges) and dust streaks that spiral into the
   portal (animated only while .is-on); while the portal is up the hole grows a little (--cp-grow).
   OPEN / CLOSE (the swallow): .cosmos-void, a dark space with a violet glow at the button, opens behind the falling page
   (z-index -1: above the page's own canvas background, under every block); .cosmos-slab, a fixed copy of a full-bleed band's
   background (the band's own background is removed while it falls, the launcher restores it); .cosmos-hole, the glowing
   hole at the button, above the page and the layer, under the button. All are created on the first press and hidden after. */
.cosmos-fx { position: fixed; inset: 0; z-index: 9988; pointer-events: none; opacity: 0; overflow: hidden; }
.cosmos-fx[hidden], .cosmos-void[hidden], .cosmos-hole[hidden], .cosmos-dim[hidden] { display: none; }
.cfx-veil {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at var(--fx-x, 100%) var(--fx-y, 100%), transparent 0 86px, rgba(169, 139, 255, .34) 98px, rgba(255, 111, 181, .16) 108px, transparent 132px),
    radial-gradient(circle at var(--fx-x, 100%) var(--fx-y, 100%), rgba(5, 6, 11, 0) 0 170px, rgba(14, 12, 44, .07) 420px, rgba(5, 6, 11, .26) 110vmax);
}
.cfx-dust i {
  position: absolute; left: var(--fx-x, 100%); top: var(--fx-y, 100%);
  width: 26px; height: 2px; margin-top: -1px; border-radius: 1px;
  background: linear-gradient(90deg, #FF6FB5, #A98BFF 35%, rgba(169, 139, 255, 0));
  transform-origin: 0 50%;
  opacity: 0;
}
.cosmos-fx.is-on .cfx-dust i { animation: cfx-spiral 2s cubic-bezier(.5, 0, .85, .45) infinite; animation-delay: var(--t); }
@keyframes cfx-spiral {
  0% { transform: rotate(var(--a)) translateX(var(--r)) scaleX(.5); opacity: 0; }
  20% { opacity: .85; }
  100% { transform: rotate(calc(var(--a) + 140deg)) translateX(12px) scaleX(1.5); opacity: 0; }
}
.cosmos-void {
  position: fixed; inset: 0; z-index: -1; pointer-events: none; opacity: 0;
  background:
    radial-gradient(circle at var(--fx-x, 100%) var(--fx-y, 100%), rgba(169, 139, 255, .34), rgba(255, 111, 181, .12) 12vmax, transparent 34vmax),
    #05060B;
}
.cosmos-slab { position: fixed; z-index: -1; pointer-events: none; }
/* touch swallow: one black scrim over the page dims a bright page before it tears apart (under the hover veil, the ring and the layer) */
.cosmos-dim { position: fixed; inset: 0; z-index: 9987; pointer-events: none; opacity: 0; background: #000; }
/* a band whose background is drawn separately (.cosmos-slab) while it falls; a class, so the author's own inline styles are never touched */
.is-slabbed { background: none !important; }
.cosmos-hole {
  position: fixed; left: var(--fx-x, 100%); top: var(--fx-y, 100%); z-index: 9991;
  width: 240px; height: 240px; margin: -120px 0 0 -120px;
  border-radius: 50%; pointer-events: none; opacity: 0;
  background: radial-gradient(circle, #000 0 20%, rgba(5, 6, 11, .96) 28%, rgba(169, 139, 255, .6) 36%, rgba(255, 111, 181, .38) 44%, rgba(169, 139, 255, .14) 58%, transparent 72%);
}
.cp-hole { animation: var(--cp-grow, none); }
.cp-halo { animation: var(--cp-grow-halo, none); }
@keyframes cp-grow { to { transform: scale(1.22); } }
@keyframes cp-grow-halo { to { transform: scale(1.08); } }

/* Task 8b: touch screens (no hover). A tap opens at once, so the portal never shows; a tap must not leave a stuck
   :hover morph behind (the button would sit 42 px up-left with a shrunken icon). The tap-friendly affordance is
   .is-hint: the pill alone ("To infinity... and beyond!") for a few seconds, once per visit, after the first scroll (launcher). */
@media (hover: none) {
  .cosmos-portal { display: none; }
  .wow-fab:hover { transform: none; }
  html:not(.wow-lock) #cosmos-toggle:not(.is-back):is(:hover, :focus-visible:not(.is-back-focus)) {
    --cp-v: hidden; --cp-o: 0; --cp-io: 1; --cp-icon: none; --cp-wc: auto; --cp-spin: none; --cp-wave: none; --cp-fall: none; --cp-grow: none; --cp-grow-halo: none;
    transform: none;
    outline-offset: 3px;
  }
  .cosmos-pill { left: -14px; pointer-events: none; }
  html:not(.wow-lock) #cosmos-toggle.is-hint { --cp-v: visible; --cp-o: 1; --cp-lt: none; --cp-ltr: opacity .3s linear, transform .4s cubic-bezier(.16, 1, .3, 1), visibility 0s; }
  .cp-bubble { padding: 8px 13px 9px 12px; }
  .cp-line { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .wow-fab, .wow-fab svg, #wow-toast { transition-duration: .01ms; }
  .wow-fab.is-shaking { animation: none; }
  .wow-loader { animation: none; width: 100%; }
  /* no morph: the button stays put, keeps its icon and ring; only the pill fades in (150 ms) */
  html:not(.wow-lock) #cosmos-toggle:not(.is-back):is(:hover, :focus-visible:not(.is-back-focus)) {
    --cp-io: 1; --cp-icon: none; --cp-lt: none; --cp-ltr: opacity .15s linear, visibility 0s;
    transform: none;
    outline-offset: 3px;
  }
  #cosmos-toggle .cosmos-portal { display: none; }
  .cosmos-fx, .cosmos-void, .cosmos-hole, .cosmos-slab, .cosmos-dim { display: none; }
  #cosmos-toggle .cosmos-pill { left: -16px; transform: none; transition: var(--cp-ltr, opacity .15s linear, visibility 0s .15s); }
}
