/* Existing-system contract: Barlow/Plex, dark metal, cyan selection.
   Variance 3 / motion 3 / density 4. Usable actions lead, menus stay out of flight. */
#hud-bottom [hidden], #result-more-dialog:not([open]) { display: none !important; }
#hud-bottom { width: min(650px, calc(100% - 48px)); gap: 6px; }
#flight-actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; align-items: end; min-width: 0; }
#hud-bottom.has-active-skills #flight-actions { grid-template-columns: minmax(0, 1fr) 130px; }
#hud-bottom.has-active-skills #flight-footer { display: block; }
#hud-bottom:not(.has-active-skills) { width: min(440px, calc(100% - 48px)); }
#flight-actions .active-abilities { grid-template-columns: repeat(var(--active-count, 1), minmax(55px, 1fr)); }
#ability-row .active-slot { height: 55px; min-height: 55px; padding: 6px 8px; }
#flight-actions #ultimate-btn { height: 55px; min-height: 55px; }
#flight-next-power { color: var(--text); font: 500 12px/1.4 var(--font-ui); text-align: center; letter-spacing: .01em; }
#hud-bottom #onb-hint { border: 0; background: var(--panel); padding: 5px 8px; font: 500 12px/1.4 var(--font-ui); letter-spacing: .01em; }
#hud-bottom #xp-wrap .xp-labels { font-size: 11px; }
#hud-bottom .passive-abilities { justify-content: flex-start; }

/* One primary decision after death. Secondary destinations are a real dialog. */
#gameover .go-inner { gap: 12px; width: min(720px, 100%); }
#gameover .run-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 4px 0 0; }
#gameover .run-actions #g-again { min-height: 52px; letter-spacing: .08em; }
#gameover .run-actions #g-revive { order: initial; }
#gameover .run-actions.no-revive #g-loadout { grid-column: 1 / -1; }
#gameover #new-best { font-size: 13px; letter-spacing: .14em; }
#gameover #post-run-progression .pr-line.muted { font: 500 13px/1.5 var(--font-ui); letter-spacing: .01em; text-transform: none; }
.result-more { align-self: center; min-height: 44px; padding: 8px 14px; color: var(--text); font: 500 14px/1.4 var(--font-ui); border-bottom: 1px solid var(--line-hi); cursor: pointer; }
.result-more:hover { color: var(--cyan); }
#death-replay-slot { width: 100%; }
#death-replay-slot:empty { display: none; }
#result-more-dialog { margin: auto; width: min(740px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 24px; overflow: auto; overscroll-behavior: contain; background: #08121c; color: var(--text); border: 1px solid var(--line-hi); box-shadow: 0 24px 90px #0008; }
#result-more-dialog::backdrop { background: #03070dd9; }
.result-more-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.result-more-heading h2 { font: 600 28px/1.2 var(--font-display); }
.result-more-heading .mbtn { min-width: 0; min-height: 44px; padding: 8px 16px; }
.result-navigation { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 20px; }
.result-navigation .mbtn { min-width: 0; min-height: 44px; font-size: 12px; letter-spacing: .04em; padding: 10px 8px; }
#result-more-dialog .run-details { border: 0; padding: 0; }
#result-more-dialog .results { margin-top: 0; }
#result-more-dialog #run-race { max-width: none; margin: 16px 0 0; }
#result-more-dialog #share-panel { width: 100%; }

/* The fitting view stays above the fixed footer at desktop. Material art remains
   the anchor, while thumbnails show their complete names without hover. */
#loadout .loadout-panel.hangar-ready { padding: 22px 26px; height: min(860px, calc(100dvh - 32px)); }
.hangar-ready .hangar-caption { margin: 4px 0 12px; }
.hangar-ready .hangar-tabs { margin-bottom: 16px; }
.hangar-ready .loadout-equipment { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr) minmax(0, .9fr); grid-template-rows: auto; gap: 22px; align-items: start; }
.hangar-ready .hangar-ship, .hangar-ready .hangar-weapon, .hangar-ready .hangar-core { grid-row: 1; grid-column: auto; }
.hangar-ready .hangar-selector .car-center { flex: none; }
.hangar-ready .car-center { min-height: 108px; grid-template-columns: 88px minmax(0, 1fr); gap: 10px; padding: 0; }
#loadout .hangar-ready canvas.ship-mini { width: 88px; margin: 0; }
.hangar-ready .car-name { font-size: 20px; line-height: 1.15; letter-spacing: .035em; overflow-wrap: anywhere; }
.hangar-ready .car-sub { font-size: 13px; line-height: 1.45; }
.hangar-ready .hangar-item-status { font-size: 10px; line-height: 1.4; letter-spacing: .07em; margin: 6px 0 0; }
.hangar-ready .hangar-ship .car-center { display: flex; min-height: 0; padding: 0; text-align: left; gap: 0; background-size: auto 260px; background-position: center top; }
.hangar-ready .hangar-ship .car-center::after { inset: 190px 0 0; }
#loadout .hangar-ready .hangar-ship canvas.ship-mini { width: 224px; height: 224px; margin: -4px auto 0; }
.hangar-ready .hangar-ship .hangar-item-copy { padding: 10px 12px 12px; width: 100%; background: #08121ce8; }
.hangar-ready .hangar-ship .car-name { font-size: 23px; letter-spacing: .07em; }
.hangar-tactics { font: 400 13px/1.5 var(--font-ui); color: var(--text); margin-top: 8px; }
.hangar-ready .hangar-thumbnails { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 10px; padding: 0; }
.hangar-ready .hangar-core .hangar-thumbnails { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.hangar-ready .hangar-thumb, .hangar-ready .hangar-thumb:not(.locked) { min-height: 66px; padding: 6px; gap: 3px; }
.hangar-ready .hangar-thumb-art { width: 32px; height: 32px; }
.hangar-ready .hangar-thumb-name { display: block; white-space: normal; overflow: visible; text-overflow: clip; font: 600 11px/1.2 var(--font-ui); letter-spacing: 0; overflow-wrap: normal; }
.hangar-ready .hangar-thumb-lock { position: static; font: 600 10px/1.25 var(--font-ui); margin-top: 1px; }
.hangar-ready .hangar-core .hangar-thumb { display: grid; grid-template-columns: 28px minmax(0, 1fr); column-gap: 6px; text-align: left; min-height: 57px; }
.hangar-ready .hangar-core .hangar-thumb-art { grid-row: 1 / 3; width: 28px; height: 28px; }
.hangar-ready .hangar-core .hangar-thumb-name, .hangar-ready .hangar-core .hangar-thumb-lock { text-align: left; }
.hangar-ready .loadout-actions { gap: 10px; }
.hangar-ready .hangar-pane:not(.loadout-equipment) { min-height: 0; padding: 16px 6px 24px; }
#hangar-weapon-preview { margin-top: 14px; min-width: 0; }
.flight-mode-options { border: 0; margin: 0 0 24px; max-width: 760px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.flight-mode-options legend { font: 600 18px var(--font-display); margin-bottom: 10px; }
.flight-mode-options label { display: flex; align-items: flex-start; gap: 12px; padding: 14px; border: 1px solid var(--line); cursor: pointer; }
.flight-mode-options label:has(input:checked) { background: #132935; border-color: var(--cyan); }
.flight-mode-options label:has(input:disabled) { opacity: .6; cursor: default; }
.flight-mode-options input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--cyan); }
.flight-mode-options strong { display: block; font: 600 18px var(--font-ui); }
.flight-mode-options small { display: block; margin-top: 5px; font: 400 14px/1.5 var(--font-ui); }
#flight-mode-hint { grid-column: 1 / -1; margin-top: 2px; font: 400 14px/1.6 var(--font-ui); color: var(--text); }

@media (max-width: 959px) {
  .hangar-ready .loadout-equipment { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
  .hangar-ready .hangar-ship { grid-column: 1; grid-row: 1 / 3; }
  .hangar-ready .hangar-weapon { grid-column: 2; grid-row: 1; }
  .hangar-ready .hangar-core { grid-column: 2; grid-row: 2; }
  .hangar-ready .hangar-thumbnails { max-width: none; }
}
@media (max-width: 599px) {
  #loadout .loadout-panel.hangar-ready { width: calc(100vw - 12px); padding: 14px 12px; height: calc(100dvh - 12px); max-height: calc(100dvh - 12px); }
  .hangar-ready .loadout-equipment { display: flex; flex-direction: column; gap: 22px; }
  .hangar-ready .loadout-equipment section { width: 100%; }
  .hangar-ready .hangar-tabs { margin-bottom: 14px; }
  .hangar-ready .hangar-tabs button { font-size: 14px; padding: 10px 4px; }
  .hangar-ready .hangar-ship .car-center { display: grid; grid-template-columns: 112px minmax(0, 1fr); background-size: cover; align-items: center; }
  #loadout .hangar-ready .hangar-ship canvas.ship-mini { width: 112px; height: 144px; margin: 0; object-fit: contain; }
  .hangar-ready .hangar-ship .hangar-item-copy { padding: 10px; }
  .hangar-ready .hangar-ship .car-name { font-size: 20px; }
  .hangar-tactics { font-size: 12px; }
  .hangar-ready .car-center { grid-template-columns: 76px minmax(0, 1fr); min-height: 94px; text-align: left; }
  #loadout .hangar-ready canvas.ship-mini { width: 76px; }
  .hangar-ready .hangar-core .hangar-thumbnails { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hangar-ready .hangar-weapon .hangar-thumbnails { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .hangar-ready .hangar-equipped { flex-basis: 100%; }
  .hangar-ready .hangar-equipped > span, .loadout-fire-help { display: none; }
  .hangar-ready .loadout-actions { gap: 7px; padding-top: 9px; }
  .hangar-ready #ld-launch, .hangar-ready #ld-practice, .hangar-ready #ld-back { padding: 10px 14px; font-size: 12px; min-height: 44px; }
  .flight-mode-options { grid-template-columns: minmax(0, 1fr); }
  #result-more-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 20px); padding: 16px; }
  .result-navigation { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Physical targets remain >=44px across the 80–130% HUD scale range. */
body.touch:not(.practicing) #hud-bottom { display: flex; flex-direction: column; left: calc(14px / var(--hud-scale, 1)); transform: none; width: calc(100% - 28px / var(--hud-scale, 1)); bottom: calc(8px + env(safe-area-inset-bottom)); gap: 5px; }
body.touch #hud-bottom.has-active-skills #flight-actions { grid-template-columns: minmax(0, 1fr) calc(76px / var(--hud-scale, 1)); gap: calc(5px / var(--hud-scale, 1)); }
body.touch #flight-actions .active-abilities { gap: calc(4px / var(--hud-scale, 1)); grid-template-columns: repeat(var(--active-count, 1), minmax(0, 1fr)); }
body.touch #hud-bottom #ability-row .active-slot { min-height: calc(48px / var(--hud-scale, 1)); height: calc(48px / var(--hud-scale, 1)); min-width: calc(44px / var(--hud-scale, 1)); display: flex; flex-direction: column; justify-content: center; gap: 3px; padding: 4px 2px; }
body.touch .active-slot .ability-key, body.touch .active-slot canvas { display: none; }
body.touch .active-slot .ability-name { margin: 0; font-family: var(--font-display); font-size: calc(12px / var(--hud-scale, 1)); line-height: 1.15; max-width: 100%; white-space: normal; text-align: center; overflow: visible; }
body.touch .active-slot .ability-status { font-size: calc(10px / var(--hud-scale, 1)); }
body.touch #flight-actions #ultimate-btn { min-height: calc(48px / var(--hud-scale, 1)); height: calc(48px / var(--hud-scale, 1)); min-width: 0; padding: 3px 2px; align-items: center; text-align: center; gap: 2px; }
body.touch #flight-actions #ultimate-btn svg { position: static; transform: none; width: calc(18px / var(--hud-scale, 1)); height: calc(18px / var(--hud-scale, 1)); }
body.touch #flight-actions .ultimate-name { display: none; }
body.touch #flight-actions #ultimate-status { font-size: calc(10px / var(--hud-scale, 1)); }
body.touch #hud-bottom .passive-abilities { display: none; }
body.touch #flight-footer { display: grid; grid-template-columns: 130px minmax(0, 1fr); }
body.touch #hud-bottom.has-active-skills #flight-footer { display: block; }
body.touch #hud-bottom #onb-hint, body.touch #hud-bottom #combo-ready, body.touch #flight-next-power { max-width: 100%; align-self: center; text-align: center; font-size: calc(12px / var(--hud-scale, 1)); }
body.touch #hud-bottom .xp-labels { display: flex; }
body.touch #hud-bottom .xp-bar { height: 4px; }
body.touch #dash-btn { bottom: calc(155px + env(safe-area-inset-bottom)); width: 64px; height: 64px; }
body.touch:not(.practicing) #minimap { bottom: calc(232px + env(safe-area-inset-bottom)); width: calc(54px / var(--hud-scale, 1)); height: calc(54px / var(--hud-scale, 1)); }
@media (max-width: 600px) and (min-height: 521px) {
  body.touch #hud-bottom.has-active-skills #flight-actions { grid-template-columns: minmax(0, 1fr) calc(76px / var(--hud-scale, 1)); }
  body.touch #hud-bottom[data-active-count="4"] .active-abilities { grid-template-columns: minmax(calc(44px / var(--hud-scale, 1)), 1fr) minmax(calc(44px / var(--hud-scale, 1)), .8fr) minmax(calc(44px / var(--hud-scale, 1)), 1.5fr) minmax(calc(44px / var(--hud-scale, 1)), 1fr); }
  /* Reserve the right thumb lane at the same zoom as Dash and the radar. */
  body.touch #hud-bottom #onb-hint, body.touch #hud-bottom #combo-ready, body.touch #flight-next-power { max-width: calc(100% - 104px); align-self: flex-start; text-align: left; }
}
@media (orientation: landscape) and (max-height: 520px) {
  body.touch:not(.practicing) #hud-bottom {
    --flight-side-space: max(calc(83px / var(--hud-scale, 1)), calc(76px + max(env(safe-area-inset-left), env(safe-area-inset-right))));
    left: 50%; transform: translateX(-50%);
    width: min(calc(520px / var(--hud-scale, 1)), calc(100% - var(--flight-side-space) - var(--flight-side-space)));
    gap: calc(2px / var(--hud-scale, 1));
  }
  body.touch:not(.practicing) #hud-bottom #onb-hint, body.touch:not(.practicing) #hud-bottom #combo-ready, body.touch #flight-next-power { font-size: calc(11px / var(--hud-scale, 1)); line-height: 1.2; padding: calc(2px / var(--hud-scale, 1)) calc(4px / var(--hud-scale, 1)); }
  body.touch #hud-bottom .xp-labels { display: none; }
  body.touch #dash-btn { bottom: calc(12px + env(safe-area-inset-bottom)); width: 56px; height: 56px; }
  body.touch:not(.practicing) #minimap { bottom: calc(84px + env(safe-area-inset-bottom)); }
  #loadout .loadout-panel.hangar-ready { padding: 12px; height: calc(100dvh - 16px); max-height: calc(100dvh - 16px); }
  .hangar-ready .loadout-equipment { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
  .hangar-ready .hangar-ship, .hangar-ready .hangar-weapon, .hangar-ready .hangar-core { grid-column: auto; grid-row: 1; }
  .hangar-ready .hangar-ship .car-center { display: grid; grid-template-columns: 70px minmax(0, 1fr); }
  #loadout .hangar-ready .hangar-ship canvas.ship-mini { width: 70px; height: 100px; }
  .hangar-ready .hangar-ship .car-name { font-size: 17px; }
  .hangar-ready .hangar-ship .hangar-item-copy { padding: 6px; }
  .hangar-ready .hangar-thumbnails { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hangar-ready .car-center { grid-template-columns: 60px minmax(0, 1fr); }
  #loadout .hangar-ready canvas.ship-mini { width: 60px; }
  .hangar-ready .car-name { font-size: 17px; }
  .hangar-ready .loadout-actions { flex-wrap: nowrap; }
}
@media (prefers-reduced-motion: reduce) {
  #result-more-dialog, #gameover .go-inner { animation: none; scroll-behavior: auto; }
}

/* Hull identity stays readable on the touch control; the pause view explains its cost. */
body.touch:not(.practicing) #hud-bottom #ultimate-btn svg { display:none; }
body.touch:not(.practicing) #hud-bottom #ultimate-btn .ultimate-name { display:block; margin:0; max-width:100%; white-space:normal; font-size:calc(12px / var(--hud-scale, 1)); line-height:1.05; letter-spacing:0; }
#pause-guide { margin:8px 0 0; border-top:1px solid var(--line); }
#pause-guide summary { min-height:44px; display:flex; align-items:center; gap:8px; cursor:pointer; list-style:none; color:var(--dim); font:600 12px/1.2 var(--font-ui); letter-spacing:.08em; }
#pause-guide summary::-webkit-details-marker { display:none; }
#pause-guide summary::before { content:""; width:6px; height:6px; border-right:1px solid currentColor; border-bottom:1px solid currentColor; transform:rotate(-45deg); transition:transform .15s; }
#pause-guide[open] summary::before { transform:rotate(45deg); }
#pause-guide summary:focus-visible { outline:2px solid var(--cyan); outline-offset:2px; }
#pause-ship-role { margin:2px 0 6px; color:var(--text); font:400 13px/1.4 var(--font-ui); text-align:left; }
@media (orientation:landscape) and (max-height:520px) {
  #pause .panel.slim { width:min(720px,calc(100vw - 32px)); max-width:none; display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:10px 24px; padding:18px; }
  #pause h2, #pause-stats { grid-column:1; margin:0; }
  #pause-guide { grid-column:1; grid-row:3; margin:0; align-self:start; }
  #pause-guide summary { min-height:36px; }
  #pause-ship-role, #pause #pause-pilot-help { font-size:12px; line-height:1.35; }
  #pause .fire-control { grid-column:2; grid-row:1 / 3; margin:0; }
  #pause .col-buttons { grid-column:2; grid-row:3; }
}

/* A single replay objective remains visible beside the real retry action. */
#run-next-goal { margin: 0; color: var(--cyan); font: 500 13px/1.5 var(--font-ui); text-align: center; overflow-wrap: anywhere; }
#run-next-goal[hidden] { display: none; }
