/* Batch #362 mobile (#562): phone layout fixes, active only with ?mobile=true (body.sfc-mobile, hud_common.js isMobileDevice).
   Tested with tools/mobile362_shots.mjs at the phone viewports listed in docs/batch362/mobile.md (Galaxy Z Fold8 / Fold7 folded and
   unfolded, 360 / 390 / 412 px phones, landscape). Loaded by index.html after hud.css; every rule is scoped to body.sfc-mobile so the
   desktop layout is untouched. */

/* ---------- battle HUD (src/ui/mobile362.js measures the bars: --m362-top, --m362-bottom, --m362-pad) */
/* the centre banner ("CONTACT: ...", 44 px) wraps into a wall of text on a phone: smaller, wrapped inside the screen */
body.sfc-mobile #center-banner { font-size: clamp(15px, 4.6vw, 30px); letter-spacing: 1px; width: min(86vw, 640px); text-align: center; line-height: 1.2; }

/* top bar: the blocks wrap next to each other (the mission clock was absolutely placed over the capacitor bar) */
body.sfc-mobile #hud #top-bar#top-bar.b356-bars { left: var(--m362-left, 48px) !important; right: 4px; height: auto; flex-wrap: wrap; justify-content: flex-start; gap: 2px 10px; }
body.sfc-mobile #hud #top-bar#top-bar.b356-bars > .bar-block { min-width: min(140px, 40vw); flex: 1 1 auto; }
body.sfc-mobile #hud #top-bar#top-bar.b356-bars > .b356-clock { position: relative; top: auto; right: auto; flex: 0 0 auto; }
/* bottom bar: full width under the touch pad; game-speed buttons wide enough for a finger */
body.sfc-mobile #hud #bottom-bar#bottom-bar.b356-bars { left: var(--m362-left, 48px) !important; right: 4px; height: auto; flex-wrap: wrap; gap: 2px 10px; }
body.sfc-mobile #hud #bottom-bar#bottom-bar > .b356-time button.sfc { min-width: 28px; height: 28px; min-height: 28px; font-size: 11px; }
/* the touch pad sits above the bottom bar instead of covering its speed / power / game-speed controls */
body.sfc-mobile .touch-pad { bottom: calc(var(--m362-bottom, 0px) + 4px); }
/* tactical status block and scenario status start under the top bar, side by side instead of on top of each other */
body.sfc-mobile #hud .status-block { top: calc(var(--m362-top, 40px) + 4px); left: var(--m362-left, 48px); max-width: calc(50vw - var(--m362-left, 48px)); }
body.sfc-mobile #hud #scenario-status { top: calc(var(--m362-top, 40px) + 4px) !important; left: auto !important; right: 4px; transform: none !important;
  max-width: calc(50vw - 8px) !important; font-size: 10px !important; padding: 2px 5px !important; }
/* the left panel column starts under the top bar (on a phone the bar runs across from the toolbar) and stops above the bottom bar */
body.sfc-mobile #hud .hud-column.left { top: calc(var(--m362-top, 40px) + 4px) !important; bottom: calc(var(--m362-bottom, 40px) + 4px) !important; }
/* open panels are drawn over the tactical status and scenario status (both are short read-outs that stay visible while no panel covers them) */
body.sfc-mobile #hud #panel-area { z-index: 2; right: var(--m362-pad, 0px); }   /* right-hand panel columns stay left of the open touch pad */
body.sfc-mobile #hud .status-block, body.sfc-mobile #hud #scenario-status { z-index: 1; }
/* panel close / fold controls big enough to hit */
body.sfc-mobile #hud .panel-ctl { min-width: 24px; min-height: 24px; }

/* narrow phones (folded Fold 360-480 px, its 657 px landscape): the panel columns cannot stand side by side next to the toolbar and the touch pad — every open panel goes into one list
   between the toolbar and the right edge, under the top bar, scrolling by touch */
@media (max-width: 700px) {
  body.sfc-mobile #hud #panel-area { left: var(--m362-left, 48px); right: max(4px, var(--m362-pad, 0px)); top: calc(var(--m362-top, 40px) + 4px); bottom: auto;
    max-height: calc(100% - var(--m362-top, 40px) - var(--m362-bottom, 40px) - 8px); overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 6px;
    touch-action: pan-y; scrollbar-width: none; }
  body.sfc-mobile #hud #panel-area > .hud-column { position: static !important; width: auto !important; overflow: visible !important; flex: none; }
  body.sfc-mobile #hud #panel-area > .hud-column.empty { display: none; }
  body.sfc-mobile #hud #panel-area > .hud-column > .panel { max-width: 100%; box-sizing: border-box; }
}

/* ---------- campaign */
/* the new-campaign form: the selects shrink to the dialog instead of running past its right edge */
body.sfc-mobile .cmp-form-row { grid-template-columns: minmax(70px, 110px) minmax(0, 1fr); }
body.sfc-mobile .cmp-form-row select, body.sfc-mobile .cmp-form-row input:not([type=checkbox]) { min-width: 0; max-width: 100%; width: 100%; box-sizing: border-box; }
body.sfc-mobile .cmp-dialog { box-sizing: border-box; max-width: calc(100% - 8px); }
body.sfc-mobile .cmp-toolbar, body.sfc-mobile .cmp-buttons { min-width: 0; max-width: 100%; }

/* ---------- menu lists (scenarios, encyclopedia, watch): on a narrow phone the table columns wrap instead of scrolling sideways */
@media (max-width: 600px) {
  body.sfc-mobile .front-table { font-size: 10.5px; }
  body.sfc-mobile .front-table th, body.sfc-mobile .front-table td { padding: 2px 3px; white-space: normal; overflow-wrap: anywhere; }
}

/* ---------- touch targets: checkboxes and radio buttons (13 px by default) big enough for a finger */
body.sfc-mobile #menu input[type=checkbox], body.sfc-mobile #menu input[type=radio],
body.sfc-mobile .modal input[type=checkbox], body.sfc-mobile .modal input[type=radio] { width: 24px; height: 24px; min-width: 24px; margin: 0 4px 0 0; vertical-align: middle; }

/* ---------- unfolded Fold / landscape phone (701-1000 px): the two-pane screens (scenarios, watch, quick battle, encyclopedia) stack
   like on a narrow phone — side by side their tables were wider than their panes and scrolled sideways */
@media (max-width: 1000px) {
  body.sfc-mobile .front-split, body.sfc-mobile .front-body > .front-split.wide-left { flex-direction: column; height: auto; }
  body.sfc-mobile .front-split > * { flex: none !important; width: 100%; box-sizing: border-box; }
  body.sfc-mobile .front-split > .front-scroll:first-child:has(table) { max-height: 46vh; }
  body.sfc-mobile .front-body { overflow-x: hidden; }
  body.sfc-mobile .front-encyclopedia, body.sfc-mobile .enc { height: auto; }
  body.sfc-mobile .enc-columns { flex-direction: column; flex: none; }
  body.sfc-mobile .enc-list { flex: none; max-height: 46vh; width: 100%; box-sizing: border-box; }
  body.sfc-mobile .enc-detail { flex: none; overflow: visible; width: 100%; box-sizing: border-box; }
  html body.sfc-mobile .enc-view-buttons button.sfc { min-height: 26px; }
  body.sfc-mobile .front-table th, body.sfc-mobile .front-table td { white-space: normal; overflow-wrap: anywhere; }
}

/* encyclopedia 3D view presets (Dorsal, Port ... BOOM): they were squeezed to 22 px in the 200 px preview; full height, the column scrolls */
body.sfc-mobile .enc-view-buttons { overflow-y: auto; scrollbar-width: none; }
html body.sfc-mobile .enc-view-buttons button.sfc { flex: none; min-height: 26px; }   /* html: menu.css is injected after this file */

/* quick battle commander's options table (shuttle / drone selects) and the main-menu "Next tip" link: fit 360 px, finger-sized */
body.sfc-mobile .front-table select { max-width: 100%; min-width: 0; width: 100%; box-sizing: border-box; }
html body.sfc-mobile .menu-tip362-next { min-height: 28px; padding: 4px 10px; }
