/* ===== 21PlayLab mobile layout for FaceMetric Studio ===== */
canvas { touch-action: none; }

@media (max-width: 760px) {
  html, body { overscroll-behavior: none; }
  .app-shell { height: 100dvh; }

  /* Top bar */
  .topbar { height: 48px; padding: 0 8px; gap: 6px; }
  #storageStatusBtn { display: none; }
  .topbar-pill-btn { height: 32px; font-size: 12px; padding: 0 10px; }

  /* Left rail -> bottom tab bar */
  .app-body { flex-direction: column-reverse; min-height: 0; }
  .main-stage { flex: 1 1 0; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .rail {
    width: auto; height: auto; flex-direction: row; justify-content: center;
    border-right: 0; border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .rail-group { flex-direction: row; gap: 2px; flex: 1; justify-content: space-around; }
  .rail-group + .rail-group { display: none; }
  .rail-btn { width: auto; flex: 1; height: 54px; font-size: 11px; }

  /* Bigger touch targets */
  .btn-outline, .btn-primary { min-height: 40px; font-size: 13px; }
  .btn-sm { min-height: 36px; padding: 6px 10px; font-size: 12px; }
  .seg-btn, .icon-tool { min-height: 36px; }

  /* Library */
  .library-view { padding: 16px 14px 24px; }
  .library-meta-bar { flex-wrap: wrap; gap: 8px; }
  .case-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }

  /* Analysis workspace: canvas on top, inspector below */
  .workspace-view { flex: none; }
  .ws-toolbar { padding: 6px 8px; }
  .ws-content { flex-direction: column; flex: none; }
  .canvas-stage { flex: none; height: 62dvh; }
  .inspector { width: auto; border-left: 0; border-top: 1px solid var(--line); flex: none; }
  .inspector-scroll { max-height: none; overflow: visible; }

  /* Simulation setup: front & side stacked */
  .simulation-view { flex: none; }
  .sim-setup-stage { flex: none; min-height: auto; }
  .sim-setup-grid { display: flex; flex-direction: column; gap: 2px; flex: none; }
  .sim-setup-pane { flex: none; height: 44dvh; }
  .sim-setup-bar { flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
  .sim-rot-controls { flex-wrap: wrap; gap: 6px; }
  .sim-rot-controls .btn-sm { white-space: nowrap; }
  .sim-drop-empty { inset: 14px; padding: 16px; text-align: center; }
  .sim-drop-empty strong { font-size: 17px; }
  .sim-drop-empty p { font-size: 14px; line-height: 1.5; }
  .sim-pick-gallery { display: inline-flex !important; }
  .sim-setup-bottom { padding: 10px 12px; gap: 8px; position: sticky; bottom: 0; z-index: 30; box-shadow: 0 -6px 16px rgba(0,0,0,.45); }
  .sim-guide-tip { font-size: 12px; line-height: 1.45; }
  .sim-setup-bottom-actions { width: 100%; }
  .sim-complete-btn { flex: 1; min-height: 46px; font-size: 14px; }

  /* Simulation editor: canvas first, docks below */
  .sim-editor-stage { flex-direction: column; flex: none; }
  .sim-stage-center { order: -1; flex: none; height: 56dvh; }
  .sim-left-dock, .sim-right-dock { width: auto; border: 0; border-top: 1px solid var(--line); }
  .sim-right-dock { overflow: visible; }
  .sim-editor-top-row { flex-wrap: wrap; }
  .sim-main-col { width: auto; flex: 1; }
  .sim-design-box { max-height: 40vh; overflow-y: auto; }

  /* Dialogs fit the screen */
  .modal, .modal-card, .dialog, [role="dialog"] { max-width: calc(100vw - 24px) !important; max-height: 88dvh; overflow-y: auto; }
}

.sim-pick-gallery {
  display: none; align-items: center; justify-content: center; gap: 8px;
  margin-top: 10px; padding: 12px 18px; min-height: 46px;
  border-radius: 10px; border: 0; background: var(--accent); color: #041311;
  font-size: 15px; font-weight: 700;
}

@media (max-width: 760px) {
  /* scroll handles: bars and footers are always finger-scrollable */
  .sim-setup-bar, .sim-setup-foot, .sim-setup-bottom, .sim-left-dock, .sim-right-dock { touch-action: pan-y; }
  .sim-setup-foot { padding: 12px 14px; font-size: 12px; }
}
@media (max-width: 760px) {
  .sim-stage-center .disclaimer-bar { position: static !important; transform: none !important; margin: 0; padding: 8px 12px; font-size: 11px; line-height: 1.4; background: var(--bg-1); border-top: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .sim-history-float { top: 10px; bottom: auto; left: 10px; }
  .sim-view-switcher { bottom: 58px; }
}

.fm-zoom-reset, .fm-zoom-hint { display: none; }
@media (max-width: 760px) {
  .fm-zoom-reset { display: inline-flex; position: absolute; top: 10px; right: 10px; z-index: 7; min-height: 36px; align-items: center;
    padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line-strong); background: rgba(19,22,28,.88); color: var(--ink); font-size: 12px; font-weight: 600; }
  .fm-zoom-hint { display: block; position: absolute; left: 50%; top: 44%; transform: translate(-50%,-50%); z-index: 8; pointer-events: none;
    padding: 10px 16px; border-radius: 999px; background: rgba(0,0,0,.78); color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap;
    opacity: 0; transition: opacity .3s; }
  .fm-zoom-hint.show { opacity: 1; }
}

.fm-mode-badge { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 7; max-width: calc(100% - 24px);
  padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: rgba(19,22,28,.9); color: var(--ink);
  font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.fm-mode-badge.on { background: var(--accent); border-color: var(--accent); color: #041311; }
@media (max-width: 760px) {
  .fm-mode-badge { top: 54px; font-size: 11.5px; }
}
