/* --- Animated Chibi Mascot ('Agna') --- */
.chibi-wrap {
  position: absolute;
  left: 205px; /* Sits in the empty space between 'main.sal' and the 3D cube */
  top: 25px;   /* Sits gracefully right on the top edge of the terminal */
  width: 125px;
  height: 200px;
  z-index: 5;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.chibi-stage {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
  touch-action: manipulation;
}

@keyframes chibiBreathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2.5px); }
}

.chibi-breathe {
  position: relative;
  width: 100%;
  height: 100%;
  animation: chibiBreathe 4.5s ease-in-out infinite;
}

@keyframes chibiBounce {
  0% { transform: scale(1, 1); }
  25% { transform: scale(0.94, 1.06) translateY(-6px); }
  50% { transform: scale(1.04, 0.96) translateY(2px); }
  75% { transform: scale(0.98, 1.02); }
  100% { transform: scale(1, 1); }
}

.chibi-stage.chibi-bounce .chibi-breathe {
  animation: chibiBounce 0.42s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Master character image: crisp, unblurred, zero floating layers */
.chibi-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 10px 22px rgba(0, 0, 0, 0.55));
}

/* Soft natural cheek blush */
.chibi-blush {
  position: absolute;
  width: 22px;
  height: 12px;
  background: radial-gradient(ellipse at center, rgba(255, 75, 110, 0.75) 0%, rgba(255, 75, 110, 0) 70%);
  border-radius: 50%;
  z-index: 4;
  opacity: 0.2;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.chibi-blush.left {
  left: 28%;
  top: 36%;
}

.chibi-blush.right {
  left: 61%;
  top: 36%;
}

/* Speech Dialogue Bubble (Clean, zero emojis) */
.chibi-bubble {
  position: absolute;
  bottom: calc(100% - 10px);
  left: 50%;
  transform: translateX(-50%) translateY(8px) scale(0.92);
  transform-origin: bottom center;
  background: rgba(18, 19, 28, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 60, 80, 0.35);
  border-radius: 12px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.22s cubic-bezier(0.16, 1, 0.3, 1),
              visibility 0.22s;
  box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.7),
              0 0 20px rgba(255, 60, 80, 0.2);
  z-index: 20;
}

.chibi-bubble.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0) scale(1);
}

.chibi-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px 6px 0 6px;
  border-style: solid;
  border-color: rgba(18, 19, 28, 0.94) transparent transparent transparent;
}

.chibi-bubble-text {
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: #f5f5f7;
  letter-spacing: -0.01em;
}

.chibi-bubble-tip {
  font-size: 0.62rem;
  font-weight: 500;
  color: #ff4767;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Starlight Sparkle Particles (Zero emojis) */
.chibi-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 10;
}

.chibi-particle {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ff4767;
  box-shadow: 0 0 10px #ff4767, 0 0 18px rgba(255, 71, 103, 0.6);
  pointer-events: none;
  animation: particleBurst 0.75s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

.chibi-particle.gold {
  background: #ffc837;
  box-shadow: 0 0 10px #ffc837, 0 0 18px rgba(255, 200, 55, 0.6);
}

.chibi-particle.white {
  background: #ffffff;
  box-shadow: 0 0 10px #ffffff, 0 0 16px rgba(255, 255, 255, 0.8);
}

@keyframes particleBurst {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1.4);
  }
  100% {
    opacity: 0;
    transform: translate(var(--pdx, 20px), var(--pdy, -20px)) scale(0.2);
  }
}

/* Mobile & Tablet Responsive Optimization */
@media (max-width: 980px) {
  .cube-chips {
    display: none !important;
  }
  .hero-scene .cube-wrap {
    margin-bottom: 30px !important;
  }
  .chibi-wrap {
    left: auto;
    right: 20px;
    width: 92px;
    height: 147px;
  }
  .chibi-bubble {
    font-size: 0.72rem;
    padding: 6px 12px;
    bottom: calc(100% - 6px);
  }
  .chibi-blush {
    width: 17px;
    height: 9px;
  }
}

@media (max-width: 480px) {
  .cube-chips {
    display: none !important;
  }
  .hero-scene .cube-wrap {
    margin-bottom: 26px !important;
  }
  .chibi-wrap {
    right: 14px;
    width: 82px;
    height: 131px;
  }
  .chibi-bubble {
    max-width: 240px;
    white-space: normal;
    text-align: center;
  }
}

/* Corner mode: fixed bottom-right once her hero spot is scrolled away */
.chibi-wrap.corner {
  position: fixed;
  left: auto !important;
  top: auto !important;
  right: 14px;
  bottom: 14px;
  width: 84px;
  height: 134px;
  z-index: 50;
  animation: chibiPop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes chibiPop {
  from { opacity: 0; transform: translateY(24px) scale(0.8); }
  to { opacity: 1; transform: none; }
}

.chibi-wrap.corner .chibi-bubble {
  left: auto;
  right: 0;
  transform: translateY(8px) scale(0.92);
  transform-origin: bottom right;
  white-space: normal;
  width: max-content;
  max-width: min(240px, calc(100vw - 28px));
  text-align: center;
}

.chibi-wrap.corner .chibi-bubble.show {
  transform: translateY(0) scale(1);
}

.chibi-wrap.corner .chibi-bubble::after {
  left: auto;
  right: 34px;
  transform: none;
}

/* Download card for the visitor's OS */
.card.match {
  border-color: var(--red);
  box-shadow: 0 0 0 2px rgba(232, 40, 60, 0.25), 0 14px 36px rgba(232, 40, 60, 0.15);
}

/* Scroll reveal (helper classes are removed after the animation) */
.rv {
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 0.6s ease, transform 0.6s ease;
}

.rv.in {
  opacity: 1;
  transform: none;
}

/* Performance: skip rendering offscreen sections, keep the breathing on the compositor */
.release, .foot { content-visibility: auto; contain-intrinsic-size: auto 420px; }
.chibi-breathe { will-change: transform; }

@media (max-width: 980px) {
  .chibi-layer { filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.4)); }
}

@media (prefers-reduced-motion: reduce) {
  .chibi-breathe { animation: none; }
}

/* Phones and tablets: bubble sized to its text and anchored to her right edge, shorter code window */
@media (max-width: 980px) {
  .chibi-bubble {
    left: auto;
    right: 0;
    transform: translateY(8px) scale(0.92);
    transform-origin: bottom right;
    white-space: normal;
    width: max-content;
    max-width: min(220px, calc(100vw - 28px));
    text-align: center;
  }
  .chibi-bubble.show { transform: translateY(0) scale(1); }
  .chibi-bubble::after { left: auto; right: 34px; transform: none; }
  .code { height: 150px; }
}
