/* Grid battle screen (js/tacticsui.js): a full-screen field under dark glass chrome with gold trim.
   Unit cards and the round plaque on top, hero portraits in the bottom corners, round spell
   buttons between them. Portrait phones stay portrait. */
#tactics-window {
  position: fixed;
  inset: 0;
  z-index: 62;
  pointer-events: auto;
  background: #2f3826;
}
#tactics-window[hidden] { display: none; }
.tx {
  --tx-glass: rgba(18, 16, 12, 0.72);
  --tx-line: rgba(215, 181, 106, 0.42);
  --tx-gold: #e2c070;
  --tx-text: #f3ead6;
  --tx-dim: #b9ad92;
  position: absolute;
  inset: 0;
  color: var(--tx-text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}
.tx button {
  margin: 0;
  min-height: 38px;
  padding: 5px 11px;
  border: 1px solid var(--tx-line);
  border-radius: 10px;
  background: linear-gradient(rgba(60, 52, 38, 0.92), rgba(34, 29, 21, 0.92));
  color: var(--tx-text);
  font: 600 13px/1.15 system-ui, sans-serif;
  cursor: pointer;
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
}
.tx button:hover:not(:disabled) { border-color: var(--tx-gold); }
.tx button:active:not(:disabled) { transform: scale(0.95); }
.tx button:disabled { opacity: 0.36; cursor: default; }
.tx button[aria-pressed="true"], .tx button.ghosting {
  border-color: var(--tx-gold);
  background: linear-gradient(rgba(120, 96, 44, 0.95), rgba(70, 54, 24, 0.95));
}
.tx button small { display: block; font-weight: 400; font-size: 10px; color: var(--tx-dim); }
.tx .tx-main-btn {
  border-color: var(--tx-gold);
  background: linear-gradient(#b8923f, #7c5d22);
  color: #1c1408;
  font-weight: 800;
}

/* The field fills the screen; the chrome floats over it. */
.tx-stage { position: absolute; inset: 0; }
.tx-stage canvas { width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- top: unit cards, round plaque, morale ---------- */
/* ---------- battle clock: the whole fight (10 min), and inside it the waiting stack's 30 s ---------- */
.tx-clock {
  position: absolute;
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  height: 6px;
  z-index: 2;
  background: rgba(6, 12, 28, 0.85);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.6);
}
.tx-clock i { position: absolute; left: 0; display: block; transition: width 0.25s linear; }
.tx-clock-all { top: 0; height: 100%; width: 100%; background: linear-gradient(#5d9cf2, #2a5cb5); }
.tx-clock-stack { top: 35%; height: 30%; width: 0; background: #d2ecff; box-shadow: 0 0 5px 1px rgba(170, 220, 255, 0.85); }
.tx-clock.late .tx-clock-all { background: linear-gradient(#8cb8ff, #3f73d6); animation: tx-clock-late 1s ease-in-out infinite; }
.tx-clock.hurry .tx-clock-stack { background: #fff; }
@keyframes tx-clock-late { 50% { opacity: 0.55; } }

.tx-top {
  position: absolute;
  top: 6px;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 6px;
  padding: calc(4px + env(safe-area-inset-top)) calc(6px + env(safe-area-inset-right)) 5px calc(6px + env(safe-area-inset-left));
  background: linear-gradient(rgba(10, 8, 6, 0.86), rgba(10, 8, 6, 0.5) 75%, rgba(10, 8, 6, 0));
}
.tx-cards { min-width: 0; }
.tx-units { display: flex; flex-wrap: wrap; gap: 3px; }
.tx-cards-foe .tx-units { justify-content: flex-end; }
.tx-unit {
  position: relative;
  width: 34px;
  height: 40px;
  border: 1px solid var(--tx-line);
  border-radius: 6px;
  background: linear-gradient(rgba(52, 60, 40, 0.92), rgba(24, 26, 18, 0.92));
  overflow: hidden;
}
.tx-cards-foe .tx-unit { background: linear-gradient(rgba(48, 44, 58, 0.92), rgba(22, 20, 26, 0.92)); }
.tx-unit canvas { position: absolute; left: 0; top: -3px; width: 100%; height: 38px; }
.tx-unit b {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  font: 800 9.5px/12px system-ui, sans-serif;
  text-align: center;
  background: rgba(8, 6, 4, 0.78);
  color: #fff3d0;
}
/* A type with no stack left standing. */
.tx-unit.dead { filter: grayscale(1) brightness(0.55); border-color: rgba(120, 120, 120, 0.4); }
.tx-unit.dead b { color: #9a9a9a; }
.tx-bar {
  position: relative;
  height: 12px;
  margin-top: 4px;
  border: 1px solid rgba(0, 0, 0, 0.7);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.tx-bar i { display: block; height: 100%; background: linear-gradient(#f1d27a, #b98a2c); transition: width 0.3s; }
.tx-bar span {
  position: absolute;
  inset: 0;
  font: 700 9px/12px system-ui, sans-serif;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 2px #000;
}
.tx-morale.low i { background: linear-gradient(#ff8a70, #b53a26); }
.tx-hp i { background: linear-gradient(#ff6f5c, #a8261b); }
.tx-hero-foe .tx-hp i, .tx-hero-me .tx-hp i { background: linear-gradient(#ff6f5c, #a8261b); }
.tx-plaque {
  min-width: 58px;
  padding: 3px 10px 4px;
  text-align: center;
  border: 2px solid var(--tx-gold);
  border-radius: 10px 10px 16px 16px;
  background: linear-gradient(#5d4416, #2c1f08);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(255, 230, 160, 0.25);
}
.tx-round { display: block; font: 900 24px/26px Georgia, "Times New Roman", serif; color: #ffe39a; text-shadow: 0 2px 3px #000; }
.tx-plaque small { display: block; font-size: 9.5px; color: var(--tx-dim); text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
.tx-timer { display: block; font: 700 11px/12px system-ui, sans-serif; }
.tx-timer.ok { color: #8fe08f; }
.tx-timer.warn { color: #f0c04a; }
.tx-timer.late { color: #ff6a55; }
.tx-corner { position: absolute; right: calc(6px + env(safe-area-inset-right)); top: 100%; display: flex; gap: 5px; }
.tx .tx-icon { min-height: 32px; width: 34px; padding: 0; font-size: 17px; border-radius: 50%; }

/* Battle log: a drawer under the corner buttons. */
.tx-log {
  position: absolute;
  right: 8px;
  top: 120px;
  width: min(300px, 78vw);
  max-height: 42vh;
  margin: 0;
  padding: 8px 10px 8px 26px;
  overflow: auto;
  border: 1px solid var(--tx-line);
  border-radius: 10px;
  background: var(--tx-glass);
  font-size: 12px;
  line-height: 1.35;
  display: none;
  z-index: 3;
}
#tactics-window.show-log .tx-log { display: block; }
.tx-log-me { color: #ffc9c0; }
.tx-log-foe { color: #c5d8ff; }

/* ---------- bottom: portraits in the corners, spells between ---------- */
.tx-bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: end;
  gap: 6px;
  padding: 14px calc(6px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(6px + env(safe-area-inset-left));
  background: linear-gradient(rgba(10, 8, 6, 0), rgba(10, 8, 6, 0.55) 30%, rgba(10, 8, 6, 0.88));
}
.tx-hero { width: 84px; display: flex; flex-direction: column; gap: 3px; }
.tx-portrait {
  position: relative;
  border: 2px solid var(--tx-gold);
  border-radius: 10px 10px 4px 4px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.7), 0 4px 12px rgba(0, 0, 0, 0.6);
  background: #120f0c;
}
.tx-face { display: block; width: 100%; height: auto; }
.tx-portrait.fallen { filter: grayscale(1) brightness(0.6); }
/* The spell phase: your hero's portrait glows. */
.tx-portrait.glow { animation: tx-hero-glow 1.2s ease-in-out infinite; border-color: #fff0b0; }
@keyframes tx-hero-glow {
  0%, 100% { box-shadow: 0 0 6px 1px rgba(255, 215, 110, 0.6); }
  50% { box-shadow: 0 0 18px 6px rgba(255, 225, 130, 0.95); }
}
.tx-fxs { position: absolute; left: 2px; right: 2px; bottom: 2px; display: flex; flex-wrap: wrap; gap: 2px; }
.tx-fx { font: 700 10px/14px system-ui, sans-serif; font-style: normal; padding: 0 3px; border-radius: 6px; background: rgba(10, 30, 8, 0.8); color: #c9ffb0; }
.tx-plate {
  padding: 2px 4px 3px;
  text-align: center;
  border: 1px solid #8a6a26;
  border-radius: 4px;
  background: linear-gradient(#e7c873, #a97f2c);
  color: #24170a;
  overflow: hidden;
}
.tx-plate b { display: block; font: 800 11px/13px Georgia, serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-plate small { display: block; font: 700 9.5px/11px system-ui, sans-serif; }
.tx-hero .tx-bar { margin-top: 0; height: 13px; }
.tx-hero .tx-bar span { line-height: 13px; }
.tx .tx-flee {
  min-height: 30px;
  border-radius: 16px;
  border-color: #d0624f;
  background: linear-gradient(#8e2f22, #561a12);
  font-weight: 800;
}
.tx-mid { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.tx-info { width: 100%; }
.tx-hint { margin: 0; padding: 4px 8px; font-size: 12px; line-height: 1.3; color: var(--tx-dim); text-align: center; text-shadow: 0 1px 2px #000; }
.tx-hint b { color: var(--tx-text); }
.tx-hint button { min-height: 26px; padding: 2px 8px; font-size: 12px; }
.tx-dock { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 5px; }
.tx-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.tx-small button { min-height: 30px; padding: 3px 9px; font-size: 12px; }
/* Round spell buttons: dim until the spell phase. */
.tx .tx-spell {
  position: relative;
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--tx-gold);
  background: radial-gradient(circle at 35% 30%, #5b4a2a, #1d160c 75%);
  font-size: 21px;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}
.tx .tx-spell i {
  position: absolute;
  right: -3px;
  bottom: -3px;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  background: #1a1410;
  border: 1px solid var(--tx-line);
  font: 800 10px/16px system-ui, sans-serif;
  font-style: normal;
  color: #ffd98a;
}
/* Spell buttons in two fixed rows: attack over defence. */
.tx-spellrows { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.tx-spellrow { display: flex; justify-content: center; gap: 6px; }
html.is-mobile .tx-spells { flex-basis: 100%; }
html.is-mobile .tx-spellrows { width: 100%; gap: 4px; }
html.is-mobile .tx-spellrow { gap: 4px; }
html.is-mobile .tx .tx-spell { width: 36px; height: 36px; min-height: 36px; font-size: 17px; }
.tx .tx-spell.aiming { border-color: #ff9b4a; box-shadow: 0 0 12px 3px rgba(255, 150, 60, 0.8); }
#tactics-window.tx-spell-phase .tx-spell:not(:disabled) { animation: tx-hero-glow 1.2s ease-in-out infinite; }
.tx .tx-next {
  height: 46px;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 23px;
  border: 2px solid var(--tx-gold);
  background: linear-gradient(#b8923f, #7c5d22);
  color: #1c1408;
  font-weight: 800;
}

/* Placement strip: formations and saved presets, above the dock. */
.tx-forms { width: 100%; }
.tx-forms:empty { display: none; }
.tx-forms-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 10px; font-size: 11.5px; color: var(--tx-dim); }
.tx-forms-head button { min-height: 28px; padding: 2px 9px; font-size: 12px; }
.tx-forms-head label { display: flex; align-items: center; gap: 3px; }
.tx-forms-row { display: flex; gap: 5px; margin-top: 4px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.tx-forms-row button { flex: 0 0 auto; min-height: 32px; padding: 3px 9px; font-size: 12px; white-space: nowrap; }
.tx-preset { border-style: dashed !important; }

/* ---------- banners and the result panel ---------- */
.tx-banner {
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  z-index: 4;
  text-align: center;
  pointer-events: none;
}
.tx-banner[hidden] { display: none; }
.tx-banner-flash b {
  display: block;
  font: 900 30px/1.1 Georgia, serif;
  color: #ffe39a;
  text-shadow: 0 3px 8px #000, 0 0 18px rgba(255, 190, 80, 0.6);
  animation: tx-pop-in 0.3s ease-out;
}
.tx-banner-flash span { display: block; margin-top: 4px; color: var(--tx-text); }
@keyframes tx-pop-in { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.tx-banner-end { pointer-events: auto; width: min(460px, 94vw); max-height: 86vh; overflow: auto; }
.tx-result {
  padding: 12px 12px 14px;
  border: 2px solid var(--tx-gold);
  border-radius: 14px;
  background: linear-gradient(rgba(44, 36, 24, 0.97), rgba(18, 15, 11, 0.97));
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8), inset 0 0 0 1px rgba(255, 230, 160, 0.18);
  animation: tx-pop-in 0.3s ease-out;
}
.tx-result-head { display: grid; grid-template-columns: 84px 1fr 84px; align-items: center; gap: 8px; }
.tx-result-side { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tx-result-side .tx-face { width: 72px; border: 2px solid var(--tx-gold); border-radius: 8px; }
.tx-result-side small { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--tx-dim); }
.tx-result-side b { font: 800 12px/1.15 Georgia, serif; text-align: center; overflow-wrap: anywhere; }
.tx-outcome {
  padding: 8px 6px;
  border-top: 2px solid var(--tx-gold);
  border-bottom: 2px solid var(--tx-gold);
  background: linear-gradient(90deg, rgba(120, 90, 30, 0), rgba(120, 90, 30, 0.55), rgba(120, 90, 30, 0));
  font: 900 21px/1.1 Georgia, serif;
  color: #ffe39a;
  text-shadow: 0 2px 4px #000;
}
.tx-outcome small { display: block; margin-top: 3px; font: 600 11px/1 system-ui, sans-serif; color: var(--tx-dim); }
.tx-result.won .tx-outcome { color: #b9f59a; }
.tx-result.lost .tx-outcome { color: #ff9a88; }
.tx-result-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; text-align: left; }
.tx-result-lists h4 { margin: 0 0 4px; padding-bottom: 3px; border-bottom: 1px solid var(--tx-line); font: 800 12px/1.2 Georgia, serif; color: var(--tx-gold); }
.tx-result-lists ul { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.tx-result-lists li { display: flex; justify-content: space-between; gap: 6px; padding: 2px 0; }
.tx-result-lists li b { color: #ff8a78; }
.tx-result-lists li.none { color: var(--tx-dim); }
.tx-result-lists li.none b { color: var(--tx-dim); font-weight: 400; }
.tx-banner-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 12px; }

/* ---------- pop-ups ---------- */
.tx-pop {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(0, 0, 0, 0.55);
}
.tx-pop[hidden] { display: none; }
.tx-pop-card {
  width: min(420px, 100%);
  max-height: 86vh;
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--tx-gold);
  border-radius: 14px;
  background: linear-gradient(rgba(44, 36, 24, 0.98), rgba(20, 17, 12, 0.98));
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
}
.tx-pop-card h3 { margin: 0 0 8px; font: 800 16px/1.2 Georgia, serif; color: var(--tx-gold); }
.tx-pop-card p { margin: 6px 0; font-size: 13px; line-height: 1.4; }
.tx-pop-card input[type="range"] { width: 100%; }
.tx-pop-card input[type="text"], .tx-pop-card textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 8px;
  border: 1px solid var(--tx-line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.4);
  color: var(--tx-text);
  font: 14px system-ui, sans-serif;
}
.tx-pop-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.tx-preset-row { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; padding: 6px 0; border-bottom: 1px solid rgba(215, 181, 106, 0.18); }
.tx-preset-row b { flex: 1 1 100%; }
.tx-preset-row button { min-height: 30px; padding: 3px 8px; font-size: 12px; }

/* Practice box in the Barracks. */
.practice-row { display: flex; flex-wrap: wrap; gap: 6px; }
.practice-modes { margin-bottom: 6px; }
.practice-modes button[aria-pressed="true"] { border-color: #e2c070; box-shadow: inset 0 0 0 1px #e2c070; }

/* Roomier chrome on wide screens. */
@media (min-width: 861px) {
  .tx-unit { width: 44px; height: 52px; }
  .tx-unit canvas { height: 50px; }
  .tx-unit b { font-size: 11px; line-height: 14px; }
  .tx-hero { width: 124px; }
  .tx-plate b { font-size: 14px; line-height: 17px; }
  .tx-plate small { font-size: 11px; line-height: 13px; }
  .tx .tx-spell { width: 56px; height: 56px; min-height: 56px; font-size: 26px; }
  .tx .tx-next { height: 56px; min-height: 56px; font-size: 15px; }
  .tx-round { font-size: 30px; line-height: 32px; }
  .tx-plaque { min-width: 76px; }
  .tx-hint { font-size: 13px; }
}
@media (max-width: 360px) {
  .tx-hero { width: 70px; }
  .tx .tx-spell { width: 40px; height: 40px; min-height: 40px; font-size: 18px; }
  .tx-unit { width: 30px; }
}
/* ---------- desktop (js/tacticsui.js sets .tx-desk when <html> is not .is-mobile) ----------
   The field is full-bleed: a thin top strip, hero corners in the two bottom triangles outside the
   board, and every control in one low row along the bottom centre. The phone keeps the rules above. */
#tactics-window.tx-desk .tx-clock { height: 8px; }
#tactics-window.tx-desk .tx-top { top: 8px; padding-top: 3px; padding-bottom: 3px; }
#tactics-window.tx-desk .tx-corner { display: none; }
#tactics-window.tx-desk .tx-log { top: 110px; }
#tactics-window.tx-desk .tx-bottom { display: block; height: 0; padding: 0; background: none; }
#tactics-window.tx-desk .tx-hero {
  position: absolute;
  bottom: 10px;
  width: auto;
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
}
#tactics-window.tx-desk .tx-hero:empty { display: none; }
#tactics-window.tx-desk .tx-hero-me { left: 10px; transform-origin: bottom left; }
#tactics-window.tx-desk .tx-hero-foe { right: 10px; flex-direction: row-reverse; transform-origin: bottom right; }
#tactics-window.tx-desk .tx-portrait { flex: none; width: 132px; }
.tx-hero-card {
  width: 178px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px;
  border: 1px solid var(--tx-line);
  border-radius: 10px;
  background: var(--tx-glass);
}
#tactics-window.tx-desk .tx-plate { display: flex; align-items: center; gap: 6px; padding: 3px 4px 3px 8px; text-align: left; }
#tactics-window.tx-desk .tx-plate b { flex: 1 1 auto; min-width: 0; font-size: 15px; line-height: 18px; }
.tx-lv {
  flex: none;
  min-width: 26px;
  height: 26px;
  padding: 0 3px;
  box-sizing: border-box;
  border: 2px solid #f6e2a0;
  border-radius: 13px;
  background: radial-gradient(#4a3413, #1b1206);
  color: #ffe39a;
  font: 800 13px/22px Georgia, serif;
  text-align: center;
}
.tx-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 0; }
.tx-stats div { padding: 3px 7px; border: 1px solid rgba(215, 181, 106, 0.25); border-radius: 6px; background: rgba(0, 0, 0, 0.38); }
.tx-stats dt { font: 700 10px/12px system-ui, sans-serif; text-transform: uppercase; letter-spacing: 0.04em; color: var(--tx-dim); }
.tx-stats dd { margin: 0; font: 800 16px/19px Georgia, serif; color: var(--tx-text); }
#tactics-window.tx-desk .tx-mid {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  box-sizing: border-box;
  width: max-content;
  max-width: calc(100% - 560px);
  max-height: 96px;
  gap: 3px;
  padding: 4px 10px 5px;
  overflow: hidden;
  border: 1px solid var(--tx-line);
  border-radius: 12px;
  background: rgba(12, 10, 8, 0.74);
}
#tactics-window.tx-desk .tx-info { order: 0; }
#tactics-window.tx-desk .tx-hint { padding: 0 4px; font-size: 12px; line-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#tactics-window.tx-desk .tx-hint button { min-height: 18px; padding: 0 7px; font-size: 11px; }
#tactics-window.tx-desk .tx-forms { order: 1; display: flex; align-items: center; gap: 6px; max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
#tactics-window.tx-desk .tx-forms:empty { display: none; }
#tactics-window.tx-desk .tx-forms-head { flex: none; flex-wrap: nowrap; white-space: nowrap; }
#tactics-window.tx-desk .tx-forms-row { flex: none; margin-top: 0; padding-bottom: 0; overflow: visible; }
#tactics-window.tx-desk .tx-dock { order: 2; max-width: 100%; }
.tx-deskrow { display: flex; align-items: center; gap: 8px; max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
.tx-deskrow .tx-row { flex: none; flex-wrap: nowrap; gap: 5px; }
#tactics-window.tx-desk .tx-mid button { min-height: 30px; padding: 2px 9px; font-size: 12px; white-space: nowrap; }
#tactics-window.tx-desk .tx-spellrows { flex-direction: row; gap: 5px; }
#tactics-window.tx-desk .tx-spellrow { gap: 5px; }
#tactics-window.tx-desk .tx-mid .tx-spell { width: 42px; height: 42px; min-height: 42px; padding: 0; font-size: 20px; }
#tactics-window.tx-desk .tx-mid .tx-next { height: 42px; min-height: 42px; }
#tactics-window.tx-desk .tx-mid .tx-icon { width: 32px; min-height: 32px; padding: 0; font-size: 16px; }
#tactics-window.tx-desk .tx-stage canvas { cursor: default; }

/* ---------- phone (js/tacticsui.js sets .tx-phone when the desktop gate is off) ----------
   Floating chrome over a full-bleed field: a one-row strip on top (cards scroll sideways, Log and
   Close at its right end), and at the bottom the info line, the spell row, and a bar with the two
   hero chips at its ends. Every bottom edge adds the phone's safe-area inset. */
.tx-pbar { display: none; }
#tactics-window.tx-phone .tx-top {
  grid-template-columns: minmax(0, 1fr) 76px minmax(0, 1fr) auto;
  align-items: center;
  gap: 4px;
  padding-top: calc(3px + env(safe-area-inset-top));
  padding-bottom: 3px;
}
#tactics-window.tx-phone .tx-units { flex-wrap: nowrap; gap: 3px; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; }
#tactics-window.tx-phone .tx-units::-webkit-scrollbar { display: none; }
#tactics-window.tx-phone .tx-cards-foe .tx-units { justify-content: flex-start; }
/* Right-aligned while the cards fit, still scrollable from the first card once they do not. */
#tactics-window.tx-phone .tx-cards-foe .tx-unit:first-child { margin-left: auto; }
#tactics-window.tx-phone .tx-unit { flex: none; width: 38px; height: 44px; box-sizing: border-box; cursor: pointer; }
#tactics-window.tx-phone .tx-unit canvas { height: 40px; }
#tactics-window.tx-phone .tx-unit b { font-size: 11px; line-height: 13px; }
#tactics-window.tx-phone .tx-unit.act-me { border: 2px solid #ffd76a; box-shadow: inset 0 0 6px rgba(255, 215, 106, 0.6); }
#tactics-window.tx-phone .tx-unit.act-foe { border: 2px solid #ff5a46; box-shadow: inset 0 0 6px rgba(255, 90, 70, 0.6); }
#tactics-window.tx-phone .tx-top .tx-bar { height: 13px; margin-top: 3px; }
#tactics-window.tx-phone .tx-top .tx-bar span { font-size: 11px; line-height: 11px; }
#tactics-window.tx-phone .tx-plaque { box-sizing: border-box; min-width: 0; width: 76px; padding: 2px 2px 3px; }
#tactics-window.tx-phone .tx-round { font-size: 22px; line-height: 24px; }
#tactics-window.tx-phone .tx-plaque small { font-size: 11px; line-height: 13px; letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; }
#tactics-window.tx-phone .tx-corner { position: static; flex-direction: column; gap: 3px; }
#tactics-window.tx-phone .tx-corner .tx-icon { width: 36px; min-height: 28px; height: 28px; border-radius: 9px; font-size: 16px; }
#tactics-window.tx-phone .tx-log { top: 80px; }

#tactics-window.tx-phone .tx-bottom {
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "mid mid mid" "me bar foe";
  align-items: center;
  gap: 3px 6px;
  padding-top: 2px;
}
#tactics-window.tx-phone .tx-mid { grid-area: mid; gap: 3px; }
#tactics-window.tx-phone .tx-hero-me { grid-area: me; }
#tactics-window.tx-phone .tx-hero-foe { grid-area: foe; }
#tactics-window.tx-phone .tx-hero { width: auto; }
#tactics-window.tx-phone .tx-pbar { grid-area: bar; display: flex; align-items: center; justify-content: center; gap: 5px; min-width: 0; }
#tactics-window.tx-phone .tx-pbar button { flex: none; min-height: 44px; padding: 3px 10px; white-space: nowrap; }
#tactics-window.tx-phone .tx-pbar .tx-icon { width: 40px; padding: 0; border-radius: 12px; font-size: 18px; }
#tactics-window.tx-phone .tx-pbar .tx-next { height: 44px; min-height: 44px; padding: 0 12px; }

/* Hero chips: a 40px face, name and level, the army's health. */
#tactics-window.tx-phone .tx .tx-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 92px;
  height: 48px;
  min-height: 48px;
  padding: 3px 5px 3px 3px;
  border-radius: 10px;
  text-align: left;
}
#tactics-window.tx-phone .tx-hero-foe .tx-chip { flex-direction: row-reverse; text-align: right; padding: 3px 3px 3px 5px; }
.tx-chip .tx-face { flex: none; width: 40px; height: 44px; border: 1px solid var(--tx-gold); border-radius: 7px; box-sizing: border-box; }
.tx-chip.fallen .tx-face { filter: grayscale(1) brightness(0.6); }
.tx .tx-chip.glow { animation: tx-hero-glow 1.2s ease-in-out infinite; border-color: #fff0b0; }
.tx-chip-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tx-chip-text b { font: 800 11px/13px Georgia, serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-chip-text small { font: 700 11px/12px system-ui, sans-serif; color: var(--tx-dim); white-space: nowrap; }
.tx-chip-hp { display: block; height: 6px; border-radius: 3px; background: rgba(0, 0, 0, 0.6); overflow: hidden; }
.tx-chip-hp span { display: block; height: 100%; background: linear-gradient(#ff6f5c, #a8261b); }

/* The info line: the hint, then the stack's own tools. */
.tx-infoline { display: flex; align-items: center; gap: 6px; min-height: 28px; }
.tx-infoline .tx-hint { flex: 1 1 auto; min-width: 0; padding: 2px 4px; text-align: left; }
.tx-infotools { flex: none; display: flex; gap: 4px; }
.tx-infotools button { min-height: 30px; padding: 3px 9px; font-size: 12px; }
/* At most two 14px lines, so the info line stays 28px tall. */
#tactics-window.tx-phone .tx-infoline { min-height: 28px; }
#tactics-window.tx-phone .tx-infoline .tx-hint { padding: 0 4px; font-size: 12px; line-height: 14px; max-height: 28px; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
#tactics-window.tx-phone .tx-infotools button { min-height: 28px; height: 28px; padding: 0 9px; }

/* The spell row: full width, 36px tall; up to five share the width, more scroll at 64px each. */
.tx-spellbar { width: 100%; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tx-spellbar::-webkit-scrollbar { display: none; }
#tactics-window.tx-phone .tx .tx-spellbar .tx-spell { flex: 1 1 0; min-width: 0; width: auto; height: 36px; min-height: 36px; border-radius: 10px; font-size: 18px; }
#tactics-window.tx-phone .tx .tx-spellbar.many .tx-spell { flex: 0 0 64px; }
.tx-spellbar .tx-spell i { right: 2px; bottom: 2px; }

/* The hero sheet rises from the bottom edge. */
#tactics-window.tx-phone .tx-pop.tx-sheet { align-items: flex-end; padding: 0; }
#tactics-window.tx-phone .tx-pop.tx-sheet .tx-pop-card {
  width: 100%;
  box-sizing: border-box;
  max-height: 80vh;
  border-radius: 16px 16px 0 0;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
}
.tx-sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.tx-sheet-head .tx-portrait { flex: none; width: 96px; }
.tx-sheet-name h3 { margin: 0 0 4px; }
.tx-sheet-name small { display: block; font-size: 12px; color: var(--tx-dim); }
.tx-sheet .tx-stats { grid-template-columns: 1fr 1fr 1fr; }
.tx-sheet-sub { margin: 10px 0 4px; font: 800 12px/1.2 Georgia, serif; color: var(--tx-gold); text-transform: uppercase; letter-spacing: 0.04em; }
.tx-leadlist { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.tx-leadlist li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px solid rgba(215, 181, 106, 0.18); }
.tx-leadlist b { color: #b9f59a; }
.tx-leadlist.fallen { opacity: 0.55; }
.tx-sheet .tx-bar { height: 14px; margin-top: 10px; }
.tx-sheet .tx-bar span { font-size: 11px; line-height: 14px; }
.tx-sheet-fx { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.tx-sheet-fx .tx-fx { font-size: 11px; line-height: 18px; padding: 0 6px; }

/* Deployment dock: the hero strip (chips, Fit, Traps), the picked stack's tools, the tray line,
   and the full-width Ready bar. The fold handle hides the hero strip. */
#tactics-window.tx-phone.tx-placing .tx-bottom {
  grid-template-areas: "me bar foe" "sel sel sel" "tray tray tray" "ready ready ready";
}
#tactics-window.tx-phone.tx-placing .tx-mid { display: contents; }
#tactics-window.tx-phone.tx-placing .tx-forms { grid-area: tray; }
#tactics-window.tx-phone.tx-placing .tx-info { grid-area: sel; }
#tactics-window.tx-phone.tx-placing .tx-info:empty { display: none; }
#tactics-window.tx-phone.tx-placing .tx-dock { grid-area: ready; }
#tactics-window.tx-phone.tx-folded .tx-hero, #tactics-window.tx-phone.tx-folded .tx-pbar { display: none; }
.tx-tray {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 2px;
  box-sizing: border-box;
  border: 1px solid var(--tx-line);
  border-radius: 12px;
  background: rgba(20, 17, 12, 0.85);
}
.tx-traytext { flex: 1 1 auto; min-width: 0; margin: 0; font: 700 12px/15px system-ui, sans-serif; color: var(--tx-text); }
.tx-traytext span { white-space: nowrap; }
#tactics-window.tx-phone .tx .tx-tray .tx-icon { flex: none; width: 40px; height: 40px; min-height: 40px; padding: 0; border-radius: 10px; font-size: 18px; }
#tactics-window.tx-phone .tx .tx-tray .tx-fold { width: 34px; }
#tactics-window.tx-phone .tx .tx-formsbtn { flex: none; min-height: 40px; padding: 0 12px; font-weight: 700; }
#tactics-window.tx-phone .tx .tx-ready { width: 100%; height: 48px; min-height: 48px; border-radius: 12px; font-size: 17px; }
.tx-selrow { display: flex; align-items: center; gap: 5px; min-height: 44px; }
.tx-selrow .tx-hint { flex: 1 1 auto; min-width: 0; margin: 0; padding: 0 4px; text-align: left; font-size: 12px; }
#tactics-window.tx-phone .tx .tx-selrow button { flex: none; min-height: 40px; padding: 0 10px; font-size: 13px; }
#tactics-window.tx-phone .tx .tx-selrow .tx-herobtn { flex: 0 1 auto; white-space: normal; line-height: 1.1; }

/* The formation sheet: cards in two columns, up to 55% of the screen; a picked card drops it to a
   peek so the preview shows on the field. */
#tactics-window.tx-phone .tx-pop.tx-fsheet .tx-pop-card { max-height: 55vh; }
.tx-fsheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.tx-fsheet-head h3 { margin: 0; }
.tx .tx-fsheet-head .tx-icon { width: 44px; height: 44px; min-height: 44px; padding: 0; font-size: 20px; }
.tx-fsheet-foot { flex-wrap: nowrap; }
.tx-fsheet-foot button { flex: 1 1 auto; padding: 0 8px; white-space: nowrap; }
.tx-fcards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tx .tx-fcard {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  min-width: 0;
  height: 88px;
  padding: 6px;
  border-radius: 10px;
  text-align: left;
}
.tx-fcard b { font: 800 13px/16px Georgia, serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-fcard canvas { display: block; width: 100%; height: auto; }
.tx .tx-fcard.ghosting, .tx .tx-fchip.ghosting { border-color: #ffd76a; box-shadow: inset 0 0 0 1px #ffd76a, 0 0 8px rgba(255, 215, 106, 0.5); }
.tx-fsheet-foot button, .tx-pop.tx-peek .tx-pop-actions button { min-height: 44px; }
#tactics-window .tx-pop.tx-peek { background: transparent; pointer-events: none; }
#tactics-window .tx-pop.tx-peek .tx-pop-card { pointer-events: auto; padding-top: 10px; }
.tx-peek-row { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.tx-peek-row::-webkit-scrollbar { display: none; }
.tx .tx-fchip { flex: none; min-height: 40px; padding: 0 12px; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .tx-clock i { transition: none; }
  .tx-clock.late .tx-clock-all { animation: none; }
  .tx button, .tx-bar i { transition: none; }
  .tx-banner-flash b, .tx-result, .tx-portrait.glow, .tx .tx-chip.glow, #tactics-window.tx-spell-phase .tx-spell:not(:disabled) { animation: none; }
}
