/* Layout only: board sprites, cells, controls and effects come from game.css. */
#versus-scene {
  /* Board: multiplier on responsive fit. D-pad: 1 = normal/endless size. */
  --versus-player-board-scale: 1;
  --versus-dpad-scale: 1;
  --versus-dpad-gap: 2vh;
  position: relative;
  display: flex;
  flex: 0 0 var(--mobile-stage-width);
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: var(--mobile-stage-width);
  height: var(--mobile-stage-height);
  box-sizing: border-box;
  text-align: center;
  z-index: 1000;
}

#versus-scene[hidden] {
  display: none;
}

#versus-scene.versus-preparing {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  visibility: hidden;
}

#versus-ghosts,
#versus-board-0 {
  flex: none;
  width: min(100vw, 50.38vh);
}

#versus-ghosts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding-top: 2vh;
}

#versus-name-1,
#versus-name-2 {
  position: absolute;
  top: 0;
  left: 8vh;
  width: 44vh;
  height: 4vh;
  font-family: var(--codex-font-family);
  font-size: 4vh;
  line-height: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  white-space: nowrap;
}

.versus-board-holder {
  --versus-unscaled-height: 79vh;
  position: relative;
  width: 100%;
  height: calc(var(--versus-unscaled-height) * var(--versus-scale, 1));
}

.versus-view {
  position: absolute;
  inset: 0 auto auto 0;
  width: 60vh;
  height: 79vh;
  transform: scale(var(--versus-scale, 1));
  transform-origin: top left;
}

#versus-ghosts .versus-board-holder {
  --versus-unscaled-height: 54vh;
}

#versus-ghosts .versus-view {
  height: 54vh;
  pointer-events: none;
}

#versus-board-0 {
  margin-top: -2vh;
  height: calc(44vh * var(--versus-scale, 1) * var(--versus-player-board-scale) + var(--versus-dpad-gap) + 22vh * var(--versus-dpad-scale) + 2vh);
}

#versus-board-0>.versus-view {
  left: 50%;
  height: 44vh;
  transform-origin: top center;
  transform: translateX(-50%) scale(calc(var(--versus-scale, 1) * var(--versus-player-board-scale)));
}

.versus-score {
  position: absolute;
  top: 0;
  left: 10vh;
  width: 40vh;
  height: 4vh;
  display: grid;
  place-items: center;
  color: #000;
  font-size: 4.2vh;
  line-height: 1;
  font-family: var(--global-font-family);
}

.versus-score.versus-score-out {
  opacity: 0.5;
}

#versus-ghosts .versus-score {
  top: 44vh;
  height: 6vh;
  font-size: 6vh;
}

.versus-score .outlined-text-front {
  color: black;
}

.versus-score .outlined-text-back {
  color: white;
  -webkit-text-stroke-color: white;
}

.versus-grid {
  position: absolute;
  left: 50%;
  transform: translate(-50%, 0);
  top: 0;
  width: 48vh;
  height: 48vh;
  display: grid;
  grid-template: repeat(8, 1fr) / repeat(8, 1fr);
  border-radius: 2vh;
  overflow: visible;
}

.versus-grid::after {
  position: absolute;
  inset: 12.5%;
  z-index: 1;
  content: '';
  pointer-events: none;
  box-shadow: 0 0 0 0.3vh rgba(0, 0, 0, 0.1);
  border-radius: 1.2vh;
}

.versus-object-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template: repeat(8, minmax(0, 1fr)) / repeat(8, minmax(0, 1fr));
  pointer-events: none;
}

#versus-dPadBox {
  position: absolute;
  left: 50%;
  top: 37vh;
  margin-top: 0;
  height: 22vh;
  transform-origin: top center;
  transform: translateX(-50%) scale(var(--versus-dpad-scale));
}

#versus-up-button {
  top: 0;
}

#versus-right-button {
  right: 0;
}

#versus-down-button {
  bottom: 0;
}

#versus-left-button {
  left: 0;
}

#versus-up-button .arrow-icon {
  transform: rotate(-90deg);
}

#versus-down-button .arrow-icon {
  transform: rotate(90deg);
}

#versus-left-button .arrow-icon {
  transform: rotate(-180deg);
}

#versus-result {
  gap: 1.2vh;
  font-size: 1.8vh;
  text-align: center;
}

#versus-result-title {
  margin: 0 0 0.5vh;
  font-size: 2.8vh;
  line-height: 1;
}

#versus-result-list {
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

#versus-result-list li {
  padding: 0.85vh 0.6vh;
  border-bottom: 0.2vh solid #d2d5dc;
}

#versus-result-list li:last-child {
  border-bottom: 0;
}

#versus-result button {
  align-self: center;
  min-width: 12vh;
  height: 4vh;
  margin-top: 0.6vh;
  font-size: 1.6vh;
}

.versus-grid.versus-game-over .character-object {
  filter: grayscale(1);
  opacity: 0.5;
}

.versus-grid.versus-game-over .star-object {
  opacity: 0;
}

.versus-grid.versus-defeated::before {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  content: 'DEFEATED';
  color: #ff3659;
  font-family: var(--global-font-family);
  /* Sample proportions relative to the shared 44vh unscaled board. */
  font-size: 7.92vh;
  line-height: 1;
  transform-origin: center;
  transform: rotate(-5deg) scale(1);
  text-shadow: .286vh .286vh #1a1521, -.286vh -.286vh #1a1521,
    -.286vh .286vh #1a1521, .286vh -.286vh #1a1521;
  background: transparent;
  border-radius: inherit;
  pointer-events: none;
}

.versus-grid.versus-defeated:not(.versus-winner)::before {
  animation: versus-defeated-in 540ms linear both;
}

.versus-grid.versus-defeated:not(.versus-winner)>.cell,
.versus-grid.versus-defeated:not(.versus-winner)>.versus-object-layer,
.versus-grid.versus-winner.versus-finish-ready>.cell,
.versus-grid.versus-winner.versus-finish-ready>.versus-object-layer {
  animation: versus-stamp-impact 180ms ease-out 360ms both;
}

@keyframes versus-defeated-in {
  0% {
    opacity: 0;
    transform: rotate(-725deg) scale(2.6);
    filter: blur(.264vh);
  }

  15% {
    opacity: 1;
  }

  48% {
    transform: rotate(-50deg) scale(1.65);
    filter: blur(0);
    animation-timing-function: ease-out;
  }

  63% {
    transform: rotate(-5deg) scale(1.5);
    animation-timing-function: ease-in;
  }

  76% {
    transform: rotate(-5deg) scale(.94);
    animation-timing-function: ease-out;
  }

  88% {
    transform: rotate(-5deg) scale(1.045);
    animation-timing-function: ease-in-out;
  }

  100% {
    opacity: 1;
    transform: rotate(-5deg) scale(1);
    filter: blur(0);
  }
}

@keyframes versus-stamp-impact {

  0%,
  100% {
    transform: translate(0, 0);
  }

  20% {
    transform: translate(0, .528vh);
  }

  45% {
    transform: translate(-.264vh, -.308vh);
  }

  70% {
    transform: translate(.176vh, .132vh);
  }
}

/* Intro is derived from the persisted match clock, never from chained timers. */
#versus-intro {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(18, 22, 35, 0.68);
  color: white;
  pointer-events: auto;
}

#versus-intro[hidden] {
  display: none;
}

#versus-profiles {
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
  width: var(--mobile-stage-width);
  padding: 2.5vh 0;
  background: rgba(23, 29, 45, 0.96);
  border-block: 0.15vh solid rgba(255, 255, 255, 0.18);
  gap: 2vh;
}

.versus-profile {
  animation: versus-popup-in 300ms ease-out both;
  width: 8vh;
  height: 8vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4vh;
  font: 1.4vh var(--codex-font-family);
}

.versus-profile img {
  width: 6vh;
  height: 6vh;
  object-fit: contain;
}

.versus-profile span {
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#versus-countdown {
  display: none;
  font: 12vh var(--global-font-family);
  text-shadow: 0 0.5vh 0 #222;
}

#versus-intro.is-counting #versus-profiles {
  display: none;
}

#versus-intro.is-counting #versus-countdown {
  display: block;
}

#versus-countdown span {
  display: block;
  animation: versus-countdown-in 1s ease-out both;
}

.versus-grid.versus-winner::before {
  content: 'WIN';
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  color: #F7B945;
  font: 8vh var(--global-font-family);
  text-shadow: 0.3vh 0.3vh #222, -0.2vh -0.2vh #222;
  pointer-events: none;
  transform: scale(1);
  visibility: hidden;
}

.versus-grid.versus-winner.versus-finish-ready::before {
  visibility: visible;
  animation: versus-win-in 540ms linear both;
}

#versus-result-dim.visible {
  animation: versus-dim-in 250ms ease-out both;
}

#versus-result-dim.visible #versus-result {
  transform-origin: center;
  animation: versus-popup-in 380ms cubic-bezier(.2, .8, .25, 1) both;
}

@keyframes versus-countdown-in {
  0% {
    opacity: 0;
    transform: scale(1.5);
  }

  20%,
  70% {
    opacity: 1;
    transform: scale(1);
  }

  100% {
    opacity: 0;
    transform: scale(.8);
  }
}

@keyframes versus-win-in {
  0% {
    opacity: 0;
    transform: scale(2.6);
    filter: blur(.264vh);
  }

  15% {
    opacity: 1;
  }

  48% {
    transform: scale(1.65);
    filter: blur(0);
    animation-timing-function: ease-out;
  }

  63% {
    transform: scale(1.5);
    animation-timing-function: ease-in;
  }

  76% {
    transform: scale(.94);
    animation-timing-function: ease-out;
  }

  88% {
    transform: scale(1.045);
    animation-timing-function: ease-in-out;
  }

  100% {
    opacity: 1;
    transform: scale(1);
    filter: blur(0);
  }
}

@keyframes versus-popup-in {
  from {
    opacity: 0;
    transform: scale(.75);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes versus-dim-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {

  .versus-grid.versus-defeated:not(.versus-winner)::before,
  .versus-grid.versus-defeated:not(.versus-winner)>.cell,
  .versus-grid.versus-defeated:not(.versus-winner)>.versus-object-layer,
  .versus-grid.versus-winner.versus-finish-ready>.cell,
  .versus-grid.versus-winner.versus-finish-ready>.versus-object-layer,
  .versus-profile,
  #versus-countdown span,
  .versus-grid.versus-winner.versus-finish-ready::before,
  #versus-result-dim.visible,
  #versus-result-dim.visible #versus-result {
    animation: none;
  }
}