/* ============================================================
   MOBILE APP SHELL — activated by body.mobile (set in JS from a
   matchMedia for small / coarse-pointer screens).

   Phone layout philosophy: the WORLD is the screen. One slim HUD
   row up top, a thumb bar at the bottom, everything else lives in
   slide-up sheets. No page scrolling, ever.
   ============================================================ */

/* ---------- thumb bar + sheet chrome (hidden on desktop) ---------- */
.mbar { display: none; }
.sheet-backdrop { display: none; }

body.mobile .mbar {
  display: flex;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 85; /* above sheets + backdrop: the thumb bar never goes dead */
  gap: 8px;
  padding: 8px max(10px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  background: linear-gradient(180deg, #16120c 0%, #0d0b07 100%);
  border-top: 1px solid var(--border-bright, rgba(212,175,93,0.26));
  box-shadow: 0 -8px 24px rgba(0,0,0,0.55);
}
body.mobile .mbar button {
  flex: 1;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--border-bright, rgba(212,175,93,0.26));
  background: linear-gradient(180deg, #241d12, #181308);
  color: var(--text, #ede4d0);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  position: relative;
}
body.mobile .mbar button:active { transform: translateY(1px); filter: brightness(1.15); }
body.mobile .mbar button.primary {
  background: linear-gradient(180deg, var(--gold-hi, #f2d68a), var(--gold, #d4af5d));
  color: #1a1408;
  border-color: rgba(0,0,0,0.4);
}
body.mobile .mb-badge {
  position: absolute;
  top: -6px; right: -4px;
  min-width: 18px; height: 18px;
  border-radius: 99px;
  background: var(--red, #e0584c);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  border: 1px solid rgba(0,0,0,0.5);
}

body.mobile .sheet-backdrop.show {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(5,4,2,0.55);
  backdrop-filter: blur(2px);
}

/* ---------- app shell: fixed, no scroll, canvas is the screen ---------- */
body.mobile {
  position: fixed; inset: 0; overflow: hidden;
  padding: 0; /* the desktop page gutter -- the world owns every pixel here */
  --mbar-h: calc(64px + env(safe-area-inset-bottom));
}
body.mobile .game {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  max-width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  padding: env(safe-area-inset-top) 0 var(--mbar-h) 0;
}

/* ---------- HUD: one slim row ---------- */
body.mobile .topbar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  border-radius: 0;
  border-left: 0; border-right: 0; border-top: 0;
}
body.mobile .topbar::-webkit-scrollbar { display: none; }
body.mobile .topbar .brand,
body.mobile .topbar .obj,
body.mobile .topbar .cell-era,
body.mobile .topbar .speed-stat,
body.mobile .topbar #tbOilCell { display: none; }
body.mobile .topbar > div { padding: 6px 12px; border-left: 1px solid var(--rule); flex: 1 0 auto; }
body.mobile .topbar .stat .k { font-size: 9px; letter-spacing: 0.08em; }
body.mobile .topbar .stat .v { font-size: 13px; }
body.mobile .topbar .stat .delta { font-size: 9px; }

/* threat banner: compact strip under the HUD */
body.mobile .threat { border-radius: 0; padding: 5px 10px; gap: 8px; }
body.mobile .threat .ico { font-size: 9px; padding: 2px 6px; }
body.mobile #threatText { font-size: 10px; line-height: 1.25; white-space: normal; }
body.mobile .threat .cd { font-size: 9px; }
body.mobile .threat-btn { font-size: 10px; padding: 6px 10px; min-height: 32px; }

/* ---------- the world fills everything between HUD and thumb bar ---------- */
body.mobile .main {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
}
body.mobile .canvas-wrap {
  position: absolute;
  inset: 0;
  max-width: none;
  margin: 0;
}
body.mobile canvas#world {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

/* overlays that sit on the world */
body.mobile .minimap {
  top: 8px; right: 8px;
  width: 96px; height: 66px;
  padding: 3px;
  opacity: 0.92;
}
body.mobile .canvas-hint { display: none; }     /* keyboard hints are meaningless on glass */
body.mobile #mmLadder { display: none !important; } /* era ladder: Level-up checklist covers this; reclaim the screen */

/* selection info is MOVED into .canvas-wrap by JS on phones (it can't be
   position:fixed inside the transformed sheet) -- floating caption chip */
body.mobile .canvas-wrap .selection-info {
  position: absolute;
  left: 10px; right: 10px; bottom: 10px;
  text-align: center;
  font-size: 11px;
  color: var(--text, #ede4d0);
  background: rgba(13,10,5,0.78);
  border: 1px solid var(--border, rgba(212,175,93,0.12));
  border-radius: 99px;
  padding: 7px 14px;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 5;
}
body.mobile .canvas-wrap .selection-info:empty { display: none; }
body.mobile .canvas-wrap .selection-info b { color: var(--gold, #d4af5d); }

/* toast: under the HUD, never over the thumb bar */
body.mobile .toast {
  top: calc(52px + env(safe-area-inset-top));
  bottom: auto;
  left: 50%;
  max-width: 92%;
  z-index: 95;
}

/* ---------- sheets: dashboard (.rail) and court (.bottom-panel) ---------- */
body.mobile .rail,
body.mobile .bottom-panel {
  position: fixed;
  left: 0; right: 0;
  bottom: var(--mbar-h); /* dock above the thumb bar so it stays usable */
  z-index: 80;
  margin: 0;
  max-height: calc(80vh - var(--mbar-h));
  max-height: calc(80dvh - var(--mbar-h));
  transform: translateY(105%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0.22, 1);
  border-radius: 16px 16px 0 0;
  border: 1px solid var(--border-bright, rgba(212,175,93,0.26));
  border-bottom: 0;
  background: var(--bg-1, #15120d);
  box-shadow: 0 -16px 48px rgba(0,0,0,0.7);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.mobile .rail.open,
body.mobile .bottom-panel.open { transform: translateY(0); }

/* grab handle */
body.mobile .rail::before,
body.mobile .bottom-panel::before {
  content: "";
  flex: 0 0 auto;
  width: 42px; height: 4px;
  border-radius: 99px;
  background: rgba(212,175,93,0.35);
  margin: 8px auto 4px;
}

body.mobile .rail { max-height: none; overflow-y: hidden; }
body.mobile .rail-shell {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  padding-bottom: 16px;
}
body.mobile .rail-tab { min-height: 42px; }
body.mobile .stat-row { min-height: 34px; }
body.mobile .sell-btn { min-height: 32px; min-width: 52px; }

body.mobile .bottom-panel > * { flex: 0 0 auto; }
body.mobile .bottom-panel .pitch-strip {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex-direction: column;
  align-items: stretch;
  padding: 8px 12px 4px;
}
body.mobile .pitch-card { width: auto; }
body.mobile .pitch-card .pc-desc { -webkit-line-clamp: 3; font-size: 11px; }
body.mobile .pitch-card .pc-name { font-size: 12px; }
body.mobile .pitch-card .pc-fund { height: 40px; font-size: 12px; }
body.mobile .pitch-empty { white-space: normal; padding: 10px; }
body.mobile .bottom-actions {
  flex-wrap: wrap;
  padding: 10px 12px 12px;
}
body.mobile .bottom-actions .action-buttons { flex: 1 1 100%; flex-wrap: wrap; }
body.mobile .bottom-actions .action-buttons .btn { flex: 1 1 45%; min-height: 46px; font-size: 12px; }

/* ---------- modals: bottom sheets with thumb-size targets ---------- */
body.mobile .build-menu { align-items: flex-end; padding: 0; }
body.mobile .build-menu .build-panel {
  max-width: 100%;
  max-height: 88vh;
  max-height: 88dvh;
  border-radius: 16px 16px 0 0;
  border-bottom: 0;
}
body.mobile .build-menu .bm-list {
  grid-template-columns: 1fr;
  max-height: none;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
body.mobile .build-menu .bm-item { padding: 13px 14px; }
body.mobile .build-menu .bm-item .bm-name { font-size: 14px; }
body.mobile .build-menu .bm-item .bm-desc { font-size: 11px; }
body.mobile .build-menu .bm-tab { padding: 12px 14px; font-size: 11px; }
body.mobile .bm-close { width: 44px !important; height: 44px !important; font-size: 20px !important; }

body.mobile .building-info { align-items: flex-end; padding: 0; }
body.mobile .building-info .bi-panel {
  max-width: 100%;
  width: 100%;
  max-height: 88vh;
  max-height: 88dvh;
  border-radius: 16px 16px 0 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
body.mobile .bi-actions .btn { min-height: 46px; }

/* dialogs / story overlays */
body.mobile .overlay .box {
  max-width: 94vw;
  max-height: 86vh;
  max-height: 86dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
body.mobile .overlay h2 { font-size: 18px; }
body.mobile .overlay .btn { min-height: 46px; }

body.mobile .tweaks { max-width: 94vw; }

/* ---------- landscape phones: reclaim vertical space ---------- */
@media (orientation: landscape) {
  body.mobile { --mbar-h: calc(50px + env(safe-area-inset-bottom)); }
  body.mobile .mbar { padding-top: 5px; padding-bottom: calc(5px + env(safe-area-inset-bottom)); }
  body.mobile .mbar button { min-height: 40px; font-size: 11px; }
  body.mobile .topbar > div { padding: 4px 12px; }
  body.mobile .topbar .stat .k { display: none; }
  body.mobile .rail,
  body.mobile .bottom-panel { max-height: calc(92vh - var(--mbar-h)); max-height: calc(92dvh - var(--mbar-h)); }
}
