/*
  Portrait character — layers that make the hero portrait feel alive.
  Works on top of the existing .portrait markup in home.css.
  All motion is driven by assets/js/portrait-character.js; this file only
  defines the layers, the resting states and the reduced-motion fallbacks.
*/

:root {
  --character-ease-out: cubic-bezier(.22, 1, .36, 1);
  --character-heart-pink: #f2a6bf;
  --character-heart-lilac: #b593d6;
  --character-bubble-bg: #ffffff;
  --character-bubble-ink: var(--color-ink, #251d2c);
}

/* Body wrapper: breathing lives here so squeeze (on .portrait-inner) can compose with it. */
.portrait .character-body {
  position: absolute;
  inset: 0;
  transform-origin: 50% 100%;
}

.character-live .character-body {
  animation: character-breathe 5.2s ease-in-out infinite;
}

@keyframes character-breathe {
  0%, 100% { transform: scale(1, 1); }
  45% { transform: scale(1.003, 1.009); }
}

.portrait-inner { transform-origin: 50% 100%; }

/* Lamp light: a soft warm highlight that follows the cursor across the felt. */
.portrait .character-light {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  mix-blend-mode: soft-light;
  background: radial-gradient(
    circle at var(--light-x, 38%) var(--light-y, 30%),
    rgba(255, 238, 214, .9) 0%,
    rgba(255, 238, 214, .35) 22%,
    rgba(255, 238, 214, 0) 46%
  );
  transition: opacity .8s var(--character-ease-out);
}

.character-live .character-light { opacity: var(--light-strength, .75); }

/* Heart: the squeezable hit area sits over the embroidered heart. */
.portrait .heart-button {
  position: absolute;
  left: 37.5%;
  top: 62%;
  width: 24%;
  height: 30%;
  padding: 0;
  border: 0;
  border-radius: 50% 50% 46% 46%;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.portrait .heart-button:focus-visible {
  outline: 2px dashed var(--color-accent, #6b3fa0);
  outline-offset: 4px;
}

/* Affordance: a soft ring pulses over the heart until it is squeezed once. */
.portrait .heart-button::before {
  content: "";
  position: absolute;
  inset: 22% 24% 30%;
  border: 2px solid rgba(255, 255, 255, .85);
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(242, 166, 191, .35);
  opacity: 0;
  animation: heart-pulse 2.6s var(--character-ease-out) 1.2s infinite;
  pointer-events: none;
}
.portrait .heart-button:hover::before { animation-duration: 1.3s; }

@keyframes heart-pulse {
  0%   { opacity: 0;  transform: scale(.8); }
  25%  { opacity: 1; }
  70%  { opacity: 0;  transform: scale(1.25); }
  100% { opacity: 0;  transform: scale(1.25); }
}

/* Label beside the heart, with a small pointer towards it. */
.portrait .heart-hint {
  position: absolute;
  left: 64%;
  top: 67%;
  padding: 7px 13px 7px 11px;
  border-radius: 999px;
  background: var(--character-bubble-bg);
  color: var(--character-bubble-ink);
  font-family: var(--font-body, "DM Sans", Arial, sans-serif);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(37, 29, 44, .06), 0 8px 22px rgba(59, 41, 69, .14);
  pointer-events: none;
  animation: heart-hint-nudge 2.6s ease-in-out 1.2s infinite;
  transition: opacity .3s ease;
}
.portrait .heart-hint::before {
  content: "←";
  margin-right: 6px;
  color: var(--color-accent, #6b3fa0);
}

@keyframes heart-hint-nudge {
  0%, 60%, 100% { transform: translateX(0); }
  75% { transform: translateX(-5px); }
}

/* Stacked layouts crop the portrait at the sides, so the label sits above the heart instead. */
@media (max-width: 1100px) {
  .portrait .heart-hint {
    left: 49.5%;
    top: 55%;
    translate: -50% 0;
    animation-name: heart-hint-bob;
  }
  .portrait .heart-hint::before { content: "↓"; }
}

@keyframes heart-hint-bob {
  0%, 60%, 100% { transform: translateY(0); }
  75% { transform: translateY(4px); }
}

.portrait.heart-found .heart-button::before { animation: none; opacity: 0; }
.portrait.heart-found .heart-hint { opacity: 0; animation: none; }
.portrait .heart-button[hidden] ~ .heart-hint { display: none; }

/* Floating hearts after a squeeze. */
.portrait .heart-burst {
  position: absolute;
  left: 49.5%;
  top: 71%;
  width: 0;
  height: 0;
  pointer-events: none;
}

.portrait .heart-burst svg {
  position: absolute;
  inset: auto;
  left: 0;
  top: 0;
  width: var(--size, 22px);
  max-width: none; /* base.css caps svg at its (zero-width) parent */
  height: var(--size, 22px);
  margin: calc(var(--size, 22px) / -2) 0 0 calc(var(--size, 22px) / -2);
  fill: var(--fill, var(--character-heart-pink));
  overflow: visible;
  will-change: transform, opacity;
}

/* Speech bubble. Positioned by JS next to her head, so it works in every layout. */
.character-bubble {
  position: absolute;
  z-index: 3;
  left: 0;
  top: 0;
  width: max-content;
  max-width: min(220px, calc(100% - 32px));
  margin: 0;
  padding: 12px 16px;
  border-radius: 18px 18px 18px 4px;
  background: var(--character-bubble-bg);
  color: var(--character-bubble-ink);
  font-family: var(--font-body, "DM Sans", Arial, sans-serif);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: -.01em;
  box-shadow: 0 1px 2px rgba(37, 29, 44, .06), 0 12px 32px rgba(59, 41, 69, .14);
  opacity: 0;
  transform: translate(-6px, 10px) scale(.92);
  transform-origin: 0 100%;
  transition: opacity .25s ease, transform .45s var(--character-ease-out);
  pointer-events: none;
}

.character-bubble.is-visible {
  opacity: 1;
  transform: none;
}

@media (max-width: 700px) {
  .character-bubble { max-width: 170px; font-size: 13px; padding: 10px 13px; }
  /* Room above her head for the bubble. */
  .page-home .hero .portrait { margin-top: 64px; }
}

/* Narrow screens: the bubble sits centred above her head, with a small tail pointing down. */
.character-bubble.is-above {
  max-width: min(260px, calc(100% - 32px));
  border-radius: 18px;
  text-align: center;
  transform: translateY(10px) scale(.92);
  transform-origin: 50% 100%;
}
.character-bubble.is-above.is-visible { transform: none; }
.character-bubble.is-above::after {
  content: "";
  position: absolute;
  left: calc(50% - 7px);
  bottom: -6px;
  width: 14px;
  height: 14px;
  border-radius: 0 0 4px 0;
  background: var(--character-bubble-bg);
  transform: rotate(45deg);
}

/* Reduced motion: no autonomous movement, no light; the bubble still answers the heart. */
@media (prefers-reduced-motion: reduce) {
  .character-live .character-body { animation: none; }
  .portrait .character-light { display: none; }
  .character-bubble { transition: opacity .2s linear; transform: none; }
  .portrait .heart-button::before { animation: none; opacity: .8; }
  .portrait .heart-hint { animation: none; }
}
