/* Sida companion — soft notebook mascot (v4) */

.yysd-mascot {
  --sida-blue-top: #6ec8e8;
  --sida-blue-bot: #4ab5d8;
  --sida-pink: #ffb4a2;
  --sida-paper: #f7f3ea;
  --sida-feature: #4a6275;
  --sida-glow: #ffcdbf;
  position: fixed;
  z-index: 9000;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  pointer-events: none;
  max-width: min(320px, calc(100vw - 32px));
  transition: transform .35s cubic-bezier(.16,1,.3,1), opacity .3s;
}
.yysd-mascot.is-hidden { opacity: 0; pointer-events: none; transform: translateY(12px) scale(.96); }
.yysd-mascot.is-ceremony {
  opacity: 0;
  transform: translate(80px, 24px) scale(.88);
  animation: sida-ceremony-in .75s cubic-bezier(.16,1,.3,1) forwards;
}
.yysd-mascot.is-ceremony .yysd-mascot__bubble { animation: sida-ceremony-bubble .55s cubic-bezier(.16,1,.3,1) .35s both; }
.yysd-mascot.is-minimized .yysd-mascot__bubble { display: none; }

.yysd-mascot:not(.is-bubble-open) .yysd-mascot__figure::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #ffb4a2;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(255, 180, 162, .55);
  animation: sida-ping 2.4s ease-in-out infinite;
}
.yysd-mascot.is-bubble-open .yysd-mascot__figure::after { display: none; }

.yysd-mascot__bubble {
  pointer-events: auto;
  position: relative;
  background: #fff;
  border: 1px solid rgba(74, 98, 117, .12);
  border-radius: 18px 18px 6px 18px;
  padding: 12px 38px 12px 14px;
  box-shadow: 0 10px 32px -12px rgba(7, 25, 47, .22), 0 0 0 1px rgba(255,255,255,.8) inset;
  font-size: .9rem;
  line-height: 1.5;
  color: var(--text, #101827);
  animation: sida-bubble-in .4s cubic-bezier(.16,1,.3,1) both;
}
.yysd-mascot__bubble[hidden] { display: none; }
.yysd-mascot__bubble b { display: block; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: #4ab5d8; margin-bottom: 2px; }
.yysd-mascot__head { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.yysd-mascot__head b { margin: 0; }
.yysd-mascot__streak {
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: #e07a5f;
  background: #fff5f0;
  border: 1px solid rgba(255, 180, 162, .45);
  border-radius: 999px;
  padding: 1px 7px;
  line-height: 1.35;
}
.yysd-mascot__bubble p { margin: 0; }
.yysd-mascot__next {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 8px 12px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #6ec8e8, #4ab5d8);
  color: #fff;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
}
.yysd-mascot__next:hover { filter: brightness(1.05); }
.yysd-mascot.is-onboarding .yysd-mascot__min,
.yysd-mascot.is-onboarding .yysd-mascot__close { display: none; }
.yysd-mascot__close,
.yysd-mascot__min {
  position: absolute;
  top: 6px;
  border: none;
  background: transparent;
  color: #9a927f;
  cursor: pointer;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}
.yysd-mascot__close { right: 4px; }
.yysd-mascot__min { right: 28px; font-size: .85rem; }
.yysd-mascot__close:hover,
.yysd-mascot__min:hover { background: #f6f3ec; color: #4a6275; }

.yysd-mascot__figure {
  pointer-events: auto;
  position: relative;
  width: 96px;
  height: 110px;
  cursor: pointer;
  transform-origin: bottom center;
  transition: transform .25s cubic-bezier(.16,1,.3,1);
  filter: drop-shadow(0 8px 18px rgba(74, 181, 216, .28));
  border: none;
  padding: 0;
  background: transparent;
  animation: sida-idle 3.2s ease-in-out infinite;
}
.yysd-mascot__figure:focus-visible { outline: 2px solid #6ec8e8; outline-offset: 4px; border-radius: 12px; }
.yysd-mascot__figure .sida-v4 { width: 100%; height: auto; display: block; }

/* --- Expression layers (3 faces; legacy states map here) --- */
.sida-v4 .sida-expr { display: none; }
.yysd-mascot[data-state="default"] .sida-expr--default,
.yysd-mascot:not([data-state]) .sida-expr--default,
.yysd-mascot[data-state="wave"] .sida-expr--default,
.yysd-mascot[data-state="think"] .sida-expr--default { display: block; }
.yysd-mascot[data-state="happy"] .sida-expr--happy,
.yysd-mascot[data-state="celebrate"] .sida-expr--happy { display: block; }
.yysd-mascot[data-state="confused"] .sida-expr--comfort,
.yysd-mascot[data-state="panic"] .sida-expr--comfort { display: block; }

.yysd-mascot[data-state="default"]:not(.is-bubble-open):not(.is-tapped) .sida-note {
  transform-origin: 148px 56px;
  animation: sida-note-wiggle 2.8s ease-in-out infinite;
}
.yysd-mascot[data-state="default"]:not(.is-bubble-open):not(.is-tapped) .sida-pages {
  transform-origin: 150px 72px;
  animation: sida-pages-rustle 3.2s ease-in-out infinite;
}
.yysd-mascot[data-state="default"]:not(.is-bubble-open):not(.is-tapped) .sida-pupil-l,
.yysd-mascot[data-state="default"]:not(.is-bubble-open):not(.is-tapped) .sida-pupil-r {
  animation: sida-pupil-drift 5s ease-in-out infinite;
}
.yysd-mascot[data-state="default"] .sida-eye-wrap {
  animation: sida-blink 5.5s ease-in-out infinite;
  transform-origin: 100px 118px;
}
.yysd-mascot.is-speaking .sida-mouth,
.yysd-mascot.is-speaking .sida-mouth-line {
  animation: sida-talk .32s ease-in-out infinite alternate;
  transform-origin: 100px 135px;
}
.yysd-mascot[data-state="happy"] .sida-note,
.yysd-mascot[data-state="celebrate"] .sida-note {
  animation: sida-note-pop .55s ease-in-out 3;
  transform-origin: 148px 56px;
}
.yysd-mascot[data-state="confused"] .sida-note,
.yysd-mascot[data-state="panic"] .sida-note {
  animation: sida-note-tuck .8s ease-in-out 2;
  transform-origin: 148px 56px;
}

@keyframes sida-note-wiggle {
  0%, 100% { transform: rotate(10deg); }
  50% { transform: rotate(16deg) translateY(-1px); }
}
@keyframes sida-note-pop {
  0%, 100% { transform: rotate(10deg); }
  45% { transform: rotate(22deg) translateY(-3px); }
}
@keyframes sida-note-tuck {
  0%, 100% { transform: rotate(10deg); }
  50% { transform: rotate(4deg) translateY(2px); }
}
@keyframes sida-pages-rustle {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(2deg); }
}
@keyframes sida-pupil-drift {
  0%, 100% { transform: translate(0, 0); }
  40% { transform: translate(1.5px, 0); }
  70% { transform: translate(-1px, .5px); }
}
@keyframes sida-blink {
  0%, 88%, 100% { transform: scaleY(1); }
  92% { transform: scaleY(.06); }
}
@keyframes sida-talk {
  from { transform: scaleY(1); }
  to { transform: scaleY(1.15); }
}

/* State-driven body motion */
.yysd-mascot[data-state="celebrate"] .yysd-mascot__figure { animation: sida-celebrate .55s ease-in-out 3; }
.yysd-mascot[data-state="think"] .yysd-mascot__figure { animation: sida-think 2s ease-in-out infinite; }
.yysd-mascot[data-state="happy"] .yysd-mascot__figure { animation: sida-happy-bounce 1.4s ease-in-out 2; }
.yysd-mascot[data-state="confused"] .yysd-mascot__figure { animation: sida-confused-tilt 1.4s ease-in-out 2; }
.yysd-mascot[data-state="panic"] .yysd-mascot__figure { animation: sida-panic-shake .3s ease-in-out 5; }
.yysd-mascot[data-state="wave"] .yysd-mascot__figure { animation: sida-wave-body .5s ease-in-out 3; }

.yysd-mascot.is-tapped .yysd-mascot__figure {
  animation: sida-tap .36s cubic-bezier(.34, 1.4, .64, 1) both !important;
}

@keyframes sida-ping {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.12); opacity: .85; }
}
@keyframes sida-idle {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}
@keyframes sida-celebrate {
  0%, 100% { transform: translateY(0) scale(1); }
  40% { transform: translateY(-10px) scale(1.04) rotate(-2deg); }
}
@keyframes sida-think {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-3deg); }
}
@keyframes sida-happy-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  45% { transform: translateY(-8px) scale(1.03); }
}
@keyframes sida-confused-tilt {
  0%, 100% { transform: rotate(0deg); }
  35% { transform: rotate(-4deg); }
  70% { transform: rotate(3deg); }
}
@keyframes sida-panic-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
@keyframes sida-wave-body {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px) rotate(-2deg); }
}
@keyframes sida-tap {
  0% { transform: scale(1); }
  40% { transform: scale(.92) translateY(2px); }
  100% { transform: scale(1.04) translateY(-3px); }
}
@keyframes sida-bubble-in {
  from { opacity: 0; transform: translateY(8px) scale(.96); }
  to { opacity: 1; transform: none; }
}
@keyframes sida-ceremony-in {
  from { opacity: 0; transform: translate(80px, 24px) scale(.88); }
  to { opacity: 1; transform: none; }
}
@keyframes sida-ceremony-bubble {
  from { opacity: 0; transform: translateY(12px) scale(.94); }
  to { opacity: 1; transform: none; }
}

.yysd-mascot-restore {
  position: fixed;
  z-index: 8999;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  padding: 10px 14px;
  border: 1px solid rgba(74, 181, 216, .35);
  border-radius: 999px;
  background: #fff;
  color: #4ab5d8;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px -10px rgba(74, 181, 216, .45);
}
.yysd-mascot-restore:hover { background: #f0faff; }

@media (max-width: 987px) {
  body.has-mobile-tabs .yysd-mascot,
  body.has-mobile-tabs .yysd-mascot-restore {
    bottom: calc(58px + env(safe-area-inset-bottom, 0px) + 10px);
  }
}

@media (max-width: 640px) {
  .yysd-mascot {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    max-width: min(280px, calc(100vw - 20px));
  }
  body.has-mobile-tabs .yysd-mascot {
    bottom: calc(58px + env(safe-area-inset-bottom, 0px) + 10px);
  }
  .yysd-mascot__figure { width: 80px; height: 92px; }
  .yysd-mascot__bubble {
    font-size: .84rem;
    padding: 10px 34px 10px 12px;
    max-height: min(42vh, 220px);
    overflow-y: auto;
  }
  .yysd-mascot:not(.is-bubble-open) .yysd-mascot__figure::after {
    width: 9px;
    height: 9px;
    top: 0;
    right: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .yysd-mascot.is-ceremony { animation: none; opacity: 1; transform: none; }
  .yysd-mascot:not(.is-bubble-open) .yysd-mascot__figure::after { animation: none; }
  .yysd-mascot__figure,
  .yysd-mascot[data-state="celebrate"] .yysd-mascot__figure,
  .yysd-mascot[data-state="think"] .yysd-mascot__figure,
  .yysd-mascot[data-state="happy"] .yysd-mascot__figure,
  .yysd-mascot[data-state="confused"] .yysd-mascot__figure,
  .yysd-mascot[data-state="panic"] .yysd-mascot__figure,
  .yysd-mascot[data-state="wave"] .yysd-mascot__figure,
  .yysd-mascot.is-tapped .yysd-mascot__figure { animation: none; }
  .sida-note, .sida-pages, .sida-pupil-l, .sida-pupil-r, .sida-eye-wrap,
  .sida-mouth, .sida-mouth-line { animation: none !important; }
  .yysd-mascot__bubble { animation: none; }
}
