.blog-mascot {
  --mascot-accent: #55ffff;
  --mascot-muted: #00aaaa;
  --mascot-size: 3rem;
  --mascot-terminal-bg: rgba(0, 0, 0, 0.94);
  --mascot-terminal-text: #55ffff;
  position: fixed;
  z-index: 9;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms linear;
}

.blog-mascot.is-ready {
  opacity: 1;
}

.mascot-world {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  user-select: none;
}

.blog-mascot.is-disabled .mascot-world {
  display: none;
}

.mascot-home {
  position: absolute;
  right: max(0.6rem, env(safe-area-inset-right));
  bottom: max(0.6rem, env(safe-area-inset-bottom));
  width: 9rem;
  height: 3.7rem;
}

.mascot-terminal {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--mascot-accent) 70%, transparent);
  background: var(--mascot-terminal-bg);
  box-shadow: 0 0 0 1px #000, 0 0 1rem rgba(0, 170, 170, 0.12);
  color: var(--mascot-terminal-text);
  font: 700 0.52rem/1.3 var(--mono);
  opacity: 0.84;
}

.mascot-terminal-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 1rem;
  padding: 0 0.35rem;
  background: rgba(0, 170, 170, 0.18);
  color: var(--gray);
  font-size: 0.45rem;
}

.mascot-terminal-bar i {
  width: 0.32rem;
  height: 0.32rem;
  background: var(--mascot-accent);
  box-shadow: 0 0 0.3rem var(--mascot-accent);
}

.mascot-terminal-command,
.mascot-terminal-output {
  overflow: hidden;
  padding-inline: 0.4rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mascot-terminal-command {
  padding-top: 0.35rem;
}

.mascot-terminal-output {
  color: var(--gray);
  font-weight: 400;
}

.mascot-terminal-output::after {
  display: inline-block;
  width: 0.38rem;
  height: 0.65rem;
  margin-left: 0.25rem;
  background: var(--mascot-accent);
  content: "";
  vertical-align: -0.12rem;
  animation: mascot-cursor 1.1s steps(1, end) infinite;
}

.mascot-actor {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--mascot-size);
  height: var(--mascot-size);
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  will-change: transform;
}

.mascot-actor:active {
  cursor: grabbing;
}

.mascot-sprite {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.65));
  image-rendering: pixelated;
  shape-rendering: crispEdges;
  transform-origin: center;
}

.mascot-actor[data-facing="left"] .mascot-sprite {
  transform: scaleX(-1);
}

.mascot-bubble {
  position: absolute;
  z-index: 2;
  right: 65%;
  bottom: 84%;
  min-width: 1.5rem;
  padding: 0.18rem 0.32rem;
  border: 1px solid var(--mascot-accent);
  background: #000;
  color: var(--mascot-accent);
  font: 700 0.52rem/1.1 var(--mono);
  text-align: center;
  white-space: nowrap;
}

.mascot-bubble::after {
  position: absolute;
  right: 0.2rem;
  bottom: -0.3rem;
  width: 0.35rem;
  height: 0.35rem;
  border-right: 1px solid var(--mascot-accent);
  border-bottom: 1px solid var(--mascot-accent);
  background: #000;
  content: "";
  transform: rotate(45deg);
}

.mascot-bubble[hidden] {
  display: none;
}

.mascot-toggle {
  position: absolute;
  right: calc(max(0.7rem, env(safe-area-inset-right)) + 9.3rem);
  bottom: max(0.7rem, env(safe-area-inset-bottom));
  padding: 0.2rem 0.35rem;
  border: 1px solid rgba(85, 255, 255, 0.38);
  background: #000;
  color: var(--gray);
  font: 700 0.48rem/1 var(--mono);
  opacity: 0.58;
  pointer-events: auto;
  cursor: pointer;
}

.mascot-toggle:hover,
.mascot-toggle:focus-visible {
  color: var(--bright-cyan);
  opacity: 1;
}

.blog-mascot.is-disabled .mascot-toggle {
  right: max(0.7rem, env(safe-area-inset-right));
  bottom: max(0.6rem, env(safe-area-inset-bottom));
}

.blog-mascot[data-state="falling"] .mascot-sprite {
  animation: mascot-fall 420ms steps(4, end) infinite;
}

.blog-mascot[data-state="panic"] .mascot-sprite {
  animation: mascot-shake 120ms steps(2, end) infinite;
}

.blog-mascot[data-state="celebrate"] .mascot-sprite {
  animation: mascot-hop 360ms steps(2, end) infinite;
}

.blog-mascot.is-rapid-typing .mascot-terminal {
  box-shadow: 0 0 0 1px #000, 0 0 1.2rem rgba(85, 255, 255, 0.38);
}

.blog-mascot[data-theme="light"] {
  --mascot-accent: #084f8f;
  --mascot-muted: #126b73;
  --mascot-terminal-bg: rgba(216, 221, 213, 0.96);
  --mascot-terminal-text: #084f8f;
}

.prose pre.has-code-copy {
  position: relative;
}

.code-copy-button {
  position: absolute;
  z-index: 2;
  top: 0.45rem;
  right: 0.45rem;
  padding: 0.18rem 0.32rem;
  border: 1px solid rgba(103, 197, 207, 0.55);
  background: rgba(0, 0, 0, 0.82);
  color: var(--code-accent);
  font: 700 0.55rem/1.1 var(--mono);
  opacity: 0.42;
  cursor: pointer;
}

.prose pre:hover .code-copy-button,
.code-copy-button:focus-visible {
  opacity: 1;
}

@keyframes mascot-cursor {
  0%, 48% { opacity: 1; }
  49%, 100% { opacity: 0; }
}

@keyframes mascot-fall {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes mascot-shake {
  0% { translate: -1px 0; }
  100% { translate: 1px 0; }
}

@keyframes mascot-hop {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -3px; }
}

@media (max-width: 48rem) {
  .blog-mascot {
    --mascot-size: 2.5rem;
  }

  .mascot-home {
    width: 7rem;
    height: 3rem;
  }

  .mascot-terminal {
    font-size: 0.46rem;
    opacity: 0.76;
  }

  .mascot-terminal-bar {
    height: 0.8rem;
    font-size: 0.4rem;
  }

  .mascot-terminal-command {
    padding-top: 0.2rem;
  }

  .mascot-toggle {
    right: calc(max(0.7rem, env(safe-area-inset-right)) + 7.3rem);
    bottom: max(0.7rem, env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  .blog-mascot,
  .mascot-sprite,
  .mascot-terminal-output::after {
    animation: none !important;
    transition: none !important;
  }
}

@media print {
  .blog-mascot,
  .code-copy-button {
    display: none !important;
  }
}
