:root {
  color-scheme: dark;
  --bg: #12151b;
  --panel: #1c222b;
  --panel-strong: #252d38;
  --line: #394350;
  --text: #f3f0e8;
  --muted: #aeb6c2;
  --gold: #d5b25f;
  --danger: #d86464;
  --ok: #69bd75;
  --shadow: 0 4px 8px rgba(0, 0, 0, 0.28);

  /* Shared UI design tokens (consumed by menu, route, and battle screens). */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-pill: 999px;
  --slot-size: 46px;
  --fire: #e85d3f;
  --water: #4387d8;
  --grass: #58a95d;
  --ring-player: #4aa3ff;
  --ring-enemy: #e0554f;
  --emblem-ink: #101318;
  --emblem-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.16);
  --chip-bg: rgba(255, 255, 255, 0.05);
  --chip-border: var(--line);
  --slot-bg: rgba(255, 255, 255, 0.06);

  font-family: Aptos, "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh; /* mobile: exclude the address bar so nothing is cut off */
  background: var(--bg);
  color: var(--text);
}

/* ---- Mobile hardening ---- */
html, body {
  /* Stop pull-to-refresh / rubber-band from reloading mid-battle. */
  overscroll-behavior: none;
}

/* Kill the grey/blue tap flash on every control. */
a, button, .mission-node, .faction-card, .route-node, .capture-ball,
.vendor-offer, .vendor-unit, .vendor-safari-card, .reward-card button {
  -webkit-tap-highlight-color: transparent;
}

/* Controls and game art shouldn't be text-selectable or long-press-saveable. */
button, .icon-button, .mission-node, .route-node, .faction-card, .command-button,
.active-party, .battle-board, .route-map, .topbar h1, .stat-stack {
  -webkit-user-select: none;
  user-select: none;
}

img {
  -webkit-touch-callout: none; /* no long-press "save image" on sprites */
}

/* Inputs must be >=16px on phones or iOS auto-zooms the whole page on focus. */
@media (max-width: 760px) {
  input, textarea, select {
    font-size: 16px;
  }
}

button {
  font: inherit;
}

button:not(:disabled) {
  cursor: pointer;
}

/* Shared component primitives. Reused across menu cards, route panels, and the
   battle board. Existing bespoke tokens (.unit-token, .mission-glyph,
   .type-row span) can converge onto these in later steps. */
.portrait-slot {
  width: var(--slot-size);
  height: var(--slot-size);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--slot-bg);
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--text);
  font-weight: 900;
  font-size: 0.72rem;
}

.portrait-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.portrait-slot--empty {
  border-style: dashed;
  opacity: 0.55;
}

.emblem {
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--accent, var(--gold));
  color: var(--emblem-ink);
  box-shadow: var(--emblem-shadow);
}

.emblem svg {
  width: 66%;
  height: 66%;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--chip-border);
  border-radius: var(--radius-pill);
  padding: 4px 8px;
  background: var(--chip-bg);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 800;
}

.chip--type {
  border-color: color-mix(in srgb, var(--type-color) 60%, var(--line));
  background: color-mix(in srgb, var(--type-color) 18%, transparent);
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  /* Respect notch / rounded-corner safe areas (home-screen / PWA use). */
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1500px;
  margin: 0 auto 16px;
}

.topbar h1,
.panel-heading h2,
.setup-copy h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 1.75rem;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar-actions,
.command-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.icon-button,
.command-button,
.reward-card button,
.mission-node,
.faction-card {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel);
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}

.icon-button:focus-visible,
.command-button:focus-visible,
.reward-card button:focus-visible,
.mission-node:focus-visible,
.faction-card:focus-visible,
.formation-options button:focus-visible,
.narrative-panel button:focus-visible,
.return-button:focus-visible,
.capture-ball:focus-visible,
.capture-flute-actions button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--gold) 76%, white);
  outline-offset: 2px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-weight: 900;
  text-decoration: none; /* the support button is an <a> styled as a button */
  cursor: pointer;
}

.icon-button svg {
  width: 22px;
  height: 22px;
}

/* Support link: a warm coffee accent so it reads as the friendly ask. */
.icon-button--support {
  font-size: 1.2rem;
  color: var(--gold);
  border-color: color-mix(in srgb, var(--gold) 45%, var(--line));
}

.icon-button--support:hover {
  background: color-mix(in srgb, var(--gold) 16%, var(--panel));
}

/* Muted state: dim the speaker so on/off reads at a glance. */
.icon-button--off {
  color: var(--muted);
  opacity: 0.85;
}

.icon-button:hover,
.command-button:hover,
.reward-card button:hover,
.mission-node:not(:disabled):hover,
.faction-card:hover {
  border-color: var(--gold);
  transform: translateY(-1px);
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.setup-view {
  max-width: 1500px;
  margin: 0 auto;
  min-height: calc(100vh - 100px);
  min-height: calc(100dvh - 100px);
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 18px;
  padding: 22px;
  border: 0;
  border-radius: 12px;
  background: #10161d;
  box-shadow: inset 0 0 0 1px rgba(226, 240, 255, 0.14);
}

.setup-view::before,
.setup-view::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.setup-view::before {
  z-index: 0;
  background: url("../assets/ui/main-menu-fortress-v1.png") center 42% / cover no-repeat;
  filter: saturate(0.88) contrast(1.04);
}

.setup-view::after {
  z-index: 0;
  background:
    linear-gradient(90deg, rgba(7, 10, 16, 0.8), rgba(7, 10, 16, 0.55) 50%, rgba(7, 10, 16, 0.8)),
    linear-gradient(180deg, rgba(7, 10, 16, 0.28), rgba(7, 10, 16, 0.9) 78%);
}

.setup-view > * {
  position: relative;
  z-index: 1;
}

.setup-copy {
  max-width: none;
  padding: 8px 10px 4px;
  border: 0;
  background: none;
  text-shadow: none;
}

.setup-copy h2 {
  font-size: 2.25rem;
  line-height: 1.12;
  max-width: 820px;
  text-wrap: balance;
}

.setup-copy p:last-child {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
  max-width: 72ch;
  text-wrap: pretty;
}

.setup-actions {
  max-width: 620px;
}

/* War Realism mode selector on the setup screen (only when unlocked). */
.mode-select {
  margin-top: 18px;
}

.mode-select__options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 8px;
}

.mode-option {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease;
}

.mode-option strong { font-size: 0.98rem; }
.mode-option span { color: var(--muted); font-size: 0.82rem; }

.mode-option:hover { border-color: color-mix(in srgb, var(--gold) 50%, var(--line)); }

.mode-option--active {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 12%, var(--panel));
}

.mode-option--realism.mode-option--active {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, var(--panel));
}

.mode-option--realism.mode-option--active strong { color: color-mix(in srgb, var(--danger) 82%, white 16%); }

/* When realism is armed, tint the army cards so the stakes read at a glance. */
.faction-grid--realism .faction-card {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--danger) 22%, transparent);
}

.chip--realism {
  --type-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 22%, var(--panel));
  color: color-mix(in srgb, var(--danger) 82%, white 18%);
  border-color: color-mix(in srgb, var(--danger) 55%, transparent);
}

.continue-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  margin-top: 18px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--gold) 42%, var(--line));
  border-radius: var(--radius-md);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--gold) 14%, transparent), transparent 48%),
    var(--panel);
}

.continue-card strong,
.continue-card span {
  display: block;
}

.continue-card span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

.continue-card__actions {
  display: flex;
  gap: 8px;
}

.continue-card__actions button {
  min-height: 38px;
  border-radius: 7px;
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 900;
  padding: 0 12px;
}

.continue-card__actions button[data-save="continue"] {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 24%, var(--panel));
}

.faction-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}

.faction-card {
  --accent: var(--gold);
  width: 100%;
  min-width: 0;
  min-height: 314px;
  border-radius: var(--radius-md);
  border: 2px solid color-mix(in srgb, var(--accent) 52%, var(--line));
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 82px minmax(82px, 1fr) auto auto;
  gap: 9px;
  text-align: left;
  background: color-mix(in srgb, var(--accent) 11%, var(--panel));
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--accent) 34%, rgba(255, 255, 255, 0.1));
  overflow: hidden;
}

.faction-card:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 17%, var(--panel));
  transform: translateY(-3px);
}

.faction-card:active {
  transform: translateY(-1px);
}

.faction-card__header,
.faction-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.faction-card__title {
  min-width: 0;
  font-size: 1.1rem;
  font-weight: 900;
  color: color-mix(in srgb, var(--accent) 64%, white);
}

.faction-card__rank {
  flex: none;
  padding: 4px 7px;
  border: 1px solid color-mix(in srgb, var(--accent) 70%, white 10%);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 24%, #11161d);
  font-size: 0.7rem;
  font-weight: 900;
}

.faction-card__insignia {
  display: grid;
  place-items: center;
  min-width: 0;
}

.faction-card__insignia img {
  width: 76px;
  height: 76px;
  object-fit: contain;
  filter: drop-shadow(0 4px 3px rgba(0, 0, 0, 0.42));
}

.faction-card__title,
.faction-card__section > span:last-child,
.faction-card__footer small {
  overflow-wrap: anywhere;
}

.faction-card__section {
  display: grid;
  align-content: start;
  gap: 4px;
}

.faction-card__label {
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.faction-card__section > span:last-child {
  color: color-mix(in srgb, var(--accent) 12%, var(--muted));
  line-height: 1.36;
  font-size: 0.76rem;
}

.faction-card__section strong {
  color: var(--text);
  font-size: 0.86rem;
  line-height: 1.3;
}

.faction-card__recruits {
  display: grid;
  gap: 5px;
}

.faction-card__starters {
  display: flex;
  gap: 6px;
}

.faction-recruit {
  position: relative;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent) 54%, var(--line));
  border-radius: var(--radius-sm);
  color: var(--text);
  background: rgba(6, 10, 15, 0.44);
  font-size: 0.7rem;
  font-weight: 900;
}

.faction-card__footer {
  align-self: end;
  padding-top: 9px;
  border-top: 1px solid color-mix(in srgb, var(--accent) 34%, var(--line));
}

.faction-card__footer small {
  max-width: 118px;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.25;
}

.faction-card__footer strong {
  flex: none;
  color: color-mix(in srgb, var(--accent) 72%, white);
  font-size: 0.74rem;
  text-align: right;
}

.unit-token,
.combatant-token,
.mission-glyph,
.route-step {
  display: grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: 0;
}

.boss-chip,
.clock-chip,
.type-row span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.75rem;
  font-weight: 800;
}

.campaign-view {
  max-width: 1700px;
  margin: 0 auto;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.command-panel {
  flex: 0 0 clamp(230px, 24%, 300px);
}

/* Route, capture, and battle share the main region; only one is shown at a time. */
.route-view,
.story-view,
.capture-view,
.spoils-view,
.battle-view {
  flex: 1 1 auto;
  min-width: 0;
}

/* Squad/roster/reward asides moved into the pause menu and spoils screen, so
   the route panel now owns the full row. */
.route-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.battle-view {
  width: 100%;
  max-width: 1380px;
  margin: 0 auto;
}

.story-view {
  width: 100%;
  max-width: 1380px;
  margin: 0 auto;
}

.campaign-view:not(.campaign-view--route) .command-panel {
  display: none;
}

.capture-view,
.spoils-view {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
}

.side-panel,
.route-panel,
.capture-panel,
.spoils-panel,
.battle-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(28, 34, 43, 0.94);
  box-shadow: var(--shadow);
}

.side-panel,
.route-panel {
  padding: 14px;
}

.battle-panel {
  padding: 14px;
}

.capture-panel,
.spoils-panel {
  padding: 14px;
}

.spoils-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
  margin: 12px 0 14px;
}

/* Small support-the-dev link (main menu footer + Options menu). */
.coffee-link {
  color: var(--gold);
  text-decoration: none;
  border-bottom: 1px dotted color-mix(in srgb, var(--gold) 60%, transparent);
  white-space: nowrap;
}

.coffee-link:hover {
  border-bottom-style: solid;
}

/* ---- Shop Pool vendor screens ---- */
.vendor-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 12px 0 14px;
}

.vendor-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
}

.vendor-head__sprite {
  width: 56px;
  height: 56px;
  image-rendering: pixelated;
  object-fit: contain;
}

.vendor-head__copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.vendor-head__copy span {
  color: var(--muted);
  font-size: 0.85rem;
}

.vendor-note {
  color: var(--muted);
  font-size: 0.85rem;
}

.vendor-offers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.vendor-offer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.vendor-offer:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--gold) 55%, var(--line));
  background: rgba(255, 255, 255, 0.06);
}

.vendor-offer:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.vendor-offer__copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.vendor-offer__copy small {
  color: var(--muted);
}

.vendor-offer__price {
  color: var(--gold);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.vendor-unit-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.vendor-unit {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.vendor-unit:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--gold) 55%, var(--line));
}

.vendor-unit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.vendor-unit--result {
  cursor: default;
}

.vendor-unit__id {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.vendor-unit__id small {
  color: var(--muted);
}

.vendor-safari-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.vendor-safari-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 12px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: inherit;
  cursor: pointer;
}

.vendor-safari-card:hover {
  border-color: color-mix(in srgb, var(--gold) 55%, var(--line));
  background: rgba(255, 255, 255, 0.06);
}

.vendor-safari-card small {
  color: var(--muted);
}

.vendor-unit .unit-token,
.vendor-safari-card .unit-token {
  display: grid;
  place-items: center;
  flex: none;
}

.vendor-result {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--gold) 40%, var(--line));
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
}

.route-status {
  margin-bottom: 12px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.panel-heading h2 {
  font-size: 1.15rem;
}

.side-panel h3 {
  margin: 16px 0 8px;
  font-size: 0.92rem;
  color: var(--muted);
}

.stat-stack {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat-stack div {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.supply-request {
  min-height: 54px;
  display: grid;
  align-content: center;
  justify-items: start;
  border: 1px solid color-mix(in srgb, var(--gold) 62%, var(--line));
  border-radius: 7px;
  padding: 8px;
  color: var(--text);
  background: color-mix(in srgb, var(--gold) 12%, rgba(255, 255, 255, 0.04));
  text-align: left;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.supply-request:not(:disabled):hover {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 19%, var(--panel));
  transform: translateY(-1px);
}

.supply-request:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.supply-request:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.supply-request span {
  color: color-mix(in srgb, var(--gold) 74%, white);
  font-weight: 800;
}

.stat-stack span,
.unit-meta,
.reward-card small,
.mission-copy small,
.empty-state span {
  color: var(--muted);
  font-size: 0.76rem;
}

.stat-stack strong {
  display: block;
  margin-top: 2px;
  font-size: 1.18rem;
}

.stat-badges {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.badge-track {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge-track .portrait-slot {
  width: 26px;
  height: 26px;
}

.insignia-slot {
  width: 24px;
  height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: #0e1218;
  background: rgba(255, 255, 255, 0.05);
  font-size: 0.7rem;
  font-weight: 900;
}

.insignia-slot--earned {
  border-color: color-mix(in srgb, var(--type-color) 75%, white 10%);
  background: color-mix(in srgb, var(--type-color) 18%, rgba(255, 255, 255, 0.05));
}

.insignia-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.45));
}

.deploy-rule,
.empty-state {
  margin-top: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--muted);
  display: grid;
  gap: 3px;
}

.deploy-rule strong,
.empty-state strong {
  color: var(--text);
}

.formation-panel {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px;
  background: rgba(255, 255, 255, 0.035);
  display: grid;
  gap: 8px;
}

.formation-panel__head {
  display: grid;
  gap: 3px;
}

.formation-panel__head strong {
  color: var(--text);
}

.formation-panel__head span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.formation-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.formation-options button {
  min-height: 34px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  font-size: 0.72rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.formation-options button.formation-option--active {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 22%, var(--panel));
}

.formation-options button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.panel-action {
  margin-top: 6px;
  width: 100%;
  min-height: 38px;
}

.active-party {
  margin: 4px 0 14px;
}

.active-party__head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

/* Opens the Pokemon management screen straight from the route header. */
.active-party__manage {
  margin-left: auto;
  padding: 5px 10px;
  min-height: 32px;
  border: 1px solid color-mix(in srgb, var(--gold) 50%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--gold) 12%, var(--panel));
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

.active-party__manage:hover {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 20%, var(--panel));
}

.active-party__title {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.active-party__count {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.active-party__list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 6px;
}

.active-party__unit {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  padding: 7px 9px;
  border: 1px solid color-mix(in srgb, var(--unit-color) 26%, var(--line));
  border-radius: var(--radius-md);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--unit-color) 12%, transparent), transparent 62%),
    rgba(255, 255, 255, 0.035);
}

.active-party__token {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  overflow: hidden;
  background: color-mix(in srgb, var(--unit-color) 22%, var(--panel-strong));
  color: var(--text);
  font-weight: 900;
  font-size: 0.72rem;
}

.active-party__token img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.active-party__id {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.active-party__id strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
}

.active-party__id small {
  color: var(--muted);
  font-size: 0.72rem;
}

.active-party__stats {
  display: flex;
  gap: 8px;
}

.active-party__stats span {
  display: grid;
  justify-items: center;
  gap: 1px;
  font-size: 0.82rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.active-party__stats em {
  color: var(--muted);
  font-size: 0.62rem;
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.narrative-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--gold) 36%, var(--line));
  border-radius: var(--radius-md);
  background:
    linear-gradient(135deg, rgba(236, 202, 116, 0.11), transparent 42%),
    rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--gold) 18%, rgba(255, 255, 255, 0.08));
}

.narrative-panel[hidden] {
  display: none;
}

.narrative-panel strong,
.narrative-panel span {
  display: block;
}

.narrative-panel strong {
  margin-bottom: 6px;
}

.narrative-panel span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.narrative-panel span + span {
  margin-top: 5px;
}

.narrative-panel button {
  min-height: 36px;
  border-radius: 7px;
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  font-weight: 900;
  padding: 0 10px;
}

.unit-list,
.reward-panel {
  display: grid;
  gap: 8px;
}

.unit-list--active-nine {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.reward-group {
  display: grid;
  gap: 6px;
}

.reward-group__label {
  margin: 0;
  color: var(--gold);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.reward-slot {
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  padding: 9px;
  color: var(--muted);
  font-size: 0.8rem;
}

.unit-card,
.reward-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.045);
}

.unit-card--deployed {
  border-color: color-mix(in srgb, var(--unit-color) 58%, var(--line));
}

.unit-list--active-nine .unit-card {
  grid-template-columns: 1fr;
  align-items: center;
  justify-items: center;
  gap: 6px;
  min-height: 112px;
  padding: 7px;
  text-align: center;
}

.unit-list--active-nine .unit-name-row,
.unit-list--active-nine .unit-meta,
.unit-list--active-nine .type-row {
  justify-content: center;
}

.unit-list--active-nine .unit-name-row span,
.unit-list--active-nine .type-row {
  display: none;
}

.unit-list--active-nine .unit-meta {
  font-size: 0.7rem;
  line-height: 1.2;
}

.unit-list--active-nine .unit-main {
  display: grid;
  gap: 4px;
  width: 100%;
}

.unit-token {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #11151b;
  background: var(--unit-color);
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.14);
  font-size: 0.78rem;
}

.reward-item-token {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #15120a;
  font-size: 0.82rem;
  font-weight: 900;
  background:
    linear-gradient(145deg, rgba(255, 240, 170, 0.95), rgba(206, 159, 58, 0.78));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 6px 16px rgba(0, 0, 0, 0.2);
}

.unit-main {
  min-width: 0;
}

.unit-name-row,
.unit-meta,
.type-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.unit-meta .combat-stat {
  color: color-mix(in srgb, var(--unit-color) 68%, var(--muted));
}

.unit-list--active-nine .unit-meta .combat-stat {
  color: var(--muted);
}

.unit-name-row {
  justify-content: space-between;
}

.unit-name-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-name-row span {
  color: var(--muted);
  font-size: 0.72rem;
}

.type-row {
  margin: 5px 0;
}

.type-row span {
  border-color: color-mix(in srgb, var(--type-color) 60%, var(--line));
  background: color-mix(in srgb, var(--type-color) 18%, transparent);
}

.xp-bar,
.health-bar,
.charge-bar {
  display: block;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.28);
}

.xp-bar {
  margin-top: 7px;
  height: 5px;
  border-radius: 999px;
}

.xp-bar span,
.health-bar span,
.charge-bar span {
  display: block;
  height: 100%;
}

.xp-bar span {
  background: var(--gold);
}

.route-map {
  display: grid;
  gap: 9px;
}

/* ---- Route node map (pokelike-style vertical graph) ---- */
.route-graph {
  position: relative;
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow: hidden;
  background:
    linear-gradient(rgba(8, 14, 12, 0.72), rgba(8, 14, 12, 0.82)),
    url("../assets/battlefields/route-field-12x8-v2.png") center / cover;
}

/* Walked-path trail: gold marching dashes along the route the trainer took,
   with a soft pulse at the head. Sits under the nodes. */
.route-graph__trail {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.route-trail {
  fill: none;
  stroke: color-mix(in srgb, var(--gold) 80%, white);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 2 8;
  vector-effect: non-scaling-stroke;
  opacity: 0.85;
  filter: drop-shadow(0 0 3px rgba(213, 178, 95, 0.55));
  animation: route-trail-march 1.4s linear infinite;
}

@keyframes route-trail-march {
  to { stroke-dashoffset: -10; }
}

.route-trail__head {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px rgba(213, 178, 95, 0.8);
  pointer-events: none;
  z-index: 1;
  animation: route-trail-pulse 1.8s ease-in-out infinite;
}

@keyframes route-trail-pulse {
  0%, 100% { opacity: 0.9; transform: translate(-50%, -50%) scale(1); }
  50% { opacity: 0.45; transform: translate(-50%, -50%) scale(1.7); }
}

@media (prefers-reduced-motion: reduce) {
  .route-trail { animation: none; }
  .route-trail__head { animation: none; }
}

.route-node {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 104px;
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  z-index: 2;
}

.route-node__label {
  max-width: 104px;
  font-size: 0.7rem;
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.route-node--active .route-node__label {
  color: var(--gold);
}

.route-node--locked .route-node__label {
  opacity: 0.55;
}

.route-node:disabled {
  cursor: default;
}

.route-node__disc {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: rgba(12, 18, 24, 0.92);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.route-node--boss .route-node__disc {
  width: 70px;
  height: 70px;
  border-color: color-mix(in srgb, var(--gold) 60%, var(--line));
}

.route-node__sprite {
  width: 44px;
  height: 44px;
  image-rendering: pixelated;
  object-fit: contain;
}

.route-node--boss .route-node__sprite {
  width: 56px;
  height: 56px;
}

.route-node__glyph {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: var(--muted);
}

.route-node__glyph svg {
  width: 100%;
  height: 100%;
}

/* Active row: gold ring pulse, hover lift. */
.route-node--active .route-node__disc {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 30%, transparent), 0 3px 12px rgba(0, 0, 0, 0.55);
  animation: route-node-pulse 1.8s ease-in-out infinite;
}

.route-node--active .route-node__glyph {
  color: var(--gold);
}

.route-node--active:hover:not(:disabled) .route-node__disc {
  transform: scale(1.07);
}

@keyframes route-node-pulse {
  0%, 100% { box-shadow: 0 0 0 2px color-mix(in srgb, var(--gold) 25%, transparent), 0 3px 12px rgba(0, 0, 0, 0.55); }
  50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--gold) 12%, transparent), 0 3px 12px rgba(0, 0, 0, 0.55); }
}

.route-node--complete .route-node__disc,
.route-node--locked .route-node__disc {
  opacity: 0.75;
}

.route-node--locked .route-node__sprite {
  filter: grayscale(0.9) brightness(0.7);
}

.route-node--complete .route-node__sprite {
  filter: saturate(0.5) brightness(0.85);
}

.route-node__badge {
  position: absolute;
  right: -5px;
  bottom: -5px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(10, 14, 20, 0.95);
  border: 1px solid var(--line);
  color: var(--muted);
}

.route-node__badge svg {
  width: 12px;
  height: 12px;
}

.route-node__badge--done {
  color: #7fd68b;
  border-color: color-mix(in srgb, #7fd68b 45%, var(--line));
}

.route-graph__marker {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  z-index: 2;
  pointer-events: none;
}

.route-graph__marker img {
  width: 52px;
  height: 52px;
  image-rendering: pixelated;
  object-fit: contain;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.6));
}

.route-row {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 8px;
  align-items: stretch;
}

.route-step {
  position: relative;
  width: 34px;
  min-height: 72px;
  border-radius: 8px;
  color: #11151b;
  background: var(--line);
}

.route-row:not(:last-child) .route-step::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 9px;
  transform: translateX(-50%);
  background: var(--line);
}

.route-row--complete .route-step {
  background: var(--ok);
}

.route-row--complete:not(:last-child) .route-step::after {
  background: var(--ok);
}

.route-row--active .route-step {
  background: var(--gold);
}

.route-options {
  display: grid;
  gap: 8px;
}

.mission-node {
  min-height: 76px;
  border-radius: 8px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px;
  text-align: left;
}

.mission-node:disabled {
  opacity: 0.55;
}

.mission-glyph {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #101318;
  background: var(--gold);
}

.mission-glyph svg {
  width: 62%;
  height: 62%;
}

.mission-node--wild .mission-glyph {
  background: #67b779;
}

.mission-node--supply .mission-glyph {
  background: #d5b25f;
}

.mission-node--elite .mission-glyph {
  background: #9b78d4;
}

.mission-node--joint .mission-glyph {
  background: #5fc1b0;
}

.mission-node--boss .mission-glyph {
  background: #d86464;
}

.route-row--complete .mission-glyph {
  background: var(--ok);
}

.route-row--locked .mission-glyph {
  background: var(--line);
}

.mission-copy {
  display: grid;
  gap: 2px;
}

.mission-copy span {
  color: var(--muted);
  line-height: 1.3;
}

.board-wrap {
  position: relative;
  isolation: isolate;
}

.mission-commander {
  display: grid;
  grid-template-columns: 44px;
  justify-items: center;
  align-content: center;
  min-width: 54px;
  color: var(--muted);
  font-size: 0.7rem;
  text-align: center;
}

.mission-commander__sprite {
  width: 44px;
  height: 48px;
  object-fit: contain;
  image-rendering: pixelated;
}

.mission-node--boss .mission-commander__sprite,
.mission-node--elite .mission-commander__sprite {
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.55));
}

.battle-heading__status,
.battle-commander {
  display: flex;
  align-items: center;
  gap: 9px;
}

.battle-heading__status {
  justify-content: flex-end;
}

.battle-commander {
  min-width: 0;
}

.battle-commander__sprite {
  width: 44px;
  height: 44px;
  object-fit: contain;
  image-rendering: pixelated;
}

.battle-commander span {
  display: grid;
  min-width: 0;
  line-height: 1.05;
}

.battle-commander small {
  color: var(--muted);
  font-size: 0.7rem;
}

.battle-commander strong {
  overflow: hidden;
  max-width: 150px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
}

.battle-intro {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 18px;
  overflow: hidden;
  border-radius: 10px;
  background: rgba(9, 12, 16, 0.84);
  pointer-events: none;
  animation: battle-intro-exit 1100ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.battle-intro__side {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 18px;
  font-weight: 900;
}

.battle-intro__side--player {
  justify-content: flex-end;
  color: #b9ddff;
}

.battle-intro__side--enemy {
  color: #ffc0b6;
}

.battle-intro__side img:not(.battle-intro__trainer) {
  width: 80px;
  height: 80px;
  object-fit: contain;
}

.battle-intro__trainer {
  width: 92px;
  height: 112px;
  object-fit: contain;
  image-rendering: pixelated;
}

.battle-intro > strong {
  color: var(--gold);
  font-size: 1.35rem;
}

.battle-intro__wild {
  grid-column: 1 / -1;
  display: grid;
  justify-items: center;
  gap: 4px;
  text-transform: uppercase;
}

.battle-intro__wild span {
  color: var(--muted);
  font-size: 0.78rem;
}

.battle-intro__wild strong {
  font-size: 1.4rem;
}

.battle-intro--xl {
  grid-template-columns: minmax(0, 1fr);
  background: rgba(9, 14, 20, 0.93);
  animation: battle-intro-exit 1800ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.battle-intro__reinforcement {
  width: min(760px, 92%);
  margin: auto;
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 18px;
  border-top: 2px solid var(--gold);
  border-bottom: 2px solid var(--gold);
  background: rgba(20, 28, 36, 0.96);
}

.battle-intro__xl-label {
  display: grid;
  gap: 2px;
  text-align: center;
  text-transform: uppercase;
}

.battle-intro__xl-label strong {
  color: var(--gold);
  font-size: 1.35rem;
}

.battle-intro__xl-label span,
.battle-intro__partners small,
.battle-intro__muso small {
  color: var(--muted);
  font-size: 0.7rem;
}

.battle-intro__muso {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.battle-intro__muso-portrait {
  width: 82px;
  height: 104px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--gold) 54%, var(--line));
  background: color-mix(in srgb, var(--gold) 10%, var(--panel-strong));
}

.battle-intro__muso-trainer {
  /* No scale transform: the frame clips anything past its border, so the
     sprite must fit entirely inside it. */
  width: 74px;
  height: 96px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.55));
}

.battle-intro__muso span {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.battle-intro__muso strong {
  font-size: 1.4rem;
  font-weight: 900;
  line-height: 1.2;
  text-wrap: balance;
}

.battle-intro__partners {
  display: flex;
  gap: 8px;
}

.battle-intro__partners > span {
  width: 68px;
  display: grid;
  justify-items: center;
  gap: 3px;
  padding: 3px;
  border: 1px solid color-mix(in srgb, var(--gold) 34%, var(--line));
  background: rgba(7, 11, 16, 0.52);
}

.battle-intro__partners img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.48));
}

@keyframes battle-intro-exit {
  0%, 56% { opacity: 1; clip-path: inset(0); }
  100% { opacity: 0; clip-path: inset(48% 0); }
}

/* Cosmetic attack VFX overlay. Anchored to the board's top-left; individual
   effects are positioned at real cell centers, so it must not clip (the board
   can render wider than this wrapper via its aspect-ratio min size). Never
   intercepts clicks. */
.vfx-layer {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 3;
}

.vfx {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  will-change: transform, opacity;
}

/* Atlas-frame attack VFX (projectile/melee/hit) positioned via left/top. */
.vfx-atlas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  z-index: 2;
}

.vfx-proj {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--vfx) 45%, transparent 72%);
  box-shadow: 0 0 10px 2px color-mix(in srgb, var(--vfx) 70%, transparent);
}

.vfx-slash {
  width: 30px;
  height: 7px;
  border-radius: 6px;
  background: linear-gradient(90deg, transparent, var(--vfx) 40%, #fff 55%, var(--vfx) 70%, transparent);
  box-shadow: 0 0 8px 1px color-mix(in srgb, var(--vfx) 60%, transparent);
  animation: vfx-slash-fade 190ms ease-out forwards;
}

.vfx-hit {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, var(--vfx) 42%, transparent 70%);
  box-shadow: 0 0 12px 3px color-mix(in srgb, var(--vfx) 55%, transparent);
  animation: vfx-hit-pop 260ms ease-out forwards;
}

.vfx--fade {
  animation: vfx-fade 200ms ease-out forwards;
}

.vfx--special.vfx-proj {
  width: 20px;
  height: 20px;
}

.vfx--special.vfx-slash {
  width: 40px;
  height: 9px;
}

.vfx--special.vfx-hit {
  width: 24px;
  height: 24px;
}

@keyframes vfx-hit-pop {
  0% {
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(2.4);
    opacity: 0;
  }
}

@keyframes vfx-slash-fade {
  0% {
    opacity: 0;
  }
  25% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes vfx-fade {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

.battle-board {
  --board-width: 12;
  --board-height: 8;

  /* Shared battlefield atmosphere (variants tune ground + one detail layer). */
  --bf-vignette: rgba(0, 0, 0, 0.5);
  --bf-enemy: rgba(226, 116, 88, 0.15); /* warm top = enemy side */
  --bf-player: rgba(78, 152, 220, 0.15); /* cool bottom = player side */
  --bf-front: rgba(255, 244, 214, 0.06); /* contested front line */
  --bf-faction: var(--gold); /* set inline from the run's faction accent */

  /* Integrated grid tints. */
  --bf-cell: rgba(255, 255, 255, 0.014);
  --bf-cell-alt: rgba(0, 0, 0, 0.08);
  --bf-line: rgba(255, 255, 255, 0.018);

  /* Neutral ground fallback (before a variant class is applied). */
  --bf-g0: #2b3327;
  --bf-g1: #354029;
  --bf-g2: #2c3a3c;

  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--board-width), minmax(42px, 1fr));
  grid-template-rows: repeat(var(--board-height), minmax(54px, 1fr));
  gap: var(--bf-gap, 3px);
  aspect-ratio: 8 / 6;
  min-height: clamp(520px, 48vw, 720px);
  border: 1px solid #11160f;
  border-radius: 10px;
  padding: var(--bf-pad, 10px);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.05),
    inset 0 3px 26px rgba(0, 0, 0, 0.5),
    var(--shadow);
  background:
    radial-gradient(150% 105% at 50% 50%, transparent 50%, var(--bf-vignette)),
    linear-gradient(180deg, var(--bf-enemy), transparent 30%),
    linear-gradient(0deg, var(--bf-player), transparent 30%),
    radial-gradient(92% 46% at 50% 104%, color-mix(in srgb, var(--bf-faction) 12%, transparent), transparent 62%),
    linear-gradient(180deg, transparent 47%, var(--bf-front) 50%, transparent 53%),
    linear-gradient(180deg, var(--bf-g1), var(--bf-g2)),
    var(--bf-g0);
}

/* Terrain detail layer, painted above the ground/atmosphere but behind cells. */
.battle-board::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  pointer-events: none;
  background: none;
}

/* A. Border Route — packed dirt, grass verges, worn stone path. */
.battlefield--route {
  --bf-g0: #2c2f22;
  --bf-g1: #3b3b29;
  --bf-g2: #34382a;
  --bf-cell: rgba(255, 245, 210, 0.004);
  --bf-cell-alt: rgba(0, 0, 0, 0);
  --bf-line: rgba(255, 245, 210, 0.014);
  --bf-gap: 0px;
  --bf-pad: 12% 9% 10%;
  aspect-ratio: 1672 / 941;
  min-height: clamp(520px, 48vw, 720px);
  border-color: rgba(21, 34, 20, 0.82);
}

.battlefield--route::before {
  background: none;
}

.battlefield-art {
  --bf-image: url("../assets/battlefields/route-field-12x8-v2.png");
  --bf-cell: rgba(255, 245, 210, 0.004);
  --bf-cell-alt: rgba(0, 0, 0, 0);
  --bf-line: rgba(255, 245, 210, 0.014);
  --bf-gap: 0px;
  --bf-pad: 12% 9% 10%;
  aspect-ratio: 1672 / 941;
  min-height: clamp(520px, 48vw, 720px);
  background:
    radial-gradient(120% 95% at 50% 50%, transparent 64%, rgba(7, 13, 9, 0.42)),
    linear-gradient(180deg, rgba(0, 0, 0, 0.12), transparent 26%, transparent 72%, rgba(0, 0, 0, 0.2)),
    var(--bf-image) center / cover no-repeat,
    linear-gradient(180deg, var(--bf-g1), var(--bf-g2)),
    var(--bf-g0);
}

.battlefield-art::before {
  background: none;
}

.battlefield-art--route-field {
  --bf-image: url("../assets/battlefields/route-field-12x8-v2.png");
}

.battlefield-art--gym-interior {
  --bf-image: url("../assets/battlefields/gym-interior-v1.png");
}

.battlefield-art--supply-depot {
  --bf-image: url("../assets/battlefields/supply-depot-v1.png");
}

.battlefield-art--volcanic-cavern {
  --bf-image: url("../assets/battlefields/volcanic-cavern-v1.png");
}

.battlefield-art--water-bastion {
  --bf-image: url("../assets/battlefields/water-bastion-v1.png");
}

/* B. Capture Field — lusher grass clumps and shallow puddles. */
.battlefield--wild {
  --bf-g0: #26341f;
  --bf-g1: #33402a;
  --bf-g2: #2b3b33;
  --bf-cell: rgba(200, 255, 190, 0.03);
  --bf-cell-alt: rgba(0, 0, 0, 0.1);
  --bf-line: rgba(200, 255, 190, 0.035);
}

.battlefield--wild::before {
  background:
    radial-gradient(70px 44px at 20% 26%, rgba(96, 156, 74, 0.2), transparent 70%),
    radial-gradient(84px 52px at 78% 66%, rgba(96, 156, 74, 0.16), transparent 70%),
    radial-gradient(60px 40px at 62% 20%, rgba(110, 168, 84, 0.14), transparent 72%),
    radial-gradient(64px 34px at 44% 58%, rgba(70, 150, 190, 0.16), transparent 72%),
    radial-gradient(48px 26px at 30% 78%, rgba(70, 150, 190, 0.12), transparent 74%);
}

/* C. Gym Front — structured stone arena, banners, faction-tinted front line. */
.battlefield--gym {
  --bf-g0: #262a30;
  --bf-g1: #363b43;
  --bf-g2: #2b3037;
  --bf-enemy: rgba(226, 116, 88, 0.18);
  --bf-player: rgba(78, 152, 220, 0.18);
  --bf-front: color-mix(in srgb, var(--bf-faction) 30%, rgba(255, 244, 214, 0.1));
  --bf-cell: rgba(210, 220, 235, 0.028);
  --bf-cell-alt: rgba(0, 0, 0, 0.12);
  --bf-line: rgba(210, 220, 235, 0.04);
}

.battlefield--gym::before {
  background:
    radial-gradient(80px 60px at 8% 2%, color-mix(in srgb, var(--bf-faction) 26%, transparent), transparent 70%),
    radial-gradient(80px 60px at 92% 2%, color-mix(in srgb, var(--bf-faction) 26%, transparent), transparent 70%),
    repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.02) 0 2px, transparent 2px 26px);
}

.battlefield-art {
  --bf-cell: rgba(255, 245, 210, 0.004);
  --bf-cell-alt: rgba(0, 0, 0, 0);
  --bf-line: rgba(255, 245, 210, 0.014);
}

.battlefield-art.battlefield--wild::before,
.battlefield-art.battlefield--gym::before {
  background: none;
}

.board-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 4px;
  background: var(--bf-cell, rgba(255, 255, 255, 0.022));
  box-shadow: inset 0 0 0 1px var(--bf-line, rgba(255, 255, 255, 0.028));
}

/* Checkerboard terrain variation instead of hard debug borders. */
.board-cell--alt {
  background: var(--bf-cell-alt, rgba(0, 0, 0, 0.08));
}

.battlefield--route .board-cell {
  border-radius: 2px;
  backdrop-filter: none;
  box-shadow:
    inset 0 0 0 1px var(--bf-line),
    inset 0 -14px 24px rgba(8, 14, 8, 0.035);
}

.battlefield--route .board-cell--occupied {
  background:
    radial-gradient(ellipse at center, rgba(255, 245, 205, 0.032), transparent 62%),
    var(--bf-cell);
}

.board-cell--enemy-front,
.board-cell--enemy-back {
  background:
    linear-gradient(180deg, rgba(198, 86, 70, 0.045), transparent 72%),
    var(--bf-cell, rgba(255, 255, 255, 0.014));
}

.board-cell--player-front,
.board-cell--player-back {
  background:
    linear-gradient(0deg, rgba(78, 152, 220, 0.045), transparent 72%),
    var(--bf-cell, rgba(255, 255, 255, 0.014));
}

.board-cell--enemy-back,
.board-cell--player-back {
  opacity: 0.96;
}

.battlefield--route .board-cell--enemy-front,
.battlefield--route .board-cell--enemy-back,
.battlefield--route .board-cell--player-front,
.battlefield--route .board-cell--player-back {
  background: var(--bf-cell);
}

.combatant {
  --ring: var(--line);
  position: absolute;
  inset: 1px;
  min-width: 0;
  border: 0;
  border-radius: 7px;
  padding: 3px;
  display: grid;
  /* sprite / bars / name, top to bottom */
  grid-template-rows: 1fr auto auto;
  align-items: center;
  justify-items: center;
  gap: 2px;
  color: var(--text);
  background: transparent;
  overflow: visible;
  will-change: transform;
}

.combatant--player {
  --ring: var(--ring-player);
}

.combatant--enemy {
  --ring: var(--ring-enemy);
}

.combatant--flash .combatant-token {
  box-shadow: 0 0 0 2.5px var(--gold), 0 0 14px color-mix(in srgb, var(--unit-color) 75%, transparent);
}

.combatant--hit .combatant-token {
  filter: brightness(1.4);
}

/* Impact polish (cosmetic only; does not touch damage timing). */
.combatant--hit {
  animation: combatant-hit-shake 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.combatant--hit .combatant-sprite {
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.55)) brightness(1.7);
}

.combatant--flash .combatant-sprite {
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.55))
    drop-shadow(0 0 4px color-mix(in srgb, var(--gold) 80%, transparent));
}

@keyframes combatant-hit-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-2px); }
  50% { transform: translateX(2px); }
  80% { transform: translateX(-1px); }
}

.combatant--moving {
  z-index: 5;
  animation: combatant-move 300ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.combatant--action-attack:not(.combatant--hit),
.combatant--action-special:not(.combatant--hit) {
  z-index: 6;
  animation: combatant-lunge 430ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.combatant--action-shoot:not(.combatant--hit) {
  z-index: 6;
  animation: combatant-recoil 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.combatant--action-special .combatant-sprite {
  filter:
    drop-shadow(0 2px 2px rgba(0, 0, 0, 0.55))
    drop-shadow(0 0 7px color-mix(in srgb, var(--unit-color) 85%, white));
}

.combatant--fainting {
  pointer-events: none;
  animation: combatant-faint 760ms cubic-bezier(0.32, 0, 0.67, 0) both;
}

@keyframes combatant-move {
  from { transform: translate(var(--move-x), var(--move-y)); }
  to { transform: translate(0, 0); }
}

@keyframes combatant-lunge {
  0%, 100% { transform: translate(0, 0); }
  46% { transform: translate(var(--action-x), var(--action-y)) scale(1.08); }
}

@keyframes combatant-recoil {
  0%, 100% { transform: translate(0, 0); }
  32% { transform: translate(var(--recoil-x), var(--recoil-y)) scale(0.96); }
  58% { transform: translate(2%, 2%) scale(1.04); }
}

@keyframes combatant-faint {
  0% { opacity: 1; filter: saturate(1); transform: translateY(0) scale(1); }
  45% { opacity: 0.8; filter: saturate(0) brightness(1.8); transform: translateY(-4px) scale(1.08); }
  100% { opacity: 0; filter: saturate(0); transform: translateY(14px) scale(0.72); }
}

.combatant-bars {
  position: relative;
  z-index: 4;
  width: clamp(26px, 88%, 46px);
  margin-top: 6px; /* drop below the sprite's feet so it stops clipping */
  display: grid;
  gap: 1px;
  padding: 1px;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.22);
  opacity: 0.8;
}

/* Empty spacer keeping the combatant's 3-row grid when a body sprite replaces
   the initials token. */
.combatant-mid {
  min-height: 0;
}

/* Tactical base ring under a sprite: a flattened, team-colored ground disc. */
.combatant-base {
  position: absolute;
  left: 50%;
  top: 76%;
  transform: translate(-50%, -50%);
  width: 58%;
  height: 22%;
  border-radius: 50%;
  background: radial-gradient(
    ellipse at center,
    color-mix(in srgb, var(--ring) 28%, transparent) 0%,
    color-mix(in srgb, var(--ring) 16%, transparent) 55%,
    transparent 74%
  );
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--ring) 38%, transparent);
  pointer-events: none;
  z-index: 0;
}

.combatant--enemy:hover .combatant-base {
  background: radial-gradient(
    ellipse at center,
    color-mix(in srgb, var(--ring) 60%, transparent) 0%,
    color-mix(in srgb, var(--ring) 34%, transparent) 55%,
    transparent 74%
  );
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ring) 70%, transparent);
}

.combatant-token {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #101318;
  background: var(--unit-color);
  font-size: 0.7rem;
  box-shadow: 0 0 0 2.5px var(--ring), 0 2px 4px rgba(0, 0, 0, 0.35);
}

.combatant-name {
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.7rem;
  font-weight: 800;
  text-align: center;
  opacity: 0;
  transform: translateY(3px);
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
  transition: opacity 140ms ease, transform 140ms ease;
}

.combatant:hover .combatant-name,
.combatant:focus-visible .combatant-name {
  opacity: 1;
  transform: translateY(0);
}

.damage-pop {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 13%;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 950;
  text-shadow: 0 1px 2px #000, 0 0 5px #000;
  pointer-events: none;
  animation: damage-pop-rise 650ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.damage-pop--effective {
  color: #ffe072;
  font-size: 0.9rem;
}

.damage-pop--resisted {
  color: #a8c7df;
}

@keyframes damage-pop-rise {
  from { opacity: 0; transform: translate(-50%, 8px) scale(0.78); }
  22% { opacity: 1; transform: translate(-50%, 0) scale(1.12); }
  to { opacity: 0; transform: translate(-50%, -24px) scale(0.96); }
}

.combatant-reticle {
  position: absolute;
  inset: 0;
  pointer-events: none;
  --c: var(--gold);
  --t: 2px;
  --l: 7px;
  background:
    linear-gradient(var(--c), var(--c)) 0 0 / var(--l) var(--t),
    linear-gradient(var(--c), var(--c)) 0 0 / var(--t) var(--l),
    linear-gradient(var(--c), var(--c)) 100% 0 / var(--l) var(--t),
    linear-gradient(var(--c), var(--c)) 100% 0 / var(--t) var(--l),
    linear-gradient(var(--c), var(--c)) 0 100% / var(--l) var(--t),
    linear-gradient(var(--c), var(--c)) 0 100% / var(--t) var(--l),
    linear-gradient(var(--c), var(--c)) 100% 100% / var(--l) var(--t),
    linear-gradient(var(--c), var(--c)) 100% 100% / var(--t) var(--l);
  background-repeat: no-repeat;
  animation: reticle-pulse 1s ease-in-out infinite;
}

@keyframes reticle-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.health-bar,
.charge-bar {
  height: 2.5px;
  border-radius: 999px;
}

.health-bar span {
  background: var(--ok);
}

/* Enemy HP reads as a soft red: clearly hostile at a glance without
   competing with the battlefield art. */
.combatant--enemy .health-bar span {
  background: color-mix(in srgb, var(--danger) 80%, white 12%);
}

.charge-bar span {
  background: var(--gold);
}

/* Imported SpriteCollab art: portraits over initials tokens, and body sprites
   on the board. Both fall back to the initials token if assets are missing. */
.portrait-slot,
.unit-token {
  position: relative;
}

.pf-portrait {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  border-radius: inherit;
}

.combatant-sprite {
  position: absolute;
  left: 50%;
  top: 57%;
  transform-origin: center;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 2;
  /* Soft contact shadow follows the sprite silhouette for grounding. */
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.55));
}

.combatant-reticle {
  z-index: 3;
}

/* ---- Shiny Pokemon ---- */
/* On the board: a golden aura on the sprite plus a twinkling star. The star's
   animation-delay is set inline from battle time so its phase survives the
   per-tick board re-render. */
.combatant--shiny .combatant-sprite {
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.55))
    drop-shadow(0 0 4px rgba(255, 214, 92, 0.85))
    drop-shadow(0 0 10px rgba(255, 186, 40, 0.4));
}

.combatant--shiny .combatant-token {
  box-shadow: 0 0 0 2px rgba(255, 214, 92, 0.85), 0 0 12px rgba(255, 186, 40, 0.55);
}

.combatant-shine {
  position: absolute;
  top: -4px;
  right: 4px;
  z-index: 4;
  font-size: 13px;
  line-height: 1;
  color: #ffd95c;
  text-shadow: 0 0 5px rgba(255, 200, 60, 0.9);
  pointer-events: none;
  animation: shiny-twinkle 1.6s ease-in-out infinite;
}

@keyframes shiny-twinkle {
  0%, 100% { opacity: 0.25; transform: scale(0.7) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.15) rotate(45deg); }
}

/* On cards and party rows: gold ring on the token, star beside the name. */
.unit-token--shiny {
  box-shadow: 0 0 0 2px rgba(255, 214, 92, 0.9), 0 0 10px rgba(255, 186, 40, 0.5);
}

.unit-card--shiny {
  border-color: color-mix(in srgb, #ffd95c 45%, var(--line));
}

.shiny-star {
  display: inline-block;
  margin-left: 4px;
  color: #ffd95c;
  text-shadow: 0 0 5px rgba(255, 200, 60, 0.85);
  animation: shiny-twinkle 1.6s ease-in-out infinite;
}

/* Ace tag on the party leader / top enemy. */
.ace-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--gold) 82%, #1a130a);
  color: #201603;
  font-size: 0.58rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  vertical-align: middle;
}

.active-party__unit--ace {
  border-color: color-mix(in srgb, var(--gold) 55%, var(--line));
}

/* Timer readout, styled like a HUD clock. */
.clock-chip {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: var(--gold);
  border-color: color-mix(in srgb, var(--gold) 45%, var(--line));
  background: rgba(0, 0, 0, 0.3);
}

/* Combat feed, styled like a HUD event log rather than a bordered textbox. */
/* Team status widget: HP/SP bars migrated off the board sprites (they clipped)
   into a compact roster above the battle log. Enemy row on top, squad below. */
.team-status {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0 0;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0.16));
}

.team-status__row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

.team-status__tag {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.team-status__row--enemy .team-status__tag {
  color: color-mix(in srgb, var(--danger) 78%, white 14%);
}

.team-status__row--player .team-status__tag {
  color: color-mix(in srgb, var(--ok) 80%, white 10%);
}

.team-status__boxes {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.team-status__empty {
  color: var(--muted);
  opacity: 0.6;
}

.team-box {
  flex: 1 1 74px;
  min-width: 62px;
  max-width: 116px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 3px 5px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.team-box--ace {
  border-color: color-mix(in srgb, var(--gold) 55%, transparent);
  background: color-mix(in srgb, var(--gold) 10%, rgba(255, 255, 255, 0.04));
}

.team-box--down {
  opacity: 0.4;
  filter: grayscale(0.7);
}

.team-box__name {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.team-box__bar {
  height: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.4);
  overflow: hidden;
}

.team-box__bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width 0.2s ease;
}

.team-box__bar--hp span {
  background: var(--ok);
}

.team-status__row--enemy .team-box__bar--hp span {
  background: color-mix(in srgb, var(--danger) 80%, white 12%);
}

.team-box__bar--sp span {
  background: var(--gold);
}

.battle-log {
  min-height: 110px;
  margin: 10px 0;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0.16)),
    linear-gradient(90deg, color-mix(in srgb, var(--gold) 10%, transparent), transparent 34%);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.3;
}

.battle-log div {
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.battle-log div:first-child {
  color: var(--text);
  font-weight: 700;
}

.command-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

#focusButton {
  --cmd: var(--ring-player);
}

#rallyButton {
  --cmd: var(--gold);
}

#potionButton {
  --cmd: var(--ok);
}

.command-button {
  border: 1px solid color-mix(in srgb, var(--cmd, var(--line)) 55%, var(--line));
  border-bottom: 3px solid var(--cmd, var(--line));
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.82rem;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--cmd, var(--line)) 20%, transparent), transparent 70%),
    var(--panel-strong);
}

.command-button,
.reward-card button {
  min-height: 44px;
  border-radius: 8px;
  font-weight: 900;
}

.command-button:disabled,
.reward-card button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.return-button {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
  border-radius: 7px;
  font-weight: 900;
  color: var(--text);
  border: 1px solid var(--gold);
  background: color-mix(in srgb, var(--gold) 22%, var(--panel));
  transition: transform 150ms ease, background 150ms ease;
}

.return-button:hover {
  transform: translateY(-1px);
  background: color-mix(in srgb, var(--gold) 32%, var(--panel));
}

.reward-card {
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
}

.reward-card--item {
  border-color: color-mix(in srgb, var(--gold) 36%, var(--line));
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--gold) 13%, transparent), transparent 50%),
    rgba(255, 255, 255, 0.045);
}

.reward-card div:nth-child(2) {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.reward-card span {
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reward-card button {
  padding: 0 10px;
  background: color-mix(in srgb, var(--unit-color) 24%, var(--panel));
}

/* Full-screen campaign ceremonies: draft, operations, promotions, insignias. */
.story-panel {
  min-width: 0;
}

.story-scene {
  position: relative;
  min-height: clamp(560px, 72vh, 760px);
  overflow: hidden;
  border: 1px solid rgba(235, 226, 196, 0.24);
  border-radius: 10px;
  background: #10161c;
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.28);
}

.story-scene__backdrop {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(6, 10, 14, 0.12), rgba(6, 10, 14, 0.34) 50%, rgba(6, 10, 14, 0.92)),
    linear-gradient(90deg, rgba(6, 10, 14, 0.58), transparent 34% 66%, rgba(6, 10, 14, 0.58)),
    var(--story-background) center / cover no-repeat;
  filter: saturate(0.9) contrast(1.04);
  animation: story-scene-focus 700ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.story-scene__stage {
  position: relative;
  z-index: 1;
  min-height: inherit;
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(340px, 1.4fr) minmax(120px, 0.8fr);
  grid-template-rows: 1fr auto;
  align-items: end;
  gap: 16px;
  padding: 28px clamp(18px, 4vw, 54px) 24px;
}

.story-focus {
  align-self: end;
  display: grid;
  justify-items: center;
  gap: 10px;
  min-width: 0;
  padding: 22px 18px 18px;
  text-align: center;
  background: linear-gradient(180deg, transparent, rgba(8, 12, 17, 0.78) 28%);
}

.story-kicker {
  margin: 0;
  color: #f0cf75;
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.story-focus h2 {
  max-width: 20ch;
  margin: 0;
  font-size: clamp(1.75rem, 3vw, 2.8rem);
  line-height: 1.02;
  letter-spacing: 0;
  text-wrap: balance;
}

.story-focus > p:not(.story-kicker) {
  max-width: 64ch;
  margin: 0;
  color: #e0e5ec;
  line-height: 1.55;
  text-wrap: pretty;
}

.story-character {
  display: grid;
  align-content: end;
  justify-items: center;
  min-width: 0;
  color: #f7f2e8;
  font-weight: 900;
  text-shadow: 0 2px 4px #000;
}

.story-character__sprite {
  width: min(220px, 22vw);
  height: min(330px, 38vh);
  object-fit: contain;
  object-position: center bottom;
  image-rendering: pixelated;
  filter: drop-shadow(0 8px 5px rgba(0, 0, 0, 0.62));
  animation: story-character-enter 420ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.story-character--player .story-character__sprite {
  transform: scaleX(-1);
  animation-name: story-character-enter-player;
}

.story-character span {
  margin-top: -8px;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  background: rgba(5, 8, 12, 0.74);
  font-size: 0.8rem;
}

.story-insignia {
  width: clamp(108px, 13vw, 178px);
  aspect-ratio: 1;
  object-fit: contain;
  filter: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.5));
  animation: insignia-award 650ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.story-choices {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.story-choices button {
  min-width: 0;
  min-height: 128px;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 13px;
  border: 1px solid rgba(230, 220, 190, 0.28);
  border-radius: 8px;
  color: var(--text);
  background: rgba(16, 22, 29, 0.9);
  text-align: left;
  transition: transform 170ms ease, border-color 170ms ease, background 170ms ease;
}

.story-choices button:hover,
.story-choices button:focus-visible {
  border-color: var(--gold);
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  background: rgba(31, 39, 48, 0.96);
  transform: translateY(-2px);
}

.story-choices span {
  color: #c8d0dc;
  font-size: 0.78rem;
  line-height: 1.4;
}

.story-choices small {
  align-self: end;
  color: var(--gold);
  font-weight: 900;
}

.story-continue {
  min-height: 44px;
  padding: 8px 18px;
  border: 1px solid var(--gold);
  border-radius: 7px;
  color: #12151b;
  background: var(--gold);
  font-weight: 900;
}

.story-progress {
  grid-column: 1 / -1;
  display: flex;
  justify-content: center;
  gap: 6px;
}

.story-progress span {
  width: 28px;
  height: 3px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.25);
}

.story-progress .is-active {
  background: var(--gold);
}

.story-progress .is-complete {
  background: rgba(105, 189, 117, 0.85);
}

@keyframes story-scene-focus {
  from { opacity: 0.6; filter: saturate(0.55) contrast(0.9) blur(4px); transform: scale(1.025); }
  to { opacity: 1; filter: saturate(0.9) contrast(1.04) blur(0); transform: scale(1); }
}

@keyframes story-character-enter {
  from { opacity: 0; transform: translateX(26px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes story-character-enter-player {
  from { opacity: 0; transform: translateX(-26px) scaleX(-1); }
  to { opacity: 1; transform: translateX(0) scaleX(-1); }
}

@keyframes insignia-award {
  from { opacity: 0; transform: translateY(16px) scale(0.72); filter: brightness(2) drop-shadow(0 8px 8px rgba(0, 0, 0, 0.5)); }
  to { opacity: 1; transform: translateY(0) scale(1); filter: brightness(1) drop-shadow(0 8px 8px rgba(0, 0, 0, 0.5)); }
}

/* Capture scene + panel (wild-battle ball capture minigame). */
/* ---- Evolution & trade cinematics ----
   Full-screen scenes that reuse the animated body-sprite pipeline. Shared shell
   first, then the per-scene animation. */
.scene-view {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
}

.scene-panel {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(28, 34, 43, 0.94);
  box-shadow: var(--shadow);
}

.scene-body {
  min-height: 420px;
}

.scene-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.scene-stage > .eyebrow {
  align-self: center;
  letter-spacing: 0.14em;
  color: color-mix(in srgb, var(--unit-color) 70%, var(--muted));
}

.scene-field {
  position: relative;
  width: 100%;
  min-height: 340px;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--unit-color) 30%, var(--line));
  border-radius: 10px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 56%, color-mix(in srgb, var(--unit-color) 26%, transparent), transparent 30%),
    linear-gradient(180deg, rgba(8, 12, 20, 0.35), rgba(6, 9, 16, 0.72)),
    url("../assets/battlefields/route-field-12x8-v2.png") center / cover no-repeat;
}

.scene-field::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 84% at 50% 50%, transparent 50%, rgba(3, 6, 12, 0.66));
}

.scene-shadow {
  position: absolute;
  left: 50%;
  bottom: 24%;
  width: 118px;
  height: 24px;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.5), transparent);
  z-index: 1;
}

.scene-sprite {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center bottom;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  z-index: 2;
  filter: drop-shadow(0 6px 3px rgba(0, 0, 0, 0.6));
}

.scene-sprite--fallback {
  width: 96px;
  height: 96px;
  transform: translate(-50%, -50%);
  border: 3px solid color-mix(in srgb, var(--unit-color) 62%, white 12%);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #11151b;
  background: var(--unit-color);
  font-weight: 950;
  font-size: 1.4rem;
}

.scene-sprite--fallback .pf-portrait {
  object-fit: contain;
  padding: 8px;
}

.scene-caption {
  font-size: 1.02rem;
  color: var(--text);
  max-width: 34ch;
}

.scene-caption strong {
  color: color-mix(in srgb, var(--unit-color) 66%, white 24%);
}

.scene-skip {
  align-self: center;
  padding: 5px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  cursor: pointer;
}

.scene-skip:hover {
  color: var(--text);
  border-color: var(--gold);
}

.scene-shine {
  position: absolute;
  left: 62%;
  top: 30%;
  z-index: 3;
  font-size: 1.5rem;
  color: #fff6c8;
  text-shadow: 0 0 8px var(--gold);
  animation: scene-shine-twinkle 1.4s ease-in-out infinite;
}

@keyframes scene-shine-twinkle {
  0%, 100% { opacity: 0.2; transform: scale(0.7) rotate(0deg); }
  50% { opacity: 1; transform: scale(1.15) rotate(20deg); }
}

/* --- Evolution --- */
.evo-pokemon {
  position: relative;
  width: 210px;
  height: 220px;
  display: grid;
  place-items: center;
  z-index: 2;
}

/* Each form sits in its own slot. Animations run on the SLOT (opacity/scale)
   so the sprite keeps the pixel-scaling transform bodyFrameHtml gave it. */
.evo-slot {
  position: absolute;
  inset: 0;
  transform-origin: 50% 58%;
}

.scene-flash {
  position: absolute;
  inset: -20% -10%;
  z-index: 4;
  pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0) 62%);
  opacity: 0;
}

/* Evolving: the two forms flicker back and forth at an accelerating cadence
   while a white glow pulses; the reveal bursts to white and settles. */
.evo-stage--evolving .evo-slot--from { animation: evo-flicker-from 2.6s linear both; }
.evo-stage--evolving .evo-slot--to { animation: evo-flicker-to 2.6s linear both; }
.evo-stage--evolving .scene-flash { animation: evo-glow 2.6s ease-in both; }

.evo-stage--done .evo-slot--from { opacity: 0; }
.evo-stage--done .evo-slot--to { animation: evo-slot-reveal 620ms cubic-bezier(0.22, 1, 0.36, 1) both; }
.evo-stage--done .scene-flash { animation: evo-burst 720ms ease-out both; }

@keyframes evo-glow {
  0% { opacity: 0; }
  70% { opacity: 0.28; }
  100% { opacity: 0.5; }
}

@keyframes evo-burst {
  0% { opacity: 0.95; }
  100% { opacity: 0; }
}

/* Container reveal (translate form) for trade slots whose base transform is
   translate(-50%,-50%). */
@keyframes evo-reveal {
  0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0.2; }
  60% { transform: translate(-50%, -50%) scale(1.08); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Slot reveal (no translate) for the evolution slots, which fill their parent
   via inset:0 and scale from transform-origin. The flicker keyframes touch
   opacity alone so the sprite's pixel scaling is preserved. */
@keyframes evo-slot-reveal {
  0% { transform: scale(0.6); opacity: 0.2; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes evo-flicker-from {
  0%, 8% { opacity: 1; }
  12% { opacity: 0; } 15% { opacity: 1; }
  26% { opacity: 0; } 30% { opacity: 1; }
  42% { opacity: 0; } 46% { opacity: 1; }
  56% { opacity: 0; } 59% { opacity: 1; }
  67% { opacity: 0; } 70% { opacity: 1; }
  76% { opacity: 0; } 79% { opacity: 1; }
  84% { opacity: 0; } 86% { opacity: 1; }
  90% { opacity: 0; } 92% { opacity: 1; }
  96% { opacity: 0; } 100% { opacity: 0; }
}

@keyframes evo-flicker-to {
  0%, 8% { opacity: 0; }
  12% { opacity: 1; } 15% { opacity: 0; }
  26% { opacity: 1; } 30% { opacity: 0; }
  42% { opacity: 1; } 46% { opacity: 0; }
  56% { opacity: 1; } 59% { opacity: 0; }
  67% { opacity: 1; } 70% { opacity: 0; }
  76% { opacity: 1; } 79% { opacity: 0; }
  84% { opacity: 1; } 86% { opacity: 0; }
  90% { opacity: 1; } 92% { opacity: 0; }
  96% { opacity: 1; } 100% { opacity: 1; }
}

/* --- Trade --- */
.trade-field .trade-pokemon {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 180px;
  height: 200px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  z-index: 2;
}

.trade-pokemon.is-gone { opacity: 0; }
.trade-pokemon--in { opacity: 0; }
.trade-pokemon--in.is-here { opacity: 1; }

.trade-stage--sending .trade-pokemon--out { animation: trade-depart 1.5s cubic-bezier(0.5, 0, 0.75, 0) both; }
.trade-stage--arriving .trade-pokemon--in { animation: trade-arrive 1.4s cubic-bezier(0.22, 1, 0.36, 1) both; }
.trade-stage--done .trade-pokemon--in { animation: evo-reveal 600ms cubic-bezier(0.22, 1, 0.36, 1) both; }

@keyframes trade-depart {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  55% { transform: translate(-50%, -50%) scale(0.2); opacity: 0.85; }
  100% { transform: translate(-50%, -140%) scale(0.08); opacity: 0; }
}

@keyframes trade-arrive {
  0% { transform: translate(-50%, -160%) scale(0.08); opacity: 0; }
  50% { transform: translate(-50%, -50%) scale(0.2); opacity: 0.9; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.trade-ball {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 34px;
  height: 34px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  z-index: 3;
  background:
    linear-gradient(#e5484d 0 calc(50% - 2px), #14181d calc(50% - 2px) calc(50% + 2px), #f4f4f5 calc(50% + 2px) 100%);
  border: 2px solid #14181d;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45);
}

.trade-ball::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 9px;
  height: 9px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #f4f4f5;
  border: 2px solid #14181d;
}

.trade-stage--done .trade-ball { display: none; }
.trade-stage--sending .trade-ball { animation: trade-ball-send 1.5s ease-in both; }
.trade-stage--arriving .trade-ball { animation: trade-ball-recv 1.4s ease-out both; }

@keyframes trade-ball-send {
  0%, 45% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  60% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -260%) scale(0.7); }
}

@keyframes trade-ball-recv {
  0% { opacity: 0; transform: translate(-50%, -260%) scale(0.7); }
  35% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.4); }
}

@media (prefers-reduced-motion: reduce) {
  .evo-stage--evolving .evo-slot--from,
  .evo-stage--evolving .evo-slot--to,
  .evo-stage--evolving .scene-flash,
  .evo-stage--done .evo-slot--to,
  .trade-stage--sending .trade-pokemon--out,
  .trade-stage--arriving .trade-pokemon--in,
  .trade-stage--done .trade-pokemon--in,
  .trade-stage--sending .trade-ball,
  .trade-stage--arriving .trade-ball {
    animation-duration: 1ms !important;
  }
}

/* War Realism reinforcement pick + Hall of Fame memorial (share the scene shell). */
.reinforce-stage,
.hall-stage {
  gap: 12px;
}

.reinforce-fallen {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 460px;
  padding: 10px 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 34%, var(--line));
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--danger) 8%, var(--panel));
  text-align: left;
}

.reinforce-fallen strong { display: block; }
.reinforce-fallen span { display: block; margin-top: 3px; color: var(--muted); font-size: 0.84rem; }

.reinforce-fallen__token,
.hall-unit__token {
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--unit-color, #2a3038);
  color: #11151b;
  font-weight: 900;
  overflow: hidden;
  position: relative;
}

.reinforce-fallen__token .pf-portrait,
.hall-unit__token .pf-portrait {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.reinforce-offers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 620px;
}

.reinforce-offer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, transform 120ms ease;
}

.reinforce-offer:hover {
  border-color: var(--unit-color);
  background: color-mix(in srgb, var(--unit-color) 12%, var(--panel));
  transform: translateY(-2px);
}

.reinforce-offer__token {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--unit-color);
  color: #11151b;
  font-weight: 900;
  overflow: hidden;
  position: relative;
}

.reinforce-offer__token .pf-portrait {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.reinforce-offer__id strong { display: block; }
.reinforce-offer__id small { color: var(--muted); font-size: 0.76rem; }

.hall-title {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.02em;
}

.hall-roll {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 680px;
  margin: 6px 0;
}

.hall-unit {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  border: 1px solid color-mix(in srgb, var(--unit-color) 30%, var(--line));
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--unit-color) 8%, var(--panel));
  text-align: center;
}

.hall-unit strong { font-size: 0.9rem; }
.hall-unit small { color: var(--muted); font-size: 0.72rem; }

.trainer-card__hall {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.capture-scene {
  min-height: 360px;
}

.capture-stage {
  display: grid;
  grid-template-columns: minmax(180px, 0.9fr) minmax(260px, 1.1fr);
  grid-template-areas:
    "target field"
    "panel field";
  gap: 12px;
}

.capture-stage__target,
.capture-stage__panel,
.capture-stage__field {
  min-width: 0;
  border: 1px solid color-mix(in srgb, var(--unit-color) 28%, var(--line));
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
}

.capture-stage__target {
  grid-area: target;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.capture-stage__target strong {
  display: block;
  font-size: 1.1rem;
}

.capture-stage__target span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 3px;
}

.capture-stage__panel {
  grid-area: panel;
  padding: 12px;
}

.capture-stage__field {
  grid-area: field;
  position: relative;
  min-height: 360px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 58%, color-mix(in srgb, var(--unit-color) 18%, transparent), transparent 24%),
    linear-gradient(180deg, rgba(10, 18, 16, 0.05), rgba(10, 18, 16, 0.3)),
    url("../assets/battlefields/route-field-12x8-v2.png") center / cover no-repeat;
}

.capture-stage__field::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(110% 80% at 50% 52%, transparent 54%, rgba(5, 10, 9, 0.5));
  opacity: 1;
}

.capture-stage__pokemon {
  position: relative;
  z-index: 2;
  width: 170px;
  height: 190px;
  display: grid;
  place-items: center;
}

.capture-pokemon-sprite {
  position: absolute;
  left: 50%;
  top: 48%;
  transform-origin: center bottom;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  filter: drop-shadow(0 6px 3px rgba(0, 0, 0, 0.62));
}

.capture-stage__pokemon--capturing {
  animation: pokemon-captured 1080ms cubic-bezier(0.32, 0, 0.67, 0) both;
}

.capture-stage__pokemon--breaking-out {
  animation: pokemon-breakout 820ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.capture-stage__pokemon--caught {
  opacity: 0;
  transform: scale(0.14);
}

.capture-stage__pokemon--escaped {
  animation: pokemon-escape 420ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.capture-stage__sprite {
  position: relative;
  z-index: 1;
  width: 94px;
  height: 94px;
  border: 3px solid color-mix(in srgb, var(--unit-color) 62%, white 12%);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #11151b;
  background: var(--unit-color);
  font-weight: 950;
  font-size: 1.5rem;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
}

.capture-stage__sprite .pf-portrait {
  object-fit: contain;
  padding: 8px;
}

.capture-stage__shadow {
  position: absolute;
  width: 128px;
  height: 28px;
  left: 50%;
  top: calc(50% + 66px);
  transform: translateX(-50%);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.32);
  filter: blur(3px);
}

.capture-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.capture-head-info {
  min-width: 0;
}

.capture-head-info strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.capture-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.capture-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.capture-bonus {
  color: var(--gold);
  font-weight: 800;
}

.capture-balls {
  display: grid;
  gap: 6px;
}

.capture-ball {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
  transition: border-color 150ms ease, transform 150ms ease;
}

.capture-ball:not(:disabled):hover {
  border-color: var(--gold);
  transform: translateY(-1px);
}

.capture-ball:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.capture-ball-name {
  font-weight: 800;
}

.capture-ball-chance {
  color: var(--gold);
  font-weight: 900;
}

.capture-ball-count {
  color: var(--muted);
  font-size: 0.78rem;
}

.capture-anim {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 14px 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.capture-anim--status strong {
  color: var(--text);
}

.capture-throw {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.capture-throw .ball-anim {
  position: absolute;
  left: 12%;
  top: 74%;
  transform: translate(-50%, -50%) scale(1.25);
  filter: drop-shadow(0 5px 3px rgba(0, 0, 0, 0.45));
}

.capture-throw .ball-anim--success {
  animation:
    ball-arc-success 1080ms cubic-bezier(0.22, 1, 0.36, 1) both,
    ball-success 1000ms steps(15) forwards;
}

.capture-throw .ball-anim--breakout {
  animation:
    ball-arc-breakout 820ms cubic-bezier(0.22, 1, 0.36, 1) both,
    ball-breakout 700ms steps(10) forwards;
}

.ball-anim {
  width: 64px;
  height: 64px;
  background-repeat: no-repeat;
  background-size: 64px auto;
  transform: scale(1.35);
  transform-origin: center;
}

.ball-anim--success {
  animation: ball-success 1s steps(15) forwards;
}

.ball-anim--breakout {
  animation: ball-breakout 0.7s steps(10) forwards;
}

@keyframes ball-success {
  from { background-position-y: 0; }
  to { background-position-y: -960px; }
}

@keyframes ball-breakout {
  from { background-position-y: 0; }
  to { background-position-y: -640px; }
}

@keyframes ball-arc-success {
  0% { left: 12%; top: 78%; transform: translate(-50%, -50%) scale(0.9) rotate(-24deg); }
  34% { left: 50%; top: 47%; transform: translate(-50%, -50%) scale(1.35) rotate(12deg); }
  100% { left: 50%; top: 58%; transform: translate(-50%, -50%) scale(1.35) rotate(0); }
}

@keyframes ball-arc-breakout {
  0% { left: 12%; top: 78%; transform: translate(-50%, -50%) scale(0.9) rotate(-24deg); }
  42% { left: 50%; top: 47%; transform: translate(-50%, -50%) scale(1.35) rotate(12deg); }
  100% { left: 50%; top: 55%; transform: translate(-50%, -50%) scale(1.35) rotate(0); }
}

@keyframes pokemon-captured {
  0%, 30% { opacity: 1; transform: scale(1); filter: brightness(1); }
  48% { opacity: 0.8; transform: scale(0.72); filter: brightness(2); }
  58%, 100% { opacity: 0; transform: scale(0.14); filter: brightness(3); }
}

@keyframes pokemon-breakout {
  0%, 36% { opacity: 1; transform: scale(1); filter: brightness(1); }
  48% { opacity: 0.3; transform: scale(0.82); filter: brightness(2.4); }
  64% { opacity: 1; transform: scale(1.12); filter: brightness(1.5); }
  100% { opacity: 1; transform: scale(1); filter: brightness(1); }
}

@keyframes pokemon-escape {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(64px); }
}

@media (prefers-reduced-motion: reduce) {
  /* Enter-style and flash animations jump to their settled state. */
  .ball-anim--success,
  .ball-anim--breakout,
  .capture-stage__pokemon--capturing,
  .capture-stage__pokemon--breaking-out,
  .capture-stage__pokemon--escaped,
  .combatant--moving,
  .combatant--action-attack,
  .combatant--action-shoot,
  .combatant--action-special,
  .combatant--hit,
  .combatant--fainting,
  .vfx-slash,
  .vfx-hit,
  .vfx--fade,
  .story-scene__backdrop,
  .story-character__sprite,
  .story-insignia {
    animation-duration: 1ms;
    animation-iteration-count: 1;
  }

  /* Informational overlays must stay READABLE: their exit animations end
     hidden, so clamping to 1ms would erase them instantly. Their lifetime
     is owned by the game clock in JS, not by the animation. */
  .battle-intro {
    animation: none;
    opacity: 1;
  }

  .damage-pop {
    animation: none;
    opacity: 1;
    transform: none;
  }

  /* Infinite decorative pulse: hold a steady frame instead. */
  .combatant-reticle {
    animation: none;
  }
}

.capture-hint {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.capture-result {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.045);
  font-size: 0.84rem;
}

.capture-result span {
  color: var(--muted);
  font-size: 0.8rem;
}

.capture-result--ok {
  border-color: color-mix(in srgb, var(--ok) 60%, var(--line));
  background: color-mix(in srgb, var(--ok) 16%, transparent);
}

.capture-result--ended {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.capture-flute {
  display: grid;
  gap: 8px;
  font-size: 0.84rem;
}

.capture-flute p {
  margin: 0;
  color: var(--muted);
}

.capture-flute-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.capture-flute-actions button {
  min-height: 38px;
  border-radius: 7px;
  font-weight: 800;
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
}

.capture-flute-actions button[data-flute="accept"] {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 22%, var(--panel));
}

.muted {
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  background: #1a2029;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast--visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1000px) {
  .route-view {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  /* Route map: three nodes per row share a narrow phone width, so the 104px
     node/label footprint made neighbouring names collide (and their tap
     targets overlap). Shrink the node, label width, and font so each stays
     inside its ~1/4-graph column with clear air between choices. */
  /* Node footprint must stay inside its ~1/4-graph column (pitch tracks the
     viewport), so size it in vw and cap it on wider phones. */
  .route-node {
    width: 18vw;
    max-width: 96px;
    gap: 3px;
  }

  .route-node__disc {
    width: 44px;
    height: 44px;
  }

  .route-node--boss .route-node__disc {
    width: 56px;
    height: 56px;
  }

  .route-node__sprite {
    width: 34px;
    height: 34px;
  }

  .route-node--boss .route-node__sprite {
    width: 44px;
    height: 44px;
  }

  .route-node__label {
    max-width: 17vw;
    font-size: 0.6rem;
    line-height: 1.15;
  }

  .battle-intro__reinforcement {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 10px;
  }

  .battle-intro__xl-label {
    grid-column: 1 / -1;
  }

  .battle-intro__muso-portrait,
  .battle-intro__muso-trainer {
    width: 56px;
    height: 74px;
  }

  .battle-intro__muso small {
    display: none;
  }

  .battle-intro__partners > span {
    width: 48px;
  }

  .battle-intro__partners img {
    width: 46px;
    height: 46px;
  }
}

@media (max-width: 1240px) {
  .faction-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 12px;
  }

  .campaign-view {
    flex-direction: column;
  }

  .command-panel {
    flex: 1 1 auto;
    width: 100%;
  }

  .battle-view {
    max-width: none;
  }

  .story-view {
    max-width: none;
  }

  .capture-view {
    max-width: none;
  }

  .setup-view {
    min-height: auto;
    justify-content: flex-start;
    padding: 16px 10px;
  }

  .faction-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .setup-copy {
    padding: 18px 8px;
  }

  .setup-copy h2 {
    font-size: 1.9rem;
  }

  .continue-card {
    grid-template-columns: 1fr;
  }

  .continue-card__actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .narrative-panel {
    grid-template-columns: 1fr;
  }

  .narrative-panel button {
    width: 100%;
  }

  .active-party__list {
    grid-template-columns: minmax(0, 1fr);
  }

  .capture-stage {
    grid-template-columns: 1fr;
    grid-template-areas:
      "target"
      "field"
      "panel";
  }

  .capture-stage__field {
    min-height: 260px;
  }

  .story-scene {
    min-height: 620px;
  }

  .story-scene__stage {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: 180px auto auto;
    align-items: end;
    gap: 8px;
    padding: 16px 10px 14px;
  }

  .story-character--player {
    grid-column: 1;
    grid-row: 1;
  }

  .story-character--speaker {
    grid-column: 2;
    grid-row: 1;
  }

  .story-character__sprite {
    width: 128px;
    height: 160px;
  }

  .story-focus {
    grid-column: 1 / -1;
    grid-row: 2;
    padding: 18px 8px 10px;
  }

  .story-focus h2 {
    font-size: 1.7rem;
  }

  .story-choices {
    grid-template-columns: 1fr;
  }

  .story-choices button {
    min-height: 92px;
  }

  .story-progress {
    grid-row: 3;
  }

  .battle-board {
    min-height: 280px;
    grid-template-columns: repeat(var(--board-width), minmax(24px, 1fr));
    grid-template-rows: repeat(var(--board-height), minmax(34px, 1fr));
  }

  .battlefield--route,
  .battlefield-art {
    aspect-ratio: auto;
    min-height: 280px;
  }

  .combatant-sprite {
    --spr-mul: 0.64;
  }

  .combatant-name {
    display: none;
  }

  .battle-heading__status {
    gap: 5px;
  }

  .battle-commander span {
    display: none;
  }

  .battle-intro {
    gap: 5px;
  }

  .battle-intro__side {
    display: grid;
    justify-items: center;
    gap: 4px;
    padding: 8px;
    font-size: 0.7rem;
    text-align: center;
  }

  .battle-intro__side img:not(.battle-intro__trainer) {
    width: 52px;
    height: 52px;
  }

  .battle-intro__trainer {
    width: 60px;
    height: 72px;
  }

  .battle-intro > strong {
    font-size: 0.9rem;
  }

  .mission-commander {
    min-width: 42px;
  }

  .mission-commander span {
    display: none;
  }

  .reward-card {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .reward-card button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .faction-grid {
    grid-template-columns: 1fr;
  }

  .faction-card {
    min-height: 292px;
  }
}

/* ---- Pause menu (Esc): Pokemon-style command menu over the route view ---- */

.menu-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

/* ---- Confirm dialog (shop affordability warning, reusable) ---- */
.confirm-dialog {
  width: min(420px, 92vw);
  padding: 0;
  border: 1px solid color-mix(in srgb, var(--gold) 40%, var(--line));
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.confirm-dialog::backdrop {
  background: rgba(6, 8, 12, 0.72);
}

.confirm-dialog[open] {
  animation: pause-menu-in 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

.confirm-dialog__body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
}

.confirm-dialog__title {
  margin: 0;
  font-size: 1.05rem;
  color: color-mix(in srgb, var(--gold) 70%, white);
}

.confirm-dialog__message {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.confirm-dialog__actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.confirm-dialog__actions button {
  flex: 1;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-weight: 600;
  cursor: pointer;
}

.confirm-dialog__cancel {
  background: color-mix(in srgb, var(--gold) 20%, var(--panel));
  border-color: color-mix(in srgb, var(--gold) 55%, var(--line));
  color: var(--text);
}

.confirm-dialog__cancel:hover {
  background: color-mix(in srgb, var(--gold) 30%, var(--panel));
}

.confirm-dialog__proceed {
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
}

.confirm-dialog__proceed:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.pause-menu {
  width: min(1080px, 94vw);
  height: min(700px, 90vh);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.pause-menu::backdrop {
  background: rgba(6, 8, 12, 0.72);
}

.pause-menu[open] {
  animation: pause-menu-in 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes pause-menu-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .pause-menu[open] {
    animation: none;
  }
}

.pause-menu__layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 218px;
  height: 100%;
}

.pause-menu__nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 14px;
  border-left: 1px solid var(--line);
  background: var(--panel-strong);
  border-radius: 0 12px 12px 0;
}

.pause-menu__nav button {
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text);
  padding: 12px 14px;
  text-align: left;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: 0.02em;
  transition: background 150ms ease, border-color 150ms ease;
}

.pause-menu__nav button:hover {
  background: rgba(255, 255, 255, 0.06);
}

.pause-menu__nav button.pause-menu__tab--active {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 14%, transparent);
}

.pause-menu__nav .pause-menu__exit {
  margin-top: auto;
  color: var(--danger);
}

.pause-menu__nav .pause-menu__close {
  color: var(--muted);
}

.pause-menu__screen {
  min-width: 0;
  padding: 20px 22px;
  overflow-y: auto;
}

.menu-screen__head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.menu-screen__head h3 {
  margin: 0;
  font-size: 1.3rem;
}

.chip--warn {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 16%, transparent);
}

.menu-subhead {
  margin: 18px 0 8px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.menu-party,
.menu-reserve {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 8px;
}

.menu-party--nine {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.menu-unit {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 0;
  min-width: 0;
}

.menu-unit__actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
}

.menu-unit .unit-card {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.menu-unit__action {
  border: 1px solid var(--line);
  border-top: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  background: var(--panel-strong);
  color: var(--text);
  padding: 7px 10px;
  font-weight: 800;
  font-size: 0.78rem;
  transition: border-color 150ms ease, background 150ms ease;
}

.menu-unit__action:hover {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 12%, var(--panel-strong));
}

.menu-unit__actions .menu-unit__action + .menu-unit__action {
  border-left: 0;
}

.menu-unit__action--trade {
  color: color-mix(in srgb, var(--gold) 78%, white);
}

.menu-unit__action--ace {
  color: color-mix(in srgb, var(--gold) 82%, white);
}

/* The current ace shows its crown and is disabled (already active) but must
   stay visibly gold rather than greyed like a truly unavailable action. */
.menu-unit__action--ace-on {
  color: var(--gold);
  background: color-mix(in srgb, var(--gold) 16%, var(--panel-strong));
  border-color: color-mix(in srgb, var(--gold) 55%, transparent);
}

.menu-unit__action--ace-on:disabled {
  opacity: 1;
  cursor: default;
}

.menu-unit__action:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

.menu-bag {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.menu-bag li {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: baseline;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-strong);
  padding: 11px 14px;
}

.menu-bag__row--empty {
  opacity: 0.55;
}

.menu-bag__count {
  font-weight: 900;
  color: var(--gold);
}

.menu-bag__note {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.menu-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.trainer-card {
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--gold) 10%, transparent), transparent 42%),
    var(--panel-strong);
  padding: 18px;
}

.trainer-card__rows {
  display: grid;
  gap: 10px;
}

.trainer-card__rows > div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  align-items: baseline;
}

.trainer-card__rows span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.trainer-card__insignias {
  display: grid;
  gap: 8px;
}

.badge-track--large .insignia-slot {
  width: 34px;
  height: 34px;
}

.menu-options {
  display: grid;
  gap: 12px;
}

.menu-option {
  display: grid;
  grid-template-columns: minmax(160px, auto) 1fr;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel-strong);
  padding: 12px 14px;
}

.menu-option label,
.menu-option > span:first-child {
  font-weight: 800;
  font-size: 0.9rem;
}

.menu-option small {
  display: block;
  color: var(--muted);
  font-weight: 600;
}

.menu-option input[type="range"] {
  width: 100%;
  accent-color: var(--gold);
}

.menu-option input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--gold);
  justify-self: start;
}

.menu-option--save {
  grid-template-columns: minmax(160px, auto) 1fr auto;
}

.menu-option--save button {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--danger);
  padding: 7px 12px;
  font-weight: 800;
  font-size: 0.8rem;
}

.menu-option--save button:not(:disabled):hover {
  border-color: var(--danger);
}

.menu-option--save button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 760px) {
  .pause-menu {
    width: 96vw;
    height: 92vh;
  }

  .pause-menu__layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .pause-menu__nav {
    order: -1;
    flex-direction: row;
    flex-wrap: wrap;
    border-left: none;
    border-bottom: 1px solid var(--line);
    border-radius: 12px 12px 0 0;
    padding: 10px;
  }

  .pause-menu__nav button {
    padding: 8px 12px;
    font-size: 0.85rem;
  }

  .pause-menu__nav .pause-menu__exit {
    margin-top: 0;
    margin-left: auto;
  }

  .menu-party,
  .menu-reserve {
    grid-template-columns: minmax(0, 1fr);
  }

  .menu-party--nine {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .menu-option,
  .menu-option--save {
    grid-template-columns: minmax(0, 1fr);
  }
}

.menu-subhead + .menu-note {
  margin: 0 0 10px;
}

/* ---- Story: enlistment identity step (name + avatar choice) ---- */

.story-identity {
  display: grid;
  gap: 14px;
  margin-top: 6px;
}

.story-identity__name {
  display: grid;
  gap: 6px;
  justify-items: start;
}

.story-identity__name span {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.story-identity__name input {
  width: min(260px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(10, 13, 18, 0.75);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 10px 12px;
}

.story-identity__name input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.story-identity__avatars {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 6px;
  max-width: 460px;
}

.story-identity__avatars button {
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: rgba(10, 13, 18, 0.6);
  padding: 4px;
  display: grid;
  place-items: center;
  transition: border-color 150ms ease, transform 150ms ease;
}

.story-identity__avatars button:hover {
  border-color: color-mix(in srgb, var(--gold) 60%, var(--line));
  transform: translateY(-1px);
}

.story-identity__avatars button.is-selected {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 18%, rgba(10, 13, 18, 0.6));
}

.story-identity__avatars img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  image-rendering: pixelated;
}

/* ---- Story: spoils requisition transfer beat ----
   Mirrors the wild capture stage: the in-game body sprite (or the initials
   disc fallback) is pulled into the success ball animation. */

.story-requisition {
  position: relative;
  width: 160px;
  height: 148px;
  margin: 10px auto 4px;
}

.story-requisition__pokemon {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.story-requisition .ball-anim {
  position: absolute;
  left: 50%;
  top: 64%;
  transform: translate(-50%, -50%) scale(1.35);
  filter: drop-shadow(0 5px 3px rgba(0, 0, 0, 0.45));
}

@media (prefers-reduced-motion: reduce) {
  .story-requisition__pokemon {
    animation: none;
    opacity: 0.3;
  }
}

.menu-trainer-portrait {
  width: 44px;
  height: 44px;
  object-fit: contain;
  image-rendering: pixelated;
}

@media (max-width: 760px) {
  .story-identity__avatars {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* ---- Legendary anomaly warning (battle intro variant) ----
   Concept: darkened board, pulsing red vignette, looming silhouette of the
   legendary's own body sprite, jagged WARNING banner across the center. */

.battle-intro--legendary {
  grid-template-columns: minmax(0, 1fr);
  background:
    radial-gradient(120% 95% at 50% 30%, rgba(64, 6, 10, 0.55), rgba(6, 4, 6, 0.94) 78%),
    rgba(6, 4, 6, 0.9);
  animation: battle-intro-exit 2400ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.battle-intro__anomaly {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 0;
  width: 100%;
}

.battle-intro__legend {
  position: relative;
  width: min(320px, 70%);
  height: 150px;
  filter: brightness(0) drop-shadow(0 0 14px rgba(255, 46, 46, 0.85)) drop-shadow(0 0 44px rgba(255, 0, 0, 0.45));
  animation: anomaly-pulse 1400ms ease-in-out infinite;
}

.battle-intro__silhouette {
  position: absolute;
  left: 50%;
  top: 72%;
  background-repeat: no-repeat;
  image-rendering: pixelated;
}

.battle-intro__silhouette-img {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 130px;
  height: 130px;
  object-fit: contain;
  image-rendering: pixelated;
}

.battle-intro__banner {
  width: 108%;
  margin: -8px -4% 0;
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 16px 20px 18px;
  background: linear-gradient(180deg, rgba(28, 6, 8, 0.96), rgba(12, 3, 5, 0.96));
  border-top: 2px solid rgba(255, 66, 56, 0.9);
  border-bottom: 2px solid rgba(255, 66, 56, 0.9);
  clip-path: polygon(0 12%, 3% 4%, 8% 10%, 15% 2%, 24% 9%, 33% 3%, 43% 10%, 52% 2%, 62% 8%, 71% 3%, 80% 10%, 89% 4%, 96% 9%, 100% 3%, 100% 88%, 96% 95%, 88% 90%, 79% 97%, 69% 91%, 58% 98%, 48% 91%, 38% 97%, 28% 92%, 18% 98%, 10% 91%, 4% 96%, 0 90%);
  box-shadow: 0 0 34px rgba(255, 30, 30, 0.35);
}

.battle-intro__banner strong {
  color: #ffd9d4;
  font-size: clamp(1.7rem, 4.6vw, 2.6rem);
  font-weight: 900;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(255, 64, 54, 0.85);
}

.battle-intro__banner span {
  color: #ff9d94;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

@keyframes anomaly-pulse {
  0%, 100% { filter: brightness(0) drop-shadow(0 0 14px rgba(255, 46, 46, 0.85)) drop-shadow(0 0 44px rgba(255, 0, 0, 0.45)); }
  50% { filter: brightness(0) drop-shadow(0 0 22px rgba(255, 70, 60, 1)) drop-shadow(0 0 64px rgba(255, 0, 0, 0.6)); }
}

@media (prefers-reduced-motion: reduce) {
  .battle-intro__legend {
    animation: none;
  }
}

.setup-disclaimer {
  margin: 18px auto 0;
  max-width: 72ch;
  text-align: center;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.6;
}

/* Keyboard-focus baseline: every interactive element gets a visible ring
   unless a component styles its own focus treatment. */
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Stat-derived combat role chip on unit cards. Colored by role so tanks,
   fighters, and rangers read at a glance next to the type tags. */
.unit-role {
  --role-color: var(--muted);
  border-color: color-mix(in srgb, var(--role-color) 55%, var(--line)) !important;
  background: color-mix(in srgb, var(--role-color) 20%, transparent) !important;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.unit-role--tank {
  --role-color: #66a8e0;
}

.unit-role--fighter {
  --role-color: #e08a5a;
}

.unit-role--ranger {
  --role-color: #8fca6a;
}

/* Defeated units "return to their ball": the closed-Pokeball frame (frame 3)
   of the in-game capture success sprite sheet replaces the unit for the back
   half of the faint. Driven by the game clock (inline background-image plus
   --recall-scale / --recall-opacity) so it reliably shows as the last frame
   before the unit is removed from the board. */
.combatant-recall {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 64px;
  height: 64px;
  background-repeat: no-repeat;
  background-size: 64px auto;
  background-position: 0 -64px; /* frame 1 of 15: clean red/white Pokeball */
  image-rendering: pixelated;
  transform: translate(-50%, -50%) scale(calc(0.7 * var(--recall-scale, 1)));
  opacity: var(--recall-opacity, 1);
  filter: drop-shadow(0 0 6px rgba(0, 0, 0, 0.55));
  z-index: 5;
}

/* Once recalled, only the ball shows on the cell. */
.combatant--recalled .combatant-bars,
.combatant--recalled .combatant-name {
  opacity: 0;
}

/* ---- Pokedex (pause menu tab): scrollable, searchable, three states ---- */
.dex-search {
  width: 100%;
  margin: 4px 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(10, 13, 18, 0.75);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  padding: 10px 14px;
}

.dex-search:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.dex-legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.dex-legend-dot--caught { background: var(--gold); }
.dex-legend-dot--seen { background: var(--muted); }

.dex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.dex-entry {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
}

.dex-entry[hidden] { display: none; }

.dex-entry--caught {
  border-color: color-mix(in srgb, var(--gold) 55%, var(--line));
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--gold) 14%, transparent), transparent 60%),
    rgba(255, 255, 255, 0.03);
}

.dex-entry--unseen {
  opacity: 0.7;
}

.dex-portrait {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.28);
}

.dex-portrait__img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

/* Unseen: black silhouette mystery. */
.dex-portrait--unseen .dex-portrait__img {
  filter: brightness(0) opacity(0.82);
}

.dex-portrait--seen .dex-portrait__img {
  filter: saturate(0.85);
}

.dex-portrait__fallback {
  font-weight: 900;
  font-size: 0.9rem;
  color: var(--muted);
}

.dex-portrait--unseen .dex-portrait__fallback {
  color: #05070a;
}

/* Caught marker: a mini Pokeball badge in the corner. */
.dex-caught {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: linear-gradient(#e2453f 0 46%, #14181c 46% 54%, #f4f0e8 54% 100%);
  border: 1px solid #14181c;
  box-shadow: 0 0 3px rgba(0, 0, 0, 0.6);
}

.dex-caught::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #f4f0e8;
  border: 1px solid #14181c;
  transform: translate(-50%, -50%);
}

.dex-entry__id {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.dex-entry__id small {
  color: var(--muted);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.dex-entry__id strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
}

.dex-types {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}

.dex-type {
  border: 1px solid color-mix(in srgb, var(--type-color) 55%, var(--line));
  background: color-mix(in srgb, var(--type-color) 20%, transparent);
  border-radius: var(--radius-pill);
  padding: 1px 6px;
  font-size: 0.62rem;
  font-weight: 800;
}

.dex-type--unknown {
  --type-color: var(--muted);
}

@media (max-width: 760px) {
  .dex-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  }
}
