.jm-mascot,
.jm-mascot * {
  box-sizing: border-box;
}

.jm-mascot {
  --jm-width: 88px;
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 50;
  width: var(--jm-width);
  height: calc(var(--jm-width) * 576 / 448);
  pointer-events: none;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.jm-mascot[hidden],
.jm-mascot-panel[hidden],
.jm-mascot-restore[hidden] {
  display: none !important;
}

.jm-mascot__launcher {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 30% 30% 44% 30%;
  color: #10232b;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  filter: drop-shadow(0 12px 18px rgba(16, 35, 43, 0.2));
  transition: filter 180ms ease, transform 180ms ease;
  transform-origin: center 88%;
}

.jm-mascot__launcher:hover,
.jm-mascot__launcher:focus-visible {
  filter: drop-shadow(0 15px 22px rgba(16, 35, 43, 0.27));
}

.jm-mascot__launcher:focus-visible {
  outline: 3px solid #3655d8;
  outline-offset: 4px;
}

.jm-mascot__sprite {
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 448 / 576;
  background-image: url('/assets/mascot/tablet-idle-v2.webp');
  background-repeat: no-repeat;
  background-position: center;
  background-size: 100% 100%;
}

.jm-mascot[data-pose="work"] .jm-mascot__sprite {
  background-image: url('/assets/mascot/tablet-work-v2.webp');
}

.jm-mascot[data-pose="success"] .jm-mascot__sprite {
  background-image: url('/assets/mascot/tablet-success-v2.webp');
}

.jm-mascot[data-pose="wave"] .jm-mascot__sprite {
  background-image: url('/assets/mascot/tablet-wave-v2.webp');
  background-position: 0 0;
  background-size: 200% 200%;
}

.jm-mascot[data-state="idle"] .jm-mascot__launcher {
  animation: jm-mascot-breathe 5s ease-in-out infinite;
}

.jm-mascot[data-state="wave"] .jm-mascot__sprite {
  animation: jm-mascot-wave 1.6s steps(1, end) 1;
}

.jm-mascot[data-state="wave"] .jm-mascot__launcher {
  animation: jm-mascot-salute 1.6s ease-in-out 1;
}

.jm-mascot[data-state="work"] .jm-mascot__launcher {
  animation: jm-mascot-review 2.5s ease-in-out 1;
}

.jm-mascot[data-state="success"] .jm-mascot__launcher {
  animation: jm-mascot-ready 1s ease-in-out 1;
}

/* Alternate names restart link previews without forcing layout. */
.jm-mascot[data-state="wave"][data-take="1"] .jm-mascot__sprite {
  animation-name: jm-mascot-wave-repeat;
}
.jm-mascot[data-state="wave"][data-take="1"] .jm-mascot__launcher {
  animation-name: jm-mascot-salute-repeat;
}
.jm-mascot[data-state="work"][data-take="1"] .jm-mascot__launcher {
  animation-name: jm-mascot-review-repeat;
}
.jm-mascot[data-state="success"][data-take="1"] .jm-mascot__launcher {
  animation-name: jm-mascot-ready-repeat;
}

.jm-mascot__hello {
  position: absolute;
  right: 78%;
  top: 4px;
  padding: 5px 9px;
  border: 1px solid rgba(16, 35, 43, 0.12);
  border-radius: 999px;
  color: #10232b;
  background: rgba(255, 254, 250, 0.96);
  box-shadow: 0 8px 22px rgba(16, 35, 43, 0.1);
  font: 700 0.66rem/1.2 Manrope, Arial, sans-serif;
  white-space: nowrap;
  opacity: 0;
  transform: translate(5px, 5px) scale(0.94);
  pointer-events: none;
  transition: opacity 160ms ease, transform 200ms ease;
}

.jm-mascot[data-state="wave"] .jm-mascot__hello {
  opacity: 1;
  transform: translate(0, 0) scale(1);
}

.jm-mascot-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  z-index: 70;
  width: min(336px, calc(100vw - 32px));
  max-height: min(520px, calc(100dvh - 154px - var(--jm-header-clearance, 92px) - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  overflow: auto;
  overscroll-behavior: contain;
  padding: 17px;
  border: 1px solid rgba(16, 35, 43, 0.14);
  border-radius: 22px 22px 44px 22px;
  color: #10232b;
  background: rgba(255, 254, 250, 0.98);
  box-shadow: 0 20px 56px rgba(16, 35, 43, 0.18);
  backdrop-filter: blur(16px);
  pointer-events: auto;
  transform-origin: right bottom;
  animation: jm-mascot-panel-in 190ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.jm-mascot-panel__top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 62px 44px;
  align-items: start;
  gap: 9px;
}

.jm-mascot-panel__copy h2 {
  margin: 0;
  color: #10232b;
  font-size: 1.12rem;
  line-height: 1.17;
  letter-spacing: -0.035em;
}

.jm-mascot-panel__copy p {
  margin: 7px 0 0;
  color: #52656d;
  font-size: 0.78rem;
  line-height: 1.45;
}

.jm-mascot-panel__pose {
  display: block;
  width: 62px;
  height: calc(62px * 576 / 448);
  filter: drop-shadow(0 7px 10px rgba(16, 35, 43, 0.12));
}

.jm-mascot-panel__close {
  display: inline-grid;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid rgba(16, 35, 43, 0.14);
  border-radius: 50%;
  place-items: center;
  color: #10232b;
  background: transparent;
  cursor: pointer;
  font: 500 1.05rem/1 Manrope, Arial, sans-serif;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.jm-mascot-panel__close:hover,
.jm-mascot-panel__close:focus-visible {
  color: #3655d8;
  border-color: rgba(54, 85, 216, 0.35);
  background: rgba(54, 85, 216, 0.05);
}

.jm-mascot-panel__close:focus-visible,
.jm-mascot-panel__link:focus-visible,
.jm-mascot-panel__control:focus-visible,
.jm-mascot-restore:focus-visible {
  outline: 3px solid rgba(54, 85, 216, 0.72);
  outline-offset: 3px;
}

.jm-mascot-panel__links {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.jm-mascot-panel__status {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  border: 0;
  white-space: nowrap;
}

.jm-mascot-panel__link {
  display: flex;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid rgba(16, 35, 43, 0.1);
  border-radius: 13px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: #10232b;
  background: #f6f4ee;
  font: 650 0.78rem/1.3 Manrope, Arial, sans-serif;
  text-decoration: none;
  transition: color 170ms ease, border-color 170ms ease, background-color 170ms ease, transform 170ms ease;
}

.jm-mascot-panel__link::after {
  color: #3655d8;
  content: '↗';
  font-size: 0.9rem;
}

.jm-mascot-panel__link:hover,
.jm-mascot-panel__link:focus-visible {
  color: #3655d8;
  border-color: rgba(54, 85, 216, 0.24);
  background: #fffefa;
  transform: translateX(2px);
}

.jm-mascot-panel__link--whatsapp {
  color: #fff;
  border-color: #137a45;
  background: #137a45;
}

.jm-mascot-panel__link--whatsapp::after,
.jm-mascot-panel__link--whatsapp:hover,
.jm-mascot-panel__link--whatsapp:focus-visible {
  color: #fff;
}

.jm-mascot-panel__link--whatsapp:hover,
.jm-mascot-panel__link--whatsapp:focus-visible {
  border-color: #0d6538;
  background: #0d6538;
}

.jm-mascot-panel__controls {
  display: flex;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(16, 35, 43, 0.1);
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.jm-mascot-panel__control {
  min-height: 44px;
  padding: 4px 6px;
  border: 0;
  color: #52656d;
  background: transparent;
  cursor: pointer;
  font: 600 0.64rem/1.3 Manrope, Arial, sans-serif;
  text-decoration: underline;
  text-decoration-color: rgba(82, 101, 109, 0.35);
  text-underline-offset: 3px;
}

.jm-mascot-panel__control:hover {
  color: #3655d8;
}

.jm-mascot-restore {
  display: inline-flex;
  min-height: 44px;
  margin-top: 14px;
  padding: 5px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  align-items: center;
  gap: 7px;
  color: #afc1c8;
  background: transparent;
  cursor: pointer;
  font: 600 0.62rem/1.2 Manrope, Arial, sans-serif;
  transition: color 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.jm-mascot-restore:hover {
  color: #fff;
  border-color: rgba(55, 201, 202, 0.45);
  background: rgba(255, 255, 255, 0.04);
}

body.jm-mascot-ready:not(.jm-mascot-hidden):not(.jm-mascot-suspended) .whatsapp-fab {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transform: translateY(10px) !important;
}

.jm-mascot[data-state="suspended"],
body.menu-open .jm-mascot {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* An active form/menu must not be covered by either floating control. */
body.jm-mascot-field-focus .whatsapp-fab,
body.menu-open .whatsapp-fab {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.jm-mascot[data-state="paused"],
.jm-mascot[data-state="paused"] *,
.jm-mascot[data-state="suspended"],
.jm-mascot[data-state="suspended"] * {
  animation: none !important;
  transition: none !important;
}

@keyframes jm-mascot-breathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-1.5px); }
}

@keyframes jm-mascot-salute {
  0%, 100% { transform: translateY(0) rotate(0); }
  35% { transform: translateY(-3px) rotate(-1.2deg); }
  68% { transform: translateY(-1px) rotate(0.8deg); }
}

@keyframes jm-mascot-wave {
  0%, 12%, 100% { background-position: 0 0; }
  25%, 88% { background-position: 100% 0; }
  42%, 76% { background-position: 0 100%; }
  60% { background-position: 100% 100%; }
}

@keyframes jm-mascot-review {
  0%, 100% { transform: rotate(0); }
  45% { transform: rotate(-1deg) translateY(-1px); }
  70% { transform: rotate(.5deg); }
}

@keyframes jm-mascot-ready {
  0%, 100% { transform: translateY(0); }
  35% { transform: translateY(-4px); }
  65% { transform: translateY(-1px); }
}

@keyframes jm-mascot-wave-repeat {
  0%, 12%, 100% { background-position: 0 0; }
  25%, 88% { background-position: 100% 0; }
  42%, 76% { background-position: 0 100%; }
  60% { background-position: 100% 100%; }
}

@keyframes jm-mascot-salute-repeat {
  0%, 100% { transform: translateY(0) rotate(0); }
  35% { transform: translateY(-3px) rotate(-1.2deg); }
  68% { transform: translateY(-1px) rotate(.8deg); }
}

@keyframes jm-mascot-review-repeat {
  0%, 100% { transform: rotate(0); }
  45% { transform: rotate(-1deg) translateY(-1px); }
  70% { transform: rotate(.5deg); }
}

@keyframes jm-mascot-ready-repeat {
  0%, 100% { transform: translateY(0); }
  35% { transform: translateY(-4px); }
  65% { transform: translateY(-1px); }
}

@keyframes jm-mascot-panel-in {
  from { opacity: 0; transform: translateY(7px) scale(0.975); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 650px) {
  .jm-mascot {
    --jm-width: 64px;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(11px, env(safe-area-inset-bottom));
  }

  .jm-mascot__hello {
    right: 73%;
    top: -4px;
    font-size: 0.59rem;
  }

  .jm-mascot-panel {
    right: 0;
    width: min(328px, calc(100vw - 40px - env(safe-area-inset-left) - env(safe-area-inset-right)));
    max-height: min(520px, calc(100dvh - 108px - var(--jm-header-clearance, 84px) - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
    padding: 15px;
    overflow: auto;
    overscroll-behavior: contain;
  }
}

@media (prefers-reduced-motion: reduce) {
  .jm-mascot,
  .jm-mascot *,
  .jm-mascot-restore {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
