.portal-pet {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1200;
  display: grid;
  grid-template-columns: minmax(210px, 290px) 96px;
  align-items: end;
  gap: 8px;
  max-width: calc(100vw - 16px);
  filter: drop-shadow(0 18px 28px rgba(2, 24, 53, .2));
  user-select: none;
  -webkit-user-select: none;
}
.portal-pet[hidden] { display: none !important; }
body.auth-pending .portal-pet, body.auth-pending .portal-pet-show,
body.firebase-pending .portal-pet, body.firebase-pending .portal-pet-show { display: none !important; }
.portal-pet-bubble[hidden] { display: none !important; }
.portal-pet-bubble {
  position: relative;
  box-sizing: border-box;
  min-width: 0;
  padding: 16px 42px 13px 17px;
  border: 1px solid rgba(27, 112, 239, .22);
  border-radius: 18px;
  background: rgba(255, 255, 255, .97);
  color: #10213a;
  box-shadow: 0 16px 42px rgba(4, 35, 73, .16);
  user-select: text;
  -webkit-user-select: text;
}
.portal-pet-bubble::after {
  content: "";
  position: absolute;
  right: -8px;
  bottom: 22px;
  width: 16px;
  height: 16px;
  border-top: 1px solid rgba(27, 112, 239, .22);
  border-right: 1px solid rgba(27, 112, 239, .22);
  background: #fff;
  transform: rotate(45deg);
}
.portal-pet-kicker {
  display: block;
  margin-bottom: 5px;
  color: #0b67d8;
  font-size: .68rem;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.portal-pet-message {
  margin: 0;
  font-size: .84rem;
  line-height: 1.46;
  opacity: 1;
  transition: opacity .16s ease;
}
.portal-pet-message.is-changing { opacity: .28; }
.portal-pet-drag-hint {
  display: block;
  margin-top: 8px;
  color: #64748b;
  font-size: .66rem;
  font-weight: 700;
  line-height: 1.25;
}
.portal-pet-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: #eef5ff;
  color: #12345f;
  font: 800 1.08rem/1 system-ui, sans-serif;
  cursor: pointer;
}
.portal-pet-close:hover, .portal-pet-close:focus-visible { background: #dceaff; outline: 2px solid #1877f2; outline-offset: 2px; }
.portal-pet-character {
  width: 96px;
  height: 118px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: grab;
  touch-action: none;
}
.portal-pet-character:active,
.portal-pet.is-dragging .portal-pet-character { cursor: grabbing; }
.portal-pet-character img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  transform-origin: 50% 100%;
  animation: portal-pet-float 3.2s ease-in-out infinite;
}
.portal-pet-character:hover img, .portal-pet-character:focus-visible img { transform: translateY(-3px) rotate(-2deg); }
.portal-pet-character:focus-visible { border-radius: 24px; outline: 3px solid #20c9e8; outline-offset: 3px; }
.portal-pet.is-dragging { filter: drop-shadow(0 22px 34px rgba(2, 24, 53, .28)); }
.portal-pet.is-dragging .portal-pet-character img { animation-play-state: paused; transform: translateY(-3px) scale(1.03); }
.portal-pet-show {
  position: fixed;
  right: 20px;
  bottom: 22px;
  z-index: 1200;
  min-width: 48px;
  min-height: 48px;
  border: 1px solid rgba(40, 182, 255, .45);
  border-radius: 999px;
  padding: 10px 14px;
  background: #082a52;
  color: #fff;
  box-shadow: 0 12px 28px rgba(2, 24, 53, .24);
  font: 800 .76rem/1 system-ui, sans-serif;
  cursor: pointer;
}
.portal-pet-show[hidden] { display: none !important; }
body.portal-pet-backtop-page .portal-pet:not(.portal-pet-positioned) { bottom: 88px; }
.portal-pet-show.portal-pet-avoid-backtop { bottom: 88px; }
.portal-pet-show:hover, .portal-pet-show:focus-visible { background: #0d58a6; outline: 3px solid rgba(39, 204, 240, .4); outline-offset: 2px; }
@keyframes portal-pet-float { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-7px) rotate(1.5deg); } }
@media (max-width: 720px) {
  .portal-pet {
    right: 10px;
    bottom: 76px;
    grid-template-columns: minmax(166px, 228px) 72px;
    gap: 5px;
  }
  .portal-pet-character { width: 72px; height: 92px; }
  .portal-pet-bubble { padding: 13px 38px 11px 14px; }
  .portal-pet-message { font-size: .77rem; }
  .portal-pet-drag-hint { font-size: .62rem; }
  body.portal-pet-backtop-page .portal-pet:not(.portal-pet-positioned) { bottom: 82px; }
  .portal-pet-show { right: 10px; bottom: 78px; }
  .portal-pet-show.portal-pet-avoid-backtop { bottom: 74px; right: 68px; }
}

/* Public website: Buddy is icon-only by default. The tip card opens on click. */
body.public-home .portal-pet-show { display: none !important; }
body.public-home .portal-pet.portal-pet-public-home {
  width: 96px;
  max-width: 96px;
  grid-template-columns: 96px;
  gap: 0;
  /* A filter on the parent would make fixed-position tip cards anchor to the pet
     instead of the viewport in mobile browsers. Keep the shadow on the robot image. */
  filter: none;
}
body.public-home .portal-pet.portal-pet-public-home .portal-pet-character img {
  filter: drop-shadow(0 12px 18px rgba(2, 24, 53, .24));
}
body.public-home .portal-pet.portal-pet-public-home .portal-pet-character {
  width: 96px;
  height: 118px;
}
body.public-home .portal-pet.portal-pet-public-home .portal-pet-bubble:not([hidden]) {
  position: fixed;
  right: 128px;
  bottom: max(24px, env(safe-area-inset-bottom));
  width: min(330px, calc(100vw - 160px));
  max-width: 330px;
  min-width: 240px;
  max-height: none;
  overflow: hidden;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
  z-index: 1201;
}

/* Match the site's mobile/tablet navigation breakpoint so Samsung/mobile browsers
   never fall back to the narrow desktop speech-bubble grid. */
@media (max-width: 860px) {
  body.public-home .portal-pet.portal-pet-mobile-home {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: 72px;
    max-width: 72px;
    grid-template-columns: 72px;
    gap: 0;
  }
  body.public-home .portal-pet.portal-pet-mobile-home .portal-pet-character {
    width: 72px;
    height: 92px;
  }
  body.public-home .portal-pet.portal-pet-mobile-home .portal-pet-bubble:not([hidden]) {
    position: fixed;
    left: 50%;
    right: auto;
    top: auto;
    bottom: calc(104px + env(safe-area-inset-bottom));
    width: calc(100vw - 24px);
    width: calc(100dvw - 24px);
    min-width: 0;
    max-width: 420px;
    max-height: none;
    margin: 0;
    padding: 13px 40px 12px 14px;
    transform: translateX(-50%);
    box-sizing: border-box;
    overflow: hidden;
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;
    border-radius: 16px;
  }
  body.public-home .portal-pet.portal-pet-mobile-home .portal-pet-bubble::after { display: none; }
  body.public-home .portal-pet.portal-pet-mobile-home .portal-pet-kicker {
    margin-bottom: 4px;
    font-size: .64rem;
    line-height: 1.2;
    letter-spacing: .05em;
  }
  body.public-home .portal-pet.portal-pet-mobile-home .portal-pet-message {
    font-size: clamp(.78rem, 3.25vw, .88rem);
    line-height: 1.38;
  }
  body.public-home .portal-pet.portal-pet-mobile-home .portal-pet-drag-hint {
    margin-top: 7px;
    font-size: .62rem;
    line-height: 1.25;
  }
  body.public-home .portal-pet.portal-pet-mobile-home .portal-pet-close {
    top: 7px;
    right: 7px;
    width: 28px;
    height: 28px;
    font-size: 1rem;
  }
}

@media (max-width: 380px) {
  .portal-pet:not(.portal-pet-public-home) { grid-template-columns: minmax(150px, 1fr) 64px; width: calc(100vw - 16px); }
  .portal-pet-character { width: 64px; height: 82px; }
  body.public-home .portal-pet.portal-pet-mobile-home { width: 64px; max-width: 64px; }
  body.public-home .portal-pet.portal-pet-mobile-home .portal-pet-character { width: 64px; height: 82px; }
  body.public-home .portal-pet.portal-pet-mobile-home .portal-pet-bubble:not([hidden]) {
    width: calc(100vw - 20px);
    width: calc(100dvw - 20px);
    padding: 12px 38px 11px 13px;
  }
  body.public-home .portal-pet.portal-pet-mobile-home .portal-pet-message { font-size: .78rem; line-height: 1.35; }
}
@media (prefers-reduced-motion: reduce) {
  .portal-pet-character img { animation: none; }
  .portal-pet-message { transition: none; }
}
/* Mobile UX: pets are intentionally disabled on phone/tablet layouts. */
@media (max-width: 860px) {
  .portal-pet,
  .portal-pet-show {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
  }
}
@media print { .portal-pet, .portal-pet-show { display: none !important; } }


/* V80 public helper placement: left side, aligned with the back-to-top control. */
body.public-home .portal-pet.portal-pet-public-home:not(.portal-pet-positioned) {
  left: max(22px, env(safe-area-inset-left));
  right: auto;
  bottom: max(22px, env(safe-area-inset-bottom));
}
body.public-home.portal-pet-backtop-page .portal-pet.portal-pet-public-home:not(.portal-pet-positioned) {
  bottom: max(22px, env(safe-area-inset-bottom));
}
body.public-home .portal-pet.portal-pet-public-home .portal-pet-bubble:not([hidden]) {
  left: 128px;
  right: auto;
  bottom: max(22px, env(safe-area-inset-bottom));
}
body.public-home .portal-pet.portal-pet-public-home .portal-pet-bubble::after {
  left: -8px;
  right: auto;
  border-right: 0;
  border-top: 0;
  border-left: 1px solid rgba(27, 112, 239, .22);
  border-bottom: 1px solid rgba(27, 112, 239, .22);
}
