/*
 * Mara Velen / visitor motion sidecar
 *
 * Loaded after styles.css. The host page adds data-case-id="mara-velen"
 * to the document body while Mara is the active visitor.
 */

[data-case-id="mara-velen"] {
  --mara-idle-duration: 8.6s;
  --mara-idle-delay: 700ms;
  --mara-red-glow: rgba(226, 75, 55, 0.72);
  --mara-red-shadow: rgba(166, 41, 36, 0.28);
}

[data-case-id="mara-velen"] .visitor-portrait {
  isolation: isolate;
}

[data-case-id="mara-velen"] .visitor-image {
  position: relative;
  z-index: 1;
  transform-origin: 50% 100%;
  filter: saturate(0.78) brightness(0.9) contrast(0.95) sepia(0.04);
  animation: mara-visitor-breath var(--mara-idle-duration) ease-in-out var(--mara-idle-delay) infinite both;
  will-change: transform;
}

[data-case-id="mara-velen"] .visitor-image.visitor-blink {
  animation: mara-blink-frame 150ms steps(1, end) both;
}

[data-case-id="mara-velen"] .visitor-portrait::before {
  position: absolute;
  z-index: 0;
  right: 17%;
  bottom: 1.5%;
  left: 17%;
  height: 8%;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.48) 0%, rgba(0, 0, 0, 0.2) 48%, transparent 76%);
  content: "";
  pointer-events: none;
  animation: mara-visitor-ground var(--mara-idle-duration) ease-in-out var(--mara-idle-delay) infinite both;
}

[data-case-id="mara-velen"] .visitor-portrait::before {
  animation: none;
  opacity: 0.48;
  transform: none;
}

[data-case-id="mara-velen"] .visitor-nameplate::before {
  position: absolute;
  top: -1px;
  left: 12px;
  width: 34px;
  height: 1px;
  background: var(--mara-red-glow);
  content: "";
  opacity: 0;
  transform: scaleX(0.2);
  transform-origin: left center;
  pointer-events: none;
}

@supports selector([data-case-id="mara-velen"]:has(.scene-hotspot)) {
  [data-case-id="mara-velen"]:has(
    .scene-hotspot.hotspot-visitor.selected,
    .scene-hotspot.hotspot-visitor.revealed,
    .scene-hotspot.hotspot-visitor:focus-visible
  ) .visitor-image {
    animation:
      mara-visitor-breath var(--mara-idle-duration) ease-in-out var(--mara-idle-delay) infinite both,
      mara-visitor-attention 920ms cubic-bezier(0.22, 0.8, 0.28, 1) 0s 1 none;
  }

  [data-case-id="mara-velen"]:has(
    .scene-hotspot.hotspot-visitor.selected,
    .scene-hotspot.hotspot-visitor.revealed,
    .scene-hotspot.hotspot-visitor:focus-visible
  ) .visitor-nameplate {
    border-color: rgba(226, 75, 55, 0.58);
    animation: mara-nameplate-attention 920ms ease-out 0s 1 none;
  }

  [data-case-id="mara-velen"]:has(
    .scene-hotspot.hotspot-visitor.selected,
    .scene-hotspot.hotspot-visitor.revealed,
    .scene-hotspot.hotspot-visitor:focus-visible
  ) .visitor-nameplate::before {
    animation: mara-nameplate-rule 920ms ease-out 0s 1 both;
  }
}

@keyframes mara-visitor-breath {
  0%,
  100% { transform: translate3d(0, 0, 0) rotate(0deg); }
  26% { transform: translate3d(-1px, 0, 0) rotate(-0.08deg); }
  53% { transform: translate3d(1px, -1px, 0) rotate(0.16deg); }
  76% { transform: translate3d(0, 0, 0) rotate(0.04deg); }
}

@keyframes mara-blink-frame {
  from,
  to { opacity: 1; }
}

@keyframes mara-visitor-ground {
  0%,
  100% { opacity: 0.48; }
  53% { opacity: 0.48; }
}

@keyframes mara-visitor-attention {
  0%,
  100% { filter: saturate(0.78) brightness(0.9) contrast(0.95) sepia(0.04); }
  23% { filter: saturate(0.82) brightness(0.94) contrast(0.97) sepia(0.04) drop-shadow(0 0 6px var(--mara-red-shadow)); }
  48% { filter: saturate(0.86) brightness(0.97) contrast(0.98) sepia(0.04) drop-shadow(0 0 10px rgba(226, 75, 55, 0.24)); }
  74% { filter: saturate(0.8) brightness(0.92) contrast(0.96) sepia(0.04) drop-shadow(0 0 4px rgba(226, 75, 55, 0.12)); }
}

@keyframes mara-nameplate-attention {
  0%,
  100% { box-shadow: 0 10px 22px rgba(0, 0, 0, 0.42); }
  42% { box-shadow: 0 0 0 1px rgba(226, 75, 55, 0.2), 0 0 18px rgba(166, 41, 36, 0.22), 0 10px 22px rgba(0, 0, 0, 0.42); }
}

@keyframes mara-nameplate-rule {
  0%,
  100% { opacity: 0; transform: scaleX(0.2); }
  22%,
  66% { opacity: 0.9; transform: scaleX(1); }
}

@media (prefers-reduced-motion: reduce) {
  [data-case-id="mara-velen"] .visitor-portrait,
  [data-case-id="mara-velen"] .visitor-image,
  [data-case-id="mara-velen"] .visitor-portrait::before,
  [data-case-id="mara-velen"] .visitor-nameplate,
  [data-case-id="mara-velen"] .visitor-nameplate::before {
    animation: none !important;
    transition-duration: 0.01ms !important;
    will-change: auto;
  }

  [data-case-id="mara-velen"] .visitor-image {
    transform: none !important;
  }

  [data-case-id="mara-velen"] .visitor-portrait::before {
    opacity: 0.42;
    transform: none;
  }

  [data-case-id="mara-velen"] .visitor-nameplate::before {
    opacity: 0;
    transform: none;
  }
}
