/* Fundo da aba Batalha: o mapa em pixel art do mundo escolhido, escurecido por uma película
   quase opaca para os cartões e os títulos continuarem legíveis. Fica atrás de tudo, e o
   cabeçalho (fundo próprio e opaco) o cobre. Troca de mundo = fade cruzado entre duas camadas. */
#lobby-screen {
  isolation: isolate;
}

.stage-backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 500ms ease;
}

.stage-backdrop.active {
  opacity: 1;
}

.stage-backdrop-layer {
  position: absolute;
  inset: 0;
  background-position: center;
  background-size: cover;
  opacity: 0;
  transition: opacity 700ms ease;
}

.stage-backdrop-layer.on {
  opacity: 1;
}

.stage-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(to bottom, rgb(14 16 21 / 0.78), rgb(14 16 21 / 0.9)),
    rgb(14 16 21 / 0.2);
}

/* Só a aba Batalha mostra o fundo. */
#lobby-screen:not(:has(#tab-play.active)) .stage-backdrop {
  opacity: 0;
}

.lobby-header,
.lobby-content {
  position: relative;
  z-index: 1;
}

/* Cabeçalho do lobby em duas linhas desde a v0.237: em cima o logo e, à direita, a conta, o online, os saldos e o Som; embaixo os
   itens do menu dividindo a largura toda. Numa linha só (v0.236 e antes) o conjunto passava de 2.000 px e cortava as moedas.
   Desde a v0.272 são cinco itens, e Batalha, Loja e Perfil ganham uma terceira linha com o submenu do grupo. */
.lobby-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: var(--s-4);
  row-gap: var(--s-2);
  padding: var(--s-2) var(--s-5);
  border-bottom: 1px solid var(--line);
  background: var(--surface-1);
}

.brand-name {
  display: flex;
  align-items: center;
  font-size: var(--fs-20);
  white-space: nowrap;
}

/* Pixel art em SVG: 22 unidades de altura, então 44 px dão exatamente 2 px por unidade. */
.brand-logo {
  display: block;
  flex: none;
  max-width: none;
  height: 44px;
  width: auto;
  image-rendering: pixelated;
}

.lobby-nav {
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  gap: 6px;
}

/* Abas em botão de fliperama (pixel art, 2 px por unidade como o logo): a moldura vem de SVG 9-slice
   gerado por scratch/gerar_bordas_cabecalho.py. A tecla é alta com base grossa; a aba ativa afunda 2 px. */
.nav-tab {
  min-height: 44px;
  padding: 0 10px;
  border: solid transparent;
  border-width: 4px 4px 6px;
  border-image: url("../assets/ui/abas/normal.svg") 4 4 5 4 / 8px 8px 10px 8px stretch;
  border-radius: 0;
  background: linear-gradient(180deg, #3B4252, #313744);
  background-clip: padding-box;
  color: var(--text-2);
  font-weight: 600;
  font-size: var(--fs-16);
  white-space: nowrap;
  flex: 1 1 0;
}

.nav-tab:hover {
  border-image-source: url("../assets/ui/abas/hover.svg");
  background: linear-gradient(180deg, #4A5265, #3C4455);
  background-clip: padding-box;
  color: var(--text);
}

.nav-tab.active,
.nav-tab.active:hover {
  border-width: 6px 4px 4px;
  border-image: url("../assets/ui/abas/ativa.svg") 5 4 4 4 / 10px 8px 8px 8px stretch;
  background: linear-gradient(180deg, var(--sel-bg-top), var(--sel-bg-bottom));
  background-clip: padding-box;
  color: var(--sel-ink);
}

/* Submenu do grupo aberto (v0.272): teclas menores no centro, sobre uma calha escura que liga a linha ao item ativo de cima.
   A moldura e o roxo de escolhido vêm do grupo das teclas (25-jogo.css e 20-selecao.css). Some quando o grupo não tem submenu. */
.lobby-subnavs {
  grid-column: 1 / -1;
  grid-row: 3;
  margin-inline: calc(var(--s-5) * -1);
  padding: 6px var(--s-5);
  border-top: 2px solid #1A0B2E;
  background: #12151D;
}

.lobby-subnavs:not(:has(.lobby-subnav:not([hidden]))) {
  display: none;
}

.lobby-subnav {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.lobby-subnav[hidden] {
  display: none;
}

.nav-sub {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 168px;
  min-height: 44px;
  padding: 0 14px;
  white-space: nowrap;
}

.wallet,
.wallet-items {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.wallet {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
}

/* Caixinha de cada moeda: visor afundado em pixel art (9-slice de scratch/gerar_icones_moedas.py, 2 px por
   unidade como as abas), ícone de 24 px (12 unidades) e o valor. O centro do SVG estica pelo `fill`. */
.wallet-item {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 10px 0 6px;
  border: 4px solid transparent;
  border-image: url("../assets/ui/moedas/caixa.svg") 2 fill / 4px stretch;
  border-radius: 0;
  line-height: 1;
  cursor: default;
}

.wallet-coin {
  width: 24px;
  height: 24px;
}

.wallet-item strong {
  font-family: var(--font-display);
  font-size: var(--fs-20);
  font-weight: 700;
  color: var(--text);
}

.lobby-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.tab-pane {
  display: none;
  padding: var(--s-5);
  max-width: 1600px;
  margin: 0 auto;
}

.tab-pane.active {
  display: block;
}

.text-link {
  color: var(--text);
  text-decoration: underline;
  text-underline-offset: 3px;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
}

/* Aba Batalha: escolhas à esquerda, resumo da partida à direita (foco: Entrar na batalha). */
.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: var(--s-5);
  align-items: start;
}

.play-setup {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}

.setup-block {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.setup-title {
  font-size: var(--fs-16);
  color: var(--text-2);
  font-family: var(--font-body);
  font-weight: 600;
}

.setup-title-row {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  flex-wrap: wrap;
}

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

.mode-select-card,
.stage-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s-1);
  padding: var(--s-4);
  border-radius: var(--radius-m);
  border: 1px solid var(--line);
  background: var(--surface-1);
  text-align: left;
  transition: border-color var(--t-fast), background var(--t-fast);
}

.mode-select-card:hover,
.stage-card:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.mode-select-card {
  position: relative;
}

.mode-select-card.active {
  border-color: var(--text);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--text);
}

.mode-select-card.active::after,
.diff-chip.active .diff-name::before {
  content: '✓';
  font-weight: 700;
}

.mode-select-card.active::after {
  position: absolute;
  top: var(--s-3);
  right: var(--s-3);
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-s);
  background: var(--text);
  color: var(--action-ink);
  font-size: var(--fs-13);
}

.diff-chip.active .diff-name::before {
  margin-right: var(--s-1);
}

.briefing-team.training .text-link {
  display: none;
}

.mode-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--fs-20);
}

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

.mode-meta {
  margin-top: auto;
  padding-top: var(--s-2);
  font-size: var(--fs-13);
  font-weight: 600;
}

/* Mundo: a cor do universo aparece no mundo selecionado. */
.stage-list {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--s-3);
}

.stage-card {
  position: relative;
  min-height: 112px;
}

/* v0.268.0: só os cartões do mundo escolhido aparecem. */
.stage-card[hidden],
.world-switch[hidden] {
  display: none;
}

/* Seletor Mundo 1 / Mundo 2, ao lado do título. */
.world-switch {
  display: inline-flex;
  gap: var(--s-2);
}

.stage-anime {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  font-size: var(--fs-12);
  color: var(--text-2);
  font-weight: 600;
}

.stage-card-name {
  font-family: var(--font-display);
  font-size: var(--fs-16);
  font-weight: 700;
  line-height: 1.2;
}

.stage-card-loc {
  color: var(--text-2);
  font-size: var(--fs-13);
  line-height: 1.3;
}

.stage-card-phase,
.stage-card-place {
  display: block;
}

.stage-card-phase {
  font-weight: 600;
}

.stage-card.active {
  border-color: var(--universe);
  background: color-mix(in srgb, var(--universe) 14%, var(--surface-1));
  box-shadow: inset 0 0 0 1px var(--universe);
}

.stage-card.active .stage-anime {
  color: var(--text);
}

.stage-card.locked {
  background: var(--surface-1);
  border-style: dashed;
}

.stage-card.locked .stage-card-name {
  color: var(--text-2);
}

.stage-card.locked .universe-swatch {
  opacity: 0.5;
}

.stage-card-lock-overlay {
  margin-top: auto;
  padding-top: var(--s-2);
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--text-2);
}

.stage-card-new {
  position: absolute;
  top: var(--s-2);
  right: var(--s-2);
  padding: 2px var(--s-2);
  border-radius: 999px;
  font-size: var(--fs-12);
  font-weight: 700;
  color: var(--action-ink);
  background: var(--universe, var(--ok));
}

.stage-card-record {
  position: absolute;
  top: var(--s-2);
  right: var(--s-2);
  padding: 2px var(--s-2);
  border-radius: 999px;
  font-size: var(--fs-12);
  font-weight: 700;
  color: var(--text);
  background: var(--bg);
  box-shadow: 0 0 0 1px var(--universe, var(--ok));
}

.difficulty-req-hint {
  font-size: var(--fs-13);
  color: var(--danger);
}

.difficulty-req-hint.flash {
  animation: hint-shake 0.3s ease;
}

@keyframes hint-shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

#difficulty-selection-box {
  flex-direction: column;
}

.difficulty-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
}

.diff-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 120px;
  min-height: 52px;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--radius-m);
  border: 1px solid var(--line-strong);
  background: var(--surface-1);
  text-align: left;
}

.diff-chip:hover {
  background: var(--surface-2);
}

.diff-name {
  font-weight: 600;
}

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

.diff-chip.active {
  border-color: var(--text);
  background: var(--surface-3);
  box-shadow: inset 0 0 0 1px var(--text);
}

.diff-chip.locked {
  border-style: dashed;
}

.diff-chip.locked .diff-name {
  color: var(--text-2);
}

/* Resumo da partida. */
.briefing {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  padding: var(--s-5);
  border-radius: var(--radius-l);
  border: 1px solid var(--line);
  background: var(--surface-1);
}

.briefing-tag {
  font-size: var(--fs-13);
  color: var(--text-2);
  font-weight: 600;
}

.briefing-title {
  font-size: var(--fs-32);
  margin-top: calc(var(--s-3) * -1);
}

.briefing-desc {
  color: var(--text-2);
}

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

/* Quinta linha (Infinito, v0.256): ocupa a largura toda em vez de ficar sozinha na coluna da esquerda. */
.briefing-stats > div:nth-child(5) {
  grid-column: 1 / -1;
}

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

.briefing-stats dd {
  font-size: var(--fs-16);
}

/* Itens possíveis (v0.129): ícone, nome e chance por vitória, em grade de células iguais. A cor do cristal vem do universo do mundo. */
.briefing-drops[hidden] {
  display: none;
}

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

/* v0.220: o bloco inteiro vem recolhido (só o título) e abre ao clicar, como as faixas do Infinito; o título é o botão (toque de 44 px). */
.briefing-drops-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 44px;
  cursor: pointer;
  list-style: none;
}

.briefing-drops-head::-webkit-details-marker {
  display: none;
}

.briefing-drops-head::before {
  content: '';
  flex: none;
  width: 0;
  height: 0;
  border-left: 6px solid var(--text-2);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  transition: transform 0.15s;
}

.briefing-drops-fold[open] > .briefing-drops-head::before {
  transform: rotate(90deg);
}

.drop-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: var(--s-2);
  margin-top: var(--s-2);
}

.drop-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--s-2);
  text-align: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--surface-2);
}

.drop-name {
  font-size: var(--fs-12);
  line-height: 1.2;
  color: var(--text-2);
  overflow-wrap: anywhere;
}

.drop-chance {
  font-size: var(--fs-16);
}

.briefing-team-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-2);
  margin-bottom: var(--s-2);
}

.briefing-team-head h3 {
  font-family: var(--font-body);
  font-size: var(--fs-14);
  font-weight: 600;
}

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

.briefing-team.training .preview-cards-row {
  display: none;
}

.preview-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.preview-card .mini-portrait {
  width: 100%;
}

.preview-card .hero-nm {
  font-size: var(--fs-12);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-card .hero-cst {
  font-size: var(--fs-12);
  color: var(--text-2);
}

.preview-card.empty .mini-portrait {
  border-style: dashed;
  background: transparent;
}

.btn-launch {
  min-height: 56px;
  font-size: var(--fs-16);
  white-space: normal;
  text-align: center;
}

/* Janela média: as cinco abas seguem numa fileira (eram nove em grade de cinco colunas até a v0.270). */
@media (max-width: 1219px) {
  .lobby-header {
    padding-inline: var(--s-4);
  }

  .lobby-subnavs {
    margin-inline: calc(var(--s-4) * -1);
    padding-inline: var(--s-4);
  }

  /* Linha de cima mais justa: com milhões de pó, as três caixinhas e a conta precisam caber ao lado do logo. */
  .wallet,
  .wallet-items {
    gap: 6px;
  }

  .wallet-item {
    gap: 4px;
    padding: 0 6px 0 4px;
  }

  .wallet-item strong {
    font-size: var(--fs-16);
  }
}

@media (max-width: 1240px) {
  .tab-pane {
    padding: var(--s-4);
  }

  .play-layout {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
    gap: var(--s-4);
  }

  .stage-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  /* Tablet retrato e celular: o logo e o Som ficam na primeira linha, as três caixinhas dividem a segunda e
     as abas vão para a terceira. Assim valores grandes (milhões de pó) cabem sem cortar; numa tela
     muito estreita a caixinha que não couber desce de linha. */
  .wallet {
    display: contents;
  }

  .mute-btn {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  .wallet-items {
    grid-column: 1 / -1;
    grid-row: 2;
    flex-wrap: wrap;
    gap: 6px;
  }

  /* As caixinhas dividem a linha, mas a do valor mais longo cresce mais. */
  .wallet-item {
    flex: 1 1 auto;
    justify-content: center;
    gap: 4px;
    padding: 0 6px 0 4px;
  }

  .wallet-coin {
    width: 20px;
    height: 20px;
  }

  .wallet-item strong {
    font-size: var(--fs-16);
  }

  .lobby-nav {
    grid-row: 3;
  }

  .lobby-subnavs {
    grid-row: 4;
  }
}

/* Tablet retrato e janelas estreitas: tudo em uma coluna. */
@media (max-width: 900px) {
  .play-layout {
    grid-template-columns: 1fr;
  }

  .briefing {
    position: static;
  }

  .mode-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .stage-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--s-2);
  }

  .stage-card {
    min-height: 96px;
    padding: var(--s-3);
  }

  .lobby-header {
    column-gap: var(--s-2);
    padding-inline: var(--s-3);
  }

  .brand-logo {
    height: 33px;
  }

  .wallet-items {
    gap: 4px;
  }

  .wallet-item {
    gap: 3px;
    padding: 0 4px 0 3px;
  }

  .wallet-coin {
    width: 18px;
    height: 18px;
  }

  .wallet-item strong {
    font-size: var(--fs-14);
  }

  /* Celular: as cinco abas numa fileira, com o ícone em cima do nome para caber "Taverna" em 360 px. */
  .lobby-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    overflow-x: visible;
  }

  .nav-tab {
    flex-direction: column;
    gap: 2px;
    min-height: 52px;
    padding: 2px 2px 0;
    font-size: var(--fs-13);
  }

  .lobby-subnavs {
    margin-inline: calc(var(--s-3) * -1);
    padding-inline: var(--s-3);
  }

  /* Submenu numa fileira só, em partes iguais; as lojas viram "Moeda" e "Raid", já que estão embaixo de Loja. */
  .lobby-subnav {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 4px;
  }

  .nav-sub {
    min-width: 0;
    padding: 0 4px;
    font-size: 14px;
  }

  .nav-sub-pre {
    display: none;
  }
}

/* Itens possíveis do Infinito (v0.180): uma linha por faixa de 20 ondas, com a cor da dificuldade na borda. */
.drop-band {
  list-style: none;
  grid-column: 1 / -1;
  padding: var(--s-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--dc, var(--line));
  border-radius: var(--radius-m);
  background: var(--surface-2);
}

.drop-band-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s-1) var(--s-2);
  font-size: var(--fs-12);
  color: var(--text-2);
}

.drop-band-head strong {
  font-size: var(--fs-14);
  color: var(--dc, var(--text));
}

/* Faixa recolhida: o cabeçalho é o botão (área de toque de 44 px), com a seta antes do título. */
.drop-band summary.drop-band-head {
  align-items: center;
  min-height: 44px;
  padding: 0 var(--s-1);
  cursor: pointer;
  list-style: none;
}

.drop-band summary.drop-band-head::-webkit-details-marker {
  display: none;
}

.drop-band summary.drop-band-head::before {
  content: '';
  flex: none;
  width: 0;
  height: 0;
  border-left: 6px solid var(--dc, var(--text-2));
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  transition: transform 0.15s;
}

.drop-band details[open] > summary.drop-band-head::before {
  transform: rotate(90deg);
}

.drop-band summary.drop-band-head strong {
  margin-right: auto;
}

.drop-band-note {
  margin-top: 2px;
  font-size: var(--fs-12);
  color: var(--text-2);
}

.drop-band-list {
  margin-top: var(--s-1);
}

.drop-band .drop-item {
  background: transparent;
}

/* v0.320: .setup-block é flex e passava por cima do atributo hidden (o "Mundo da Raid" aparecia em todos os modos). */
.setup-block[hidden] {
  display: none;
}

/* v0.320: seletor de mundo no alto da aba Batalha, antes do Modo, com o ícone do banner de cada mundo. */
.world-pick {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
}

.world-pick-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  min-height: 48px;
  padding: var(--s-2) var(--s-5) var(--s-2) var(--s-3);
  border-radius: var(--radius-m);
  border: 1px solid var(--line);
  background: var(--surface-1);
  font-family: var(--font-display);
  font-size: var(--fs-16);
  font-weight: 700;
  transition: border-color var(--t-fast), background var(--t-fast);
}

.world-pick-btn:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.world-pick-btn.active {
  border-color: var(--text);
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--text);
}

@media (max-width: 600px) {
  .world-pick {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .world-pick-btn {
    justify-content: center;
    padding-right: var(--s-3);
  }
}
