/* ══════════════════════════════════════════════════════════════════════════
   Packet — the site companion (pixel-art pet)
   Sprite sheet: /img/packet/packet-sheet-v2.png, 48×36 px frames,
   rows: 0 idle (12) · 1 walk (8) · 2 sit (10) · 3 sleep (8) · 4 bark (6) · 5 run (6) · 6 jump (6).
   Drawn by tools/packet/sprite.py.
   nitepet.js only sets --fx / --fy (frame, row), --x / --y (px) and data-*
   flags; all drawing stays here, so the CSP (style-src 'self') needs no change.
   ══════════════════════════════════════════════════════════════════════════ */

.nitepet {
  --nitepet-scale: 2;                       /* whole pixels only: 2 = 96×72 on screen */
  --fx: 0;                                  /* frame column */
  --fy: 2;                                  /* row: the resting default is "sit" */
  --x: 0px;
  --y: 0px;
  --w: calc(48px * var(--nitepet-scale));
  --h: calc(36px * var(--nitepet-scale));
  pointer-events: none;                     /* only the sprite itself is clickable */
}

/* At home: a strip above the footer. This is the no-JS and reduced-motion state. */
.nitepet.is-home {
  flex: 1 0 100%;
  position: relative;
  height: var(--h);
  border-bottom: 1px dashed var(--border);  /* the floor it sits on */
}
/* Out and about: one layer over the page, in document coordinates, so the pet
   scrolls with whatever it is standing on. Below the sticky nav (z 100). */
.nitepet.is-roaming {
  position: absolute; left: 0; top: 0; width: 0; height: 0;
  z-index: 50;
}

.nitepet-sprite {
  position: absolute; left: 0;
  width: var(--w); height: var(--h);
  transform: translate(var(--x), var(--y));
  background: url('/img/packet/packet-sheet-v2.png') no-repeat;
  background-size: calc(576px * var(--nitepet-scale)) calc(252px * var(--nitepet-scale));
  background-position:
    calc(var(--fx) * -48px * var(--nitepet-scale))
    calc(var(--fy) * -36px * var(--nitepet-scale));
  image-rendering: pixelated;
  pointer-events: auto;
  border-radius: var(--r-md);
  -webkit-tap-highlight-color: transparent;
}
.is-home .nitepet-sprite { bottom: 0; left: 12px; }
.is-roaming .nitepet-sprite { top: 0; will-change: transform; }
/* Facing left is the sprite mirrored; the bubble is a sibling, so its text never flips. */
.nitepet[data-facing="left"] .nitepet-sprite { transform: translate(var(--x), var(--y)) scaleX(-1); }

.nitepet.is-live .nitepet-sprite { cursor: pointer; }
.nitepet-sprite:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 3px; }

/* Speech bubble above its head */
.nitepet-bubble {
  position: absolute; left: 0; top: 0;
  transform: translate(calc(var(--x) + var(--w) * 0.5 - 50%), calc(var(--y) - 100% - 2px));
  padding: 3px 9px;
  font-size: 0.76rem; font-weight: 700; white-space: nowrap;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  opacity: 0;
  transition: opacity .18s var(--ease);
  pointer-events: none;
}
.is-home .nitepet-bubble { top: auto; bottom: calc(var(--h) + 4px); left: 12px; transform: translateX(calc(var(--w) * 0.5 - 50%)); }
.nitepet[data-bubble] .nitepet-bubble { opacity: 1; }

/* Footer switch: send it home / let it out */
.foot-right { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.nitepet-toggle {
  font: inherit; font-size: 0.86rem; color: var(--muted); cursor: pointer;
  background: none; border: 0; padding: 0;
  text-decoration: underline; text-decoration-color: var(--border-strong); text-underline-offset: 3px;
}
.nitepet-toggle:hover { color: var(--ink); }
.nitepet-toggle[hidden] { display: none; }

@media print { .nitepet, .nitepet-toggle { display: none; } }
/* Nothing to stand on in view: it waits off screen. */
.nitepet[data-away] .nitepet-sprite { visibility: hidden; }
