.battle {
  --ink: #08090d;
  --line: #735693;
  --panel: #2d1c49;
  --cream: #fff1ca;
  --gutter: clamp(6px, 1.5dvh, 15px);
  box-sizing: border-box;
  display: grid;
  grid-template-columns: clamp(162px, 29%, 370px) minmax(0, 1fr);
  gap: var(--gutter);
  width: min(100%, 1440px);
  height: min(100dvh, 820px);
  padding: max(var(--gutter), env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right))
    max(var(--gutter), env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  background: radial-gradient(ellipse at 62% 10%, #473062, #170e26 72%);
  color: var(--cream);
  font-size: clamp(.8rem, 2.15dvh, 1.15rem);
}

.battle-filters { position: absolute; }
.machine, .arena-panel, .recruit-status {
  min-height: 0;
  border: 3px solid var(--ink);
  border-radius: 15px;
  box-shadow: inset 0 0 0 2px var(--line), 0 3px var(--ink);
  overflow: hidden;
}

.recruit {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: var(--gutter);
}

.machine {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(44px, 6vw, 67px);
  grid-template-rows: auto minmax(72px, 1fr);
  gap: var(--gutter) 3px;
  padding: clamp(7px, 2dvh, 20px);
  background: linear-gradient(150deg, #493266 0, var(--panel) 40%, #21152f);
}

.recruit-header, .battle-hud, .field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.recruit-header { grid-column: 1 / -1; }

.battle h1, .battle h2 {
  margin: 0;
  font-size: clamp(1.05rem, 3.7dvh, 2rem);
  line-height: 1.1;
  font-weight: 900;
  filter: url(#game-text-outline);
}

.spin-balance, .phase, .roster {
  display: flex;
  align-items: center;
  padding: .24em .6em;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #153a6b;
  color: #fff;
  font-weight: 800;
}
.spin-balance { min-width: 2.4em; justify-content: center; gap: .25em; }
.spin-balance img { width: 1.25em; height: 1.25em; object-fit: contain; }

.reels {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 0 clamp(2px, .7dvh, 6px);
  padding: clamp(4px, 1.3dvh, 10px);
  border: 3px solid var(--ink);
  border-radius: 11px;
  background: #1c102c;
  box-shadow: inset 0 2px #0e0619, 0 2px #8364a6;
  overflow: hidden;
}
.reels > div {
  display: grid;
  place-items: center;
  min-height: 0;
  border: 2px solid #11192e;
  border-radius: 3px;
  background: linear-gradient(#f7ebcf, #dac8a8);
}
.reels > :nth-child(-n+3) { border-radius: 8px 8px 3px 3px; }
.reels > :nth-child(n+7) { border-radius: 3px 3px 8px 8px; }
.reels img {
  width: 79%;
  height: 79%;
  min-height: 0;
  object-fit: contain;
  filter: drop-shadow(0 2px 1px #16152870);
}
.reels .matched {
  border-color: #fff2a0;
  background: linear-gradient(#fff0b3, #e2a924 85%, #9b671a 85%);
  box-shadow: 0 0 8px #ffcd56;
}
.reels.spinning img { animation: reel-drop .16s linear infinite; }
.reels.spinning > :nth-child(3n + 2) img { animation-delay: -.05s; }
.reels.spinning > :nth-child(3n) img { animation-delay: -.10s; }
@keyframes reel-drop {
  0% { transform: translateY(-23%); opacity: .58; }
  100% { transform: translateY(24%); opacity: .85; }
}
.recruit-status {
  display: grid;
  align-content: center;
  margin: 0;
  min-height: 3.2em;
  padding: .5em .7em;
  background: #261733;
  color: #f0e5ff;
  font-weight: 650;
  line-height: 1.2;
  text-align: center;
}

.spin-lever {
  position: relative;
  display: grid;
  grid-template-rows: minmax(46px, 1fr) auto;
  align-items: center;
  justify-items: center;
  width: 100%;
  min-width: 44px;
  padding: .4em 0;
  border: 0;
  background: transparent;
  color: #ffdf88;
  font-size: clamp(.62rem, 1.9dvh, 1rem);
  font-weight: 900;
  cursor: pointer;
}
.lever-track {
  position: relative;
  box-sizing: border-box;
  width: 13px;
  height: 70%;
  max-height: 160px;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: linear-gradient(90deg, #827096, #ebd7ff 48%, #544566 52%);
  box-shadow: 0 3px 0 var(--ink);
}
.lever-track span {
  position: absolute;
  top: -6px;
  left: 50%;
  width: clamp(24px, 5dvh, 40px);
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 25%, #fff2a7, #dfa031 47%, #874719 75%);
  box-shadow: 0 2px 2px #0009;
  transform: translate(-50%, -30%);
  transition: top .16s ease;
}
.spin-lever:active:not(:disabled) .lever-track span, .spin-lever.is-pulled .lever-track span { top: 72%; }
.spin-lever:disabled { color: #b4a5c2; cursor: default; }
.spin-lever:disabled:not(.is-pulled) .lever-track { filter: grayscale(1) brightness(.7); }
.spin-lever:focus-visible { outline: 3px solid #ffdf6c; outline-offset: -2px; }
.lever-caption { filter: url(#game-text-outline); }

.game-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .42em;
  box-sizing: border-box;
  min-height: 44px;
  padding: .4em .85em;
  border: 3px solid var(--ink);
  border-radius: 10px;
  background: linear-gradient(#4bb9f0 0 11%, #1e92d9 11% calc(100% - 5px), #1766a3 0);
  box-shadow: 0 3px var(--ink);
  color: white;
  font-weight: 900;
  white-space: nowrap;
  cursor: pointer;
}
.game-button span { filter: url(#game-text-outline); }
.game-button img { width: 1.12em; height: 1.12em; object-fit: contain; }
.game-button:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }
.game-button:focus-visible { outline: 3px solid #ffdf6c; outline-offset: 1px; }
.game-button:disabled { background: #616c85; color: #e0e4f0; cursor: default; }
.game-button--fight {
  min-width: 6.5em;
  background: linear-gradient(#a5e96b 0 11%, #71c533 11% calc(100% - 5px), #3d8528 0);
}

.arena-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--gutter);
  padding: var(--gutter);
  background: linear-gradient(155deg, #402850, #21152f);
}
.battle-hud h2 { font-size: clamp(.78rem, 2.7dvh, 1.5rem); }
.field {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: clamp(3px, .9dvh, 8px) solid #d7b884;
  border-radius: 12px;
  outline: 2px solid #08090d;
  background: #2c1944;
  isolation: isolate;
}
.field canvas { position: absolute; inset: 0; width: 100%; height: 100%; z-index: -2; }
.field::after {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(#11082042, transparent 24% 80%, #11082043);
  content: '';
  pointer-events: none;
}
.field-header { position: relative; justify-content: flex-end; padding: var(--gutter); }
.wave {
  position: absolute;
  top: var(--gutter);
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: .12em;
  padding: .18em .65em .28em;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #573873;
  color: #fff0a6;
  white-space: nowrap;
  line-height: 1.05;
}
.phase { padding: 0; border: 0; background: transparent; font-size: .76em; }
.roster { background: #281939eb; font-size: .84em; white-space: nowrap; }
.battle-result {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  justify-items: center;
  gap: var(--gutter);
  padding: .8em 1.25em;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #392351;
  box-shadow: inset 0 0 0 2px #8e6bab, 0 4px var(--ink);
  text-align: center;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  clip-path: inset(50%);
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .reels.spinning img { animation: none; }
  .lever-track span { transition: none; }
}
