:root { --hamish-safe-bottom: env(safe-area-inset-bottom, 0px); }

.hamish-mascot {
  --hamish-x: 18px;
  --hamish-y: 18px;
  position: fixed;
  left: 0;
  top: 0;
  width: clamp(180px, 18vw, 250px);
  height: clamp(250px, 25vw, 340px);
  pointer-events: none;
  transform: translate3d(var(--hamish-x), var(--hamish-y), 0);
  will-change: transform;
  transition: opacity 180ms ease;
  contain: style;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.hamish-mascot[hidden] { display: none !important; }

.hamish-mascot__character {
  position: absolute;
  inset: auto 0 0 0;
  width: 100%;
  height: 78%;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  border-radius: 46% 46% 18% 18%;
  -webkit-tap-highlight-color: transparent;
  transform-origin: 50% 82%;
  transition: transform 120ms ease;
}

.hamish-mascot[data-direction="left"] .hamish-mascot__character { transform: scaleX(-1); }
.hamish-mascot[data-direction="right"] .hamish-mascot__character { transform: scaleX(1); }

.hamish-mascot__character:focus-visible {
  outline: 4px solid #ffd43b;
  outline-offset: 4px;
}

.hamish-mascot__art {
  display: block;
  position: absolute;
  inset: -18% -16% -8%;
  filter: drop-shadow(0 16px 16px rgba(10, 19, 33, .34));
  transform-origin: 50% 88%;
}

.hamish-mascot__frame {
  position: absolute;
  inset: 0;
  display: block;
  background-repeat: no-repeat;
  background-size: 400% 200%;
  background-position: 0 0;
  pointer-events: none;
  will-change: background-position;
}

.hamish-mascot__frame[hidden] { display: none; }

.hamish-mascot__rive {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.hamish-mascot__rive[hidden] { display: none; }

.hamish-mascot[data-state="idle"] .hamish-mascot__art {
  animation: hamish-breathe 3.2s ease-in-out infinite;
}

.hamish-mascot[data-state="walk"] .hamish-mascot__art,
.hamish-mascot[data-state="exit"] .hamish-mascot__art {
  animation: hamish-walk var(--hamish-walk-duration, .624s) linear infinite;
}

.hamish-mascot[data-speaking="true"]:not([data-state="walk"]):not([data-state="exit"]) .hamish-mascot__art {
  animation: hamish-talk .56s ease-in-out infinite alternate;
}

.hamish-mascot[data-state="attention"] .hamish-mascot__art,
.hamish-mascot[data-state="open-chat"] .hamish-mascot__art {
  animation: hamish-attention .8s ease-in-out 2;
}

.hamish-mascot__bubble {
  position: absolute;
  z-index: 2;
  right: 10%;
  bottom: 75%;
  width: min(310px, calc(100vw - 24px));
  min-width: 250px;
  padding: 18px;
  color: #102033;
  background: #fff;
  border: 2px solid #dce6ee;
  border-radius: 20px 20px 6px 20px;
  box-shadow: 0 18px 50px rgba(10, 25, 43, .24);
  pointer-events: auto;
  transform-origin: 88% 100%;
  animation: hamish-pop .22s cubic-bezier(.2,.9,.3,1.2) both;
}

.hamish-mascot__bubble::after {
  content: "";
  position: absolute;
  right: 14px;
  bottom: -12px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-right: 2px solid #dce6ee;
  border-bottom: 2px solid #dce6ee;
  transform: rotate(45deg);
}

.hamish-mascot__bubble[hidden] { display: none; }

.hamish-mascot__message {
  padding-right: 22px;
  font-size: 1rem;
  line-height: 1.45;
  font-weight: 650;
}

.hamish-mascot__close {
  position: absolute;
  top: 7px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #4c5b69;
  font: 600 24px/1 system-ui;
  cursor: pointer;
}

.hamish-mascot__close:hover { background: #edf3f7; }

.hamish-mascot__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.hamish-mascot__cta {
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid #b8c7d2;
  border-radius: 999px;
  color: #142d46;
  background: #fff;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
}

.hamish-mascot__cta.is-primary {
  border-color: #075caa;
  color: #fff;
  background: #075caa;
}

.hamish-mascot__cta:hover { filter: brightness(.94); }
.hamish-mascot__cta:focus-visible { outline: 3px solid #ffd43b; outline-offset: 2px; }

@keyframes hamish-breathe { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-4px) scale(1.012); } }
@keyframes hamish-walk {
  0%,100% { transform: translateY(0) rotate(-.7deg); }
  25% { transform: translateY(-5px) rotate(0); }
  50% { transform: translateY(0) rotate(.7deg); }
  75% { transform: translateY(-5px) rotate(0); }
}
@keyframes hamish-talk { from { transform: translateY(0) rotate(-.35deg); } to { transform: translateY(-3px) rotate(.35deg); } }
@keyframes hamish-attention { 0%,100% { transform: translateY(0) rotate(0); } 40% { transform: translateY(-9px) rotate(-2deg); } }
@keyframes hamish-pop { from { opacity: 0; transform: scale(.86) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

@media (max-width: 639px) {
  .hamish-mascot {
    width: 160px;
    height: 230px;
  }
  .hamish-mascot__bubble {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(175px + var(--hamish-safe-bottom));
    width: auto;
    min-width: 0;
    border-radius: 18px;
  }
  .hamish-mascot__bubble::after { right: 54px; }
}

@media (prefers-reduced-motion: reduce) {
  .hamish-mascot,
  .hamish-mascot__character,
  .hamish-mascot__art,
  .hamish-mascot__bubble {
    animation: none !important;
    transition-duration: 0ms !important;
    scroll-behavior: auto !important;
  }
}
