/* ===== Маскот «Матвей» ===== */
.matvey {
  position: fixed;
  left: 24px;
  bottom: 24px;
  z-index: 999;
  font-family: "Manrope", sans-serif;
  user-select: none;
  -webkit-user-select: none;
}
.matvey.dragging { z-index: 1001; }

/* Сам маскот — без кружка, свободно перемещается */
.matvey-avatar {
  display: block;
  position: relative;
  aspect-ratio: 1;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: grab;
  width: 168px;
  filter: drop-shadow(0 12px 18px rgba(29, 58, 95, .25));
  transition: filter .25s ease;
  animation: matvey-breathe 3.2s ease-in-out infinite;
  touch-action: none;
}
.matvey-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
  opacity: 0;
  transition: opacity .45s ease;
}
.matvey-avatar img.on { opacity: 1; }

/* Машет рукой — плавное покачивание */
.matvey-avatar.waving {
  transform-origin: 50% 100%;
  animation: matvey-wave-sway 1.6s ease-in-out infinite;
}
@keyframes matvey-wave-sway {
  0%, 100% { transform: rotate(-3deg) translateY(0); }
  30% { transform: rotate(3deg) translateY(-6px); }
  60% { transform: rotate(-2deg) translateY(-3px); }
}

/* Указывает на блок — лёгкий наклон в сторону */
.matvey-avatar.pointing {
  transform-origin: 50% 100%;
  animation: matvey-point-lean 2.4s ease-in-out infinite;
}
@keyframes matvey-point-lean {
  0%, 100% { transform: rotate(0deg) translateX(0); }
  50% { transform: rotate(2deg) translateX(6px); }
}
.matvey-avatar:hover { filter: drop-shadow(0 16px 24px rgba(29, 58, 95, .32)); }
.matvey-avatar:active { cursor: grabbing; animation-play-state: paused; }
@keyframes matvey-breathe {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-8px) rotate(-1.2deg); }
}

/* Облачко с текстом */
.matvey-bubble {
  position: absolute;
  bottom: calc(100% + 14px);
  left: 0;
  width: min(300px, calc(100vw - 48px));
  background: #ffffff;
  border: 1px solid #dbe9f3;
  border-radius: 16px;
  box-shadow: 0 10px 34px rgba(36, 78, 125, .14);
  padding: 14px 16px 13px;
  opacity: 0;
  transform: translateY(12px) scale(.96);
  transform-origin: bottom left;
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
}
.matvey-bubble::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 60px;
  width: 16px;
  height: 16px;
  background: #ffffff;
  border-right: 1px solid #dbe9f3;
  border-bottom: 1px solid #dbe9f3;
  transform: rotate(45deg);
}
.matvey-bubble.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
/* Если Матвей у правого края и облачку тесно — не выходит за экран */
.matvey-bubble { max-width: calc(100vw - 32px); }

.matvey-bubble-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.matvey-bubble-name {
  font-family: "Neucha", cursive;
  font-size: 22px;
  color: #245a8d;
  flex: 1;
}
.matvey-close {
  border: 0;
  background: transparent;
  color: #5e7488;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}
.matvey-close:hover { color: #1d3a5f; background: #f5fafe; }
.matvey-bubble-text {
  font-size: 14px;
  line-height: 1.6;
  color: #1d3a5f;
  white-space: pre-line;
  margin: 0 0 14px;
}
.matvey-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.matvey-btn {
  border: 1px solid #dbe9f3;
  background: #f5fafe;
  color: #245a8d;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s ease, transform .2s ease;
}
.matvey-btn:hover { background: #eaf5fc; transform: translateY(-1px); }
.matvey-btn.primary {
  background: #245a8d;
  border-color: #245a8d;
  color: #ffffff;
  box-shadow: 0 8px 20px rgba(36, 90, 141, .22);
}
.matvey-btn.primary:hover { background: #5b8db8; border-color: #5b8db8; }

.matvey-highlight {
  outline: 3px solid #7ec3ea;
  outline-offset: 6px;
  border-radius: 16px;
  animation: matvey-pulse 1.8s ease-in-out infinite;
}
@keyframes matvey-pulse {
  0%, 100% { outline-color: #7ec3ea; }
  50% { outline-color: #d3e9f7; }
}

/* Плашка «вернуть Матвея» */
.matvey-restore {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 8px;
  border-radius: 999px;
  border: 1px solid #dbe9f3;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 8px 22px rgba(36, 78, 125, .18);
  color: #245a8d;
  font-family: "Manrope", sans-serif;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .3s ease, transform .3s ease;
}
.matvey-restore img { width: 34px; height: 34px; object-fit: contain; }
.matvey-restore.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.matvey-restore:hover { background: #eaf5fc; }

@media (max-width: 640px) {
  /* Мобильная версия: Матвей живёт в собственной нижней панели и не перекрывает текст */
  body { padding-bottom: 86px; }
  .matvey {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px calc(8px + env(safe-area-inset-bottom, 0px));
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid #dbe9f3;
    box-shadow: 0 -6px 20px rgba(36, 78, 125, .10);
  }
  .matvey-avatar { width: 60px; flex: 0 0 auto; animation: matvey-breathe 3.2s ease-in-out infinite; }
  .matvey-hint {
    position: static;
    animation: none;
    white-space: normal;
    font-size: 12px;
    padding: 6px 12px;
  }
  .matvey-hint::after { display: none; }
  .matvey-hint.gone { display: none; }
  .matvey-hide { top: -8px; right: -4px; opacity: 1; }
  /* Облачко открывается над панелью во всю ширину */
  .matvey-bubble {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: calc(100% + 10px);
    transform-origin: bottom left;
  }
}

/* Подсказка «Нажми на меня!» */
.matvey-hint {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  background: #ffffff;
  border: 1px solid #dbe9f3;
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(36, 78, 125, .16);
  color: #245a8d;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 16px;
  white-space: nowrap;
  pointer-events: none;
  animation: matvey-hint-bob 2s ease-in-out infinite;
}
.matvey-hint::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 34px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-right: 1px solid #dbe9f3;
  border-bottom: 1px solid #dbe9f3;
  transform: rotate(45deg);
}
.matvey-hint.gone { display: none; }
@keyframes matvey-hint-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* Крестик «скрыть Матвея» */
.matvey-hide {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  background: #8fb8d8;
  color: #ffffff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(36, 78, 125, .3);
  opacity: .65;
  transition: opacity .2s ease, background .2s ease;
  z-index: 2;
}
.matvey:hover .matvey-hide,
.matvey-hide:focus-visible { opacity: 1; }
.matvey-hide:hover { background: #245a8d; }

/* Скрытый Матвей */
.matvey.gone { display: none; }

/* Свой композитный слой — убирает артефакты отрисовки поверх анимированных секций */
.matvey {
  transform: translateZ(0);
  backface-visibility: hidden;
}
