/* Battle command surface. Shared --ui-* tokens belong to styles.css.
   Keep stage, dock, pad handedness and touch geometry in the existing contract. */
.mode-battle .command-art {
  display: block;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
#game.mode-battle:has(.is-command) { grid-template-rows: minmax(0,1fr) auto; }
.mode-battle:has(.is-command) #stage { margin: 54px 0 0; }
.mode-battle:has(.is-command) #hud {
  position: relative;
  left: auto;
  right: auto;
  bottom: auto;
  margin: 6px max(16px,env(safe-area-inset-right)) 12px max(16px,env(safe-area-inset-left));
}
.mode-battle .battle-bar.is-command {
  display: grid;
  grid-template-columns: 288px minmax(100px,1fr) 130px 190px 64px;
  align-items: center;
  gap: 20px;
  height: 102px;
  max-width: 1120px;
  margin: auto;
  padding: 7px 0;
  background: none;
  border: 0;
  box-shadow: none;
  color: var(--ui-text,#eee3ce);
  font-family: var(--ui-font,system-ui,-apple-system,"Segoe UI","Malgun Gothic",sans-serif);
}

/* Portrait cards: one matte frame, a quiet label band and a selection underline. */
.formation-tabs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 0;
}
.is-command .formation {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  flex: 0 0 82px;
  width: 82px;
  height: 84px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 0 3px;
  border: 1px solid var(--ui-line,#b9996140);
  border-radius: var(--ui-radius,10px);
  background: var(--ui-panel,#26383b);
  color: var(--ui-text,#eee3ce);
  box-shadow: none;
  overflow: visible;
  transition: background-color .12s,border-color .12s;
}
.is-command .formation::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 0;
  height: 2px;
  border-radius: 1px;
  background: var(--ui-gold,#b99961);
  opacity: 0;
  pointer-events: none;
}
@media (hover:hover) { .is-command .formation:hover { background: #34484a; } }
.is-command .formation[aria-pressed=true] {
  border-color: var(--ui-gold,#b99961);
  background: var(--ui-panel,#26383b);
  color: var(--ui-paper,#f0e5cf);
}
.is-command .formation[aria-pressed=true]::after { opacity: 1; }
.is-command .formation:active { transform: none; background: var(--ui-ink,#202d30); }
.is-command .formation:disabled { filter: grayscale(1); opacity: .4; transform: none; }
.is-command .formation:focus-visible,
.is-command .command-fire:focus-visible,
.battle-bar.is-command .combat-exit:focus-visible,
.mode-battle .touch-fire:focus-visible {
  outline: 2px solid var(--ui-gold,#b99961);
  outline-offset: 3px;
}
.portrait-well {
  position: absolute;
  left: 4px;
  right: 4px;
  top: 2px;
  bottom: 27px;
  overflow: hidden;
  border-radius: calc(var(--ui-radius,10px) - 3px) calc(var(--ui-radius,10px) - 3px) 0 0;
  pointer-events: none;
}
.unit-portrait { display: block; width: 100%; height: 100%; object-fit: contain; }
.formation .name {
  position: relative;
  display: block;
  width: 100%;
  padding: 2px 8px;
  font-size: 14px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
  background: var(--ui-ink,#202d30);
  border-top: 1px solid var(--ui-line,#b9996140);
  border-radius: 0 0 calc(var(--ui-radius,10px) - 2px) calc(var(--ui-radius,10px) - 2px);
  white-space: nowrap;
  pointer-events: none;
}
.formation-strength {
  position: absolute;
  right: -3px;
  top: -3px;
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 24px;
  min-height: 24px;
  padding: 2px 6px;
  border: 1px solid var(--ui-line,#b9996140);
  border-radius: calc(var(--ui-radius,10px) - 4px);
  background: var(--ui-ink,#202d30);
  color: var(--ui-text,#eee3ce);
  font-variant-numeric: tabular-nums;
  z-index: 2;
}
.formation .count { font-size: 14px; font-weight: 700; line-height: 18px; margin: 0; color: inherit; }
.reserve-count { font-size: 12px; font-weight: 500; line-height: 16px; color: var(--ui-muted,#b4b3a3); }
.formation[aria-pressed=true] .formation-strength { border-color: var(--ui-gold,#b99961); }
.formation .number {
  display: block;
  position: absolute;
  left: 6px;
  top: 4px;
  z-index: 3;
  font-size: 12px;
  font-weight: 500;
  line-height: 16px;
  color: var(--ui-muted,#b4b3a3);
}
/* A single check keeps selection unambiguous on touch screens and in monochrome. */
.selected-tag { display: none; }
.formation[aria-pressed=true] .selected-tag {
  display: grid;
  place-items: center;
  position: absolute;
  left: -3px;
  top: -3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ui-gold,#b99961);
  color: var(--ui-ink,#202d30);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  z-index: 4;
  pointer-events: none;
}
.formation[aria-pressed=true] .number { visibility: hidden; }
.formation-load {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 0;
  height: 2px;
  background: var(--ui-ink,#202d30);
  border-radius: 1px;
  overflow: hidden;
  pointer-events: none;
}
.formation-load i { display: block; width: 0; height: 100%; background: var(--ui-gold,#b99961); transition: width .1s linear; }
.is-command .formation.next-corps:not(:focus-visible) { outline: 1px dashed var(--ui-gold,#b99961); outline-offset: 3px; }
.is-training .formation:disabled { display: none; }

/* Desktop readout: unit label, current state, progress, then supporting detail. */
.combat-readout {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
  max-width: none;
  min-width: 0;
  padding: 2px 18px;
  border-left: 1px solid var(--ui-line,#b9996140);
  color: var(--ui-text,#eee3ce);
}
#combat-status { font-size: 15px; font-weight: 600; line-height: 21px; margin: 0; word-break: keep-all; }
#combat-status > span { display: block; font-size: 12px; font-weight: 500; line-height: 17px; color: var(--ui-muted,#b4b3a3); margin-bottom: 3px; }
#combat-status > strong { font-size: 15px; font-weight: 600; line-height: 21px; }
.combat-readout .reload-track { height: 4px; background: var(--ui-panel,#26383b); border: 0; border-radius: 2px; overflow: hidden; }
#combat-load { display: block; height: 100%; background: var(--ui-gold,#b99961); }
#combat-tip { font-size: 12px; font-weight: 400; line-height: 18px; color: var(--ui-muted,#b4b3a3); margin: 0; font-variant-numeric: tabular-nums; }
.command-move { display: grid; grid-template-columns: 1fr; gap: 4px; color: var(--ui-muted,#b4b3a3); font-size: 12px; line-height: 17px; }
.command-move b { font-size: 14px; font-weight: 600; color: var(--ui-text,#eee3ce); grid-column: 1; align-self: end; }
.command-move > span { grid-column: 1; grid-row: 2; font-size: 12px; }
.command-move > small { grid-column: 1; grid-row: 3; display: flex; align-items: center; gap: 2px; justify-content: flex-start; }
.command-move small span { display: flex; gap: 2px; }
.command-move kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 20px;
  border: 1px solid var(--ui-line,#b9996140);
  border-radius: 3px;
  background: var(--ui-panel,#26383b);
  box-shadow: none;
  color: var(--ui-muted,#b4b3a3);
  font: 12px/18px var(--ui-font,system-ui,-apple-system,"Segoe UI","Malgun Gothic",sans-serif);
}
.is-command .command-fire {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 76px;
  padding: 8px 12px;
  border: 1px solid var(--ui-line,#b9996140);
  border-radius: var(--ui-radius,10px);
  background: var(--ui-red,#a04d3d);
  color: var(--ui-text,#eee3ce);
  box-shadow: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.action-art { display: block; width: 54px; height: 54px; flex: none; pointer-events: none; }
.action-art .command-art { width: 100%; height: 100%; }
.action-art [data-emblem] { display: none; width: 100%; height: 100%; }
[data-kind=infantry] .action-art [data-emblem=infantry],
[data-kind=cavalry] .action-art [data-emblem=cavalry],
[data-kind=artillery] .action-art [data-emblem=artillery] { display: block; }
.action-copy { display: flex; flex-direction: column; gap: 3px; align-items: center; min-width: 0; }
.action-copy b { font-size: 16px; font-weight: 600; white-space: nowrap; line-height: 22px; }
.action-copy small { font-size: 12px; font-weight: 500; line-height: 16px; word-break: keep-all; }
.action-copy kbd { font: 12px/16px var(--ui-font,system-ui,-apple-system,"Segoe UI","Malgun Gothic",sans-serif); letter-spacing: .04em; color: var(--ui-paper,#f0e5cf); background: transparent; border: 0; padding: 0; box-shadow: none; }
.is-command .command-fire[data-state=reload] { background: linear-gradient(90deg,var(--ui-panel,#26383b) calc(var(--action-progress,0)*100%),var(--ui-ink,#202d30) 0); }
.is-command .command-fire[data-state=blocked] { background: var(--ui-panel,#26383b); color: var(--ui-muted,#b4b3a3); }
.is-command .command-fire:hover { border-color: var(--ui-gold,#b99961); }
.is-command .command-fire:active,
.is-command .command-fire[data-state=active],
.is-command .command-fire.held-fire { box-shadow: inset 0 -2px var(--ui-gold,#b99961); transform: none; border-color: var(--ui-gold,#b99961); }
.battle-bar.is-command .combat-exit {
  min-width: 44px;
  min-height: 44px;
  max-width: 68px;
  padding: 8px;
  border: 1px solid var(--ui-line,#b9996140);
  background: var(--ui-panel,#26383b);
  color: var(--ui-muted,#b4b3a3);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--ui-radius,10px);
  box-shadow: none;
  line-height: 18px;
  word-break: keep-all;
}
.battle-bar.is-command .combat-exit:hover { border-color: var(--ui-gold,#b99961); color: var(--ui-text,#eee3ce); }

/* Round touch controls keep their learned silhouette and original hit areas. */
.mode-battle #stick-detail { display: none; }
.mode-battle .touch-fire {
  position: relative;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-height: 44px;
  padding: 4px;
  /* Legacy base .touch-fire still has !important; keep these two boundaries. */
  border: 1px solid var(--ui-gold,#b99961) !important;
  border-radius: 50%;
  background: var(--ui-red,#a04d3d) !important;
  color: var(--ui-text,#eee3ce);
  font-family: var(--ui-font,system-ui,-apple-system,"Segoe UI","Malgun Gothic",sans-serif);
  box-shadow: none;
  transform: none;
  opacity: 1;
}
.mode-battle .touch-fire::before { content: ""; position: absolute; inset: 3px; border-radius: 50%; z-index: -1; pointer-events: none; }
.mode-battle .touch-fire[data-state=reload] {
  background: conic-gradient(var(--ui-gold,#b99961) calc(var(--action-progress,0)*1turn),var(--ui-panel,#26383b) 0) !important;
  border-color: var(--ui-line,#b9996140) !important;
}
.mode-battle .touch-fire[data-state=reload]::before { background: var(--ui-ink,#202d30); }
.mode-battle .touch-fire[data-state=blocked] { background: var(--ui-panel,#26383b) !important; border-color: var(--ui-line,#b9996140) !important; color: var(--ui-muted,#b4b3a3); }
.mode-battle .touch-fire[data-state=active],
.mode-battle .touch-fire.held-fire { border-color: var(--ui-paper,#f0e5cf) !important; color: var(--ui-paper,#f0e5cf); box-shadow: none; }
.mode-battle #fire-label { font-size: 14px; font-weight: 600; line-height: 18px; white-space: nowrap; }
.mode-battle #fire-detail { font-size: 12px; font-weight: 500; line-height: 16px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mode-battle #fire-detail:empty { display: none; }

@media(max-width:1050px) and (pointer:fine) {
  .mode-battle .battle-bar.is-command { grid-template-columns: 260px minmax(90px,1fr) 170px 50px; gap: 14px; }
  .command-move { display: none; }
  .is-command .formation { flex-basis: 76px; width: 76px; }
  .combat-readout { padding-inline: 12px; }
}

/* Geometry is unchanged: parent owns 84px / 70px dock and pad variables. */
@media(pointer:coarse) and (orientation:landscape) {
  #game.mode-battle:has(.is-command) { grid-template-rows: minmax(0,1fr); }
  .mode-battle:has(.is-command) #stage { margin: 0 max(76px,calc(env(safe-area-inset-right) + 52px)) var(--battle-dock) max(76px,calc(env(safe-area-inset-left) + 68px)); }
  .mode-battle:has(.is-command) #hud { position: absolute; margin: 0; left: calc(var(--battle-pad-left) + var(--battle-pad-size) + 8px); right: calc(var(--battle-pad-right) + var(--battle-pad-size) + 8px); bottom: calc(3px + env(safe-area-inset-bottom)); }
  .mode-battle .battle-bar.is-command { display: flex; justify-content: center; align-items: center; gap: 0; height: calc(var(--battle-dock) - 8px); padding: 0; max-width: none; overflow: visible; }
  .formation-tabs { gap: 13px; width: auto; max-width: none; align-self: flex-end; }
  .is-command .formation { flex: 0 0 76px; width: 76px; height: 74px; }
  .formation .number { display: none; }
  .formation .name { line-height: 18px; }
  .portrait-well { bottom: 25px; }
  .formation-strength { min-height: 22px; padding: 2px 5px; }
  .formation .count { line-height: 16px; }
  .combat-readout {
    position: fixed;
    left: max(8px,env(safe-area-inset-left));
    top: 99px;
    width: 60px;
    gap: 6px;
    padding: 7px 0 0;
    border-left: 0;
    border-top: 1px solid var(--ui-line,#b9996140);
    pointer-events: none;
  }
  #combat-status { font-size: 12px; line-height: 18px; font-weight: 500; white-space: normal; overflow-wrap: normal; }
  #combat-status > span { line-height: 17px; margin-bottom: 2px; }
  #combat-status > strong { font-size: 12px; line-height: 18px; }
  #combat-tip { font-size: 12px; line-height: 18px; }
  .command-move,.is-command .command-fire { display: none; }
  .battle-bar.is-command .combat-exit { position: fixed; right: max(8px,env(safe-area-inset-right)); top: 61px; width: 64px; height: 44px; max-width: none; font-size: 14px; }
  .mode-battle #stick {
    left: var(--battle-pad-left);
    right: auto;
    bottom: env(safe-area-inset-bottom);
    width: var(--battle-pad-size);
    height: var(--battle-pad-size);
    border: 1px solid var(--ui-line,#b9996140);
    border-radius: 50%;
    background: var(--ui-panel,#26383b);
    box-shadow: none;
    user-select: none;
    -webkit-user-select: none;
  }
  .mode-battle #stick-knob {
    left: calc(50% - 17px);
    top: calc(50% - 17px);
    width: 34px;
    height: 34px;
    border: 1px solid var(--ui-gold,#b99961);
    border-radius: 50%;
    background: var(--ui-paper,#f0e5cf);
    box-shadow: none;
  }
  .mode-battle #stick-label { display: block; position: absolute; left: 0; right: 0; bottom: 3px; top: auto; font-size: 12px; line-height: 16px; font-weight: 500; text-align: center; color: var(--ui-muted,#b4b3a3); pointer-events: none; white-space: nowrap; }
  .mode-battle .touch-actions { right: var(--battle-pad-right); left: auto; bottom: env(safe-area-inset-bottom); gap: 0; }
  .mode-battle .touch-fire { width: var(--battle-pad-size); height: var(--battle-pad-size); min-height: var(--battle-pad-size); }
  .mode-battle .touch-fire .action-art { width: 58px; height: 50px; margin-top: -2px; }
  .mode-battle .touch-fire:has(#fire-detail:not(:empty)) .action-art { width: 43px; height: 36px; }
  #game.mode-battle[data-pad-side=left] #stick { left: auto; right: var(--battle-pad-right); }
  #game.mode-battle[data-pad-side=left] .touch-actions { right: auto; left: var(--battle-pad-left); }
  .mode-battle.is-training .formation-tabs,.mode-battle.is-training .combat-readout,.mode-battle.is-training .selected-tag { visibility: hidden; }
  .mode-battle #training-guide { left: calc(var(--battle-pad-left) + var(--battle-pad-size) + 8px); right: calc(var(--battle-pad-right) + var(--battle-pad-size) + 8px); }
}
@media(pointer:coarse) and (orientation:landscape) and (max-height:350px) {
  .formation-tabs { gap: 12px; }
  .is-command .formation { flex-basis: 64px; width: 64px; height: 60px; }
  .formation .name { font-size: 14px; line-height: 18px; }
  .portrait-well { top: 1px; left: 2px; right: 2px; }
  .formation .count,.reserve-count { font-size: 12px; line-height: 16px; }
  .mode-battle .touch-fire .action-art { width: 48px; height: 40px; }
  .mode-battle .touch-fire:has(#fire-detail:not(:empty)) .action-art { width: 35px; height: 26px; }
  .mode-battle #stick-knob { left: calc(50% - 14px); top: calc(50% - 14px); width: 28px; height: 28px; }
  .combat-readout { top: 93px; }
}
@media(prefers-reduced-motion:reduce) {
  .is-command .formation,.formation-load i { transition: none; }
}
