/* Jugue translations can be longer than the original Liceo labels.
   Keep complete text in flow; never let a badge paint over a neighbouring card. */
#screen-home .launch-text .game-age-badge {
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
  flex-shrink: 0;
}

#screen-home .game-cards {
  grid-auto-rows: minmax(min-content, 1fr);
  max-height: none;
}

#screen-home .game-launch-card {
  min-height: min-content;
}

/* A shrinking flex stats group still paints its non-shrinking children outside
   its box. Explicit rows reserve space for every control and every statistic.
   Wide/landscape screens keep the original compact one-row HUD. */
@media (max-width: 519px) {
  :is(#screen-bubble, #screen-tetris) > .hud-bar {
    display: grid;
    grid-template-columns: 44px 44px minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 6px;
    align-items: center;
  }

  :is(#screen-bubble, #screen-tetris) > .hud-bar > .hud-back {
    grid-column: 1;
    grid-row: 1;
    min-width: 44px;
  }

  :is(#screen-bubble, #screen-tetris) > .hud-bar > .hud-actions {
    display: contents;
  }

  :is(#screen-bubble, #screen-tetris) .hud-pause {
    grid-column: 2;
    grid-row: 1;
    min-width: 44px;
  }

  :is(#screen-bubble, #screen-tetris) .hud-speaker {
    grid-column: 3;
    grid-row: 1;
    min-width: 0;
    min-height: 46px;
    padding: 6px 10px;
    white-space: normal;
  }

  :is(#screen-bubble, #screen-tetris) .hud-speaker span {
    display: inline;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  :is(#screen-bubble, #screen-tetris) > .hud-bar > .hud-stats {
    grid-column: 1 / -1;
    grid-row: 2;
    flex-wrap: wrap;
    justify-content: center;
    gap: 5px;
  }

  /* The three public flight games share this header. Keep the counters between
     navigation and a compact replay button, so the stage gets the second row back. */
  #screen-bubble > .hud-bar {
    grid-template-columns: 44px 44px minmax(0, 1fr) fit-content(7rem);
    grid-template-rows: auto;
    gap: 3px;
  }

  #screen-bubble > .hud-bar > .hud-stats {
    grid-column: 3;
    grid-row: 1;
    flex-wrap: wrap;
    gap: 2px;
  }

  #screen-bubble .stat-pill {
    padding: 4px;
    font-size: 0.75rem;
  }

  #screen-bubble .hud-speaker {
    grid-column: 4;
    justify-self: end;
    width: fit-content;
    min-width: 44px;
    max-width: 7rem;
    padding: 4px 6px;
    gap: 3px;
    font-size: 0.75rem;
    line-height: 1.15;
    flex-wrap: wrap;
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: manual;
    -webkit-hyphens: manual;
  }

  #screen-bubble .hud-speaker span {
    display: inline;
    min-width: min-content;
    max-width: 100%;
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
    hyphens: manual;
    -webkit-hyphens: manual;
  }

  /* At enlarged text sizes, preserve complete counters and reachable controls
     rather than forcing enlarged text into the normal-size single row. */
  @container (max-width: 16rem) {
    #screen-bubble > .hud-bar > .hud-stats {
      grid-column: 1 / -1;
      grid-row: 2;
      flex-wrap: wrap;
    }

    #screen-bubble .hud-speaker {
      grid-column: 3 / -1;
      max-width: 100%;
    }
  }
}

@media (max-width: 359px) {
  #screen-bubble > .hud-bar { gap: 2px; }
  #screen-bubble .hud-speaker span {
    display: inline;
    min-width: min-content;
    font-size: 0.75rem;
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
  }
  #screen-bubble .stat-pill { padding: 4px 1px; border-width: 1px; font-size: 0.6875rem; }
}

/* Before a solo flight, the hidden pause and replay controls leave balanced
   space on both sides of the counters. Live duel and playing headers keep their layout. */
#screen-bubble:not(.duel-integrated) > .hud-bar:has(#bubble-pause[hidden]):has(#bubble-replay[hidden]) {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  grid-template-rows: auto;
  align-items: center;
}

#screen-bubble:not(.duel-integrated) > .hud-bar:has(#bubble-pause[hidden]):has(#bubble-replay[hidden]) > .hud-back {
  grid-column: 1;
  grid-row: 1;
}

#screen-bubble:not(.duel-integrated) > .hud-bar:has(#bubble-pause[hidden]):has(#bubble-replay[hidden]) > .hud-stats {
  grid-column: 2;
  grid-row: 1;
  justify-content: center;
  flex-wrap: wrap;
}

#screen-bubble:not(.duel-integrated) > .hud-bar:has(#bubble-pause[hidden]):has(#bubble-replay[hidden]) > .hud-actions {
  display: none;
}

/* styles.css hides these words on a short wide header once enlarged text narrows it. */
@media (min-width: 520px) and (max-height: 520px) {
  @container (max-width: 31rem) {
    #screen-bubble > .hud-bar .hud-speaker {
      min-width: 44px;
      min-height: 44px;
      max-width: 100%;
      flex-wrap: wrap;
      white-space: normal;
      overflow: visible;
      overflow-wrap: normal;
      word-break: normal;
      hyphens: manual;
      -webkit-hyphens: manual;
    }

    #screen-bubble > .hud-bar .hud-speaker span {
      display: inline;
      min-width: min-content;
      max-width: 100%;
      white-space: normal;
      overflow: visible;
      overflow-wrap: normal;
      word-break: normal;
      hyphens: manual;
      -webkit-hyphens: manual;
    }
  }
}
