/*
 * mobile.css — phone layout for every page (loaded after each page's own styles).
 * Only applies to narrow screens; desktop is unchanged.
 */
/* ── Scrollbars, every page and screen size: wide enough to grab, still quiet ── */
::-webkit-scrollbar { width: 9px !important; height: 9px !important; }
::-webkit-scrollbar-track { background: #0a0c10 !important; }
::-webkit-scrollbar-thumb { background: #2a3d55 !important; border: 2px solid #0a0c10; border-radius: 6px; min-height: 28px; }
::-webkit-scrollbar-thumb:hover { background: #3d5878 !important; }
::-webkit-scrollbar-thumb:active { background: #00c8ff !important; }
::-webkit-scrollbar-corner { background: #0a0c10; }
/* Firefox only (in Chrome these would switch off the styling above) */
@supports (-moz-appearance: none) { * { scrollbar-color: #2a3d55 #0a0c10; } }

@media (max-width: 760px) {

  /* ── Top bar: logo · balance · ☰ menu ─────────────────────────────────── */
  #hud { padding: 0 0.7rem !important; gap: 0.6rem !important; flex-wrap: nowrap !important; overflow: visible; }
  .hud-logo { font-size: 0.85rem !important; letter-spacing: 0.12em !important; flex-shrink: 0; }
  .hud-menu-btn { display: inline-flex !important; }
  .hud-nav { display: none !important; position: fixed; top: 52px; left: 0; right: 0; z-index: 300;
             flex-direction: column; background: var(--surface); border-bottom: 1px solid var(--accent);
             box-shadow: 0 10px 30px rgba(0,0,0,0.6); max-height: calc(100vh - 52px); overflow-y: auto; }
  .hud-nav.open { display: flex !important; }
  .hud-nav a { display: block; padding: 0.85rem 1.1rem !important; font-size: 0.85rem !important;
               border: none !important; border-bottom: 1px solid var(--border) !important; }
  .hud-nav a.active { background: rgba(0,200,255,0.08); }
  .hud-stat { font-size: 0.7rem !important; white-space: nowrap; }
  .hud-stat.m-hide, #hud-wallet { display: none !important; }
  .hud-right { gap: 0.5rem !important; margin-left: auto; }
  .hud-right .btn { padding: 0.35rem 0.55rem !important; font-size: 0.6rem !important; letter-spacing: 0.05em !important; }

  /* Bigger tap targets for buttons and form fields */
  select, input[type=text], input[type=number] { font-size: 16px !important; }   /* stops iOS zooming in on focus */
  .btn-sm { padding: 0.45rem 0.8rem !important; }

  /* ── Pages with side-by-side columns: stack them, map first ───────────── */
  body.m-stack { overflow: auto !important; height: auto !important; }

  /* Map page */
  #main-layout { display: flex !important; flex-direction: column; height: auto !important; }
  #main-layout > #map-container { order: 1; height: 58vh; min-height: 300px; flex: none; }
  #main-layout > .panel.split { order: 2; height: auto !important; max-height: none !important; border: none; border-top: 1px solid var(--border); }
  #main-layout > #empire-panel { order: 3; border: none; border-top: 1px solid var(--border); }
  #main-layout > .panel { overflow: visible !important; }
  #main-layout > .panel.split > section { max-height: 60vh; }

  /* Zone View and Deployment: map on top, panels underneath */
  body.m-stack #main, body.m-stack #page.m-cols { display: flex !important; flex-direction: column; height: auto !important; }
  body.m-stack #main > #canvas-container, body.m-stack #page.m-cols > #canvas-container { order: 1; height: 55vh; min-height: 280px; flex: none; }
  body.m-stack #main > .panel, body.m-stack #page.m-cols > .panel { order: 2; overflow: visible !important; border: none; border-top: 1px solid var(--border); }
  body.m-stack #main > .panel.right, body.m-stack #page.m-cols > .panel:last-child { order: 3; }

  /* Tower Builder: one column */
  #page.m-builder { display: block !important; padding: 64px 0.9rem 2rem !important; }
  #page.m-builder .builder-section[style*="sticky"] { position: static !important; }
  #page.m-builder > div + div { margin-top: 1.2rem; }

  /* Battle: map full width on top, then my side, then the enemy's */
  /* Battle on a phone, one column, top to bottom:
     map · your unit card + target card · your formations and units · battle messages · enemy lists.
     #center's own children (map, cards, messages) take part in that order directly. */
  /* The battle page fits one screen on a laptop, so it turns page scrolling off; a phone needs it back.
     Drag on the map to move the map; drag anywhere else to scroll the page. */
  html:has(body.m-battle), body.m-battle { overflow-y: auto !important; overflow-x: hidden !important; height: auto !important; }
  body.m-battle { touch-action: pan-y; }
  body.m-battle #layout { display: flex !important; flex-direction: column; height: auto !important; }
  body.m-battle #center { display: contents !important; }
  body.m-battle #battle-container { order: 1; height: 56vh; min-height: 300px; flex: none; }
  body.m-battle #m-cards { order: 2; }
  body.m-battle .panel.side { order: 3; display: block !important; overflow: visible !important; border: none; border-top: 1px solid var(--border); }
  body.m-battle #bottom { order: 4; max-height: 30vh; border-top: 1px solid var(--border); }
  body.m-battle .panel.side:last-child { order: 5; }
  body.m-battle .side > div { overflow: visible !important; max-height: none !important; }
  body.m-battle .battle-info { font-size: 0.62rem !important; }
  body.m-battle #hud-enemy { display: none; }

  /* Wide tables scroll sideways inside their box instead of stretching the page */
  .m-scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Common page padding */
  #page:not(.m-cols):not(.m-builder) { padding-left: 0.9rem !important; padding-right: 0.9rem !important; }
  h1 { font-size: 1.15rem !important; }
}

/* The ☰ button is hidden on desktop */
.hud-menu-btn { display: none; align-items: center; justify-content: center; background: transparent; border: 1px solid var(--border);
                color: var(--accent); font-size: 1.1rem; width: 36px; height: 32px; cursor: pointer; flex-shrink: 0; padding: 0; }

@media (max-width: 760px) {
  /* Marketplace list view and other wide tables */
  .list-group, .unit-table-wrap, .roster-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

@media (max-width: 760px) {
  /* Top bar: just the number for the balance ("250000.00"), no label */
  .hud-stat { font-size: 0 !important; }
  .hud-stat > span { font-size: 0.72rem !important; }
  /* On pages with a menu, the top-bar buttons (War, Disconnect…) move into it */
  .m-moved { display: none !important; }
  .hud-menu-btn { margin-left: auto; }
  .hud-nav .m-menu-action { color: var(--text-dim); }
  .hud-nav .m-menu-action.danger { color: var(--danger); }

  /* Toolbars and filter rows wrap instead of running off the screen */
  .top-bar, .filter-tabs, .zone-select-bar, .zone-filter, .view-toggle, .form-row, .add-weapon { flex-wrap: wrap !important; }
  .top-bar > *, .zone-select-bar, .zone-filter { min-width: 0; max-width: 100%; }
  .zone-filter { margin-left: 0 !important; width: 100%; }
  .zone-filter select { flex: 1 1 40%; min-width: 0; }
  .zone-select-bar select { width: 100%; min-width: 0; }
  .view-toggle { margin-left: 0 !important; }
  .filter-tabs .tab { padding: 0.45rem 0.7rem !important; }

  /* Tower Builder form */
  .form-row { gap: 0.4rem !important; }
  .form-label { width: 100% !important; }
  .form-row input[type=text], .form-row select { width: 100%; min-width: 0; }
  .add-weapon { display: flex !important; gap: 0.5rem; }
  .add-weapon select { flex: 1 1 100%; width: 100%; min-width: 0; max-width: 100%; }
  select { max-width: 100%; }
}

@media (max-width: 760px) {
  /* Map page: "DOM" label after the balance */
  .hud-stat > span + span { display: none !important; }
  /* Marketplace: zone picker on its own full-width row */
  .top-bar { flex-direction: column; align-items: stretch !important; }
  .zone-select-bar { flex-direction: column; align-items: stretch !important; gap: 0.4rem !important; flex: none !important; }
  .market-status { width: 100%; }
  /* Tower Builder: hint text under the level picker, not beside it */
  .form-row > span { flex-basis: 100%; }
  /* Units list view: two tidy columns per unit */
  .urow { gap: 0.5rem 0.8rem !important; padding: 0.7rem 0.8rem !important; }
  .urow > * { min-width: 0; overflow-wrap: anywhere; }
  .summary { grid-template-columns: repeat(2, 1fr) !important; gap: 0.6rem !important; }
}

@media (max-width: 760px) {
  .urow .acts { flex-wrap: wrap; }
}

/* The ☰ menu's copies of the top-bar buttons (War, Disconnect…) exist for
   phones only; on a desktop the real buttons are already in the top bar. */
.hud-nav .m-menu-action { display: none; }
@media (max-width: 760px) {
  .hud-nav .m-menu-action { display: block; }
}

/* Laptop widths (900-1439px): fit the full header on one line.
   The wallet address is hidden here (it's in VeWorld anyway). */
@media (min-width: 1200px) and (max-width: 1439px) {
  #hud { gap: 0.7rem !important; padding-left: 1rem !important; padding-right: 1rem !important; }
  #hud .hud-logo, .hud-logo { letter-spacing: 0.08em !important; font-size: 1rem !important; }
  .hud-nav { gap: 0.1rem !important; }
  .hud-nav a { padding: 0.3rem 0.35rem !important; }
  .hud-wallet, #hud-wallet { display: none !important; }
}
/* Small laptops and tablets (761-1199px): the page links fold into the ☰ menu,
   like on phones; the rest of each page keeps its desktop layout. */
@media (min-width: 761px) and (max-width: 1199px) {
  .hud-menu-btn { display: inline-flex !important; }
  .hud-nav { display: none !important; position: fixed; top: 52px; left: 0; width: 280px; z-index: 300;
             flex-direction: column; background: var(--surface); border: 1px solid var(--accent); border-top: none;
             box-shadow: 0 10px 30px rgba(0,0,0,0.6); max-height: calc(100vh - 52px); overflow-y: auto; }
  .hud-nav.open { display: flex !important; }
  .hud-nav a { display: block; padding: 0.75rem 1.1rem !important; font-size: 0.8rem !important;
               border: none !important; border-bottom: 1px solid var(--border) !important; }
  .hud-nav a.active { background: rgba(0,200,255,0.08); }
  .hud-wallet, #hud-wallet { display: none !important; }
}
