/* ============================================================================
   POKÉSPIRE · Defeat Ceremony & Luminous Whiteout Return-to-Title Transition
   Inspired by Slay the Spire 2's atmospheric in-combat defeat pacing,
   tailored for POKÉSPIRE's light-porcelain & animated waterfall aesthetic.
   ============================================================================ */

/* --------------------------------------------------------------------------
   1. IN-COMBAT DEFEAT STATE (Keep both combatants visible on stage)
   -------------------------------------------------------------------------- */
.battle-screen.is-defeat-scene {
  pointer-events: none;
  user-select: none;
}

/* Gently dissolve hand dock & non-essential combat chrome */
.battle-screen.is-defeat-scene .hand-dock,
.battle-screen.is-defeat-scene .battle-field-bar,
.battle-screen.is-defeat-scene .intent-pill,
.battle-screen.is-defeat-scene .battle-lock-frame,
.battle-screen.is-defeat-scene .enemy-speech-bubble,
.battle-screen.is-defeat-scene .partner-power-badge,
.battle-screen.is-defeat-scene .power-field-badge {
  opacity: 0 !important;
  transform: translate3d(0, 26px, 0);
  transition: opacity 0.65s ease-out, transform 0.72s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none !important;
}

.battle-screen.is-defeat-scene .player-plate,
.battle-screen.is-defeat-scene .enemy-plate,
.battle-screen.is-defeat-scene .player-trainer-plate,
.battle-screen.is-defeat-scene .enemy-trainer-plate {
  opacity: 0.22;
  transition: opacity 0.9s ease;
}

/* Keep stage-area above the dimming veil? No — veil sits behind characters OR
   semi-transparently over the arena while combatants remain clearly legible.
   We elevate the stage-area smoothly and dim it via Phase 1 -> Phase 2 classes. */
.battle-screen.is-defeat-scene .stage-area {
  position: relative;
  z-index: 60;
  transition: opacity 0.95s ease, filter 0.95s ease;
}

/* Phase 1: Combatants remain clearly present on the darkened battlefield */
.battle-screen.is-defeat-scene.defeat-phase-1 .stage-area {
  opacity: 0.92;
  filter: saturate(0.76) brightness(0.88);
}

/* Phase 2: Combatants recede softly into the deep dusk behind the stats */
.battle-screen.is-defeat-scene.defeat-phase-2 .stage-area {
  opacity: 0.34;
  filter: saturate(0.45) brightness(0.58);
}

/* Player partner fainting / collapsing onto the ground pad */
.battle-screen.is-defeat-scene .partner-on-field {
  animation: defeatPartnerFaint 1.15s cubic-bezier(0.22, 0.78, 0.32, 1) forwards !important;
  transform-origin: center bottom;
}

.battle-screen.is-defeat-scene .trainer-on-field {
  filter: saturate(0.48) brightness(0.72);
  transform: translate3d(0, 6px, 0);
  transition: filter 1.1s ease, transform 1.1s ease;
}

/* Enemy remains standing intact, slightly shadowed */
.battle-screen.is-defeat-scene .enemy-sprite-2d {
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.65));
  transition: filter 1s ease;
}

.battle-screen.is-defeat-scene .ground-ring {
  opacity: 0.35;
  transition: opacity 0.9s ease;
}

@keyframes defeatPartnerFaint {
  0% {
    transform: translate3d(0, 0, 0) rotate(0deg) scale(1);
    filter: brightness(1.35) saturate(0.8);
    opacity: 1;
  }
  22% {
    transform: translate3d(-10px, -6px, 0) rotate(-6deg) scale(0.98);
    filter: brightness(0.85) saturate(0.5);
    opacity: 0.95;
  }
  58% {
    transform: translate3d(-6px, 16px, 0) rotate(-18deg) scale(0.92, 0.84);
    filter: grayscale(0.55) brightness(0.68);
    opacity: 0.88;
  }
  100% {
    transform: translate3d(-4px, 24px, 0) rotate(-24deg) scale(0.9, 0.78);
    filter: grayscale(0.72) brightness(0.6);
    opacity: 0.82;
  }
}

/* Dim top HUD subtly during defeat so it stays legible like STS2 */
body.is-defeat-ceremony #app > .run-hud.pa-live-hud,
body.is-defeat-ceremony #app > .run-hud.pa-live-hud * {
  pointer-events: none !important;
}

body.is-defeat-ceremony .run-hud {
  filter: saturate(0.65) brightness(0.82);
  transition: filter 0.9s ease, opacity 0.9s ease;
}

/* --------------------------------------------------------------------------
   2. ATMOSPHERIC VEIL & BRUSH CURTAIN (Beneath stage-area -> above stage)
   -------------------------------------------------------------------------- */
.defeat-backdrop-veil {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(ellipse 80% 55% at 50% 42%, rgba(42, 12, 24, 0.76) 0%, rgba(16, 7, 15, 0.90) 70%, rgba(9, 4, 11, 0.96) 100%);
  transition: opacity 1.15s cubic-bezier(0.22, 1, 0.36, 1), background 0.9s ease;
}

.defeat-backdrop-veil.is-active {
  opacity: 1;
}

.defeat-backdrop-veil.is-deep {
  background:
    radial-gradient(ellipse 74% 58% at 50% 45%, rgba(28, 8, 17, 0.90) 0%, rgba(13, 5, 12, 0.95) 68%, rgba(7, 3, 9, 0.98) 100%);
}

/* Vertical crimson-dusk brushstroke curtain sweep (homage to STS2 lethal veil) */
.defeat-brush-curtain {
  position: fixed;
  inset: 0;
  z-index: 55;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2vw;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.85s ease;
}

.defeat-brush-curtain.is-sweeping {
  opacity: 1;
}

.defeat-brush-curtain.is-settled {
  opacity: 0.16;
  transition: opacity 1.2s ease;
}

.defeat-brush-stroke {
  flex: 1 1 0;
  height: 54vh;
  margin: 0 -0.6vw;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(64, 10, 24, 0.12) 0%, rgba(56, 7, 20, 0.86) 24%, rgba(46, 5, 17, 0.92) 76%, rgba(64, 10, 24, 0.08) 100%);
  transform: scaleY(0.08) translate3d(0, var(--stroke-y, 0px), 0);
  opacity: 0;
  animation: defeatBrushSweep 0.95s cubic-bezier(0.18, 0.86, 0.28, 1) var(--stroke-delay, 0ms) forwards;
}

@keyframes defeatBrushSweep {
  0% {
    transform: scaleY(0.05) translate3d(0, var(--stroke-y, 0px), 0);
    opacity: 0;
  }
  45% {
    transform: scaleY(1.06) translate3d(0, var(--stroke-y, 0px), 0);
    opacity: 0.92;
  }
  100% {
    transform: scaleY(1) translate3d(0, var(--stroke-y, 0px), 0);
    opacity: 0.84;
  }
}

/* --------------------------------------------------------------------------
   3. FOREGROUND CEREMONY LAYER (Banner, Epitaph, Staggered Stats, Buttons)
   -------------------------------------------------------------------------- */
.defeat-ceremony-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--run-hud-size, 74px) + 34px) 24px 44px;
  pointer-events: auto;
  color: #f8fafc;
}

/* Top group: Ribbon banner + poetic subtitle / epitaph */
.defeat-header-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  max-width: 680px;
  width: 100%;
}

/* Parchment-porcelain scroll banner echoing STS2 while matching POKÉSPIRE craft */
.defeat-ribbon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 310px;
  max-width: min(86vw, 460px);
  padding: 13px 54px;
  background: linear-gradient(180deg, #f3e6cf 0%, #e4cfa9 52%, #d3b88d 100%);
  border: 2px solid rgba(92, 66, 40, 0.72);
  border-radius: 6px;
  box-shadow:
    0 14px 36px rgba(0, 0, 0, 0.52),
    inset 0 1px 0 rgba(255, 252, 245, 0.75),
    inset 0 -3px 8px rgba(105, 74, 42, 0.28);
  opacity: 0;
  transform: translate3d(0, -14px, 0) scale(0.94);
  transition: opacity 0.95s cubic-bezier(0.22, 1, 0.36, 1), transform 0.95s cubic-bezier(0.22, 1, 0.36, 1);
}

.defeat-ribbon::before,
.defeat-ribbon::after {
  content: '';
  position: absolute;
  top: 9px;
  width: 32px;
  height: calc(100% - 8px);
  background: linear-gradient(180deg, #d7be95 0%, #b9996b 100%);
  border: 2px solid rgba(92, 66, 40, 0.65);
  z-index: -1;
}

.defeat-ribbon::before {
  left: -24px;
  border-right: none;
  border-radius: 4px 0 0 4px;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 28% 50%);
}

.defeat-ribbon::after {
  right: -24px;
  border-left: none;
  border-radius: 0 4px 4px 0;
  clip-path: polygon(0 0, 100% 0, 72% 50%, 100% 100%, 0 100%);
}

.defeat-ribbon.is-visible {
  opacity: 1;
  transform: translate3d(0, 0, 0) scale(1);
}

.defeat-ribbon-title {
  margin: 0;
  font-family: 'Noto Sans SC', sans-serif;
  font-size: clamp(22px, 2.8vw, 30px);
  font-weight: 900;
  letter-spacing: 0.14em;
  color: #fffdf8;
  text-shadow:
    0 2px 6px rgba(42, 22, 10, 0.72),
    0 0 1px rgba(42, 22, 10, 0.9);
}

.defeat-subtitle {
  margin: 0;
  font-size: clamp(15px, 1.55vw, 18px);
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.6;
  color: #f87171;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
  opacity: 0;
  transform: translate3d(0, 8px, 0);
  transition: opacity 0.85s ease, transform 0.85s cubic-bezier(0.22, 1, 0.36, 1);
  min-height: 1.7em;
}

.defeat-subtitle.is-visible {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.defeat-subtitle .epitaph-enemy {
  color: #fde047;
  font-weight: 900;
}

.defeat-subtitle .epitaph-partner {
  color: #fca5a5;
  font-weight: 900;
}

.defeat-subtitle .epitaph-move {
  color: #fdba74;
  font-weight: 800;
}

.defeat-meta-caption {
  margin: -4px 0 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: rgba(226, 232, 240, 0.7);
  opacity: 0;
  transform: translate3d(0, 6px, 0);
  transition: opacity 0.7s ease, transform 0.7s ease;
}

.defeat-meta-caption.is-visible {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

/* --------------------------------------------------------------------------
   4. PHASE 2: STAGGERED RUN STATS LIST (Slow, deliberate STS2 reveal)
   -------------------------------------------------------------------------- */
.defeat-stats-stage {
  width: 100%;
  max-width: 480px;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 12px 0;
  cursor: default;
}

.defeat-stats-stage.is-revealing {
  cursor: pointer;
}

.defeat-stats-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px 24px;
  border-radius: 16px;
  background: rgba(18, 10, 18, 0.42);
  border: 1px solid rgba(248, 250, 252, 0.08);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transform: translate3d(0, 12px, 0);
  transition: opacity 0.7s ease, transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

.defeat-stats-card.is-open {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.defeat-stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 5px 4px;
  font-size: 15px;
  font-weight: 600;
  color: rgba(248, 250, 252, 0.92);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.75);
  opacity: 0;
  transform: translate3d(0, 12px, 0);
  transition: opacity 0.62s cubic-bezier(0.22, 1, 0.36, 1), transform 0.62s cubic-bezier(0.22, 1, 0.36, 1);
}

.defeat-stat-row.is-revealed {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.defeat-stat-left {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.defeat-stat-ico {
  width: 22px;
  height: 22px;
  object-fit: contain;
  image-rendering: pixelated;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.5));
}

.defeat-stat-label {
  color: rgba(241, 245, 249, 0.92);
}

.defeat-stat-val {
  color: #fde68a;
  font-family: 'Barlow Condensed', 'Noto Sans SC', sans-serif;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.defeat-stat-val.is-neutral {
  color: rgba(226, 232, 240, 0.78);
  font-family: 'Noto Sans SC', sans-serif;
  font-size: 14px;
  font-weight: 700;
}

.defeat-stat-divider {
  height: 1px;
  margin: 4px 0;
  background: linear-gradient(90deg, transparent 0%, rgba(248, 250, 252, 0.26) 20%, rgba(248, 250, 252, 0.26) 80%, transparent 100%);
  opacity: 0;
  transform: scaleX(0.6);
  transition: opacity 0.6s ease, transform 0.65s cubic-bezier(0.22, 1, 0.36, 1);
}

.defeat-stat-divider.is-revealed {
  opacity: 1;
  transform: scaleX(1);
}

.defeat-total-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 6px 4px 2px;
  opacity: 0;
  transform: translate3d(0, 12px, 0);
  transition: opacity 0.7s cubic-bezier(0.22, 1, 0.36, 1), transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

.defeat-total-row.is-revealed {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.defeat-total-label {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #f8fafc;
}

.defeat-total-score {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 32px;
  font-weight: 800;
  color: #fde047;
  text-shadow: 0 2px 14px rgba(250, 204, 21, 0.38);
  letter-spacing: 0.04em;
}

.defeat-settlement-note {
  margin-top: 6px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: rgba(203, 213, 225, 0.85);
  min-height: 20px;
  opacity: 0;
  transition: opacity 0.55s ease;
}

.defeat-settlement-note.is-revealed {
  opacity: 1;
}

.defeat-settlement-note .unlock-highlight {
  color: #86efac;
  margin-left: 8px;
}

/* --------------------------------------------------------------------------
   5. ACTION BUTTONS (Hex-chamfered STS2-inspired tactile buttons)
   -------------------------------------------------------------------------- */
.defeat-actions-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 52px;
  opacity: 0;
  transform: translate3d(0, 14px, 0);
  pointer-events: none;
  transition: opacity 0.75s cubic-bezier(0.22, 1, 0.36, 1), transform 0.75s cubic-bezier(0.22, 1, 0.36, 1);
}

.defeat-actions-bar.is-visible {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  pointer-events: auto;
}

.defeat-btn[hidden],
.defeat-stats-stage[hidden] {
  display: none !important;
}

.defeat-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 156px;
  height: 44px;
  padding: 0 30px;
  border-radius: 10px;
  font-family: 'Noto Sans SC', sans-serif;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition:
    transform 0.2s cubic-bezier(0.22, 1, 0.36, 1),
    filter 0.2s ease,
    box-shadow 0.2s ease,
    background 0.2s ease;
}

.defeat-btn:hover:not(:disabled) {
  transform: translate3d(0, -2px, 0);
  filter: brightness(1.08);
}

.defeat-btn:active:not(:disabled) {
  transform: translate3d(0, 0, 0) scale(0.98);
}

.defeat-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

/* Phase 1: Cool slate-teal "继续" button */
.defeat-btn-continue {
  color: #f8fafc;
  background: linear-gradient(180deg, #3b6f7b 0%, #274c56 100%);
  border: 1.5px solid rgba(148, 210, 224, 0.55);
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

/* Phase 2: Warm crimson-rose "主菜单" button */
.defeat-btn-menu {
  color: #fff7ed;
  background: linear-gradient(180deg, #9a4a44 0%, #6f302c 100%);
  border: 1.5px solid rgba(252, 165, 165, 0.48);
  box-shadow:
    0 10px 24px rgba(0, 0, 0, 0.48),
    inset 0 1px 0 rgba(255, 237, 213, 0.28);
}

.defeat-btn-secondary {
  min-width: 128px;
  padding: 0 22px;
  color: rgba(241, 245, 249, 0.9);
  background: rgba(30, 41, 59, 0.55);
  border: 1.5px solid rgba(148, 163, 184, 0.35);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
}

/* --------------------------------------------------------------------------
   6. LUMINOUS WHITEOUT TRANSITION TO ANIMATED MAIN MENU
   -------------------------------------------------------------------------- */
#spire-whiteout-transition {
  position: fixed;
  inset: 0;
  z-index: 2600;
  pointer-events: none;
  opacity: 0;
  background:
    radial-gradient(ellipse 85% 75% at 50% 45%, #ffffff 0%, #f7fbff 55%, #edf4fc 100%);
  will-change: opacity;
}

#spire-whiteout-transition.is-covering {
  pointer-events: auto;
  opacity: 1;
  transition: opacity 0.78s cubic-bezier(0.32, 0.04, 0.22, 1);
}

#spire-whiteout-transition.is-revealing {
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.88s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Gentle entrance for title UI as the whiteout veil lifts */
body.is-whiteout-title-enter #app[data-screen="title"] {
  animation: whiteoutTitleReveal 0.95s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes whiteoutTitleReveal {
  0% {
    opacity: 0;
    transform: translate3d(0, 12px, 0) scale(0.992);
  }
  100% {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

/* --------------------------------------------------------------------------
   7. REDUCED MOTION SUPPORT
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .battle-screen.is-defeat-scene .partner-on-field,
  .defeat-brush-stroke,
  body.is-whiteout-title-enter #app[data-screen="title"] {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
  }

  .defeat-backdrop-veil,
  .defeat-ribbon,
  .defeat-subtitle,
  .defeat-meta-caption,
  .defeat-stats-card,
  .defeat-stat-row,
  .defeat-stat-divider,
  .defeat-total-row,
  .defeat-actions-bar,
  #spire-whiteout-transition {
    transition-duration: 0.12s !important;
  }
}
