/* Flying genie with a speed-reactive glow — driven by public/js/genie-fx.js.
 *
 * .gfx-companion is a fixed, full-viewport layer: he flies around it on his own and rests
 * in the bottom-right corner between flights.
 *
 * Layering inside a genie, outer → inner:
 *   .gfx-genie  positioned by JS every frame (translate / tilt / squash-stretch)
 *   .gfx-bob    gentle idle float, pure CSS
 *   .gfx-aura   the glow; size + brightness follow --gfx-energy, set by JS from speed
 *   .gfx-aura-pulse  slow "breathing" pulse, pure CSS
 *
 * Each of those owns its own element on purpose. The reference design put a CSS pulse
 * animation and a JS speed-scale on the SAME element's transform — the animation always
 * wins, so the speed reaction silently never showed. Splitting them lets both work.
 * Likewise the glow lives inside .gfx-bob so it floats with the genie instead of
 * drifting apart from him. */

.gfx-stage {
  pointer-events: none; /* never blocks a click; only .gfx-dismiss opts back in */
}

.gfx-companion {
  position: fixed;
  inset: 0;
  z-index: 25; /* below the sticky header (30) and every modal (1000) */
  overflow: hidden; /* particles near the edge can't create page scrollbars */
}

/* Hidden until JS has placed him — avoids a one-frame flash at the top-left corner. */
.gfx-stage.gfx-booting .gfx-genie { opacity: 0; }

.gfx-stage.is-dismissed { display: none; }

.gfx-particles {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

/* ---- the genie --------------------------------------------------------- */

.gfx-genie {
  position: absolute;
  left: 0;
  top: 0;
  width: 72px;  /* 3:4, matching the 360x480 art */
  height: 96px;
  transform-origin: 50% 50%;
  will-change: transform;
  transition: opacity .3s ease;
  --gfx-energy: 0;
  /* Deliberately NO transition on transform — JS already moves him every frame, and a
     transition on top only adds lag and jitter (the reference had exactly that bug). */
}

.gfx-bob {
  position: absolute;
  inset: 0;
  animation: gfxBob 3.2s ease-in-out infinite;
}

.gfx-genie img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 10px 14px rgba(0, 12, 82, .28));
  user-select: none;
  -webkit-user-drag: none;
}

/* ---- the glow ------------------------------------------------------------ */

.gfx-aura {
  position: absolute;
  left: 50%;
  top: 52%;
  width: 230%;
  height: 190%;
  border-radius: 50%;
  /* Calm → full speed: grows up to 1.85x and goes from 60% to fully bright. */
  transform: translate(-50%, -50%) scale(calc(1 + var(--gfx-energy) * .85));
  opacity: calc(.6 + var(--gfx-energy) * .4);
}

.gfx-aura-pulse,
.gfx-aura-core {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

/* Teal halo: stronger than the reference (which peaked at .35 alpha behind a heavy blur). */
.gfx-aura-pulse {
  background: radial-gradient(closest-side,
    rgba(124, 196, 232, .85) 0%,
    rgba(79, 163, 209, .55) 38%,
    rgba(124, 196, 232, .18) 68%,
    rgba(124, 196, 232, 0) 100%);
  filter: blur(6px);
  animation: gfxPulse 3.4s ease-in-out infinite;
}

/* Warm gold core that only shows up at speed — negative opacity clamps to 0, so it's
   invisible below ~35% energy and ramps to full near the top. */
.gfx-aura-core {
  inset: 18% 22%;
  background: radial-gradient(closest-side,
    rgba(248, 211, 131, .9) 0%,
    rgba(242, 184, 75, .45) 45%,
    rgba(242, 184, 75, 0) 100%);
  filter: blur(8px);
  opacity: calc((var(--gfx-energy) - .35) * 1.6);
}

/* ---- dismiss (companion only) ------------------------------------------- */

.gfx-dismiss {
  position: absolute;
  top: -4px;
  right: -6px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(11, 21, 80, .78);
  color: #fff;
  font-size: 14px;
  line-height: 22px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transform: scale(.6);
  transition: opacity .2s ease, transform .2s ease;
}

/* Only clickable while he rests in his corner — a button riding on a moving genie
   would be impossible to hit. */
.gfx-companion.is-resting .gfx-dismiss {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}

.gfx-dismiss:focus-visible {
  opacity: 1;
  transform: scale(1);
  outline: 2px solid #f2b84b;
  outline-offset: 2px;
}

/* ---- particles ----------------------------------------------------------- */

.gfx-dust {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(242, 184, 75, .65), rgba(242, 184, 75, 0) 70%);
  animation: gfxDust .75s ease-out forwards;
}

/* Four-point twinkling star. The star shape is a clip-path on ::before, and the glow is
   a drop-shadow on the parent — a shadow on the clipped element itself would be clipped
   away with it. --spark-color is set per star by genie-fx.js. */
.gfx-spark {
  position: absolute;
  filter: drop-shadow(0 0 2px var(--spark-color)) drop-shadow(0 0 5px var(--spark-color));
  animation: gfxSpark 2.4s ease-out forwards;
}

.gfx-spark::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--spark-color);
  clip-path: polygon(50% 0%, 61% 39%, 100% 50%, 61% 61%, 50% 100%, 39% 61%, 0% 50%, 39% 39%);
  animation: gfxTwinkle .7s ease-in-out infinite alternate;
}

/* ---- keyframes ------------------------------------------------------------ */

@keyframes gfxBob {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50%      { transform: translateY(-9px) rotate(1.5deg); }
}

@keyframes gfxPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.12); }
}

@keyframes gfxDust {
  0%   { transform: scale(.3); opacity: .9; }
  100% { transform: scale(1.8); opacity: 0; }
}

@keyframes gfxSpark {
  0%   { transform: translateY(0) scale(0); opacity: 0; }
  15%  { transform: translateY(-6px) scale(1); opacity: 1; }
  100% { transform: translateY(-80px) scale(.4); opacity: 0; }
}

@keyframes gfxTwinkle {
  from { transform: rotate(0deg) scale(.7); opacity: .75; }
  to   { transform: rotate(45deg) scale(1); opacity: 1; }
}

/* ---- tap / click the resting genie → Magic Wish ---------------------------- */

/* Invisible button over the whole genie. It carries .js-open-magic-wish, so
   public/js/magic-wish.js opens the existing Magic Wish popup with no extra wiring.
   Only clickable while he rests — mid-flight, taps and clicks pass straight through. */
.gfx-wish {
  position: absolute;
  inset: 0;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 40%;
  cursor: pointer;
}

.gfx-companion.is-resting .gfx-wish { pointer-events: auto; }

.gfx-wish:focus-visible {
  outline: 2px solid #f2b84b;
  outline-offset: 2px;
}

.gfx-dismiss { z-index: 1; } /* above .gfx-wish, so × hides instead of opening the wish */

/* ---- mobile ------------------------------------------------------------------ */

@media (hover: none), (pointer: coarse) {
  .gfx-companion .gfx-genie {
    width: 56px;
    height: 75px;
  }
}

/* ---- back to top  [DISABLED] --------------------------------------------------
   GENIE-DISABLED (2026-09-18): the button and its JS are commented out for now; these
   rules are left in place and match nothing until it is re-enabled. */

.gfx-top {
  position: fixed;
  left: 16px;
  bottom: 18px;
  z-index: 25;
  width: 50px;
  height: 50px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: radial-gradient(circle, #ffffff 0%, #e6f4fb 62%, #bfe2f4 100%);
  box-shadow: 0 0 0 2px rgba(124, 196, 232, .55), 0 6px 18px rgba(79, 163, 209, .45);
  cursor: pointer;
  opacity: 0;
  transform: translateY(16px) scale(.8);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}

.gfx-top.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

/* The genie pops up out of the top of the badge. */
.gfx-top img {
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 36px;
  height: 48px;
  margin-left: -18px;
  filter: drop-shadow(0 2px 3px rgba(0, 12, 82, .3));
  transition: transform .7s cubic-bezier(.5, 0, .75, .3), opacity .7s ease;
}

.gfx-top-arrow {
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translateX(-50%);
  padding: 0 6px;
  border-radius: 999px;
  background: #0b1550;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 15px;
}

/* Tapped: he flies off the top of the screen while the page scrolls up after him. */
.gfx-top.is-launching img {
  transform: translateY(-110vh) rotate(-8deg);
  opacity: .2;
}

.gfx-top:focus-visible {
  outline: 2px solid #f2b84b;
  outline-offset: 3px;
}

/* ---- page loader  [DISABLED] ---------------------------------------------------
   GENIE-DISABLED (2026-09-18): the loader JS is commented out for now; these rules are
   left in place and match nothing until it is re-enabled. */

/* Appended to <html> (not <body>) by genie-fx.js, so wire:navigate swapping the body
   out mid-load can't remove it before it's hidden again. */
.gfx-loader {
  position: fixed;
  inset: 0;
  z-index: 2000; /* above everything, modals included — it's only there while loading */
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(240, 245, 254, .55);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}

.gfx-loader.is-visible { opacity: 1; }

.gfx-loader-genie {
  position: relative;
  width: 72px;
  height: 96px;
}

.gfx-loader-genie img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  animation: gfxBob 1.6s ease-in-out infinite;
}

/* Spinning teal-and-gold glow ring behind him. */
.gfx-loader-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 150px;
  height: 150px;
  margin: -75px 0 0 -75px;
  border-radius: 50%;
  background: conic-gradient(from 0deg,
    rgba(124, 196, 232, 0), rgba(124, 196, 232, .9), rgba(242, 184, 75, .9), rgba(124, 196, 232, 0));
  -webkit-mask: radial-gradient(circle, transparent 58%, #000 60%, #000 70%, transparent 72%);
  mask: radial-gradient(circle, transparent 58%, #000 60%, #000 70%, transparent 72%);
  filter: blur(1px) drop-shadow(0 0 8px rgba(124, 196, 232, .8));
  animation: gfxSpin 1.1s linear infinite;
}

@keyframes gfxSpin {
  to { transform: rotate(360deg); }
}

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

/* ---- empty states ------------------------------------------------------------- */

.gfx-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.gfx-empty-genie {
  position: relative;
  width: 96px;
  height: 128px;
  margin: 4px auto 18px;
  --gfx-energy: 0;
}

.gfx-empty-genie img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  animation: gfxBob 3.2s ease-in-out infinite;
  filter: drop-shadow(0 8px 12px rgba(0, 12, 82, .22));
}

.gfx-empty-title {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
  color: var(--navy-text, #0b1550);
}

.gfx-empty-message {
  max-width: 420px;
  margin: 0 auto 18px;
  color: var(--text-muted, #6b7280);
  font-size: 14px;
  line-height: 1.6;
}

.gfx-empty-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ---- reduced motion ------------------------------------------------------------ */

/* A still genie with a steady glow — no floating, pulsing, spinning,
   flying or particles. Everything still works; it just doesn't move. */
@media (prefers-reduced-motion: reduce) {
  .gfx-bob,
  .gfx-aura-pulse,
  .gfx-empty-genie img,
  .gfx-loader-genie img,
  .gfx-loader-ring { animation: none; }
  .gfx-particles { display: none; }
  .gfx-top img { transition: none; }
  .gfx-top.is-launching img { transform: none; opacity: 1; }
}

/* ---- footer "Show Gini" link --------------------------------------------- */

.gfx-restore {
  margin-left: 16px;
  padding: 4px 12px;
  border: 1px solid rgba(124, 196, 232, .45);
  border-radius: 999px;
  background: rgba(124, 196, 232, .08);
  color: #7cc4e8;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background .2s ease, color .2s ease;
}

.gfx-restore:hover,
.gfx-restore:focus-visible {
  background: rgba(124, 196, 232, .2);
  color: #fff;
}

/* An author display rule would override the [hidden] attribute's UA display:none. */
.gfx-restore[hidden] { display: none; }
