/* Real-time battle HUD. Loaded last; all rules are scoped to the battle so
   exploration layout is untouched. Layout bands:
   top: hero bar (left) + enemy bar (right)
   middle: fighting stage (measured by combat.js, never covered)
   bottom: movement (left), menus (centre), fighting actions (right). */
#battleHud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}
#battleHud > * {
  pointer-events: auto;
}
#battleHud .bhud-top {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  pointer-events: none;
}
#battleHud .enemybar {
  position: static;
  width: min(360px, 42vw);
  padding: 10px 12px;
  pointer-events: auto;
}
#battleHud .enemybar > span {
  display: block;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#battleHud .enemyhp i {
  background: linear-gradient(90deg, #e8645a, #f5a46a);
}
#enemyIntent {
  display: block;
  margin-top: 4px;
  font-size: 11.5px;
  line-height: 1.35;
  color: #f1dfb2;
}
#enemyIntent.danger {
  color: #ffb08a;
  font-weight: 700;
}
body.battling .herobar {
  z-index: 7;
}
body.battling .herobar #menuBtn {
  display: none;
}
#battleMode {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  letter-spacing: 0.08em;
  font-weight: 800;
  background: #0d2333cc;
  color: #9fe8c8;
  border: 1px solid #9fe8c855;
  pointer-events: none;
}
#battleMode.paused {
  color: #ffd27a;
  border-color: #ffd27a88;
}
#battleLog {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: calc(42px + env(safe-area-inset-top, 0px));
  max-width: min(520px, 46vw);
  font-size: 12px;
  color: #e8f2ee;
  text-align: center;
  text-shadow: 0 1px 3px #000c;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
/* buttons */
#battleHud button {
  position: relative;
  font: inherit;
  color: var(--ink);
  border: 1px solid #b8d9cb55;
  background: linear-gradient(160deg, #1d4258f2, #10283af2);
  border-radius: 12px;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#battleHud button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
#battleHud button .lbl {
  display: block;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#battleHud button .keycap {
  display: block;
  font-size: 10px;
  color: #a9c6c8;
  margin-top: 1px;
}
#battleHud button .cd {
  position: absolute;
  top: 3px;
  right: 6px;
  font-style: normal;
  font-size: 10px;
  color: #ffd27a;
  font-weight: 700;
}
#battleHud button.held,
#battleHud button.active {
  background: linear-gradient(160deg, #3a7d8a, #1e5060);
  border-color: #bff4e6;
  transform: translateY(1px);
}
#battleHud button.cooling {
  opacity: 0.62;
}
#battleHud button.nomp .lbl {
  color: #8fb0c8;
}
#battleHud button:disabled {
  opacity: 0.35;
  cursor: default;
}
/* desktop: one low strip along the bottom */
#battleMove,
#commands,
#battleMenu {
  position: absolute;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: grid;
  gap: 6px;
}
#battleMove {
  left: calc(12px + env(safe-area-inset-left, 0px));
  grid-template-columns: repeat(3, 58px);
}
#commands {
  right: calc(12px + env(safe-area-inset-right, 0px));
  grid-template-columns: repeat(5, 84px);
}
#battleMenu {
  left: 50%;
  transform: translateX(-50%);
  grid-template-columns: repeat(6, auto);
}
#battleMove button,
#commands button {
  height: 56px;
  padding: 4px;
}
#battleMove .lbl {
  font-size: 18px;
}
#battleMenu button {
  height: 40px;
  padding: 3px 12px;
}
#battleMenu .lbl {
  font-size: 12px;
}
#commands .act-punch,
#commands .act-kick {
  background: linear-gradient(160deg, #6a3a2c, #3e2018);
  border-color: #ffb08a77;
}
#commands .act-cast {
  background: linear-gradient(160deg, #3a3a7a, #222048);
  border-color: #c8b6ff77;
}
#commands .act-guard {
  background: linear-gradient(160deg, #2c5a6a, #173440);
}
/* selection panel: pauses the fight, scrolls internally */
#battleHud #battleSub {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 24px));
  max-height: min(70dvh, 560px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 14px;
  border-radius: 16px;
  background: #0f2536f6;
  border: 1px solid #b8d9cb55;
  box-shadow: 0 18px 60px #000a;
  z-index: 20;
  display: block;
}
#battleHud #battleSub.hidden {
  display: none;
}
#battleSub .subhead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  gap: 8px;
}
#battleSub .subhead span {
  font-size: 12px;
  color: #ffd27a;
}
#battleSub .subgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
}
#battleHud #battleSub .subbtn {
  text-align: left;
  padding: 9px 10px;
  min-height: 64px;
}
#battleSub .subbtn b {
  display: block;
  font-size: 13px;
}
#battleSub .subbtn small {
  display: block;
  font-size: 11px;
  color: #b7d3d0;
  margin-top: 2px;
}
#battleSub .subbtn small.desc {
  color: #d8e6e2;
}
#battleSub .subbtn.selected {
  border-color: var(--gold);
}
#battleHud #battleSub .back {
  width: 100%;
  margin-top: 10px;
  padding: 10px;
}
.controlsgrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
  font-size: 13px;
}
.controlsgrid div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid #ffffff14;
  padding: 3px 0;
}
.movelist {
  margin: 4px 0 8px;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.55;
}
/* medium widths: stack menus above the strip */
@media (max-width: 1100px) {
  #battleMenu {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
  #commands {
    grid-template-columns: repeat(5, 72px);
  }
}
/* touch devices and phones: thumb clusters */
@media (pointer: coarse), (max-width: 760px) {
  #battleHud button .keycap {
    display: none;
  }
  #battleMenu {
    left: 50%;
    bottom: auto;
    top: calc(98px + env(safe-area-inset-top, 0px));
    transform: translateX(-50%);
    grid-template-columns: repeat(6, auto);
    gap: 4px;
  }
  #battleMenu button {
    height: 34px;
    padding: 2px 8px;
  }
  #battleMenu .lbl {
    font-size: 11px;
  }
}
/* phone portrait */
@media (max-width: 600px) and (min-height: 501px) {
  body.battling .herobar {
    width: calc(50% - 12px);
    padding: 6px;
    gap: 6px;
  }
  body.battling .herobar canvas {
    width: 36px;
    height: 40px;
  }
  body.battling .herobar strong {
    font-size: 11px;
  }
  body.battling .herobar .bar {
    height: 14px;
  }
  body.battling .herobar .bar span {
    font-size: 9.5px;
  }
  #battleHud .bhud-top {
    top: calc(8px + env(safe-area-inset-top, 0px));
    right: 8px;
  }
  #battleHud .enemybar {
    width: calc(50vw - 12px);
    padding: 7px 8px;
  }
  #battleHud .enemybar > span {
    font-size: 11px;
  }
  #enemyIntent {
    font-size: 10px;
  }
  #battleMode {
    top: auto;
    bottom: calc(196px + env(safe-area-inset-bottom, 0px));
  }
  #battleLog {
    top: auto;
    bottom: calc(172px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 24px);
    font-size: 11px;
  }
  #battleMenu {
    top: auto;
    bottom: calc(132px + env(safe-area-inset-bottom, 0px));
    width: calc(100vw - 16px);
    grid-template-columns: repeat(6, 1fr);
  }
  #battleMove {
    left: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: 58px 58px;
  }
  #battleMove .mv-jump {
    grid-column: 2;
    grid-row: 1;
  }
  #battleMove .mv-left {
    grid-column: 1;
    grid-row: 2;
  }
  #battleMove .mv-right {
    grid-column: 3;
    grid-row: 2;
  }
  #battleMove button,
  #commands button {
    height: 100%;
    min-height: 54px;
  }
  #commands {
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    grid-template-columns: repeat(3, 62px);
    grid-template-rows: 58px 58px;
  }
  #commands .act-punch {
    grid-column: 2;
    grid-row: 2;
  }
  #commands .act-kick {
    grid-column: 3;
    grid-row: 2;
  }
  #commands .act-cast {
    grid-column: 3;
    grid-row: 1;
  }
  #commands .act-guard {
    grid-column: 1;
    grid-row: 2;
  }
  #commands .act-dodge {
    grid-column: 2;
    grid-row: 1;
  }
  #commands .lbl {
    font-size: 12px;
  }
}
@media (max-width: 380px) and (min-height: 501px) {
  #battleMove {
    grid-template-columns: repeat(3, 46px);
  }
  #commands {
    grid-template-columns: repeat(3, 56px);
  }
  #commands .lbl {
    font-size: 11px;
  }
}
/* phone landscape: short screens */
@media (max-height: 500px) {
  body.battling .herobar {
    width: 230px;
    padding: 5px;
    top: 6px;
    left: calc(6px + env(safe-area-inset-left, 0px));
  }
  body.battling .herobar canvas {
    width: 32px;
    height: 36px;
  }
  body.battling .herobar strong {
    font-size: 11px;
    margin-bottom: 2px;
  }
  body.battling .herobar .bar {
    height: 13px;
    margin: 2px 0;
  }
  #battleHud .bhud-top {
    top: 6px;
    right: calc(6px + env(safe-area-inset-right, 0px));
  }
  #battleHud .enemybar {
    width: 250px;
    padding: 6px 8px;
  }
  #enemyIntent {
    font-size: 10px;
  }
  #battleMode {
    top: 6px;
  }
  #battleLog {
    top: 30px;
    max-width: calc(100vw - 520px);
    font-size: 11px;
  }
  #battleMenu {
    top: auto;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    grid-template-columns: repeat(3, auto);
    gap: 3px;
  }
  #battleMenu button {
    height: 30px;
    padding: 1px 8px;
  }
  #battleMove {
    left: calc(8px + env(safe-area-inset-left, 0px));
    bottom: 8px;
    grid-template-columns: repeat(3, 50px);
  }
  #battleMove button,
  #commands button {
    height: 48px;
    min-height: 0;
  }
  #commands {
    right: calc(8px + env(safe-area-inset-right, 0px));
    bottom: 8px;
    grid-template-columns: repeat(5, 58px);
  }
  #commands .lbl {
    font-size: 11px;
  }
  #battleHud #battleSub {
    max-height: calc(100dvh - 24px);
  }
}
@media (prefers-reduced-motion: reduce) {
  #battleHud button.held {
    transform: none;
  }
}
@media (max-width: 1180px) and (min-height: 501px) and (min-width: 601px) {
  #battleLog {
    top: calc(104px + env(safe-area-inset-top, 0px));
    max-width: calc(100vw - 40px);
  }
}
/* compact menu rows on phones (fixes overlap with thumb clusters) */
#battleMenu button {
  min-width: 0;
}
@media (max-width: 600px) and (min-height: 501px) {
  #battleMenu {
    bottom: calc(142px + env(safe-area-inset-bottom, 0px));
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
  #battleMenu button {
    padding: 2px 3px;
    height: 44px;
  }
  #battleMenu .lbl {
    font-size: 10.5px;
  }
  #battleMode {
    bottom: calc(220px + env(safe-area-inset-bottom, 0px));
  }
  #battleLog {
    bottom: calc(194px + env(safe-area-inset-bottom, 0px));
  }
}
@media (max-height: 500px) {
  #battleMenu {
    grid-template-columns: repeat(6, 52px);
    gap: 3px;
  }
  #battleMenu button {
    height: 44px;
    padding: 0 2px;
  }
  #battleMenu .lbl {
    font-size: 10px;
  }
  #commands {
    grid-template-columns: repeat(5, 54px);
    gap: 5px;
  }
  #battleMove {
    gap: 5px;
  }
}
@media (max-height: 500px) {
  #battleMenu {
    left: calc(176px + env(safe-area-inset-left, 0px));
    transform: none;
  }
}
#battleHud button .spell {
  display: block;
  font-size: 10px;
  color: #d8ccff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (pointer: coarse), (max-width: 760px) {
  #battleMenu .lbl {
    letter-spacing: -0.02em;
  }
  #battleHud .menu-analyze .lbl {
    font-size: 9.5px;
  }
}
@media (max-height: 500px) {
  #commands {
    grid-template-columns: repeat(5, 60px);
  }
  #commands .lbl {
    font-size: 11px;
  }
}
/* notices during a fight sit in the sky band, above the fighters' heads */
body.battling #toast {
  top: calc(96px + env(safe-area-inset-top, 0px));
  padding: 8px 14px;
  font-size: 13px;
}
body.battling #banner {
  top: calc(84px + env(safe-area-inset-top, 0px));
  font-size: 24px;
}
@media (max-width: 600px) and (min-height: 501px) {
  #battleMode {
    bottom: auto;
    top: calc(84px + env(safe-area-inset-top, 0px));
  }
  body.battling #toast {
    top: calc(112px + env(safe-area-inset-top, 0px));
  }
}
@media (max-height: 500px) {
  body.battling #toast,
  body.battling #banner {
    top: 64px;
    font-size: 12px;
  }
  body.battling #banner {
    font-size: 18px;
  }
}
