/* FR/LG composition: stage, one context-sensitive console, online controls outside it. */
@font-face {
  font-family: 'Carinena FRLG';
  src: url('/assets/battle-frlg/latin.ttf') format('truetype');
  font-display: swap;
}
#battle-dialog {
  width: min(800px, calc(100vw - 12px), calc((100dvh - 64px) * 1.5));
  max-width: none;
  max-height: calc(100dvh - 12px);
  padding: 0;
  border: 4px solid #41434c;
  border-radius: 4px;
  background: #303443;
  box-shadow: 0 5px 0 #20252c;
  overflow: auto;
  container-type: inline-size;
  color: #414141;
  font-family: 'Carinena FRLG', monospace;
  font-size: 6.667cqw;
  line-height: 1;
  text-shadow: 1px 1px #c6c6bd;
}
#battle-dialog[open] {
  display: flex;
  flex-direction: column;
}
#battle-dialog [hidden] {
  display: none !important;
}
#battle-dialog::backdrop {
  background: #152725b8;
  backdrop-filter: blur(2px);
}
#battle-dialog button {
  font: inherit;
  color: inherit;
  text-shadow: inherit;
  touch-action: manipulation;
}
#battle-dialog .battle-top {
  order: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 32px;
  padding: 0 12px;
  background: #303443;
  color: #ebe8db;
  font:
    16px 'Comarca Pixel',
    monospace;
  text-shadow: none;
  gap: 8px;
}
#battle-dialog .battle-top button {
  min-height: 32px;
  padding: 0 6px;
  border: 0;
  box-shadow: none;
  background: none;
}
#battle-dialog .battle-scene {
  position: relative;
  flex: none;
  height: auto;
  min-height: 0;
  aspect-ratio: 240 / 112;
  overflow: hidden;
  background: #dff6da url('/assets/battle-frlg/grass.png') center / 100% 100% no-repeat;
  image-rendering: pixelated;
  isolation: isolate;
}
#battle-dialog[data-terrain='building'] .battle-scene {
  background-image: url('/assets/battle-frlg/building.png');
}
#battle-dialog .battle-scene::before,
#battle-dialog .battle-scene::after {
  display: none;
}
#battle-dialog .own-sprite,
#battle-dialog .enemy-sprite {
  position: absolute;
  width: 27%;
  height: 50%;
  max-width: none;
  object-fit: contain;
  image-rendering: pixelated;
  z-index: 1;
  transform-origin: center bottom;
  transition: none;
}
#battle-dialog .own-sprite {
  left: 9%;
  right: auto;
  top: auto;
  bottom: -7%;
  height: 60%;
}
#battle-dialog .enemy-sprite {
  right: 9%;
  left: auto;
  top: 5%;
  bottom: auto;
}
#battle-dialog .is-fainted,
#battle-dialog .is-captured {
  opacity: 0;
}
#battle-dialog .monster-info {
  position: absolute;
  z-index: 5;
  width: 42%;
  padding: 1.1% 1.6% 1%;
  border: max(2px, 0.4cqw) solid #3c4932;
  border-radius: 1.5cqw 0.4cqw 1.5cqw 0.4cqw;
  background: #ffffde;
  box-shadow:
    0.4cqw 0.4cqw 0 #bdc59c,
    1.2cqw 1.7cqw 0 #52665d;
  font-size: 5.3cqw;
  line-height: 1;
}
#battle-dialog .enemy-info {
  left: 4%;
  top: 10%;
  right: auto;
  bottom: auto;
}
#battle-dialog .own-info {
  right: 3%;
  bottom: 6%;
  left: auto;
  top: auto;
  width: 45%;
  padding-bottom: 0.5%;
}
#battle-dialog .monster-info > div:first-child {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1%;
}
#battle-dialog .monster-info strong {
  font: inherit;
  text-transform: uppercase;
  white-space: nowrap;
}
#battle-dialog .monster-info span {
  font-size: inherit;
}
#battle-dialog #enemy-level,
#battle-dialog #own-level {
  font-size: 5.3cqw;
  white-space: nowrap;
}
#battle-dialog .hp-row {
  display: flex;
  align-items: center;
  gap: 2%;
  margin: 0.3cqw 0 0 19%;
  padding: 0.1cqw 0.6cqw;
  border-radius: 2cqw;
  background: #52665d;
}
#battle-dialog .hp-row b {
  color: #f7d44a;
  font-size: 4cqw;
  font-weight: normal;
  text-shadow: 1px 1px #9a781a;
}
#battle-dialog .hp-track {
  flex: 1;
  height: 1.7cqw;
  min-height: 6px;
  margin: 0;
  padding: 1px;
  border: 1px solid #ffffde;
  border-radius: 3cqw;
  background: #424b48;
  overflow: hidden;
}
#battle-dialog .hp-track i {
  display: block;
  height: 100%;
  background: linear-gradient(#398b6b 0 35%, #70f7a0 35% 75%, #b2ffcc 75%);
  border-radius: 0;
  transition: width 300ms linear;
}
#battle-dialog .hp-track i.medium {
  background: linear-gradient(#be9229 0 35%, #ffde4a 35% 75%, #fff49c 75%);
}
#battle-dialog .hp-track i.low {
  background: linear-gradient(#a84129 0 35%, #f77352 35% 75%, #ffb594 75%);
}
#battle-dialog #own-health {
  display: block;
  font: inherit;
  text-align: right;
  margin: 0 1cqw 0 0;
}
#battle-dialog #enemy-count {
  position: absolute;
  top: calc(100% + 2.7cqw);
  left: 0;
  font:
    16px 'Comarca Pixel',
    monospace;
  text-shadow: none;
}
#battle-dialog .monster-meta {
  position: absolute;
  left: 1.4cqw;
  bottom: 1.1cqw;
  margin: 0;
  display: flex;
  gap: 1cqw;
}
#battle-dialog .enemy-info .monster-meta {
  bottom: 0.5cqw;
}
#battle-dialog .monster-meta .battle-status {
  font:
    16px 'Comarca Pixel',
    monospace;
  background: #936880;
  color: white;
  padding: 0 3px;
  text-shadow: none;
}
#battle-dialog .team-balls {
  display: none;
}
#battle-dialog .battle-exp {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 0.2cqw);
  height: 1.8cqw;
  display: flex;
  gap: 1cqw;
  align-items: center;
  padding: 0 1cqw;
  background: #52665d;
}
#battle-dialog .battle-exp b {
  font: 2.5cqw 'Carinena FRLG';
  color: #f7de39;
  text-shadow: none;
}
#own-exp-track {
  flex: 1;
  height: 0.8cqw;
  background: #394b50;
}
#own-exp {
  display: block;
  height: 100%;
  background: #48cee9;
  transition: width 400ms linear;
}
#battle-dialog .battle-console {
  position: relative;
  display: block;
  flex: none;
  height: max(20cqw, 104px);
  min-height: 0;
  padding: 0;
  border: 0;
  background: #29526a;
}
#battle-dialog .battle-narration {
  display: none;
  height: 100%;
  padding: 2cqw 7cqw 2cqw 3cqw;
  border: 1.1cqw solid #c5a54a;
  border-radius: 1cqw;
  box-shadow: inset 0 0 0 0.7cqw #deded6;
  background: #29526a;
  align-items: center;
  min-height: 0;
  overflow: hidden;
}
#battle-dialog[data-playing='true'] .battle-narration,
#battle-dialog[data-waiting='true'] .battle-narration,
#battle-dialog[data-finished='true'] .battle-narration {
  display: flex;
}
#battle-dialog #battle-message {
  margin: 0;
  color: #fff;
  font: inherit;
  font-size: 6cqw;
  line-height: 1.1;
  text-shadow: 0.25cqw 0.25cqw #687388;
  max-height: 100%;
  overflow-y: auto;
  min-width: 0;
  overflow-wrap: anywhere;
  overscroll-behavior: contain;
}
#battle-dialog #battle-skip {
  position: absolute;
  right: 1cqw;
  bottom: 1cqw;
  width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  box-shadow: none;
  background: none;
  color: #fff;
  font: 26px 'Comarca Pixel';
}
#battle-dialog #battle-controls {
  color: #414141;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: 46% 54%;
  grid-template-rows: 1fr;
  padding: 0;
  gap: 0;
}
#battle-dialog #battle-question {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  align-items: center;
  margin: 0;
  padding: 2cqw 3cqw;
  color: white;
  font: inherit;
  font-size: 5.8cqw;
  line-height: 1.1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overflow-wrap: anywhere;
  border: 1cqw solid #c5a54a;
  box-shadow: inset 0 0 0 0.6cqw #deded6;
  text-shadow: 0.25cqw 0.25cqw #687388;
}
#battle-dialog .battle-commands,
#battle-dialog .move-buttons {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: repeat(2, 1fr);
  padding: 1cqw;
  margin: 0;
  gap: 0;
  border: 0.8cqw solid #666b81;
  box-shadow: inset 0 0 0 0.5cqw #c6bcd5;
  background: #fffaff;
}
#battle-dialog .battle-commands button,
#battle-dialog .move-buttons button {
  position: relative;
  display: block;
  text-align: left;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 0 0 0 2.8cqw;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: none;
  font-size: 5.3cqw;
  line-height: 1;
  text-transform: uppercase;
  outline: none;
}
#battle-dialog .battle-commands button::before,
#battle-dialog .move-buttons button::before {
  display: none;
  content: '';
  position: absolute;
  top: calc(50% - 0.9cqw);
  left: 0.6cqw;
  border-top: 0.9cqw solid transparent;
  border-bottom: 0.9cqw solid transparent;
  border-left: 1.2cqw solid #414141;
}
#battle-dialog .battle-commands button:focus:not(:disabled)::before,
#battle-dialog .move-buttons button:focus:not(:disabled)::before {
  display: block;
}
#battle-dialog button:disabled {
  opacity: 0.4;
}
#battle-dialog[data-panel='fight'] #battle-controls {
  grid-template-columns: 70% 30%;
}
#battle-dialog[data-panel='fight'] #battle-question {
  display: none;
}
#battle-dialog .move-buttons {
  grid-column: 1;
  padding: 1cqw 0.8cqw;
}
#battle-dialog .move-buttons button {
  font-size: 5.3cqw;
  letter-spacing: -0.08cqw;
}
#battle-dialog #move-details {
  grid-column: 2;
  grid-row: 1;
  border: 0.8cqw solid #666b81;
  box-shadow: inset 0 0 0 0.5cqw #c6bcd5;
  background: #fffaff;
  padding: 2.3cqw 1.5cqw 0;
  font-size: 5.8cqw;
}
#move-details > div {
  display: flex;
  justify-content: space-between;
}
#move-details b {
  font-weight: normal;
  color: #c9aa00;
}
#move-details p {
  margin: 0.7cqw 0 0;
  font-size: 5.1cqw;
  white-space: nowrap;
  text-transform: uppercase;
}
#battle-dialog #battle-help {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
#battle-dialog #battle-back {
  width: auto;
  position: absolute;
  right: 1cqw;
  bottom: 0;
  height: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 4px;
  background: none;
  border: 0;
  box-shadow: none;
  font:
    18px 'Comarca Pixel',
    monospace;
}
#battle-dialog[data-panel='party'] .battle-console,
#battle-dialog[data-panel='bag'] .battle-console,
#battle-dialog[data-panel='potion'] .battle-console {
  height: max(24cqw, 190px);
}
#battle-dialog[data-panel='party'] #battle-question,
#battle-dialog[data-panel='bag'] #battle-question,
#battle-dialog[data-panel='potion'] #battle-question {
  display: none;
}
#battle-dialog #switch-options,
#battle-dialog #battle-bag,
#battle-dialog #battle-potion-targets {
  grid-column: 1 / -1;
  grid-row: 1;
  margin: 0;
  padding: 2cqw 2cqw 44px;
  background: #fffaff;
  border: 0.8cqw solid #666b81;
  font:
    24px 'Comarca Pixel',
    monospace;
  text-shadow: none;
}
#battle-dialog #switch-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  overflow: auto;
  gap: 5px;
}
#battle-dialog #switch-options button {
  padding: 3px;
  min-height: 52px;
  line-height: 1;
  border: 2px solid #93a28c;
  background: #f7f9e6;
}
#battle-dialog #switch-options img {
  width: 32px;
  height: 32px;
  float: left;
  image-rendering: pixelated;
}
#battle-dialog :is(#capture-button, #battle-potion-button) {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 8px 12px;
  color: #293544;
  background: #fff4cb;
  border: 2px solid #52665d;
  border-radius: 2px;
  box-shadow: 0 3px 0 #bdc59c;
  text-shadow: none;
}
#battle-dialog :is(#capture-button, #battle-potion-button):is(:focus, :hover):not(:disabled) {
  background: #ffe199;
  outline: 3px solid #a43f24;
  outline-offset: 2px;
}
#battle-dialog :is(#capture-button, #battle-potion-button):disabled {
  color: #53595d;
  background: #e1e2dc;
  opacity: 1;
  box-shadow: none;
}
#capture-count,
#battle-potion-count {
  margin-left: auto;
}
.capture-ball-icon {
  position: relative;
  flex: 0 0 26px;
  height: 26px;
  border: 3px solid #293544;
  border-radius: 50%;
  background: linear-gradient(#d94535 0 43%, #293544 43% 57%, #fffdf0 57%);
}
.capture-ball-icon::after {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px solid #293544;
  border-radius: 50%;
  background: #fffdf0;
}
#battle-dialog #bag-battle-help {
  margin-top: 12px;
  color: #414141;
  font:
    18px / 1.15 'Comarca Pixel',
    monospace;
  text-shadow: none;
}
#battle-dialog #battle-finish {
  width: auto;
  margin: 0;
  position: absolute;
  right: 1cqw;
  bottom: 0;
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  box-shadow: none;
  background: #29526a;
  color: white;
  font:
    20px 'Comarca Pixel',
    monospace;
  text-shadow: none;
}
#battle-dialog[data-finished='true'] #battle-message {
  padding-bottom: 28px;
  font-size: 5cqw;
}
#battle-effects {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  z-index: 3;
  pointer-events: none;
}
#battle-feedback {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  padding: 3px 6px;
  border: 2px solid #fffde4;
  background: #6a4141;
  color: white;
  font: 20px 'Comarca Pixel';
  text-shadow: none;
}
#battle-feedback[data-side='enemy'] {
  right: 14%;
  top: 38%;
}
#battle-feedback[data-side='own'] {
  left: 16%;
  top: 68%;
}
#battle-feedback[data-good='true'] {
  background: #3e7756;
}
@media (max-width: 600px) {
  #battle-dialog {
    width: calc(100vw - 8px);
    border-width: 2px;
  }
  #battle-dialog #enemy-count {
    font-size: 12px;
  }
  #battle-dialog .battle-top {
    font-size: 13px;
    padding: 0 6px;
    gap: 3px;
  }
  #battle-dialog .monster-meta .battle-status {
    font-size: 12px;
  }
  #battle-dialog #switch-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    font-size: 20px;
  }
  #battle-dialog[data-panel='fight'] #battle-controls {
    grid-template-columns: 69% 31%;
  }
}
@media (max-height: 500px) and (orientation: landscape) {
  #battle-dialog {
    width: min(680px, calc((100dvh - 46px) * 1.5));
  }
  #battle-dialog .battle-top,
  #battle-dialog .battle-top button {
    min-height: 28px;
  }
  #battle-dialog[data-panel='party'] .battle-console,
  #battle-dialog[data-panel='bag'] .battle-console,
  #battle-dialog[data-panel='potion'] .battle-console {
    height: 155px;
  }
  .mobile-game #battle-dialog[data-panel='bag'] .battle-screen,
  .mobile-game #battle-dialog[data-panel='potion'] .battle-screen {
    /* Keep the stage proportions while reserving room for the item and B/Volver. */
    width: min(
      100%,
      calc((100dvh - 203px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 2.142857)
    );
  }
  #battle-dialog #battle-bag,
  #battle-dialog #battle-potion-targets {
    padding: 6px 8px 44px;
    border-width: 3px;
  }
  #battle-dialog :is(#capture-button, #battle-potion-button) {
    min-height: 44px;
    padding: 6px 8px;
    font-size: 20px;
    gap: 8px;
  }
  #battle-dialog #bag-battle-help {
    margin-top: 8px;
    font-size: 16px;
  }
}
@media (prefers-reduced-motion: reduce) {
  #battle-dialog .hp-track i,
  #own-exp {
    transition: none;
  }
}

#battle-dialog .battle-commands,
#battle-dialog .move-buttons,
#battle-dialog #move-details,
#battle-dialog #battle-back {
  width: auto;
  color: #414141;
}

#battle-items {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
#battle-items.only-potions {
  grid-template-columns: 1fr;
}
#battle-dialog #battle-bag {
  overflow-y: auto;
}
.potion-bottle-icon {
  display: grid;
  place-items: center;
  flex: 0 0 22px;
  height: 26px;
  border: 2px solid #51476f;
  border-top: 5px solid #ded5ee;
  border-radius: 5px;
  background: #8e66b5;
  color: white;
  font: bold 20px monospace;
}
#battle-dialog #battle-potion-targets {
  overflow-y: auto;
}
.battle-item-caption {
  margin: 0 0 6px;
  font:
    17px / 1.1 'Comarca Pixel',
    monospace;
}
.battle-item-team {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}
#battle-dialog .battle-item-team button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px;
  min-height: 52px;
  font:
    18px / 1.1 'Comarca Pixel',
    monospace;
  color: #293544;
  background: #f7f9e6;
  border: 2px solid #93a28c;
  text-align: left;
}
.battle-item-team img {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
}
.battle-item-team small {
  display: block;
  font-size: 14px;
}
#battle-dialog .battle-item-team button:disabled {
  opacity: 1;
  background: #e1e2dc;
  color: #5f6464;
}
@media (max-width: 500px) {
  #battle-dialog :is(#capture-button, #battle-potion-button) {
    padding: 6px;
    gap: 6px;
    font-size: 20px;
  }
}

/* Keep the scrollable team above B/Volver, including the last row on a phone. */
#battle-dialog[data-panel='potion'] #battle-controls {
  background: #fffaff;
}
#battle-dialog #battle-potion-targets {
  margin-bottom: 44px;
  padding-bottom: 8px;
  border-bottom: 0;
}
