/* V56: painted containers own their text layout and safe areas. */

@media (min-width: 721px) and (min-height: 500px) {
  .game-shell.phase-playing .topbar,
  .game-shell.phase-training .topbar {
    top: 4px;
    width: min(92%, 920px);
    height: 94px;
    padding: 0;
    grid-template-columns: minmax(0, 1fr) 154px;
    grid-template-rows: 52px 42px;
    gap: 0 8px;
    align-items: start;
    overflow: visible;
    background: none;
  }

  .game-shell.phase-playing .hud,
  .game-shell.phase-training .hud {
    grid-column: 1;
    grid-row: 1;
    box-sizing: border-box;
    width: min(459px, 100%);
    height: 52px;
    min-height: 52px;
    margin: 0;
    padding: 5px 46px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    justify-self: center;
    align-self: start;
    overflow: hidden;
    aspect-ratio: 1960 / 222;
    background: transparent url("../assets/meowa/ui/hud-plaque-v10.png") center / 100% 100% no-repeat;
  }

  .game-shell.phase-playing .pill,
  .game-shell.phase-training .pill {
    position: relative;
    box-sizing: border-box;
    width: auto;
    height: 42px;
    min-width: 0;
    min-height: 42px;
    padding: 5px 3px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    overflow: hidden;
    background: none !important;
    color: #432631;
    font: 1000 15px/1 var(--ui);
    text-align: center;
    text-shadow: 0 1px #f9e4b4;
  }

  /* Older character passes targeted `.hud .pill`; match that specificity here. */
  .game-shell.phase-playing .hud .pill,
  .game-shell.phase-training .hud .pill {
    box-sizing: border-box;
    width: auto;
    height: 42px;
    min-height: 42px;
    padding: 5px 3px 4px;
    overflow: hidden;
    background: none !important;
    font-size: 15px;
  }

  .game-shell.phase-playing .pill::before,
  .game-shell.phase-training .pill::before {
    content: attr(data-label);
    position: static;
    inset: auto;
    width: auto;
    flex: 0 0 auto;
    color: #76503a;
    font: 900 9px/1 var(--ui);
    letter-spacing: .02em;
    text-align: center;
    transform: none;
  }

  .game-shell.phase-playing .hud .pill::before,
  .game-shell.phase-training .hud .pill::before {
    position: static;
    inset: auto;
    width: auto;
    font-size: 9px;
    line-height: 1;
    transform: none;
  }

  .game-shell.phase-playing .pill b,
  .game-shell.phase-training .pill b,
  .game-shell.phase-playing .pill.timer,
  .game-shell.phase-training .pill.timer {
    font-size: 15px;
    line-height: 1;
  }

  .game-shell.phase-playing .hud .pill b,
  .game-shell.phase-training .hud .pill b {
    font-size: 15px;
    line-height: 1;
  }

  .game-shell.phase-playing .top-actions,
  .game-shell.phase-training .top-actions {
    position: static;
    grid-column: 2;
    grid-row: 1;
    width: 154px;
    height: 44px;
    margin: 4px 0 0;
    align-self: start;
  }

  .game-shell.phase-playing .hud-subline,
  .game-shell.phase-training .hud-subline {
    position: relative;
    inset: auto;
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    height: 42px;
    min-height: 42px;
    padding: 0;
    display: block;
    overflow: visible;
  }

  .game-shell.phase-playing .shift-brief,
  .game-shell.phase-training .shift-brief {
    position: absolute;
    z-index: 2;
    top: 0;
    left: 50%;
    box-sizing: border-box;
    width: min(360px, calc(100% - 310px));
    height: 41px;
    min-height: 41px;
    margin: 0;
    padding: 5px 34px 6px;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 34px;
    grid-template-rows: 24px 3px;
    align-items: center;
    gap: 1px 7px;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: transparent url("../assets/meowa/ui/hud-plaque-v10.png") center / 100% 100% no-repeat;
    box-shadow: none;
    transform: translateX(-50%);
  }

  .game-shell.phase-playing .hud-subline .shift-act,
  .game-shell.phase-training .hud-subline .shift-act,
  .game-shell.phase-playing .hud-subline .shift-copy,
  .game-shell.phase-training .hud-subline .shift-copy,
  .game-shell.phase-playing .hud-subline .shift-count,
  .game-shell.phase-training .hud-subline .shift-count {
    position: static;
    inset: auto;
    box-sizing: border-box;
    margin: 0;
    transform: none;
  }

  .game-shell.phase-playing .hud-subline .shift-act,
  .game-shell.phase-training .hud-subline .shift-act {
    min-width: 0;
    padding: 0;
    display: block;
    overflow: hidden;
    color: #7a3f36;
    font: 900 8px/1.1 var(--ui);
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .game-shell.phase-playing .hud-subline .shift-copy,
  .game-shell.phase-training .hud-subline .shift-copy {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    overflow: hidden;
    white-space: nowrap;
  }

  .game-shell.phase-playing .hud-subline .shift-copy strong,
  .game-shell.phase-training .hud-subline .shift-copy strong {
    flex: 0 0 auto;
    font-size: 11px;
    line-height: 1;
  }

  .game-shell.phase-playing .hud-subline .shift-copy > span:not(.stage-reward),
  .game-shell.phase-training .hud-subline .shift-copy > span:not(.stage-reward) {
    min-width: 0;
    display: block;
    overflow: hidden;
    color: #6b3d36;
    font-size: 8px;
    line-height: 1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .game-shell.phase-playing .hud-subline .shift-count,
  .game-shell.phase-training .hud-subline .shift-count {
    color: #7c3044;
    font: 1000 10px/1 var(--ui);
    text-align: center;
    white-space: nowrap;
  }

  .game-shell.phase-playing .hud-subline .shift-track,
  .game-shell.phase-training .hud-subline .shift-track {
    grid-column: 1 / -1;
    width: 100%;
    height: 3px;
    align-self: end;
  }

  .game-shell.phase-playing .stage-reward,
  .game-shell.phase-training .stage-reward {
    display: none !important;
  }

  .game-shell.phase-playing .hud-subline .combo-stat,
  .game-shell.phase-training .hud-subline .combo-stat,
  .game-shell.phase-playing .hud-subline .currency-stat,
  .game-shell.phase-training .hud-subline .currency-stat {
    position: absolute;
    top: 8px;
    box-sizing: border-box;
    min-width: 72px;
    min-height: 25px;
    padding: 4px 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border: 1px solid #a97942;
    border-radius: 999px;
    background: rgb(18 42 50 / 92%);
    color: #fff0c8;
    font: 900 10px/1 var(--ui);
    text-shadow: 0 1px 2px #09060c;
  }

  .game-shell.phase-playing .hud-subline .combo-stat,
  .game-shell.phase-training .hud-subline .combo-stat { right: 84px; }

  .game-shell.phase-playing .hud-subline .currency-stat,
  .game-shell.phase-training .hud-subline .currency-stat { right: 0; }

  .game-shell.phase-playing .contract-chip,
  .game-shell.phase-training .contract-chip {
    position: absolute;
    z-index: 14;
    right: 18px;
    bottom: 18px;
    left: auto;
    box-sizing: border-box;
    width: 156px;
    height: 44px;
    min-height: 44px;
    margin: 0;
    padding: 5px 10px;
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 6px;
    overflow: hidden;
    background-position: center;
    background-size: 100% 100%;
  }

  .game-shell.phase-playing .contract-chip img,
  .game-shell.phase-training .contract-chip img {
    width: 30px;
    height: 30px;
  }

  .game-shell.phase-playing .contract-chip span,
  .game-shell.phase-training .contract-chip span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .purchase-dock .supply-tools {
    min-height: 32px;
    margin-top: 5px;
  }

  .purchase-dock .cargo-refresh,
  .purchase-dock .recycle {
    box-sizing: border-box;
    height: 32px;
    min-height: 32px;
    padding-block: 4px;
    overflow: hidden;
  }
}

@media (min-width: 721px) and (min-height: 500px) and (max-aspect-ratio: 3 / 2) {
  .game-shell.phase-playing .topbar,
  .game-shell.phase-training .topbar {
    width: 92%;
  }

  .game-shell.phase-playing .shift-brief,
  .game-shell.phase-training .shift-brief {
    left: 50%;
    width: min(360px, calc(100% - 300px));
  }
}

@media (max-width: 720px) and (orientation: portrait) {
  .game-shell.phase-playing .hud,
  .game-shell.phase-training .hud {
    box-sizing: border-box;
    width: min(286px, calc(100% - 94px));
    height: 40px;
    min-height: 40px;
    margin-left: 4px;
    padding: 3px 27px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    overflow: hidden;
    background: transparent url("../assets/meowa/ui/hud-plaque-v10.png") center / 100% 100% no-repeat;
  }

  .game-shell.phase-playing .pill,
  .game-shell.phase-training .pill {
    height: 34px;
    min-height: 34px;
    padding: 4px 1px 3px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    overflow: hidden;
    background: none !important;
    font-size: 11px;
  }

  .game-shell.phase-playing .pill::before,
  .game-shell.phase-training .pill::before {
    position: static;
    inset: auto;
    font-size: 7px;
    line-height: 1;
    transform: none;
  }

  .game-shell.phase-playing .shift-brief,
  .game-shell.phase-training .shift-brief {
    top: 44px;
    left: 7px;
    box-sizing: border-box;
    width: 270px;
    height: 31px;
    min-height: 31px;
    padding: 3px 25px 4px;
    grid-template-columns: 34px minmax(0, 1fr) 30px;
    grid-template-rows: 18px 3px;
    gap: 1px 4px;
    overflow: hidden;
    background-size: 100% 100%;
    transform: none;
  }

  .game-shell.phase-playing .stage-reward,
  .game-shell.phase-training .stage-reward { display: none !important; }
}

@media (max-height: 430px) and (orientation: landscape) {
  .game-shell.phase-playing .shift-brief,
  .game-shell.phase-training .shift-brief {
    top: -4px;
    left: 50%;
    box-sizing: border-box;
    width: 270px;
    height: 31px;
    min-height: 31px;
    padding: 3px 25px 4px;
    grid-template-columns: 34px minmax(0, 1fr) 30px;
    grid-template-rows: 18px 3px;
    overflow: hidden;
    background-size: 100% 100%;
    transform: translateX(-50%);
  }

  .game-shell.phase-playing .stage-reward,
  .game-shell.phase-training .stage-reward { display: none !important; }
}
