/* ---------------------------------------------------------------
   Companion bird (js/components/petCompanion.js, petPicker.js)

   .pet-layer is a fixed, click-through overlay at z-index 9999 so the
   bird flies over the whole main menu. Modals (.modal-backdrop) sit at
   10000 (see menu.css) so they still cover it.

   Structure (each wrapper owns exactly one transform):
     .pet-bird           translate3d position + Web Animations flight
       .pet-bird__flip     scaleX facing; click / keyboard target
         .pet-bird__body     flap, slow bounce, landing squash
           img               hop when petted
       .pet-bubble         the popup (not mirrored)
   ----------------------------------------------------------------*/
.pet-layer {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none; /* only the bird + popup are interactive */
  overflow: hidden;
  --pet-size: 110px;    /* long side of the sprite */
}

.pet-bird {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: auto;
  will-change: transform;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Mid-flight (or fading out) the bird can't be clicked. */
.pet-bird.is-flying,
.pet-bird.is-retiring {
  pointer-events: none;
}

.pet-bird.is-retiring {
  opacity: 0;
  transition: opacity 250ms ease;
}

.pet-bird__flip {
  cursor: pointer;
  border-radius: 10px;
}

.pet-bird__flip:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 4px;
}

.pet-bird__body {
  transform-origin: 50% 100%;
}

/* Sizes by the longer side so tall birds (owl, heron) and wide birds
   (shoveler, sandpiper) both read at a similar scale. */
.pet-bird__img {
  display: block;
  width: auto;
  height: auto;
  max-width: var(--pet-size);
  max-height: var(--pet-size);
  filter: drop-shadow(0 6px 5px rgba(32, 42, 31, 0.35));
  -webkit-user-drag: none;
}

/* ---- Animations ---- */
@keyframes pet-flap {
  from { transform: scale(1, 1) rotate(-4deg); }
  to   { transform: scale(1.05, 0.86) rotate(4deg); }
}

@keyframes pet-bounce-slow {
  0%, 100% { transform: translateY(0) scale(1, 1); }
  50%      { transform: translateY(-10px) scale(0.98, 1.03); }
}

@keyframes pet-land {
  0%   { transform: scale(1.1, 0.84); }
  60%  { transform: scale(0.97, 1.05); }
  100% { transform: scale(1, 1); }
}

@keyframes pet-hop {
  0%, 100% { transform: translateY(0); }
  30%      { transform: translateY(-16px); }
  60%      { transform: translateY(0); }
  80%      { transform: translateY(-6px); }
}

@keyframes pet-emoji {
  0%   { opacity: 0; transform: translate(-50%, 0) scale(0.5); }
  20%  { opacity: 1; transform: translate(-50%, -6px) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -34px) scale(1); }
}

.pet-bird.is-flying .pet-bird__body {
  animation: pet-flap 0.18s ease-in-out infinite alternate;
}

.pet-bird.is-active .pet-bird__body {
  animation: pet-bounce-slow 1.8s ease-in-out infinite;
}

.pet-bird__body.is-landing {
  animation: pet-land 0.35s ease-out;
}

.pet-bird__img.is-petted {
  animation: pet-hop 0.5s ease-out;
}

/* Smiley / food emoji: appears over the bird's body, rises and fades. */
.pet-emoji {
  position: absolute;
  left: 50%;
  top: 20%;
  font-size: 2rem;
  line-height: 1;
  pointer-events: none;
  animation: pet-emoji 1s ease-out forwards;
}

@media (prefers-reduced-motion: reduce) {
  .pet-bird.is-flying .pet-bird__body,
  .pet-bird.is-active .pet-bird__body,
  .pet-bird__body.is-landing,
  .pet-bird__img.is-petted {
    animation: none;
  }

  /* Keep the feedback, drop the movement. */
  .pet-emoji {
    animation: pet-emoji-fade 1.2s ease-out forwards;
    transform: translate(-50%, 0);
  }

  @keyframes pet-emoji-fade {
    0%, 70% { opacity: 1; }
    100%    { opacity: 0; }
  }
}

/* ---- Popup ---- */
.pet-bubble {
  --shift: 0px; /* set by placeBubble() to stay on-screen */
  position: absolute;
  left: 50%;
  bottom: calc(100% + 14px);
  z-index: 2;
  width: 210px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--pine);
  box-shadow: 0 14px 28px -14px rgba(32, 42, 31, 0.6);
  transform: translateX(calc(-50% + var(--shift)));
  cursor: default;
}

.pet-bubble[hidden] {
  display: none;
}

/* Tail pointing at the bird, counter-shifted so it stays centred on it. */
.pet-bubble::after {
  content: '';
  position: absolute;
  left: calc(50% - var(--shift));
  bottom: -9px;
  width: 14px;
  height: 14px;
  background: var(--card);
  border-right: 2px solid var(--pine);
  border-bottom: 2px solid var(--pine);
  transform: translateX(-50%) rotate(45deg);
}

/* No room above (bird near the top edge): drop below it instead. */
.pet-bubble.is-below {
  bottom: auto;
  top: calc(100% + 14px);
}

.pet-bubble.is-below::after {
  bottom: auto;
  top: -9px;
  transform: translateX(-50%) rotate(225deg);
}

.pet-bubble__name {
  margin: 0;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.1;
  color: var(--pine-dark);
}

.pet-stat__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(32, 42, 31, 0.7);
}

.pet-stat__value {
  font-size: 0.8rem;
  letter-spacing: 0;
  color: var(--ink);
}

.pet-stat__bar {
  height: 8px;
  background: rgba(166, 156, 124, 0.35);
  border: 1px solid var(--rule);
  overflow: hidden;
}

.pet-stat__fill {
  height: 100%;
  width: 0;
  background: var(--pine);
  transition: width 300ms ease, background-color 300ms ease;
}

.pet-stat__fill.is-low {
  background: var(--error);
}

.pet-bubble__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pet-bubble__btn {
  padding: 8px 10px;
  font-size: 0.85rem;
}

/* ---- "Your bird flew away" notice ---- */
.pet-notice {
  position: absolute;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  max-width: min(420px, calc(100% - 32px));
  margin: 0;
  padding: 12px 16px;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--rule);
  box-shadow: 0 14px 28px -14px rgba(32, 42, 31, 0.6);
  font-size: 0.9rem;
  line-height: 1.4;
  text-align: center;
}

/* ---------------------------------------------------------------
   Picker modal (components/petPicker.js)
   Reuses .modal-backdrop / .modal-card / .modal-close from menu.css.
   ----------------------------------------------------------------*/
.modal-card--pet {
  width: min(760px, 100%);
}

.pet-picker {
  max-height: min(680px, 84vh);
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  color: var(--ink);
  background: var(--card);
  border: 6px solid var(--pine);
}

.pet-picker__title {
  margin: 0 0 4px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.5rem;
  color: var(--pine-dark);
}

.pet-picker__hint {
  margin: 0;
  font-size: 0.9rem;
  color: rgba(32, 42, 31, 0.7);
}

.pet-picker__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(124px, 1fr));
  gap: 10px;
  min-height: 0;
  padding: 2px 4px 2px 2px;
}

.pet-picker__status {
  grid-column: 1 / -1;
  margin: 0;
  padding: 24px 0;
  text-align: center;
  color: rgba(32, 42, 31, 0.6);
}

.pet-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  cursor: pointer;
}

.pet-choice:hover {
  border-color: var(--pine);
  background: #efe9d2;
}

.pet-choice:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.pet-choice.is-current {
  border-color: var(--pine);
  box-shadow: inset 0 0 0 2px var(--pine);
}

.pet-choice__frame {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
  height: 84px;
}

.pet-choice__img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  -webkit-user-drag: none;
}

.pet-choice__name {
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
}