/* Caret guide — the travelling, live Caret for the portfolio's Caret block.
   Ported from Target7's landing (MascotGuide + Mascot liveEyes). Everything is
   scoped under .cg-* so it cannot touch the site's own styles. */

:root {
  --cg-ease-enter: cubic-bezier(0.16, 1, 0.3, 1);
  --cg-ease-pop: cubic-bezier(0.2, 1.4, 0.4, 1);
}

/* ---- the character box ----
   The art is a 1254² frame with a transparent margin. These values scale it up
   and pull the margin off, so the box width is the character's own width
   (content bbox 86,131 → 1171,1060). Height ÷ width = 929/1085. */
.cg-char {
  position: relative;
  display: block;
  width: 100%;
  --mz: 115.58%;
  --mml: -7.93%;
  --mmt: -12.07%;
  --mmb: -17.88%;
}
.cg-body {
  display: flow-root;
  position: relative;
  z-index: 1;
}
.cg-img {
  display: block;
  width: var(--mz);
  max-width: none;
  margin: var(--mmt) 0 var(--mmb) var(--mml);
  pointer-events: none;
  user-select: none;
}

/* live pupils: patches in the face colour hide the baked eyes, redrawn pupils
   look toward the pointer via --gx / --gy ∈ [-1, 1] */
.cg-eyes {
  position: absolute;
  left: -7.93%;
  top: -14.1%;
  width: 115.58%;
  aspect-ratio: 1;
  pointer-events: none;
}
.cg-eye {
  position: absolute;
  width: 3.9%;
  height: 6.3%;
  top: 64.2%;
  border-radius: 50%;
  background: #dbbbfc;
  transform: translate(-50%, -50%);
}
.cg-eye.l { left: 45.18%; }
.cg-eye.r { left: 54.95%; }
.cg-pupil {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 78%;
  height: 82%;
  border-radius: 50%;
  background: #2b1043;
  transform: translate(calc(-50% + var(--gx, 0) * 34%), calc(-50% + var(--gy, 0) * 14%));
  transition: transform 90ms linear;
}
.cg-pupil::after {
  content: "";
  position: absolute;
  left: 24%;
  top: 16%;
  width: 36%;
  height: 27%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.32);
}
.cg-lid {
  position: absolute;
  inset: -10%;
  border-radius: 50%;
  background: #dbbbfc;
  transform: scaleY(0);
  transform-origin: 50% 0%;
  animation: cg-blink 5.4s ease-in-out infinite;
}
.cg-eye.r .cg-lid { animation-delay: 0.03s; }
@keyframes cg-blink {
  0%, 93.5%, 100% { transform: scaleY(0); }
  95.5%, 97.5% { transform: scaleY(1); }
}

/* talking mouth over the baked smirk */
.cg-mouth {
  position: absolute;
  left: 51.75%;
  top: 70.5%;
  width: 12.5%;
  height: 6.6%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #dbb9fb;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 240ms ease 140ms;
}
.cg-lip {
  position: relative;
  width: 62%;
  height: 66%;
  border-radius: 46% 46% 50% 50% / 40% 40% 60% 60%;
  background: #b8352a;
  transform: scaleY(0.25);
  overflow: hidden;
  transition: transform 160ms ease;
}
.cg-lip::after {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -4%;
  height: 46%;
  border-radius: 50% 50% 40% 40%;
  background: #fc8577;
}
.cg-talking .cg-mouth { opacity: 1; transition: opacity 90ms ease; }
.cg-talking .cg-lip { animation: cg-talk 0.34s ease-in-out infinite; }
@keyframes cg-talk {
  0%, 100% { transform: scaleY(0.22) scaleX(0.86); }
  45% { transform: scaleY(1) scaleX(1); }
  70% { transform: scaleY(0.55) scaleX(0.95); }
}

/* ---- the travelling layer ---- */
.cg-guide {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 40;
  pointer-events: none;
  will-change: transform, width;
  transition: opacity 0.5s ease;
}
.cg-guide.cg-enter { opacity: 0; }
.cg-guide.cg-hidden { opacity: 0; }
.cg-guide .cg-art {
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 22px 20px rgba(60, 30, 140, 0.16));
}
/* only the character itself takes clicks (interactive), never the box around it */
.cg-guide .cg-hit {
  position: absolute;
  inset: 4% 10% 0 10%;
  pointer-events: auto;
  cursor: pointer;
  border-radius: 40% 40% 50% 50%;
  z-index: 3;
}
.cg-guide .cg-char { transition: transform 0.35s var(--cg-ease-enter); }
.cg-guide.cg-flip .cg-char { transform: scaleX(-1); }
.cg-guide .cg-bob { transition: transform 0.5s var(--cg-ease-enter); }
.cg-guide.cg-enter .cg-bob { transform: scale(0.86); }
.cg-guide.cg-parked .cg-bob { animation: cg-breathe 3.4s ease-in-out infinite alternate; }
@keyframes cg-breathe {
  from { transform: translateY(0) rotate(-0.5deg) scale(1); }
  to { transform: translateY(-5px) rotate(0.55deg) scale(1.012); }
}
.cg-guide.cg-talking .cg-bob {
  animation: cg-talkbody 0.46s ease-in-out infinite;
  transform-origin: 50% 88%;
}
@keyframes cg-talkbody {
  0%, 100% { transform: translateY(0) rotate(-0.9deg); }
  50% { transform: translateY(-6px) rotate(1deg); }
}
.cg-guide.cg-talkend .cg-bob {
  animation: cg-settle 0.5s var(--cg-ease-pop) 1 both;
  transform-origin: 50% 88%;
}
@keyframes cg-settle {
  from { transform: translateY(-4px) rotate(0.6deg); }
  to { transform: translateY(0) rotate(0deg); }
}
.cg-guide.cg-travel { opacity: 0.9; }
.cg-guide.cg-land .cg-art {
  animation: cg-land 400ms var(--cg-ease-pop);
  transform-origin: 50% 94%;
}
@keyframes cg-land {
  0% { transform: scale(1.05, 0.88); }
  55% { transform: scale(0.975, 1.035); }
  100% { transform: scale(1, 1); }
}
/* click: a happy hop */
.cg-guide.cg-hop .cg-bob {
  animation: cg-hop 620ms var(--cg-ease-pop) 1 both;
  transform-origin: 50% 94%;
}
@keyframes cg-hop {
  0% { transform: translateY(0) scale(1.06, 0.9); }
  35% { transform: translateY(-34px) rotate(-6deg) scale(0.96, 1.06); }
  70% { transform: translateY(0) scale(1.05, 0.92); }
  100% { transform: translateY(0) scale(1); }
}

/* ground shadow: the character's own silhouette, squashed and inked */
.cg-guide .cg-shadowpos {
  position: absolute;
  left: 50%;
  bottom: -4%;
  width: 103%;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 0;
}
.cg-guide .cg-shadow { display: block; }
.cg-guide .cg-shadow img {
  display: block;
  width: 100%;
  transform: scaleY(0.24);
  transform-origin: 50% 100%;
  filter: brightness(0) blur(3px);
  opacity: 0.3;
}
.cg-guide.cg-flip .cg-shadow img { transform: scaleY(0.24) scaleX(-1); }
.cg-guide.cg-night .cg-shadow img { filter: brightness(0) invert(1) blur(5px); opacity: 0.2; }

/* ---- stops ----
   A stop is any element with [data-caret-stop]. The guide parks on its box;
   its width sets the Caret's size there. While the guide is live the stop's
   own static Caret turns invisible (layout kept). */
[data-caret-stop] { position: relative; display: block; }
[data-caret-stop] > .cg-static { display: block; width: 100%; }
.cg-live [data-caret-stop] > .cg-static { visibility: hidden; }

/* speech bubble, popped once the Caret has landed */
.cg-say {
  position: absolute;
  left: 58%;
  bottom: 96%;
  width: max-content;
  max-width: 260px;
  padding: 10px 14px;
  border-radius: 16px;
  background: #fff;
  color: #1b1530;
  font: 500 14px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif;
  box-shadow: 0 10px 30px rgba(40, 20, 90, 0.16), 0 0 0 1px rgba(40, 20, 90, 0.06);
  opacity: 0;
  transform: translateY(6px) scale(0.92);
  transform-origin: 10% 100%;
  transition: opacity 0.2s ease, transform 0.35s var(--cg-ease-pop);
  pointer-events: none;
  z-index: 41;
}
[data-caret-flip] .cg-say { left: auto; right: 58%; transform-origin: 90% 100%; }
/* little tail toward the head */
.cg-say::after {
  content: ""; position: absolute; left: 16px; bottom: -6px; width: 12px; height: 12px;
  background: inherit; transform: rotate(45deg); border-radius: 0 0 3px 0;
  box-shadow: 1px 1px 0 rgba(40, 20, 90, 0.06);
}
[data-caret-flip] .cg-say::after { left: auto; right: 16px; }
.cg-say.cg-say-on { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .cg-lid, .cg-guide .cg-bob { animation: none !important; }
}
