.battle-scene {
  isolation: isolate;
  display: grid;
  grid-template-rows: auto minmax(300px, 1fr) auto auto auto;
  gap: 9px;
  min-height: 100vh;
  padding: 12px 14px max(12px, env(safe-area-inset-bottom));
  overflow: hidden;
  background:
    linear-gradient(180deg, rgb(122 69 36 / 14%), rgb(20 13 9 / 42%)),
    #3a2518;
}

.battle-scene > *:not(.battle-atmosphere) {
  position: relative;
  z-index: 1;
}

.battle-atmosphere {
  position: absolute;
  z-index: 0;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    linear-gradient(180deg, #945f39 0%, #69442a 31%, #342419 63%, #17110e 100%);
}

.battle-atmosphere::before {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(102deg, transparent 0 34px, rgb(255 226 166 / 2%) 35px 36px),
    radial-gradient(circle at 50% 14%, rgb(255 217 137 / 20%), transparent 27%);
  content: "";
  opacity: 0.76;
}

.battle-atmosphere::after {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgb(18 10 7 / 38%), transparent 15% 85%, rgb(18 10 7 / 38%)),
    linear-gradient(180deg, transparent 46%, rgb(15 10 8 / 54%) 100%);
  content: "";
}

.battle-atmosphere__sun {
  position: absolute;
  top: 72px;
  left: 50%;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 34%, #fff0b0, #eeba65 55%, #c77a39 100%);
  box-shadow:
    0 0 0 16px rgb(250 211 132 / 6%),
    0 0 72px rgb(250 199 102 / 34%);
  opacity: 0.72;
  transform: translateX(-50%);
}

.battle-atmosphere__stadium {
  position: absolute;
  top: 152px;
  right: -8%;
  left: -8%;
  height: 154px;
  border: 9px solid rgb(57 35 23 / 45%);
  border-bottom: 0;
  border-radius: 50% 50% 0 0;
  opacity: 0.62;
  transform: perspective(260px) rotateX(55deg);
}

.battle-atmosphere__stadium::before,
.battle-atmosphere__stadium::after {
  position: absolute;
  top: 18px;
  bottom: -4px;
  width: 8px;
  background: rgb(53 32 20 / 50%);
  content: "";
}

.battle-atmosphere__stadium::before { left: 24%; }
.battle-atmosphere__stadium::after { right: 24%; }

.battle-atmosphere__dune {
  position: absolute;
  right: -24%;
  left: -24%;
  border-radius: 50% 50% 0 0;
  transform: rotate(-2deg);
}

.battle-atmosphere__dune--far {
  top: 244px;
  height: 165px;
  background: linear-gradient(180deg, rgb(141 83 43 / 88%), rgb(87 53 32 / 84%));
  box-shadow: inset 0 12px 24px rgb(244 186 103 / 8%);
}

.battle-atmosphere__dune--near {
  top: 318px;
  height: 188px;
  background: linear-gradient(180deg, rgb(91 55 34 / 92%), rgb(42 29 21 / 94%));
  transform: rotate(3deg);
}

.battle-atmosphere__dust {
  position: absolute;
  top: 146px;
  left: 18%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: rgb(255 229 174 / 42%);
  box-shadow:
    44px 28px rgb(255 229 174 / 22%),
    126px -18px rgb(255 229 174 / 28%),
    208px 52px rgb(255 229 174 / 18%),
    286px 12px rgb(255 229 174 / 24%),
    352px 74px rgb(255 229 174 / 16%);
  animation: dust-drift 7s ease-in-out infinite alternate;
}

.battle-header,
.battle-header__actions,
.battle-chapter-card,
.enemy-summary,
.player-summary,
.ultimate-row,
.hand-panel__header,
.pile-bar,
.pile-chip {
  display: flex;
  align-items: center;
}

.battle-header,
.enemy-summary,
.player-summary,
.ultimate-row,
.hand-panel__header {
  justify-content: space-between;
}

.battle-header {
  z-index: 5;
  min-height: 48px;
  padding: 5px 7px;
  border: 1px solid rgb(255 228 170 / 15%);
  border-radius: 18px;
  background: linear-gradient(180deg, rgb(60 38 23 / 78%), rgb(31 21 15 / 68%));
  box-shadow:
    inset 0 1px rgb(255 255 255 / 7%),
    0 8px 24px rgb(15 8 5 / 18%);
  backdrop-filter: blur(8px);
}

.battle-chapter-card {
  min-width: 0;
  gap: 7px;
}

.battle-chapter-card .chapter-icon {
  width: 38px;
  height: 38px;
}

.battle-chapter-card .eyebrow {
  margin-bottom: -1px;
  font-size: 0.57rem;
}

.battle-chapter-card strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.9rem;
  line-height: 1.05;
}

.battle-header__actions {
  justify-content: flex-end;
  gap: 5px;
}

.currency-label {
  min-width: 58px;
  padding: 6px 9px;
  border: 1px solid rgb(242 197 92 / 24%);
  border-radius: var(--radius-pill);
  color: var(--color-sand-light);
  background: rgb(88 56 26 / 34%);
  font-size: 0.66rem;
  font-weight: 900;
  text-align: center;
}

.enemy-area {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 8px 10px 5px;
  border: 1px solid rgb(255 225 164 / 10%);
  border-radius: 24px;
  background: linear-gradient(180deg, rgb(65 39 22 / 18%), rgb(24 17 13 / 8%));
}

.enemy-summary {
  gap: 12px;
}

.enemy-summary .eyebrow {
  margin-bottom: 1px;
}

.enemy-summary h2 {
  margin-bottom: 0;
  font-family: var(--font-display);
  font-size: 1.42rem;
  text-shadow: 0 2px 10px rgb(0 0 0 / 28%);
}

.status-stack {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.status-chip {
  padding: 4px 8px;
  border: 1px solid rgb(92 165 198 / 40%);
  border-radius: var(--radius-pill);
  color: #ccefff;
  background: rgb(36 72 88 / 78%);
  font-size: 0.68rem;
}

.health-bar {
  position: relative;
  height: 20px;
  margin: 6px 0 2px;
  overflow: hidden;
  border: 2px solid rgb(32 18 13 / 72%);
  border-radius: var(--radius-pill);
  background: rgb(24 12 10 / 72%);
  box-shadow:
    inset 0 2px 6px rgb(0 0 0 / 42%),
    0 2px 8px rgb(0 0 0 / 18%);
}

.health-bar__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 18%), transparent 48%),
    linear-gradient(90deg, #84272a, #ce514b);
  transition: width var(--transition-normal);
}

.health-bar__text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  text-shadow: 0 1px 3px #000;
}

.enemy-stage {
  position: relative;
  display: grid;
  flex: 1;
  min-height: 218px;
  place-items: center;
}

.enemy-placeholder {
  position: relative;
  width: min(58%, 250px);
  min-height: 184px;
  margin: 8px auto 0;
  border-radius: 48% 48% 25% 25%;
  background:
    radial-gradient(circle at 50% 36%, rgb(255 239 197 / 11%), transparent 48%),
    linear-gradient(180deg, rgb(64 45 30 / 38%), rgb(39 28 20 / 20%));
  box-shadow:
    inset 0 0 34px rgb(255 226 161 / 4%),
    0 24px 34px rgb(18 10 7 / 20%);
}

.enemy-placeholder.has-art {
  overflow: hidden;
  border-color: rgb(255 229 169 / 22%);
  background-color: #33241b;
  background-image:
    linear-gradient(180deg, rgb(255 233 188 / 2%) 0%, rgb(35 22 15 / 0%) 54%, rgb(28 17 12 / 72%) 100%),
    var(--enemy-image);
  background-blend-mode: normal, var(--enemy-art-blend, normal);
  background-position: center, var(--enemy-art-position, center bottom);
  background-repeat: no-repeat;
  background-size: 100% 100%, var(--enemy-art-size, contain);
  box-shadow:
    inset 0 0 34px rgb(39 22 13 / 24%),
    0 24px 34px rgb(18 10 7 / 22%);
}

.enemy-placeholder.has-art .placeholder-art__label {
  bottom: 2px;
}

.enemy-placeholder::after {
  position: absolute;
  right: 14%;
  bottom: -11px;
  left: 14%;
  height: 18px;
  border-radius: 50%;
  background: rgb(15 9 6 / 38%);
  filter: blur(6px);
  content: "";
}

.intent-panel {
  position: absolute;
  top: 16px;
  right: 2px;
  display: grid;
  min-width: 126px;
  max-width: 148px;
  gap: 0;
  padding: 8px 10px 9px 45px;
  border: 1px solid rgb(242 197 92 / 34%);
  border-radius: 16px 16px 5px 16px;
  background: linear-gradient(150deg, rgb(53 27 19 / 94%), rgb(30 17 14 / 94%));
  box-shadow: 0 10px 28px rgb(17 8 5 / 35%);
  text-align: left;
}

.intent-panel::after {
  position: absolute;
  right: 12px;
  bottom: -8px;
  width: 16px;
  height: 16px;
  background: rgb(31 18 14 / 96%);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
  content: "";
}

.intent-panel .intent-icon {
  position: absolute;
  top: 50%;
  left: 8px;
  width: 34px;
  height: 34px;
  transform: translateY(-50%);
}

.intent-panel__label {
  color: var(--color-muted);
  font-size: 0.52rem;
  letter-spacing: 0.08em;
}

.intent-panel strong {
  font-family: var(--font-display);
  font-size: 0.79rem;
  line-height: 1.25;
}

#intent-value {
  color: #ffaaa0;
  font-size: 0.66rem;
}

.battle-log {
  min-height: 34px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid rgb(242 197 92 / 10%);
  border-left: 3px solid rgb(242 197 92 / 48%);
  border-radius: 5px 12px 12px 5px;
  color: var(--color-muted);
  background: linear-gradient(90deg, rgb(66 43 24 / 56%), rgb(20 15 12 / 48%));
  font-size: 0.7rem;
  text-align: center;
  backdrop-filter: blur(5px);
}

.player-area {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgb(242 197 92 / 22%);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgb(255 255 255 / 4%), transparent 42%),
    rgb(20 15 12 / 88%);
  box-shadow:
    inset 0 1px rgb(255 255 255 / 5%),
    0 10px 30px rgb(12 7 5 / 24%);
  backdrop-filter: blur(9px);
}

.player-summary,
.ultimate-row {
  gap: 10px;
}

.player-avatar {
  flex: 0 0 54px;
  width: 54px;
  height: 54px;
  border: 2px solid rgb(242 197 92 / 28%);
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgb(0 0 0 / 15%);
}

.player-avatar.has-art {
  background-color: #33241b;
  background-image:
    linear-gradient(180deg, transparent 60%, rgb(27 18 13 / 38%)),
    url("../assets/characters/IMG_2373.jpg");
  background-blend-mode: normal, normal;
  background-position: center, center 22%;
  background-repeat: no-repeat;
  background-size: 100% 100%, 116% auto;
}

.player-avatar.has-art .placeholder-art__label {
  display: none;
}

.player-avatar .placeholder-art__label {
  font-size: 0.78rem;
}

.player-vitals {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(2, minmax(0, auto));
  gap: 1px 12px;
  font-size: 0.72rem;
}

.player-vitals strong {
  grid-column: 1 / -1;
  color: #ffc3b9;
}

.ultimate-row {
  padding-top: 7px;
  border-top: 1px solid var(--color-line);
}

.ultimate-row__label {
  display: block;
  color: var(--color-muted);
  font-size: 0.6rem;
}

#player-grievance {
  color: #e8a9dc;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
}

.hand-panel {
  min-width: 0;
  padding: 8px 8px 5px;
  border: 1px solid rgb(255 225 164 / 16%);
  border-radius: 18px 18px 8px 8px;
  background:
    linear-gradient(180deg, rgb(56 37 24 / 76%), rgb(18 14 12 / 94%));
  box-shadow: 0 -7px 22px rgb(11 7 5 / 14%);
  backdrop-filter: blur(8px);
}

.hand-panel__header {
  min-height: 22px;
  margin-bottom: 4px;
  color: var(--color-muted);
  font-size: 0.65rem;
}

.hand-panel__header strong {
  color: var(--color-text);
  font-size: 0.76rem;
}

.pile-bar {
  gap: 6px;
  margin-bottom: 4px;
}

.pile-chip {
  min-width: 0;
  gap: 3px;
  padding: 2px 6px 2px 3px;
  border: 1px solid rgb(242 197 92 / 12%);
  border-radius: var(--radius-pill);
  color: var(--color-muted);
  background: rgb(0 0 0 / 16%);
  font-size: 0.56rem;
}

.pile-chip .card-icon {
  width: 23px;
  height: 23px;
}

.pile-chip strong {
  color: var(--color-sand-light);
  font-size: 0.67rem;
}

.hand-area {
  display: flex;
  gap: 9px;
  min-height: 143px;
  padding: 8px 3px 9px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  scrollbar-color: rgb(242 197 92 / 34%) rgb(0 0 0 / 14%);
  scrollbar-width: thin;
}

.battle-card {
  position: relative;
  flex: 0 0 104px;
  min-height: 132px;
  padding: 12px 8px 8px;
  overflow: hidden;
  border: 2px solid var(--card-color, var(--color-gold-dark));
  border-radius: 15px;
  color: var(--color-text);
  background:
    radial-gradient(circle at 50% 9%, rgb(255 255 255 / 12%), transparent 28%),
    linear-gradient(180deg, rgb(255 255 255 / 7%), transparent 34%),
    var(--card-background, #402a1c);
  box-shadow:
    inset 0 1px rgb(255 255 255 / 8%),
    0 8px 15px rgb(8 5 4 / 28%);
  scroll-snap-align: center;
  text-align: left;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    filter var(--transition-fast);
}

.battle-card::after {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(120deg, transparent 32%, rgb(255 255 255 / 8%) 46%, transparent 60%);
  content: "";
  opacity: 0;
  pointer-events: none;
  transform: translateX(-70%);
  transition: opacity var(--transition-fast), transform 360ms ease;
}

.battle-card:hover::after,
.battle-card.is-selected::after {
  opacity: 1;
  transform: translateX(70%);
}

.battle-card.is-selected {
  z-index: 2;
  box-shadow:
    0 0 0 2px rgb(255 226 152 / 62%),
    0 13px 26px rgb(0 0 0 / 38%);
  transform: translateY(-9px) scale(1.02);
}

.battle-card.is-unplayable:not(.is-selected) {
  filter: grayscale(0.65) brightness(0.68);
}

#enemy-placeholder.is-hit {
  animation: enemy-hit 360ms ease;
}

#player-area.is-hit {
  animation: player-hit 360ms ease;
}

.battle-card--attack {
  --card-color: #c45f4c;
  --card-background: #4d221c;
}

.battle-card--skill {
  --card-color: #4d8dab;
  --card-background: #183540;
}

.battle-card--power {
  --card-color: #a478bd;
  --card-background: #362342;
}

@keyframes dust-drift {
  from { transform: translate3d(-14px, 0, 0); }
  to { transform: translate3d(22px, 10px, 0); }
}

@keyframes enemy-hit {
  0%, 100% { transform: translateX(0); filter: none; }
  30% { transform: translateX(10px); filter: brightness(1.7) saturate(0.6); }
  55% { transform: translateX(-7px); }
}

@keyframes player-hit {
  0%, 100% { transform: translateX(0); filter: none; }
  30% { transform: translateX(-7px); filter: brightness(1.5) sepia(0.4); }
  55% { transform: translateX(5px); }
}

@media (max-width: 390px) {
  .battle-scene {
    padding-inline: 10px;
  }

  .battle-chapter-card .chapter-icon {
    width: 33px;
    height: 33px;
  }

  .battle-header__actions {
    gap: 3px;
  }

  .sprite-button {
    flex-basis: 34px;
    width: 34px;
    height: 34px;
  }

  .sprite-button .game-icon {
    width: 26px;
    height: 26px;
  }

  .currency-label {
    min-width: 51px;
    padding-inline: 6px;
  }

  .intent-panel {
    right: -2px;
    min-width: 118px;
    padding-left: 41px;
  }

  .hand-panel__header span {
    max-width: 65%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .pile-chip span:not(.game-icon) {
    display: none;
  }
}

@media (max-height: 760px) {
  .battle-scene {
    grid-template-rows: auto minmax(235px, 1fr) auto auto auto;
    gap: 6px;
    padding-top: 8px;
  }

  .enemy-stage {
    min-height: 155px;
  }

  .enemy-placeholder {
    width: min(52%, 220px);
    min-height: 135px;
  }

  .intent-panel {
    top: 7px;
  }

  .player-area {
    padding-block: 7px;
  }

  .hand-area {
    min-height: 121px;
    padding-top: 5px;
  }

  .battle-card {
    min-height: 112px;
  }

}

@media (prefers-reduced-motion: reduce) {
  .battle-atmosphere__dust {
    animation: none;
  }

  .battle-card::after {
    transition: none;
  }
}
