/* One physical card size in every playable zone. Load after the legacy layers. */
:root {
  --unit-card-width: 192px;
  --unit-card-height: 384px;
  --unit-card-gap: 12px;
  --market-heading-height: 84px;
}

/* A small viewport scrolls the row; it never changes the dimensions of a card. */
#app .game-table,
#app .game-table.has-hand {
  width: 100%;
  max-width: 1536px;
  min-width: 0;
  min-height: 0;
  height: auto;
  max-height: none;
  padding: 0 20px max(28px, env(safe-area-inset-bottom));
  overflow: visible;
}
#app .preparation-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 216px;
  align-items: start;
  gap: 20px;
}
#app .preparation-main,
#market-row,
#shop-row,
#hand-row,
#app .warband-row { min-width: 0; max-width: 100%; }
#market-row { display: block; }
#shop-row { display: block; padding: 0; }
#shop-row,
#hand-row.hand-panel { min-height: calc(var(--unit-card-height) + var(--market-heading-height) + 22px); }
#hand-row { display: none; }
#app.reserve-open #shop-row { display: none; }
#app.reserve-open #hand-row { display: block; }

#app .shop-grid,
#app .team-board {
  display: flex;
  flex-flow: row nowrap;
  align-items: flex-start;
  justify-content: flex-start;
  grid-template-columns: none;
  gap: var(--unit-card-gap);
  width: 100%;
  min-width: 0;
  max-width: none;
  min-height: calc(var(--unit-card-height) + 20px);
  margin: 0;
  padding: 6px 4px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-color: #60849d #102131;
  scrollbar-width: thin;
  scroll-padding-inline: 4px;
}

:is(#app, #modal-root, .battle-team, .scout-grid) .card,
#app :is(.empty-shop, .empty-slot, .empty-stash-slot) {
  box-sizing: border-box;
  flex: 0 0 var(--unit-card-width);
  width: var(--unit-card-width);
  min-width: var(--unit-card-width);
  max-width: var(--unit-card-width);
  height: var(--unit-card-height);
  min-height: var(--unit-card-height);
  max-height: var(--unit-card-height);
  margin: 0;
  padding: 0;
  scale: none;
  zoom: 1;
}
:is(#app, #modal-root, .battle-team, .scout-grid) .card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: visible;
  text-align: left;
  vertical-align: top;
  transition: border-color 120ms, box-shadow 120ms, opacity 120ms;
}
#app .card.hand-card {
  border: 1px solid #40576d;
  border-radius: 5px;
  background: #132131;
  box-shadow: 0 10px 20px #0005;
}
#app .card.hand-card[data-tribe="Терраны"] { border-color: #3e667e; background: #122332; }
#app .card.hand-card[data-tribe="Протоссы"] { border-color: #766347; background: #25251f; }
#app .card.hand-card[data-tribe="Зерги"] { border-color: #717b6b; background: #3d403a; }
#app :is(.team-card, .stash-card).selected { border-color: #93d6fb; box-shadow: 0 0 0 2px #6abce644, 0 10px 24px #0006; outline: none; }
#app :is(.team-card, .stash-card):focus-visible { outline: 2px solid #b8e8ff; outline-offset: 3px; }
#app .shop-card > div:first-child {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: inherit;
}
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-art {
  display: block;
  width: 100%;
  height: auto;
  min-height: 0;
  max-height: none;
  aspect-ratio: 3 / 2;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 4px 4px 0 0;
  border-bottom: 1px solid #8fa7bb2a;
  background: #101924;
}
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-art::after { background: linear-gradient(180deg, #0006, transparent 35%, #07101c15 65%, #07101c80); }
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-art img,
:is(#app, #modal-root, .battle-team, .scout-grid) .card:hover .card-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  transform: none !important;
  scale: none;
  transition: none;
}
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-copy {
  display: block;
  box-sizing: border-box;
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  height: auto;
  max-height: none;
  padding: 10px 10px 8px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-color: #60849d transparent;
  scrollbar-width: thin;
}
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-name {
  display: block;
  min-height: 0;
  margin: 0 0 7px;
  font-size: 15px;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
}
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-text {
  display: block;
  min-height: 0;
  height: auto;
  max-height: none;
  font-size: 13px;
  line-height: 1.5;
  white-space: normal;
  overflow: visible;
  overflow-wrap: anywhere;
}
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-stats {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  column-gap: 4px;
  box-sizing: border-box;
  flex: 0 0 46px;
  width: 100%;
  min-height: 46px;
  margin: 0;
  padding: 5px 9px 9px;
  font-size: 22px;
  line-height: 1.2;
}
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-stats .stat { display: flex; align-items: center; flex-wrap: wrap; gap: 1px 4px; min-width: 0; }
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-stats .health-stat { justify-content: flex-end; }
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-stats .stat > svg { display: block; width: 24px; height: 24px; flex: 0 0 24px; }
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-stats .stat-value { white-space: nowrap; font-variant-numeric: tabular-nums; }
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-stats .ability-icons { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px; max-width: 36px; }
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-tier,
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-tribe,
:is(#app, #modal-root, .battle-team, .scout-grid) .card .golden-label { display: block; }
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-tier { top: 8px; left: 7px; font-size: 11px; line-height: 1.2; }
:is(#app, #modal-root, .battle-team, .scout-grid) .card .card-tribe { top: 9px; right: 5px; padding: 3px 4px; font-size: 10px; line-height: 1.2; letter-spacing: 0; }
:is(#app, #modal-root, .battle-team, .scout-grid) .card .golden-label { font-size: 10px; line-height: 1.3; }
:is(#app, #modal-root, .battle-team, .scout-grid) .card .combat-status { display: flex; }
:is(#app, #modal-root, .battle-team, .scout-grid) .card .combat-status > span { font-size: 11px; line-height: 1.4; }
#app .card:hover,
#app .card:active,
#app .card.selected,
#app .card:focus-visible,
#modal-root .card,
#modal-root .card:hover,
#modal-root .card:active,
#modal-root .card:focus-visible { transform: none; }
#modal-root .fusion-elite { animation: none; }
#modal-root .collection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--unit-card-width));
  grid-auto-rows: var(--unit-card-height);
  justify-content: start;
  gap: var(--unit-card-gap);
  width: 100%;
  min-width: 0;
  padding: 6px 4px;
  overflow-x: auto;
}
#modal-root .reward-grid,
#modal-root .scout-grid {
  display: flex;
  flex-flow: row nowrap;
  align-items: flex-start;
  justify-content: flex-start;
  gap: var(--unit-card-gap);
  padding: 6px 4px 12px;
  overflow-x: auto;
}
#modal-root .reward-card .reward-choose { flex: 0 0 auto; min-height: 40px; padding: 8px; font-size: 12px; }
#modal-root .fusion-summary { flex-wrap: wrap; }
#modal-root .fusion-upgrade { max-width: 100%; overflow-x: auto; padding: 8px 4px; }

/* The reserve occupies the shop row. Its cards have the same full face. */
#hand-row.hand-panel {
  position: relative;
  height: auto;
  margin: 0;
  padding: 0;
  border: 1px solid #3b607c;
  border-radius: 8px;
  overflow: hidden;
}
#hand-row .hand-heading {
  position: static;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  align-content: center;
  align-items: center;
  gap: 4px 16px;
  width: auto;
  height: var(--market-heading-height);
  margin: 0;
  padding: 12px 14px 4px;
  overflow: visible;
  clip-path: none;
  white-space: normal;
}
#hand-row .hand-heading h2 { margin: 0; font-size: 16px; line-height: 1.4; }
#hand-row .hand-caption { grid-column: 1; margin: 0; font-size: 12px; line-height: 1.5; color: #aec8da; }
#hand-row .hand-heading .reserve-back { grid-column: 2; grid-row: 1 / 3; }
#hand-row .hand-scroll {
  height: auto;
  min-height: calc(var(--unit-card-height) + 20px);
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-padding-inline: 6px;
}
#hand-row .hand-board.stash-board {
  display: flex;
  flex-flow: row nowrap;
  align-items: flex-start;
  justify-content: flex-start;
  gap: var(--unit-card-gap);
  width: max-content;
  min-width: 100%;
  height: auto;
  min-height: calc(var(--unit-card-height) + 16px);
  padding: 6px 6px 10px;
}
#hand-row .hand-slot {
  flex: 0 0 var(--unit-card-width);
  width: var(--unit-card-width);
  height: var(--unit-card-height);
  min-height: 0;
  margin: 0;
  border: 0;
  border-radius: 5px;
  background: none;
  box-shadow: none;
  overflow: visible;
}
#hand-row .hand-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--unit-card-height);
  padding: 20px;
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
}
#app .hand-inspector { display: none !important; }
#hand-row .hand-controls.has-selection { display: flex !important; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px; }
#hand-row .hand-controls .selected-title { width: 100%; margin: 0; font-size: 13px; }
#hand-row .hand-controls button { min-height: 40px; padding: 7px 10px; font-size: 13px; }
#hand-row .reserve-back { min-height: 38px; padding: 7px 10px; font-size: 13px; }

/* Reserve, fight and commander form one rail. There is no bottom hand dock. */
#app .fight-rail {
  position: sticky;
  top: 16px;
  right: auto;
  bottom: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  align-self: start;
  gap: 14px;
  width: 100%;
  min-width: 0;
  max-width: none;
  min-height: 0;
  max-height: calc(100svh - 32px);
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #60849d transparent;
}
#hand-zone { width: 100%; min-width: 0; }
#reserve-toggle {
  position: relative;
  inset: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 100%;
  min-width: 0;
  min-height: 144px;
  margin: 0;
  padding: 12px;
  border: 1px solid #65899e;
  border-radius: 8px;
  background: linear-gradient(140deg, #27414c, #122a39);
  color: #e0edf5;
  box-shadow: inset 0 1px #b9e4ff16;
  font-size: 15px;
  line-height: 1.4;
}
#reserve-toggle > svg,
#reserve-toggle .reserve-icon { display: block; width: 96px; height: 70px; flex: 0 0 70px; fill: initial; stroke: none; }
#reserve-toggle > span { display: flex; flex-direction: column; gap: 3px; }
#reserve-toggle .reserve-label { margin-top: 4px; font-size: 16px; font-weight: 600; line-height: 1.3; }
#reserve-toggle b { font-size: 16px; line-height: 1.3; }
#reserve-count { font-size: 14px; line-height: 1.4; color: #b2d4e9; font-variant-numeric: tabular-nums; }
#reserve-toggle:hover,
#reserve-toggle[aria-expanded="true"] { border-color: #c0e8fb; background: linear-gradient(140deg, #35586a, #1c3d51); }
#reserve-toggle:focus-visible { outline: 2px solid #c3eaff; outline-offset: 3px; }
#hand-zone.is-drag-over #reserve-toggle { border-color: #c0ecff; box-shadow: 0 0 0 2px #93d9f5, inset 0 0 24px #67c9ff33; }
#hand-zone .reserve-hint { display: block; margin-top: 7px; color: #a7c4d8; font-size: 12px; line-height: 1.4; text-align: center; }
#app .fight-rail .fight-btn {
  position: static;
  width: 100%;
  min-width: 0;
  height: 84px;
  min-height: 84px;
  margin: 0;
  font-size: 27px;
}
#app .preparation-main .team-controls.has-selection {
  position: static;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 8px;
  margin: 4px 0;
  padding: 6px 0;
}
#app .preparation-main .team-controls.has-selection .selected-title { flex-basis: 100%; text-align: left; }

#hero-panel.hero-power-panel {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  height: auto;
  min-height: 0;
  margin: 0;
  padding: 14px;
  border-radius: 8px;
}
#hero-panel .hero-panel-portrait { position: absolute; top: 14px; left: 14px; width: 40px; height: 40px; align-self: flex-start; }
#hero-panel .hero-panel-copy { min-width: 0; max-height: none; overflow: visible; }
#hero-panel .hero-panel-heading { display: block; min-height: 42px; margin-bottom: 10px; padding-left: 50px; }
#hero-panel .hero-panel-name { display: block; margin: 0 0 4px; font-size: 17px; line-height: 1.3; color: #e8f3fc; white-space: normal; }
#hero-panel .hero-panel-power-name { display: block; margin: 0; font-size: 13px; line-height: 1.4; color: var(--hero-accent, #a3c9e0); }
#hero-panel .hero-power-description { margin: 0; font-size: 13px; line-height: 1.5; color: #c1d4e1; }
#hero-panel .hero-power-meta { display: block; margin: 9px 0 5px; font-size: 12px; line-height: 1.4; color: #a3c7dc; }
#hero-panel .hero-power-status { display: block; margin: 0; font-size: 12px; line-height: 1.5; white-space: normal; overflow: visible; color: #b5c8d5; }
#hero-panel .hero-power-button { width: 100%; min-height: 44px; padding: 10px; font-size: 14px; line-height: 1.4; }
#hero-panel .hero-targets { position: static; width: 100%; max-height: none; margin: 0; padding: 10px 0 0; border: 0; border-top: 1px solid #466278; background: none; box-shadow: none; overflow: visible; }
#hero-panel .hero-targets > button { flex-basis: 100%; min-height: 44px; font-size: 13px; }

/* Scroll the battle surface, not individual rows, so attack motion can cross rows. */
.battle-layer {
  display: block;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 16px 20px 28px;
  overflow: auto;
  overscroll-behavior: contain;
}
/* Flatten the wrapper so viewport controls use the actual scrollport width,
   excluding its scrollbar. Wide rows still overflow this same surface. */
.battle-layer .battle-view { display: contents; }
.battle-layer .battle-team,
.battle-layer.battle-fx-active .battle-team {
  display: flex;
  flex-flow: row nowrap;
  align-items: flex-start;
  justify-content: center;
  grid-template-columns: none;
  gap: var(--unit-card-gap);
  width: max-content;
  min-width: 100%;
  min-height: var(--unit-card-height);
  padding: 6px 4px;
  overflow: visible;
}
.battle-layer .battle-top {
  position: sticky;
  top: -16px;
  left: 0;
  width: 100%;
  max-width: 1496px;
  min-width: 0;
  gap: 12px;
  padding: 12px 0;
  flex-wrap: wrap;
}
.battle-layer :is(.battle-inspection, .battle-event, .battle-progress) { width: 100%; max-width: 1496px; }
.battle-layer .battle-side-label { justify-content: flex-start; flex-wrap: wrap; gap: 6px 16px; }
.scout-grid { display: flex; flex-wrap: nowrap; gap: var(--unit-card-gap); overflow-x: auto; padding: 6px; }

@media (max-width: 900px) {
  .battle-layer .battle-team,
  .battle-layer.battle-fx-active .battle-team { justify-content: flex-start; }
  #app .game-table,
  #app .game-table.has-hand { padding-left: 12px; padding-right: 12px; }
  #app .preparation-layout { display: flex; flex-direction: column; gap: 16px; }
  #app .preparation-main { width: 100%; }
  #app .fight-rail { position: static; order: -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; max-height: none; overflow: visible; }
  #app .fight-rail .fight-btn { grid-column: 1; grid-row: 1; height: 100%; }
  #hand-zone { grid-column: 2; grid-row: 1; }
  #hero-panel.hero-power-panel { grid-column: 1 / -1; display: grid; grid-template-columns: 48px minmax(0, 1fr); align-items: start; }
  #hero-panel .hero-panel-portrait { position: static; width: 48px; height: 48px; }
  #hero-panel .hero-panel-heading { min-height: 0; padding-left: 0; }
  #hero-panel .hero-power-button,
  #hero-panel .hero-targets { grid-column: 1 / -1; }
}
@media (max-width: 600px) {
  #app .game-table,
  #app .game-table.has-hand { padding-left: 8px; padding-right: 8px; }
  #app .fight-rail .fight-btn { min-height: 76px; }
  #reserve-toggle { min-height: 144px; padding: 10px 7px; }
  #reserve-toggle > svg,
  #reserve-toggle .reserve-icon { width: 96px; height: 70px; flex-basis: 70px; }
  #reserve-toggle b { font-size: 14px; }
  #app .fight-rail .fight-btn { font-size: 23px; }
  .battle-layer { padding: 12px 8px 24px; }
  .battle-layer .battle-top { top: -12px; }
}
