/* ============================================================
   FrameArmies : バトル画面

   レイアウトの原則
   - 盤面の位置は何をしても動かさない。そのため右パネルの高さは
     JS（fitLayout）で盤面列の高さに固定し、中身が増減しても外側に影響させない。
   - 盤面の表示サイズもJSが画面に合わせて決める（横画面のモバイルまで想定）。
   ============================================================ */

#screen-battle {
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.battle {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin: auto;
}

.battle__left {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: none;
  min-width: 0;
  /* 幅は battle_ui.js の fitLayout が盤面に合わせて設定する */
}

/* ---------------------------- 盤面 ---------------------------- */

.battle__board {
  padding: 10px;
  background: linear-gradient(150deg, rgba(40, 34, 22, 0.9), rgba(16, 14, 12, 0.9));
  border: 1px solid rgba(230, 199, 106, 0.28);
  border-radius: 14px;
  box-shadow: var(--shadow);
  line-height: 0;
}

#board {
  display: block;
  border-radius: 6px;
  cursor: pointer;
  touch-action: none;
}

#board.is-locked {
  cursor: wait;
}

#board.is-remove {
  cursor: crosshair;
}

/* ------------------- 盤面下の駒情報ウィンドウ ------------------- */

.board-info {
  height: 104px;
  flex: none;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 14px;
  background: linear-gradient(170deg, rgba(27, 33, 48, 0.95), rgba(13, 16, 24, 0.95));
  border: 1px solid rgba(230, 199, 106, 0.22);
  border-radius: 12px;
  overflow: hidden;
}

.board-info__icon {
  width: 56px;
  height: 56px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-info__icon img {
  width: 56px;
  height: 56px;
}

.board-info__body {
  min-width: 0;
  flex: 1;
  overflow-wrap: anywhere;
}

.board-info__head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.board-info__name {
  font-size: 16px;
  color: var(--gold);
  letter-spacing: 0.06em;
}

.board-info__side {
  font-size: 10px;
  letter-spacing: 0.14em;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
}

.board-info__side--ally {
  color: var(--blue);
}

.board-info__side--enemy {
  color: var(--red);
}

.board-info__stats {
  font-size: 12px;
  color: var(--ink-dim);
}

.board-info__stats b {
  color: var(--ink);
  font-size: 13px;
}

.board-info__stats .ice {
  color: var(--blue);
}

.board-info__desc {
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink-dim);
  margin-top: 2px;
}

.board-info__warn {
  color: #ffb0a4;
}

.board-info__hint {
  color: var(--ink-faint);
  font-size: 12.5px;
  line-height: 1.6;
  align-self: center;
}

.board-info__hp {
  display: inline-block;
  width: 74px;
  height: 7px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  vertical-align: -1px;
  margin: 0 6px;
  overflow: hidden;
}

.board-info__hp i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #5a8f6a, var(--green));
}

/* ---------------------------- 情報パネル ---------------------------- */

.battle__panel {
  width: 330px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 14px;
  background: linear-gradient(170deg, rgba(27, 33, 48, 0.95), rgba(13, 16, 24, 0.95));
  border: 1px solid rgba(230, 199, 106, 0.22);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* 通常はまとめ役の div を透過させ、パネル直下の縦並びとして扱う */
.panel-col {
  display: contents;
}

.panel-head {
  border-bottom: 1px solid rgba(230, 199, 106, 0.22);
  padding-bottom: 9px;
  flex: none;
}

.panel-head__stage {
  font-size: 17px;
  color: var(--gold);
  letter-spacing: 0.08em;
}

.panel-head__turn {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-top: 2px;
}

.turn-now {
  font-family: var(--font-en);
  font-size: 30px;
  line-height: 1;
  color: var(--ink);
}

.turn-sep,
.turn-max {
  color: var(--ink-faint);
  font-family: var(--font-en);
  font-size: 17px;
}

.turn-label {
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.14em;
  margin-left: 4px;
}

.panel-head__turn.is-warn .turn-now {
  color: var(--red);
}

/* コストゲージ */
.gauge {
  flex: none;
}

.gauge__label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.1em;
  margin-bottom: 5px;
}

.gauge__label strong {
  color: var(--gold);
  font-size: 14px;
}

.gauge__bar {
  height: 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.gauge__fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #5a8f6a, var(--green));
  transition: width 0.25s ease, background 0.25s ease;
}

.gauge__fill.is-high {
  background: linear-gradient(90deg, #a07a2a, var(--gold));
}

.gauge__fill.is-full {
  background: linear-gradient(90deg, #8e2f22, var(--red));
}

/* カウンタ */
.counters {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  flex: none;
}

.counter {
  text-align: center;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 8px;
  padding: 6px 4px;
}

.counter__num {
  display: block;
  font-family: var(--font-en);
  font-size: 21px;
  line-height: 1.1;
}

.counter__label {
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.1em;
}

.counter.is-warn {
  background: rgba(224, 96, 79, 0.14);
}

.counter.is-warn .counter__num {
  color: var(--red);
}

/* ブロック見出し */
.block-title {
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--gold);
  margin-bottom: 7px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.block-title__hint {
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0;
}

/* ---------------------------- 手札 ---------------------------- */

.hand-block {
  flex: none;
}

.hand {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  min-height: 112px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 6px;
  background: linear-gradient(170deg, rgba(44, 52, 72, 0.95), rgba(20, 25, 36, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 9px;
  cursor: pointer;
  transition: 0.14s ease;
  user-select: none;
}

.card:hover {
  transform: translateY(-3px);
  border-color: rgba(230, 199, 106, 0.6);
}

.card.is-sel {
  border-color: var(--gold);
  background: linear-gradient(170deg, rgba(78, 66, 34, 0.95), rgba(38, 32, 18, 0.95));
  box-shadow: 0 0 0 1px var(--gold), 0 8px 20px rgba(230, 199, 106, 0.16);
  transform: translateY(-4px);
}

.card.is-unaffordable {
  opacity: 0.55;
  filter: grayscale(0.5);
  padding-top: 15px;
}

.card.is-unaffordable::after {
  content: "コスト超過";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  padding: 1px 0;
  font-size: 9px;
  letter-spacing: 0.04em;
  color: #ffd9d2;
  background: rgba(142, 47, 34, 0.92);
  border-radius: 8px 8px 0 0;
  text-align: center;
}

.card.is-unaffordable .card__dir {
  display: none;
}

.card img {
  width: 44px;
  height: 44px;
  display: block;
}

.card__name {
  font-size: 12px;
  letter-spacing: 0.02em;
}

.card__stats {
  display: flex;
  gap: 7px;
  font-size: 10px;
  color: var(--ink-faint);
}

.card__cost {
  color: var(--gold);
  font-weight: 700;
}

.card__atk {
  color: #ffb9a8;
}

.card__dir {
  position: absolute;
  top: 4px;
  right: 5px;
  font-size: 9px;
  color: var(--blue);
}

.card-empty {
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-faint);
  font-size: 11px;
}

/* ---------------------------- 向きパッド ---------------------------- */

.dir-block {
  background: rgba(127, 212, 255, 0.06);
  border: 1px solid rgba(127, 212, 255, 0.22);
  border-radius: 9px;
  padding: 8px 10px;
  flex: none;
  transition: opacity 0.15s ease;
}

/* 向き指定が不要なときも枠は残す。消すと盤面の位置が動いてしまうため */
.dir-block.is-idle {
  opacity: 0.4;
  pointer-events: none;
}

.dir-pad {
  display: grid;
  grid-template-columns: repeat(3, 38px);
  grid-template-rows: repeat(2, 30px);
  gap: 5px;
  justify-content: center;
}

.dir-btn {
  font-family: inherit;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  color: var(--ink-dim);
  cursor: pointer;
  font-size: 13px;
  transition: 0.12s ease;
}

.dir-btn:hover {
  border-color: var(--blue);
  color: var(--ink);
}

.dir-btn.is-on {
  background: rgba(127, 212, 255, 0.2);
  border-color: var(--blue);
  color: #eaf9ff;
}

.dir-btn[data-dir="up"] {
  grid-column: 2;
  grid-row: 1;
}

.dir-btn[data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.dir-btn[data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

.dir-btn[data-dir="down"] {
  grid-column: 2;
  grid-row: 2;
}

/* ---------------------------- 操作ボタン ---------------------------- */

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex: none;
}

.btn--turn {
  font-size: 17px;
  letter-spacing: 0.2em;
  padding: 12px;
  background: linear-gradient(180deg, #7a5f1f, #4d3a10);
  border-color: var(--gold);
  color: #fff6dd;
  font-weight: 600;
  flex: none;
}

.btn--turn:hover:not(:disabled) {
  background: linear-gradient(180deg, #8d6e25, #5b4514);
  box-shadow: 0 0 22px rgba(230, 199, 106, 0.22);
}

#btn-retreat {
  flex: none;
}

/* ---------------------------- 戦況ログ ---------------------------- */

.log-block {
  margin-top: auto;
  flex: none;
}

.log {
  height: 120px;
  overflow-y: auto;
  font-size: 11.5px;
  line-height: 1.55;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--ink-dim);
}

.log p {
  margin: 0 0 2px;
}

.log .lg-turn {
  color: var(--gold);
  border-top: 1px solid rgba(230, 199, 106, 0.18);
  margin-top: 5px;
  padding-top: 4px;
}

.log .lg-hit {
  color: #ffd0a8;
}

.log .lg-miss {
  color: var(--ink-faint);
}

.log .lg-kill {
  color: var(--green);
}

.log .lg-bad {
  color: var(--red);
}

.log .lg-ice {
  color: var(--blue);
}

/* ============================================================
   画面が狭い・低いときの詰め方
   横画面のモバイル（高さ400〜500px程度）でも成立させる。
   ============================================================ */

/* 横に入りきらない場合のみ縦積みにする */
@media (max-width: 900px) and (orientation: portrait) {
  .battle {
    flex-direction: column;
    align-items: center;
  }

  .battle__panel {
    width: min(100%, 560px);
  }
}

/* 高さの低い横画面（モバイル横持ちなど）
   縦に積むと「ターン開始」が画面外へ落ちるので、パネルを2列に組み替える。
   ※このメディアクエリの条件は battle_ui.js の SHORT_LANDSCAPE と一致させること */
@media (max-height: 620px) and (orientation: landscape) {
  .battle__panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-content: start;
  }

  .panel-col {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
  }

  .log-block {
    margin-top: 0;
  }

  .battle__panel {
    overflow-x: hidden;
  }
}

/* 2列にすると1列あたりが細くなる幅では、中身も1列に落とす */
@media (max-height: 620px) and (orientation: landscape) and (max-width: 800px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .block-title__hint {
    display: none;
  }

  .dir-pad {
    grid-template-columns: repeat(3, 30px);
  }
}

/* 高さの低い画面全般の詰め方 */
@media (max-height: 620px) {
  #screen-battle {
    padding: 8px;
  }

  .battle {
    gap: 10px;
  }

  .battle__left {
    gap: 7px;
  }

  .battle__board {
    padding: 7px;
    border-radius: 10px;
  }

  .board-info {
    height: 78px;
    padding: 7px 10px;
    gap: 9px;
  }

  .board-info__icon,
  .board-info__icon img {
    width: 42px;
    height: 42px;
  }

  .board-info__name {
    font-size: 14px;
  }

  .board-info__desc,
  .board-info__stats,
  .board-info__hint {
    font-size: 11px;
    line-height: 1.45;
  }

  /* 幅は battle_ui.js の fitLayout が画面に合わせて決める */
  .battle__panel {
    padding: 10px;
    gap: 8px;
  }

  .panel-head__stage {
    font-size: 14px;
  }

  .turn-now {
    font-size: 24px;
  }

  .counter {
    padding: 4px 2px;
  }

  .counter__num {
    font-size: 17px;
  }

  .hand {
    min-height: 96px;
  }

  .card img {
    width: 36px;
    height: 36px;
  }

  .card__name {
    font-size: 11px;
  }

  .dir-pad {
    grid-template-columns: repeat(3, 32px);
    grid-template-rows: repeat(2, 26px);
  }

  .btn--turn {
    font-size: 15px;
    padding: 9px;
  }

  .log {
    height: 76px;
  }
}

/* さらに低い画面ではログを畳んで盤面を優先する */
@media (max-height: 460px) {
  .board-info {
    height: 66px;
  }

  .log {
    height: 54px;
  }
}
