/* Mobile portrait layout — everything here is scoped to body.mobile
   (public/js/mobile/layoutMode.js). Desktop never matches these rules. */

.mobile-only { display: none !important; }
body.mobile .mobile-only:not([hidden]) { display: flex !important; }

body.mobile {
  display: block;
  margin: 0;
  padding: 0;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: #0d0c0b;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* Column: status strip, then the canvas filling the rest. The tab bar is
   fixed at the bottom; the container's bottom padding keeps the canvas
   clear of it, so the canvas wrapper's box is exactly the visible world. */
body.mobile #game-container {
  width: 100%;
  max-width: none;
  height: 100dvh;
  gap: 0;
  align-items: stretch;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
}

body.mobile #info-panel,
body.mobile #instructions,
body.mobile #canvas-top-right,
body.mobile #version-display { display: none !important; }

body.mobile #mobile-status {
  flex: 0 0 40px;
  align-items: center;
  gap: 10px;
  padding: 0 4px 0 8px;
  background: #2a2622;
  border-bottom: 1px solid #1a1816;
  color: #e8dcc0;
  font-family: Georgia, serif;
}
body.mobile #mobile-hp {
  position: relative;
  width: 96px;
  height: 22px;
  background: #3a1414;
  border: 1px solid #1a1816;
  border-radius: 4px;
  overflow: hidden;
}
body.mobile #mobile-hp-fill { position: absolute; top: 0; bottom: 0; left: 0; background: #3f9a3f; }
body.mobile #mobile-hp-fill.mid { background: #c9a227; }
body.mobile #mobile-hp-fill.low { background: #c8201c; }
body.mobile #mobile-hp-text {
  position: relative;
  display: block;
  text-align: center;
  font-size: 13px;
  line-height: 22px;
  text-shadow: 0 1px 0 #000;
}
body.mobile #mobile-zone {
  flex: 1;
  font-size: 15px;
  color: #d4a84b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.mobile #mobile-more-btn {
  width: 48px;
  height: 40px;
  font-size: 24px;
  background: none;
  border: none;
  color: #e8dcc0;
}

body.mobile #canvas-wrapper { position: relative; flex: 1 1 auto; min-height: 0; }
body.mobile #game-canvas {
  display: block;
  border: none;
  border-radius: 0;
  box-shadow: none;
  touch-action: none;
}

/* Tab bar in the thumb zone */
body.mobile #panel-cluster {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: auto;
  z-index: 30;
  pointer-events: auto;
  padding-bottom: env(safe-area-inset-bottom);
  background: #2a2622;
}
body.mobile #panel-tabs {
  height: 56px;
  box-sizing: border-box;
  padding: 4px 6px;
  gap: 4px;
  border: none;
  border-top: 1px solid #1a1816;
  border-radius: 0;
  box-shadow: none;
}
body.mobile #panel-tabs .ptab { height: 48px; font-size: 22px; position: relative; }
body.mobile #mobile-chat-badge {
  position: absolute;
  top: 6px;
  right: 18%;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #c8201c;
}

/* Keyboard bridge: docked above the tab bar */
body.mobile #mobile-keyboard-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(56px + env(safe-area-inset-bottom));
  z-index: 70; /* above popup sheets: the bank's X prompt types through it */
  gap: 6px;
  padding: 6px 8px;
  background: #2a2622;
  border-top: 1px solid #8b5a2b;
}
body.mobile #mobile-keyboard-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  font-size: 16px;
  padding: 0 10px;
  background: #1a1816;
  color: #e8dcc0;
  border: 1px solid #3a3530;
  border-radius: 6px;
  -webkit-user-select: text;
  user-select: text;
}
body.mobile #mobile-keyboard-send {
  min-width: 72px;
  min-height: 44px;
  font-size: 16px;
  background: #8b5a2b;
  color: #fff5e0;
  border: 1px solid #c49660;
  border-radius: 6px;
}

/* With a popup sheet open the tab bar is covered; dock above the sheet's
   Close bar instead (.mobile-sheet-bar ≈ 65px). */
body.mobile.mobile-sheet-open #mobile-keyboard-bar { bottom: calc(65px + env(safe-area-inset-bottom)); }

/* ⋯ menu: bottom action sheet */
body.mobile #mobile-more-sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0.5);
}
body.mobile .mobile-more-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: #1f1c19;
  border-top: 2px solid #8b5a2b;
  border-radius: 12px 12px 0 0;
  font-family: Georgia, serif;
  box-sizing: border-box;
}
body.mobile .mobile-more-panel > button,
body.mobile .mobile-more-panel > label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 12px;
  font-size: 17px;
  font-family: inherit;
  color: #e8dcc0;
  background: #2a2622;
  border: 1px solid #3a3530;
  border-radius: 8px;
  text-align: left;
}
body.mobile .mobile-more-panel select { font-size: 16px; min-height: 36px; }
body.mobile .mobile-more-panel > .mobile-more-close { justify-content: center; background: #5c3d2e; }

/* Landscape phone: the canvas is only ~300px tall, so the status strip and
   tab bar slim down, and the notch side (safe-area left/right) is padded.
   Tab panels open as a side sheet on the right (mobile/sheetLayout.js). */
@media (orientation: landscape) {
  body.mobile #game-container {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: calc(44px + env(safe-area-inset-bottom));
  }
  body.mobile #mobile-status { flex-basis: 32px; }
  body.mobile #mobile-more-btn { height: 32px; }
  body.mobile #panel-cluster {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  body.mobile #panel-tabs { height: 44px; padding: 3px 6px; }
  body.mobile #panel-tabs .ptab { height: 38px; font-size: 20px; }
  body.mobile #mobile-keyboard-bar { bottom: calc(44px + env(safe-area-inset-bottom)); }
  body.mobile .mobile-more-panel {
    max-height: 100dvh;
    overflow-y: auto;
  }
}

/* Desktop layout on a touch screen (tablets; body.touch-ui is set on touch
   input by mobile/touchInput.js): the canvas takes all gestures, and the
   keyboard bar docks at the bottom for X-amount prompts. */
#game-canvas { touch-action: none; } /* every layout: the gesture layer owns touch */
body.touch-ui:not(.mobile) #mobile-keyboard-bar:not([hidden]) {
  display: flex !important;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: #2a2622;
  border-top: 1px solid #8b5a2b;
}
body.touch-ui:not(.mobile) #mobile-keyboard-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  font-size: 16px;
  padding: 0 10px;
  background: #1a1816;
  color: #e8dcc0;
  border: 1px solid #3a3530;
  border-radius: 6px;
}
body.touch-ui:not(.mobile) #mobile-keyboard-send {
  min-width: 72px;
  min-height: 44px;
  font-size: 16px;
  background: #8b5a2b;
  color: #fff5e0;
  border: 1px solid #c49660;
  border-radius: 6px;
}
