/* Title footer fits any screen width: the start prompt, the continue line and the controls hint wrap inside the
   screen (with the notch insets) instead of running off both edges on narrow / upright phones. */
#titleBottom {
  box-sizing: border-box;
  width: max-content;
  max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
}
#titleBottom > * {
  box-sizing: border-box;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}
#pressStart,
#kbHint,
#contTxt {
  white-space: normal;
  overflow-wrap: anywhere;
  text-align: center;
  text-wrap: balance;
}
#kbHint { line-height: 1.4; }
#contInfo {
  white-space: normal;
  flex-wrap: wrap;
  justify-content: center;
  text-align: center;
}

/* ---------- upright phones: every screen re-laid for a narrow, tall page ---------- */
@media (orientation: portrait) and (max-width: 600px) {
  /* title: the portrait key art (the lobby cover), the logo below the trophy button */
  #titleBg { background-image: url("assets/cover-bg.webp"); background-position: center top; }
  #titleLogo { top: calc(74px + env(safe-area-inset-top, 0px)); width: min(84vw, 520px); max-height: 24vh; }
  #kbHint { font-size: 13px; }

  /* HUD: stats top-left, timer + cores top-right under the pause button, boss bar beside the stats,
     quests in a full-width row below */
  #hudLeft { top: 16px; padding: 6px 10px; gap: 5px; }
  #hudLeft .bar { width: 104px; height: 15px; }
  #hudLeft .bar.small { width: 58px; height: 11px; }
  #hudLeft .num { font-size: 17px; min-width: 30px; }
  #loadout { max-width: 176px; }
  .slot { width: 26px; height: 26px; }
  #hudCenter {
    left: auto; right: calc(12px + env(safe-area-inset-right, 0px)); top: 62px;
    transform: none; align-items: flex-end;
  }
  #topRow { flex-direction: column; align-items: flex-end; gap: 4px; }
  #timer { font-size: 18px; }
  #fragBox { padding: 3px 12px; gap: 8px; }
  #bossBar { align-items: flex-end; }
  #bossName { font-size: 14px; max-width: 40vw; text-align: right; }
  .bar.boss { width: 40vw; height: 14px; }
  #quests {
    top: 178px; left: calc(12px + env(safe-area-inset-left, 0px)); right: auto;
    max-width: calc(100vw - 24px); align-items: flex-start;
  }
  #quests .qi { font-size: 14px; }
  #region { top: 31%; }
  #region .rgName { font-size: 24px; letter-spacing: .04em; }
  #region .rgName::before, #region .rgName::after { width: .9em; margin: 0 .35em; }
  #subtitle { top: 37%; max-width: 88vw; font-size: 16px; }
  #hint { top: 45%; max-width: 88vw; font-size: 15px; }
  #banner { font-size: 26px; white-space: normal; text-align: center; width: max-content; max-width: 90vw; }

  /* level up: the three cards stacked, each a wide row */
  #levelUp { justify-content: flex-start; padding-top: max(56px, 13vh); overflow-y: auto; }
  #luTitle { font-size: 34px; }
  #luCards { flex-direction: column; align-items: center; gap: 8px; width: 100%; }
  .card {
    width: min(92vw, 380px); min-height: 0; border-width: 18px; padding: 2px 4px;
    display: grid; grid-template-columns: 56px 1fr; column-gap: 10px; row-gap: 2px;
    align-items: center; text-align: left;
  }
  .card img { grid-row: 1 / span 4; width: 56px; height: 56px; }
  .card .cname { font-size: 16px; }
  .card .cdesc { font-size: 13px; }
  .card .pips { margin-top: 2px; }

  /* the adventure log: the list on top, the page below; the tab labels wrap onto two lines */
  #jrPanel { width: 96vw; height: 90vh; border-width: 16px; gap: 6px; }
  #jrHead { gap: 6px; }
  #jrTabs { gap: 4px; }
  .gbtn.jrTab {
    font-size: 12px; padding: 2px 3px; min-height: 46px; line-height: 1.15;
    white-space: normal; text-overflow: clip; overflow-wrap: normal; word-break: keep-all;
  }
  .gbtn#jrClose { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
  #jrBody { grid-template-columns: 1fr; grid-template-rows: minmax(0, 38%) minmax(0, 1fr); gap: 8px; }
  #jrBody:has(#jrList.emptyList) { grid-template-rows: 1fr; }
  #jrDetail { border-left: 0; border-top: 2px solid rgba(255, 217, 138, .25); padding: 6px 4px 4px; font-size: 15px; }
  #jrBody:has(#jrList.emptyList) #jrDetail { border-top: 0; }
  #jrDetail h3 { font-size: 20px; }
  .jdIcon { width: 88px; height: 88px; }

  /* conversations and choices */
  #talkBox { width: 94vw; gap: 10px; border-width: 18px; }
  #talkPic { width: 76px; height: 76px; margin-top: -36px; }
  #talkName { font-size: 18px; }
  #talkText { font-size: 16px; }
  #talkChoices { right: -8px; max-width: 88vw; }
  .gbtn.talkChoice { min-width: 0; font-size: 15px; }
  #dlgPanel { flex-direction: column; gap: 6px; border-width: 22px; }
  #dlgImg { width: 34%; max-height: 22vh; }
  #dlgMain { max-height: 70vh; }
  #modalPanel { border-width: 22px; }
  #modalBody { max-height: 56vh; font-size: 15px; }
}
