:root {
  --battle-panel: rgba(7, 13, 22, .90);
  --battle-border: rgba(153, 204, 255, .18);
  --battle-glow: rgba(88, 176, 255, .28);
  --battle-card-bg: rgba(255, 255, 255, .035);
  --battle-card-border: rgba(255, 255, 255, .10);
}

* {
  box-sizing: border-box;
}

.battle-page {
  min-height: 100dvh;
  color: #eef6ff;
  overflow-x: hidden;
}

/* `hidden` is application state and must beat component display rules. */
.battle-page [hidden] {
  display: none !important;
}

.battle-page .bg-wrap {
  position: fixed;
  inset: 0;
  z-index: -2;
  overflow: hidden;
  background: #05090f;
}

.battle-page .bg-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(2, 6, 12, .58), rgba(2, 6, 12, .84));
}

.battle-page .bg-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.battle-header-inner,
.battle-header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.battle-header-actions {
  justify-content: flex-end;
}

.battle-page .brand img {
  width: auto;
  height: 42px;
}

.battle-main {
  width: min(1440px, 94vw);
  margin: 20px auto 50px;
  display: grid;
  gap: 16px;
  min-width: 0;
}

.battle-panel,
.player-zone {
  min-width: 0;
  border: 1px solid var(--battle-border);
  border-radius: 18px;
  background: var(--battle-panel);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
  backdrop-filter: blur(12px);
}

.battle-panel {
  padding: 18px;
}

.battle-intro {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
}

.battle-kicker {
  margin: 0 0 5px;
  color: #8dcaff;
  font-size: .75rem;
  font-weight: 900;
  letter-spacing: .14em;
}

.battle-intro h1,
.section-head h2 {
  margin: 0;
}

.battle-intro p {
  max-width: 760px;
}

.battle-status {
  color: rgba(235, 245, 255, .75);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

/* -------------------------------------------------------------------------
   Deck chooser
   ------------------------------------------------------------------------- */

.deck-builder {
  min-width: 0;
  overflow: hidden;
}

.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 10px;
  width: 100%;
  max-height: min(52svh, 680px);
  padding: 3px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.deck-card,
.hand-card {
  position: relative;
  min-width: 0;
  border: 1px solid var(--battle-card-border);
  border-radius: 13px;
  background: var(--battle-card-bg);
  color: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: inset 3px 0 0 var(--tier, transparent);
}

.deck-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  width: 100%;
  padding: 7px;
  overflow: hidden;
}

.deck-card > span {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

.deck-card b,
.hand-card b {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-card small,
.hand-card small {
  color: #9bc8e8;
}

.deck-card em,
.hand-card em {
  color: rgba(235, 245, 255, .68);
  font-size: .78rem;
  font-style: normal;
  line-height: 1.25;
}

.deck-card.selected,
.hand-card.selected {
  border-color: rgba(120, 212, 255, .85);
  outline: 2px solid #78d4ff;
  outline-offset: -2px;
  background: rgba(64, 169, 255, .12);
}

.deck-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.deck-actions .muted {
  min-width: 0;
}

.tier-1 { --tier: #f8cf57; }
.tier-2 { --tier: #bc7aff; }
.tier-3 { --tier: #66e0c0; }
.tier-4 { --tier: #68aefc; }

/* -------------------------------------------------------------------------
   Card art shared by deck and hand
   ------------------------------------------------------------------------- */

.battle-art {
  position: relative;
  width: 72px;
  max-width: 100%;
  aspect-ratio: 960 / 1240;
  overflow: hidden;
  border-radius: 8px;
  background: #101b29;
}

.battle-art img {
  position: absolute;
  inset: 0 auto auto 0;
  width: 200%;
  max-width: none;
  height: 100%;
  object-fit: fill;
}

.battle-art.fallback {
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 900;
}

/* -------------------------------------------------------------------------
   Lobby / matchmaking
   ------------------------------------------------------------------------- */

.matchmaking-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid rgba(104, 174, 252, .22);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(68, 169, 255, .10), rgba(255, 255, 255, .025));
}

.matchmaking-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.matchmaking-title-row {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.matchmaking-copy strong {
  font-size: 1.02rem;
}

.matchmaking-copy > span,
.matchmaking-status {
  color: rgba(235, 245, 255, .70);
  font-size: .84rem;
  line-height: 1.35;
}

.matchmaking-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.matchmaking-status {
  grid-column: 1 / -1;
  min-height: 1.2em;
}

.matchmaking-status:not(:empty)::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: #78d4ff;
  box-shadow: 0 0 14px rgba(88, 190, 255, .7);
  animation: matchmakingPulse 1.2s ease-in-out infinite;
}

.matchmaking-queue-count {
  flex: 0 0 auto;
  padding: 4px 8px;
  border: 1px solid rgba(120, 212, 255, .26);
  border-radius: 999px;
  background: rgba(88, 176, 255, .10);
  color: #a9ddff;
  font-size: .72rem;
  font-weight: 800;
  white-space: nowrap;
}

.lobby-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 14px;
  color: rgba(235, 245, 255, .50);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .10em;
  text-transform: uppercase;
}

.lobby-divider::before,
.lobby-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, .08);
}

.lobby-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.join-row {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.join-row input {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.room-code-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-top: 12px;
}

.room-code-wrap strong {
  min-width: 0;
  font-size: 1.35rem;
  letter-spacing: .14em;
  overflow-wrap: anywhere;
}

.connection-badge {
  padding: 5px 9px;
  border: 1px solid rgba(255, 110, 110, .30);
  border-radius: 999px;
  background: rgba(255, 110, 110, .12);
  font-size: .75rem;
  font-weight: 900;
  transition: color .2s ease, background-color .2s ease, border-color .2s ease;
}

.connection-badge.checking {
  animation: reconnectPulse 1.35s ease-in-out infinite;
}

.connection-badge.offline {
  animation: none;
}

.connection-badge.online {
  border-color: rgba(80, 220, 155, .35);
  background: rgba(80, 220, 155, .12);
  color: #9dffd1;
}

/* -------------------------------------------------------------------------
   Battle board
   ------------------------------------------------------------------------- */

.battle-board {
  display: grid;
  grid-template-rows: auto minmax(180px, .8fr) auto;
  gap: 12px;
  min-width: 0;
}

.player-zone {
  padding: 14px;
}

.fighter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.fighter-head > div:first-child {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.fighter-resources {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.played-row {
  min-height: 24px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.battle-center {
  min-height: 220px;
}

.turn-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.resolution-queue {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  padding: 12px 0;
}

.queue-chip {
  padding: 6px 8px;
  border-radius: 9px;
  background: rgba(90, 190, 255, .12);
  font-size: .78rem;
}

.queue-chip.enemy {
  background: rgba(255, 115, 115, .11);
}

.battle-log {
  display: grid;
  gap: 4px;
  max-height: 130px;
  overflow: auto;
  color: rgba(235, 245, 255, .75);
  font-size: .83rem;
}

.hand-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0 8px;
}

.battle-hand {
  display: flex;
  gap: 10px;
  min-width: 0;
  padding: 4px 2px 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
}

.hand-card {
  flex: 0 0 260px;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 10px;
  padding: 7px;
  scroll-snap-align: center;
}

.hand-card .battle-art {
  width: 82px;
}

.hand-card-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hand-card i {
  color: #f6cb69;
  font-size: .72rem;
  font-style: normal;
}

.hand-card:disabled {
  cursor: default;
}

.turn-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.battle-lock {
  min-width: 150px;
}

.btn-danger {
  border-color: rgba(255, 104, 104, .42);
  background: rgba(190, 48, 48, .18);
  color: #ffd7d7;
}

.btn-danger:hover:not(:disabled) {
  border-color: rgba(255, 118, 118, .72);
  background: rgba(210, 55, 55, .28);
}

.battle-exit-action {
  margin-left: auto;
}

.battle-dialog {
  max-width: 420px;
  padding: 22px;
  border: 1px solid var(--battle-border);
  border-radius: 16px;
  background: #0a1320;
  color: #eef6ff;
}

.battle-dialog::backdrop {
  background: rgba(0, 0, 0, .72);
}

.battle-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* -------------------------------------------------------------------------
   Motion
   ------------------------------------------------------------------------- */

@keyframes battleCardDeal {
  0% { opacity: 0; transform: translate3d(18px, 18px, 0) scale(.92) rotate(1.5deg); }
  65% { opacity: 1; transform: translate3d(-2px, -3px, 0) scale(1.015) rotate(-.3deg); }
  100% { opacity: 1; transform: none; }
}

@keyframes battleSelected {
  0% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-7px) scale(1.025); }
  100% { transform: translateY(-4px) scale(1.015); }
}

@keyframes battleHit {
  0%, 100% { transform: translateX(0); filter: none; }
  20% { transform: translateX(-7px); filter: brightness(1.35); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

@keyframes battleHeal {
  0% { box-shadow: 0 18px 50px rgba(0, 0, 0, .28); }
  45% { box-shadow: 0 0 0 2px rgba(90, 255, 170, .35), 0 0 34px rgba(90, 255, 170, .32); }
  100% { box-shadow: 0 18px 50px rgba(0, 0, 0, .28); }
}

@keyframes resourceHit {
  0% { transform: scale(1); color: inherit; }
  35% { transform: scale(1.35); color: #ff8c8c; text-shadow: 0 0 16px rgba(255, 80, 80, .8); }
  100% { transform: scale(1); color: inherit; }
}

@keyframes resourceGain {
  0% { transform: scale(1); }
  40% { transform: scale(1.3); color: #9dffd1; text-shadow: 0 0 14px rgba(80, 240, 160, .65); }
  100% { transform: scale(1); }
}

@keyframes resourceShield {
  0% { transform: scale(1); }
  45% { transform: scale(1.3); color: #8fdcff; text-shadow: 0 0 16px rgba(80, 190, 255, .8); }
  100% { transform: scale(1); }
}

@keyframes resourceEnergy {
  0% { transform: scale(1); }
  45% { transform: scale(1.32); color: #ffd66e; text-shadow: 0 0 16px rgba(255, 205, 80, .85); }
  100% { transform: scale(1); }
}

@keyframes queueEnter {
  0% { opacity: 0; transform: translateY(-8px) scale(.9); }
  70% { opacity: 1; transform: translateY(2px) scale(1.035); }
  100% { opacity: 1; transform: none; }
}

@keyframes queueFlash {
  0%, 100% { box-shadow: none; }
  40% { box-shadow: inset 0 0 28px rgba(92, 190, 255, .14); }
}

@keyframes roundPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.4); color: #9edcff; text-shadow: 0 0 18px rgba(70, 180, 255, .8); }
  100% { transform: scale(1); }
}

@keyframes roundTransition {
  0% { transform: translateY(0); }
  35% { transform: translateY(-2px); }
  100% { transform: translateY(0); }
}

@keyframes battleLogEnter {
  from { opacity: 0; transform: translateX(-6px); }
  to { opacity: 1; transform: none; }
}

@keyframes gameOverEnter {
  0% { opacity: 0; transform: translateY(18px) scale(.9); }
  70% { opacity: 1; transform: translateY(-3px) scale(1.025); }
  100% { opacity: 1; transform: none; }
}

@keyframes battleBackdropIn {
  from { background: rgba(0, 0, 0, 0); }
  to { background: rgba(0, 0, 0, .72); }
}

@keyframes reconnectPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 190, 75, 0); }
  50% { box-shadow: 0 0 0 5px rgba(255, 190, 75, .12), 0 0 20px rgba(255, 190, 75, .18); }
}

@keyframes matchmakingPulse {
  0%, 100% { opacity: .45; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1.18); }
}

.hand-card {
  transform-origin: 50% 100%;
  animation: battleCardDeal .44s cubic-bezier(.2, .8, .25, 1) both;
  animation-delay: calc(var(--card-index, 0) * 55ms);
  transition: transform .18s ease, border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
}

.hand-card:hover:not(:disabled) {
  transform: translateY(-4px);
}

.hand-card.selected {
  animation: battleSelected .28s ease-out both;
  transform: translateY(-4px) scale(1.015);
  box-shadow: inset 3px 0 0 var(--tier, transparent), 0 8px 24px rgba(68, 183, 255, .20);
}

.deck-card {
  transition: transform .16s ease, border-color .16s ease, background-color .16s ease, box-shadow .16s ease;
}

.deck-card:hover {
  transform: translateY(-2px);
}

.deck-card.selected {
  transform: translateY(-2px) scale(1.01);
}

.queue-chip {
  animation: queueEnter .34s cubic-bezier(.2, .8, .25, 1) both;
  animation-delay: calc(var(--queue-index, 0) * 90ms);
}

.queue-activate {
  animation: queueFlash .85s ease-out;
}

.battle-log > div {
  animation: battleLogEnter .26s ease-out both;
  animation-delay: calc(var(--log-index, 0) * 25ms);
}

.battle-hit { animation: battleHit .62s ease-out; }
.battle-heal { animation: battleHeal .68s ease-out; }

.resource-hit,
.resource-gain,
.resource-shield,
.resource-energy,
.round-pop {
  display: inline-block;
  transform-origin: center;
}

.resource-hit { animation: resourceHit .58s ease-out; }
.resource-gain { animation: resourceGain .58s ease-out; }
.resource-shield { animation: resourceShield .62s ease-out; }
.resource-energy { animation: resourceEnergy .62s ease-out; }
.round-pop { animation: roundPop .70s ease-out; }
.round-transition { animation: roundTransition .76s ease-out; }

.battle-dialog.game-over-enter[open] {
  animation: gameOverEnter .42s cubic-bezier(.2, .8, .25, 1) both;
}

.battle-dialog.game-over-enter::backdrop {
  animation: battleBackdropIn .32s ease both;
}

/* -------------------------------------------------------------------------
   Responsive
   ------------------------------------------------------------------------- */

@media (max-width: 800px) {
  .battle-main {
    width: calc(100% - 12px);
    margin: 8px auto 28px;
    gap: 10px;
  }

  .battle-header-inner {
    width: 100%;
    min-width: 0;
    padding-inline: 10px;
  }

  .battle-page .brand {
    min-width: 0;
    max-width: calc(100% - 120px);
  }

  .battle-page .brand img {
    height: 34px;
    flex: 0 0 auto;
  }

  .battle-page .brand .title {
    font-size: .95rem;
  }

  .battle-page .brand .subtitle {
    font-size: .72rem;
  }

  .battle-header-actions {
    flex: 0 0 auto;
    gap: 6px;
    flex-wrap: nowrap;
  }

  .battle-header-actions .btn {
    min-height: 36px;
    padding: 7px 9px;
    white-space: nowrap;
  }

  .battle-intro {
    display: block;
    padding: 14px;
  }

  .battle-intro h1 {
    font-size: clamp(1.35rem, 7vw, 1.8rem);
    line-height: 1.05;
  }

  .battle-intro p {
    margin-bottom: 0;
    font-size: .9rem;
    line-height: 1.4;
  }

  .section-head {
    align-items: flex-start;
    margin-bottom: 10px;
  }

  .section-head h2 {
    font-size: 1.12rem;
  }

  /* Two-column chooser on normal phones/tablets. */
  .deck-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 54dvh;
    gap: 7px;
    padding: 2px;
  }

  .deck-card {
    grid-template-columns: 54px minmax(0, 1fr);
    gap: 7px;
    padding: 6px;
  }

  .deck-card .battle-art {
    width: 54px;
  }

  .deck-card b {
    font-size: .82rem;
  }

  .deck-card small,
  .deck-card em {
    font-size: .68rem;
  }

  .deck-actions {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .deck-actions .btn {
    width: 100%;
  }

  .lobby-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .join-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    width: 100%;
  }

  .room-code-wrap {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    width: 100%;
  }

  .battle-board {
    grid-template-rows: auto auto auto;
    gap: 8px;
  }

  .player-zone {
    padding: 10px;
  }

  .fighter-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
  }

  .fighter-head > div:first-child {
    gap: 8px;
  }

  .fighter-head > div:first-child > span {
    color: rgba(235, 245, 255, .72);
    font-size: .78rem;
  }

  .fighter-head > div:first-child strong {
    font-size: 1rem;
    white-space: nowrap;
  }

  .fighter-resources {
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: nowrap;
    font-size: .78rem;
    white-space: nowrap;
  }

  .played-row {
    min-height: 0;
    gap: 4px;
  }

  .battle-center {
    min-height: 0;
    padding: 10px;
  }

  .turn-bar {
    align-items: flex-start;
    gap: 8px;
    padding-bottom: 7px;
    font-size: .78rem;
  }

  .turn-bar > :last-child {
    text-align: right;
    line-height: 1.25;
  }

  .resolution-queue {
    gap: 4px;
    padding: 7px 0;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: thin;
  }

  .queue-chip {
    flex: 0 0 auto;
    padding: 5px 7px;
    font-size: .70rem;
  }

  .battle-log {
    max-height: 72px;
    font-size: .72rem;
    line-height: 1.25;
  }

  .hand-head {
    margin: 8px 0 5px;
    font-size: .78rem;
  }

  .hand-head > :last-child {
    text-align: right;
  }

  .battle-hand {
    width: calc(100% + 20px);
    max-width: none;
    margin-inline: -10px;
    padding: 3px 10px 7px;
    gap: 7px;
    scroll-padding-inline: 10px;
    scroll-snap-type: x mandatory;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .hand-card {
    flex-basis: min(76vw, 245px);
    max-width: min(76vw, 245px);
    grid-template-columns: 70px minmax(0, 1fr);
    gap: 8px;
    padding: 6px;
  }

  .hand-card .battle-art {
    width: 70px;
  }

  .hand-card b { font-size: .84rem; }
  .hand-card small { font-size: .72rem; }
  .hand-card em { font-size: .70rem; line-height: 1.18; }
  .hand-card i { font-size: .66rem; }

  .turn-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 7px;
    position: sticky;
    bottom: 0;
    z-index: 4;
    margin: 6px -10px -10px;
    padding: 8px 10px max(8px, env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(7, 13, 22, .45), rgba(7, 13, 22, .98) 36%);
    backdrop-filter: blur(8px);
  }

  .turn-actions .btn {
    min-width: 0;
    min-height: 42px;
  }

  .battle-lock {
    width: 100%;
    min-width: 0;
  }

  .battle-exit-action {
    margin-left: 0;
  }

  .turn-actions .battle-exit-action:not([hidden]) {
    grid-column: 1 / -1;
    width: 100%;
  }
}

@media (max-width: 620px) {
  .matchmaking-box {
    grid-template-columns: 1fr;
    gap: 9px;
    padding: 11px;
  }

  .matchmaking-actions {
    justify-content: stretch;
  }

  .matchmaking-actions .btn {
    flex: 1;
  }

  .matchmaking-status {
    grid-column: 1;
  }
}

@media (max-width: 520px) {
  .battle-main {
    width: calc(100% - 8px);
    margin-top: 5px;
    gap: 7px;
  }

  .battle-panel,
  .player-zone {
    border-radius: 12px;
  }

  .battle-panel {
    padding: 10px;
  }

  .battle-page .brand {
    max-width: calc(100% - 105px);
  }

  .battle-page .brand img {
    height: 30px;
  }

  .battle-page .brand .title {
    font-size: .86rem;
  }

  .battle-page .brand .subtitle {
    display: none;
  }

  .battle-header-actions .btn {
    padding-inline: 7px;
    font-size: .76rem;
  }

  .lang-switch button {
    min-width: 30px;
    padding-inline: 5px;
  }

  .battle-intro {
    padding: 11px;
  }

  .battle-intro .battle-kicker {
    font-size: .65rem;
  }

  /* One-column chooser only on genuinely narrow screens. */
  .deck-grid {
    grid-template-columns: minmax(0, 1fr);
    max-height: 58dvh;
  }

  .deck-card {
    grid-template-columns: 62px minmax(0, 1fr);
  }

  .deck-card .battle-art {
    width: 62px;
  }

  .join-row {
    grid-template-columns: 1fr;
  }

  .join-row .btn {
    width: 100%;
  }

  .room-code-wrap {
    grid-template-columns: 1fr auto;
  }

  .room-code-wrap > span {
    grid-column: 1 / -1;
  }

  .fighter-head {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .fighter-resources {
    justify-content: flex-start;
    gap: 10px;
  }

  .battle-opponent .fighter-head {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .battle-opponent .fighter-resources {
    justify-content: flex-end;
    gap: 7px;
    font-size: .72rem;
  }

  .battle-center {
    padding: 8px;
  }

  .turn-bar {
    font-size: .73rem;
  }

  .battle-log {
    max-height: 60px;
  }

  .hand-card {
    flex-basis: min(82vw, 236px);
    max-width: min(82vw, 236px);
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .hand-card .battle-art {
    width: 64px;
  }

  .turn-actions {
    grid-template-columns: 1fr 92px;
  }

  .battle-dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .battle-dialog-actions .btn {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .matchmaking-title-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }
}

@media (max-width: 380px) {
  .battle-header-actions .btn {
    display: none;
  }

  .battle-page .brand {
    max-width: calc(100% - 74px);
  }

  .fighter-resources {
    gap: 6px;
    font-size: .70rem;
  }

  .battle-opponent .fighter-head {
    grid-template-columns: 1fr;
  }

  .battle-opponent .fighter-resources {
    justify-content: flex-start;
  }

  .hand-card {
    flex-basis: 86vw;
    max-width: 86vw;
  }
}

/* Avoid hover states sticking after a touch. */
@media (hover: none) {
  .hand-card:hover:not(:disabled),
  .deck-card:hover {
    transform: none;
  }

  .hand-card.selected {
    transform: translateY(-3px) scale(1.01);
  }

  .deck-card.selected {
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .hand-card,
  .hand-card.selected,
  .deck-card,
  .queue-chip,
  .queue-activate,
  .battle-log > div,
  .battle-hit,
  .battle-heal,
  .resource-hit,
  .resource-gain,
  .resource-shield,
  .resource-energy,
  .round-pop,
  .round-transition,
  .connection-badge,
  .matchmaking-status:not(:empty)::before,
  .battle-dialog.game-over-enter[open],
  .battle-dialog.game-over-enter::backdrop {
    animation: none !important;
    transition: none !important;
    transform: none !important;
  }
}


/* Card-by-card turn resolution ------------------------------------------- */
.resolution-stage {
  position: relative;
  min-height: 230px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  align-content: center;
  gap: 10px;
  margin: 8px 0 12px;
  padding: 14px;
  overflow: hidden;
  border: 1px solid rgba(140, 205, 255, .18);
  border-radius: 15px;
  background:
    radial-gradient(circle at 50% 30%, rgba(96, 168, 230, .10), transparent 56%),
    rgba(3, 9, 16, .68);
}

.resolution-owner {
  font-size: .70rem;
  font-weight: 900;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #a9ddff;
}

.resolution-enemy .resolution-owner {
  color: #ffb0b0;
}

.resolution-card-wrap {
  width: min(100%, 390px);
  min-height: 126px;
  display: grid;
  place-items: center;
  perspective: 900px;
}

.resolution-card-visual {
  --tier: #68aefc;
  width: min(100%, 350px);
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, .13);
  border-left: 4px solid var(--tier);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(19, 34, 51, .98), rgba(8, 15, 25, .98));
  box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
  transform-origin: center;
}

.resolution-card-visual.tier-1 { --tier: #f8cf57; }
.resolution-card-visual.tier-2 { --tier: #bc7aff; }
.resolution-card-visual.tier-3 { --tier: #66e0c0; }
.resolution-card-visual.tier-4 { --tier: #68aefc; }

.resolution-card-visual .battle-art {
  width: 88px;
}

.resolution-card-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.resolution-card-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.08rem;
}

.resolution-card-copy span {
  color: #9bc8e8;
  font-size: .78rem;
}

.resolution-card-copy em {
  color: rgba(235, 245, 255, .72);
  font-size: .78rem;
  font-style: normal;
  line-height: 1.3;
}

.resolution-effects {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 29px;
}

.resolution-effect {
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 999px;
  background: rgba(255, 255, 255, .055);
  font-size: .75rem;
  font-weight: 800;
}

.resolution-effect-damage {
  color: #ffb2b2;
  border-color: rgba(255, 110, 110, .25);
  background: rgba(200, 60, 60, .12);
}

.resolution-effect-heal {
  color: #9dffd1;
  border-color: rgba(90, 255, 170, .25);
  background: rgba(65, 190, 130, .12);
}

.resolution-effect-shield {
  color: #a9ddff;
  border-color: rgba(80, 190, 255, .25);
  background: rgba(70, 160, 220, .12);
}

.resolution-effect-energy {
  color: #ffe09a;
  border-color: rgba(255, 205, 80, .25);
  background: rgba(210, 160, 50, .12);
}

.resolution-effect-muted {
  color: rgba(235, 245, 255, .58);
}

.resolution-description {
  min-height: 1.25em;
  max-width: 620px;
  color: rgba(235, 245, 255, .74);
  font-size: .77rem;
  line-height: 1.3;
  text-align: center;
}

.resolution-progress {
  color: rgba(235, 245, 255, .42);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .08em;
}

@keyframes resolutionCardFromSelf {
  0% { opacity: 0; transform: translateY(50px) scale(.84) rotateX(12deg); }
  70% { opacity: 1; transform: translateY(-4px) scale(1.025) rotateX(0); }
  100% { opacity: 1; transform: none; }
}

@keyframes resolutionCardFromEnemy {
  0% { opacity: 0; transform: translateY(-50px) scale(.84) rotateX(-12deg); }
  70% { opacity: 1; transform: translateY(4px) scale(1.025) rotateX(0); }
  100% { opacity: 1; transform: none; }
}

@keyframes resolutionImpact {
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(1.045); filter: brightness(1.45); }
  100% { transform: scale(1); filter: brightness(1); }
}

@keyframes resolutionEffectPop {
  from { opacity: 0; transform: translateY(6px) scale(.88); }
  to { opacity: 1; transform: none; }
}

.resolution-self.resolution-enter .resolution-card-visual {
  animation: resolutionCardFromSelf .45s cubic-bezier(.2, .8, .25, 1) both;
}

.resolution-enemy.resolution-enter .resolution-card-visual {
  animation: resolutionCardFromEnemy .45s cubic-bezier(.2, .8, .25, 1) both;
}

.resolution-impact .resolution-card-visual {
  animation: resolutionImpact .48s ease-out;
}

.resolution-impact .resolution-effect {
  animation: resolutionEffectPop .30s ease-out both;
}

.resolution-impact .resolution-effect:nth-child(2) { animation-delay: 55ms; }
.resolution-impact .resolution-effect:nth-child(3) { animation-delay: 110ms; }
.resolution-impact .resolution-effect:nth-child(4) { animation-delay: 165ms; }

@media (max-width: 520px) {
  .resolution-stage {
    min-height: 206px;
    padding: 10px 8px;
    gap: 7px;
  }

  .resolution-card-visual {
    grid-template-columns: 68px minmax(0, 1fr);
    gap: 9px;
    padding: 8px;
  }

  .resolution-card-visual .battle-art {
    width: 68px;
  }

  .resolution-card-copy strong {
    font-size: .92rem;
  }

  .resolution-card-copy span,
  .resolution-card-copy em {
    font-size: .68rem;
  }

  .resolution-effect {
    padding: 4px 7px;
    font-size: .68rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .resolution-card-visual,
  .resolution-effect {
    animation: none !important;
    transition: none !important;
  }
}


/* Clear combat values on cards -------------------------------------------- */
.card-combat-stats {
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  gap:5px;
  margin:5px 0 3px;
}
.card-combat-stats > strong,
.card-combat-stats > span {
  display:inline-flex;
  align-items:center;
  min-height:24px;
  padding:3px 7px;
  border:1px solid rgba(255,255,255,.10);
  border-radius:7px;
  background:rgba(255,255,255,.045);
  color:rgba(235,245,255,.76);
  font-size:.70rem;
  font-style:normal;
  font-weight:800;
  line-height:1;
  white-space:nowrap;
}
.card-combat-stats .damage-stat {
  border-color:rgba(255,100,100,.40);
  background:rgba(185,45,45,.18);
  color:#ffb5b5;
  font-size:.78rem;
  box-shadow:inset 0 0 12px rgba(255,70,70,.06);
}
.card-combat-stats .shield-stat {
  border-color:rgba(100,195,255,.28);
  background:rgba(60,150,215,.12);
  color:#a9ddff;
}
.hand-card .card-combat-stats { margin-top:4px; }
.resolution-card-copy .card-combat-stats { margin:2px 0; }

.resolution-overtime .resolution-owner { color:#ff9b9b; }
.resolution-overtime-card {
  display:grid;
  place-items:center;
  gap:8px;
  width:min(440px,100%);
  padding:22px 18px;
  border:1px solid rgba(255,90,90,.30);
  border-radius:14px;
  background:radial-gradient(circle at 50% 40%,rgba(210,45,45,.18),transparent 65%),rgba(45,8,12,.72);
  box-shadow:0 12px 35px rgba(0,0,0,.30),inset 0 0 30px rgba(255,60,60,.05);
  text-align:center;
}
.resolution-overtime-card strong {
  color:#ffb0b0;
  font-size:1.16rem;
  letter-spacing:.04em;
}
.resolution-overtime-card span {
  color:rgba(255,225,225,.75);
  font-size:.84rem;
}

.game-over-dialog { max-width:min(520px,calc(100vw - 28px)); }
.game-over-prompt { margin-bottom:7px; }
.game-over-countdown {
  min-height:1.4em;
  margin:0 0 15px;
  color:rgba(235,245,255,.62);
  font-size:.82rem;
  font-variant-numeric:tabular-nums;
}

@media (max-width:520px) {
  .card-combat-stats { gap:4px; }
  .card-combat-stats > strong,
  .card-combat-stats > span { padding:3px 5px;font-size:.64rem; }
  .card-combat-stats .damage-stat { font-size:.72rem; }
  .game-over-dialog .battle-dialog-actions {
    display:grid;
    grid-template-columns:1fr;
  }
}


/* Battle exit controls ---------------------------------------------------- */
.battle-exit-row {
  display:flex;
  justify-content:flex-end;
  margin-top:14px;
}

.battle-live-actions {
  display:flex;
  justify-content:flex-end;
  margin:0 0 10px;
}

.battle-leave-button {
  min-width:120px;
}

@media (max-width:520px) {
  .battle-exit-row .btn,
  .battle-live-actions .btn {
    width:100%;
  }
}


/* Battle deck archetype tags --------------------------------------------- */
.archetype-tags {
  display:flex;
  flex-wrap:wrap;
  gap:4px;
  margin:4px 0 2px;
}
.archetype-tags i {
  display:inline-flex;
  align-items:center;
  min-height:19px;
  padding:2px 6px;
  border:1px solid rgba(115,190,255,.20);
  border-radius:999px;
  background:rgba(80,150,220,.08);
  color:rgba(220,240,255,.74);
  font-size:.60rem;
  font-style:normal;
  font-weight:800;
  letter-spacing:.02em;
}


/* Six battle archetypes -------------------------------------------------- */
.archetype-tags .archetype-energy-theft {
  border-color:rgba(186,120,255,.38);
  background:rgba(128,74,190,.16);
  color:#dfc1ff;
}


/* Matchmaking service status badge --------------------------------------- */
.matchmaking-status-badge {
  min-width: 150px;
  text-align: center;
}
.matchmaking-status-badge.checking {
  opacity: .72;
}
.matchmaking-status-badge.offline {
  border-color: rgba(255,100,100,.30);
  background: rgba(170,45,45,.12);
  color: #ffb5b5;
}
.matchmaking-status-badge.online {
  border-color: rgba(95,225,155,.32);
  background: rgba(45,145,95,.12);
}
@media (max-width:520px) {
  .matchmaking-status-badge {
    min-width: 0;
    font-size: .68rem;
  }
}


/* Battle readability: keep the player's own HUD/hand in view ------------- */
.battle-self {
  position: sticky;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 30;
  background: rgba(8, 16, 27, .97);
  box-shadow:
    0 -10px 34px rgba(0, 0, 0, .34),
    0 18px 50px rgba(0, 0, 0, .32);
  backdrop-filter: blur(14px);
}

.battle-self .fighter-head {
  position: relative;
  z-index: 2;
}

.battle-self .fighter-head strong {
  font-size: 1.08rem;
}

.battle-self .fighter-resources {
  font-weight: 700;
}

/* Stronger selected-card state ------------------------------------------- */
.hand-card {
  position: relative;
}

.battle-hand.has-selection .hand-card:not(.selected) {
  opacity: .62;
  filter: saturate(.72) brightness(.84);
}

.hand-card.selected,
.hand-card.selected:disabled {
  opacity: 1 !important;
  filter: none !important;
  border: 3px solid rgba(106, 211, 255, .96);
  background:
    linear-gradient(145deg, rgba(64, 170, 230, .20), rgba(20, 75, 115, .11)),
    rgba(10, 20, 32, .98);
  box-shadow:
    0 0 0 2px rgba(106, 211, 255, .16),
    0 0 24px rgba(69, 184, 255, .34),
    0 12px 30px rgba(0, 0, 0, .34);
  transform: translateY(-7px) scale(1.025);
}

.hand-card.selected::after {
  content: "✓";
  position: absolute;
  top: 7px;
  right: 7px;
  z-index: 5;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: #a9e8ff;
  color: #07121d;
  font-size: .82rem;
  font-weight: 1000;
  box-shadow: 0 0 16px rgba(95, 205, 255, .55);
}

.hand-selected-badge {
  position: absolute;
  left: 7px;
  top: 7px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: calc(100% - 44px);
  padding: 4px 7px;
  border: 1px solid rgba(180, 235, 255, .55);
  border-radius: 999px;
  background: rgba(5, 25, 39, .94);
  color: #dff7ff;
  font-size: .61rem;
  font-weight: 900;
  letter-spacing: .055em;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .28);
}

.hand-selected-badge b {
  display: grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: #a9e8ff;
  color: #07121d;
  font-size: .66rem;
}

/* Make the resolution card stay visually dominant while it is being read. */
.resolution-stage:not([hidden]) {
  min-height: 250px;
}
.resolution-card-visual {
  transition: transform .28s ease, box-shadow .28s ease;
}
.resolution-stage.resolution-impact .resolution-card-visual {
  transform: scale(1.025);
}

@media (max-width: 800px) {
  .battle-self {
    bottom: max(4px, env(safe-area-inset-bottom));
    border-color: rgba(108, 198, 255, .30);
  }

  .battle-self .fighter-head {
    padding-bottom: 2px;
  }

  .hand-card.selected {
    transform: translateY(-5px) scale(1.018);
  }

  .resolution-stage:not([hidden]) {
    min-height: 220px;
  }
}

@media (max-height: 650px) {
  .battle-self {
    position: relative;
    bottom: auto;
  }
}

/* Reveal/resolution focus mode ------------------------------------------- */
/* The real game container is .battle-board. */
body.battle-resolving .battle-board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, .95fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(280px, auto);
  gap: 14px;
  align-items: stretch;
}

body.battle-resolving .battle-live-actions {
  grid-column: 1 / -1;
  grid-row: 1;
  display: none;
}

body.battle-resolving .battle-opponent {
  grid-column: 1;
  grid-row: 2;
}

body.battle-resolving .battle-center {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  min-height: 0;
}

body.battle-resolving .battle-self {
  grid-column: 3;
  grid-row: 2;
}

body.battle-resolving .battle-hand,
body.battle-resolving .hand-head,
body.battle-resolving .turn-actions,
body.battle-resolving .played-row,
body.battle-resolving .resolution-queue,
body.battle-resolving .battle-log {
  display: none !important;
}

body.battle-resolving .battle-opponent,
body.battle-resolving .battle-self {
  position: relative;
  inset: auto;
  bottom: auto;
  z-index: 2;
  min-height: 170px;
  max-height: none;
  overflow: visible;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: rgba(8, 16, 27, .97);
  border-color: rgba(110, 195, 255, .28);
  box-shadow: 0 16px 42px rgba(0, 0, 0, .34);
  backdrop-filter: blur(14px);
}

body.battle-resolving .fighter-head {
  margin-bottom: 0;
}

body.battle-resolving .fighter-head > div:first-child {
  flex-wrap: wrap;
}

body.battle-resolving .fighter-head strong {
  font-size: 1.22rem;
}

body.battle-resolving .fighter-resources {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, 1fr));
  gap: 8px;
  width: 100%;
  margin-top: 12px;
}

body.battle-resolving .fighter-resources > * {
  min-width: 0;
  min-height: 58px;
  display: grid;
  place-items: center;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, .09);
  border-radius: 10px;
  background: rgba(255, 255, 255, .035);
  font-size: 1.05rem;
  font-weight: 800;
  text-align: center;
}

body.battle-resolving #selfHp,
body.battle-resolving #opponentHp {
  font-size: 1.4rem;
  font-weight: 950;
}

body.battle-resolving .turn-bar {
  margin-bottom: 8px;
}

body.battle-resolving .resolution-stage:not([hidden]) {
  width: 100%;
  min-height: 280px;
  margin: 0;
  align-self: stretch;
  justify-self: stretch;
  display: grid;
  align-content: center;
  gap: 10px;
  padding: 16px;
  border: 1px solid rgba(115, 200, 255, .24);
  border-radius: 16px;
  background:
    radial-gradient(circle at 50% 35%, rgba(82, 165, 225, .12), transparent 58%),
    rgba(6, 13, 23, .96);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .38);
}

body.battle-resolving .resolution-card-visual {
  width: min(100%, 460px);
  max-width: 100%;
  margin-inline: auto;
}

@media (max-width: 900px) {
  body.battle-resolving .battle-board {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    gap: 8px;
  }

  body.battle-resolving .battle-center {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  body.battle-resolving .battle-opponent {
    grid-column: 1;
    grid-row: 3;
  }

  body.battle-resolving .battle-self {
    grid-column: 2;
    grid-row: 3;
  }

  body.battle-resolving .resolution-stage:not([hidden]) {
    min-height: 235px;
    padding: 12px;
  }

  body.battle-resolving .battle-opponent,
  body.battle-resolving .battle-self {
    min-height: 140px;
  }
}

@media (max-width: 620px) {
  body.battle-resolving .battle-board {
    gap: 6px;
  }

  body.battle-resolving .battle-opponent,
  body.battle-resolving .battle-self {
    min-width: 0;
    min-height: 116px;
    padding: 9px;
  }

  body.battle-resolving .fighter-head {
    display: block;
  }

  body.battle-resolving .fighter-head > div:first-child {
    display: flex;
    justify-content: space-between;
    gap: 6px;
  }

  body.battle-resolving .fighter-head strong {
    font-size: .98rem;
  }

  body.battle-resolving .fighter-resources {
    grid-template-columns: 1fr;
    gap: 4px;
    margin-top: 7px;
  }

  body.battle-resolving .fighter-resources > * {
    min-height: 31px;
    padding: 3px 5px;
    font-size: .78rem;
  }

  body.battle-resolving #selfHp,
  body.battle-resolving #opponentHp {
    font-size: 1.12rem;
  }

  body.battle-resolving .resolution-stage:not([hidden]) {
    min-height: 205px;
    padding: 9px;
  }
}

/* Sticky self panel ------------------------------------------------------ */
body:not(.battle-resolving) .battle-self {
  max-height: calc(100dvh - 110px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

body:not(.battle-resolving) .battle-self .battle-hand {
  overflow-x: auto;
  overflow-y: hidden;
}

@media (max-height: 650px) {
  body:not(.battle-resolving) .battle-self {
    position: sticky;
    bottom: max(4px, env(safe-area-inset-bottom));
    max-height: calc(100dvh - 74px);
  }
}


/* Full-viewport match layout -------------------------------------------- */
/* Lobby/deck builder keep their normal document scrolling. Only an active
   match becomes a fixed-height app view. */
body.battle-in-match {
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

body.battle-in-match > header {
  min-height: 0;
}

body.battle-in-match > footer {
  display: none;
}

body.battle-in-match .battle-main {
  width: min(1600px, 100%);
  height: 100%;
  min-height: 0;
  margin: 0 auto;
  padding: 8px clamp(6px, 1.2vw, 16px) max(8px, env(safe-area-inset-bottom));
  display: block;
  overflow: hidden;
}

body.battle-in-match #eligibilityPanel,
body.battle-in-match #deckBuilderPanel,
body.battle-in-match #lobbyPanel {
  display: none !important;
}

body.battle-in-match .battle-board {
  height: 100%;
  min-height: 0;
  overflow: hidden;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(6px, 1vh, 12px);
}

body.battle-in-match .battle-opponent,
body.battle-in-match .battle-center,
body.battle-in-match .battle-self {
  min-height: 0;
}

/* The player's hand must be an ordinary part of the game grid, never sticky. */
body.battle-in-match .battle-self {
  position: relative !important;
  inset: auto !important;
  bottom: auto !important;
  z-index: 2;
  max-height: none !important;
  overflow: hidden !important;
  padding: clamp(8px, 1.2vh, 14px);
}

body.battle-in-match .battle-self .fighter-head {
  flex: 0 0 auto;
}

body.battle-in-match .hand-head {
  flex: 0 0 auto;
  margin: 7px 0 5px;
}

body.battle-in-match .battle-hand {
  flex: 0 1 auto;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
}

body.battle-in-match .turn-actions {
  position: relative !important;
  inset: auto !important;
  bottom: auto !important;
  flex: 0 0 auto;
}

body.battle-in-match .battle-center {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.battle-in-match .turn-bar,
body.battle-in-match .resolution-queue {
  flex: 0 0 auto;
}

body.battle-in-match .battle-log {
  min-height: 0;
  max-height: none;
  flex: 1 1 auto;
  overflow-y: auto;
}

body.battle-in-match .battle-opponent {
  padding: clamp(8px, 1.2vh, 14px);
}

/* Resolution is intentionally a stripped-down arena. The hand, selection
   controls and logs disappear so HP/resources and the currently resolving
   played card get the available viewport. */
body.battle-in-match.battle-resolving .battle-hand,
body.battle-in-match.battle-resolving .hand-head,
body.battle-in-match.battle-resolving .turn-actions,
body.battle-in-match.battle-resolving .battle-log,
body.battle-in-match.battle-resolving .resolution-queue {
  display: none !important;
}

body.battle-in-match.battle-resolving .battle-board {
  height: 100%;
  overflow: hidden;
}

body.battle-in-match.battle-resolving .battle-center {
  overflow: hidden;
}

body.battle-in-match.battle-resolving .resolution-stage:not([hidden]) {
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
}

body.battle-in-match.battle-resolving .resolution-card-wrap {
  min-height: 0;
  overflow: hidden;
}

body.battle-in-match.battle-resolving .resolution-card-visual {
  max-height: min(48dvh, 430px);
}

body.battle-in-match.battle-resolving .resolution-card-visual .battle-art {
  max-height: min(34dvh, 300px);
}

/* Short desktops/laptops: compress secondary UI instead of allowing the page
   itself to scroll. */
@media (max-height: 760px) {
  body.battle-in-match .battle-main {
    padding-top: 5px;
    padding-bottom: max(5px, env(safe-area-inset-bottom));
  }

  body.battle-in-match .battle-board {
    gap: 5px;
  }

  body.battle-in-match .battle-opponent,
  body.battle-in-match .battle-self {
    padding: 7px 9px;
  }

  body.battle-in-match .fighter-head {
    gap: 7px;
  }

  body.battle-in-match .fighter-resources {
    gap: 7px;
  }

  body.battle-in-match .hand-head {
    margin: 4px 0 3px;
  }

  body.battle-in-match .battle-hand {
    padding-top: 2px;
    padding-bottom: 3px;
  }

  body.battle-in-match .hand-card {
    grid-template-columns: 64px minmax(0, 1fr);
    flex-basis: 225px;
    padding: 5px;
  }

  body.battle-in-match .hand-card .battle-art {
    width: 64px;
  }

  body.battle-in-match .turn-actions {
    margin-top: 4px;
    padding-top: 5px;
    padding-bottom: 5px;
  }
}

/* Phone/tablet: keep the full match inside the visible dynamic viewport.
   Hand cards can scroll horizontally, but the page itself never scrolls. */
@media (max-width: 800px) {
  body.battle-in-match .battle-main {
    width: 100%;
    margin: 0;
    padding-inline: 5px;
  }

  body.battle-in-match .battle-board {
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  body.battle-in-match .battle-opponent {
    padding: 7px 9px;
  }

  body.battle-in-match .battle-center {
    padding: 8px;
  }

  body.battle-in-match .battle-self {
    padding: 7px 9px;
  }

  body.battle-in-match .battle-hand {
    width: calc(100% + 18px);
    margin-inline: -9px;
    padding-inline: 9px;
  }

  body.battle-in-match .turn-actions {
    margin: 4px 0 0;
    padding: 5px 0 0;
    background: none;
    backdrop-filter: none;
  }
}

@media (max-width: 620px) {
  body.battle-in-match.battle-resolving .battle-board {
    grid-template-rows: minmax(0, 1fr) auto;
  }

  body.battle-in-match.battle-resolving .battle-center {
    min-height: 0;
  }

  body.battle-in-match.battle-resolving .battle-opponent,
  body.battle-in-match.battle-resolving .battle-self {
    min-height: 96px;
    max-height: 128px;
  }

  body.battle-in-match.battle-resolving .fighter-resources > * {
    min-height: 27px;
  }

  body.battle-in-match.battle-resolving .resolution-stage:not([hidden]) {
    min-height: 0;
    height: 100%;
  }

  body.battle-in-match.battle-resolving .resolution-card-visual {
    max-height: min(40dvh, 310px);
  }
}

@media (max-height: 600px) {
  body.battle-in-match .battle-page header,
  body.battle-in-match header {
    min-height: 0;
  }

  body.battle-in-match .battle-header-inner {
    padding-block: 4px;
  }

  body.battle-in-match .battle-page .brand img,
  body.battle-in-match .brand img {
    height: 30px;
  }

  body.battle-in-match .battle-page .brand .subtitle,
  body.battle-in-match .brand .subtitle {
    display: none;
  }

  body.battle-in-match .battle-opponent {
    padding-block: 5px;
  }

  body.battle-in-match .battle-self {
    padding-block: 5px;
  }

  body.battle-in-match .hand-card {
    flex-basis: 205px;
    max-width: 205px;
    grid-template-columns: 56px minmax(0, 1fr);
  }

  body.battle-in-match .hand-card .battle-art {
    width: 56px;
  }

  body.battle-in-match .hand-card em {
    display: none;
  }
}


/* Strong resolution ownership -------------------------------------------- */
.resolution-owner {
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
}

.resolution-owner small {
  color: rgba(235, 245, 255, .66);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .035em;
  text-transform: none;
}

.resolution-player-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: min(100%, 220px);
  padding: 7px 14px;
  border: 2px solid currentColor;
  border-radius: 999px;
  font-size: clamp(.82rem, 1.5vw, 1.05rem);
  font-weight: 1000;
  letter-spacing: .10em;
  line-height: 1;
  box-shadow: 0 0 22px color-mix(in srgb, currentColor 24%, transparent);
}

.resolution-player-self {
  color: #8bd8ff;
  background: rgba(50, 155, 220, .15);
}

.resolution-player-enemy {
  color: #ff9f9f;
  background: rgba(210, 65, 65, .15);
}

.resolution-player-overtime {
  color: #ffb06f;
  background: rgba(210, 100, 35, .14);
}

.resolution-stage.resolution-self {
  border-color: rgba(92, 201, 255, .52);
  box-shadow:
    inset 5px 0 0 rgba(92, 201, 255, .78),
    0 18px 50px rgba(0, 0, 0, .38),
    0 0 32px rgba(60, 165, 225, .10);
}

.resolution-stage.resolution-enemy {
  border-color: rgba(255, 112, 112, .52);
  box-shadow:
    inset -5px 0 0 rgba(255, 112, 112, .78),
    0 18px 50px rgba(0, 0, 0, .38),
    0 0 32px rgba(220, 70, 70, .10);
}

.resolution-stage.resolution-self::before,
.resolution-stage.resolution-enemy::before {
  position: absolute;
  top: 50%;
  z-index: 0;
  font-size: clamp(3.5rem, 10vw, 8rem);
  font-weight: 1000;
  opacity: .035;
  transform: translateY(-50%);
  pointer-events: none;
}

.resolution-stage.resolution-self::before {
  content: "YOU";
  left: 4%;
  color: #8bd8ff;
}

.resolution-stage.resolution-enemy::before {
  content: "ENEMY";
  right: 3%;
  color: #ff9f9f;
}

.resolution-stage > * {
  position: relative;
  z-index: 1;
}

@media (max-width: 620px) {
  .resolution-player-label {
    min-width: 0;
    padding: 6px 10px;
    font-size: .76rem;
  }

  .resolution-owner small {
    font-size: .64rem;
  }

  .resolution-stage.resolution-self::before,
  .resolution-stage.resolution-enemy::before {
    font-size: 3.2rem;
  }
}


/* Mobile resolution layout ------------------------------------------------
   The resolving card owns the upper area. Both player HUDs stay visible below
   it in a compact two-column row. */
@media (max-width: 620px) {
  body.battle-in-match.battle-resolving .battle-main {
    padding: 4px 5px max(5px, env(safe-area-inset-bottom));
  }

  body.battle-in-match.battle-resolving .battle-board {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 6px;
    overflow: hidden;
  }

  body.battle-in-match.battle-resolving .battle-center {
    grid-column: 1 / -1 !important;
    grid-row: 1 !important;
    min-width: 0;
    min-height: 0;
    padding: 6px;
    overflow: hidden;
  }

  body.battle-in-match.battle-resolving .battle-opponent {
    grid-column: 1 !important;
    grid-row: 2 !important;
  }

  body.battle-in-match.battle-resolving .battle-self {
    grid-column: 2 !important;
    grid-row: 2 !important;
  }

  body.battle-in-match.battle-resolving .battle-opponent,
  body.battle-in-match.battle-resolving .battle-self {
    min-width: 0;
    min-height: 0 !important;
    max-height: none !important;
    padding: 7px;
    overflow: hidden !important;
    border-radius: 12px;
    box-shadow: 0 7px 20px rgba(0, 0, 0, .25);
  }

  body.battle-in-match.battle-resolving .fighter-head {
    display: grid !important;
    grid-template-columns: 1fr;
    gap: 5px;
    margin: 0;
  }

  body.battle-in-match.battle-resolving .fighter-head > div:first-child {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 5px;
    min-width: 0;
  }

  body.battle-in-match.battle-resolving .fighter-head > div:first-child > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .67rem;
  }

  body.battle-in-match.battle-resolving .fighter-head strong {
    flex: 0 0 auto;
    font-size: .94rem;
    white-space: nowrap;
  }

  body.battle-in-match.battle-resolving #selfHp,
  body.battle-in-match.battle-resolving #opponentHp {
    font-size: 1.15rem;
  }

  body.battle-in-match.battle-resolving .fighter-resources {
    width: 100%;
    margin: 0;
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 3px !important;
    font-size: .66rem;
    white-space: nowrap;
  }

  body.battle-in-match.battle-resolving .fighter-resources > * {
    min-width: 0;
    min-height: 27px !important;
    padding: 3px 2px !important;
    border-radius: 7px;
    font-size: .66rem !important;
  }

  body.battle-in-match.battle-resolving .turn-bar {
    flex: 0 0 auto;
    padding: 0 1px 5px;
    margin: 0 0 5px;
    font-size: .68rem;
  }

  body.battle-in-match.battle-resolving .resolution-stage:not([hidden]) {
    width: 100%;
    height: calc(100% - 32px);
    min-height: 0 !important;
    max-height: none !important;
    margin: 0;
    padding: 7px;
    display: flex !important;
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    gap: 6px;
    overflow: hidden;
    border-radius: 12px;
  }

  body.battle-in-match.battle-resolving .resolution-owner {
    flex: 0 0 auto;
    gap: 2px;
  }

  body.battle-in-match.battle-resolving .resolution-player-label {
    min-width: 0;
    max-width: 100%;
    padding: 5px 9px;
    border-width: 1px;
    font-size: .70rem;
    letter-spacing: .07em;
  }

  body.battle-in-match.battle-resolving .resolution-owner small {
    font-size: .58rem;
  }

  body.battle-in-match.battle-resolving .resolution-card-wrap {
    width: 100%;
    min-height: 0;
    flex: 1 1 auto;
    display: grid;
    place-items: center;
    overflow: hidden;
  }

  body.battle-in-match.battle-resolving .resolution-card-visual {
    width: min(100%, 330px);
    max-width: 100%;
    max-height: 100%;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 8px;
    padding: 7px;
    border-radius: 10px;
  }

  body.battle-in-match.battle-resolving .resolution-card-visual .battle-art {
    width: 58px;
    max-height: 94px;
  }

  body.battle-in-match.battle-resolving .resolution-card-copy {
    gap: 3px;
  }

  body.battle-in-match.battle-resolving .resolution-card-copy strong {
    font-size: .88rem;
  }

  body.battle-in-match.battle-resolving .resolution-card-copy em {
    font-size: .63rem;
    line-height: 1.18;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  body.battle-in-match.battle-resolving .resolution-card-copy .card-combat-stats {
    gap: 3px;
    margin: 1px 0;
  }

  body.battle-in-match.battle-resolving .resolution-card-copy .card-combat-stats > strong,
  body.battle-in-match.battle-resolving .resolution-card-copy .card-combat-stats > span {
    padding: 2px 4px;
    font-size: .58rem;
  }

  body.battle-in-match.battle-resolving .resolution-effects {
    flex: 0 0 auto;
    gap: 3px;
  }

  body.battle-in-match.battle-resolving .resolution-effect {
    padding: 3px 5px;
    font-size: .61rem;
  }

  body.battle-in-match.battle-resolving .resolution-description {
    flex: 0 0 auto;
    max-height: 2.5em;
    overflow: hidden;
    font-size: .61rem;
    line-height: 1.2;
    text-align: center;
  }

  body.battle-in-match.battle-resolving .resolution-progress {
    flex: 0 0 auto;
    font-size: .60rem;
  }

  body.battle-in-match.battle-resolving .resolution-stage.resolution-self::before,
  body.battle-in-match.battle-resolving .resolution-stage.resolution-enemy::before {
    display: none;
  }

  body.battle-in-match.battle-resolving .resolution-stage.resolution-self {
    box-shadow:
      inset 3px 0 0 rgba(92, 201, 255, .80),
      0 8px 24px rgba(0, 0, 0, .28);
  }

  body.battle-in-match.battle-resolving .resolution-stage.resolution-enemy {
    box-shadow:
      inset -3px 0 0 rgba(255, 112, 112, .80),
      0 8px 24px rgba(0, 0, 0, .28);
  }
}

@media (max-width: 420px) {
  body.battle-in-match.battle-resolving .battle-opponent,
  body.battle-in-match.battle-resolving .battle-self {
    padding: 6px 5px;
  }

  body.battle-in-match.battle-resolving .fighter-resources > * {
    min-height: 24px !important;
    font-size: .61rem !important;
  }

  body.battle-in-match.battle-resolving .resolution-card-visual {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  body.battle-in-match.battle-resolving .resolution-card-visual .battle-art {
    width: 52px;
  }
}


/* Resolution result presentation ----------------------------------------- */
.resolution-effects {
  width: min(100%, 620px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  justify-content: center;
  gap: 7px;
  min-height: 42px;
}

.resolution-effect {
  min-width: 0;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 11px;
  border-radius: 10px;
  font-size: .78rem;
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  letter-spacing: .025em;
}

.resolution-effect-primary {
  grid-column: 1 / -1;
  min-height: 50px;
  padding: 10px 14px;
  border-width: 2px;
  border-radius: 12px;
  font-size: clamp(.96rem, 2vw, 1.25rem);
  font-weight: 1000;
  letter-spacing: .045em;
}

.resolution-effect-pending {
  grid-column: 1 / -1;
  min-height: 42px;
  border-style: dashed;
  color: rgba(220, 238, 255, .70);
  background: rgba(100, 160, 210, .06);
  animation: resolutionPendingPulse 1.1s ease-in-out infinite;
}

.resolution-effect-shield-break {
  color: #9bd9ff;
  border-color: rgba(85, 185, 255, .50);
  background: rgba(45, 125, 195, .20);
}

.resolution-effect-steal {
  color: #ffe28e;
  border-color: rgba(255, 205, 65, .58);
  background: rgba(205, 145, 30, .20);
  box-shadow: inset 0 0 18px rgba(255, 200, 55, .07);
}

.resolution-effect-drain {
  color: #ffc979;
  border-color: rgba(255, 165, 70, .42);
  background: rgba(180, 105, 35, .16);
}

.resolution-effect-cost {
  color: rgba(235, 245, 255, .54);
  border-color: rgba(255, 255, 255, .08);
  background: rgba(255, 255, 255, .025);
  font-size: .68rem;
  font-weight: 750;
}

@keyframes resolutionPendingPulse {
  0%, 100% { opacity: .55; }
  50% { opacity: 1; }
}

@keyframes resolutionPrimaryImpact {
  0% { opacity: 0; transform: translateY(7px) scale(.92); }
  55% { opacity: 1; transform: translateY(-2px) scale(1.035); }
  100% { opacity: 1; transform: none; }
}

.resolution-impact .resolution-effect-primary {
  animation: resolutionPrimaryImpact .44s cubic-bezier(.2, .8, .25, 1) both;
}

.resource-energy-loss {
  animation: resourceEnergyLoss .72s ease-out;
}

@keyframes resourceEnergyLoss {
  0%, 100% { transform: scale(1); color: inherit; }
  32% {
    transform: scale(1.32);
    color: #ffc879;
    text-shadow: 0 0 16px rgba(255, 170, 70, .75);
  }
}

/* Make the changed HP/resource values more visually dominant during impact. */
body.battle-in-match.battle-resolving .fighter-head strong {
  transition: transform .2s ease, color .2s ease;
}

body.battle-in-match.battle-resolving .resolution-description {
  width: min(100%, 620px);
  padding: 0 6px;
}

/* Mobile: one clear primary result, then compact secondary results. */
@media (max-width: 620px) {
  body.battle-in-match.battle-resolving .resolution-stage:not([hidden]) {
    justify-content: flex-start;
  }

  body.battle-in-match.battle-resolving .resolution-card-wrap {
    flex: 1 1 auto;
    min-height: 92px;
  }

  body.battle-in-match.battle-resolving .resolution-effects {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    min-height: 34px;
  }

  body.battle-in-match.battle-resolving .resolution-effect {
    min-height: 29px;
    padding: 4px 5px;
    border-radius: 8px;
    font-size: .60rem;
  }

  body.battle-in-match.battle-resolving .resolution-effect-primary {
    min-height: 40px;
    padding: 7px 8px;
    font-size: .82rem;
  }

  body.battle-in-match.battle-resolving .resolution-effect-pending {
    min-height: 34px;
    font-size: .66rem;
  }

  body.battle-in-match.battle-resolving .resolution-effect-cost {
    font-size: .55rem;
  }

  body.battle-in-match.battle-resolving .resolution-description {
    max-height: 2.4em;
    padding: 0 3px;
    font-size: .58rem;
  }
}

@media (max-width: 390px) {
  body.battle-in-match.battle-resolving .resolution-effect-primary {
    font-size: .76rem;
  }
}


/* Stable deck-builder height on mobile ----------------------------------- */
@media (max-width: 800px) {
  .deck-builder {
    contain: layout paint;
  }

  .deck-grid {
    max-height: min(52svh, 680px);
  }
}
