/* ==========================================================================
   VRDevAI — VIRA, the guide mascot
   Uses brand tokens only (brand.css). No new colours are introduced here.

   One single mascot element lives in the hero and re-docks to the corner once
   the hero scrolls away, so the visitor keeps the same character rather than
   meeting a second copy of it.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. The character
   -------------------------------------------------------------------------- */

.vira {
  --vira-w: 234px;             /* character width; height follows the art ratio */
  position: absolute;
  z-index: 40;
  width: var(--vira-w);
  /* Head only by default (484 x 303). The hero variant below is the full
     character and overrides this. */
  height: calc(var(--vira-w) * 0.6260);
  --gx: 0;   /* cursor direction, -1..1, written by mascot.js */
  --gy: 0;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  transform-origin: center bottom;
  transition: width 0.45s var(--ease);
}

.vira:focus-visible {
  outline: 3px solid var(--tech-blue);
  outline-offset: 6px;
  border-radius: var(--r-md);
}

/* Hero placement — overlaps the brand mark deliberately, but clear of the
   Security chip at `bottom: 14%; right: -7%` in site.css. */
.vira--hero {
  right: 12%;
  bottom: -14px;
  /* Full character, 484 x 778. The head is rows 0..303 of that art and the body
     is rows 303.., so stacking them at those offsets rebuilds the original
     exactly — no seam to hide. Numbers come from tools/build_hero.py; change the
     art and re-run it rather than nudging them by hand. */
  height: calc(var(--vira-w) * 1.6074);
}

/* Docked placement — follows the reader down the page. */
.vira.is-docked {
  --vira-w: 152px;
  position: fixed;
  right: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vw, 24px);
  animation: vira-arrive 0.5s var(--ease) both;
}

@keyframes vira-arrive {
  from { opacity: 0; transform: translateY(24px) scale(0.9); }
  to   { opacity: 1; transform: none; }
}

/* Soft brand glow on the floor so the character sits on the page. */
.vira__glow {
  position: absolute;
  left: 50%;
  bottom: 2%;
  width: 74%;
  height: 14%;
  transform: translateX(-50%);
  background: radial-gradient(ellipse at center, rgba(8, 124, 255, 0.35), transparent 70%);
  filter: blur(6px);
  pointer-events: none;
}

/* Scoped with .vira because `.hero__art img` in site.css is more specific than a
   bare class and would otherwise resize the rig layers. */
.vira .vira__placeholder {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 22px rgba(7, 21, 47, 0.18));
}

/* --- rig layers --- */

.vira .vira__bodyart {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 61.05%;
  object-fit: contain;
  filter: drop-shadow(0 10px 22px rgba(7, 21, 47, 0.18));
  /* The body leans a fraction of what the head turns, so a turned head reads as
     the whole character looking rather than a head swivelling on a still body. */
  transform: rotate(calc(var(--gx) * 1.1deg));
  transform-origin: center bottom;
  transition: transform 0.5s var(--ease);
}

.vira .vira__head {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 0;
  padding-bottom: 62.60%;
  /* A real turn, not a tilt. Rotating the flat head image around the vertical
     axis under perspective reads as the head turning to face the cursor; a flat
     `rotate()` only ever reads as a cocked neck. The small counter-translate and
     the tilt keep it from looking like a card flipping. Angles stay modest —
     past about 20deg a flat image starts to show that it is flat. */
  transform: perspective(760px)
             translate(calc(var(--gx) * 2.5%), calc(var(--gy) * 2%))
             rotateY(calc(var(--gx) * 20deg))
             rotateX(calc(var(--gy) * -10deg))
             rotate(calc(var(--gx) * 2.5deg));
  transform-origin: center 92%;
  transform-style: preserve-3d;
  transition: transform 0.32s var(--ease);
}

/* Docked and in the panel VIRA is a head only: hide the body and let the head
   fill the box. */
.vira.is-docked .vira__bodyart { display: none; }
.vira.is-docked .vira__head {
  padding-bottom: 62.60%;
}

.vira .vira__headart,
.vira .vira__eyes,
.vira .vira__mouth {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.vira .vira__headart {
  filter: drop-shadow(0 8px 18px rgba(7, 21, 47, 0.20));
}

.vira .vira__eyes {
  /* The eyes travel further than the head turns, and they lead it slightly in
     time — that difference is what makes the gaze land on the cursor rather than
     drift after it. */
  transform: translate(calc(var(--gx) * 4.5%), calc(var(--gy) * 3.2%));
  transition: transform 0.16s var(--ease);
}

/* The mouth sits on the screen too, so it has to travel with the face — a
   quarter of the eye movement, the way a feature further from the pivot does. */
.vira .vira__mouth {
  transform: translate(calc(var(--gx) * 1.2%), calc(var(--gy) * 0.9%));
  transition: transform 0.2s var(--ease);
}

/* The whole character animates; the frame swap does the acting. */
.vira__stage {
  position: absolute;
  inset: 0;
  animation: vira-idle 3.5s ease-in-out infinite;
  transform-origin: center bottom;
}

.vira[data-motion="happy"]     .vira__stage { animation: vira-happy 2.4s ease-in-out infinite; }
.vira[data-motion="thinking"]  .vira__stage { animation: vira-think 1.6s ease-in-out infinite; }
.vira[data-motion="working"]   .vira__stage { animation: vira-work 1.2s ease-in-out infinite; }
.vira[data-motion="excited"]   .vira__stage { animation: vira-excited 0.6s ease-in-out infinite; }
.vira[data-motion="surprised"] .vira__stage { animation: vira-surprised 0.6s ease-in-out 1; }
.vira[data-motion="talking"]   .vira__stage { animation: vira-talk 0.4s ease-in-out infinite; }

@keyframes vira-idle      { 0%,100% { transform: translateY(0) rotate(-1.5deg); } 50% { transform: translateY(-4%) rotate(1.5deg); } }
@keyframes vira-happy     { 0%,100% { transform: translateY(0); }                 50% { transform: translateY(-7%); } }
@keyframes vira-think     { 0%,100% { transform: rotate(-4deg); }                 50% { transform: rotate(4deg); } }
@keyframes vira-work      { 0%,100% { transform: translateY(0) rotate(-2deg); }   50% { transform: translateY(-3%) rotate(2deg); } }
@keyframes vira-excited   { 0%,100% { transform: translateY(0) scale(1); }        50% { transform: translateY(-12%) scale(1.04); } }
@keyframes vira-talk      { 0%,100% { transform: translateY(0); }                 50% { transform: translateY(-3%); } }
@keyframes vira-surprised {
  0%,100% { transform: translateX(0) scale(1); }
  25%     { transform: translateX(-5%) scale(1.05); }
  50%     { transform: translateX(5%) scale(1.05); }
  75%     { transform: translateX(-3%) scale(1.03); }
}

/* --------------------------------------------------------------------------
   2. Greeting bubble
   -------------------------------------------------------------------------- */

.vira-bubble {
  position: fixed;
  z-index: 41;
  right: clamp(12px, 3vw, 28px);
  bottom: calc(clamp(12px, 3vw, 24px) + 128px);
  max-width: min(280px, calc(100vw - 32px));
  padding: 0.7rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md) var(--r-md) 4px var(--r-md);
  background: var(--white);
  box-shadow: var(--shadow-md);
  color: var(--text);
  font-size: var(--fs-small);
  line-height: 1.5;
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  pointer-events: none;
}

.vira-bubble.is-visible { opacity: 1; transform: none; pointer-events: auto; }

.vira-bubble__close {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--white);
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   3. Chat panel
   -------------------------------------------------------------------------- */

.vira-panel {
  position: fixed;
  z-index: 60;
  right: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vw, 24px);
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100vw - 24px));
  height: min(560px, calc(100vh - 96px));
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--white);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  transition: opacity 0.28s var(--ease), transform 0.28s var(--ease);
  pointer-events: none;
}

.vira-panel.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.vira-panel__head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1rem;
  background: var(--grad-deep);
  color: var(--text-invert);
}

.vira-panel__avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.08);
  object-fit: contain;
}

.vira-panel__title { font-weight: var(--fw-semibold); font-size: 0.95rem; }
.vira-panel__sub   { font-size: 0.75rem; color: rgba(255, 255, 255, 0.68); }

.vira-panel__close {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-invert);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.vira-panel__close:hover { background: rgba(255, 255, 255, 0.2); }

.vira-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  background: var(--bg-alt);
}

.vira-msg {
  max-width: 84%;
  padding: 0.6rem 0.85rem;
  border-radius: var(--r-md);
  font-size: var(--fs-small);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.vira-msg--bot {
  align-self: flex-start;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  background: var(--white);
  color: var(--text);
}

.vira-msg--me {
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  background: var(--grad-accent);
  color: var(--text-invert);
}

.vira-msg--error {
  align-self: flex-start;
  border: 1px solid #F3C7C7;
  background: #FDF3F3;
  color: #8A2B2B;
}

/* Three-dot wait state while the backend is thinking. */
.vira-typing { display: inline-flex; gap: 4px; align-items: center; }
.vira-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--tech-blue);
  animation: vira-dot 1s ease-in-out infinite;
}
.vira-typing i:nth-child(2) { animation-delay: 0.15s; }
.vira-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes vira-dot { 0%,100% { opacity: 0.25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }

.vira-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem 0.75rem;
  background: var(--bg-alt);
}

.vira-chip {
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 0.35rem 0.75rem;
  background: var(--white);
  color: var(--tech-blue);
  font: inherit;
  font-size: 0.78rem;
  font-weight: var(--fw-medium);
  cursor: pointer;
}

.vira-chip:hover { border-color: var(--tech-blue); box-shadow: var(--shadow-sm); }

.vira-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  background: var(--white);
}

.vira-form input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font: inherit;
  font-size: var(--fs-small);
  color: var(--text);
}

.vira-form input:focus-visible { outline: 2px solid var(--tech-blue); outline-offset: 1px; }

.vira-send {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--r-pill);
  background: var(--grad-accent);
  color: var(--text-invert);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.vira-send:disabled { opacity: 0.5; cursor: not-allowed; }
.vira-send svg { width: 17px; height: 17px; fill: currentColor; }

.vira-consent {
  padding: 0 0.9rem 0.7rem;
  background: var(--white);
  color: var(--text-muted);
  font-size: 0.68rem;
  line-height: 1.45;
}

/* --------------------------------------------------------------------------
   4. Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 860px) {
  /* The hero art column stacks on small screens; a mascot standing in it would
     collide with the copy, so it starts docked instead. */
  .vira--hero { display: none; }
}

@media (max-width: 480px) {
  .vira.is-docked { --vira-w: 124px; }
  .vira-panel { height: min(70vh, calc(100vh - 80px)); }
  .vira-bubble { bottom: calc(clamp(12px, 3vw, 24px) + 100px); }
}

/* --------------------------------------------------------------------------
   5. Reduced motion — the character still appears and still talks, it just
   stops bobbing. Frame swaps are information, not decoration, so they stay.
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .vira__stage,
  .vira.is-docked,
  .vira-typing i { animation: none !important; }
  .vira,
  .vira-bubble,
  .vira-panel { transition: none !important; }
  /* Cursor tracking is motion too. mascot.js does not even register the
     listener under reduced motion; this is the belt to that pair of braces. */
  .vira .vira__head,
  .vira .vira__eyes,
  .vira .vira__mouth,
  .vira .vira__bodyart { transform: none !important; transition: none !important; }
}
