/* ============================ Pet companion ============================
   The pixel-art mascot that floats in a corner of every signed-in screen, its
   speech bubble, and the panel (talk, pick a pet, settings). Loaded after shell.css.
   Sits at z-index 80: above the header (30) and mobile nav (60), below popovers
   (100) and modals (1000). */

.pet {
  position: fixed; right: 24px; bottom: 24px; z-index: 80;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  font-family: var(--font-sans); color: var(--ink);
}
.pet--left { right: auto; left: 24px; align-items: flex-start; }
@media (max-width: 640px) {
  .pet { right: 12px; bottom: 12px; }
  .pet--left { left: 12px; }
}

/* ---------- The character ---------- */
.pet__body {
  position: relative; display: grid; place-items: center;
  width: 96px; height: 96px; padding: 0; border: 0; background: none; cursor: pointer;
  border-radius: 50%; -webkit-tap-highlight-color: transparent;
}
.pet__body:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 4px; }
.pet__body::before {
  /* soft shadow on the "floor" so the bob reads as hovering */
  content: ""; position: absolute; bottom: 8px; left: 50%; width: 44px; height: 10px;
  transform: translateX(-50%); border-radius: 50%;
  background: rgba(18, 25, 38, 0.14); filter: blur(2px);
  animation: pet-shadow 2.4s ease-in-out infinite;
}
.pet__sprite {
  display: block; width: 72px; height: 72px;
  image-rendering: pixelated; image-rendering: crisp-edges;
  transform-origin: 50% 100%;
  animation: pet-bob 2.4s ease-in-out infinite;
  filter: drop-shadow(0 2px 0 rgba(18, 25, 38, 0.08));
}
@media (max-width: 640px) {
  .pet__body { width: 72px; height: 72px; }
  .pet__sprite { width: 56px; height: 56px; }
}
.pet__body:hover .pet__sprite { animation-duration: 1.4s; }

/* Moods override the idle bob. */
.pet__body[data-mood="happy"] .pet__sprite { animation: pet-happy 0.9s ease-in-out 2; }
.pet__body[data-mood="cheer"] .pet__sprite { animation: pet-cheer 0.7s cubic-bezier(.3,1.6,.5,1) 3; }
.pet__body[data-mood="think"] .pet__sprite { animation: pet-think 2.2s ease-in-out infinite; }
.pet__body[data-mood="sad"] .pet__sprite { animation: pet-sad 3s ease-in-out infinite; }
.pet__body[data-mood="sleepy"] .pet__sprite { animation: pet-sleep 4s ease-in-out infinite; }
.pet__body--squash .pet__sprite { animation: pet-squash 320ms ease-out 1 !important; }

.pet__zz {
  position: absolute; top: 4px; right: 10px; font-size: 13px; font-weight: 700; color: var(--ink-muted);
  pointer-events: none; animation: pet-zz 2s ease-in-out infinite;
}
.pet__zz::after { content: "z"; position: absolute; left: 9px; top: -9px; font-size: 10px; animation: pet-zz 2s ease-in-out infinite 0.6s; }
.pet--left .pet__zz { right: auto; left: 10px; }

@keyframes pet-bob    { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes pet-shadow { 0%,100% { transform: translateX(-50%) scale(1); opacity: .9; } 50% { transform: translateX(-50%) scale(.82); opacity: .55; } }
@keyframes pet-happy  { 0%,100% { transform: translateY(0) rotate(0); } 25% { transform: translateY(-5px) rotate(-6deg); } 75% { transform: translateY(-5px) rotate(6deg); } }
@keyframes pet-cheer  { 0%,100% { transform: translateY(0) scale(1, 1); } 20% { transform: translateY(2px) scale(1.12, .88); } 60% { transform: translateY(-18px) scale(.94, 1.08); } }
@keyframes pet-think  { 0%,100% { transform: rotate(0); } 50% { transform: rotate(-8deg) translateY(-2px); } }
@keyframes pet-sad    { 0%,100% { transform: translateY(0) scale(1, 1); } 50% { transform: translateY(3px) scale(1.04, .96); } }
@keyframes pet-sleep  { 0%,100% { transform: rotate(-3deg) scale(1, .98); } 50% { transform: rotate(3deg) scale(1, 1); } }
@keyframes pet-squash { 0% { transform: scale(1, 1); } 40% { transform: scale(1.2, .8); } 70% { transform: scale(.92, 1.08); } 100% { transform: scale(1, 1); } }
@keyframes pet-zz     { 0% { opacity: 0; transform: translate(0, 4px); } 30% { opacity: 1; } 100% { opacity: 0; transform: translate(6px, -10px); } }

/* ---------- Speech bubble ---------- */
.pet__bubble {
  position: relative; max-width: 240px; margin: 0 6px;
  padding: 10px 14px; border-radius: var(--radius-lg); border: 1px solid var(--border-hairline);
  background: var(--surface-card); box-shadow: var(--shadow-popover);
  font-size: 13.5px; line-height: 1.4; cursor: pointer;
  animation: pet-pop 220ms cubic-bezier(.3,1.4,.5,1) both;
}
.pet__bubble::after {
  content: ""; position: absolute; bottom: -7px; right: 26px; width: 12px; height: 12px;
  background: var(--surface-card); border-right: 1px solid var(--border-hairline); border-bottom: 1px solid var(--border-hairline);
  transform: rotate(45deg);
}
.pet--left .pet__bubble::after { right: auto; left: 26px; }
.pet__bubble--out { animation: pet-fade 260ms ease-in both; }
@keyframes pet-pop  { from { opacity: 0; transform: translateY(6px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes pet-fade { to { opacity: 0; transform: translateY(4px); } }

/* ---------- Panel ---------- */
.pet__panel {
  width: 320px; max-width: calc(100vw - 24px); max-height: min(520px, calc(100vh - 140px));
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: var(--radius-lg); border: 1px solid var(--border-hairline);
  background: var(--surface-card); box-shadow: var(--shadow-popover);
  animation: pet-pop 200ms ease-out both;
}
.pet__tabs { display: flex; border-bottom: 1px solid var(--border-hairline); padding: 6px 6px 0; gap: 2px; }
.pet__tab {
  flex: 1; padding: 8px 6px; border: 0; border-bottom: 2px solid transparent; background: none;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--ink-muted); cursor: pointer;
}
.pet__tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--primary); }
.pet__tab:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; border-radius: 6px; }
.pet__pane { padding: 12px; overflow-y: auto; display: grid; gap: 10px; }
.pet__hint { margin: 0; font-size: 12.5px; color: var(--ink-muted); line-height: 1.45; }
.pet__err { margin: 0; font-size: 12.5px; color: var(--danger); }

/* Talk */
.pet__log { display: grid; gap: 8px; }
.pet__msg { font-size: 13.5px; line-height: 1.4; padding: 8px 10px; border-radius: 10px; max-width: 92%; }
.pet__msg--you { justify-self: end; background: var(--primary-soft); color: var(--primary-ink); }
.pet__msg--pet { justify-self: start; background: var(--surface-sunken); border: 1px solid var(--border-hairline); }
.pet__msg--pet small { display: block; margin-top: 2px; font-size: 11px; color: var(--ink-faint); }
.pet__ask { display: flex; gap: 6px; }
.pet__ask input {
  flex: 1; min-width: 0; padding: 9px 10px; border-radius: var(--radius-md); border: 1px solid var(--border-control);
  font: inherit; font-size: 13.5px; background: var(--surface-card); color: var(--ink);
}
.pet__ask input:focus { outline: 2px solid var(--focus-ring); outline-offset: 1px; border-color: transparent; }
.pet__ask button {
  padding: 0 14px; border-radius: var(--radius-md); border: 0; background: var(--primary); color: var(--on-primary);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.pet__ask button:disabled { opacity: .55; cursor: default; }
.pet__meta { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-faint); }

/* Gallery */
.pet__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.pet__card {
  display: grid; justify-items: center; align-content: start; gap: 4px; padding: 10px 6px 8px;
  border-radius: var(--radius-md); border: 1px solid var(--border-hairline); background: var(--surface-card);
  font: inherit; cursor: pointer; text-align: center; color: var(--ink);
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.pet__card:hover { transform: translateY(-2px); box-shadow: var(--shadow-raised); }
.pet__card[aria-pressed="true"] { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.pet__card .pix { width: 44px; height: 44px; image-rendering: pixelated; }
.pet__card:hover .pix { animation: pet-happy 0.8s ease-in-out infinite; }
.pet__cardname { font-size: 12.5px; font-weight: 600; }
.pet__cardtag { font-size: 10.5px; line-height: 1.3; color: var(--ink-muted); }
.pet__card--none .pet__nonemark {
  width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%;
  border: 1.5px dashed var(--border-control); color: var(--ink-faint); font-size: 18px;
}

/* Settings */
.pet__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.pet__row label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.pet__seg { display: inline-flex; border: 1px solid var(--border-control); border-radius: var(--radius-pill); overflow: hidden; }
.pet__seg button { padding: 5px 12px; border: 0; background: none; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--ink-muted); }
.pet__seg button[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary-ink); font-weight: 600; }
.pet__row input[type="text"] {
  width: 140px; padding: 6px 8px; border-radius: var(--radius-sm); border: 1px solid var(--border-control); font: inherit; font-size: 13px;
}

.pet__foot { border-top: 1px solid var(--border-hairline); padding: 6px 8px; display: flex; justify-content: flex-end; }
.pet__link { border: 0; background: none; padding: 4px 6px; font: inherit; font-size: 12px; color: var(--primary-ink); cursor: pointer; border-radius: 6px; }
.pet__link:hover { text-decoration: underline; }
.pet__link:focus-visible { outline: 2px solid var(--focus-ring); }

/* ---------- Profile page ---------- */
.profile { display: flex; align-items: flex-start; gap: var(--space-5); }
.profile__who { display: grid; gap: 4px; min-width: 0; }
.profile__who .h2 { margin: 0; }
.profile__facts { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-6); margin: var(--space-3) 0 0; }
.profile__facts div { display: grid; gap: 2px; }
.profile__facts dt { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-faint); }
.profile__facts dd { margin: 0; font-size: 14px; }

.petset { display: grid; gap: var(--space-4); }
.petset__head .h2 { margin: 0 0 4px; }
.petset__head p { margin: 0; max-width: 60ch; }
.petset__preview {
  display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap;
  padding: var(--space-4); border-radius: var(--radius-lg); background: var(--surface-sunken); border: 1px solid var(--border-hairline);
}
.petset__stage { display: grid; place-items: center; width: 128px; height: 128px; border-radius: var(--radius-lg); background: var(--surface-card); border: 1px solid var(--border-hairline); }
.petset__stage--off { opacity: .4; filter: grayscale(1); }
.petset__sprite { image-rendering: pixelated; animation: pet-bob 2.4s ease-in-out infinite; }
.petset__meta { display: grid; gap: 2px; flex: 1 1 160px; min-width: 0; }
.petset__meta strong { font-size: 16px; }
.petset__sub { margin: var(--space-2) 0 0; }
.pet__grid--wide { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.pet__grid--wide .pet__card { padding: 16px 10px 12px; gap: 6px; }
.pet__grid--wide .pet__card .pix { width: 56px; height: 56px; }
.pet__grid--wide .pet__cardname { font-size: 13.5px; }
.pet__grid--wide .pet__cardtag { font-size: 11.5px; }
.petset__rows { display: grid; gap: var(--space-3); max-width: 520px; }
.petset__rows .pet__row { padding: 10px 12px; border: 1px solid var(--border-hairline); border-radius: var(--radius-md); }
@media (max-width: 640px) { .profile { flex-direction: column; } }

/* Hidden pet: a faint dot in the corner brings it back. */
.pet__restore {
  position: fixed; right: 16px; bottom: 16px; z-index: 80; width: 22px; height: 22px; border-radius: 50%;
  border: 1px solid var(--border-hairline); background: var(--surface-card); color: var(--ink-faint);
  font-size: 12px; line-height: 1; cursor: pointer; opacity: .45; transition: opacity 120ms ease, transform 120ms ease;
  display: grid; place-items: center; padding: 0;
}
.pet__restore--left { right: auto; left: 16px; }
.pet__restore:hover, .pet__restore:focus-visible { opacity: 1; transform: scale(1.1); }

@media (prefers-reduced-motion: reduce) {
  .pet__sprite, .petset__sprite, .pet__body::before, .pet__card:hover .pix, .pet__zz, .pet__zz::after { animation: none !important; }
  .pet__bubble, .pet__panel { animation: none; }
  .pet__card:hover { transform: none; }
}
