/* One compact phone layout, including short landscape screens. Desktop stays in its own styles. */
.phone-action-label { display: none; }
#flight-vitals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; width: 240px; max-width: 100%; pointer-events: none; }
#flight-vitals .flight-meter { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto 4px; gap: 4px 6px; min-width: 0; }
#flight-vitals .flight-meter-label { font: 600 10px/1.2 system-ui, sans-serif; color: #9faebc; letter-spacing: .02em; }
#flight-vitals .flight-meter-value { grid-column: 2; grid-row: 1; text-align: right; white-space: nowrap; font: 600 11px/1.1 system-ui, sans-serif; font-variant-numeric: tabular-nums; color: #d5eee5; }
#flight-vitals .flight-meter-track { grid-column: 1 / -1; grid-row: 2; width: 100%; height: 4px; border: 0; border-radius: 2px; background: #24333c; }
#flight-vitals .bar-fill { height: 100%; box-shadow: none; transition: none; }
#flight-vitals #hud-shield-fill { background: #75c7f2; }
#flight-vitals .flight-meter-shield .flight-meter-value { color: #acdbf1; }
#flight-vitals [data-empty=true] { background: #303841; }
.mobile-layout.has-flight-vitals #hud-chamber-title { display: none; }
.mobile-layout.has-flight-vitals #hud .organism-info { grid-template-rows: 12px 14px; }
.mobile-layout.has-flight-vitals #hud #hud-mass-count { line-height: 11px; }
.mobile-layout #hud #hud-mass-count { white-space:nowrap; font-variant-numeric:tabular-nums; }
.mobile-layout #flight-vitals { grid-column: 1 / -1; grid-row: 2; width: 100%; gap: 10px; }
.mobile-layout #flight-vitals .flight-meter { grid-template-rows: 11px 2px; gap: 1px 4px; }
.mobile-layout #flight-vitals .flight-meter-label { font-size: 8px; line-height: 11px; }
.mobile-layout #flight-vitals .flight-meter-value { font-size: 10px; line-height: 11px; }
.mobile-layout #flight-vitals .flight-meter-track { height: 2px; }
#btn-phone-contracts { display: none; }
#btn-phone-fullscreen { display: none; }
.mobile-layout #btn-phone-fullscreen, .is-fullscreen #btn-phone-fullscreen {
  display: block; position: fixed; top: var(--phone-top, 12px); right: var(--phone-right, 12px);
  z-index: 200; width: 56px; height: 44px; padding: 0; border: 1px solid #896f42;
  border-radius: 6px; background: #07111c; color: #e8c478; font: 600 12px system-ui;
  touch-action: manipulation;
}
#phone-screen-notice:not([hidden]) {
  position: fixed; z-index: 201; top: calc(var(--phone-top, 12px) + 48px);
  left: 12px; right: 12px; max-width: 500px; margin: 0 auto; padding: 14px;
  border: 1px solid #896f42; background: #07111c; color: #ebeadb; font: 14px/1.5 system-ui;
}

html.mobile-layout {
  --phone-top: max(10px, env(safe-area-inset-top));
  --phone-bottom: max(12px, env(safe-area-inset-bottom));
  --phone-left: max(12px, env(safe-area-inset-left));
  --phone-right: max(12px, env(safe-area-inset-right));
}
.mobile-layout #hud { z-index: 46; }
.mobile-layout #hud .hud-top {
  position: fixed; left: var(--phone-left); right: calc(var(--phone-right) + 66px);
  top: var(--phone-top); gap: 0; display: block; pointer-events: none;
}
.mobile-layout #hud .organism-card {
  width: 100%; max-width: none; min-height: 0; gap: 0; padding: 4px 7px;
  background: rgba(5, 13, 20, .94); border-radius: 3px; backdrop-filter: none;
}
.mobile-layout #hud .core-avatar { display: none; }
.mobile-layout #hud .organism-info { min-width: 0; width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 1px 8px; }
.mobile-layout #hud .game-title {
  display: flex; gap: 6px; align-items: center; justify-content: space-between;
  margin: 0; font-size: 10px; line-height: 1.2; letter-spacing: .02em;
}
.mobile-layout #hud #hud-callsign { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-layout #hud .forge-badge { display: none; }
.mobile-layout #hud .stage-label { grid-row: 2; grid-column: 1 / -1; font-size: 8px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mobile-layout #hud .rank-label, .mobile-layout #hud .vitals-card { display: none; }
.mobile-layout #hud .organism-info .mass-row { grid-row: 1; grid-column: 2; display: flex; gap: 3px; margin: 0; line-height: 1.2; }
.mobile-layout #hud .mass-row .vital-label { display: none; }
.mobile-layout #hud #hud-mass-count { font-size: 9px; min-width: 0; margin: 0; color: #e8c478; }
.mobile-layout .radar-box {
  position: fixed; top: calc(var(--phone-top) + 49px); right: var(--phone-right);
  width: 56px !important; height: 56px !important; min-width: 0; flex: none;
  pointer-events: none; z-index: 44;
}
.mobile-layout #hud .hud-bottom, .mobile-layout #system-strip { display: none !important; }
.mobile-layout #reactor-hud {
  top: calc(var(--phone-top) + 34px) !important; bottom: auto !important;
  left: var(--phone-left) !important; right: calc(var(--phone-right) + 66px) !important;
  width: auto !important; transform: none !important; gap: 4px !important;
}
.mobile-layout #reactor-hud > div:first-child { width: 100% !important; height: 3px !important; }
.mobile-layout #reactor-hud > div:last-child { width: 100%; gap: 3px !important; }
.mobile-layout #reactor-hud > div:last-child > span {
  flex: 1; min-width: 0; padding: 5px 2px !important; text-align: center;
  font-size: 7px !important; letter-spacing: .02em; padding: 3px 1px !important;
}

/* Reuse the real touch action buttons; the lower left remains free for the move stick. */
.mobile-layout #mobile-controls { display: block; }
.mobile-layout .mobile-action-bar {
  position: fixed; bottom: calc(var(--phone-bottom) + 120px); right: var(--phone-right);
  display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(2, 48px);
  gap: 6px; align-items: stretch; z-index: 45;
}
.mobile-layout .touch-action-btn {
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px;
  width: 48px !important; height: 48px !important; min-width: 48px; min-height: 48px;
  padding: 3px; border: 1px solid rgba(201, 162, 92, .6); border-radius: 9px;
  background: rgba(5, 13, 20, .94); box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none;
}
.mobile-layout .touch-action-btn .touch-btn-icon { font-size: 19px; line-height: 1; }
.mobile-layout .phone-action-label { display: block; font: 600 9px/1.2 system-ui, sans-serif; color: #d5e2df; }
.mobile-layout #btn-touch-pause { grid-column: 1; grid-row: 1; }
.mobile-layout #btn-touch-designer { grid-column: 2; grid-row: 1; }
.mobile-layout #btn-touch-build { grid-column: 3; grid-row: 1; }
.mobile-layout #btn-phone-contracts { display: flex; grid-column: 1; grid-row: 2; }
.mobile-layout #btn-touch-map { grid-column: 2; grid-row: 2; }
.mobile-layout #btn-touch-ability { grid-column: 3; grid-row: 2; border-color: var(--primary-cyan); }
.mobile-layout .touch-cd-ring { pointer-events: none; }
.mobile-layout #contracts {
  display: none; position: fixed; left: var(--phone-left); right: var(--phone-right);
  top: calc(var(--phone-top) + 112px); width: auto; max-width: 460px;
  max-height: calc(var(--phone-height, 100dvh) - 350px); overflow-y: auto;
  padding: 14px; z-index: 55; background: rgba(5, 13, 20, .98); pointer-events: auto;
  border: 1px solid #896f42; border-radius: 8px; touch-action: pan-y;
}
.mobile-layout body.phone-contracts-open #contracts { display: block; }
.mobile-layout #contracts .ct-t { font-size: 13px; line-height: 1.4; }
.mobile-layout #contracts .ct-r { font-size: 11px; line-height: 1.5; }
.mobile-layout #contracts .ct { display: block; padding: 9px 0; }
.mobile-layout #btn-phone-contracts[aria-expanded="true"] { border-color: #e8c478; background: #4b3b21; }
.mobile-layout #boss-bar { top: calc(var(--phone-top) + 119px) !important; width: min(480px, calc(100% - 24px)) !important; }
.mobile-layout #hunt-chain { top: calc(var(--phone-top) + 109px) !important; right: var(--phone-right) !important; font-size: 11px !important; }
.mobile-layout #first-tip { bottom: auto; max-width: min(400px, calc(100vw - 28px)); padding: 8px 12px; font-size: 12px; }
.mobile-layout .event-banner { max-width: calc(100vw - 24px); font-size: 12px; white-space: normal; }
.mobile-layout #flight-diagnostics { right: var(--phone-right); bottom: calc(var(--phone-bottom) + 116px); width: min(340px, calc(100vw - 24px)); max-height: calc(var(--phone-height, 100dvh) - 250px); touch-action: pan-y; }
.mobile-layout body.game-paused #mobile-controls, .mobile-layout body.game-paused #contracts { visibility: hidden; }
.mobile-layout body.workshop-open #btn-phone-fullscreen { display: none; }
.mobile-layout #touch-joystick-base { display: none !important; }
#phone-zoom, .phone-stick { display: none; }
.mobile-layout #phone-zoom { display: flex; position: fixed; left: var(--phone-left); top: calc(var(--phone-top) + 62px); gap: 2px; align-items: center; pointer-events: auto; }
.mobile-layout #phone-zoom button { width: 44px; height: 44px; border: 1px solid #38515e; border-radius: 6px; color: #d7e9e5; background: rgba(5,13,20,.8); font: 22px system-ui; touch-action: manipulation; }
.mobile-layout #phone-zoom-value { width: 34px; text-align: center; font: 10px system-ui; color: #bbd0d1; }
.mobile-layout .phone-stick { display: block; position: fixed; bottom: var(--phone-bottom); width: 108px; height: 108px; border: 1px solid rgba(127,194,190,.45); border-radius: 50%; background: rgba(9,25,32,.22); pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none; }
.mobile-layout #phone-move-stick { left: calc(var(--phone-left) + 8px); }
.mobile-layout #phone-aim-stick { right: calc(var(--phone-right) + 8px); border-color: rgba(201,162,92,.6); }
.phone-stick-knob { position: absolute; left: 50%; top: 50%; width: 43px; height: 43px; border: 1px solid rgba(127,194,190,.7); border-radius: 50%; background: rgba(75,119,125,.28); transform: translate(-50%,-50%); pointer-events: none; }
.phone-stick-caption { position: absolute; width: 100%; bottom: 6px; text-align: center; color: #9cb4b3; font: 8px system-ui; letter-spacing: .1em; pointer-events: none; }
.phone-stick.engaged { background: rgba(38,76,85,.3); border-color: #a4dfd3; }
@media (max-height: 500px) {
  .mobile-layout .phone-stick { width: 92px; height: 92px; }
  .mobile-layout .mobile-action-bar { bottom: calc(var(--phone-bottom) + 102px); gap: 4px; }
  .mobile-layout #contracts { top: calc(var(--phone-top) + 62px); max-height: calc(var(--phone-height, 100dvh) - 142px); right: 190px; }
}

/* Every menu scrolls inside the actual visible screen; no essential action sits below it. */
.mobile-layout .menu-overlay, .mobile-layout .bc-overlay, .mobile-layout .modal-overlay {
  padding: var(--phone-top) var(--phone-right) var(--phone-bottom) var(--phone-left);
  box-sizing: border-box; height: var(--phone-height, 100dvh); max-height: var(--phone-height, 100dvh);
  align-items: center; overflow: hidden; touch-action: pan-y;
}
.mobile-layout .menu-card, .mobile-layout .bc-card, .mobile-layout .modal-card {
  max-width: 100%; min-width: 0; max-height: calc(var(--phone-height, 100dvh) - var(--phone-top) - var(--phone-bottom));
  overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; -webkit-overflow-scrolling: touch;
  padding: 20px 16px; border-radius: 6px;
}
.mobile-layout .menu-card { width: min(520px, 100%); }
.mobile-layout .menu-title { font-size: 24px; line-height: 1.2; letter-spacing: .12em; overflow-wrap: anywhere; }
.mobile-layout .tm-doors { gap: 8px; }
.mobile-layout .tm-door { min-height: 48px; padding: 13px 16px 13px 22px; font-size: 14px; letter-spacing: .08em; }
.mobile-layout .tm-back { min-height: 44px; min-width: 70px; top: 4px; left: 8px; padding: 12px 8px; }
.mobile-layout .panel-card { padding-top: 52px; }
.mobile-layout .panel-card .menu-title { font-size: 22px; }
.mobile-layout .pause-where { font-size: 12px; line-height: 1.5; margin-bottom: 15px; overflow-wrap: anywhere; }
.mobile-layout .set-row { grid-template-columns: 95px minmax(0, 1fr) 42px; gap: 8px; min-height: 52px; }
.mobile-layout .set-row.toggle { grid-template-columns: minmax(0, 1fr) 36px; }
.mobile-layout .set-row > span { font-size: 14px; }
.mobile-layout .set-row input[type="range"] { min-height: 44px; margin: 0; touch-action: pan-x; }
.mobile-layout .set-row input[type="checkbox"] { width: 28px; height: 28px; }
.mobile-layout .howto-keys { grid-template-columns: minmax(0, 95px) minmax(0, 1fr); gap: 9px 12px; }
.mobile-layout .howto-keys dt { white-space: normal; font-size: 12px; }
.mobile-layout .howto-keys dd, .mobile-layout .howto-line { font-size: 14px; line-height: 1.5; }
.mobile-layout .credit-v { font-size: 15px; overflow-wrap: anywhere; }

/* Title and new-game picker. Inputs stay large enough to type without browser zoom. */
.mobile-layout #title-overlay.menu-mode { justify-content: center; align-items: center; overflow-y: auto; }
.mobile-layout .title-menu { width: min(480px, 100%); max-height: 100%; gap: 18px; }
.mobile-layout .tm-word { font-size: clamp(38px, 11vw, 58px); letter-spacing: .02em; }
.mobile-layout .tm-kicker { font-size: 9px; letter-spacing: .18em; }
.mobile-layout .tm-tag { margin-top: 10px; font-size: 14px; max-width: 38ch; }
.mobile-layout .tm-foot { display: none; }
.mobile-layout #title-newgame { padding-top: 52px; width: min(620px, 100%); }
.mobile-layout #title-newgame .bc-title { font-size: 34px; line-height: 1; }
.mobile-layout #title-newgame .bc-sub { font-size: 13px; line-height: 1.5; }
.mobile-layout #title-callsign { min-height: 48px; font-size: 16px; }
.mobile-layout #title-newgame .choice-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mobile-layout #title-newgame .choice-row > * { min-width: 0; min-height: 48px; }
.mobile-layout #title-newgame .bc-actions { position: sticky; bottom: -20px; padding: 10px 0 4px; background: #07111c; z-index: 3; }
.mobile-layout #title-newgame .bc-actions .btn { min-height: 48px; width: 100%; font-size: 13px; }
.mobile-layout .mission-card .btn, .mobile-layout .reward-card .btn { min-height: 48px; }

/* Chart, docking and building reuse their real panels with generous hit areas. */
.mobile-layout .map-card { width: min(650px, 100%); padding: 16px; }
.mobile-layout .modal-header h2 { font-size: 22px; line-height: 1.2; letter-spacing: .06em; }
.mobile-layout .modal-header p { font-size: 12px; line-height: 1.5; }
.mobile-layout #chart-tabs { margin-top: 12px; }
.mobile-layout .chart-tab { min-height: 44px; flex: 1; padding: 10px 12px; font-size: 12px; }
.mobile-layout #matrix-grid-container { width: 100%; max-width: 480px; height: auto; min-height: 280px; aspect-ratio: 1; margin: 12px auto; }
.mobile-layout #galaxy-canvas { width: min(100%, 440px, calc(var(--phone-height, 100dvh) - 190px)); min-width: 180px; }
.mobile-layout #galaxy-info { font-size: 12px; line-height: 1.4; }
.mobile-layout .modal-footer { position: sticky; bottom: -16px; padding: 10px 0 0; background: #07111c; z-index: 2; }
.mobile-layout .modal-footer .btn { min-height: 48px; font-size: 13px; }
.mobile-layout #danger-legend { font-size: 12px; }
.mobile-layout .dock-prompt { bottom: calc(var(--phone-bottom) + 116px); min-height: 44px; padding: 12px 18px; font-size: 12px; max-width: calc(100vw - 24px); }
.mobile-layout .dock-card, .mobile-layout .build-card-wrap { width: min(720px, 100%); }
.mobile-layout .dock-cols { grid-template-columns: 1fr; gap: 14px; }
.mobile-layout .dock-cols section { max-height: none; overflow: visible; }
.mobile-layout .dock-row { min-height: 52px; font-size: 14px; gap: 8px; }
.mobile-layout .dock-row button { min-width: 76px; min-height: 44px; font-size: 12px; }
.mobile-layout .dock-doors { position: sticky; bottom: -20px; flex-direction: row; padding-top: 10px; background: #07111c; z-index: 2; }
.mobile-layout .dock-doors .tm-door { flex: 1; min-width: 0; font-size: 12px; padding-left: 18px; }
.mobile-layout #build-list { grid-template-columns: 1fr; }
.mobile-layout .build-card { gap: 12px; padding: 12px; }
.mobile-layout .build-pic { width: 64px; height: 64px; }
.mobile-layout .build-text { flex: 1; }
.mobile-layout .build-text p { font-size: 13px; }
.mobile-layout .build-text button { min-height: 44px; min-width: 100px; padding: 10px 12px; font-size: 12px; }
.mobile-layout #build-close { min-height: 48px; }

@media (max-height: 500px) and (min-width: 600px) {
  .mobile-layout .title-menu { width: min(780px, 100%); display: grid; grid-template-columns: 1fr 1fr; gap: 10px 26px; align-items: center; }
  .mobile-layout .tm-brand { grid-column: 1; grid-row: 1 / span 2; }
  .mobile-layout .tm-word { font-size: clamp(34px, 11vh, 50px); }
  .mobile-layout .tm-tag { font-size: 13px; }
  .mobile-layout .title-menu .tm-continue { grid-column: 2; padding: 8px 10px; gap: 4px 10px; }
  .mobile-layout .title-menu .tm-doors { grid-column: 2; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .mobile-layout .title-menu .tm-door { font-size: 12px; min-height: 48px; padding: 11px 12px 11px 18px; letter-spacing: .04em; }
  .mobile-layout .menu-card { padding-top: 18px; padding-bottom: 16px; }
  .mobile-layout .panel-card, .mobile-layout #title-newgame { padding-top: 48px; }
  .mobile-layout .pause-card { width: min(650px, 100%); }
  .mobile-layout .pause-card .tm-doors { display: grid; grid-template-columns: 1fr 1fr; }
  .mobile-layout .pause-where { margin-bottom: 10px; }
  .mobile-layout .dock-cols { grid-template-columns: 1fr 1fr; }
  .mobile-layout #build-list { grid-template-columns: 1fr 1fr; }
  .mobile-layout .build-card { gap: 8px; padding: 10px; }
  .mobile-layout .build-pic { width: 44px; height: 44px; }
  .mobile-layout #first-tip { max-width: 340px; padding: 6px 10px; font-size: 11px; }
}

/* The dock prompt sat over the Contracts thumb button at the Forge spawn; lift it under the status strip. */
.mobile-layout #dock-prompt { top: calc(var(--phone-top, 10px) + 216px); bottom: auto; }   /* Stage 4: below the doctrine buttons, not over them */

/* Ship systems (reactor modes) as real buttons, left side between the zoom row and the move stick. */
#phone-reactor { display: none; }
.mobile-layout #phone-reactor {
  display: grid; grid-template-columns: repeat(2, 68px); gap: 4px; position: fixed; z-index: 46; pointer-events: auto;
  left: var(--phone-left, 12px); top: calc(var(--phone-top, 10px) + 112px);
}
.mobile-layout #phone-reactor button {
  min-height: 42px; padding: 3px 4px; border-radius: 8px; font: inherit; color: #dfeef0;
  border: 1px solid color-mix(in srgb, var(--mode) 55%, transparent); background: rgba(4, 12, 18, .78);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
}
.mobile-layout #phone-reactor b { font-size: 11px; letter-spacing: .06em; color: var(--mode); }
.mobile-layout #phone-reactor small { font-size: 8px; line-height: 1.1; opacity: .8; text-align: center; }
.mobile-layout #phone-reactor button[aria-pressed="true"] {
  border-color: var(--mode); background: color-mix(in srgb, var(--mode) 26%, rgba(4, 12, 18, .85));
  box-shadow: 0 0 10px color-mix(in srgb, var(--mode) 45%, transparent);
}
.mobile-layout #phone-reactor button.locked { opacity: .5; }
.mobile-layout #phone-reactor button:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.mobile-layout #reactor-hud > div:last-child { display: none !important; }
