/* A loss is a deliberate recovery moment, with no automatic jump to the map. */
#battle-ending.lost {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  transform: none;
  z-index: 80;
  display: block;
  padding: 0;
  border: 0;
  border-radius: 0;
  overflow: hidden;
  color: #e6eeec;
  background: radial-gradient(ellipse at 50% 15%, #4d4c58, #19394b 45%, #0c2438 85%);
  box-shadow: none;
  text-align: center;
}
.defeat-scene {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  max-width: 1120px;
  margin: auto;
}
.defeat-content {
  overflow-y: auto;
  min-height: 0;
  padding: max(24px, env(safe-area-inset-top)) 24px 20px;
}
.defeat-header {
  max-width: 640px;
  margin: 0 auto 24px;
}
#battle-ending.lost .defeat-level {
  color: #c0c9cc;
  font:
    900 11px/1.4 'Nunito',
    sans-serif;
  letter-spacing: 1.6px;
  margin: 0 0 15px;
}

.defeat-emblem i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(#d3855850, transparent 70%);
  scale: 1.5;
}

#battle-ending.lost h2 {
  margin: 0;
  color: #ffe6b7;
  font:
    48px/1.05 'Lilita One',
    sans-serif;
  text-shadow: 0 4px 0 #5f4036;
  animation: defeat-rise 0.6s 0.2s both;
}
#battle-ending.lost .defeat-regroup {
  font:
    800 17px/1.5 'Nunito',
    sans-serif;
  color: #e4e6db;
  margin: 14px 0 8px;
  animation: defeat-rise 0.6s 0.35s both;
}
#battle-ending.lost .defeat-reason {
  display: inline-block;
  color: #b8ced5;
  font:
    700 13px/1.5 'Nunito',
    sans-serif;
  animation: defeat-rise 0.6s 0.45s both;
}
#battle-ending.lost .defeat-loot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
  color: #b6ecf3;
  font:
    900 12px/1.4 'Nunito',
    sans-serif;
}
.defeat-loot img {
  width: 20px;
  height: 24px;
}
.defeat-advice {
  max-width: 600px;
  margin: 0 auto 18px;
  animation: defeat-rise 0.6s 0.55s both;
}
#battle-ending.lost h3 {
  color: #ffe8b6;
  font:
    25px/1.1 'Lilita One',
    sans-serif;
  margin: 0 0 8px;
}
.defeat-advice p,
.defeat-tactic p {
  margin: 0 auto 8px;
  color: #c9dce0;
  font:
    700 14px/1.5 'Nunito',
    sans-serif;
  max-width: 480px;
}
#battle-ending.lost .defeat-advice > span {
  color: #91b1be;
  font:
    800 10px/1.4 'Nunito',
    sans-serif;
  letter-spacing: 0.6px;
}
.defeat-cards {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 288px;
  gap: 16px;
  justify-content: safe center;
  overflow-x: auto;
  padding: 8px 8px 14px;
  scroll-snap-type: x proximity;
  scrollbar-color: #73919b #0b273b;
  scrollbar-width: thin;
}

#battle-ending.lost h4 {
  margin: 6px 0;
  font:
    23px/1 'Lilita One',
    sans-serif;
  color: #fff0c7;
}

.defeat-tactic {
  max-width: 440px;
  margin: 0 auto;
  padding: 20px;
  border-top: 1px solid #a9c9d32b;
  animation: defeat-rise 0.6s 0.55s both;
}
.defeat-tactic > img {
  width: 36px;
  margin-bottom: 8px;
}
#battle-ending.lost .defeat-tactic button {
  background: none;
  border: 1px solid #789ca9;
  color: #e4ece9;
  font:
    16px/1 'Lilita One',
    sans-serif;
  margin-top: 12px;
}
.defeat-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  width: min(600px, 100%);
  box-sizing: border-box;
  margin: auto;
  padding: 16px 24px max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(#0c243800, #0c2438 25%);
  animation: defeat-rise 0.6s 1s both;
}
#battle-ending.lost .defeat-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 52px;
  font:
    20px/1.1 'Lilita One',
    sans-serif;
}
.defeat-actions button img {
  width: 24px;
  height: 28px;
}
#battle-ending.lost #defeat-map {
  color: #dfebeb;
  background: #2b4e60;
  border: 1px solid #7697a5;
  box-shadow: 0 3px 0 #071c30;
}
#defeat-status {
  grid-column: 1/-1;
  margin: 0;
  color: #c5dce1;
  font:
    800 12px/1.3 'Nunito',
    sans-serif;
}
#defeat-status:empty {
  display: none;
}

@keyframes defeat-rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (max-width: 600px) {
  .defeat-content {
    padding-inline: 16px;
  }
  .defeat-cards {
    grid-auto-columns: min(288px, calc(100vw - 64px));
    justify-content: start;
  }
  .defeat-cards:has(> :only-child) {
    justify-content: center;
  }
  .defeat-actions {
    padding-inline: 16px;
    gap: 10px;
  }
  #battle-ending.lost .defeat-actions button {
    font-size: 18px;
  }
}
@media (max-height: 700px) {
  .defeat-content {
    padding-top: 16px;
  }

  #battle-ending.lost h2 {
    font-size: 36px;
  }
  #battle-ending.lost .defeat-regroup {
    font-size: 14px;
    margin-top: 10px;
  }
  .defeat-header {
    margin-bottom: 18px;
  }
}
@media (prefers-reduced-motion: reduce) {
  #battle-ending.lost *,
  #battle-ending.lost *::before,
  #battle-ending.lost *::after {
    animation: none !important;
  }
}

#battle-ending.lost #defeat-title:focus {
  outline: none;
}
#battle-ending.lost .defeat-actions button {
  border-radius: 14px;
}
#battle-ending.lost .defeat-tactic button {
  padding: 10px 16px;
  border-radius: 12px;
  background: #2b4e60;
}
@media (max-height: 500px) and (orientation: landscape) and (min-width: 700px) {
  .defeat-content {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    gap: 24px;
    padding: 12px 24px;
    align-items: start;
  }
  .defeat-header {
    margin: 0;
  }
  #battle-ending.lost .defeat-level {
    font-size: 9px;
    margin-bottom: 8px;
  }

  #battle-ending.lost h2 {
    font-size: 32px;
  }
  #battle-ending.lost .defeat-regroup {
    font-size: 12px;
  }
  #battle-ending.lost .defeat-reason {
    font-size: 10px;
  }
  .defeat-advice {
    margin-bottom: 6px;
  }
  #battle-ending.lost h3 {
    font-size: 20px;
  }
  .defeat-advice p {
    font-size: 11px;
    line-height: 1.4;
  }
  #battle-ending.lost .defeat-advice > span {
    display: none;
  }
  .defeat-cards {
    grid-auto-columns: 260px;
    justify-content: start;
    gap: 12px;
  }

  #battle-ending.lost h4 {
    font-size: 20px;
  }

  .defeat-actions {
    padding-top: 10px;
    padding-bottom: 10px;
  }
}

.defeat-topline {
  display: flex;
  justify-content: flex-end;
  padding: max(12px, env(safe-area-inset-top)) 20px 0;
}
.defeat-topline:has([hidden]) {
  display: none;
}
#defeat-balance {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 14px 8px 10px;
  border: 1px solid #7ab9c16b;
  border-radius: 14px;
  background: #0c293bb3;
  box-shadow: inset 0 1px #d0f7f01a;
  text-align: left;
}
#defeat-balance[hidden] {
  display: none;
}
#defeat-balance img {
  width: 30px;
  height: 34px;
}
#defeat-balance span {
  color: #bbd4dc;
  font:
    800 10px/1.2 'Nunito',
    sans-serif;
}
#battle-ending.lost #defeat-balance strong {
  display: block;
  color: #b7f6ff;
  font:
    26px/1 'Lilita One',
    sans-serif;
  font-variant-numeric: tabular-nums;
}

.defeat-training-complete {
  grid-column: 1/-1;
  padding: 13px 8px;
  border-radius: 10px;
  background: #8de1c41a;
  color: #baf5dc;
  font:
    900 13px/1.4 'Nunito',
    sans-serif;
}
@media (max-height: 500px) and (orientation: landscape) {
  .defeat-topline {
    padding-top: 6px;
  }
  #defeat-balance {
    padding: 4px 10px;
  }
  #defeat-balance img {
    width: 24px;
    height: 26px;
  }
  #battle-ending.lost #defeat-balance strong {
    font-size: 22px;
  }
}

#battle-ending.lost .defeat-afterword {
  margin: 18px auto 4px;
  font-size: 22px;
}
.defeat-advice p {
  color: #ffe8b6;
}

@media (max-height: 700px) {
}
@media (max-height: 500px) and (orientation: landscape) {
  #battle-ending.lost .defeat-afterword {
    font-size: 17px;
    margin-top: 10px;
  }
}

#battle-ending.lost .live-training-heading,
#battle-ending.lost .live-training-progress .training-countdown {
  display: flex;
}

@media (max-height: 700px) {
}
@media (max-height: 500px) and (orientation: landscape) {
}

/* The crest is a registered 8-frame sheet, never a rotated static image. */
.defeat-emblem {
  position: relative;
  display: grid;
  place-items: center;
  width: 144px;
  height: 144px;
  margin: 0 auto 12px;
}
.defeat-crest-sprite {
  position: relative;
  width: 100%;
  height: 100%;
  opacity: 0;
  background: url('art/defeat-crest-break-v1.png') 100% 100% / 400% 200% no-repeat;
  filter: drop-shadow(0 5px 5px #061c2c66);
}
.defeat-art-ready .defeat-crest-sprite {
  opacity: 1;
  animation: defeat-crest-break 1.4s step-end both;
}
@keyframes defeat-crest-break {
  0% {
    background-position: 0% 0%;
  }
  14.28% {
    background-position: 33.333333% 0%;
  }
  28.57% {
    background-position: 66.666667% 0%;
  }
  42.86% {
    background-position: 100% 0%;
  }
  57.14% {
    background-position: 0% 100%;
  }
  71.43% {
    background-position: 33.333333% 100%;
  }
  85.71% {
    background-position: 66.666667% 100%;
  }
  100% {
    background-position: 100% 100%;
  }
}
#battle-ending.lost .defeat-afterword {
  margin: 6px auto 28px;
  text-decoration: underline;
  text-decoration-color: #e6c17a99;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
}
.defeat-cards {
  padding-bottom: 8px;
}
.defeat-overview {
  min-width: 0;
}
.defeat-header {
  margin-bottom: 16px;
}
.defeat-memorial {
  max-width: 680px;
  margin: 20px auto 24px;
}
.defeat-tombs {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 6px;
}
.defeat-tomb {
  flex: 0 0 88px;
  margin: 0;
  opacity: 0;
}
.defeat-tomb-art {
  width: 80px;
  height: 80px;
  margin: auto;
  background-image: url('art/troop-memorials-v1.png');
  background-size: 400% 400%;
  background-repeat: no-repeat;
}
.defeat-tomb figcaption {
  margin-top: 4px;
  font:
    800 10px/1.3 'Nunito',
    sans-serif;
  color: #d7e1e0;
}
#battle-ending.lost .defeat-tomb figcaption b {
  display: block;
  margin-top: 2px;
  color: #a5c5ca;
  font:
    800 9px/1.3 'Nunito',
    sans-serif;
}
.defeat-memorial blockquote {
  margin: 18px auto 0;
  max-width: 480px;
  color: #d2dcd9;
  font:
    italic 600 13px/1.6 'Nunito',
    sans-serif;
  opacity: 0;
}
.defeat-art-ready .defeat-tomb {
  animation: defeat-memorial-rise 0.6s calc(1.45s + var(--tomb-order) * 0.12s) both;
}
.defeat-art-ready .defeat-memorial blockquote {
  animation: defeat-memorial-rise 0.7s 1.9s both;
}
@keyframes defeat-memorial-rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@media (max-height: 700px) {
  .defeat-emblem {
    width: 100px;
    height: 100px;
  }
}
@media (max-height: 500px) and (orientation: landscape) and (min-width: 700px) {
  .defeat-emblem {
    width: 84px;
    height: 84px;
  }
  .defeat-memorial {
    margin: 12px auto;
  }
  .defeat-tomb {
    flex-basis: 64px;
  }
  .defeat-tomb-art {
    width: 60px;
    height: 60px;
  }
  .defeat-memorial blockquote {
    font-size: 11px;
    margin-top: 10px;
  }
  #battle-ending.lost .defeat-afterword {
    margin: 6px auto 24px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .defeat-tomb,
  .defeat-memorial blockquote {
    opacity: 1;
    transform: none;
  }
}
/* The recovery wallet is deliberately unboxed; other navigation wallets are untouched. */
#defeat-balance {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
  gap: 8px;
  position: relative;
  z-index: 6;
}
#battle-ending.lost #defeat-balance strong {
  font-size: 28px;
}
.defeat-topline {
  position: relative;
  z-index: 6;
}
.has-farewell .defeat-content,
.has-farewell .defeat-actions {
  opacity: 0;
}
.defeat-content,
.defeat-actions {
  transition: opacity 0.35s ease;
}
.defeat-art-ready .defeat-tomb,
.defeat-art-ready .defeat-memorial blockquote {
  animation: none;
  opacity: 1;
}
#battle-ending.lost .defeat-tomb figcaption b {
  color: #f2e4c8;
  font:
    800 13px/1.3 'Nunito',
    sans-serif;
}
.defeat-tomb figcaption small {
  display: block;
  color: #a9c5ca;
  font-size: 9px;
}
.defeat-farewell {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 20%, #43505a, #19394b 50%, #0c2438 90%);
}
.farewell-shield {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 144px;
  height: 144px;
  transform: translate(-50%, -50%);
  z-index: 2;
}
.defeat-art-ready .farewell-shield {
  animation: farewell-shield-rise 3.7s ease-in-out both;
}
@keyframes farewell-shield-rise {
  0%,
  58% {
    top: 50%;
    width: 144px;
    height: 144px;
  }
  100% {
    top: 70px;
    width: 100px;
    height: 100px;
  }
}
.farewell-cemetery {
  position: absolute;
  top: 23%;
  left: 50%;
  width: min(1000px, calc(100% - 32px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(var(--grave-columns), minmax(0, 1fr));
  gap: 14px 8px;
  justify-content: center;
}
.farewell-tomb {
  position: relative;
  margin: 0;
  min-width: 0;
}
.farewell-tomb-art {
  width: var(--grave-size);
  height: var(--grave-size);
  margin: auto;
  background: url('art/troop-memorials-v1.png') 0 0 / 400% 400% no-repeat;
  opacity: 0;
}
.farewell-tomb figcaption {
  opacity: 0;
  margin-top: 3px;
  color: #e8e6db;
  font:
    800 12px/1.25 'Nunito',
    sans-serif;
}
#battle-ending.lost .farewell-tomb figcaption b {
  display: block;
  font: inherit;
  color: #f3e7cd;
}
.farewell-tomb figcaption small {
  display: block;
  font-size: 9px;
  color: #a3bfc6;
}
.defeat-art-ready .farewell-tomb-art,
.defeat-art-ready .farewell-tomb figcaption {
  animation: farewell-tomb-settle 2.2s var(--tomb-start) ease-out both;
}
@keyframes farewell-tomb-settle {
  from {
    opacity: 0;
    filter: blur(3px) brightness(1.25) saturate(0.35) drop-shadow(0 0 8px #d5b49555);
  }
  50% {
    opacity: 0.65;
  }
  to {
    opacity: 1;
    filter: blur(0) brightness(0.94) saturate(0.85) drop-shadow(0 4px 4px #0008);
  }
}
.farewell-soul {
  position: absolute;
  left: calc(50% - 19px);
  top: 22px;
  width: 38px;
  height: 48px;
  opacity: 0;
  z-index: 3;
  filter: drop-shadow(0 0 9px #b2f5ef99);
}
.soul-sprite {
  display: block;
  width: 100%;
  height: 100%;
  background: url('art/farewell-ghost-wave-v3.png') 0 0 / 400% 400% no-repeat;
}
.defeat-art-ready .farewell-soul {
  animation: farewell-soul-flight 12s
    calc(var(--soul-start) + var(--soul-order) * var(--soul-stagger)) both;
}
@keyframes farewell-soul-flight {
  0% {
    opacity: 0;
    transform: translateY(18px) scale(0.55);
    animation-timing-function: cubic-bezier(0.12, 0.8, 0.2, 1);
  }
  27%,
  67% {
    opacity: 0.9;
    transform: translateY(var(--soul-hover-rise, -140px)) scale(1);
  }
  68% {
    animation-timing-function: cubic-bezier(0.55, 0, 0.85, 0.3);
  }
  88% {
    opacity: 0.7;
  }
  100% {
    opacity: 0;
    transform: translateY(calc(-100dvh - 180px)) scale(0.8);
  }
}
.defeat-art-ready .soul-sprite {
  animation: farewell-sprite-wave 1.7s steps(1)
    calc(var(--wave-start) + var(--soul-order) * var(--soul-stagger)) 2 both;
}
@keyframes farewell-sprite-wave {
  0% {
    background-position: 0% 0%;
    transform: scaleX(1);
  }
  6.25% {
    background-position: 33.33333% 0%;
    transform: scaleX(1);
  }
  12.5% {
    background-position: 66.66667% 0%;
    transform: scaleX(1);
  }
  18.75% {
    background-position: 100% 0%;
    transform: scaleX(1);
  }
  25% {
    background-position: 0% 33.33333%;
    transform: scaleX(1);
  }
  31.25% {
    background-position: 33.33333% 33.33333%;
    transform: scaleX(1);
  }
  37.5% {
    background-position: 66.66667% 33.33333%;
    transform: scaleX(-1);
  }
  43.75% {
    background-position: 100% 33.33333%;
    transform: scaleX(1);
  }
  50% {
    background-position: 0% 66.66667%;
    transform: scaleX(1);
  }
  56.25% {
    background-position: 33.33333% 66.66667%;
    transform: scaleX(1);
  }
  62.5% {
    background-position: 66.66667% 66.66667%;
    transform: scaleX(1);
  }
  68.75% {
    background-position: 100% 66.66667%;
    transform: scaleX(1);
  }
  75% {
    background-position: 0% 100%;
    transform: scaleX(-1);
  }
  81.25% {
    background-position: 33.33333% 100%;
    transform: scaleX(1);
  }
  87.5% {
    background-position: 66.66667% 100%;
    transform: scaleX(1);
  }
  93.75% {
    background-position: 100% 100%;
    transform: scaleX(1);
  }
  100% {
    background-position: 100% 100%;
    transform: scaleX(1);
  }
}
.farewell-villagers {
  position: absolute;
  bottom: 138px;
  left: 50%;
  transform: translateX(-50%);
  width: min(600px, calc(100% - 36px));
  height: 130px;
  pointer-events: none;
}
@keyframes farewell-villagers-arrive {
  to {
    opacity: 1;
  }
}
.farewell-villager {
  position: absolute;
  left: var(--crowd-x);
  top: var(--crowd-y);
  width: clamp(68px, 15vw, 94px);
  height: clamp(68px, 15vw, 94px);
  transform: translateX(-50%);
  filter: drop-shadow(0 5px 3px #0008);
  opacity: 0;
}
.defeat-art-ready .farewell-villager {
  animation: farewell-crowd-arrive 1.4s calc(var(--crowd-start) + var(--arrival-offset)) both;
}
@keyframes farewell-crowd-arrive {
  from {
    opacity: 0;
    translate: 0 12px;
  }
  to {
    opacity: 1;
    translate: 0 0;
  }
}
.villager-sprite {
  display: block;
  width: 100%;
  height: 100%;
  background: url('art/farewell-villagers-young-v2.png') 0 var(--sprite-y0) / 800% 400% no-repeat;
}
.defeat-art-ready .is-waving .villager-sprite {
  animation: farewell-crowd-wave var(--wave-duration) steps(1)
    calc(var(--crowd-wave-start) + var(--wave-offset)) both;
}
.farewell-eulogy {
  position: absolute;
  bottom: 62px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 42px));
  margin: 0;
  font:
    italic 600 14px/1.6 'Nunito',
    sans-serif;
  color: #d8e3df;
  opacity: 0;
}
.defeat-art-ready .farewell-eulogy {
  animation: farewell-villagers-arrive 0.8s var(--quote-start) both;
}
#battle-ending.lost .farewell-skip {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: none;
  border: 0;
  box-shadow: none;
  min-height: 40px;
  padding: 8px 16px;
  width: max-content;
  color: #d6e6e4;
  font:
    800 13px/1.3 'Nunito',
    sans-serif;
}
@media (max-height: 500px) and (orientation: landscape) {
  @keyframes farewell-shield-rise {
    0%,
    58% {
      top: 50%;
      width: 120px;
      height: 120px;
    }
    100% {
      top: 48px;
      width: 74px;
      height: 74px;
    }
  }
  .farewell-cemetery {
    top: 28%;
    width: min(800px, calc(100% - 60px));
    gap: 6px;
  }
  .farewell-tomb-art {
    width: min(60px, var(--grave-size));
    height: min(60px, var(--grave-size));
  }
  .farewell-tomb figcaption {
    font-size: 10px;
  }
  .farewell-tomb figcaption small {
    font-size: 8px;
  }
  .farewell-villagers {
    bottom: 68px;
    height: 46px;
    transform: translateX(-50%) scale(0.65);
    transform-origin: bottom;
  }
  .farewell-eulogy {
    bottom: 44px;
    font-size: 10px;
    line-height: 1.4;
    width: calc(100% - 60px);
  }
  #battle-ending.lost .farewell-skip {
    bottom: 2px;
    min-height: 32px;
    font-size: 11px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .defeat-content,
  .defeat-actions {
    transition: none;
  }
}
.farewell-cemetery {
  width: min(calc(var(--grave-columns) * 112px), calc(100% - 32px));
}

@media (min-height: 501px), (orientation: portrait) {
  .farewell-villagers {
    top: var(--village-top);
    bottom: auto;
  }
  .farewell-eulogy {
    top: var(--eulogy-top);
    bottom: auto;
  }
}

@media (max-height: 700px) and (orientation: portrait) {
  @keyframes farewell-shield-rise {
    0%,
    58% {
      top: 50%;
      width: 144px;
      height: 144px;
    }
    100% {
      top: 52px;
      width: 80px;
      height: 80px;
    }
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  @keyframes farewell-shield-rise {
    0%,
    58% {
      top: 50%;
      width: 120px;
      height: 120px;
    }
    100% {
      top: 30px;
      width: 52px;
      height: 52px;
    }
  }
}

.farewell-survivors {
  position: absolute;
  top: 42%;
  left: 20px;
  right: 20px;
  color: #ecdfbf;
  font:
    26px/1.3 'Lilita One',
    sans-serif;
  opacity: 0;
}
.farewell-survivors small {
  display: block;
  margin-top: 10px;
  color: #bfd5d9;
  font:
    800 14px/1.5 'Nunito',
    sans-serif;
}
.defeat-art-ready .farewell-survivors {
  animation: farewell-villagers-arrive 0.6s 2.8s both;
}
/* Compact recovery: one viewport, with horizontal memorial and offer strips. */
.defeat-scene {
  display: flex;
  flex-direction: column;
}
.defeat-topline {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 16px;
  padding: 0;
}
.defeat-content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  overflow: hidden;
  padding: max(8px, env(safe-area-inset-top)) 16px 0;
}
.defeat-overview {
  display: contents;
}
.defeat-header {
  width: 100%;
  margin: 0;
}
.defeat-emblem {
  width: 64px;
  height: 64px;
  margin: 0 auto 4px;
}
#battle-ending.lost h2 {
  font-size: 32px;
}
.defeat-memorial {
  width: 100%;
  max-width: 720px;
  margin: 0;
}
.defeat-tombs {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(var(--memorial-rows, 1), auto);
  grid-auto-columns: 64px;
  justify-content: safe center;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 3px 0;
  scrollbar-width: thin;
  scrollbar-color: #73919b transparent;
}
.defeat-tomb {
  width: 64px;
}
.defeat-tomb-art {
  width: 48px;
  height: 48px;
}
#battle-ending.lost .defeat-tomb figcaption b {
  font-size: 11px;
}
.defeat-tomb figcaption {
  margin-top: 1px;
  line-height: 1.1;
}
.defeat-tomb figcaption small {
  font-size: 8px;
}
.defeat-memorial blockquote {
  font-size: 12px;
  line-height: 1.4;
  margin: 7px auto 0;
  max-width: 560px;
}
#battle-ending.lost .defeat-regroup {
  font-size: 14px;
  line-height: 1.35;
  margin: 0;
  max-width: 550px;
}
#defeat-opportunities {
  --offer-width: 236px;
  width: 100%;
  min-width: 0;
}
.defeat-cards {
  grid-auto-columns: var(--offer-width);
  gap: 12px;
  padding: 13px 4px 8px;
  max-width: 100%;
  box-sizing: border-box;
}
#battle-ending.lost .defeat-afterword {
  font-size: 17px;
  margin: 3px auto 0;
}
.defeat-actions {
  flex: 0 0 auto;
  padding: 10px 16px max(12px, env(safe-area-inset-bottom));
  gap: 10px;
}
#battle-ending.lost .defeat-actions button {
  min-height: 46px;
  font-size: 18px;
}
.defeat-cards .horizontal-offer.is-training {
  height: 152px;
  grid-template-rows: minmax(0, 1fr) 66px;
}
.defeat-cards .horizontal-offer .horizontal-offer-action.training-in-progress {
  height: 66px;
  min-height: 66px;
  padding: 5px 8px;
}
.defeat-cards .live-training-heading {
  font-size: 13px;
}
.defeat-cards .live-training-heading img {
  width: 18px;
  height: 18px;
}
.defeat-cards .training-progress-track {
  height: 11px;
  margin: 4px 0;
}
.defeat-cards .training-countdown {
  font-size: 10px;
}
@media (max-height: 700px) {
  .defeat-content {
    gap: 6px;
    padding-top: 6px;
  }
  .defeat-emblem {
    width: 44px;
    height: 44px;
    margin-bottom: 3px;
  }
  #battle-ending.lost h2 {
    font-size: 28px;
  }
  .defeat-tomb-art {
    width: 36px;
    height: 36px;
  }
  .defeat-memorial blockquote {
    font-size: 11px;
    margin-top: 5px;
  }
  #battle-ending.lost .defeat-regroup {
    font-size: 12px;
  }
  .defeat-tactic {
    padding: 10px;
  }
  .defeat-tactic > img {
    display: none;
  }
}
@media (max-height: 500px) and (orientation: landscape) and (min-width: 700px) {
  .defeat-content {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px 20px;
    align-items: start;
    padding: 8px 24px 0;
  }
  .defeat-header {
    grid-column: 1;
    grid-row: 1;
  }
  .defeat-memorial {
    grid-column: 1;
    grid-row: 2;
  }
  .defeat-regroup {
    grid-column: 2;
    grid-row: 1;
    align-self: end;
    padding-right: 70px;
  }
  #defeat-opportunities {
    grid-column: 2;
    grid-row: 2;
  }
  .defeat-cards {
    padding-top: 6px;
  }
  .defeat-cards .horizontal-offer.is-training {
    height: 120px;
    grid-template-rows: 1fr 62px;
  }
  .defeat-actions {
    padding-top: 6px;
    padding-bottom: 8px;
  }
}
@media (prefers-reduced-motion: reduce) {
  #battle-ending.lost .defeat-content,
  #battle-ending.lost .defeat-actions {
    transition: none;
  }
}
@media (max-height: 500px) and (orientation: landscape) and (min-width: 700px) {
  .defeat-content {
    display: flex;
    gap: 4px;
    padding-top: 4px;
  }
  .defeat-emblem {
    width: 30px;
    height: 30px;
    margin-bottom: 2px;
  }
  #battle-ending.lost h2 {
    font-size: 24px;
  }
  .defeat-memorial {
    max-width: 760px;
  }
  .defeat-tombs {
    grid-template-rows: auto;
    grid-auto-columns: 60px;
    padding: 0;
  }
  .defeat-tomb-art {
    width: 28px;
    height: 28px;
  }
  .defeat-memorial blockquote {
    font-size: 10px;
    margin-top: 3px;
    max-width: 730px;
  }
  #battle-ending.lost .defeat-regroup {
    font-size: 11px;
    padding: 0;
    align-self: center;
    max-width: 700px;
  }
  .defeat-cards {
    padding-top: 5px;
    padding-bottom: 4px;
  }
  #battle-ending.lost .defeat-afterword {
    font-size: 14px;
    margin-top: 1px;
  }
}
.defeat-actions {
  margin: 0 auto;
}
#battle-ending.lost .defeat-actions button {
  padding: 8px 10px;
  font-size: 17px;
  white-space: nowrap;
}
/* Give tall loss screens presence without reintroducing vertical scrolling. */
@media (min-height: 501px), (orientation: portrait) {
  .defeat-content {
    gap: clamp(8px, 1.5dvh, 15px);
  }
  .defeat-emblem {
    width: clamp(64px, 10.5dvh, 100px);
    height: clamp(64px, 10.5dvh, 100px);
  }
  .defeat-tombs {
    grid-auto-columns: clamp(68px, 9dvh, 88px);
    gap: 8px;
  }
  .defeat-tomb {
    width: auto;
  }
  .defeat-tomb-art {
    width: clamp(48px, 8.5dvh, 78px);
    height: clamp(48px, 8.5dvh, 78px);
  }
  #battle-ending.lost .defeat-regroup {
    color: #ffe6b7;
    font:
      clamp(21px, 3.2dvh, 28px) / 1.1 'Lilita One',
      sans-serif;
    text-shadow: 0 3px 0 #5f4036;
    max-width: 680px;
  }
}
.defeat-tomb-art,
.farewell-tomb-art {
  filter: drop-shadow(0 5px 4px #000b) drop-shadow(0 1px 0 #0008);
}
@media (max-height: 500px) and (orientation: landscape) {
  #battle-ending.lost .defeat-regroup {
    color: #ffe6b7;
    font:
      20px/1.1 'Lilita One',
      sans-serif;
    text-shadow: 0 2px 0 #5f4036;
  }
}
@media (max-height: 700px) and (orientation: portrait) {
  .defeat-content {
    gap: 6px;
  }
  .defeat-emblem {
    width: 56px;
    height: 56px;
  }
  .defeat-tomb-art {
    width: 48px;
    height: 48px;
  }
}
@media (max-height: 700px) and (orientation: portrait) {
  .defeat-content {
    gap: 5px;
  }
  #battle-ending.lost .defeat-loot {
    margin-top: 4px;
    font-size: 11px;
    line-height: 1.2;
  }
  .defeat-loot img {
    width: 16px;
    height: 18px;
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  #battle-ending.lost .defeat-regroup {
    font-size: 18px;
    max-width: 760px;
  }
  #battle-ending.lost .defeat-loot {
    margin-top: 2px;
    font-size: 10px;
  }
  .defeat-loot img {
    width: 16px;
    height: 18px;
  }
}

/* Taller recovery composition: deliberate pauses between the main reading groups. */
@media (min-height: 750px) and (orientation: portrait) {
  .defeat-content {
    gap: clamp(16px, 2.8dvh, 32px);
    padding-top: 16px;
  }
  .defeat-emblem {
    width: clamp(106px, 13dvh, 148px);
    height: clamp(106px, 13dvh, 148px);
    margin-bottom: 12px;
  }
  .defeat-header {
    margin-bottom: 4px;
  }
  .defeat-memorial blockquote {
    margin-top: 18px;
    line-height: 1.6;
  }
  #battle-ending.lost .defeat-regroup {
    margin-top: 8px;
  }
  .defeat-cards {
    padding-top: 20px;
    padding-bottom: 12px;
  }
  #battle-ending.lost .defeat-afterword {
    margin-top: 8px;
  }
}
.farewell-soul {
  left: calc(50% - 32px);
  width: 64px;
  height: 84px;
  filter: drop-shadow(0 0 7px #b2f5ef55);
}
@media (max-height: 500px) and (orientation: landscape) {
  .farewell-villagers {
    height: 70px;
    bottom: 88px;
  }
  .farewell-villager {
    width: 46px;
    height: 46px;
    top: calc(var(--crowd-y) * 0.5);
  }
  .farewell-soul {
    width: 42px;
    height: 54px;
    left: calc(50% - 21px);
  }
}

.soul-sprite {
  mask-image: linear-gradient(#000 55%, transparent 96%);
}
.soul-vapor {
  position: absolute;
  inset: 0;
  background: url('art/farewell-ghost-wave-v3.png') 0 0 / 400% 400% no-repeat;
  mask-image: linear-gradient(transparent 42%, #000 70%, transparent 100%);
  filter: blur(0.6px);
  transform-origin: 50% 50%;
}
.defeat-art-ready .soul-vapor {
  animation: farewell-vapor-drift 2.7s ease-in-out calc(var(--soul-order) * -0.39s) infinite
    alternate;
}
@keyframes farewell-vapor-drift {
  from {
    transform: skewX(-9deg) scaleX(0.9) translate(-2px, 2px);
    opacity: 0.7;
  }
  to {
    transform: skewX(11deg) scaleX(1.15) translate(3px, -4px);
    opacity: 1;
  }
}
.defeat-art-ready .is-waving .villager-sprite {
  animation-name: farewell-crowd-wave;
}
@keyframes farewell-crowd-wave {
  0.000000% {
    background-position: 0% var(--sprite-y0);
  }
  2.777778% {
    background-position: 14.28571% var(--sprite-y0);
  }
  5.555556% {
    background-position: 28.57143% var(--sprite-y0);
  }
  8.333333% {
    background-position: 42.85714% var(--sprite-y0);
  }
  11.111111% {
    background-position: 57.14286% var(--sprite-y0);
  }
  13.888889% {
    background-position: 71.42857% var(--sprite-y0);
  }
  16.666667% {
    background-position: 85.71429% var(--sprite-y0);
  }
  19.444444% {
    background-position: 100% var(--sprite-y0);
  }
  22.222222% {
    background-position: 0% var(--sprite-y1);
  }
  25.000000% {
    background-position: 14.28571% var(--sprite-y1);
  }
  27.777778% {
    background-position: 28.57143% var(--sprite-y1);
  }
  30.555556% {
    background-position: 42.85714% var(--sprite-y1);
  }
  33.333333% {
    background-position: 28.57143% var(--sprite-y1);
  }
  36.111111% {
    background-position: 14.28571% var(--sprite-y1);
  }
  38.888889% {
    background-position: 0% var(--sprite-y1);
  }
  41.666667% {
    background-position: 100% var(--sprite-y0);
  }
  44.444444% {
    background-position: 85.71429% var(--sprite-y0);
  }
  47.222222% {
    background-position: 100% var(--sprite-y0);
  }
  50.000000% {
    background-position: 0% var(--sprite-y1);
  }
  52.777778% {
    background-position: 14.28571% var(--sprite-y1);
  }
  55.555556% {
    background-position: 28.57143% var(--sprite-y1);
  }
  58.333333% {
    background-position: 42.85714% var(--sprite-y1);
  }
  61.111111% {
    background-position: 28.57143% var(--sprite-y1);
  }
  63.888889% {
    background-position: 14.28571% var(--sprite-y1);
  }
  66.666667% {
    background-position: 0% var(--sprite-y1);
  }
  69.444444% {
    background-position: 100% var(--sprite-y0);
  }
  72.222222% {
    background-position: 85.71429% var(--sprite-y0);
  }
  75.000000% {
    background-position: 100% var(--sprite-y0);
  }
  77.777778% {
    background-position: 0% var(--sprite-y1);
  }
  80.555556% {
    background-position: 14.28571% var(--sprite-y1);
  }
  83.333333% {
    background-position: 28.57143% var(--sprite-y1);
  }
  86.111111% {
    background-position: 42.85714% var(--sprite-y1);
  }
  88.888889% {
    background-position: 57.14286% var(--sprite-y1);
  }
  91.666667% {
    background-position: 71.42857% var(--sprite-y1);
  }
  94.444444% {
    background-position: 85.71429% var(--sprite-y1);
  }
  97.222222% {
    background-position: 100% var(--sprite-y1);
  }
  100% {
    background-position: 100% var(--sprite-y1);
  }
}
@media (min-height: 750px) and (max-height: 899px) and (orientation: portrait) {
  .defeat-content:has(.defeat-tombs[style*='--memorial-rows:2']) {
    gap: 9px;
  }
  .defeat-content:has(.defeat-tombs[style*='--memorial-rows:2']) .defeat-emblem {
    width: 84px;
    height: 84px;
    margin-bottom: 6px;
  }
  .defeat-content:has(.defeat-tombs[style*='--memorial-rows:2']) .defeat-memorial blockquote {
    margin-top: 12px;
  }
}

@media (min-height: 900px) and (max-height: 1040px) and (orientation: portrait) {
  .defeat-content:has(.defeat-tombs[style*='--memorial-rows:2']) {
    gap: 20px;
  }
}

/* Each villager has sixteen chronological poses, stored over two atlas rows. */
.farewell-villager {
  --sprite-y0: 0%;
  --sprite-y1: 33.33333%;
  height: auto;
  aspect-ratio: 3 / 4;
}
.villager-type-2,
.villager-type-3 {
  --sprite-y0: 66.66667%;
  --sprite-y1: 100%;
}
.villager-type-1 .villager-sprite,
.villager-type-3 .villager-sprite {
  background-image: url('art/farewell-villagers-elders-v2.png');
}
.farewell-soul {
  width: 84px;
  left: calc(50% - 42px);
}
@media (max-height: 500px) and (orientation: landscape) {
  .farewell-villager {
    width: 35px;
    height: auto;
  }
  .farewell-soul {
    width: 54px;
    left: calc(50% - 27px);
  }
}

.villager-type-0.is-waving .villager-sprite,
.villager-type-2.is-waving .villager-sprite {
  animation-name: farewell-crowd-wave, farewell-young-facing;
}
@keyframes farewell-young-facing {
  0.000000% {
    transform: scaleX(1);
  }
  2.777778% {
    transform: scaleX(1);
  }
  5.555556% {
    transform: scaleX(1);
  }
  8.333333% {
    transform: scaleX(1);
  }
  11.111111% {
    transform: scaleX(-1);
  }
  13.888889% {
    transform: scaleX(-1);
  }
  16.666667% {
    transform: scaleX(-1);
  }
  19.444444% {
    transform: scaleX(-1);
  }
  22.222222% {
    transform: scaleX(-1);
  }
  25.000000% {
    transform: scaleX(-1);
  }
  27.777778% {
    transform: scaleX(-1);
  }
  30.555556% {
    transform: scaleX(1);
  }
  33.333333% {
    transform: scaleX(-1);
  }
  36.111111% {
    transform: scaleX(-1);
  }
  38.888889% {
    transform: scaleX(-1);
  }
  41.666667% {
    transform: scaleX(-1);
  }
  44.444444% {
    transform: scaleX(-1);
  }
  47.222222% {
    transform: scaleX(-1);
  }
  50.000000% {
    transform: scaleX(-1);
  }
  52.777778% {
    transform: scaleX(-1);
  }
  55.555556% {
    transform: scaleX(-1);
  }
  58.333333% {
    transform: scaleX(1);
  }
  61.111111% {
    transform: scaleX(-1);
  }
  63.888889% {
    transform: scaleX(-1);
  }
  66.666667% {
    transform: scaleX(-1);
  }
  69.444444% {
    transform: scaleX(-1);
  }
  72.222222% {
    transform: scaleX(-1);
  }
  75.000000% {
    transform: scaleX(-1);
  }
  77.777778% {
    transform: scaleX(-1);
  }
  80.555556% {
    transform: scaleX(-1);
  }
  83.333333% {
    transform: scaleX(-1);
  }
  86.111111% {
    transform: scaleX(1);
  }
  88.888889% {
    transform: scaleX(-1);
  }
  91.666667% {
    transform: scaleX(-1);
  }
  94.444444% {
    transform: scaleX(-1);
  }
  97.222222% {
    transform: scaleX(1);
  }
  100% {
    transform: scaleX(1);
  }
}
.defeat-art-ready .farewell-shield {
  animation:
    farewell-shield-rise 3.7s ease-in-out both,
    farewell-crest-recede 1.2s calc(var(--soul-start) - 1s) ease both;
}
@keyframes farewell-crest-recede {
  from {
    opacity: 1;
  }
  to {
    opacity: 0.22;
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  .farewell-soul {
    --soul-hover-rise: -94px;
  }
}
/* Two centred rows keep the final partial row balanced, including seven casualties. */
.defeat-tombs {
  display: block;
  --memorial-item-width: 64px;
}
.defeat-memorial-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  width: max-content;
  min-width: 100%;
}
.defeat-memorial-row + .defeat-memorial-row {
  margin-top: 6px;
}
.defeat-memorial-row .defeat-tomb {
  flex: 0 0 var(--memorial-item-width);
  width: var(--memorial-item-width);
}
.farewell-cemetery {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}
.farewell-tomb {
  flex: 0 0 calc((100% + 8px) / var(--grave-columns) - 8px);
}
@media (min-height: 501px), (orientation: portrait) {
  .defeat-tombs {
    --memorial-item-width: clamp(68px, 9dvh, 88px);
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  .defeat-tombs {
    --memorial-item-width: 60px;
  }
}
