/* Battle HUD: commander rail beside the map, army bar under it, feeds and status below. */
.battle-layout.battle-hud {
  display: grid;
  /* Right to left: the map comes first (right), the commander rail sits on its left. */
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 12px;
  align-items: start;
}
.battle-rail {
  position: sticky;
  top: 12px;
  z-index: 6;
}
.battle-rail ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 8px 6px;
  list-style: none;
  border-radius: 14px;
  border: 1px solid #c9a35c66;
  background: linear-gradient(#141c27f2, #0d131bf2);
  box-shadow: 0 8px 20px #0007;
}
.rail-commander {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 3px;
}
.rail-face {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 8%;
  background: #1f2b38;
  border: 2px solid var(--owner-color);
  box-shadow: 0 0 0 2px #0009;
}
.rail-commander.is-me .rail-face {
  box-shadow:
    0 0 0 2px #0009,
    0 0 10px var(--owner-color);
}
.rail-commander.is-dead .rail-face,
.rail-commander.is-out .rail-face {
  filter: grayscale(1) brightness(0.6);
}
.rail-commander.is-dead::after {
  content: '✕';
  position: absolute;
  top: 8px;
  color: #ff9f8a;
  font-weight: 700;
  font-size: 22px;
}
.rail-troops {
  min-width: 38px;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid #fff6;
  background: var(--owner-color);
  color: #fff;
  font-size: 15px;
  text-align: center;
  text-shadow: 0 1px 2px #0009;
}
.rail-shield {
  position: absolute;
  top: -4px;
  inset-inline-start: -4px;
  width: 22px;
  height: 26px;
}
.rail-shield .resist-shield {
  width: 100%;
  height: 100%;
}
.rail-spells {
  position: absolute;
  top: 26px;
  inset-inline-end: -6px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #caa2ff;
  background: #2a1d3d;
  color: #e3d0ff;
}
.rail-spells .icon {
  width: 18px;
  height: 18px;
}
.rail-spells[aria-expanded='true'] {
  background: #6a46a8;
}
.spell-popover {
  position: absolute;
  top: 0;
  inset-inline-end: calc(100% + 8px); /* opens over the map, towards the right */
  width: min(320px, 80vw);
  z-index: 8;
  animation: map-menu-in 0.14s ease-out;
}
.spell-popover .spell-bar {
  margin: 0;
  box-shadow: 0 10px 26px #000a;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.battle-elapsed {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 8px;
  background: #0b1219;
  color: #fff3d0;
  font-variant-numeric: tabular-nums;
}
.battle-elapsed .icon {
  width: 18px;
  height: 18px;
}
/* Castle extra time: resistance is off for everyone until the castle falls or time runs out. */
.badge.is-overtime {
  background: #4a2222;
  border-color: #b8574f;
  color: #ffd0c8;
}
/* An eliminated commander only watches, with the team's own view. */
.battle-spectator {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 12px;
  padding: 10px 14px;
  border: 1px solid #62718a;
  border-radius: 8px;
  background: #1a2433;
  color: #e3e8f0;
}
.battle-spectator .icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  color: #f4d99d;
}

/* Army bar under the map. */
.army-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(#141c27, #0d131b);
  border-top: 1px solid #c9a35c55;
}
.army-hero img {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  object-position: 50% 8%;
  border: 2px solid #c9a35c;
  background: #1f2b38;
}
.army-hero.is-dead img {
  filter: grayscale(1);
}
.army-stat {
  display: grid;
  justify-items: center;
  min-width: 92px;
  padding: 4px 10px;
  border-radius: 10px;
  background: #0b1219;
  border: 1px solid #ffffff1f;
  font-size: 13px;
  color: #d9e1ea;
}
.army-stat b {
  font-size: 20px;
  color: #ffe9a3;
}
.army-stat small {
  color: #b9c6d3;
}
.army-bar .field-command {
  margin-inline-start: auto;
}

/* Feeds and status under the map. */
.battle-bottom {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(0, 1.4fr);
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}
.battle-bottom .battle-feeds {
  margin: 0;
}
.battle-status {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid #c9a35c66;
  background: linear-gradient(#141c27f2, #0d131bf2);
}
.battle-status h3 {
  margin: 0;
}
.resist-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 64px;
  border-radius: 14px;
  border: 1px solid #ffffff33;
  background: #1a222d;
  color: #d9e1ea;
  font-weight: 700;
}
.resist-toggle .resist-shield {
  width: 44px;
  height: 52px;
  filter: grayscale(1) brightness(0.9);
  transition:
    filter 0.25s,
    transform 0.25s;
}
.resist-toggle.is-on {
  border-color: #8adfff;
  background: linear-gradient(#173246, #0f2232);
  color: #c7f1ff;
  box-shadow: 0 0 16px #8adfff55;
}
.resist-toggle.is-on .resist-shield {
  filter: none;
  transform: scale(1.06);
}
.resist-shield .resist-rim {
  fill: #c9a35c;
  stroke: #5b3d16;
  stroke-width: 1.5;
}
.resist-shield .resist-face {
  fill: #2f7fc0;
}
.resist-shield .resist-band {
  stroke: #e9d7a3;
  stroke-width: 3;
  fill: none;
}
.resist-shield .resist-gem {
  fill: #8adfff;
  stroke: #fff;
  stroke-width: 1;
}
.status-list {
  display: grid;
  gap: 8px;
  margin: 0;
}
.status-list > div {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}
.status-list dt {
  font-weight: 700;
  color: #f1e3c0;
}
.status-list dd {
  display: grid;
  gap: 2px;
  margin: 0;
}
.status-list small {
  color: #a9b5c7;
  font-size: 12px;
  line-height: 1.6;
}
.status-meter {
  height: 10px;
  border-radius: 5px;
  background: #0b1219;
  border: 1px solid #ffffff22;
  overflow: hidden;
}
.status-meter i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #6f9f45, #b8e07a);
}
.battle-invite {
  margin-top: 8px;
}
@media (max-width: 900px) {
  .battle-bottom {
    grid-template-columns: minmax(0, 1fr);
  }
}
@media (max-width: 640px) {
  .battle-layout.battle-hud {
    grid-template-columns: minmax(0, 1fr);
  }
  .battle-rail {
    position: relative;
    top: 0;
    order: -1; /* phones: commanders above the map */
  }
  .battle-rail ul {
    display: flex;
    overflow-x: auto;
    gap: 12px;
  }
  .rail-commander {
    flex: 0 0 auto;
  }
  .spell-popover {
    position: static;
    width: 100%;
    margin-top: 8px;
  }
  .army-stat {
    min-width: 0;
    flex: 1 1 30%;
  }
  .army-bar .field-command {
    margin-inline-start: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  .resist-toggle .resist-shield,
  .spell-popover {
    transition: none;
    animation: none;
  }
}

/* Active battles give the field priority over account chrome. The single wooden
   navigation remains available, including on small screens. */
.game-shell:has(#battle-content) .topbar,
.game-shell:has(#battle-content) .workspace-heading {
  display: none;
}
.game-shell:has(#battle-content) {
  padding-top: 12px;
}
.game-shell:has(#battle-content) .wood-nav {
  display: flex;
  flex-wrap: nowrap !important; /* Overrides the legacy wrapped wooden menu only in battle. */
  overflow: auto !important;
  min-height: 64px;
  margin-block: 0 16px;
  padding: 6px 10px !important;
  scrollbar-width: thin;
}
.game-shell:has(#battle-content) .wood-nav a {
  flex: 1 0 auto;
  min-width: 82px;
  min-height: 48px !important;
  padding: 8px 14px;
  flex-direction: row;
  gap: 6px;
}
.game-shell:has(#battle-content) .game-layout {
  margin-top: 8px;
}
#battle-content .battle-heading {
  padding: 14px 18px;
  margin-bottom: 12px;
  gap: 12px;
}
#battle-content .battle-heading h2 {
  margin-block: 2px;
  font-size: 22px;
}
#battle-content .battle-heading p {
  margin-block: 4px 0;
}
#battle-content .battle-heading button {
  min-height: 44px;
}
.battle-vitals {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.battle-vital,
.battle-ready {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px 8px;
  padding: 12px 14px;
  border: 1px solid #52647a;
  border-radius: 10px;
  background: #131d2a;
  color: #d9e2ee;
  font-size: 13px;
}
.battle-vital b,
.battle-ready b {
  color: #fff1c9;
  font-variant-numeric: tabular-nums;
}
.battle-vital progress {
  grid-column: 1 / -1;
  appearance: none;
  width: 100%;
  height: 7px;
  border: 0;
  border-radius: 6px;
  overflow: hidden;
  background: #080e17;
  accent-color: #8ed6ad;
}
.battle-vital progress::-webkit-progress-bar {
  background: #080e17;
}
.battle-vital progress::-webkit-progress-value {
  background: var(--vital-color, #8ed6ad);
}
.battle-vital progress::-moz-progress-bar {
  background: var(--vital-color, #8ed6ad);
}
.battle-vital.is-energy {
  --vital-color: #90caff;
}
.battle-vital.is-morale {
  --vital-color: #e9ca7f;
}
.battle-vital.is-dead {
  border-color: #b06e71;
}
.battle-vital.is-critical {
  --vital-color: #ffad96;
  border-color: #c68b79;
}
.battle-ready small {
  grid-column: 1 / -1;
  color: #c2cfdf;
  font-size: 12px;
}
.battle-ready .resist-toggle {
  grid-column: 1 / -1;
  min-height: 44px;
  gap: 6px;
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 6px;
}
.battle-ready .resist-shield {
  width: 22px;
  height: 26px;
}
.battle-network:not([hidden]) {
  padding: 12px 16px;
  border: 1px solid #e8b577;
  border-radius: 10px;
  background: #3b2818;
  color: #ffe5c4;
}
.battle-layout.battle-hud {
  grid-template-columns: minmax(0, 1fr) 176px;
}
.battle-rail h3 {
  margin: 0 0 8px;
  color: #e9d8af;
  font-size: 14px;
}
.battle-rail ul {
  gap: 10px;
  padding: 10px;
}
.rail-commander {
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid #ffffff24;
  justify-items: stretch;
  align-items: center;
}
.rail-commander:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}
.rail-identity {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.rail-identity b {
  color: #f3e8cb;
  font-size: 13px;
  overflow-wrap: anywhere;
}
.rail-identity small,
.rail-count small {
  color: #c4d0df;
  font-size: 12px;
}
.rail-count {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 6px;
}
.rail-troops {
  border-color: var(--owner-color);
  background: #0a121d;
  text-shadow: none;
}
.rail-health {
  grid-column: 1 / -1;
  color: #ffc0bc;
  font-size: 12px;
}
.rail-commander.is-dead::after {
  inset-inline-start: 13px;
  pointer-events: none;
}
.rail-spells {
  position: static;
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  border-radius: 8px;
  font-size: 13px;
}
.spell-popover {
  width: min(340px, 80vw);
}
#battle-content .map-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: #182b32;
}
#battle-content .map-tools button {
  min-width: 44px;
  min-height: 44px;
  font-size: 14px;
}
.battle-territories {
  color: #e1e9e8;
  font-size: 13px;
}
.battle-territories b {
  color: #ffe6a6;
  margin-inline-start: 6px;
}
.battle-command-guide {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  background: #111c29;
  border-block: 1px solid #52647a;
  color: #e4edf6;
}
.battle-command-guide > div {
  display: grid;
  gap: 4px;
  flex: 1 1 200px;
}
.command-phase {
  color: #f5d792;
  font-size: 12px;
}
#battle-content .map-step {
  color: #e4edf6;
  font-size: 14px;
  line-height: 1.7;
}
.battle-command-guide button {
  min-height: 44px;
}
.command-reasons {
  flex-basis: 100%;
  margin: 0;
  padding-inline-start: 20px;
  color: #d8c9ba;
  font-size: 12px;
  line-height: 1.8;
}
#battle-content .natural-map {
  height: min(65svh, 720px);
  min-height: 320px;
}
#battle-content .army-bar {
  gap: 8px;
}
#battle-content .map-action-close {
  min-width: 44px;
  min-height: 44px;
}
#battle-content .map-action:disabled {
  opacity: 1;
  color: #c4c9d0;
  background: #28303a;
  filter: none;
}
#battle-content .natural-cell.valid-attack .tile-top {
  stroke-dasharray: 6 3;
  stroke-width: 2 !important;
}
#battle-content .natural-cell.valid-move .tile-top {
  stroke-dasharray: 1 3;
  stroke-width: 2 !important;
}
#battle-content button:focus-visible,
#battle-content a:focus-visible,
.game-shell:has(#battle-content) .wood-nav a:focus-visible {
  outline: 3px solid #ffe29b;
  outline-offset: 3px;
}
@media (max-width: 900px) {
  .battle-layout.battle-hud {
    grid-template-columns: minmax(0, 1fr);
  }
  .battle-rail {
    position: relative;
    top: 0;
    order: -1;
  }
  .battle-rail h3 {
    font-size: 13px;
    margin-bottom: 6px;
  }
  .battle-rail ul {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 156px;
    overflow-x: auto;
    justify-content: start;
  }
  .rail-commander {
    border-bottom: 0;
    padding-bottom: 0;
    align-content: start;
  }
  .spell-popover {
    width: 100%;
    position: static;
    margin-top: 8px;
  }
  .battle-vitals {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #battle-content .natural-map {
    height: auto;
    min-height: 245px;
  }
}
@media (max-width: 550px) {
  .game-shell:has(#battle-content) .wood-nav {
    min-height: 56px;
    margin-bottom: 8px;
  }
  #battle-content .battle-heading {
    padding: 10px 12px;
    gap: 8px;
  }
  #battle-content .battle-heading h2 {
    font-size: 19px;
  }
  #battle-content .battle-heading .eyebrow {
    display: none;
  }
  #battle-content .battle-heading > div:last-child {
    justify-content: space-between;
    width: 100%;
  }
  .battle-vitals {
    gap: 6px;
    margin-bottom: 8px;
  }
  .battle-vital,
  .battle-ready {
    padding: 8px;
    font-size: 12px;
    gap: 4px;
  }
  .battle-rail h3 {
    display: none;
  }
  .battle-rail {
    order: 0;
  }
  .battle-rail ul {
    padding: 8px;
  }
  #battle-content .map-tools {
    padding: 6px 8px;
    gap: 6px;
  }
  #battle-content .map-zoom {
    margin-inline-start: auto;
  }
  .battle-elapsed {
    padding: 3px 6px;
    font-size: 12px;
  }
  .battle-territories {
    font-size: 12px;
  }
  .battle-command-guide {
    padding: 8px 10px;
  }
  /* Touch orders dock below the map, so they never hide the selected territory. */
  #battle-content .map-action-menu,
  #battle-content .map-action-menu.below {
    position: static;
    transform: none;
    margin: 0;
    border: 0;
    border-top: 1px solid #bfa66d;
    border-radius: 0;
    justify-content: space-between;
    padding: 8px;
    animation: none;
  }
  #battle-content .map-action-menu::after {
    display: none;
  }
  #battle-content .map-action {
    min-width: 0;
    flex: 1;
    min-height: 52px;
    font-size: 12px;
  }
  #battle-content .map-action-close {
    flex: 0 0 44px;
  }
  #battle-content .army-bar {
    padding: 8px;
  }
  #battle-content .army-hero {
    display: none;
  }
  #battle-content .army-stat {
    padding: 6px;
    font-size: 12px;
  }
  #battle-content .army-stat b {
    font-size: 18px;
  }
  #battle-content .army-bar .field-command {
    width: 100%;
    min-height: 44px;
  }
}
@media (prefers-reduced-motion: reduce) {
  #battle-content .natural-cell.selected .tile-top,
  #battle-content .natural-cell.valid-attack .tile-top {
    animation: none;
  }
}
