:root {
  --red: #b9502f;
  --amber: #f2b23e;
  --sand: #d9bd86;
  --sand-deep: #b9995f;
  --ivory: #efe1bc;
  --walnut: #5b3a22;
  --olive: #4b5234;
  --olive-dark: #313823;
  --olive-black: #1d2118;
  --gun: #23272a;
  --steel: #6f756f;
  --ink: #17130e;
  --paper: #e8dcc0;
  --titleH: clamp(62px, 13vh, 118px);
  --bottomH: clamp(62px, 10.5vh, 86px);
  --railL: 150px;
  --railR: 196px;
  --gap: 12px;
  --board: min(calc(100dvh - var(--titleH) - var(--bottomH) - 70px), calc(100vw - 470px), 800px);
  --phone-board: calc(100dvh - 92px);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: #10120d;
  color: #ece0c2;
  font-family: "Chakra Petch", "Segoe UI", sans-serif;
  overflow: hidden;
}

body {
  -webkit-font-smoothing: none;
  font-smooth: never;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid #ffd76a;
  outline-offset: 2px;
}

img {
  display: block;
  -webkit-user-drag: none;
  user-select: none;
}

.pixel,
#boardArt,
.hudBtn img {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hidden { display: none !important; }

#app {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 540px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  isolation: isolate;
}

#backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: url(assets/cozy_table.webp);
  background-size: cover;
  background-position: center 54%;
  filter: saturate(1.02) brightness(0.82);
}

#backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
  radial-gradient(ellipse 46% 44% at 50% 48%, rgba(255, 186, 84, 0.13), rgba(0, 0, 0, 0) 66%),
  radial-gradient(ellipse 78% 86% at 50% 50%, rgba(0, 0, 0, 0) 42%, rgba(8, 4, 2, 0.58) 100%);
}

/* ---------- Title ---------- */

#titleRow {
  position: relative;
  z-index: 6;
  flex: 0 0 var(--titleH);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-top: 6px;
  pointer-events: none;
}

#titleHeading {
  margin: 0;
  width: min(calc(var(--board) * 0.48), 320px);
  height: calc(var(--titleH) - 16px);
  max-height: 108px;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.45));
}

#titlePlate {
  width: 100%;
  height: 100%;
  object-fit: fill;
  filter: sepia(0.42) hue-rotate(-16deg) saturate(1.25) brightness(1.06);
}

#titleTag {
  margin-top: 2px;
  height: 14px;
  font-family: "Silkscreen", monospace;
  font-size: 8px;
  letter-spacing: 0.24em;
  color: #cbbb8e;
  text-shadow: 0 1px 0 #000;
  opacity: 0.85;
  white-space: nowrap;
}

#buildTag:not(:empty)::before { content: " / BUILD "; }

/* ---------- Stage ---------- */

#stage {
  position: relative;
  z-index: 5;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--railL) var(--board) var(--railR);
  gap: var(--gap);
  align-items: stretch;
  justify-content: center;
  padding: 0 10px;
}

.railTitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-family: "Big Shoulders Stencil", "Chakra Petch", sans-serif;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.12em;
  color: #e6d6ac;
  text-shadow: 0 1px 0 #000;
  border-bottom: 1px solid rgba(18, 20, 13, 0.8);
  padding: 2px 0 3px;
  margin-bottom: 5px;
}

.railTitle .tiny {
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  letter-spacing: 0.08em;
  color: #8f8e6d;
}

.keyTag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 18px;
  padding: 0 4px;
  background: linear-gradient(#d8c89a, #a6966d);
  border: 1px solid #2b2618;
  box-shadow: inset 0 1px 0 rgba(255, 247, 217, 0.6), 0 2px 0 #14150e;
  color: #201c12;
  font-family: "Silkscreen", monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
}

/* ---------- Bot rail ---------- */

#botRail {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 5px 7px 4px;
  background: linear-gradient(170deg, #4a3020, #33201183 70%, #2a1a0f);
  border: 1px solid #170c05;
  box-shadow: inset 0 0 0 1px rgba(240, 186, 110, 0.24), inset 0 2px 0 rgba(255, 219, 160, 0.12), 0 4px 10px rgba(0, 0, 0, 0.35);
}

#botList {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 auto;
  min-height: 0;
}

.botCard {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 6px;
  min-height: 0;
  flex: 1 1 0;
  padding: 2px;
  background: rgba(20, 23, 15, 0.45);
  border: 1px solid rgba(12, 14, 9, 0.75);
  text-align: left;
  color: #c6bd9e;
  transition: none;
}

.botCard .plateBox {
  position: relative;
  flex: 0 0 clamp(54px, 9vh, 84px);
  width: clamp(54px, 9vh, 84px);
  aspect-ratio: 314 / 347;
  align-self: center;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(220, 214, 180, 0.22), rgba(220, 214, 180, 0) 62%),
    linear-gradient(155deg, #5f6250, #3a3e31 58%, #24271d);
  border: 1px solid #0f110b;
  box-shadow: inset 0 0 0 1px rgba(200, 190, 150, 0.18);
}

.botCard .plateBox img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: 50% 58%;
  padding: 4px 3px 2px;
  image-rendering: auto;
  filter: drop-shadow(1px 2px 2px rgba(0, 0, 0, 0.6));
}

.botCard .botMeta {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding-right: 3px;
}

.botCard .botName {
  font-family: "Big Shoulders Stencil", "Chakra Petch", sans-serif;
  font-weight: 700;
  font-size: 15px;
  line-height: 0.9;
  letter-spacing: 0.08em;
  color: #b8b096;
}

.botCard .botDiff {
  margin-top: 2px;
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  line-height: 1.2;
  letter-spacing: 0.05em;
  color: #7f8066;
  overflow-wrap: anywhere;
}

.botCard .botRank {
  position: absolute;
  right: 2px;
  top: 2px;
  font-family: "Silkscreen", monospace;
  font-size: 6px;
  color: #6f7259;
}

.botCard:hover .plateBox img { filter: grayscale(0.1) brightness(1.05) sepia(0.2); }
.botCard:hover .botName { color: #e5d6ad; }

.botCard.active {
  background: linear-gradient(90deg, rgba(241, 170, 51, 0.2), rgba(48, 40, 22, 0.5));
  border-color: #e6a838;
  box-shadow: inset 0 0 0 1px rgba(255, 214, 120, 0.5), 0 0 8px rgba(241, 170, 51, 0.22);
}

.botCard.active .plateBox img { filter: sepia(0.38) saturate(1.16) brightness(1.04); }
.botCard.active .botName { color: #ffd375; }
.botCard.active .botDiff { color: #e0a849; }
.botCard.active .botRank { color: #ffcf6a; }

.botCard:disabled {
  cursor: default;
  opacity: 0.56;
}

#botFoot {
  flex: 0 0 auto;
  margin-top: 4px;
  font-family: "Silkscreen", monospace;
  font-size: 6px;
  letter-spacing: 0.04em;
  color: #8d8e70;
  text-align: center;
  border-top: 1px solid rgba(16, 18, 11, 0.7);
  padding-top: 3px;
}

/* ---------- Board ---------- */

#boardColumn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

#boardWrap {
  position: relative;
  width: var(--board);
  height: var(--board);
  flex: 0 0 auto;
}

#boardFrame {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 10px 10px 12px 14px;
  background:
    linear-gradient(148deg, #84552f 0%, #5b351c 24%, #3c2110 58%, #2c160a 82%, #5d3a20 100%);
  border: 1px solid #1a0e06;
  box-shadow:
    0 9px 22px rgba(0, 0, 0, 0.46),
    0 3px 0 rgba(0, 0, 0, 0.32),
    inset 0 0 0 2px rgba(255, 214, 150, 0.14),
    inset 0 2px 0 rgba(255, 228, 180, 0.26),
    inset 0 -4px 10px rgba(0, 0, 0, 0.5);
}

#boardFrame::before,
#boardFrame::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  border: 2px solid #3a2711;
  background:
    radial-gradient(circle at 50% 50%, #f3d58c 0 3px, #b8842f 3px 5px, #513312 5px 6px, transparent 6px),
    linear-gradient(145deg, #e2b562, #8d6326);
  box-shadow: inset 0 1px 1px rgba(255, 240, 200, 0.55), 0 2px 3px rgba(0, 0, 0, 0.45);
  z-index: 3;
}

#boardFrame::before { left: 3px; top: 3px; }
#boardFrame::after { right: 3px; top: 3px; }

#board {
  position: relative;
  width: 100%;
  height: 100%;
  background: #20140b url(assets/chessboard_top.webp) center / 100% 100% no-repeat;
  border: 1px solid #1b0e06;
  box-shadow: inset 0 0 0 1px rgba(255, 214, 150, 0.16), inset 0 0 26px rgba(32, 15, 5, 0.32);
  overflow: hidden;
  touch-action: manipulation;
}

#boardGlow {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 72% 58% at 24% 14%, rgba(255, 208, 138, 0.2), rgba(255, 190, 90, 0) 66%),
    radial-gradient(ellipse 94% 94% at 50% 50%, rgba(255, 195, 100, 0) 54%, rgba(24, 10, 3, 0.22) 100%);
}

#boardShade {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  box-shadow: inset 0 0 22px rgba(25, 15, 6, 0.28);
}

#cells {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}

.cell {
  position: relative;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: default;
  -webkit-tap-highlight-color: transparent;
  box-shadow: inset 0 0 0 1px rgba(42, 27, 14, 0.1);
  overflow: hidden;
}

.cell.light {
  background-color: transparent;
  background-image: none;
}

.cell.dark {
  background-color: transparent;
  background-image: none;
}

.cell.dark::before { display: none; }

.cell[data-pick="1"] { cursor: pointer; }

.cell:hover {
  background: rgba(255, 195, 85, 0.07);
}

.cell.sel {
  background: rgba(255, 176, 46, 0.11);
}

.cell.sel::after {
  content: "";
  position: absolute;
  inset: 3px;
  background:
    linear-gradient(var(--red), var(--red)) left top / 10px 2px no-repeat,
    linear-gradient(var(--red), var(--red)) left top / 2px 10px no-repeat,
    linear-gradient(var(--red), var(--red)) right top / 10px 2px no-repeat,
    linear-gradient(var(--red), var(--red)) right top / 2px 10px no-repeat,
    linear-gradient(var(--red), var(--red)) left bottom / 10px 2px no-repeat,
    linear-gradient(var(--red), var(--red)) left bottom / 2px 10px no-repeat,
    linear-gradient(var(--red), var(--red)) right bottom / 10px 2px no-repeat,
    linear-gradient(var(--red), var(--red)) right bottom / 2px 10px no-repeat;
  filter: drop-shadow(0 0 2px rgba(255, 140, 64, 0.35));
  pointer-events: none;
}

.cell.move::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  transform: translate(-50%, -50%);
  background: #f4e6c3;
  border: 1px solid #342817;
  box-shadow: 0 0 0 1px rgba(40, 29, 14, 0.55), 0 1px 0 rgba(255, 240, 200, 0.28);
  pointer-events: none;
}

.cell.capture::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64%;
  height: 58%;
  transform: translate(-50%, -50%);
  border: 2px solid var(--red);
  background:
    linear-gradient(45deg, transparent 46%, rgba(185, 80, 47, 0.9) 46% 54%, transparent 54%),
    linear-gradient(-45deg, transparent 46%, rgba(185, 80, 47, 0.9) 54%, transparent 54%);
  opacity: 0.8;
  pointer-events: none;
}

.cell.check {
  box-shadow: inset 0 0 0 2px #e04b2d, inset 0 0 16px rgba(224, 75, 45, 0.6);
  animation: checkPulse 900ms steps(2, end) infinite;
}

@keyframes checkPulse {
  0%, 100% { box-shadow: inset 0 0 0 2px #e04b2d, inset 0 0 16px rgba(224, 75, 45, 0.6); }
  50% { box-shadow: inset 0 0 0 2px #ffd15c, inset 0 0 20px rgba(255, 209, 92, 0.65); }
}

.cell.last::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  bottom: 4px;
  height: 2px;
  background: var(--amber);
  box-shadow: 0 0 3px rgba(242, 178, 62, 0.6);
  pointer-events: none;
}

.cell.target {
  background: rgba(255, 177, 48, 0.13);
}

.cell.target::after {
  content: "";
  position: absolute;
  inset: 4px;
  background:
    linear-gradient(var(--amber), var(--amber)) left top / 9px 2px no-repeat,
    linear-gradient(var(--amber), var(--amber)) left top / 2px 9px no-repeat,
    linear-gradient(var(--amber), var(--amber)) right top / 9px 2px no-repeat,
    linear-gradient(var(--amber), var(--amber)) right top / 2px 9px no-repeat,
    linear-gradient(var(--amber), var(--amber)) left bottom / 9px 2px no-repeat,
    linear-gradient(var(--amber), var(--amber)) left bottom / 2px 9px no-repeat,
    linear-gradient(var(--amber), var(--amber)) right bottom / 9px 2px no-repeat,
    linear-gradient(var(--amber), var(--amber)) right bottom / 2px 9px no-repeat;
  pointer-events: none;
}

.cell.range {
  background: rgba(255, 177, 48, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 177, 48, 0.16);
}

.cell.blast {
  background: rgba(185, 80, 47, 0.24);
  box-shadow: inset 0 0 0 1px rgba(255, 160, 90, 0.5);
}

@keyframes targetBlink {
  0%, 60% { opacity: 1; }
  61%, 100% { opacity: 0.35; }
}

/* ---------- Pieces ---------- */

#decor, #pieces, #ghosts {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#decor { z-index: 1; }
#pieces { z-index: 4; }
#ghosts { z-index: 3; }

#glPieces {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 500ms ease;
  filter: saturate(1.06) contrast(1.03);
}

body.gl-on #glPieces { opacity: 1; }
body.gl-on #pieces img,
body.gl-on #ghosts { opacity: 0 !important; }
#fx { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 7; pointer-events: none; }
#boardBanner {
  position: absolute;
  z-index: 6;
  left: 50%;
  top: 6px;
  transform: translateX(-50%);
  max-width: 94%;
  padding: 3px 8px 2px;
  background: rgba(18, 20, 13, 0.9);
  border: 1px solid #b98630;
  box-shadow: inset 0 0 0 1px rgba(255, 205, 100, 0.18), 0 2px 0 rgba(0, 0, 0, 0.4);
  color: #ffd67d;
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  line-height: 1.35;
  letter-spacing: 0.04em;
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
}

.piece {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  will-change: transform;
}

.piece img {
  display: block;
  height: 97%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: 50% 100%;
  filter: drop-shadow(1px 2px 2px rgba(10, 8, 4, 0.55));
  image-rendering: auto;
}

.piece.wall img {
  height: 95%;
  max-width: 100%;
  filter: drop-shadow(2px 1px 0 rgba(10, 8, 4, 0.45));
}

.piece.black { z-index: 3; }
.piece.white { z-index: 4; }
.piece.hopper { z-index: 8; }

.shieldBadge {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 9;
  width: 13px;
  height: 15px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  line-height: 1;
  text-align: center;
  color: #2a1a06;
  background: linear-gradient(155deg, #fff2c2 0%, #f0cc72 34%, #c38c2e 70%, #7c5115 100%);
  clip-path: polygon(50% 0%, 97% 17%, 97% 56%, 50% 100%, 3% 56%, 3% 17%);
  border: 0;
  box-shadow: none;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.7));
  text-shadow: 0 1px 0 rgba(255, 247, 210, 0.65);
  pointer-events: none;
}

.shieldBadge::before {
  content: "";
  position: absolute;
  inset: 1px;
  background: linear-gradient(155deg, rgba(255, 253, 235, 0.9) 0%, rgba(255, 242, 195, 0) 48%, rgba(70, 42, 8, 0.4) 100%);
  clip-path: polygon(50% 2%, 95% 18%, 95% 55%, 50% 96%, 5% 55%, 5% 18%);
  pointer-events: none;
}

.shieldBadge.endless {
  width: 15px;
  height: 17px;
  color: #3a2300;
  font-size: 9px;
  background: linear-gradient(155deg, #fffce4 0%, #ffdc83 36%, #cf9229 72%, #7c5115 100%);
}

.piece.spawn img { animation: pieceSettle 160ms steps(2, end) both; }

@keyframes pieceSettle {
  0% { transform: translateY(2%) scaleY(1.02); }
  100% { transform: translateY(5%) scaleY(1); }
}

.ghost {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
  z-index: 6;
}

.ghost img {
  height: 97%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: 50% 100%;
  filter: drop-shadow(2px 1px 0 rgba(10, 8, 4, 0.5));
  image-rendering: auto;
}

.decorImg {
  position: absolute;
  pointer-events: none;
  image-rendering: pixelated;
}

.decorImg.crater {
  width: 37.5%;
  height: 37.5%;
  opacity: 0.92;
  filter: brightness(0.92);
  mix-blend-mode: multiply;
}

.decorImg.rubble {
  width: 14%;
  height: 12%;
  opacity: 0.95;
}

/* ---------- Coords ---------- */

.coords {
  position: absolute;
  z-index: 4;
  display: flex;
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  line-height: 1;
  color: #cdbd8c;
  text-shadow: 0 1px 0 #15150e;
  pointer-events: none;
  opacity: 0.9;
}

#coordRanks {
  left: 4px;
  top: 13px;
  bottom: 16px;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  width: 12px;
}

#coordFiles {
  left: 19px;
  right: 13px;
  bottom: 3px;
  flex-direction: row;
  justify-content: space-around;
  align-items: center;
  height: 11px;
}

#coordFiles span, #coordRanks span { width: 8px; text-align: center; }

/* ---------- Nuke device ---------- */

#nukeDock {
  flex: 0 0 auto;
  align-self: flex-end;
  padding-bottom: 2px;
}

#nukeDevice {
  width: 62px;
  height: auto;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.42));
  pointer-events: none;
  opacity: 0.96;
}

/* ---------- Ability rail ---------- */

#abilityRail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 5px 7px 5px;
  background: linear-gradient(170deg, #4a3020, #33201183 70%, #2a1a0f);
  border: 1px solid #170c05;
  box-shadow: inset 0 0 0 1px rgba(240, 186, 110, 0.24), inset 0 2px 0 rgba(255, 219, 160, 0.12), 0 4px 10px rgba(0, 0, 0, 0.35);
}

#shieldLegend {
  flex: 0 0 auto;
  margin: 0 0 4px;
  padding: 2px 3px 1px;
  background: rgba(18, 20, 13, 0.62);
  border: 1px solid rgba(242, 178, 62, 0.35);
  color: #f0cf86;
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  line-height: 1.3;
  letter-spacing: 0.02em;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
}

#shieldLegend span { color: #9b8b61; }

#abilityGrid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(3, 1fr);
  gap: 5px;
}

.ability {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 0;
  padding: 3px 3px 2px;
  background:
    radial-gradient(circle at 4px 4px, #6d5a33 0 1px, rgba(0, 0, 0, 0) 1.7px),
    radial-gradient(circle at calc(100% - 4px) 4px, #6d5a33 0 1px, rgba(0, 0, 0, 0) 1.7px),
    radial-gradient(130% 100% at 50% -10%, #f5e6bb 0%, #dcc996 52%, #b99d63 100%);
  border: 1px solid #3b2f19;
  box-shadow: inset 0 1px 0 rgba(255, 252, 228, 0.8), inset 0 -2px 3px rgba(80, 56, 20, 0.42), 0 2px 0 #1a130a, 0 4px 7px rgba(0, 0, 0, 0.35);
  color: #272215;
  text-align: center;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.ability::after {
  content: "";
  position: absolute;
  inset: 2px;
  border: 1px solid rgba(86, 64, 28, 0.26);
  pointer-events: none;
}

.ability .abName {
  font-family: "Silkscreen", monospace;
  font-size: 6px;
  line-height: 1.2;
  letter-spacing: 0.03em;
  color: #4a3a1c;
  text-shadow: 0 1px 0 rgba(255, 248, 220, 0.55);
  white-space: nowrap;
}

.ability .abIcon {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 1px 0;
}

.ability .abIcon img {
  width: 94%;
  height: 94%;
  object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(0 2px 2px rgba(35, 22, 8, 0.55)) saturate(1.04);
}

.ability .abCd {
  font-family: "Silkscreen", monospace;
  font-size: 16px;
  line-height: 1;
  font-weight: 700;
  color: #2b2414;
  text-shadow: 0 1px 0 rgba(255, 250, 225, 0.7), 0 -1px 0 rgba(74, 48, 14, 0.3);
}

.ability .abCorner {
  position: absolute;
  top: 2px;
  right: 3px;
  min-width: 11px;
  height: 11px;
  padding: 0 1px;
  display: none;
  align-items: center;
  justify-content: center;
  background: #32180e;
  color: #ff8552;
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  font-weight: 700;
  line-height: 1;
  border: 1px solid #110b06;
}

.ability .abUnder {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 1px;
  height: 2px;
  background: var(--amber);
  box-shadow: 0 0 4px rgba(255, 178, 58, 0.65);
  opacity: 0;
}

.ability.ready .abUnder { opacity: 1; animation: cdPulse 2s steps(2, end) infinite; }
@keyframes cdPulse {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.35; }
}

.ability.cooling {
  background: #8d8462;
}

.ability.cooling .abIcon img,
.ability.cooling .abName,
.ability.cooling .abCd {
  filter: grayscale(0.7) brightness(0.58) sepia(0.25);
}

.ability.cooling .abCorner { display: flex; }

.ability.selected {
  border-color: #f0b53e;
  box-shadow: inset 0 0 0 2px rgba(255, 207, 111, 0.72), 0 0 9px rgba(242, 178, 62, 0.35), 0 2px 0 rgba(0, 0, 0, 0.35);
}

.ability.armed {
  border-color: #ffd166;
  box-shadow: inset 0 0 0 2px #ffe5a1, 0 0 14px rgba(255, 188, 70, 0.8);
}

.ability.disabled { cursor: default; }

.ability .abKey {
  position: absolute;
  left: 3px;
  bottom: 2px;
  font-family: "Silkscreen", monospace;
  font-size: 6px;
  color: #58492a;
}

#intel {
  flex: 0 0 auto;
  margin-top: 5px;
  padding: 4px 5px;
  background: rgba(16, 19, 12, 0.72);
  border: 1px solid rgba(12, 14, 9, 0.8);
  box-shadow: inset 0 0 0 1px rgba(197, 185, 142, 0.11);
  min-height: 50px;
}

.intelLine {
  font-family: "Silkscreen", monospace;
  font-size: 6px;
  line-height: 1.55;
  letter-spacing: 0.02em;
  color: #b3ae8a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.intelLine.warn { color: #ffc25c; }
.intelLine.enemy { color: #d79070; }

.intelBtns { display: flex; gap: 4px; margin-top: 3px; }

.manualBtn {
  margin-top: 0;
  width: 100%;
  padding: 2px 2px 1px;
  font-family: "Silkscreen", monospace;
  font-size: 6px;
  letter-spacing: 0.04em;
  color: #d8c9a0;
  background: rgba(58, 57, 35, 0.85);
  border: 1px solid #181a11;
  box-shadow: inset 0 0 0 1px rgba(220, 207, 160, 0.14);
}

.manualBtn:hover { color: #ffd678; background: rgba(82, 76, 42, 0.9); }

/* ---------- Bottom bar ---------- */

#bottomBar {
  position: relative;
  z-index: 6;
  flex: 0 0 var(--bottomH);
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 12px 6px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.028) 0 1px, rgba(0, 0, 0, 0.03) 1px 3px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, rgba(0, 0, 0, 0.025) 1px 3px),
    linear-gradient(180deg, #513622 0%, #3a2414 55%, #281609 100%);
  border-top: 2px solid #150b05;
  box-shadow: inset 0 1px 0 rgba(240, 200, 140, 0.3), 0 -3px 12px rgba(0, 0, 0, 0.34);
}

#turnBlock {
  flex: 0 0 190px;
  min-width: 0;
}

#turnMain {
  font-family: "Big Shoulders Stencil", "Chakra Petch", sans-serif;
  font-weight: 700;
  font-size: clamp(16px, 2.1vh, 24px);
  line-height: 1;
  letter-spacing: 0.08em;
  color: #f2e2b6;
  text-shadow: 0 2px 0 #17100a, 0 0 10px rgba(255, 185, 64, 0.2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#turnMain.enemy { color: #e0a07a; }
#turnMain.win { color: #ffd36f; }

#turnSub {
  display: flex;
  gap: 10px;
  margin-top: 2px;
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  letter-spacing: 0.03em;
  color: #b09a72;
}

#hud {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}

.hudBtn {
  position: relative;
  width: clamp(30px, 5.6vh, 42px);
  height: clamp(30px, 5.6vh, 42px);
  padding: 2px;
  background: linear-gradient(#6b4a30, #3d2717);
  border: 1px solid #150b05;
  box-shadow: inset 0 0 0 1px rgba(255, 232, 190, 0.24), 0 2px 0 rgba(0, 0, 0, 0.45);
  -webkit-tap-highlight-color: transparent;
}

.hudBtn img { width: 100%; height: 100%; object-fit: contain; }
.hudBtn:hover { filter: brightness(1.18); }
.hudBtn:active { transform: translateY(1px); box-shadow: inset 0 0 0 1px rgba(255, 246, 208, 0.18); }
.hudBtn:disabled { opacity: 0.35; cursor: default; }

#hint {
  flex: 1 1 150px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  padding-left: 88px;
  border-left: 1px solid rgba(151, 148, 108, 0.35);
}

#hintMain {
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  line-height: 1.35;
  color: #d9cda5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#hintSub {
  font-family: "Chakra Petch", sans-serif;
  font-size: 9px;
  line-height: 1.1;
  color: #949471;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#hintSub.hot { color: #ffc560; }

/* Lobby plate */

#lobbyTag {
  position: relative;
  flex: 0 0 258px;
  height: 100%;
  max-height: 72px;
  min-height: 54px;
  align-self: center;
}

#lobbyPlate {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  filter: drop-shadow(0 3px 0 rgba(0, 0, 0, 0.35));
  image-rendering: auto;
}

#lobbyHead {
  position: absolute;
  left: 13%;
  right: 13%;
  top: 5%;
  height: 19%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Big Shoulders Stencil", "Chakra Petch", sans-serif;
  font-weight: 700;
  font-size: 9px;
  letter-spacing: 0.18em;
  color: #ffd9c2;
  text-shadow: 0 1px 0 #531c0e;
  pointer-events: none;
}

#lobbyBody {
  position: absolute;
  left: 12%;
  right: 12%;
  top: 27%;
  bottom: 10%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  color: #232215;
}

#lobbyIdle {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 4px;
}

.stencilBtn {
  font-family: "Big Shoulders Stencil", "Chakra Petch", sans-serif;
  font-weight: 700;
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.08em;
  padding: 4px 7px 3px;
  color: #2a2416;
  background: linear-gradient(#e6d6a6, #bfa872);
  border: 1px solid #4e4024;
  box-shadow: inset 0 1px 0 rgba(255, 250, 224, 0.6), 0 2px 0 #3b3220;
}

.stencilBtn:hover { filter: brightness(1.06); }
.stencilBtn:active { transform: translateY(1px); box-shadow: inset 0 1px 0 rgba(255, 250, 224, 0.6); }

.ghostBtn {
  background: transparent;
  color: #e5d4a7;
  border-color: #8b805a;
}

.miniBtn {
  font-family: "Silkscreen", monospace;
  font-size: 6px;
  line-height: 1;
  padding: 3px 4px 2px;
  color: #2a2416;
  background: #d3c294;
  border: 1px solid #5a4b2d;
  box-shadow: 0 1px 0 #3b3220;
}

.miniBtn:hover { filter: brightness(1.08); }

#joinCode {
  width: 100%;
  min-width: 0;
  height: 18px;
  padding: 1px 3px;
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  color: #241f12;
  background: #e9dcba;
  border: 1px solid #6b5836;
  border-radius: 0;
  outline: none;
}

#joinCode::placeholder { color: #8b7a53; }

#lobbyLive, #lobbyWait {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1px;
}

.lobbyLabel {
  font-family: "Silkscreen", monospace;
  font-size: 5px;
  letter-spacing: 0.1em;
  color: #786845;
}

#lobbyCode, #lobbyWaitCode {
  font-family: "Silkscreen", monospace;
  font-size: clamp(12px, 2.5vh, 18px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0.12em;
  color: #211d10;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lobbyActions {
  display: flex;
  gap: 4px;
  margin-top: 1px;
}

#lobbyWaitText {
  font-family: "Silkscreen", monospace;
  font-size: 5px;
  letter-spacing: 0.03em;
  color: #7a4a2c;
  white-space: nowrap;
  overflow: hidden;
}

#lobbyNote {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -13px;
  font-family: "Silkscreen", monospace;
  font-size: 5px;
  color: #cbb97f;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

#lobbyTag.is-wait #lobbyHead { color: #ffd2a8; }
#lobbyTag.is-live #lobbyHead { color: #ffd9a0; }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottomH) + 14px);
  transform: translateX(-50%) translateY(6px);
  z-index: 40;
  padding: 5px 12px 4px;
  background: rgba(17, 19, 12, 0.94);
  border: 1px solid #7f6c42;
  box-shadow: inset 0 0 0 1px rgba(255, 220, 140, 0.11), 0 3px 0 rgba(0, 0, 0, 0.4);
  font-family: "Silkscreen", monospace;
  font-size: 8px;
  line-height: 1.4;
  letter-spacing: 0.04em;
  color: #ecd8a6;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms steps(2, end), transform 120ms steps(2, end);
  max-width: 84vw;
  text-align: center;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.hot { color: #ffd06b; border-color: #b98630; }

/* ---------- Nuke ---------- */

#nukeFlash {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #fffdf4;
  opacity: 0;
  pointer-events: none;
}

#nukeFlash.fire { animation: flashFire 900ms steps(2, end) both; }
@keyframes flashFire {
  0% { opacity: 0; }
  4% { opacity: 1; }
  22% { opacity: 1; }
  40% { opacity: 0.72; }
  100% { opacity: 0; }
}

#nukeScene {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: #050505;
  opacity: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#nukeScene.show { opacity: 1; }
#nukeScene::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 60% 70% at 50% 40%, rgba(255, 255, 240, 0.08), rgba(0, 0, 0, 0) 70%);
}

#blastImg {
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: center bottom;
  image-rendering: pixelated;
  filter: brightness(0.92) contrast(1.08);
  opacity: 0.95;
}

#ashLine {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.02) 0 1px, rgba(0, 0, 0, 0) 1px 3px),
    radial-gradient(ellipse at 50% 100%, rgba(0, 0, 0, 0.55), transparent 62%);
  pointer-events: none;
}

.shake {
  animation: hardShake 520ms steps(2, end) both;
}

@keyframes hardShake {
  0% { transform: translate(0, 0); }
  12% { transform: translate(-5px, 3px); }
  24% { transform: translate(4px, -4px); }
  36% { transform: translate(-3px, -2px); }
  48% { transform: translate(5px, 2px); }
  60% { transform: translate(-2px, 3px); }
  72% { transform: translate(3px, -1px); }
  84% { transform: translate(-1px, 1px); }
  100% { transform: translate(0, 0); }
}

#result {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse 50% 50% at 50% 55%, rgba(8, 8, 7, 0.2), rgba(5, 5, 5, 0.74));
}

#resultPlate {
  position: relative;
  width: min(460px, 92vw);
  padding: 18px 20px 16px;
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.024) 0 1px, rgba(0, 0, 0, 0.04) 1px 3px),
    linear-gradient(166deg, #75714c 0%, #55563a 48%, #3d402a 100%);
  border: 2px solid #16180f;
  box-shadow:
    inset 0 0 0 2px #8f895c,
    inset 0 0 0 3px #2b2d1c,
    0 10px 0 rgba(0, 0, 0, 0.45),
    0 18px 40px rgba(0, 0, 0, 0.5);
  transform: rotate(-0.7deg);
}

#resultPlate::before,
#resultPlate::after {
  content: "";
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #d9d1a0 0 2px, #5d5e44 2px 3px, #17180f 3px 4px);
}

#resultPlate::before { left: 8px; top: 8px; }
#resultPlate::after { right: 8px; bottom: 8px; }

#resultKicker {
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  letter-spacing: 0.16em;
  color: #d7a461;
}

#resultTitle {
  margin-top: 2px;
  font-family: "Big Shoulders Stencil", "Chakra Petch", sans-serif;
  font-weight: 700;
  font-size: clamp(40px, 8.5vh, 60px);
  line-height: 0.92;
  letter-spacing: 0.03em;
  color: #f5e7c2;
  text-shadow: 0 2px 0 #191a10, 0 0 12px rgba(255, 180, 60, 0.16);
}

#resultSub {
  margin-top: 3px;
  font-family: "Chakra Petch", sans-serif;
  font-size: 11px;
  color: #d8c293;
  letter-spacing: 0.02em;
}

#resultStats {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(23, 25, 16, 0.5);
  font-family: "Silkscreen", monospace;
  font-size: 7px;
  color: #c7c09d;
}

#resultBtns {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* ---------- Help ---------- */

#helpModal {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 9, 6, 0.7);
}

#helpCard {
  width: min(560px, 94vw);
  max-height: 88vh;
  overflow: auto;
  padding: 16px 18px;
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.025) 0 1px, rgba(255, 255, 255, 0.02) 1px 3px),
    linear-gradient(#e4d7b5, #c8b88f);
  border: 2px solid #3b3220;
  box-shadow: inset 0 0 0 2px #f3e8c8, 0 10px 0 rgba(0, 0, 0, 0.4), 0 18px 40px rgba(0, 0, 0, 0.5);
  color: #2a2417;
}

#helpTitle {
  font-family: "Big Shoulders Stencil", "Chakra Petch", sans-serif;
  font-weight: 700;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0.05em;
  color: #2b2517;
}

#helpCard p {
  margin: 8px 0 0;
  font-family: "Chakra Petch", sans-serif;
  font-size: 12px;
  line-height: 1.35;
}

#helpCard b { font-weight: 600; color: #1c1a10; }
#helpCloseRow { margin-top: 12px; text-align: right; }

/* ---------- Responsive ---------- */

@media (max-width: 1180px) {
  :root {
    --railL: 148px;
    --railR: 196px;
    --gap: 8px;
  }
  #lobbyTag { flex-basis: 230px; }
  #turnBlock { flex-basis: 168px; }
  #hint { display: none; }
}

@media (max-width: 980px) {
  :root {
    --railL: 138px;
    --railR: 182px;
  }
  #lobbyTag { flex-basis: 210px; }
  .botCard .plateBox { flex-basis: 48px; }
  #turnBlock { flex-basis: 150px; }
}

@media (max-width: 820px), (max-height: 560px) {
  html, body { overflow: auto; }
  #app {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }
  #backdrop { position: fixed; }
  #titleRow {
    flex: 0 0 auto;
    height: 76px;
    padding-top: 4px;
  }
  #titleHeading { width: min(64vw, 250px); height: 62px; max-height: 62px; }
  #titleTag { font-size: 6px; }
  #stage {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 8px;
  }
  #boardColumn { width: 100%; order: -1; }
  #abilityRail { order: 1; }
  #botRail { order: 2; }
  #boardWrap {
    width: min(94vw, 78vh, 520px);
    height: min(94vw, 78vh, 520px);
    max-width: 520px;
  }
  #botRail {
    width: min(94vw, 520px);
    padding: 5px 7px;
  }
  #botList {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }
  .botCard { min-height: 48px; }
  .botCard .plateBox { flex-basis: 42px; }
  .botCard .botName { font-size: 12px; }
  .botCard .botDiff { font-size: 5px; }
  #botFoot { display: none; }
  #abilityRail {
    width: min(94vw, 520px);
    padding: 5px 7px;
  }
  #abilityGrid {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 92px);
  }
  #intel { min-height: 44px; }
  #bottomBar {
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 8px 10px;
  }
  #turnBlock { flex: 1 1 140px; }
  #hud { flex: 0 0 auto; gap: 3px; }
  .hudBtn { width: 34px; height: 34px; }
  #hint { display: flex; flex: 1 1 100%; border-left: 0; padding-left: 0; min-height: 24px; }
  #hintMain { font-size: 7px; white-space: normal; }
  #hintSub { font-size: 8px; white-space: normal; }
  #lobbyTag { flex: 1 1 100%; height: 76px; max-height: none; }
  #nukeDevice {
    width: 48px;
    height: auto;
  }
  #resultTitle { font-size: 44px; }
}

@media (max-width: 480px) {
  #titleRow { height: 64px; }
  #titleHeading { width: min(72vw, 220px); height: 52px; max-height: 52px; }
  #titleTag { display: none; }
  #botList { grid-template-columns: 1fr; }
  .botCard { min-height: 44px; }
  #abilityGrid { grid-template-rows: repeat(2, 86px); }
  #turnBlock { flex-basis: 120px; }
  #turnMain { font-size: 17px; }
  #lobbyTag { height: 72px; }
  #resultPlate { padding: 14px 14px 12px; }
  #helpCard p { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .ability.ready .abUnder { animation: none; }
  .shake { animation: none; }
}

/* Landscape phone: the whole table, not a stacked menu. */
/* Portrait phone: one screen, board filling the width, both racks in reach. */
@media (orientation: portrait) and (max-width: 820px) {
  html, body { height: 100dvh; overflow: hidden; }
  #app { height: 100dvh; min-height: 0; overflow: hidden; }

  #titleRow { flex: 0 0 46px; height: 46px; padding-top: 0; justify-content: flex-end; }
  #titleHeading { width: min(52vw, 210px); height: 40px; max-height: 40px; }
  #titleTag { display: none; }

  #stage {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 5px;
    padding: 0 4px;
    overflow: hidden;
  }

  #boardColumn { order: -1; width: 100%; min-height: 0; display: flex; justify-content: center; }
  #boardWrap {
    --pb: min(calc(100vw - 8px), calc(100dvh - 428px));
    width: var(--pb);
    height: var(--pb);
    max-width: none;
    max-height: none;
    flex: 0 0 auto;
    margin: calc(var(--pb) * 0.041) 0 0;
  }

  #abilityRail { order: 1; width: 100%; max-width: none; padding: 3px 5px; align-self: stretch; }
  #botRail { order: 2; width: 100%; max-width: none; padding: 3px 5px 4px; align-self: stretch; }

  .railTitle { font-size: 9px; letter-spacing: 0.1em; padding: 1px 0 2px; margin-bottom: 2px; }
  .railTitle .tiny { display: none; }
  .keyTag { min-width: 18px; height: 14px; font-size: 7px; }
  #shieldLegend { margin-bottom: 2px; padding: 0; font-size: 6px; }

  #abilityGrid {
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: 60px;
    gap: 3px;
    min-height: 0;
  }
  .ability { padding: 2px 2px 1px; }
  .ability .abName { font-size: 6px; }
  .ability .abKey { font-size: 5px; top: auto; bottom: 1px; left: 2px; }
  .ability .abCd { font-size: 11px; }
  .ability .abCorner { font-size: 5px; min-width: 9px; height: 9px; top: 1px; right: 2px; }

  #intel { margin-top: 3px; padding: 2px 4px; min-height: 0; max-height: 40px; overflow: hidden; }
  .intelLine { font-size: 5px; line-height: 1.25; }
  .intelBtns { gap: 3px; margin-top: 1px; }
  .manualBtn { font-size: 5px; padding: 1px 3px 0; }

  #botList {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 42px);
    gap: 3px;
    min-height: 0;
  }
  .botCard { min-height: 0; padding: 1px 2px; gap: 4px; align-items: center; }
  .botCard .plateBox { flex: 0 0 30px; width: 30px; align-self: center; }
  .botCard .botMeta { padding-right: 1px; }
  .botCard .botName { font-size: 9px; line-height: 0.95; }
  .botCard .botDiff { font-size: 5px; margin-top: 1px; }
  .botCard .botRank { display: none; }
  #botFoot { display: none; }

  #bottomBar {
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 4px;
    padding: 3px 6px calc(3px + env(safe-area-inset-bottom));
    align-items: center;
  }
  #nukeDock { display: none; }
  #turnBlock { flex: 1 1 92px; }
  #turnMain { font-size: 13px; }
  #turnSub { font-size: 5px; gap: 4px; margin-top: 1px; }
  #hud { gap: 2px; flex: 0 0 auto; }
  .hudBtn { width: 32px; height: 32px; }
  #hint { display: none; }
  #lobbyTag { flex: 1 1 100%; height: 42px; max-height: 42px; min-height: 0; }
  #lobbyHead { font-size: 6px; }
  #lobbyBody { top: 24%; bottom: 6%; }
  #lobbyIdle { grid-template-columns: auto 1fr auto; gap: 3px; }
  #lobbyCode, #lobbyWaitCode { font-size: 12px; }
  #lobbyWaitText, .lobbyLabel { font-size: 5px; }
  .stencilBtn { font-size: 9px; padding: 2px 5px 1px; }
  .miniBtn { font-size: 6px; padding: 2px 4px 1px; }
  #joinCode { height: 15px; font-size: 6px; }
  #lobbyNote { display: none; }
  #toast { bottom: 94px; font-size: 7px; }
}
/* Short portrait phone: six bots in one row so the board stays big. */
@media (orientation: portrait) and (max-width: 820px) and (max-height: 720px) {
  #titleRow { flex: 0 0 34px; height: 34px; }
  #titleHeading { height: 30px; max-height: 30px; }
  #abilityRail, #botRail { padding: 2px 5px; }
  #abilityRail .railTitle, #botRail .railTitle { display: none; }
  #shieldLegend { display: none; }
  #abilityGrid { grid-template-rows: 56px; }
  .ability .abCd { font-size: 10px; }
  #botList {
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: 46px;
  }
  .botCard {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 1px;
  }
  .botCard .plateBox { flex: 0 0 22px; width: 22px; }
  .botCard .botMeta { align-items: center; text-align: center; padding: 0; }
  .botCard .botName { font-size: 6px; line-height: 1; }
  .botCard .botDiff { font-size: 5px; margin-top: 0; }
  #intel {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    margin-top: 2px;
    padding: 1px 3px;
    max-height: none;
  }
  #intel .intelLine { display: none; }
  #intel .intelBtns { margin-top: 0; }
  .manualBtn { font-size: 6px; padding: 2px 5px 1px; }
  #bottomBar { gap: 3px; padding: 2px 5px calc(2px + env(safe-area-inset-bottom)); }
  #lobbyTag { height: 36px; max-height: 36px; }
  #turnMain { font-size: 12px; }
  .hudBtn { width: 30px; height: 30px; }
  #boardWrap {
    --pb: min(calc(100vw - 8px), calc(100dvh - 274px));
    width: var(--pb);
    height: var(--pb);
    margin-top: calc(var(--pb) * 0.041);
  }
}


@media (orientation: landscape) and (max-height: 560px) {
  html, body { overflow: hidden; }
  #app {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }
  #titleRow {
    flex: 0 0 40px;
    height: 40px;
    padding: 1px 0 0;
    justify-content: flex-end;
  }
  #titleHeading {
    width: min(18vw, 142px);
    height: 38px;
    max-height: 38px;
  }
  #titleTag { display: none; }
  #stage {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: 148px var(--phone-board) 168px;
    gap: 8px;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
  }
  #boardColumn {
    order: 0;
    width: auto;
    min-width: 0;
    min-height: 0;
    align-self: stretch;
    justify-content: center;
  }
  #boardWrap {
    width: var(--phone-board);
    height: var(--phone-board);
    max-width: none;
    max-height: none;
    flex: 0 0 auto;
  }
  #boardFrame { padding: 9px 8px 12px 13px; }
  #coordRanks { left: 2px; top: 9px; bottom: 12px; font-size: 5px; }
  #coordFiles { left: 13px; right: 8px; bottom: 2px; font-size: 5px; }
  #nukeDevice {
    width: 48px;
    height: auto;
  }
  #boardBanner { font-size: 5px; padding: 2px 5px 1px; top: 3px; }
  #botRail { order: 0; width: auto; padding: 3px 4px; min-height: 0; align-self: stretch; }
  #botList { display: flex; flex-direction: column; gap: 2px; min-height: 0; }
  .botCard { min-height: 0; flex: 1 1 0; padding: 1px; gap: 4px; }
  .botCard .plateBox { flex: 0 0 30px; width: 30px; }
  .botCard .botName { font-size: 11px; }
  .botCard .botDiff { font-size: 5px; margin-top: 0; }
  .botCard .botRank { font-size: 5px; }
  .railTitle { font-size: 10px; margin-bottom: 3px; padding: 1px 0 2px; }
  .railTitle .tiny { display: none; }
  .keyTag { min-width: 17px; height: 14px; font-size: 7px; }
  #shieldLegend { margin-bottom: 2px; padding: 1px 2px 0; font-size: 5px; }
  #botFoot { display: none; }
  #abilityRail { order: 0; width: auto; padding: 3px 4px; min-height: 0; align-self: stretch; }
  #abilityGrid {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(3, 1fr);
    gap: 3px;
    min-height: 0;
  }
  .ability { padding: 2px 2px 1px; }
  .ability .abName { font-size: 5px; }
  .ability .abKey { font-size: 5px; top: auto; bottom: 1px; left: 2px; }
  .ability .abCd { font-size: 11px; }
  .ability .abCorner { font-size: 5px; min-width: 9px; height: 9px; top: 1px; right: 2px; }
  #intel { margin-top: 3px; padding: 2px 3px; min-height: 0; max-height: 44px; overflow: hidden; }
  .intelLine { font-size: 5px; line-height: 1.3; }
  .intelBtns { gap: 2px; margin-top: 1px; }
  .manualBtn { font-size: 5px; padding: 1px 1px 0; }
  #bottomBar {
    flex: 0 0 50px;
    height: 50px;
    flex-wrap: nowrap;
    gap: 4px;
    padding: 2px 6px;
  }
  #nukeDock { align-self: center; padding-bottom: 0; }
  #turnBlock { flex: 0 0 124px; }
  #turnMain { font-size: 11px; }
  #turnSub { gap: 4px; font-size: 5px; margin-top: 1px; }
  #hud { gap: 2px; }
  .hudBtn { width: 25px; height: 25px; }
  #hint { display: flex; flex: 1 1 110px; min-width: 0; border-left: 0; padding-left: 4px; }
  #hintMain { font-size: 5px; white-space: nowrap; }
  #hintSub { display: none; }
  #lobbyTag { flex: 0 0 206px; height: 44px; max-height: 44px; min-height: 0; }
  #lobbyHead { font-size: 5px; letter-spacing: 0.1em; }
  #lobbyBody { top: 26%; bottom: 8%; }
  #lobbyCode, #lobbyWaitCode { font-size: 11px; }
  #lobbyWaitText, .lobbyLabel { font-size: 4px; }
  #lobbyIdle { grid-template-columns: auto 1fr auto; gap: 3px; }
  .stencilBtn { font-size: 8px; padding: 2px 4px 1px; }
  .miniBtn { font-size: 5px; padding: 2px 3px 1px; }
  #joinCode { height: 13px; font-size: 5px; }
  #lobbyNote { display: none; }
  #toast { bottom: 58px; font-size: 6px; }
  #resultPlate { width: min(360px, 86vw); padding: 10px 12px; }
  #resultTitle { font-size: 36px; }
  #resultSub { font-size: 9px; }
  #resultStats { font-size: 6px; margin-top: 6px; padding-top: 5px; }
  #resultBtns { margin-top: 7px; }
  #helpCard { max-height: 92vh; }
  #helpCard p { font-size: 10px; }
}
