/* Shared mobile layout. Components retain their regional content and theme tokens. */
/* The workspace never scrolls as a whole, only its panels: no whole-page bounce at either end. */
html, body { overscroll-behavior-y:none; }
@media (max-width:760px) {
  :root { --mobile-dock:calc(52px + env(safe-area-inset-bottom,0px)); }
  html { -webkit-text-size-adjust:100%; text-size-adjust:100%; }
  body.in-app .side { display:none; }
  body.in-app .workspace { height:var(--mg-viewport-height,100dvh); max-height:var(--mg-viewport-height,100dvh); min-height:0; padding-bottom:var(--mobile-dock); }
  body.in-app .top { overflow:visible; flex:none; height:calc(52px + env(safe-area-inset-top,0px)); padding:env(safe-area-inset-top,0px) 10px 0; gap:6px; }
  .top .page-title { flex:1; min-width:0; font-size:15px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .top .top-bal { flex:none; max-width:32%; font-size:13px; font-variant-numeric:tabular-nums; }
  .top .mode-btn,.top .bell-btn,.top .avatar { flex:0 0 44px; width:44px; height:44px; min-width:44px; }
  .top .notice-drop,.top .user-drop { position:fixed; top:calc(58px + env(safe-area-inset-top,0px)); right:max(10px,env(safe-area-inset-right,0px)); max-width:calc(100vw - 20px); max-height:calc(var(--mg-viewport-height,100dvh) - 80px); overflow-y:auto; overscroll-behavior:contain; }
  body.in-app .dock { height:var(--mobile-dock); padding-bottom:env(safe-area-inset-bottom,0px); }
  .dock>button,.dock>a { height:52px; min-width:0; white-space:nowrap; }
  /* iOS does not zoom focused controls at 16px. Do not disable page zoom. */
  body input:not([type=range]):not([type=checkbox]):not([type=radio]),body textarea,body select { font-size:16px; }
  body input:not([type=range]):not([type=checkbox]):not([type=radio]):not([type=file]),body select { min-height:44px; }
  body input,body textarea,body select { max-width:100%; scroll-margin-block:20px; }
  .glide-trigger { min-height:44px; min-width:0; max-width:100%; }
  .glide-value { min-width:0; }
  .glide-option { min-height:44px; padding-block:11px; }
  .glide-list { overscroll-behavior:contain; -webkit-overflow-scrolling:touch; }
  button,a,input,select,textarea { -webkit-tap-highlight-color:transparent; }
  button,a { touch-action:manipulation; }
  .stage-body,.gen-split,.creative-assets-body,.agent-log,.community-dialog,.creative-dialog,.modal-card,.ux-more-sheet { overscroll-behavior-y:contain; -webkit-overflow-scrolling:touch; }
  .stage-head { gap:10px; flex-wrap:wrap; padding:16px; }
  .stage-head h1,.stage-head h2 { min-width:0; overflow-wrap:anywhere; }
  .stage-head .hint { min-width:0; line-height:1.6; }
  .stage-body { scroll-padding-block:16px; }
  /* Bottom actions and floating assistant never compete for the same space. */
  body.in-app .agent-fab { display:none; }
  .agent-fab { width:44px; height:44px; justify-content:center; right:max(12px,env(safe-area-inset-right,0px)); bottom:calc(var(--mobile-dock) + 12px); padding:0; }
  body.in-app #page-gen .gen-heading { padding:12px 16px; gap:12px; align-items:center; }
  #page-gen .gen-heading h1 { font-size:22px; line-height:1.35; }
  #page-gen .gen-heading>button { flex:none; max-width:40%; min-height:44px; }
  body.in-app #page-gen .gen-split { display:block; overflow-y:auto; padding:0 12px calc(var(--mg-submit-height,112px) + 20px); scroll-padding-bottom:calc(var(--mg-submit-height,112px) + 20px); }
  body.in-app #page-gen .bench,body.in-app #page-gen .bench-scroll { height:auto; overflow:visible; }
  #page-gen .gen-composer-top { padding:12px; }
  #page-gen .kind-switch button { min-height:44px; }
  #page-gen .gen-composer-body { padding:16px 12px; }
  #page-gen .gen-parameters { gap:6px; margin-block:14px 18px; }
  #page-gen .gen-param-label { font-size:10px; line-height:1.4; }
  #page-gen .gen-parameter { padding:10px 7px; }
  #page-gen .gen-parameter .glide-trigger.field { min-height:44px; }
  #page-gen .dur-bar { min-height:28px; align-items:center; }
  #page-gen #dur { height:28px; }
  #page-gen #prompt { font-size:16px; line-height:1.65; }
  #page-gen #genMention,#page-gen #genRefsToggle { min-height:44px; }
  #page-gen .ref-x { width:32px; height:32px; opacity:1; }
  body.in-app #page-gen .bench-go { position:fixed; bottom:var(--mobile-dock); left:env(safe-area-inset-left,0px); right:env(safe-area-inset-right,0px); z-index:10; padding:10px 16px 8px; border-radius:0; }
  #page-gen .gen-submit-row { gap:12px; }
  #page-gen #go { min-height:48px; min-width:0; }
  #page-gen #priceHint { font-size:11px; line-height:1.5; max-height:48px; overflow-y:auto; }
  body.in-app #page-gen #feed { grid-template-columns:1fr; overflow:visible; }
  body.in-app #page-gen .feed-panel { overflow:visible; }
  #page-gen #feed .clip { grid-template-rows:56px auto minmax(57px,auto) minmax(40px,auto) 30px auto; }
  #page-gen #feed .clip-actions { height:auto; max-height:none; overflow:visible; }
  #page-gen #feed .clip-actions a,#page-gen #feed .clip-actions button { min-height:44px; }
  #page-gen #feed .clip-actions .clip-copy { min-height:48px; }
  .ux-history-filters { gap:8px; }
  .clip-actions a,.clip-actions button,.hist-delete-actions button { min-height:44px; }
  /* Keep the canvas selector, create action and save state on separate tracks. */
  .canvas-board-bar { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:4px 8px; padding:8px 12px; }
  .canvas-board-bar>.field,.canvas-board-bar>.glide-trigger { width:100%; min-width:0; max-width:100%; }
  .canvas-board-bar .glide-value { overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }
  .canvas-board-bar #canvasNewBoard { min-height:44px; white-space:nowrap; padding-inline:12px; }
  .canvas-board-bar .canvas-board-status { grid-column:1/-1; max-width:none; font-size:11px; line-height:1.5; min-height:17px; }
  #tapnowCanvasFrame { touch-action:none; }
  /* Reclaim vertical room without shrinking touch controls. */
  #page-assets .creative-desk-head { padding:16px; gap:12px; }
  #page-assets .creative-desk-head h1 { font-size:24px; }
  #page-assets .creative-desk-head button { min-height:44px; }
  #page-assets .creative-desk-head .creative-eyebrow { margin-bottom:6px; }
  #page-assets .creative-desk-toolbar { gap:8px; padding:0 16px 12px; }
  .asset-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); }
  .asset-actions button,.asset-actions a { min-height:44px; padding:8px 6px; text-align:center; }
  #page-assets .creative-assets-body { padding-bottom:64px; scroll-padding-bottom:64px; }
  .wallet-tabs { flex-wrap:nowrap; }
  #page-pay .wallet-tabs { width:100%; }
  #page-pay .wallet-tabs button { flex:none; min-height:44px; min-width:80px; white-space:nowrap; }
  .redeem-form input.field { letter-spacing:.3px; font-size:16px; }
  .api-tabs { gap:6px; }
  .api-tabs button { min-height:44px; line-height:1.4; }
  .api-key-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
  .api-key-actions button { min-height:44px; }
  .api-base { min-width:0; flex-wrap:wrap; }
  .api-base code { min-width:0; max-width:100%; overflow-wrap:anywhere; }
  .api-pane pre,.api-endpoints { max-width:100%; overscroll-behavior-x:contain; }
  .api-shell .stage-head { padding:16px; }
  .api-key-main strong,.api-key-main code { overflow-wrap:anywhere; }
  .agent-layout { height:100%; min-height:0; max-height:none; }
  #page-agent { padding-bottom:0; }
  .agent-top { flex-wrap:nowrap; min-height:60px; }
  .agent-model-wrap { flex:1; width:auto; max-width:none; }
  .agent-top .agent-icon-btn,.agent-close,.agent-send { flex:none; min-width:44px; min-height:44px; width:44px; height:44px; }
  .agent-top-brand { flex:none; }
  .agent-top-brand svg { width:16px; }
  .agent-new-chat-top { padding:0; }
  .agent-composer textarea { font-size:16px; }
  .agent-compose-tools { flex-wrap:wrap; gap:4px; }
  .agent-icon-btn { min-height:44px; }
  .agent-compose-wrap { padding:8px 12px 10px; max-height:55%; overflow-y:auto; }
  .agent-floating { top:calc(var(--mg-viewport-top,0px) + env(safe-area-inset-top,0px) + 8px); bottom:auto; height:calc(var(--mg-viewport-height,100dvh) - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px) - 16px); }
  .agent-empty { padding:20px 0; }
  .agent-empty p { margin-bottom:18px; }
  .agent-starters button { min-height:44px; }
  .community-dialog,.creative-dialog,.ux-more-sheet,.user-price-dialog { max-height:calc(var(--mg-viewport-height,100dvh) - 24px); overscroll-behavior:contain; }
  .community-dialog input,.community-dialog textarea,.creative-dialog input,.creative-dialog textarea { font-size:16px; }
  body #communityPostForm select,body #communityProfileForm input,body #page-community #communitySort { font-size:16px; }
  .community-dialog .glide-trigger { min-height:44px; }
  .community-form-actions { flex-wrap:wrap; }
  .community-form-actions button,.community-toolbar button,.community-card-actions button { min-height:44px; }
  .community-profile-card input { font-size:16px; }
  .community-feed { padding-bottom:20px; }
  .modal { top:var(--mg-viewport-top,0px); bottom:auto; height:var(--mg-viewport-height,100dvh); }
  .modal-card { max-height:calc(var(--mg-viewport-height,100dvh) - 24px); }
  .modal-x,.ref-view-x { min-width:44px; min-height:44px; }
  .gate { height:var(--mg-viewport-height,100dvh); min-height:0; top:var(--mg-viewport-top,0px); padding-block:max(16px,env(safe-area-inset-top,0px)) max(16px,env(safe-area-inset-bottom,0px)); overflow-y:auto; }
  .auth-frame { flex:none; max-height:none; }
  .ux-more-sheet { padding-bottom:max(16px,env(safe-area-inset-bottom,0px)); }
  .admin-tabs { scroll-padding-inline:16px; overscroll-behavior-x:contain; }
  .admin-tabs button { min-height:44px; white-space:nowrap; }
  .cards-summary { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .cards-controls { grid-template-columns:1fr; }
  .price-console-toolbar,.user-price-toolbar { flex-wrap:wrap; }
  body.mobile-keyboard .dock,body.mobile-keyboard .agent-fab { display:none!important; }
  body.in-app.mobile-keyboard .workspace { padding-bottom:0; }
  body.mobile-keyboard #page-gen .bench-go { position:static; }
  body.mobile-keyboard #page-gen .gen-split { padding-bottom:20px; scroll-padding-bottom:20px; }
  body.mobile-keyboard .agent-compose-note,body.mobile-keyboard .agent-price-details { display:none; }
}
@media (max-width:360px) {
  .top .page-title { font-size:14px; }
  #page-gen .gen-heading>div>span { font-size:9px; letter-spacing:.08em; }
  #page-gen .gen-heading h1 { font-size:20px; }
  #page-gen .gen-heading>button { font-size:11px; padding:8px; }
  #page-gen .gen-param-label { font-size:9px; }
  .agent-top { gap:4px; padding-inline:8px; }
  .agent-top-brand { display:none; }
  .community-card-actions { flex-wrap:wrap; }
}
@media (max-width:1024px) and (max-height:500px) and (pointer:coarse) {
  body.in-app .workspace { height:var(--mg-viewport-height,100dvh); min-height:0; }
  body.in-app #page-gen .gen-heading { padding-block:6px; }
  body.in-app #page-gen .bench-go { position:static; }
  body.in-app #page-gen .gen-split { padding-bottom:20px; }
  .agent-layout { min-height:0; }
  .agent-empty { padding-block:8px; }
  .agent-empty-logo,.agent-empty p,.agent-starters { display:none; }
  .agent-compose-note { display:none; }
}


/* Mobile rendering budget: retain original media and avoid full-surface backdrop sampling. */
@media (max-width:760px), (hover:none) and (pointer:coarse) {
  body .top, body.community-standalone .top, body .dock, body .glass, body .nav, body .user-drop,
  body .notice-drop, body .modal-card, body .auth-frame,
  body .ux-more-sheet, body .community-dialog::backdrop,
  body .creative-modal::backdrop, body .mg-dialog::backdrop {
    -webkit-backdrop-filter:none; backdrop-filter:none;
  }
  body .top, body .dock { background:var(--panel); }
  .feed-panel::after, .auth-frame::after, .motion-card::after { display:none; }
  .refine-frame[data-refine-status="generating"]::before,
  .refine-frame[data-refine-status="refining"]::before { animation:none; }
}
