/* SPRITE — Junior, a pixel-art character that tells visitors facts about Jared, plus a bird that flits around the page */

.sprite-summon {
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color 0.15s;
}
.sprite-summon:hover { border-color: var(--text); }
.sprite-summon:focus-visible { outline: 2px solid #0b5fff; outline-offset: 4px; border-radius: 2px; }

.sprite {
  --sprite-skin: #a96b43;
  --sprite-skin-shade: #7a4a2b;
  --sprite-cap: #3b82f6;
  --sprite-cap-shade: #1d4ed8;
  --sprite-hoodie: #111111;
  --sprite-pants: #4b5563;
  --bird-body: #ea580c;
  --bird-wing: #9a3412;
  --bird-belly: #fdba74;
  --bird-beak: #b45309;

  /* Distance of the character from the viewport edge, and the room around him the bird perches in. */
  --sprite-inset: 24px;
  --sprite-orbit: 16px;

  position: fixed;
  right: calc(var(--sprite-inset) - var(--sprite-orbit));
  bottom: calc(var(--sprite-inset) - var(--sprite-orbit));
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}
.sprite.is-open {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
}

/* Nothing animates while Junior is dismissed */
.sprite:not(.is-open) * { animation-play-state: paused; }

/* BUBBLE */
.sprite-bubble {
  position: relative;
  z-index: 1; /* the bird flies behind the bubble, never over the text */
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: max-content;
  max-width: min(280px, calc(100vw - 32px));
  margin-right: var(--sprite-orbit); /* line the bubble up with the character, not the bird's lane */
  padding: 12px 16px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

/* Tail: a rotated square centred over the sprite (sprite is 64px wide, so its centre is 32px from the right) */
.sprite-bubble::after {
  content: '';
  position: absolute;
  right: 24px;
  bottom: -8px;
  width: 16px;
  height: 16px;
  border-right: 1px solid rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  background: #ffffff;
  transform: rotate(45deg);
}

.sprite-bubble-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.sprite-fact {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  font-weight: 300;
  line-height: 1.6;
  color: var(--text);
}
.sprite-fact.is-quip { font-style: italic; color: var(--muted); }
.sprite-fact.is-swapping { animation: sprite-swap 0.2s ease; }

.sprite-hint {
  font-size: 0.7rem;
  color: #767676;
}

/* Close: a 32px hit area whose 12px × sits at the bubble's top-right corner (24px in from both edges) */
.sprite-close {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  margin: -4px -8px -4px 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.sprite-close:hover { color: var(--text); background: #f7f7f7; }
.sprite-close:focus-visible { outline: 2px solid #0b5fff; outline-offset: 2px; }

/* CHARACTER — 16×16 pixel grid drawn at 4px per pixel */
.sprite-stage {
  position: relative;
  padding: var(--sprite-orbit);
}

.sprite-btn {
  display: block;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.sprite-btn:focus-visible { outline: 2px solid #0b5fff; outline-offset: 4px; border-radius: 4px; }

.sprite-figure {
  display: block;
  width: 64px;
  height: 64px;
  overflow: visible;
  shape-rendering: crispEdges;
  animation: sprite-bob 1.2s steps(1, end) infinite;
}

.sprite-skin { fill: var(--sprite-skin); }
.sprite-skin-shade { fill: var(--sprite-skin-shade); }
.sprite-cap { fill: var(--sprite-cap); }
.sprite-cap-shade { fill: var(--sprite-cap-shade); }
.sprite-hoodie { fill: var(--sprite-hoodie); }
.sprite-string { fill: #ffffff; }
.sprite-pants { fill: var(--sprite-pants); }
.sprite-shoe { fill: #111111; }
.sprite-eye {
  fill: #111111;
  transform-box: fill-box;
  transform-origin: center;
  animation: sprite-blink 4s ease-in-out infinite;
}

/* BIRD — 6×5 pixel grid at 4px per pixel (a 24×20 box). It starts perched in the stage's top-left
   corner; sprite.js moves it with transforms in stage coordinates, within a short range of Junior.
   The lane wrapper takes a sideways bulge so flights curve. */
.sprite-bird {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 20px;
  pointer-events: none;
}

.sprite-bird-art {
  display: block;
  width: 24px;
  height: 20px;
  shape-rendering: crispEdges;
  transform-origin: center;
}

.sprite-bird-body, .sprite-bird-head { fill: var(--bird-body); }
.sprite-bird-tail, .sprite-bird-wing-up, .sprite-bird-wing-down { fill: var(--bird-wing); }
.sprite-bird-belly { fill: var(--bird-belly); }
.sprite-bird-beak { fill: var(--bird-beak); }
.sprite-bird-eye, .sprite-bird-leg { fill: #111111; }

/* Perched: wings down. Flying: wings alternate. */
.sprite-bird-wing-up { opacity: 0; }
.sprite-bird.is-flying .sprite-bird-wing-up { animation: sprite-flap-up 0.4s steps(1, end) infinite; }
.sprite-bird.is-flying .sprite-bird-wing-down { animation: sprite-flap-down 0.4s steps(1, end) infinite; }

@keyframes sprite-flap-up {
  0%   { opacity: 1; }
  50%  { opacity: 0; }
}

@keyframes sprite-flap-down {
  0%   { opacity: 0; }
  50%  { opacity: 1; }
}

/* IDLE — one-pixel bob (4px) and an occasional blink */
@keyframes sprite-bob {
  0%   { transform: translateY(0); }
  50%  { transform: translateY(-4px); }
}

@keyframes sprite-blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95%           { transform: scaleY(0.1); }
}

@keyframes sprite-swap {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

@media (max-width: 768px) {
  .sprite { --sprite-inset: 16px; }
}

/* Reduced motion: no bob, blink or text swap, and the bird stays perched (sprite.js never launches it). */
@media (prefers-reduced-motion: reduce) {
  .sprite { transition: opacity 0.2s ease, visibility 0s linear 0.2s; transform: none; }
  .sprite.is-open { transition-delay: 0s; }
  .sprite-figure, .sprite-eye, .sprite-fact.is-swapping { animation: none; }
}
