/* HUD de batalha: barra superior compacta, campo e barra de heróis. */
/* Altura fixa: nenhum elemento entra, sai ou muda de largura conforme o estado da partida
   (B-14). Uma linha a partir de 1280px; abaixo, duas linhas fixas (grid). */
#top-hud {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: var(--s-2) var(--s-4);
  padding: var(--s-2) var(--s-4);
  border-bottom: 1px solid var(--line);
  background: var(--surface-1);
  z-index: 10;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  min-width: 0;
}

.stage-badge {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.stage-tag {
  font-size: var(--fs-12);
  color: var(--text-2);
  white-space: nowrap;
}

.stage-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-16);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.hud-vitals {
  display: flex;
  align-items: stretch;
  gap: var(--s-2);
  margin: 0 auto;
}

.hud-stat {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 72px;
  padding: 2px var(--s-3);
  border-radius: var(--radius-m);
  background: var(--surface-2);
  line-height: 1.15;
  text-align: left;
}

.hud-label {
  font-size: var(--fs-12);
  color: var(--text-2);
}

.hud-val {
  font-size: var(--fs-20);
  white-space: nowrap;
}

.hud-stat-btn {
  border: 1px solid var(--line-strong);
}

.hud-stat-btn:hover {
  background: var(--surface-3);
}

.health-card {
  min-width: 110px;
  padding-bottom: 8px;
}

.health-bar-bg {
  position: absolute;
  left: var(--s-3);
  right: var(--s-3);
  bottom: 4px;
  height: 3px;
  border-radius: 2px;
  background: var(--surface-4);
  overflow: hidden;
}

#health-bar-fill {
  height: 100%;
  background: var(--ok);
  transition: width var(--t-fast);
}

.hud-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-2);
}

.call-wave-btn {
  flex-direction: column;
  gap: 0;
  min-width: 148px;
  min-height: 44px;
  line-height: 1.1;
}

.call-wave-btn .btn-sub {
  font-size: var(--fs-12);
  font-weight: 400;
}

.toggle-btn {
  gap: var(--s-2);
}

.toggle-btn.active {
  background: var(--text);
  border-color: var(--text);
  color: var(--action-ink);
}

.toggle-btn.active .auto-wave-dot,
.toggle-btn.active .status-dot {
  background: var(--action-ink);
  border-color: var(--action-ink);
}

.auto-wave-dot,
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid var(--text-2);
}

.auto-wave-dot.active,
.status-dot.green {
  background: var(--ok);
  border-color: var(--ok);
}

.speed-controls {
  display: flex;
  border-radius: var(--radius-m);
  border: 1px solid var(--line-strong);
  overflow: hidden;
}

.speed-btn {
  min-width: 40px;
  min-height: 32px;
  padding: 0 var(--s-2);
  color: var(--text-2);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.speed-btn + .speed-btn {
  border-left: 1px solid var(--line);
}

.speed-btn:focus-visible {
  outline-offset: -3px;
}

kbd {
  font-family: var(--font-body);
  font-size: var(--fs-12);
  padding: 0 5px;
  border-radius: 3px;
  border: 1px solid var(--line-strong);
  color: var(--text-2);
}

/* Painel do Dojo. */
.dojo-sandbox-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s-2) var(--s-4);
  padding: var(--s-2) var(--s-4);
  border-bottom: 1px solid var(--line);
  background: var(--surface-1);
}

.sandbox-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
}

.sandbox-label {
  font-size: var(--fs-13);
  color: var(--text-2);
}

/* Campo: o renderer acopla a superfície aqui; qualquer canvas é centrado e escalado. */
#viewport-container {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  background: var(--bg);
}

#viewport-container:focus-visible {
  outline-offset: -4px;
}

#viewport-container > canvas {
  max-width: 100%;
  max-height: 100%;
  cursor: crosshair;
  /* Pinça e arraste são do jogo (view-zoom.js), não da página. */
  touch-action: none;
}

#viewport-container > canvas.is-panning {
  cursor: grabbing;
}

/* Marcadores de entrada e de base antes da onda 1 (ui/route-markers.js). Camada por cima do canvas, sem ponteiro:
   vermelho é por onde os inimigos entram, verde é a base. Some quando a onda 1 começa. */
.route-markers {
  --rm-entry: var(--danger);
  --rm-base: var(--ok);
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.6s ease, visibility 0s linear 0s;
}

.route-markers.is-off {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s ease, visibility 0s linear 0.6s;
}

.rm-svg {
  position: absolute;
  overflow: hidden;
}

.rm-line-shadow,
.rm-line,
.rm-guide {
  fill: none;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}

.rm-line-shadow {
  stroke: var(--bg);
  stroke-opacity: 0.55;
  stroke-width: 7px;
}

.rm-line {
  stroke: var(--rm-entry);
  stroke-width: 3px;
  stroke-dasharray: 2 14;
  animation: rm-flow 1.2s linear infinite;
}

.rm-guide {
  stroke: none;
}

.rm-arrow-shape {
  fill: var(--rm-entry);
  stroke: var(--bg);
  stroke-width: 2px;
  paint-order: stroke;
}

@keyframes rm-flow {
  to { stroke-dashoffset: -16; }
}

.rm {
  position: absolute;
  inset: 0;
}

.rm-dot,
.rm-tag {
  position: absolute;
  left: 0;
  top: 0;
}

.rm-dot {
  width: 0;
  height: 0;
}

.rm-dot::before,
.rm-dot::after {
  content: '';
  position: absolute;
  left: -9px;
  top: -9px;
  width: 18px;
  height: 18px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 3px solid var(--rm-color);
  background: color-mix(in srgb, var(--rm-color) 30%, var(--bg));
}

.rm-dot::after {
  background: none;
  border-width: 2px;
  animation: rm-pulse 1.6s ease-out infinite;
}

@keyframes rm-pulse {
  from { transform: scale(1); opacity: 0.9; }
  to { transform: scale(2.4); opacity: 0; }
}

.rm-entry { --rm-color: var(--rm-entry); }
.rm-base { --rm-color: var(--rm-base); }

/* Raid: bandeira na entrada de cada caminho, na cor do universo, com o nome em cima (--rm-color vem do mundo). O pé do
   mastro fica no ponto da trilha. */
.rm-flag .rm-dot::before,
.rm-flag .rm-dot::after {
  content: none;
}

.rm-flag-art {
  position: absolute;
  left: -10px;
  top: -58px;
  image-rendering: pixelated;
  filter: drop-shadow(1px 2px 0 rgb(0 0 0 / 0.55));
  transform-origin: 6px 58px;
  animation: rm-flag-wave 2.4s ease-in-out infinite;
}

.rm-flag-pole { fill: #2b2420; }
.rm-flag-tip { fill: #d9b36a; }
.rm-flag-cloth { fill: var(--rm-color); }
.rm-flag-band { fill: rgb(0 0 0 / 0.35); }

.rm-flag .rm-tag {
  border-width: 2px;
  font-size: var(--fs-14);
  font-weight: 700;
}

@keyframes rm-flag-wave {
  0%, 100% { transform: skewY(0deg); }
  50% { transform: skewY(-3deg); }
}

.rm-tag {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 4px var(--s-2);
  border: 1px solid var(--rm-color);
  border-radius: var(--radius-s);
  background: color-mix(in srgb, var(--surface-1) 94%, transparent);
  color: var(--text);
  font-size: var(--fs-13);
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.rm-entry.is-late {
  opacity: 0.7;
}

/* Seta da etiqueta presa na borda: aponta para o ponto fora da tela. Só aparece nesse caso. */
.rm-pointer {
  display: none;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 5px 0 5px 8px;
  border-color: transparent transparent transparent var(--rm-color);
}

.rm.is-offscreen .rm-pointer {
  display: block;
}

.rm.is-offscreen .rm-dot {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .rm-line,
  .rm-dot::after,
  .rm-flag-art {
    animation: none;
  }
}

/* Zoom do campo: aproximar, afastar e voltar à visão padrão. Fica no canto, fora da trilha. */
.view-zoom {
  position: absolute;
  right: var(--s-2);
  bottom: var(--s-2);
  z-index: 5;
  display: flex;
  gap: 1px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--line-strong);
  overflow: hidden;
}

.view-zoom-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 0 var(--s-2);
  border: 0;
  background: var(--surface-2);
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-14);
  line-height: 1;
  cursor: pointer;
}

.view-zoom-btn:hover:not(:disabled) {
  background: var(--surface-4);
  color: var(--focus);
}

.view-zoom-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.view-zoom-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.view-zoom-reset {
  min-width: 48px;
  font-variant-numeric: tabular-nums;
}

.view-zoom.is-zoomed .view-zoom-reset {
  color: var(--focus);
}

/* Painel da unidade: único vidro da interface, para o campo continuar visível atrás. */
.unit-floating-modal {
  position: absolute;
  top: var(--s-3);
  right: var(--s-3);
  max-height: calc(100% - 24px);
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  width: 320px;
  max-width: calc(100% - 24px);
  padding: var(--s-4);
  border-radius: var(--radius-l);
  border: 1px solid var(--line-strong);
  background: rgba(22, 25, 32, 0.9);
  backdrop-filter: blur(10px);
  overflow-y: auto;
}

.unit-floating-modal.hidden {
  display: none;
}

.unit-head {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: var(--s-3);
  align-items: center;
}

.unit-portrait {
  aspect-ratio: var(--card-ratio);
  display: grid;
  place-items: center;
  border-radius: var(--radius-s);
  border: 1px solid var(--line-strong);
  font-size: 22px;
  overflow: hidden;
}

.unit-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.unit-title h3 {
  font-size: var(--fs-20);
}

.unit-stats,
.unit-perf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-2) var(--s-3);
}

.unit-stats dt,
.unit-perf-grid dt {
  font-size: var(--fs-12);
  color: var(--text-2);
}

.unit-stats dd {
  font-weight: 600;
}

/* Passivas do herói (ui/mechanic-text.js): um bloco por passiva, aberto por padrão, recolhe no nome dela. */
.unit-mech {
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-m);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.unit-mech-group {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.unit-mech-group[hidden] {
  display: none;
}

.unit-mech > summary {
  min-height: 24px;
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.unit-mech .mech-text {
  margin: var(--s-2) 0 0;
  font-size: var(--fs-13);
  line-height: 1.45;
  color: var(--text-2);
}

@media (max-width: 600px), (pointer: coarse) {
  .unit-mech > summary {
    padding-block: 10px;
  }
}

.span-2 {
  grid-column: 1 / -1;
}

.unit-perf {
  padding: var(--s-3);
  border-radius: var(--radius-m);
  background: var(--surface-2);
}

.unit-perf-head {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--s-2);
  font-size: var(--fs-13);
  font-weight: 600;
}

.unit-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s-2);
}

.unit-actions .btn {
  flex-direction: column;
  gap: 0;
  line-height: 1.15;
}

/* Nível máximo: o botão de upar fica no lugar, neutro e apagado, para o Vender não mudar de posição.
   Sem a opacidade do disabled: o texto "Nível máximo" precisa continuar legível. */
.unit-actions .btn.is-max {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--text-2);
  opacity: 1;
}

/* Barra de heróis: 6 slots; no Dojo, todos os heróis em fila rolável. */
#bottom-hud {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  padding: var(--s-2) var(--s-4);
  border-top: 1px solid var(--line);
  background: var(--surface-1);
}

.hotbar-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-1) var(--s-3);
}

.hotbar-label {
  font-size: var(--fs-12);
  color: var(--text-2);
}

/* Dojo: um chip por universo, na cor do anime, acima da lista de heróis. */
.hotbar-universes {
  display: flex;
  gap: var(--s-2);
  max-width: 100%;
  overflow-x: auto;
}

.hotbar-universes.hidden {
  display: none;
}

.universe-chip {
  flex: none;
}

.hotbar-slots {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--s-2);
}

.hotbar-slots.training-mode {
  display: flex;
  overflow-x: auto;
  padding-bottom: var(--s-1);
  scroll-snap-type: x proximity;
}

.hotbar-slots.training-mode .hero-slot {
  flex: 0 0 168px;
  scroll-snap-align: start;
}

.hero-slot {
  position: relative;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: var(--s-2);
  align-items: center;
  min-height: 64px;
  padding: var(--s-1) var(--s-2);
  padding-top: calc(var(--s-1) + 3px);
  border-radius: var(--radius-m);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  text-align: left;
  overflow: hidden;
}

.hero-slot::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--rarity, transparent);
}

.hero-slot:hover {
  background: var(--surface-3);
}

.hero-slot.selected {
  border-color: var(--text);
  box-shadow: inset 0 0 0 1px var(--text);
  background: var(--surface-3);
}

.hero-slot.disabled .mini-portrait {
  opacity: 0.5;
}

.hero-slot.disabled .slot-name,
.hero-slot.disabled .slot-cost {
  color: var(--text-2);
}

.slot-hotkey {
  position: absolute;
  top: 5px;
  right: 6px;
  font-size: var(--fs-12);
  color: var(--text-2);
  font-weight: 600;
}

.slot-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.2;
}

.slot-name {
  font-weight: 600;
  font-size: var(--fs-13);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: var(--s-3);
}

.slot-line {
  display: flex;
  gap: var(--s-2);
  font-size: var(--fs-12);
  color: var(--text-2);
  white-space: nowrap;
}

.slot-cost {
  color: var(--text);
  font-weight: 600;
}

.slot-count.maxed-badge {
  color: var(--text);
}

.slot-state {
  font-size: var(--fs-12);
  color: var(--text-2);
}

.slot-dmg-badge {
  font-size: var(--fs-12);
  color: var(--text-2);
}

/* Fim de partida. */
#game-overlay {
  position: absolute;
}

.overlay-card {
  width: min(560px, calc(100% - 32px));
  text-align: center;
  align-items: center;
}

/* O fim de partida mora dentro do campo, que é mais baixo que a janela: o cartão rola em vez de sair da tela (a lista de drops pode ser longa). */
#game-overlay .overlay-card {
  max-height: 100%;
  overflow-y: auto;
}

#overlay-title {
  font-size: var(--fs-32);
}

#overlay-title.victory {
  color: var(--ok);
}

#overlay-title.defeat {
  color: var(--danger);
}

#overlay-desc {
  color: var(--text-2);
  white-space: pre-line;
}

.overlay-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--s-3);
  width: 100%;
  margin: var(--s-2) 0;
  padding: var(--s-3) 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

/* Desafio mostra seis números: três por linha. */
.overlay-stats:has(#overlay-challenge-waves:not([hidden])) {
  grid-template-columns: repeat(3, 1fr);
}

.overlay-stats dt {
  font-size: var(--fs-12);
  color: var(--text-2);
}

.overlay-stats dd {
  font-size: var(--fs-20);
}

/* Resumo de drops (v0.175): quadradinhos do que caiu no fim da partida, no marco de 20 ondas do Infinito e no inventário de drops. */
.drop-summary {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  width: 100%;
}

.drop-summary[hidden] {
  display: none;
}

.drop-summary-title {
  font-family: var(--font-body);
  font-size: var(--fs-14);
  font-weight: 600;
}

.drop-summary-list {
  grid-template-columns: repeat(auto-fit, minmax(96px, 112px));
  justify-content: center;
  margin-top: 0;
}

/* Botão do inventário de drops: no canto do campo, para não apertar o HUD do alto. */
.drop-inventory-btn {
  position: absolute;
  top: var(--s-3);
  left: var(--s-3);
  z-index: 7;
}

.drop-inventory-btn[hidden] {
  display: none;
}

.overlay-card .drop-summary-list {
  grid-template-columns: repeat(auto-fit, minmax(84px, 100px));
}

.overlay-card .drop-item {
  padding: var(--s-1);
}

.drop-summary-hint,
.drop-summary-empty {
  font-size: var(--fs-12);
  color: var(--text-2);
}

.drop-got .drop-chance {
  color: var(--text);
}

/* Aviso do marco do Infinito: no alto do campo, sem pausar a partida nem tirar o foco do campo. */
.drop-milestone {
  position: absolute;
  top: var(--s-3);
  left: 50%;
  z-index: 9;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  width: min(440px, calc(100% - 24px));
  padding: var(--s-3) var(--s-4);
  text-align: center;
  transform: translateX(-50%);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-l);
  background: rgba(22, 25, 32, 0.94);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.drop-milestone.hidden {
  display: none;
}

.drop-milestone-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
}

.drop-milestone-head h3 {
  flex: 1;
  font-size: var(--fs-16);
}

.overlay-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s-2);
}

/* Próxima fase (v0.236): botão de duas linhas, o destino aparece embaixo do nome. */
.btn-next-stage {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1.2;
}

.btn-next-stage[hidden] {
  display: none;
}

.btn-next-stage-sub {
  font-size: var(--fs-12);
  font-weight: 500;
  opacity: 0.85;
}

/* Telas menores que 1280: HUD em duas linhas, nomes longos encurtam. */
@media (max-width: 1279px) {
  .hud-vitals {
    margin: 0;
  }

  .hud-controls {
    margin-left: auto;
  }

  .hud-stat {
    min-width: 76px;
  }

  .hud-val {
    font-size: var(--fs-16);
  }

  .stage-title {
    max-width: 160px;
  }

  .hero-slot {
    grid-template-columns: 32px minmax(0, 1fr);
    min-height: 56px;
  }

  .unit-floating-modal {
    width: 280px;
  }
}

@media (max-width: 900px) {
  .hotbar-slots {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Celular estreito: os quatro universos em duas colunas (em fila, o quarto ficava fora da tela)
   e a barra de inimigos do Dojo em fileiras que rolam para o lado, em vez de ocupar quatro linhas. */
@media (max-width: 600px) {
  .hotbar-universes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    overflow: visible;
  }

  .hotbar-universes .universe-chip {
    justify-content: center;
    min-height: 40px;
  }

  .dojo-sandbox-bar {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: var(--s-1);
  }

  .dojo-sandbox-bar .sandbox-group {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: var(--s-1);
  }

  .dojo-sandbox-bar .sandbox-group > * {
    flex: none;
  }
}

@media (max-width: 600px) and (max-height: 700px) {
  .hotbar-label {
    display: none;
  }
}

/* Celular: os atalhos de teclado não servem; a lista do Dojo vira duas fileiras rolando para o lado,
   para caberem de quatro a seis heróis por tela em vez de um e meio. */
@media (max-width: 600px), (pointer: coarse) {
  .hotbar-keys,
  .hotbar-slots.training-mode .slot-hotkey {
    display: none;
  }

  .universe-chip {
    min-height: 44px;
  }

  .hotbar-slots.training-mode {
    display: grid;
    grid-auto-flow: column;
    grid-template-columns: none;
    grid-template-rows: repeat(2, auto);
    grid-auto-columns: 148px;
    gap: var(--s-2);
  }

  .hotbar-slots.training-mode .hero-slot {
    flex: none;
  }
}

/* Celular: com três cartas por linha o nome cabia em 4 letras; passa a quebrar em até duas linhas. */
@media (max-width: 520px) {
  .hero-slot {
    gap: var(--s-1);
  }

  .slot-name {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    white-space: normal;
    padding-right: 10px;
    font-size: var(--fs-12);
    line-height: 1.15;
  }
}

@media (max-width: 760px) {

  .overlay-stats,
  .overlay-stats:has(#overlay-challenge-waves:not([hidden])) {
    grid-template-columns: 1fr;
  }
}

/* Larguras mínimas para que números maiores (yen de 7 dígitos, onda 10) não mudem o HUD. */
.hud-left {
  flex: 1 1 auto;
}

.stage-badge {
  flex: 1 1 auto;
}

.hud-vitals,
.hud-controls {
  flex: none;
  flex-wrap: nowrap;
}

#base-health-card {
  min-width: 112px;
}

#yen-card {
  min-width: 132px;
}

#wave-card {
  min-width: 88px;
}

/* Cronômetro: largura de "0:00:00" para a hora cheia não empurrar o HUD. Fica fora de .hud-vitals, mas com o mesmo
   espaço entre os cartões. */
#time-card {
  flex: none;
  min-width: 84px;
  margin-left: calc(var(--s-2) - var(--s-4));
}

#team-dps-card {
  min-width: 124px;
}

.hud-label kbd {
  margin-left: 2px;
  padding: 0 4px;
  font-size: 11px;
  line-height: 1.2;
}

/* Com o cronômetro (v0.244) o HUD numa linha só não cabe abaixo de 1440: vai para duas linhas. */
@media (max-width: 1439px) {
  .hud-vitals {
    margin: 0;
  }

  .hud-controls {
    margin-left: auto;
  }

  #top-hud {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      'left vitals time'
      'controls controls controls';
  }

  #time-card {
    grid-area: time;
  }

  .hud-left {
    grid-area: left;
  }

  .hud-vitals {
    grid-area: vitals;
  }

  .hud-controls {
    grid-area: controls;
    justify-content: flex-end;
  }
}

/* Celular (N-02, v0.93): HUD em três linhas curtas para sobrar altura ao campo.
   Fase, cronômetro e Som; os quatro números lado a lado; onda, Auto e velocidades. */
@media (max-width: 600px) {
  #top-hud {
    grid-template-columns: minmax(0, 1fr) auto auto auto;
    grid-template-areas:
      'left left time mute'
      'vitals vitals vitals vitals'
      'call auto speed speed';
    gap: var(--s-1) var(--s-2);
    padding: var(--s-1) var(--s-2);
  }

  .hud-left {
    gap: var(--s-2);
  }

  .stage-title {
    max-width: none;
    font-size: var(--fs-14);
  }

  .hud-vitals {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--s-1);
  }

  #base-health-card,
  #yen-card,
  #wave-card,
  #time-card,
  #team-dps-card {
    min-width: 0;
    padding: 2px var(--s-2);
  }

  #time-card {
    margin-left: 0;
  }

  #base-health-card {
    padding-bottom: 7px;
  }

  .health-bar-bg {
    left: var(--s-2);
    right: var(--s-2);
  }

  .hud-label {
    font-size: 11px;
    white-space: nowrap;
  }

  .hud-label kbd {
    display: none;
  }

  .hud-val {
    font-size: var(--fs-14);
  }

  .hud-controls {
    display: contents;
  }

  #btn-call-wave {
    grid-area: call;
    min-width: 0;
    padding: 0 var(--s-2);
  }

  #btn-call-wave .btn-text,
  #btn-call-wave .btn-sub {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #btn-auto-wave {
    grid-area: auto;
    padding: 0 var(--s-3);
  }

  .speed-controls {
    grid-area: speed;
    align-self: stretch;
  }

  .speed-btn {
    min-width: 34px;
    padding: 0 var(--s-1);
  }

  #btn-mute {
    grid-area: mute;
    justify-self: end;
  }

  #bottom-hud {
    padding: var(--s-1) var(--s-2);
  }

  /* Na partida o texto de ajuda fala de teclado e botão direito; no celular a carta selecionada já diz o que fazer. */
  .hotbar-head:has(+ .hotbar-slots:not(.training-mode)) {
    display: none;
  }
}

/* Celular deitado (tela baixa, v0.93): HUD sem folgas, ajuda escondida e as seis cartas numa fileira só,
   para o campo não ficar com uma faixa de 100 px. Botões seguem com 44 px para o toque. */
@media (max-height: 500px) and (min-width: 601px) {
  #top-hud {
    gap: 2px var(--s-2);
    padding: 2px var(--s-2);
  }

  .hud-stat {
    padding: 0 var(--s-2);
  }

  .health-card {
    padding-bottom: 7px;
  }

  #bottom-hud {
    padding: var(--s-1) var(--s-2);
  }

  .hotbar-head:has(+ .hotbar-slots:not(.training-mode)) {
    display: none;
  }

  .hotbar-slots {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: var(--s-1);
  }

  .hero-slot {
    grid-template-columns: 28px minmax(0, 1fr);
    min-height: 44px;
  }

  /* O estado (Yen insuficiente, limite) já aparece na carta apagada e no leitor de tela. */
  .hero-slot .slot-state {
    display: none;
  }
}

/* Painel da unidade: nível da carta, ranks e aura (v0.27). */
.unit-levels {
  display: block;
  font-size: var(--fs-12);
  color: var(--text-2);
}

.unit-stats dt .rank {
  margin-left: 4px;
  min-width: 22px;
  font-size: var(--fs-12);
}

.unit-aura {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px var(--s-2);
  margin-top: calc(var(--s-1) * -1);
}

.unit-aura-bonus {
  font-size: var(--fs-12);
  color: var(--text-2);
}

.unit-floating-modal {
  gap: var(--s-2);
}

.unit-floating-modal .unit-stats {
  gap: var(--s-1) var(--s-3);
}

.unit-floating-modal .unit-perf {
  padding: var(--s-2) var(--s-3);
}

.unit-floating-modal .unit-perf-grid {
  gap: var(--s-1) var(--s-3);
}

.unit-floating-modal .unit-perf-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.unit-floating-modal .unit-perf-grid .span-2 {
  grid-column: span 2;
}

.unit-floating-modal .unit-stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.unit-floating-modal .unit-stats .unit-aoe {
  grid-column: span 2;
}

.unit-floating-modal .unit-stats .span-2 {
  grid-column: 1 / -1;
}

/* Seletor de mira (v0.37): grupo de rádio com seis botões em 3 x 2, texto em caixa normal.
   Marcado = preenchimento claro da ação primária, sem neon (neon fica para raridade). */
.unit-aim {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.unit-aim-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 var(--s-2);
  font-size: var(--fs-12);
  color: var(--text-2);
}

.unit-aim-title {
  font-size: var(--fs-13);
  font-weight: 600;
  color: var(--text);
}

.unit-aim-keys kbd {
  font-size: 11px;
  line-height: 1.3;
}

.aim-modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-1);
}

.aim-mode-btn {
  min-height: 36px;
  padding: 0 var(--s-2);
  border-radius: var(--radius-s);
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  font-size: var(--fs-13);
  line-height: 1.15;
  color: var(--text-2);
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}

.aim-mode-btn:hover {
  background: var(--surface-3);
  color: var(--text);
}

.aim-mode-btn[aria-checked='true'] {
  background: var(--text);
  border-color: var(--text);
  color: var(--action-ink);
  font-weight: 600;
}

.unit-aim-hint {
  margin: 0;
  min-height: 2.6em;
  font-size: var(--fs-12);
  line-height: 1.3;
  color: var(--text-2);
}

/* Toque: alvos de 44px (o painel rola quando a tela é baixa). */
@media (pointer: coarse) {
  .aim-mode-btn {
    min-height: 44px;
  }

  .aim-modes {
    gap: var(--s-2);
  }
}

/* Painel estreito ou sem teclado: a linha das teclas sai; os seis botões seguem em 3 x 2 e o texto quebra. */
@media (max-width: 420px), (pointer: coarse) {
  .unit-aim-keys {
    display: none;
  }

  .aim-mode-btn {
    padding: 0 var(--s-1);
  }
}

/* Trilha dos 10 níveis da partida no painel da unidade (v0.81.0). Todos os traços aparecem apagados e
   acendem até o nível atual. Os níveis de evolução (5 e 10) se distinguem por forma, tamanho e cor: mais
   largos, mais altos, contorno tracejado enquanto apagados, losango em cima e o nome da evolução embaixo.
   A mesma trilha, em miniatura, fica na plaquinha do herói no campo (render/three/card-painter.js). */
.level-track {
  --lt-level: #ffbe26;
  --lt-evo: #5ce1ff;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.5fr) repeat(4, minmax(0, 1fr)) minmax(0, 1.5fr);
  align-items: end;
  gap: 3px;
  padding: 8px 0 18px;
}

.level-track:empty {
  display: none;
}

.lt-seg {
  position: relative;
  height: 8px;
  border-radius: 2px;
  border: 1px solid #3a4150;
  background: rgba(255, 255, 255, 0.05);
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.lt-seg.next {
  border-color: var(--line-strong);
}

.lt-seg.on {
  border-color: var(--lt-level);
  background: var(--lt-level);
}

.lt-seg.lt-evo {
  height: 14px;
  border: 1px dashed rgba(92, 225, 255, 0.55);
  background: rgba(92, 225, 255, 0.08);
}

/* Losango sobre o traço da evolução. */
.lt-seg.lt-evo::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -5px;
  width: 7px;
  height: 7px;
  transform: translateX(-50%) rotate(45deg);
  border: 1px solid rgba(92, 225, 255, 0.7);
  background: var(--surface-1);
}

.lt-seg.lt-evo.on {
  border-style: solid;
  border-color: var(--lt-evo);
  background: var(--lt-evo);
  box-shadow: 0 0 8px rgba(92, 225, 255, 0.55);
}

.lt-seg.lt-evo.on::before {
  border-color: #ffffff;
  background: #ffffff;
}

.lt-tag {
  position: absolute;
  top: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--fs-12);
  line-height: 1.2;
  white-space: nowrap;
  color: var(--text-2);
}

.lt-seg:last-child .lt-tag {
  left: auto;
  right: 0;
  transform: none;
}

.lt-seg.lt-evo.on .lt-tag {
  color: var(--lt-evo);
}

@media (prefers-reduced-motion: reduce) {
  .lt-seg {
    transition: none;
  }
}

/* Painel do inimigo (v0.128): clicar num inimigo mostra vida, velocidade e o que pesa sobre ele. Usa o vidro do painel da unidade;
   os dois nunca ficam abertos juntos. As barras laterais dizem a natureza do efeito sem depender de cor: o texto traz o sinal. */
.enemy-modal {
  width: 260px;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
}

.enemy-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s-3);
  align-items: start;
}

.enemy-title h3 {
  margin: 0;
  font-size: var(--fs-16);
  overflow-wrap: anywhere;
}

.enemy-badge {
  font-size: var(--fs-12);
  color: var(--text-2);
}

.enemy-hp-line,
.enemy-speed {
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
  font-size: var(--fs-13);
}

.enemy-hp-line span:first-child,
.enemy-speed span:first-child {
  color: var(--text-2);
}

.enemy-hp-track {
  margin-top: var(--s-1);
  height: 8px;
  border-radius: 4px;
  background: var(--surface-3);
  overflow: hidden;
}

.enemy-hp-fill {
  height: 100%;
  width: 100%;
  background: var(--ok);
}

.enemy-effects {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.enemy-effects:empty {
  display: none;
}

.enemy-effects:not(:empty) + .enemy-empty {
  display: none;
}

.enemy-effect {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 var(--s-3);
  padding: var(--s-1) var(--s-2) var(--s-1) var(--s-3);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  font-size: var(--fs-13);
}

.enemy-effect.is-slow { border-left-color: #8FB8FF; }
.enemy-effect.is-weak { border-left-color: #FFD27A; }

.enemy-effect-label { font-weight: 600; }
.enemy-effect-time { color: var(--text-2); text-align: right; }
.enemy-effect-value { grid-column: 1 / -1; }
.enemy-effect-owner { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--s-2); margin-top: 2px; color: var(--text-2); font-size: var(--fs-12); }
/* Vários heróis no mesmo efeito (v0.141): as carinhas numa fileira e os nomes embaixo, para o texto não espremer ao lado. */
.enemy-effect-owner.is-multi { flex-wrap: wrap; gap: var(--s-1) var(--s-2); }
.enemy-effect-owner.is-multi > span:last-child { flex-basis: 100%; }

.enemy-empty {
  margin: 0;
  color: var(--text-2);
  font-size: var(--fs-13);
}

@media (max-width: 600px) {
  .enemy-modal {
    width: 220px;
    max-height: 55%;
    padding: var(--s-2) var(--s-3);
    gap: var(--s-2);
  }

  .enemy-modal .btn-small {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Bônus no painel do herói (v0.132): atributo com o bônus de agora entre parênteses e a lista de quem está bonificando. O sinal vai
   no texto; a cor só reforça (verde melhora, rosa piora). */
.stat-bonus { font-weight: 600; }
.stat-bonus.is-up { color: var(--ok); }
.stat-bonus.is-down { color: var(--danger); }

.unit-bonuses {
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-s);
  background: var(--surface-2);
}

.unit-bonuses[hidden] { display: none; }

.unit-map-bonus-text {
  margin: 0;
  font-size: var(--fs-13);
}

.unit-bonuses-title {
  margin: 0 0 var(--s-1);
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--text-2);
}

.unit-bonus-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.unit-bonus {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 var(--s-3);
  font-size: var(--fs-13);
}

.unit-bonus-label { font-weight: 600; }
.unit-bonus-time { color: var(--text-2); text-align: right; }
.unit-bonus-value { grid-column: 1 / -1; }
.unit-bonus-from { grid-column: 1 / -1; display: flex; align-items: center; gap: var(--s-2); margin-top: 2px; color: var(--text-2); font-size: var(--fs-12); }

/* Celular: o painel do herói rola por dentro, então os atributos e os bônus ativos sobem para logo abaixo dos botões de nível e venda,
   e o papel, as regras, a mira e o desempenho da onda descem (v0.132). */
@media (max-width: 600px) {
  #unit-modal .unit-role,
  #unit-modal .unit-mech-group,
  #unit-modal .unit-aim,
  #unit-modal .unit-perf {
    order: 1;
  }
}
