/*
  SafeSteps Mascot (plug-and-play)
  This file is intentionally separate from styles.css so it can be replaced later.
*/

#mascotHost {
  position: fixed;
  left: clamp(12px, calc(50vw + 360px), calc(100vw - 182px));
  bottom: 16px;
  right: auto;
  z-index: 11000;
  pointer-events: none;
  --ss-move-speed: 0.7s;
  transition: left var(--ss-move-speed) ease, top var(--ss-move-speed) ease, bottom var(--ss-move-speed) ease, transform 0.35s ease;
}

#mascotHost.pos-0 { left: clamp(12px, calc(50vw + 360px), calc(100vw - 182px)); bottom: 20px; top: auto; right: auto; }
#mascotHost.pos-1 { left: clamp(8px, calc(50vw - 460px), calc(100vw - 182px)); bottom: 28px; top: auto; right: auto; }
#mascotHost.pos-2 { left: clamp(12px, calc(50vw + 340px), calc(100vw - 182px)); top: 210px; bottom: auto; right: auto; }
#mascotHost.pos-3 { left: clamp(8px, calc(50vw - 450px), calc(100vw - 182px)); top: 228px; bottom: auto; right: auto; }
#mascotHost.pos-4 { left: clamp(12px, calc(50vw + 350px), calc(100vw - 182px)); bottom: 112px; top: auto; right: auto; }

#mascotHost.pos-0 .ss-mascot-wrap { transform: scale(1); }
#mascotHost.pos-1 .ss-mascot-wrap { transform: scale(0.97); }
#mascotHost.pos-2 .ss-mascot-wrap { transform: scale(0.95); }
#mascotHost.pos-3 .ss-mascot-wrap { transform: scale(0.98); }
#mascotHost.pos-4 .ss-mascot-wrap { transform: scale(1.04); }

#mascotHost.pos-1 .ss-speech,
#mascotHost.pos-3 .ss-speech {
  right: auto;
  left: 126px;
}

#mascotHost.pos-1 .ss-speech::after,
#mascotHost.pos-3 .ss-speech::after {
  right: auto;
  left: -10px;
  border-right: none;
  border-bottom: none;
  border-left: 2px solid #d9e2ec;
  border-top: 2px solid #d9e2ec;
}

.ss-mascot-wrap {
  width: 170px;
  height: 210px;
  perspective: 900px;
  filter: drop-shadow(0 16px 20px rgba(0, 0, 0, 0.2));
  pointer-events: auto;
  cursor: pointer;
  touch-action: none;
  --ss-float-speed: 3.1s;
}

.ss-mascot {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  animation: ss-idle-float var(--ss-float-speed) ease-in-out infinite;
}

.ss-shadow {
  position: absolute;
  width: 88px;
  height: 20px;
  left: 40px;
  bottom: 4px;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.25), rgba(0, 0, 0, 0));
  animation: ss-shadow-breathe var(--ss-float-speed) ease-in-out infinite;
}

.ss-body {
  position: absolute;
  left: 28px;
  bottom: 28px;
  width: 112px;
  height: 120px;
  border-radius: 50% 50% 42% 42%;
  background: linear-gradient(160deg, #ffef8e, #ff9f74);
  border: 4px solid #ffffff;
  transform: translateZ(18px);
}

.ss-cape {
  position: absolute;
  left: -6px;
  top: 28px;
  width: 124px;
  height: 86px;
  border-radius: 46% 54% 38% 62%;
  background: linear-gradient(160deg, rgba(75, 36, 168, 0.95), rgba(54, 119, 201, 0.95));
  transform: translateZ(8px) rotate(-8deg);
  clip-path: polygon(12% 0%, 90% 10%, 98% 58%, 65% 92%, 18% 84%, 0% 42%);
  z-index: -1;
  animation: ss-cape-wave 2.6s ease-in-out infinite;
}

.ss-face {
  position: absolute;
  left: 23px;
  top: 30px;
  width: 66px;
  height: 54px;
  border-radius: 28px;
  background: #fff8e9;
}

.ss-eye {
  position: absolute;
  top: 17px;
  width: 10px;
  height: 12px;
  background: #27374a;
  border-radius: 50%;
  animation: ss-blink 4.4s infinite;
}

.ss-eye.left { left: 18px; }
.ss-eye.right { right: 18px; }

.ss-mouth {
  position: absolute;
  left: 27px;
  top: 35px;
  width: 14px;
  height: 8px;
  border-bottom: 3px solid #b54747;
  border-radius: 0 0 10px 10px;
}

.ss-mascot-wrap.expr-happy .ss-mouth {
  border-bottom-color: #1f9d55;
  width: 16px;
  left: 26px;
}

.ss-mascot-wrap.expr-sad .ss-mouth {
  border-bottom: none;
  border-top: 3px solid #b54747;
  border-radius: 10px 10px 0 0;
  top: 39px;
}

.ss-mascot-wrap.expr-think .ss-eye.left {
  transform: translateY(1px) scaleY(0.75);
}

.ss-mascot-wrap.expr-think .ss-eye.right {
  transform: translateY(-1px) scaleY(0.75);
}

.ss-mascot-wrap.expr-wow .ss-mouth {
  width: 10px;
  height: 10px;
  left: 29px;
  top: 34px;
  border: 2px solid #b54747;
  border-radius: 50%;
  background: transparent;
}

.ss-ear {
  position: absolute;
  width: 30px;
  height: 34px;
  border-radius: 50% 50% 46% 46%;
  background: linear-gradient(180deg, #ffd77c, #ffb56a);
  border: 3px solid #fff;
}

.ss-ear.left {
  left: -6px;
  top: -10px;
  transform: rotate(-20deg) translateZ(10px);
}

.ss-ear.right {
  right: -6px;
  top: -10px;
  transform: rotate(20deg) translateZ(10px);
}

.ss-arm {
  position: absolute;
  width: 24px;
  height: 56px;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffd27a, #f29b63);
  border: 3px solid #fff;
  top: 52px;
}

.ss-arm.left {
  left: -14px;
  transform-origin: top center;
  animation: ss-arm-wave 2.6s ease-in-out infinite;
}

.ss-arm.right {
  right: -14px;
  transform: rotate(-10deg);
}

.ss-leg {
  position: absolute;
  width: 26px;
  height: 34px;
  border-radius: 14px;
  background: linear-gradient(180deg, #ffc569, #ed8c5d);
  border: 3px solid #fff;
  bottom: -18px;
}

.ss-leg.left { left: 24px; }
.ss-leg.right { right: 24px; }

.ss-badge {
  position: absolute;
  right: 12px;
  top: 14px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #2f6ea8;
  border: 3px solid #fff;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.ss-speech {
  position: absolute;
  right: 124px;
  top: 0;
  min-width: 140px;
  max-width: 220px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #ffffff;
  border: 2px solid #d9e2ec;
  color: #243447;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
  transform-origin: bottom right;
  animation: ss-bubble-in 0.25s ease;
}

.ss-speech::after {
  content: "";
  position: absolute;
  right: -10px;
  top: 24px;
  width: 12px;
  height: 12px;
  background: #fff;
  border-right: 2px solid #d9e2ec;
  border-bottom: 2px solid #d9e2ec;
  transform: rotate(-45deg);
}

.ss-mascot.celebrate {
  animation: ss-celebrate 0.85s ease;
}

.ss-mascot.oops {
  animation: ss-oops 0.6s ease;
}

.ss-mascot.levelup {
  animation: ss-levelup 1s ease;
}

.ss-mascot.poke {
  animation: ss-poke 0.65s ease;
}

.ss-mascot-wrap.pose-stand .ss-body {
  transform: translateZ(18px) translateY(0);
}

.ss-mascot-wrap.pose-sit .ss-body {
  transform: translateZ(18px) translateY(10px) scaleY(0.93);
}

.ss-mascot-wrap.pose-sit .ss-leg {
  transform: scaleY(0.72);
}

.ss-mascot-wrap.pose-peek .ss-body {
  transform: translateZ(18px) rotateY(16deg);
}

.ss-mascot-wrap.pose-proud .ss-body {
  transform: translateZ(18px) scale(1.04);
}

.ss-mascot-wrap.pose-proud .ss-arm.left {
  transform: rotate(-25deg);
}

.ss-mascot-wrap.pose-hero .ss-body {
  transform: translateZ(20px) translateY(-4px);
}

.ss-mascot-wrap.pose-hero .ss-arm.right {
  transform: rotate(-40deg);
}

#mascotHost.ss-fly-pass .ss-mascot {
  animation-name: ss-fly-dash;
  animation-duration: 1.15s;
}

#mascotHost.ss-fly-pass .ss-cape {
  animation-duration: 0.5s;
}

#mascotHost.dragging .ss-mascot-wrap {
  transform: scale(1.03);
}

@keyframes ss-idle-float {
  0%, 100% { transform: translateY(0) rotateY(-7deg); }
  50% { transform: translateY(-7px) rotateY(7deg); }
}

@keyframes ss-shadow-breathe {
  0%, 100% { transform: scaleX(0.98); opacity: 0.8; }
  50% { transform: scaleX(1.06); opacity: 0.55; }
}

@keyframes ss-arm-wave {
  0%, 100% { transform: rotate(18deg); }
  50% { transform: rotate(-18deg); }
}

@keyframes ss-cape-wave {
  0%, 100% { transform: translateZ(8px) rotate(-8deg); }
  50% { transform: translateZ(8px) rotate(-15deg) translateY(2px); }
}

@keyframes ss-blink {
  0%, 44%, 48%, 100% { transform: scaleY(1); }
  46% { transform: scaleY(0.15); }
}

@keyframes ss-bubble-in {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes ss-fly-dash {
  0% { transform: translateX(0) translateY(0) rotate(-6deg) scale(1); }
  50% { transform: translateX(12px) translateY(-18px) rotate(6deg) scale(1.05); }
  100% { transform: translateX(0) translateY(0) rotate(-2deg) scale(1); }
}

@keyframes ss-celebrate {
  0% { transform: translateY(0) scale(1) rotateZ(0deg); }
  35% { transform: translateY(-12px) scale(1.1) rotateZ(-5deg); }
  70% { transform: translateY(-6px) scale(1.06) rotateZ(5deg); }
  100% { transform: translateY(0) scale(1) rotateZ(0deg); }
}

@keyframes ss-oops {
  0% { transform: translateX(0); }
  25% { transform: translateX(-8px) rotateZ(-4deg); }
  50% { transform: translateX(8px) rotateZ(4deg); }
  100% { transform: translateX(0); }
}

@keyframes ss-levelup {
  0% { transform: scale(1) rotateY(0deg); }
  50% { transform: scale(1.18) rotateY(180deg); }
  100% { transform: scale(1) rotateY(360deg); }
}

@keyframes ss-poke {
  0% { transform: translateX(0) rotateZ(0deg) scale(1); }
  20% { transform: translateX(-14px) rotateZ(-8deg) scale(0.98); }
  45% { transform: translateX(12px) rotateZ(7deg) scale(1.02); }
  70% { transform: translateX(-8px) rotateZ(-4deg); }
  100% { transform: translateX(0) rotateZ(0deg) scale(1); }
}

@media (max-width: 760px) {
  #mascotHost {
    right: 8px;
    bottom: 8px;
  }

  #mascotHost.pos-0,
  #mascotHost.pos-1,
  #mascotHost.pos-2,
  #mascotHost.pos-3,
  #mascotHost.pos-4 {
    right: 6px;
    left: auto;
    top: auto;
    bottom: 8px;
  }

  .ss-mascot-wrap {
    width: 132px;
    height: 168px;
  }

  .ss-speech {
    right: 98px;
    min-width: 104px;
    font-size: 12px;
    padding: 8px 10px;
  }
}

#mascotHost.theme-behavioural .ss-body {
  background: linear-gradient(160deg, #c8f0b7, #78d0a8);
}

#mascotHost.theme-behavioural .ss-cape {
  background: linear-gradient(160deg, rgba(34, 125, 86, 0.95), rgba(53, 155, 116, 0.95));
}

#mascotHost.theme-ai .ss-body {
  background: linear-gradient(160deg, #d8d9ff, #8fb2ff);
}

#mascotHost.theme-ai .ss-cape {
  background: linear-gradient(160deg, rgba(71, 73, 170, 0.95), rgba(90, 140, 225, 0.95));
}

.ss-chat-panel {
  position: absolute;
  right: 124px;
  bottom: 0;
  width: min(310px, calc(100vw - 34px));
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid #d5e1ee;
  border-radius: 12px;
  box-shadow: 0 10px 20px rgba(17, 37, 58, 0.16);
  display: none;
  pointer-events: auto;
  text-align: left;
}

.ss-chat-panel.open {
  display: block;
}

.ss-chat-head {
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
  color: #28537c;
  border-bottom: 1px solid #e1e9f2;
  background: linear-gradient(90deg, #eff6ff, #f8fbff);
  border-radius: 12px 12px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ss-chat-close {
  width: 22px;
  height: 22px;
  border: 1px solid #c8d9ea;
  border-radius: 6px;
  background: #ffffff;
  color: #325d85;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.ss-chat-close:hover {
  background: #eef6ff;
}

.ss-chat-body {
  padding: 8px;
}

.ss-chat-output {
  min-height: 56px;
  max-height: 128px;
  overflow-y: auto;
  font-size: 12px;
  line-height: 1.35;
  color: #23384d;
  border: 1px solid #dbe5f0;
  border-radius: 8px;
  background: #f8fbff;
  padding: 8px;
  margin-bottom: 7px;
}

.ss-chat-output.error {
  color: #a73c3c;
  background: #fff4f4;
  border-color: #efcece;
}

.ss-chat-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.ss-chat-input {
  height: 32px;
  border: 1px solid #cfdde9;
  border-radius: 8px;
  padding: 0 8px;
  font-size: 12px;
}

.ss-chat-send {
  height: 32px;
  border: 1px solid #3f75a7;
  border-radius: 8px;
  padding: 0 10px;
  background: #2f6ea8;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

#mascotHost.pos-1 .ss-chat-panel,
#mascotHost.pos-3 .ss-chat-panel {
  left: 126px;
  right: auto;
}
