/* The game HUD uses three independent columns beneath the toolbar. */
body {
  --hud-controls: 44px;
  --hud-gap: 8px;
  --hud-column: min(236px, 23vw);
}
body[data-screen="playing"] .hud-header {
  z-index: 5;
  min-height: var(--hud-controls);
}
body[data-screen="playing"] .hud-header .actions .icon-button { height: var(--hud-controls); }
body[data-screen="playing"] .hud-header .world-label { min-width: 0; max-width: 43vw; }
body[data-screen="playing"] .hud-header .world-label > div { min-width: 0; }
body[data-screen="playing"] .world-label :is(strong,small) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-hud {
  position: absolute;
  z-index: 3;
  inset: calc(var(--safe-top) + var(--hud-controls) + var(--hud-gap)) var(--safe-right) auto var(--safe-left);
  display: grid;
  grid-template-columns: var(--hud-column) minmax(0,1fr) var(--hud-column);
  align-items: start;
  gap: clamp(5px,1.7vw,22px);
  pointer-events: none;
}
body:not([data-screen="playing"]) .field-hud { display: none; }
.field-hud > div { display: grid; min-width: 0; gap: var(--hud-gap); align-content: start; }
.field-player,.field-encounter { justify-items: start; }
.field-navigation { justify-items: end; }
.field-hud :is(.vitals,.story-hud,.map,.companion-hud,.flight-status,.boss-status,.play-hint,.round-score) {
  position: static;
  inset: auto;
  transform: none;
  max-width: 100%;
  min-width: 0;
  margin: 0;
}
.field-player .vitals { width: min(158px,100%); gap: 5px; }
.field-player .health {
  min-width: 0;
  border-radius: 8px;
  padding: 6px 9px;
  line-height: 1.1;
  background: #2c2032f5;
}
.field-player .health strong { font-size: clamp(1.02rem,2dvh,1.31rem); }
.field-player .health > div:first-child { white-space: nowrap; }
#condition-hud {
  display: block;
  margin-top: 4px;
  font-size: .68rem;
  font-weight: 750;
  color: #ffd387;
}
body[data-condition="frost"] #condition-hud { color: #b4ebff; }
body[data-condition="frost"] #ink-view { filter: sepia(.7) hue-rotate(149deg) saturate(1.7); }
body[data-condition="storm"] .view-shade { box-shadow: inset 0 0 18vw #20192eeb; }
.altitude-controls {
  position: absolute;
  z-index: 5;
  right: var(--safe-right);
  bottom: calc(var(--safe-bottom) + clamp(84px,22dvh,144px));
  display: flex;
  gap: 5px;
  touch-action: none;
}
body:not([data-mode="playing"]) .altitude-controls { display: none; }
.altitude-controls button {
  display: grid;
  align-content: center;
  justify-items: center;
  min-width: 50px;
  min-height: 47px;
  padding: 2px 7px 4px;
  color: #fff1d1;
  background: #3c2c44f5;
  border: 1px solid #c58d86;
  border-radius: 9px;
  box-shadow: 0 3px #251c2a;
  touch-action: none;
}
.altitude-controls button:active { background: #6c4f71; }
.altitude-controls b { color: #ffdb99; font-size: 1.3rem; line-height: 1; }
.altitude-controls span { font-size: .68rem; line-height: 1.2; }
.book-slot-row small { flex: 1 1 15ch; text-align: right; color: #dfba93; line-height: 1.25; }
.field-hud .story-hud { width: 100%; gap: 5px; }
.field-hud #story-journal {
  width: 100%;
  background: #302239f4;
  padding: 7px 9px;
  border-radius: 8px;
  gap: 3px;
}
#story-journal:focus-visible,#story-journal:hover { border-color: #eec99b; }
#story-journal .story-eyebrow {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  column-gap: 7px;
  row-gap: 2px;
}
#story-journal .journal-name { color: #ffdea7; font-weight: 750; }
#story-quest { overflow-wrap: anywhere; }
#story-distance:empty { display: none; }
.story-commands { display: flex; max-width: 100%; min-width: 0; flex-wrap: wrap; gap: 4px; }
.story-commands:empty { display: none; }
.field-hud .story-commands button {
  min-width: 0;
  min-height: 34px;
  padding: 5px 7px;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.12;
}
.field-hud #story-gift { position: static; inset: auto; max-width: 100%; }
.field-hud .map { width: min(155px,100%); pointer-events: auto; }
.field-hud .map #open-map { text-align: left; flex: 1; }
.field-hud .flight-status { width: max-content; }
.field-hud .flight-status strong { overflow-wrap: anywhere; }
.field-hud .boss-status { width: min(400px,100%); }
.field-hud .play-hint { width: max-content; min-height: auto; }
body[data-screen="playing"] .field-hud .play-hint { max-width: 100%; }
.field-encounter > * { justify-self: center; }
.field-hud .companion-hud {
  display: grid;
  max-width: 100%;
  border: 0;
  box-shadow: none;
  background: none;
}
.field-hud #companion-toggle { width: max-content; max-width: 100%; pointer-events: auto; }
.field-hud #companion-controls {
  position: fixed;
  top: calc(var(--safe-top) + var(--hud-controls) + var(--hud-gap));
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  width: min(290px,46vw);
  pointer-events: auto;
  z-index: 6;
}
#story-start {
  display: grid;
  place-content: center;
  row-gap: 2px;
  line-height: 1.06;
  text-align: center;
}
#story-start::before { display: none; }
#story-start strong { font-weight: 820; }
#story-start > span { font-size: .75em; color: #54404f; }

@media (max-width: 900px), (max-height: 540px) and (orientation: landscape) {
  .menu-main .spawn-select { grid-template-columns: minmax(0,1fr); gap: 4px; }
  #title-spawn { width: 100%; min-width: 0; }
}
@media (max-height: 540px) and (orientation: landscape) {
  #title-screen {
    inset: max(9px,var(--safe-top)) var(--safe-right) max(8px,var(--safe-bottom)) var(--safe-left);
    margin: 0;
    grid-template-columns: minmax(0,1.6fr) minmax(0,1fr);
    grid-template-rows: minmax(0,1fr);
    gap: clamp(10px,3vw,36px);
  }
  #title-screen .menu-main {
    max-height: 100%;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    padding: 4px 5px 6px;
  }
  #title-screen h1 { margin-bottom: 9px; }
  #title-screen .fighter { height: 100%; }
  #title-screen #skins { gap: 4px; }
  #title-screen .skin-card { min-height: 0; }
  #title-screen .skin-card canvas { height: clamp(27px,10dvh,53px); }
  #title-screen .skin-card span { padding: 3px 1px; font-size: clamp(.65rem,2vw,.8rem); line-height: 1.12; }
  #title-screen .spawn-select { margin-top: 8px; font-size: .74rem; }
  #title-screen #title-spawn { min-height: 32px; padding-block: 4px; }
  #title-screen .opening-actions { gap: 6px; margin-top: 8px; }
  #title-screen .opening-actions button { min-height: 40px; padding: 4px 6px; line-height: 1.16; }
  #title-screen #story-start { display: flex; flex-wrap: wrap; gap: 3px 9px; }
  #title-screen #story-start > span { font-size: .87em; }
  #title-screen .play-icon { display: none; }
  #title-screen .menu-tools { gap: 2px 12px; }
  #title-screen .menu-tools button { min-height: 29px; font-size: .75rem; }
}

#pause-screen { width: min(615px,calc(100% - 30px)); }
#pause-screen .pause-actions { display: grid; gap: 7px; margin-top: 9px; }
#pause-screen .pause-primary { grid-template-columns: 1fr; }
#pause-screen .pause-nav { grid-template-columns: repeat(2,minmax(0,1fr)); }
#pause-screen .pause-preferences { grid-template-columns: repeat(2,minmax(0,1fr)); }
#pause-screen .pause-footer { grid-template-columns: repeat(2,minmax(0,1fr)); }
#pause-screen .pause-actions > button { grid-column: auto; max-width: 100%; min-width: 0; }
#pause-screen .pause-actions #pause-view,#pause-screen .pause-actions #exit:only-of-type { grid-column: 1 / -1; }
#pause-screen .pause-footer { padding-top: 7px; border-top: 1px solid #c8957e40; }
#pause-screen .pause-footer #reset[hidden]+#exit { grid-column: 1 / -1; }
#pause-screen :is(#auto-jump,#auto-aim,#pause-view) { justify-content: space-between; text-align: left; }
.settings-tabs {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: 5px;
  margin-bottom: 11px;
}
.settings-tabs button { min-width: 0; min-height: 39px; padding: 5px 6px; font-size: .82rem; }
.settings-tabs button[aria-pressed="true"] { background: #f5cc8a; color: #332337; border-color: #daa77d; }
.audio-settings {
  border: 1px solid #ad796d80;
  border-radius: 8px;
  margin: 10px 0;
  padding: 8px 10px;
  min-inline-size: 0;
}
.audio-settings label,.audio-actions { display: flex; justify-content: space-between; align-items: center; gap: 9px; }
.audio-settings input#audio-volume { width: 100%; min-height: 26px; padding: 0; accent-color: #f4bd78; }
.audio-actions button { font-size: .82rem; min-height: 35px; padding: 4px 9px; }
#audio-status { font-size: .77rem; color: #edc49f; }
#audio[data-audio-state="waiting"]::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 5px;
  height: 5px;
  background: #f3b76b;
  border-radius: 50%;
}

@media (max-height: 520px) and (orientation: landscape) {
  body { --hud-controls: 39px; --hud-gap: 5px; --hud-column: min(188px, 25vw); }
  .field-hud .map { width: clamp(67px,23dvh,116px); }
  .field-hud .health { width: min(136px,100%); padding: 4px 7px; }
  .field-hud .health-bar { height: 5px; margin-top: 3px; }
  .field-player .vitals .tally { display: none; }
  .field-hud #story-journal { padding: 5px 7px; gap: 2px; }
  #story-quest { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  #story-journal .story-eyebrow > span { font-size: .61rem; }
  .field-hud .story-commands button { min-height: 31px; font-size: .69rem; }
  .field-hud .boss-status,.field-hud .play-hint { padding: 4px 6px; }
  .field-hud .map .coordinates,.field-hud .route-distance { display: none; }
  #pause-screen .pause-nav { grid-template-columns: repeat(3,minmax(0,1fr)); }
  #pause-screen .pause-preferences { grid-template-columns: repeat(3,minmax(0,1fr)); }
  #pause-screen .pause-preferences #pause-view { grid-column: auto; }
  #pause-screen .pause-actions > button { min-height: 39px; margin: 0; }
  #pause-screen .pause-preferences > button { display: grid; justify-items: start; gap: 3px; }
}

@media (max-height: 320px) and (orientation: landscape) {
  body {
    --safe-top: max(7px,env(safe-area-inset-top));
    --safe-bottom: max(8px,env(safe-area-inset-bottom));
    --hud-controls: 34px;
  }
  .field-hud #story-level {
    display: none;
  }
  .field-hud .story-commands { flex-wrap: nowrap; }
  .field-hud .story-commands button { min-height: 27px; }
  .field-hud .flight-status :is(#flight-name,#flight-speed,.flight-keys) { display: none; }
  .field-hud .field-navigation:has(.flight-status:not([hidden])) #minimap { display: none; }
  .field-hud #companion-toggle { min-height: 29px; }
  #pause-screen { padding-block: 8px 11px; max-height: calc(100dvh - 12px); }
  body[data-input="touch"] #stick { width: clamp(59px,24dvh,86px); height: clamp(59px,24dvh,86px); }
}

@media (orientation: portrait) {
  body { --hud-column: min(153px,35vw); --hud-gap: 5px; --hud-controls: 39px; }
  .field-hud .map { width: min(103px,100%); }
  .field-hud .play-hint { display: none; }
}

@media (max-width: 370px) {
  .hud-header .world-label div strong { display: none; }
  #pause-screen .pause-nav { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
