#mascot-game {
  --mit-figure: 139px;
  --mit-caption-line: 15px;
  position: fixed;
  inset: 0;
  z-index: 4;
  overflow: clip;
  pointer-events: none;
  color: #1a2029;
}
#mascot-game:not([data-loaded="true"]),
#mascot-game:not([data-placed="true"]),
#mascot-game[data-available="false"] { visibility: hidden; }
.mit-object {
  position: absolute;
  top: 0;
  left: 0;
  width: max-content;
  transition: transform var(--mit-travel, 0ms) cubic-bezier(.33,.1,.46,.99);
}
.mit-actor {
  width: max(146px, var(--mit-figure));
  /* Placement measures this box before the next caption appears. */
  height: calc(var(--mit-figure) + 2 * var(--mit-caption-line) + 10px);
  position: relative;
}
.mit-target {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: start;
  padding: 0;
  outline-offset: -3px;
  border-radius: 16px;
  color: #161c24;
  background: none;
  pointer-events: none;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.mit-target:focus-visible { outline: 3px solid #4771ee; }
.mit-figure {
  flex: none;
  width: var(--mit-figure);
  height: var(--mit-figure);
  position: relative;
  transform-origin: 50% 89%;
  pointer-events: auto;
  filter: drop-shadow(0 1px 1px #14233320);
}
.mit-sprite {
  display: block;
  width: 100%;
  height: 100%;
  background: url("/assets/mascot.webp") 0 0 / 400% 300% no-repeat;
}
.mit-gaze-head, .mit-gaze-origin { display: none; pointer-events: none; }

/* Each face uses its own neck outline and eye locations from the original sprite. */
#mascot-game[data-pose="idle"] {
  --face-position: 0 0;
  --face-cut: 24% 3%, 66% 3%, 67% 31%, 63% 35%, 61% 37%, 57% 38.8%, 53% 39.3%, 49% 38.8%, 45% 37.4%, 41.2% 34.1%, 35% 34%, 24% 29%;
  --neck-x: 51%; --neck-y: 38%;
  --eye-lx: 47.3%; --eye-ly: 22.2%; --eye-lw: 4.25%; --eye-lh: 3.8%;
  --eye-rx: 55.1%; --eye-ry: 19.8%; --eye-rw: 4.2%; --eye-rh: 3.4%;
}
#mascot-game[data-pose="sign"] {
  --face-position: 33.333333% 0;
  --face-cut: 24% 3%, 67% 3%, 67% 31%, 60% 34%, 57% 36.5%, 50% 36.5%, 45.5% 36.5%, 40% 35%, 38.2% 34%, 32% 32%, 24% 28%;
  --neck-x: 50%; --neck-y: 36.4%;
  --eye-lx: 44.5%; --eye-ly: 21.5%; --eye-lw: 4.2%; --eye-lh: 3.7%;
  --eye-rx: 52.5%; --eye-ry: 19.9%; --eye-rw: 4.1%; --eye-rh: 3.3%;
}
#mascot-game[data-pose="peek"] {
  --face-position: 0 50%;
  --face-cut: 16% 4%, 48% 4%, 48% 14%, 49% 17%, 50.7% 20.5%, 53% 24%, 54.8% 26.6%, 56% 30.3%, 56.4% 33%, 56.4% 37%, 55.2% 40%, 52.6% 42.1%, 49% 44%, 45% 44%, 41% 42.5%, 38.1% 40.5%, 35.4% 39%, 32.4% 39%, 29% 36%, 26% 34%, 22% 31%, 16% 31%;
  --neck-x: 46%; --neck-y: 42%;
  --eye-lx: 39.8%; --eye-ly: 27.9%; --eye-lw: 5.15%; --eye-lh: 5.3%;
  --eye-rx: 46.2%; --eye-ry: 22.7%; --eye-rw: 4.2%; --eye-rh: 4.6%;
}
@media (prefers-reduced-motion: no-preference) {
  #mascot-game:is([data-pose="idle"],[data-pose="sign"],[data-pose="peek"]) .mit-figure[data-looking] {
    .mit-sprite {
      clip-path: polygon(evenodd, 0 0, 100% 0, 100% 100%, 0 100%, 0 0, var(--face-cut), var(--face-start, 24% 3%), 0 0);
    }
    .mit-gaze-origin {
      display: block; position: absolute;
      left: calc((var(--eye-lx) + var(--eye-rx)) / 2);
      top: calc((var(--eye-ly) + var(--eye-ry)) / 2);
    }
    .mit-gaze-head {
      position: absolute; display: block; inset: 0;
      background: url("/assets/mascot.webp") var(--face-position) / 400% 300% no-repeat;
      clip-path: polygon(var(--face-cut));
      transform-origin: var(--neck-x) var(--neck-y);
      transition: transform 120ms ease-out;
      transform: translate(calc(var(--look-x, 0) * 1.05%), calc(var(--look-y, 0) * .65%))
        perspective(calc(var(--mit-figure) * 3)) rotateY(calc(var(--look-x, 0) * 15deg))
        rotateX(calc(var(--look-y, 0) * -10deg)) rotate(calc(var(--look-x, 0) * 4deg));
    }
    .mit-gaze-head::before, .mit-gaze-head::after {
      content: ""; display: block; position: absolute;
      left: var(--eye-lx); top: var(--eye-ly); width: var(--eye-lw); height: var(--eye-lh);
      transform: translate(-50%, -50%) rotate(-9deg); border-radius: 50%; overflow: hidden;
      --iris-x: calc(50% + var(--look-x, 0) * 20%);
      --iris-y: calc(50% + var(--look-y, 0) * 15%);
      background:
        radial-gradient(ellipse 8% 9% at calc(var(--iris-x) - 9%) calc(var(--iris-y) - 11%), #fff 63%, transparent 100%),
        radial-gradient(ellipse 27% 36% at var(--iris-x) var(--iris-y), #22150e 56%, #694126 73%, #4b2c1a 90%, transparent 100%),
        radial-gradient(ellipse at 48% 62%, #fff9e8 40%, #e7d6bf 85%, #b08c70 100%);
    }
    .mit-gaze-head::after { left: var(--eye-rx); top: var(--eye-ry); width: var(--eye-rw); height: var(--eye-rh); }
  }
}
#mascot-game[data-pose="peek"] { --face-start: 16% 4%; }
.mit-ground {
  position: absolute;
  width: 42%;
  height: 6px;
  top: calc(var(--mit-figure) * .905);
  border-radius: 50%;
  background: #28394740;
  filter: blur(2px);
}
.mit-board {
  display: none;
  position: absolute;
  left: 50.1%;
  top: 50.1%;
  transform: translate(-50%, -50%);
  color: #202c55;
  font: 900 calc(var(--mit-figure) * .095)/1 Arial, sans-serif;
  letter-spacing: -.025em;
}
#mascot-game[data-art="fallback"] .mit-sprite {
  display: grid;
  align-content: center;
  justify-content: center;
  background: #264ddc;
  border: 3px solid #ffc57b;
  border-radius: 50%;
  color: #fff;
  font-weight: 750;
}
#mascot-game[data-art="fallback"] .mit-sprite::after { content: "Митя"; }
#mascot-game[data-art="fallback"] .mit-board { display: none; }
#mascot-game[data-pose="sign"] .mit-board { display: block; }
.mit-caption, .mit-reopen {
  border: 1px solid #172a4a2b;
  box-shadow: 0 3px 12px #19243622;
}
.mit-caption {
  position: relative;
  z-index: 1;
  max-width: 100%;
  border-radius: 14px;
  background: #fffaf1;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 650;
  line-height: var(--mit-caption-line);
  text-align: center;
  white-space: normal;
  text-wrap: balance;
  overflow-wrap: anywhere;
  pointer-events: auto;
}
.mit-caption:empty { visibility: hidden; }
.mit-reopen {
  border-radius: 20px;
  padding: 7px 12px;
  min-height: 34px;
  background: #fff8ed;
  color: #27344d;
  font-size: 13px;
  font-weight: 600;
  pointer-events: auto;
}
.mit-screen-reader {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; border: 0;
}
#mascot-game[data-pose="sign"] .mit-sprite { background-position: 33.333333% 0; }
#mascot-game[data-pose="run"] .mit-sprite { background-position: 66.666667% 0; }
#mascot-game[data-pose="run"][data-facing="left"] .mit-figure { scale: -1 1; }
#mascot-game[data-pose="dodge"] .mit-sprite { background-position: 0 50%; }
#mascot-game[data-pose="fall"] .mit-sprite { background-position: 33.333333% 50%; }
#mascot-game[data-pose="lezginka"] .mit-sprite { background-position: 66.666667% 50%; }
#mascot-game[data-pose="gangnam"] .mit-sprite { background-position: 0 100%; }
#mascot-game[data-pose="hypno"] .mit-sprite { background-position: 66.666667% 100%; }
#mascot-game[data-measure-ready="true"]:is([data-pose="measure"],[data-pose="window-measure"]) .mit-sprite {
  background: url("/assets/mitya-measure.webp") 0 100% / 200% 200% no-repeat;
}
#mascot-game[data-measure-ready="true"][data-pose="measure"] .mit-ground { visibility: hidden; }
@media (prefers-reduced-motion: no-preference) {
  #mascot-game[data-measure-ready="true"]:is([data-pose="measure"],[data-pose="window-measure"]) .mit-target:not(:focus-visible) .mit-sprite {
    animation: mit-measure var(--mit-measure-time, 3.4s) steps(1, end) both;
  }
  #mascot-game[data-pose="run"] .mit-sprite { animation: mit-stride .23s steps(1,end) infinite; }
  #mascot-game[data-pose="run"] .mit-figure { animation: mit-bounce .23s ease-in-out infinite; }
  #mascot-game[data-pose="sign"] .mit-figure { animation: mit-board-wobble 2.4s ease-in-out infinite; }
  #mascot-game[data-pose="idle"] .mit-figure { animation: mit-breathe 1.5s ease-in-out infinite; }
  #mascot-game[data-pose="dodge"] .mit-figure { animation: mit-dodge .36s ease-out both; }
  #mascot-game[data-pose="fall"] .mit-figure { animation: mit-fall .8s ease-out both; }
  #mascot-game[data-pose="lezginka"] .mit-sprite { animation: mit-caucasus-feet .56s steps(1,end) infinite; }
  #mascot-game[data-pose="lezginka"] .mit-figure { animation: mit-toe-hop .56s ease-in-out infinite; }
  #mascot-game[data-pose="gangnam"] .mit-sprite { animation: mit-horse-steps .5s steps(1,end) infinite; }
  #mascot-game[data-pose="gangnam"] .mit-figure { animation: mit-gallop .5s ease-in-out infinite; }
  #mascot-game[data-pose="hypno"] .mit-sprite { animation: mit-hypno-arms 1.2s steps(1,end) infinite; }
  #mascot-game[data-pose="hypno"] .mit-figure { animation: mit-wave 1.2s ease-in-out infinite; }
}
@keyframes mit-measure {
  0% { background-position: 0 0; }
  23% { background-position: 100% 0; }
  43% { background-position: 0 100%; }
  79%, 100% { background-position: 100% 100%; }
}
@keyframes mit-stride { 50% { background-position: 100% 0; } }
@keyframes mit-caucasus-feet { 50% { background-position: 100% 50%; } }
@keyframes mit-horse-steps { 50% { background-position: 33.333333% 100%; } }
@keyframes mit-hypno-arms { 50% { background-position: 100% 100%; } }
@keyframes mit-board-wobble { 0%,100% { transform: rotate(-2deg); } 48% { transform: rotate(2deg) translateY(-1px); } }
@keyframes mit-breathe { 50% { transform: translateY(-1px) scale(1.015,.987); } }
@keyframes mit-bounce { 48% { transform: translateY(-4px) rotate(3deg); } }
@keyframes mit-dodge { 0% { transform: scale(1.06,.85); } 48% { transform: translate(-4px,-7px) rotate(-9deg); } 100% { transform: rotate(-2deg); } }
@keyframes mit-fall {
  0% { transform: translateY(-12px) rotate(-26deg) scale(.9,1.07); }
  42% { transform: translateY(3px) rotate(7deg) scale(1.12,.87); }
  65% { transform: translateY(-4px) rotate(-4deg); }
  83% { transform: translateY(1px) rotate(2deg); }
  100% { transform: none; }
}
@keyframes mit-toe-hop { 0%,100% { transform: translateX(-3px) rotate(-2deg); } 25%,75% { transform: translateY(-6px); } 50% { transform: translateX(3px) rotate(2deg); } }
@keyframes mit-gallop { 0%,100% { transform: translateX(-3px) scale(1.04,.96); } 26%,76% { transform: translateY(-5px) scale(.99,1.02); } 50% { transform: translateX(3px) scale(1.04,.96); } }
@keyframes mit-wave { 0%,100% { transform: translateX(-3px) rotate(-6deg) skewX(-2deg); } 50% { transform: translateX(3px) rotate(6deg) skewX(2deg); } }
@media (max-width: 680px), (max-height: 530px) {
  #mascot-game { --mit-figure: 98px; --mit-caption-line: 14px; }
  .mit-actor { width: 135px; }
  .mit-caption { font-size: 11px; }
}
@media (max-height: 380px) {
  #mascot-game { --mit-figure: 82px; }
  .mit-actor { width: 125px; }
}
#mascot-game[data-compact="true"] { --mit-figure: 72px; }
#mascot-game[data-compact="true"] .mit-actor { width: 82px; height: 91px; }
#mascot-game[data-compact="true"] .mit-caption { font-size: 0; line-height: 1; padding: 3px 7px; }
#mascot-game[data-compact="true"] .mit-caption::after { content: "−10%"; font-size: 11px; }
#mascot-game[data-compact="true"][data-hits="2"] .mit-caption::after { content: "Ещё раз!"; }
#mascot-game[data-perched="true"] { z-index: 6; --mit-figure: 53px; }
#mascot-game[data-perched="true"] .mit-actor { width: 84px; height: 55px; }
#mascot-game[data-perched="true"] .mit-caption { display: none; }

/* The actor slides while its holder stays at the viewport edge. */
#mascot-game[data-pose="peek"] {
  --peek-from-x: 0%;
  --peek-from-y: 0%;
  --peek-x: 0%;
  --peek-y: 0%;
  --peek-mirror: 1;
}
#mascot-game[data-pose="peek"][data-edge="left"] {
  --peek-from-x: -120%;
  --peek-x: -39%;
  --peek-angle: 54deg;
}
#mascot-game[data-pose="peek"][data-edge="right"] {
  --peek-from-x: 120%;
  --peek-x: 39%;
  --peek-angle: 54deg;
  --peek-mirror: -1;
}
#mascot-game[data-pose="peek"][data-edge="top"] {
  --mit-figure: 72px;
  --peek-from-y: -120%;
  --peek-y: -26%;
  --peek-angle: 174deg;
  z-index: 6;
}
#mascot-game[data-pose="peek"][data-edge="bottom"] {
  --peek-from-y: 120%;
  --peek-y: 39%;
  --peek-angle: -7deg;
}
#mascot-game[data-pose="peek"] .mit-actor {
  width: var(--mit-figure);
  height: var(--mit-figure);
  transform: translate(var(--peek-x), var(--peek-y));
}
#mascot-game[data-pose="peek"] .mit-figure {
  transform-origin: center;
  transform: scaleX(var(--peek-mirror)) rotate(var(--peek-angle));
}
#mascot-game[data-pose="peek"] :is(.mit-caption, .mit-ground) { display: none; }

/* Split the open palm from the existing surprised pose so it can turn at the wrist. */
#mascot-game:not([data-art="fallback"])[data-pose="peek"] .mit-sprite {
  --palm: 69.5% 0%, 69.5% 30.7%, 69.1% 33.3%, 68.4% 35.1%, 67.3% 35.5%,
    64.8% 34.7%, 63.4% 34.9%, 62.5% 35.8%, 62.1% 37.2%, 62.7% 38%,
    65% 39.1%, 67.8% 40.5%, 70.1% 42%, 72.8% 43%, 75% 43.1%,
    77.5% 42.1%, 79.4% 40%, 81% 38%, 100% 38%, 100% 0%;
  background: radial-gradient(ellipse 7% 6% at 69.1% 36.4%, #24375c 25%, #182643 86%, transparent 100%);
}
#mascot-game:not([data-art="fallback"])[data-pose="peek"] .mit-sprite::before,
#mascot-game:not([data-art="fallback"])[data-pose="peek"] .mit-sprite::after {
  content: "";
  position: absolute;
  inset: 0;
  background: url("/assets/mascot.webp") 0 50% / 400% 300% no-repeat;
}
#mascot-game:not([data-art="fallback"])[data-pose="peek"] .mit-sprite::before {
  clip-path: polygon(evenodd, 69.5% 0%, 0 0, 0 100%, 100% 100%, 100% 0%, var(--palm));
}
#mascot-game:not([data-art="fallback"])[data-pose="peek"] .mit-sprite::after {
  clip-path: polygon(var(--palm));
  transform-origin: 73.6% 41.4%;
}
@media (max-width: 680px), (max-height: 530px) {
  #mascot-game[data-pose="peek"][data-edge="top"] { --mit-figure: 50px; }
}

#mascot-game[data-pose="bump"] .mit-sprite { background-position: 0 50%; }
#mascot-game[data-pose="bump"][data-wall="left"] .mit-sprite { scale: -1 1; }
#mascot-game[data-pose="bump"] {
  --impact-x: 0px; --impact-y: 0px;
  --impact-wide: .82; --impact-tall: 1.11;
  --impact-tilt: 0deg;
  --impact-flash-x: 50%; --impact-flash-y: 50%;
}
#mascot-game[data-wall="left"] {
  --impact-x: -17px; --impact-tilt: -9deg;
  --impact-flash-x: 7%; --impact-flash-y: 34%;
}
#mascot-game[data-wall="right"] {
  --impact-x: 17px; --impact-tilt: 9deg;
  --impact-flash-x: 93%; --impact-flash-y: 34%;
}
#mascot-game[data-pose="bump"]:is([data-wall="top"],[data-wall="bottom"]) {
  --impact-wide: 1.13; --impact-tall: .8;
}
#mascot-game[data-wall="top"] {
  --impact-y: -14px; --impact-tilt: -6deg;
  --impact-flash-x: 42%; --impact-flash-y: 8%;
}
#mascot-game[data-wall="bottom"] {
  --impact-y: 14px; --impact-tilt: 6deg;
  --impact-flash-x: 63%; --impact-flash-y: 93%;
}
@media (prefers-reduced-motion: no-preference) {
  #mascot-game[data-pose="peek"] .mit-actor { animation: mit-peek 3.6s ease-in-out both; }
  #mascot-game:not([data-art="fallback"])[data-pose="peek"] .mit-sprite::after {
    animation: mit-hello .47s ease-in-out .46s 5 alternate both;
  }
  #mascot-game[data-pose="peek"][data-braced="true"] .mit-actor,
  #mascot-game:not([data-art="fallback"])[data-pose="peek"][data-braced="true"] .mit-sprite::after {
    animation-play-state: paused;
  }
  #mascot-game[data-pose="bump"] .mit-figure {
    transform-origin: center;
    animation: mit-wall-bounce .65s ease-out both;
  }
  #mascot-game[data-pose="bump"] .mit-actor::after {
    content: "";
    position: absolute;
    left: var(--impact-flash-x); top: var(--impact-flash-y);
    width: calc(var(--mit-figure) * .18); aspect-ratio: 1;
    pointer-events: none;
    background: #ffbf60;
    clip-path: polygon(48% 0, 61% 33%, 94% 14%, 75% 45%, 100% 59%, 69% 66%, 78% 96%, 52% 76%, 30% 98%, 36% 65%, 0 66%, 25% 46%, 5% 20%, 38% 32%);
    animation: mit-impact-flash .5s ease-out both;
  }
}
@keyframes mit-peek {
  0%, 100% { transform: translate(var(--peek-from-x), var(--peek-from-y)); }
  20%, 77% { transform: translate(var(--peek-x), var(--peek-y)); }
}
@keyframes mit-hello {
  from { transform: rotate(-17deg); }
  to { transform: rotate(22deg); }
}
@keyframes mit-wall-bounce {
  0% { transform: none; }
  18% { transform: translate(var(--impact-x), var(--impact-y)) rotate(var(--impact-tilt)) scale(var(--impact-wide), var(--impact-tall)); }
  48% { transform: translate(calc(var(--impact-x) * -.72), calc(var(--impact-y) * -.72)) rotate(calc(var(--impact-tilt) * -.65)); }
  74% { transform: translate(calc(var(--impact-x) * .18), calc(var(--impact-y) * .18)); }
  100% { transform: none; }
}
@keyframes mit-impact-flash {
  0%, 6% { opacity: 0; transform: translate(-50%, -50%) scale(.3); }
  19% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); }
  86%, 100% { opacity: 0; transform: translate(-50%, -50%) scale(.65) rotate(14deg); }
}
