/* Standoff beats: poses, telegraphs, resolve pips, outcome words, the
   loss screen. Motion runs through element.animate in combat-view.mjs. */
/* A painting's measured fit (combat-portraits.mjs) about the figure's foot. */
.portrait-body > img {
  transform-origin: 50% 100%;
  translate: 0 var(--pose-drop, 0);
  scale: var(--pose-scale, 1);
}
.portrait[data-combat-art] .portrait-held-item {
  visibility: hidden;
}
.stage[data-combat="true"] .portrait,
.portrait[data-combat-art] {
  transition: none;
}
.portrait[data-pose="threaten"] .portrait-body {
  transform: translateY(-3px) scale(1.03);
}
.portrait[data-pose="guard"] .portrait-body {
  transform: translateY(2px) scale(0.97) rotate(var(--lean, 0deg));
  filter: brightness(0.95);
}
.portrait[data-pose="attack"] .portrait-body {
  transform: translateY(-2px) rotate(calc(var(--lean, 0deg) * 6));
}
.portrait[data-pose="beaten"] .portrait-body {
  transform: translateY(6%) rotate(5deg) scaleY(0.94);
  filter: grayscale(0.85) brightness(0.65);
}

.combat-dim {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 55%, #0000 30%, #06070cb3);
  opacity: 0;
}
.stage[data-combat="true"] .backdrop,
.stage[data-combat="true"] .cast {
  transform-origin: 50% 62%;
}
/* The painting recedes behind a fight (combat-backdrop.mjs sets the
   attribute and --recede-ms). weather.css keeps the opacity in its eased
   light. Reduced motion cuts to the same dim. */
.stage > .backdrop {
  transition: opacity var(--recede-ms, 0ms) ease-in-out;
}
.stage[data-recede] > .backdrop {
  opacity: 0.45;
}
@media (prefers-reduced-motion: reduce) {
  .stage > .backdrop {
    transition: none;
  }
}

/* The caption reads under the top bar, never over the place name. It keeps
   one width at each breakpoint, so a new beat never resizes or re-centres
   it; the words crossfade (combat-view.mjs) over a ghost of the last ones. */
.combat-caption {
  position: absolute;
  z-index: 5;
  top: 64px;
  left: 50%;
  translate: -50% 0;
  width: min(26em, calc(100% - 32px));
  margin: 0;
  padding: 7px 14px;
  border: 1px solid #a38b64;
  border-radius: 6px;
  background: #181925e6;
  color: var(--ink);
  font:
    15px/1.4 Georgia,
    serif;
  text-align: center;
}

.combat-caption[aria-hidden] {
  pointer-events: none;
  border-color: transparent;
  background: none;
}

.combat-telegraph {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: -1%;
  width: clamp(26px, 18%, 42px);
  aspect-ratio: 1;
  translate: -50% 0;
  color: var(--gold);
  filter: drop-shadow(0 2px 6px #000a);
}
.combat-telegraph svg {
  width: 100%;
  height: 100%;
  fill: #181925cc;
  stroke: currentColor;
  stroke-width: 4;
  stroke-linejoin: round;
}
.combat-telegraph[data-verb="guard"],
.combat-telegraph[data-verb="intercept"] {
  color: #b8d2e8;
}
/* The fighter a strike aims at takes a soft gold rim light over the
   telegraph (no target circle). */
.combat-aim .portrait-body > img {
  filter: drop-shadow(0 0 7px #e9c27ab3) drop-shadow(0 8px 14px #08091390)
    var(--tod-figure,);
  animation: combat-rim 0.3s ease-out;
}
@keyframes combat-rim {
  from {
    filter: drop-shadow(0 0 0 #e9c27a00) drop-shadow(0 8px 14px #08091390)
      var(--tod-figure,);
  }
}
/* Reduced motion swaps the lunge and recoil for an outline. */
.combat-outline .portrait-body {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 10px;
}

/* Resolve: a slim bar with rounded ends, cut into four, under each
   fighter. The fill cools from warm gold toward moon blue as it drains and
   pulses slowly at the last point. */
.combat-pips {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: -2px;
  width: clamp(56px, 54%, 112px);
  height: 4px;
  translate: -50% 0;
  border-radius: 2px;
  background: #0b0c1480;
  overflow: hidden;
  mask-image: linear-gradient(
    90deg,
    #000 calc(25% - 1.5px),
    #0000 0 25%,
    #000 0 calc(50% - 1.5px),
    #0000 0 50%,
    #000 0 calc(75% - 1.5px),
    #0000 0 75%,
    #000 0
  );
}
.combat-pips-ghost,
.combat-pips-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
}
.combat-pips-ghost {
  background: #f1e8d580;
}
.combat-pips-fill {
  background: #f0c67a;
  box-shadow: 0 0 6px #f0c67a66;
}
.combat-pips[data-resolve="2"] .combat-pips-fill {
  background: #d6cbb0;
}
.combat-pips[data-resolve="1"] .combat-pips-fill {
  background: #a9c2e6;
  animation: resolve-pulse 1.6s ease-in-out infinite;
}
@keyframes resolve-pulse {
  50% {
    opacity: 0.45;
  }
}

.combat-word {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: 18%;
  translate: -50% 0;
  white-space: nowrap;
  padding: 2px 9px;
  border-radius: 5px;
  background: #10111bd9;
  color: var(--ink);
  font:
    bold 16px/1.3 Georgia,
    serif;
  pointer-events: none;
}
.combat-word[data-tone="hit"],
.combat-word[data-tone="yield"],
.combat-word[data-tone="sent-home"],
.combat-word[data-tone="beaten"] {
  color: var(--gold);
}
.combat-word[data-tone="guard"],
.combat-word[data-tone="guarded"] {
  color: #b8d2e8;
}

/* The loss screen on the black (defeat-view.mjs): the winner's and the lost
   things' full-art cards, at most hand size and narrower to fit the row,
   with the words written under them. The row gives up height first. */
.defeat-reveal {
  --fit: calc((100cqw - 22px - var(--cards) * 10px) / var(--cards) * 1.5);
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, min(300px, 36cqh, var(--fit))) auto auto;
  justify-items: center;
  align-content: safe center;
  gap: 12px;
  padding: 56px 16px 16px;
  font-size: 0.95rem;
  text-align: center;
}
.defeat-cards {
  display: flex;
  gap: 10px;
  height: 100%;
  animation: beat-fade 600ms ease backwards;
}
.defeat-card {
  --card-height: 100cqh;
  height: 100%;
  aspect-ratio: 2 / 3;
  container-type: size;
}
.defeat-card .card[data-tier] {
  border-color: var(--tier-color);
}
.defeat-line {
  margin: 0;
  color: #fff4dc;
  font:
    1.4em/1.35 Georgia,
    serif;
  text-wrap: balance;
}
.defeat-captions .beat-caption {
  font-size: 1em;
}
/* A card too short to read leaves; a very short stage writes smaller. */
@container (max-height: 40px) {
  .defeat-card > .card {
    display: none;
  }
}
@container (max-height: 420px) {
  .defeat-reveal {
    font-size: 0.8rem;
  }
}

/* Phones keep the caption below the toolbar's logo and menu button, at
   most three short lines; the beat's full text reads in the story. */
@media (max-width: 640px) {
  .combat-caption {
    top: 60px;
    width: min(24em, calc(100% - 32px));
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
    padding: 5px 12px;
    font-size: 13px;
    line-height: 1.35;
  }
  .combat-word {
    font-size: 14px;
  }
}

/* While the beats play, the locked hand tucks down to a strip of card tops,
   so it covers neither the fighters' feet nor the impact; it rises back to
   where the player left it as the beats end. */
.stage[data-combat="true"] ~ .play-dock {
  translate: 0 calc(100% - 44px);
}
/* On the loss screen's black it leaves altogether. */
.stage[data-combat="true"]:has(.defeat-reveal) ~ .play-dock {
  translate: 0 100%;
}
.play-dock {
  transition: translate 280ms ease-in-out;
}
/* After a loss it stays away until the new place's hand is dealt. */
body[data-hand-away="true"] .play-dock {
  translate: 0 100%;
}
/* The beat card steps out of the fight too: its strip would cover the
   fighters' feet and still read the beat from before the fight. The caption
   carries the fight, and the card returns with the speech that follows. */
body .stage[data-combat="true"] ~ .dialogue.beat-stack[data-dropped="true"] {
  opacity: 0;
}

/* In battle the current exchange steps to the front slots and the other
   combatants wait behind, dimmed (phones draw combat art at one depth, so
   the rows set it). Reduced motion swaps with a fade. */
.stage[data-combat="true"] #cast[data-battle] .portrait {
  transition:
    left 0.32s ease-out,
    bottom 0.32s ease-out,
    height 0.32s ease-out;
}
#cast[data-battle] .portrait[data-battle-row="front"] {
  z-index: 5;
}
#cast[data-battle] .portrait[data-battle-row="back"] {
  z-index: 2;
}
#cast[data-battle] .portrait[data-battle-row="back"] .portrait-body {
  filter: brightness(0.7) saturate(0.8);
}
/* Phones pin the ordinary three-person scene's foreground figures to one
   side (style.css), which would stack both fighters of an exchange. In
   battle each combatant stands on its own mark from combat-view.mjs: the
   exchange at the two sides, facing each other, the rest behind the middle. */
@media (max-width: 700px) {
  #cast[data-battle] .portrait[data-battle-row] {
    left: var(--battle-x, var(--stage-x));
  }
  /* The exchange shares one scale whatever each painting's framing, so a
     strike painting swapping in never resizes its fighter. Each stays on
     screen: a mark keeps about half the widest painting from either edge.
     The margin is the same for every fighter, so the exchange keeps the
     middle that combat-view.mjs turns those waiting toward. The height
     reads the cast, not each slot's own size, since a beat's shorter cast
     (style.css) can leave a smaller slot under the cap. */
  #cast[data-battle] .portrait[data-battle-row="front"] {
    height: min(80%, 88vw);
    left: clamp(32vw, var(--battle-x), calc(100% - 32vw));
  }
  /* Stepping from the scene's close-up into the two-shot is one slow
     camera move: no push-in zoom against it (combat-view.mjs). */
  .stage[data-combat="true"] #cast[data-battle] .portrait {
    transition:
      left 0.6s ease-in-out,
      bottom 0.6s ease-in-out,
      height 0.6s ease-in-out;
  }
  /* Those waiting stand further back, smaller, between the two sides. */
  #cast[data-battle] .portrait[data-battle-row="back"] {
    height: calc(var(--stage-size) * 0.5);
    bottom: calc(var(--stage-floor) + 7%);
  }
}
@media (prefers-reduced-motion: reduce) {
  .stage[data-combat="true"] #cast[data-battle] .portrait,
  .play-dock {
    transition: none;
  }
  .combat-aim .portrait-body > img,
  .combat-pips[data-resolve="1"] .combat-pips-fill {
    animation: none;
  }
}

/* Painted effect stills (#1920), drawn over a fighter by combat-view.mjs. */
.combat-effect {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 38%;
  width: clamp(72px, 70%, 200px);
  translate: -50% -50%;
  pointer-events: none;
  opacity: 0;
}
.combat-effect[data-effect^="swipe"],
.combat-effect[data-effect^="jab"] {
  width: clamp(120px, 130%, 360px);
}
/* A swipe starts at the attacker and travels toward the target, so a fighter
   at the stage edge keeps its trail on screen. */
.combat-effect[data-effect^="swipe-right"],
.combat-effect[data-effect^="jab-right"] {
  translate: -25% -50%;
}
.combat-effect[data-effect^="swipe-left"],
.combat-effect[data-effect^="jab-left"] {
  translate: -75% -50%;
}
