/* The gold rim follows the bezel. The flame tips can extend past its edge. */
.portrait > :is(.victory-rim, .streak-flames, .streak-crown) {
  display: none;
  position: absolute;
  pointer-events: none;
  user-select: none;
}

.portrait[data-winner] > .victory-rim {
  display: block;
  inset: 2px;
  padding: 2.5px;
  border-radius: 21px;
  background: linear-gradient(135deg, #976b2a 0%, #e9c770 19%, #a4742d 41%, #fcdfa0 60%, #ae7d31 83%, #ecd088);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

.portrait:is([data-streak="warm"], [data-streak="crowned"]) > .streak-flames {
  display: block;
  left: -19px;
  top: -22px;
  width: 112px;
  height: 108px;
  background: url("./assets/streak-fire.webp") no-repeat;
  background-size: 800% 1200%;
  /* One fully lit frame for reduced motion. */
  background-position: 57.142857% 63.636364%;
}

.portrait[data-streak="crowned"] > .streak-crown {
  display: flex;
  top: -13px;
  left: 50%;
  align-items: center;
  flex-direction: column;
  transform: translateX(-50%);
  transform-origin: center bottom;
  filter: drop-shadow(0 1px 1px #49351f63);
}

.streak-crown::before {
  content: "";
  width: 33px;
  height: 18px;
  background: url("./assets/streak-crown.svg") center bottom / contain no-repeat;
  z-index: 1;
}

.streak-crown b {
  display: block;
  min-width: 25px;
  margin-top: -2px;
  padding: 0 3px;
  border: 1px solid #aa7e37;
  border-radius: 2px 2px 5px 5px;
  color: #fff5d7;
  background: linear-gradient(#745d39, #574328);
  box-shadow: inset 0 -1px #37291980;
  font: 800 14px/15px var(--mono, monospace);
  font-variant-numeric: tabular-nums;
  text-align: center;
  white-space: nowrap;
}

/* These two seats open their speech bubbles leftward, adjacent to the central crest. */
.seat:is([data-id="liang"], [data-id="etshan"]):has(.portrait[data-streak="crowned"]) .seat-tag {
  right: calc(50% + 20px);
}

@media (prefers-reduced-motion: no-preference) {
  .portrait.celebrate-win[data-winner] > .victory-rim::after {
    content: "";
    position: absolute;
    inset: -50%;
    background: conic-gradient(transparent 0deg 272deg, #ffce6a80 300deg, #fff7c8 326deg, white 337deg, transparent 347deg);
    animation: victory-highlight 880ms cubic-bezier(.25, .5, .5, 1) both;
  }

  @keyframes victory-highlight {
    0% { transform: rotate(0); opacity: 0; }
    10%, 84% { opacity: 1; }
    100% { transform: rotate(1turn); opacity: 0; }
  }

  .portrait > .streak-flames {
    /* Eight frames per row, twelve rows, thirty distinct frames per second. */
    animation: fire-column calc(3.2s / 12) steps(8, end) infinite,
               fire-row 3.2s steps(12, end) infinite;
    animation-delay: var(--streak-delay, 0ms);
  }
  @keyframes fire-column {
    from { background-position-x: 0%; }
    to { background-position-x: calc(800% / 7); }
  }
  @keyframes fire-row {
    from { background-position-y: 0%; }
    to { background-position-y: calc(1200% / 11); }
  }

  .portrait.celebrate-crown[data-streak="crowned"] > .streak-crown {
    animation: crown-engage 460ms cubic-bezier(.2, .7, .25, 1) both;
  }

  @keyframes crown-engage {
    0% { transform: translate(-50%, 6px) scale(.86, .6); opacity: 0; }
    58% { transform: translate(-50%, -2px) scale(1.04, 1.06); opacity: 1; }
    81% { transform: translate(-50%, 1px) scale(.99, .97); }
    100% { transform: translateX(-50%); opacity: 1; }
  }
}
